lecture-04-6up

lecture-04-6up - Parsers Monday, September 13, 2010 Agenda...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Parsers Monday, September 13, 2010 Agenda Terminology LL(1) Parsers Overview of LR Parsing Monday, September 13, 2010 Terminology Grammar G = (V t , V n , S, P) V t is the set of terminals V n is the set of non-terminals S is the start symbol P is the set of productions Each production takes the form: V n ! ! | (V n | V t )+ Grammar is context-free (why?) A simple grammar: G = ({a, b}, {S, A, B}, {S ! A B $, A ! A a, A ! a, B ! B b, B ! b}, S) Monday, September 13, 2010 Terminology V is the vocabulary of a grammar, consisting of terminal (V t ) and non-terminal (V n ) symbols For our sample grammar V n = {S, A, B} Non-terminals are symbols on the LHS of a production Non-terminals are constructs in the language that are recognized during parsing V t = {a, b} Terminals are the tokens recognized by the scanner They correspond to symbols in the text of the program Monday, September 13, 2010 Terminology Productions (rewrite rules) tell us how to derive strings in the language Apply productions to rewrite strings into other strings We will use the standard BNF form P = { S ! A B $ A ! A a A ! a B ! B b B ! b } Monday, September 13, 2010 Generating strings Given a start rule, productions tell us how to rewrite a non-terminal into a different set of symbols By convention, rst production applied has the start symbol on the left, and there is only one such production S ! A B $ A ! A a A ! a B ! B b B ! b To derive the string a a b b b we can do the following rewrites: S A B $ A a B $ a a B $ a a B b $ a a B b b $ a a b b b $ Monday, September 13, 2010 Terminology Strings are composed of symbols A A a a B b b A a is a string We will use Greek letters to represent strings composed of both terminals and non-terminals L(G) is the language produced by the grammar G All strings consisting of only terminals that can be produced by G In our example, L(G) = a+b+$ All regular expressions can be expressed as grammars for context-free languages, but not vice-versa Consider: a i b i $ (what is the grammar for this?) Monday, September 13, 2010 Parse trees Tree which shows how a string was produced by a language Interior nodes of tree: non- terminals Children: the terminals and non-terminals generated by applying a production rule Leaf nodes: terminals S A B A a B b B b b a Monday, September 13, 2010 Leftmost derivation Rewriting of a given string starts with the leftmost symbol Exercise: do a leftmost derivation of the input program F(V + V) using the following grammar: What does the parse tree look like?...
View Full Document

Page1 / 14

lecture-04-6up - Parsers Monday, September 13, 2010 Agenda...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online