4

What is the best way to flex and bison to stop processing when an error is encountered. If I call yyerror, it does not stop scanning and parsing my file. While the input is syntactically correct, there is an user error, such as they tried to load the same file twice. Once I am out of flex/bison, then my program will return an error to the user and the program should keep running. I assume that throwing a C++ exception would probably break something?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Juan
  • 3,667
  • 3
  • 28
  • 32

2 Answers2

2

YYABORT is the standard way of getting out; it causes yyparse to return immediately with a failure (1). You can then throw an exception or do whatever you want. You'll need to reset flex's input if you want to parse something else, but if you do, you can just call yyparse again and parsing will start over from the beginning.

Chris Dodd
  • 119,907
  • 13
  • 134
  • 226
  • Thanks for your reply. I suspect the issue I was having last July was that the YYABORT macro has to be in the action, and not within a function being called by the action. – Juan Mar 06 '12 at 18:22
0

YYACCEPT stop parse and return 0.

  • 2
    I doubt that this helps, or even works at all. To convince me otherwise please explain how this works and why it supposed to solve the problem. Or is this not even an attempt to answer and actually just describes the symptoms of a problem you would like to discuss? In that case please create your own question instead. – Yunnosch Feb 25 '20 at 17:24