1 23 24 package net.percederberg.grammatica; 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 GrammarAnalyzer extends Analyzer { 39 40 47 protected void enter(Node node) throws ParseException { 48 switch (node.getId()) { 49 case GrammarConstants.HEADER: 50 enterHeader((Token) node); 51 break; 52 case GrammarConstants.TOKENS: 53 enterTokens((Token) node); 54 break; 55 case GrammarConstants.PRODUCTIONS: 56 enterProductions((Token) node); 57 break; 58 case GrammarConstants.IGNORE: 59 enterIgnore((Token) node); 60 break; 61 case GrammarConstants.ERROR: 62 enterError((Token) node); 63 break; 64 case GrammarConstants.UNTERMINATED_DIRECTIVE: 65 enterUnterminatedDirective((Token) node); 66 break; 67 case GrammarConstants.EQUALS: 68 enterEquals((Token) node); 69 break; 70 case GrammarConstants.LEFT_PAREN: 71 enterLeftParen((Token) node); 72 break; 73 case GrammarConstants.RIGHT_PAREN: 74 enterRightParen((Token) node); 75 break; 76 case GrammarConstants.LEFT_BRACE: 77 enterLeftBrace((Token) node); 78 break; 79 case GrammarConstants.RIGHT_BRACE: 80 enterRightBrace((Token) node); 81 break; 82 case GrammarConstants.LEFT_BRACKET: 83 enterLeftBracket((Token) node); 84 break; 85 case GrammarConstants.RIGHT_BRACKET: 86 enterRightBracket((Token) node); 87 break; 88 case GrammarConstants.QUESTION_MARK: 89 enterQuestionMark((Token) node); 90 break; 91 case GrammarConstants.PLUS_SIGN: 92 enterPlusSign((Token) node); 93 break; 94 case GrammarConstants.ASTERISK: 95 enterAsterisk((Token) node); 96 break; 97 case GrammarConstants.VERTICAL_BAR: 98 enterVerticalBar((Token) node); 99 break; 100 case GrammarConstants.SEMICOLON: 101 enterSemicolon((Token) node); 102 break; 103 case GrammarConstants.IDENTIFIER: 104 enterIdentifier((Token) node); 105 break; 106 case GrammarConstants.QUOTED_STRING: 107 enterQuotedString((Token) node); 108 break; 109 case GrammarConstants.REGEXP: 110 enterRegexp((Token) node); 111 break; 112 case GrammarConstants.GRAMMAR: 113 enterGrammar((Production) node); 114 break; 115 case GrammarConstants.HEADER_PART: 116 enterHeaderPart((Production) node); 117 break; 118 case GrammarConstants.HEADER_DECLARATION: 119 enterHeaderDeclaration((Production) node); 120 break; 121 case GrammarConstants.TOKEN_PART: 122 enterTokenPart((Production) node); 123 break; 124 case GrammarConstants.TOKEN_DECLARATION: 125 enterTokenDeclaration((Production) node); 126 break; 127 case GrammarConstants.TOKEN_VALUE: 128 enterTokenValue((Production) node); 129 break; 130 case GrammarConstants.TOKEN_HANDLING: 131 enterTokenHandling((Production) node); 132 break; 133 case GrammarConstants.PRODUCTION_PART: 134 enterProductionPart((Production) node); 135 break; 136 case GrammarConstants.PRODUCTION_DECLARATION: 137 enterProductionDeclaration((Production) node); 138 break; 139 case GrammarConstants.PRODUCTION: 140 enterProduction((Production) node); 141 break; 142 case GrammarConstants.PRODUCTION_ATOM: 143 enterProductionAtom((Production) node); 144 break; 145 } 146 } 147 148 158 protected Node exit(Node node) throws ParseException { 159 switch (node.getId()) { 160 case GrammarConstants.HEADER: 161 return exitHeader((Token) node); 162 case GrammarConstants.TOKENS: 163 return exitTokens((Token) node); 164 case GrammarConstants.PRODUCTIONS: 165 return exitProductions((Token) node); 166 case GrammarConstants.IGNORE: 167 return exitIgnore((Token) node); 168 case GrammarConstants.ERROR: 169 return exitError((Token) node); 170 case GrammarConstants.UNTERMINATED_DIRECTIVE: 171 return exitUnterminatedDirective((Token) node); 172 case GrammarConstants.EQUALS: 173 return exitEquals((Token) node); 174 case GrammarConstants.LEFT_PAREN: 175 return exitLeftParen((Token) node); 176 case GrammarConstants.RIGHT_PAREN: 177 return exitRightParen((Token) node); 178 case GrammarConstants.LEFT_BRACE: 179 return exitLeftBrace((Token) node); 180 case GrammarConstants.RIGHT_BRACE: 181 return exitRightBrace((Token) node); 182 case GrammarConstants.LEFT_BRACKET: 183 return exitLeftBracket((Token) node); 184 case GrammarConstants.RIGHT_BRACKET: 185 return exitRightBracket((Token) node); 186 case GrammarConstants.QUESTION_MARK: 187 return exitQuestionMark((Token) node); 188 case GrammarConstants.PLUS_SIGN: 189 return exitPlusSign((Token) node); 190 case GrammarConstants.ASTERISK: 191 return exitAsterisk((Token) node); 192 case GrammarConstants.VERTICAL_BAR: 193 return exitVerticalBar((Token) node); 194 case GrammarConstants.SEMICOLON: 195 return exitSemicolon((Token) node); 196 case GrammarConstants.IDENTIFIER: 197 return exitIdentifier((Token) node); 198 case GrammarConstants.QUOTED_STRING: 199 return exitQuotedString((Token) node); 200 case GrammarConstants.REGEXP: 201 return exitRegexp((Token) node); 202 case GrammarConstants.GRAMMAR: 203 return exitGrammar((Production) node); 204 case GrammarConstants.HEADER_PART: 205 return exitHeaderPart((Production) node); 206 case GrammarConstants.HEADER_DECLARATION: 207 return exitHeaderDeclaration((Production) node); 208 case GrammarConstants.TOKEN_PART: 209 return exitTokenPart((Production) node); 210 case GrammarConstants.TOKEN_DECLARATION: 211 return exitTokenDeclaration((Production) node); 212 case GrammarConstants.TOKEN_VALUE: 213 return exitTokenValue((Production) node); 214 case GrammarConstants.TOKEN_HANDLING: 215 return exitTokenHandling((Production) node); 216 case GrammarConstants.PRODUCTION_PART: 217 return exitProductionPart((Production) node); 218 case GrammarConstants.PRODUCTION_DECLARATION: 219 return exitProductionDeclaration((Production) node); 220 case GrammarConstants.PRODUCTION: 221 return exitProduction((Production) node); 222 case GrammarConstants.PRODUCTION_ATOM: 223 return exitProductionAtom((Production) node); 224 } 225 return node; 226 } 227 228 236 protected void child(Production node, Node child) 237 throws ParseException { 238 239 switch (node.getId()) { 240 case GrammarConstants.GRAMMAR: 241 childGrammar(node, child); 242 break; 243 case GrammarConstants.HEADER_PART: 244 childHeaderPart(node, child); 245 break; 246 case GrammarConstants.HEADER_DECLARATION: 247 childHeaderDeclaration(node, child); 248 break; 249 case GrammarConstants.TOKEN_PART: 250 childTokenPart(node, child); 251 break; 252 case GrammarConstants.TOKEN_DECLARATION: 253 childTokenDeclaration(node, child); 254 break; 255 case GrammarConstants.TOKEN_VALUE: 256 childTokenValue(node, child); 257 break; 258 case GrammarConstants.TOKEN_HANDLING: 259 childTokenHandling(node, child); 260 break; 261 case GrammarConstants.PRODUCTION_PART: 262 childProductionPart(node, child); 263 break; 264 case GrammarConstants.PRODUCTION_DECLARATION: 265 childProductionDeclaration(node, child); 266 break; 267 case GrammarConstants.PRODUCTION: 268 childProduction(node, child); 269 break; 270 case GrammarConstants.PRODUCTION_ATOM: 271 childProductionAtom(node, child); 272 break; 273 } 274 } 275 276 283 protected void enterHeader(Token node) throws ParseException { 284 } 285 286 296 protected Node exitHeader(Token node) throws ParseException { 297 return node; 298 } 299 300 307 protected void enterTokens(Token node) throws ParseException { 308 } 309 310 320 protected Node exitTokens(Token node) throws ParseException { 321 return node; 322 } 323 324 331 protected void enterProductions(Token node) throws ParseException { 332 } 333 334 344 protected Node exitProductions(Token node) throws ParseException { 345 return node; 346 } 347 348 355 protected void enterIgnore(Token node) throws ParseException { 356 } 357 358 368 protected Node exitIgnore(Token node) throws ParseException { 369 return node; 370 } 371 372 379 protected void enterError(Token node) throws ParseException { 380 } 381 382 392 protected Node exitError(Token node) throws ParseException { 393 return node; 394 } 395 396 403 protected void enterUnterminatedDirective(Token node) 404 throws ParseException { 405 } 406 407 417 protected Node exitUnterminatedDirective(Token node) 418 throws ParseException { 419 420 return node; 421 } 422 423 430 protected void enterEquals(Token node) throws ParseException { 431 } 432 433 443 protected Node exitEquals(Token node) throws ParseException { 444 return node; 445 } 446 447 454 protected void enterLeftParen(Token node) throws ParseException { 455 } 456 457 467 protected Node exitLeftParen(Token node) throws ParseException { 468 return node; 469 } 470 471 478 protected void enterRightParen(Token node) throws ParseException { 479 } 480 481 491 protected Node exitRightParen(Token node) throws ParseException { 492 return node; 493 } 494 495 502 protected void enterLeftBrace(Token node) throws ParseException { 503 } 504 505 515 protected Node exitLeftBrace(Token node) throws ParseException { 516 return node; 517 } 518 519 526 protected void enterRightBrace(Token node) throws ParseException { 527 } 528 529 539 protected Node exitRightBrace(Token node) throws ParseException { 540 return node; 541 } 542 543 550 protected void enterLeftBracket(Token node) throws ParseException { 551 } 552 553 563 protected Node exitLeftBracket(Token node) throws ParseException { 564 return node; 565 } 566 567 574 protected void enterRightBracket(Token node) throws ParseException { 575 } 576 577 587 protected Node exitRightBracket(Token node) throws ParseException { 588 return node; 589 } 590 591 598 protected void enterQuestionMark(Token node) throws ParseException { 599 } 600 601 611 protected Node exitQuestionMark(Token node) throws ParseException { 612 return node; 613 } 614 615 622 protected void enterPlusSign(Token node) throws ParseException { 623 } 624 625 635 protected Node exitPlusSign(Token node) throws ParseException { 636 return node; 637 } 638 639 646 protected void enterAsterisk(Token node) throws ParseException { 647 } 648 649 659 protected Node exitAsterisk(Token node) throws ParseException { 660 return node; 661 } 662 663 670 protected void enterVerticalBar(Token node) throws ParseException { 671 } 672 673 683 protected Node exitVerticalBar(Token node) throws ParseException { 684 return node; 685 } 686 687 694 protected void enterSemicolon(Token node) throws ParseException { 695 } 696 697 707 protected Node exitSemicolon(Token node) throws ParseException { 708 return node; 709 } 710 711 718 protected void enterIdentifier(Token node) throws ParseException { 719 } 720 721 731 protected Node exitIdentifier(Token node) throws ParseException { 732 return node; 733 } 734 735 742 protected void enterQuotedString(Token node) throws ParseException { 743 } 744 745 755 protected Node exitQuotedString(Token node) throws ParseException { 756 return node; 757 } 758 759 766 protected void enterRegexp(Token node) throws ParseException { 767 } 768 769 779 protected Node exitRegexp(Token node) throws ParseException { 780 return node; 781 } 782 783 790 protected void enterGrammar(Production node) throws ParseException { 791 } 792 793 803 protected Node exitGrammar(Production node) throws ParseException { 804 return node; 805 } 806 807 815 protected void childGrammar(Production node, Node child) 816 throws ParseException { 817 818 node.addChild(child); 819 } 820 821 828 protected void enterHeaderPart(Production node) 829 throws ParseException { 830 } 831 832 842 protected Node exitHeaderPart(Production node) 843 throws ParseException { 844 845 return node; 846 } 847 848 856 protected void childHeaderPart(Production node, Node child) 857 throws ParseException { 858 859 node.addChild(child); 860 } 861 862 869 protected void enterHeaderDeclaration(Production node) 870 throws ParseException { 871 } 872 873 883 protected Node exitHeaderDeclaration(Production node) 884 throws ParseException { 885 886 return node; 887 } 888 889 897 protected void childHeaderDeclaration(Production node, Node child) 898 throws ParseException { 899 900 node.addChild(child); 901 } 902 903 910 protected void enterTokenPart(Production node) 911 throws ParseException { 912 } 913 914 924 protected Node exitTokenPart(Production node) 925 throws ParseException { 926 927 return node; 928 } 929 930 938 protected void childTokenPart(Production node, Node child) 939 throws ParseException { 940 941 node.addChild(child); 942 } 943 944 951 protected void enterTokenDeclaration(Production node) 952 throws ParseException { 953 } 954 955 965 protected Node exitTokenDeclaration(Production node) 966 throws ParseException { 967 968 return node; 969 } 970 971 979 protected void childTokenDeclaration(Production node, Node child) 980 throws ParseException { 981 982 node.addChild(child); 983 } 984 985 992 protected void enterTokenValue(Production node) 993 throws ParseException { 994 } 995 996 1006 protected Node exitTokenValue(Production node) 1007 throws ParseException { 1008 1009 return node; 1010 } 1011 1012 1020 protected void childTokenValue(Production node, Node child) 1021 throws ParseException { 1022 1023 node.addChild(child); 1024 } 1025 1026 1033 protected void enterTokenHandling(Production node) 1034 throws ParseException { 1035 } 1036 1037 1047 protected Node exitTokenHandling(Production node) 1048 throws ParseException { 1049 1050 return node; 1051 } 1052 1053 1061 protected void childTokenHandling(Production node, Node child) 1062 throws ParseException { 1063 1064 node.addChild(child); 1065 } 1066 1067 1074 protected void enterProductionPart(Production node) 1075 throws ParseException { 1076 } 1077 1078 1088 protected Node exitProductionPart(Production node) 1089 throws ParseException { 1090 1091 return node; 1092 } 1093 1094 1102 protected void childProductionPart(Production node, Node child) 1103 throws ParseException { 1104 1105 node.addChild(child); 1106 } 1107 1108 1115 protected void enterProductionDeclaration(Production node) 1116 throws ParseException { 1117 } 1118 1119 1129 protected Node exitProductionDeclaration(Production node) 1130 throws ParseException { 1131 1132 return node; 1133 } 1134 1135 1143 protected void childProductionDeclaration(Production node, Node child) 1144 throws ParseException { 1145 1146 node.addChild(child); 1147 } 1148 1149 1156 protected void enterProduction(Production node) 1157 throws ParseException { 1158 } 1159 1160 1170 protected Node exitProduction(Production node) 1171 throws ParseException { 1172 1173 return node; 1174 } 1175 1176 1184 protected void childProduction(Production node, Node child) 1185 throws ParseException { 1186 1187 node.addChild(child); 1188 } 1189 1190 1197 protected void enterProductionAtom(Production node) 1198 throws ParseException { 1199 } 1200 1201 1211 protected Node exitProductionAtom(Production node) 1212 throws ParseException { 1213 1214 return node; 1215 } 1216 1217 1225 protected void childProductionAtom(Production node, Node child) 1226 throws ParseException { 1227 1228 node.addChild(child); 1229 } 1230} 1231 | Popular Tags |