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
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:
|