|
|
|
|
|
by scott_s
5656 days ago
|
|
Meaning, parse word by word until you hit a key word or a significant character (,:". etc). If keywords are allowable in identifiers (such as "end of file"), then your algorithm is not sophisticated enough. When you encounter a token that is the same token as a keyword, you need to use context to determine if it is actually a keyword or part of an identifier. This may be a serious problem if the grammar has "<identifier> <keyword>" in it. That is, "X keyword" could be the identifier "X keyword" or it could be the identifier "X" followed by "keyword." There's a reason that most programming languages require that identifiers are a single token. |
|
You're presuming here that a space delimits tokens. In this language, that may not be the case. The lexer may create a single token from "a b c".