compiler construction - How does the lexical analyzer identify whether given token is Identifier or Keyword? -
i have basic question on lexical analysis. lexical analyzer (which dfa accepts lexemes , produces token) can produce tokens can identifier([a-z]/[a-z]/[0-9] knowing digit not first char), keywords (if, else,..) , operators & delimiters.
so if lexeme 'whil' comes. lexical error stating its not valid keyword or will accepted identifier(variable), lexical analyzer not consider whether syntax right or not ?
does lexical analyzer use different dfa identifiers, keywords, operators ?
then lexical error stating not valid keyword
no.
or accepted identifier(variable)
yes, , there syntax error parser.
as lexical analyzer not consider whether syntax right or not ?
the lexical analyser doesn't know syntax. that's parser's job.
Comments
Post a Comment