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;
186 // NON-TERMINALS /////////////////////////////////////////////////////////
190 ------------------------------------------------------------------------*/
191 nonterminal ParseNode spacedefs;
192 nonterminal ParseNode space;
193 nonterminal ParseNode mult;
194 nonterminal ParseNode optstatic;
195 nonterminal ParseNode optpartition;
196 nonterminal ParseNode setlist;
197 nonterminal ParseNode type;
198 nonterminal ParseNode optrange;
202 precedence right EQ, NE;
203 precedence right LT, LE, GE, GT;
204 precedence left ADD, SUB;
205 precedence left MULT, DIV;
209 // PRODUCTION RULES /////////////////////////////////////////////////////
211 start with spacedefs;
214 spacedefs:spacedefs space:space
216 debugMessage(PRODSTRING);
217 spacedefs.addChild(space);
222 debugMessage(PRODSTRING);
223 ParseNode spacedefs = new ParseNode("space", parser.curLine(1));
224 spacedefs.addChild(space);
230 SET ID:setname OPENPAREN type:settype CLOSEPAREN SEMICOLON
232 debugMessage(PRODSTRING);
233 ParseNode set = new ParseNode("setdefinition", parser.curLine(6));
234 set.addChild("name", parser.curLine(5)).addChild(setname);
235 set.addChild(settype);
238 | SET ID:setname OPENPAREN type:settype CLOSEPAREN COLON optpartition:partition setlist:setlist SEMICOLON
240 debugMessage(PRODSTRING);
241 ParseNode set = new ParseNode("setdefinition", parser.curLine(8));
242 set.addChild("name", parser.curLine(7)).addChild(setname);
243 set.addChild(settype);
244 if (partition != null) set.addChild(partition);
245 if (setlist != null) set.addChild(setlist);
248 | ID:name optstatic:optstatic COLON type:domain ARROW type:range optrange:optrange SEMICOLON
250 debugMessage(PRODSTRING);
251 ParseNode relation = new ParseNode("relationdefinition", parser.curLine(8));
252 if (optstatic != null) relation.addChild(optstatic);
253 relation.addChild("name", parser.curLine(7)).addChild(name);
254 relation.addChild("domain").addChild(domain);
255 relation.addChild("range").addChild(range);
256 if (optrange != null) {
257 relation.getChild("domain").addChild(optrange.getChild("domainmult"));
258 relation.getChild("range").addChild(optrange.getChild("rangemult"));
265 OPENPAREN mult:domainmult ARROW mult:rangemult CLOSEPAREN
267 debugMessage(PRODSTRING);
268 ParseNode optrange = new ParseNode("optrange", parser.curLine(5));
269 optrange.addChild("domainmult").addChild(domainmult);
270 optrange.addChild("rangemult").addChild(rangemult);
282 debugMessage(PRODSTRING);
283 ParseNode mult = new ParseNode("mult", parser.curLine(1));
289 debugMessage(PRODSTRING);
290 ParseNode mult = new ParseNode("mult", parser.curLine(1));
291 mult.addChild("many");
299 debugMessage(PRODSTRING);
300 RESULT = new ParseNode("static", parser.curLine(1));
304 debugMessage(PRODSTRING);
312 debugMessage(PRODSTRING);
313 RESULT = new ParseNode("partition", parser.curLine(1));
317 debugMessage(PRODSTRING);
323 setlist:setlist BAR ID:set
325 debugMessage(PRODSTRING);
326 setlist.addChild(set, parser.curLine(1));
331 debugMessage(PRODSTRING);
332 ParseNode setlist = new ParseNode("setlist");
333 setlist.addChild(set, parser.curLine(1));
338 debugMessage(PRODSTRING);
346 debugMessage(PRODSTRING);
347 ParseNode type = new ParseNode("type", parser.curLine(1));
348 type.addChild("bit");
353 debugMessage(PRODSTRING);
354 ParseNode type = new ParseNode("type", parser.curLine(1));
355 type.addChild("byte");
360 debugMessage(PRODSTRING);
361 ParseNode type = new ParseNode("type", parser.curLine(1));
362 type.addChild("short");
367 debugMessage(PRODSTRING);
368 ParseNode type = new ParseNode("type", parser.curLine(1));
369 type.addChild("int");
374 debugMessage(PRODSTRING);
375 ParseNode type = new ParseNode("type", parser.curLine(1));
376 type.addChild(typename);