31-10-2012, 05:00 PM
Compiler Front-End
LP-overview.ppt (Size: 191.5 KB / Downloads: 15)
What Does the Front-end Do?
Consist of those phases that depend on the source language but largely independent of the target machine.
The Structure of Front End
Lexical analysis
Stream of characters are grouped into tokens
Syntax analysis
Tokens are grouped hierarchically with collective meaning
Semantic Analysis:
Ensure the components of a program fit together.
Intermediate Code Generation
A standard representation for later process.
Lexical Analyzer
Functions
• Grouping input characters into tokens
• Stripping out comments and white spaces
• Correlating error messages with the source program
Issues (why separating lexical analysis from parsing)
• Simpler design
• Compiler efficiency
• Compiler portability (e.g. Linux to Win)
LEX
Lex: A Language for Specifying Lexical Analyzers
• Implemented by Lesk and Schmidt of Bell Lab initially for Unix
• Not only a table generator, but also allows “actions” to associate with RE’s.
• Lex is widely used in the Unix community
• Lex is not efficient enough for production compilers, however.