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 java method delete(key1, key2) to delete

1. Write a Java method delete(key1, key2) to delete all records with keys between key1 and key2 (inclusive) from a binary search tree.

  Create a gui client side application that is a java version

q1. create a gui client side application that is a java version of notepad giving the ability to open modify and save

  Write the entry or record into a sequential file

Develop a Java based GUI application(using swing) that allows the user to enter Charity/Fund information: Write the entry/record into a sequential file

  Calculates the total at the end

Make a program that asks the user how much change they have and then calculates the total at the end.

  The user for number of letters

Write a java program that asks the user for number of letters in a word followed by those letters. Store those letters in an array. Then it calls a method called public static void toNumerals(char[] word) to determine the corresponding number for eac..

  Sentence patterns and verb formulas

Provide the sentence pattern. Write out the sentence pattern - then write out the tense of the verb and provide the formula.

  Apply the bfs algorithm and show the output

Apply the BFS algorithm and show the output and Apply the DFS algorithm and show the output - Define the necessary functions to implement the search problem. This should include a function that takes a vertex as input and returns the set of vertice..

  Eax contains the given contents before the instruction

For each add instruction in this problem, assume that EAX contains the given contents before the instruction is executed, and give the contents of EAX as well as the values of the CF, OF, SF, and ZF flags after the instruction is executed:

  How both the time and space complexity change

Write the java code that implements the methods and Discuss how both the time and space complexity change for each of the methods above if the underlying structure of your SmartULS is an array or a linked list?

  Java graphics-write an application that extends jframe and

java graphics-write an application that extends jframe and that displays a phrase in every font size from 6 through

  Display student details and classes in applet

Display student details and classes they have enrolled in Applet. The Applet should have following features. Update and View.

  Instantiates an instance of the nested class

which statement, if placed in a class other than MyOuter or MyInner, instantiates an instance of the nested 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