/* * xtc - The eXTensible Compiler * Copyright (C) 2004-2005 Robert Grimm, New York University * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /** * Definition of Java's hierarchical syntax. * * @author Stacey Kuznetsov * @author Robert Grimm * @version $Revision: 1.2 $ */ module xtc.lang.JavaCore(Type, Constant, Identifier, Symbol, Spacing); import Type; import Constant; import Identifier; import Symbol; import Spacing; // ---------------------------------------------------------- Compilation Unit public transient generic CompilationUnit = Spacing PackageDeclaration? ImportDeclaration* Declaration* void:'\u001a'? EndOfFile ; transient generic PackageDeclaration = void:"package":Word QualifiedIdentifier void:";":Symbol ; transient generic ImportDeclaration = void:"import":Word QualifiedIdentifier DotStarTail? void:";":Symbol ; transient generic DotStarTail = void:".":Symbol void:"*":Symbol ; // ---------------------------------------------------------- Declarations generic Modifiers = Modifier* ; String Modifier = "public":Word / "protected":Word / "private":Word / "static":Word / "abstract":Word / "final":Word / "native":Word / "synchronized":Word / "transient":Word / "volatile":Word / "strictfp":Word ; transient generic FormalParameter = FinalClause? Type Identifier Dimensions? ; generic FinalClause = void:"final":Word ; generic FormalParameters = void:"(":Symbol FormalParameter ( void:",":Symbol FormalParameter )* void:")":Symbol / void:"(":Symbol void:")":Symbol ; transient generic Declarator = Identifier Dimensions? ( void:"=":Symbol VariableInitializer )? ; generic Declarators = Declarator ( void:",":Symbol Declarator )* ; transient generic ClassBody = void:"{":Symbol Declaration* void:"}":Symbol ; transient GNode Declaration = FieldDeclaration / MethodDeclaration / ConstructorDeclaration / ClassDeclaration / InterfaceDeclaration / BlockDeclaration ; generic FieldDeclaration = Modifiers Type Declarators void:";":Symbol ; generic MethodDeclaration = Modifiers ResultType Identifier FormalParameters Dimensions? OptionalThrowsClause? ( Block / void:";":Symbol ) ; generic ConstructorDeclaration = Modifiers Identifier FormalParameters OptionalThrowsClause? Block ; generic ClassDeclaration = Modifiers void:"class":Word Identifier Extension? Implementation? ClassBody ; generic InterfaceDeclaration = Modifiers void:"interface":Word Identifier Extension? ClassBody ; generic BlockDeclaration = (StaticClause)? Block ; generic StaticClause = void:"static":Word ; generic OptionalThrowsClause = void:"throws":Word QualifiedIdentifier ( void:",":Symbol QualifiedIdentifier )* ; generic Extension = void:"extends":Word Type ( void:",":Symbol Type )* / void:"extends":Word Type; generic Implementation = void:"implements":Word Type ( void:",":Symbol Type )*; // ---------------------------------------------------------- Statements generic Block = void:"{":Symbol BlockStatement* void:"}":Symbol ; transient GNode BlockStatement = Declaration / Statement ; transient GNode Statement = Block / ConditionalStatement / ForStatement / WhileStatement / DoWhileStatement / TryStatement / SwitchStatement / SynchronizedStatement / ReturnStatement / ThrowStatement / BreakStatement / ContinueStatement / LabeledStatement / ExpressionStatement / VoidStatement ; GNode ConditionalStatement = IfElseStatement / IfStatement ; generic IfElseStatement = void:"if":Word ParExpression Statement void:"else":Word Statement ; generic IfStatement = void:"if":Word ParExpression Statement ; generic ForStatement= void:"for":Word void:"(":Symbol ForInit Expression? void:";":Symbol ExpressionList? void:")":Symbol Statement ; generic ForInit = FinalClause? Type Declarators void:";":Symbol / ExpressionList void:";":Symbol / void:";":Symbol ; generic WhileStatement = void:"while":Word ParExpression Statement; generic DoWhileStatement = void:"do":Word Statement void:"while":Word ParExpression void:";":Symbol; generic ParExpression = void:"(":Symbol Expression void:")":Symbol ; GNode TryStatement = TryCatchFinallyStatement / TryCatchStatement ; generic TryCatchFinallyStatement = void: "try":Word Block CatchClause* void:"finally":Word Block ; generic TryCatchStatement = void:"try":Word Block CatchClause+ ; generic CatchClause = void:"catch":Word void:"(":Symbol FormalParameter void:")":Symbol Block ; generic SwitchStatement = void:"switch":Word ParExpression void:"{":Symbol SwitchGroup* void:"}":Symbol ; GNode SwitchGroup = CaseExpression / DefaultExpression ; generic CaseExpression = void:"case":Word Expression void:":":Symbol BlockStatement* ; generic DefaultExpression = void:"default":Word void:":":Symbol BlockStatement* ; generic SynchronizedStatement = void:"synchronized":Word ParExpression Block ; generic ReturnStatement = void:"return":Word Expression? void:";":Symbol ; generic ThrowStatement = void:"throw":Word Expression void:";":Symbol ; generic BreakStatement = void:"break":Word Identifier? void:";":Symbol ; generic ContinueStatement = void:"continue":Word Identifier? void:";":Symbol ; generic LabeledStatement = Identifier void:":":Symbol Statement ; generic ExpressionStatement = Expression void:";":Symbol; generic VoidStatement = void:";":Symbol ; // ---------------------------------------------------------- Expressions transient generic ExpressionList = Expression ( void:",":Symbol Expression )* ; generic Expression = ConditionalExpression AssignmentOperator Expression / yyValue: ConditionalExpression ; String AssignmentOperator = "=":Symbol / "+=":Symbol / "-=":Symbol / "*=":Symbol / "/=":Symbol / "&=":Symbol / "|=":Symbol / "^=":Symbol / "%=":Symbol / "<<=":Symbol / ">>=":Symbol / ">>>=":Symbol ; generic ConditionalExpression = ConditionalOrExpression void:"?":Symbol Expression void:":":Symbol ConditionalExpression / yyValue:ConditionalOrExpression ; generic ConditionalOrExpression = ConditionalOrExpression void:"||":Symbol ConditionalAndExpression / yyValue:ConditionalAndExpression ; transient generic ConditionalAndExpression = ConditionalAndExpression void:"&&":Symbol InclusiveOrExpression / yyValue:InclusiveOrExpression ; transient generic InclusiveOrExpression = InclusiveOrExpression void:"|":Symbol ExclusiveOrExpression / yyValue:ExclusiveOrExpression ; transient generic ExclusiveOrExpression = ExclusiveOrExpression void:"^":Symbol AndExpression / yyValue:AndExpression ; transient generic AndExpression = AndExpression void:"&":Symbol EqualityExpression / yyValue:EqualityExpression ; transient generic EqualityExpression = EqualityExpression EqualityOperator InstanceOfExpression / yyValue:InstanceOfExpression ; String EqualityOperator = "==":Symbol / "!=":Symbol ; transient generic InstanceOfExpression = RelationalExpression void:"instanceof":Word Type / yyValue:RelationalExpression ; generic RelationalExpression = RelationalExpression RelationalOperator ShiftExpression / yyValue:ShiftExpression ; String RelationalOperator = "<":Symbol / ">":Symbol / "<=":Symbol / ">=":Symbol ; transient generic ShiftExpression = ShiftExpression ShiftOperator AdditiveExpression / yyValue:AdditiveExpression ; String ShiftOperator = "<<":Symbol / ">>":Symbol / ">>>":Symbol ; transient generic AdditiveExpression = AdditiveExpression AdditiveOperator MultiplicativeExpression / yyValue:MultiplicativeExpression ; String AdditiveOperator = "+":Symbol / "-":Symbol ; transient generic MultiplicativeExpression = MultiplicativeExpression MultiplicativeOperator UnaryExpression / yyValue:UnaryExpression ; String MultiplicativeOperator = "*":Symbol / "/":Symbol / "%":Symbol ; transient generic UnaryExpression = "+":Symbol UnaryExpression / "-":Symbol UnaryExpression / "++":Symbol UnaryExpression / "--":Symbol UnaryExpression / yyValue:UnaryExpressionNotPlusMinus ; transient GNode UnaryExpressionNotPlusMinus = BitwiseNegationExpression / LogicalNegationExpression / BasicCastExpression / CastExpression / PostfixExpression ; transient generic BitwiseNegationExpression = void:"~":Symbol UnaryExpression ; transient generic LogicalNegationExpression = void:"!":Symbol UnaryExpression ; transient generic BasicCastExpression = void:"(":Symbol BasicType Dimensions? void:")":Symbol UnaryExpression ; transient generic CastExpression = void:"(":Symbol Type void:")":Symbol UnaryExpressionNotPlusMinus ; generic PostfixExpression = PrimaryExpression PostfixExpressionTail* ; GNode PostfixExpressionTail = SubscriptExpression / Arguments / PrimaryExpressionTail / ClassTail / PostincrementExpression / PostdecrementExpression ; generic SubscriptExpression = void:"[":Symbol Expression? void:"]":Symbol ; generic PrimaryExpressionTail = void:".":Symbol PrimaryExpression ; generic ClassTail = void:".":Symbol void:"class":Word ; generic PostincrementExpression = void:"++":Symbol ; generic PostdecrementExpression = void:"--":Symbol ; transient GNode PrimaryExpression = Literal / PrimaryIdentifier / NestedExpression / ThisExpression / SuperExpression / NewExpression / VoidClassExpression ; transient generic PrimaryIdentifier = Identifier ; transient generic NestedExpression = void:"(":Symbol Expression void:")":Symbol ; transient generic ThisExpression = void:"this":Word ; transient generic SuperExpression = void:"super":Word ; transient generic NewExpression = void:"new":Word QualifiedIdentifier Arguments ClassBody? / void:"new":Word TypeName DimensionExpressions Dimensions? / void:"new":Word TypeName Dimensions? ArrayInitializer ; transient generic VoidClassExpression = void:"void":Word void:".":Symbol void:"class":Word ; transient generic DimensionExpressions = DimensionExpression+; transient generic DimensionExpression = void:"[":Symbol Expression void:"]":Symbol ; transient generic Arguments = void:"(":Symbol ExpressionList void:")":Symbol / void:"(":Symbol void:")":Symbol ; transient generic ArrayInitializer = void:"{":Symbol ( VariableInitializer void:",":Symbol )* void:"}":Symbol / void:"{":Symbol VariableInitializer ( void:",":Symbol VariableInitializer )* void:"}":Symbol ; GNode VariableInitializer = ArrayInitializer / Expression ;