In: Computer Science
Write the EBNF for mini Java language based of the following information:
Data Types
Complex Data Structures
Methods
Program
Statements
Statement Blocks
ANSWER :
Type: PrimitiveType ReferenceType PrimitiveType: int boolean ReferenceType: ClassType ArrayType ClassType: Name ArrayType: PrimitiveType [ ] ClassType [ ] ArrayType [ ]
Names
Name: SimpleName QualifiedName SimpleName: Identifier QualifiedName: Name . Identifier
Packages
CompilationUnit: TypeDeclaration* TypeDeclaration: ClassDeclaration ;
Modifiers
Modifiers: Modifier* Modifier: public static native
Classes
Class Declaration
ClassDeclaration: class Identifier Superopt ClassBody Super: extends ClassType ClassBody: { ClassMemberDeclaration* } ClassMemberDeclaration: FieldDeclaration MethodDeclaration
Field Declarations
FieldDeclaration: Modifiers Type IdentifierList ; IdentifierList: Identifier IdentifierList , Identifier
Method Declarations
MethodDeclaration: MethodHeader MethodBody MethodHeader: Modifiers Type MethodDeclarator Throwsopt Modifiers void MethodDeclarator Throwsopt MethodDeclarator: Identifier ( FormalParameterListopt ) FormalParameterList: FormalParameter FormalParameterList , FormalParameter FormalParameter: Type Identifier Throws: throws ClassType MethodBody: Block ;
Blocks and Statements
Block: { BlockStatement* } BlockStatement: LocalVariableDeclarationStatement Statement LocalVariableDeclarationStatement: LocalVariableDeclaration ; LocalVariableDeclaration: Type VariableDeclarators VariableDeclarators: VariableDeclarator VariableDeclarators , VariableDeclarator VariableDeclarator: Identifier Identifier = Expression Statement: Block ExpressionStatement IfThenStatement IfThenElseStatement WhileStatement DoWhileStatement ReturnStatement BreakStatement ContinueStatement ForStatement ExpressionStatement: StatementExpressionopt ; StatementExpression: Expression IfThenStatement: if ( Expression ) Statement IfThenElseStatement: if ( Expression ) Statement else Statement WhileStatement: while ( Expression ) Statement DoWhileStatement: do Statement while ( Expression ) ; ReturnStatement: return Expressionopt ; BreakStatement: break ; ContinueStatement: continue ; ForStatement: for ( ForInitopt ; Expressionopt ; ForUpdateopt ) Statement ForInit: StatementExpressionList LocalVariableDeclaration ForUpdate: StatementExpressionList StatementExpressionList: StatementExpression StatementExpressionList , StatementExpression
Expressions
Expression: ConditionalExpression AssignmentExpression AssignmentExpression: ConditionalExpression = Expression ConditionalExpression: InfixExpression InfixExpression ? Expression : ConditionalExpression InfixExpression: PrefixExpression InfixExpression InfixOp PrefixExpression InfixOp: || && == != < > <= >= + - * / PrefixExpression: PrefixOp PrefixExpression PostfixExpression PrefixOp: - ! PostfixExpression: Primary Suffix* Suffix: ArrayAccess FieldAccess MethodInvocation ArrayAccess: [ Expression ] Selector: . Identifier FieldAccess: Selector MethodInvocation: Selector ( ArgumentListopt ) ArgumentList: Expression ArgumentList , Expression Primary: ( Expression ) this Literal Identifier super FieldAccess super MethodInvocation ClassInstanceCreationExpression ArrayCreationExpression ClassInstanceCreationExpression: new ClassType ( ) ArrayCreationExpression: new PrimitiveType [ Expression ] Dimension* new ClassType [ Expression ] Dimension* Dimension: [ ]
( PLEASE VOTE FOR THIS ANSWER )
I THINK IT WILL BE USEFULL TO YOU ....
PLZZZZ COMMENT IF YOU HAVE ANY PROBLEM I WILL TRY TO SOLVE IT ......
THANK YOU .......