The Parser code will be broken into four main functions, one for each of the major token types:
get_identifier() - checks for and gets an identifier
get_number() - checks for and gets an constant integer or double number
get_string() - checks for and gets a string constant
get_operator() - checks for and gets an operator (symbol characters)
Each of these functions will take no arguments and return a Boolean flag if they found a token of the type they were looking. If they don't find their token type at the current position, they will return false, so the next main token function can be called. If all return false, then a syntax error will be returned.
When one of these functions find their token type, they will continue scanning the input line for end of the token. They will fill the previous allocated token before returning true. If they detect an error, they will set the token to the error token type with an appropriate error message. They will leave the current position set to the first character that they did not process, ready for the next token to be parsed (after skipping white space).
Tuesday, January 19, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
All comments and feedback welcomed, whether positive or negative.
(Anonymous comments are allowed, but comments with URL links or unrelated comments will be removed.)