Tuesday, March 16, 2010

Translator Class – Design

There is more that the Translator will handle like parentheses, arrays and functions, commas and semicolons, commands, data type handling and references. Before getting too involved, it's time to layout the Translator class and get basic functionality working with simple expressions and then build the rest upon it. First up is how the Translator class will be used, which will have these member functions:

    start()       - initializes the RPN list, stacks and other variables for a new line
    add_token()   - adds a token obtained from the Parser
    get_result()  - gets the RPN list after the last token has been added

The get_token() function will return an enumeration status code on the result of the adding the token with values of Good (token accepted), Done (last token has been added) and various return error codes. If an error occurs, the caller will use the information in the current token to output the error (like was done with error tokens from the Parser).

The get_result() function will be nothing more than an access function that will return the RPN list.