Question

I have a basic question on Lexical Analysis. As lexical analyzer (which is a DFA which accepts lexemes and produces token) can produce tokens which can be Identifier([a-z]/[A-Z]/[0-9] knowing digit not the first char), Keywords (if, else,..) , Operators & Delimiters.

So if a lexeme like 'whil' comes. Then will it be a lexical error stating Its not a valid keyword or will it be accepted as Identifier(variable), as lexical analyzer do not consider whether the syntax is right or not ?

Does Lexical Analyzer use different DFA for Identifiers, Keywords, Operators ?

Était-ce utile?

La solution

Then will it be a lexical error stating Its not a valid keyword

No.

or will it be accepted as Identifier(variable)

Yes, and then there will be a syntax error from the parser.

as lexical analyzer do not consider whether the syntax is right or not ?

The lexical analyser doesn't know anything about syntax. That's the parser's job.

Autres conseils

To identify keywords, It uses the same regexp for identifier, and then checks the keyword table, whether it's a keyword. If yes, then keyword, else it is an identifier

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top