Definition A Grammar is a collection of four elements: 1. Set of nonterminal symbols (uppercase) 2. Set of terminal symbols (lowercase). Terminals can be tokens or specific words. 1. Set of production rules saying how each nonterminal can be converted by a string of terminals and nonterminals, 2. A start symbol
§ A parse tree is a tree encoding the steps in a derivation. § Internal nodes represent nonterminal symbols used in the production. § Inorder walk of the leaves contains the generated string. § Encodes what productions are used, not the order in which those productions are applied.
A grammar is said to be ambiguous if there is at least one string with two or more parse trees. § Note that ambiguity is a property of grammars, not languages. We will review this topic in the next lecture
If a grammar can be made unambiguous at all, it is usually made unambiguous through layering. § Have exactly one way to build each piece of the string. § Have exactly one way of combining pieces back together. § Recursive constructions
Include rules to accept variables names (identifiers) in expressions. The grammar should accept as correct the following expressions: A * 20 + time (x * y) + 15 10 * (ASU + cse340) (10) * (20) + (15) (hello * world + Arizona) 10 * (counter) + 15
slides can only be used as study material for the Compilers course at Universidad Panamericana. They cannot be distributed or used for another purpose.