Use the braces described in Exercise 4.2.4 to simplify the following grammar for statement blocks and conditional statements: stmt -> if expr the n stmt else stmt | if stmt the n stmt | begin stmtList...


Use the braces described in Exercise 4.2.4 to simplify the following grammar for statement blocks and conditional statements: stmt -> if expr the n stmt else stmt | if stmt the n stmt | begin stmtList end stmtList -> stmt; stmtList | stmt.


Exercise 4.2.4


There is an extended grammar notation in common use. In this notation, square and curly braces in production bodies are metasymbols (like —>• or |) with the following meanings:

i) Square braces around a grammar symbol or symbols denotes that these constructs are optional. Thus, production A —> X [Y] Z has the same effect as the two productions A X Y Z and A -± X Z.

ii) Curly braces around a grammar symbol or symbols says that these symbols may be repeated any number of times, including zero times. Thus, A —>• X {Y Z} has the same effect as the infinite sequence of productions A-*X,A->XYZ,A-*XYZYZ, and    so      on.

Show that these two extensions do not add power to grammars; that is, any language that can be generated by a grammar with these extensions can be generated by a grammar without the extensions.



May 22, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here