Tags

compiler

http://stackoverflow.com/questions/11172287/what-is-the-lexical-and-syntactic-analysis-during-the-process-of-compiling-in-c

Consider this code:

     int a = 10;
     if (a < 4)
     {
          printf("%d",a);
     }

In the Lexical Analysis phase: You identify each word/token and assign a meaning to it. In the code above, you start by identifying that i followed by n followed by t and then a space is the wordint, and that it is a language keyword;1 followed by 0 and a space is a number 10 and so on.

In the Syntactic Analysis phase: You verify whether the code follows the language syntax(grammar rules). For example, you check whether there is only one variable on the LHS of an operator(considering language C), that each statement is terminated by a ;, that if is followed by a conditional/Boolean statement etc.

Advertisements