Question

In: Computer Science

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

Types

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:
        [ ]

Related Solutions

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...
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};...
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...
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.
JAVA LANGUAGE ArrayList<Integer> al = new ArrayList<Integer>(); HashSet<Integer> hs = new HashSet<Integer>(); HashMap<Integer, Integer> hm =...
JAVA LANGUAGE ArrayList<Integer> al = new ArrayList<Integer>(); HashSet<Integer> hs = new HashSet<Integer>(); HashMap<Integer, Integer> hm = new HashMap<Integer,Integer>(); for (int i= 0; i<2; i++) { al.add(i); al.add(i+1); hs.add(i); hs.add(i+1); hm.put(al.get(i), al.get(i+1)); hm.put(hm.get(i), hm.get(i+1)); }   System.out.println(al); System.out.println(hs); System.out.println(hm); // {key=value}. ---------------------------------- What output is produced by the following code and why?
Language: Java or C (NO OTHER LANGUAGE) Do NOT use Java library implementations of the data...
Language: Java or C (NO OTHER LANGUAGE) Do NOT use Java library implementations of the data structures (queues, lists, STs, hashtables etc.) Have a unit test implemented in main(). And comment every code. Show examples from the executions. Assume that the edges defined by the vertex pairs in the data base are one-way. Question: Write a program that can answer if there is a path between any to vertices. For the vertex pairs use this as your input example: AL...
Language: Java or C (NO OTHER LANGUAGE) Do NOT use Java library implementations of the data...
Language: Java or C (NO OTHER LANGUAGE) Do NOT use Java library implementations of the data structures (queues, lists, STs, hashtables etc.) Have a unit test implemented in main(). And comment every code. Show examples from the executions. Assume that the edges defined by the vertex pairs are two-way. Question: First step: write a program based on DFS which can answer questions of the type: "Find the a path from X to Y" Which should result in a list of...
Language: Java or C (NO OTHER LANGUAGE) Do NOT use Java library implementations of the data...
Language: Java or C (NO OTHER LANGUAGE) Do NOT use Java library implementations of the data structures (queues, lists, STs, hashtables etc.) Have a unit test implemented in main(). And comment every code. Show examples from the executions. Question: First step: write a program based on DFS which can answer questions of the type: "Find the a path from X to Y" Which should result in a list of vertices traversed from X to Y if there is a path....
(java)Write a recursive method public static int sumForEachOther(Int n) that takes a positive Int as an...
(java)Write a recursive method public static int sumForEachOther(Int n) that takes a positive Int as an argument and returns the sum for every other Int from n down to 1. For example, sumForEachOther(8) should return 20, since 8+6+4+ 2=20.And the call sumForEachOther(9) should return 25 since 9+7+5 + 3+1-=25. Your method must use recursion.
The language is java Write a class called Tablet that stores information about a tablet's age,...
The language is java Write a class called Tablet that stores information about a tablet's age, capacity (in GB), and current usage (in GB). You should not need to store any more information Write actuators and mutators for all instance data Write a toString method When you print a tablet, the info should be presented as such: This tablet is X years old with a capacity of Y gb and has Z gb used. There is A gb free on...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT