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

  Create a function that carries out the desired action

Create your own assignment to get more practice with arrays. Listed below are twenty seven functions you can write that deal with arrays. Listed next to each function is a number of points each is worth in parenthesis. Create a function that carri..

  Explain and evaluate post-fix expression

Many early calculators used a post-fix entry to perform arithmetic calculations. For example 2 + 3 in in-fix notation would be 2 3 + in post-fix notation. ( 2 + 3 ) * 4, would be 2 3 + 4 *. Utilizing a stack, post-fix expressions are very easily e..

  Create the logic for a program that accepts input values

Create the logic for a program that accepts input values for the projected cost of a vacation and the number of month until vacation. Pass both values to a method that displays the amount you must save per month to achieve your goal.

  Design a class named pet, which should have following fields

The type field holds the type of animal that is the pet. Example values are "Dog", "Cat", and "Bird".

  Write function to calculate and print fractional powers

Write down a function which calculates and prints fractional powers of its first argument as shown below for first argument of 2(1/2,1/4,1/8 and so on).

  Compute and print annual salary of employee

Identify input, process and output to solves each problem. Compute and print the annual salary of employee. suppose the employee receive 6% increase in pay.

  Describe what a branch hazard is, and what causes to it

Fully describe at least TWO of the techniques, OTHER than stalling, that can be used (in an attempt) to overcome branch hazards.

  Business rules form the basis of the database design.

A member receives many invitations, and each invitation is sent to many members.

  Program that will first ask the number of overs each team

The program will also display the winning team and the result. That is, if Team A wins then it will display the result in terms of runs. For example, Team A wins by 54 runs, which is the difference between the total runs scored by the teams. Howev..

  Console application that displays the sizes of the two files

Create a file that contains your favorite movie quote. Use a text editor such as Notepad and save the file as Quote.txt. Copy the file contents and paste them into a word-processing program such as Word. Save the file as Quote.doc.

  Define prolog relations for the following

Provide some facts for the father, mother, male, and female predicates and then test the entire thing using Prolog.

  Write program to read the size of side of square

Write a program that reads in the size of the side of a square and then prints a hollow square of that size out of asterisks (i.e., *) and blanks.

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