[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 13/16] examples: bistromathic: demonstrate error recovery
From: |
Akim Demaille |
Subject: |
[PATCH 13/16] examples: bistromathic: demonstrate error recovery |
Date: |
Sun, 26 Apr 2020 16:40:48 +0200 |
* examples/c/bistromathic/parse.y: here.
* examples/c/bistromathic/bistromathic.test: Check it.
Included a stupid case where the error is actually ignored.
---
examples/c/README.md | 1 +
examples/c/bistromathic/README.md | 1 +
examples/c/bistromathic/bistromathic.test | 21 ++++++++++++++++++---
examples/c/bistromathic/parse.y | 1 +
4 files changed, 21 insertions(+), 3 deletions(-)
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 <<EOF
-100%
+((1 ++ 2) ** 3)
+(1 ++ 2) + (3 ** 4)
EOF
-run 0 '> 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 <<EOF
+100% + 10
+EOF
+run 0 '> 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.
--
2.26.2
- [PATCH 03/16] style: glr.c: fix indentation issue, (continued)
- [PATCH 03/16] style: glr.c: fix indentation issue, Akim Demaille, 2020/04/26
- [PATCH 04/16] style: prefer b4_has_translations_if, Akim Demaille, 2020/04/26
- [PATCH 02/16] style: fix a few remaining 'type' instead of 'kind', Akim Demaille, 2020/04/26
- [PATCH 01/16] skeletons: make the warning about implementation details clearer, Akim Demaille, 2020/04/26
- [PATCH 06/16] all: prefer YYERRCODE to YYERROR, Akim Demaille, 2020/04/26
- [PATCH 08/16] c++: always define symbol_name, Akim Demaille, 2020/04/26
- [PATCH 09/16] c++: make valid to print the empty symbol, Akim Demaille, 2020/04/26
- [PATCH 11/16] examples: bistromathic: comment changes, Akim Demaille, 2020/04/26
- [PATCH 10/16] doc: hacking tricks, Akim Demaille, 2020/04/26
- [PATCH 05/16] style: glr.c: clarify, Akim Demaille, 2020/04/26
- [PATCH 13/16] examples: bistromathic: demonstrate error recovery,
Akim Demaille <=
- [PATCH 12/16] examples: bistromathic: when quitting, close the current line, Akim Demaille, 2020/04/26
- [PATCH 15/16] all: don't emit an error message when the scanner returns YYERRCODE, Akim Demaille, 2020/04/26
- [PATCH 16/16] todo: update, Akim Demaille, 2020/04/26
- [PATCH 14/16] c: don't emit an error message when the scanner returns YYERRCODE, Akim Demaille, 2020/04/26