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

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -