(a) One simple grammar for describing expressions is:
Goal = Expression . Expression = Term | Expression "-" Term . Term = Factor | Term "*" Factor . Factor = "a" | "b" | "c" | "d" .
Show the parse tree corresponding to the string a - b - c
(b) Another grammar is
Goal = Expression . Expression = Term | Term "-" Expression . Term = Factor | Factor "*" Term . Factor = "a" | "b" | "c" | "d" .
Show the parse tree corresponding to the string a - b - c and discuss the differences between this grammar and the last.
(c) Yet another grammar for describing expressions might be:
Goal = Expression . Expression = Term | Expression "*" Term . Term = Factor | Term "-" Factor . Factor = "a" | "b" | "c" | "d" .
Show the parse tree corresponding to the string a - b * c
(d) How does one find a grammar that will allow all four operators (+ - * and /) with the familiar precedence and associativity conventions, and will also allow for parentheses within expressions - so that one can derive strings like
(a - b) * (c + d)
(e) The contents of a very useful textbook (if you can find a copy) begins as follows:
All you need to know to be able to pass your compiler examination. by Pat Terry. Chapter 1 Bribery is unlikely to succeed. Chapter 2 Understand the phases of compilation. 2.1 Lexical and syntactic analysis are easily confused 2.2 Constraint analysis involves the concept of type 2.3 Code generation for the PVM is a breeze Chapter 3 Get clued up on grammars. 3.1 Terminals 3.2 Sentences and sentential forms 3.3 Productions 3.4 EBNF and Cocol 3.5 Ambiguity is bad news
and so on. Develop a Cocol grammar that describes the contents. Assume that the words in the contents are all fairly simple, but notice that full stops (periods) appear in significant places. Since this is a long course, you should be able to handle more than three chapters, and some of might them have many sub-sections.