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;
187 // NON-TERMINALS /////////////////////////////////////////////////////////
191 ------------------------------------------------------------------------*/
192 nonterminal ParseNode spacedefs;
193 nonterminal ParseNode space;
194 nonterminal ParseNode mult;
195 nonterminal ParseNode optstatic;
196 nonterminal ParseNode optpartition;
197 nonterminal ParseNode setlist;
198 nonterminal ParseNode type;
199 nonterminal ParseNode optrange;
203 precedence right EQ, NE;
204 precedence right LT, LE, GE, GT;
205 precedence left ADD, SUB;
206 precedence left MULT, DIV;
210 // PRODUCTION RULES /////////////////////////////////////////////////////
212 start with spacedefs;
215 spacedefs:spacedefs space:space
217 debugMessage(PRODSTRING);
218 spacedefs.addChild(space);
223 debugMessage(PRODSTRING);
224 ParseNode spacedefs = new ParseNode("space", parser.curLine(1));
225 spacedefs.addChild(space);
231 SET ID:setname OPENPAREN type:settype CLOSEPAREN SEMICOLON
233 debugMessage(PRODSTRING);
234 ParseNode set = new ParseNode("setdefinition", parser.curLine(6));
235 set.addChild("name", parser.curLine(5)).addChild(setname);
236 set.addChild(settype);
239 | SET ID:setname OPENPAREN type:settype CLOSEPAREN COLON optpartition:partition setlist:setlist SEMICOLON
241 debugMessage(PRODSTRING);
242 ParseNode set = new ParseNode("setdefinition", parser.curLine(8));
243 set.addChild("name", parser.curLine(7)).addChild(setname);
244 set.addChild(settype);
245 if (partition != null) set.addChild(partition);
246 if (setlist != null) set.addChild(setlist);
249 | ID:name optstatic:optstatic COLON type:domain ARROW type:range optrange:optrange SEMICOLON
251 debugMessage(PRODSTRING);
252 ParseNode relation = new ParseNode("relationdefinition", parser.curLine(8));
253 if (optstatic != null) relation.addChild(optstatic);
254 relation.addChild("name", parser.curLine(7)).addChild(name);
255 relation.addChild("domain").addChild(domain);
256 relation.addChild("range").addChild(range);
257 if (optrange != null) {
258 relation.getChild("domain").addChild(optrange.getChild("domainmult"));
259 relation.getChild("range").addChild(optrange.getChild("rangemult"));
266 OPENPAREN mult:domainmult ARROW mult:rangemult CLOSEPAREN
268 debugMessage(PRODSTRING);
269 ParseNode optrange = new ParseNode("optrange", parser.curLine(5));
270 optrange.addChild("domainmult").addChild(domainmult);
271 optrange.addChild("rangemult").addChild(rangemult);
283 debugMessage(PRODSTRING);
284 ParseNode mult = new ParseNode("mult", parser.curLine(1));
290 debugMessage(PRODSTRING);
291 ParseNode mult = new ParseNode("mult", parser.curLine(1));
292 mult.addChild("many");
300 debugMessage(PRODSTRING);
301 RESULT = new ParseNode("static", parser.curLine(1));
305 debugMessage(PRODSTRING);
313 debugMessage(PRODSTRING);
314 RESULT = new ParseNode("partition", parser.curLine(1));
318 debugMessage(PRODSTRING);
324 setlist:setlist BAR ID:set
326 debugMessage(PRODSTRING);
327 setlist.addChild(set, parser.curLine(1));
332 debugMessage(PRODSTRING);
333 ParseNode setlist = new ParseNode("setlist");
334 setlist.addChild(set, parser.curLine(1));
339 debugMessage(PRODSTRING);
347 debugMessage(PRODSTRING);
348 ParseNode type = new ParseNode("type", parser.curLine(1));
349 type.addChild("bit");
354 debugMessage(PRODSTRING);
355 ParseNode type = new ParseNode("type", parser.curLine(1));
356 type.addChild("byte");
361 debugMessage(PRODSTRING);
362 ParseNode type = new ParseNode("type", parser.curLine(1));
363 type.addChild("short");
368 debugMessage(PRODSTRING);
369 ParseNode type = new ParseNode("type", parser.curLine(1));
370 type.addChild("int");
375 debugMessage(PRODSTRING);
376 ParseNode type = new ParseNode("type", parser.curLine(1));
377 type.addChild(typename);