⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 regression.at

📁 GNU的词法/语法分析器bison源码
💻 AT
📖 第 1 页 / 共 2 页
字号:
# Bison Regressions.                               -*- Autotest -*-# Copyright (C) 2001, 2002, 2003, 2004, 2005 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 2, 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, write to the Free Software# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA# 02110-1301, USA.AT_BANNER([[Regression tests.]])## ------------------------- #### Early token definitions.  #### ------------------------- ##AT_SETUP([Early token definitions])# Found in GCJ: they expect the tokens to be defined before the user# prologue, so that they can use the token definitions in it.AT_DATA_GRAMMAR([input.y],[[%{void yyerror (const char *s);int yylex (void);%}%union{  int val;};%{#ifndef MY_TOKEN# error "MY_TOKEN not defined."#endif%}%token MY_TOKEN%%exp: MY_TOKEN;%%]])AT_CHECK([bison -o input.c input.y])AT_COMPILE([input.o], [-c input.c])AT_CLEANUP## ---------------- #### Braces parsing.  #### ---------------- ##AT_SETUP([Braces parsing])AT_DATA([input.y],[[/* Bison used to swallow the character after `}'. */%%exp: { tests = {{{{{{{{{{}}}}}}}}}}; };%%]])AT_CHECK([bison -v -o input.c input.y])AT_CHECK([grep 'tests = {{{{{{{{{{}}}}}}}}}};' input.c], 0, [ignore])AT_CLEANUP## ------------------ #### Duplicate string.  #### ------------------ ##AT_SETUP([Duplicate string])AT_DATA([input.y],[[/* `Bison -v' used to dump core when two tokens are defined with the same   string, as LE and GE below. */%token NUM%token LE "<="%token GE "<="%%exp: '(' exp ')' | NUM ;%%]])AT_CHECK([bison -v -o input.c input.y], 0, [],[[input.y:6.8-14: warning: symbol `"<="' used more than once as a literal string]])AT_CLEANUP## ------------------- #### Rule Line Numbers.  #### ------------------- ##AT_SETUP([Rule Line Numbers])AT_KEYWORDS([report])AT_DATA([input.y],[[%%expr:'a'{}'b'{}|{}'c'{};]])AT_CHECK([bison -o input.c -v input.y])# Check the contents of the report.AT_CHECK([cat input.output], [],[[Grammar    0 $accept: expr $end    1 @1: /* empty */    2 expr: 'a' @1 'b'    3 @2: /* empty */    4 expr: @2 'c'Terminals, with rules where they appear$end (0) 0'a' (97) 2'b' (98) 2'c' (99) 4error (256)Nonterminals, with rules where they appear$accept (6)    on left: 0expr (7)    on left: 2 4, on right: 0@1 (8)    on left: 1, on right: 2@2 (9)    on left: 3, on right: 4state 0    0 $accept: . expr $end    'a'  shift, and go to state 1    $default  reduce using rule 3 (@2)    expr  go to state 2    @2    go to state 3state 1    2 expr: 'a' . @1 'b'    $default  reduce using rule 1 (@1)    @1  go to state 4state 2    0 $accept: expr . $end    $end  shift, and go to state 5state 3    4 expr: @2 . 'c'    'c'  shift, and go to state 6state 4    2 expr: 'a' @1 . 'b'    'b'  shift, and go to state 7state 5    0 $accept: expr $end .    $default  acceptstate 6    4 expr: @2 'c' .    $default  reduce using rule 4 (expr)state 7    2 expr: 'a' @1 'b' .    $default  reduce using rule 2 (expr)]])AT_CLEANUP## ---------------------- #### Mixing %token styles.  #### ---------------------- ##AT_SETUP([Mixing %token styles])# Taken from the documentation.AT_DATA([input.y],[[%token  <operator>  OR      "||"%token  <operator>  LE 134  "<="%left  OR  "<="%%exp: ;%%]])AT_CHECK([bison -v -o input.c input.y])AT_CLEANUP## ---------------- #### Invalid inputs.  #### ---------------- ##AT_SETUP([Invalid inputs])AT_DATA([input.y],[[%%?default: 'a' }%&%a-does-not-exist%-%{]])AT_CHECK([bison input.y], [1], [],[[input.y:2.1: invalid character: `?'input.y:3.14: invalid character: `}'input.y:4.1: invalid character: `%'input.y:4.2: invalid character: `&'input.y:5.1-17: invalid directive: `%a-does-not-exist'input.y:6.1: invalid character: `%'input.y:6.2: invalid character: `-'input.y:7.1-8.0: missing `%}' at end of file]])AT_CLEANUPAT_SETUP([Invalid inputs with {}])AT_DATA([input.y],[[%destructor%initial-action%lex-param%parse-param%printer%union]])AT_CHECK([bison input.y], [1], [],[[input.y:3.1: missing `{' in "%destructor {...}"input.y:4.1: missing `{' in "%initial-action {...}"input.y:4.1: syntax error, unexpected %initial-action {...}, expecting string or identifier]])AT_CLEANUP## ------------------- #### Token definitions.  #### ------------------- ##AT_SETUP([Token definitions])# Bison managed, when fed with `%token 'f' "f"' to #define 'f'!AT_DATA_GRAMMAR([input.y],[%{#include <stdio.h>void yyerror (const char *s);int yylex (void);%}[%error-verbose%token MYEOF 0 "end of file"%token 'a' "a"%token B_TOKEN "b"%token C_TOKEN 'c'%token 'd' D_TOKEN%token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"%%exp: "a" "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!";%%voidyyerror (char const *s){  fprintf (stderr, "%s\n", s);}intyylex (void){  return SPECIAL;}intmain (void){  return yyparse ();}]])AT_CHECK([bison -o input.c input.y])AT_COMPILE([input])AT_DATA([experr],[[syntax error, unexpected "\\'?\"\a\b\f\n\r\t\v\001\201\001\201?\?!", expecting a]])AT_PARSER_CHECK([./input], 1, [], [experr])AT_CLEANUP## -------------------- #### Characters Escapes.  #### -------------------- ##AT_SETUP([Characters Escapes])AT_DATA_GRAMMAR([input.y],[%{void yyerror (const char *s);int yylex (void);%}[%%exp:  '\'' "\'"| '\"' "\""| '"'  "'";]])# Pacify font-lock-mode: "AT_CHECK([bison -o input.c input.y])AT_COMPILE([input.o], [-c input.c])AT_CLEANUP## -------------- #### Web2c Report.  #### -------------- ### The generation of the reduction was once wrong in Bison, and made it# miss some reductions.  In the following test case, the reduction on# `undef_id_tok' in state 1 was missing.  This is stripped down from# the actual web2c.y.AT_SETUP([Web2c Report])AT_KEYWORDS([report])

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -