check in changes to allow [this.length] into grammar
[repair.git] / Repair / RepairCompiler / MCC / TDL.cup
index c616b94395dd1c9df0cc43928f80ce0af3fad521..b2e990e9b724c2128e38cc624cf03c7d0ed96388 100755 (executable)
@@ -56,13 +56,17 @@ action code {:
 init with {: :}
 
 parser code {:
+
+       public String filename;
        
        public void syntax_error (java_cup.runtime.Symbol current) {
 
                CUP$TDLParser$actions.errors = true;
                Symbol symbol = (Symbol) current;
-               report_error("TDL: Syntax error at line " + (symbol.line + 1)
-               + ", 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);
        }
 
        public void report_fatal_error (String message, Object info) {
@@ -116,6 +120,7 @@ parser code {:
     terminal SUB; 
     terminal MULT; 
     terminal DIV;
+    terminal SUM;
 
     terminal NOT;
     terminal LT;
@@ -128,6 +133,7 @@ parser code {:
     terminal FORALL;
     terminal IN;
     terminal INTEST;
+    terminal THIS;
 
     terminal COMMA;
     terminal SIZEOF;
@@ -158,6 +164,7 @@ parser code {:
     terminal LABEL;
     terminal INT;
     terminal SUBTYPE;
+    terminal SUBCLASS;
     terminal OF;
 
     terminal SEMICOLON;
@@ -189,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;
@@ -240,19 +248,40 @@ 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 ::= 
-          
+               /* subtype */
        SUBTYPE OF ID:type
        {:
        debugMessage(PRODSTRING);
@@ -260,6 +289,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 */
        {:
@@ -436,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));
@@ -450,7 +500,7 @@ expr ::=
        RESULT = expr;
        :}     
     
-       | LITERAL OPENPAREN literal:literal CLOSEPAREN       
+       | literal:literal
        {:
        debugMessage(PRODSTRING);
        ParseNode expr = new ParseNode("expr", parser.curLine(4));
@@ -517,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
        {:
@@ -530,7 +586,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();
@@ -579,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