User:Majindm24

9/8/08 PRINCIPLES OF PROGRAMMING LANGUAGES

recall
lexical analysis - takes us from source ( string of characters) to a stream of tokens. syntax analysis - scrutinizes the stream of tokens.

left off with unambiguous grammar

ambiguous - more than one parse tree per expression unambiguou - only one parse tree per expression

Today
grammar - specifies what legal programs look like

The Parsing Problem
We are given a CFG and a stream of tokens, we want to know if the stream of tokens satisfy the grammar, and what is the parse tree, if program is illegal report syntax error.

yacc tool
takes as input a CFG and automatically construct a LALR(1) parser if possible. If there is ambiguity yacc gives errors.

RECURSIVE-DESCENT PARSING

 * Not as powerful as LALR(1), but easy to implement by hand.

a+b*c a*b+c


 * Idea: often one lookahead token is enough to tell which rule to use next.

ex: S -> if E then S else S | begin S L | print E L -> end | ;SL E -> ...