terminal SUB;
terminal MULT;
terminal DIV;
+ terminal SUM;
terminal NOT;
terminal LT;
terminal FORALL;
terminal IN;
terminal INTEST;
+ terminal THIS;
terminal COMMA;
terminal SIZEOF;
terminal LABEL;
terminal INT;
terminal SUBTYPE;
+ terminal SUBCLASS;
terminal OF;
terminal SEMICOLON;
nonterminal ParseNode field;
nonterminal ParseNode optptr;
nonterminal ParseNode type;
+nonterminal ParseNode primtype;
nonterminal ParseNode optindex;
nonterminal ParseNode expr;
nonterminal ParseNode simple_expr;
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);
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 */
{:
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));
RESULT = expr;
:}
- | LITERAL OPENPAREN literal:literal CLOSEPAREN
+ | literal:literal
{:
debugMessage(PRODSTRING);
ParseNode expr = new ParseNode("expr", parser.curLine(4));
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
{:
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();
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