質問

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 ?

役に立ちましたか?

解決

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.

他のヒント

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top