1 2 //---------------------------------------------------- 3 // The following code was generated by Java(tm) CUP v0.9d 4 // Sun Jan 07 17:10:11 EST 1996 5 //---------------------------------------------------- 6 7 import java_cup.runtime.*; 8 9 public class parser extends java_cup.runtime.lr_parser { 10 11 /** constructor */ parser()12 public parser() {super();} 13 14 /** production table */ 15 protected static final short _production_table[][] = { 16 {1, 2}, {0, 2}, {1, 1}, {6, 0}, {2, 3}, 17 {3, 3}, {3, 3}, {3, 1}, {4, 3}, {4, 3}, 18 {4, 3}, {4, 1}, {5, 1}, {5, 2}, {5, 3} 19 }; 20 21 /** access to production table */ production_table()22 public short[][] production_table() {return _production_table;} 23 24 /** parse action table */ 25 protected static final short[][] _action_table = { 26 /*0*/{4,2,8,9,10,4,-1,0}, 27 /*1*/{4,2,8,9,10,4,-1,0}, 28 /*2*/{2,-12,3,-12,4,-12,5,-12,6,-12,7,-12,9,-12,-1,0}, 29 /*3*/{2,-13,3,-13,4,-13,5,-13,6,-13,7,-13,9,-13,-1,0}, 30 /*4*/{0,-3,4,-3,8,-3,10,-3,-1,0}, 31 /*5*/{2,-4,3,13,4,11,-1,0}, 32 /*6*/{0,23,4,2,8,9,10,4,-1,0}, 33 /*7*/{2,-8,3,-8,4,-8,5,16,6,17,7,15,9,-8,-1,0}, 34 /*8*/{4,2,8,9,10,4,-1,0}, 35 /*9*/{3,13,4,11,9,12,-1,0}, 36 /*10*/{4,2,8,9,10,4,-1,0}, 37 /*11*/{2,-15,3,-15,4,-15,5,-15,6,-15,7,-15,9,-15,-1,0}, 38 /*12*/{4,2,8,9,10,4,-1,0}, 39 /*13*/{2,-6,3,-6,4,-6,5,16,6,17,7,15,9,-6,-1,0}, 40 /*14*/{4,2,8,9,10,4,-1,0}, 41 /*15*/{4,2,8,9,10,4,-1,0}, 42 /*16*/{4,2,8,9,10,4,-1,0}, 43 /*17*/{2,-10,3,-10,4,-10,5,-10,6,-10,7,-10,9,-10,-1,0}, 44 /*18*/{2,-9,3,-9,4,-9,5,-9,6,-9,7,-9,9,-9,-1,0}, 45 /*19*/{2,-11,3,-11,4,-11,5,-11,6,-11,7,-11,9,-11,-1,0}, 46 /*20*/{2,-7,3,-7,4,-7,5,16,6,17,7,15,9,-7,-1,0}, 47 /*21*/{0,-1,4,-1,8,-1,10,-1,-1,0}, 48 /*22*/{0,-2,-1,0}, 49 /*23*/{2,25,-1,0}, 50 /*24*/{0,-5,4,-5,8,-5,10,-5,-1,0}, 51 /*25*/{2,-14,3,-14,4,-14,5,-14,6,-14,7,-14,9,-14,-1,0}, 52 }; 53 54 /** access to parse action table */ action_table()55 public short[][] action_table() {return _action_table;} 56 57 /** reduce_goto table */ 58 protected static final short[][] _reduce_table = { 59 /*0*/{1,6,2,4,3,5,4,7,5,2,-1,-1}, 60 /*1*/{5,25,-1,-1}, 61 /*2*/{-1,-1}, 62 /*3*/{-1,-1}, 63 /*4*/{-1,-1}, 64 /*5*/{6,23,-1,-1}, 65 /*6*/{2,21,3,5,4,7,5,2,-1,-1}, 66 /*7*/{-1,-1}, 67 /*8*/{3,9,4,7,5,2,-1,-1}, 68 /*9*/{-1,-1}, 69 /*10*/{4,20,5,2,-1,-1}, 70 /*11*/{-1,-1}, 71 /*12*/{4,13,5,2,-1,-1}, 72 /*13*/{-1,-1}, 73 /*14*/{5,19,-1,-1}, 74 /*15*/{5,18,-1,-1}, 75 /*16*/{5,17,-1,-1}, 76 /*17*/{-1,-1}, 77 /*18*/{-1,-1}, 78 /*19*/{-1,-1}, 79 /*20*/{-1,-1}, 80 /*21*/{-1,-1}, 81 /*22*/{-1,-1}, 82 /*23*/{-1,-1}, 83 /*24*/{-1,-1}, 84 /*25*/{-1,-1}, 85 }; 86 87 /** access to reduce_goto table */ reduce_table()88 public short[][] reduce_table() {return _reduce_table;} 89 90 /** instance of action encapsulation class */ 91 protected CUP$actions action_obj; 92 93 /** action encapsulation object initializer */ init_actions()94 protected void init_actions() 95 { 96 action_obj = new CUP$actions(); 97 } 98 99 /** invoke a user supplied parse action */ do_action( int act_num, java_cup.runtime.lr_parser parser, java.util.Stack stack, int top)100 public java_cup.runtime.symbol do_action( 101 int act_num, 102 java_cup.runtime.lr_parser parser, 103 java.util.Stack stack, 104 int top) 105 throws java.lang.Exception 106 { 107 /* call code in generated class */ 108 return action_obj.CUP$do_action(act_num, parser, stack, top); 109 } 110 111 /** start state */ start_state()112 public int start_state() {return 0;} 113 /** start production */ start_production()114 public int start_production() {return 1;} 115 116 /** EOF symbol index */ EOF_sym()117 public int EOF_sym() {return 0;} 118 119 /** error symbol index */ error_sym()120 public int error_sym() {return 1;} 121 122 123 /** user initialization */ user_init()124 public void user_init() throws java.lang.Exception 125 { 126 scanner.init(); 127 } 128 129 /** scan to get the next token */ scan()130 public java_cup.runtime.token scan() 131 throws java.lang.Exception 132 { 133 return scanner.next_token(); 134 } 135 }; 136 137 /** JavaCup generated class to encapsulate user supplied action code.*/ 138 class CUP$actions { 139 140 /** Constructor */ CUP$actions()141 CUP$actions() { } 142 143 /** Method with the actual generated action code. */ CUP$do_action( int CUP$act_num, java_cup.runtime.lr_parser CUP$parser, java.util.Stack CUP$stack, int CUP$top)144 public final java_cup.runtime.symbol CUP$do_action( 145 int CUP$act_num, 146 java_cup.runtime.lr_parser CUP$parser, 147 java.util.Stack CUP$stack, 148 int CUP$top) 149 throws java.lang.Exception 150 { 151 /* object for return from actions */ 152 java_cup.runtime.symbol CUP$result; 153 154 /* select the action based on the action number */ 155 switch (CUP$act_num) 156 { 157 /*. . . . . . . . . . . . . . . . . . . .*/ 158 case 14: // factor ::= LPAREN expr RPAREN 159 { 160 CUP$result = new int_token(/*factor*/5); 161 ((int_token)CUP$result).int_val = (/*e*/(int_token)CUP$stack.elementAt(CUP$top-1)).int_val; 162 } 163 return CUP$result; 164 165 /*. . . . . . . . . . . . . . . . . . . .*/ 166 case 13: // factor ::= MINUS factor 167 { 168 CUP$result = new int_token(/*factor*/5); 169 ((int_token)CUP$result).int_val = -(/*e*/(int_token)CUP$stack.elementAt(CUP$top-0)).int_val; 170 } 171 return CUP$result; 172 173 /*. . . . . . . . . . . . . . . . . . . .*/ 174 case 12: // factor ::= NUMBER 175 { 176 CUP$result = new int_token(/*factor*/5); 177 ((int_token)CUP$result).int_val = (/*n*/(int_token)CUP$stack.elementAt(CUP$top-0)).int_val; 178 } 179 return CUP$result; 180 181 /*. . . . . . . . . . . . . . . . . . . .*/ 182 case 11: // term ::= factor 183 { 184 CUP$result = new int_token(/*term*/4); 185 ((int_token)CUP$result).int_val = (/*e*/(int_token)CUP$stack.elementAt(CUP$top-0)).int_val; 186 } 187 return CUP$result; 188 189 /*. . . . . . . . . . . . . . . . . . . .*/ 190 case 10: // term ::= term MOD factor 191 { 192 CUP$result = new int_token(/*term*/4); 193 ((int_token)CUP$result).int_val = (/*e1*/(int_token)CUP$stack.elementAt(CUP$top-2)).int_val % (/*e2*/(int_token)CUP$stack.elementAt(CUP$top-0)).int_val; 194 } 195 return CUP$result; 196 197 /*. . . . . . . . . . . . . . . . . . . .*/ 198 case 9: // term ::= term DIVIDE factor 199 { 200 CUP$result = new int_token(/*term*/4); 201 ((int_token)CUP$result).int_val = (/*e1*/(int_token)CUP$stack.elementAt(CUP$top-2)).int_val / (/*e2*/(int_token)CUP$stack.elementAt(CUP$top-0)).int_val; 202 } 203 return CUP$result; 204 205 /*. . . . . . . . . . . . . . . . . . . .*/ 206 case 8: // term ::= term TIMES factor 207 { 208 CUP$result = new int_token(/*term*/4); 209 ((int_token)CUP$result).int_val = (/*e1*/(int_token)CUP$stack.elementAt(CUP$top-2)).int_val * (/*e2*/(int_token)CUP$stack.elementAt(CUP$top-0)).int_val; 210 } 211 return CUP$result; 212 213 /*. . . . . . . . . . . . . . . . . . . .*/ 214 case 7: // expr ::= term 215 { 216 CUP$result = new int_token(/*expr*/3); 217 ((int_token)CUP$result).int_val = (/*e1*/(int_token)CUP$stack.elementAt(CUP$top-0)).int_val; 218 } 219 return CUP$result; 220 221 /*. . . . . . . . . . . . . . . . . . . .*/ 222 case 6: // expr ::= expr MINUS term 223 { 224 CUP$result = new int_token(/*expr*/3); 225 ((int_token)CUP$result).int_val = (/*e1*/(int_token)CUP$stack.elementAt(CUP$top-2)).int_val - (/*e2*/(int_token)CUP$stack.elementAt(CUP$top-0)).int_val; 226 } 227 return CUP$result; 228 229 /*. . . . . . . . . . . . . . . . . . . .*/ 230 case 5: // expr ::= expr PLUS term 231 { 232 CUP$result = new int_token(/*expr*/3); 233 ((int_token)CUP$result).int_val = (/*e1*/(int_token)CUP$stack.elementAt(CUP$top-2)).int_val + (/*e2*/(int_token)CUP$stack.elementAt(CUP$top-0)).int_val; 234 } 235 return CUP$result; 236 237 /*. . . . . . . . . . . . . . . . . . . .*/ 238 case 4: // expr_part ::= expr NT$0 SEMI 239 { 240 CUP$result = new symbol(/*expr_part*/2); 241 242 } 243 return CUP$result; 244 245 /*. . . . . . . . . . . . . . . . . . . .*/ 246 case 3: // NT$0 ::= 247 { 248 CUP$result = new java_cup.runtime.token(/*NT$0*/6); 249 System.out.println("= " + (/*e*/(int_token)CUP$stack.elementAt(CUP$top-0)).int_val); 250 } 251 return CUP$result; 252 253 /*. . . . . . . . . . . . . . . . . . . .*/ 254 case 2: // expr_list ::= expr_part 255 { 256 CUP$result = new symbol(/*expr_list*/1); 257 258 } 259 return CUP$result; 260 261 /*. . . . . . . . . . . . . . . . . . . .*/ 262 case 1: // $START ::= expr_list EOF 263 { 264 CUP$result = new java_cup.runtime.token(/*$START*/0); 265 266 } 267 /* ACCEPT */ 268 CUP$parser.done_parsing(); 269 return CUP$result; 270 271 /*. . . . . . . . . . . . . . . . . . . .*/ 272 case 0: // expr_list ::= expr_list expr_part 273 { 274 CUP$result = new symbol(/*expr_list*/1); 275 276 } 277 return CUP$result; 278 279 /* . . . . . .*/ 280 default: 281 throw new Exception( 282 "Invalid action number found in internal parse table"); 283 284 } 285 } 286 }; 287 288