Professional Documents
Culture Documents
Student Name: Tittle: Course: Second Stage: 2 Lecturer Name: D.wijdan Abdul Ameer
Student Name: Tittle: Course: Second Stage: 2 Lecturer Name: D.wijdan Abdul Ameer
1
Complications to Scanning
●
Most languages today are free form
- Layout doesn’t matter
-White space separates
tokens
●
Alternatives
• Fortran -- line oriented
• Haskell -- indentation and layout can imply
grouping
●
Separating scanning from parsing is standard
●
Alternative: C/C++/Java: type vs idenifier
• Parser wants scanner to distinguish
between names that are types and names
that are variables
• Scanner doesn’t know how things are
declared … done in semantic analysis, a\k\a
type checking
2
Scanner-Parser Interaction
3
Tokens, Patterns, Lexemes
[A-Za-z][A-Za-z_0-9]*
●
The pattern matches each string in the set.
●
A lexeme is a sequence of characters in the
source text that is matched by the
pattern for a token.
4
Example
●
Few errors are discernible at the lexical level alone.
●
Lexical analyzer has a very localized view of the
source text.
●
It cannot tell whether a string fi is a misspelling of a
keyword if or an identifier.
●
The lexical analyzer can detect characters that are
not in the alphabet or strings
that have no pattern.
●
In general, when an error is found, the lexical
analyzer stops (but other actions
are also possible).
6
source
3- http://www.info.univ-tours.fr/˜
By M´ırian Halfeld-Ferrari