Programming Language Pragmatics, Fourth Edition
Programming Language Pragmatics, Fourth Edition
4th Edition
ISBN: 9780124104099
Author: Michael L. Scott
Publisher: Elsevier Science
Expert Solution & Answer
Book Icon
Chapter 4, Problem 2E

Explanation of Solution

Modifying the grammar based on Figure 2.25:

  • In Figure 2.25, they used LR grammar to obtain a realistic example.
  • Figure 2.25 uses a left recursive production for stmt_list.
  • Using left recursion allows the parser to break the long statement lists as it goes along, rather than waiting until the entire list is on the stack and then break it from the end.
  • It also uses left recursive productions for expr and term.
  • These two productions captured using left associativity while keeping an operator and its operands together in the same right-hand side.
  • The following grammar shows the use of at least one write statement with grammar provided in Figure 2.25.

programother_stmt_list write expr stmt_list $$other_stmt_listother_stmt_list other_stmt | other_stmtid := expr | read idstmt_liststmt_list stmt |

Explanation of Solution

Modifying the grammar based on Example 2.17:

  • The Example 2.17 shows the recursive descent parser.
  • In this method, the execution starts in procedure program. And then the recursive calls are traced out to form a traversal of the parse tree.

program  other_stmt_list writing_stmt stmt_list $$other_stmt_list  other_stmt_list other_stmt | other_stmt  id := expr | read id| if condition then other_stmt_list fi| while condition do other_stmt_list odwriting_stmt  write expr| if condition then other_stmt_list writing_stmt stmt_list fi| while condition do other_stmt_list writing_

Blurred answer
Students have asked these similar questions
I would like to know the features of BranchCache, Metadata, and LPR Port Monitor
Please answer the JAVA OOP questions below: How do arrays of objects differ from arrays of primitive types? Why and when would you use an array of objects? What are the different ways to initialize an array of objects? What is a static variable in Java?  How does its scope differ from instance variables? When should you use static variables?  Provide examples where static variables are beneficial over instance variables. What is the difference between static and non-static methods in the Data Definition Class?  What are the benefits of using static methods?
Assume you are a loyal member of Costco. You have been expecting your membership reward from the company, and you just received a text message on your mobile phone. The message appears to be from Costco: Costco - Your 3% return is ready: costco.wholesaledividend.com Before clicking the link in the message, you consider whether this is genuinely from Costco or a phishing attack on you. How can you tell? If it is a phishing attack, what mechanism was most likely used to send the message to you? What actions can you take if you are not sure whether it is a genuine message from Costco? What actions can you take if you are sure this is a phishing attack?
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education