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

  Write a class encapsulating a pc-based game

Write a class encapsulating a PC-based game, which inherits from Game. A PC-bases game has the following additional attributes: the minimum megabytes of RAM needed to play the fame, the number of megabytes needed on the hard drive to install the fame..

  Write an application that extends jframe

Write an application that extends JFrame and that displays a phrase in every font size from 6 through 20.

  Design a java program that simulates a slot machine

Instead of displaying images, the program will randomly select a word from the following list: Cherries, Oranges, Plums, Bars, and Bells. The program will select and display a word from this list three times.

  Designing an application utilizing event-driven programming

Designing an application utilizing event-driven programming - the Model-View-Controller design pattern - You can review the code of the program "Puzzler" seen in lab 4 to help you with the class DotButton.

  An api for a library that provides for all these operations

Quaternions can be represented with four (4) real numbers (a,b,c,d). They can be added, subtracted, multiplied and divided. You can multiply a quaternion by a scalar (which produces a quaternion as a result)

  Three most primary forms of loops: the while loop, the do..

explored the world of loops we have accepted the three most primary forms of loops: the while loop, the do...while loop (even though Python does not use this loop), and the for loop. The for loop has approximately three primary implementations that w..

  Write class encapsulating the concept of weather forecast

Write a class encapsulating the concept of the weather forecast, assuming that it has the given attributes: the temperature and the sky conditions, which could be sunny, snowy, cloudy, or rainy.

  Write a piece of code that prints the values

Write a piece of code that prints the values requested in each part, given these variables:

  The drink machine should have a supply

When the applet starts, the drink machine should have a supply of 20 of each of the drinks. The applet should have a text field where the user can enter the amount of money he or she is giving the machine. The user can then click on a button to selec..

  How array is declared and initialized in java

What is a Java applet - how array is declared and initialized in Java and what are the access control attributes in Java?

  Write and run a java program

Write and run a Java program which allows the user to input two doubles and outputs the greater of the two?

  Create a book class which stores the information

You run a small library. Ask the user to provide information for several books. The information must include the author, title and publisher of each book.

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