[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 03/10] api.token.raw: check it
From: |
Akim Demaille |
Subject: |
[PATCH 03/10] api.token.raw: check it |
Date: |
Sun, 1 Sep 2019 18:41:16 +0200 |
* tests/local.at (AT_TOKEN_RAW_IF): New.
* tests/local.mk: New.
Use it.
---
tests/local.at | 3 ++
tests/local.mk | 1 +
tests/scanner.at | 120 +++++++++++++++++++++++++++++++++++++++++++++
tests/testsuite.at | 3 ++
4 files changed, 127 insertions(+)
create mode 100644 tests/scanner.at
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])
--
2.23.0
- RFC: Introduce api.token.raw, Akim Demaille, 2019/09/01
- [PATCH 01/10] style: tidy yacc.c, Akim Demaille, 2019/09/01
- [PATCH 02/10] api.token.raw: implement, Akim Demaille, 2019/09/01
- [PATCH 03/10] api.token.raw: check it,
Akim Demaille <=
- [PATCH 04/10] api.token.raw: apply to the other skeletons, Akim Demaille, 2019/09/01
- [PATCH 05/10] api.token.raw: cannot be used with character literals, Akim Demaille, 2019/09/01
- [PATCH 06/10] api.token.raw: document it, Akim Demaille, 2019/09/01
- [PATCH 07/10] parser: use api.token.raw, Akim Demaille, 2019/09/01
- [PATCH 09/10] d: handle eof in yytranslate, Akim Demaille, 2019/09/01
- [PATCH 10/10] java: handle eof in yytranslate, Akim Demaille, 2019/09/01
- [PATCH 08/10] regen, Akim Demaille, 2019/09/01
- Re: RFC: Introduce api.token.raw, Akim Demaille, 2019/09/14