1,159 views
1 votes
1 votes
How will the compiler detect whether "if" is a keyword or an identifier?

Please tell me the concept behind this.

2 Answers

0 votes
0 votes

In some language like c, java etc keyword is specified so the compiler will detect the keyword in the lexical analysis phase.

While in some language like FORTAN keyword are not specified, it uses lookahead operator ( follow certain pattern before certainty of token for the keyword). These patterns are specified in Lex language (lexical analyzer generator).

Like for keyword the pattern are defined as in LEX language:

  IF / \  ( .*  \ ) { letter}       here for certainty of IF as keyword lookahead  (lookahead operator '/ ' ) certain pattern.

for more information follow book compiler design by ULLMAN.

Related questions

2 votes
2 votes
5 answers
2
Mizuki asked Nov 11, 2018
1,785 views
What it the number of tokens in the following line?printf("%d numbers.", &x);
1 votes
1 votes
1 answer
4
ankit_thawal asked Feb 1, 2018
717 views
1. macros are not considered as tokens in tokenizing.2.#include considered as single token2.stdio.h considered as single token. Are the above statements true?