001 // Generated from /home/csz-naf/examples/PicoJava/AST/PicoJavaParser.all 002 package AST; 003 import AST.*; 004 import java.util.ArrayList; 005 import beaver.*; 006 007 /** 008 * This class is a LALR parser generated by 009 * <a href="http://beaver.sourceforge.net">Beaver</a> v0.9.4 010 * from the grammar specification "PicoJavaParser.beaver". 011 */ 012 public class PicoJavaParser extends Parser { 013 static public class Terminals { 014 static public final short EOF = 0; 015 static public final short WHILE = 1; 016 static public final short LPAREN = 2; 017 static public final short RPAREN = 3; 018 static public final short LBRACE = 4; 019 static public final short RBRACE = 5; 020 static public final short CLASS = 6; 021 static public final short IDENTIFIER = 7; 022 static public final short SEMICOLON = 8; 023 static public final short ASSIGN = 9; 024 static public final short EXTENDS = 10; 025 static public final short DOT = 11; 026 static public final short BOOLEAN_LITERAL = 12; 027 028 static public final String[] NAMES = { 029 "EOF", 030 "WHILE", 031 "LPAREN", 032 "RPAREN", 033 "LBRACE", 034 "RBRACE", 035 "CLASS", 036 "IDENTIFIER", 037 "SEMICOLON", 038 "ASSIGN", 039 "EXTENDS", 040 "DOT", 041 "BOOLEAN_LITERAL" 042 }; 043 } 044 045 static final ParsingTables PARSING_TABLES = new ParsingTables( 046 "U9ojaijh544Gnd#patLcTvFTx2FxI3QwnXT8BYA4411o4K6y218GGRo85q54GV4o1$NaFsf" + 047 "Y7kRzJlbrPRD4rgFpyLLtLzLqTttL$E0AjucfKsE28Xr6I2bmbMiaPlBLv2lIfddXjrLRfS" + 048 "jK63MRbZspCtBaRINCX1N7B$6dRMiKw8aLsLDATEt4xH6ZZDcX7JaE7GUwJTdsxS2nxzYXo" + 049 "hXjsevZq$7RjcZOdiQ0FSSkjsXnqtOT6txROzjm73lMLSaCLLkpTLjM5HrRKoNBJDDZakl0" + 050 "3R7B66KfaUZSWhGfIOUcTcvBYxBY1VbBybUbpeK$zln9CUWqgZX4Z9DN92#LatuaLcJASyC" + 051 "gqgeeUvvnRYEnCkGRqLx3UOr$vAL3lgfyzS4gtFRlZDWh2MCg9hfJgafILH7fX9pUGImctC" + 052 "bCdIvpNshDCCS35dd4O#QPvI5FUS9pckhj4i$qtojUy94FKlGpT$d2IrxpZKzyvojlTUwxp" + 053 "6Xen#tCP2qRW7iio2vUykJwu$lCBeCtub9$$d#$bheK#XUhzuYHtaHWJlL70zRxR4htYl8g" + 054 "YhVqJrlhZjIjALPp5KCN0cCf6z7z0ws7vx8="); 055 // Generated from /home/csz-naf/examples/PicoJava/AST/PicoJavaParser.all 056 class Events extends Parser.Events { 057 public void syntaxError(Symbol token) { 058 StringBuffer s = new StringBuffer(); 059 s.append(token.getLine(token.getStart()) + ", " + token.getColumn(token.getStart()) + "\n"); 060 s.append(" *** Syntactic error: unexpected token " + Terminals.NAMES[token.getId()]); 061 throw new Error(s.toString()); 062 } 063 public void scannerError(Scanner.Exception e) { 064 StringBuffer s = new StringBuffer(); 065 s.append(e.line + ", " + e.column + "\n"); 066 s.append(" *** Lexical error: " + e.getMessage()); 067 throw new Error(s.toString()); 068 } 069 } 070 { report = new Events(); } // Use error handler in parser 071 072 public PicoJavaParser() { 073 super(PARSING_TABLES); 074 } 075 076 protected Symbol invokeReduceAction(int rule_num, int offset) { 077 switch(rule_num) { 078 case 0: // goal = block.block 079 { 080 final Symbol _symbol_block = _symbols[offset + 1]; 081 final Block block = (Block) _symbol_block.value; 082 ASTNode _node_ = new Program(block); 083 _node_.setStart(Symbol.getLine(_symbol_block.getStart()), (short) Symbol.getColumn(_symbol_block.getStart())); 084 _node_.setEnd(Symbol.getLine(_symbol_block.getEnd()), (short) Symbol.getColumn(_symbol_block.getEnd())); 085 return new Symbol(_node_); 086 } 087 case 1: // block = LBRACE.LBRACE block_stmt_list_opt.block_stmt_list_opt RBRACE.RBRACE 088 { 089 final Symbol LBRACE = _symbols[offset + 1]; 090 final Symbol _symbol_block_stmt_list_opt = _symbols[offset + 2]; 091 final List block_stmt_list_opt = (List) _symbol_block_stmt_list_opt.value; 092 final Symbol RBRACE = _symbols[offset + 3]; 093 ASTNode _node_ = new Block(block_stmt_list_opt); 094 _node_.setStart(Symbol.getLine(LBRACE.getStart()), (short) Symbol.getColumn(LBRACE.getStart())); 095 _node_.setEnd(Symbol.getLine(RBRACE.getEnd()), (short) Symbol.getColumn(RBRACE.getEnd())); 096 return new Symbol(_node_); 097 } 098 case 2: // block_stmt_list_opt = 099 { 100 return new Symbol(new List()); 101 } 102 case 3: // block_stmt_list_opt = block_stmt_list.block_stmt_list 103 { 104 final Symbol _symbol_block_stmt_list = _symbols[offset + 1]; 105 final List block_stmt_list = (List) _symbol_block_stmt_list.value; 106 ASTNode _node_ = block_stmt_list; 107 _node_.setStart(Symbol.getLine(_symbol_block_stmt_list.getStart()), (short) Symbol.getColumn(_symbol_block_stmt_list.getStart())); 108 _node_.setEnd(Symbol.getLine(_symbol_block_stmt_list.getEnd()), (short) Symbol.getColumn(_symbol_block_stmt_list.getEnd())); 109 return new Symbol(_node_); 110 } 111 case 4: // block_stmt_list = block_stmt.block_stmt 112 { 113 final Symbol _symbol_block_stmt = _symbols[offset + 1]; 114 final BlockStmt block_stmt = (BlockStmt) _symbol_block_stmt.value; 115 ASTNode _node_ = new List().add(block_stmt); 116 _node_.setStart(Symbol.getLine(_symbol_block_stmt.getStart()), (short) Symbol.getColumn(_symbol_block_stmt.getStart())); 117 _node_.setEnd(Symbol.getLine(_symbol_block_stmt.getEnd()), (short) Symbol.getColumn(_symbol_block_stmt.getEnd())); 118 return new Symbol(_node_); 119 } 120 case 5: // block_stmt_list = block_stmt_list.block_stmt_list block_stmt.block_stmt 121 { 122 final Symbol _symbol_block_stmt_list = _symbols[offset + 1]; 123 final List block_stmt_list = (List) _symbol_block_stmt_list.value; 124 final Symbol _symbol_block_stmt = _symbols[offset + 2]; 125 final BlockStmt block_stmt = (BlockStmt) _symbol_block_stmt.value; 126 ASTNode _node_ = block_stmt_list.add(block_stmt); 127 _node_.setStart(Symbol.getLine(_symbol_block_stmt_list.getStart()), (short) Symbol.getColumn(_symbol_block_stmt_list.getStart())); 128 _node_.setEnd(Symbol.getLine(_symbol_block_stmt.getEnd()), (short) Symbol.getColumn(_symbol_block_stmt.getEnd())); 129 return new Symbol(_node_); 130 } 131 case 11: // class_decl = CLASS.CLASS IDENTIFIER.IDENTIFIER extends_opt.extends_opt block.block 132 { 133 final Symbol CLASS = _symbols[offset + 1]; 134 final Symbol IDENTIFIER = _symbols[offset + 2]; 135 final Symbol _symbol_extends_opt = _symbols[offset + 3]; 136 final Opt extends_opt = (Opt) _symbol_extends_opt.value; 137 final Symbol _symbol_block = _symbols[offset + 4]; 138 final Block block = (Block) _symbol_block.value; 139 ASTNode _node_ = new ClassDecl(((String)IDENTIFIER.value), extends_opt, block); 140 _node_.setStart(Symbol.getLine(CLASS.getStart()), (short) Symbol.getColumn(CLASS.getStart())); 141 _node_.setEnd(Symbol.getLine(_symbol_block.getEnd()), (short) Symbol.getColumn(_symbol_block.getEnd())); 142 return new Symbol(_node_); 143 } 144 case 12: // extends_opt = 145 { 146 return new Symbol(new Opt()); 147 } 148 case 13: // extends_opt = EXTENDS.EXTENDS use.use 149 { 150 final Symbol EXTENDS = _symbols[offset + 1]; 151 final Symbol _symbol_use = _symbols[offset + 2]; 152 final Use use = (Use) _symbol_use.value; 153 ASTNode _node_ = new Opt(use); 154 _node_.setStart(Symbol.getLine(EXTENDS.getStart()), (short) Symbol.getColumn(EXTENDS.getStart())); 155 _node_.setEnd(Symbol.getLine(_symbol_use.getEnd()), (short) Symbol.getColumn(_symbol_use.getEnd())); 156 return new Symbol(_node_); 157 } 158 case 14: // var_decl = name.name IDENTIFIER.IDENTIFIER SEMICOLON.SEMICOLON 159 { 160 final Symbol _symbol_name = _symbols[offset + 1]; 161 final Access name = (Access) _symbol_name.value; 162 final Symbol IDENTIFIER = _symbols[offset + 2]; 163 final Symbol SEMICOLON = _symbols[offset + 3]; 164 ASTNode _node_ = new VarDecl(((String)IDENTIFIER.value), name); 165 _node_.setStart(Symbol.getLine(_symbol_name.getStart()), (short) Symbol.getColumn(_symbol_name.getStart())); 166 _node_.setEnd(Symbol.getLine(SEMICOLON.getEnd()), (short) Symbol.getColumn(SEMICOLON.getEnd())); 167 return new Symbol(_node_); 168 } 169 case 15: // assign_stmt = name.name ASSIGN.ASSIGN exp.exp SEMICOLON.SEMICOLON 170 { 171 final Symbol _symbol_name = _symbols[offset + 1]; 172 final Access name = (Access) _symbol_name.value; 173 final Symbol ASSIGN = _symbols[offset + 2]; 174 final Symbol _symbol_exp = _symbols[offset + 3]; 175 final Exp exp = (Exp) _symbol_exp.value; 176 final Symbol SEMICOLON = _symbols[offset + 4]; 177 ASTNode _node_ = new AssignStmt(name, exp); 178 _node_.setStart(Symbol.getLine(_symbol_name.getStart()), (short) Symbol.getColumn(_symbol_name.getStart())); 179 _node_.setEnd(Symbol.getLine(SEMICOLON.getEnd()), (short) Symbol.getColumn(SEMICOLON.getEnd())); 180 return new Symbol(_node_); 181 } 182 case 16: // while_stmt = WHILE.WHILE LPAREN.LPAREN exp.exp RPAREN.RPAREN stmt.stmt 183 { 184 final Symbol WHILE = _symbols[offset + 1]; 185 final Symbol LPAREN = _symbols[offset + 2]; 186 final Symbol _symbol_exp = _symbols[offset + 3]; 187 final Exp exp = (Exp) _symbol_exp.value; 188 final Symbol RPAREN = _symbols[offset + 4]; 189 final Symbol _symbol_stmt = _symbols[offset + 5]; 190 final Stmt stmt = (Stmt) _symbol_stmt.value; 191 ASTNode _node_ = new WhileStmt(exp, stmt); 192 _node_.setStart(Symbol.getLine(WHILE.getStart()), (short) Symbol.getColumn(WHILE.getStart())); 193 _node_.setEnd(Symbol.getLine(_symbol_stmt.getEnd()), (short) Symbol.getColumn(_symbol_stmt.getEnd())); 194 return new Symbol(_node_); 195 } 196 case 19: // use = IDENTIFIER.IDENTIFIER 197 { 198 final Symbol IDENTIFIER = _symbols[offset + 1]; 199 ASTNode _node_ = new Use(((String)IDENTIFIER.value)); 200 _node_.setStart(Symbol.getLine(IDENTIFIER.getStart()), (short) Symbol.getColumn(IDENTIFIER.getStart())); 201 _node_.setEnd(Symbol.getLine(IDENTIFIER.getEnd()), (short) Symbol.getColumn(IDENTIFIER.getEnd())); 202 return new Symbol(_node_); 203 } 204 case 20: // name = IDENTIFIER.IDENTIFIER 205 { 206 final Symbol IDENTIFIER = _symbols[offset + 1]; 207 ASTNode _node_ = new Use(((String)IDENTIFIER.value)); 208 _node_.setStart(Symbol.getLine(IDENTIFIER.getStart()), (short) Symbol.getColumn(IDENTIFIER.getStart())); 209 _node_.setEnd(Symbol.getLine(IDENTIFIER.getEnd()), (short) Symbol.getColumn(IDENTIFIER.getEnd())); 210 return new Symbol(_node_); 211 } 212 case 21: // name = name.name DOT.DOT use.use 213 { 214 final Symbol _symbol_name = _symbols[offset + 1]; 215 final Access name = (Access) _symbol_name.value; 216 final Symbol DOT = _symbols[offset + 2]; 217 final Symbol _symbol_use = _symbols[offset + 3]; 218 final Use use = (Use) _symbol_use.value; 219 ASTNode _node_ = new Dot(name, use); 220 _node_.setStart(Symbol.getLine(_symbol_name.getStart()), (short) Symbol.getColumn(_symbol_name.getStart())); 221 _node_.setEnd(Symbol.getLine(_symbol_use.getEnd()), (short) Symbol.getColumn(_symbol_use.getEnd())); 222 return new Symbol(_node_); 223 } 224 case 22: // boolean_literal = BOOLEAN_LITERAL.BOOLEAN_LITERAL 225 { 226 final Symbol BOOLEAN_LITERAL = _symbols[offset + 1]; 227 ASTNode _node_ = new BooleanLiteral(((String)BOOLEAN_LITERAL.value)); 228 _node_.setStart(Symbol.getLine(BOOLEAN_LITERAL.getStart()), (short) Symbol.getColumn(BOOLEAN_LITERAL.getStart())); 229 _node_.setEnd(Symbol.getLine(BOOLEAN_LITERAL.getEnd()), (short) Symbol.getColumn(BOOLEAN_LITERAL.getEnd())); 230 return new Symbol(_node_); 231 } 232 case 6: // block_stmt = class_decl.class_decl 233 case 7: // block_stmt = var_decl.var_decl 234 case 8: // block_stmt = stmt.stmt 235 case 9: // stmt = assign_stmt.assign_stmt 236 case 10: // stmt = while_stmt.while_stmt 237 case 17: // exp = name.name 238 case 18: // exp = boolean_literal.boolean_literal 239 { 240 return _symbols[offset + 1]; 241 } 242 default: 243 throw new IllegalArgumentException("unknown production #" + rule_num); 244 } 245 } 246 }