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;
179 // NON-TERMINALS /////////////////////////////////////////////////////////
183 ------------------------------------------------------------------------*/
184 nonterminal ParseNode spacedefs;
185 nonterminal ParseNode space;
186 nonterminal ParseNode mult;
187 nonterminal ParseNode optstatic;
188 nonterminal ParseNode optpartition;
189 nonterminal ParseNode setlist;
190 nonterminal ParseNode type;
191 nonterminal ParseNode optrange;
195 precedence right EQ, NE;
196 precedence right LT, LE, GE, GT;
197 precedence left ADD, SUB;
198 precedence left MULT, DIV;
202 // PRODUCTION RULES /////////////////////////////////////////////////////
204 start with spacedefs;
207 spacedefs:spacedefs space:space
209 debugMessage(PRODSTRING);
210 spacedefs.addChild(space);
215 debugMessage(PRODSTRING);
216 ParseNode spacedefs = new ParseNode("space", parser.curLine(1));
217 spacedefs.addChild(space);
223 SET ID:setname OPENPAREN type:settype CLOSEPAREN SEMICOLON
225 debugMessage(PRODSTRING);
226 ParseNode set = new ParseNode("setdefinition", parser.curLine(6));
227 set.addChild("name", parser.curLine(5)).addChild(setname);
228 set.addChild(settype);
231 | SET ID:setname OPENPAREN type:settype CLOSEPAREN COLON optpartition:partition setlist:setlist SEMICOLON
233 debugMessage(PRODSTRING);
234 ParseNode set = new ParseNode("setdefinition", parser.curLine(8));
235 set.addChild("name", parser.curLine(7)).addChild(setname);
236 set.addChild(settype);
237 if (partition != null) set.addChild(partition);
238 if (setlist != null) set.addChild(setlist);
241 | ID:name optstatic:optstatic COLON type:domain ARROW type:range optrange:optrange SEMICOLON
243 debugMessage(PRODSTRING);
244 ParseNode relation = new ParseNode("relationdefinition", parser.curLine(8));
245 if (optstatic != null) relation.addChild(optstatic);
246 relation.addChild("name", parser.curLine(7)).addChild(name);
247 relation.addChild("domain").addChild(domain);
248 relation.addChild("range").addChild(range);
249 if (optrange != null) {
250 relation.getChild("domain").addChild(optrange.getChild("domainmult"));
251 relation.getChild("range").addChild(optrange.getChild("rangemult"));
258 OPENPAREN mult:domainmult ARROW mult:rangemult CLOSEPAREN
260 debugMessage(PRODSTRING);
261 ParseNode optrange = new ParseNode("optrange", parser.curLine(5));
262 optrange.addChild("domainmult").addChild(domainmult);
263 optrange.addChild("rangemult").addChild(rangemult);
275 debugMessage(PRODSTRING);
276 ParseNode mult = new ParseNode("mult", parser.curLine(1));
282 debugMessage(PRODSTRING);
283 ParseNode mult = new ParseNode("mult", parser.curLine(1));
284 mult.addChild("many");
292 debugMessage(PRODSTRING);
293 RESULT = new ParseNode("static", parser.curLine(1));
297 debugMessage(PRODSTRING);
305 debugMessage(PRODSTRING);
306 RESULT = new ParseNode("partition", parser.curLine(1));
310 debugMessage(PRODSTRING);
316 setlist:setlist BAR ID:set
318 debugMessage(PRODSTRING);
319 setlist.addChild(set, parser.curLine(1));
324 debugMessage(PRODSTRING);
325 ParseNode setlist = new ParseNode("setlist");
326 setlist.addChild(set, parser.curLine(1));
331 debugMessage(PRODSTRING);
339 debugMessage(PRODSTRING);
340 ParseNode type = new ParseNode("type", parser.curLine(1));
341 type.addChild("bit");
346 debugMessage(PRODSTRING);
347 ParseNode type = new ParseNode("type", parser.curLine(1));
348 type.addChild("byte");
353 debugMessage(PRODSTRING);
354 ParseNode type = new ParseNode("type", parser.curLine(1));
355 type.addChild("short");
360 debugMessage(PRODSTRING);
361 ParseNode type = new ParseNode("type", parser.curLine(1));
362 type.addChild("int");
367 debugMessage(PRODSTRING);
368 ParseNode type = new ParseNode("type", parser.curLine(1));
369 type.addChild(typename);