Hack grammar to add unary minus.
[repair.git] / Repair / RepairCompiler / MCC / TDL.cup
index 0ae3eb5765e778e633011f0dae3d82effa106869..ee4ba5988cbd1e63976490ff6ee408c027b786c4 100755 (executable)
@@ -194,6 +194,7 @@ nonterminal ParseNode               label;
 nonterminal    ParseNode               field;
 nonterminal    ParseNode               optptr;
 nonterminal    ParseNode               type;
+nonterminal    ParseNode               primtype;
 nonterminal    ParseNode               optindex;
 nonterminal    ParseNode               expr;
 nonterminal    ParseNode               simple_expr;
@@ -250,10 +251,20 @@ structure ::=
        {:
        debugMessage(PRODSTRING);
        ParseNode global = new ParseNode("global", parser.curLine(4));
+       global.addChild("ptr");
        global.addChild("type").addChild(type);
        global.addChild("name").addChild(name);
        RESULT = global;
        :}
+
+       | primtype:type ID:name SEMICOLON
+       {:
+       debugMessage(PRODSTRING);
+       ParseNode global = new ParseNode("global", parser.curLine(4));
+       global.addChild(type);
+       global.addChild("name").addChild(name);
+       RESULT = global;
+       :}
        ;
 
 optsubtype ::= 
@@ -532,6 +543,12 @@ literal ::=
        debugMessage(PRODSTRING);
        RESULT = (new ParseNode("literal", parser.curLine(1))).addChild("decimal").addChild(dec).getRoot();
        :}
+
+       | SUB DECIMAL:dec
+       {:
+       debugMessage(PRODSTRING);
+       RESULT = (new ParseNode("literal", parser.curLine(1))).addChild("decimal").addChild("-"+dec).getRoot();
+       :}
         
        | STRING:str
        {:
@@ -594,3 +611,38 @@ type ::=
        RESULT = type;
        :}
        ;
+
+primtype ::= 
+     
+       BIT
+       {:
+       debugMessage(PRODSTRING);
+       ParseNode type = new ParseNode("type", parser.curLine(1));
+       type.addChild("bit");
+       RESULT = type;
+       :}
+     
+       | BYTE
+       {:
+       debugMessage(PRODSTRING);
+       ParseNode type = new ParseNode("type", parser.curLine(1));
+       type.addChild("byte");
+       RESULT = type;
+       :}
+     
+       | SHORT
+       {:
+       debugMessage(PRODSTRING);
+       ParseNode type = new ParseNode("type", parser.curLine(1));
+       type.addChild("short");
+       RESULT = type;
+       :}
+     
+       | INT 
+       {:
+       debugMessage(PRODSTRING);
+       ParseNode type = new ParseNode("type", parser.curLine(1));
+       type.addChild("int");
+       RESULT = type;
+       :}
+;
\ No newline at end of file