g*********s 发帖数: 1782 | 1 Hi, can any guru give some suggestion on how to develop a smart parser/
compiler
given a set of syntax definition?
By "smart" I mean the parser can skip some errors and continue, like gcc
does in some situation. I hope to learn some general principles on this
issue.
Thanks! | c*****t 发帖数: 1879 | 2 For LR parsers, when a set of tokens couldn't be reduced, there is a
error. At this point, you can decided on a case by case basis to
manipulate the parsing stack or directly generate an error.
For LL parsers, if your look ahead token isn't what you expect (such
as missing ';'), you can insert this pretty easily. Usually LL parsers
is a bit easier for this kind of stuff.
I'd say don't waste your time on itt. It's really not that importat.
【在 g*********s 的大作中提到】 : Hi, can any guru give some suggestion on how to develop a smart parser/ : compiler : given a set of syntax definition? : By "smart" I mean the parser can skip some errors and continue, like gcc : does in some situation. I hope to learn some general principles on this : issue. : Thanks!
| d****2 发帖数: 6250 | 3 bison supports "error" token, you can do whatever you want. | N********n 发帖数: 8363 | 4 The idea is simple: Add additional rules to track potential errors.
Like switch case statements:
switch (status)
case 0 : // do status 0
...
case 1 : // do status 1
...
case 2 : // wrong, status 2 is caused by some certain mistake
generateErrorReportOnStatus2 ();
... ...
"case 2" is an example of the additional rules.
【在 g*********s 的大作中提到】 : Hi, can any guru give some suggestion on how to develop a smart parser/ : compiler : given a set of syntax definition? : By "smart" I mean the parser can skip some errors and continue, like gcc : does in some situation. I hope to learn some general principles on this : issue. : Thanks!
|
|