Explain the different methods of handling reserved words that look like identifiers.

System Software and Compiler Design

Explanation

1350
0

There are two ways, you can handle reserved words that look like identifiers:

► Put the reserved words in a symbol table initially, with a field indicating that they’re not ordinary identifiers, and tells what tokens do they represent.

When we find an identifier, a call to installID() places it in the symbol table if it’s not already there, and returns a pointer to the symbol table entry for the lexeme found. Any identifier not in the table is recognized as an 'id’.

► Create separate transition diagrams for each keyword, consisting of states representing the situation the keyword is to be detected.

The diagram consists of states representing each letter in the keyword, and check if the identifier has ended, with proper suffix detection. For e.g. 'then' should not be matched in 'thenextstep'.