Tuesday, February 9, 2010

Parser – Immediate Commands (Implementation)

Immediate Commands will be parsed in the separate function get_command(), which will be called only for the first token on the line (when the column is zero). The entire command will be parsed including the command's arguments, and the entire command will be put into a single token. If the line does not contain a valid command, the Parser will proceed to the other functions from the beginning of the line. The commands are one of the forms:

    Blank        Command has no arguments
    Line         Command has a line number
    Range  Command has a line number range
    Line-Incr  Command has a line number and an increment
    Range-Incr  Command has a line number range, a start line and an increment
    String  Command has a string argument

There will be an field in the Table for each of the immediate commands that will contain flags to which forms each command supports. The first thing get_command() will do is search the Table for the letter command to see if it is a valid command. If it is, then get_command() will proceed to parse the rest of the line looking for one of the above forms for the arguments. The separate function scan_command() will be called to actually scan and parse the arguments . This will make it easy to return immediately when the command is fully parsed or an error is found. After the arguments are parsed and the command syntax is good, the table will be search again for the command letter and the form of the arguments found to see if it is a valid command syntax.

The scan_command() function will detect and return most invalid command argument syntax errors, but for other syntaxes, it will just return to let the other Parser functions process it (remember the example L100=5, which is an assignment and not a list command). The form of the arguments will be returned or a Null flag will be returned if no valid command syntax was found or an error was found (for errors, the token type will be set to an error).

There will be a special structure allocated that will hold the begin line number of a range (or the single line number), end line number of a range, start line number (only for RENUM command) and increment value. If any are not present, then the value will be set to -1. The increment must be a positive non-zero value. If the increment is not present following a final comma, then it will be set to 0 to tell the command to use a default value (for example the AUTO command will used the last increment specified or 10 if there was no previous value).  The pointer to the allocated structure will be put into the string field of the token. String arguments will be put into the string field of the token. Commands with no arguments will have a null string pointer.

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.)