Write a recursive-descent parser

Assignment Help Programming Languages
Reference no: EM13315210

Submission: Please upload the following to the CMS.
1. Source code
2. A screen shot of the execution of your program including the input file you used

Use any programming language you prefer to write a recursive-descent parser that parses the language generated by the following EBNF descriptions. Your parser should detect whether or not the input program has any syntax errors. It does not have to specify what and where the error is.

<program> → begin <stmt_list> end
<stmt_list> → <stmt> {;<stmt_list>}
<stmt> → <assign_stmt> | <while_stmt>
<assign_stmt> → <var> = <expr>
<var> → identifier (An identifier is a string that begins with a letter followed by 0 or more letters and digits)
<expr> → <var> { (+|-) <var>}
<while_stmt> → while (<logic_expr>) <stmt>
<logic_expr> ® <var> (< | >) <var> (Assume that logic expressions have only less than or greater than operators)

You can use the following examples to test your parser.
An input program without syntax errors:

begin

total = var1 + var2;

while (var1 < var2)

     while ( var3 > var4)

                 var2 = var2 - var1

end

 

Some input programs with syntax errors:

 

total = var1 + var2;

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

end

The keyword begin is missing

 

begin

total = var1 + var2;

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

end

The last statement should not end with a semicolon

 

begin

total = var1 + var2;

whie (var1 < var2)
while ( var3 > var4)
var2 = var2 - var1

end

The keyword while is misspelled

Reference no: EM13315210

Questions Cloud

Question for database schema : The patient information along with the ID of any prescribing doctor for each patient and the prescription information along with patient name, DOB, medication brand name, and prescribing doctor name sorted by most recent date.
What type of system would you classify an electric wire : A system consists of a gas confined between a cylinder and piston such that work and heat may cross the boundary. What type of system is that. What type of system is a free body as used in mechanics or civil engineering.
Find the surface charge density on each sphere : Charge is placed on two conducting spheres that are very far apart and connected by a long thin wire. Find the surface charge density on each sphere
Air traffic controllers use radar to keep track of location : Air traffic controllers use radar to keep track of the location of aircraft.
Write a recursive-descent parser : Use any programming language you prefer to write a recursive-descent parser that parses the language generated by the following EBNF descriptions.
Determine what tension load is needed to return the length : A 4 meter long steel plate with a rectangular cross section (10mm x 50mm) is resting on a frictionless surface under the sun. The plate temperature is measured to be at 40 degrees Celsius.
Find the heat flow from the hot to the cold temperature : A brass rod with a length of 20.0 cm is placed side by side with an aluminum rod with a length of 20.0 cm, What is the heat flow from the hot temperature to the cold temperature
Physics and chemistry found in vital signs of planet earth : Physics and Chemistry Found in Vital Signs of Planet Earth
What is the steady-state concentration of radon in the house : The total volume of the house is 650 m3 (assume that the volume is well mixed throughout). The radon source emits 250 pCi/s (A picoCurie [pCi] is a unit proportional to the amount of radon gas and indicates the amount of radioactivity of the gas)

Reviews

Write a Review

Programming Languages Questions & Answers

  Program to compute unit price of items sold

Manager of a Supermarket would like to be able to calculate the unit price of items sold there. To do this the program should input the name and the price of the item.

  Write the program to model simple calculator

Write the program to model the simple calculator. Each data line must consist of next operation to be performed from list below and right operand.

  Write non-abstract subclass constructor accepting double

Write (non-abstract) subclass, ApartmentHouse, containing: an int instance variable numberOfApartments. a constructor accepting a double, passed to superclass constructor, and an int used to initialize numberOfApartments

  Write program to read series of pairs of numbers

Write the program which reads series of pairs of numbers (product code and quantity sold) then the program must compute and print the total retail value

  Write program to read line of text which ends with sentinel

Write program which will read line of text which ends with a period, that serves as sentinel value. Display all the letters which occur in text, one per line and in alphabetical order,

  Write a program to clean up lane9.dat

Write a program to clean up lane9.dat. Write all numbers and spaces to cleanlane9.txt.

  Determine average cpi for program for clock cycle time

The table above illustrates the execution time of two different compiled programs. Determine the average CPI for each program given that processor has clock cycle time of 1 nS.

  Write program to prints the question

Write a program that prints the question"do you want to continue?" and reads a user input. if the user input is"y", "yes", "ok", "sure", or "why not?".

  Design fraction class to represent numerator and denominator

Design a fraction class. The class should have 2 data members to represent the numerator and denominator. Both of these numbers should obviously be integers.

  Write application to use random-number to create sentences

Write an application that uses random-number generation to create sentences. Use four arrays of strings called article, noun, verb and preposition.

  Timer interrupt to coordinate peripherals on microcontroller

The timer interrupts to coordinate peripherals on the microcontroller. Use code from prior labs to drive the peripherals and will make minor modifications to use the interrupts.

  Program-inputting data from files-writing-calling functions

This program will give you practice inputting data from files, writing and calling functions, using linked lists and outputting data to a file. You should only use one linked list of structs.

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