Currently, an instance of the Parser class is created for the program and a reference to it is passed around between the various routines. The Parser class only has a few member variables and except for the reference to the table instance, these members are initialized for each new line that is parsed. Therefore, it is not necessary to have a single parser instance for the program - a parser instance can be created as needed and destroyed when no longer needed.
The Parser class can be though of as a function call, though a complex one. The parser is given an input line and returns one token at a time until either the end of the line is reached or an error is found. A new function could be implemented to return a list of tokens for the line being parsed. There are two locations where the parser is currently being used: the test parse input and test translate input routines.
Both of these callers work slightly different. The test parse input routine just gets tokens until the line end or an error is found. However, the test translate routine sets the Parser operands state from its own operand state (whether looking for an operand or not) before getting each token. This is done so that the Parser can determine when it should be looking for a negative sign on a constant (operand state) or a minus operator (not operand state).
This implies a intimate use of the parser while a line is being translated. So a function was not implemented to return a list of tokens. The code was modified to instance a Parser when needed - in the two test routines - instead of passing a single instance reference of the Parser around. These leads to the usage of the Translator class...
Saturday, November 10, 2012
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.)