You have to design a syntactic analyzer for the language

Assignment Help Theory of Computation
Reference no: EM13347675

You have to design a syntactic analyzer for the language specified by the grammar below. We are using the following convention: Terminals (lexical elements) are represented with the bold courier font like this. Non-terminals are represented in angle brackets <like this>. The character ε (epsilon) represents an empty stream. The non-terminal <prog> is the starting symbol of the grammar.

Grammar

<prog> ::= <classDecl>*<progBody>
<classDecl> ::= class id {<varDecl>*<funcDef>*};
<progBody> ::= program<funcBody>;<funcDef>*
<funcHead> ::= <type>id(<fParams>)
<funcDef> ::= <funcHead><funcBody>;
<funcBody> ::= {<varDecl>*<statement>*}
<varDecl> ::= <type>id<arraySize>*;
<statement> ::= <variable><assignOp><expr>;
| if(<expr>)then<statBlock>else<statBlock>;
| while(<expr>)do<statBlock>;
| read(<variable>);
| write(<expr>);
| return(<expr>);
<statBlock> ::= {<statement>*} | <statement> | ε
<expr> ::= <arithExpr> | <arithExpr><relOp><arithExpr>
<arithExpr> ::= <arithExpr><addOp><term> | <term>
<sign> ::= + | -
<term> ::= <term><multOp><factor> | <factor>
<factor> ::= <variable>
| <idnest>*id(<aParams>)
| num
| (<expr>)
| not<factor>
| <sign><factor>
<variable> ::= <idnest>*id<indice>*
<idnest> ::= id<indice>*.
<indice> ::= [<arithExpr>]
<arraySize> ::= [ int ]
<type> ::= integer | real | id
<fParams> ::= <type>id<arraySize>*<fParamsTail>* | ε
<aParams> ::= <expr><aParamsTail>* | ε
<fParamsTail> ::= ,<type>id<arraySize>*
<aParamsTail> ::= ,<expr>

Operators and additional lexical conventions

<assignOp> ::= =
<relOp> ::= == | <> | < | > | <= | >=
<AddOp> ::= + | - | or
<multOp> ::= * | / | and

id ::= follows specification for identifiers found in assignment#1
num ::= follows specification for numbers found in assignment#1
int ::= <nonZero><digit>*
<nonZero> ::= 1..9
<digit> ::= <nonZero> | 0

For example, the non-terminal <addOp> is a generalization of the addition operators tokens +, - and or. The use of this notation here does not necessarily imply that you have to define a new type of token in your lexical analyzer. Also, id and num are tokens that refer to the lexical conventions given in the first assignment. Note that a new lexical convention for the token int has been added.

Work to be done

• Analyze the syntactical definition given on the first page (and the additional lexical definition for the token int). Remove all the * notations and replace them by list-generating productions. List in your documentation all the ambiguities and left recursions, or any error you may find in the grammar. Modify the productions so that the left recursions and ambiguities are removed without modifying the language. You should obtain a set of productions that can be parsed using the top-down predictive parsing method. Include the transformed grammar in your documentation.

• Derive the FIRST and FOLLOW sets for each non-terminal in your transformed grammar and list them in your documentation.

• Implement a predictive parser (recursive descent or table-driven) for your modified set of grammar rules.

• Your parser should optionally output to a file the derivation that derives the source program from the starting symbol.

• The parser should call your lexical analyzer as developed in assignment 1 when it needs a new token.

• The parser should properly identify the errors in the input program and print a meaningful message to the user for each error encountered. The parser should implement an error recover method that permits to report all errors. The error messages should be informative on the nature of the errors, as well as the location of the errors in the input file.

• In this assignment, you only check the syntactic correctness of the program, i.e., check whether the source program can be parsed according to the grammar. Do not check the semantic correctness of the program in this assignment.

• Write a set of source files that enable to test the parser for all syntactical structures involved in the language. Include cases testing for a variety of different errors to demonstrate the accuracy of your error reporting and recovery.

Reference no: EM13347675

Questions Cloud

Question 1mega industries corporation has eighteen years of : question 1.mega industries corporation has eighteen years of a bond outstanding to maturity an 8.25 nominal coupon with
Investment management assignmentprepare a report : investment management assignmentprepare a report recommending the appropriate investment of aud3 million for a five
Question 1a whatnbsp was the neolithic revolutionnbsp : question 1a. whatnbsp was the neolithic revolution?nbsp describe carefully what basic changes caused this revolution
Problem 1 solve the following functions for x where x is a : problem 1. solve the following functions for x where x is a real number. leave your answers in exact form that is do
You have to design a syntactic analyzer for the language : you have to design a syntactic analyzer for the language specified by the grammar below. we are using the following
You are to design and fir filter where the filter : you are to design and fir filter where the filter coefficients are the following numbers 3323939therefore the
Problem 1 we can evaluate the target wacc for apex printing : problem 1. we can evaluate the target wacc for apex printing given these assumptionsbullweights of 40 debt and 60
Question 1 consider the functions f g and h all defined on : question 1 consider the functions f g and h all defined on the set 0 1 2 3 ... 12i write down the values of ghf8 and
Systems research and investigate novel ideas and : systems research and investigate novel ideas and applications.write a research report outlining the architecture and

Reviews

Write a Review

Theory of Computation Questions & Answers

  The roommate problem and intern assignment problem

Implementation of both the algorithms using C/C++ code 1. roommates problem 2. Intern Problem

  Prove that l is not regular using pumping theorem

Prove that L is not regular. (Be particularly careful if you use the Pumping Theorem. You must choose a w that is actually in L.)

  How to express correctness properties in ltl

Express the given correctness properties in LTL. Defne propositions/variables to model the events mentioned in the question. If a parent process calls the blocking waitpid() system call then it is blocked until child process terminates.

  Millenium development goal

Millenium Development Goal has proved to be one of the most ambitious and difficult and global education starts with, well, education-informing and inciting into action those who are more capable of bringing about change.

  Explaining syntactically legal boolean expression

In this problem, we consider a very restricted subset of Boolean expressions. Define an operator to be one of  the four symbols: ¬, ∧, ∨, and →. Define a variable to be one of the five symbols

  1using suffix trees give an algorithm to nd a longest

1.using suffix trees give an algorithm to nd a longest common substring shared among three input strings. s1 of length

  Modify the syntax of a programming language

Sometimes it is necessary to modify the syntax of a programming language. This is done by changing the CFG that the language uses. What changes would have to be made to ac's CFG (Figure) to implement the following changes?

  Farmers friend for their customer support systems

Create the two main documents that model the current processes at Farmers Friend for their Customer Support Systems (CSS).

  Subset-sum problem

Calculate some number x= Sum - 2K. Create new set A by add x to the set B {b1, b2,....., bn} U {x}, where the summation now is B+x. it is possible to split the numbers in A into some subsets iff they can summing up to K:

  Create mealy type state machine with input and output

Create the Mealy type state machine with input X and output Y. Y must be 1 whenever sequence 110 or 101 has been detected on X on last 3 consecutive rising clock edges.

  Create a mealy machine which produces the output

Create a Mealy Machine which produces the output of 1 whenever discrepancy in above pattern is detected, and produces the output of 0 otherwise. Write states meaningful names.

  Considering a single programmed operating system

Considering a single programmed operating system, what is the minimal total time required to complete executions of the two processes? You should explain your answer with a diagram.

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