Question

In: Computer Science

Write the EBNF for mini Java language based of the following information: Data Types Integer Int...

Write the EBNF for mini Java language based of the following information:

Data Types

  • Integer
    • Int
    • Long
  • Double
  • Boolean
  • Char
  • References

Complex Data Structures

  • Arrays
    • int v[30];
  • Classes
    • member variables
      • class Name {
      • int a;
      • char b;
      • char name[25];
      • }

Methods

  • Return data type
    • Primitive data type
    • Void
  • Method Name
  • Parameter list
    • Could be empty
  • Statement Block
    • {
    • Variable declarations
    • Executable Statements
    • }

Program

  • Variable Declarations
  • Class Definitions
  • Methods
  • Only one method named "main" but must have one method named main

Statements

  • Expression Statements
    • Assignment operation allowed in expressions
    • Add, Sub, Mult, Divd, 6 comparisons, Logical operations (and, or, not), Assignment
  • If statements
    • else is allowed but optional
  • While statements
  • Print
    • eol value to go to new line
    • allow multiple print items
  • Return statement - returns the value of an expression

Statement Blocks

  • Enclosed in braces
  • Separate statements using semicolons

Solutions

Expert Solution


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 .......


Related Solutions

Write the BNF for mini Java language based of the following information: Data Types Integer Int...
Write the BNF for mini Java language based of the following information: Data Types Integer Int Long Double Boolean Char References Complex Data Structures Arrays int v[30]; Classes member variables class Name { int a; char b; char name[25]; } Methods Return data type Primitive data type Void Method Name Parameter list Could be empty Statement Block { Variable declarations Executable Statements } Program Variable Declarations Class Definitions Methods Only one method named "main" but must have one method named...
Java Language The int t contains an integer between 1 and 50 (inclusive). Write code that...
Java Language The int t contains an integer between 1 and 50 (inclusive). Write code that outputs the number in words and stores the result in the String inwords. For example, if t is 35 then inwords should contain "thirty five". Test Cases Test case #1 Expected result: When t is 2, your code sets inwords to "two" Test case #2 Expected result: When t is 50, your code sets inwords to "fifty" Test case #3 Expected result: When t...
Write EBNF descriptions for the following: • a Java For each statement Assume that EBNF descriptions...
Write EBNF descriptions for the following: • a Java For each statement Assume that EBNF descriptions for statement(s), type, array, white space are given. (statmnts, type, array, and whitespace respectively) You have to create EBNF descriptions for For each statement and also variable. Use the following Java variable naming rules to create EBNF description for variable. o All variable names must begin with a letter of the alphabet, an underscore ( _ ) , or a dollar sign ( $...
Very easy: Write an EBNF rule that describes the following for statement in Java for (...
Very easy: Write an EBNF rule that describes the following for statement in Java for ( counter = 1; counter <= 10; counter ++) { sum=sum+1; } Then test your EBNF rule in Java as a recursive-descent subprogram
Java language (a) Write code segments to perform the following: (i) declare and create an integer...
Java language (a) Write code segments to perform the following: (i) declare and create an integer array freqArray of size 8 (ii) declare and initialize an array weight (with suitable type) which contains 48.5, 80 and 68 (iii) declare a Mouse array of size 2 with name mouse and initialize it with Mouse objects using one statement (b) A incomplete definition of a class Temperature is given below: public class Temperature { private double value[] = {36.5, 40, 37, 38.3};...
5-Write an EBNF rules that describes the following while statement of Java. Then, write the recursive-descent...
5-Write an EBNF rules that describes the following while statement of Java. Then, write the recursive-descent subprogram in Java or C/C++ for the EBNF rule. Please summit your source code and a screen shot of the parsing of the following examples. do { if ( number % 2 == 0 ) even ++; number=number+1; } while (number <= 10)
JAVA Language: Write a program that prompts the user to enter a positive integer n (0...
JAVA Language: Write a program that prompts the user to enter a positive integer n (0 up to 232 -1). You must write a function that takes as input n and returns a string s representing the number n in binary. For this assignment, you must use the method of successive division by 2 to convert the number to binary. Your main program must print out s. Example: If the user enters the number 66, your program must print out...
JAVA programing language: What is printed when the following code is executed? int columns; int rows;...
JAVA programing language: What is printed when the following code is executed? int columns; int rows; for(rows = 1; rows < 2; ++rows) { for(columns = 1; columns < 3; ++columns) { System.out.print("x"); } System.out.println(): } select one: A) xx B) xxx xxx C) x x D) xx xx xx
C++ language. struct Node {    int data;    Node *next; } Write a function to...
C++ language. struct Node {    int data;    Node *next; } Write a function to concatenate two linked lists. Given lists A* = (4, 6) and B* = (3, 7, 12), after return from Concatenate_Lists(Node A*, Node B*) the list A should be changed to be A = (4, 6, 3, 7, 12). Your function should not change B and should not directly link nodes from A to B (i.e. the nodes inserted into A should be copies of...
how to write in java; Write a method int[] coPrime[int num, int[]numbers] { // instructions are...
how to write in java; Write a method int[] coPrime[int num, int[]numbers] { // instructions are that it returns an array of all the elements of the int[] array numbers which are coprime with x } Note that the array that is returned may be an empty array--you will have to count how many times gcf(x, numbers[i]) == 1. ASSUME numbers is not null and not empty.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT