Ask Question, Ask an Expert

+1-415-315-9853

info@mywordsolution.com

Ask Java Expert


Home >> Java

You have to design the syntactic analyzer for language specified by the grammar shown below. We are using the following convention: Terminals (lexical elements) are represented with bold courier font like this.  Non-terminals are represented in the angle brackets .  The character ε (epsilon) represents an empty stream. The non-terminal is the starting symbol of grammar.

Grammar

   ::= *
  ::=  class id {**};
  ::=  program;*
  ::=  id()
  ::=  ;
  ::=  {**}
  ::=  id*;
  ::=  ;
  |  if()thenelse;
  |  while()do;
  |  read();
  |  prepare();
  |  return();
  ::=  {*} | | ε
  ::= |
  ::= |  
  ::=  + | -
  ::= |
  ::=
  |  *id()
  |  num
  |   ()
  |  not
  |
  ::=  *id*
  ::=  id*.
  ::=  []
  ::=  [ int ]
  ::=  integer | real | id
  ::=  id** | ε
  ::=  * | ε
  ::=  ,id*
  ::= ,
Operators and additional lexical conventions
   ::=  =
  ::=  == | <> | < | > | <= | >= 
  ::=  + | - | or 
  ::=  * | / | and
    
id  ::=  follows specification for identifiers found in assignment#1
num  ::=  follows specification for numbers found in assignment#1
int  ::= *
  ::=  1..9
  ::=  | 0
 
For illustration, the non-terminal is a generalization of the addition operators tokens +, - and or. The use of this notation here doesn’t necessarily imply which you have to define a new kind of token in your lexical analyzer. Also, id and num are tokens that refer to the lexical conventions. Note that a new lexical convention for the token int has been added. 
Work to be done

• Analyze the syntactical definition given on the first page (and the additional lexical definition for the token int). Remove all the * notations and replace them by list-generating productions. List in your documentation all the ambiguities and left recursions, or any error you might find in grammar. Modify the productions so that the left recursions and ambiguities are deleting without modifying the language. You must get a set of productions that can be parsed using the top-down predictive parsing method. Include the transformed grammar in your documentation.

• Derive the FIRST and FOLLOW sets for each non-terminal in your transformed grammar and list them in your documentation.

• Implement a predictive parser (recursive descent or table-driven) for your modified set of grammar rules.

• Your parser must optionally output to a file the derivation which derives the source program from the starting symbol.

• The parser must call your lexical analyzer as it needs a new token.

• The parser must properly identify the errors in the input program and print a meaningful message to the user for each error encountered.

The parser must implement an error recover way that permits to report all errors. The error messages must be informative on the nature of the errors, as well as the location of the errors in the input file.

• In this assignment, you only check the syntactic correctness of the program, that is, check whether the source program can be parsed according to the grammar. Don’t check the semantic correctness of the program in this assignment.

• prepare a set of source files that facilitate to test the parser for all syntactical structures involved in the language. Include cases testing for a variety of different errors to demonstrate the accurateness of your error reporting and recovery.

Java, Programming

  • Category:- Java
  • Reference No.:- M91652

Have any Question? 


Related Questions in Java

Assignmentupload your completed assignment to the

Assignment Upload your completed assignment to the Assignment 2 link on the course home page for marking and tutor feedback. Be sure to complete the final step-click on the Send for Marking button to notify your tutor. P ...

Java programmingyou have been asked by your manager to

Java programming You have been asked by your manager to create a user-friendly application that will present a survey to your customers. The application will compile and analyze the results entered by the survey responde ...

Instructionsi what are the diagrams defined in the uml

Instructions I. What are the diagrams defined in the UML Standard. Give a one or two sentence description of each one. II. Given the following code, how should the toString methods in the classes H2ClassA and H2ClassB be ...

Below is the beginning of a java classpublic class

Below is the beginning of a Java class. public class Implement { private String name; private boolean hasMovingParts; private String constructedFrom; public Implement() { } a) Complete this class so that: i. The instance ...

Programmers often develop different types of accounts to

Programmers often develop different types of accounts to provide access to a program for a variety of users. The structure of each account is formatted based on the needs of the user and how the program will be used. One ...

Part 1 text readingchapter 3 chapter 4 part 2 textbook

Part 1. Text reading Chapter 3, Chapter 4 Part 2 . Textbook questions Chapter 3. Describe why an application developer might choose to run over TCP rather than UDP. Suppose host A is sending host B a large file over a TC ...

Java- object-oriented and concurrent programmingheres a

Java- Object-Oriented and Concurrent Programming Here's a very quick overview of the projects: 1. Read a data file, create the internal data structure, create a GUI to display the structure, and let the user search the s ...

Student class and driverthis student class will be the data

"Student Class and Driver" This Student Class will be the data that will be used for each of the projects assigned and graded this semester. Your Student Class will consist of: Student Attributes: First Name Last Name ID ...

Question 1 illustrate that the nodes of any avl tree t can

Question 1. Illustrate that the nodes of any AVL tree T can be colored "red" and "black" so that T becomes a red-black tree. Question 2. Illustrate that via AVL single rotation, any binary search tree T1 can be transform ...

Code reviewcan some have this done immediatelypublic class

Code Review Can some have this done immediately public class BankAccount { private double balance; public BankAccount() { balance = 0; } public BankAccount(double initialBalance) { balance = initialBalance; } public void ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

A cola-dispensing machine is set to dispense 9 ounces of

A cola-dispensing machine is set to dispense 9 ounces of cola per cup, with a standard deviation of 1.0 ounce. The manuf

What is marketingbullwhat is marketing think back to your

What is Marketing? • "What is marketing"? Think back to your impressions before you started this class versus how you

Question -your client david smith runs a small it

QUESTION - Your client, David Smith runs a small IT consulting business specialising in computer software and techno

Inspection of a random sample of 22 aircraft showed that 15

Inspection of a random sample of 22 aircraft showed that 15 needed repairs to fix a wiring problem that might compromise

Effective hrmquestionhow can an effective hrm system help

Effective HRM Question How can an effective HRM system help facilitate the achievement of an organization's strate