For my compilers class, we had to create a Lexical Analyzer and a Syntax Analyzer using JFlex and CUP. Part of the assignment also requires us to print out the tokens and corresponding parsing actions for a given input file. Additionally, the reduce actions need to display the corresponding production number.
For example, if my parser's grammar was
- S -> aXc
- X -> bX
- X -> b
- X -> Yd
- Y -> Yd
- Y -> d
Then a string of abbbc given as input would output
a [shift]
b [shift]
b [shift]
b [shift]
c [reduce 3] [reduce 2] [reduce 2] [shift]
[reduce 1]
[accept]
I know that CUP has the debug option, but the output needs to be in this specific format. Displaying the tokens was easy because I could just print out the tokens in the rules section of the Flex specification, but I can't figure out how to print out the actions in the CUP specification.