Implement a lexical and syntax analyzer

Assignment Help JAVA Programming
Reference no: EM131395292

Programming Assignment

Implement a lexical and syntax analyzer based on the following grammar. Your analyzer should read an input test program from a file and then determine if it contains a syntax error. It does not have to show where the syntax error occurs or what kind of error it is.

<program> → begin <statement_list> end
<statement_list> → <statement> {;<statement_list>}
<statement> → <assignment_statement> | <loop_statement>
<assignment_statement> → <variable> = <expression>
<variable> → identifier (An identifier is a string that begins with a letter followed by 0 or more letters and/or digits)
<expression> → <variable> { (+|-) <variable>}
<loop_statement> → loop (<logic_expression>) <statement>
<logic_expression> ® <variable> (< | >) <variable> (Assume that logic expressions have only less than or greater than operators)

Use the examples below to test your analyzer.
Input program with no syntax errors:

begin

total = var1 + var2;

loop (var1 < var2)
loop ( var3 > var4)
var2 = var2 - var1

end

Input programs containing syntax errors:

total = var1 + var2;

loop (var1 < var2)
loop ( var3 > var4)
var2 = var2 - var1

end

begin

total = var1 + var2;

loop (var1 < var2)
loop ( var3 > var4)
var2 = var2 - var1;

end

The keyword begin is missing.

The last statement shouldn't end with a semicolon.

begin

total = var1 + var2;

lop (var1 < var2)
var2 = var2 - var1

end

The keyword loop is misspelled.

Reference no: EM131395292

Questions Cloud

Where are their initial movement direction and speed defined : Where are their initial movement direction and speed defined?
Describe the packet switched and circuit switched : Research Point-to-Point (dedicated), Packet Switched, and Circuit Switched WAN protocols/circuits/types. Define each protocol and describe at least two data transmission technologies associated with the protocol. Include the bandwidth limitation..
What is the legal range for these integer numbers : Find the description of the constructor we have used (the one with three integers as parameters). What is the legal range for these integer numbers?
How does what adichie describes relate to research : Watch the following TED talk and make observations based on the terms described in the chapter on Experimental Research. How does what Adichie describes relate to research
Implement a lexical and syntax analyzer : Implement a lexical and syntax analyzer based on the following grammar. Your analyzer should read an input test program from a file and then determine if it contains a syntax error.
Find out how many objects are currently in the list : Look up java.util.List in the Java Library Documentation. What are the names of the methods used to add an object to the list, remove an object from the list, and to find out how many objects are currently in the list?
Use counterexample method - some politicians are people : Use the counterexample method to prove the following categorical syllogisms invalid.- Some politicians are people who will stop at nothing to win an election, and no people who will stop at nothing to win an election are true statesmen.
Use counterexample method - some farm workers are not people : Use the counterexample method to prove the following categorical syllogisms invalid.- Some farm workers are not people who are paid decent wages, because no undocumented individuals are people who are paid decent wages, and some undocumented indivi..
What is a business intelligence system : CMPT641 : What is a Business Intelligence system? How does it work? How can a Business Intelligence system help companies, large or small, to build or maintain competitive advantage? What concerns a business owner should have before investing in a..

Reviews

Write a Review

JAVA Programming Questions & Answers

  Demonstrating your understanding of java collections

Design, write and test the Java program ReadStoreShow.java with the following requirements:

  What do you mean by operator overloading

What do you mean by operator overloading

  Create a data set with 100 integer values.

Create a data set with 100 integer values. Create a program that uses the division method of hashing to store the data values into hash tables with table sizes of 7,,51 and 151. Use the linear probing method of collision resolution. Print out the ..

  Design a dynamic programming algorithm

Assume that at a station ti takes 2 hours to change horses and a horse takes (x ln x)/100 hours to travel x miles. Design a dynamic programming algorithm to determine a sequence of stations at which to stop so as to minimize the total hours.

  Create two house object using constructor with two parameter

Create two House objects using the constructor with two parameters, plug in the data below as the actual parameters of the constructor. Each line below contains the two actual parameters for one object.

  Pass in the number of gallons on board

public float usefulLoad() // this is the grossWeight - emptyWeight public float usefulLoadWithFuel( in gallons ) // this is the useful load - gallons x 6. The programmer user will pass in the number of gallons on board.

  Compute the maximum points scored by player one and two

Compute the maximum points scored by Player 1 and Player 2. Compute the maximum number of points scored in a continuous sequence by Player 1 and Player 2.

  Implement a personal address book

How to use the program. As soon as an address book is loaded, print out a concise but complete list of the commands a user can enter. One of them should be a "help" command to print out the list again.

  Create a new project in your ide named animalinfo

Create a new project in your IDE named "AnimalInfo." Create a class called "AnimalInfo" as the main class for the program.

  Design implement and test an object-oriented java program

Design, implement and test an object-oriented Java program for processing single-variable polynomials represented as lists.

  Allows the user to enter a temperature and whether

Write a program that allows the user to enter a temperature and whether the temperature is stated in Celsius or Fahrenheit...or whethe

  Write following java expressions in mathematical notation

Write the following Java expressions in mathematical notation.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd