c: don't emit an error message when the scanner returns YYERRCODE

* data/skeletons/yacc.c (yyparse): When the scanner returns YYERRCODE,
go directly to error recovery (yyerrlab1).
However, don't keep the error token as lookahead, that token is too
special.
* data/skeletons/lalr1.cc: Likewise.

* examples/c/bistromathic/parse.y (yylex): Use that feature to report
nicely invalid characters.
* examples/c/bistromathic/bistromathic.test: Check that.
* examples/test: Neutralize gratuitous differences such as rule
position.

* tests/calc.at: Check that case in C only.
The other case seem to be working, but that's an illusion that the
next commit will address (in fact, they can enter endless loops, and
report the error several times anyway).
This commit is contained in:
Akim Demaille
2020-04-15 07:38:46 +02:00
parent 60366b152b
commit 58e79539fc
6 changed files with 214 additions and 22 deletions

View File

@@ -89,11 +89,13 @@ run ()
shift
# Expected output.
if $strip_prompt; then
$echo "$1" | sed -e '/^> /d' >exp
else
$echo "$1" >exp
fi
$echo "$1" |
sed -e 's/Reducing stack by rule .* (line .*):/Reducing stack by rule XX (line XXX):/g' |
if $strip_prompt; then
sed -e '/^> /d'
else
cat
fi >exp
shift
# Effective exit status.
@@ -102,7 +104,14 @@ run ()
prog "$@" - <input >out_eff 2>err_eff || sta_eff=$?
# Combine effective output and error streams.
{ cat out_eff && $noerr || sed -e 's/^/err: /g' err_eff; } >eff
{
cat out_eff
if ! $noerr; then
sed -e 's/^/err: /g' \
-e 's/Reducing stack by rule .* (line .*):/Reducing stack by rule XX (line XXX):/g' \
err_eff
fi
} >eff
if test $sta_eff -eq $sta_exp; then
if cmp eff exp 2>/dev/null; then