1%options scopes,act,an=javaact.cpp,hn=javaact.h,em,tab,gp=c++, 2%options fp=java,escape=$,prefix=TK_,em,defer,output-size=125 3%options hblockb=\:,hblocke=:\,nogoto-default,single-productions 4%options la=1,names=max,jikes 5-- $Id: java.g,v 1.48 2004/03/25 13:32:27 ericb Exp $ 6-- This software is subject to the terms of the IBM Jikes Compiler 7-- License Agreement available at the following URL: 8-- http://ibm.com/developerworks/opensource/jikes. 9-- Copyright (C) 1996, 2004 IBM Corporation and others. All Rights Reserved. 10-- You must accept the terms of that agreement to use this software. 11 12------------------------------------------------------------------------ 13-- 14-- J A V A 15-- 16-- This Java grammar started from the grammar defined in chapter 19 of the 17-- first edition of the Java Language Specification manual. It has since been 18-- updated with several additional rules to cover additional language features, 19-- as well as simplified in places where it makes sense to share code. Comments 20-- are given where this grammar differs from the original. Note that the 21-- second edition JLS grammar (chapter 18) is completely broken. This grammar 22-- is in JIKES PG format with semantic actions following each rule. In 23-- specifying the rules, the symbols are enclosed in single quotes, and the 24-- keywords are all caps, so that they can be quickly distinguished from 25-- non-terminals. Optional symbols are suffixed with "opt" and the rules 26-- expanding such definitions can be found at the end. Also, some syntactic 27-- markers have been added to aid the parser in skipping irrelevant 28-- components during different parse phases. 29-- 30-- The file javaact.h produced by JIKESPG from this file (java.g) contains a 31-- very readable definition of the grammar rules together with their 32-- associated semantic actions. That file is marked with appropriate 33-- location directives (automatically generated) which instructs the C++ 34-- compiler to issue error messages in terms of this file (java.g). 35-- Therefore, though the user is encouraged to read javaact.h, no 36-- change should ever be made to that file. Instead, changes should 37-- always be made in this file and javaact.h should be regenerated 38-- using JIKESPG. 39-- 40------------------------------------------------------------------------ 41 42$Define 43 44-- 45-- This macro generates a header for an action function consisting 46-- of the rule in question (commented) and a location directive. 47-- 48$location 49/. 50 51// 52// Rule $rule_number: $rule_text 53// 54#line $next_line "$input_file"./ 55 56-- 57-- This macro is used to initialize the rule_action array 58-- to an unnamed function. A name is generated using the 59-- number of the rule in question. 60-- 61$action 62/. 63#ifndef HEADERS 64 rule_action[$rule_number] = &Parser::Act$rule_number; 65#else 66 void Act$rule_number(); 67#endif 68./ 69 70-- 71-- These macros are used to initialize the rule_action array 72-- to a specific named function. 73-- 74 75$MakeTypeArguments 76/. 77#ifndef HEADERS 78 rule_action[$rule_number] = &Parser::MakeTypeArguments; 79#endif 80./ 81 82$MakeArrayType 83/. 84#ifndef HEADERS 85 rule_action[$rule_number] = &Parser::MakeArrayType; 86#endif 87./ 88 89$MakeCompilationUnit 90/. 91#ifndef HEADERS 92 rule_action[$rule_number] = &Parser::MakeCompilationUnit; 93#endif 94./ 95 96$MakePackageDeclaration 97/. 98#ifndef HEADERS 99 rule_action[$rule_number] = &Parser::MakePackageDeclaration; 100#endif 101./ 102 103$MakeImportDeclaration 104/. 105#ifndef HEADERS 106 rule_action[$rule_number] = &Parser::MakeImportDeclaration; 107#endif 108./ 109 110$MakeModifier 111/. 112#ifndef HEADERS 113 rule_action[$rule_number] = &Parser::MakeModifier; 114#endif 115./ 116 117$MakeAnnotation 118/. 119#ifndef HEADERS 120 rule_action[$rule_number] = &Parser::MakeAnnotation; 121#endif 122./ 123 124$MakeArrayInitializer 125/. 126#ifndef HEADERS 127 rule_action[$rule_number] = &Parser::MakeArrayInitializer; 128#endif 129./ 130 131$MakeClassDeclaration 132/. 133#ifndef HEADERS 134 rule_action[$rule_number] = &Parser::MakeClassDeclaration; 135#endif 136./ 137 138$MakeClassBody 139/. 140#ifndef HEADERS 141 rule_action[$rule_number] = &Parser::MakeClassBody; 142#endif 143./ 144 145$MakeFieldDeclaration 146/. 147#ifndef HEADERS 148 rule_action[$rule_number] = &Parser::MakeFieldDeclaration; 149#endif 150./ 151 152$MakeMethodDeclaration 153/. 154#ifndef HEADERS 155 rule_action[$rule_number] = &Parser::MakeMethodDeclaration; 156#endif 157./ 158 159$MakeMethodHeader 160/. 161#ifndef HEADERS 162 rule_action[$rule_number] = &Parser::MakeMethodHeader; 163#endif 164./ 165 166$MakeMethodDeclarator 167/. 168#ifndef HEADERS 169 rule_action[$rule_number] = &Parser::MakeMethodDeclarator; 170#endif 171./ 172 173$MakeFormalParameter 174/. 175#ifndef HEADERS 176 rule_action[$rule_number] = &Parser::MakeFormalParameter; 177#endif 178./ 179 180$MakeInitializerDeclaration 181/. 182#ifndef HEADERS 183 rule_action[$rule_number] = &Parser::MakeInitializerDeclaration; 184#endif 185./ 186 187$MakeConstructorDeclaration 188/. 189#ifndef HEADERS 190 rule_action[$rule_number] = &Parser::MakeConstructorDeclaration; 191#endif 192./ 193 194$MakeQualifiedSuper 195/. 196#ifndef HEADERS 197 rule_action[$rule_number] = &Parser::MakeQualifiedSuper; 198#endif 199./ 200 201$MakeEnumDeclaration 202/. 203#ifndef HEADERS 204 rule_action[$rule_number] = &Parser::MakeEnumDeclaration; 205#endif 206./ 207 208$MakeEnumBody 209/. 210#ifndef HEADERS 211 rule_action[$rule_number] = &Parser::MakeEnumBody; 212#endif 213./ 214 215$MakeInterfaceDeclaration 216/. 217#ifndef HEADERS 218 rule_action[$rule_number] = &Parser::MakeInterfaceDeclaration; 219#endif 220./ 221 222$MakeAnnotationTypeDeclaration 223/. 224#ifndef HEADERS 225 rule_action[$rule_number] = &Parser::MakeAnnotationTypeDeclaration; 226#endif 227./ 228 229$MakeAnnotationTypeMemberDeclaration 230/. 231#ifndef HEADERS 232 rule_action[$rule_number] = &Parser::MakeAnnotationTypeMemberDeclaration; 233#endif 234./ 235 236$MakeLocalVariable 237/. 238#ifndef HEADERS 239 rule_action[$rule_number] = &Parser::MakeLocalVariable; 240#endif 241./ 242 243$MakeLabeledStatement 244/. 245#ifndef HEADERS 246 rule_action[$rule_number] = &Parser::MakeLabeledStatement; 247#endif 248./ 249 250$MakeExpressionStatement 251/. 252#ifndef HEADERS 253 rule_action[$rule_number] = &Parser::MakeExpressionStatement; 254#endif 255./ 256 257$MakeIfThenElseStatement 258/. 259#ifndef HEADERS 260 rule_action[$rule_number] = &Parser::MakeIfThenElseStatement; 261#endif 262./ 263 264$MakeSwitchLabel 265/. 266#ifndef HEADERS 267 rule_action[$rule_number] = &Parser::MakeSwitchLabel; 268#endif 269./ 270 271$MakeWhileStatement 272/. 273#ifndef HEADERS 274 rule_action[$rule_number] = &Parser::MakeWhileStatement; 275#endif 276./ 277 278$MakeForStatement 279/. 280#ifndef HEADERS 281 rule_action[$rule_number] = &Parser::MakeForStatement; 282#endif 283./ 284 285$MakeForeachStatement 286/. 287#ifndef HEADERS 288 rule_action[$rule_number] = &Parser::MakeForeachStatement; 289#endif 290./ 291 292$MakeAssertStatement 293/. 294#ifndef HEADERS 295 rule_action[$rule_number] = &Parser::MakeAssertStatement; 296#endif 297./ 298 299$MakeTryStatement 300/. 301#ifndef HEADERS 302 rule_action[$rule_number] = &Parser::MakeTryStatement; 303#endif 304./ 305 306$MakeParenthesizedExpression 307/. 308#ifndef HEADERS 309 rule_action[$rule_number] = &Parser::MakeParenthesizedExpression; 310#endif 311./ 312 313$MakeClassLiteral 314/. 315#ifndef HEADERS 316 rule_action[$rule_number] = &Parser::MakeClassLiteral; 317#endif 318./ 319 320$MakeQualifiedNew 321/. 322#ifndef HEADERS 323 rule_action[$rule_number] = &Parser::MakeQualifiedNew; 324#endif 325./ 326 327$MakeArrayCreationUninitialized 328/. 329#ifndef HEADERS 330 rule_action[$rule_number] = &Parser::MakeArrayCreationUninitialized; 331#endif 332./ 333 334$MakeArrayCreationInitialized 335/. 336#ifndef HEADERS 337 rule_action[$rule_number] = &Parser::MakeArrayCreationInitialized; 338#endif 339./ 340 341$MakeFieldAccess 342/. 343#ifndef HEADERS 344 rule_action[$rule_number] = &Parser::MakeFieldAccess; 345#endif 346./ 347 348$MakeMethodInvocation 349/. 350#ifndef HEADERS 351 rule_action[$rule_number] = &Parser::MakeMethodInvocation; 352#endif 353./ 354 355$MakeArrayAccess 356/. 357#ifndef HEADERS 358 rule_action[$rule_number] = &Parser::MakeArrayAccess; 359#endif 360./ 361 362$MakePreUnaryExpression 363/. 364#ifndef HEADERS 365 rule_action[$rule_number] = &Parser::MakePreUnaryExpression; 366#endif 367./ 368 369$MakeCastExpression 370/. 371#ifndef HEADERS 372 rule_action[$rule_number] = &Parser::MakeCastExpression; 373#endif 374./ 375 376$MakeBinaryExpression 377/. 378#ifndef HEADERS 379 rule_action[$rule_number] = &Parser::MakeBinaryExpression; 380#endif 381./ 382 383$MakeInstanceofExpression 384/. 385#ifndef HEADERS 386 rule_action[$rule_number] = &Parser::MakeInstanceofExpression; 387#endif 388./ 389 390$MakeConditionalExpression 391/. 392#ifndef HEADERS 393 rule_action[$rule_number] = &Parser::MakeConditionalExpression; 394#endif 395./ 396 397$MakeWildcard 398/. 399#ifndef HEADERS 400 rule_action[$rule_number] = &Parser::MakeWildcard; 401#endif 402./ 403 404$MakeTypeParameter 405/. 406#ifndef HEADERS 407 rule_action[$rule_number] = &Parser::MakeTypeParameter; 408#endif 409./ 410 411$MakeTypeBound 412/. 413#ifndef HEADERS 414 rule_action[$rule_number] = &Parser::MakeTypeBound; 415#endif 416./ 417 418$SetSym1ToSym2 419/. 420#ifndef HEADERS 421 rule_action[$rule_number] = &Parser::SetSym1ToSym2; 422#endif 423./ 424 425$StartList 426/. 427#ifndef HEADERS 428 rule_action[$rule_number] = &Parser::StartList; 429#endif 430./ 431 432$AddList2 433/. 434#ifndef HEADERS 435 rule_action[$rule_number] = &Parser::AddList2; 436#endif 437./ 438 439$AddList3 440/. 441#ifndef HEADERS 442 rule_action[$rule_number] = &Parser::AddList3; 443#endif 444./ 445 446-- 447-- This macro is used to initialize the rule_action array 448-- to the NullAction function. 449-- 450$NullAction 451/. 452#ifndef HEADERS 453 rule_action[$rule_number] = &Parser::NullAction; 454#endif 455./ 456 457-- 458-- This macro is used to initialize the rule_action array 459-- to the NoAction function. 460-- 461$NoAction 462/. 463#ifndef HEADERS 464 rule_action[$rule_number] = &Parser::NoAction; 465#endif 466./ 467 468-- 469-- This macro generates a header for a named action function that is 470-- already defined and will be shared. 471-- 472$shared_function 473/. 474 475// 476// Rule $rule_number: $rule_text./ 477 478-- 479-- This macro generates a header for a rule that invokes the 480-- no_function routine. 481-- 482$shared_NoAction 483/. 484 485// 486// Rule $rule_number: $rule_text 487// 488// void NoAction(); 489//./ 490 491-- 492-- This macro generates a header for a rule that invokes the 493-- null_function routine. 494-- 495$shared_NullAction 496/. 497 498// 499// Rule $rule_number: $rule_text 500// 501// void NullAction(); 502//./ 503 504-- 505-- This macro generates a header for a rule that invokes the 506-- StartList routine. 507-- 508$shared_StartList 509/. 510 511// 512// Rule $rule_number: $rule_text 513// 514// void StartList(); 515//./ 516 517-- 518-- This macro generates a header for a rule that invokes the 519-- AddList2 routine. 520-- 521$shared_AddList2 522/. 523 524// 525// Rule $rule_number: $rule_text 526// 527// void AddList2(); 528//./ 529 530-- 531-- This macro generates a header for a rule that invokes the 532-- AddList3 routine. 533-- 534$shared_AddList3 535/. 536 537// 538// Rule $rule_number: $rule_text 539// 540// void AddList3(); 541//./ 542 543-- 544-- This macro generates a header for MakePreUnaryExpression. 545-- 546$shared_Unary 547/. 548 549// 550// Rule $rule_number: $rule_text 551// 552// void MakePreUnaryExpression(); 553//./ 554-- 555-- This macro generates a header for MakeBinaryExpression. 556-- 557$shared_Binary 558/. 559 560// 561// Rule $rule_number: $rule_text 562// 563// void MakeBinaryExpression(); 564//./ 565 566$Terminals 567 568 abstract assert boolean break byte case catch char class continue 569 default do double else extends false final finally float for 570 if implements import instanceof int interface long native new null 571 package private protected public return short static strictfp super switch 572 synchronized this throw throws transient true try void volatile while 573 574 Identifier IntegerLiteral LongLiteral FloatLiteral DoubleLiteral 575 CharacterLiteral StringLiteral 576 577 PLUS_PLUS 578 MINUS_MINUS 579 EQUAL_EQUAL 580 LESS_EQUAL 581 GREATER_EQUAL 582 NOT_EQUAL 583 LEFT_SHIFT 584 RIGHT_SHIFT 585 UNSIGNED_RIGHT_SHIFT 586 PLUS_EQUAL 587 MINUS_EQUAL 588 MULTIPLY_EQUAL 589 DIVIDE_EQUAL 590 AND_EQUAL 591 OR_EQUAL 592 XOR_EQUAL 593 REMAINDER_EQUAL 594 LEFT_SHIFT_EQUAL 595 RIGHT_SHIFT_EQUAL 596 UNSIGNED_RIGHT_SHIFT_EQUAL 597 OR_OR 598 AND_AND 599 PLUS 600 MINUS 601 NOT 602 REMAINDER 603 XOR 604 AND 605 MULTIPLY 606 OR 607 TWIDDLE 608 DIVIDE 609 GREATER 610 LESS 611 LPAREN 612 RPAREN 613 LBRACE 614 RBRACE 615 LBRACKET 616 RBRACKET 617 SEMICOLON 618 QUESTION 619 COLON 620 COMMA 621 DOT 622 EQUAL 623 624-- This is a special token that allows us to do a 2-pass parse. 625 BodyMarker 626 627-- These tokens will be used in JDK 1.5, but are not used now. 628 enum 629 AT 630 ELLIPSIS 631 632-- These remaining tokens are not used in the grammar. 633 const 634 goto 635 ERROR 636 EOF 637 638$Alias 639 640 '++' ::= PLUS_PLUS 641 '--' ::= MINUS_MINUS 642 '==' ::= EQUAL_EQUAL 643 '<=' ::= LESS_EQUAL 644 '>=' ::= GREATER_EQUAL 645 '!=' ::= NOT_EQUAL 646 '<<' ::= LEFT_SHIFT 647 '>>' ::= RIGHT_SHIFT 648 '>>>' ::= UNSIGNED_RIGHT_SHIFT 649 '+=' ::= PLUS_EQUAL 650 '-=' ::= MINUS_EQUAL 651 '*=' ::= MULTIPLY_EQUAL 652 '/=' ::= DIVIDE_EQUAL 653 '&=' ::= AND_EQUAL 654 '|=' ::= OR_EQUAL 655 '^=' ::= XOR_EQUAL 656 '%=' ::= REMAINDER_EQUAL 657 '<<=' ::= LEFT_SHIFT_EQUAL 658 '>>=' ::= RIGHT_SHIFT_EQUAL 659 '>>>=' ::= UNSIGNED_RIGHT_SHIFT_EQUAL 660 '||' ::= OR_OR 661 '&&' ::= AND_AND 662 '+' ::= PLUS 663 '-' ::= MINUS 664 '!' ::= NOT 665 '%' ::= REMAINDER 666 '^' ::= XOR 667 '&' ::= AND 668 '*' ::= MULTIPLY 669 '|' ::= OR 670 '~' ::= TWIDDLE 671 '/' ::= DIVIDE 672 '>' ::= GREATER 673 '<' ::= LESS 674 '(' ::= LPAREN 675 ')' ::= RPAREN 676 '{' ::= LBRACE 677 '}' ::= RBRACE 678 '[' ::= LBRACKET 679 ']' ::= RBRACKET 680 ';' ::= SEMICOLON 681 '?' ::= QUESTION 682 ':' ::= COLON 683 ',' ::= COMMA 684 '.' ::= DOT 685 '=' ::= EQUAL 686 687 '@' ::= AT 688 '...' ::= ELLIPSIS 689 690 $EOF ::= EOF 691 $ERROR ::= ERROR 692 693$Start 694 695 Goal 696 697$Rules 698 699\: 700// $Id: java.g,v 1.48 2004/03/25 13:32:27 ericb Exp $ -*- c++ -*- 701// DO NOT MODIFY THIS FILE - it is generated using jikespg on java.g. 702// 703// This software is subject to the terms of the IBM Jikes Compiler Open 704// Source License Agreement available at the following URL: 705// http://ibm.com/developerworks/opensource/jikes. 706// Copyright (C) 1996, 2004 IBM Corporation and others. All Rights Reserved. 707// You must accept the terms of that agreement to use this software. 708// 709 710#ifndef HEADERS 711 712#ifdef HAVE_JIKES_NAMESPACE 713namespace Jikes { // Open namespace Jikes block 714#endif 715 716void Parser::InitRuleAction() 717{ 718 rule_action[0] = &Parser::BadAction; 719#else // HEADERS 720 AstTypeName* MakeTypeArguments(int tokennum); 721 AstType* MakeArrayType(int tokennum); 722 AstName* MakeSimpleName(int tokennum); 723 AstModifiers* MakeModifiers(); 724 AstTypeParameters* MakeTypeParameters(int tokennum); 725 AstTypeArguments* MakeExplicitTypeArguments(int tokennum); 726 AstBlock* MakeBlock(int tokennum); 727 AstStatement* MakeSwitchBlockStatement(AstListNode* labels, 728 AstListNode* statements = NULL); 729 void MakeCastExpression(AstType* type, int tokennum); 730 731 void BadAction(); 732 void NoAction(); 733 void NullAction(); 734 void SetSym1ToSym2(); 735 void StartList(); 736 void AddList2(); 737 void AddList3(); 738 void MakeTypeArguments(); 739 void MakeArrayType(); 740 void MakeCompilationUnit(); 741 void MakePackageDeclaration(); 742 void MakeImportDeclaration(); 743 void MakeModifier(); 744 void MakeAnnotation(); 745 void MakeArrayInitializer(); 746 void MakeClassDeclaration(); 747 void MakeClassBody(); 748 void MakeMethodDeclaration(); 749 void MakeFieldDeclaration(); 750 void MakeMethodHeader(); 751 void MakeMethodDeclarator(); 752 void MakeFormalParameter(); 753 void MakeInitializerDeclaration(); 754 void MakeConstructorDeclaration(); 755 void MakeQualifiedSuper(); 756 void MakeEnumDeclaration(); 757 void MakeEnumBody(); 758 void MakeInterfaceDeclaration(); 759 void MakeAnnotationTypeDeclaration(); 760 void MakeAnnotationTypeMemberDeclaration(); 761 void MakeLocalVariable(); 762 void MakeLabeledStatement(); 763 void MakeExpressionStatement(); 764 void MakeIfThenElseStatement(); 765 void MakeSwitchLabel(); 766 void MakeWhileStatement(); 767 void MakeForStatement(); 768 void MakeForeachStatement(); 769 void MakeAssertStatement(); 770 void MakeTryStatement(); 771 void MakeParenthesizedExpression(); 772 void MakeClassLiteral(); 773 void MakeQualifiedNew(); 774 void MakeArrayCreationUninitialized(); 775 void MakeArrayCreationInitialized(); 776 void MakeFieldAccess(); 777 void MakeMethodInvocation(); 778 void MakeArrayAccess(); 779 void MakePreUnaryExpression(); 780 void MakeCastExpression(); 781 void MakeBinaryExpression(); 782 void MakeInstanceofExpression(); 783 void MakeConditionalExpression(); 784 void MakeWildcard(); 785 void MakeTypeParameter(); 786 void MakeTypeBound(); 787#endif // HEADERS 788 789:\ 790 791/.#line $next_line "$input_file" 792// $Id: java.g,v 1.48 2004/03/25 13:32:27 ericb Exp $ 793// DO NOT MODIFY THIS FILE - it is generated using jikespg on java.g. 794// 795// This software is subject to the terms of the IBM Jikes Compiler Open 796// Source License Agreement available at the following URL: 797// http://ibm.com/developerworks/opensource/jikes. 798// Copyright (C) 1996, 2004 IBM Corporation and others. All Rights Reserved. 799// You must accept the terms of that agreement to use this software. 800// 801 802#include "platform.h" 803#include "parser.h" 804#include "ast.h" 805#include "stream.h" 806 807#undef HEADERS 808#include "javaact.h" 809 810#ifdef HAVE_JIKES_NAMESPACE 811namespace Jikes { // Open namespace Jikes block 812#endif 813 814//**************************************************************************// 815//**************************************************************************// 816//* *// 817//* Below, we show each rule of the Java grammar together with the *// 818//* semantic action that is invoked when the parser performs a reduction *// 819//* by that rule. *// 820//**************************************************************************// 821//**************************************************************************// 822 823./ 824 825--18.2 Productions from 2.3: The syntactic Grammar 826 827Goal ::= CompilationUnit 828\:$NoAction:\ 829/. 830// 831// The parse was bad. Give up now. 832// 833void Parser::BadAction() { assert(false); } 834 835$location 836// 837// Given a rule of the form A ::= x1 x2 ... xn n >= 1 838// Do nothing - Whatever Ast was produced for x1 is inherited by A. 839// 840void Parser::NoAction() {} 841./ 842 843Goal ::= BodyMarker MethodBody 844\:$SetSym1ToSym2:\ 845/. 846// 847// This next rule was added to allow the parser to recognize the body of a 848// funtion (constructor, method, or initializer) out of context. Note that 849// the artificial terminal BodyMarker is added here to prevent an ordinary 850// parse from accepting a body as a valid input - i.e., to recognize a body 851// out-of-context, the BodyMarker terminal must be inserted in front of the 852// input stream containing the body in question. 853$location 854// 855// Given a rule of the form A ::= x1 x2, inherit the result from x2. 856// 857void Parser::SetSym1ToSym2() { Sym(1) = Sym(2); } 858./ 859 860 861--18.3 Productions from 3: Lexical Structure 862 863Literal ::= IntegerLiteral 864\:$action:\ 865/.$location 866void Parser::Act$rule_number() 867{ 868 Sym(1) = ast_pool -> NewIntegerLiteral(Token(1)); 869} 870./ 871 872Literal ::= LongLiteral 873\:$action:\ 874/.$location 875void Parser::Act$rule_number() 876{ 877 Sym(1) = ast_pool -> NewLongLiteral(Token(1)); 878} 879./ 880 881Literal ::= FloatLiteral 882\:$action:\ 883/.$location 884void Parser::Act$rule_number() 885{ 886 Sym(1) = ast_pool -> NewFloatLiteral(Token(1)); 887} 888./ 889 890Literal ::= DoubleLiteral 891\:$action:\ 892/.$location 893void Parser::Act$rule_number() 894{ 895 Sym(1) = ast_pool -> NewDoubleLiteral(Token(1)); 896} 897./ 898 899Literal ::= BooleanLiteral 900\:$NoAction:\ 901/.$shared_NoAction./ 902 903Literal ::= CharacterLiteral 904\:$action:\ 905/.$location 906void Parser::Act$rule_number() 907{ 908 Sym(1) = ast_pool -> NewCharacterLiteral(Token(1)); 909} 910./ 911 912Literal ::= StringLiteral 913\:$action:\ 914/.$location 915void Parser::Act$rule_number() 916{ 917 Sym(1) = ast_pool -> NewStringLiteral(Token(1)); 918} 919./ 920 921Literal ::= 'null' 922\:$action:\ 923/.$location 924void Parser::Act$rule_number() 925{ 926 Sym(1) = ast_pool -> NewNullLiteral(Token(1)); 927} 928./ 929 930BooleanLiteral ::= 'true' 931\:$action:\ 932/.$location 933void Parser::Act$rule_number() 934{ 935 Sym(1) = ast_pool -> NewTrueLiteral(Token(1)); 936} 937./ 938 939BooleanLiteral ::= 'false' 940\:$action:\ 941/.$location 942void Parser::Act$rule_number() 943{ 944 Sym(1) = ast_pool -> NewFalseLiteral(Token(1)); 945} 946./ 947 948--18.4 Productions from 4: Types, Values and Variables 949 950Type ::= PrimitiveType 951\:$NoAction:\ 952/.$shared_NoAction./ 953 954Type ::= ReferenceType 955\:$NoAction:\ 956/.$shared_NoAction./ 957 958PrimitiveType ::= NumericType 959\:$NoAction:\ 960/.$shared_NoAction./ 961 962PrimitiveType ::= 'boolean' 963\:$action:\ 964/.$location 965void Parser::Act$rule_number() 966{ 967 Sym(1) = ast_pool -> NewPrimitiveType(Ast::BOOLEAN, Token(1)); 968} 969./ 970 971NumericType ::= IntegralType 972\:$NoAction:\ 973/.$shared_NoAction./ 974 975NumericType ::= FloatingPointType 976\:$NoAction:\ 977/.$shared_NoAction./ 978 979IntegralType ::= 'byte' 980\:$action:\ 981/.$location 982void Parser::Act$rule_number() 983{ 984 Sym(1) = ast_pool -> NewPrimitiveType(Ast::BYTE, Token(1)); 985} 986./ 987 988IntegralType ::= 'short' 989\:$action:\ 990/.$location 991void Parser::Act$rule_number() 992{ 993 Sym(1) = ast_pool -> NewPrimitiveType(Ast::SHORT, Token(1)); 994} 995./ 996 997IntegralType ::= 'int' 998\:$action:\ 999/.$location 1000void Parser::Act$rule_number() 1001{ 1002 Sym(1) = ast_pool -> NewPrimitiveType(Ast::INT, Token(1)); 1003} 1004./ 1005 1006IntegralType ::= 'long' 1007\:$action:\ 1008/.$location 1009void Parser::Act$rule_number() 1010{ 1011 Sym(1) = ast_pool -> NewPrimitiveType(Ast::LONG, Token(1)); 1012} 1013./ 1014 1015IntegralType ::= 'char' 1016\:$action:\ 1017/.$location 1018void Parser::Act$rule_number() 1019{ 1020 Sym(1) = ast_pool -> NewPrimitiveType(Ast::CHAR, Token(1)); 1021} 1022./ 1023 1024FloatingPointType ::= 'float' 1025\:$action:\ 1026/.$location 1027void Parser::Act$rule_number() 1028{ 1029 Sym(1) = ast_pool -> NewPrimitiveType(Ast::FLOAT, Token(1)); 1030} 1031./ 1032 1033FloatingPointType ::= 'double' 1034\:$action:\ 1035/.$location 1036void Parser::Act$rule_number() 1037{ 1038 Sym(1) = ast_pool -> NewPrimitiveType(Ast::DOUBLE, Token(1)); 1039} 1040./ 1041 1042-- 1043-- Added rule to make parsing 'void' easier. 1044-- 1045VoidType ::= 'void' 1046\:$action:\ 1047/.$location 1048void Parser::Act$rule_number() 1049{ 1050 Sym(1) = ast_pool -> NewPrimitiveType(Ast::VOID_TYPE, Token(1)); 1051} 1052./ 1053 1054ReferenceType ::= ClassOrInterfaceType 1055\:$NoAction:\ 1056/.$shared_NoAction./ 1057 1058ReferenceType ::= ArrayType 1059\:$NoAction:\ 1060/.$shared_NoAction./ 1061 1062-- 1063-- Simplify. 1064-- 1065--ClassOrInterfaceType ::= ClassType 1066--ClassOrInterfaceType ::= InterfaceType 1067--ClassType ::= Name 1068--InterfaceType ::= Name 1069ClassOrInterfaceType ::= ClassOrInterface 1070\:$NoAction:\ 1071/.$shared_NoAction./ 1072 1073-- 1074-- Parameterized types were added in JSR 14. 1075-- Use of Marker allows us to easily find the closing '>'. 1076-- 1077ClassOrInterfaceType ::= ClassOrInterface '<' TypeArgumentList1 Marker 1078\:$MakeTypeArguments:\ 1079/.$location 1080void Parser::MakeTypeArguments() { Sym(1) = MakeTypeArguments(1); } 1081 1082// 1083// Given AstName/AstType '<' TypeArgumentList1 at tokennum, generate the 1084// AstTypeName that includes the type arguments. There must be a production at 1085// tokennum + 3 to allow finding the closing '>'. 1086// 1087AstTypeName* Parser::MakeTypeArguments(int tokennum) 1088{ 1089 AstTypeName* p = Sym(tokennum) -> NameCast() 1090 ? ast_pool -> NewTypeName(DYNAMIC_CAST<AstName*> (Sym(tokennum))) 1091 : DYNAMIC_CAST<AstTypeName*> (Sym(tokennum)); 1092 AstListNode* tail = DYNAMIC_CAST<AstListNode*> (Sym(tokennum + 2)); 1093 AstTypeArguments* q = 1094 ast_pool -> NewTypeArguments(Token(tokennum + 1), 1095 Token(tokennum + 3) - 1); 1096 q -> AllocateTypeArguments(tail -> index + 1); 1097 AstListNode* root = tail; 1098 do 1099 { 1100 root = root -> next; 1101 q -> AddTypeArgument(DYNAMIC_CAST<AstType*> (root -> element)); 1102 } while (root != tail); 1103 FreeCircularList(tail); 1104 p -> type_arguments_opt = q; 1105 return p; 1106} 1107./ 1108 1109ClassOrInterface ::= Name 1110\:$action:\ 1111/.$location 1112void Parser::Act$rule_number() 1113{ 1114 AstTypeName* p = ast_pool -> NewTypeName(DYNAMIC_CAST<AstName*> (Sym(1))); 1115 Sym(1) = p; 1116} 1117./ 1118 1119-- 1120-- Parameterized types were added in JSR 14. 1121-- 1122ClassOrInterface ::= ClassOrInterface '<' TypeArgumentList1 '.' Name 1123\:$action:\ 1124/.$location 1125void Parser::Act$rule_number() 1126{ 1127 AstTypeName* p = ast_pool -> NewTypeName(DYNAMIC_CAST<AstName*> (Sym(5))); 1128 p -> base_opt = MakeTypeArguments(1); 1129 Sym(1) = p; 1130} 1131./ 1132 1133-- 1134-- These rules have been rewritten to avoid some conflicts introduced 1135-- by adding the 1.1 features, and to simplify syntax tree generation. 1136-- 1137-- JLS1 lists: 1138--ArrayType ::= PrimitiveType '[' ']' 1139--ArrayType ::= Name '[' ']' 1140--ArrayType ::= ArrayType '[' ']' 1141-- JLS2 lists: 1142--ArrayType ::= Type '[' ']' 1143-- 1144ArrayType ::= PrimitiveType Dims 1145\:$MakeArrayType:\ 1146/.$location 1147void Parser::MakeArrayType() { Sym(1) = MakeArrayType(1); } 1148 1149// 1150// Used on variants of "Type Dimsopt". If this type has dimensions, make an 1151// array type; otherwise return the type name. 1152// 1153AstType* Parser::MakeArrayType(int tokennum) 1154{ 1155 AstType* p = Sym(tokennum) -> NameCast() 1156 ? ast_pool -> NewTypeName(DYNAMIC_CAST<AstName*> (Sym(tokennum))) 1157 : DYNAMIC_CAST<AstType*> (Sym(tokennum)); 1158 return ! Sym(tokennum + 1) ? p 1159 : ast_pool -> NewArrayType(p, (DYNAMIC_CAST<AstBrackets*> 1160 (Sym(tokennum + 1)))); 1161} 1162./ 1163 1164--ArrayType ::= ClassOrInterfaceType Dims 1165ArrayType ::= Name Dims 1166\:$MakeArrayType:\ 1167/.$shared_function 1168// 1169// void MakeArrayType(); 1170//./ 1171 1172-- 1173-- Parameterized types were added in JSR 14. 1174-- 1175ArrayType ::= ClassOrInterface '<' TypeArgumentList1 '.' Name Dims 1176\:$action:\ 1177/.$location 1178void Parser::Act$rule_number() 1179{ 1180 AstTypeName* p = ast_pool -> NewTypeName(DYNAMIC_CAST<AstName*> (Sym(5))); 1181 p -> base_opt = MakeTypeArguments(1); 1182 Sym(5) = p; 1183 Sym(1) = MakeArrayType(5); 1184} 1185./ 1186 1187-- 1188-- Parameterized types were added in JSR 14. 1189-- 1190ArrayType ::= ClassOrInterface '<' TypeArgumentList1 Dims 1191\:$action:\ 1192/.$location 1193void Parser::Act$rule_number() 1194{ 1195 Sym(3) = MakeTypeArguments(1); 1196 Sym(1) = MakeArrayType(3); 1197} 1198./ 1199 1200-- 1201-- Simplify the syntax tree. 1202-- 1203--ClassType ::= ClassOrInterfaceType 1204--InterfaceType ::= ClassOrInterfaceType 1205 1206--18.5 Productions from 6: Names 1207 1208Name ::= 'Identifier' 1209\:$action:\ 1210/.$location 1211void Parser::Act$rule_number() { MakeSimpleName(1); } 1212 1213// 1214// Used on "Identifier", and sets the corresponding symbol to a simple name. 1215// 1216AstName* Parser::MakeSimpleName(int tokennum) 1217{ 1218 AstName* name = ast_pool -> NewName(Token(tokennum)); 1219 Sym(tokennum) = name; 1220 return name; 1221} 1222./ 1223 1224-- 1225-- The use of Marker allows us to share code. 1226-- 1227--Name ::= Name '.' 'Identifier' 1228Name ::= Name '.' Marker 'Identifier' 1229\:$action:\ 1230/.$location 1231void Parser::Act$rule_number() 1232{ 1233 AstName* p = ast_pool -> NewName(Token(4)); 1234 p -> base_opt = DYNAMIC_CAST<AstName*> (Sym(1)); 1235 Sym(1) = p; 1236} 1237./ 1238 1239--18.6 Productions from 7: Packages 1240 1241-- 1242-- Annotations were added in JSR 175. As a result, we must inline expand 1243-- PackageDeclaration vs. TypeDeclaration in order to resolve the ambiguity 1244-- between '@A' starting '@A package B;' vs. '@A B{}'. 1245-- 1246--CompilationUnit ::= PackageDeclarationopt ImportDeclarationsopt 1247-- TypeDeclarationsopt 1248CompilationUnit ::= PackageDeclaration ImportDeclarationsopt 1249 TypeDeclarationsopt 1250\:$MakeCompilationUnit:\ 1251/.$location 1252void Parser::MakeCompilationUnit() 1253{ 1254 AstCompilationUnit* p = ast_pool -> NewCompilationUnit(); 1255 p -> package_declaration_opt = 1256 DYNAMIC_CAST<AstPackageDeclaration*> (Sym(1)); 1257 if (Sym(2)) 1258 { 1259 AstListNode* tail = DYNAMIC_CAST<AstListNode*> (Sym(2)); 1260 p -> AllocateImportDeclarations(tail -> index + 1); 1261 AstListNode* root = tail; 1262 do 1263 { 1264 root = root -> next; 1265 p -> AddImportDeclaration(DYNAMIC_CAST<AstImportDeclaration*> 1266 (root -> element)); 1267 } while (root != tail); 1268 FreeCircularList(tail); 1269 } 1270 if (Sym(3)) 1271 { 1272 AstListNode* tail = DYNAMIC_CAST<AstListNode*> (Sym(3)); 1273 p -> AllocateTypeDeclarations(tail -> index + 1); 1274 AstListNode* root = tail; 1275 do 1276 { 1277 root = root -> next; 1278 p -> AddTypeDeclaration(DYNAMIC_CAST<AstDeclaredType*> 1279 (root -> element)); 1280 } while (root != tail); 1281 FreeCircularList(tail); 1282 } 1283 Sym(1) = p; 1284} 1285./ 1286 1287-- 1288-- The use of Marker allows us to share code. 1289-- 1290CompilationUnit ::= Marker ImportDeclarations TypeDeclarationsopt 1291\:$MakeCompilationUnit:\ 1292/.$shared_function 1293// 1294// void MakeCompilationUnit(); 1295//./ 1296 1297-- 1298-- See comments above why this is inline expanded. 1299-- 1300CompilationUnit ::= TypeDeclarationsopt 1301\:$action:\ 1302/.$location 1303void Parser::Act$rule_number() 1304{ 1305 Sym(3) = Sym(1); 1306 Sym(1) = NULL; 1307 Sym(2) = NULL; 1308 MakeCompilationUnit(); 1309} 1310./ 1311 1312ImportDeclarations ::= ImportDeclaration 1313\:$StartList:\ 1314/.$location 1315// 1316// This starts a list containing a single element. 1317// Note that the list is circular so as to preserve the order of the elements. 1318// 1319void Parser::StartList() 1320{ 1321 AstListNode* p = AllocateListNode(); 1322 p -> next = p; 1323 p -> element = Sym(1); 1324 p -> index = 0; 1325 Sym(1) = p; 1326} 1327./ 1328 1329ImportDeclarations ::= ImportDeclarations ImportDeclaration 1330\:$AddList2:\ 1331/.$location 1332// 1333// This adds token 2 to an existing list. 1334// Note that the list is circular so as to preserve the order of the elements. 1335// 1336void Parser::AddList2() 1337{ 1338 AstListNode* tail = DYNAMIC_CAST<AstListNode*> (Sym(1)); 1339 AstListNode* p = AllocateListNode(); 1340 p -> element = Sym(2); 1341 p -> index = tail -> index + 1; 1342 p -> next = tail -> next; 1343 tail -> next = p; 1344 Sym(1) = p; 1345} 1346 1347// 1348// This adds token 3 to an existing list (thus, token 2 was a delimiter). 1349// Note that the list is circular so as to preserve the order of the elements. 1350// 1351void Parser::AddList3() 1352{ 1353 AstListNode* tail = DYNAMIC_CAST<AstListNode*> (Sym(1)); 1354 AstListNode* p = AllocateListNode(); 1355 p -> element = Sym(3); 1356 p -> index = tail -> index + 1; 1357 p -> next = tail -> next; 1358 tail -> next = p; 1359 Sym(1) = p; 1360} 1361./ 1362 1363ImportDeclarationsopt ::= $empty 1364\:$NullAction:\ 1365/.$location 1366// 1367// Given a rule of the form A ::= x1 x2 ... xn 1368// 1369// Construct a NULL Ast for A. 1370// 1371void Parser::NullAction() { Sym(1) = NULL; } 1372./ 1373 1374ImportDeclarationsopt ::= ImportDeclarations 1375\:$NoAction:\ 1376/.$shared_NoAction./ 1377 1378TypeDeclarations ::= TypeDeclaration 1379\:$StartList:\ 1380/.$shared_StartList./ 1381 1382TypeDeclarations ::= TypeDeclarations TypeDeclaration 1383\:$AddList2:\ 1384/.$shared_AddList2./ 1385 1386TypeDeclarationsopt ::= $empty 1387\:$NullAction:\ 1388/.$shared_NullAction./ 1389 1390TypeDeclarationsopt ::= TypeDeclarations 1391\:$NoAction:\ 1392/.$shared_NoAction./ 1393 1394-- 1395-- The use of Marker allows us to share code. 1396-- 1397--PackageDeclaration ::= 'package' Name PackageHeaderMarker ';' 1398PackageDeclaration ::= Marker 'package' Name PackageHeaderMarker ';' 1399\:$MakePackageDeclaration:\ 1400/.$location 1401void Parser::MakePackageDeclaration() 1402{ 1403 AstPackageDeclaration* p = ast_pool -> NewPackageDeclaration(); 1404 p -> modifiers_opt = MakeModifiers(); 1405 p -> package_token = Token(2); 1406 p -> name = DYNAMIC_CAST<AstName*> (Sym(3)); 1407 p -> semicolon_token = Token(5); 1408 Sym(1) = p; 1409} 1410 1411// 1412// Converts the list at symbol 1 to AstModifiers. 1413// 1414AstModifiers* Parser::MakeModifiers() 1415{ 1416 if (! Sym(1)) 1417 return NULL; 1418 AstModifiers* p = ast_pool -> NewModifiers(); 1419 AstListNode* tail = DYNAMIC_CAST<AstListNode*> (Sym(1)); 1420 p -> AllocateModifiers(tail -> index + 1); 1421 AstListNode* root = tail; 1422 do 1423 { 1424 root = root -> next; 1425 if (root -> element -> ModifierKeywordCast()) 1426 { 1427 AstModifierKeyword* mod = (AstModifierKeyword*) root -> element; 1428 p -> AddModifier(mod); 1429 if (lex_stream -> Kind(mod -> modifier_token) == TK_static) 1430 p -> static_token_opt = mod -> modifier_token; 1431 } 1432 else p -> AddModifier(DYNAMIC_CAST<AstAnnotation*> (root -> element)); 1433 } while (root != tail); 1434 FreeCircularList(tail); 1435 return p; 1436} 1437./ 1438 1439-- 1440-- Annotations were added in JSR 175. We must use Modifiers with a semantic 1441-- check that no modifier keywords appeared, because of the ambiguity between 1442-- '@A @B' starting '@A @B package C;' or '@A @B class C{}'. 1443-- 1444PackageDeclaration ::= Modifiers 'package' Name PackageHeaderMarker ';' 1445\:$MakePackageDeclaration:\ 1446/.$shared_function 1447// 1448// void MakePackageDeclaration(); 1449//./ 1450 1451ImportDeclaration ::= SingleTypeImportDeclaration 1452\:$NoAction:\ 1453/.$shared_NoAction./ 1454 1455ImportDeclaration ::= TypeImportOnDemandDeclaration 1456\:$NoAction:\ 1457/.$shared_NoAction./ 1458 1459-- 1460-- Static imports were added in JSR 201. 1461-- 1462ImportDeclaration ::= SingleStaticImportDeclaration 1463\:$NoAction:\ 1464/.$shared_NoAction./ 1465 1466-- 1467-- Static imports were added in JSR 201. 1468-- 1469ImportDeclaration ::= StaticImportOnDemandDeclaration 1470\:$NoAction:\ 1471/.$shared_NoAction./ 1472 1473-- 1474-- Note that semantically, Name must be qualified to be valid (since simple 1475-- type names are not in scope). However, the grammar accepts simple names. 1476-- The use of Marker allows us to share code. 1477-- 1478--SingleTypeImportDeclaration ::= 'import' TypeName ';' 1479SingleTypeImportDeclaration ::= 'import' Marker Name Marker Marker ';' 1480\:$MakeImportDeclaration:\ 1481/.$location 1482void Parser::MakeImportDeclaration() 1483{ 1484 AstImportDeclaration* p = ast_pool -> NewImportDeclaration(); 1485 p -> import_token = Token(1); 1486 if (Token(3) > Token(2)) 1487 p -> static_token_opt = Token(2); 1488 p -> name = DYNAMIC_CAST<AstName*> (Sym(3)); 1489 if (Token(6) > Token(5)) 1490 p -> star_token_opt = Token(5); 1491 p -> semicolon_token = Token(6); 1492 Sym(1) = p; 1493} 1494./ 1495 1496-- 1497-- The use of Marker allows us to share code. 1498-- 1499--TypeImportOnDemandDeclaration ::= 'import' PackageOrTypeName '.' '*' ';' 1500TypeImportOnDemandDeclaration ::= 'import' Marker Name '.' '*' ';' 1501\:$MakeImportDeclaration:\ 1502/.$shared_function 1503// 1504// void MakeImportDeclaration(); 1505//./ 1506 1507-- 1508-- Static imports were added in JSR 201. 1509-- The use of Marker allows us to share code. 1510-- 1511--SingleStaticImportDeclaration ::= 'import' 'static' TypeName '.' 1512-- 'Identifier' ';' 1513SingleStaticImportDeclaration ::= 'import' 'static' Name Marker Marker ';' 1514\:$MakeImportDeclaration:\ 1515/.$shared_function 1516// 1517// void MakeImportDeclaration(); 1518//./ 1519 1520-- 1521-- Static imports were added in JSR 201. 1522-- 1523--StaticImportOnDemandDeclaration ::= 'import' 'static' TypeName '.' '*' ';' 1524StaticImportOnDemandDeclaration ::= 'import' 'static' Name '.' '*' ';' 1525\:$MakeImportDeclaration:\ 1526/.$shared_function 1527// 1528// void MakeImportDeclaration(); 1529//./ 1530 1531TypeDeclaration ::= ClassDeclaration 1532\:$NoAction:\ 1533/.$shared_NoAction./ 1534 1535-- 1536-- Enums were added in JSR 201. 1537-- 1538TypeDeclaration ::= EnumDeclaration 1539\:$NoAction:\ 1540/.$shared_NoAction./ 1541 1542TypeDeclaration ::= InterfaceDeclaration 1543\:$NoAction:\ 1544/.$shared_NoAction./ 1545 1546-- 1547-- Annotations were added in JSR 175. 1548-- 1549TypeDeclaration ::= AnnotationTypeDeclaration 1550\:$NoAction:\ 1551/.$shared_NoAction./ 1552 1553TypeDeclaration ::= ';' 1554\:$action:\ 1555/.$location 1556void Parser::Act$rule_number() 1557{ 1558 Sym(1) = ast_pool -> NewEmptyDeclaration(Token(1)); 1559} 1560./ 1561 1562--18.7 Only in the LALR(1) Grammar 1563-- Remember that we do semantic filtering on modifiers, for every context 1564-- they can appear in. For better error messages, we also accept all modifiers 1565-- for initializer blocks, formal parameters, and local variable declarations. 1566-- 1567--ClassModifiers ::= Modifiers 1568--FieldModifiers ::= Modifiers 1569--MethodModifiers ::= Modifiers 1570--ConstructorModifiers ::= Modifiers 1571--InterfaceModifiers ::= Modifiers 1572--ConstantModifiers ::= Modifiers 1573--AbstractMethodModifiers ::= Modifiers 1574Modifiers ::= Modifier 1575\:$StartList:\ 1576/.$shared_StartList./ 1577 1578Modifiers ::= Modifiers Modifier 1579\:$AddList2:\ 1580/.$shared_AddList2./ 1581 1582Modifiersopt ::= $empty 1583\:$NullAction:\ 1584/.$shared_NullAction./ 1585 1586Modifiersopt ::= Modifiers 1587\:$NoAction:\ 1588/.$shared_NoAction./ 1589 1590Modifier ::= 'public' 1591\:$MakeModifier:\ 1592/.$location 1593void Parser::MakeModifier() 1594{ 1595 Sym(1) = ast_pool -> NewModifierKeyword(Token(1)); 1596} 1597./ 1598 1599Modifier ::= 'protected' 1600\:$MakeModifier:\ 1601/.$shared_function 1602// 1603// void MakeModifier(); 1604//./ 1605 1606Modifier ::= 'private' 1607\:$MakeModifier:\ 1608/.$shared_function 1609// 1610// void MakeModifier(); 1611//./ 1612 1613Modifier ::= 'static' 1614\:$MakeModifier:\ 1615/.$shared_function 1616// 1617// void MakeModifier(); 1618//./ 1619 1620Modifier ::= 'abstract' 1621\:$MakeModifier:\ 1622/.$shared_function 1623// 1624// void MakeModifier(); 1625//./ 1626 1627Modifier ::= 'final' 1628\:$MakeModifier:\ 1629/.$shared_function 1630// 1631// void MakeModifier(); 1632//./ 1633 1634Modifier ::= 'native' 1635\:$MakeModifier:\ 1636/.$shared_function 1637// 1638// void MakeModifier(); 1639//./ 1640 1641Modifier ::= 'strictfp' 1642\:$MakeModifier:\ 1643/.$shared_function 1644// 1645// void MakeModifier(); 1646//./ 1647 1648Modifier ::= 'synchronized' 1649\:$MakeModifier:\ 1650/.$shared_function 1651// 1652// void MakeModifier(); 1653//./ 1654 1655Modifier ::= 'transient' 1656\:$MakeModifier:\ 1657/.$shared_function 1658// 1659// void MakeModifier(); 1660//./ 1661 1662Modifier ::= 'volatile' 1663\:$MakeModifier:\ 1664/.$shared_function 1665// 1666// void MakeModifier(); 1667//./ 1668 1669-- 1670-- Annotations were added in JSR 175. They are valid anywhere a modifier is, 1671-- additionally they are valid on package declarations. 1672-- 1673Modifier ::= Annotation 1674\:$NoAction:\ 1675/.$shared_NoAction./ 1676 1677-- 1678-- Annotations were added in JSR 175. 1679-- 1680Annotation ::= NormalAnnotation 1681\:$NoAction:\ 1682/.$shared_NoAction./ 1683 1684-- 1685-- Annotations were added in JSR 175. 1686-- 1687Annotation ::= MarkerAnnotation 1688\:$NoAction:\ 1689/.$shared_NoAction./ 1690 1691-- 1692-- Annotations were added in JSR 175. 1693-- 1694Annotation ::= SingleMemberAnnotation 1695\:$NoAction:\ 1696/.$shared_NoAction./ 1697 1698-- 1699-- Annotations were added in JSR 175. 1700-- 1701--NormalAnnotation ::= '@' TypeName '(' MemberValuePairsopt ')' 1702NormalAnnotation ::= '@' Name '(' MemberValuePairsopt ')' 1703\:$MakeAnnotation:\ 1704/.$location 1705void Parser::MakeAnnotation() 1706{ 1707 AstAnnotation* p = ast_pool -> NewAnnotation(); 1708 p -> at_token = Token(1); 1709 p -> name = DYNAMIC_CAST<AstName*> (Sym(2)); 1710 if (Sym(4)) 1711 { 1712 AstListNode* tail = DYNAMIC_CAST<AstListNode*> (Sym(4)); 1713 p -> AllocateMemberValuePairs(tail -> index + 1); 1714 AstListNode* root = tail; 1715 do 1716 { 1717 root = root -> next; 1718 p -> AddMemberValuePair(DYNAMIC_CAST<AstMemberValuePair*> 1719 (root -> element)); 1720 } while (root != tail); 1721 FreeCircularList(tail); 1722 } 1723 if (Token(5) > Token(3)) 1724 p -> right_paren_token_opt = Token(5); 1725 Sym(1) = p; 1726} 1727./ 1728 1729-- 1730-- Annotations were added in JSR 175. 1731-- 1732MemberValuePairs ::= MemberValuePair 1733\:$StartList:\ 1734/.$shared_StartList./ 1735 1736-- 1737-- Annotations were added in JSR 175. 1738-- 1739MemberValuePairs ::= MemberValuePairs ',' MemberValuePair 1740\:$AddList3:\ 1741/.$shared_AddList3./ 1742 1743-- 1744-- Annotations were added in JSR 175. 1745-- 1746MemberValuePairsopt ::= $empty 1747\:$NullAction:\ 1748/.$shared_NullAction./ 1749 1750-- 1751-- Annotations were added in JSR 175. 1752-- 1753MemberValuePairsopt ::= MemberValuePairs 1754\:$NoAction:\ 1755/.$shared_NoAction./ 1756 1757-- 1758-- Annotations were added in JSR 175. We got rid of SimpleName. 1759-- 1760--MemberValuePair ::= SimpleName '=' MemberValue 1761MemberValuePair ::= 'Identifier' '=' MemberValue 1762\:$action:\ 1763/.$location 1764void Parser::Act$rule_number() 1765{ 1766 AstMemberValuePair* p = ast_pool -> NewMemberValuePair(); 1767 p -> identifier_token_opt = Token(1); 1768 p -> member_value = DYNAMIC_CAST<AstMemberValue*> (Sym(3)); 1769 Sym(1) = p; 1770} 1771./ 1772 1773-- 1774-- Annotations were added in JSR 175. 1775-- 1776MemberValue ::= ConditionalExpression 1777\:$NoAction:\ 1778/.$shared_NoAction./ 1779 1780-- 1781-- Annotations were added in JSR 175. 1782-- 1783MemberValue ::= Annotation 1784\:$NoAction:\ 1785/.$shared_NoAction./ 1786 1787-- 1788-- Annotations were added in JSR 175. 1789-- 1790MemberValue ::= MemberValueArrayInitializer 1791\:$NoAction:\ 1792/.$shared_NoAction./ 1793 1794-- 1795-- Annotations were added in JSR 175. The rule was expanded inline below to 1796-- make the grammar LALR(1). The use of Marker allows us to share code. 1797-- 1798--MemberValueArrayInitializer ::= '{' MemberValuesopt ,opt '}' 1799MemberValueArrayInitializer ::= '{' Marker ,opt '}' 1800\:$MakeArrayInitializer:\ 1801/.$location 1802void Parser::MakeArrayInitializer() 1803{ 1804 AstArrayInitializer* p = ast_pool -> NewArrayInitializer(); 1805 p -> left_brace_token = Token(1); 1806 if (Sym(2)) 1807 { 1808 AstListNode* tail = DYNAMIC_CAST<AstListNode*> (Sym(2)); 1809 p -> AllocateVariableInitializers(tail -> index + 1); 1810 AstListNode* root = tail; 1811 do 1812 { 1813 root = root -> next; 1814 p -> AddVariableInitializer(DYNAMIC_CAST<AstMemberValue*> 1815 (root -> element)); 1816 } while (root != tail); 1817 FreeCircularList(tail); 1818 } 1819 p -> right_brace_token = Token(4); 1820 Sym(1) = p; 1821} 1822./ 1823 1824-- 1825-- Annotations were added in JSR 175. 1826-- 1827MemberValueArrayInitializer ::= '{' MemberValues ,opt '}' 1828\:$MakeArrayInitializer:\ 1829/.$shared_function 1830// 1831// void MakeArrayInitializer(); 1832//./ 1833 1834-- 1835-- Annotations were added in JSR 175. 1836-- 1837MemberValues ::= MemberValue 1838\:$StartList:\ 1839/.$shared_StartList./ 1840 1841-- 1842-- Annotations were added in JSR 175. 1843-- 1844MemberValues ::= MemberValues ',' MemberValue 1845\:$AddList3:\ 1846/.$shared_AddList3./ 1847 1848-- 1849-- Annotations were added in JSR 175. 1850-- The use of Marker allows us to share code. 1851-- 1852--MarkerAnnotation ::= '@' TypeName 1853MarkerAnnotation ::= '@' Name Marker Marker Marker 1854\:$MakeAnnotation:\ 1855/.$shared_function 1856// 1857// void MakeAnnotation(); 1858//./ 1859 1860-- 1861-- Annotations were added in JSR 175. 1862-- 1863--SingleMemberAnnotation ::= '@' TypeName '(' MemberValue ')' 1864SingleMemberAnnotation ::= '@' Name '(' MemberValue ')' 1865\:$action:\ 1866/.$location 1867void Parser::Act$rule_number() 1868{ 1869 AstMemberValuePair* mvp = ast_pool -> NewMemberValuePair(); 1870 mvp -> member_value = DYNAMIC_CAST<AstMemberValue*> (Sym(4)); 1871 AstListNode* p = AllocateListNode(); 1872 p -> next = p; 1873 p -> element = mvp; 1874 p -> index = 0; 1875 Sym(4) = p; 1876 MakeAnnotation(); 1877} 1878./ 1879 1880--18.8 Productions from 8: Class Declarations 1881--18.8.1 Productions from 8.1: Class Declarations 1882 1883-- 1884-- Parameterized types were added in JSR 14. We must inline expand 1885-- Modifiersopt to avoid ambiguity. The use of Marker allows us to share code. 1886-- 1887--ClassDeclaration ::= ClassModifiersopt 'class' 'Identifier' Superopt 1888-- Interfacesopt ClassBody 1889ClassDeclaration ::= Marker 'class' 'Identifier' TypeParametersopt 1890 Superopt Interfacesopt ClassBody 1891\:$MakeClassDeclaration:\ 1892/.$location 1893void Parser::MakeClassDeclaration() 1894{ 1895 AstClassDeclaration* p = ast_pool -> NewClassDeclaration(); 1896 p -> modifiers_opt = MakeModifiers(); 1897 p -> class_token = Token(2); 1898 p -> type_parameters_opt = MakeTypeParameters(4); 1899 p -> super_opt = DYNAMIC_CAST<AstTypeName*> (Sym(5)); 1900 if (Sym(6)) 1901 { 1902 AstListNode* tail = DYNAMIC_CAST<AstListNode*> (Sym(6)); 1903 p -> AllocateInterfaces(tail -> index + 1); 1904 AstListNode* root = tail; 1905 do 1906 { 1907 root = root -> next; 1908 p -> AddInterface(DYNAMIC_CAST<AstTypeName*> (root -> element)); 1909 } while (root != tail); 1910 FreeCircularList(tail); 1911 } 1912 p -> class_body = DYNAMIC_CAST<AstClassBody*> (Sym(7)); 1913 p -> class_body -> identifier_token = Token(3); 1914 p -> class_body -> owner = p; 1915 Sym(1) = p; 1916} 1917 1918// 1919// Creates an AstTypeParameters node for insertion into an AstTypeName. 1920// 1921AstTypeParameters* Parser::MakeTypeParameters(int tokennum) 1922{ 1923 if (! Sym(tokennum)) 1924 return NULL; 1925 AstTypeParameters* p = ast_pool -> NewTypeParameters(); 1926 AstListNode* tail = DYNAMIC_CAST<AstListNode*> (Sym(tokennum)); 1927 p -> AllocateTypeParameters(tail -> index + 1); 1928 AstListNode* root = tail; 1929 do 1930 { 1931 root = root -> next; 1932 p -> AddTypeParameter(DYNAMIC_CAST<AstTypeParameter*> 1933 (root -> element)); 1934 } while (root != tail); 1935 FreeCircularList(tail); 1936 p -> right_angle_token = Token(tokennum + 1) - 1; 1937 return p; 1938} 1939./ 1940 1941-- 1942-- Parameterized types were added in JSR 14. We must inline expand 1943-- Modifiersopt to avoid ambiguity. 1944-- 1945ClassDeclaration ::= Modifiers 'class' 'Identifier' TypeParametersopt 1946 Superopt Interfacesopt ClassBody 1947\:$MakeClassDeclaration:\ 1948/.$shared_function 1949// 1950// void MakeClassDeclaration(); 1951//./ 1952 1953-- 1954-- Simplify. 1955-- 1956--Super ::= 'extends' ClassType 1957Super ::= 'extends' ClassOrInterfaceType 1958\:$SetSym1ToSym2:\ 1959/.$shared_function 1960// 1961// void SetSym1ToSym2(); 1962//./ 1963 1964Superopt ::= $empty 1965\:$NullAction:\ 1966/.$shared_NullAction./ 1967 1968Superopt ::= Super 1969\:$NoAction:\ 1970/.$shared_NoAction./ 1971 1972-- 1973-- Simplify. 1974-- 1975--Interfaces ::= 'implements' InterfaceTypeList 1976Interfaces ::= 'implements' TypeList 1977\:$SetSym1ToSym2:\ 1978/.$shared_function 1979// 1980// void SetSym1ToSym2(); 1981//./ 1982 1983Interfacesopt ::= $empty 1984\:$NullAction:\ 1985/.$shared_NullAction./ 1986 1987Interfacesopt ::= Interfaces 1988\:$NoAction:\ 1989/.$shared_NoAction./ 1990 1991--InterfaceTypeList ::= InterfaceType 1992--ClassTypeList ::= ClassType 1993TypeList ::= ClassOrInterfaceType 1994\:$StartList:\ 1995/.$shared_StartList./ 1996 1997--InterfaceTypeList ::= InterfaceTypeList ',' InterfaceType 1998--ClassTypeList ::= ClassTypeList ',' ClassType 1999TypeList ::= TypeList ',' ClassOrInterfaceType 2000\:$AddList3:\ 2001/.$shared_AddList3./ 2002 2003ClassBody ::= '{' ClassBodyDeclarationsopt '}' 2004\:$MakeClassBody:\ 2005/.$location 2006void Parser::MakeClassBody() 2007{ 2008 AstClassBody* p = ast_pool -> NewClassBody(); 2009 if (parse_header_only) 2010 p -> MarkUnparsed(); 2011 2012 p -> left_brace_token = Token(1); 2013 if (Sym(2)) 2014 { 2015 unsigned num_instance_variables = 0; 2016 unsigned num_class_variables = 0; 2017 unsigned num_methods = 0; 2018 unsigned num_constructors = 0; 2019 unsigned num_static_initializers = 0; 2020 unsigned num_instance_initializers = 0; 2021 unsigned num_inner_classes = 0; 2022 unsigned num_inner_enums = 0; 2023 unsigned num_inner_interfaces = 0; 2024 unsigned num_inner_annotations = 0; 2025 unsigned num_empty_declarations = 0; 2026 2027 AstListNode* tail = DYNAMIC_CAST<AstListNode*> (Sym(2)); 2028 p -> AllocateClassBodyDeclarations(tail -> index + 1); 2029 AstListNode* root = tail; 2030 do 2031 { 2032 root = root -> next; 2033 AstDeclared* declaration = 2034 DYNAMIC_CAST<AstDeclared*> (root -> element); 2035 AstFieldDeclaration* field_declaration = 2036 declaration -> FieldDeclarationCast(); 2037 AstInitializerDeclaration* initializer = 2038 declaration -> InitializerDeclarationCast(); 2039 if (field_declaration) 2040 { 2041 if (field_declaration -> modifiers_opt && 2042 field_declaration -> modifiers_opt -> static_token_opt) 2043 { 2044 field_declaration -> MarkStatic(); 2045 } 2046 // 2047 // Interface fields were already marked static. 2048 // 2049 if (field_declaration -> StaticFieldCast()) 2050 num_class_variables++; 2051 else num_instance_variables++; 2052 } 2053 else if (declaration -> MethodDeclarationCast()) 2054 num_methods++; 2055 else if (declaration -> ConstructorDeclarationCast()) 2056 num_constructors++; 2057 else if (initializer) 2058 { 2059 if (initializer -> modifiers_opt && 2060 initializer -> modifiers_opt -> static_token_opt) 2061 { 2062 initializer -> MarkStatic(); 2063 num_static_initializers++; 2064 } 2065 else num_instance_initializers++; 2066 } 2067 else if (declaration -> ClassDeclarationCast()) 2068 num_inner_classes++; 2069 else if (declaration -> EnumDeclarationCast()) 2070 num_inner_enums++; 2071 else if (declaration -> InterfaceDeclarationCast()) 2072 num_inner_interfaces++; 2073 else if (declaration -> AnnotationDeclarationCast()) 2074 num_inner_annotations++; 2075 else num_empty_declarations++; 2076 } while (root != tail); 2077 2078 p -> AllocateInstanceVariables(num_instance_variables); 2079 p -> AllocateClassVariables(num_class_variables); 2080 p -> AllocateMethods(num_methods); 2081 p -> AllocateConstructors(num_constructors); 2082 p -> AllocateStaticInitializers(num_static_initializers); 2083 p -> AllocateInstanceInitializers(num_instance_initializers); 2084 p -> AllocateNestedClasses(num_inner_classes); 2085 p -> AllocateNestedEnums(num_inner_enums); 2086 p -> AllocateNestedInterfaces(num_inner_interfaces); 2087 p -> AllocateNestedAnnotations(num_inner_annotations); 2088 p -> AllocateEmptyDeclarations(num_empty_declarations); 2089 2090 root = tail; 2091 do 2092 { 2093 root = root -> next; 2094 p -> AddClassBodyDeclaration(DYNAMIC_CAST<AstDeclared*> 2095 (root -> element)); 2096 } while (root != tail); 2097 FreeCircularList(tail); 2098 } 2099 p -> right_brace_token = Token(3); 2100 // from now on, this is the storage pool to use for this type 2101 p -> pool = body_pool; 2102 Sym(1) = p; 2103} 2104./ 2105 2106ClassBodyopt ::= $empty 2107\:$NullAction:\ 2108/.$shared_NullAction./ 2109 2110ClassBodyopt ::= ClassBody 2111\:$NoAction:\ 2112/.$shared_NoAction./ 2113 2114ClassBodyDeclarations ::= ClassBodyDeclaration 2115\:$StartList:\ 2116/.$shared_StartList./ 2117 2118ClassBodyDeclarations ::= ClassBodyDeclarations ClassBodyDeclaration 2119\:$AddList2:\ 2120/.$shared_AddList2./ 2121 2122ClassBodyDeclarationsopt ::= $empty 2123\:$NullAction:\ 2124/.$shared_NullAction./ 2125 2126ClassBodyDeclarationsopt ::= ClassBodyDeclarations 2127\:$NoAction:\ 2128/.$shared_NoAction./ 2129 2130-- 2131-- Simplify. See below. 2132-- 2133--ClassBodyDeclaration ::= ClassMemberDeclaration 2134 2135ClassBodyDeclaration ::= ConstructorDeclaration 2136\:$NoAction:\ 2137/.$shared_NoAction./ 2138 2139-- 2140-- For nicer semantic error messages, we lump static and instance initializers 2141-- together. Also, we parse arbitrary modifiers, but semantically only accept 2142-- static or no modifiers. 2143-- 2144--ClassBodyDeclaration ::= StaticInitializer 2145--ClassBodyDeclaration ::= MethodBody 2146ClassBodyDeclaration ::= InitializerDeclaration 2147\:$NoAction:\ 2148/.$shared_NoAction./ 2149 2150-- 2151-- Simplify. 2152-- 2153--ClassMemberDeclaration ::= FieldDeclaration 2154ClassBodyDeclaration ::= FieldDeclaration 2155\:$NoAction:\ 2156/.$shared_NoAction./ 2157 2158-- 2159-- Simplify. 2160-- 2161--ClassMemberDeclaration ::= MethodDeclaration 2162ClassBodyDeclaration ::= MethodDeclaration 2163\:$NoAction:\ 2164/.$shared_NoAction./ 2165 2166--1.1 feature 2167-- 2168-- Consolidate and simplify. 2169--ClassMemberDeclaration ::= ClassDeclaration 2170--ClassMemberDeclaration ::= InterfaceDeclaration 2171--ClassMemberDeclaration ::= ';' 2172-- 2173ClassBodyDeclaration ::= TypeDeclaration 2174\:$NoAction:\ 2175/.$shared_NoAction./ 2176 2177--18.8.2 Productions from 8.3: Field Declarations 2178 2179-- 2180-- The use of Marker allows us to share code. We must inline expand 2181-- Modifiersopt to avoid ambiguity. 2182-- 2183--FieldDeclaration ::= FieldModifiersopt Type VariableDeclarators ';' 2184FieldDeclaration ::= Marker Marker Type VariableDeclarators ';' 2185\:$MakeFieldDeclaration:\ 2186/.$location 2187void Parser::MakeFieldDeclaration() 2188{ 2189 AstFieldDeclaration* p = ast_pool -> NewFieldDeclaration(); 2190 p -> modifiers_opt = MakeModifiers(); 2191 p -> type = DYNAMIC_CAST<AstType*> (Sym(3)); 2192 AstListNode* tail = DYNAMIC_CAST<AstListNode*> (Sym(4)); 2193 p -> AllocateVariableDeclarators(tail -> index + 1); 2194 AstListNode* root = tail; 2195 do 2196 { 2197 root = root -> next; 2198 p -> AddVariableDeclarator(DYNAMIC_CAST<AstVariableDeclarator*> 2199 (root -> element)); 2200 } while (root != tail); 2201 FreeCircularList(tail); 2202 p -> semicolon_token = Token(5); 2203 Sym(1) = p; 2204} 2205./ 2206 2207FieldDeclaration ::= Modifiers Marker Type VariableDeclarators ';' 2208\:$MakeFieldDeclaration:\ 2209/.$shared_function 2210// 2211// void MakeFieldDeclaration(); 2212//./ 2213 2214VariableDeclarators ::= VariableDeclarator 2215\:$StartList:\ 2216/.$shared_StartList./ 2217 2218VariableDeclarators ::= VariableDeclarators ',' VariableDeclarator 2219\:$AddList3:\ 2220/.$shared_AddList3./ 2221 2222VariableDeclarator ::= VariableDeclaratorId 2223\:$action:\ 2224/.$location 2225void Parser::Act$rule_number() 2226{ 2227 AstVariableDeclarator* p = ast_pool -> NewVariableDeclarator(); 2228 p -> variable_declarator_name = 2229 DYNAMIC_CAST<AstVariableDeclaratorId*> (Sym(1)); 2230 Sym(1) = p; 2231} 2232./ 2233 2234VariableDeclarator ::= VariableDeclaratorId '=' VariableInitializer 2235\:$action:\ 2236/.$location 2237void Parser::Act$rule_number() 2238{ 2239 AstVariableDeclarator* p = ast_pool -> NewVariableDeclarator(); 2240 p -> variable_declarator_name = 2241 DYNAMIC_CAST<AstVariableDeclaratorId*> (Sym(1)); 2242 p -> variable_initializer_opt = Sym(3); 2243 Sym(1) = p; 2244} 2245./ 2246 2247VariableDeclaratorId ::= 'Identifier' Dimsopt 2248\:$action:\ 2249/.$location 2250void Parser::Act$rule_number() 2251{ 2252 AstVariableDeclaratorId* p = ast_pool -> NewVariableDeclaratorId(); 2253 p -> identifier_token = Token(1); 2254 p -> brackets_opt = DYNAMIC_CAST<AstBrackets*> (Sym(2)); 2255 Sym(1) = p; 2256} 2257./ 2258 2259VariableInitializer ::= Expression 2260\:$NoAction:\ 2261/.$shared_NoAction./ 2262 2263VariableInitializer ::= ArrayInitializer 2264\:$NoAction:\ 2265/.$shared_NoAction./ 2266 2267--18.8.3 Productions from 8.4: Method Declarations 2268-- 2269-- We use "MethodHeaderMarker" to speed up parsing while minimizing memory. 2270-- During the first pass, we only care about declarations, so we skip 2271-- everything inside { }. On the second pass, we parse only one method at a 2272-- time (see the production of Goal above). 2273-- 2274-- Also, we expanded MethodBody inline to enable the sharing of MethodBody 2275-- between methods, constructors, and initializers. Note that MethodBody 2276-- can support an explicit constructor call; so it requires semantic filtering. 2277-- 2278--MethodDeclaration ::= MethodHeader MethodBody 2279MethodDeclaration ::= MethodHeader MethodHeaderMarker MethodBody 2280\:$MakeMethodDeclaration:\ 2281/.$location 2282void Parser::MakeMethodDeclaration() 2283{ 2284 AstMethodDeclaration* p = DYNAMIC_CAST<AstMethodDeclaration*> (Sym(1)); 2285 if (Sym(3)) 2286 p -> method_body_opt = DYNAMIC_CAST<AstMethodBody*> (Sym(3)); 2287 else p -> semicolon_token_opt = Token(4); 2288} 2289./ 2290 2291-- 2292-- The use of Marker allows us to share code. 2293-- 2294MethodDeclaration ::= MethodHeader MethodHeaderMarker Marker ';' 2295\:$MakeMethodDeclaration:\ 2296/.$shared_function 2297// 2298// void MakeMethodDeclaration(); 2299//./ 2300 2301-- 2302-- The use of Marker allows us to share code. We must inline expand 2303-- Modifiersopt to avoid ambiguity. 2304-- 2305--MethodHeader ::= MethodModifiersopt Type MethodDeclarator Throwsopt 2306MethodHeader ::= Marker Marker Type MethodDeclarator Throwsopt 2307\:$MakeMethodHeader:\ 2308/.$location 2309void Parser::MakeMethodHeader() 2310{ 2311 AstMethodDeclaration* p = ast_pool -> NewMethodDeclaration(); 2312 p -> modifiers_opt = MakeModifiers(); 2313 p -> type_parameters_opt = MakeTypeParameters(2); 2314 p -> type = DYNAMIC_CAST<AstType*> (Sym(3)); 2315 p -> method_declarator = DYNAMIC_CAST<AstMethodDeclarator*> (Sym(4)); 2316 if (Sym(5)) 2317 { 2318 AstListNode* tail = DYNAMIC_CAST<AstListNode*> (Sym(5)); 2319 p -> AllocateThrows(tail -> index + 1); 2320 AstListNode* root = tail; 2321 do 2322 { 2323 root = root -> next; 2324 p -> AddThrow(DYNAMIC_CAST<AstTypeName*> (root -> element)); 2325 } while (root != tail); 2326 FreeCircularList(tail); 2327 } 2328 Sym(1) = p; 2329} 2330./ 2331 2332-- 2333-- The use of Marker allows us to share code. We must inline expand 2334-- Modifiersopt to avoid ambiguity. 2335-- 2336MethodHeader ::= Modifiers Marker Type MethodDeclarator Throwsopt 2337\:$MakeMethodHeader:\ 2338/.$shared_function 2339// 2340// void MakeMethodHeader(); 2341//./ 2342 2343-- 2344-- Parameterized types were added in JSR 14. We must inline expand 2345-- Modifiersopt to avoid ambiguity. The use of Marker allows us to share code. 2346-- 2347--MethodHeader ::= MethodModifiersopt Type MethodDeclarator Throwsopt 2348MethodHeader ::= Marker TypeParameters Type MethodDeclarator Throwsopt 2349\:$MakeMethodHeader:\ 2350/.$shared_function 2351// 2352// void MakeMethodHeader(); 2353//./ 2354 2355-- 2356-- Parameterized types were added in JSR 14. We must inline expand 2357-- Modifiersopt to avoid ambiguity. 2358-- 2359MethodHeader ::= Modifiers TypeParameters Type MethodDeclarator Throwsopt 2360\:$MakeMethodHeader:\ 2361/.$shared_function 2362// 2363// void MakeMethodHeader(); 2364//./ 2365 2366-- 2367-- The use of Marker allows us to share code. We must inline expand 2368-- Modifiersopt to avoid ambiguity. 2369-- 2370--MethodHeader ::= MethodModifiersopt 'void' MethodDeclarator Throwsopt 2371MethodHeader ::= Marker Marker VoidType MethodDeclarator Throwsopt 2372\:$MakeMethodHeader:\ 2373/.$shared_function 2374// 2375// void MakeMethodHeader(); 2376//./ 2377 2378-- 2379-- The use of Marker allows us to share code. We must inline expand 2380-- Modifiersopt to avoid ambiguity. 2381-- 2382MethodHeader ::= Modifiers Marker VoidType MethodDeclarator Throwsopt 2383\:$MakeMethodHeader:\ 2384/.$shared_function 2385// 2386// void MakeMethodHeader(); 2387//./ 2388 2389-- 2390-- Parameterized types were added in JSR 14. We must inline expand 2391-- Modifiersopt to avoid ambiguity. The use of Marker allows us to share code. 2392-- 2393--MethodHeader ::= Modifiersopt 'void' MethodDeclarator Throwsopt 2394MethodHeader ::= Marker TypeParameters VoidType MethodDeclarator Throwsopt 2395\:$MakeMethodHeader:\ 2396/.$shared_function 2397// 2398// void MakeMethodHeader(); 2399//./ 2400 2401-- 2402-- Parameterized types were added in JSR 14. We must inline expand 2403-- Modifiersopt to avoid ambiguity. 2404-- 2405MethodHeader ::= Modifiers TypeParameters VoidType MethodDeclarator Throwsopt 2406\:$MakeMethodHeader:\ 2407/.$shared_function 2408// 2409// void MakeMethodHeader(); 2410//./ 2411 2412MethodDeclarator ::= 'Identifier' '(' FormalParameterListopt ')' Dimsopt 2413\:$MakeMethodDeclarator:\ 2414/.$location 2415void Parser::MakeMethodDeclarator() 2416{ 2417 AstMethodDeclarator* p = ast_pool -> NewMethodDeclarator(); 2418 p -> identifier_token = Token(1); 2419 p -> left_parenthesis_token = Token(2); 2420 if (Sym(3)) 2421 { 2422 AstListNode* tail = DYNAMIC_CAST<AstListNode*> (Sym(3)); 2423 p -> AllocateFormalParameters(tail -> index + 1); 2424 AstListNode* root = tail; 2425 do 2426 { 2427 root = root -> next; 2428 p -> AddFormalParameter(DYNAMIC_CAST<AstFormalParameter*> 2429 (root -> element)); 2430 } while (root != tail); 2431 FreeCircularList(tail); 2432 } 2433 p -> right_parenthesis_token = Token(4); 2434 p -> brackets_opt = DYNAMIC_CAST<AstBrackets*> (Sym(5)); 2435 Sym(1) = p; 2436} 2437./ 2438 2439-- 2440-- Varargs were added in JSR 201. 2441-- 2442--FormalParameterList ::= FormalParameter 2443FormalParameterList ::= LastFormalParameter 2444\:$StartList:\ 2445/.$shared_StartList./ 2446 2447-- 2448-- Varargs were added in JSR 201. 2449-- 2450--FormalParameterList ::= FormalParameterList ',' FormalParameter 2451FormalParameterList ::= FormalParameters ',' LastFormalParameter 2452\:$AddList3:\ 2453/.$shared_AddList3./ 2454 2455FormalParameterListopt ::= $empty 2456\:$NullAction:\ 2457/.$shared_NullAction./ 2458 2459FormalParameterListopt ::= FormalParameterList 2460\:$NoAction:\ 2461/.$shared_NoAction./ 2462 2463-- 2464-- Varargs were added in JSR 201. 2465-- 2466FormalParameters ::= FormalParameter 2467\:$StartList:\ 2468/.$shared_StartList./ 2469 2470-- 2471-- Varargs were added in JSR 201. 2472-- 2473FormalParameters ::= FormalParameters ',' FormalParameter 2474\:$AddList3:\ 2475/.$shared_AddList3./ 2476 2477-- 2478-- For nicer error messages, we accept all modifiers, even though only 2479-- 'final' and annotations are valid. Also, we must inline expand finalopt 2480-- to avoid ambiguity. The use of Marker allows us to share code. 2481-- 2482--FormalParameter ::= finalopt Type VariableDeclaratorId 2483FormalParameter ::= Type Marker Marker VariableDeclaratorId 2484\:$MakeFormalParameter:\ 2485/.$location 2486void Parser::MakeFormalParameter() 2487{ 2488 AstFormalParameter* p = ast_pool -> NewFormalParameter(); 2489 if (Sym(2)) 2490 { 2491 p -> modifiers_opt = MakeModifiers(); 2492 p -> type = DYNAMIC_CAST<AstType*> (Sym(2)); 2493 } 2494 else p -> type = DYNAMIC_CAST<AstType*> (Sym(1)); 2495 if (Token(4) > Token(3)) 2496 p -> ellipsis_token_opt = Token(3); 2497 AstVariableDeclarator* formal_declarator = 2498 ast_pool -> NewVariableDeclarator(); 2499 formal_declarator -> variable_declarator_name = 2500 DYNAMIC_CAST<AstVariableDeclaratorId*> (Sym(4)); 2501 p -> formal_declarator = formal_declarator; 2502 Sym(1) = p; 2503} 2504./ 2505 2506--1.1 feature 2507-- 2508-- For nicer error messages, we accept all modifiers, even though only 2509-- 'final' and annotations are valid. Also, we must inline expand finalopt 2510-- to avoid ambiguity. The use of Marker allows us to share code. 2511-- 2512--FormalParameter ::= final Type VariableDeclaratorId 2513FormalParameter ::= Modifiers Type Marker VariableDeclaratorId 2514\:$MakeFormalParameter:\ 2515/.$shared_function 2516// 2517// void MakeFormalParameter(); 2518//./ 2519 2520-- 2521-- Varargs were added in JSR 201. We must match the inline expansion of 2522-- FormalParameter to avoid ambiguity. 2523-- 2524--LastFormalParameter ::= Modifiersopt Type ...opt VariableDeclaratorId 2525LastFormalParameter ::= FormalParameter 2526\:$NoAction:\ 2527/.$shared_NoAction./ 2528 2529-- 2530-- Varargs were added in JSR 201. The use of Marker allows us to share code. 2531-- 2532LastFormalParameter ::= Type Marker '...' VariableDeclaratorId 2533\:$MakeFormalParameter:\ 2534/.$shared_function 2535// 2536// void MakeFormalParameter(); 2537//./ 2538 2539-- 2540-- Varargs were added in JSR 201. 2541-- For nicer error messages, we accept all modifiers, even though only 2542-- 'final' and annotations are valid. 2543-- 2544LastFormalParameter ::= Modifiers Type '...' VariableDeclaratorId 2545\:$MakeFormalParameter:\ 2546/.$shared_function 2547// 2548// void MakeFormalParameter(); 2549//./ 2550 2551-- 2552-- Simplify. 2553-- 2554--Throws ::= 'throws' ClassTypeList 2555Throws ::= 'throws' TypeList 2556\:$SetSym1ToSym2:\ 2557/.$shared_function 2558// 2559// void SetSym1ToSym2(); 2560//./ 2561 2562Throwsopt ::= $empty 2563\:$NullAction:\ 2564/.$shared_NullAction./ 2565 2566Throwsopt ::= Throws 2567\:$NoAction:\ 2568/.$shared_NoAction./ 2569 2570-- 2571-- Notice that we filter out an initial explicit constructor invocation, 2572-- since we have modified Statement to include this() and super(). Other 2573-- explicit constructor calls are ignored now, and flagged as errors 2574-- during semantic analysis. 2575-- 2576MethodBody ::= '{' BlockStatementsopt '}' 2577\:$action:\ 2578/.$location 2579void Parser::Act$rule_number() 2580{ 2581 AstMethodBody* p = ast_pool -> NewMethodBody(); 2582 p -> left_brace_token = Token(1); 2583 p -> right_brace_token = Token(3); 2584 2585 if (Sym(2)) 2586 { 2587 AstListNode* tail = DYNAMIC_CAST<AstListNode*> (Sym(2)); 2588 // Allocate 1 extra for possible generated return statement. 2589 p -> AllocateStatements(tail -> index + 2); 2590 AstListNode* root = tail -> next; 2591 if (root -> element -> IsExplicitConstructorInvocation()) 2592 p -> explicit_constructor_opt = 2593 DYNAMIC_CAST<AstStatement*> (root -> element); 2594 else 2595 p -> AddStatement(DYNAMIC_CAST<AstStatement*> (root -> element)); 2596 while (root != tail) 2597 { 2598 root = root -> next; 2599 p -> AddStatement(DYNAMIC_CAST<AstStatement*> (root -> element)); 2600 } 2601 FreeCircularList(tail); 2602 } 2603 else p -> AllocateStatements(1); 2604 Sym(1) = p; 2605} 2606./ 2607 2608-- 2609-- Instead of directly including this rule, we have expanded it inline above. 2610-- 2611--MethodBody ::= ';' 2612-- 2613 2614--18.8.4 Productions from 8.5: Static Initializers 2615-- 2616-- For nicer error messages, we accept arbitrary modifiers. Thus this rule can 2617-- parse static and instance initializers. The use of MethodHeaderMarker 2618-- allows the 2-pass parsing. See comments of MethodDeclaration. 2619-- The use of Marker allows us to share code. 2620-- 2621--StaticInitializer ::= 'static' MethodBody 2622InitializerDeclaration ::= Marker MethodHeaderMarker MethodBody 2623\:$MakeInitializerDeclaration:\ 2624/.$location 2625void Parser::MakeInitializerDeclaration() 2626{ 2627 AstInitializerDeclaration* p = ast_pool -> NewInitializerDeclaration(); 2628 p -> modifiers_opt = MakeModifiers(); 2629 p -> block = DYNAMIC_CAST<AstMethodBody*> (Sym(3)); 2630 Sym(1) = p; 2631} 2632./ 2633 2634-- For nicer error messages, we accept arbitrary modifiers. Thus this rule can 2635-- parse static and instance initializers. The use of MethodHeaderMarker 2636-- allows the 2-pass parsing. See comments of MethodDeclaration. 2637-- 2638InitializerDeclaration ::= Modifiers MethodHeaderMarker MethodBody 2639\:$MakeInitializerDeclaration:\ 2640/.$shared_function 2641// 2642// void MakeInitializerDeclaration(); 2643//./ 2644 2645--18.8.5 Productions from 8.6: Constructor Declarations 2646-- 2647-- The use of Marker allows us to share code. MethodHeaderMarker allows us to 2648-- do 2-pass parsing, and MethodBody was rewritten to handle constructor 2649-- bodies. We must inline expand Modifiersopt to avoid ambiguity. 2650-- 2651--ConstructorDeclaration ::= ConstructorModifiersopt ConstructorDeclarator 2652-- Throwsopt ConstructorBody 2653ConstructorDeclaration ::= Marker Marker ConstructorDeclarator Throwsopt 2654 MethodHeaderMarker MethodBody 2655\:$MakeConstructorDeclaration:\ 2656/.$location 2657void Parser::MakeConstructorDeclaration() 2658{ 2659 AstConstructorDeclaration* p = ast_pool -> NewConstructorDeclaration(); 2660 p -> modifiers_opt = MakeModifiers(); 2661 p -> type_parameters_opt = MakeTypeParameters(2); 2662 p -> constructor_declarator = DYNAMIC_CAST<AstMethodDeclarator*> (Sym(3)); 2663 if (Sym(4)) 2664 { 2665 AstListNode* tail = DYNAMIC_CAST<AstListNode*> (Sym(4)); 2666 p -> AllocateThrows(tail -> index + 1); 2667 AstListNode* root = tail; 2668 do 2669 { 2670 root = root -> next; 2671 p -> AddThrow(DYNAMIC_CAST<AstTypeName*> (root -> element)); 2672 } while (root != tail); 2673 FreeCircularList(tail); 2674 } 2675 p -> constructor_body = DYNAMIC_CAST<AstMethodBody*> (Sym(6)); 2676 Sym(1) = p; 2677} 2678./ 2679 2680-- 2681-- The use of Marker allows us to share code. MethodHeaderMarker allows us to 2682-- do 2-pass parsing, and MethodBody was rewritten to handle constructor 2683-- bodies. We must inline expand Modifiersopt to avoid ambiguity. 2684-- 2685ConstructorDeclaration ::= Modifiers Marker ConstructorDeclarator Throwsopt 2686 MethodHeaderMarker MethodBody 2687\:$MakeConstructorDeclaration:\ 2688/.$shared_function 2689// 2690// void MakeConstructorDeclaration(); 2691//./ 2692 2693-- 2694-- Parameterized types were added in JSR 14. We must inline expand 2695-- Modifiersopt to avoid ambiguity. The use of Marker allows us to share code. 2696-- 2697--ConstructorDeclaration ::= ConstructorModifiersopt ConstructorDeclarator 2698-- Throwsopt ConstructorBody 2699ConstructorDeclaration ::= Marker TypeParameters ConstructorDeclarator 2700 Throwsopt MethodHeaderMarker MethodBody 2701\:$MakeConstructorDeclaration:\ 2702/.$shared_function 2703// 2704// void MakeConstructorDeclaration(); 2705//./ 2706 2707-- 2708-- Parameterized types were added in JSR 14. We must inline expand 2709-- Modifiersopt to avoid ambiguity. 2710-- 2711ConstructorDeclaration ::= Modifiers TypeParameters ConstructorDeclarator 2712 Throwsopt MethodHeaderMarker MethodBody 2713\:$MakeConstructorDeclaration:\ 2714/.$shared_function 2715// 2716// void MakeConstructorDeclaration(); 2717//./ 2718 2719-- 2720-- The use of Marker allows us to share code. Also, we got rid of SimpleName. 2721-- 2722--ConstructorDeclarator ::= SimpleName '(' FormalParameterListopt ')' 2723ConstructorDeclarator ::= 'Identifier' '(' FormalParameterListopt ')' Marker 2724\:$MakeMethodDeclarator:\ 2725/.$shared_function 2726// 2727// void MakeMethodDeclarator(); 2728//./ 2729 2730-- 2731-- For better error reporting, we have coalesced ExplicitConstructorInvocation 2732-- into BlockStatement. Therefore, we do not need a rule for ConstructorBody, 2733-- since MethodBody does the same amount of work. During semantic analysis, 2734-- we then check calls of an explicit constructor invocation out of context. 2735-- 2736--ConstructorBody ::= '{' ExplicitConstructorInvocationopt 2737-- BlockStatementsopt '}' 2738-- 2739 2740-- 2741-- Simplify. 2742-- 2743--ExplicitConstructorInvocation ::= 'this' '(' ArgumentListopt ')' ';' 2744ExplicitConstructorInvocation ::= 'this' Arguments ';' 2745\:$action:\ 2746/.$location 2747void Parser::Act$rule_number() 2748{ 2749 AstThisCall* p = ast_pool -> NewThisCall(); 2750 p -> this_token = Token(1); 2751 p -> arguments = DYNAMIC_CAST<AstArguments*> (Sym(2)); 2752 p -> semicolon_token = Token(3); 2753 Sym(1) = p; 2754} 2755./ 2756 2757-- 2758-- Parameterized types were added in JSR 14. 2759-- 2760ExplicitConstructorInvocation ::= TypeArguments 'this' Arguments ';' 2761\:$action:\ 2762/.$location 2763void Parser::Act$rule_number() 2764{ 2765 AstThisCall* p = ast_pool -> NewThisCall(); 2766 p -> type_arguments_opt = MakeExplicitTypeArguments(1); 2767 p -> this_token = Token(2); 2768 p -> arguments = DYNAMIC_CAST<AstArguments*> (Sym(3)); 2769 p -> semicolon_token = Token(4); 2770 Sym(1) = p; 2771} 2772 2773// 2774// Given TypeArgumentsopt at tokennum, generate the AstTypeArguments for use 2775// in a method call's explicit type arguments. There must be a production 2776// at tokennum + 1 to allow finding the closing '>'. 2777// 2778AstTypeArguments* Parser::MakeExplicitTypeArguments(int tokennum) 2779{ 2780 if (! Sym(tokennum)) 2781 return NULL; 2782 AstTypeArguments* p = 2783 ast_pool -> NewTypeArguments(Token(tokennum), 2784 Token(tokennum + 1) - 1); 2785 AstListNode* tail = DYNAMIC_CAST<AstListNode*> (Sym(tokennum)); 2786 p -> AllocateTypeArguments(tail -> index + 1); 2787 AstListNode* root = tail; 2788 do 2789 { 2790 root = root -> next; 2791 p -> AddTypeArgument(DYNAMIC_CAST<AstType*> (root -> element)); 2792 } while (root != tail); 2793 FreeCircularList(tail); 2794 return p; 2795} 2796./ 2797 2798-- 2799-- Simplify. 2800-- 2801--ExplicitConstructorInvocation ::= 'super' '(' ArgumentListopt ')' ';' 2802ExplicitConstructorInvocation ::= 'super' Arguments ';' 2803\:$action:\ 2804/.$location 2805void Parser::Act$rule_number() 2806{ 2807 AstSuperCall* p = ast_pool -> NewSuperCall(); 2808 p -> super_token = Token(1); 2809 p -> arguments = DYNAMIC_CAST<AstArguments*> (Sym(2)); 2810 p -> semicolon_token = Token(3); 2811 Sym(1) = p; 2812} 2813./ 2814 2815-- 2816-- Parameterized types were added in JSR 14. 2817-- 2818ExplicitConstructorInvocation ::= TypeArguments 'super' Arguments ';' 2819\:$action:\ 2820/.$location 2821void Parser::Act$rule_number() 2822{ 2823 AstSuperCall* p = ast_pool -> NewSuperCall(); 2824 p -> type_arguments_opt = MakeExplicitTypeArguments(1); 2825 p -> super_token = Token(2); 2826 p -> arguments = DYNAMIC_CAST<AstArguments*> (Sym(3)); 2827 p -> semicolon_token = Token(4); 2828 Sym(1) = p; 2829} 2830./ 2831 2832--1.1 feature 2833-- 2834-- Parameterized types were added in JSR 14. 2835-- 2836--ExplicitConstructorInvocation ::= Primary '.' 'super' '(' ArgumentListopt ')' 2837-- ';' 2838ExplicitConstructorInvocation ::= Primary '.' TypeArgumentsopt 'super' 2839 Arguments ';' 2840\:$MakeQualifiedSuper:\ 2841/.$location 2842void Parser::MakeQualifiedSuper() 2843{ 2844 AstSuperCall* p = ast_pool -> NewSuperCall(); 2845 p -> base_opt = DYNAMIC_CAST<AstExpression*> (Sym(1)); 2846 p -> type_arguments_opt = MakeExplicitTypeArguments(3); 2847 p -> super_token = Token(4); 2848 p -> arguments = DYNAMIC_CAST<AstArguments*> (Sym(5)); 2849 p -> semicolon_token = Token(6); 2850 Sym(1) = p; 2851} 2852./ 2853 2854--1.1 feature 2855-- 2856-- The use of Marker allows us to share code. 2857-- 2858--ExplicitConstructorInvocation ::= Name '.' 'super' '(' ArgumentListopt ')' 2859-- ';' 2860ExplicitConstructorInvocation ::= Name '.' Marker 'super' Arguments ';' 2861\:$MakeQualifiedSuper:\ 2862/.$shared_function 2863// 2864// void MakeQualifiedSuper(); 2865//./ 2866 2867--1.1 feature 2868-- 2869-- Parameterized types were added in JSR 14. 2870-- 2871--ExplicitConstructorInvocation ::= Name '.' 'super' '(' ArgumentListopt ')' 2872-- ';' 2873ExplicitConstructorInvocation ::= Name '.' TypeArguments 'super' Arguments ';' 2874\:$MakeQualifiedSuper:\ 2875/.$shared_function 2876// 2877// void MakeQualifiedSuper(); 2878//./ 2879 2880-- 2881-- Enums were added in JSR 201. We must inline expand Modifiersopt to avoid 2882-- ambiguity. The use of Marker allows us to share code. 2883-- 2884--EnumDeclaration ::= ClassModifiersopt 'enum' 'Identifier' Interfacesopt 2885-- EnumBody 2886EnumDeclaration ::= Marker 'enum' 'Identifier' Interfacesopt EnumBody 2887\:$MakeEnumDeclaration:\ 2888/.$location 2889void Parser::MakeEnumDeclaration() 2890{ 2891 // 2892 // Because of how we handle EnumConstants, the EnumBody production already 2893 // created the AstEnumDeclaration, and populated the class_body field. 2894 // 2895 AstEnumDeclaration* p = DYNAMIC_CAST<AstEnumDeclaration*> (Sym(5)); 2896 p -> modifiers_opt = MakeModifiers(); 2897 p -> enum_token = Token(2); 2898 p -> class_body -> identifier_token = Token(3); 2899 if (Sym(4)) 2900 { 2901 AstListNode* tail = DYNAMIC_CAST<AstListNode*> (Sym(4)); 2902 p -> AllocateInterfaces(tail -> index + 1); 2903 AstListNode* root = tail; 2904 do 2905 { 2906 root = root -> next; 2907 p -> AddInterface(DYNAMIC_CAST<AstTypeName*> (root -> element)); 2908 } while (root != tail); 2909 FreeCircularList(tail); 2910 } 2911 p -> class_body -> identifier_token = Token(3); 2912 Sym(1) = p; 2913} 2914./ 2915 2916-- 2917-- Enums were added in JSR 201. We must inline expand Modifiersopt to avoid 2918-- ambiguity. The use of Marker allows us to share code. 2919-- 2920EnumDeclaration ::= Modifiers 'enum' 'Identifier' Interfacesopt EnumBody 2921\:$MakeEnumDeclaration:\ 2922/.$shared_function 2923// 2924// void MakeEnumDeclaration(); 2925//./ 2926 2927-- 2928-- Enums were added in JSR 201. The rule was expanded inline below to 2929-- make the grammar LALR(1). The use of Marker allows us to share code. 2930-- 2931--EnumBody ::= '{' EnumConstantsopt ,opt EnumBodyDeclarationsopt '}' 2932EnumBody ::= '{' Marker ,opt EnumBodyDeclarationsopt '}' 2933\:$MakeEnumBody:\ 2934/.$location 2935void Parser::MakeEnumBody() 2936{ 2937 // 2938 // The class_body was either created in EnumBodyDeclarations, or we must 2939 // generate it here. 2940 // 2941 AstEnumDeclaration* p = ast_pool -> NewEnumDeclaration(); 2942 if (Sym(2)) 2943 { 2944 AstListNode* tail = DYNAMIC_CAST<AstListNode*> (Sym(2)); 2945 p -> AllocateEnumConstants(tail -> index + 1); 2946 AstListNode* root = tail; 2947 do 2948 { 2949 root = root -> next; 2950 p -> AddEnumConstant(DYNAMIC_CAST<AstEnumConstant*> 2951 (root -> element)); 2952 } while (root != tail); 2953 FreeCircularList(tail); 2954 } 2955 if (Sym(4)) 2956 { 2957 p -> class_body = DYNAMIC_CAST<AstClassBody*> (Sym(4)); 2958 } 2959 else 2960 { 2961 p -> class_body = ast_pool -> NewClassBody(); 2962 p -> class_body -> right_brace_token = Token(5); 2963 p -> class_body -> pool = body_pool; 2964 } 2965 p -> class_body -> left_brace_token = Token(1); 2966 p -> class_body -> owner = p; 2967 Sym(1) = p; 2968} 2969./ 2970 2971-- 2972-- Enums were added in JSR 201. 2973-- 2974EnumBody ::= '{' EnumConstants ,opt EnumBodyDeclarationsopt '}' 2975\:$MakeEnumBody:\ 2976/.$shared_function 2977// 2978// void MakeEnumBody(); 2979//./ 2980 2981-- 2982-- Enums were added in JSR 201. 2983-- 2984EnumConstants ::= EnumConstant 2985\:$StartList:\ 2986/.$shared_StartList./ 2987 2988-- 2989-- Enums were added in JSR 201. 2990-- 2991EnumConstants ::= EnumConstants ',' EnumConstant 2992\:$AddList3:\ 2993/.$shared_AddList3./ 2994 2995-- 2996-- Enums were added in JSR 201. 2997-- 2998EnumConstant ::= Modifiersopt 'Identifier' Argumentsopt ClassBodyopt 2999\:$action:\ 3000/.$location 3001void Parser::Act$rule_number() 3002{ 3003 AstEnumConstant* p = ast_pool -> NewEnumConstant(Token(2)); 3004 p -> modifiers_opt = MakeModifiers(); 3005 p -> arguments_opt = DYNAMIC_CAST<AstArguments*> (Sym(3)); 3006 p -> class_body_opt = DYNAMIC_CAST<AstClassBody*> (Sym(4)); 3007 Sym(1) = p; 3008} 3009./ 3010 3011-- 3012-- Enums were added in JSR 201. As long as enums introduce this production, we 3013-- use it elsewhere, too. 3014-- 3015Arguments ::= '(' ArgumentListopt ')' 3016\:$action:\ 3017/.$location 3018void Parser::Act$rule_number() 3019{ 3020 AstArguments* p = ast_pool -> NewArguments(Token(1), Token(3)); 3021 if (Sym(2)) 3022 { 3023 AstListNode* tail = DYNAMIC_CAST<AstListNode*> (Sym(2)); 3024 p -> AllocateArguments(tail -> index + 1); 3025 AstListNode* root = tail; 3026 do 3027 { 3028 root = root -> next; 3029 p -> AddArgument(DYNAMIC_CAST<AstExpression*> (root -> element)); 3030 } while (root != tail); 3031 FreeCircularList(tail); 3032 } 3033 Sym(1) = p; 3034} 3035./ 3036 3037-- 3038-- Enums were added in JSR 201. 3039-- 3040Argumentsopt ::= $empty 3041\:$NullAction:\ 3042/.$shared_NullAction./ 3043 3044-- 3045-- Enums were added in JSR 201. 3046-- 3047Argumentsopt ::= Arguments 3048\:$NoAction:\ 3049/.$shared_NoAction./ 3050 3051-- 3052-- Enums were added in JSR 201. The use of Marker allows us to share code. 3053-- 3054--EnumBodyDeclarations ::= ';' ClassBodyDeclarationsopt 3055EnumBodyDeclarations ::= ';' ClassBodyDeclarationsopt Marker 3056\:$MakeClassBody:\ 3057/.$shared_function 3058// 3059// void MakeClassBody(); 3060//./ 3061 3062-- 3063-- Enums were added in JSR 201. 3064-- 3065EnumBodyDeclarationsopt ::= $empty 3066\:$NullAction:\ 3067/.$shared_NullAction./ 3068 3069-- 3070-- Enums were added in JSR 201. 3071-- 3072EnumBodyDeclarationsopt ::= EnumBodyDeclarations 3073\:$NoAction:\ 3074/.$shared_NoAction./ 3075 3076--18.9 Productions from 9: Interface Declarations 3077--18.9.1 Productions from 9.1: Interface Declarations 3078-- 3079-- Parameterized types were added in JSR 14. We must inline expand 3080-- Modifiersopt to avoid ambiguity. The use of Marker allows us to share code. 3081-- 3082--InterfaceDeclaration ::= InterfaceModifiersopt 'interface' 'Identifier' 3083-- ExtendsInterfacesopt InterfaceBody 3084InterfaceDeclaration ::= Marker 'interface' 'Identifier' TypeParametersopt 3085 ExtendsInterfacesopt InterfaceBody 3086\:$MakeInterfaceDeclaration:\ 3087/.$location 3088void Parser::MakeInterfaceDeclaration() 3089{ 3090 AstInterfaceDeclaration* p = ast_pool -> NewInterfaceDeclaration(); 3091 p -> modifiers_opt = MakeModifiers(); 3092 p -> interface_token = Token(2); 3093 p -> type_parameters_opt = MakeTypeParameters(4); 3094 if (Sym(5)) 3095 { 3096 AstListNode* tail = DYNAMIC_CAST<AstListNode*> (Sym(5)); 3097 p -> AllocateInterfaces(tail -> index + 1); 3098 AstListNode* root = tail; 3099 do 3100 { 3101 root = root -> next; 3102 p -> AddInterface(DYNAMIC_CAST<AstTypeName*> (root -> element)); 3103 } while (root != tail); 3104 FreeCircularList(tail); 3105 } 3106 p -> class_body = DYNAMIC_CAST<AstClassBody*> (Sym(6)); 3107 p -> class_body -> identifier_token = Token(3); 3108 p -> class_body -> owner = p; 3109 Sym(1) = p; 3110} 3111./ 3112 3113-- 3114-- Parameterized types were added in JSR 14. We must inline expand 3115-- Modifiersopt to avoid ambiguity. 3116-- 3117InterfaceDeclaration ::= Modifiers 'interface' 'Identifier' TypeParametersopt 3118 ExtendsInterfacesopt InterfaceBody 3119\:$MakeInterfaceDeclaration:\ 3120/.$shared_function 3121// 3122// void MakeInterfaceDeclaration(); 3123//./ 3124 3125-- 3126-- Simplify. 3127-- 3128--ExtendsInterfaces ::= 'extends' InterfaceTypeList 3129ExtendsInterfaces ::= 'extends' TypeList 3130\:$SetSym1ToSym2:\ 3131/.$shared_function 3132// 3133// void SetSym1ToSym2(); 3134//./ 3135 3136ExtendsInterfacesopt ::= $empty 3137\:$NullAction:\ 3138/.$shared_NullAction./ 3139 3140ExtendsInterfacesopt ::= ExtendsInterfaces 3141\:$NoAction:\ 3142/.$shared_NoAction./ 3143 3144InterfaceBody ::= '{' InterfaceMemberDeclarationsopt '}' 3145\:$MakeClassBody:\ 3146/.$shared_function 3147// 3148// void MakeClassBody(); 3149//./ 3150 3151InterfaceMemberDeclarations ::= InterfaceMemberDeclaration 3152\:$StartList:\ 3153/.$shared_StartList./ 3154 3155InterfaceMemberDeclarations ::= InterfaceMemberDeclarations 3156 InterfaceMemberDeclaration 3157\:$AddList2:\ 3158/.$shared_AddList2./ 3159 3160InterfaceMemberDeclarationsopt ::= $empty 3161\:$NullAction:\ 3162/.$shared_NullAction./ 3163 3164InterfaceMemberDeclarationsopt ::= InterfaceMemberDeclarations 3165\:$NoAction:\ 3166/.$shared_NoAction./ 3167 3168-- 3169-- 3170-- For less code duplication and better semantic messages, we parse 3171-- non-abstract method bodies and non-initialized fields now, then do a 3172-- semantic check that this was valid. 3173-- 3174InterfaceMemberDeclaration ::= ConstantDeclaration 3175\:$NoAction:\ 3176/.$shared_NoAction./ 3177 3178-- 3179-- Simplify. See below. 3180-- 3181--InterfaceMemberDeclaration ::= AbstractMethodDeclaration 3182 3183--1.1 feature 3184-- 3185-- Consolidate and simplify. 3186-- 3187--InterfaceMemberDeclaration ::= ClassDeclaration 3188--InterfaceMemberDeclaration ::= InterfaceDeclaration 3189--InterfaceMemberDeclaration ::= ';' 3190InterfaceMemberDeclaration ::= TypeDeclaration 3191\:$NoAction:\ 3192/.$shared_NoAction./ 3193 3194ConstantDeclaration ::= FieldDeclaration 3195\:$action:\ 3196/.$location 3197void Parser::Act$rule_number() 3198{ 3199 DYNAMIC_CAST<AstFieldDeclaration*> (Sym(1)) -> MarkStatic(); 3200} 3201./ 3202 3203-- 3204-- Simplify. 3205-- 3206--AbstractMethodDeclaration ::= MethodHeader ';' 3207InterfaceMemberDeclaration ::= MethodDeclaration 3208\:$NoAction:\ 3209/.$shared_NoAction./ 3210 3211-- 3212-- Annotations were added in JSR 175. We must inline expand Modifiersopt to 3213-- avoid ambiguity: does 'public @' start 'public @A class B{}' or 3214-- 'public @interface A{}'. The use of Marker allows us to share code. 3215-- 3216--AnnotationTypeDeclaration ::= InterfaceModifiersopt '@' 'interface' 3217-- 'Identifier' AnnotationTypeBody 3218AnnotationTypeDeclaration ::= '@' Marker 'interface' 'Identifier' 3219 AnnotationTypeBody 3220\:$MakeAnnotationTypeDeclaration:\ 3221/.$location 3222void Parser::MakeAnnotationTypeDeclaration() 3223{ 3224 AstAnnotationDeclaration* p = 3225 ast_pool -> NewAnnotationDeclaration(Token(3)); 3226 if (Token(3) > Token(2)) 3227 p -> modifiers_opt = MakeModifiers(); 3228 p -> class_body = DYNAMIC_CAST<AstClassBody*> (Sym(5)); 3229 p -> class_body -> identifier_token = Token(4); 3230 p -> class_body -> owner = p; 3231 Sym(1) = p; 3232} 3233./ 3234 3235-- Annotations were added in JSR 175. We must inline expand Modifiersopt to 3236-- avoid ambiguity: does 'public @' start 'public @A class B{}' or 3237-- 'public @interface A{}'. 3238-- 3239AnnotationTypeDeclaration ::= Modifiers '@' 'interface' 'Identifier' 3240 AnnotationTypeBody 3241\:$MakeAnnotationTypeDeclaration:\ 3242/.$shared_function 3243// 3244// void MakeAnnotationTypeDeclaration(); 3245//./ 3246 3247-- 3248-- Annotations were added in JSR 175. 3249-- 3250AnnotationTypeBody ::= '{' AnnotationTypeMemberDeclarationsopt '}' 3251\:$MakeClassBody:\ 3252/.$shared_function 3253// 3254// void MakeClassBody(); 3255//./ 3256 3257-- 3258-- Annotations were added in JSR 175. 3259-- 3260AnnotationTypeMemberDeclarations ::= AnnotationTypeMemberDeclaration 3261\:$StartList:\ 3262/.$shared_StartList./ 3263 3264-- 3265-- Annotations were added in JSR 175. 3266-- 3267AnnotationTypeMemberDeclarations ::= AnnotationTypeMemberDeclarations 3268 AnnotationTypeMemberDeclaration 3269\:$AddList2:\ 3270/.$shared_AddList2./ 3271 3272-- 3273-- Annotations were added in JSR 175. 3274-- 3275AnnotationTypeMemberDeclarationsopt ::= $empty 3276\:$NullAction:\ 3277/.$shared_NullAction./ 3278 3279-- 3280-- Annotations were added in JSR 175. 3281-- 3282AnnotationTypeMemberDeclarationsopt ::= AnnotationTypeMemberDeclarations 3283\:$NoAction:\ 3284/.$shared_NoAction./ 3285 3286-- 3287-- Annotations were added in JSR 175. We must inline expand Modifiersopt to 3288-- avoid ambiguity. The use of Marker allows us to share code. 3289-- 3290--AnnotationTypeMemberDeclaration ::= AbstractMethodModifiersopt Type 3291-- 'Identifier' '(' ')' DefaultValueopt ';' 3292AnnotationTypeMemberDeclaration ::= Marker Marker Type 'Identifier' '(' ')' 3293 DefaultValueopt ';' 3294\:$MakeAnnotationTypeMemberDeclaration:\ 3295/.$location 3296void Parser::MakeAnnotationTypeMemberDeclaration() 3297{ 3298 AstMethodDeclaration* p = ast_pool -> NewMethodDeclaration(); 3299 p -> modifiers_opt = MakeModifiers(); 3300 p -> type = DYNAMIC_CAST<AstType*> (Sym(3)); 3301 AstMethodDeclarator* q = ast_pool -> NewMethodDeclarator(); 3302 q -> identifier_token = Token(4); 3303 q -> left_parenthesis_token = Token(5); 3304 q -> right_parenthesis_token = Token(6); 3305 p -> method_declarator = q; 3306 p -> default_value_opt = DYNAMIC_CAST<AstMemberValue*> (Sym(7)); 3307 p -> semicolon_token_opt = Token(8); 3308 Sym(1) = p; 3309} 3310./ 3311 3312-- 3313-- Annotations were added in JSR 175. We must inline expand Modifiersopt to 3314-- avoid ambiguity. 3315-- 3316AnnotationTypeMemberDeclaration ::= Modifiers Marker Type 'Identifier' '(' ')' 3317 DefaultValueopt ';' 3318\:$MakeAnnotationTypeMemberDeclaration:\ 3319/.$shared_function 3320// 3321// void MakeAnnotationTypeMemberDeclaration(); 3322//./ 3323 3324-- 3325-- Annotations were added in JSR 175. 3326-- 3327AnnotationTypeMemberDeclaration ::= ConstantDeclaration 3328\:$NoAction:\ 3329/.$shared_NoAction./ 3330 3331-- 3332-- Annotations were added in JSR 175. Consolidate and simplify. 3333-- 3334--AnnotationTypeMemberDeclaration ::= ClassDeclaration 3335--AnnotationTypeMemberDeclaration ::= InterfaceDeclaration 3336--AnnotationTypeMemberDeclaration ::= EnumDeclaration 3337--AnnotationTypeMemberDeclaration ::= AnnotationTypeDeclaration 3338--AnnotationTypeMemberDeclaration ::= ';' 3339AnnotationTypeMemberDeclaration ::= TypeDeclaration 3340\:$NoAction:\ 3341/.$shared_NoAction./ 3342 3343-- 3344-- Annotations were added in JSR 175. 3345-- 3346DefaultValue ::= 'default' MemberValue 3347\:$SetSym1ToSym2:\ 3348/.$shared_function 3349// 3350// void SetSym1ToSym2(); 3351//./ 3352 3353-- 3354-- Annotations were added in JSR 175. 3355-- 3356DefaultValueopt ::= $empty 3357\:$NullAction:\ 3358/.$shared_NullAction./ 3359 3360-- 3361-- Annotations were added in JSR 175. 3362-- 3363DefaultValueopt ::= DefaultValue 3364\:$NoAction:\ 3365/.$shared_NoAction./ 3366 3367--18.10 Productions from 10: Arrays 3368-- 3369-- The rule VariableInitializersopt was expanded inline below to make the 3370-- grammar LALR(1). The use of Marker allows us to share code. 3371-- 3372-- ArrayInitializer ::= '{' VariableInitializersopt ,opt '}' 3373ArrayInitializer ::= '{' Marker ,opt '}' 3374\:$MakeArrayInitializer:\ 3375/.$shared_function 3376// 3377// void MakeArrayInitializer(); 3378//./ 3379 3380ArrayInitializer ::= '{' VariableInitializers ,opt '}' 3381\:$MakeArrayInitializer:\ 3382/.$shared_function 3383// 3384// void MakeArrayInitializer(); 3385//./ 3386 3387VariableInitializers ::= VariableInitializer 3388\:$StartList:\ 3389/.$shared_StartList./ 3390 3391VariableInitializers ::= VariableInitializers ',' VariableInitializer 3392\:$AddList3:\ 3393/.$shared_AddList3./ 3394 3395--18.11 Productions from 13: Blocks and Statements 3396 3397Block ::= '{' BlockStatementsopt '}' 3398\:$action:\ 3399/.$location 3400void Parser::Act$rule_number() 3401{ 3402 AstBlock* p = ast_pool -> NewBlock(); 3403 p -> left_brace_token = Token(1); 3404 if (Sym(2)) 3405 { 3406 AstListNode* tail = DYNAMIC_CAST<AstListNode*> (Sym(2)); 3407 p -> AllocateStatements(tail -> index + 1); 3408 AstListNode* root = tail; 3409 do 3410 { 3411 root = root -> next; 3412 p -> AddStatement(DYNAMIC_CAST<AstStatement*> (root -> element)); 3413 } while (root != tail); 3414 FreeCircularList(tail); 3415 } 3416 p -> right_brace_token = Token(3); 3417 Sym(1) = p; 3418} 3419./ 3420 3421BlockStatements ::= BlockStatement 3422\:$StartList:\ 3423/.$shared_StartList./ 3424 3425BlockStatements ::= BlockStatements BlockStatement 3426\:$AddList2:\ 3427/.$shared_AddList2./ 3428 3429BlockStatementsopt ::= $empty 3430\:$NullAction:\ 3431/.$shared_NullAction./ 3432 3433BlockStatementsopt ::= BlockStatements 3434\:$NoAction:\ 3435/.$shared_NoAction./ 3436 3437BlockStatement ::= LocalVariableDeclarationStatement 3438\:$NoAction:\ 3439/.$shared_NoAction./ 3440 3441BlockStatement ::= Statement 3442\:$NoAction:\ 3443/.$shared_NoAction./ 3444 3445--1.1 feature 3446BlockStatement ::= ClassDeclaration 3447\:$action:\ 3448/.$location 3449void Parser::Act$rule_number() 3450{ 3451 Sym(1) = ast_pool -> 3452 NewLocalClassStatement(DYNAMIC_CAST<AstClassDeclaration*> (Sym(1))); 3453} 3454./ 3455 3456-- 3457-- Enums were added in JSR 201. 3458-- 3459BlockStatement ::= EnumDeclaration 3460\:$action:\ 3461/.$location 3462void Parser::Act$rule_number() 3463{ 3464 Sym(1) = ast_pool -> 3465 NewLocalClassStatement(DYNAMIC_CAST<AstEnumDeclaration*> (Sym(1))); 3466} 3467./ 3468 3469-- 3470-- NOTE: This rule is not in the original grammar. We added it, and changed 3471-- the rule for ConstructorBody, in order to issue a nicer error message 3472-- when this() or super() is encountered out of context. 3473-- 3474BlockStatement ::= ExplicitConstructorInvocation 3475\:$NoAction:\ 3476/.$shared_NoAction./ 3477 3478LocalVariableDeclarationStatement ::= LocalVariableDeclaration ';' 3479\:$action:\ 3480/.$location 3481void Parser::Act$rule_number() 3482{ 3483 DYNAMIC_CAST<AstLocalVariableStatement*> (Sym(1)) -> semicolon_token_opt = 3484 Token(2); 3485} 3486./ 3487 3488-- 3489-- For nicer error messages, we accept all modifiers, even though only 3490-- 'final' and annotations are valid. Also, we must inline expand finalopt 3491-- to avoid ambiguity. The use of Marker allows us to share code. 3492-- 3493--LocalVariableDeclaration ::= finalopt Type VariableDeclarators 3494LocalVariableDeclaration ::= Type Marker Marker VariableDeclarators 3495\:$MakeLocalVariable:\ 3496/.$location 3497void Parser::MakeLocalVariable() 3498{ 3499 AstLocalVariableStatement* p = ast_pool -> NewLocalVariableStatement(); 3500 if (Sym(2)) 3501 { 3502 p -> modifiers_opt = MakeModifiers(); 3503 p -> type = DYNAMIC_CAST<AstType*> (Sym(2)); 3504 } 3505 else p -> type = DYNAMIC_CAST<AstType*> (Sym(1)); 3506 AstListNode* tail = DYNAMIC_CAST<AstListNode*> (Sym(4)); 3507 p -> AllocateVariableDeclarators(tail -> index + 1); 3508 AstListNode* root = tail; 3509 do 3510 { 3511 root = root -> next; 3512 p -> AddVariableDeclarator(DYNAMIC_CAST<AstVariableDeclarator*> 3513 (root -> element)); 3514 } while (root != tail); 3515 FreeCircularList(tail); 3516 Sym(1) = p; 3517} 3518./ 3519 3520--1.1 feature 3521-- 3522-- For nicer error messages, we accept all modifiers, even though only 3523-- 'final' and annotations are valid. Also, we must inline expand finalopt 3524-- to avoid ambiguity. The use of Marker allows us to share code. 3525-- 3526--LocalVariableDeclaration ::= final Type VariableDeclarators 3527LocalVariableDeclaration ::= Modifiers Type Marker VariableDeclarators 3528\:$MakeLocalVariable:\ 3529/.$shared_function 3530// 3531// void MakeLocalVariable(); 3532//./ 3533 3534Statement ::= StatementWithoutTrailingSubstatement 3535\:$NoAction:\ 3536/.$shared_NoAction./ 3537 3538Statement ::= LabeledStatement 3539\:$NoAction:\ 3540/.$shared_NoAction./ 3541 3542Statement ::= IfThenStatement 3543\:$NoAction:\ 3544/.$shared_NoAction./ 3545 3546Statement ::= IfThenElseStatement 3547\:$NoAction:\ 3548/.$shared_NoAction./ 3549 3550Statement ::= WhileStatement 3551\:$NoAction:\ 3552/.$shared_NoAction./ 3553 3554Statement ::= ForStatement 3555\:$NoAction:\ 3556/.$shared_NoAction./ 3557 3558-- 3559-- Enhanced for statements (also known as foreach, but without a new keyword), 3560-- were added in JDK 1.5, as part of JSR 201. 3561-- 3562Statement ::= ForeachStatement 3563\:$NoAction:\ 3564/.$shared_NoAction./ 3565 3566StatementNoShortIf ::= StatementWithoutTrailingSubstatement 3567\:$NoAction:\ 3568/.$shared_NoAction./ 3569 3570StatementNoShortIf ::= LabeledStatementNoShortIf 3571\:$NoAction:\ 3572/.$shared_NoAction./ 3573 3574StatementNoShortIf ::= IfThenElseStatementNoShortIf 3575\:$NoAction:\ 3576/.$shared_NoAction./ 3577 3578StatementNoShortIf ::= WhileStatementNoShortIf 3579\:$NoAction:\ 3580/.$shared_NoAction./ 3581 3582StatementNoShortIf ::= ForStatementNoShortIf 3583\:$NoAction:\ 3584/.$shared_NoAction./ 3585 3586-- 3587-- Enhanced for statements (also known as foreach, but without a new keyword), 3588-- were added in JDK 1.5, as part of JSR 201. 3589-- 3590StatementNoShortIf ::= ForeachStatementNoShortIf 3591\:$NoAction:\ 3592/.$shared_NoAction./ 3593 3594StatementWithoutTrailingSubstatement ::= Block 3595\:$NoAction:\ 3596/.$shared_NoAction./ 3597 3598StatementWithoutTrailingSubstatement ::= EmptyStatement 3599\:$NoAction:\ 3600/.$shared_NoAction./ 3601 3602StatementWithoutTrailingSubstatement ::= ExpressionStatement 3603\:$NoAction:\ 3604/.$shared_NoAction./ 3605 3606StatementWithoutTrailingSubstatement ::= SwitchStatement 3607\:$NoAction:\ 3608/.$shared_NoAction./ 3609 3610StatementWithoutTrailingSubstatement ::= DoStatement 3611\:$NoAction:\ 3612/.$shared_NoAction./ 3613 3614StatementWithoutTrailingSubstatement ::= BreakStatement 3615\:$NoAction:\ 3616/.$shared_NoAction./ 3617 3618StatementWithoutTrailingSubstatement ::= ContinueStatement 3619\:$NoAction:\ 3620/.$shared_NoAction./ 3621 3622StatementWithoutTrailingSubstatement ::= ReturnStatement 3623\:$NoAction:\ 3624/.$shared_NoAction./ 3625 3626StatementWithoutTrailingSubstatement ::= SynchronizedStatement 3627\:$NoAction:\ 3628/.$shared_NoAction./ 3629 3630StatementWithoutTrailingSubstatement ::= ThrowStatement 3631\:$NoAction:\ 3632/.$shared_NoAction./ 3633 3634StatementWithoutTrailingSubstatement ::= TryStatement 3635\:$NoAction:\ 3636/.$shared_NoAction./ 3637 3638StatementWithoutTrailingSubstatement ::= AssertStatement 3639\:$NoAction:\ 3640/.$shared_NoAction./ 3641 3642EmptyStatement ::= ';' 3643\:$action:\ 3644/.$location 3645void Parser::Act$rule_number() 3646{ 3647 Sym(1) = ast_pool -> NewEmptyStatement(Token(1)); 3648} 3649./ 3650 3651LabeledStatement ::= 'Identifier' ':' Statement 3652\:$MakeLabeledStatement:\ 3653/.$location 3654void Parser::MakeLabeledStatement() 3655{ 3656 AstBlock* p = Sym(3) -> BlockCast(); 3657 3658 if (! p || p -> label_opt) 3659 { 3660 // 3661 // When a statement is labeled, it is enclosed in a block. 3662 // This is necessary in order to allow the same name to be 3663 // reused to label a subsequent statement at the same nesting 3664 // level... See ProcessBlock, ProcessStatement,... 3665 // 3666 p = ast_pool -> GenBlock(); 3667 p -> AllocateStatements(1); // allocate 1 element 3668 p -> left_brace_token = Token(1); 3669 p -> AddStatement(DYNAMIC_CAST<AstStatement*> (Sym(3))); 3670 p -> right_brace_token = Sym(3) -> RightToken(); 3671 } 3672 3673 p -> label_opt = Token(1); // add label to statement 3674 Sym(1) = p; // The final result is a block containing the labeled-statement 3675} 3676./ 3677 3678LabeledStatementNoShortIf ::= 'Identifier' ':' StatementNoShortIf 3679\:$MakeLabeledStatement:\ 3680/.$shared_function 3681// 3682// void MakeLabeledStatement(); 3683//./ 3684 3685ExpressionStatement ::= StatementExpression ';' 3686\:$action:\ 3687/.$location 3688void Parser::Act$rule_number() 3689{ 3690 DYNAMIC_CAST<AstExpressionStatement*> (Sym(1)) -> semicolon_token_opt = 3691 Token(2); 3692} 3693./ 3694 3695StatementExpression ::= Assignment 3696\:$MakeExpressionStatement:\ 3697/.$location 3698void Parser::MakeExpressionStatement() 3699{ 3700 AstExpressionStatement* p = ast_pool -> NewExpressionStatement(); 3701 p -> expression = DYNAMIC_CAST<AstExpression*> (Sym(1)); 3702 Sym(1) = p; 3703} 3704./ 3705 3706StatementExpression ::= PreIncrementExpression 3707\:$MakeExpressionStatement:\ 3708/.$shared_function 3709// 3710// void MakeExpressionStatement(); 3711//./ 3712 3713StatementExpression ::= PreDecrementExpression 3714\:$MakeExpressionStatement:\ 3715/.$shared_function 3716// 3717// void MakeExpressionStatement(); 3718//./ 3719 3720StatementExpression ::= PostIncrementExpression 3721\:$MakeExpressionStatement:\ 3722/.$shared_function 3723// 3724// void MakeExpressionStatement(); 3725//./ 3726 3727StatementExpression ::= PostDecrementExpression 3728\:$MakeExpressionStatement:\ 3729/.$shared_function 3730// 3731// void MakeExpressionStatement(); 3732//./ 3733 3734StatementExpression ::= MethodInvocation 3735\:$MakeExpressionStatement:\ 3736/.$shared_function 3737// 3738// void MakeExpressionStatement(); 3739//./ 3740 3741StatementExpression ::= ClassInstanceCreationExpression 3742\:$MakeExpressionStatement:\ 3743/.$shared_function 3744// 3745// void MakeExpressionStatement(); 3746//./ 3747 3748-- 3749-- The use of Marker allows us to share code. 3750-- 3751--IfThenStatement ::= 'if' '(' Expression ')' Statement 3752IfThenStatement ::= 'if' '(' Expression ')' Statement Marker Marker 3753\:$MakeIfThenElseStatement:\ 3754/.$location 3755void Parser::MakeIfThenElseStatement() 3756{ 3757 // 3758 // We wrap the true and false statements in a block, to make the semantic 3759 // pass easier. 3760 // 3761 AstIfStatement* p = ast_pool -> NewIfStatement(); 3762 p -> if_token = Token(1); 3763 p -> expression = DYNAMIC_CAST<AstExpression*> (Sym(3)); 3764 p -> true_statement = MakeBlock(5); 3765 p -> false_statement_opt = Sym(7) ? MakeBlock(7) : NULL; 3766 Sym(1) = p; 3767} 3768 3769// 3770// Ensures the symbol at tokennum is an AstBlock (wrapping it in a generated 3771// block if necessary). 3772// 3773AstBlock* Parser::MakeBlock(int tokennum) 3774{ 3775 AstBlock* block = Sym(tokennum) -> BlockCast(); 3776 if (! block) 3777 { 3778 block = ast_pool -> GenBlock(); 3779 block -> AllocateStatements(1); // allocate 1 element 3780 block -> left_brace_token = Token(tokennum); 3781 block -> AddStatement(DYNAMIC_CAST<AstStatement*> (Sym(tokennum))); 3782 block -> right_brace_token = Sym(tokennum) -> RightToken(); 3783 } 3784 return block; 3785} 3786./ 3787 3788IfThenElseStatement ::= 'if' '(' Expression ')' StatementNoShortIf 3789 'else' Statement 3790\:$MakeIfThenElseStatement:\ 3791/.$shared_function 3792// 3793// void MakeIfThenElseStatement(); 3794//./ 3795 3796IfThenElseStatementNoShortIf ::= 'if' '(' Expression ')' StatementNoShortIf 3797 'else' StatementNoShortIf 3798\:$MakeIfThenElseStatement:\ 3799/.$shared_function 3800// 3801// void MakeIfThenElseStatement(); 3802//./ 3803 3804SwitchStatement ::= 'switch' '(' Expression ')' SwitchBlock 3805\:$action:\ 3806/.$location 3807void Parser::Act$rule_number() 3808{ 3809 AstSwitchStatement* p = DYNAMIC_CAST<AstSwitchStatement*> (Sym(5)); 3810 p -> switch_token = Token(1); 3811 p -> expression = DYNAMIC_CAST<AstExpression*> (Sym(3)); 3812 Sym(1) = p; 3813} 3814./ 3815 3816-- 3817-- To avoid ambiguity with consecutive optional items, and to special 3818-- case trailing labels, we expand this inline. 3819-- 3820--SwitchBlock ::= '{' SwitchBlockStatementsopt SwitchLabelsopt '}' 3821-- 3822SwitchBlock ::= '{' SwitchBlockStatements SwitchLabelsopt '}' 3823\:$action:\ 3824/.$location 3825void Parser::Act$rule_number() 3826{ 3827 AstSwitchStatement* p = ast_pool -> NewSwitchStatement(); 3828 AstBlock* block = ast_pool -> NewBlock(); 3829 block -> left_brace_token = Token(1); 3830 AstListNode* tail = DYNAMIC_CAST<AstListNode*> (Sym(2)); 3831 block -> AllocateStatements(tail -> index + (Sym(3) ? 2 : 1)); 3832 AstListNode* root = tail; 3833 do 3834 { 3835 root = root -> next; 3836 block -> AddStatement(DYNAMIC_CAST<AstStatement*> (root -> element)); 3837 } while (root != tail); 3838 FreeCircularList(tail); 3839 if (Sym(3)) 3840 block -> AddStatement 3841 (MakeSwitchBlockStatement(DYNAMIC_CAST<AstListNode*> (Sym(3)))); 3842 block -> right_brace_token = Token(4); 3843 block -> SetTag(AstBlock::SWITCH); 3844 p -> switch_block = block; 3845 Sym(1) = p; 3846} 3847 3848// 3849// Creates an AstSwitchBlockStatement from the given non-null labels, and 3850// possibly null list of statements. 3851// 3852AstStatement* Parser::MakeSwitchBlockStatement(AstListNode* labels, 3853 AstListNode* statements) 3854{ 3855 AstSwitchBlockStatement* p = ast_pool -> NewSwitchBlockStatement(); 3856 assert(labels); 3857 AstListNode* tail = labels; 3858 p -> AllocateSwitchLabels(tail -> index + 1); 3859 AstListNode* root = tail; 3860 do 3861 { 3862 root = root -> next; 3863 p -> AddSwitchLabel(DYNAMIC_CAST<AstSwitchLabel*> (root -> element)); 3864 } while (root != tail); 3865 FreeCircularList(tail); 3866 if (statements) 3867 { 3868 tail = statements; 3869 p -> AllocateStatements(tail -> index + 1); 3870 root = tail; 3871 do 3872 { 3873 root = root -> next; 3874 p -> AddStatement(DYNAMIC_CAST<AstStatement*> (root -> element)); 3875 } while (root != tail); 3876 FreeCircularList(tail); 3877 } 3878 else 3879 { 3880 p -> AllocateStatements(1); 3881 p -> AddStatement(ast_pool -> GenEmptyStatement(labels -> 3882 RightToken())); 3883 } 3884 p -> right_brace_token = 3885 p -> Statement(p -> NumStatements() - 1) -> RightToken(); 3886 return p; 3887} 3888./ 3889 3890SwitchBlock ::= '{' SwitchLabelsopt '}' 3891\:$action:\ 3892/.$location 3893void Parser::Act$rule_number() 3894{ 3895 AstSwitchStatement* p = ast_pool -> NewSwitchStatement(); 3896 AstBlock* block = ast_pool -> NewBlock(); 3897 block -> AllocateStatements(1); // allocate 1 element 3898 block -> left_brace_token = Token(1); 3899 if (Sym(2)) 3900 block -> AddStatement 3901 (MakeSwitchBlockStatement(DYNAMIC_CAST<AstListNode*> (Sym(2)))); 3902 block -> right_brace_token = Token(3); 3903 block -> SetTag(AstBlock::SWITCH); 3904 3905 p -> switch_block = block; 3906 3907 Sym(1) = p; 3908} 3909./ 3910 3911SwitchBlockStatements ::= SwitchBlockStatement 3912\:$StartList:\ 3913/.$shared_StartList./ 3914 3915SwitchBlockStatements ::= SwitchBlockStatements SwitchBlockStatement 3916\:$AddList2:\ 3917/.$shared_AddList2./ 3918 3919SwitchBlockStatement ::= SwitchLabels BlockStatements 3920\:$action:\ 3921/.$location 3922void Parser::Act$rule_number() 3923{ 3924 Sym(1) = MakeSwitchBlockStatement(DYNAMIC_CAST<AstListNode*> (Sym(1)), 3925 DYNAMIC_CAST<AstListNode*> (Sym(2))); 3926} 3927./ 3928 3929SwitchLabels ::= SwitchLabel 3930\:$StartList:\ 3931/.$shared_StartList./ 3932 3933SwitchLabels ::= SwitchLabels SwitchLabel 3934\:$AddList2:\ 3935/.$shared_AddList2./ 3936 3937SwitchLabelsopt ::= $empty 3938\:$NullAction:\ 3939/.$shared_NullAction./ 3940 3941SwitchLabelsopt ::= SwitchLabels 3942\:$NoAction:\ 3943/.$shared_NoAction./ 3944 3945-- 3946-- Simplify. 3947-- 3948--SwitchLabel ::= 'case' ConstantExpression ':' 3949SwitchLabel ::= 'case' Expression ':' 3950\:$MakeSwitchLabel:\ 3951/.$location 3952void Parser::MakeSwitchLabel() 3953{ 3954 AstSwitchLabel* p = ast_pool -> NewSwitchLabel(); 3955 p -> case_token = Token(1); 3956 p -> expression_opt = DYNAMIC_CAST<AstExpression*> (Sym(2)); 3957 p -> colon_token = Token(3); 3958 Sym(1) = p; 3959} 3960./ 3961 3962-- 3963-- The use of Marker allows us to share code. 3964-- 3965--SwitchLabel ::= 'default' ':' 3966SwitchLabel ::= 'default' Marker ':' 3967\:$MakeSwitchLabel:\ 3968/.$shared_function 3969// 3970// void MakeSwitchLabel(); 3971//./ 3972 3973WhileStatement ::= 'while' '(' Expression ')' Statement 3974\:$MakeWhileStatement:\ 3975/.$location 3976void Parser::MakeWhileStatement() 3977{ 3978 // 3979 // We wrap the loop statement in a block, to make the semantic pass easier. 3980 // 3981 AstWhileStatement* p = ast_pool -> NewWhileStatement(); 3982 p -> while_token = Token(1); 3983 p -> expression = DYNAMIC_CAST<AstExpression*> (Sym(3)); 3984 p -> statement = MakeBlock(5); 3985 3986 // 3987 // We also wrap the loop in a block, to make the semantic pass easier. 3988 // 3989 AstBlock* block = ast_pool -> GenBlock(); 3990 block -> AllocateStatements(1); // allocate 1 element 3991 block -> left_brace_token = Token(1); 3992 block -> AddStatement(p); 3993 block -> right_brace_token = Sym(5) -> RightToken(); 3994 Sym(1) = block; 3995} 3996./ 3997 3998WhileStatementNoShortIf ::= 'while' '(' Expression ')' StatementNoShortIf 3999\:$MakeWhileStatement:\ 4000/.$shared_function 4001// 4002// void MakeWhileStatement(); 4003//./ 4004 4005DoStatement ::= 'do' Statement 'while' '(' Expression ')' ';' 4006\:$action:\ 4007/.$location 4008void Parser::Act$rule_number() 4009{ 4010 // 4011 // We wrap the loop statement in a block, to make the semantic pass easier. 4012 // 4013 AstDoStatement* p = ast_pool -> NewDoStatement(); 4014 p -> do_token = Token(1); 4015 p -> statement = MakeBlock(2); 4016 p -> while_token = Token(3); 4017 p -> expression = DYNAMIC_CAST<AstExpression*> (Sym(5)); 4018 p -> semicolon_token = Token(7); 4019 4020 // 4021 // We also wrap the loop in a block, to make the semantic pass easier. 4022 // 4023 AstBlock* block = ast_pool -> GenBlock(); 4024 block -> AllocateStatements(1); // allocate 1 element 4025 block -> left_brace_token = Token(1); 4026 block -> AddStatement(p); 4027 block -> right_brace_token = Token(7); 4028 Sym(1) = block; 4029} 4030./ 4031 4032ForStatement ::= 'for' '(' ForInitopt ';' Expressionopt ';' ForUpdateopt ')' 4033 Statement 4034\:$MakeForStatement:\ 4035/.$location 4036void Parser::MakeForStatement() 4037{ 4038 // 4039 // We wrap the loop statement in a block, to make the semantic pass easier. 4040 // 4041 AstForStatement* p = ast_pool -> NewForStatement(); 4042 p -> for_token = Token(1); 4043 if (Sym(3)) 4044 { 4045 AstListNode* tail = DYNAMIC_CAST<AstListNode*> (Sym(3)); 4046 p -> AllocateForInitStatements(tail -> index + 1); 4047 AstListNode* root = tail; 4048 do 4049 { 4050 root = root -> next; 4051 p -> AddForInitStatement(DYNAMIC_CAST<AstStatement*> 4052 (root -> element)); 4053 } while (root != tail); 4054 FreeCircularList(tail); 4055 } 4056 p -> end_expression_opt = DYNAMIC_CAST<AstExpression*> (Sym(5)); 4057 if (Sym(7)) 4058 { 4059 AstListNode* tail = DYNAMIC_CAST<AstListNode*> (Sym(7)); 4060 p -> AllocateForUpdateStatements(tail -> index + 1); 4061 AstListNode* root = tail; 4062 do 4063 { 4064 root = root -> next; 4065 p -> AddForUpdateStatement(DYNAMIC_CAST<AstExpressionStatement*> 4066 (root -> element)); 4067 } while (root != tail); 4068 FreeCircularList(tail); 4069 } 4070 p -> statement = MakeBlock(9); 4071 4072 // 4073 // We also wrap the loop in a block, to make the semantic pass easier. In 4074 // particular, this lets us correctly handle "for(int i;;);for(int i;;);". 4075 // 4076 AstBlock* block = ast_pool -> NewBlock(); 4077 block -> AllocateStatements(1); // allocate 1 element 4078 block -> left_brace_token = Token(1); 4079 block -> AddStatement(p); 4080 block -> right_brace_token = Sym(9) -> RightToken(); 4081 block -> no_braces = true; 4082 Sym(1) = block; 4083} 4084./ 4085 4086ForStatementNoShortIf ::= 'for' '(' ForInitopt ';' Expressionopt ';' 4087 ForUpdateopt ')' StatementNoShortIf 4088\:$MakeForStatement:\ 4089/.$shared_function 4090// 4091// void MakeForStatement(); 4092//./ 4093 4094ForInit ::= StatementExpressionList 4095\:$NoAction:\ 4096/.$shared_NoAction./ 4097 4098ForInit ::= LocalVariableDeclaration 4099\:$StartList:\ 4100/.$shared_StartList./ 4101 4102ForInitopt ::= $empty 4103\:$NullAction:\ 4104/.$shared_NullAction./ 4105 4106ForInitopt ::= ForInit 4107\:$NoAction:\ 4108/.$shared_NoAction./ 4109 4110ForUpdate ::= StatementExpressionList 4111\:$NoAction:\ 4112/.$shared_NoAction./ 4113 4114ForUpdateopt ::= $empty 4115\:$NullAction:\ 4116/.$shared_NullAction./ 4117 4118ForUpdateopt ::= ForUpdate 4119\:$NoAction:\ 4120/.$shared_NoAction./ 4121 4122StatementExpressionList ::= StatementExpression 4123\:$StartList:\ 4124/.$shared_StartList./ 4125 4126StatementExpressionList ::= StatementExpressionList ',' StatementExpression 4127\:$AddList3:\ 4128/.$shared_AddList3./ 4129 4130ForeachStatement ::= 'for' '(' FormalParameter ':' Expression ')' Statement 4131\:$MakeForeachStatement:\ 4132/.$location 4133void Parser::MakeForeachStatement() 4134{ 4135 // 4136 // We wrap the loop statement in a block, to make the semantic pass easier. 4137 // 4138 AstForeachStatement* p = ast_pool -> NewForeachStatement(); 4139 p -> for_token = Token(1); 4140 p -> formal_parameter = DYNAMIC_CAST<AstFormalParameter*> (Sym(3)); 4141 p -> expression = DYNAMIC_CAST<AstExpression*> (Sym(5)); 4142 p -> statement = MakeBlock(7); 4143 4144 // 4145 // We also wrap the loop in a block, to make the semantic pass easier. In 4146 // particular, this lets us correctly handle 4147 // "for(int i:new int[0]);for(int i::new int[0]);". 4148 // 4149 AstBlock* block = ast_pool -> NewBlock(); 4150 block -> AllocateStatements(1); // allocate 1 element 4151 block -> left_brace_token = Token(1); 4152 block -> AddStatement(p); 4153 block -> right_brace_token = Sym(7) -> RightToken(); 4154 block -> no_braces = true; 4155 Sym(1) = block; 4156} 4157./ 4158 4159ForeachStatementNoShortIf ::= 'for' '(' FormalParameter ':' Expression ')' 4160 StatementNoShortIf 4161\:$MakeForeachStatement:\ 4162/.$shared_function 4163// 4164// void MakeForeachStatement(); 4165//./ 4166 4167-- 4168-- Assert statements were added in JDK 1.4, as part of JSR 41. 4169-- The use of Marker allows us to share code. 4170-- 4171--AssertStatement ::= 'assert' Expression ';' 4172AssertStatement ::= 'assert' Expression Marker Marker ';' 4173\:$MakeAssertStatement:\ 4174/.$location 4175void Parser::MakeAssertStatement() 4176{ 4177 AstAssertStatement* p = ast_pool -> NewAssertStatement(); 4178 p -> assert_token = Token(1); 4179 p -> condition = DYNAMIC_CAST<AstExpression*> (Sym(2)); 4180 p -> message_opt = DYNAMIC_CAST<AstExpression*> (Sym(4)); 4181 p -> semicolon_token = Token(5); 4182 Sym(1) = p; 4183} 4184./ 4185 4186AssertStatement ::= 'assert' Expression ':' Expression ';' 4187\:$MakeAssertStatement:\ 4188/.$shared_function 4189// 4190// void MakeAssertStatement(); 4191//./ 4192 4193BreakStatement ::= 'break' Identifieropt ';' 4194\:$action:\ 4195/.$location 4196void Parser::Act$rule_number() 4197{ 4198 AstBreakStatement* p = ast_pool -> NewBreakStatement(); 4199 p -> break_token = Token(1); 4200 if (Token(3) > Token(2)) 4201 p -> identifier_token_opt = Token(2); 4202 p -> semicolon_token = Token(3); 4203 Sym(1) = p; 4204} 4205./ 4206 4207ContinueStatement ::= 'continue' Identifieropt ';' 4208\:$action:\ 4209/.$location 4210void Parser::Act$rule_number() 4211{ 4212 AstContinueStatement* p = ast_pool -> NewContinueStatement(); 4213 p -> continue_token = Token(1); 4214 if (Token(3) > Token(2)) 4215 p -> identifier_token_opt = Token(2); 4216 p -> semicolon_token = Token(3); 4217 Sym(1) = p; 4218} 4219./ 4220 4221ReturnStatement ::= 'return' Expressionopt ';' 4222\:$action:\ 4223/.$location 4224void Parser::Act$rule_number() 4225{ 4226 AstReturnStatement* p = ast_pool -> NewReturnStatement(); 4227 p -> return_token = Token(1); 4228 p -> expression_opt = DYNAMIC_CAST<AstExpression*> (Sym(2)); 4229 p -> semicolon_token = Token(3); 4230 Sym(1) = p; 4231} 4232./ 4233 4234ThrowStatement ::= 'throw' Expression ';' 4235\:$action:\ 4236/.$location 4237void Parser::Act$rule_number() 4238{ 4239 AstThrowStatement* p = ast_pool -> NewThrowStatement(); 4240 p -> throw_token = Token(1); 4241 p -> expression = DYNAMIC_CAST<AstExpression*> (Sym(2)); 4242 p -> semicolon_token = Token(3); 4243 Sym(1) = p; 4244} 4245./ 4246 4247SynchronizedStatement ::= 'synchronized' '(' Expression ')' Block 4248\:$action:\ 4249/.$location 4250void Parser::Act$rule_number() 4251{ 4252 AstSynchronizedStatement* p = ast_pool -> NewSynchronizedStatement(); 4253 p -> synchronized_token = Token(1); 4254 p -> expression = DYNAMIC_CAST<AstExpression*> (Sym(3)); 4255 p -> block = DYNAMIC_CAST<AstBlock*> (Sym(5)); 4256 p -> block -> SetTag(AstBlock::SYNCHRONIZED); 4257 4258 Sym(1) = p; 4259} 4260./ 4261 4262-- 4263-- The use of Marker allows us to share code. 4264-- 4265--TryStatement ::= 'try' Block Catches 4266TryStatement ::= 'try' Block Catches Marker 4267\:$MakeTryStatement:\ 4268/.$location 4269void Parser::MakeTryStatement() 4270{ 4271 AstTryStatement* p = ast_pool -> NewTryStatement(); 4272 p -> try_token = Token(1); 4273 p -> block = DYNAMIC_CAST<AstBlock*> (Sym(2)); 4274 if (Sym(3)) 4275 { 4276 AstListNode* tail = DYNAMIC_CAST<AstListNode*> (Sym(3)); 4277 p -> AllocateCatchClauses(tail -> index + 1); 4278 AstListNode* root = tail; 4279 do 4280 { 4281 root = root -> next; 4282 p -> AddCatchClause(DYNAMIC_CAST<AstCatchClause*> 4283 (root -> element)); 4284 } while (root != tail); 4285 FreeCircularList(tail); 4286 } 4287 if (Sym(4)) 4288 { 4289 p -> block -> SetTag(AstBlock::TRY_CLAUSE_WITH_FINALLY); 4290 for (unsigned i = 0; i < p -> NumCatchClauses(); i++) 4291 p -> CatchClause(i) -> block -> 4292 SetTag(AstBlock::TRY_CLAUSE_WITH_FINALLY); 4293 p -> finally_clause_opt = DYNAMIC_CAST<AstFinallyClause*> (Sym(4)); 4294 } 4295 Sym(1) = p; 4296} 4297./ 4298 4299TryStatement ::= 'try' Block Catchesopt Finally 4300\:$MakeTryStatement:\ 4301/.$shared_function 4302// 4303// void MakeTryStatement(); 4304//./ 4305 4306Catches ::= CatchClause 4307\:$StartList:\ 4308/.$shared_StartList./ 4309 4310Catches ::= Catches CatchClause 4311\:$AddList2:\ 4312/.$shared_AddList2./ 4313 4314Catchesopt ::= $empty 4315\:$NullAction:\ 4316/.$shared_NullAction./ 4317 4318Catchesopt ::= Catches 4319\:$NoAction:\ 4320/.$shared_NoAction./ 4321 4322CatchClause ::= 'catch' '(' FormalParameter ')' Block 4323\:$action:\ 4324/.$location 4325void Parser::Act$rule_number() 4326{ 4327 AstCatchClause* p = ast_pool -> NewCatchClause(); 4328 p -> catch_token = Token(1); 4329 p -> formal_parameter = DYNAMIC_CAST<AstFormalParameter*> (Sym(3)); 4330 p -> block = DYNAMIC_CAST<AstBlock*> (Sym(5)); 4331 4332 Sym(1) = p; 4333} 4334./ 4335 4336Finally ::= 'finally' Block 4337\:$action:\ 4338/.$location 4339void Parser::Act$rule_number() 4340{ 4341 AstFinallyClause* p = ast_pool -> NewFinallyClause(); 4342 p -> finally_token = Token(1); 4343 p -> block = DYNAMIC_CAST<AstBlock*> (Sym(2)); 4344 p -> block -> SetTag(AstBlock::FINALLY); 4345 4346 Sym(1) = p; 4347} 4348./ 4349 4350--18.12 Productions from 14: Expressions 4351 4352Primary ::= PrimaryNoNewArray 4353\:$NoAction:\ 4354/.$shared_NoAction./ 4355 4356--1.2 feature 4357-- 4358-- It is legal to access an element of an initialized array, as in 4359-- new int[] {0}[0]; this requires splitting the original rule for 4360-- array creation into two. 4361-- 4362--Primary ::= ArrayCreationExpression 4363Primary ::= ArrayCreationUninitialized 4364\:$NoAction:\ 4365/.$shared_NoAction./ 4366 4367Primary ::= ArrayCreationInitialized 4368\:$NoAction:\ 4369/.$shared_NoAction./ 4370 4371PrimaryNoNewArray ::= Literal 4372\:$NoAction:\ 4373/.$shared_NoAction./ 4374 4375PrimaryNoNewArray ::= 'this' 4376\:$action:\ 4377/.$location 4378void Parser::Act$rule_number() 4379{ 4380 Sym(1) = ast_pool -> NewThisExpression(Token(1)); 4381} 4382./ 4383 4384-- 4385-- We split this into two rules to allow better parsing of parenthesized 4386-- expressions vs. casts. All expressions have a dual *NotName form, so that 4387-- the decision of whether "(name)" starts a cast or is a primary does not 4388-- cause parsing ambiguities. The use of Marker allows us to share code. 4389-- Also note that splitting this rule aids in parsing generics. 4390-- 4391--PrimaryNoNewArray ::= '(' Expression ')' 4392PrimaryNoNewArray ::= '(' Name Marker ')' 4393\:$MakeParenthesizedExpression:\ 4394/.$location 4395void Parser::MakeParenthesizedExpression() 4396{ 4397 AstParenthesizedExpression* p = ast_pool -> NewParenthesizedExpression(); 4398 p -> left_parenthesis_token = Token(1); 4399 p -> expression = DYNAMIC_CAST<AstExpression*> (Sym(2)); 4400 p -> right_parenthesis_token = Token(4); 4401 Sym(1) = p; 4402} 4403./ 4404 4405-- 4406-- The use of Marker allows us to share code. 4407-- 4408PrimaryNoNewArray ::= '(' ExpressionNotName Marker ')' 4409\:$MakeParenthesizedExpression:\ 4410/.$shared_function 4411// 4412// void MakeParenthesizedExpression(); 4413//./ 4414 4415PrimaryNoNewArray ::= ClassInstanceCreationExpression 4416\:$NoAction:\ 4417/.$shared_NoAction./ 4418 4419PrimaryNoNewArray ::= FieldAccess 4420\:$NoAction:\ 4421/.$shared_NoAction./ 4422 4423--1.1 feature 4424-- 4425-- Note that we had to rework this to avoid ambiguity 4426-- 4427--PrimaryNoNewArray ::= ClassType '.' 'this' 4428PrimaryNoNewArray ::= Name '.' 'this' 4429\:$action:\ 4430/.$location 4431void Parser::Act$rule_number() 4432{ 4433 AstThisExpression* p = ast_pool -> NewThisExpression(Token(3)); 4434 p -> base_opt = ast_pool -> NewTypeName(DYNAMIC_CAST<AstName*> (Sym(1))); 4435 Sym(1) = p; 4436} 4437./ 4438 4439--1.1 feature 4440-- 4441-- Note that we had to rework this to avoid ambiguity. 4442-- 4443--PrimaryNoNewArray ::= Type '.' 'class' 4444PrimaryNoNewArray ::= PrimitiveType Dimsopt '.' 'class' 4445\:$MakeClassLiteral:\ 4446/.$location 4447void Parser::MakeClassLiteral() 4448{ 4449 AstClassLiteral* p = ast_pool -> NewClassLiteral(Token(4)); 4450 if (Token(3) == Token(4)) 4451 Sym(2) = NULL; 4452 p -> type = MakeArrayType(1); 4453 Sym(1) = p; 4454} 4455./ 4456 4457PrimaryNoNewArray ::= Name Dims '.' 'class' 4458\:$MakeClassLiteral:\ 4459/.$shared_function 4460// 4461// void MakeClassLiteral(); 4462//./ 4463 4464-- 4465-- The use of Marker allows us to share code. 4466-- 4467--PrimaryNoNewArray ::= Name '.' 'class' 4468PrimaryNoNewArray ::= Name '.' Marker 'class' 4469\:$MakeClassLiteral:\ 4470/.$shared_function 4471// 4472// void MakeClassLiteral(); 4473//./ 4474 4475-- 4476-- The use of Marker allows us to share code. 4477-- 4478--PrimaryNoNewArray ::= 'void' '.' 'class' 4479PrimaryNoNewArray ::= VoidType '.' Marker 'class' 4480\:$MakeClassLiteral:\ 4481/.$shared_function 4482// 4483// void MakeClassLiteral(); 4484//./ 4485 4486PrimaryNoNewArray ::= MethodInvocation 4487\:$NoAction:\ 4488/.$shared_NoAction./ 4489 4490PrimaryNoNewArray ::= ArrayAccess 4491\:$NoAction:\ 4492/.$shared_NoAction./ 4493 4494--1.1 feature 4495-- 4496-- In Java 1.0 a ClassBody could not appear at all in a 4497-- ClassInstanceCreationExpression. Simplify. 4498-- 4499--ClassInstanceCreationExpression ::= 'new' ClassOrInterfaceType '(' 4500-- ArgumentListopt ')' ClassBodyopt 4501ClassInstanceCreationExpression ::= 'new' ClassOrInterfaceType Arguments 4502 ClassBodyopt 4503\:$action:\ 4504/.$location 4505void Parser::Act$rule_number() 4506{ 4507 AstClassCreationExpression* p = ast_pool -> NewClassCreationExpression(); 4508 p -> new_token = Token(1); 4509 p -> class_type = DYNAMIC_CAST<AstTypeName*> (Sym(2)); 4510 p -> arguments = DYNAMIC_CAST<AstArguments*> (Sym(3)); 4511 p -> class_body_opt = DYNAMIC_CAST<AstClassBody*> (Sym(4)); 4512 if (p -> class_body_opt) 4513 p -> class_body_opt -> identifier_token = 4514 p -> class_type -> IdentifierToken(); 4515 Sym(1) = p; 4516} 4517./ 4518 4519-- 4520-- Parameterized types were added in JSR 14. 4521-- 4522--ClassInstanceCreationExpression ::= 'new' ClassOrInterfaceType '(' 4523-- ArgumentListopt ')' ClassBodyopt 4524ClassInstanceCreationExpression ::= 'new' TypeArguments ClassOrInterfaceType 4525 Arguments ClassBodyopt 4526\:$action:\ 4527/.$location 4528void Parser::Act$rule_number() 4529{ 4530 AstClassCreationExpression* p = ast_pool -> NewClassCreationExpression(); 4531 p -> new_token = Token(1); 4532 p -> type_arguments_opt = MakeExplicitTypeArguments(2); 4533 p -> class_type = DYNAMIC_CAST<AstTypeName*> (Sym(3)); 4534 p -> arguments = DYNAMIC_CAST<AstArguments*> (Sym(4)); 4535 p -> class_body_opt = DYNAMIC_CAST<AstClassBody*> (Sym(5)); 4536 if (p -> class_body_opt) 4537 p -> class_body_opt -> identifier_token = 4538 p -> class_type -> IdentifierToken(); 4539 Sym(1) = p; 4540} 4541./ 4542 4543--1.1 feature 4544-- 4545-- Parameterized types were added in JSR 14. 4546-- 4547--ClassInstanceCreationExpression ::= Primary '.' 'new' 'Identifier' '(' 4548-- ArgumentListopt ')' ClassBodyopt 4549ClassInstanceCreationExpression ::= Primary '.' 'new' TypeArgumentsopt 4550 'Identifier' TypeArgumentsopt Arguments 4551 ClassBodyopt 4552\:$MakeQualifiedNew:\ 4553/.$location 4554void Parser::MakeQualifiedNew() 4555{ 4556 AstClassCreationExpression* p = ast_pool -> NewClassCreationExpression(); 4557 p -> base_opt = DYNAMIC_CAST<AstExpression*> (Sym(1)); 4558 p -> new_token = Token(3); 4559 p -> type_arguments_opt = MakeExplicitTypeArguments(4); 4560 p -> class_type = ast_pool -> NewTypeName(MakeSimpleName(5)); 4561 p -> class_type -> type_arguments_opt = MakeExplicitTypeArguments(6); 4562 p -> arguments = DYNAMIC_CAST<AstArguments*> (Sym(7)); 4563 p -> class_body_opt = DYNAMIC_CAST<AstClassBody*> (Sym(8)); 4564 if (p -> class_body_opt) 4565 p -> class_body_opt -> identifier_token = Token(5); 4566 Sym(1) = p; 4567} 4568./ 4569 4570--1.1 feature 4571-- 4572-- Parameterized types were added in JSR 14. 4573-- 4574--ClassInstanceCreationExpression ::= Name '.' 'new' 'Identifier' '(' 4575-- ArgumentListopt ')' ClassBodyopt 4576ClassInstanceCreationExpression ::= Name '.' 'new' TypeArgumentsopt 4577 'Identifier' TypeArgumentsopt Arguments 4578 ClassBodyopt 4579\:$MakeQualifiedNew:\ 4580/.$shared_function 4581// 4582// void MakeQualifiedNew(); 4583//./ 4584 4585ArgumentList ::= Expression 4586\:$StartList:\ 4587/.$shared_StartList./ 4588 4589ArgumentList ::= ArgumentList ',' Expression 4590\:$AddList3:\ 4591/.$shared_AddList3./ 4592 4593ArgumentListopt ::= $empty 4594\:$NullAction:\ 4595/.$shared_NullAction./ 4596 4597ArgumentListopt ::= ArgumentList 4598\:$NoAction:\ 4599/.$shared_NoAction./ 4600 4601--1.2 feature 4602-- 4603-- ArrayCreationExpression is split into two parsing categories, to 4604-- allow array access on an initialized array. See above. 4605-- 4606--ArrayCreationExpression ::= 'new' PrimitiveType DimExprs Dimsopt 4607ArrayCreationUninitialized ::= 'new' PrimitiveType DimExprs Dimsopt 4608\:$MakeArrayCreationUninitialized:\ 4609/.$location 4610void Parser::MakeArrayCreationUninitialized() 4611{ 4612 AstArrayCreationExpression* p = ast_pool -> NewArrayCreationExpression(); 4613 p -> new_token = Token(1); 4614 p -> array_type = DYNAMIC_CAST<AstType*> (Sym(2)); 4615 AstListNode* tail = DYNAMIC_CAST<AstListNode*> (Sym(3)); 4616 p -> AllocateDimExprs(tail -> index + 1); 4617 AstListNode* root = tail; 4618 do 4619 { 4620 root = root -> next; 4621 p -> AddDimExpr(DYNAMIC_CAST<AstDimExpr*> (root -> element)); 4622 } while (root != tail); 4623 FreeCircularList(tail); 4624 p -> brackets_opt = DYNAMIC_CAST<AstBrackets*> (Sym(4)); 4625 Sym(1) = p; 4626} 4627./ 4628 4629--ArrayCreationExpression ::= 'new' ClassOrInterfaceType DimExprs Dimsopt 4630ArrayCreationUninitialized ::= 'new' ClassOrInterfaceType DimExprs Dimsopt 4631\:$MakeArrayCreationUninitialized:\ 4632/.$shared_function 4633// 4634// void MakeArrayCreationUninitialized(); 4635//./ 4636 4637--1.1 feature 4638-- 4639--ArrayCreationExpression ::= 'new' ArrayType ArrayInitializer 4640ArrayCreationInitialized ::= 'new' PrimitiveType Dims ArrayInitializer 4641\:$MakeArrayCreationInitialized:\ 4642/.$location 4643void Parser::MakeArrayCreationInitialized() 4644{ 4645 AstArrayCreationExpression* p = ast_pool -> NewArrayCreationExpression(); 4646 p -> new_token = Token(1); 4647 p -> array_type = MakeArrayType(2); 4648 p -> array_initializer_opt = DYNAMIC_CAST<AstArrayInitializer*> (Sym(4)); 4649 Sym(1) = p; 4650} 4651./ 4652 4653ArrayCreationInitialized ::= 'new' ClassOrInterfaceType Dims ArrayInitializer 4654\:$MakeArrayCreationInitialized:\ 4655/.$shared_function 4656// 4657// void MakeArrayCreationInitialized(); 4658//./ 4659 4660DimExprs ::= DimExpr 4661\:$StartList:\ 4662/.$shared_StartList./ 4663 4664DimExprs ::= DimExprs DimExpr 4665\:$AddList2:\ 4666/.$shared_AddList2./ 4667 4668DimExpr ::= '[' Expression ']' 4669\:$action:\ 4670/.$location 4671void Parser::Act$rule_number() 4672{ 4673 AstDimExpr* p = ast_pool -> NewDimExpr(); 4674 p -> left_bracket_token = Token(1); 4675 p -> expression = DYNAMIC_CAST<AstExpression*> (Sym(2)); 4676 p -> right_bracket_token = Token(3); 4677 Sym(1) = p; 4678} 4679./ 4680 4681Dims ::= '[' ']' 4682\:$action:\ 4683/.$location 4684void Parser::Act$rule_number() 4685{ 4686 Sym(1) = ast_pool -> NewBrackets(Token(1), Token(2)); 4687} 4688./ 4689 4690Dims ::= Dims '[' ']' 4691\:$action:\ 4692/.$location 4693void Parser::Act$rule_number() 4694{ 4695 AstBrackets* p = DYNAMIC_CAST<AstBrackets*> (Sym(1)); 4696 p -> right_bracket_token = Token(2); 4697 p -> dims++; 4698} 4699./ 4700 4701Dimsopt ::= $empty 4702\:$NullAction:\ 4703/.$shared_NullAction./ 4704 4705Dimsopt ::= Dims 4706\:$NoAction:\ 4707/.$shared_NoAction./ 4708 4709-- 4710-- Added rule to make parsing 'super' '.' easier. 4711-- 4712SuperAccess ::= 'super' 4713\:$action:\ 4714/.$location 4715void Parser::Act$rule_number() 4716{ 4717 Sym(1) = ast_pool -> NewSuperExpression(Token(1)); 4718} 4719./ 4720 4721-- 4722-- Added rule to make parsing 'super' '.' easier. Technically, only ClassType 4723-- is allowed instead of Name, but that would be ambiguous with qualified 4724-- names. The use of Marker allows us to share code. 4725-- 4726--SuperAccess ::= ClassType '.' 'super' 4727SuperAccess ::= Name '.' Marker 'super' 4728\:$action:\ 4729/.$location 4730void Parser::Act$rule_number() 4731{ 4732 AstSuperExpression* p = ast_pool -> NewSuperExpression(Token(4)); 4733 p -> base_opt = ast_pool -> NewTypeName(DYNAMIC_CAST<AstName*> (Sym(1))); 4734 Sym(1) = p; 4735} 4736./ 4737 4738-- 4739-- The use of Marker allows us to share code. 4740-- 4741--FieldAccess ::= Primary '.' 'Identifier' 4742FieldAccess ::= Primary '.' Marker 'Identifier' 4743\:$MakeFieldAccess:\ 4744/.$location 4745void Parser::MakeFieldAccess() 4746{ 4747 AstFieldAccess* p = ast_pool -> NewFieldAccess(); 4748 p -> base = DYNAMIC_CAST<AstExpression*> (Sym(1)); 4749 p -> identifier_token = Token(4); 4750 Sym(1) = p; 4751} 4752./ 4753 4754-- 4755-- The use of Marker allows us to share code. Likewise, SuperAccess 4756-- simplifies tree creation. 4757-- 4758--FieldAccess ::= 'super' '.' 'Identifier' 4759--FieldAccess ::= ClassType '.' 'super' '.' 'Identifier' 4760FieldAccess ::= SuperAccess '.' Marker 'Identifier' 4761\:$MakeFieldAccess:\ 4762/.$shared_function 4763// 4764// void MakeFieldAccess(); 4765//./ 4766 4767-- 4768-- Inline expand Name so we can distinguish the optional base from the required 4769-- method identifier. 4770-- 4771--MethodInvocation ::= Name '(' ArgumentListopt ')' 4772MethodInvocation ::= 'Identifier' Arguments 4773\:$action:\ 4774/.$location 4775void Parser::Act$rule_number() 4776{ 4777 AstMethodInvocation* p = ast_pool -> NewMethodInvocation(Token(1)); 4778 p -> arguments = DYNAMIC_CAST<AstArguments*> (Sym(2)); 4779 Sym(1) = p; 4780} 4781./ 4782 4783-- 4784-- Inline expand Name so we can distinguish the optional base from the required 4785-- method identifier. The use of Marker allows us to share code. 4786-- 4787--MethodInvocation ::= Name '(' ArgumentListopt ')' 4788MethodInvocation ::= Name '.' Marker 'Identifier' Arguments 4789\:$MakeMethodInvocation:\ 4790/.$location 4791void Parser::MakeMethodInvocation() 4792{ 4793 AstMethodInvocation* p = ast_pool -> NewMethodInvocation(Token(4)); 4794 p -> base_opt = DYNAMIC_CAST<AstExpression*> (Sym(1)); 4795 p -> type_arguments_opt = MakeExplicitTypeArguments(3); 4796 p -> arguments = DYNAMIC_CAST<AstArguments*> (Sym(5)); 4797 Sym(1) = p; 4798} 4799./ 4800 4801-- 4802-- Parameterized types were added in JSR 14. 4803-- 4804MethodInvocation ::= Name '.' TypeArguments 'Identifier' Arguments 4805\:$MakeMethodInvocation:\ 4806/.$shared_function 4807// 4808// void MakeMethodInvocation(); 4809//./ 4810 4811-- 4812-- The use of Marker allows us to share code. 4813-- 4814--MethodInvocation ::= Primary '.' 'Identifier' '(' ArgumentListopt ')' 4815MethodInvocation ::= Primary '.' Marker 'Identifier' Arguments 4816\:$MakeMethodInvocation:\ 4817/.$shared_function 4818// 4819// void MakeMethodInvocation(); 4820//./ 4821 4822-- 4823-- Parameterized types were added in JSR 14. 4824-- 4825MethodInvocation ::= Primary '.' TypeArguments 'Identifier' Arguments 4826\:$MakeMethodInvocation:\ 4827/.$shared_function 4828// 4829// void MakeMethodInvocation(); 4830//./ 4831 4832-- 4833-- The use of Marker allows us to share code. Likewise, SuperAccess 4834-- simplifies tree creation. 4835-- 4836--MethodInvocation ::= 'super' '.' 'Identifier' '(' ArgumentListopt ')' 4837--MethodInvocation ::= ClassType '.' 'super' '.' 'Identifier' '(' 4838-- ArgumentListopt ')' 4839MethodInvocation ::= SuperAccess '.' Marker 'Identifier' Arguments 4840\:$MakeMethodInvocation:\ 4841/.$shared_function 4842// 4843// void MakeMethodInvocation(); 4844//./ 4845 4846-- 4847-- Parameterized types were added in JSR 14. Likewise, SuperAccess 4848-- simplifies tree creation. 4849-- 4850--MethodInvocation ::= 'super' '.' TypeArguments 'Identifier' '(' 4851-- ArgumentListopt ')' 4852--MethodInvocation ::= ClassType '.' 'super' '.' TypeArguments 'Identifier' '(' 4853-- ArgumentListopt ')' 4854MethodInvocation ::= SuperAccess '.' TypeArguments 'Identifier' Arguments 4855\:$MakeMethodInvocation:\ 4856/.$shared_function 4857// 4858// void MakeMethodInvocation(); 4859//./ 4860 4861ArrayAccess ::= Name '[' Expression ']' 4862\:$MakeArrayAccess:\ 4863/.$location 4864void Parser::MakeArrayAccess() 4865{ 4866 AstArrayAccess* p = ast_pool -> NewArrayAccess(); 4867 p -> base = DYNAMIC_CAST<AstExpression*> (Sym(1)); 4868 p -> left_bracket_token = Token(2); 4869 p -> expression = DYNAMIC_CAST<AstExpression*> (Sym(3)); 4870 p -> right_bracket_token = Token(4); 4871 Sym(1) = p; 4872} 4873./ 4874 4875ArrayAccess ::= PrimaryNoNewArray '[' Expression ']' 4876\:$MakeArrayAccess:\ 4877/.$shared_function 4878// 4879// void MakeArrayAccess(); 4880//./ 4881 4882--1.2 feature 4883-- 4884-- Access of an initialized array is legal. See above. 4885-- 4886ArrayAccess ::= ArrayCreationInitialized '[' Expression ']' 4887\:$MakeArrayAccess:\ 4888/.$shared_function 4889// 4890// void MakeArrayAccess(); 4891//./ 4892 4893PostfixExpression ::= Primary 4894\:$NoAction:\ 4895/.$shared_NoAction./ 4896 4897PostfixExpression ::= Name 4898\:$NoAction:\ 4899/.$shared_NoAction./ 4900 4901PostfixExpression ::= PostIncrementExpression 4902\:$NoAction:\ 4903/.$shared_NoAction./ 4904 4905PostfixExpression ::= PostDecrementExpression 4906\:$NoAction:\ 4907/.$shared_NoAction./ 4908 4909PostfixExpressionNotName ::= Primary 4910\:$NoAction:\ 4911/.$shared_NoAction./ 4912 4913PostfixExpressionNotName ::= PostIncrementExpression 4914\:$NoAction:\ 4915/.$shared_NoAction./ 4916 4917PostfixExpressionNotName ::= PostDecrementExpression 4918\:$NoAction:\ 4919/.$shared_NoAction./ 4920 4921PostIncrementExpression ::= PostfixExpression '++' 4922\:$action:\ 4923/.$location 4924void Parser::Act$rule_number() 4925{ 4926 AstPostUnaryExpression* p = 4927 ast_pool -> NewPostUnaryExpression(AstPostUnaryExpression::PLUSPLUS); 4928 p -> expression = DYNAMIC_CAST<AstExpression*> (Sym(1)); 4929 p -> post_operator_token = Token(2); 4930 Sym(1) = p; 4931} 4932./ 4933 4934PostDecrementExpression ::= PostfixExpression '--' 4935\:$action:\ 4936/.$location 4937void Parser::Act$rule_number() 4938{ 4939 AstPostUnaryExpression* p = 4940 ast_pool -> NewPostUnaryExpression(AstPostUnaryExpression::MINUSMINUS); 4941 p -> expression = DYNAMIC_CAST<AstExpression*> (Sym(1)); 4942 p -> post_operator_token = Token(2); 4943 Sym(1) = p; 4944} 4945./ 4946 4947UnaryExpression ::= PreIncrementExpression 4948\:$NoAction:\ 4949/.$shared_NoAction./ 4950 4951UnaryExpression ::= PreDecrementExpression 4952\:$NoAction:\ 4953/.$shared_NoAction./ 4954 4955UnaryExpression ::= '+' UnaryExpression 4956\:$MakePreUnaryExpression:\ 4957/.$location 4958void Parser::MakePreUnaryExpression() 4959{ 4960 AstPreUnaryExpression::PreUnaryExpressionTag tag; 4961 switch (lex_stream -> Kind(Token(1))) 4962 { 4963 case TK_PLUS_PLUS: tag = AstPreUnaryExpression::PLUSPLUS; break; 4964 case TK_MINUS_MINUS: tag = AstPreUnaryExpression::MINUSMINUS; break; 4965 case TK_PLUS: tag = AstPreUnaryExpression::PLUS; break; 4966 case TK_MINUS: tag = AstPreUnaryExpression::MINUS; break; 4967 case TK_TWIDDLE: tag = AstPreUnaryExpression::TWIDDLE; break; 4968 case TK_NOT: tag = AstPreUnaryExpression::NOT; break; 4969 default: tag = AstPreUnaryExpression::NONE; 4970 } 4971 AstPreUnaryExpression* p = ast_pool -> NewPreUnaryExpression(tag); 4972 p -> pre_operator_token = Token(1); 4973 p -> expression = DYNAMIC_CAST<AstExpression*> (Sym(2)); 4974 Sym(1) = p; 4975} 4976./ 4977 4978UnaryExpression ::= '-' UnaryExpression 4979\:$MakePreUnaryExpression:\ 4980/.$shared_Unary./ 4981 4982UnaryExpression ::= UnaryExpressionNotPlusMinus 4983\:$NoAction:\ 4984/.$shared_NoAction./ 4985 4986UnaryExpressionNotName ::= PreIncrementExpression 4987\:$NoAction:\ 4988/.$shared_NoAction./ 4989 4990UnaryExpressionNotName ::= PreDecrementExpression 4991\:$NoAction:\ 4992/.$shared_NoAction./ 4993 4994UnaryExpressionNotName ::= '+' UnaryExpression 4995\:$MakePreUnaryExpression:\ 4996/.$shared_Unary./ 4997 4998UnaryExpressionNotName ::= '-' UnaryExpression 4999\:$MakePreUnaryExpression:\ 5000/.$shared_Unary./ 5001 5002UnaryExpressionNotName ::= UnaryExpressionNotPlusMinusNotName 5003\:$NoAction:\ 5004/.$shared_NoAction./ 5005 5006PreIncrementExpression ::= '++' UnaryExpression 5007\:$MakePreUnaryExpression:\ 5008/.$shared_Unary./ 5009 5010PreDecrementExpression ::= '--' UnaryExpression 5011\:$MakePreUnaryExpression:\ 5012/.$shared_Unary./ 5013 5014UnaryExpressionNotPlusMinus ::= PostfixExpression 5015\:$NoAction:\ 5016/.$shared_NoAction./ 5017 5018UnaryExpressionNotPlusMinus ::= '~' UnaryExpression 5019\:$MakePreUnaryExpression:\ 5020/.$shared_Unary./ 5021 5022UnaryExpressionNotPlusMinus ::= '!' UnaryExpression 5023\:$MakePreUnaryExpression:\ 5024/.$shared_Unary./ 5025 5026UnaryExpressionNotPlusMinus ::= CastExpression 5027\:$NoAction:\ 5028/.$shared_NoAction./ 5029 5030UnaryExpressionNotPlusMinusNotName ::= PostfixExpressionNotName 5031\:$NoAction:\ 5032/.$shared_NoAction./ 5033 5034UnaryExpressionNotPlusMinusNotName ::= '~' UnaryExpression 5035\:$MakePreUnaryExpression:\ 5036/.$shared_Unary./ 5037 5038UnaryExpressionNotPlusMinusNotName ::= '!' UnaryExpression 5039\:$MakePreUnaryExpression:\ 5040/.$shared_Unary./ 5041 5042UnaryExpressionNotPlusMinusNotName ::= CastExpression 5043\:$NoAction:\ 5044/.$shared_NoAction./ 5045 5046-- 5047-- Due to grammar ambiguities, we must rewrite this (otherwise, it is not 5048-- obvious whether "(a<b" starts a parenthesized expression or a cast). Note 5049-- that our rewrite guarantees that the contents of the parenthesis will 5050-- syntactically be a type, based on the way we factored parenthesized 5051-- expressions in Primary. 5052-- 5053-- JLS2 15 lists: 5054--CastExpression ::= '(' PrimitiveType ')' UnaryExpression 5055--CastExpression ::= '(' ReferenceType ')' UnaryExpressionNotPlusMinus 5056-- JLS1 suggests: 5057--CastExpression ::= '(' PrimitiveType Dimsopt ')' UnaryExpression 5058--CastExpression ::= '(' Expression ')' UnaryExpressionNotPlusMinus 5059--CastExpression ::= '(' Name Dims ')' UnaryExpressionNotPlusMinus 5060-- 5061CastExpression ::= '(' PrimitiveType Dimsopt ')' UnaryExpression 5062\:$MakeCastExpression:\ 5063/.$location 5064void Parser::MakeCastExpression() { MakeCastExpression(MakeArrayType(2), 4); } 5065 5066// 5067// Builds a cast expression. type must be the target AstType, and tokennum 5068// should point to the ')'. 5069// 5070void Parser::MakeCastExpression(AstType* type, int tokennum) 5071{ 5072 AstCastExpression* p = ast_pool -> NewCastExpression(); 5073 p -> left_parenthesis_token = Token(1); 5074 p -> type = type; 5075 p -> right_parenthesis_token = Token(tokennum); 5076 p -> expression = DYNAMIC_CAST<AstExpression*> (Sym(tokennum + 1)); 5077 Sym(1) = p; 5078} 5079./ 5080 5081-- 5082-- The use of Marker allows us to share code. 5083-- 5084CastExpression ::= '(' Name Marker ')' UnaryExpressionNotPlusMinus 5085\:$MakeCastExpression:\ 5086/.$shared_function 5087// 5088// void MakeCastExpression(); 5089//./ 5090 5091CastExpression ::= '(' Name Dims ')' UnaryExpressionNotPlusMinus 5092\:$MakeCastExpression:\ 5093/.$shared_function 5094// 5095// void MakeCastExpression(); 5096//./ 5097 5098-- 5099-- Parameterized types were added in JSR 14. 5100-- 5101CastExpression ::= '(' Name '<' TypeArgumentList1 Dimsopt ')' 5102 UnaryExpressionNotPlusMinus 5103\:$action:\ 5104/.$location 5105void Parser::Act$rule_number() 5106{ 5107 Sym(4) = MakeTypeArguments(2); 5108 MakeCastExpression(MakeArrayType(4), 6); 5109} 5110./ 5111 5112-- 5113-- Parameterized types were added in JSR 14. 5114-- 5115CastExpression ::= '(' Name '<' TypeArgumentList1 '.' ClassOrInterfaceType 5116 Dimsopt ')' UnaryExpressionNotPlusMinus 5117\:$action:\ 5118/.$location 5119void Parser::Act$rule_number() 5120{ 5121 AstTypeName* p = DYNAMIC_CAST<AstTypeName*> (Sym(6)); 5122 while (p -> base_opt) 5123 p = p -> base_opt; 5124 p -> base_opt = MakeTypeArguments(2); 5125 MakeCastExpression(MakeArrayType(6), 8); 5126} 5127./ 5128 5129MultiplicativeExpression ::= UnaryExpression 5130\:$NoAction:\ 5131/.$shared_NoAction./ 5132 5133MultiplicativeExpression ::= MultiplicativeExpression '*' UnaryExpression 5134\:$MakeBinaryExpression:\ 5135/.$location 5136// 5137// This creates a binary expression of the named type. 5138// 5139void Parser::MakeBinaryExpression() 5140{ 5141 AstBinaryExpression::BinaryExpressionTag tag; 5142 switch (lex_stream -> Kind(Token(2))) 5143 { 5144 case TK_MULTIPLY: tag = AstBinaryExpression::STAR; break; 5145 case TK_DIVIDE: tag = AstBinaryExpression::SLASH; break; 5146 case TK_REMAINDER: tag = AstBinaryExpression::MOD; break; 5147 case TK_PLUS: tag = AstBinaryExpression::PLUS; break; 5148 case TK_MINUS: tag = AstBinaryExpression::MINUS; break; 5149 case TK_LEFT_SHIFT: tag = AstBinaryExpression::LEFT_SHIFT; break; 5150 case TK_RIGHT_SHIFT: tag = AstBinaryExpression::RIGHT_SHIFT; break; 5151 case TK_UNSIGNED_RIGHT_SHIFT: 5152 tag = AstBinaryExpression::UNSIGNED_RIGHT_SHIFT; break; 5153 case TK_LESS: tag = AstBinaryExpression::LESS; break; 5154 case TK_GREATER: tag = AstBinaryExpression::GREATER; break; 5155 case TK_LESS_EQUAL: tag = AstBinaryExpression::LESS_EQUAL; break; 5156 case TK_GREATER_EQUAL: tag = AstBinaryExpression::GREATER_EQUAL; break; 5157 case TK_EQUAL_EQUAL: tag = AstBinaryExpression::EQUAL_EQUAL; break; 5158 case TK_NOT_EQUAL: tag = AstBinaryExpression::NOT_EQUAL; break; 5159 case TK_AND: tag = AstBinaryExpression::AND; break; 5160 case TK_XOR: tag = AstBinaryExpression::XOR; break; 5161 case TK_OR: tag = AstBinaryExpression::IOR; break; 5162 case TK_AND_AND: tag = AstBinaryExpression::AND_AND; break; 5163 case TK_OR_OR: tag = AstBinaryExpression::OR_OR; break; 5164 default: tag = AstBinaryExpression::NONE; 5165 } 5166 AstBinaryExpression* p = ast_pool -> NewBinaryExpression(tag); 5167 p -> left_expression = DYNAMIC_CAST<AstExpression*> (Sym(1)); 5168 p -> binary_operator_token = Token(2); 5169 p -> right_expression = DYNAMIC_CAST<AstExpression*> (Sym(3)); 5170 Sym(1) = p; 5171} 5172./ 5173 5174MultiplicativeExpression ::= MultiplicativeExpression '/' UnaryExpression 5175\:$MakeBinaryExpression:\ 5176/.$shared_Binary./ 5177 5178MultiplicativeExpression ::= MultiplicativeExpression '%' UnaryExpression 5179\:$MakeBinaryExpression:\ 5180/.$shared_Binary./ 5181 5182MultiplicativeExpressionNotName ::= UnaryExpressionNotName 5183\:$NoAction:\ 5184/.$shared_NoAction./ 5185 5186MultiplicativeExpressionNotName ::= MultiplicativeExpressionNotName '*' 5187 UnaryExpression 5188\:$MakeBinaryExpression:\ 5189/.$shared_Binary./ 5190 5191MultiplicativeExpressionNotName ::= Name '*' UnaryExpression 5192\:$MakeBinaryExpression:\ 5193/.$shared_Binary./ 5194 5195MultiplicativeExpressionNotName ::= MultiplicativeExpressionNotName '/' 5196 UnaryExpression 5197\:$MakeBinaryExpression:\ 5198/.$shared_Binary./ 5199 5200MultiplicativeExpressionNotName ::= Name '/' UnaryExpression 5201\:$MakeBinaryExpression:\ 5202/.$shared_Binary./ 5203 5204MultiplicativeExpressionNotName ::= MultiplicativeExpressionNotName '%' 5205 UnaryExpression 5206\:$MakeBinaryExpression:\ 5207/.$shared_Binary./ 5208 5209MultiplicativeExpressionNotName ::= Name '%' UnaryExpression 5210\:$MakeBinaryExpression:\ 5211/.$shared_Binary./ 5212 5213AdditiveExpression ::= MultiplicativeExpression 5214\:$NoAction:\ 5215/.$shared_NoAction./ 5216 5217AdditiveExpression ::= AdditiveExpression '+' MultiplicativeExpression 5218\:$MakeBinaryExpression:\ 5219/.$shared_Binary./ 5220 5221AdditiveExpression ::= AdditiveExpression '-' MultiplicativeExpression 5222\:$MakeBinaryExpression:\ 5223/.$shared_Binary./ 5224 5225AdditiveExpressionNotName ::= MultiplicativeExpressionNotName 5226\:$NoAction:\ 5227/.$shared_NoAction./ 5228 5229AdditiveExpressionNotName ::= AdditiveExpressionNotName '+' 5230 MultiplicativeExpression 5231\:$MakeBinaryExpression:\ 5232/.$shared_Binary./ 5233 5234AdditiveExpressionNotName ::= Name '+' MultiplicativeExpression 5235\:$MakeBinaryExpression:\ 5236/.$shared_Binary./ 5237 5238AdditiveExpressionNotName ::= AdditiveExpressionNotName '-' 5239 MultiplicativeExpression 5240\:$MakeBinaryExpression:\ 5241/.$shared_Binary./ 5242 5243AdditiveExpressionNotName ::= Name '-' MultiplicativeExpression 5244\:$MakeBinaryExpression:\ 5245/.$shared_Binary./ 5246 5247ShiftExpression ::= AdditiveExpression 5248\:$NoAction:\ 5249/.$shared_NoAction./ 5250 5251ShiftExpression ::= ShiftExpression '<<' AdditiveExpression 5252\:$MakeBinaryExpression:\ 5253/.$shared_Binary./ 5254 5255ShiftExpression ::= ShiftExpression '>>' AdditiveExpression 5256\:$MakeBinaryExpression:\ 5257/.$shared_Binary./ 5258 5259ShiftExpression ::= ShiftExpression '>>>' AdditiveExpression 5260\:$MakeBinaryExpression:\ 5261/.$shared_Binary./ 5262 5263ShiftExpressionNotName ::= AdditiveExpressionNotName 5264\:$NoAction:\ 5265/.$shared_NoAction./ 5266 5267ShiftExpressionNotName ::= ShiftExpressionNotName '<<' AdditiveExpression 5268\:$MakeBinaryExpression:\ 5269/.$shared_Binary./ 5270 5271ShiftExpressionNotName ::= Name '<<' AdditiveExpression 5272\:$MakeBinaryExpression:\ 5273/.$shared_Binary./ 5274 5275ShiftExpressionNotName ::= ShiftExpressionNotName '>>' AdditiveExpression 5276\:$MakeBinaryExpression:\ 5277/.$shared_Binary./ 5278 5279ShiftExpressionNotName ::= Name '>>' AdditiveExpression 5280\:$MakeBinaryExpression:\ 5281/.$shared_Binary./ 5282 5283ShiftExpressionNotName ::= ShiftExpressionNotName '>>>' AdditiveExpression 5284\:$MakeBinaryExpression:\ 5285/.$shared_Binary./ 5286 5287ShiftExpressionNotName ::= Name '>>>' AdditiveExpression 5288\:$MakeBinaryExpression:\ 5289/.$shared_Binary./ 5290 5291RelationalExpression ::= ShiftExpression 5292\:$NoAction:\ 5293/.$shared_NoAction./ 5294 5295-- 5296-- Relational expressions do not operate on boolean. Rewriting this 5297-- rule avoids an ambiguity in generics with no semantic penalty. The 5298-- alternative is to lower the precedence of instanceof. 5299-- 5300--RelationalExpression ::= RelationalExpression '<' ShiftExpression 5301RelationalExpression ::= ShiftExpression '<' ShiftExpression 5302\:$MakeBinaryExpression:\ 5303/.$shared_Binary./ 5304 5305RelationalExpression ::= RelationalExpression '>' ShiftExpression 5306\:$MakeBinaryExpression:\ 5307/.$shared_Binary./ 5308 5309RelationalExpression ::= RelationalExpression '<=' ShiftExpression 5310\:$MakeBinaryExpression:\ 5311/.$shared_Binary./ 5312 5313RelationalExpression ::= RelationalExpression '>=' ShiftExpression 5314\:$MakeBinaryExpression:\ 5315/.$shared_Binary./ 5316 5317RelationalExpression ::= RelationalExpression 'instanceof' ReferenceType 5318\:$MakeInstanceofExpression:\ 5319/.$location 5320void Parser::MakeInstanceofExpression() 5321{ 5322 AstInstanceofExpression* p = ast_pool -> NewInstanceofExpression(); 5323 p -> expression = DYNAMIC_CAST<AstExpression*> (Sym(1)); 5324 p -> instanceof_token = Token(2); 5325 p -> type = DYNAMIC_CAST<AstType*> (Sym(3)); 5326 Sym(1) = p; 5327} 5328./ 5329 5330RelationalExpressionNotName ::= ShiftExpressionNotName 5331\:$NoAction:\ 5332/.$shared_NoAction./ 5333 5334--RelationalExpressionNotName ::= RelationalExpressionNotName '<' 5335-- ShiftExpression 5336RelationalExpressionNotName ::= ShiftExpressionNotName '<' ShiftExpression 5337\:$MakeBinaryExpression:\ 5338/.$shared_Binary./ 5339 5340RelationalExpressionNotName ::= Name '<' ShiftExpression 5341\:$MakeBinaryExpression:\ 5342/.$shared_Binary./ 5343 5344--RelationalExpressionNotName ::= RelationalExpressionNotName '>' 5345-- ShiftExpression 5346RelationalExpressionNotName ::= ShiftExpressionNotName '>' ShiftExpression 5347\:$MakeBinaryExpression:\ 5348/.$shared_Binary./ 5349 5350RelationalExpressionNotName ::= Name '>' ShiftExpression 5351\:$MakeBinaryExpression:\ 5352/.$shared_Binary./ 5353 5354RelationalExpressionNotName ::= RelationalExpressionNotName '<=' 5355 ShiftExpression 5356\:$MakeBinaryExpression:\ 5357/.$shared_Binary./ 5358 5359RelationalExpressionNotName ::= Name '<=' ShiftExpression 5360\:$MakeBinaryExpression:\ 5361/.$shared_Binary./ 5362 5363RelationalExpressionNotName ::= RelationalExpressionNotName '>=' 5364 ShiftExpression 5365\:$MakeBinaryExpression:\ 5366/.$shared_Binary./ 5367 5368RelationalExpressionNotName ::= Name '>=' ShiftExpression 5369\:$MakeBinaryExpression:\ 5370/.$shared_Binary./ 5371 5372RelationalExpressionNotName ::= RelationalExpressionNotName 'instanceof' 5373 ReferenceType 5374\:$MakeInstanceofExpression:\ 5375/.$shared_function 5376// 5377// void MakeInstanceofExpression(); 5378//./ 5379 5380RelationalExpressionNotName ::= Name 'instanceof' ReferenceType 5381\:$MakeInstanceofExpression:\ 5382/.$shared_function 5383// 5384// void MakeInstanceofExpression(); 5385//./ 5386 5387EqualityExpression ::= RelationalExpression 5388\:$NoAction:\ 5389/.$shared_NoAction./ 5390 5391EqualityExpression ::= EqualityExpression '==' RelationalExpression 5392\:$MakeBinaryExpression:\ 5393/.$shared_Binary./ 5394 5395EqualityExpression ::= EqualityExpression '!=' RelationalExpression 5396\:$MakeBinaryExpression:\ 5397/.$shared_Binary./ 5398 5399EqualityExpressionNotName ::= RelationalExpressionNotName 5400\:$NoAction:\ 5401/.$shared_NoAction./ 5402 5403EqualityExpressionNotName ::= EqualityExpressionNotName '==' 5404 RelationalExpression 5405\:$MakeBinaryExpression:\ 5406/.$shared_Binary./ 5407 5408EqualityExpressionNotName ::= Name '==' RelationalExpression 5409\:$MakeBinaryExpression:\ 5410/.$shared_Binary./ 5411 5412EqualityExpressionNotName ::= EqualityExpressionNotName '!=' 5413 RelationalExpression 5414\:$MakeBinaryExpression:\ 5415/.$shared_Binary./ 5416 5417EqualityExpressionNotName ::= Name '!=' RelationalExpression 5418\:$MakeBinaryExpression:\ 5419/.$shared_Binary./ 5420 5421AndExpression ::= EqualityExpression 5422\:$NoAction:\ 5423/.$shared_NoAction./ 5424 5425AndExpression ::= AndExpression '&' EqualityExpression 5426\:$MakeBinaryExpression:\ 5427/.$shared_Binary./ 5428 5429AndExpressionNotName ::= EqualityExpressionNotName 5430\:$NoAction:\ 5431/.$shared_NoAction./ 5432 5433AndExpressionNotName ::= AndExpressionNotName '&' EqualityExpression 5434\:$MakeBinaryExpression:\ 5435/.$shared_Binary./ 5436 5437AndExpressionNotName ::= Name '&' EqualityExpression 5438\:$MakeBinaryExpression:\ 5439/.$shared_Binary./ 5440 5441ExclusiveOrExpression ::= AndExpression 5442\:$NoAction:\ 5443/.$shared_NoAction./ 5444 5445ExclusiveOrExpression ::= ExclusiveOrExpression '^' AndExpression 5446\:$MakeBinaryExpression:\ 5447/.$shared_Binary./ 5448 5449ExclusiveOrExpressionNotName ::= AndExpressionNotName 5450\:$NoAction:\ 5451/.$shared_NoAction./ 5452 5453ExclusiveOrExpressionNotName ::= ExclusiveOrExpressionNotName '^' AndExpression 5454\:$MakeBinaryExpression:\ 5455/.$shared_Binary./ 5456 5457ExclusiveOrExpressionNotName ::= Name '^' AndExpression 5458\:$MakeBinaryExpression:\ 5459/.$shared_Binary./ 5460 5461InclusiveOrExpression ::= ExclusiveOrExpression 5462\:$NoAction:\ 5463/.$shared_NoAction./ 5464 5465InclusiveOrExpression ::= InclusiveOrExpression '|' ExclusiveOrExpression 5466\:$MakeBinaryExpression:\ 5467/.$shared_Binary./ 5468 5469InclusiveOrExpressionNotName ::= ExclusiveOrExpressionNotName 5470\:$NoAction:\ 5471/.$shared_NoAction./ 5472 5473InclusiveOrExpressionNotName ::= InclusiveOrExpressionNotName '|' 5474 ExclusiveOrExpression 5475\:$MakeBinaryExpression:\ 5476/.$shared_Binary./ 5477 5478InclusiveOrExpressionNotName ::= Name '|' ExclusiveOrExpression 5479\:$MakeBinaryExpression:\ 5480/.$shared_Binary./ 5481 5482ConditionalAndExpression ::= InclusiveOrExpression 5483\:$NoAction:\ 5484/.$shared_NoAction./ 5485 5486ConditionalAndExpression ::= ConditionalAndExpression '&&' 5487 InclusiveOrExpression 5488\:$MakeBinaryExpression:\ 5489/.$shared_Binary./ 5490 5491ConditionalAndExpressionNotName ::= InclusiveOrExpressionNotName 5492\:$NoAction:\ 5493/.$shared_NoAction./ 5494 5495ConditionalAndExpressionNotName ::= ConditionalAndExpressionNotName '&&' 5496 InclusiveOrExpression 5497\:$MakeBinaryExpression:\ 5498/.$shared_Binary./ 5499 5500ConditionalAndExpressionNotName ::= Name '&&' InclusiveOrExpression 5501\:$MakeBinaryExpression:\ 5502/.$shared_Binary./ 5503 5504ConditionalOrExpression ::= ConditionalAndExpression 5505\:$NoAction:\ 5506/.$shared_NoAction./ 5507 5508ConditionalOrExpression ::= ConditionalOrExpression '||' 5509 ConditionalAndExpression 5510\:$MakeBinaryExpression:\ 5511/.$shared_Binary./ 5512 5513ConditionalOrExpressionNotName ::= ConditionalAndExpressionNotName 5514\:$NoAction:\ 5515/.$shared_NoAction./ 5516 5517ConditionalOrExpressionNotName ::= ConditionalOrExpressionNotName '||' 5518 ConditionalAndExpression 5519\:$MakeBinaryExpression:\ 5520/.$shared_Binary./ 5521 5522ConditionalOrExpressionNotName ::= Name '||' ConditionalAndExpression 5523\:$MakeBinaryExpression:\ 5524/.$shared_Binary./ 5525 5526ConditionalExpression ::= ConditionalOrExpression 5527\:$NoAction:\ 5528/.$shared_NoAction./ 5529 5530ConditionalExpression ::= ConditionalOrExpression '?' Expression ':' 5531 ConditionalExpression 5532\:$MakeConditionalExpression:\ 5533/.$location 5534void Parser::MakeConditionalExpression() 5535{ 5536 AstConditionalExpression* p = ast_pool -> NewConditionalExpression(); 5537 p -> test_expression = DYNAMIC_CAST<AstExpression*> (Sym(1)); 5538 p -> question_token = Token(2); 5539 p -> true_expression = DYNAMIC_CAST<AstExpression*> (Sym(3)); 5540 p -> colon_token = Token(4); 5541 p -> false_expression = DYNAMIC_CAST<AstExpression*> (Sym(5)); 5542 Sym(1) = p; 5543} 5544./ 5545 5546ConditionalExpressionNotName ::= ConditionalOrExpressionNotName 5547\:$NoAction:\ 5548/.$shared_NoAction./ 5549 5550ConditionalExpressionNotName ::= ConditionalOrExpressionNotName '?' Expression 5551 ':' ConditionalExpression 5552\:$MakeConditionalExpression:\ 5553/.$shared_function 5554// 5555// void MakeConditionalExpression(); 5556//./ 5557 5558ConditionalExpressionNotName ::= Name '?' Expression ':' ConditionalExpression 5559\:$MakeConditionalExpression:\ 5560/.$shared_function 5561// 5562// void MakeConditionalExpression(); 5563//./ 5564 5565AssignmentExpression ::= ConditionalExpression 5566\:$NoAction:\ 5567/.$shared_NoAction./ 5568 5569AssignmentExpression ::= Assignment 5570\:$NoAction:\ 5571/.$shared_NoAction./ 5572 5573AssignmentExpressionNotName ::= ConditionalExpressionNotName 5574\:$NoAction:\ 5575/.$shared_NoAction./ 5576 5577AssignmentExpressionNotName ::= Assignment 5578\:$NoAction:\ 5579/.$shared_NoAction./ 5580 5581-- 5582-- The original grammar uses LeftHandSide, instead of PostfixExpression. 5583-- However, parenthesized variables were added in JLS 2, and the 5584-- grammar is ambiguous unless we include all non-assignment 5585-- expressions. The semantic pass will filter out bad left-hand sides. 5586-- 5587--Assignment ::= LeftHandSide AssignmentOperator AssignmentExpression 5588Assignment ::= PostfixExpression AssignmentOperator AssignmentExpression 5589\:$action:\ 5590/.$location 5591void Parser::Act$rule_number() 5592{ 5593 AstAssignmentExpression::AssignmentExpressionTag tag; 5594 switch (lex_stream -> Kind(Token(2))) 5595 { 5596 case TK_EQUAL: tag = AstAssignmentExpression::SIMPLE_EQUAL; break; 5597 case TK_MULTIPLY_EQUAL: tag = AstAssignmentExpression::STAR_EQUAL; break; 5598 case TK_DIVIDE_EQUAL: tag = AstAssignmentExpression::SLASH_EQUAL; break; 5599 case TK_REMAINDER_EQUAL: tag = AstAssignmentExpression::MOD_EQUAL; break; 5600 case TK_PLUS_EQUAL: tag = AstAssignmentExpression::PLUS_EQUAL; break; 5601 case TK_MINUS_EQUAL: tag = AstAssignmentExpression::MINUS_EQUAL; break; 5602 case TK_LEFT_SHIFT_EQUAL: 5603 tag = AstAssignmentExpression::LEFT_SHIFT_EQUAL; break; 5604 case TK_RIGHT_SHIFT_EQUAL: 5605 tag = AstAssignmentExpression::RIGHT_SHIFT_EQUAL; break; 5606 case TK_UNSIGNED_RIGHT_SHIFT_EQUAL: 5607 tag = AstAssignmentExpression::UNSIGNED_RIGHT_SHIFT_EQUAL; break; 5608 case TK_AND_EQUAL: tag = AstAssignmentExpression::AND_EQUAL; break; 5609 case TK_XOR_EQUAL: tag = AstAssignmentExpression::XOR_EQUAL; break; 5610 case TK_OR_EQUAL: tag = AstAssignmentExpression::IOR_EQUAL; break; 5611 default: tag = AstAssignmentExpression::NONE; 5612 } 5613 AstAssignmentExpression* p = 5614 ast_pool -> NewAssignmentExpression(tag, Token(2)); 5615 p -> left_hand_side = DYNAMIC_CAST<AstExpression*> (Sym(1)); 5616 p -> expression = DYNAMIC_CAST<AstExpression*> (Sym(3)); 5617 Sym(1) = p; 5618} 5619./ 5620 5621-- 5622-- See comments above for Assignment - LeftHandSide is now a useless rule. 5623-- 5624--LeftHandSide -> Name 5625--LeftHandSide -> FieldAccess 5626--LeftHandSide -> ArrayAccess 5627 5628AssignmentOperator ::= '=' 5629\:$NoAction:\ 5630/.$shared_NoAction./ 5631 5632AssignmentOperator ::= '*=' 5633\:$NoAction:\ 5634/.$shared_NoAction./ 5635 5636AssignmentOperator ::= '/=' 5637\:$NoAction:\ 5638/.$shared_NoAction./ 5639 5640AssignmentOperator ::= '%=' 5641\:$NoAction:\ 5642/.$shared_NoAction./ 5643 5644AssignmentOperator ::= '+=' 5645\:$NoAction:\ 5646/.$shared_NoAction./ 5647 5648AssignmentOperator ::= '-=' 5649\:$NoAction:\ 5650/.$shared_NoAction./ 5651 5652AssignmentOperator ::= '<<=' 5653\:$NoAction:\ 5654/.$shared_NoAction./ 5655 5656AssignmentOperator ::= '>>=' 5657\:$NoAction:\ 5658/.$shared_NoAction./ 5659 5660AssignmentOperator ::= '>>>=' 5661\:$NoAction:\ 5662/.$shared_NoAction./ 5663 5664AssignmentOperator ::= '&=' 5665\:$NoAction:\ 5666/.$shared_NoAction./ 5667 5668AssignmentOperator ::= '^=' 5669\:$NoAction:\ 5670/.$shared_NoAction./ 5671 5672AssignmentOperator ::= '|=' 5673\:$NoAction:\ 5674/.$shared_NoAction./ 5675 5676Expression ::= AssignmentExpression 5677\:$NoAction:\ 5678/.$shared_NoAction./ 5679 5680Expressionopt ::= $empty 5681\:$NullAction:\ 5682/.$shared_NullAction./ 5683 5684Expressionopt ::= Expression 5685\:$NoAction:\ 5686/.$shared_NoAction./ 5687 5688ExpressionNotName ::= AssignmentExpressionNotName 5689\:$NoAction:\ 5690/.$shared_NoAction./ 5691 5692-- 5693-- Simplify the syntax tree. 5694-- 5695--ConstantExpression ::= Expression 5696 5697----------------------------------------------------------------------------- 5698-- 5699-- The following rules are for optional and helper productions. 5700-- 5701----------------------------------------------------------------------------- 5702 5703-- 5704-- This rule exists solely to put NULL on the symbol stack, allowing us to 5705-- share productions that differ by the presence or absence of a rule. 5706-- 5707Marker ::= $empty 5708\:$NullAction:\ 5709/.$shared_NullAction./ 5710 5711,opt ::= $empty 5712\:$NoAction:\ 5713/.$shared_NoAction./ 5714 5715,opt ::= ',' 5716\:$NoAction:\ 5717/.$shared_NoAction./ 5718 5719Identifieropt ::= $empty 5720\:$NoAction:\ 5721/.$shared_NoAction./ 5722 5723Identifieropt ::= 'Identifier' 5724\:$NoAction:\ 5725/.$shared_NoAction./ 5726 5727PackageHeaderMarker ::= $empty 5728\:$action:\ 5729/.$location 5730// 5731// When this function is invoked, if the "parse_package_header_only" flag 5732// is turned on, we skip to the end-of-file token. 5733// 5734void Parser::Act$rule_number() 5735{ 5736 if (parse_package_header_only) 5737 // point to the EOF token 5738 lex_stream -> Reset(lex_stream -> NumTokens() - 1); 5739 Sym(1) = NULL; 5740} 5741./ 5742 5743MethodHeaderMarker ::= $empty 5744\:$action:\ 5745/.$location 5746// 5747// When this function is invoked, if the "parse_header_only" flag 5748// is turned on, the body of the method being parsed is skipped. 5749// 5750void Parser::Act$rule_number() 5751{ 5752 if (parse_header_only) 5753 { 5754 TokenObject token = Token(1); 5755 5756 // 5757 // If the first token immediately following the method header 5758 // is not an open brace, then we have a syntactic error. Do 5759 // nothing and let the error recovery take care of it. 5760 // 5761 if (lex_stream -> Kind(token) == TK_LBRACE) 5762 lex_stream -> Reset(lex_stream -> MatchingBrace(token)); 5763 } 5764 Sym(1) = NULL; 5765} 5766./ 5767 5768----------------------------------------------------------------------------- 5769-- 5770-- These rules add generics. Also search for JSR 14 in the comments above. 5771-- 5772----------------------------------------------------------------------------- 5773 5774-- 5775-- Parameterized types were added in JSR 14. 5776-- 5777TypeArguments ::= '<' TypeArgumentList1 5778\:$SetSym1ToSym2:\ 5779/.$shared_function 5780// 5781// void SetSym1ToSym2(); 5782//./ 5783 5784-- 5785-- Parameterized types were added in JSR 14. 5786-- 5787TypeArgumentsopt ::= $empty 5788\:$NullAction:\ 5789/.$shared_NullAction./ 5790 5791-- 5792-- Parameterized types were added in JSR 14. 5793-- 5794TypeArgumentsopt ::= TypeArguments 5795\:$NoAction:\ 5796/.$shared_NoAction./ 5797 5798-- 5799-- Parameterized types were added in JSR 14. We inline expanded WildcardBounds 5800-- for simplicity. The use of Marker allows us to share code. 5801-- 5802--Wildcard ::= '?' WildcardBoundsopt 5803--WildcardBounds ::= extends ReferenceType 5804--WildcardBounds ::= super ReferenceType 5805-- 5806Wildcard ::= '?' Marker Marker Marker 5807\:$MakeWildcard:\ 5808/.$location 5809void Parser::MakeWildcard() 5810{ 5811 AstWildcard* p = ast_pool -> NewWildcard(Token(1)); 5812 if (Token(3) > Token(2)) 5813 { 5814 p -> extends_token_opt = Token(2); 5815 p -> bounds_opt = DYNAMIC_CAST<AstType*> (Sym(4)); 5816 } 5817 else if (Token(4) > Token(3)) 5818 { 5819 p -> super_token_opt = Token(3); 5820 p -> bounds_opt = DYNAMIC_CAST<AstType*> (Sym(4)); 5821 } 5822 Sym(1) = p; 5823} 5824./ 5825 5826-- 5827-- Parameterized types were added in JSR 14. 5828-- The use of Marker allows us to share code. 5829-- 5830Wildcard ::= '?' 'extends' Marker ReferenceType 5831\:$MakeWildcard:\ 5832/.$shared_function 5833// 5834// void MakeWildcard(); 5835//./ 5836 5837-- 5838-- Parameterized types were added in JSR 14. 5839-- The use of Marker allows us to share code. 5840-- 5841Wildcard ::= '?' Marker 'super' ReferenceType 5842\:$MakeWildcard:\ 5843/.$shared_function 5844// 5845// void MakeWildcard(); 5846//./ 5847 5848-- 5849-- Parameterized types were added in JSR 14. 5850-- The use of Marker allows us to share code. 5851-- 5852Wildcard1 ::= '?' Marker Marker '>' 5853\:$MakeWildcard:\ 5854/.$shared_function 5855// 5856// void MakeWildcard(); 5857//./ 5858 5859-- 5860-- Parameterized types were added in JSR 14. 5861-- The use of Marker allows us to share code. 5862-- 5863Wildcard1 ::= '?' 'extends' Marker ReferenceType1 5864\:$MakeWildcard:\ 5865/.$shared_function 5866// 5867// void MakeWildcard(); 5868//./ 5869 5870-- 5871-- Parameterized types were added in JSR 14. 5872-- The use of Marker allows us to share code. 5873-- 5874Wildcard1 ::= '?' Marker 'super' ReferenceType1 5875\:$MakeWildcard:\ 5876/.$shared_function 5877// 5878// void MakeWildcard(); 5879//./ 5880 5881-- 5882-- Parameterized types were added in JSR 14. 5883-- The use of Marker allows us to share code. 5884-- 5885Wildcard2 ::= '?' Marker Marker '>>' 5886\:$MakeWildcard:\ 5887/.$shared_function 5888// 5889// void MakeWildcard(); 5890//./ 5891 5892-- 5893-- Parameterized types were added in JSR 14. 5894-- The use of Marker allows us to share code. 5895-- 5896Wildcard2 ::= '?' 'extends' Marker ReferenceType2 5897\:$MakeWildcard:\ 5898/.$shared_function 5899// 5900// void MakeWildcard(); 5901//./ 5902 5903-- 5904-- Parameterized types were added in JSR 14. 5905-- The use of Marker allows us to share code. 5906-- 5907Wildcard2 ::= '?' Marker 'super' ReferenceType2 5908\:$MakeWildcard:\ 5909/.$shared_function 5910// 5911// void MakeWildcard(); 5912//./ 5913 5914-- 5915-- Parameterized types were added in JSR 14. 5916-- The use of Marker allows us to share code. 5917-- 5918Wildcard3 ::= '?' Marker Marker '>>>' 5919\:$MakeWildcard:\ 5920/.$shared_function 5921// 5922// void MakeWildcard(); 5923//./ 5924 5925-- 5926-- Parameterized types were added in JSR 14. 5927-- The use of Marker allows us to share code. 5928-- 5929Wildcard3 ::= '?' 'extends' Marker ReferenceType3 5930\:$MakeWildcard:\ 5931/.$shared_function 5932// 5933// void MakeWildcard(); 5934//./ 5935 5936-- 5937-- Parameterized types were added in JSR 14. 5938-- The use of Marker allows us to share code. 5939-- 5940Wildcard3 ::= '?' Marker 'super' ReferenceType3 5941\:$MakeWildcard:\ 5942/.$shared_function 5943// 5944// void MakeWildcard(); 5945//./ 5946 5947-- 5948-- Parameterized types were added in JSR 14. 5949-- 5950TypeArgumentList ::= TypeArgument 5951\:$StartList:\ 5952/.$shared_StartList./ 5953 5954-- 5955-- Parameterized types were added in JSR 14. 5956-- 5957TypeArgumentList ::= TypeArgumentList ',' TypeArgument 5958\:$AddList3:\ 5959/.$shared_AddList3./ 5960 5961-- 5962-- Parameterized types were added in JSR 14. 5963-- 5964TypeArgumentList1 ::= TypeArgument1 5965\:$StartList:\ 5966/.$shared_StartList./ 5967 5968-- 5969-- Parameterized types were added in JSR 14. 5970-- 5971TypeArgumentList1 ::= TypeArgumentList ',' TypeArgument1 5972\:$AddList3:\ 5973/.$shared_AddList3./ 5974 5975-- 5976-- Parameterized types were added in JSR 14. 5977-- 5978TypeArgumentList2 ::= TypeArgument2 5979\:$StartList:\ 5980/.$shared_StartList./ 5981 5982-- 5983-- Parameterized types were added in JSR 14. 5984-- 5985TypeArgumentList2 ::= TypeArgumentList ',' TypeArgument2 5986\:$AddList3:\ 5987/.$shared_AddList3./ 5988 5989-- 5990-- Parameterized types were added in JSR 14. 5991-- 5992TypeArgumentList3 ::= TypeArgument3 5993\:$StartList:\ 5994/.$shared_StartList./ 5995 5996-- 5997-- Parameterized types were added in JSR 14. 5998-- 5999TypeArgumentList3 ::= TypeArgumentList ',' TypeArgument3 6000\:$AddList3:\ 6001/.$shared_AddList3./ 6002 6003-- 6004-- Parameterized types were added in JSR 14. 6005-- 6006TypeArgument ::= ReferenceType 6007\:$NoAction:\ 6008/.$shared_NoAction./ 6009 6010-- 6011-- Parameterized types were added in JSR 14. 6012-- 6013TypeArgument ::= Wildcard 6014\:$NoAction:\ 6015/.$shared_NoAction./ 6016 6017-- 6018-- Parameterized types were added in JSR 14. 6019-- 6020TypeArgument1 ::= ReferenceType1 6021\:$NoAction:\ 6022/.$shared_NoAction./ 6023 6024-- 6025-- Parameterized types were added in JSR 14. 6026-- 6027TypeArgument1 ::= Wildcard1 6028\:$NoAction:\ 6029/.$shared_NoAction./ 6030 6031-- 6032-- Parameterized types were added in JSR 14. 6033-- 6034TypeArgument2 ::= ReferenceType2 6035\:$NoAction:\ 6036/.$shared_NoAction./ 6037 6038-- 6039-- Parameterized types were added in JSR 14. 6040-- 6041TypeArgument2 ::= Wildcard2 6042\:$NoAction:\ 6043/.$shared_NoAction./ 6044 6045-- 6046-- Parameterized types were added in JSR 14. 6047-- 6048TypeArgument3 ::= ReferenceType3 6049\:$NoAction:\ 6050/.$shared_NoAction./ 6051 6052-- 6053-- Parameterized types were added in JSR 14. 6054-- 6055TypeArgument3 ::= Wildcard3 6056\:$NoAction:\ 6057/.$shared_NoAction./ 6058 6059-- 6060-- Parameterized types were added in JSR 14. 6061-- 6062ReferenceType1 ::= ReferenceType '>' 6063\:$NoAction:\ 6064/.$shared_NoAction./ 6065 6066-- 6067-- Parameterized types were added in JSR 14. 6068-- Use of Marker allows us to easily find the closing '>>'. 6069-- 6070ReferenceType1 ::= ClassOrInterface '<' TypeArgumentList2 Marker 6071\:$MakeTypeArguments:\ 6072/.$shared_function 6073// 6074// void MakeTypeArguments(); 6075//./ 6076 6077-- 6078-- Parameterized types were added in JSR 14. 6079-- 6080ReferenceType2 ::= ReferenceType '>>' 6081\:$NoAction:\ 6082/.$shared_NoAction./ 6083 6084-- 6085-- Parameterized types were added in JSR 14. 6086-- Use of Marker allows us to easily find the closing '>>>'. 6087-- 6088ReferenceType2 ::= ClassOrInterface '<' TypeArgumentList3 Marker 6089\:$MakeTypeArguments:\ 6090/.$shared_function 6091// 6092// void MakeTypeArguments(); 6093//./ 6094 6095-- 6096-- Parameterized types were added in JSR 14. 6097-- 6098ReferenceType3 ::= ReferenceType '>>>' 6099\:$NoAction:\ 6100/.$shared_NoAction./ 6101 6102-- 6103-- Parameterized types were added in JSR 14. 6104-- 6105TypeParameters ::= '<' TypeParameterList1 6106\:$SetSym1ToSym2:\ 6107/.$shared_function 6108// 6109// void SetSym1ToSym2(); 6110//./ 6111 6112-- 6113-- Parameterized types were added in JSR 14. 6114-- 6115TypeParametersopt ::= $empty 6116\:$NullAction:\ 6117/.$shared_NullAction./ 6118 6119-- 6120-- Parameterized types were added in JSR 14. 6121-- 6122TypeParametersopt ::= TypeParameters 6123\:$NoAction:\ 6124/.$shared_NoAction./ 6125 6126-- 6127-- Parameterized types were added in JSR 14. 6128-- 6129TypeParameterList ::= TypeParameter 6130\:$StartList:\ 6131/.$shared_StartList./ 6132 6133-- 6134-- Parameterized types were added in JSR 14. 6135-- 6136TypeParameterList ::= TypeParameterList ',' TypeParameter 6137\:$AddList3:\ 6138/.$shared_AddList3./ 6139 6140-- 6141-- Parameterized types were added in JSR 14. 6142-- 6143TypeParameterList1 ::= TypeParameter1 6144\:$StartList:\ 6145/.$shared_StartList./ 6146 6147-- 6148-- Parameterized types were added in JSR 14. 6149-- 6150TypeParameterList1 ::= TypeParameterList ',' TypeParameter1 6151\:$AddList3:\ 6152/.$shared_AddList3./ 6153 6154-- 6155-- Parameterized types were added in JSR 14. 6156-- 6157TypeParameter ::= 'Identifier' TypeBoundopt 6158\:$MakeTypeParameter:\ 6159/.$location 6160void Parser::MakeTypeParameter() 6161{ 6162 AstTypeParameter* p = ast_pool -> NewTypeParameter(Token(1)); 6163 if (Sym(2)) 6164 { 6165 // 6166 // Remember, we built the circular list with the first element at 6167 // the tail of the list, because of the grammar of TypeBound. 6168 // 6169 AstListNode* tail = DYNAMIC_CAST<AstListNode*> (Sym(2)); 6170 p -> AllocateBounds(tail -> index + 1); 6171 AstListNode* root = tail; 6172 do 6173 { 6174 p -> AddBound(DYNAMIC_CAST<AstTypeName*> (root -> element)); 6175 root = root -> next; 6176 } while (root != tail); 6177 FreeCircularList(tail); 6178 } 6179 Sym(1) = p; 6180} 6181./ 6182 6183-- 6184-- Parameterized types were added in JSR 14. 6185-- The use of Marker allows us to share code. 6186-- 6187TypeParameter1 ::= 'Identifier' Marker '>' 6188\:$MakeTypeParameter:\ 6189/.$shared_function 6190// 6191// void MakeTypeParameter(); 6192//./ 6193 6194-- 6195-- Parameterized types were added in JSR 14. 6196-- 6197TypeParameter1 ::= 'Identifier' TypeBound1 6198\:$MakeTypeParameter:\ 6199/.$shared_function 6200// 6201// void MakeTypeParameter(); 6202//./ 6203 6204-- 6205-- Parameterized types were added in JSR 14. 6206-- 6207TypeBound ::= 'extends' ReferenceType AdditionalBoundListopt 6208\:$MakeTypeBound:\ 6209/.$location 6210void Parser::MakeTypeBound() 6211{ 6212 // 6213 // Unlike most AstListNodes, we stick Sym(2) at the end of the list 6214 // instead of the beginning. MakeTypeParameter expects this unusual 6215 // ordering, because it is easier than rewriting the grammar to build the 6216 // list in lexical order. 6217 // 6218 if (Sym(3)) 6219 { 6220 Sym(1) = Sym(3); 6221 AddList2(); 6222 } 6223 else 6224 { 6225 Sym(1) = Sym(2); 6226 StartList(); 6227 } 6228} 6229./ 6230 6231-- 6232-- Parameterized types were added in JSR 14. 6233-- 6234TypeBoundopt ::= $empty 6235\:$NullAction:\ 6236/.$shared_NullAction./ 6237 6238-- 6239-- Parameterized types were added in JSR 14. 6240-- 6241TypeBoundopt ::= TypeBound 6242\:$NoAction:\ 6243/.$shared_NoAction./ 6244 6245-- 6246-- Parameterized types were added in JSR 14. 6247-- The use of Marker allows us to share code. 6248-- 6249TypeBound1 ::= 'extends' ReferenceType1 Marker 6250\:$MakeTypeBound:\ 6251/.$shared_function 6252// 6253// void MakeTypeBound(); 6254//./ 6255 6256-- 6257-- Parameterized types were added in JSR 14. 6258-- 6259TypeBound1 ::= 'extends' ReferenceType AdditionalBoundList1 6260\:$MakeTypeBound:\ 6261/.$shared_function 6262// 6263// void MakeTypeBound(); 6264//./ 6265 6266-- 6267-- Parameterized types were added in JSR 14. 6268-- 6269AdditionalBoundList ::= AdditionalBound 6270\:$StartList:\ 6271/.$shared_StartList./ 6272 6273-- 6274-- Parameterized types were added in JSR 14. 6275-- 6276AdditionalBoundList ::= AdditionalBoundList AdditionalBound 6277\:$AddList2:\ 6278/.$shared_AddList2./ 6279 6280-- 6281-- Parameterized types were added in JSR 14. 6282-- 6283AdditionalBoundListopt ::= $empty 6284\:$NullAction:\ 6285/.$shared_NullAction./ 6286 6287-- 6288-- Parameterized types were added in JSR 14. 6289-- 6290AdditionalBoundListopt ::= AdditionalBoundList 6291\:$NoAction:\ 6292/.$shared_NoAction./ 6293 6294-- 6295-- Parameterized types were added in JSR 14. 6296-- 6297AdditionalBoundList1 ::= AdditionalBound1 6298\:$StartList:\ 6299/.$shared_StartList./ 6300 6301-- 6302-- Parameterized types were added in JSR 14. 6303-- 6304AdditionalBoundList1 ::= AdditionalBoundList AdditionalBound1 6305\:$AddList2:\ 6306/.$shared_AddList2./ 6307 6308-- 6309-- Parameterized types were added in JSR 14. 6310-- 6311AdditionalBound ::= '&' ClassOrInterfaceType 6312\:$SetSym1ToSym2:\ 6313/.$shared_function 6314// 6315// void SetSym1ToSym2(); 6316//./ 6317 6318-- 6319-- Parameterized types were added in JSR 14. 6320-- 6321AdditionalBound1 ::= '&' ClassOrInterfaceType1 6322\:$SetSym1ToSym2:\ 6323/.$shared_function 6324// 6325// void SetSym1ToSym2(); 6326//./ 6327 6328-- 6329-- Parameterized types were added in JSR 14. 6330-- 6331ClassOrInterfaceType1 ::= ClassOrInterfaceType '>' 6332\:$NoAction:\ 6333/.$shared_NoAction./ 6334 6335-- 6336-- Parameterized types were added in JSR 14. 6337-- Use of Marker allows us to easily find the closing '>>'. 6338-- 6339ClassOrInterfaceType1 ::= ClassOrInterface '<' TypeArgumentList2 Marker 6340\:$MakeTypeArguments:\ 6341/.$shared_function 6342// 6343// void MakeTypeArguments(); 6344//./ 6345 6346------ Finish off the files 6347/. 6348#ifdef HAVE_JIKES_NAMESPACE 6349} // Close namespace Jikes block 6350#endif 6351./ 6352 6353\: 6354#ifndef HEADERS 6355 return; 6356} 6357 6358#ifdef HAVE_JIKES_NAMESPACE 6359} // Close namespace Jikes block 6360#endif 6361 6362#endif // ! HEADERS 6363:\ 6364 6365-- Names allow diagnose.cpp debug output to be more legible 6366$names 6367 6368BodyMarker ::= '"class Identifier { ... MethodHeader "' 6369 6370PLUS_PLUS ::= '++' 6371MINUS_MINUS ::= '--' 6372EQUAL_EQUAL ::= '==' 6373LESS_EQUAL ::= '<=' 6374GREATER_EQUAL ::= '>=' 6375NOT_EQUAL ::= '!=' 6376LEFT_SHIFT ::= '<<' 6377RIGHT_SHIFT ::= '>>' 6378UNSIGNED_RIGHT_SHIFT ::= '>>>' 6379PLUS_EQUAL ::= '+=' 6380MINUS_EQUAL ::= '-=' 6381MULTIPLY_EQUAL ::= '*=' 6382DIVIDE_EQUAL ::= '/=' 6383AND_EQUAL ::= '&=' 6384OR_EQUAL ::= '|=' 6385XOR_EQUAL ::= '^=' 6386REMAINDER_EQUAL ::= '%=' 6387LEFT_SHIFT_EQUAL ::= '<<=' 6388RIGHT_SHIFT_EQUAL ::= '>>=' 6389UNSIGNED_RIGHT_SHIFT_EQUAL ::= '>>>=' 6390OR_OR ::= '||' 6391AND_AND ::= '&&' 6392PLUS ::= '+' 6393MINUS ::= '-' 6394NOT ::= '!' 6395REMAINDER ::= '%' 6396XOR ::= '^' 6397AND ::= '&' 6398MULTIPLY ::= '*' 6399OR ::= '|' 6400TWIDDLE ::= '~' 6401DIVIDE ::= '/' 6402GREATER ::= '>' 6403LESS ::= '<' 6404LPAREN ::= '(' 6405RPAREN ::= ')' 6406LBRACE ::= '{' 6407RBRACE ::= '}' 6408LBRACKET ::= '[' 6409RBRACKET ::= ']' 6410SEMICOLON ::= ';' 6411QUESTION ::= '?' 6412COLON ::= ':' 6413COMMA ::= ',' 6414DOT ::= '.' 6415EQUAL ::= '=' 6416AT ::= '@' 6417ELLIPSIS ::= '...' 6418 6419StatementNoShortIf ::= 'Statement' 6420StatementWithoutTrailingSubstatement ::= 'Statement' 6421LabeledStatementNoShortIf ::= 'LabeledStatement' 6422IfThenElseStatementNoShortIf ::= 'IfThenElseStatement' 6423WhileStatementNoShortIf ::= 'WhileStatement' 6424ForStatementNoShortIf ::= 'ForStatement' 6425ForeachStatementNoShortIf ::= 'ForeachStatement' 6426UnaryExpressionNotPlusMinus ::= 'UnaryExpression' 6427 6428PostfixExpressionNotName ::= 'PostfixExpression' 6429UnaryExpressionNotName ::= 'UnaryExpression' 6430UnaryExpressionNotPlusMinusNotName ::= 'UnaryExpression' 6431MultiplicativeExpressionNotName ::= 'MultiplicativeExpression' 6432AdditiveExpressionNotName ::= 'AdditiveExpression' 6433ShiftExpressionNotName ::= 'ShiftExpression' 6434RelationalExpressionNotName ::= 'RelationalExpression' 6435EqualityExpressionNotName ::= 'EqualityExpression' 6436AndExpressionNotName ::= 'AndExpression' 6437ExclusiveOrExpressionNotName ::= 'ExclusiveOrExpression' 6438InclusiveOrExpressionNotName ::= 'InclusiveOrExpression' 6439ConditionalAndExpressionNotName ::= 'ConditionalAndExpression' 6440ConditionalOrExpressionNotName ::= 'ConditionalOrExpression' 6441ConditionalExpressionNotName ::= 'ConditionalExpression' 6442AssignmentExpressionNotName ::= 'AssignmentExpression' 6443ExpressionNotName ::= 'Expression' 6444 6445Wildcard1 ::= 'Wildcard' 6446Wildcard2 ::= 'Wildcard' 6447Wildcard3 ::= 'Wildcard' 6448TypeArgumentList1 ::= 'TypeArgumentList' 6449TypeArgumentList2 ::= 'TypeArgumentList' 6450TypeArgumentList3 ::= 'TypeArgumentList' 6451TypeArgument1 ::= 'TypeArgument' 6452TypeArgument2 ::= 'TypeArgument' 6453TypeArgument3 ::= 'TypeArgument' 6454ReferenceType1 ::= 'ReferenceType' 6455ReferenceType2 ::= 'ReferenceType' 6456ReferenceType3 ::= 'ReferenceType' 6457TypeParameterList1 ::= 'TypeParameterList' 6458TypeParameter1 ::= 'TypeParameter' 6459TypeBound1 ::= 'TypeBound' 6460AdditionalBoundList1 ::= 'AdditionalBoundList' 6461AdditionalBound1 ::= 'AdditionalBound' 6462ClassOrInterfaceType1 ::= 'ClassOrInterfaceType' 6463 6464$end 6465