Hack grammar to add unary minus.
[repair.git] / Repair / RepairCompiler / MCC / TDL.cup
index db35ad5cc0af5510ec2bceabb34eab2a5f15378c..ee4ba5988cbd1e63976490ff6ee408c027b786c4 100755 (executable)
@@ -63,7 +63,9 @@ parser code {:
 
                CUP$TDLParser$actions.errors = true;
                Symbol symbol = (Symbol) current;
-               report_error(filename+":"+(symbol.line+1)+": Syntax error at column " + LineCount.getColumn(symbol.left) +": " + current.value, current);
+               report_error(filename+":"+(symbol.line+1)+": Syntax error at column " 
+                + (LineCount.getColumn(symbol.left)+1) +": " + current.value, current);
+               System.out.println();
                System.exit(0);
        }
 
@@ -160,6 +162,7 @@ parser code {:
     terminal LABEL;
     terminal INT;
     terminal SUBTYPE;
+    terminal SUBCLASS;
     terminal OF;
 
     terminal SEMICOLON;
@@ -191,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;
@@ -247,14 +251,24 @@ 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 ::= 
-          
+               /* subtype */
        SUBTYPE OF ID:type
        {:
        debugMessage(PRODSTRING);
@@ -262,6 +276,16 @@ optsubtype ::=
        subtype.addChild(type);
        RESULT = subtype;
        :}
+
+       | /* subclass */
+
+       SUBCLASS OF ID:type
+       {:
+       debugMessage(PRODSTRING);
+       ParseNode subtype = new ParseNode("subclass", parser.curLine(3));
+       subtype.addChild(type);
+       RESULT = subtype;
+       :}
        
        | /* nothing */
        {:
@@ -452,7 +476,7 @@ expr ::=
        RESULT = expr;
        :}     
     
-       | LITERAL OPENPAREN literal:literal CLOSEPAREN       
+       | literal:literal
        {:
        debugMessage(PRODSTRING);
        ParseNode expr = new ParseNode("expr", parser.curLine(4));
@@ -519,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
        {:
@@ -532,7 +562,7 @@ literal ::=
        RESULT = (new ParseNode("literal", parser.curLine(1))).addChild("char").addChild(chr).getRoot();
        :}
         
-       | ID:literal
+       | LITERAL OPENPAREN ID:literal CLOSEPAREN
        {:
        debugMessage(PRODSTRING);
        RESULT = (new ParseNode("literal", parser.curLine(1))).addChild("token").addChild(literal).getRoot();
@@ -581,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