03 Parsing-1 - Parsing-1 Cop5555 Fall 08 Recall first step of language translation is lexical analysis Converts sequence of characters into a

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

View Full Document Right Arrow Icon
Parsing-1 Cop5555 Fall 08
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Recall: first step of language translation is lexical analysis Converts sequence of characters into a sequence of tokens Lexical structure usually specified with regular expressions Second step of language translation is parsing Recognizes legal phrases (order of tokens) Constructs AST Need a new formalism--can’t use regular expressions
Background image of page 2
3 Since regular expressions don’t allow recursion, they cannot specify the nested constructs that frequently appear in programming languages. For example, (x + y) + (w + z) is a sentence from a language of expressions: it is an expression comprising two subexpressions, (x + y) and (w + z) each comprising two subexpressions x,y,w,and z The language of expressions cannot be specified with regular expressions.
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Instead, we specify the language with a grammar using BNF (Backus-Naur Form) or EBNF (extended BNF) notation. BNF allows us to specify context-free- grammars
Background image of page 4
5 Context Free Grammar A grammar is a tuple ( Σ , N, P, S) where Σ is a set specifying the alphabet of tokens (also called terminal symbols ). N is the set of non-terminal symbols . non-terminals are variables that denote sets of sentences. impose a hierarchical structure on sentences. P is a set of productions (substitution rules). S is the start symbol where S is in N. ε ∈⇒∈
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Benefits of (E)BNF notation Compact and precise specification that allows an infinite number of sentences to be specified with a finite definition Allows systematic or automatic generation of parsers for certain types of grammars Provides a framework for specifying semantics . We will see this later. Allows formal reasoning about languages.
Background image of page 6
7 Example S ::= ε S ::= ( S ) S 2200 Σ , N are left implicit but Σ = { ( , ) }, N = {S} Note recursion—S defined in terms of itself As expected, ε is the empty sequence What language does this grammar generate?
Background image of page 7

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

View Full DocumentRight Arrow Icon
8 Example S ::= ε S ::= ( S ) S 2200 Σ , N are left implicit but Σ = { ( , ) }, N = {S} Note recursion—S defined in terms of itself As expected, ε is the empty sequence The set of strings of balance parentheses
Background image of page 8
9 EBNF Notation Pure BNF only allows productions only of the form σ 1 ::= σ 2, where σ 1 and σ 2 are strings of terminal and non-terminal symbols. EBNF (extended BNF) adds |, *, + from RE
Background image of page 9

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

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

This note was uploaded on 12/09/2009 for the course COP 5555 taught by Professor Staff during the Fall '08 term at University of Florida.

Page1 / 50

03 Parsing-1 - Parsing-1 Cop5555 Fall 08 Recall first step of language translation is lexical analysis Converts sequence of characters into a

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

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