Compiler Design and Construction - Old Questions

Question Answer Details

2.  List out the major tasks carried out in Lexical Analysis Phase. Convert the following NFA to DFA.


6 marks
Asked in 2075

Answer

AI Generated Answer

AI is thinking...

Official Answer

In lexical analysis phase, Lexical Analyzer reads the input characters of the source program, groups them into lexemes, and produces a sequence of tokens for each lexeme. The tokens are then sent to the parser for syntax analysis.

Task carried out in lexical analysis phase are:

  • Lexical analyzer reads the input character and produces output sequence of tokens that the Parser uses for syntax analysis.
  • Lexical analyzer helps to identify token into the symbol table.
  • Lexical Analyzer is also responsible for eliminating comments and white spaces from the source program.
  • It also generates lexical errors.
  • Lexical analyzer is used by web browsers to format and display a web page with the help of parsed data from JavsScript, HTML, CSS

Second part:

Using the subset construction we have the DFA as:

States

Next states

0

1

→ *{p}

{r, q}

Φ

*{r, q}

{r, q}

{r}

*{r}

{r}

Φ

Φ

Φ

Φ

Now Transition diagram for above table is: