parser checked
[cdsspec-compiler.git] / grammer / spec-compiler.jj
index 85aabff..2238268 100644 (file)
@@ -71,6 +71,8 @@ package edu.uci.eecs.specCompiler.grammerParser;
 
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.io.ByteArrayInputStream;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -97,6 +99,15 @@ import edu.uci.eecs.specCompiler.specExtraction.ActionSubConstruct.DefineVar;
                                e.printStackTrace();
                        }
                }
+       
+               public static Construct parseSpec(String text)
+               throws ParseException, TokenMgrError {
+                       InputStream input = new ByteArrayInputStream(text.getBytes());
+                       SpecParser parser = new SpecParser(input);
+                       return parser.Parse();
+               }
+
+
        }
 PARSER_END(SpecParser)
 
@@ -198,6 +209,8 @@ TOKEN :
        <STAR: "*">
 |
        <NEGATE: "~">
+|
+       <EXCLAMATION: "!">
 |
        <AND: "&">
 |
@@ -313,7 +326,7 @@ Construct Parse() :
        )
        <EOF>
        {
-               System.out.println(res);
+               //System.out.println(res);
                return res;
        }
 }
@@ -354,7 +367,7 @@ String C_CPP_CODE() :
        (
        t = <IDENTIFIER> | t = <EQUALS> | t = <OPEN_PAREN> | t = <CLOSE_PAREN> |
        t = <OPEN_BRACKET> | t = <CLOSE_BRACKET> | t = <HB_SYMBOL> | t = <COMMA> |
-       t = <DOT> | t = <STAR> | t = <NEGATE> | t = <AND> | t = <OR> | t = <MOD> | t = <PLUS> |
+       t = <DOT> | t = <STAR> | t = <NEGATE> | t = <EXCLAMATION> | t = <AND> | t = <OR> | t = <MOD> | t = <PLUS> |
        t = <PLUSPLUS> | t = <MINUS> | t = <MINUSMINUS> | t = <DIVIDE> | t = <BACKSLASH> |
        t = <LESS_THAN> | t = <GREATER_THAN> | t = <GREATER_EQUALS>     | t = <LESS_EQUALS> |
        t = <LOGICAL_EQUALS> | t = <NOT_EQUALS> | t = <LOGICAL_AND> | t = <LOGICAL_OR> | t = <XOR> |
@@ -512,8 +525,11 @@ ActionSubConstruct Action() :
 {
        {
                defineVars = new ArrayList<DefineVar>();
+               code = "";
        }
        <ACTION>
+       (
+               (
                (<DEFINEVAR> (defineVarStr = C_CPP_CODE()) 
                {
                        int eqIdx = defineVarStr.indexOf('=');
@@ -523,13 +539,13 @@ ActionSubConstruct Action() :
                        expr = defineVarStr.substring(eqIdx + 2);
                        DefineVar defineVar = new DefineVar(type, name, expr);
                        defineVars.add(defineVar);
-               }
-               )*
-               <CODE> (code = C_CPP_CODE())
-               {
-                       ActionSubConstruct res = new ActionSubConstruct(defineVars, code);
-                       return res;
-               }
+               })*  (<CODE> (code = C_CPP_CODE()))? ) 
+       )
+       
+       {
+               ActionSubConstruct res = new ActionSubConstruct(defineVars, code);
+               return res;
+       }
 }
 
 PotentialCPDefineConstruct Potential_commit_point_define() :