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

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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