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

Java programmingscenario a mom and pop used car dealership

JAVA PROGRAMMING SCENARIO: A Mom and Pop used car dealership wants you to create a program that will manage their sales and inventory. They have provided a menu for you to follow. 1. Add To Inventory 2. Remove From Inven ...

Design your own java class that includes at least 3 data

Design your own Java Class that includes at least 3 data fields, 2 constructors and 4 methods. When designing your class, pick an object that you are familiar with and make it your own, realistic, yet simple design with ...

Assignmentmust be done on bluejin this exercise you will

Assignment MUST BE DONE ON BLUEJ In this exercise you will create a simple VotingMachine. In the United States, when a candidate runs for office, the person is often identified as a Democrat, Republican, or Independent. ...

Write a java program that prints asks the user to enter a

Write a Java program that prints asks the user to enter a positive value (1 less than or equal to 200) and print each number up to that line, 1 per line with the following changes (SNAP CRACKLE POP). • If a number is *** ...

Java application - distancecalculatorcreate a java

Java Application - DistanceCalculator Create a Java application named DistanceCalculator.java to solve the following problem. An application is needed to allow a user to enter two cities and display the distances between ...

Java application product and inventoryreadingchapter 9 of

Java Application Product and Inventory Reading Chapter 9 of the text Moodle: Class Coding Style Java Classes Java Application Product and Inventory Product.java Create a class to encapsulate the data and behavior of a pr ...

Write a jsp program that generates subtraction quizzes

Write a JSP program that generates subtraction quizzes randomly, as shown in Figure 43.14a (http://postimg.org/image/ze4uwdhqp/) . The first number must always be greater than or equal to the second number. After the use ...

Javacreating a new subclass of employee other types of

Java (Creating a New Subclass of Employee) Other types of Employees might include SalariedEmployees who get paid a fixed weekly salary, PieceWorkers who get paid by the number of pieces they produce or HourlyEmployees wh ...

Write a java application using netbeans integrated

Write a Java application using NetBeans Integrated Development Environment (IDE) that calculates the total annual compensation of a salesperson. Consider the following factors: A salesperson will earn a fixed salary of 8 ...

Assignment introduction to web developmentwhen you see

Assignment: Introduction to Web Development When you see "Richard Ricardo" in the example screen captures, change it to . If you do not put / in the above mentioned fields, you will get 0 points for the question(s). No t ...

  • 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

Section onea in an atwood machine suppose two objects of

SECTION ONE (a) In an Atwood Machine, suppose two objects of unequal mass are hung vertically over a frictionless

Part 1you work in hr for a company that operates a factory

Part 1: You work in HR for a company that operates a factory manufacturing fiberglass. There are several hundred empl

Details on advanced accounting paperthis paper is intended

DETAILS ON ADVANCED ACCOUNTING PAPER This paper is intended for students to apply the theoretical knowledge around ac

Create a provider database and related reports and queries

Create a provider database and related reports and queries to capture contact information for potential PC component pro

Describe what you learned about the impact of economic

Describe what you learned about the impact of economic, social, and demographic trends affecting the US labor environmen