more changes
[cdsspec-compiler.git] / grammer / spec-compiler.jj
index 2238268a43ac644a62e490703ea226c6d3060f2f..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:
+               @DefineFunc:
                ...
        @Interface_cluster:
                ...
        @Potential_commit_point_label: ...
        @Label: ...
        @End
+
+       e) Entry point construct
+       @Begin
+       @Entry_point
+       @End
+
+       f) Interface define construct
+       @Begin
+       @Interface_define: <Interface_Name>
+       @End
 */
 
 
@@ -86,6 +104,9 @@ import edu.uci.eecs.specCompiler.specExtraction.CPDefineCheckConstruct;
 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)
@@ -140,8 +161,16 @@ TOKEN :
        <BEGIN: "@Begin">
 |
        <END: "@End">
+|
+       <OPTIONS: "@Options:">
 |
        <GLOBAL_DEFINE: "@Global_define:">
+|
+       <DECLARE_VAR: "@DeclareVar:">
+|
+       <INIT_VAR: "@InitVar:">
+|
+       <DEFINE_FUNC: "@DefineFunc:">
 |
        <INTERFACE_CLUSTER: "@Interface_cluster:">
 |
@@ -150,6 +179,10 @@ TOKEN :
        <INTERFACE: "@Interface:">
 |
        <COMMIT_POINT_SET: "@Commit_point_set:">
+|
+       <ENTRY_POINT: "@Entry_point">
+|
+       <INTERFACE_DEFINE: "@Interface_define:">
 |
        <CONDITION: "@Condition:">
 |
@@ -322,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>
        {
@@ -334,14 +369,32 @@ Construct Parse() :
 GlobalConstruct Global_construct() :
 {
        GlobalConstruct res;
-       String code;
+       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>
@@ -390,14 +443,24 @@ String C_CPP_CODE() :
        }
 }
 
-String Global_define() :
+SequentialDefineSubConstruct Global_define() :
 {
-       String code;    
+       String declareVar, initVar, defineFunc;
 }
 {
-       <GLOBAL_DEFINE> (code = C_CPP_CODE())
        {
-               return code;
+               declareVar = "";
+               initVar = "";
+               defineFunc = "";
+       }
+       <GLOBAL_DEFINE>
+               (<DECLARE_VAR> (declareVar = C_CPP_CODE()))?
+       (<INIT_VAR> (initVar = C_CPP_CODE()))?
+       (<DEFINE_FUNC> (defineFunc = C_CPP_CODE()))?
+       {
+               SequentialDefineSubConstruct res = new SequentialDefineSubConstruct(declareVar, initVar, defineFunc);
+               //System.out.println(res);
+               return res;
        }
 }
 
@@ -610,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);
+       }
+}
+
+