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