CS118 Programming LanguagesLecture 16Contents
Review of shift/reduceThe problem is parsing text according to a cfg; an answer is LR(k). The first step is a closer look at parsing. A 10-rule cfg for propositions:P O eol r0 O O | A r1 A r2 A A & N r3 N r4 N ~ B r5 B r6 B t r7 f r8 ( O ) r9 An input text (to be parsed):t&(t|f)A shift/reduce sequence for the input:
The set of all reducible parse stacks is a language(See Worcester talk) Some elementary automata theory:A FA (finite automaton) has rules of the form: If you see X in state S1, eat the X and goto state S2. There is an initial state. There are one or more final states. If, obeying the rules of a FA, you eat all the input and end up in a final state, the input is accepted. A DFA (deterministic FA) is a FA where each step either succeeds or fails (no ambiguity). An NFA is a FA that is not deterministic (more than one correct choice at some point). There is an algorithm that turns an NFA into an equivalent DFA. Example of a regular expression and corresponding DFA(see book)The LR(0) machineGiven the grammar for x+ eof
G -> E eof
E -> T
T -> T x
T -> x
Do the LR(0) computation for P (grammar above) (appoint a FA scribe -- he/she does what the others say to do) Now you know what yacc does.
|