more changes
[cdsspec-compiler.git] / grammer / spec-compiler.jj
index 67769868dcf93af2a1cd16844c68a0b73a71ee31..e4f723f64f99d828bc615ef9a08e45bca4e3ce48 100644 (file)
        
        a) Global construct
        @Begin
+       @Options:
+               # If LANG is not define, it's C++ by default. C does not support class
+               # and template, so if it's defined as C, we should also have a explicit
+               # entry point.
+               LANG = C;
        @Global_define:
                @DeclareVar:
                @InitVar:
        @Potential_commit_point_label: ...
        @Label: ...
        @End
+
+       e) Entry point construct
+       @Begin
+       @Entry_point
+       @End
+
+       f) Interface define construct
+       @Begin
+       @Interface_define: <Interface_Name>
+       @End
 */
 
 
@@ -90,6 +105,8 @@ import edu.uci.eecs.specCompiler.specExtraction.ConditionalInterface;
 import edu.uci.eecs.specCompiler.specExtraction.ActionSubConstruct;
 import edu.uci.eecs.specCompiler.specExtraction.ActionSubConstruct.DefineVar;
 import edu.uci.eecs.specCompiler.specExtraction.SequentialDefineSubConstruct;
+import edu.uci.eecs.specCompiler.specExtraction.InterfaceDefineConstruct;
+import edu.uci.eecs.specCompiler.specExtraction.EntryPointConstruct;
 
        public class SpecParser {
                public static void main(String[] argvs)
@@ -144,6 +161,8 @@ TOKEN :
        <BEGIN: "@Begin">
 |
        <END: "@End">
+|
+       <OPTIONS: "@Options:">
 |
        <GLOBAL_DEFINE: "@Global_define:">
 |
@@ -160,6 +179,10 @@ TOKEN :
        <INTERFACE: "@Interface:">
 |
        <COMMIT_POINT_SET: "@Commit_point_set:">
+|
+       <ENTRY_POINT: "@Entry_point">
+|
+       <INTERFACE_DEFINE: "@Interface_define:">
 |
        <CONDITION: "@Condition:">
 |
@@ -332,7 +355,9 @@ Construct Parse() :
        LOOKAHEAD(3) res = Interface() |
        LOOKAHEAD(3) res = Potential_commit_point_define() |
        LOOKAHEAD(3) res = Commit_point_define() |
-       LOOKAHEAD(3) res = Commit_point_define_check()
+       LOOKAHEAD(3) res = Commit_point_define_check() |
+       LOOKAHEAD(3) res = Entry_point() |
+       LOOKAHEAD(3) res = Interface_define()
        )
        <EOF>
        {
@@ -345,13 +370,31 @@ GlobalConstruct Global_construct() :
 {
        GlobalConstruct res;
        SequentialDefineSubConstruct code;
+       HashMap<String, String> options;
+       String key, value;
 }
 {
-       { res = null; }
+       {
+               res = null;
+               options = new HashMap<String, String>();
+       }
        <HEAD>
                <BEGIN> 
+                       (<OPTIONS>
+                               ((key = <IDENTIFIER>.image)
+                               <EQUALS>
+                               (value = <IDENTIFIER>.image)
+                               {
+                                       if (options.containsKey(key)) {
+                                               throw new ParseException("Duplicate options!");
+                                       }
+                                       options.put(key, value);
+                               }
+                               <SEMI_COLON>
+                               )*
+                       )?
                        (code = Global_define())
-                       { res = new GlobalConstruct(code); }
+                       { res = new GlobalConstruct(code, options); }
                        (Interface_clusters(res))?
                        (Happens_before(res))?
                <END>
@@ -410,8 +453,8 @@ SequentialDefineSubConstruct Global_define() :
                initVar = "";
                defineFunc = "";
        }
-       <GLOBAL_DEFINE> 
-       (<DECLARE_VAR> (declareVar = C_CPP_CODE()))?
+       <GLOBAL_DEFINE>
+               (<DECLARE_VAR> (declareVar = C_CPP_CODE()))?
        (<INIT_VAR> (initVar = C_CPP_CODE()))?
        (<DEFINE_FUNC> (defineFunc = C_CPP_CODE()))?
        {
@@ -630,3 +673,34 @@ CPDefineCheckConstruct Commit_point_define_check() :
                return res;
        }
 }
+
+EntryPointConstruct Entry_point() :
+{}
+{
+
+       <HEAD> 
+               <BEGIN> 
+                       <ENTRY_POINT>
+               <END>
+       <TAIL>
+       {
+               return new EntryPointConstruct();
+       }
+}
+
+InterfaceDefineConstruct Interface_define() :
+{
+       String name;    
+}
+{
+       <HEAD>
+               <BEGIN>
+                       <INTERFACE_DEFINE> (name = <IDENTIFIER>.image)
+               <END>
+       <TAIL>
+       {
+               return new InterfaceDefineConstruct(name);
+       }
+}
+
+