fixed bugs
[cdsspec-compiler.git] / grammer / spec_compiler.jj
index 22fada84bf025aaee801daa7da9d01569a3f9729..93a5d8b07f7985553c9439a2601a73d3a1770ab2 100644 (file)
@@ -16,6 +16,7 @@
                # entry point.
                LANG = C;
        @Global_define:
+               @DeclareStruct:
                @DeclareVar:
                @InitVar:
                @DefineFunc:
@@ -124,7 +125,7 @@ import edu.uci.eecs.specCompiler.specExtraction.VariableDeclaration;
                                File f = new File("./grammer/spec.txt");
                                FileInputStream fis = new FileInputStream(f);
                                SpecParser parser = new SpecParser(fis);
-                               
+                               /*
                                ArrayList<String> content = new ArrayList<String>();
                                ArrayList<Construct> constructs = new ArrayList<Construct>();
                                ArrayList<String> headers = new ArrayList<String>();
@@ -136,8 +137,9 @@ import edu.uci.eecs.specCompiler.specExtraction.VariableDeclaration;
                                for (int i = 0; i < constructs.size(); i++) {
                                        System.out.println(constructs.get(i));
                                }
+                               */
                                
-                               //parser.Test();
+                               parser.Test();
                                System.out.println("Parsing finished!");
                        } catch (FileNotFoundException e) {
                                e.printStackTrace();
@@ -241,6 +243,8 @@ SKIP : {
        <OPTIONS: "@Options:">
 |
        <GLOBAL_DEFINE: "@Global_define:">
+|
+       <DECLARE_STRUCT: "@DeclareStruct:">
 |
        <DECLARE_VAR: "@DeclareVar:">
 |
@@ -301,6 +305,8 @@ SKIP : {
        <STRUCT: "struct">
 |
        <CLASS: "class">
+|
+       <UNSIGNED: "unsigned">
 |
        <TEMPLATE: "template">
 |
@@ -459,7 +465,7 @@ String Type() :
        ("const"
        { type = "const"; }
        )?
-       (((str = <STRUCT>.image | str = <CLASS>.image) { type = type + " " + str; })? 
+       (((str = <STRUCT>.image | str = <CLASS>.image | str = <UNSIGNED>.image) { type = type + " " + str; })? 
        (
        name = ParseQualifiedName() {
                if (!type.equals(""))
@@ -508,6 +514,8 @@ void Test() :
        {
                System.out.println(func);
        }
+
+       
 }
 
 String ParameterizedName() :
@@ -629,9 +637,12 @@ ArrayList<String> C_CPP_CODE(ArrayList<String> headers) :
        (
        LOOKAHEAD(2)
        (
-       t = <CONST> | t = <STRUCT> | t = <CLASS> |
+       t = <CONST> | t = <STRUCT> | t = <CLASS> | t = <UNSIGNED> |
        (t = <TEMPLATE> { inTemplate = true;  })|
-       (header = <INCLUDE>.image {
+       (t = <INCLUDE>
+       {
+               header = t.image;
+               newLine = true;
                if (headers != null) {
                        headers.add(header.substring(header.lastIndexOf(' ') + 1));
                }
@@ -665,6 +676,9 @@ ArrayList<String> C_CPP_CODE(ArrayList<String> headers) :
        )+
 
        {
+               if (content.size() == 0) {
+                       content.add(text);
+               }
                return content;
        }
 }
@@ -747,26 +761,30 @@ GlobalConstruct Global_construct() :
 
 SequentialDefineSubConstruct Global_define() :
 {
-       ArrayList<String> initVar, defineFunc, code;
+       ArrayList<String> initVar, defineFunc, code, declareStruct;
        ArrayList<ArrayList<String>> defineFuncs;
        ArrayList<VariableDeclaration> declareVars;
+       ArrayList<ArrayList<String>> declareStructs;
        VariableDeclaration declareVar;
 
 }
 {
        {
-               declareVars = null;
+               declareVars = new ArrayList<VariableDeclaration>();
                initVar = null;
                defineFuncs = new ArrayList<ArrayList<String>>();
+               declareStructs = new ArrayList<ArrayList<String>>();
        }
        <GLOBAL_DEFINE>
+       (<DECLARE_STRUCT> (declareStruct = C_CPP_CODE(null) {
+               declareStructs.add(declareStruct); }))*
                (<DECLARE_VAR> ((declareVar = TypeParam() ";" {
                        declareVars.add(declareVar); } )*))?
        (<INIT_VAR> (code = C_CPP_CODE(null) { initVar = code; } ))?
        (<DEFINE_FUNC> (defineFunc = C_CPP_CODE(null) { defineFuncs.add(defineFunc); }))*
        {
                SequentialDefineSubConstruct res = new
-                       SequentialDefineSubConstruct(declareVars, initVar, defineFuncs);
+                       SequentialDefineSubConstruct(declareStructs, declareVars, initVar, defineFuncs);
                //System.out.println(res);
                return res;
        }
@@ -835,16 +853,14 @@ InterfaceConstruct Interface() :
 {
        {
                res = null;
-               action = null;
+               action = new ArrayList<String>();
                condition = "";
                idCode = "";
                check = "";
                postCheck = "";
                commitPointSet = new ArrayList<String>();
                hbConditions = new HashMap<String, String>();
-
-               action = null;
-               postAction = null;
+               postAction = new ArrayList<String>();
        }
                <BEGIN>
                        <INTERFACE> (interfaceName = <IDENTIFIER>.image)