Output Format for Parser

Production Rules

For grading purposes, we would like your parser to output the list of productions taken while parsing an inputted sequence of lexical tokens. These productions should be outputted in the order in which they are actually taken during parsing. The general format of each production should be as follows:

LEFT-HAND-SIDE -> RIGHT-HAND-SIDE

We do not specify the detailed format for each production (such as the names of the terminals and non-terminals used, and which symbols are present in each production). This is because these details will depend upon the particular grammar you create. However, we ask that you pay attention to precendence so that the relative order of the taken productions adheres to precedence rules (such as "+" and "-" having lower precendence than "*" and "/"). Although precedence will not really be important until the next phase of the project, this will make it easier for us during grading of the current phase.

For example, for program mytest.min (which is syntactically correct), the outputted list of productions taken during parsing might look like this (you are not required to number each production or label each non-terminal with the corresponding production number). The actual output of your parser may differ depending upon the grammar you write.


Syntax Error Messages

An important function of a parser is to emit helpful syntax error messages in the event of a syntax error. Accordingly, your parser must emit a syntax error message whenever a syntax error is present in the inputted sequence of tokens, and your parser must not emit any syntax error messages whenever an inputted sequence of tokens is syntactically correct.

You are free to choose the particular format of each syntax error message outputted by your parser. At a minimum, each syntax error message should include the source code line number at which the syntax error is encountered.

Sometimes, multiple syntax errors may exist in an inputted sequence of tokens. It can be helpful for a parser to try to emit syntax error messages for every syntax error, so that a programmer can attempt to fix multiple errors before having to re-compile the program. As a result, your parser should continue parsing even after a syntax error is encountered and an appropriate syntax error message is emitted. However, sometimes syntax errors may "confuse" a parser and so some syntax error messages may be extraneous. Therefore, it is okay for your parser to emit some extraneous syntax error messages as long as the very first syntax error message outputted by your parser accurately describes the first true syntax error that occurs in the inputted sequence of tokens.

Example 1:

1. program x;
2. a : integer;
3. beginprogram
4. a = 1 + 2 * 3;
5. endprogram

In the above MINI-L program, the programmer tries to assign to variable a at line 4, but uses the incorrect assignment operator (it should be :=). As a result, when parsing the above MINI-L program, the following helpful error message might be emitted: Syntax error at line 4: ":=" expected

Example 2:

1. program x;
2. a integer;
3. beginprogram
4. a := 1 + 2 * 3;
5. endprogram

In the above MINI-L program, the programmer forgets the colon between a and integer at line 2. The following error message might be emitted by the parser in this case: Syntax error at line 2: invalid declaration