edited by
22,381 views
58 58 votes

In a compiler, keywords of a language are recognized during

  1. parsing of the program
  2. the code generation
  3. the lexical analysis of the program
  4. dataflow analysis

4 Answers

Best answer
80 80 votes

Typically, the lexical analysis phase of compilation breaks the input text up into sequences of lexemes that each belongs to some particular token type that's useful in later analysis. Consequently, keywords are usually first recognized during lexical analysis in order to make parsing easier. Since parsers tend to be implemented by writing context-free grammars of tokens rather than of lexemes (that is, the category of the lexeme rather than the contents of the lexeme), it is significantly easier to build a parser when keywords are marked during lexing. Any identifier is also a token so it is recognized in lexical Analysis .
Hence, option C is True.
ref@ http://stackoverflow.com/questions/5202709/phases-of-a-compiler

edited by
6 6 votes
In most modern languages, keywords (identifiers that have special meaning to the compiler)
are reserved (meaning user cannot redefine/remove/overload the predefined meaning).
Typically, the symbol table is preloaded with the keywords.

The lexical analyzer first
identifies keywords as identifiers and before inserting them into the symbol table, checks
against the preloaded keywords to correctly classify them as identifiers or keywords.

Therefore, option c is correct.
4 4 votes

Doubt might arise between the lexical phase or parsing phase, but remember: parsing phase/syntax analysis is just to verify the syntax of the language,

whereas the lexical analyzer checks for valid tokens. The lexical analyzer gives an error if and only if there exists an invalid token in the program. And as we know, a keyword is also a token, so we may conclude that option C is the correct answer.

Answer:
Position:
Show:

Related questions

55 55 votes
5 answers 5 answers
20.4k
20.4k views
go_editor asked Sep 29, 2014
20,413 views
The lexical analysis for a modern computer language such as Java needs the power of which one of the following machine models in a necessary and sufficient sense?Finite s...
75 75 votes
4 answers 4 answers
24.3k
24.3k views
go_editor asked Sep 29, 2014
24,266 views
On a non-pipelined sequential processor, a program segment, which is the part of the interrupt service routine, is given to transfer $500$ bytes from an I/O device to mem...
47 47 votes
2 answers 2 answers
16.6k
16.6k views
akash asked Oct 29, 2014
16,558 views
Let $P$ be a regular language and $Q$ be a context-free language such that $Q \subseteq P$. (For example, let $P$ be the language represented by the regular expression $p...
23 23 votes
2 answers 2 answers
8.5k
8.5k views
go_editor asked Sep 29, 2014
8,500 views
Choose the most appropriate word(s) from the options given below to complete the following sentence.I contemplated _________ Singapore for my vacation but decided against...