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;
185 // NON-TERMINALS /////////////////////////////////////////////////////////
189 ------------------------------------------------------------------------*/
190 nonterminal ParseNode spacedefs;
191 nonterminal ParseNode space;
192 nonterminal ParseNode mult;
193 nonterminal ParseNode optstatic;
194 nonterminal ParseNode optpartition;
195 nonterminal ParseNode setlist;
196 nonterminal ParseNode type;
197 nonterminal ParseNode optrange;
201 precedence right EQ, NE;
202 precedence right LT, LE, GE, GT;
203 precedence left ADD, SUB;
204 precedence left MULT, DIV;
208 // PRODUCTION RULES /////////////////////////////////////////////////////
210 start with spacedefs;
213 spacedefs:spacedefs space:space
215 debugMessage(PRODSTRING);
216 spacedefs.addChild(space);
221 debugMessage(PRODSTRING);
222 ParseNode spacedefs = new ParseNode("space", parser.curLine(1));
223 spacedefs.addChild(space);
229 SET ID:setname OPENPAREN type:settype CLOSEPAREN SEMICOLON
231 debugMessage(PRODSTRING);
232 ParseNode set = new ParseNode("setdefinition", parser.curLine(6));
233 set.addChild("name", parser.curLine(5)).addChild(setname);
234 set.addChild(settype);
237 | SET ID:setname OPENPAREN type:settype CLOSEPAREN COLON optpartition:partition setlist:setlist SEMICOLON
239 debugMessage(PRODSTRING);
240 ParseNode set = new ParseNode("setdefinition", parser.curLine(8));
241 set.addChild("name", parser.curLine(7)).addChild(setname);
242 set.addChild(settype);
243 if (partition != null) set.addChild(partition);
244 if (setlist != null) set.addChild(setlist);
247 | ID:name optstatic:optstatic COLON type:domain ARROW type:range optrange:optrange SEMICOLON
249 debugMessage(PRODSTRING);
250 ParseNode relation = new ParseNode("relationdefinition", parser.curLine(8));
251 if (optstatic != null) relation.addChild(optstatic);
252 relation.addChild("name", parser.curLine(7)).addChild(name);
253 relation.addChild("domain").addChild(domain);
254 relation.addChild("range").addChild(range);
255 if (optrange != null) {
256 relation.getChild("domain").addChild(optrange.getChild("domainmult"));
257 relation.getChild("range").addChild(optrange.getChild("rangemult"));
264 OPENPAREN mult:domainmult ARROW mult:rangemult CLOSEPAREN
266 debugMessage(PRODSTRING);
267 ParseNode optrange = new ParseNode("optrange", parser.curLine(5));
268 optrange.addChild("domainmult").addChild(domainmult);
269 optrange.addChild("rangemult").addChild(rangemult);
281 debugMessage(PRODSTRING);
282 ParseNode mult = new ParseNode("mult", parser.curLine(1));
288 debugMessage(PRODSTRING);
289 ParseNode mult = new ParseNode("mult", parser.curLine(1));
290 mult.addChild("many");
298 debugMessage(PRODSTRING);
299 RESULT = new ParseNode("static", parser.curLine(1));
303 debugMessage(PRODSTRING);
311 debugMessage(PRODSTRING);
312 RESULT = new ParseNode("partition", parser.curLine(1));
316 debugMessage(PRODSTRING);
322 setlist:setlist BAR ID:set
324 debugMessage(PRODSTRING);
325 setlist.addChild(set, parser.curLine(1));
330 debugMessage(PRODSTRING);
331 ParseNode setlist = new ParseNode("setlist");
332 setlist.addChild(set, parser.curLine(1));
337 debugMessage(PRODSTRING);
345 debugMessage(PRODSTRING);
346 ParseNode type = new ParseNode("type", parser.curLine(1));
347 type.addChild("bit");
352 debugMessage(PRODSTRING);
353 ParseNode type = new ParseNode("type", parser.curLine(1));
354 type.addChild("byte");
359 debugMessage(PRODSTRING);
360 ParseNode type = new ParseNode("type", parser.curLine(1));
361 type.addChild("short");
366 debugMessage(PRODSTRING);
367 ParseNode type = new ParseNode("type", parser.curLine(1));
368 type.addChild("int");
373 debugMessage(PRODSTRING);
374 ParseNode type = new ParseNode("type", parser.curLine(1));
375 type.addChild(typename);