api.token.raw: check it

* tests/local.at (AT_TOKEN_RAW_IF): New.
* tests/local.mk: New.
Use it.
This commit is contained in:
Akim Demaille
2019-08-28 16:28:32 -05:00
parent 9861bcc540
commit b1679f8346
4 changed files with 127 additions and 0 deletions

View File

@@ -213,6 +213,8 @@ m4_pushdef([AT_TOKEN_CTOR_IF],
m4_pushdef([AT_TOKEN_PREFIX],
[m4_bmatch([$3], [%define api\.token\.prefix {.*}],
[m4_bregexp([$3], [%define api\.token\.prefix {\(.*\)}], [\1])])])
m4_pushdef([AT_TOKEN_RAW_IF],
[m4_bmatch([$3], [%define api\.token\.raw], [$1], [$2])])
m4_pushdef([AT_VARIANT_IF],
[m4_bmatch([$3], [%define api\.value\.type variant], [$1], [$2])])
m4_pushdef([AT_API_prefix],
@@ -325,6 +327,7 @@ m4_popdef([AT_YYERROR_ARG_LOC_IF])
m4_popdef([AT_API_PREFIX])
m4_popdef([AT_API_prefix])
m4_popdef([AT_VARIANT_IF])
m4_popdef([AT_TOKEN_RAW_IF])
m4_popdef([AT_TOKEN_PREFIX])
m4_popdef([AT_TOKEN_CTOR_IF])
m4_popdef([AT_NAMESPACE])

View File

@@ -63,6 +63,7 @@ TESTSUITE_AT = \
%D%/reduce.at \
%D%/regression.at \
%D%/report.at \
%D%/scanner.at \
%D%/sets.at \
%D%/skeletons.at \
%D%/synclines.at \

120
tests/scanner.at Normal file
View File

@@ -0,0 +1,120 @@
# Interface with the scanner. -*- Autotest -*-
# Copyright (C) 2019 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
AT_BANNER([[Interface with the scanner.]])
## ------------------- ##
## Raw token numbers. ##
## ------------------- ##
m4_pushdef([AT_TEST],
[
AT_SETUP([Token numbers: $1])
AT_BISON_OPTION_PUSHDEFS([%debug $1])
AT_DATA_GRAMMAR([[input.y]],
[[$1
%debug
%code
{
#include <stdio.h>
]AT_YYERROR_DECLARE[
]AT_YYLEX_DECLARE[
}
%union {
int val;
}
%token <val> NUM "number"
%token
PLUS "+"
MINUS "-"
STAR "*"
SLASH "/"
LPAR "("
RPAR ")"
%nterm <val> exp
%left "+" "-"
%left "*" "/"
%%
input
: exp { printf ("%d\n", $][1); }
;
exp
: exp "+" exp { $][$][ = $][1 + $][3; }
| exp "-" exp { $][$][ = $][1 - $][3; }
| exp "*" exp { $][$][ = $][1 * $][3; }
| exp "/" exp { $][$][ = $][1 / $][3; }
| "(" exp ")" { $][$][ = $][2; }
| "number" { $][$][ = $][1; }
;
%%
]AT_YYERROR_DEFINE[
]AT_MAIN_DEFINE[
int yylex (void)
{
static const char* input = "0-(1+2)*3/9";
int c = *input++;
switch (c)
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
yylval.val = c - '0';
return NUM;
case '+': return PLUS;
case '-': return MINUS;
case '*': return STAR;
case '/': return SLASH;
case '(': return LPAR;
case ')': return RPAR;
case 0: return 0;
}
}
]])
AT_FULL_COMPILE([input])
AT_CHECK([grep -c yytranslate input.c], [ignore], [AT_TOKEN_RAW_IF([0], [2])[
]])
AT_PARSER_CHECK([input], 0,
[[-1
]])
AT_BISON_OPTION_POPDEFS
AT_CLEANUP
])
AT_TEST([])
AT_TEST([%define api.token.raw])
m4_popdef([AT_TEST])

View File

@@ -56,6 +56,9 @@ m4_include([actions.at])
# Semantic types support.
m4_include([types.at])
# Interface with the scanner.
m4_include([scanner.at])
# Fulling testing (compilation and execution of the parser) on calc.
m4_include([calc.at])