Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7956 Discussions

Lexical Analyzer and Syntax Analyzer

Akshaynath
Beginner
663 Views

Hello friends

I want to know what is the diference between Lexical Analyzer And Syntax Analyzer.

I know that these are the different components of a compiler. But i dont know their functions and difference.Please help.

0 Kudos
1 Solution
kfsone
New Contributor I
663 Views
http://en.wikipedia.org/wiki/Lexicon
In the statement
int x = p->value();
"int", "x", "=" and "p", "->", "value", "()" and ";" are lexical symbols (discrete atoms of the language that have specific meanings).
The lexical analyzer determines the meaning of each component of the expression:
int :- typename (base type);
x :- user variable name;
= :- operator (assignment);
p :- pointer;
-> : operator (dereference);
value : member name;
() : operator (call)
The syntactical analyzer tries to make sense from that as to what you are doing, in the abstract:
declare user variable;
dereference pointer;
dereference member function;
call resulting address;
assign return value to user variable

View solution in original post

0 Kudos
2 Replies
kfsone
New Contributor I
664 Views
http://en.wikipedia.org/wiki/Lexicon
In the statement
int x = p->value();
"int", "x", "=" and "p", "->", "value", "()" and ";" are lexical symbols (discrete atoms of the language that have specific meanings).
The lexical analyzer determines the meaning of each component of the expression:
int :- typename (base type);
x :- user variable name;
= :- operator (assignment);
p :- pointer;
-> : operator (dereference);
value : member name;
() : operator (call)
The syntactical analyzer tries to make sense from that as to what you are doing, in the abstract:
declare user variable;
dereference pointer;
dereference member function;
call resulting address;
assign return value to user variable
0 Kudos
Om_S_Intel
Employee
663 Views
The lexical analyzer breaks the incoming charater stream into tokes (languages keywords and idetifiers).

The Syntax analyzer recognizes the incommingtokens and attaches the meaning. If the tokens do not follow language syntax then it emits the error massage.


You may learn more on this topic from any compiler design text book.

There is popular lexical analyser called lex and populartool yacc used for building sytax analysers.

0 Kudos
Reply