You will build a recursive-descent parser for the right

Assignment Help Application Programming
Reference no: EM13347719

You will build a recursive-descent parser for the right recursive version of the classic expression grammar found in the text. Take the approach,  because this can free you from the need to write any stack management functions. Plus, most of the work has been done for you.

UNIX doesn't provide any tools for top-down parsers because bottom-up parsers, although more complex, are of more general utility. But since top-down parsers are simpler in structure, writing your own parser in C or C++ is not too difficult. (There is a free Java-based top-down parser generator called ANTLR available.)

You need to have a scanner as the front end to your parser. You should use flex to identify your tokens. One call to flex will return one token. We've already covered a lot of what we need in class. We figured out how to make the grammar right-recursive and we worked out the first sets and when we need them. You should use the most complete form of the grammar, which uses all four operators and parentheses. We won't be using variables, though, just integers.

Remember that a recursive descent parser has a function to match every non-terminal symbol. To match the terminal symbols you could just have some kind of match function. See the Stanford notes below. You still need a scanner and you should use flex for that.

Recursive Descent Parser

The input is a string consisting of identifiers, operators and parentheses. The output is an abstract syntax tree. The input string may be of arbitrary complexity.

It is permissible to truncate the length of identifiers to make your tree look nicer.

The tree should be totally constructed first and then printed, not printed while the parse is still going on.

Here is the full set of operations:

1. Write a flex file that identifies integers, parentheses and +-*/.

2. Add to the flex file code to implement your recursive-descent parser that will take as its input an arithmetic expression.

3. Compile your flex code to create a compiler for the language of arithmetic expressions.

4. Run your compiler with an arithmetic expression as input. The compiler builds the parse tree and then prints it.

Implementation Specification

A few points to consider

• I believe the best approach would probably be to have each non-terminal function return a pointer to the subtree it has built.

• The C equivalent to the C++ new operator is malloc.

• You are free to create a node structure as you wish. However, there is no need to make it very complicated. For example, an operator node has an operator (one character) and two subtree pointers. A leaf node has just a string containing the identifier name.

• A pointer-based data structure is the obvious way to handle the arbitrary complexity of the tree.

• Write your own hand-coded parser following the structure of the pseudocode given in the text. Do not use yacc.

• Please try to do nice error-handling, pointing out where in the input string the error occurs and what kind of error it is. However, you should halt your parse on the first error in a line; don't try to continue. Start a new parse on the next line.

• Note that this kind of stack-based evaluation is essentially the same as postfix notation. You might find some useful information by searching on this topic.

• Possible enhancements are adding the exponentiation operator ^ and adding unary + and - operators. Both of these will require additional levels of operator precedence.

Reference no: EM13347719

Questions Cloud

Part-1reinforce understanding of power beta and : part-1reinforce understanding of power beta and alpha.problem a packing process is designed to fill steel drums with
Methods are commonly used to break a problem down into : methods are commonly used to break a problem down into small manageable pieces. a large task can be broken down into
This is a simulation of rolling dice actual results : this is a simulation of rolling dice. actual results approach theory only when the sample size is large. so we will
Problem 1 in a study relating college grade point average : problem 1 in a study relating college grade point average to time spent in various activities students are asked how
You will build a recursive-descent parser for the right : you will build a recursive-descent parser for the right recursive version of the classic expression grammar found in
The comma-separated values csv file format is a delimited : the comma-separated values csv file format is a delimited data format commonly used as a portable representation of
The virgin brand entered the australian aviation market in : the virgin brand entered the australian aviation market in 2000 in competition with qantas and the other major airlines
Research paper the law laid down in soloman v soloman and : research paper the law laid down in soloman v. soloman and co. is usually considered the source on the basis of which
You have been asked by the president of your company to : you have been asked by the president of your company to determine the proposed acquisition of a new special-purpose

Reviews

Write a Review

Application Programming Questions & Answers

  Memory managementwrite a paper to provide depth knowledge

memory managementwrite a paper to provide depth knowledge of how memory is used in executing your programs and its

  Write a paper on mcdonaldsethics and social responsibility

write a paper on mcdonalds.ethics and social responsibility at mcdonaldspaper includesabout mcdonaldscorporate social

  Hypertext markup languagethe basics of hypertext markup

hypertext markup languagethe basics of hypertext markup language and world wide web. first you will learn about

  Write a program that creates a hierarchy of processes using

write a program that creates a hierarchy of processes using the fork system call. the initial program termed the root

  Problemthe manager of the super supermarket would like to

problemthe manager of the super supermarket would like to be able to compute the unit price for products sold there. to

  Basic requirementsscreen one has three edittext views and

basic requirementsscreen one has three edittext views and one button.the edittext views allow you to enter a students

  Hubspot is currently at a crossroads with management

hubspot is currently at a crossroads with management looking for rapid acceleration of sales and profits. in their

  Problem 1 create a simple shell basically your shell should

problem 1. create a simple shell. basically your shell should read the line from standard input parse the line with

  Assessmentthe project reports will be evaluated in three

assessmentthe project reports will be evaluated in three areasaccuracy and completeness of computationsyou have to get

  To design a class-based solution to a problem using

to design a class-based solution to a problem using multiple data structures.the problemwrite a program to help an

  Imagine that your company has decided to expand to the web

imagine that your company has decided to expand to the web. you want to reuse some data entry code that has been

  In this project you will create an application to run in

in this project you will create an application to run in the amazon ec2 service and you will also create a client that

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