diff options
author | Akim Demaille <akim.demaille@gmail.com> | 2019-08-28 16:28:32 -0500 |
---|---|---|
committer | Akim Demaille <akim.demaille@gmail.com> | 2019-09-14 09:55:17 +0200 |
commit | b1679f834674d2f08686807870e29f7bd6387ba8 (patch) | |
tree | cc2f0b782853f88f4e6f881aa0878f2dfc421728 /tests | |
parent | 9861bcc540298810ebe4a66d39923de5f08b8789 (diff) | |
download | bison-b1679f834674d2f08686807870e29f7bd6387ba8.tar.gz |
api.token.raw: check it
* tests/local.at (AT_TOKEN_RAW_IF): New.
* tests/local.mk: New.
Use it.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/local.at | 3 | ||||
-rw-r--r-- | tests/local.mk | 1 | ||||
-rw-r--r-- | tests/scanner.at | 120 | ||||
-rw-r--r-- | tests/testsuite.at | 3 |
4 files changed, 127 insertions, 0 deletions
diff --git a/tests/local.at b/tests/local.at index 48b65114..e70da61e 100644 --- a/tests/local.at +++ b/tests/local.at @@ -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]) diff --git a/tests/local.mk b/tests/local.mk index 7c233042..9a2b4d51 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -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 \ diff --git a/tests/scanner.at b/tests/scanner.at new file mode 100644 index 00000000..a3a8b479 --- /dev/null +++ b/tests/scanner.at @@ -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]) diff --git a/tests/testsuite.at b/tests/testsuite.at index 54f494fa..4ccbfd1e 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -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]) |