Explanation of Solution
a.
Context-free grammar for “case” or “switch” statements:
- The context-free grammar (CFG) generates the context-free language (CFL).
- Production rules of CFG are simple replacement.
- Parsing is a method of finding a tree which has a given yield.
- Rules can also be applied in reverse to check whether a string is grammatically correct according to the grammar.
In the following grammar, the input is error-free if and only if
Explanation of Solution
b.
Replacing the semantic functions with action routines:
- Action routines are a semantic function that the user instructs the compiler to execute at a specific part in the parse.
- An ad hoc translation scheme which is inserted with parsing takes the form of a set of action routine.
- Many parser generators allow the user to identify action routines.
Assumes exponents in the input are all positive integers. The grammar is as follows:
Want to see more full solutions like this?
Chapter 4 Solutions
Programming Language Pragmatics, Fourth Edition
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education