Write semantic actions to calculate the result of dice roll

Assignment Help Computer Engineering
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

Reference no: EM132706825

Questions Cloud

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.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

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