I just started using packcc yesterday. I modified the calc example to read from a line buffer that did not contain EOL, and made a custom PCC_ERROR that printed an error message but did not exit, because I wanted to print an error message and then read the next line.
It took me a while to realize why my parse loop never ended.
I thought this might be related to #43 “Simple grammar goes into an infinite loop instead of erroring”, but in that case the parser is working correctly, matching ε again and again.
Of course the real fix is to modify the grammar to make it handle all inputs and report errors from there, but it is useful to have this way of stopping when an error occurs. What I do now is to store a special error message in auxil inside PCC_ERROR and then return 0; that way control goes back to the main program which prints that special error message saying that the grammar does not match all inputs.
I just started using
packcc
yesterday. I modified thecalc
example to read from a line buffer that did not contain EOL, and made a customPCC_ERROR
that printed an error message but did not exit, because I wanted to print an error message and then read the next line. It took me a while to realize why my parse loop never ended.I thought this might be related to #43 “Simple grammar goes into an infinite loop instead of erroring”, but in that case the parser is working correctly, matching ε again and again.
Of course the real fix is to modify the grammar to make it handle all inputs and report errors from there, but it is useful to have this way of stopping when an error occurs. What I do now is to store a special error message in
auxil
insidePCC_ERROR
and then return0
; that way control goes back to the main program which prints that special error message saying that the grammar does not match all inputs.