Reference no: EM132706825
Assignment - Parsing and Semantic Actions
Dice notation is a system to represent di?erent combi- nations of dice in role-playing games using simple algebra-like notation. The syntax of dice notation follows the following grammar, where all symbols in typewritter font (+, x, d, and int) are terminal symbols:
Rolls → Roll | Sum
Sum → Sum1 + Rolls | Roll
Roll → Dice | int | Dice x int
Dice → int1 d int2 | d int
A sample string of the language is 42 + 4d7x3 + d20
1. Is the grammar ambiguous? If it is, give an example. Otherwise, justify why it is not.
2. Give a leftmost derivation for the sample string.
3. Draw a parse tree for the sample string.
4. Write semantic actions to calculate the result of a dice roll expressed in dice notation. You may assume that in your actions you can also call the function random(n) which returns an integer between 1 and n (inclusive). You can execute arbitrary code in semantic actions (e.g., a for loop might come in handy), as long as you also assign some value to the left-hand side symbol. The final result should be stored as the value of the start symbol (i.e., Rolls.val).
5. Label/number your semantic actions. Describe an evaluation of the sample input, using the tree from question 3 and mentioning the order in which the actions are executed (use arbitrary random values for the results of calls to random).
2 LL(1) Grammars
In the following context-free grammar, which describes expressions in a simplified functional language, the symbols +, (, ), ->, and <id> are terminals and S is the initial symbol.
S → F + S | <id> -> S | F F → A V
A → F | ?
V → <id> | ( S )
1. Explain briefly why this grammar cannot be directly parsed by an LL(1) parser.
2. Convert this grammar to an equivalent one that has a better chance to be LL(1).
3. Write the First and Follow sets for all non-terminal symbols of the new grammar.
4. Construct the complete LL(1) parsing table for the new grammar.
5. Consider the tokens x and f to belong to the <id> token class. Show all the steps required to parse the input string: f(x -> x + f f x).
Attachment:- CSE_assignment 2.rar
Find what is the expected return of the preferred stock
: Find What is the expected return of the preferred stock?Bank of America has a preferred stock dividend of $2.83. The stock is trading for $94.63.
|
Determine the cost of manufacturing one custom kitchen
: Determine the cost of manufacturing one custom kitchen assuming the units given. Assume the MOH costs are allocated based on the direct labor hours per unit
|
What are your thoughts on the overall experience in general
: For this unit, you will write a one- to two-page reflective paper on your experience with the scenario-based case study, course, and on what you have learned.
|
How much must deposit today in an account
: If you wish to accumulate K140,000 in 13 years, how much must you deposit today in an account that pays an annual interest rate of 14%?
|
Write semantic actions to calculate the result of dice roll
: Write semantic actions to calculate the result of a dice roll expressed in dice notation. You may assume that in your actions you can also call the function
|
Explain the importance of safety in the design of apparatus
: In previous units, you were given a scenario and asked to demonstrate your knowledge of the concepts in this course and your ability to relate the concepts.
|
The dia is all-source defense intelligence agency
: The DIA is an all-source defense intelligence agency that is designed to prevent strategic surprise and deliver a decision advantage to warfighters
|
Record the amortization expense for all depreciable capital
: Record the amortization expense for all depreciable capital assets for the month of January 2020. Hall $850,000, Straight line 5 years, no residual value
|
Develop a job analysis for waiter in a restaurant
: Develop a Job analysis (JD & JS) for one of the following jobs: Sale-person in a retail shop, Waiter in a restaurant, A job of your own choice.
|