CST 8152 - Assignment Five
Topic: Panic-Mode error recovery and beginning Semantic Actions
This page last updated: Sunday September 27, 1998 01:07
This is actually the first half of what I had originally conceived as assignment five.
I've split assignment five into assignments five and six to have different due
dates for each half.
Deliverables for this assignment:
Due: 2pm, Monday April 6 - the one-week-late penalty is waived.
Hand in, on paper:
- A listing of these two functions from your parser:
- Your root parsing function and
- Your panic-mode function that skips to after the next semicolon when an error is
detected.
- Your state transition diagram for your Scanner that recognizes all the Tokens in the
enhanced Program Grammar #2 grammar.
- Your translation scheme for the given grammar, showing the correct placement of
the semantic action symbols for each grammar production.
No output is required for this assignment; however, the next assignment will
be building on this one, so don't wait until next week to finish coding!
The submission must follow the online course
submission standards, including an Assignment Submission Label and a Table of
Contents. (The Label and Contents may be on the same exterior cover page.)
Purpose:
This assignment adds Panic-Mode Error Recovery to the
Parser. It enhances the grammar from the previous assignment, adding some new
productions and new token types, to become Program Grammar #2.
You may use the main() program from the previous assignment to test
your Parser (or, you may write your own driver).
Instructions:
- Part 0 (optional but highly recommended)
- Get the MEM package and install it in a simple program. Learn how it works. Then install it in this
assignment, and use it all subsequent assignments. It will save you a lot of
debugging time.
- Part 1
- Add Boolean Panic-Mode Error Recovery to your parser:
- Change all the void parsing functions except your root parsing function
to Boolean functions that return TRUE if parsing succeeds, and FALSE if
parsing fails.
- Change any functions that print error messages and exit, to print the message and then
return FALSE instead of exiting. The parser will not exit on any syntax errors; it
will recover and continue parsing.
- Check the return status of all parsing functions called and return FALSE if any of them
return FALSE. You do not have to issue more error messages if a called parsing
function fails, since the parsing function itself will have printed its own error message.
- Add panic-mode error recovery to your top-level (root) parsing function. Modify it to
call your panic-mode function when a parsing error is detected. Have the top-level
function count the number of times it has to call the panic-mode function and return the
count as an integer to parser(). Have parser()
print the number of times panic-mode was invoked.
- Write your panic-mode function to skip to the token after the next semicolon. Have it
print the tokens that are skipped, as it skips them. Watch out for end-of-file!
- Test your that parser still works on all your source files. Test the error recovery.
Make sure it works as you expect and that the program does not exit prematurely.
- Hand in your top-level (root) parsing function and your panic-mode error recovery
function.
- Part 2
- Examine the enhanced Program Grammar #2. Use the method from
the previous assignment to enhance your DFA transition diagram, and then your Scanner, to
recognize the new token types. Two special token types that require a bit more explanation
are the print keyword and the double-quoted string of characters.
Test your new Scanner. (The Assignment 3 main.c program is good for testing Scanners
-- it prints all the token types the Scanner recognizes.) Make sure the Scanner
still recognizes all the previous tokens correctly, as well as the new ones. Test
the string token carefully. Make sure that print
is recognized.
Hand in your DFA state transition diagram.
- Part 3
- On paper, insert the appropriate semantic
action symbols into Program Grammar #2, turning it
into a translation scheme. Don't add any semantic action code to
your parser yet; merely develop the translation scheme.
Since handling identifiers requires a symbol table, and we don't yet have one, we can't
yet specify semantic actions for the two grammar productions that involve identifier
tokens. Ignore the semantic actions for these two productions. My test files
for this assignment will use only number and string constants.
Hand in your translation scheme. In addition to inserting the pseudocode semantic
action symbols in the grammar, supply short explanations of what each inserted symbol
means.
- Part 4
- Enhance your parser to parse the new grammar productions in Program
Grammar #2. Don't add any semantic actions to your parser yet; merely parse the
input, as in the previous assignment.
To choose the correct production to expand for stmt, you will
need to know the FIRST sets of the alternative productions (read
Aho, section 2.4, p.45-46) and have your code select the appropriate production based on
its FIRST set. The function for stmt
must generate an error message if the lookahead token doesn't match any of the three
alternatives.
Test your parser using assignment statements with expressions made up of numbers and
strings, and with print statements with expressions separated by commas.
I have a large a5test.txt
file containing some deeply nested print expressions. (This file has no errors in
it; your parser should not generate any error messages.)
Since the parser has no action statements in it, you won't see any output from the print
statements.
The output of running the enhanced Scanner using the Assignment 3 main program and the a5test.txt
file as input is in the (very large) output.txt
file. This shows all the tokens parsed by the enhanced Scanner. There
are no unknown tokens or syntax errors in this test file.
Some sample panic-mode error messages generated by syntax errors are in the errors.txt file.
Testing
- No program output is required for this assignment; however, if you don't test your
Scanner and Parser thoroughly, you will have problems handling the next assignment.
Ian D. Allen CST8152 Home Page
This page last updated: Sunday September 27, 1998 01:07