Construct a parse tree for string

Assignment Help Programming Languages
Reference no: EM131060638

The name of the course is called Compilers. We are using a tool called ANTLR.

Exercise 1

Consider the context-free grammar

S → S S + |S S* | a

a. Show how the string aa + a* can be generated by this grammar.

b. Construct a parse tree for this string.

c. What language does this grammar generate?  Justify your answer.

Exercise 2

What language is generated by the following grammars?  In each case justify your answer. Also describe each language informally using a sentence or two in English.

a. S → 0 S 1 | 0 1

b. S → + S S | - S S | a

c. S → S ( S ) S | ε

d. S → a S b S | b S a S |'

e. S → a | S + S | S S | S * | ( S )

Exercise 3

Which of the grammars in Exercise 2 are ambiguous?

Exercise 4

Construct a syntax-directed translation scheme that translates arithmetic expressions from infix notation into prefix notation in which an operator appears before its operands; e.g.,  -xy is the prefix notation for x - y.  Give annotated parse trees for the inputs 9-5+2 and 9-5*2.

Programming Assignment

A really simple Scheme (RSS) expression takes one of two forms: a floating-point literal whose value is itself; or an application in which the function named by an operator is applied to the (argument) values of two expressions (its operands). A RSS program is a sequence of one or more newline-terminated expressions. Here is the syntax, with nonterrninals in italics, and tokens in uppercase or enclosed in apostrophes:

prog → (expr NEWLINE)+
expr → DOUBLE
         |  '(' RATOR expr expr ')'

RATOR → '+' | '*'|'/'|'^'

A floating-point literal (DOUBLE) is represented by one or more digits, optionally preceded by a minus sign, and optionally followed by a radix point (.) and zero or more digits. An operator is one of the standard symbols for the four basic arithmetic operations and exponentiation.

The program evaluates and prints each of the top-level expressions (i.e., that appears on its own line). In this example, user input is bold, and AZ is used to simulate end-of-file:

> java RSS

(+ 2 3.0)
(/ 9 (+ 2 1) )
84.3
(^ 2 3)
(+ (* 3 -4) (- 12 6) )
^Z
5.0
3.0
84.3
8.0
-6.0

Reference no: EM131060638

Questions Cloud

Financial business report on advanced braking technology : Financial Business Report on Advanced Braking Technology Ltd. The assignment aims to develop an understanding of financial statements structure and their use in decision-making.from the Australian Stock Exchange (ASX), analyse the latest financial..
Write a paper about how smoke moves throughout a structure : Write a research paper about how smoke moves throughout a structure. The paper should expand on what you learned during this course. Show that you understand the issues using life experiences.
Cost to retained earnings in investor-owned businesses : Why is there a cost to retained earnings in investor-owned businesses? What are the three methods commonly used to estimate the cost of equity? Is the risk premium in the CAPM the same as the risk premium in the debt-cost-plus-risk-premium model? How..
How the method can be used by the trader : What Fibonacci method can be very helpful to a investment trader in either determining a stop that would allow staying with a major trend, or in finding an entry level for new positions? Explain how the method can be used by the trader.
Construct a parse tree for string : Construct a parse tree for this string - what language does this grammar generate and describe each language informally using a sentence or two in English.
Value of the firm be if the company takes on debt equal : Letang Corporation expects an EBIT of $21,750 every year forever. The company currently has no debt, and its cost of equity is 15 percent. The company can borrow at 9 percent and the corporate tax rate is 38. What will the value of the firm be if the..
Draw the shear-force and bending-moment diagrams for beam : The simple beam AB shown in the figure is subjected to a concentrated load P and a clockwise couple M1= PL/3 acting at the third points. Draw the shear-force and bending-moment diagrams for this beam.
Additional machines in producing widgets : You are a producer of widgets.  You own two factories, which were built at different times and have different efficiencies. Your production engineers tell you that the marginal productivity (per hour) of additional machines in producing widgets in..
What legal invasions of privacy : What legal invasions of privacy would you be willing to justify in the name of public policy? Would you be able to defend surveillance for the purpose of:

Reviews

Write a Review

Programming Languages Questions & Answers

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

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

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

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