25-08-2017, 09:32 PM
Lexical Analyzer and Parser
Lexical Analyzer and Parser.doc (Size: 58.5 KB / Downloads: 29)
About the project-
This project takes input from users in the form of program and performs
lexical and syntax analysis. In lexical analysis it scans the stream of cha-
racters and groups them into a meaningful sequence which is also known
as lexemes. For each lexemes lexical analyzer produces a token in the fo-
rm of-
<token-name, attribute-value>
The token name is used during syntax analysis and attribute value points an
entry in the symbol table.
During lexical analysis if lexical analyzer is unable to produce any lexeme t-
hen it gives an erroneous message.
The output of lexical analysis works as an input for syntax analyzer also kn-
own as parser. The parser now uses tokens produced by lexical analyzer and
creates a tree like structure also known as syntax tree. During this phase if
syntax analyzer faces any problem to construct a syntax tree then it generate-
s syntax error.
Introduction-The introduction of project covers following topics:
Grammar-As in our daily life in order to communicate in either language
we need some grammar, similarly to implement all the programming langu-
ages there is also need of some grammars and this grammar is defined by f-
our tuples
G=<V, T, P, S >
V is the non empty set of non terminals or variables,
T is non empty set terminal,
P is the set of production rules,
S is a start symbol
The grammar used for this purpose is Context Free Grammar(CFG).
A grammar is said to be CFG if it has the following form
Where the length of L.H.S. must be one and it must be non terminal and the
Length of the R.H.S. can be arbitrary and it may be a string over terminals a-
nd non terminals.
Lexical Analyzer- Lexical analyzer takes input from users in the form
of program and performs lexical and syntax analysis.
In lexical analysis it scans the stream of characters and groups them into a
meaningful sequence which is also known as lexemes. For each lexemes
lexical analyzer produces a token in the form of-
<token-name , attribute-value>
The token name is used during syntax analysis and attribute value points an
entry in the symbol table.
During lexical analysis if lexical analyzer is unable to produce any lexeme
then it gives an erroneous message.
Lexical analysis
Syntax Analyzer- The output of lexical analysis works as an input for
syntax analyzer also known as parser. The parser now uses tokens produced
by lexical analyzer and creates a tree like structure also known as syntax tre-
This technique is also known as parsing.
During this phase if syntax analyzer faces any problem to construct a syntax
tree then it generates syntax error.
Compiler-A compiler is a program that takes a source program in any
language and translates it into semantically equivalent target program in
desired language.
During this translation it goes through various phases which are shown
below in figure
and during translation if it detects any error then it gives an informative
message.
Advantages-
1-This is a good project to develop a new language.
2-This project can be very useful to get the idea behind the working of
compiler.
3-It is very useful from practical point of view.
Limitations-
1-Since this project is implemented for the language like ‘C’, so it can not
recognize the keywords of Object Oriented Languages like Class, public,
private, protected etc.
Future Scope-
It can be further extended to work just as an compiler, and it will translate
the source program into the target program