Question: Compiler Theory Ch4 Syntax Analysis 1. Design grammars for the following languages: 1) The set of all strings of Os and 1s such that every

 Compiler Theory Ch4 Syntax Analysis 1. Design grammars for the following

Compiler Theory Ch4 Syntax Analysis 1. Design grammars for the following languages: 1) The set of all strings of Os and 1s such that every 1 is immediately followed by at least one 0. 2) The set of all strings of Os and 1s that are palindromes; that is, the string reads the same backward as forward 3) The set of all strings of 0s and 1s with an equal number of Os and 1s. 4) The set of all strings of Os and 1s with an unequal number of Os and 1s. 5) The set of all strings of Os and 1s in which 011 does not appear as a substring. 2. Square braces around a grammar symbol or symbols denotes that these constructs are optional. Thus, production A->XIYJZ has the same effect as the two productions A-> XYZ and A->XZ Now, use the braces described above to simplify the following grammar for statement blocks and conditional statements: stmt -if expr then stmt else stmt if expr then stmt begin stmtlist end stmtlist - stmt; stmtList | stmt 3. The following is a grammar for regular expressions over symbols a and b only, using + for union, to avoid conflict with the use of vertical bar as a meta-symbol in grammars: rexpr rexprrterm I rterm rterm - rterm rfactor | rfactor rfactor - rfactorI rprimary rprimary - b a) Left factor this grammar b) Does left factoring make the grammar suitable for top-down parsing? c) In addition to left factoring, eliminate left recursion from the original gramma d) Is the resulting grammar suitable for top-down parsing? Repeat above exercise 3 for the following grammars

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!