2 import MCC.IR.ParseNode;
3 import MCC.IR.ParseNodeVector;
8 public static boolean errors;
9 public static boolean debug;
11 // debugMessage: writes debug production message only if debug = true
13 void debugMessage (String production) {
15 System.out.println("Applying production: " + production);
19 String unescape (String str) {
20 StringBuffer sb = new StringBuffer();
22 // Note that we skip the first and last characters (they're "'s)
23 for (i = 1; i < str.length() - 1; i++) {
24 if (str.charAt(i) == '\\') {
26 switch (str.charAt(i)) {
43 System.err.print("Error in string literal: ");
44 System.err.println(str.charAt(i));
45 System.err.println("Aborting...");
49 sb.append(str.charAt(i));
60 public void syntax_error (java_cup.runtime.Symbol current) {
62 CUP$SDLParser$actions.errors = true;
63 Symbol symbol = (Symbol) current;
64 report_error("SDL: Syntax error at line " + (symbol.line + 1)
65 + ", column " + LineCount.getColumn(symbol.left) + ": " + current.value, current);
68 public void report_fatal_error (String message, Object info) {
71 report_error(message, info);
72 CUP$SDLParser$actions.errors = true;
75 public int curPos () {
76 return cur_token.left;
79 public int curLine (int back) {
80 Stack st = new Stack();
83 for (i = 0; i < back; i++) {
87 java_cup.runtime.Symbol s;
88 s = (java_cup.runtime.Symbol) st.peek();
90 for (i = 0; i < back; i++) {
94 return LineCount.getLine(s.left);
99 // TERMINALS /////////////////////////////////////////////////////////////
104 terminal String DECIMAL;
105 terminal String CHAR;
106 terminal String STRING;
112 terminal OPENBRACKET;
113 terminal CLOSEBRACKET;
179 // NON-TERMINALS /////////////////////////////////////////////////////////
183 ------------------------------------------------------------------------*/
184 nonterminal ParseNode spacedefs;
185 nonterminal ParseNode space;
186 nonterminal ParseNode mult;
187 nonterminal ParseNode optstatic;
188 nonterminal ParseNode optpartition;
189 nonterminal ParseNode setlist;
190 nonterminal ParseNode type;
194 precedence right EQ, NE;
195 precedence right LT, LE, GE, GT;
196 precedence left ADD, SUB;
197 precedence left MULT, DIV;
201 // PRODUCTION RULES /////////////////////////////////////////////////////
203 start with spacedefs;
206 spacedefs:spacedefs space:space
208 debugMessage(PRODSTRING);
209 spacedefs.addChild(space);
214 debugMessage(PRODSTRING);
215 ParseNode spacedefs = new ParseNode("space", parser.curLine(1));
216 spacedefs.addChild(space);
222 SET ID:setname OPENPAREN type:settype CLOSEPAREN SEMICOLON
224 debugMessage(PRODSTRING);
225 ParseNode set = new ParseNode("setdefinition", parser.curLine(6));
226 set.addChild("name", parser.curLine(5)).addChild(setname);
227 set.addChild(settype);
230 | SET ID:setname OPENPAREN type:settype CLOSEPAREN COLON optpartition:partition setlist:setlist SEMICOLON
232 debugMessage(PRODSTRING);
233 ParseNode set = new ParseNode("setdefinition", parser.curLine(8));
234 set.addChild("name", parser.curLine(7)).addChild(setname);
235 set.addChild(settype);
236 if (partition != null) set.addChild(partition);
237 if (setlist != null) set.addChild(setlist);
240 | ID:name optstatic:optstatic COLON type:domain ARROW type:range OPENPAREN mult:domainmult ARROW mult:rangemult CLOSEPAREN SEMICOLON
242 debugMessage(PRODSTRING);
243 ParseNode relation = new ParseNode("relationdefinition", parser.curLine(12));
244 if (optstatic != null) relation.addChild(optstatic);
245 relation.addChild("name", parser.curLine(11)).addChild(name);
246 relation.addChild("domain").addChild(domain);
247 relation.addChild("range").addChild(range);
248 relation.getChild("domain").addChild(domainmult);
249 relation.getChild("range").addChild(rangemult);
257 debugMessage(PRODSTRING);
258 ParseNode mult = new ParseNode("mult", parser.curLine(1));
264 debugMessage(PRODSTRING);
265 ParseNode mult = new ParseNode("mult", parser.curLine(1));
266 mult.addChild("many");
274 debugMessage(PRODSTRING);
275 RESULT = new ParseNode("static", parser.curLine(1));
279 debugMessage(PRODSTRING);
287 debugMessage(PRODSTRING);
288 RESULT = new ParseNode("partition", parser.curLine(1));
292 debugMessage(PRODSTRING);
298 setlist:setlist BAR ID:set
300 debugMessage(PRODSTRING);
301 setlist.addChild(set, parser.curLine(1));
306 debugMessage(PRODSTRING);
307 ParseNode setlist = new ParseNode("setlist");
308 setlist.addChild(set, parser.curLine(1));
313 debugMessage(PRODSTRING);
321 debugMessage(PRODSTRING);
322 ParseNode type = new ParseNode("type", parser.curLine(1));
323 type.addChild("bit");
328 debugMessage(PRODSTRING);
329 ParseNode type = new ParseNode("type", parser.curLine(1));
330 type.addChild("byte");
335 debugMessage(PRODSTRING);
336 ParseNode type = new ParseNode("type", parser.curLine(1));
337 type.addChild("short");
342 debugMessage(PRODSTRING);
343 ParseNode type = new ParseNode("type", parser.curLine(1));
344 type.addChild("int");
349 debugMessage(PRODSTRING);
350 ParseNode type = new ParseNode("type", parser.curLine(1));
351 type.addChild(typename);