Ask Question, Ask an Expert


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.


   ::= *
  ::=  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

Topic java part a airline seatingmillions of commercial

Topic: Java Part A: Airline seating Millions of commercial airline flights cross the world's cities every year, and each one of these flights must solve what seems like a simple problem: how do you arrange where each pas ...

Programming assignment - summer semester 2015-purpose-to

Programming Assignment - Summer Semester 2015- Purpose- To provide students with the opportunity to apply the knowledge acquired and skills developed. These include understanding of primitive data types and the concept o ...

As we have discussed in class section 41 of our text

As we have discussed in class, section 4.1 of our text develops a List ADT and then offers two different implementations of it in the classes AList and LList. The ADT is defined in a Java interface file, and bo ...

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

Java programmingnow that your survey class has been

Java programming Now that your Survey class has been implemented, it is time to implement the SurveyConductor application class. This class uses the Survey class to conduct a survey. First, create pseudocode to develop t ...

Write two java program by netbeans1 create a program that

Write two java program by Netbeans. 1. Create a program that ask for a radius of a circle and has the ability to return both the Area and Circumference - so methods call getArea() and getCircumferance() 2. Create a progr ...

The class below has some errors for each error do the

The class below has some errors. For each error do the following: a) Write the erring section of code and explain what the error is. b) Fix the error (i.e. re-write the code correctly). public class ClassWithErrors { pub ...

Chapter 1 - challenge 3 - training workshopsyour company

Chapter 1 - Challenge #3 - Training Workshops Your company likes to present training workshops that help people in the information technology industry improve their skills. Your task is to write and object-oriented appli ...

Animal characteristicsin todays fast-paced world it is

Animal characteristics In today's fast-paced world, it is important for programmers to think about potential future changes that impact their programs. One way that software developers can address this concern is by desi ...

Overviewthis assignment is intended to familiarize students

Overview: This assignment is intended to familiarize students with web application design, basic servlet functionality, and application deployment with a focus on servlet HTML generation and page navigation. The goal is ...

  • 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