SpecExtractor.java seems to work
authorPeizhao Ou <peizhaoo@uci.edu>
Thu, 10 Oct 2013 08:01:20 +0000 (01:01 -0700)
committerPeizhao Ou <peizhaoo@uci.edu>
Thu, 10 Oct 2013 08:01:20 +0000 (01:01 -0700)
grammer/spec-compiler.jj
src/edu/uci/eecs/specCompiler/specExtraction/SpecExtractor.java

index 6ce4495..f7a4248 100644 (file)
@@ -64,12 +64,20 @@ options {
 PARSER_BEGIN(SpecParser)
 package edu.uci.eecs.specCompiler.grammerParser;
 
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+
        class SpecParser {
                public static void main(String[] argvs)
                throws ParseException, TokenMgrError {
-                       SpecParser parser = new SpecParser(System.in);
-                       parser.Start();
-                       System.out.println("Parsing finished!");
+                       try {
+                               FileInputStream fis = new FileInputStream("./grammer/spec.txt");
+                               SpecParser parser = new SpecParser(fis);
+                               parser.Start();
+                               System.out.println("Parsing finished!");
+                       } catch (FileNotFoundException e) {
+                               e.printStackTrace();
+                       }
                }
        }
 PARSER_END(SpecParser)
@@ -81,14 +89,18 @@ SKIP :
        "\n"
 |
        "\r"
+|
+       "\r\n"
 |
        "\t"
+       /*
 |
        // "#" comment for the specification
        <"#" (~["\n", "\r"])* (["\n", "\r"])>
 |
        // "//" comment for the specification
        <"//" (~["\n", "\r"])* (["\n", "\r"])>
+       */
 }
 
 TOKEN :
@@ -136,12 +148,8 @@ TOKEN :
        <POTENTIAL_COMMIT_POINT_LABEL: "@Potential_commit_point_label:">
 |
        <#DIGIT: ["0"-"9"]>
-|
-       <#NONZERO_DIGIT: ["1"-"9"]>
 |
        <#LETTER: ["a"-"z", "A"-"Z"]>
-|
-       <#NUM: <NONZERO_DIGIT> <DIGIT>>
 |
        <IDENTIFIER: <LETTER> (<LETTER> | <DIGIT> | "_")>       
 }
@@ -149,7 +157,9 @@ TOKEN :
 void Start() :
 {}
 {
-       Global_construct() <EOF>
+       //Global_construct() <EOF>
+       <EOF>
+       //<IDENTIFIER> <EOF>
 }
 
 void Global_construct() :
@@ -157,13 +167,13 @@ void Global_construct() :
 {
        <HEAD>
                <BEGIN> 
-                       Global_define() (Interface_cluster())? (Happens_before())?
+                       //Global_define() (Interface_cluster())? (Happens_before())?
                <END>
        <TAIL>
 }
 
 void C_CPP_CODE() :
-{}
+{String code;}
 {
        <(~["@"])+>
 }
@@ -201,10 +211,6 @@ void Happens_before() :
 void Interface() :
 {}
 {
-       <HEAD> 
-               <BEGIN> 
-                       <HAPPENS_BEFORE> <IDENTIFIER> "(" <IDENTIFIER> ")"  "->" <IDENTIFIER>
-               <END>
        <TAIL>
 }
 
@@ -213,7 +219,6 @@ void Potential_commit_point_define() :
 {
        <HEAD> 
                <BEGIN> 
-                       <HAPPENS_BEFORE> <IDENTIFIER> "(" <IDENTIFIER> ")"  "->" <IDENTIFIER>
                <END>
        <TAIL>
 }
@@ -224,7 +229,6 @@ void Commit_point_define() :
 {
        <HEAD> 
                <BEGIN> 
-                       <HAPPENS_BEFORE> <IDENTIFIER> "(" <IDENTIFIER> ")"  "->" <IDENTIFIER>
                <END>
        <TAIL>
 }
@@ -235,7 +239,6 @@ void Commit_point_define_check() :
 {
        <HEAD> 
                <BEGIN> 
-                       <HAPPENS_BEFORE> <IDENTIFIER> "(" <IDENTIFIER> ")"  "->" <IDENTIFIER>
                <END>
        <TAIL>
 }
index ba04343..2d28fce 100644 (file)
@@ -57,25 +57,29 @@ public class SpecExtractor {
                                        if (trimedLine.startsWith("/**")) {
                                                _beginLine = reader.getLineNumber();
                                                _foundHead = true;
+                                               specText.append("\n");
+                                               specText.append(curLine);
                                                if (trimedLine.endsWith("*/")) {
                                                        _endLine = reader.getLineNumber();
                                                        _foundHead = false;
                                                        
                                                        System.out.println("Spec<" + specIndex + "> Begin: "
                                                                        + _beginLine + "  End: " + _endLine);
-                                                       System.out.println(curLine);
+                                                       System.out.println(specText);
+                                                       specIndex++;
                                                }
                                        }
                                } else {
+                                       specText.append("\n");
+                                       specText.append(curLine);
                                        if (trimedLine.endsWith("*/")) {
                                                _endLine = reader.getLineNumber();
                                                _foundHead = false;
-                                               specText.append("\n");
-                                               specText.append(curLine);
                                                
                                                System.out.println("Spec<" + specIndex + "> Begin: "
                                                                + _beginLine + "  End: " + _endLine);
-                                               System.out.println(curLine);
+                                               System.out.println(specText);
+                                               specIndex++;
                                                
                                                specText = new StringBuilder();
                                        } else {
@@ -95,16 +99,12 @@ public class SpecExtractor {
                char ch;
                for (i = 0; i < line.length(); i++) {
                        ch = line.charAt(i);
-                       if (ch == ' ' || ch == '\t')
-                               i++;
-                       else
+                       if (ch != ' ' && ch != '\t')
                                break;
                }
                for (j = line.length() - 1; j >= 0; j--) {
                        ch = line.charAt(j);
-                       if (ch == ' ' || ch == '\t')
-                               j--;
-                       else
+                       if (ch != ' ' && ch != '\t')
                                break;
                }
                if (i > j)