1 23 24 package net.percederberg.grammatica.test; 25 26 import net.percederberg.grammatica.parser.Analyzer; 27 import net.percederberg.grammatica.parser.Node; 28 import net.percederberg.grammatica.parser.ParseException; 29 import net.percederberg.grammatica.parser.Production; 30 import net.percederberg.grammatica.parser.Token; 31 32 38 abstract class ArithmeticAnalyzer extends Analyzer { 39 40 47 protected void enter(Node node) throws ParseException { 48 switch (node.getId()) { 49 case ArithmeticConstants.ADD: 50 enterAdd((Token) node); 51 break; 52 case ArithmeticConstants.SUB: 53 enterSub((Token) node); 54 break; 55 case ArithmeticConstants.MUL: 56 enterMul((Token) node); 57 break; 58 case ArithmeticConstants.DIV: 59 enterDiv((Token) node); 60 break; 61 case ArithmeticConstants.LEFT_PAREN: 62 enterLeftParen((Token) node); 63 break; 64 case ArithmeticConstants.RIGHT_PAREN: 65 enterRightParen((Token) node); 66 break; 67 case ArithmeticConstants.NUMBER: 68 enterNumber((Token) node); 69 break; 70 case ArithmeticConstants.IDENTIFIER: 71 enterIdentifier((Token) node); 72 break; 73 case ArithmeticConstants.EXPRESSION: 74 enterExpression((Production) node); 75 break; 76 case ArithmeticConstants.EXPRESSION_REST: 77 enterExpressionRest((Production) node); 78 break; 79 case ArithmeticConstants.TERM: 80 enterTerm((Production) node); 81 break; 82 case ArithmeticConstants.TERM_REST: 83 enterTermRest((Production) node); 84 break; 85 case ArithmeticConstants.FACTOR: 86 enterFactor((Production) node); 87 break; 88 case ArithmeticConstants.ATOM: 89 enterAtom((Production) node); 90 break; 91 } 92 } 93 94 104 protected Node exit(Node node) throws ParseException { 105 switch (node.getId()) { 106 case ArithmeticConstants.ADD: 107 return exitAdd((Token) node); 108 case ArithmeticConstants.SUB: 109 return exitSub((Token) node); 110 case ArithmeticConstants.MUL: 111 return exitMul((Token) node); 112 case ArithmeticConstants.DIV: 113 return exitDiv((Token) node); 114 case ArithmeticConstants.LEFT_PAREN: 115 return exitLeftParen((Token) node); 116 case ArithmeticConstants.RIGHT_PAREN: 117 return exitRightParen((Token) node); 118 case ArithmeticConstants.NUMBER: 119 return exitNumber((Token) node); 120 case ArithmeticConstants.IDENTIFIER: 121 return exitIdentifier((Token) node); 122 case ArithmeticConstants.EXPRESSION: 123 return exitExpression((Production) node); 124 case ArithmeticConstants.EXPRESSION_REST: 125 return exitExpressionRest((Production) node); 126 case ArithmeticConstants.TERM: 127 return exitTerm((Production) node); 128 case ArithmeticConstants.TERM_REST: 129 return exitTermRest((Production) node); 130 case ArithmeticConstants.FACTOR: 131 return exitFactor((Production) node); 132 case ArithmeticConstants.ATOM: 133 return exitAtom((Production) node); 134 } 135 return node; 136 } 137 138 146 protected void child(Production node, Node child) 147 throws ParseException { 148 149 switch (node.getId()) { 150 case ArithmeticConstants.EXPRESSION: 151 childExpression(node, child); 152 break; 153 case ArithmeticConstants.EXPRESSION_REST: 154 childExpressionRest(node, child); 155 break; 156 case ArithmeticConstants.TERM: 157 childTerm(node, child); 158 break; 159 case ArithmeticConstants.TERM_REST: 160 childTermRest(node, child); 161 break; 162 case ArithmeticConstants.FACTOR: 163 childFactor(node, child); 164 break; 165 case ArithmeticConstants.ATOM: 166 childAtom(node, child); 167 break; 168 } 169 } 170 171 178 protected void enterAdd(Token node) throws ParseException { 179 } 180 181 191 protected Node exitAdd(Token node) throws ParseException { 192 return node; 193 } 194 195 202 protected void enterSub(Token node) throws ParseException { 203 } 204 205 215 protected Node exitSub(Token node) throws ParseException { 216 return node; 217 } 218 219 226 protected void enterMul(Token node) throws ParseException { 227 } 228 229 239 protected Node exitMul(Token node) throws ParseException { 240 return node; 241 } 242 243 250 protected void enterDiv(Token node) throws ParseException { 251 } 252 253 263 protected Node exitDiv(Token node) throws ParseException { 264 return node; 265 } 266 267 274 protected void enterLeftParen(Token node) throws ParseException { 275 } 276 277 287 protected Node exitLeftParen(Token node) throws ParseException { 288 return node; 289 } 290 291 298 protected void enterRightParen(Token node) throws ParseException { 299 } 300 301 311 protected Node exitRightParen(Token node) throws ParseException { 312 return node; 313 } 314 315 322 protected void enterNumber(Token node) throws ParseException { 323 } 324 325 335 protected Node exitNumber(Token node) throws ParseException { 336 return node; 337 } 338 339 346 protected void enterIdentifier(Token node) throws ParseException { 347 } 348 349 359 protected Node exitIdentifier(Token node) throws ParseException { 360 return node; 361 } 362 363 370 protected void enterExpression(Production node) 371 throws ParseException { 372 } 373 374 384 protected Node exitExpression(Production node) 385 throws ParseException { 386 387 return node; 388 } 389 390 398 protected void childExpression(Production node, Node child) 399 throws ParseException { 400 401 node.addChild(child); 402 } 403 404 411 protected void enterExpressionRest(Production node) 412 throws ParseException { 413 } 414 415 425 protected Node exitExpressionRest(Production node) 426 throws ParseException { 427 428 return node; 429 } 430 431 439 protected void childExpressionRest(Production node, Node child) 440 throws ParseException { 441 442 node.addChild(child); 443 } 444 445 452 protected void enterTerm(Production node) throws ParseException { 453 } 454 455 465 protected Node exitTerm(Production node) throws ParseException { 466 return node; 467 } 468 469 477 protected void childTerm(Production node, Node child) 478 throws ParseException { 479 480 node.addChild(child); 481 } 482 483 490 protected void enterTermRest(Production node) 491 throws ParseException { 492 } 493 494 504 protected Node exitTermRest(Production node) throws ParseException { 505 return node; 506 } 507 508 516 protected void childTermRest(Production node, Node child) 517 throws ParseException { 518 519 node.addChild(child); 520 } 521 522 529 protected void enterFactor(Production node) throws ParseException { 530 } 531 532 542 protected Node exitFactor(Production node) throws ParseException { 543 return node; 544 } 545 546 554 protected void childFactor(Production node, Node child) 555 throws ParseException { 556 557 node.addChild(child); 558 } 559 560 567 protected void enterAtom(Production node) throws ParseException { 568 } 569 570 580 protected Node exitAtom(Production node) throws ParseException { 581 return node; 582 } 583 584 592 protected void childAtom(Production node, Node child) 593 throws ParseException { 594 595 node.addChild(child); 596 } 597 } 598 | Popular Tags |