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 String filename;
62 public void syntax_error (java_cup.runtime.Symbol current) {
64 CUP$SDLParser$actions.errors = true;
65 Symbol symbol = (Symbol) current;
67 report_error(filename+":"+(symbol.line+1)+": Syntax error at column "
68 + (LineCount.getColumn(symbol.left)+1) +": " + current.value, current);
74 public void report_fatal_error (String message, Object info) {
77 report_error(message, info);
78 CUP$SDLParser$actions.errors = true;
81 public int curPos () {
82 return cur_token.left;
85 public int curLine (int back) {
86 Stack st = new Stack();
89 for (i = 0; i < back; i++) {
93 java_cup.runtime.Symbol s;
94 s = (java_cup.runtime.Symbol) st.peek();
96 for (i = 0; i < back; i++) {
100 return LineCount.getLine(s.left);
105 // TERMINALS /////////////////////////////////////////////////////////////
110 terminal String DECIMAL;
111 terminal String CHAR;
112 terminal String STRING;
118 terminal OPENBRACKET;
119 terminal CLOSEBRACKET;
188 // NON-TERMINALS /////////////////////////////////////////////////////////
192 ------------------------------------------------------------------------*/
193 nonterminal ParseNode spacedefs;
194 nonterminal ParseNode space;
195 nonterminal ParseNode mult;
196 nonterminal ParseNode optstatic;
197 nonterminal ParseNode optpartition;
198 nonterminal ParseNode setlist;
199 nonterminal ParseNode type;
200 nonterminal ParseNode optrange;
204 precedence right EQ, NE;
205 precedence right LT, LE, GE, GT;
206 precedence left ADD, SUB;
207 precedence left MULT, DIV;
211 // PRODUCTION RULES /////////////////////////////////////////////////////
213 start with spacedefs;
216 spacedefs:spacedefs space:space
218 debugMessage(PRODSTRING);
219 spacedefs.addChild(space);
224 debugMessage(PRODSTRING);
225 ParseNode spacedefs = new ParseNode("space", parser.curLine(1));
226 spacedefs.addChild(space);
232 SET ID:setname OPENPAREN type:settype CLOSEPAREN SEMICOLON
234 debugMessage(PRODSTRING);
235 ParseNode set = new ParseNode("setdefinition", parser.curLine(6));
236 set.addChild("name", parser.curLine(5)).addChild(setname);
237 set.addChild(settype);
240 | SET ID:setname OPENPAREN type:settype CLOSEPAREN COLON optpartition:partition setlist:setlist SEMICOLON
242 debugMessage(PRODSTRING);
243 ParseNode set = new ParseNode("setdefinition", parser.curLine(8));
244 set.addChild("name", parser.curLine(7)).addChild(setname);
245 set.addChild(settype);
246 if (partition != null) set.addChild(partition);
247 if (setlist != null) set.addChild(setlist);
250 | ID:name optstatic:optstatic COLON type:domain ARROW type:range optrange:optrange SEMICOLON
252 debugMessage(PRODSTRING);
253 ParseNode relation = new ParseNode("relationdefinition", parser.curLine(8));
254 if (optstatic != null) relation.addChild(optstatic);
255 relation.addChild("name", parser.curLine(7)).addChild(name);
256 relation.addChild("domain").addChild(domain);
257 relation.addChild("range").addChild(range);
258 if (optrange != null) {
259 relation.getChild("domain").addChild(optrange.getChild("domainmult"));
260 relation.getChild("range").addChild(optrange.getChild("rangemult"));
267 OPENPAREN mult:domainmult ARROW mult:rangemult CLOSEPAREN
269 debugMessage(PRODSTRING);
270 ParseNode optrange = new ParseNode("optrange", parser.curLine(5));
271 optrange.addChild("domainmult").addChild(domainmult);
272 optrange.addChild("rangemult").addChild(rangemult);
284 debugMessage(PRODSTRING);
285 ParseNode mult = new ParseNode("mult", parser.curLine(1));
291 debugMessage(PRODSTRING);
292 ParseNode mult = new ParseNode("mult", parser.curLine(1));
293 mult.addChild("many");
301 debugMessage(PRODSTRING);
302 RESULT = new ParseNode("static", parser.curLine(1));
306 debugMessage(PRODSTRING);
314 debugMessage(PRODSTRING);
315 RESULT = new ParseNode("partition", parser.curLine(1));
319 debugMessage(PRODSTRING);
325 setlist:setlist BAR ID:set
327 debugMessage(PRODSTRING);
328 setlist.addChild(set, parser.curLine(1));
333 debugMessage(PRODSTRING);
334 ParseNode setlist = new ParseNode("setlist");
335 setlist.addChild(set, parser.curLine(1));
340 debugMessage(PRODSTRING);
348 debugMessage(PRODSTRING);
349 ParseNode type = new ParseNode("type", parser.curLine(1));
350 type.addChild("bit");
355 debugMessage(PRODSTRING);
356 ParseNode type = new ParseNode("type", parser.curLine(1));
357 type.addChild("byte");
362 debugMessage(PRODSTRING);
363 ParseNode type = new ParseNode("type", parser.curLine(1));
364 type.addChild("short");
369 debugMessage(PRODSTRING);
370 ParseNode type = new ParseNode("type", parser.curLine(1));
371 type.addChild("int");
376 debugMessage(PRODSTRING);
377 ParseNode type = new ParseNode("type", parser.curLine(1));
378 type.addChild(typename);