diff --git a/examples/c/README.md b/examples/c/README.md index 47963f13..0d8031c3 100644 --- a/examples/c/README.md +++ b/examples/c/README.md @@ -53,6 +53,7 @@ push-parser model. This example demonstrates best practices when using Bison. - Its hand-written scanner tracks locations. - Its interface is pure. +- It uses the `error` token to get error recovery. - Its interface is "incremental", well suited for interaction: it uses the push-parser API to feed the parser with the incoming tokens. - It features an interactive command line with completion based on the diff --git a/examples/c/bistromathic/README.md b/examples/c/bistromathic/README.md index 6b6521de..05f1b7ed 100644 --- a/examples/c/bistromathic/README.md +++ b/examples/c/bistromathic/README.md @@ -2,6 +2,7 @@ This example demonstrates best practices when using Bison. - Its hand-written scanner tracks locations. - Its interface is pure. +- It uses the `error` token to get error recovery. - Its interface is "incremental", well suited for interaction: it uses the push-parser API to feed the parser with the incoming tokens. - It features an interactive command line with completion based on the diff --git a/examples/c/bistromathic/bistromathic.test b/examples/c/bistromathic/bistromathic.test index c32c1f45..629c32c5 100755 --- a/examples/c/bistromathic/bistromathic.test +++ b/examples/c/bistromathic/bistromathic.test @@ -82,11 +82,26 @@ run 0 '> 1 / 0 > '' err: 1.1-5: error: division by zero' +# Error recovery. cat >input < 100% -100 +run 0 '> ((1 ++ 2) ** 3) +666 +> (1 ++ 2) + (3 ** 4) +1332 +> '' +err: 1.6: syntax error: expected - or ( or number or function or variable before + +err: 2.5: syntax error: expected - or ( or number or function or variable before + +err: 2.16: syntax error: expected - or ( or number or function or variable before *' + +# This is really stupid: we just discarded % and did not enter error recovery. +cat >input < 100% + 10 +110 > '' err: 1.4: error: invalid character' diff --git a/examples/c/bistromathic/parse.y b/examples/c/bistromathic/parse.y index 607a6ef4..5d422651 100644 --- a/examples/c/bistromathic/parse.y +++ b/examples/c/bistromathic/parse.y @@ -146,6 +146,7 @@ exp: | "-" exp %prec NEG { $$ = -$2; } | exp[l] "^" exp[r] { $$ = pow ($l, $r); } | "(" exp ")" { $$ = $2; } +| "(" error ")" { $$ = 666; } ; // End of grammar.