











































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!












































Lexical Analyzer Parser Source program Symbol table Rest of Front End token getNext Token Parse tree (^) Intermediate representation
L(regular) L(context free) L(context sensitive) L(unrestricted) Where L(T) = { L(G) | G is of type T } That is: the set of all languages generated by grammars G of type T L 1 = { a n b n | n 1 } is context free L 2 = { a n b n c n | n 1 } is context sensitive Every finite language is regular! (construct a FSA for strings in L(G)) Examples:
Grammar G = ({E}, {+,*,(,), ,id}, P, E) with productions P = E E + E E E * E E ( E ) E E E id E E id E
E E
id * id + id
rm
rm E + id rm id + id Example derivations: E
id + id
Grammar: E T + T T ( E ) T E T id Leftmost derivation: E lm
lm id + T lm id + id E E T
id id
id
Problems for topdown parsing with backtracking : (1) leftrecursion (can cause a topdown parser to go into an infinite loop) Def. A grammar is said to be leftrecursive if it has a nonterminal A s.t. there is a derivation A ⇒ A for some . (2) backtracking undo not only the movement but also the semantics entering in symbol table. (3) the order the alternatives are tried (For the grammar shown above, try w = cabd where A a is applied first)