1
Prof. Aiken
CS 143
Lecture 5
1
Introduction to Parsing
Lecture 5
Prof. Aiken
CS 143
Lecture 5
2
Outline
•
Regular languages revisited
•
Parser overview
•
Context-free grammars (CFG’s)
• Derivations
• Ambiguity
Prof. Aiken
CS 143
Lecture 5
3
Languages and Automata
•
Formal languages are very important in CS
–
Especially in programming languages
•
Regular languages
–
The weakest formal languages widely used
–
Many applications
•
We will also study context-free languages,
tree languages
Prof. Aiken
CS 143
Lecture 5
4
Beyond Regular Languages
•
Many languages are not regular
•
Strings of balanced parentheses are not regular:
( ) |
0
i
i
i
Prof. Aiken
CS 143
Lecture 5
5
What Can Regular Languages Express?
•
Languages requiring counting modulo a fixed
integer
•
Intuition: A finite automaton that runs long
enough must repeat states
•
Finite automaton can’t remember # of times it
has visited a particular state
Prof. Aiken
CS 143
Lecture 5
6
The Functionality of the Parser
•
Input:
sequence of tokens from lexer
•
Output:
parse tree of the program
(But some parsers never produce a parse tree . . .)

This
** preview**
has intentionally

**sections.**

*blurred***to view the full version.**

*Sign up*