Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.
7692 Discussions

Lexical Analyzer and Syntax Analyzer

Akshaynath
Beginner
277 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
277 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

2 Replies
kfsone
New Contributor I
278 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
Om_S_Intel
Employee
277 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.

Reply