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;
66 report_error("TDL: Syntax error at line " + (symbol.line + 1)
67 + ", column " + LineCount.getColumn(symbol.left) + ": " + current.value, current);
71 public void report_fatal_error (String message, Object info) {
74 report_error(message, info);
75 CUP$SDLParser$actions.errors = true;
78 public int curPos () {
79 return cur_token.left;
82 public int curLine (int back) {
83 Stack st = new Stack();
86 for (i = 0; i < back; i++) {
90 java_cup.runtime.Symbol s;
91 s = (java_cup.runtime.Symbol) st.peek();
93 for (i = 0; i < back; i++) {
97 return LineCount.getLine(s.left);
102 // TERMINALS /////////////////////////////////////////////////////////////
107 terminal String DECIMAL;
108 terminal String CHAR;
109 terminal String STRING;
115 terminal OPENBRACKET;
116 terminal CLOSEBRACKET;
182 // NON-TERMINALS /////////////////////////////////////////////////////////
186 ------------------------------------------------------------------------*/
187 nonterminal ParseNode spacedefs;
188 nonterminal ParseNode space;
189 nonterminal ParseNode mult;
190 nonterminal ParseNode optstatic;
191 nonterminal ParseNode optpartition;
192 nonterminal ParseNode setlist;
193 nonterminal ParseNode type;
194 nonterminal ParseNode optrange;
198 precedence right EQ, NE;
199 precedence right LT, LE, GE, GT;
200 precedence left ADD, SUB;
201 precedence left MULT, DIV;
205 // PRODUCTION RULES /////////////////////////////////////////////////////
207 start with spacedefs;
210 spacedefs:spacedefs space:space
212 debugMessage(PRODSTRING);
213 spacedefs.addChild(space);
218 debugMessage(PRODSTRING);
219 ParseNode spacedefs = new ParseNode("space", parser.curLine(1));
220 spacedefs.addChild(space);
226 SET ID:setname OPENPAREN type:settype CLOSEPAREN SEMICOLON
228 debugMessage(PRODSTRING);
229 ParseNode set = new ParseNode("setdefinition", parser.curLine(6));
230 set.addChild("name", parser.curLine(5)).addChild(setname);
231 set.addChild(settype);
234 | SET ID:setname OPENPAREN type:settype CLOSEPAREN COLON optpartition:partition setlist:setlist SEMICOLON
236 debugMessage(PRODSTRING);
237 ParseNode set = new ParseNode("setdefinition", parser.curLine(8));
238 set.addChild("name", parser.curLine(7)).addChild(setname);
239 set.addChild(settype);
240 if (partition != null) set.addChild(partition);
241 if (setlist != null) set.addChild(setlist);
244 | ID:name optstatic:optstatic COLON type:domain ARROW type:range optrange:optrange SEMICOLON
246 debugMessage(PRODSTRING);
247 ParseNode relation = new ParseNode("relationdefinition", parser.curLine(8));
248 if (optstatic != null) relation.addChild(optstatic);
249 relation.addChild("name", parser.curLine(7)).addChild(name);
250 relation.addChild("domain").addChild(domain);
251 relation.addChild("range").addChild(range);
252 if (optrange != null) {
253 relation.getChild("domain").addChild(optrange.getChild("domainmult"));
254 relation.getChild("range").addChild(optrange.getChild("rangemult"));
261 OPENPAREN mult:domainmult ARROW mult:rangemult CLOSEPAREN
263 debugMessage(PRODSTRING);
264 ParseNode optrange = new ParseNode("optrange", parser.curLine(5));
265 optrange.addChild("domainmult").addChild(domainmult);
266 optrange.addChild("rangemult").addChild(rangemult);
278 debugMessage(PRODSTRING);
279 ParseNode mult = new ParseNode("mult", parser.curLine(1));
285 debugMessage(PRODSTRING);
286 ParseNode mult = new ParseNode("mult", parser.curLine(1));
287 mult.addChild("many");
295 debugMessage(PRODSTRING);
296 RESULT = new ParseNode("static", parser.curLine(1));
300 debugMessage(PRODSTRING);
308 debugMessage(PRODSTRING);
309 RESULT = new ParseNode("partition", parser.curLine(1));
313 debugMessage(PRODSTRING);
319 setlist:setlist BAR ID:set
321 debugMessage(PRODSTRING);
322 setlist.addChild(set, parser.curLine(1));
327 debugMessage(PRODSTRING);
328 ParseNode setlist = new ParseNode("setlist");
329 setlist.addChild(set, parser.curLine(1));
334 debugMessage(PRODSTRING);
342 debugMessage(PRODSTRING);
343 ParseNode type = new ParseNode("type", parser.curLine(1));
344 type.addChild("bit");
349 debugMessage(PRODSTRING);
350 ParseNode type = new ParseNode("type", parser.curLine(1));
351 type.addChild("byte");
356 debugMessage(PRODSTRING);
357 ParseNode type = new ParseNode("type", parser.curLine(1));
358 type.addChild("short");
363 debugMessage(PRODSTRING);
364 ParseNode type = new ParseNode("type", parser.curLine(1));
365 type.addChild("int");
370 debugMessage(PRODSTRING);
371 ParseNode type = new ParseNode("type", parser.curLine(1));
372 type.addChild(typename);