check in changes to allow [this.length] into grammar
[repair.git] / Repair / RepairCompiler / MCC / TDL.cup
index 0ae3eb5765e778e633011f0dae3d82effa106869..b2e990e9b724c2128e38cc624cf03c7d0ed96388 100755 (executable)
@@ -120,6 +120,7 @@ parser code {:
     terminal SUB; 
     terminal MULT; 
     terminal DIV;
+    terminal SUM;
 
     terminal NOT;
     terminal LT;
@@ -132,6 +133,7 @@ parser code {:
     terminal FORALL;
     terminal IN;
     terminal INTEST;
+    terminal THIS;
 
     terminal COMMA;
     terminal SIZEOF;
@@ -194,6 +196,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;
@@ -245,15 +248,36 @@ structure ::=
        structure.addChild(lf);
        RESULT = structure;
        :}
+       |
+       STRUCTURE ID:typename optsubtype:subtype OPENBRACE CLOSEBRACE
+       {:
+       debugMessage(PRODSTRING);
+       ParseNode structure = new ParseNode("structure", parser.curLine(6));
+       structure.addChild("name", parser.curLine(5)).addChild(typename);
+       if (subtype != null) {
+        structure.addChild(subtype);
+       }
+       RESULT = structure;
+       :}
 
        | ID:type MULT ID:name SEMICOLON
        {:
        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 ::= 
@@ -451,7 +475,18 @@ location ::=
      
 expr ::= 
 
-       simple_expr:se 
+       THIS DOT ID:field
+       {:
+       debugMessage(PRODSTRING);
+       ParseNode expr = new ParseNode("expr", parser.curLine(1));
+       ParseNode sexpr = new ParseNode("simple_expr", parser.curLine(1));
+       ParseNode loc = new ParseNode("location", parser.curLine(1));
+       loc.addChild("thisfield",parser.curLine(1)).addChild(field);
+       sexpr.addChild(loc);
+       expr.addChild(sexpr);
+       RESULT = expr;
+       :}
+       | simple_expr:se 
        {:
        debugMessage(PRODSTRING);
        ParseNode expr = new ParseNode("expr", parser.curLine(1));
@@ -532,6 +567,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 +635,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