Introduction To Compiler Development
Introduction To Compiler Development
TO COMPILER
DEVELOPMENT
Compiler Construction
PRESENTED BY
DEEP
CS-E19-015
WHAT IS COMPILER
The first phase of scanner works as a text scanner. This phase scans the
source code as a stream of characters and converts it into meaningful
lexemes. Lexical analyzer represents these lexemes in the form of tokens
as:
<token-name, attribute-value>
HELLO WORLD PROGRAM
#include <iostream>
int main() {
cout << "Hello World!";
return 0;
}
SYNTAX ANALYSIS
The next phase is called the syntax analysis or
parsing. It takes the token produced by lexical
analysis as input and generates a parse tree (or
syntax tree). In this phase, token arrangements are
checked against the source code grammar, i.e. the
parser checks if the expression made by the
tokens is syntactically correct.
SEMANTIC
ANALYSIS Semantic analysis checks whether the parse tree
constructed follows the rules of language. For
example, assignment of values is between
compatible data types, and adding string to an
integer. Also, the semantic analyzer keeps track of
identifiers, their types and expressions; whether
identifiers are declared before use or not etc. The
semantic analyzer produces an annotated syntax
tree as an output.
INTERMEDIATE CODE GENERATION