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

  Describe the necessary formulas and sample calculations

Demonstrates your thought process and steps used to analyze the problem. Be sure to include the required input and output and how you will obtain the required output from the given input

  Write attribute grammar using only synthesized attributes

Semantics of this string literal is correct if numeric value of baseten numeral matches length of string. Write attribute grammar using only synthesized attributes for nonterminals in definition of

  Write program to compute diameter in centimeters

Write a program to compute the diameter in centimeters of a steel rod, an aluminum rod, and a copper rod, which can withstand a particular compression load.

  Write program with procedure which draws shape

Write down program with procedure which draws a shape of your choice. Your program must then call the procedure 10 times to draw the shape at 10 random locations.

  Write a little man program that adds a column of input value

Write a Little Man program that adds a column of input values and produces the sum as output. An input value of zero will indicate the last value in the input stream of input values.

  Java api represented associative array

Character strings in C and C++ are implemented as arrays of char and Java API represented associative array?

  Write a program that display amount of discount on item

Write a program that asks the user to enter number of packages purchased. Program must then display amount of the discount (if any) and total amount of the purchase after the discount.

  Application should calculate and display the order amounts

Make sure the number of units for each package is numeric, and is not negative.

  Write application to retrieve the telephone number

Consider a program to enter codes of one to eight characters along with an associated telephone number and associated notes. A code can represent a person's name, a person's initials, a place, or anything.

  Using a graphics application, such as microsoft powerpoint

What would be the most appropriate network topology to use on this network?

  Write a program that decides if a number x is in the matrix

Write a program that decides if a number X is in the matrix. Let the user enter the size of the matrix n, the content, and the number X to search. Display the result of your search in the screen. While testing your program for submission, make sur..

  Create a java application to convert english to pig latin

Create a java application to convert English words to pig Latin using the above rules.

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