we now? After lexical analysis, we have a series of tokens. But we can not: I. define a DFA matching all expressions with properly balanced parentheses. II. i.e., define a DFA matching all functions with properly nested block structure. void a () { b (c); for (;;) {a=(-(1+2)+5); } }
we now? Now, we want to: ▪ Review the structure defined by the given series of tokens, i.e., whether the order of words is correct. ▪ Report errors if the tokens do not correctly represent a valid structure.
Definition A Grammar is a collection of four elements: 1. Set of terminal symbols (lowercase). Terminals can be tokens or specific words. 2. Set of non-terminal symbols (uppercase) 3. Set of production rules saying how each nonterminal can be converted by a string of terminals and nonterminals, 4. A start symbol
▪ A parse tree is a tree encoding the steps in a derivation. ▪ Internal nodes represent nonterminal symbols used in the production. ▪ Leaves represent terminals ▪ In-order Traversal describes a well-formed input ▪ Encodes what rules are used, not the order in which those rules are applied.
slides can only be used as study material for the Compilers course at Universidad Panamericana. They cannot be distributed or used for another purpose.