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;
178 // NON-TERMINALS /////////////////////////////////////////////////////////
182 ------------------------------------------------------------------------*/
183 nonterminal ParseNode spacedefs;
184 nonterminal ParseNode space;
185 nonterminal ParseNode mult;
186 nonterminal ParseNode optstatic;
187 nonterminal ParseNode optpartition;
188 nonterminal ParseNode setlist;
189 nonterminal ParseNode type;
193 precedence right EQ, NE;
194 precedence right LT, LE, GE, GT;
195 precedence left ADD, SUB;
196 precedence left MULT, DIV;
200 // PRODUCTION RULES /////////////////////////////////////////////////////
202 start with spacedefs;
205 spacedefs:spacedefs space:space
207 debugMessage(PRODSTRING);
208 spacedefs.addChild(space);
213 debugMessage(PRODSTRING);
214 ParseNode spacedefs = new ParseNode("space", parser.curLine(1));
215 spacedefs.addChild(space);
221 SET ID:setname OPENPAREN type:settype CLOSEPAREN SEMICOLON
223 debugMessage(PRODSTRING);
224 ParseNode set = new ParseNode("setdefinition", parser.curLine(6));
225 set.addChild("name", parser.curLine(5)).addChild(setname);
226 set.addChild(settype);
229 | SET ID:setname OPENPAREN type:settype CLOSEPAREN COLON optpartition:partition setlist:setlist SEMICOLON
231 debugMessage(PRODSTRING);
232 ParseNode set = new ParseNode("setdefinition", parser.curLine(8));
233 set.addChild("name", parser.curLine(7)).addChild(setname);
234 set.addChild(settype);
235 if (partition != null) set.addChild(partition);
236 if (setlist != null) set.addChild(setlist);
239 | ID:name optstatic:optstatic COLON type:domain ARROW type:range OPENPAREN mult:domainmult ARROW mult:rangemult CLOSEPAREN SEMICOLON
241 debugMessage(PRODSTRING);
242 ParseNode relation = new ParseNode("relationdefinition", parser.curLine(12));
243 if (optstatic != null) relation.addChild(optstatic);
244 relation.addChild("name", parser.curLine(11)).addChild(name);
245 relation.addChild("domain").addChild(domain);
246 relation.addChild("range").addChild(range);
247 relation.getChild("domain").addChild(domainmult);
248 relation.getChild("range").addChild(rangemult);
256 debugMessage(PRODSTRING);
257 ParseNode mult = new ParseNode("mult", parser.curLine(1));
263 debugMessage(PRODSTRING);
264 ParseNode mult = new ParseNode("mult", parser.curLine(1));
265 mult.addChild("many");
273 debugMessage(PRODSTRING);
274 RESULT = new ParseNode("static", parser.curLine(1));
278 debugMessage(PRODSTRING);
286 debugMessage(PRODSTRING);
287 RESULT = new ParseNode("partition", parser.curLine(1));
291 debugMessage(PRODSTRING);
297 setlist:setlist BAR ID:set
299 debugMessage(PRODSTRING);
300 setlist.addChild(set, parser.curLine(1));
305 debugMessage(PRODSTRING);
306 ParseNode setlist = new ParseNode("setlist");
307 setlist.addChild(set, parser.curLine(1));
312 debugMessage(PRODSTRING);
320 debugMessage(PRODSTRING);
321 ParseNode type = new ParseNode("type", parser.curLine(1));
322 type.addChild("bit");
327 debugMessage(PRODSTRING);
328 ParseNode type = new ParseNode("type", parser.curLine(1));
329 type.addChild("byte");
334 debugMessage(PRODSTRING);
335 ParseNode type = new ParseNode("type", parser.curLine(1));
336 type.addChild("short");
341 debugMessage(PRODSTRING);
342 ParseNode type = new ParseNode("type", parser.curLine(1));
343 type.addChild("int");
348 debugMessage(PRODSTRING);
349 ParseNode type = new ParseNode("type", parser.curLine(1));
350 type.addChild(typename);