Import byacc 20120115
Approved by: des (mentor)
This commit is contained in:
commit
aec86590e4
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/vendor/byacc/dist/; revision=234949 svn path=/vendor/byacc/20120115/; revision=234950; tag=vendor/byacc/20120115
25
ACKNOWLEDGEMENTS
Normal file
25
ACKNOWLEDGEMENTS
Normal file
@ -0,0 +1,25 @@
|
||||
Berkeley Yacc owes much to the unflagging efforts of Keith Bostic.
|
||||
His badgering kept me working on it long after I was ready to quit.
|
||||
|
||||
Berkeley Yacc is based on the excellent algorithm for computing LALR(1)
|
||||
lookaheads developed by Tom Pennello and Frank DeRemer. The algorithm is
|
||||
described in their almost impenetrable article in TOPLAS 4,4.
|
||||
|
||||
Finally, much of the credit for the latest version must go to those
|
||||
who pointed out deficiencies of my earlier releases. Among the most
|
||||
prolific contributors were
|
||||
|
||||
Benson I. Margulies
|
||||
Dave Gentzel
|
||||
Antoine Verheijen
|
||||
Peter S. Housel
|
||||
Dale Smith
|
||||
Ozan Yigit
|
||||
John Campbell
|
||||
Bill Sommerfeld
|
||||
Paul Hilfinger
|
||||
Gary Bridgewater
|
||||
Dave Bakken
|
||||
Dan Lanciani
|
||||
Richard Sargent
|
||||
Parag Patel
|
7
AUTHORS
Normal file
7
AUTHORS
Normal file
@ -0,0 +1,7 @@
|
||||
-- $Id: AUTHORS,v 1.1 2010/06/06 20:31:51 tom Exp $
|
||||
-- vile:txtmode
|
||||
-- This file is used by a script that collects contributor information and
|
||||
-- resolves nicknames vs fullnames.
|
||||
dickey Thomas Dickey
|
||||
schmitz Sylvain Schmitz
|
||||
unknown Robert Corbett
|
84
Makefile.old
Normal file
84
Makefile.old
Normal file
@ -0,0 +1,84 @@
|
||||
DEST = .
|
||||
|
||||
HDRS = defs.h
|
||||
|
||||
CFLAGS = -O -DNDEBUG
|
||||
|
||||
LDFLAGS =
|
||||
|
||||
LIBS =
|
||||
|
||||
LINKER = cc
|
||||
|
||||
MAKEFILE = Makefile
|
||||
|
||||
OBJS = closure.o \
|
||||
error.o \
|
||||
lalr.o \
|
||||
lr0.o \
|
||||
main.o \
|
||||
mkpar.o \
|
||||
output.o \
|
||||
reader.o \
|
||||
skeleton.o \
|
||||
symtab.o \
|
||||
verbose.o \
|
||||
warshall.o
|
||||
|
||||
PRINT = pr -f -l88
|
||||
|
||||
PROGRAM = yacc
|
||||
|
||||
SRCS = closure.c \
|
||||
error.c \
|
||||
lalr.c \
|
||||
lr0.c \
|
||||
main.c \
|
||||
mkpar.c \
|
||||
output.c \
|
||||
reader.c \
|
||||
skeleton.c \
|
||||
symtab.c \
|
||||
verbose.c \
|
||||
warshall.c
|
||||
|
||||
all: $(PROGRAM)
|
||||
|
||||
$(PROGRAM): $(OBJS) $(LIBS)
|
||||
@echo -n "Loading $(PROGRAM) ... "
|
||||
@$(LINKER) $(LDFLAGS) -o $(PROGRAM) $(OBJS) $(LIBS)
|
||||
@echo "done"
|
||||
|
||||
clean:; @rm -f $(OBJS)
|
||||
|
||||
clobber:; @rm -f $(OBJS) $(PROGRAM)
|
||||
|
||||
depend:; @mkmf -f $(MAKEFILE) PROGRAM=$(PROGRAM) DEST=$(DEST)
|
||||
|
||||
index:; @ctags -wx $(HDRS) $(SRCS)
|
||||
|
||||
install: $(PROGRAM)
|
||||
@echo Installing $(PROGRAM) in $(DEST)
|
||||
@install -s $(PROGRAM) $(DEST)
|
||||
|
||||
listing:; @$(PRINT) Makefile $(HDRS) $(SRCS) | lpr
|
||||
|
||||
lint:; @lint $(SRCS)
|
||||
|
||||
program: $(PROGRAM)
|
||||
|
||||
tags: $(HDRS) $(SRCS); @ctags $(HDRS) $(SRCS)
|
||||
|
||||
###
|
||||
closure.o: defs.h
|
||||
error.o: defs.h
|
||||
lalr.o: defs.h
|
||||
lr0.o: defs.h
|
||||
main.o: defs.h
|
||||
mkpar.o: defs.h
|
||||
output.o: defs.h
|
||||
reader.o: defs.h
|
||||
skeleton.o: defs.h
|
||||
symtab.o: defs.h
|
||||
verbose.o: defs.h
|
||||
warshall.o: defs.h
|
46
NEW_FEATURES
Normal file
46
NEW_FEATURES
Normal file
@ -0,0 +1,46 @@
|
||||
The -r option has been implemented. The -r option tells Yacc to
|
||||
put the read-only tables in y.tab.c and the code and variables in
|
||||
y.code.c. Keith Bostic asked for this option so that :yyfix could be
|
||||
eliminated.
|
||||
|
||||
The -l and -t options have been implemented. The -l option tells
|
||||
Yacc not to include #line directives in the code it produces. The -t
|
||||
option causes debugging code to be included in the compiled parser.
|
||||
|
||||
The code for error recovery has been changed to implement the same
|
||||
algorithm as AT&T Yacc. There will still be differences in the way
|
||||
error recovery works because AT&T Yacc uses more default reductions
|
||||
than Berkeley Yacc.
|
||||
|
||||
The environment variable TMPDIR determines the directory where
|
||||
temporary files will be created. If TMPDIR is defined, temporary files
|
||||
will be created in the directory whose pathname is the value of TMPDIR.
|
||||
By default, temporary files are created in /tmp.
|
||||
|
||||
The keywords are now case-insensitive. For example, %nonassoc,
|
||||
%NONASSOC, %NonAssoc, and %nOnAsSoC are all equivalent.
|
||||
|
||||
Commas and semicolons that are not part of C code are treated as
|
||||
commentary.
|
||||
|
||||
Line-end comments, as in BCPL, are permitted. Line-end comments
|
||||
begin with // and end at the next end-of-line. Line-end comments are
|
||||
permitted in C code; they are converted to C comments on output.
|
||||
|
||||
The form of y.output files has been changed to look more like
|
||||
those produced by AT&T Yacc.
|
||||
|
||||
A new kind of declaration has been added. The form of the declaration
|
||||
is
|
||||
|
||||
%ident string
|
||||
|
||||
where string is a sequence of characters begining with a double quote
|
||||
and ending with either a double quote or the next end-of-line, whichever
|
||||
comes first. The declaration will cause a #ident directive to be written
|
||||
near the start of the output file.
|
||||
|
||||
If a parser has been compiled with debugging code, that code can be
|
||||
enabled by setting an environment variable. If the environment variable
|
||||
YYDEBUG is set to 0, debugging output is suppressed. If it is set to 1,
|
||||
debugging output is written to standard output.
|
9
NOTES
Normal file
9
NOTES
Normal file
@ -0,0 +1,9 @@
|
||||
Berkeley Yacc reflects its origins. The reason so many routines
|
||||
use exactly six register variables is that Berkeley Yacc was
|
||||
developed on a VAX using PCC. PCC placed at most six variables
|
||||
in registers. I went to considerable effort to find which six
|
||||
variables most belonged in registers. Changes in machines and
|
||||
compilers make that effort worthless, perhaps even harmful.
|
||||
|
||||
The code contains many instances where address calculations are
|
||||
performed in particular ways to optimize the code for the VAX.
|
3
NO_WARRANTY
Normal file
3
NO_WARRANTY
Normal file
@ -0,0 +1,3 @@
|
||||
Berkeley Yacc is distributed with no warranty whatever. The author
|
||||
and any other contributors take no responsibility for the consequences of
|
||||
its use.
|
29
README
Normal file
29
README
Normal file
@ -0,0 +1,29 @@
|
||||
-- $Id: README,v 1.2 2004/03/28 17:24:53 tom Exp $
|
||||
|
||||
The original README is below. I've updated this version of Berkeley Yacc
|
||||
to make it ANSI C compliant - Thomas Dickey
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
Berkeley Yacc is an LALR(1) parser generator. Berkeley Yacc has been made
|
||||
as compatible as possible with AT&T Yacc. Berkeley Yacc can accept any input
|
||||
specification that conforms to the AT&T Yacc documentation. Specifications
|
||||
that take advantage of undocumented features of AT&T Yacc will probably be
|
||||
rejected.
|
||||
|
||||
Berkeley Yacc is distributed with no warranty whatever. The code is certain
|
||||
to contain errors. Neither the author nor any contributor takes responsibility
|
||||
for any consequences of its use.
|
||||
|
||||
Berkeley Yacc is in the public domain. The data structures and algorithms
|
||||
used in Berkeley Yacc are all either taken from documents available to the
|
||||
general public or are inventions of the author. Anyone may freely distribute
|
||||
source or binary forms of Berkeley Yacc whether unchanged or modified.
|
||||
Distributers may charge whatever fees they can obtain for Berkeley Yacc.
|
||||
Programs generated by Berkeley Yacc may be distributed freely.
|
||||
|
||||
Please report bugs to
|
||||
|
||||
robert.corbett@eng.Sun.COM
|
||||
|
||||
Include a small example if possible. Please include the banner string from
|
||||
skeleton.c with the bug report. Do not expect rapid responses.
|
1144
aclocal.m4
vendored
Normal file
1144
aclocal.m4
vendored
Normal file
File diff suppressed because it is too large
Load Diff
251
closure.c
Normal file
251
closure.c
Normal file
@ -0,0 +1,251 @@
|
||||
/* $Id: closure.c,v 1.9 2010/06/09 08:21:47 tom Exp $ */
|
||||
|
||||
#include "defs.h"
|
||||
|
||||
Value_t *itemset;
|
||||
Value_t *itemsetend;
|
||||
unsigned *ruleset;
|
||||
|
||||
static unsigned *first_derives;
|
||||
static unsigned *EFF;
|
||||
|
||||
static void
|
||||
set_EFF(void)
|
||||
{
|
||||
unsigned *row;
|
||||
int symbol;
|
||||
short *sp;
|
||||
int rowsize;
|
||||
int i;
|
||||
int rule;
|
||||
|
||||
rowsize = WORDSIZE(nvars);
|
||||
EFF = NEW2(nvars * rowsize, unsigned);
|
||||
|
||||
row = EFF;
|
||||
for (i = start_symbol; i < nsyms; i++)
|
||||
{
|
||||
sp = derives[i];
|
||||
for (rule = *sp; rule > 0; rule = *++sp)
|
||||
{
|
||||
symbol = ritem[rrhs[rule]];
|
||||
if (ISVAR(symbol))
|
||||
{
|
||||
symbol -= start_symbol;
|
||||
SETBIT(row, symbol);
|
||||
}
|
||||
}
|
||||
row += rowsize;
|
||||
}
|
||||
|
||||
reflexive_transitive_closure(EFF, nvars);
|
||||
|
||||
#ifdef DEBUG
|
||||
print_EFF();
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
set_first_derives(void)
|
||||
{
|
||||
unsigned *rrow;
|
||||
unsigned *vrow;
|
||||
int j;
|
||||
unsigned k;
|
||||
unsigned cword = 0;
|
||||
short *rp;
|
||||
|
||||
int rule;
|
||||
int i;
|
||||
int rulesetsize;
|
||||
int varsetsize;
|
||||
|
||||
rulesetsize = WORDSIZE(nrules);
|
||||
varsetsize = WORDSIZE(nvars);
|
||||
first_derives = NEW2(nvars * rulesetsize, unsigned) - ntokens * rulesetsize;
|
||||
|
||||
set_EFF();
|
||||
|
||||
rrow = first_derives + ntokens * rulesetsize;
|
||||
for (i = start_symbol; i < nsyms; i++)
|
||||
{
|
||||
vrow = EFF + ((i - ntokens) * varsetsize);
|
||||
k = BITS_PER_WORD;
|
||||
for (j = start_symbol; j < nsyms; k++, j++)
|
||||
{
|
||||
if (k >= BITS_PER_WORD)
|
||||
{
|
||||
cword = *vrow++;
|
||||
k = 0;
|
||||
}
|
||||
|
||||
if (cword & (unsigned)(1 << k))
|
||||
{
|
||||
rp = derives[j];
|
||||
while ((rule = *rp++) >= 0)
|
||||
{
|
||||
SETBIT(rrow, rule);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rrow += rulesetsize;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
print_first_derives();
|
||||
#endif
|
||||
|
||||
FREE(EFF);
|
||||
}
|
||||
|
||||
void
|
||||
closure(short *nucleus, int n)
|
||||
{
|
||||
unsigned ruleno;
|
||||
unsigned word;
|
||||
unsigned i;
|
||||
Value_t *csp;
|
||||
unsigned *dsp;
|
||||
unsigned *rsp;
|
||||
int rulesetsize;
|
||||
|
||||
Value_t *csend;
|
||||
unsigned *rsend;
|
||||
int symbol;
|
||||
Value_t itemno;
|
||||
|
||||
rulesetsize = WORDSIZE(nrules);
|
||||
rsend = ruleset + rulesetsize;
|
||||
for (rsp = ruleset; rsp < rsend; rsp++)
|
||||
*rsp = 0;
|
||||
|
||||
csend = nucleus + n;
|
||||
for (csp = nucleus; csp < csend; ++csp)
|
||||
{
|
||||
symbol = ritem[*csp];
|
||||
if (ISVAR(symbol))
|
||||
{
|
||||
dsp = first_derives + symbol * rulesetsize;
|
||||
rsp = ruleset;
|
||||
while (rsp < rsend)
|
||||
*rsp++ |= *dsp++;
|
||||
}
|
||||
}
|
||||
|
||||
ruleno = 0;
|
||||
itemsetend = itemset;
|
||||
csp = nucleus;
|
||||
for (rsp = ruleset; rsp < rsend; ++rsp)
|
||||
{
|
||||
word = *rsp;
|
||||
if (word)
|
||||
{
|
||||
for (i = 0; i < BITS_PER_WORD; ++i)
|
||||
{
|
||||
if (word & (unsigned)(1 << i))
|
||||
{
|
||||
itemno = rrhs[ruleno + i];
|
||||
while (csp < csend && *csp < itemno)
|
||||
*itemsetend++ = *csp++;
|
||||
*itemsetend++ = itemno;
|
||||
while (csp < csend && *csp == itemno)
|
||||
++csp;
|
||||
}
|
||||
}
|
||||
}
|
||||
ruleno += BITS_PER_WORD;
|
||||
}
|
||||
|
||||
while (csp < csend)
|
||||
*itemsetend++ = *csp++;
|
||||
|
||||
#ifdef DEBUG
|
||||
print_closure(n);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
finalize_closure(void)
|
||||
{
|
||||
FREE(itemset);
|
||||
FREE(ruleset);
|
||||
FREE(first_derives + ntokens * WORDSIZE(nrules));
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
void
|
||||
print_closure(int n)
|
||||
{
|
||||
short *isp;
|
||||
|
||||
printf("\n\nn = %d\n\n", n);
|
||||
for (isp = itemset; isp < itemsetend; isp++)
|
||||
printf(" %d\n", *isp);
|
||||
}
|
||||
|
||||
void
|
||||
print_EFF(void)
|
||||
{
|
||||
int i, j;
|
||||
unsigned *rowp;
|
||||
unsigned word;
|
||||
unsigned k;
|
||||
|
||||
printf("\n\nEpsilon Free Firsts\n");
|
||||
|
||||
for (i = start_symbol; i < nsyms; i++)
|
||||
{
|
||||
printf("\n%s", symbol_name[i]);
|
||||
rowp = EFF + ((i - start_symbol) * WORDSIZE(nvars));
|
||||
word = *rowp++;
|
||||
|
||||
k = BITS_PER_WORD;
|
||||
for (j = 0; j < nvars; k++, j++)
|
||||
{
|
||||
if (k >= BITS_PER_WORD)
|
||||
{
|
||||
word = *rowp++;
|
||||
k = 0;
|
||||
}
|
||||
|
||||
if (word & (1 << k))
|
||||
printf(" %s", symbol_name[start_symbol + j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
print_first_derives(void)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
unsigned *rp;
|
||||
unsigned cword = 0;
|
||||
unsigned k;
|
||||
|
||||
printf("\n\n\nFirst Derives\n");
|
||||
|
||||
for (i = start_symbol; i < nsyms; i++)
|
||||
{
|
||||
printf("\n%s derives\n", symbol_name[i]);
|
||||
rp = first_derives + i * WORDSIZE(nrules);
|
||||
k = BITS_PER_WORD;
|
||||
for (j = 0; j <= nrules; k++, j++)
|
||||
{
|
||||
if (k >= BITS_PER_WORD)
|
||||
{
|
||||
cword = *rp++;
|
||||
k = 0;
|
||||
}
|
||||
|
||||
if (cword & (1 << k))
|
||||
printf(" %d\n", j);
|
||||
}
|
||||
}
|
||||
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
#endif
|
1511
config.guess
vendored
Executable file
1511
config.guess
vendored
Executable file
File diff suppressed because it is too large
Load Diff
1760
config.sub
vendored
Executable file
1760
config.sub
vendored
Executable file
File diff suppressed because it is too large
Load Diff
3
config_h.in
Normal file
3
config_h.in
Normal file
@ -0,0 +1,3 @@
|
||||
/* @configure_input@ */
|
||||
/* $Id: config_h.in,v 1.1 1995/01/01 19:34:59 tom Exp $ */
|
||||
@DEFS@
|
30
configure.in
Normal file
30
configure.in
Normal file
@ -0,0 +1,30 @@
|
||||
dnl Process this file with 'autoconf' to produce a 'configure' script
|
||||
dnl $Id: configure.in,v 1.10 2010/12/26 19:10:21 tom Exp $
|
||||
AC_PREREQ(2.13.20020210)
|
||||
AC_REVISION($Revision: 1.10 $)
|
||||
AC_INIT(main.c)
|
||||
AC_CONFIG_HEADER(config.h:config_h.in)
|
||||
|
||||
CF_CHECK_CACHE([AC_CANONICAL_SYSTEM])
|
||||
|
||||
AC_ARG_PROGRAM
|
||||
AC_PROG_CC
|
||||
AC_CONST
|
||||
AC_PROG_MAKE_SET
|
||||
AC_PROG_INSTALL
|
||||
CF_MAKE_TAGS
|
||||
CF_PROG_LINT
|
||||
|
||||
CF_ANSI_CC_REQD
|
||||
CF_XOPEN_SOURCE
|
||||
AC_CHECK_HEADERS(fcntl.h)
|
||||
AC_CHECK_FUNCS(atexit)
|
||||
CF_MKSTEMP
|
||||
|
||||
CF_WITH_WARNINGS(Wwrite-strings)
|
||||
CF_DISABLE_ECHO
|
||||
CF_PROG_EXT
|
||||
CF_DISABLE_LEAKS
|
||||
|
||||
### output makefile
|
||||
AC_OUTPUT(makefile,,,cat)
|
439
defs.h
Normal file
439
defs.h
Normal file
@ -0,0 +1,439 @@
|
||||
/* $Id: defs.h,v 1.36 2011/12/20 01:31:16 tom Exp $ */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define YYMAJOR 1
|
||||
#define YYMINOR 9
|
||||
|
||||
#define CONCAT(first,second) first #second
|
||||
#define CONCAT1(string,number) CONCAT(string, number)
|
||||
#define CONCAT2(first,second) #first "." #second
|
||||
|
||||
#ifdef YYPATCH
|
||||
#define VSTRING(a,b) CONCAT2(a,b) CONCAT1(" ",YYPATCH)
|
||||
#else
|
||||
#define VSTRING(a,b) CONCAT2(a,b)
|
||||
#endif
|
||||
|
||||
#define VERSION VSTRING(YYMAJOR, YYMINOR)
|
||||
|
||||
/* machine-dependent definitions */
|
||||
/* the following definitions are for the Tahoe */
|
||||
/* they might have to be changed for other machines */
|
||||
|
||||
/* MAXCHAR is the largest unsigned character value */
|
||||
/* MAXSHORT is the largest value of a C short */
|
||||
/* MINSHORT is the most negative value of a C short */
|
||||
/* MAXTABLE is the maximum table size */
|
||||
/* BITS_PER_WORD is the number of bits in a C unsigned */
|
||||
/* WORDSIZE computes the number of words needed to */
|
||||
/* store n bits */
|
||||
/* BIT returns the value of the n-th bit starting */
|
||||
/* from r (0-indexed) */
|
||||
/* SETBIT sets the n-th bit starting from r */
|
||||
|
||||
#define MAXCHAR 255
|
||||
#define MAXSHORT 32767
|
||||
#define MINSHORT -32768
|
||||
#define MAXTABLE 32500
|
||||
#define BITS_PER_WORD 32
|
||||
#define WORDSIZE(n) (((n)+(BITS_PER_WORD-1))/BITS_PER_WORD)
|
||||
#define BIT(r, n) ((((r)[(n)>>5])>>((n)&31))&1)
|
||||
#define SETBIT(r, n) ((r)[(n)>>5]|=((unsigned)1<<((n)&31)))
|
||||
|
||||
/* character names */
|
||||
|
||||
#define NUL '\0' /* the null character */
|
||||
#define NEWLINE '\n' /* line feed */
|
||||
#define SP ' ' /* space */
|
||||
#define BS '\b' /* backspace */
|
||||
#define HT '\t' /* horizontal tab */
|
||||
#define VT '\013' /* vertical tab */
|
||||
#define CR '\r' /* carriage return */
|
||||
#define FF '\f' /* form feed */
|
||||
#define QUOTE '\'' /* single quote */
|
||||
#define DOUBLE_QUOTE '\"' /* double quote */
|
||||
#define BACKSLASH '\\' /* backslash */
|
||||
|
||||
#define UCH(c) (unsigned char)(c)
|
||||
|
||||
/* defines for constructing filenames */
|
||||
|
||||
#if defined(VMS)
|
||||
#define CODE_SUFFIX "_code.c"
|
||||
#define DEFINES_SUFFIX "_tab.h"
|
||||
#define EXTERNS_SUFFIX "_tab.i"
|
||||
#define OUTPUT_SUFFIX "_tab.c"
|
||||
#else
|
||||
#define CODE_SUFFIX ".code.c"
|
||||
#define DEFINES_SUFFIX ".tab.h"
|
||||
#define EXTERNS_SUFFIX ".tab.i"
|
||||
#define OUTPUT_SUFFIX ".tab.c"
|
||||
#endif
|
||||
#define VERBOSE_SUFFIX ".output"
|
||||
#define GRAPH_SUFFIX ".dot"
|
||||
|
||||
/* keyword codes */
|
||||
|
||||
#define TOKEN 0
|
||||
#define LEFT 1
|
||||
#define RIGHT 2
|
||||
#define NONASSOC 3
|
||||
#define MARK 4
|
||||
#define TEXT 5
|
||||
#define TYPE 6
|
||||
#define START 7
|
||||
#define UNION 8
|
||||
#define IDENT 9
|
||||
#define EXPECT 10
|
||||
#define EXPECT_RR 11
|
||||
#define PURE_PARSER 12
|
||||
#define PARSE_PARAM 13
|
||||
#define LEX_PARAM 14
|
||||
#define POSIX_YACC 15
|
||||
|
||||
/* symbol classes */
|
||||
|
||||
#define UNKNOWN 0
|
||||
#define TERM 1
|
||||
#define NONTERM 2
|
||||
|
||||
/* the undefined value */
|
||||
|
||||
#define UNDEFINED (-1)
|
||||
|
||||
/* action codes */
|
||||
|
||||
#define SHIFT 1
|
||||
#define REDUCE 2
|
||||
|
||||
/* character macros */
|
||||
|
||||
#define IS_IDENT(c) (isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$')
|
||||
#define IS_OCTAL(c) ((c) >= '0' && (c) <= '7')
|
||||
#define NUMERIC_VALUE(c) ((c) - '0')
|
||||
|
||||
/* symbol macros */
|
||||
|
||||
#define ISTOKEN(s) ((s) < start_symbol)
|
||||
#define ISVAR(s) ((s) >= start_symbol)
|
||||
|
||||
/* storage allocation macros */
|
||||
|
||||
#define CALLOC(k,n) (calloc((size_t)(k),(size_t)(n)))
|
||||
#define FREE(x) (free((char*)(x)))
|
||||
#define MALLOC(n) (malloc((size_t)(n)))
|
||||
#define NEW(t) ((t*)allocate(sizeof(t)))
|
||||
#define NEW2(n,t) ((t*)allocate(((size_t)(n)*sizeof(t))))
|
||||
#define REALLOC(p,n) (realloc((char*)(p),(size_t)(n)))
|
||||
|
||||
#define DO_FREE(x) if (x) { FREE(x); x = 0; }
|
||||
|
||||
#define NO_SPACE(p) if (p == 0) no_space(); assert(p != 0)
|
||||
|
||||
/* messages */
|
||||
#define PLURAL(n) ((n) > 1 ? "s" : "")
|
||||
|
||||
typedef char Assoc_t;
|
||||
typedef char Class_t;
|
||||
typedef short Index_t;
|
||||
typedef short Value_t;
|
||||
|
||||
/* the structure of a symbol table entry */
|
||||
|
||||
typedef struct bucket bucket;
|
||||
struct bucket
|
||||
{
|
||||
struct bucket *link;
|
||||
struct bucket *next;
|
||||
char *name;
|
||||
char *tag;
|
||||
Value_t value;
|
||||
Index_t index;
|
||||
Value_t prec;
|
||||
Class_t class;
|
||||
Assoc_t assoc;
|
||||
};
|
||||
|
||||
/* the structure of the LR(0) state machine */
|
||||
|
||||
typedef struct core core;
|
||||
struct core
|
||||
{
|
||||
struct core *next;
|
||||
struct core *link;
|
||||
Value_t number;
|
||||
Value_t accessing_symbol;
|
||||
Value_t nitems;
|
||||
Value_t items[1];
|
||||
};
|
||||
|
||||
/* the structure used to record shifts */
|
||||
|
||||
typedef struct shifts shifts;
|
||||
struct shifts
|
||||
{
|
||||
struct shifts *next;
|
||||
Value_t number;
|
||||
Value_t nshifts;
|
||||
Value_t shift[1];
|
||||
};
|
||||
|
||||
/* the structure used to store reductions */
|
||||
|
||||
typedef struct reductions reductions;
|
||||
struct reductions
|
||||
{
|
||||
struct reductions *next;
|
||||
Value_t number;
|
||||
Value_t nreds;
|
||||
Value_t rules[1];
|
||||
};
|
||||
|
||||
/* the structure used to represent parser actions */
|
||||
|
||||
typedef struct action action;
|
||||
struct action
|
||||
{
|
||||
struct action *next;
|
||||
Value_t symbol;
|
||||
Value_t number;
|
||||
Value_t prec;
|
||||
char action_code;
|
||||
Assoc_t assoc;
|
||||
char suppressed;
|
||||
};
|
||||
|
||||
/* the structure used to store parse/lex parameters */
|
||||
typedef struct param param;
|
||||
struct param
|
||||
{
|
||||
struct param *next;
|
||||
char *name; /* parameter name */
|
||||
char *type; /* everything before parameter name */
|
||||
char *type2; /* everything after parameter name */
|
||||
};
|
||||
|
||||
/* global variables */
|
||||
|
||||
extern char dflag;
|
||||
extern char gflag;
|
||||
extern char iflag;
|
||||
extern char lflag;
|
||||
extern char rflag;
|
||||
extern char sflag;
|
||||
extern char tflag;
|
||||
extern char vflag;
|
||||
extern const char *symbol_prefix;
|
||||
|
||||
extern const char *myname;
|
||||
extern char *cptr;
|
||||
extern char *line;
|
||||
extern int lineno;
|
||||
extern int outline;
|
||||
extern int exit_code;
|
||||
extern int pure_parser;
|
||||
|
||||
extern const char *const banner[];
|
||||
extern const char *const xdecls[];
|
||||
extern const char *const tables[];
|
||||
extern const char *const global_vars[];
|
||||
extern const char *const impure_vars[];
|
||||
extern const char *const hdr_defs[];
|
||||
extern const char *const hdr_vars[];
|
||||
extern const char *const body_1[];
|
||||
extern const char *const body_vars[];
|
||||
extern const char *const body_2[];
|
||||
extern const char *const body_3[];
|
||||
extern const char *const trailer[];
|
||||
extern const char *const trailer_2[];
|
||||
|
||||
extern char *code_file_name;
|
||||
extern char *input_file_name;
|
||||
extern char *defines_file_name;
|
||||
extern char *externs_file_name;
|
||||
|
||||
extern FILE *action_file;
|
||||
extern FILE *code_file;
|
||||
extern FILE *defines_file;
|
||||
extern FILE *externs_file;
|
||||
extern FILE *input_file;
|
||||
extern FILE *output_file;
|
||||
extern FILE *text_file;
|
||||
extern FILE *union_file;
|
||||
extern FILE *verbose_file;
|
||||
extern FILE *graph_file;
|
||||
|
||||
extern int nitems;
|
||||
extern int nrules;
|
||||
extern int nsyms;
|
||||
extern int ntokens;
|
||||
extern int nvars;
|
||||
extern int ntags;
|
||||
|
||||
extern char unionized;
|
||||
extern char line_format[];
|
||||
|
||||
extern Value_t start_symbol;
|
||||
extern char **symbol_name;
|
||||
extern char **symbol_pname;
|
||||
extern Value_t *symbol_value;
|
||||
extern Value_t *symbol_prec;
|
||||
extern char *symbol_assoc;
|
||||
|
||||
extern Value_t *ritem;
|
||||
extern Value_t *rlhs;
|
||||
extern Value_t *rrhs;
|
||||
extern Value_t *rprec;
|
||||
extern Assoc_t *rassoc;
|
||||
|
||||
extern Value_t **derives;
|
||||
extern char *nullable;
|
||||
|
||||
extern bucket *first_symbol;
|
||||
extern bucket *last_symbol;
|
||||
|
||||
extern int pure_parser;
|
||||
extern int nstates;
|
||||
extern core *first_state;
|
||||
extern shifts *first_shift;
|
||||
extern reductions *first_reduction;
|
||||
extern Value_t *accessing_symbol;
|
||||
extern core **state_table;
|
||||
extern shifts **shift_table;
|
||||
extern reductions **reduction_table;
|
||||
extern unsigned *LA;
|
||||
extern Value_t *LAruleno;
|
||||
extern Value_t *lookaheads;
|
||||
extern Value_t *goto_map;
|
||||
extern Value_t *from_state;
|
||||
extern Value_t *to_state;
|
||||
|
||||
extern action **parser;
|
||||
extern int SRexpect;
|
||||
extern int RRexpect;
|
||||
extern int SRtotal;
|
||||
extern int RRtotal;
|
||||
extern Value_t *SRconflicts;
|
||||
extern Value_t *RRconflicts;
|
||||
extern Value_t *defred;
|
||||
extern Value_t *rules_used;
|
||||
extern Value_t nunused;
|
||||
extern Value_t final_state;
|
||||
|
||||
extern Value_t *itemset;
|
||||
extern Value_t *itemsetend;
|
||||
extern unsigned *ruleset;
|
||||
|
||||
extern param *lex_param;
|
||||
extern param *parse_param;
|
||||
|
||||
/* global functions */
|
||||
|
||||
extern bucket *lookup(const char *);
|
||||
extern bucket *make_bucket(const char *);
|
||||
|
||||
#ifndef GCC_NORETURN
|
||||
#define GCC_NORETURN /* nothing */
|
||||
#endif
|
||||
|
||||
#ifndef GCC_UNUSED
|
||||
#define GCC_UNUSED /* nothing */
|
||||
#endif
|
||||
|
||||
/* closure.c */
|
||||
extern void closure(Value_t * nucleus, int n);
|
||||
extern void finalize_closure(void);
|
||||
extern void set_first_derives(void);
|
||||
|
||||
/* error.c */
|
||||
extern void default_action_warning(void);
|
||||
extern void dollar_error(int a_lineno, char *a_line, char *a_cptr) GCC_NORETURN;
|
||||
extern void dollar_warning(int a_lineno, int i);
|
||||
extern void fatal(const char *msg) GCC_NORETURN;
|
||||
extern void illegal_character(char *c_cptr) GCC_NORETURN;
|
||||
extern void illegal_tag(int t_lineno, char *t_line, char *t_cptr) GCC_NORETURN;
|
||||
extern void missing_brace(void) GCC_NORETURN;
|
||||
extern void no_grammar(void) GCC_NORETURN;
|
||||
extern void no_space(void) GCC_NORETURN;
|
||||
extern void open_error(const char *filename) GCC_NORETURN;
|
||||
extern void over_unionized(char *u_cptr) GCC_NORETURN;
|
||||
extern void prec_redeclared(void);
|
||||
extern void reprec_warning(char *s);
|
||||
extern void restarted_warning(void);
|
||||
extern void retyped_warning(char *s);
|
||||
extern void revalued_warning(char *s);
|
||||
extern void syntax_error(int st_lineno, char *st_line, char *st_cptr) GCC_NORETURN;
|
||||
extern void terminal_lhs(int s_lineno) GCC_NORETURN;
|
||||
extern void terminal_start(char *s) GCC_NORETURN;
|
||||
extern void tokenized_start(char *s) GCC_NORETURN;
|
||||
extern void undefined_goal(char *s) GCC_NORETURN;
|
||||
extern void undefined_symbol_warning(char *s);
|
||||
extern void unexpected_EOF(void) GCC_NORETURN;
|
||||
extern void unknown_rhs(int i) GCC_NORETURN;
|
||||
extern void unterminated_action(int a_lineno, char *a_line, char *a_cptr) GCC_NORETURN;
|
||||
extern void unterminated_comment(int c_lineno, char *c_line, char *c_cptr) GCC_NORETURN;
|
||||
extern void unterminated_string(int s_lineno, char *s_line, char *s_cptr) GCC_NORETURN;
|
||||
extern void unterminated_text(int t_lineno, char *t_line, char *t_cptr) GCC_NORETURN;
|
||||
extern void unterminated_union(int u_lineno, char *u_line, char *u_cptr) GCC_NORETURN;
|
||||
extern void untyped_lhs(void) GCC_NORETURN;
|
||||
extern void untyped_rhs(int i, char *s) GCC_NORETURN;
|
||||
extern void used_reserved(char *s) GCC_NORETURN;
|
||||
|
||||
/* graph.c */
|
||||
extern void graph(void);
|
||||
|
||||
/* lalr.c */
|
||||
extern void create_symbol_table(void);
|
||||
extern void free_symbol_table(void);
|
||||
extern void free_symbols(void);
|
||||
|
||||
/* lalr.c */
|
||||
extern void lalr(void);
|
||||
|
||||
/* lr0.c */
|
||||
extern void lr0(void);
|
||||
extern void show_cores(void);
|
||||
extern void show_ritems(void);
|
||||
extern void show_rrhs(void);
|
||||
extern void show_shifts(void);
|
||||
|
||||
/* main.c */
|
||||
extern void *allocate(size_t n);
|
||||
extern void done(int k) GCC_NORETURN;
|
||||
|
||||
/* mkpar.c */
|
||||
extern void free_parser(void);
|
||||
extern void make_parser(void);
|
||||
|
||||
/* output.c */
|
||||
extern void output(void);
|
||||
|
||||
/* reader.c */
|
||||
extern void reader(void);
|
||||
|
||||
/* skeleton.c */
|
||||
extern void write_section(FILE *fp, const char *const section[]);
|
||||
|
||||
/* verbose.c */
|
||||
extern void verbose(void);
|
||||
|
||||
/* warshall.c */
|
||||
extern void reflexive_transitive_closure(unsigned *R, int n);
|
||||
|
||||
#ifdef NO_LEAKS
|
||||
extern void lr0_leaks(void);
|
||||
extern void lalr_leaks(void);
|
||||
extern void mkpar_leaks(void);
|
||||
extern void output_leaks(void);
|
||||
extern void reader_leaks(void);
|
||||
#endif
|
37
descrip.mms
Normal file
37
descrip.mms
Normal file
@ -0,0 +1,37 @@
|
||||
CFLAGS = /decc $(CC_OPTIONS)/Diagnostics /Define=(NDEBUG) /Object=$@ /Include=([])
|
||||
|
||||
LINKFLAGS = /map=$(MMS$TARGET_NAME)/cross_reference/exec=$(MMS$TARGET_NAME).exe
|
||||
|
||||
LINKER = cc
|
||||
|
||||
OBJS = closure.obj, \
|
||||
error.obj, \
|
||||
lalr.obj, \
|
||||
lr0.obj, \
|
||||
main.obj, \
|
||||
mkpar.obj, \
|
||||
output.obj, \
|
||||
reader.obj, \
|
||||
skeleton.obj, \
|
||||
symtab.obj, \
|
||||
verbose.obj, \
|
||||
warshall.obj
|
||||
|
||||
PROGRAM = yacc.exe
|
||||
|
||||
all : $(PROGRAM)
|
||||
|
||||
$(PROGRAM) : $(OBJS)
|
||||
@ write sys$output "Loading $(PROGRAM) ... "
|
||||
@ $(LINK) $(LINKFLAGS) $(OBJS)
|
||||
@ write sys$output "done"
|
||||
|
||||
clean :
|
||||
@- if f$search("*.obj") .nes. "" then delete *.obj;*
|
||||
@- if f$search("*.lis") .nes. "" then delete *.lis;*
|
||||
@- if f$search("*.log") .nes. "" then delete *.log;*
|
||||
|
||||
clobber : clean
|
||||
@- if f$search("*.exe") .nes. "" then delete *.exe;*
|
||||
|
||||
$(OBJS) : defs.h
|
288
error.c
Normal file
288
error.c
Normal file
@ -0,0 +1,288 @@
|
||||
/* $Id: error.c,v 1.9 2011/09/05 23:27:43 tom Exp $ */
|
||||
|
||||
/* routines for printing error messages */
|
||||
|
||||
#include "defs.h"
|
||||
|
||||
void
|
||||
fatal(const char *msg)
|
||||
{
|
||||
fprintf(stderr, "%s: f - %s\n", myname, msg);
|
||||
done(2);
|
||||
}
|
||||
|
||||
void
|
||||
no_space(void)
|
||||
{
|
||||
fprintf(stderr, "%s: f - out of space\n", myname);
|
||||
done(2);
|
||||
}
|
||||
|
||||
void
|
||||
open_error(const char *filename)
|
||||
{
|
||||
fprintf(stderr, "%s: f - cannot open \"%s\"\n", myname, filename);
|
||||
done(2);
|
||||
}
|
||||
|
||||
void
|
||||
missing_brace(void)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", missing '}'\n",
|
||||
myname, lineno, input_file_name);
|
||||
done(1);
|
||||
}
|
||||
|
||||
void
|
||||
unexpected_EOF(void)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", unexpected end-of-file\n",
|
||||
myname, lineno, input_file_name);
|
||||
done(1);
|
||||
}
|
||||
|
||||
static void
|
||||
print_pos(char *st_line, char *st_cptr)
|
||||
{
|
||||
char *s;
|
||||
|
||||
if (st_line == 0)
|
||||
return;
|
||||
for (s = st_line; *s != '\n'; ++s)
|
||||
{
|
||||
if (isprint(UCH(*s)) || *s == '\t')
|
||||
putc(*s, stderr);
|
||||
else
|
||||
putc('?', stderr);
|
||||
}
|
||||
putc('\n', stderr);
|
||||
for (s = st_line; s < st_cptr; ++s)
|
||||
{
|
||||
if (*s == '\t')
|
||||
putc('\t', stderr);
|
||||
else
|
||||
putc(' ', stderr);
|
||||
}
|
||||
putc('^', stderr);
|
||||
putc('\n', stderr);
|
||||
}
|
||||
|
||||
void
|
||||
syntax_error(int st_lineno, char *st_line, char *st_cptr)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", syntax error\n",
|
||||
myname, st_lineno, input_file_name);
|
||||
print_pos(st_line, st_cptr);
|
||||
done(1);
|
||||
}
|
||||
|
||||
void
|
||||
unterminated_comment(int c_lineno, char *c_line, char *c_cptr)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", unmatched /*\n",
|
||||
myname, c_lineno, input_file_name);
|
||||
print_pos(c_line, c_cptr);
|
||||
done(1);
|
||||
}
|
||||
|
||||
void
|
||||
unterminated_string(int s_lineno, char *s_line, char *s_cptr)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", unterminated string\n",
|
||||
myname, s_lineno, input_file_name);
|
||||
print_pos(s_line, s_cptr);
|
||||
done(1);
|
||||
}
|
||||
|
||||
void
|
||||
unterminated_text(int t_lineno, char *t_line, char *t_cptr)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", unmatched %%{\n",
|
||||
myname, t_lineno, input_file_name);
|
||||
print_pos(t_line, t_cptr);
|
||||
done(1);
|
||||
}
|
||||
|
||||
void
|
||||
unterminated_union(int u_lineno, char *u_line, char *u_cptr)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", unterminated %%union \
|
||||
declaration\n", myname, u_lineno, input_file_name);
|
||||
print_pos(u_line, u_cptr);
|
||||
done(1);
|
||||
}
|
||||
|
||||
void
|
||||
over_unionized(char *u_cptr)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", too many %%union \
|
||||
declarations\n", myname, lineno, input_file_name);
|
||||
print_pos(line, u_cptr);
|
||||
done(1);
|
||||
}
|
||||
|
||||
void
|
||||
illegal_tag(int t_lineno, char *t_line, char *t_cptr)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", illegal tag\n",
|
||||
myname, t_lineno, input_file_name);
|
||||
print_pos(t_line, t_cptr);
|
||||
done(1);
|
||||
}
|
||||
|
||||
void
|
||||
illegal_character(char *c_cptr)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", illegal character\n",
|
||||
myname, lineno, input_file_name);
|
||||
print_pos(line, c_cptr);
|
||||
done(1);
|
||||
}
|
||||
|
||||
void
|
||||
used_reserved(char *s)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: e - line %d of \"%s\", illegal use of reserved symbol \
|
||||
%s\n", myname, lineno, input_file_name, s);
|
||||
done(1);
|
||||
}
|
||||
|
||||
void
|
||||
tokenized_start(char *s)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: e - line %d of \"%s\", the start symbol %s cannot be \
|
||||
declared to be a token\n", myname, lineno, input_file_name, s);
|
||||
done(1);
|
||||
}
|
||||
|
||||
void
|
||||
retyped_warning(char *s)
|
||||
{
|
||||
fprintf(stderr, "%s: w - line %d of \"%s\", the type of %s has been \
|
||||
redeclared\n", myname, lineno, input_file_name, s);
|
||||
}
|
||||
|
||||
void
|
||||
reprec_warning(char *s)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: w - line %d of \"%s\", the precedence of %s has been \
|
||||
redeclared\n", myname, lineno, input_file_name, s);
|
||||
}
|
||||
|
||||
void
|
||||
revalued_warning(char *s)
|
||||
{
|
||||
fprintf(stderr, "%s: w - line %d of \"%s\", the value of %s has been \
|
||||
redeclared\n", myname, lineno, input_file_name, s);
|
||||
}
|
||||
|
||||
void
|
||||
terminal_start(char *s)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", the start symbol %s is a \
|
||||
token\n", myname, lineno, input_file_name, s);
|
||||
done(1);
|
||||
}
|
||||
|
||||
void
|
||||
restarted_warning(void)
|
||||
{
|
||||
fprintf(stderr, "%s: w - line %d of \"%s\", the start symbol has been \
|
||||
redeclared\n", myname, lineno, input_file_name);
|
||||
}
|
||||
|
||||
void
|
||||
no_grammar(void)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", no grammar has been \
|
||||
specified\n", myname, lineno, input_file_name);
|
||||
done(1);
|
||||
}
|
||||
|
||||
void
|
||||
terminal_lhs(int s_lineno)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", a token appears on the lhs \
|
||||
of a production\n", myname, s_lineno, input_file_name);
|
||||
done(1);
|
||||
}
|
||||
|
||||
void
|
||||
prec_redeclared(void)
|
||||
{
|
||||
fprintf(stderr, "%s: w - line %d of \"%s\", conflicting %%prec \
|
||||
specifiers\n", myname, lineno, input_file_name);
|
||||
}
|
||||
|
||||
void
|
||||
unterminated_action(int a_lineno, char *a_line, char *a_cptr)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", unterminated action\n",
|
||||
myname, a_lineno, input_file_name);
|
||||
print_pos(a_line, a_cptr);
|
||||
done(1);
|
||||
}
|
||||
|
||||
void
|
||||
dollar_warning(int a_lineno, int i)
|
||||
{
|
||||
fprintf(stderr, "%s: w - line %d of \"%s\", $%d references beyond the \
|
||||
end of the current rule\n", myname, a_lineno, input_file_name, i);
|
||||
}
|
||||
|
||||
void
|
||||
dollar_error(int a_lineno, char *a_line, char *a_cptr)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", illegal $-name\n",
|
||||
myname, a_lineno, input_file_name);
|
||||
print_pos(a_line, a_cptr);
|
||||
done(1);
|
||||
}
|
||||
|
||||
void
|
||||
untyped_lhs(void)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", $$ is untyped\n",
|
||||
myname, lineno, input_file_name);
|
||||
done(1);
|
||||
}
|
||||
|
||||
void
|
||||
untyped_rhs(int i, char *s)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", $%d (%s) is untyped\n",
|
||||
myname, lineno, input_file_name, i, s);
|
||||
done(1);
|
||||
}
|
||||
|
||||
void
|
||||
unknown_rhs(int i)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", $%d is untyped\n",
|
||||
myname, lineno, input_file_name, i);
|
||||
done(1);
|
||||
}
|
||||
|
||||
void
|
||||
default_action_warning(void)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"%s: w - line %d of \"%s\", the default action assigns an \
|
||||
undefined value to $$\n", myname, lineno, input_file_name);
|
||||
}
|
||||
|
||||
void
|
||||
undefined_goal(char *s)
|
||||
{
|
||||
fprintf(stderr, "%s: e - the start symbol %s is undefined\n", myname, s);
|
||||
done(1);
|
||||
}
|
||||
|
||||
void
|
||||
undefined_symbol_warning(char *s)
|
||||
{
|
||||
fprintf(stderr, "%s: w - the symbol %s is undefined\n", myname, s);
|
||||
}
|
112
graph.c
Normal file
112
graph.c
Normal file
@ -0,0 +1,112 @@
|
||||
/* $Id: graph.c,v 1.7 2009/10/27 09:25:20 tom Exp $ */
|
||||
|
||||
#include "defs.h"
|
||||
|
||||
static void graph_state(int stateno);
|
||||
static void graph_LA(int ruleno);
|
||||
|
||||
static unsigned int larno;
|
||||
|
||||
void
|
||||
graph(void)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
shifts *sp;
|
||||
int sn;
|
||||
int as;
|
||||
|
||||
if (!gflag)
|
||||
return;
|
||||
|
||||
for (i = 0; i < nstates; ++i)
|
||||
{
|
||||
closure(state_table[i]->items, state_table[i]->nitems);
|
||||
graph_state(i);
|
||||
}
|
||||
|
||||
fprintf(graph_file, "\n\n");
|
||||
for (i = 0; i < nstates; ++i)
|
||||
{
|
||||
|
||||
sp = shift_table[i];
|
||||
if (sp)
|
||||
for (j = 0; j < sp->nshifts; ++j)
|
||||
{
|
||||
sn = sp->shift[j];
|
||||
as = accessing_symbol[sn];
|
||||
fprintf(graph_file,
|
||||
"\tq%d -> q%d [label=\"%s\"];\n",
|
||||
i, sn, symbol_pname[as]);
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(graph_file, "}\n");
|
||||
|
||||
for (i = 0; i < nsyms; ++i)
|
||||
FREE(symbol_pname[i]);
|
||||
FREE(symbol_pname);
|
||||
}
|
||||
|
||||
static void
|
||||
graph_state(int stateno)
|
||||
{
|
||||
short *isp;
|
||||
int rule;
|
||||
short *sp;
|
||||
short *sp1;
|
||||
|
||||
larno = (unsigned)lookaheads[stateno];
|
||||
fprintf(graph_file, "\n\tq%d [label=\"%d:\\l", stateno, stateno);
|
||||
|
||||
for (isp = itemset; isp < itemsetend; isp++)
|
||||
{
|
||||
sp1 = sp = ritem + *isp;
|
||||
|
||||
while (*sp >= 0)
|
||||
++sp;
|
||||
rule = -(*sp);
|
||||
fprintf(graph_file, " %s -> ", symbol_pname[rlhs[rule]]);
|
||||
|
||||
for (sp = ritem + rrhs[rule]; sp < sp1; sp++)
|
||||
fprintf(graph_file, "%s ", symbol_pname[*sp]);
|
||||
|
||||
putc('.', graph_file);
|
||||
|
||||
while (*sp >= 0)
|
||||
{
|
||||
fprintf(graph_file, " %s", symbol_pname[*sp]);
|
||||
sp++;
|
||||
}
|
||||
|
||||
if (*sp1 < 0)
|
||||
graph_LA(-*sp1);
|
||||
|
||||
fprintf(graph_file, "\\l");
|
||||
}
|
||||
fprintf(graph_file, "\"];");
|
||||
}
|
||||
|
||||
static void
|
||||
graph_LA(int ruleno)
|
||||
{
|
||||
int i;
|
||||
unsigned tokensetsize;
|
||||
unsigned *rowp;
|
||||
|
||||
tokensetsize = (unsigned)WORDSIZE(ntokens);
|
||||
|
||||
if (ruleno == LAruleno[larno])
|
||||
{
|
||||
rowp = LA + larno * tokensetsize;
|
||||
|
||||
fprintf(graph_file, " { ");
|
||||
for (i = ntokens - 1; i >= 0; i--)
|
||||
{
|
||||
if (BIT(rowp, i))
|
||||
fprintf(graph_file, "%s ", symbol_pname[i]);
|
||||
}
|
||||
fprintf(graph_file, "}");
|
||||
++larno;
|
||||
}
|
||||
}
|
294
install-sh
Executable file
294
install-sh
Executable file
@ -0,0 +1,294 @@
|
||||
#! /bin/sh
|
||||
#
|
||||
# install - install a program, script, or datafile
|
||||
#
|
||||
# This originates from X11R5 (mit/util/scripts/install.sh), which was
|
||||
# later released in X11R6 (xc/config/util/install.sh) with the
|
||||
# following copyright and license.
|
||||
#
|
||||
# Copyright (C) 1994 X Consortium
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to
|
||||
# deal in the Software without restriction, including without limitation the
|
||||
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
# sell copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
|
||||
# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
#
|
||||
# Except as contained in this notice, the name of the X Consortium shall not
|
||||
# be used in advertising or otherwise to promote the sale, use or other deal-
|
||||
# ings in this Software without prior written authorization from the X Consor-
|
||||
# tium.
|
||||
#
|
||||
#
|
||||
# FSF changes to this file are in the public domain.
|
||||
#
|
||||
# Calling this script install-sh is preferred over install.sh, to prevent
|
||||
# `make' implicit rules from creating a file called install from it
|
||||
# when there is no Makefile.
|
||||
#
|
||||
# This script is compatible with the BSD install script, but was written
|
||||
# from scratch. It can only install one file at a time, a restriction
|
||||
# shared with many OS's install programs.
|
||||
|
||||
|
||||
# set DOITPROG to echo to test this script
|
||||
|
||||
# Don't use :- since 4.3BSD and earlier shells don't like it.
|
||||
doit="${DOITPROG-}"
|
||||
|
||||
|
||||
# put in absolute paths if you don't have them in your path; or use env. vars.
|
||||
|
||||
mvprog="${MVPROG-mv}"
|
||||
cpprog="${CPPROG-cp}"
|
||||
chmodprog="${CHMODPROG-chmod}"
|
||||
chownprog="${CHOWNPROG-chown}"
|
||||
chgrpprog="${CHGRPPROG-chgrp}"
|
||||
stripprog="${STRIPPROG-strip}"
|
||||
rmprog="${RMPROG-rm}"
|
||||
mkdirprog="${MKDIRPROG-mkdir}"
|
||||
|
||||
transformbasename=""
|
||||
transform_arg=""
|
||||
instcmd="$mvprog"
|
||||
chmodcmd="$chmodprog 0755"
|
||||
chowncmd=""
|
||||
chgrpcmd=""
|
||||
stripcmd=""
|
||||
rmcmd="$rmprog -f"
|
||||
mvcmd="$mvprog"
|
||||
src=""
|
||||
dst=""
|
||||
dir_arg=""
|
||||
|
||||
while [ x"$1" != x ]; do
|
||||
case $1 in
|
||||
-c) instcmd=$cpprog
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-d) dir_arg=true
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-m) chmodcmd="$chmodprog $2"
|
||||
shift
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-o) chowncmd="$chownprog $2"
|
||||
shift
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-g) chgrpcmd="$chgrpprog $2"
|
||||
shift
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-s) stripcmd=$stripprog
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-t=*) transformarg=`echo $1 | sed 's/-t=//'`
|
||||
shift
|
||||
continue;;
|
||||
|
||||
-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
|
||||
shift
|
||||
continue;;
|
||||
|
||||
*) if [ x"$src" = x ]
|
||||
then
|
||||
src=$1
|
||||
else
|
||||
# this colon is to work around a 386BSD /bin/sh bug
|
||||
:
|
||||
dst=$1
|
||||
fi
|
||||
shift
|
||||
continue;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ x"$src" = x ]
|
||||
then
|
||||
echo "$0: no input file specified" >&2
|
||||
exit 1
|
||||
else
|
||||
:
|
||||
fi
|
||||
|
||||
if [ x"$dir_arg" != x ]; then
|
||||
dst=$src
|
||||
src=""
|
||||
|
||||
if [ -d "$dst" ]; then
|
||||
instcmd=:
|
||||
chmodcmd=""
|
||||
else
|
||||
instcmd=$mkdirprog
|
||||
fi
|
||||
else
|
||||
|
||||
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
|
||||
# might cause directories to be created, which would be especially bad
|
||||
# if $src (and thus $dsttmp) contains '*'.
|
||||
|
||||
if [ -f "$src" ] || [ -d "$src" ]
|
||||
then
|
||||
:
|
||||
else
|
||||
echo "$0: $src does not exist" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ x"$dst" = x ]
|
||||
then
|
||||
echo "$0: no destination specified" >&2
|
||||
exit 1
|
||||
else
|
||||
:
|
||||
fi
|
||||
|
||||
# If destination is a directory, append the input filename; if your system
|
||||
# does not like double slashes in filenames, you may need to add some logic
|
||||
|
||||
if [ -d "$dst" ]
|
||||
then
|
||||
dst=$dst/`basename "$src"`
|
||||
else
|
||||
:
|
||||
fi
|
||||
fi
|
||||
|
||||
## this sed command emulates the dirname command
|
||||
dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
|
||||
|
||||
# Make sure that the destination directory exists.
|
||||
# this part is taken from Noah Friedman's mkinstalldirs script
|
||||
|
||||
# Skip lots of stat calls in the usual case.
|
||||
if [ ! -d "$dstdir" ]; then
|
||||
defaultIFS='
|
||||
'
|
||||
IFS="${IFS-$defaultIFS}"
|
||||
|
||||
oIFS=$IFS
|
||||
# Some sh's can't handle IFS=/ for some reason.
|
||||
IFS='%'
|
||||
set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
|
||||
IFS=$oIFS
|
||||
|
||||
pathcomp=''
|
||||
|
||||
while [ $# -ne 0 ] ; do
|
||||
pathcomp=$pathcomp$1
|
||||
shift
|
||||
|
||||
if [ ! -d "$pathcomp" ] ;
|
||||
then
|
||||
$mkdirprog "$pathcomp"
|
||||
else
|
||||
:
|
||||
fi
|
||||
|
||||
pathcomp=$pathcomp/
|
||||
done
|
||||
fi
|
||||
|
||||
if [ x"$dir_arg" != x ]
|
||||
then
|
||||
$doit $instcmd "$dst" &&
|
||||
|
||||
if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dst"; else : ; fi &&
|
||||
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dst"; else : ; fi &&
|
||||
if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dst"; else : ; fi &&
|
||||
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dst"; else : ; fi
|
||||
else
|
||||
|
||||
# If we're going to rename the final executable, determine the name now.
|
||||
|
||||
if [ x"$transformarg" = x ]
|
||||
then
|
||||
dstfile=`basename "$dst"`
|
||||
else
|
||||
dstfile=`basename "$dst" $transformbasename |
|
||||
sed $transformarg`$transformbasename
|
||||
fi
|
||||
|
||||
# don't allow the sed command to completely eliminate the filename
|
||||
|
||||
if [ x"$dstfile" = x ]
|
||||
then
|
||||
dstfile=`basename "$dst"`
|
||||
else
|
||||
:
|
||||
fi
|
||||
|
||||
# Make a couple of temp file names in the proper directory.
|
||||
|
||||
dsttmp=$dstdir/#inst.$$#
|
||||
rmtmp=$dstdir/#rm.$$#
|
||||
|
||||
# Trap to clean up temp files at exit.
|
||||
|
||||
trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0
|
||||
trap '(exit $?); exit' 1 2 13 15
|
||||
|
||||
# Move or copy the file name to the temp name
|
||||
|
||||
$doit $instcmd "$src" "$dsttmp" &&
|
||||
|
||||
# and set any options; do chmod last to preserve setuid bits
|
||||
|
||||
# If any of these fail, we abort the whole thing. If we want to
|
||||
# ignore errors from any of these, just make sure not to ignore
|
||||
# errors from the above "$doit $instcmd $src $dsttmp" command.
|
||||
|
||||
if [ x"$chowncmd" != x ]; then $doit $chowncmd "$dsttmp"; else :;fi &&
|
||||
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd "$dsttmp"; else :;fi &&
|
||||
if [ x"$stripcmd" != x ]; then $doit $stripcmd "$dsttmp"; else :;fi &&
|
||||
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd "$dsttmp"; else :;fi &&
|
||||
|
||||
# Now remove or move aside any old file at destination location. We try this
|
||||
# two ways since rm can't unlink itself on some systems and the destination
|
||||
# file might be busy for other reasons. In this case, the final cleanup
|
||||
# might fail but the new file should still install successfully.
|
||||
|
||||
{
|
||||
if [ -f "$dstdir/$dstfile" ]
|
||||
then
|
||||
$doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null ||
|
||||
$doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null ||
|
||||
{
|
||||
echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
|
||||
(exit 1); exit
|
||||
}
|
||||
else
|
||||
:
|
||||
fi
|
||||
} &&
|
||||
|
||||
# Now rename the file to the real destination.
|
||||
|
||||
$doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
|
||||
|
||||
fi &&
|
||||
|
||||
# The final little trick to "correctly" pass the exit status to the exit trap.
|
||||
|
||||
{
|
||||
(exit 0); exit
|
||||
}
|
655
lalr.c
Normal file
655
lalr.c
Normal file
@ -0,0 +1,655 @@
|
||||
/* $Id: lalr.c,v 1.9 2009/10/27 09:49:27 tom Exp $ */
|
||||
|
||||
#include "defs.h"
|
||||
|
||||
typedef struct shorts
|
||||
{
|
||||
struct shorts *next;
|
||||
Value_t value;
|
||||
}
|
||||
shorts;
|
||||
|
||||
static Value_t map_goto(int state, int symbol);
|
||||
static Value_t **transpose(Value_t ** R, int n);
|
||||
static void add_lookback_edge(int stateno, int ruleno, int gotono);
|
||||
static void build_relations(void);
|
||||
static void compute_FOLLOWS(void);
|
||||
static void compute_lookaheads(void);
|
||||
static void digraph(Value_t ** relation);
|
||||
static void initialize_F(void);
|
||||
static void initialize_LA(void);
|
||||
static void set_accessing_symbol(void);
|
||||
static void set_goto_map(void);
|
||||
static void set_maxrhs(void);
|
||||
static void set_reduction_table(void);
|
||||
static void set_shift_table(void);
|
||||
static void set_state_table(void);
|
||||
static void traverse(int i);
|
||||
|
||||
static int tokensetsize;
|
||||
Value_t *lookaheads;
|
||||
Value_t *LAruleno;
|
||||
unsigned *LA;
|
||||
Value_t *accessing_symbol;
|
||||
core **state_table;
|
||||
shifts **shift_table;
|
||||
reductions **reduction_table;
|
||||
Value_t *goto_map;
|
||||
Value_t *from_state;
|
||||
Value_t *to_state;
|
||||
|
||||
static Value_t infinity;
|
||||
static int maxrhs;
|
||||
static int ngotos;
|
||||
static unsigned *F;
|
||||
static Value_t **includes;
|
||||
static shorts **lookback;
|
||||
static Value_t **R;
|
||||
static Value_t *INDEX;
|
||||
static Value_t *VERTICES;
|
||||
static Value_t top;
|
||||
|
||||
void
|
||||
lalr(void)
|
||||
{
|
||||
tokensetsize = WORDSIZE(ntokens);
|
||||
|
||||
set_state_table();
|
||||
set_accessing_symbol();
|
||||
set_shift_table();
|
||||
set_reduction_table();
|
||||
set_maxrhs();
|
||||
initialize_LA();
|
||||
set_goto_map();
|
||||
initialize_F();
|
||||
build_relations();
|
||||
compute_FOLLOWS();
|
||||
compute_lookaheads();
|
||||
}
|
||||
|
||||
static void
|
||||
set_state_table(void)
|
||||
{
|
||||
core *sp;
|
||||
|
||||
state_table = NEW2(nstates, core *);
|
||||
for (sp = first_state; sp; sp = sp->next)
|
||||
state_table[sp->number] = sp;
|
||||
}
|
||||
|
||||
static void
|
||||
set_accessing_symbol(void)
|
||||
{
|
||||
core *sp;
|
||||
|
||||
accessing_symbol = NEW2(nstates, Value_t);
|
||||
for (sp = first_state; sp; sp = sp->next)
|
||||
accessing_symbol[sp->number] = sp->accessing_symbol;
|
||||
}
|
||||
|
||||
static void
|
||||
set_shift_table(void)
|
||||
{
|
||||
shifts *sp;
|
||||
|
||||
shift_table = NEW2(nstates, shifts *);
|
||||
for (sp = first_shift; sp; sp = sp->next)
|
||||
shift_table[sp->number] = sp;
|
||||
}
|
||||
|
||||
static void
|
||||
set_reduction_table(void)
|
||||
{
|
||||
reductions *rp;
|
||||
|
||||
reduction_table = NEW2(nstates, reductions *);
|
||||
for (rp = first_reduction; rp; rp = rp->next)
|
||||
reduction_table[rp->number] = rp;
|
||||
}
|
||||
|
||||
static void
|
||||
set_maxrhs(void)
|
||||
{
|
||||
Value_t *itemp;
|
||||
Value_t *item_end;
|
||||
int length;
|
||||
int max;
|
||||
|
||||
length = 0;
|
||||
max = 0;
|
||||
item_end = ritem + nitems;
|
||||
for (itemp = ritem; itemp < item_end; itemp++)
|
||||
{
|
||||
if (*itemp >= 0)
|
||||
{
|
||||
length++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (length > max)
|
||||
max = length;
|
||||
length = 0;
|
||||
}
|
||||
}
|
||||
|
||||
maxrhs = max;
|
||||
}
|
||||
|
||||
static void
|
||||
initialize_LA(void)
|
||||
{
|
||||
int i, j, k;
|
||||
reductions *rp;
|
||||
|
||||
lookaheads = NEW2(nstates + 1, Value_t);
|
||||
|
||||
k = 0;
|
||||
for (i = 0; i < nstates; i++)
|
||||
{
|
||||
lookaheads[i] = (Value_t) k;
|
||||
rp = reduction_table[i];
|
||||
if (rp)
|
||||
k += rp->nreds;
|
||||
}
|
||||
lookaheads[nstates] = (Value_t) k;
|
||||
|
||||
LA = NEW2(k * tokensetsize, unsigned);
|
||||
LAruleno = NEW2(k, Value_t);
|
||||
lookback = NEW2(k, shorts *);
|
||||
|
||||
k = 0;
|
||||
for (i = 0; i < nstates; i++)
|
||||
{
|
||||
rp = reduction_table[i];
|
||||
if (rp)
|
||||
{
|
||||
for (j = 0; j < rp->nreds; j++)
|
||||
{
|
||||
LAruleno[k] = rp->rules[j];
|
||||
k++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
set_goto_map(void)
|
||||
{
|
||||
shifts *sp;
|
||||
int i;
|
||||
int symbol;
|
||||
int k;
|
||||
Value_t *temp_map;
|
||||
Value_t state2;
|
||||
Value_t state1;
|
||||
|
||||
goto_map = NEW2(nvars + 1, Value_t) - ntokens;
|
||||
temp_map = NEW2(nvars + 1, Value_t) - ntokens;
|
||||
|
||||
ngotos = 0;
|
||||
for (sp = first_shift; sp; sp = sp->next)
|
||||
{
|
||||
for (i = sp->nshifts - 1; i >= 0; i--)
|
||||
{
|
||||
symbol = accessing_symbol[sp->shift[i]];
|
||||
|
||||
if (ISTOKEN(symbol))
|
||||
break;
|
||||
|
||||
if (ngotos == MAXSHORT)
|
||||
fatal("too many gotos");
|
||||
|
||||
ngotos++;
|
||||
goto_map[symbol]++;
|
||||
}
|
||||
}
|
||||
|
||||
k = 0;
|
||||
for (i = ntokens; i < nsyms; i++)
|
||||
{
|
||||
temp_map[i] = (Value_t) k;
|
||||
k += goto_map[i];
|
||||
}
|
||||
|
||||
for (i = ntokens; i < nsyms; i++)
|
||||
goto_map[i] = temp_map[i];
|
||||
|
||||
goto_map[nsyms] = (Value_t) ngotos;
|
||||
temp_map[nsyms] = (Value_t) ngotos;
|
||||
|
||||
from_state = NEW2(ngotos, Value_t);
|
||||
to_state = NEW2(ngotos, Value_t);
|
||||
|
||||
for (sp = first_shift; sp; sp = sp->next)
|
||||
{
|
||||
state1 = sp->number;
|
||||
for (i = sp->nshifts - 1; i >= 0; i--)
|
||||
{
|
||||
state2 = sp->shift[i];
|
||||
symbol = accessing_symbol[state2];
|
||||
|
||||
if (ISTOKEN(symbol))
|
||||
break;
|
||||
|
||||
k = temp_map[symbol]++;
|
||||
from_state[k] = state1;
|
||||
to_state[k] = state2;
|
||||
}
|
||||
}
|
||||
|
||||
FREE(temp_map + ntokens);
|
||||
}
|
||||
|
||||
/* Map_goto maps a state/symbol pair into its numeric representation. */
|
||||
|
||||
static Value_t
|
||||
map_goto(int state, int symbol)
|
||||
{
|
||||
int high;
|
||||
int low;
|
||||
int middle;
|
||||
int s;
|
||||
|
||||
low = goto_map[symbol];
|
||||
high = goto_map[symbol + 1];
|
||||
|
||||
for (;;)
|
||||
{
|
||||
assert(low <= high);
|
||||
middle = (low + high) >> 1;
|
||||
s = from_state[middle];
|
||||
if (s == state)
|
||||
return (Value_t) (middle);
|
||||
else if (s < state)
|
||||
low = middle + 1;
|
||||
else
|
||||
high = middle - 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
initialize_F(void)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
shifts *sp;
|
||||
Value_t *edge;
|
||||
unsigned *rowp;
|
||||
Value_t *rp;
|
||||
Value_t **reads;
|
||||
int nedges;
|
||||
int stateno;
|
||||
int symbol;
|
||||
int nwords;
|
||||
|
||||
nwords = ngotos * tokensetsize;
|
||||
F = NEW2(nwords, unsigned);
|
||||
|
||||
reads = NEW2(ngotos, Value_t *);
|
||||
edge = NEW2(ngotos + 1, Value_t);
|
||||
nedges = 0;
|
||||
|
||||
rowp = F;
|
||||
for (i = 0; i < ngotos; i++)
|
||||
{
|
||||
stateno = to_state[i];
|
||||
sp = shift_table[stateno];
|
||||
|
||||
if (sp)
|
||||
{
|
||||
k = sp->nshifts;
|
||||
|
||||
for (j = 0; j < k; j++)
|
||||
{
|
||||
symbol = accessing_symbol[sp->shift[j]];
|
||||
if (ISVAR(symbol))
|
||||
break;
|
||||
SETBIT(rowp, symbol);
|
||||
}
|
||||
|
||||
for (; j < k; j++)
|
||||
{
|
||||
symbol = accessing_symbol[sp->shift[j]];
|
||||
if (nullable[symbol])
|
||||
edge[nedges++] = map_goto(stateno, symbol);
|
||||
}
|
||||
|
||||
if (nedges)
|
||||
{
|
||||
reads[i] = rp = NEW2(nedges + 1, Value_t);
|
||||
|
||||
for (j = 0; j < nedges; j++)
|
||||
rp[j] = edge[j];
|
||||
|
||||
rp[nedges] = -1;
|
||||
nedges = 0;
|
||||
}
|
||||
}
|
||||
|
||||
rowp += tokensetsize;
|
||||
}
|
||||
|
||||
SETBIT(F, 0);
|
||||
digraph(reads);
|
||||
|
||||
for (i = 0; i < ngotos; i++)
|
||||
{
|
||||
if (reads[i])
|
||||
FREE(reads[i]);
|
||||
}
|
||||
|
||||
FREE(reads);
|
||||
FREE(edge);
|
||||
}
|
||||
|
||||
static void
|
||||
build_relations(void)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
Value_t *rulep;
|
||||
Value_t *rp;
|
||||
shifts *sp;
|
||||
int length;
|
||||
int nedges;
|
||||
int done_flag;
|
||||
Value_t state1;
|
||||
Value_t stateno;
|
||||
int symbol1;
|
||||
int symbol2;
|
||||
Value_t *shortp;
|
||||
Value_t *edge;
|
||||
Value_t *states;
|
||||
Value_t **new_includes;
|
||||
|
||||
includes = NEW2(ngotos, Value_t *);
|
||||
edge = NEW2(ngotos + 1, Value_t);
|
||||
states = NEW2(maxrhs + 1, Value_t);
|
||||
|
||||
for (i = 0; i < ngotos; i++)
|
||||
{
|
||||
nedges = 0;
|
||||
state1 = from_state[i];
|
||||
symbol1 = accessing_symbol[to_state[i]];
|
||||
|
||||
for (rulep = derives[symbol1]; *rulep >= 0; rulep++)
|
||||
{
|
||||
length = 1;
|
||||
states[0] = state1;
|
||||
stateno = state1;
|
||||
|
||||
for (rp = ritem + rrhs[*rulep]; *rp >= 0; rp++)
|
||||
{
|
||||
symbol2 = *rp;
|
||||
sp = shift_table[stateno];
|
||||
k = sp->nshifts;
|
||||
|
||||
for (j = 0; j < k; j++)
|
||||
{
|
||||
stateno = sp->shift[j];
|
||||
if (accessing_symbol[stateno] == symbol2)
|
||||
break;
|
||||
}
|
||||
|
||||
states[length++] = stateno;
|
||||
}
|
||||
|
||||
add_lookback_edge(stateno, *rulep, i);
|
||||
|
||||
length--;
|
||||
done_flag = 0;
|
||||
while (!done_flag)
|
||||
{
|
||||
done_flag = 1;
|
||||
rp--;
|
||||
if (ISVAR(*rp))
|
||||
{
|
||||
stateno = states[--length];
|
||||
edge[nedges++] = map_goto(stateno, *rp);
|
||||
if (nullable[*rp] && length > 0)
|
||||
done_flag = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (nedges)
|
||||
{
|
||||
includes[i] = shortp = NEW2(nedges + 1, Value_t);
|
||||
for (j = 0; j < nedges; j++)
|
||||
shortp[j] = edge[j];
|
||||
shortp[nedges] = -1;
|
||||
}
|
||||
}
|
||||
|
||||
new_includes = transpose(includes, ngotos);
|
||||
|
||||
for (i = 0; i < ngotos; i++)
|
||||
if (includes[i])
|
||||
FREE(includes[i]);
|
||||
|
||||
FREE(includes);
|
||||
|
||||
includes = new_includes;
|
||||
|
||||
FREE(edge);
|
||||
FREE(states);
|
||||
}
|
||||
|
||||
static void
|
||||
add_lookback_edge(int stateno, int ruleno, int gotono)
|
||||
{
|
||||
int i, k;
|
||||
int found;
|
||||
shorts *sp;
|
||||
|
||||
i = lookaheads[stateno];
|
||||
k = lookaheads[stateno + 1];
|
||||
found = 0;
|
||||
while (!found && i < k)
|
||||
{
|
||||
if (LAruleno[i] == ruleno)
|
||||
found = 1;
|
||||
else
|
||||
++i;
|
||||
}
|
||||
assert(found);
|
||||
|
||||
sp = NEW(shorts);
|
||||
sp->next = lookback[i];
|
||||
sp->value = (Value_t) gotono;
|
||||
lookback[i] = sp;
|
||||
}
|
||||
|
||||
static Value_t **
|
||||
transpose(Value_t ** R2, int n)
|
||||
{
|
||||
Value_t **new_R;
|
||||
Value_t **temp_R;
|
||||
Value_t *nedges;
|
||||
Value_t *sp;
|
||||
int i;
|
||||
int k;
|
||||
|
||||
nedges = NEW2(n, Value_t);
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
sp = R2[i];
|
||||
if (sp)
|
||||
{
|
||||
while (*sp >= 0)
|
||||
nedges[*sp++]++;
|
||||
}
|
||||
}
|
||||
|
||||
new_R = NEW2(n, Value_t *);
|
||||
temp_R = NEW2(n, Value_t *);
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
k = nedges[i];
|
||||
if (k > 0)
|
||||
{
|
||||
sp = NEW2(k + 1, Value_t);
|
||||
new_R[i] = sp;
|
||||
temp_R[i] = sp;
|
||||
sp[k] = -1;
|
||||
}
|
||||
}
|
||||
|
||||
FREE(nedges);
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
sp = R2[i];
|
||||
if (sp)
|
||||
{
|
||||
while (*sp >= 0)
|
||||
*temp_R[*sp++]++ = (Value_t) i;
|
||||
}
|
||||
}
|
||||
|
||||
FREE(temp_R);
|
||||
|
||||
return (new_R);
|
||||
}
|
||||
|
||||
static void
|
||||
compute_FOLLOWS(void)
|
||||
{
|
||||
digraph(includes);
|
||||
}
|
||||
|
||||
static void
|
||||
compute_lookaheads(void)
|
||||
{
|
||||
int i, n;
|
||||
unsigned *fp1, *fp2, *fp3;
|
||||
shorts *sp, *next;
|
||||
unsigned *rowp;
|
||||
|
||||
rowp = LA;
|
||||
n = lookaheads[nstates];
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
fp3 = rowp + tokensetsize;
|
||||
for (sp = lookback[i]; sp; sp = sp->next)
|
||||
{
|
||||
fp1 = rowp;
|
||||
fp2 = F + tokensetsize * sp->value;
|
||||
while (fp1 < fp3)
|
||||
*fp1++ |= *fp2++;
|
||||
}
|
||||
rowp = fp3;
|
||||
}
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
for (sp = lookback[i]; sp; sp = next)
|
||||
{
|
||||
next = sp->next;
|
||||
FREE(sp);
|
||||
}
|
||||
|
||||
FREE(lookback);
|
||||
FREE(F);
|
||||
}
|
||||
|
||||
static void
|
||||
digraph(Value_t ** relation)
|
||||
{
|
||||
int i;
|
||||
|
||||
infinity = (Value_t) (ngotos + 2);
|
||||
INDEX = NEW2(ngotos + 1, Value_t);
|
||||
VERTICES = NEW2(ngotos + 1, Value_t);
|
||||
top = 0;
|
||||
|
||||
R = relation;
|
||||
|
||||
for (i = 0; i < ngotos; i++)
|
||||
INDEX[i] = 0;
|
||||
|
||||
for (i = 0; i < ngotos; i++)
|
||||
{
|
||||
if (INDEX[i] == 0 && R[i])
|
||||
traverse(i);
|
||||
}
|
||||
|
||||
FREE(INDEX);
|
||||
FREE(VERTICES);
|
||||
}
|
||||
|
||||
static void
|
||||
traverse(int i)
|
||||
{
|
||||
unsigned *fp1;
|
||||
unsigned *fp2;
|
||||
unsigned *fp3;
|
||||
int j;
|
||||
Value_t *rp;
|
||||
|
||||
Value_t height;
|
||||
unsigned *base;
|
||||
|
||||
VERTICES[++top] = (Value_t) i;
|
||||
INDEX[i] = height = top;
|
||||
|
||||
base = F + i * tokensetsize;
|
||||
fp3 = base + tokensetsize;
|
||||
|
||||
rp = R[i];
|
||||
if (rp)
|
||||
{
|
||||
while ((j = *rp++) >= 0)
|
||||
{
|
||||
if (INDEX[j] == 0)
|
||||
traverse(j);
|
||||
|
||||
if (INDEX[i] > INDEX[j])
|
||||
INDEX[i] = INDEX[j];
|
||||
|
||||
fp1 = base;
|
||||
fp2 = F + j * tokensetsize;
|
||||
|
||||
while (fp1 < fp3)
|
||||
*fp1++ |= *fp2++;
|
||||
}
|
||||
}
|
||||
|
||||
if (INDEX[i] == height)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
j = VERTICES[top--];
|
||||
INDEX[j] = infinity;
|
||||
|
||||
if (i == j)
|
||||
break;
|
||||
|
||||
fp1 = base;
|
||||
fp2 = F + j * tokensetsize;
|
||||
|
||||
while (fp1 < fp3)
|
||||
*fp2++ = *fp1++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef NO_LEAKS
|
||||
void
|
||||
lalr_leaks(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (includes != 0)
|
||||
{
|
||||
for (i = 0; i < ngotos; i++)
|
||||
{
|
||||
free(includes[i]);
|
||||
}
|
||||
DO_FREE(includes);
|
||||
}
|
||||
}
|
||||
#endif
|
599
lr0.c
Normal file
599
lr0.c
Normal file
@ -0,0 +1,599 @@
|
||||
/* $Id: lr0.c,v 1.12 2010/06/09 08:53:17 tom Exp $ */
|
||||
|
||||
#include "defs.h"
|
||||
|
||||
static core *new_state(int symbol);
|
||||
static Value_t get_state(int symbol);
|
||||
static void allocate_itemsets(void);
|
||||
static void allocate_storage(void);
|
||||
static void append_states(void);
|
||||
static void free_storage(void);
|
||||
static void generate_states(void);
|
||||
static void initialize_states(void);
|
||||
static void new_itemsets(void);
|
||||
static void save_reductions(void);
|
||||
static void save_shifts(void);
|
||||
static void set_derives(void);
|
||||
static void set_nullable(void);
|
||||
|
||||
int nstates;
|
||||
core *first_state;
|
||||
shifts *first_shift;
|
||||
reductions *first_reduction;
|
||||
|
||||
static core **state_set;
|
||||
static core *this_state;
|
||||
static core *last_state;
|
||||
static shifts *last_shift;
|
||||
static reductions *last_reduction;
|
||||
|
||||
static int nshifts;
|
||||
static short *shift_symbol;
|
||||
|
||||
static Value_t *redset;
|
||||
static Value_t *shiftset;
|
||||
|
||||
static Value_t **kernel_base;
|
||||
static Value_t **kernel_end;
|
||||
static Value_t *kernel_items;
|
||||
|
||||
static void
|
||||
allocate_itemsets(void)
|
||||
{
|
||||
short *itemp;
|
||||
short *item_end;
|
||||
int symbol;
|
||||
int i;
|
||||
int count;
|
||||
int max;
|
||||
short *symbol_count;
|
||||
|
||||
count = 0;
|
||||
symbol_count = NEW2(nsyms, short);
|
||||
|
||||
item_end = ritem + nitems;
|
||||
for (itemp = ritem; itemp < item_end; itemp++)
|
||||
{
|
||||
symbol = *itemp;
|
||||
if (symbol >= 0)
|
||||
{
|
||||
count++;
|
||||
symbol_count[symbol]++;
|
||||
}
|
||||
}
|
||||
|
||||
kernel_base = NEW2(nsyms, short *);
|
||||
kernel_items = NEW2(count, short);
|
||||
|
||||
count = 0;
|
||||
max = 0;
|
||||
for (i = 0; i < nsyms; i++)
|
||||
{
|
||||
kernel_base[i] = kernel_items + count;
|
||||
count += symbol_count[i];
|
||||
if (max < symbol_count[i])
|
||||
max = symbol_count[i];
|
||||
}
|
||||
|
||||
shift_symbol = symbol_count;
|
||||
kernel_end = NEW2(nsyms, short *);
|
||||
}
|
||||
|
||||
static void
|
||||
allocate_storage(void)
|
||||
{
|
||||
allocate_itemsets();
|
||||
shiftset = NEW2(nsyms, short);
|
||||
redset = NEW2(nrules + 1, short);
|
||||
state_set = NEW2(nitems, core *);
|
||||
}
|
||||
|
||||
static void
|
||||
append_states(void)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
Value_t symbol;
|
||||
|
||||
#ifdef TRACE
|
||||
fprintf(stderr, "Entering append_states()\n");
|
||||
#endif
|
||||
for (i = 1; i < nshifts; i++)
|
||||
{
|
||||
symbol = shift_symbol[i];
|
||||
j = i;
|
||||
while (j > 0 && shift_symbol[j - 1] > symbol)
|
||||
{
|
||||
shift_symbol[j] = shift_symbol[j - 1];
|
||||
j--;
|
||||
}
|
||||
shift_symbol[j] = symbol;
|
||||
}
|
||||
|
||||
for (i = 0; i < nshifts; i++)
|
||||
{
|
||||
symbol = shift_symbol[i];
|
||||
shiftset[i] = get_state(symbol);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
free_storage(void)
|
||||
{
|
||||
FREE(shift_symbol);
|
||||
FREE(redset);
|
||||
FREE(shiftset);
|
||||
FREE(kernel_base);
|
||||
FREE(kernel_end);
|
||||
FREE(kernel_items);
|
||||
FREE(state_set);
|
||||
}
|
||||
|
||||
static void
|
||||
generate_states(void)
|
||||
{
|
||||
allocate_storage();
|
||||
itemset = NEW2(nitems, short);
|
||||
ruleset = NEW2(WORDSIZE(nrules), unsigned);
|
||||
set_first_derives();
|
||||
initialize_states();
|
||||
|
||||
while (this_state)
|
||||
{
|
||||
closure(this_state->items, this_state->nitems);
|
||||
save_reductions();
|
||||
new_itemsets();
|
||||
append_states();
|
||||
|
||||
if (nshifts > 0)
|
||||
save_shifts();
|
||||
|
||||
this_state = this_state->next;
|
||||
}
|
||||
|
||||
free_storage();
|
||||
}
|
||||
|
||||
static Value_t
|
||||
get_state(int symbol)
|
||||
{
|
||||
int key;
|
||||
short *isp1;
|
||||
short *isp2;
|
||||
short *iend;
|
||||
core *sp;
|
||||
int found;
|
||||
int n;
|
||||
|
||||
#ifdef TRACE
|
||||
fprintf(stderr, "Entering get_state(%d)\n", symbol);
|
||||
#endif
|
||||
|
||||
isp1 = kernel_base[symbol];
|
||||
iend = kernel_end[symbol];
|
||||
n = (int)(iend - isp1);
|
||||
|
||||
key = *isp1;
|
||||
assert(0 <= key && key < nitems);
|
||||
sp = state_set[key];
|
||||
if (sp)
|
||||
{
|
||||
found = 0;
|
||||
while (!found)
|
||||
{
|
||||
if (sp->nitems == n)
|
||||
{
|
||||
found = 1;
|
||||
isp1 = kernel_base[symbol];
|
||||
isp2 = sp->items;
|
||||
|
||||
while (found && isp1 < iend)
|
||||
{
|
||||
if (*isp1++ != *isp2++)
|
||||
found = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
if (sp->link)
|
||||
{
|
||||
sp = sp->link;
|
||||
}
|
||||
else
|
||||
{
|
||||
sp = sp->link = new_state(symbol);
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
state_set[key] = sp = new_state(symbol);
|
||||
}
|
||||
|
||||
return (sp->number);
|
||||
}
|
||||
|
||||
static void
|
||||
initialize_states(void)
|
||||
{
|
||||
unsigned i;
|
||||
short *start_derives;
|
||||
core *p;
|
||||
|
||||
start_derives = derives[start_symbol];
|
||||
for (i = 0; start_derives[i] >= 0; ++i)
|
||||
continue;
|
||||
|
||||
p = (core *)MALLOC(sizeof(core) + i * sizeof(short));
|
||||
NO_SPACE(p);
|
||||
|
||||
p->next = 0;
|
||||
p->link = 0;
|
||||
p->number = 0;
|
||||
p->accessing_symbol = 0;
|
||||
p->nitems = (Value_t) i;
|
||||
|
||||
for (i = 0; start_derives[i] >= 0; ++i)
|
||||
p->items[i] = rrhs[start_derives[i]];
|
||||
|
||||
first_state = last_state = this_state = p;
|
||||
nstates = 1;
|
||||
}
|
||||
|
||||
static void
|
||||
new_itemsets(void)
|
||||
{
|
||||
Value_t i;
|
||||
int shiftcount;
|
||||
short *isp;
|
||||
short *ksp;
|
||||
Value_t symbol;
|
||||
|
||||
for (i = 0; i < nsyms; i++)
|
||||
kernel_end[i] = 0;
|
||||
|
||||
shiftcount = 0;
|
||||
isp = itemset;
|
||||
while (isp < itemsetend)
|
||||
{
|
||||
i = *isp++;
|
||||
symbol = ritem[i];
|
||||
if (symbol > 0)
|
||||
{
|
||||
ksp = kernel_end[symbol];
|
||||
if (!ksp)
|
||||
{
|
||||
shift_symbol[shiftcount++] = symbol;
|
||||
ksp = kernel_base[symbol];
|
||||
}
|
||||
|
||||
*ksp++ = (Value_t) (i + 1);
|
||||
kernel_end[symbol] = ksp;
|
||||
}
|
||||
}
|
||||
|
||||
nshifts = shiftcount;
|
||||
}
|
||||
|
||||
static core *
|
||||
new_state(int symbol)
|
||||
{
|
||||
unsigned n;
|
||||
core *p;
|
||||
short *isp1;
|
||||
short *isp2;
|
||||
short *iend;
|
||||
|
||||
#ifdef TRACE
|
||||
fprintf(stderr, "Entering new_state(%d)\n", symbol);
|
||||
#endif
|
||||
|
||||
if (nstates >= MAXSHORT)
|
||||
fatal("too many states");
|
||||
|
||||
isp1 = kernel_base[symbol];
|
||||
iend = kernel_end[symbol];
|
||||
n = (unsigned)(iend - isp1);
|
||||
|
||||
p = (core *)allocate((sizeof(core) + (n - 1) * sizeof(short)));
|
||||
p->accessing_symbol = (Value_t) symbol;
|
||||
p->number = (Value_t) nstates;
|
||||
p->nitems = (Value_t) n;
|
||||
|
||||
isp2 = p->items;
|
||||
while (isp1 < iend)
|
||||
*isp2++ = *isp1++;
|
||||
|
||||
last_state->next = p;
|
||||
last_state = p;
|
||||
|
||||
nstates++;
|
||||
|
||||
return (p);
|
||||
}
|
||||
|
||||
/* show_cores is used for debugging */
|
||||
|
||||
void
|
||||
show_cores(void)
|
||||
{
|
||||
core *p;
|
||||
int i, j, k, n;
|
||||
int itemno;
|
||||
|
||||
k = 0;
|
||||
for (p = first_state; p; ++k, p = p->next)
|
||||
{
|
||||
if (k)
|
||||
printf("\n");
|
||||
printf("state %d, number = %d, accessing symbol = %s\n",
|
||||
k, p->number, symbol_name[p->accessing_symbol]);
|
||||
n = p->nitems;
|
||||
for (i = 0; i < n; ++i)
|
||||
{
|
||||
itemno = p->items[i];
|
||||
printf("%4d ", itemno);
|
||||
j = itemno;
|
||||
while (ritem[j] >= 0)
|
||||
++j;
|
||||
printf("%s :", symbol_name[rlhs[-ritem[j]]]);
|
||||
j = rrhs[-ritem[j]];
|
||||
while (j < itemno)
|
||||
printf(" %s", symbol_name[ritem[j++]]);
|
||||
printf(" .");
|
||||
while (ritem[j] >= 0)
|
||||
printf(" %s", symbol_name[ritem[j++]]);
|
||||
printf("\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* show_ritems is used for debugging */
|
||||
|
||||
void
|
||||
show_ritems(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nitems; ++i)
|
||||
printf("ritem[%d] = %d\n", i, ritem[i]);
|
||||
}
|
||||
|
||||
/* show_rrhs is used for debugging */
|
||||
void
|
||||
show_rrhs(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nrules; ++i)
|
||||
printf("rrhs[%d] = %d\n", i, rrhs[i]);
|
||||
}
|
||||
|
||||
/* show_shifts is used for debugging */
|
||||
|
||||
void
|
||||
show_shifts(void)
|
||||
{
|
||||
shifts *p;
|
||||
int i, j, k;
|
||||
|
||||
k = 0;
|
||||
for (p = first_shift; p; ++k, p = p->next)
|
||||
{
|
||||
if (k)
|
||||
printf("\n");
|
||||
printf("shift %d, number = %d, nshifts = %d\n", k, p->number,
|
||||
p->nshifts);
|
||||
j = p->nshifts;
|
||||
for (i = 0; i < j; ++i)
|
||||
printf("\t%d\n", p->shift[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
save_shifts(void)
|
||||
{
|
||||
shifts *p;
|
||||
short *sp1;
|
||||
short *sp2;
|
||||
short *send;
|
||||
|
||||
p = (shifts *)allocate((sizeof(shifts) +
|
||||
(unsigned)(nshifts - 1) * sizeof(short)));
|
||||
|
||||
p->number = this_state->number;
|
||||
p->nshifts = (Value_t) nshifts;
|
||||
|
||||
sp1 = shiftset;
|
||||
sp2 = p->shift;
|
||||
send = shiftset + nshifts;
|
||||
|
||||
while (sp1 < send)
|
||||
*sp2++ = *sp1++;
|
||||
|
||||
if (last_shift)
|
||||
{
|
||||
last_shift->next = p;
|
||||
last_shift = p;
|
||||
}
|
||||
else
|
||||
{
|
||||
first_shift = p;
|
||||
last_shift = p;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
save_reductions(void)
|
||||
{
|
||||
short *isp;
|
||||
short *rp1;
|
||||
short *rp2;
|
||||
int item;
|
||||
Value_t count;
|
||||
reductions *p;
|
||||
short *rend;
|
||||
|
||||
count = 0;
|
||||
for (isp = itemset; isp < itemsetend; isp++)
|
||||
{
|
||||
item = ritem[*isp];
|
||||
if (item < 0)
|
||||
{
|
||||
redset[count++] = (Value_t) - item;
|
||||
}
|
||||
}
|
||||
|
||||
if (count)
|
||||
{
|
||||
p = (reductions *)allocate((sizeof(reductions) +
|
||||
(unsigned)(count - 1) *
|
||||
sizeof(short)));
|
||||
|
||||
p->number = this_state->number;
|
||||
p->nreds = count;
|
||||
|
||||
rp1 = redset;
|
||||
rp2 = p->rules;
|
||||
rend = rp1 + count;
|
||||
|
||||
while (rp1 < rend)
|
||||
*rp2++ = *rp1++;
|
||||
|
||||
if (last_reduction)
|
||||
{
|
||||
last_reduction->next = p;
|
||||
last_reduction = p;
|
||||
}
|
||||
else
|
||||
{
|
||||
first_reduction = p;
|
||||
last_reduction = p;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
set_derives(void)
|
||||
{
|
||||
Value_t i, k;
|
||||
int lhs;
|
||||
short *rules;
|
||||
|
||||
derives = NEW2(nsyms, short *);
|
||||
rules = NEW2(nvars + nrules, short);
|
||||
|
||||
k = 0;
|
||||
for (lhs = start_symbol; lhs < nsyms; lhs++)
|
||||
{
|
||||
derives[lhs] = rules + k;
|
||||
for (i = 0; i < nrules; i++)
|
||||
{
|
||||
if (rlhs[i] == lhs)
|
||||
{
|
||||
rules[k] = i;
|
||||
k++;
|
||||
}
|
||||
}
|
||||
rules[k] = -1;
|
||||
k++;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
print_derives();
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
void
|
||||
print_derives(void)
|
||||
{
|
||||
int i;
|
||||
short *sp;
|
||||
|
||||
printf("\nDERIVES\n\n");
|
||||
|
||||
for (i = start_symbol; i < nsyms; i++)
|
||||
{
|
||||
printf("%s derives ", symbol_name[i]);
|
||||
for (sp = derives[i]; *sp >= 0; sp++)
|
||||
{
|
||||
printf(" %d", *sp);
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
putchar('\n');
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
set_nullable(void)
|
||||
{
|
||||
int i, j;
|
||||
int empty;
|
||||
int done_flag;
|
||||
|
||||
nullable = MALLOC(nsyms);
|
||||
NO_SPACE(nullable);
|
||||
|
||||
for (i = 0; i < nsyms; ++i)
|
||||
nullable[i] = 0;
|
||||
|
||||
done_flag = 0;
|
||||
while (!done_flag)
|
||||
{
|
||||
done_flag = 1;
|
||||
for (i = 1; i < nitems; i++)
|
||||
{
|
||||
empty = 1;
|
||||
while ((j = ritem[i]) >= 0)
|
||||
{
|
||||
if (!nullable[j])
|
||||
empty = 0;
|
||||
++i;
|
||||
}
|
||||
if (empty)
|
||||
{
|
||||
j = rlhs[-j];
|
||||
if (!nullable[j])
|
||||
{
|
||||
nullable[j] = 1;
|
||||
done_flag = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
for (i = 0; i < nsyms; i++)
|
||||
{
|
||||
if (nullable[i])
|
||||
printf("%s is nullable\n", symbol_name[i]);
|
||||
else
|
||||
printf("%s is not nullable\n", symbol_name[i]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
lr0(void)
|
||||
{
|
||||
set_derives();
|
||||
set_nullable();
|
||||
generate_states();
|
||||
}
|
||||
|
||||
#ifdef NO_LEAKS
|
||||
void
|
||||
lr0_leaks(void)
|
||||
{
|
||||
DO_FREE(derives[start_symbol]);
|
||||
DO_FREE(derives);
|
||||
DO_FREE(nullable);
|
||||
}
|
||||
#endif
|
664
main.c
Normal file
664
main.c
Normal file
@ -0,0 +1,664 @@
|
||||
/* $Id: main.c,v 1.38 2012/01/14 01:01:15 tom Exp $ */
|
||||
|
||||
#include <signal.h>
|
||||
#include <unistd.h> /* for _exit() */
|
||||
|
||||
#include "defs.h"
|
||||
|
||||
#if defined(HAVE_ATEXIT)
|
||||
# ifdef HAVE_MKSTEMP
|
||||
# define USE_MKSTEMP 1
|
||||
# elif defined(HAVE_FCNTL_H)
|
||||
# define USE_MKSTEMP 1
|
||||
# include <fcntl.h> /* for open(), O_EXCL, etc. */
|
||||
# else
|
||||
# define USE_MKSTEMP 0
|
||||
# endif
|
||||
#else
|
||||
# define USE_MKSTEMP 0
|
||||
#endif
|
||||
|
||||
#if USE_MKSTEMP
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
typedef struct _my_tmpfiles
|
||||
{
|
||||
struct _my_tmpfiles *next;
|
||||
char *name;
|
||||
}
|
||||
MY_TMPFILES;
|
||||
|
||||
static MY_TMPFILES *my_tmpfiles;
|
||||
#endif /* USE_MKSTEMP */
|
||||
|
||||
char dflag;
|
||||
char gflag;
|
||||
char iflag;
|
||||
char lflag;
|
||||
static char oflag;
|
||||
char rflag;
|
||||
char sflag;
|
||||
char tflag;
|
||||
char vflag;
|
||||
|
||||
const char *symbol_prefix;
|
||||
const char *myname = "yacc";
|
||||
|
||||
int lineno;
|
||||
int outline;
|
||||
|
||||
static char empty_string[] = "";
|
||||
static char default_file_prefix[] = "y";
|
||||
|
||||
static char *file_prefix = default_file_prefix;
|
||||
|
||||
char *code_file_name;
|
||||
char *input_file_name = empty_string;
|
||||
char *defines_file_name;
|
||||
char *externs_file_name;
|
||||
|
||||
static char *graph_file_name;
|
||||
static char *output_file_name;
|
||||
static char *verbose_file_name;
|
||||
|
||||
FILE *action_file; /* a temp file, used to save actions associated */
|
||||
/* with rules until the parser is written */
|
||||
FILE *code_file; /* y.code.c (used when the -r option is specified) */
|
||||
FILE *defines_file; /* y.tab.h */
|
||||
FILE *externs_file; /* y.tab.i */
|
||||
FILE *input_file; /* the input file */
|
||||
FILE *output_file; /* y.tab.c */
|
||||
FILE *text_file; /* a temp file, used to save text until all */
|
||||
/* symbols have been defined */
|
||||
FILE *union_file; /* a temp file, used to save the union */
|
||||
/* definition until all symbol have been */
|
||||
/* defined */
|
||||
FILE *verbose_file; /* y.output */
|
||||
FILE *graph_file; /* y.dot */
|
||||
|
||||
int nitems;
|
||||
int nrules;
|
||||
int nsyms;
|
||||
int ntokens;
|
||||
int nvars;
|
||||
|
||||
Value_t start_symbol;
|
||||
char **symbol_name;
|
||||
char **symbol_pname;
|
||||
Value_t *symbol_value;
|
||||
short *symbol_prec;
|
||||
char *symbol_assoc;
|
||||
|
||||
int pure_parser;
|
||||
int exit_code;
|
||||
|
||||
Value_t *ritem;
|
||||
Value_t *rlhs;
|
||||
Value_t *rrhs;
|
||||
Value_t *rprec;
|
||||
Assoc_t *rassoc;
|
||||
Value_t **derives;
|
||||
char *nullable;
|
||||
|
||||
/*
|
||||
* Since fclose() is called via the signal handler, it might die. Don't loop
|
||||
* if there is a problem closing a file.
|
||||
*/
|
||||
#define DO_CLOSE(fp) \
|
||||
if (fp != 0) { \
|
||||
FILE *use = fp; \
|
||||
fp = 0; \
|
||||
fclose(use); \
|
||||
}
|
||||
|
||||
static int got_intr = 0;
|
||||
|
||||
void
|
||||
done(int k)
|
||||
{
|
||||
DO_CLOSE(input_file);
|
||||
DO_CLOSE(output_file);
|
||||
|
||||
DO_CLOSE(action_file);
|
||||
DO_CLOSE(defines_file);
|
||||
DO_CLOSE(graph_file);
|
||||
DO_CLOSE(text_file);
|
||||
DO_CLOSE(union_file);
|
||||
DO_CLOSE(verbose_file);
|
||||
|
||||
if (got_intr)
|
||||
_exit(EXIT_FAILURE);
|
||||
|
||||
#ifdef NO_LEAKS
|
||||
if (rflag)
|
||||
DO_FREE(code_file_name);
|
||||
|
||||
if (dflag)
|
||||
DO_FREE(defines_file_name);
|
||||
|
||||
if (iflag)
|
||||
DO_FREE(externs_file_name);
|
||||
|
||||
if (oflag)
|
||||
DO_FREE(output_file_name);
|
||||
|
||||
if (vflag)
|
||||
DO_FREE(verbose_file_name);
|
||||
|
||||
if (gflag)
|
||||
DO_FREE(graph_file_name);
|
||||
|
||||
lr0_leaks();
|
||||
lalr_leaks();
|
||||
mkpar_leaks();
|
||||
output_leaks();
|
||||
reader_leaks();
|
||||
#endif
|
||||
|
||||
if (rflag)
|
||||
DO_CLOSE(code_file);
|
||||
|
||||
exit(k);
|
||||
}
|
||||
|
||||
static void
|
||||
onintr(int sig GCC_UNUSED)
|
||||
{
|
||||
got_intr = 1;
|
||||
done(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static void
|
||||
set_signals(void)
|
||||
{
|
||||
#ifdef SIGINT
|
||||
if (signal(SIGINT, SIG_IGN) != SIG_IGN)
|
||||
signal(SIGINT, onintr);
|
||||
#endif
|
||||
#ifdef SIGTERM
|
||||
if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
|
||||
signal(SIGTERM, onintr);
|
||||
#endif
|
||||
#ifdef SIGHUP
|
||||
if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
|
||||
signal(SIGHUP, onintr);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
static const char *msg[] =
|
||||
{
|
||||
""
|
||||
,"Options:"
|
||||
," -b file_prefix set filename prefix (default \"y.\")"
|
||||
," -d write definitions (y.tab.h)"
|
||||
," -i write interface (y.tab.i)"
|
||||
," -g write a graphical description"
|
||||
," -l suppress #line directives"
|
||||
," -o output_file (default \"y.tab.c\")"
|
||||
," -p symbol_prefix set symbol prefix (default \"yy\")"
|
||||
," -P create a reentrant parser, e.g., \"%pure-parser\""
|
||||
," -r produce separate code and table files (y.code.c)"
|
||||
," -s suppress #define's for quoted names in %token lines"
|
||||
," -t add debugging support"
|
||||
," -v write description (y.output)"
|
||||
," -V show version information and exit"
|
||||
};
|
||||
unsigned n;
|
||||
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "Usage: %s [options] filename\n", myname);
|
||||
for (n = 0; n < sizeof(msg) / sizeof(msg[0]); ++n)
|
||||
fprintf(stderr, "%s\n", msg[n]);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void
|
||||
setflag(int ch)
|
||||
{
|
||||
switch (ch)
|
||||
{
|
||||
case 'd':
|
||||
dflag = 1;
|
||||
break;
|
||||
|
||||
case 'g':
|
||||
gflag = 1;
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
iflag = 1;
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
lflag = 1;
|
||||
break;
|
||||
|
||||
case 'P':
|
||||
pure_parser = 1;
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
rflag = 1;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
sflag = 1;
|
||||
break;
|
||||
|
||||
case 't':
|
||||
tflag = 1;
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
vflag = 1;
|
||||
break;
|
||||
|
||||
case 'V':
|
||||
printf("%s - %s\n", myname, VERSION);
|
||||
exit(EXIT_SUCCESS);
|
||||
|
||||
case 'y':
|
||||
/* noop for bison compatibility. byacc is already designed to be posix
|
||||
* yacc compatible. */
|
||||
break;
|
||||
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
getargs(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
char *s;
|
||||
int ch;
|
||||
|
||||
if (argc > 0)
|
||||
myname = argv[0];
|
||||
|
||||
for (i = 1; i < argc; ++i)
|
||||
{
|
||||
s = argv[i];
|
||||
if (*s != '-')
|
||||
break;
|
||||
switch (ch = *++s)
|
||||
{
|
||||
case '\0':
|
||||
input_file = stdin;
|
||||
if (i + 1 < argc)
|
||||
usage();
|
||||
return;
|
||||
|
||||
case '-':
|
||||
++i;
|
||||
goto no_more_options;
|
||||
|
||||
case 'b':
|
||||
if (*++s)
|
||||
file_prefix = s;
|
||||
else if (++i < argc)
|
||||
file_prefix = argv[i];
|
||||
else
|
||||
usage();
|
||||
continue;
|
||||
|
||||
case 'o':
|
||||
if (*++s)
|
||||
output_file_name = s;
|
||||
else if (++i < argc)
|
||||
output_file_name = argv[i];
|
||||
else
|
||||
usage();
|
||||
continue;
|
||||
|
||||
case 'p':
|
||||
if (*++s)
|
||||
symbol_prefix = s;
|
||||
else if (++i < argc)
|
||||
symbol_prefix = argv[i];
|
||||
else
|
||||
usage();
|
||||
continue;
|
||||
|
||||
default:
|
||||
setflag(ch);
|
||||
break;
|
||||
}
|
||||
|
||||
for (;;)
|
||||
{
|
||||
switch (ch = *++s)
|
||||
{
|
||||
case '\0':
|
||||
goto end_of_option;
|
||||
|
||||
default:
|
||||
setflag(ch);
|
||||
break;
|
||||
}
|
||||
}
|
||||
end_of_option:;
|
||||
}
|
||||
|
||||
no_more_options:;
|
||||
if (i + 1 != argc)
|
||||
usage();
|
||||
input_file_name = argv[i];
|
||||
}
|
||||
|
||||
void *
|
||||
allocate(size_t n)
|
||||
{
|
||||
void *p;
|
||||
|
||||
p = NULL;
|
||||
if (n)
|
||||
{
|
||||
p = CALLOC(1, n);
|
||||
NO_SPACE(p);
|
||||
}
|
||||
return (p);
|
||||
}
|
||||
|
||||
#define CREATE_FILE_NAME(dest, suffix) \
|
||||
dest = MALLOC(len + strlen(suffix) + 1); \
|
||||
NO_SPACE(dest); \
|
||||
strcpy(dest, file_prefix); \
|
||||
strcpy(dest + len, suffix)
|
||||
|
||||
static void
|
||||
create_file_names(void)
|
||||
{
|
||||
size_t len;
|
||||
const char *defines_suffix;
|
||||
const char *externs_suffix;
|
||||
char *prefix;
|
||||
|
||||
prefix = NULL;
|
||||
defines_suffix = DEFINES_SUFFIX;
|
||||
externs_suffix = EXTERNS_SUFFIX;
|
||||
|
||||
/* compute the file_prefix from the user provided output_file_name */
|
||||
if (output_file_name != 0)
|
||||
{
|
||||
if (!(prefix = strstr(output_file_name, ".tab.c"))
|
||||
&& (prefix = strstr(output_file_name, ".c")))
|
||||
{
|
||||
defines_suffix = ".h";
|
||||
externs_suffix = ".i";
|
||||
}
|
||||
}
|
||||
|
||||
if (prefix != NULL)
|
||||
{
|
||||
len = (size_t) (prefix - output_file_name);
|
||||
file_prefix = (char *)MALLOC(len + 1);
|
||||
NO_SPACE(file_prefix);
|
||||
strncpy(file_prefix, output_file_name, len)[len] = 0;
|
||||
}
|
||||
else
|
||||
len = strlen(file_prefix);
|
||||
|
||||
/* if "-o filename" was not given */
|
||||
if (output_file_name == 0)
|
||||
{
|
||||
oflag = 1;
|
||||
CREATE_FILE_NAME(output_file_name, OUTPUT_SUFFIX);
|
||||
}
|
||||
|
||||
if (rflag)
|
||||
{
|
||||
CREATE_FILE_NAME(code_file_name, CODE_SUFFIX);
|
||||
}
|
||||
else
|
||||
code_file_name = output_file_name;
|
||||
|
||||
if (dflag)
|
||||
{
|
||||
CREATE_FILE_NAME(defines_file_name, defines_suffix);
|
||||
}
|
||||
|
||||
if (iflag)
|
||||
{
|
||||
CREATE_FILE_NAME(externs_file_name, externs_suffix);
|
||||
}
|
||||
|
||||
if (vflag)
|
||||
{
|
||||
CREATE_FILE_NAME(verbose_file_name, VERBOSE_SUFFIX);
|
||||
}
|
||||
|
||||
if (gflag)
|
||||
{
|
||||
CREATE_FILE_NAME(graph_file_name, GRAPH_SUFFIX);
|
||||
}
|
||||
|
||||
if (prefix != NULL)
|
||||
{
|
||||
FREE(file_prefix);
|
||||
}
|
||||
}
|
||||
|
||||
#if USE_MKSTEMP
|
||||
static void
|
||||
close_tmpfiles(void)
|
||||
{
|
||||
while (my_tmpfiles != 0)
|
||||
{
|
||||
MY_TMPFILES *next = my_tmpfiles->next;
|
||||
|
||||
chmod(my_tmpfiles->name, 0644);
|
||||
unlink(my_tmpfiles->name);
|
||||
|
||||
free(my_tmpfiles->name);
|
||||
free(my_tmpfiles);
|
||||
|
||||
my_tmpfiles = next;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef HAVE_MKSTEMP
|
||||
static int
|
||||
my_mkstemp(char *temp)
|
||||
{
|
||||
int fd;
|
||||
char *dname;
|
||||
char *fname;
|
||||
char *name;
|
||||
|
||||
/*
|
||||
* Split-up to use tempnam, rather than tmpnam; the latter (like
|
||||
* mkstemp) is unusable on Windows.
|
||||
*/
|
||||
if ((fname = strrchr(temp, '/')) != 0)
|
||||
{
|
||||
dname = strdup(temp);
|
||||
dname[++fname - temp] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
dname = 0;
|
||||
fname = temp;
|
||||
}
|
||||
if ((name = tempnam(dname, fname)) != 0)
|
||||
{
|
||||
fd = open(name, O_CREAT | O_EXCL | O_RDWR);
|
||||
strcpy(temp, name);
|
||||
}
|
||||
else
|
||||
{
|
||||
fd = -1;
|
||||
}
|
||||
|
||||
if (dname != 0)
|
||||
free(dname);
|
||||
|
||||
return fd;
|
||||
}
|
||||
#define mkstemp(s) my_mkstemp(s)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* tmpfile() should be adequate, except that it may require special privileges
|
||||
* to use, e.g., MinGW and Windows 7 where it tries to use the root directory.
|
||||
*/
|
||||
static FILE *
|
||||
open_tmpfile(const char *label)
|
||||
{
|
||||
FILE *result;
|
||||
#if USE_MKSTEMP
|
||||
int fd;
|
||||
const char *tmpdir;
|
||||
char *name;
|
||||
const char *mark;
|
||||
|
||||
if ((tmpdir = getenv("TMPDIR")) == 0 || access(tmpdir, W_OK) != 0)
|
||||
{
|
||||
#ifdef P_tmpdir
|
||||
tmpdir = P_tmpdir;
|
||||
#else
|
||||
tmpdir = "/tmp";
|
||||
#endif
|
||||
if (access(tmpdir, W_OK) != 0)
|
||||
tmpdir = ".";
|
||||
}
|
||||
|
||||
name = malloc(strlen(tmpdir) + 10 + strlen(label));
|
||||
|
||||
result = 0;
|
||||
if (name != 0)
|
||||
{
|
||||
if ((mark = strrchr(label, '_')) == 0)
|
||||
mark = label + strlen(label);
|
||||
|
||||
sprintf(name, "%s/%.*sXXXXXX", tmpdir, (int)(mark - label), label);
|
||||
fd = mkstemp(name);
|
||||
if (fd >= 0)
|
||||
{
|
||||
result = fdopen(fd, "w+");
|
||||
if (result != 0)
|
||||
{
|
||||
MY_TMPFILES *item;
|
||||
|
||||
if (my_tmpfiles == 0)
|
||||
{
|
||||
atexit(close_tmpfiles);
|
||||
}
|
||||
|
||||
item = NEW(MY_TMPFILES);
|
||||
NO_SPACE(item);
|
||||
|
||||
item->name = name;
|
||||
NO_SPACE(item->name);
|
||||
|
||||
item->next = my_tmpfiles;
|
||||
my_tmpfiles = item;
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
result = tmpfile();
|
||||
#endif
|
||||
|
||||
if (result == 0)
|
||||
open_error(label);
|
||||
return result;
|
||||
}
|
||||
|
||||
static void
|
||||
open_files(void)
|
||||
{
|
||||
create_file_names();
|
||||
|
||||
if (input_file == 0)
|
||||
{
|
||||
input_file = fopen(input_file_name, "r");
|
||||
if (input_file == 0)
|
||||
open_error(input_file_name);
|
||||
}
|
||||
|
||||
action_file = open_tmpfile("action_file");
|
||||
text_file = open_tmpfile("text_file");
|
||||
|
||||
if (vflag)
|
||||
{
|
||||
verbose_file = fopen(verbose_file_name, "w");
|
||||
if (verbose_file == 0)
|
||||
open_error(verbose_file_name);
|
||||
}
|
||||
|
||||
if (gflag)
|
||||
{
|
||||
graph_file = fopen(graph_file_name, "w");
|
||||
if (graph_file == 0)
|
||||
open_error(graph_file_name);
|
||||
fprintf(graph_file, "digraph %s {\n", file_prefix);
|
||||
fprintf(graph_file, "\tedge [fontsize=10];\n");
|
||||
fprintf(graph_file, "\tnode [shape=box,fontsize=10];\n");
|
||||
fprintf(graph_file, "\torientation=landscape;\n");
|
||||
fprintf(graph_file, "\trankdir=LR;\n");
|
||||
fprintf(graph_file, "\t/*\n");
|
||||
fprintf(graph_file, "\tmargin=0.2;\n");
|
||||
fprintf(graph_file, "\tpage=\"8.27,11.69\"; // for A4 printing\n");
|
||||
fprintf(graph_file, "\tratio=auto;\n");
|
||||
fprintf(graph_file, "\t*/\n");
|
||||
}
|
||||
|
||||
if (dflag)
|
||||
{
|
||||
defines_file = fopen(defines_file_name, "w");
|
||||
if (defines_file == 0)
|
||||
open_error(defines_file_name);
|
||||
union_file = open_tmpfile("union_file");
|
||||
}
|
||||
|
||||
if (iflag)
|
||||
{
|
||||
externs_file = fopen(externs_file_name, "w");
|
||||
if (externs_file == 0)
|
||||
open_error(externs_file_name);
|
||||
}
|
||||
|
||||
output_file = fopen(output_file_name, "w");
|
||||
if (output_file == 0)
|
||||
open_error(output_file_name);
|
||||
|
||||
if (rflag)
|
||||
{
|
||||
code_file = fopen(code_file_name, "w");
|
||||
if (code_file == 0)
|
||||
open_error(code_file_name);
|
||||
}
|
||||
else
|
||||
code_file = output_file;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
SRexpect = -1;
|
||||
RRexpect = -1;
|
||||
exit_code = EXIT_SUCCESS;
|
||||
|
||||
set_signals();
|
||||
getargs(argc, argv);
|
||||
open_files();
|
||||
reader();
|
||||
lr0();
|
||||
lalr();
|
||||
make_parser();
|
||||
graph();
|
||||
finalize_closure();
|
||||
verbose();
|
||||
output();
|
||||
done(exit_code);
|
||||
/*NOTREACHED */
|
||||
}
|
182
makefile.in
Normal file
182
makefile.in
Normal file
@ -0,0 +1,182 @@
|
||||
# $Id: makefile.in,v 1.17 2012/01/15 19:11:21 tom Exp $
|
||||
#
|
||||
# UNIX template-makefile for Berkeley Yacc
|
||||
|
||||
THIS = yacc
|
||||
|
||||
#### Start of system configuration section. ####
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
CC = @CC@
|
||||
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
transform = @program_transform_name@
|
||||
|
||||
DEFINES =
|
||||
EXTRA_CFLAGS = @EXTRA_CFLAGS@
|
||||
CPPFLAGS = -I. -I$(srcdir) $(DEFINES) -DHAVE_CONFIG_H -DYYPATCH=`cat $(srcdir)/VERSION` @CPPFLAGS@
|
||||
CFLAGS = @CFLAGS@ $(CPPFLAGS) $(EXTRA_CFLAGS)
|
||||
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBS = @LIBS@
|
||||
|
||||
CTAGS = @CTAGS@
|
||||
ETAGS = @ETAGS@
|
||||
LINT = @LINT@
|
||||
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
|
||||
bindir = $(DESTDIR)@bindir@
|
||||
mandir = $(DESTDIR)@mandir@/man1
|
||||
manext = 1
|
||||
|
||||
testdir = $(srcdir)/test
|
||||
|
||||
x = @EXEEXT@
|
||||
o = .@OBJEXT@
|
||||
|
||||
#### End of system configuration section. ####
|
||||
|
||||
SHELL = /bin/sh
|
||||
@SET_MAKE@
|
||||
|
||||
H_FILES = \
|
||||
defs.h
|
||||
|
||||
C_FILES = \
|
||||
closure.c \
|
||||
error.c \
|
||||
graph.c \
|
||||
lalr.c \
|
||||
lr0.c \
|
||||
main.c \
|
||||
mkpar.c \
|
||||
output.c \
|
||||
reader.c \
|
||||
skeleton.c \
|
||||
symtab.c \
|
||||
verbose.c \
|
||||
warshall.c
|
||||
|
||||
OBJS = \
|
||||
closure$o \
|
||||
error$o \
|
||||
graph$o \
|
||||
lalr$o \
|
||||
lr0$o \
|
||||
main$o \
|
||||
mkpar$o \
|
||||
output$o \
|
||||
reader$o \
|
||||
skeleton$o \
|
||||
symtab$o \
|
||||
verbose$o \
|
||||
warshall$o
|
||||
|
||||
TRANSFORM_BIN = sed 's/$x$$//' |sed '$(transform)'|sed 's/$$/$x/'
|
||||
TRANSFORM_MAN = sed 's/$(manext)$$//'|sed '$(transform)'|sed 's/$$/$(manext)/'
|
||||
|
||||
actual_bin = `echo $(THIS)$x | $(TRANSFORM_BIN)`
|
||||
actual_man = `echo $(THIS).$(manext)| $(TRANSFORM_MAN)`
|
||||
|
||||
all : $(THIS)$x
|
||||
|
||||
install: all installdirs
|
||||
$(INSTALL_PROGRAM) $(THIS)$x $(bindir)/$(actual_bin)
|
||||
- $(INSTALL_DATA) $(srcdir)/$(THIS).1 $(mandir)/$(actual_man)
|
||||
|
||||
installdirs:
|
||||
mkdir -p $(bindir)
|
||||
- mkdir -p $(mandir)
|
||||
|
||||
uninstall:
|
||||
- rm -f $(bindir)/$(actual_bin)
|
||||
- rm -f $(mandir)/$(actual_man)
|
||||
|
||||
################################################################################
|
||||
.SUFFIXES : $o .i .html .$(manext) .cat .ps .pdf .txt
|
||||
|
||||
.c$o:
|
||||
@RULE_CC@
|
||||
@ECHO_CC@$(CC) -c $(CFLAGS) $<
|
||||
|
||||
.c.i :
|
||||
@RULE_CC@
|
||||
@ECHO_CC@$(CPP) -C $(CPPFLAGS) $*.c >$@
|
||||
|
||||
.$(manext).cat :
|
||||
- nroff -man $(srcdir)/$(THIS).$(manext) >$@
|
||||
|
||||
.$(manext).html :
|
||||
GROFF_NO_SGR=stupid $(SHELL) -c "tbl $*.$(manext) | groff -Thtml -man" >$@
|
||||
|
||||
.$(manext).ps :
|
||||
$(SHELL) -c "tbl $*.$(manext) | groff -man" >$@
|
||||
|
||||
.$(manext).txt :
|
||||
GROFF_NO_SGR=stupid $(SHELL) -c "tbl $*.$(manext) | nroff -Tascii -man | col -bx" >$@
|
||||
|
||||
.ps.pdf :
|
||||
ps2pdf $*.ps
|
||||
|
||||
################################################################################
|
||||
|
||||
$(THIS)$x : $(OBJS)
|
||||
@ECHO_LD@$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(OBJS) $(LIBS)
|
||||
|
||||
mostlyclean :
|
||||
- rm -f core .nfs* *$o *.bak *.BAK *.out
|
||||
|
||||
clean : mostlyclean
|
||||
- rm -f $(THIS)$x
|
||||
|
||||
distclean : clean
|
||||
- rm -f config.log config.cache config.status config.h makefile
|
||||
- rm -f *.html *.cat *.pdf *.ps *.txt
|
||||
- cd test && rm -f test-*
|
||||
|
||||
realclean: distclean
|
||||
- rm -f tags TAGS
|
||||
|
||||
################################################################################
|
||||
docs :: $(THIS).html \
|
||||
$(THIS).pdf \
|
||||
$(THIS).ps \
|
||||
$(THIS).txt
|
||||
$(THIS).html : $(THIS).$(manext)
|
||||
$(THIS).pdf : $(THIS).ps
|
||||
$(THIS).ps : $(THIS).$(manext)
|
||||
$(THIS).txt : $(THIS).$(manext)
|
||||
################################################################################
|
||||
check: $(THIS)$x
|
||||
$(SHELL) $(testdir)/run_test.sh $(testdir)
|
||||
|
||||
check_make: $(THIS)$x
|
||||
$(SHELL) $(testdir)/run_make.sh $(testdir)
|
||||
|
||||
check_lint:
|
||||
$(SHELL) $(testdir)/run_lint.sh $(testdir)
|
||||
################################################################################
|
||||
tags: $(H_FILES) $(C_FILES)
|
||||
$(CTAGS) $(C_FILES) $(H_FILES)
|
||||
|
||||
lint: $(C_FILES)
|
||||
$(LINT) $(CPPFLAGS) $(C_FILES)
|
||||
|
||||
@MAKE_UPPER_TAGS@TAGS: $(H_FILES) $(C_FILES)
|
||||
@MAKE_UPPER_TAGS@ $(ETAGS) $(C_FILES) $(H_FILES)
|
||||
|
||||
depend:
|
||||
makedepend -- $(CPPFLAGS) -- $(C_FILES)
|
||||
|
||||
$(OBJS) : defs.h
|
||||
|
||||
main$o \
|
||||
skeleton$o : makefile VERSION
|
||||
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
392
mkpar.c
Normal file
392
mkpar.c
Normal file
@ -0,0 +1,392 @@
|
||||
/* $Id: mkpar.c,v 1.11 2010/06/09 08:53:17 tom Exp $ */
|
||||
|
||||
#include "defs.h"
|
||||
|
||||
static action *add_reduce(action *actions, int ruleno, int symbol);
|
||||
static action *add_reductions(int stateno, action *actions);
|
||||
static action *get_shifts(int stateno);
|
||||
static action *parse_actions(int stateno);
|
||||
static int sole_reduction(int stateno);
|
||||
static void defreds(void);
|
||||
static void find_final_state(void);
|
||||
static void free_action_row(action *p);
|
||||
static void remove_conflicts(void);
|
||||
static void total_conflicts(void);
|
||||
static void unused_rules(void);
|
||||
|
||||
action **parser;
|
||||
|
||||
int SRexpect;
|
||||
int RRexpect;
|
||||
|
||||
int SRtotal;
|
||||
int RRtotal;
|
||||
|
||||
Value_t *SRconflicts;
|
||||
Value_t *RRconflicts;
|
||||
Value_t *defred;
|
||||
Value_t *rules_used;
|
||||
Value_t nunused;
|
||||
Value_t final_state;
|
||||
|
||||
static Value_t SRcount;
|
||||
static Value_t RRcount;
|
||||
|
||||
void
|
||||
make_parser(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
parser = NEW2(nstates, action *);
|
||||
for (i = 0; i < nstates; i++)
|
||||
parser[i] = parse_actions(i);
|
||||
|
||||
find_final_state();
|
||||
remove_conflicts();
|
||||
unused_rules();
|
||||
if (SRtotal + RRtotal > 0)
|
||||
total_conflicts();
|
||||
defreds();
|
||||
}
|
||||
|
||||
static action *
|
||||
parse_actions(int stateno)
|
||||
{
|
||||
action *actions;
|
||||
|
||||
actions = get_shifts(stateno);
|
||||
actions = add_reductions(stateno, actions);
|
||||
return (actions);
|
||||
}
|
||||
|
||||
static action *
|
||||
get_shifts(int stateno)
|
||||
{
|
||||
action *actions, *temp;
|
||||
shifts *sp;
|
||||
Value_t *to_state2;
|
||||
Value_t i, k;
|
||||
Value_t symbol;
|
||||
|
||||
actions = 0;
|
||||
sp = shift_table[stateno];
|
||||
if (sp)
|
||||
{
|
||||
to_state2 = sp->shift;
|
||||
for (i = (Value_t) (sp->nshifts - 1); i >= 0; i--)
|
||||
{
|
||||
k = to_state2[i];
|
||||
symbol = accessing_symbol[k];
|
||||
if (ISTOKEN(symbol))
|
||||
{
|
||||
temp = NEW(action);
|
||||
temp->next = actions;
|
||||
temp->symbol = symbol;
|
||||
temp->number = k;
|
||||
temp->prec = symbol_prec[symbol];
|
||||
temp->action_code = SHIFT;
|
||||
temp->assoc = symbol_assoc[symbol];
|
||||
actions = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (actions);
|
||||
}
|
||||
|
||||
static action *
|
||||
add_reductions(int stateno, action *actions)
|
||||
{
|
||||
int i, j, m, n;
|
||||
int ruleno, tokensetsize;
|
||||
unsigned *rowp;
|
||||
|
||||
tokensetsize = WORDSIZE(ntokens);
|
||||
m = lookaheads[stateno];
|
||||
n = lookaheads[stateno + 1];
|
||||
for (i = m; i < n; i++)
|
||||
{
|
||||
ruleno = LAruleno[i];
|
||||
rowp = LA + i * tokensetsize;
|
||||
for (j = ntokens - 1; j >= 0; j--)
|
||||
{
|
||||
if (BIT(rowp, j))
|
||||
actions = add_reduce(actions, ruleno, j);
|
||||
}
|
||||
}
|
||||
return (actions);
|
||||
}
|
||||
|
||||
static action *
|
||||
add_reduce(action *actions,
|
||||
int ruleno,
|
||||
int symbol)
|
||||
{
|
||||
action *temp, *prev, *next;
|
||||
|
||||
prev = 0;
|
||||
for (next = actions; next && next->symbol < symbol; next = next->next)
|
||||
prev = next;
|
||||
|
||||
while (next && next->symbol == symbol && next->action_code == SHIFT)
|
||||
{
|
||||
prev = next;
|
||||
next = next->next;
|
||||
}
|
||||
|
||||
while (next && next->symbol == symbol &&
|
||||
next->action_code == REDUCE && next->number < ruleno)
|
||||
{
|
||||
prev = next;
|
||||
next = next->next;
|
||||
}
|
||||
|
||||
temp = NEW(action);
|
||||
temp->next = next;
|
||||
temp->symbol = (Value_t) symbol;
|
||||
temp->number = (Value_t) ruleno;
|
||||
temp->prec = rprec[ruleno];
|
||||
temp->action_code = REDUCE;
|
||||
temp->assoc = rassoc[ruleno];
|
||||
|
||||
if (prev)
|
||||
prev->next = temp;
|
||||
else
|
||||
actions = temp;
|
||||
|
||||
return (actions);
|
||||
}
|
||||
|
||||
static void
|
||||
find_final_state(void)
|
||||
{
|
||||
int goal, i;
|
||||
Value_t *to_state2;
|
||||
shifts *p;
|
||||
|
||||
p = shift_table[0];
|
||||
to_state2 = p->shift;
|
||||
goal = ritem[1];
|
||||
for (i = p->nshifts - 1; i >= 0; --i)
|
||||
{
|
||||
final_state = to_state2[i];
|
||||
if (accessing_symbol[final_state] == goal)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
unused_rules(void)
|
||||
{
|
||||
int i;
|
||||
action *p;
|
||||
|
||||
rules_used = (Value_t *) MALLOC((unsigned)nrules * sizeof(Value_t));
|
||||
NO_SPACE(rules_used);
|
||||
|
||||
for (i = 0; i < nrules; ++i)
|
||||
rules_used[i] = 0;
|
||||
|
||||
for (i = 0; i < nstates; ++i)
|
||||
{
|
||||
for (p = parser[i]; p; p = p->next)
|
||||
{
|
||||
if (p->action_code == REDUCE && p->suppressed == 0)
|
||||
rules_used[p->number] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
nunused = 0;
|
||||
for (i = 3; i < nrules; ++i)
|
||||
if (!rules_used[i])
|
||||
++nunused;
|
||||
|
||||
if (nunused)
|
||||
{
|
||||
if (nunused == 1)
|
||||
fprintf(stderr, "%s: 1 rule never reduced\n", myname);
|
||||
else
|
||||
fprintf(stderr, "%s: %d rules never reduced\n", myname, nunused);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
remove_conflicts(void)
|
||||
{
|
||||
int i;
|
||||
int symbol;
|
||||
action *p, *pref = 0;
|
||||
|
||||
SRtotal = 0;
|
||||
RRtotal = 0;
|
||||
SRconflicts = NEW2(nstates, Value_t);
|
||||
RRconflicts = NEW2(nstates, Value_t);
|
||||
for (i = 0; i < nstates; i++)
|
||||
{
|
||||
SRcount = 0;
|
||||
RRcount = 0;
|
||||
symbol = -1;
|
||||
for (p = parser[i]; p; p = p->next)
|
||||
{
|
||||
if (p->symbol != symbol)
|
||||
{
|
||||
pref = p;
|
||||
symbol = p->symbol;
|
||||
}
|
||||
else if (i == final_state && symbol == 0)
|
||||
{
|
||||
SRcount++;
|
||||
p->suppressed = 1;
|
||||
}
|
||||
else if (pref != 0 && pref->action_code == SHIFT)
|
||||
{
|
||||
if (pref->prec > 0 && p->prec > 0)
|
||||
{
|
||||
if (pref->prec < p->prec)
|
||||
{
|
||||
pref->suppressed = 2;
|
||||
pref = p;
|
||||
}
|
||||
else if (pref->prec > p->prec)
|
||||
{
|
||||
p->suppressed = 2;
|
||||
}
|
||||
else if (pref->assoc == LEFT)
|
||||
{
|
||||
pref->suppressed = 2;
|
||||
pref = p;
|
||||
}
|
||||
else if (pref->assoc == RIGHT)
|
||||
{
|
||||
p->suppressed = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
pref->suppressed = 2;
|
||||
p->suppressed = 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SRcount++;
|
||||
p->suppressed = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RRcount++;
|
||||
p->suppressed = 1;
|
||||
}
|
||||
}
|
||||
SRtotal += SRcount;
|
||||
RRtotal += RRcount;
|
||||
SRconflicts[i] = SRcount;
|
||||
RRconflicts[i] = RRcount;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
total_conflicts(void)
|
||||
{
|
||||
fprintf(stderr, "%s: ", myname);
|
||||
if (SRtotal == 1)
|
||||
fprintf(stderr, "1 shift/reduce conflict");
|
||||
else if (SRtotal > 1)
|
||||
fprintf(stderr, "%d shift/reduce conflicts", SRtotal);
|
||||
|
||||
if (SRtotal && RRtotal)
|
||||
fprintf(stderr, ", ");
|
||||
|
||||
if (RRtotal == 1)
|
||||
fprintf(stderr, "1 reduce/reduce conflict");
|
||||
else if (RRtotal > 1)
|
||||
fprintf(stderr, "%d reduce/reduce conflicts", RRtotal);
|
||||
|
||||
fprintf(stderr, ".\n");
|
||||
|
||||
if (SRexpect >= 0 && SRtotal != SRexpect)
|
||||
{
|
||||
fprintf(stderr, "%s: ", myname);
|
||||
fprintf(stderr, "expected %d shift/reduce conflict%s.\n",
|
||||
SRexpect, PLURAL(SRexpect));
|
||||
exit_code = EXIT_FAILURE;
|
||||
}
|
||||
if (RRexpect >= 0 && RRtotal != RRexpect)
|
||||
{
|
||||
fprintf(stderr, "%s: ", myname);
|
||||
fprintf(stderr, "expected %d reduce/reduce conflict%s.\n",
|
||||
RRexpect, PLURAL(RRexpect));
|
||||
exit_code = EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
sole_reduction(int stateno)
|
||||
{
|
||||
int count, ruleno;
|
||||
action *p;
|
||||
|
||||
count = 0;
|
||||
ruleno = 0;
|
||||
for (p = parser[stateno]; p; p = p->next)
|
||||
{
|
||||
if (p->action_code == SHIFT && p->suppressed == 0)
|
||||
return (0);
|
||||
else if (p->action_code == REDUCE && p->suppressed == 0)
|
||||
{
|
||||
if (ruleno > 0 && p->number != ruleno)
|
||||
return (0);
|
||||
if (p->symbol != 1)
|
||||
++count;
|
||||
ruleno = p->number;
|
||||
}
|
||||
}
|
||||
|
||||
if (count == 0)
|
||||
return (0);
|
||||
return (ruleno);
|
||||
}
|
||||
|
||||
static void
|
||||
defreds(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
defred = NEW2(nstates, Value_t);
|
||||
for (i = 0; i < nstates; i++)
|
||||
defred[i] = (Value_t) sole_reduction(i);
|
||||
}
|
||||
|
||||
static void
|
||||
free_action_row(action *p)
|
||||
{
|
||||
action *q;
|
||||
|
||||
while (p)
|
||||
{
|
||||
q = p->next;
|
||||
FREE(p);
|
||||
p = q;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
free_parser(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nstates; i++)
|
||||
free_action_row(parser[i]);
|
||||
|
||||
FREE(parser);
|
||||
}
|
||||
|
||||
#ifdef NO_LEAKS
|
||||
void
|
||||
mkpar_leaks(void)
|
||||
{
|
||||
DO_FREE(defred);
|
||||
DO_FREE(rules_used);
|
||||
DO_FREE(SRconflicts);
|
||||
DO_FREE(RRconflicts);
|
||||
}
|
||||
#endif
|
60
package/byacc.spec
Normal file
60
package/byacc.spec
Normal file
@ -0,0 +1,60 @@
|
||||
Summary: byacc - public domain Berkeley LALR Yacc parser generator
|
||||
%define AppProgram byacc
|
||||
%define AppVersion 20120115
|
||||
%define UseProgram yacc
|
||||
# $XTermId: byacc.spec,v 1.13 2012/01/15 19:30:29 tom Exp $
|
||||
Name: %{AppProgram}
|
||||
Version: %{AppVersion}
|
||||
Release: 1
|
||||
License: Public Domain, MIT
|
||||
Group: Applications/Development
|
||||
URL: ftp://invisible-island.net/%{AppProgram}
|
||||
Source0: %{AppProgram}-%{AppVersion}.tgz
|
||||
Packager: Thomas Dickey <dickey@invisible-island.net>
|
||||
|
||||
%description
|
||||
This package provides a parser generator utility that reads a grammar
|
||||
specification from a file and generates an LR(1) parser for it. The
|
||||
parsers consist of a set of LALR(1) parsing tables and a driver
|
||||
routine written in the C programming language. It has a public domain
|
||||
license which includes the generated C.
|
||||
|
||||
%prep
|
||||
|
||||
%setup -q -n %{AppProgram}-%{AppVersion}
|
||||
|
||||
%build
|
||||
|
||||
INSTALL_PROGRAM='${INSTALL}' \
|
||||
./configure \
|
||||
--program-prefix=b \
|
||||
--target %{_target_platform} \
|
||||
--prefix=%{_prefix} \
|
||||
--bindir=%{_bindir} \
|
||||
--libdir=%{_libdir} \
|
||||
--mandir=%{_mandir}
|
||||
|
||||
make
|
||||
|
||||
%install
|
||||
[ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT
|
||||
|
||||
make install DESTDIR=$RPM_BUILD_ROOT
|
||||
( cd $RPM_BUILD_ROOT%{_bindir} && ln -s %{AppProgram} %{UseProgram} )
|
||||
|
||||
strip $RPM_BUILD_ROOT%{_bindir}/%{AppProgram}
|
||||
|
||||
%clean
|
||||
[ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT
|
||||
|
||||
%files
|
||||
%defattr(-,root,root)
|
||||
%{_prefix}/bin/%{AppProgram}
|
||||
%{_prefix}/bin/%{UseProgram}
|
||||
%{_mandir}/man1/%{AppProgram}.*
|
||||
|
||||
%changelog
|
||||
# each patch should add its ChangeLog entries here
|
||||
|
||||
* Sun Jun 06 2010 Thomas Dickey
|
||||
- initial version
|
223
package/debian/changelog
Normal file
223
package/debian/changelog
Normal file
@ -0,0 +1,223 @@
|
||||
byacc (20120115) unstable; urgency=low
|
||||
|
||||
* add testcases, improve documentation for "-s" option.
|
||||
|
||||
-- Thomas E. Dickey <dickey@invisible-island.net> Fri, 13 Jan 2012 20:44:34 -0500
|
||||
|
||||
byacc (20111219) unstable; urgency=low
|
||||
|
||||
* add "-s" option.
|
||||
|
||||
-- Thomas E. Dickey <dickey@invisible-island.net> Mon, 19 Dec 2011 20:54:09 -0500
|
||||
|
||||
byacc (20110908) unstable; urgency=low
|
||||
|
||||
* add "-i" option.
|
||||
* add error-check in reader.c
|
||||
|
||||
-- Thomas E. Dickey <dickey@invisible-island.net> Mon, 05 Sep 2011 20:05:51 -0400
|
||||
|
||||
byacc (20101229) unstable; urgency=low
|
||||
|
||||
* fixes from Christos Zoulos
|
||||
|
||||
-- Thomas E. Dickey <dickey@invisible-island.net> Wed, 29 Dec 2010 13:03:50 -0500
|
||||
|
||||
byacc (20101226) unstable; urgency=low
|
||||
|
||||
* portability fix for MinGW
|
||||
|
||||
-- Thomas E. Dickey <dickey@invisible-island.net> Sat, 25 Dec 2010 19:37:54 -0500
|
||||
|
||||
byacc (20101127) unstable; urgency=low
|
||||
|
||||
* corrected yyerror use of %parse-param data
|
||||
|
||||
-- Thomas E. Dickey <dickey@invisible-island.net> Sat, 27 Nov 2010 12:32:00 -0500
|
||||
|
||||
byacc (20101126) unstable; urgency=low
|
||||
|
||||
* additional fix to generated code to avoid symbol conflict
|
||||
|
||||
-- Thomas E. Dickey <dickey@invisible-island.net> Fri, 26 Nov 2010 04:23:08 -0500
|
||||
|
||||
byacc (20101124) unstable; urgency=low
|
||||
|
||||
* amend fix for Red Hat #112617 to restore warning message.
|
||||
|
||||
-- Thomas E. Dickey <dickey@invisible-island.net> Mon, 22 Nov 2010 08:21:23 -0500
|
||||
|
||||
byacc (20101122) unstable; urgency=low
|
||||
|
||||
* fix for generated header to avoid symbol conflict
|
||||
|
||||
-- Thomas E. Dickey <dickey@invisible-island.net> Mon, 22 Nov 2010 08:21:23 -0500
|
||||
|
||||
byacc (20100610) unstable; urgency=low
|
||||
|
||||
* Add package scripts to upstream source, for test-builds.
|
||||
|
||||
-- Thomas E. Dickey <dickey@invisible-island.net> Thu, 10 Jun 2010 08:59:11 -0400
|
||||
|
||||
byacc (20100216-1) unstable; urgency=low
|
||||
|
||||
* New upstream release
|
||||
* debian/source/format: Added using format "3.0 (quilt)"
|
||||
|
||||
-- Dave Beckett <dajobe@debian.org> Tue, 20 Apr 2010 12:56:11 -0700
|
||||
|
||||
byacc (20091027-1) unstable; urgency=low
|
||||
|
||||
* New upstream release
|
||||
* debian/control:
|
||||
- Updated to policy 3.8.4
|
||||
- Add ${misc:Depends}
|
||||
|
||||
-- Dave Beckett <dajobe@debian.org> Tue, 02 Feb 2010 21:36:34 -0800
|
||||
|
||||
byacc (20090221-1) unstable; urgency=low
|
||||
|
||||
* New upstream release
|
||||
|
||||
-- Dave Beckett <dajobe@debian.org> Thu, 26 Feb 2009 21:06:20 -0800
|
||||
|
||||
byacc (20080826-1) unstable; urgency=high
|
||||
|
||||
* New upstream release
|
||||
* debian/patches/02-skeleton.patch: Removed - merged upstream
|
||||
* debian/control: Updated to policy 3.8.0
|
||||
* debian/preinst, debian/postrm: removed - empty (lintian)
|
||||
* debian/watch: version 3 and make FTP passive
|
||||
* Acknowledge NMU - thanks.
|
||||
|
||||
-- Dave Beckett <dajobe@debian.org> Wed, 11 Sep 2008 23:58:00 -0700
|
||||
|
||||
byacc (20070509-1.1) unstable; urgency=high
|
||||
|
||||
* Non-maintainer upload.
|
||||
* Fix stack overflow in skeleton.c with upstream patch.
|
||||
Closes: #491182 aka CVE-2008-3196
|
||||
|
||||
-- Thomas Viehmann <tv@beamnet.de> Sun, 24 Aug 2008 23:13:07 +0200
|
||||
|
||||
byacc (20070509-1) unstable; urgency=low
|
||||
|
||||
* New upstream release
|
||||
* debian/watch: Fix to use passive FTP
|
||||
* debian/compat: added instead of use of DH_COMPAT in debian/rules
|
||||
|
||||
-- Dave Beckett <dajobe@debian.org> Tue, 26 Jun 2007 22:39:45 -0700
|
||||
|
||||
byacc (20050813-1) unstable; urgency=low
|
||||
|
||||
* New upstream release:
|
||||
- Do not close union_file for -d option (Closes: #322858)
|
||||
|
||||
-- Dave Beckett <dajobe@debian.org> Sun, 14 Aug 2005 10:14:12 +0100
|
||||
|
||||
byacc (20050505-1) unstable; urgency=low
|
||||
|
||||
* New maintainer (Closes: #321377)
|
||||
* Switch to new upstream and new source (Closes: #240662)
|
||||
* debian/copyright: Update to new upstream and add source information
|
||||
(Closes: #166300)
|
||||
* Acknowledge fix in NMUs (Closes: #283174)
|
||||
* New manual page does not have the formatting problem (Closes: #100947)
|
||||
* Added debian/watch file.
|
||||
|
||||
-- Dave Beckett <dajobe@debian.org> Fri, 5 Aug 2005 22:50:20 +0100
|
||||
|
||||
byacc (1.9.1-1.1) unstable; urgency=low
|
||||
|
||||
* Remove alternative in prerm. Closes: #283174
|
||||
|
||||
-- LaMont Jones <lamont@debian.org> Fri, 26 Nov 2004 18:49:09 -0700
|
||||
|
||||
byacc (1.9.1-1) unstable; urgency=low
|
||||
|
||||
* Maintainer upload.
|
||||
* Fixed alternatives entry, closes: Bug#146195;
|
||||
* Changed priority to "extra" at behest of Daniel Bungert,
|
||||
closes: Bug#142271.
|
||||
* Fixed awful packaging error which meant the test/ directory was excluded
|
||||
from the orig.tar.gz.
|
||||
|
||||
-- Jason Henry Parker <henry@debian.org> Fri, 27 Sep 2002 16:25:27 -0400
|
||||
|
||||
byacc (1.9-13.1) unstable; urgency=low
|
||||
|
||||
* Non-maintainer upload
|
||||
* Removed erraneous escapes in manpage - some data wasn't visable,
|
||||
closes: Bug#100947
|
||||
* Alternatives entry added, closes: Bug#113168
|
||||
* Standards-version: 3.5.6
|
||||
* Maintainer script cleaning
|
||||
|
||||
-- Daniel Bungert <drb@debian.org> Fri, 29 Mar 2002 16:58:30 -0500
|
||||
|
||||
byacc (1.9-13) unstable; urgency=low
|
||||
|
||||
* Applied patch from "Randolph Chung" <tausq@debian.org> to fix build problems
|
||||
on ia64, closes: Bug#91966
|
||||
|
||||
-- Jason Henry Parker <henry@debian.org> Thu, 29 Mar 2001 21:41:19 +1000
|
||||
|
||||
byacc (1.9-12) unstable; urgency=low
|
||||
|
||||
* Updated to latest version of debhelper, and Standards-Version: 3.2.1.0, closes: Bug#81444
|
||||
* Added Build-Depends: debhelper, closes: Bug#70207
|
||||
* Removed mktemp() calls in main.c
|
||||
|
||||
-- Jason Henry Parker <henry@debian.org> Mon, 18 Dec 2000 08:02:54 +1000
|
||||
|
||||
byacc (1.9-11.7) unstable; urgency=low
|
||||
|
||||
* New maintainer.
|
||||
* Updated to dh_make and standards version 2.4.0.0, no lintian errors
|
||||
or warnings.
|
||||
* Added several more files from the upstream distribution to
|
||||
/usr/doc/byacc.
|
||||
|
||||
-- Jason Henry Parker <henry@debian.org> Sat, 2 Jan 1999 03:04:17 +1000
|
||||
|
||||
byacc (1.9-11.6) unstable; urgency=low
|
||||
|
||||
* Patch by <mdorman@law.miami.edu> to remove some
|
||||
superfluous files that can interfere with the build process on other
|
||||
architectures. (Bug #21607).
|
||||
|
||||
-- Vincent Renardias <vincent@waw.com> Fri, 24 Apr 1998 19:56:58 +0200
|
||||
|
||||
byacc (1.9-11.5) unstable; urgency=low
|
||||
|
||||
* Added 'binary-arch' target in debian/rules (Bug #12742).
|
||||
|
||||
-- Vincent Renardias <vincent@waw.com> Sun, 9 Nov 1997 23:37:31 +0100
|
||||
|
||||
byacc (1.9-11.4) unstable; urgency=low
|
||||
|
||||
* Cosmetic change (Fix bug #9623).
|
||||
|
||||
-- Vincent Renardias <vincent@waw.com> Fri, 9 May 1997 16:30:24 +0200
|
||||
|
||||
byacc (1.9-11.3) unstable; urgency=low
|
||||
|
||||
* Rebuilt with libc6.
|
||||
|
||||
-- Debian QA Group <debian-qa@lists.debian.org> Thu, 1 May 1997 22:02:04 +0200
|
||||
|
||||
byacc (1.9-11.2) unstable; urgency=low
|
||||
|
||||
* Orphaned the package at his maintainer's request (dgregor@coil.com).
|
||||
|
||||
-- Debian QA Group <debian-qa@lists.debian.org> Sun, 20 Apr 1997 20:03:03 +0200
|
||||
|
||||
byacc (1.9-11.1) unstable; urgency=low
|
||||
|
||||
* Converted to new source format (Fixes #8085).
|
||||
* Compressed manpage.
|
||||
* Fixed to allow compilation on non-i386 (Fixes #3361).
|
||||
* Added extended description (Fixes #3567).
|
||||
* Added diversion to avoid conflict with bison (Fixes #8086).
|
||||
|
||||
-- Vincent Renardias <vincent@waw.com> Sun, 20 Apr 1997 15:59:28 +0200
|
1
package/debian/compat
Normal file
1
package/debian/compat
Normal file
@ -0,0 +1 @@
|
||||
5
|
17
package/debian/control
Normal file
17
package/debian/control
Normal file
@ -0,0 +1,17 @@
|
||||
Source: byacc
|
||||
Maintainer: Dave Beckett <dajobe@debian.org>
|
||||
Section: devel
|
||||
Priority: extra
|
||||
Standards-Version: 3.8.4
|
||||
Build-Depends: debhelper (>= 5)
|
||||
Homepage: http://invisible-island.net/byacc/
|
||||
|
||||
Package: byacc
|
||||
Architecture: any
|
||||
Depends: ${shlibs:Depends}, ${misc:Depends}
|
||||
Description: public domain Berkeley LALR Yacc parser generator
|
||||
This package provides a parser generator utility that reads a grammar
|
||||
specification from a file and generates an LR(1) parser for it. The
|
||||
parsers consist of a set of LALR(1) parsing tables and a driver
|
||||
routine written in the C programming language. It has a public domain
|
||||
license which includes the generated C.
|
120
package/debian/copyright
Normal file
120
package/debian/copyright
Normal file
@ -0,0 +1,120 @@
|
||||
Upstream source http://dickey.his.com/byacc/byacc.html
|
||||
|
||||
Berkeley Yacc is in the public domain; changes made to it by the current
|
||||
maintainer are likewise unrestricted. That applies to most of the files.
|
||||
A few files (currently those related to autoconf scripting) have other
|
||||
licenses as noted here.
|
||||
|
||||
Current byacc upstream maintainer: Thomas Dickey <dickey@invisible-island.net>
|
||||
|
||||
Public domain notice and no warranty:
|
||||
-------------------------------------------------------------------------------
|
||||
Berkeley Yacc is an LALR(1) parser generator. Berkeley Yacc has been made
|
||||
as compatible as possible with AT&T Yacc. Berkeley Yacc can accept any input
|
||||
specification that conforms to the AT&T Yacc documentation. Specifications
|
||||
that take advantage of undocumented features of AT&T Yacc will probably be
|
||||
rejected.
|
||||
|
||||
Berkeley Yacc is distributed with no warranty whatever. The code
|
||||
is certain to contain errors. Neither the author nor any contributor
|
||||
takes responsibility for any consequences of its use.
|
||||
|
||||
Berkeley Yacc is in the public domain. The data structures and algorithms
|
||||
used in Berkeley Yacc are all either taken from documents available to the
|
||||
general public or are inventions of the author. Anyone may freely distribute
|
||||
source or binary forms of Berkeley Yacc whether unchanged or modified.
|
||||
Distributers may charge whatever fees they can obtain for Berkeley Yacc.
|
||||
Programs generated by Berkeley Yacc may be distributed freely.
|
||||
|
||||
Please report bugs to
|
||||
|
||||
robert.corbett@eng.Sun.COM
|
||||
|
||||
Include a small example if possible. Please include the banner string from
|
||||
skeleton.c with the bug report. Do not expect rapid responses.
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
Files: aclocal.m4
|
||||
Licence: other-BSD
|
||||
Copyright: 2004-2011,2012 by Thomas E. Dickey
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, distribute with modifications, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
||||
THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
Except as contained in this notice, the name(s) of the above copyright
|
||||
holders shall not be used in advertising or otherwise to promote the
|
||||
sale, use or other dealings in this Software without prior written
|
||||
authorization.
|
||||
|
||||
Files: install-sh
|
||||
Copyright: 1994 X Consortium
|
||||
Licence: other-BSD
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to
|
||||
deal in the Software without restriction, including without limitation the
|
||||
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
|
||||
TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
Except as contained in this notice, the name of the X Consortium shall not
|
||||
be used in advertising or otherwise to promote the sale, use or other deal-
|
||||
ings in this Software without prior written authorization from the X Consor-
|
||||
tium.
|
||||
|
||||
FSF changes to this file are in the public domain.
|
||||
|
||||
Calling this script install-sh is preferred over install.sh, to prevent
|
||||
`make' implicit rules from creating a file called install from it
|
||||
when there is no Makefile.
|
||||
|
||||
This script is compatible with the BSD install script, but was written
|
||||
from scratch. It can only install one file at a time, a restriction
|
||||
shared with many OS's install programs.
|
||||
|
||||
Files: debian/*
|
||||
Copyright: 2012 Thomas E. Dickey
|
||||
Licence: other-BSD
|
||||
Permission to use, copy, modify, and distribute this software and its
|
||||
documentation for any purpose and without fee is hereby granted,
|
||||
provided that the above copyright notice appear in all copies and that
|
||||
both that copyright notice and this permission notice appear in
|
||||
supporting documentation, and that the name of the above listed
|
||||
copyright holder(s) not be used in advertising or publicity pertaining
|
||||
to distribution of the software without specific, written prior
|
||||
permission.
|
||||
|
||||
THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD
|
||||
TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE
|
||||
LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
On Debian systems, the complete text of the GNU General
|
||||
Public License can be found in '/usr/share/common-licenses/GPL-2'
|
4
package/debian/docs
Normal file
4
package/debian/docs
Normal file
@ -0,0 +1,4 @@
|
||||
README
|
||||
ACKNOWLEDGEMENTS
|
||||
NEW_FEATURES
|
||||
NOTES
|
15
package/debian/postinst
Normal file
15
package/debian/postinst
Normal file
@ -0,0 +1,15 @@
|
||||
#! /bin/sh
|
||||
# postinst script for byacc
|
||||
|
||||
set -e
|
||||
|
||||
if [ $1 != "upgrade" ] ; then
|
||||
update-alternatives \
|
||||
--install /usr/bin/yacc yacc /usr/bin/byacc 80 \
|
||||
--slave /usr/share/man/man1/yacc.1.gz yaccman \
|
||||
/usr/share/man/man1/byacc.1.gz
|
||||
fi
|
||||
|
||||
#DEBHELPER#
|
||||
|
||||
exit 0
|
12
package/debian/prerm
Normal file
12
package/debian/prerm
Normal file
@ -0,0 +1,12 @@
|
||||
#! /bin/sh
|
||||
# prerm script for byacc
|
||||
|
||||
set -e
|
||||
|
||||
if [ $1 != "upgrade" ]; then
|
||||
update-alternatives --remove yacc /usr/bin/byacc
|
||||
fi
|
||||
|
||||
#DEBHELPER#
|
||||
|
||||
exit 0
|
93
package/debian/rules
Executable file
93
package/debian/rules
Executable file
@ -0,0 +1,93 @@
|
||||
#!/usr/bin/make -f
|
||||
# MAde with the aid of dh_make, by Craig Small
|
||||
# Sample debian/rules that uses debhelper. GNU copyright 1997 by Joey Hess.
|
||||
# Some lines taken from debmake, by Cristoph Lameter.
|
||||
|
||||
# Uncomment this to turn on verbose mode.
|
||||
#export DH_VERBOSE=1
|
||||
|
||||
# These are used for cross-compiling and for saving the configure script
|
||||
# from having to guess our platform (since we know it already)
|
||||
DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
|
||||
DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
|
||||
|
||||
CFLAGS =
|
||||
|
||||
ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
|
||||
CFLAGS += -O0
|
||||
else
|
||||
CFLAGS += -O2
|
||||
endif
|
||||
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
|
||||
INSTALL_PROGRAM += -s
|
||||
endif
|
||||
|
||||
|
||||
configure: configure-stamp
|
||||
configure-stamp:
|
||||
dh_testdir
|
||||
|
||||
CFLAGS="$(CFLAGS)" ./configure \
|
||||
--host=$(DEB_HOST_GNU_TYPE) \
|
||||
--build=$(DEB_BUILD_GNU_TYPE) \
|
||||
--prefix=/usr \
|
||||
--mandir=\$${prefix}/share/man \
|
||||
--sysconfdir=/etc \
|
||||
--program-transform-name='s,^,b,'
|
||||
|
||||
touch configure-stamp
|
||||
|
||||
build: build-stamp
|
||||
build-stamp: configure-stamp
|
||||
dh_testdir
|
||||
|
||||
$(MAKE)
|
||||
|
||||
touch build-stamp
|
||||
|
||||
clean:
|
||||
dh_testdir
|
||||
dh_testroot
|
||||
|
||||
[ ! -f Makefile ] || $(MAKE) clean
|
||||
|
||||
rm -f configure-stamp build-stamp install-stamp \
|
||||
config.cache config.h config.status config.log makefile
|
||||
|
||||
rm -f *.o yacc
|
||||
|
||||
dh_clean
|
||||
|
||||
install: install-stamp
|
||||
install-stamp: build-stamp
|
||||
dh_testdir
|
||||
dh_testroot
|
||||
dh_clean -k
|
||||
dh_installdirs
|
||||
|
||||
$(MAKE) install DESTDIR=$(CURDIR)/debian/byacc
|
||||
|
||||
touch install-stamp
|
||||
|
||||
# Build architecture-independent files here.
|
||||
binary-indep: build install
|
||||
# No binary-indep target.
|
||||
|
||||
# Build architecture-dependent files here.
|
||||
binary-arch: build install
|
||||
dh_testdir
|
||||
dh_testroot
|
||||
dh_installdocs
|
||||
dh_installexamples
|
||||
dh_installchangelogs CHANGES
|
||||
dh_strip
|
||||
dh_compress
|
||||
dh_fixperms
|
||||
dh_installdeb
|
||||
dh_shlibdeps
|
||||
dh_gencontrol
|
||||
dh_md5sums
|
||||
dh_builddeb
|
||||
|
||||
binary: binary-indep binary-arch
|
||||
.PHONY: build clean binary-indep binary-arch binary install install-stamp
|
1
package/debian/source/format
Normal file
1
package/debian/source/format
Normal file
@ -0,0 +1 @@
|
||||
3.0 (quilt)
|
4
package/debian/watch
Normal file
4
package/debian/watch
Normal file
@ -0,0 +1,4 @@
|
||||
version=3
|
||||
|
||||
opts=passive ftp://invisible-island.net/byacc/byacc-(\d+)\.tgz \
|
||||
debian uupdate
|
6
package/pkgsrc/DESCR
Normal file
6
package/pkgsrc/DESCR
Normal file
@ -0,0 +1,6 @@
|
||||
Berkeley Yacc (byacc) is a LALR(1) parser generator. Berkeley Yacc
|
||||
has been made as compatible as possible with AT&T Yacc. Berkeley
|
||||
Yacc can accept any input specification that conforms to the AT&T
|
||||
Yacc documentation.
|
||||
|
||||
Some programs depend on a byacc (instead of bison).
|
19
package/pkgsrc/Makefile
Normal file
19
package/pkgsrc/Makefile
Normal file
@ -0,0 +1,19 @@
|
||||
# $NetBSD: Makefile,v 1.9 2008/07/24 17:13:00 tonnerre Exp $
|
||||
#
|
||||
|
||||
DISTNAME= byacc-20050813
|
||||
PKGREVISION= 1
|
||||
CATEGORIES= devel
|
||||
MASTER_SITES= ftp://invisible-island.net/byacc/
|
||||
EXTRACT_SUFX= .tgz
|
||||
|
||||
MAINTAINER= pkgsrc-users@NetBSD.org
|
||||
HOMEPAGE= http://dickey.his.com/byacc/byacc.html
|
||||
COMMENT= Berkeley Yacc
|
||||
|
||||
PKG_DESTDIR_SUPPORT= user-destdir
|
||||
|
||||
GNU_CONFIGURE= YES
|
||||
MAKE_FILE= makefile
|
||||
|
||||
.include "../../mk/bsd.pkg.mk"
|
3
package/pkgsrc/PLIST
Normal file
3
package/pkgsrc/PLIST
Normal file
@ -0,0 +1,3 @@
|
||||
@comment $NetBSD: PLIST,v 1.2 2005/04/13 14:11:54 wiz Exp $
|
||||
bin/yacc
|
||||
man/man1/yacc.1
|
6
package/pkgsrc/distinfo
Normal file
6
package/pkgsrc/distinfo
Normal file
@ -0,0 +1,6 @@
|
||||
$NetBSD: distinfo,v 1.4 2008/07/24 17:13:00 tonnerre Exp $
|
||||
|
||||
SHA1 (byacc-20050813.tgz) = 3258494f3422eb3150944c1823af1c9c2c386062
|
||||
RMD160 (byacc-20050813.tgz) = 3ee159857a79025a83e2b0807577925fe460f816
|
||||
Size (byacc-20050813.tgz) = 138684 bytes
|
||||
SHA1 (patch-aa) = decae78775a5e0f1e1f7aaaa258da53903aa1f7a
|
439
skeleton.c
Normal file
439
skeleton.c
Normal file
@ -0,0 +1,439 @@
|
||||
/* $Id: skeleton.c,v 1.31 2011/09/07 09:37:59 tom Exp $ */
|
||||
|
||||
#include "defs.h"
|
||||
|
||||
/* The definition of yysccsid in the banner should be replaced with */
|
||||
/* a #pragma ident directive if the target C compiler supports */
|
||||
/* #pragma ident directives. */
|
||||
/* */
|
||||
/* If the skeleton is changed, the banner should be changed so that */
|
||||
/* the altered version can be easily distinguished from the original. */
|
||||
/* */
|
||||
/* The #defines included with the banner are there because they are */
|
||||
/* useful in subsequent code. The macros #defined in the header or */
|
||||
/* the body either are not useful outside of semantic actions or */
|
||||
/* are conditional. */
|
||||
|
||||
const char *const banner[] =
|
||||
{
|
||||
"#ifndef lint",
|
||||
"static const char yysccsid[] = \"@(#)yaccpar 1.9 (Berkeley) 02/21/93\";",
|
||||
"#endif",
|
||||
"",
|
||||
"#define YYBYACC 1",
|
||||
CONCAT1("#define YYMAJOR ", YYMAJOR),
|
||||
CONCAT1("#define YYMINOR ", YYMINOR),
|
||||
#ifdef YYPATCH
|
||||
CONCAT1("#define YYPATCH ", YYPATCH),
|
||||
#endif
|
||||
"",
|
||||
"#define YYEMPTY (-1)",
|
||||
"#define yyclearin (yychar = YYEMPTY)",
|
||||
"#define yyerrok (yyerrflag = 0)",
|
||||
"#define YYRECOVERING() (yyerrflag != 0)",
|
||||
"",
|
||||
0
|
||||
};
|
||||
|
||||
const char *const xdecls[] =
|
||||
{
|
||||
"",
|
||||
"extern int YYPARSE_DECL();",
|
||||
0
|
||||
};
|
||||
|
||||
const char *const tables[] =
|
||||
{
|
||||
"extern short yylhs[];",
|
||||
"extern short yylen[];",
|
||||
"extern short yydefred[];",
|
||||
"extern short yydgoto[];",
|
||||
"extern short yysindex[];",
|
||||
"extern short yyrindex[];",
|
||||
"extern short yygindex[];",
|
||||
"extern short yytable[];",
|
||||
"extern short yycheck[];",
|
||||
"",
|
||||
"#if YYDEBUG",
|
||||
"extern char *yyname[];",
|
||||
"extern char *yyrule[];",
|
||||
"#endif",
|
||||
0
|
||||
};
|
||||
|
||||
const char *const global_vars[] =
|
||||
{
|
||||
"",
|
||||
"int yydebug;",
|
||||
"int yynerrs;",
|
||||
0
|
||||
};
|
||||
|
||||
const char *const impure_vars[] =
|
||||
{
|
||||
"",
|
||||
"int yyerrflag;",
|
||||
"int yychar;",
|
||||
"YYSTYPE yyval;",
|
||||
"YYSTYPE yylval;",
|
||||
0
|
||||
};
|
||||
|
||||
const char *const hdr_defs[] =
|
||||
{
|
||||
"",
|
||||
"/* define the initial stack-sizes */",
|
||||
"#ifdef YYSTACKSIZE",
|
||||
"#undef YYMAXDEPTH",
|
||||
"#define YYMAXDEPTH YYSTACKSIZE",
|
||||
"#else",
|
||||
"#ifdef YYMAXDEPTH",
|
||||
"#define YYSTACKSIZE YYMAXDEPTH",
|
||||
"#else",
|
||||
"#define YYSTACKSIZE 500",
|
||||
"#define YYMAXDEPTH 500",
|
||||
"#endif",
|
||||
"#endif",
|
||||
"",
|
||||
"#define YYINITSTACKSIZE 500",
|
||||
"",
|
||||
"typedef struct {",
|
||||
" unsigned stacksize;",
|
||||
" short *s_base;",
|
||||
" short *s_mark;",
|
||||
" short *s_last;",
|
||||
" YYSTYPE *l_base;",
|
||||
" YYSTYPE *l_mark;",
|
||||
"} YYSTACKDATA;",
|
||||
0
|
||||
};
|
||||
|
||||
const char *const hdr_vars[] =
|
||||
{
|
||||
"/* variables for the parser stack */",
|
||||
"static YYSTACKDATA yystack;",
|
||||
0
|
||||
};
|
||||
|
||||
const char *const body_vars[] =
|
||||
{
|
||||
" int yyerrflag;",
|
||||
" int yychar;",
|
||||
" YYSTYPE yyval;",
|
||||
" YYSTYPE yylval;",
|
||||
"",
|
||||
" /* variables for the parser stack */",
|
||||
" YYSTACKDATA yystack;",
|
||||
0
|
||||
};
|
||||
|
||||
const char *const body_1[] =
|
||||
{
|
||||
"",
|
||||
"#if YYDEBUG",
|
||||
"#include <stdio.h> /* needed for printf */",
|
||||
"#endif",
|
||||
"",
|
||||
"#include <stdlib.h> /* needed for malloc, etc */",
|
||||
"#include <string.h> /* needed for memset */",
|
||||
"",
|
||||
"/* allocate initial stack or double stack size, up to YYMAXDEPTH */",
|
||||
"static int yygrowstack(YYSTACKDATA *data)",
|
||||
"{",
|
||||
" int i;",
|
||||
" unsigned newsize;",
|
||||
" short *newss;",
|
||||
" YYSTYPE *newvs;",
|
||||
"",
|
||||
" if ((newsize = data->stacksize) == 0)",
|
||||
" newsize = YYINITSTACKSIZE;",
|
||||
" else if (newsize >= YYMAXDEPTH)",
|
||||
" return -1;",
|
||||
" else if ((newsize *= 2) > YYMAXDEPTH)",
|
||||
" newsize = YYMAXDEPTH;",
|
||||
"",
|
||||
" i = data->s_mark - data->s_base;",
|
||||
" newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));",
|
||||
" if (newss == 0)",
|
||||
" return -1;",
|
||||
"",
|
||||
" data->s_base = newss;",
|
||||
" data->s_mark = newss + i;",
|
||||
"",
|
||||
" newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));",
|
||||
" if (newvs == 0)",
|
||||
" return -1;",
|
||||
"",
|
||||
" data->l_base = newvs;",
|
||||
" data->l_mark = newvs + i;",
|
||||
"",
|
||||
" data->stacksize = newsize;",
|
||||
" data->s_last = data->s_base + newsize - 1;",
|
||||
" return 0;",
|
||||
"}",
|
||||
"",
|
||||
"#if YYPURE || defined(YY_NO_LEAKS)",
|
||||
"static void yyfreestack(YYSTACKDATA *data)",
|
||||
"{",
|
||||
" free(data->s_base);",
|
||||
" free(data->l_base);",
|
||||
" memset(data, 0, sizeof(*data));",
|
||||
"}",
|
||||
"#else",
|
||||
"#define yyfreestack(data) /* nothing */",
|
||||
"#endif",
|
||||
"",
|
||||
"#define YYABORT goto yyabort",
|
||||
"#define YYREJECT goto yyabort",
|
||||
"#define YYACCEPT goto yyaccept",
|
||||
"#define YYERROR goto yyerrlab",
|
||||
"",
|
||||
"int",
|
||||
"YYPARSE_DECL()",
|
||||
"{",
|
||||
0
|
||||
};
|
||||
|
||||
const char *const body_2[] =
|
||||
{
|
||||
" int yym, yyn, yystate;",
|
||||
"#if YYDEBUG",
|
||||
" const char *yys;",
|
||||
"",
|
||||
" if ((yys = getenv(\"YYDEBUG\")) != 0)",
|
||||
" {",
|
||||
" yyn = *yys;",
|
||||
" if (yyn >= '0' && yyn <= '9')",
|
||||
" yydebug = yyn - '0';",
|
||||
" }",
|
||||
"#endif",
|
||||
"",
|
||||
" yynerrs = 0;",
|
||||
" yyerrflag = 0;",
|
||||
" yychar = YYEMPTY;",
|
||||
" yystate = 0;",
|
||||
"",
|
||||
"#if YYPURE",
|
||||
" memset(&yystack, 0, sizeof(yystack));",
|
||||
"#endif",
|
||||
"",
|
||||
" if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;",
|
||||
" yystack.s_mark = yystack.s_base;",
|
||||
" yystack.l_mark = yystack.l_base;",
|
||||
" yystate = 0;",
|
||||
" *yystack.s_mark = 0;",
|
||||
"",
|
||||
"yyloop:",
|
||||
" if ((yyn = yydefred[yystate]) != 0) goto yyreduce;",
|
||||
" if (yychar < 0)",
|
||||
" {",
|
||||
" if ((yychar = YYLEX) < 0) yychar = 0;",
|
||||
"#if YYDEBUG",
|
||||
" if (yydebug)",
|
||||
" {",
|
||||
" yys = 0;",
|
||||
" if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
|
||||
" if (!yys) yys = \"illegal-symbol\";",
|
||||
" printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
|
||||
" YYPREFIX, yystate, yychar, yys);",
|
||||
" }",
|
||||
"#endif",
|
||||
" }",
|
||||
" if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&",
|
||||
" yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
|
||||
" {",
|
||||
"#if YYDEBUG",
|
||||
" if (yydebug)",
|
||||
" printf(\"%sdebug: state %d, shifting to state %d\\n\",",
|
||||
" YYPREFIX, yystate, yytable[yyn]);",
|
||||
"#endif",
|
||||
" if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))",
|
||||
" {",
|
||||
" goto yyoverflow;",
|
||||
" }",
|
||||
" yystate = yytable[yyn];",
|
||||
" *++yystack.s_mark = yytable[yyn];",
|
||||
" *++yystack.l_mark = yylval;",
|
||||
" yychar = YYEMPTY;",
|
||||
" if (yyerrflag > 0) --yyerrflag;",
|
||||
" goto yyloop;",
|
||||
" }",
|
||||
" if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&",
|
||||
" yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
|
||||
" {",
|
||||
" yyn = yytable[yyn];",
|
||||
" goto yyreduce;",
|
||||
" }",
|
||||
" if (yyerrflag) goto yyinrecovery;",
|
||||
"",
|
||||
0
|
||||
};
|
||||
|
||||
const char *const body_3[] =
|
||||
{
|
||||
"",
|
||||
" goto yyerrlab;",
|
||||
"",
|
||||
"yyerrlab:",
|
||||
" ++yynerrs;",
|
||||
"",
|
||||
"yyinrecovery:",
|
||||
" if (yyerrflag < 3)",
|
||||
" {",
|
||||
" yyerrflag = 3;",
|
||||
" for (;;)",
|
||||
" {",
|
||||
" if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&",
|
||||
" yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)",
|
||||
" {",
|
||||
"#if YYDEBUG",
|
||||
" if (yydebug)",
|
||||
" printf(\"%sdebug: state %d, error recovery shifting\\",
|
||||
" to state %d\\n\", YYPREFIX, *yystack.s_mark, yytable[yyn]);",
|
||||
"#endif",
|
||||
" if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))",
|
||||
" {",
|
||||
" goto yyoverflow;",
|
||||
" }",
|
||||
" yystate = yytable[yyn];",
|
||||
" *++yystack.s_mark = yytable[yyn];",
|
||||
" *++yystack.l_mark = yylval;",
|
||||
" goto yyloop;",
|
||||
" }",
|
||||
" else",
|
||||
" {",
|
||||
"#if YYDEBUG",
|
||||
" if (yydebug)",
|
||||
" printf(\"%sdebug: error recovery discarding state %d\
|
||||
\\n\",",
|
||||
" YYPREFIX, *yystack.s_mark);",
|
||||
"#endif",
|
||||
" if (yystack.s_mark <= yystack.s_base) goto yyabort;",
|
||||
" --yystack.s_mark;",
|
||||
" --yystack.l_mark;",
|
||||
" }",
|
||||
" }",
|
||||
" }",
|
||||
" else",
|
||||
" {",
|
||||
" if (yychar == 0) goto yyabort;",
|
||||
"#if YYDEBUG",
|
||||
" if (yydebug)",
|
||||
" {",
|
||||
" yys = 0;",
|
||||
" if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
|
||||
" if (!yys) yys = \"illegal-symbol\";",
|
||||
" printf(\"%sdebug: state %d, error recovery discards token %d\
|
||||
(%s)\\n\",",
|
||||
" YYPREFIX, yystate, yychar, yys);",
|
||||
" }",
|
||||
"#endif",
|
||||
" yychar = YYEMPTY;",
|
||||
" goto yyloop;",
|
||||
" }",
|
||||
"",
|
||||
"yyreduce:",
|
||||
"#if YYDEBUG",
|
||||
" if (yydebug)",
|
||||
" printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\",",
|
||||
" YYPREFIX, yystate, yyn, yyrule[yyn]);",
|
||||
"#endif",
|
||||
" yym = yylen[yyn];",
|
||||
" if (yym)",
|
||||
" yyval = yystack.l_mark[1-yym];",
|
||||
" else",
|
||||
" memset(&yyval, 0, sizeof yyval);",
|
||||
" switch (yyn)",
|
||||
" {",
|
||||
0
|
||||
};
|
||||
|
||||
const char *const trailer[] =
|
||||
{
|
||||
" }",
|
||||
" yystack.s_mark -= yym;",
|
||||
" yystate = *yystack.s_mark;",
|
||||
" yystack.l_mark -= yym;",
|
||||
" yym = yylhs[yyn];",
|
||||
" if (yystate == 0 && yym == 0)",
|
||||
" {",
|
||||
"#if YYDEBUG",
|
||||
" if (yydebug)",
|
||||
" printf(\"%sdebug: after reduction, shifting from state 0 to\\",
|
||||
" state %d\\n\", YYPREFIX, YYFINAL);",
|
||||
"#endif",
|
||||
" yystate = YYFINAL;",
|
||||
" *++yystack.s_mark = YYFINAL;",
|
||||
" *++yystack.l_mark = yyval;",
|
||||
" if (yychar < 0)",
|
||||
" {",
|
||||
" if ((yychar = YYLEX) < 0) yychar = 0;",
|
||||
"#if YYDEBUG",
|
||||
" if (yydebug)",
|
||||
" {",
|
||||
" yys = 0;",
|
||||
" if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
|
||||
" if (!yys) yys = \"illegal-symbol\";",
|
||||
" printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
|
||||
" YYPREFIX, YYFINAL, yychar, yys);",
|
||||
" }",
|
||||
"#endif",
|
||||
" }",
|
||||
" if (yychar == 0) goto yyaccept;",
|
||||
" goto yyloop;",
|
||||
" }",
|
||||
" if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&",
|
||||
" yyn <= YYTABLESIZE && yycheck[yyn] == yystate)",
|
||||
" yystate = yytable[yyn];",
|
||||
" else",
|
||||
" yystate = yydgoto[yym];",
|
||||
"#if YYDEBUG",
|
||||
" if (yydebug)",
|
||||
" printf(\"%sdebug: after reduction, shifting from state %d \\",
|
||||
"to state %d\\n\", YYPREFIX, *yystack.s_mark, yystate);",
|
||||
"#endif",
|
||||
" if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))",
|
||||
" {",
|
||||
" goto yyoverflow;",
|
||||
" }",
|
||||
" *++yystack.s_mark = (short) yystate;",
|
||||
" *++yystack.l_mark = yyval;",
|
||||
" goto yyloop;",
|
||||
"",
|
||||
"yyoverflow:",
|
||||
0
|
||||
};
|
||||
|
||||
const char *const trailer_2[] =
|
||||
{
|
||||
"",
|
||||
"yyabort:",
|
||||
" yyfreestack(&yystack);",
|
||||
" return (1);",
|
||||
"",
|
||||
"yyaccept:",
|
||||
" yyfreestack(&yystack);",
|
||||
" return (0);",
|
||||
"}",
|
||||
0
|
||||
};
|
||||
|
||||
void
|
||||
write_section(FILE * fp, const char *const section[])
|
||||
{
|
||||
int c;
|
||||
int i;
|
||||
const char *s;
|
||||
|
||||
for (i = 0; (s = section[i]) != 0; ++i)
|
||||
{
|
||||
while ((c = *s) != 0)
|
||||
{
|
||||
putc(c, fp);
|
||||
++s;
|
||||
}
|
||||
if (fp == code_file)
|
||||
++outline;
|
||||
putc('\n', fp);
|
||||
}
|
||||
}
|
117
symtab.c
Normal file
117
symtab.c
Normal file
@ -0,0 +1,117 @@
|
||||
/* $Id: symtab.c,v 1.9 2010/11/24 15:12:29 tom Exp $ */
|
||||
|
||||
#include "defs.h"
|
||||
|
||||
/* TABLE_SIZE is the number of entries in the symbol table. */
|
||||
/* TABLE_SIZE must be a power of two. */
|
||||
|
||||
#define TABLE_SIZE 1024
|
||||
|
||||
static bucket **symbol_table = 0;
|
||||
bucket *first_symbol;
|
||||
bucket *last_symbol;
|
||||
|
||||
static int
|
||||
hash(const char *name)
|
||||
{
|
||||
const char *s;
|
||||
int c, k;
|
||||
|
||||
assert(name && *name);
|
||||
s = name;
|
||||
k = *s;
|
||||
while ((c = *++s) != 0)
|
||||
k = (31 * k + c) & (TABLE_SIZE - 1);
|
||||
|
||||
return (k);
|
||||
}
|
||||
|
||||
bucket *
|
||||
make_bucket(const char *name)
|
||||
{
|
||||
bucket *bp;
|
||||
|
||||
assert(name != 0);
|
||||
|
||||
bp = (bucket *)MALLOC(sizeof(bucket));
|
||||
NO_SPACE(bp);
|
||||
|
||||
bp->link = 0;
|
||||
bp->next = 0;
|
||||
|
||||
bp->name = MALLOC(strlen(name) + 1);
|
||||
NO_SPACE(bp->name);
|
||||
|
||||
bp->tag = 0;
|
||||
bp->value = UNDEFINED;
|
||||
bp->index = 0;
|
||||
bp->prec = 0;
|
||||
bp->class = UNKNOWN;
|
||||
bp->assoc = TOKEN;
|
||||
strcpy(bp->name, name);
|
||||
|
||||
return (bp);
|
||||
}
|
||||
|
||||
bucket *
|
||||
lookup(const char *name)
|
||||
{
|
||||
bucket *bp, **bpp;
|
||||
|
||||
bpp = symbol_table + hash(name);
|
||||
bp = *bpp;
|
||||
|
||||
while (bp)
|
||||
{
|
||||
if (strcmp(name, bp->name) == 0)
|
||||
return (bp);
|
||||
bpp = &bp->link;
|
||||
bp = *bpp;
|
||||
}
|
||||
|
||||
*bpp = bp = make_bucket(name);
|
||||
last_symbol->next = bp;
|
||||
last_symbol = bp;
|
||||
|
||||
return (bp);
|
||||
}
|
||||
|
||||
void
|
||||
create_symbol_table(void)
|
||||
{
|
||||
int i;
|
||||
bucket *bp;
|
||||
|
||||
symbol_table = (bucket **)MALLOC(TABLE_SIZE * sizeof(bucket *));
|
||||
NO_SPACE(symbol_table);
|
||||
|
||||
for (i = 0; i < TABLE_SIZE; i++)
|
||||
symbol_table[i] = 0;
|
||||
|
||||
bp = make_bucket("error");
|
||||
bp->index = 1;
|
||||
bp->class = TERM;
|
||||
|
||||
first_symbol = bp;
|
||||
last_symbol = bp;
|
||||
symbol_table[hash("error")] = bp;
|
||||
}
|
||||
|
||||
void
|
||||
free_symbol_table(void)
|
||||
{
|
||||
FREE(symbol_table);
|
||||
symbol_table = 0;
|
||||
}
|
||||
|
||||
void
|
||||
free_symbols(void)
|
||||
{
|
||||
bucket *p, *q;
|
||||
|
||||
for (p = first_symbol; p; p = q)
|
||||
{
|
||||
q = p->next;
|
||||
FREE(p);
|
||||
}
|
||||
}
|
4
test/README
Normal file
4
test/README
Normal file
@ -0,0 +1,4 @@
|
||||
-- $Id: README,v 1.1 2004/03/28 19:10:48 tom Exp $
|
||||
|
||||
The files in this directory are input (.y) and output (.output, .tab.c, .tab.h)
|
||||
examples.
|
461
test/calc.output
Normal file
461
test/calc.output
Normal file
@ -0,0 +1,461 @@
|
||||
0 $accept : list $end
|
||||
|
||||
1 list :
|
||||
2 | list stat '\n'
|
||||
3 | list error '\n'
|
||||
|
||||
4 stat : expr
|
||||
5 | LETTER '=' expr
|
||||
|
||||
6 expr : '(' expr ')'
|
||||
7 | expr '+' expr
|
||||
8 | expr '-' expr
|
||||
9 | expr '*' expr
|
||||
10 | expr '/' expr
|
||||
11 | expr '%' expr
|
||||
12 | expr '&' expr
|
||||
13 | expr '|' expr
|
||||
14 | '-' expr
|
||||
15 | LETTER
|
||||
16 | number
|
||||
|
||||
17 number : DIGIT
|
||||
18 | number DIGIT
|
||||
|
||||
state 0
|
||||
$accept : . list $end (0)
|
||||
list : . (1)
|
||||
|
||||
. reduce 1
|
||||
|
||||
list goto 1
|
||||
|
||||
|
||||
state 1
|
||||
$accept : list . $end (0)
|
||||
list : list . stat '\n' (2)
|
||||
list : list . error '\n' (3)
|
||||
|
||||
$end accept
|
||||
error shift 2
|
||||
DIGIT shift 3
|
||||
LETTER shift 4
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
stat goto 7
|
||||
expr goto 8
|
||||
number goto 9
|
||||
|
||||
|
||||
state 2
|
||||
list : list error . '\n' (3)
|
||||
|
||||
'\n' shift 10
|
||||
. error
|
||||
|
||||
|
||||
state 3
|
||||
number : DIGIT . (17)
|
||||
|
||||
. reduce 17
|
||||
|
||||
|
||||
state 4
|
||||
stat : LETTER . '=' expr (5)
|
||||
expr : LETTER . (15)
|
||||
|
||||
'=' shift 11
|
||||
'|' reduce 15
|
||||
'&' reduce 15
|
||||
'+' reduce 15
|
||||
'-' reduce 15
|
||||
'*' reduce 15
|
||||
'/' reduce 15
|
||||
'%' reduce 15
|
||||
'\n' reduce 15
|
||||
|
||||
|
||||
state 5
|
||||
expr : '-' . expr (14)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 13
|
||||
number goto 9
|
||||
|
||||
|
||||
state 6
|
||||
expr : '(' . expr ')' (6)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 14
|
||||
number goto 9
|
||||
|
||||
|
||||
state 7
|
||||
list : list stat . '\n' (2)
|
||||
|
||||
'\n' shift 15
|
||||
. error
|
||||
|
||||
|
||||
state 8
|
||||
stat : expr . (4)
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
'|' shift 16
|
||||
'&' shift 17
|
||||
'+' shift 18
|
||||
'-' shift 19
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
'\n' reduce 4
|
||||
|
||||
|
||||
state 9
|
||||
expr : number . (16)
|
||||
number : number . DIGIT (18)
|
||||
|
||||
DIGIT shift 23
|
||||
'|' reduce 16
|
||||
'&' reduce 16
|
||||
'+' reduce 16
|
||||
'-' reduce 16
|
||||
'*' reduce 16
|
||||
'/' reduce 16
|
||||
'%' reduce 16
|
||||
'\n' reduce 16
|
||||
')' reduce 16
|
||||
|
||||
|
||||
state 10
|
||||
list : list error '\n' . (3)
|
||||
|
||||
. reduce 3
|
||||
|
||||
|
||||
state 11
|
||||
stat : LETTER '=' . expr (5)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 24
|
||||
number goto 9
|
||||
|
||||
|
||||
state 12
|
||||
expr : LETTER . (15)
|
||||
|
||||
. reduce 15
|
||||
|
||||
|
||||
state 13
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
expr : '-' expr . (14)
|
||||
|
||||
. reduce 14
|
||||
|
||||
|
||||
state 14
|
||||
expr : '(' expr . ')' (6)
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
'|' shift 16
|
||||
'&' shift 17
|
||||
'+' shift 18
|
||||
'-' shift 19
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
')' shift 25
|
||||
. error
|
||||
|
||||
|
||||
state 15
|
||||
list : list stat '\n' . (2)
|
||||
|
||||
. reduce 2
|
||||
|
||||
|
||||
state 16
|
||||
expr : expr '|' . expr (13)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 26
|
||||
number goto 9
|
||||
|
||||
|
||||
state 17
|
||||
expr : expr '&' . expr (12)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 27
|
||||
number goto 9
|
||||
|
||||
|
||||
state 18
|
||||
expr : expr '+' . expr (7)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 28
|
||||
number goto 9
|
||||
|
||||
|
||||
state 19
|
||||
expr : expr '-' . expr (8)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 29
|
||||
number goto 9
|
||||
|
||||
|
||||
state 20
|
||||
expr : expr '*' . expr (9)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 30
|
||||
number goto 9
|
||||
|
||||
|
||||
state 21
|
||||
expr : expr '/' . expr (10)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 31
|
||||
number goto 9
|
||||
|
||||
|
||||
state 22
|
||||
expr : expr '%' . expr (11)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 32
|
||||
number goto 9
|
||||
|
||||
|
||||
state 23
|
||||
number : number DIGIT . (18)
|
||||
|
||||
. reduce 18
|
||||
|
||||
|
||||
state 24
|
||||
stat : LETTER '=' expr . (5)
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
'|' shift 16
|
||||
'&' shift 17
|
||||
'+' shift 18
|
||||
'-' shift 19
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
'\n' reduce 5
|
||||
|
||||
|
||||
state 25
|
||||
expr : '(' expr ')' . (6)
|
||||
|
||||
. reduce 6
|
||||
|
||||
|
||||
state 26
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
expr : expr '|' expr . (13)
|
||||
|
||||
'&' shift 17
|
||||
'+' shift 18
|
||||
'-' shift 19
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
'|' reduce 13
|
||||
'\n' reduce 13
|
||||
')' reduce 13
|
||||
|
||||
|
||||
state 27
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr '&' expr . (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
'+' shift 18
|
||||
'-' shift 19
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
'|' reduce 12
|
||||
'&' reduce 12
|
||||
'\n' reduce 12
|
||||
')' reduce 12
|
||||
|
||||
|
||||
state 28
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr '+' expr . (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
'|' reduce 7
|
||||
'&' reduce 7
|
||||
'+' reduce 7
|
||||
'-' reduce 7
|
||||
'\n' reduce 7
|
||||
')' reduce 7
|
||||
|
||||
|
||||
state 29
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr '-' expr . (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
'|' reduce 8
|
||||
'&' reduce 8
|
||||
'+' reduce 8
|
||||
'-' reduce 8
|
||||
'\n' reduce 8
|
||||
')' reduce 8
|
||||
|
||||
|
||||
state 30
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr '*' expr . (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
. reduce 9
|
||||
|
||||
|
||||
state 31
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr '/' expr . (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
. reduce 10
|
||||
|
||||
|
||||
state 32
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr '%' expr . (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
. reduce 11
|
||||
|
||||
|
||||
16 terminals, 5 nonterminals
|
||||
19 grammar rules, 33 states
|
673
test/calc.tab.c
Normal file
673
test/calc.tab.c
Normal file
@ -0,0 +1,673 @@
|
||||
#ifndef lint
|
||||
static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
|
||||
#endif
|
||||
|
||||
#define YYBYACC 1
|
||||
#define YYMAJOR 1
|
||||
#define YYMINOR 9
|
||||
|
||||
#define YYEMPTY (-1)
|
||||
#define yyclearin (yychar = YYEMPTY)
|
||||
#define yyerrok (yyerrflag = 0)
|
||||
#define YYRECOVERING() (yyerrflag != 0)
|
||||
|
||||
|
||||
#ifndef yyparse
|
||||
#define yyparse calc_parse
|
||||
#endif /* yyparse */
|
||||
|
||||
#ifndef yylex
|
||||
#define yylex calc_lex
|
||||
#endif /* yylex */
|
||||
|
||||
#ifndef yyerror
|
||||
#define yyerror calc_error
|
||||
#endif /* yyerror */
|
||||
|
||||
#ifndef yychar
|
||||
#define yychar calc_char
|
||||
#endif /* yychar */
|
||||
|
||||
#ifndef yyval
|
||||
#define yyval calc_val
|
||||
#endif /* yyval */
|
||||
|
||||
#ifndef yylval
|
||||
#define yylval calc_lval
|
||||
#endif /* yylval */
|
||||
|
||||
#ifndef yydebug
|
||||
#define yydebug calc_debug
|
||||
#endif /* yydebug */
|
||||
|
||||
#ifndef yynerrs
|
||||
#define yynerrs calc_nerrs
|
||||
#endif /* yynerrs */
|
||||
|
||||
#ifndef yyerrflag
|
||||
#define yyerrflag calc_errflag
|
||||
#endif /* yyerrflag */
|
||||
|
||||
#ifndef yylhs
|
||||
#define yylhs calc_lhs
|
||||
#endif /* yylhs */
|
||||
|
||||
#ifndef yylen
|
||||
#define yylen calc_len
|
||||
#endif /* yylen */
|
||||
|
||||
#ifndef yydefred
|
||||
#define yydefred calc_defred
|
||||
#endif /* yydefred */
|
||||
|
||||
#ifndef yydgoto
|
||||
#define yydgoto calc_dgoto
|
||||
#endif /* yydgoto */
|
||||
|
||||
#ifndef yysindex
|
||||
#define yysindex calc_sindex
|
||||
#endif /* yysindex */
|
||||
|
||||
#ifndef yyrindex
|
||||
#define yyrindex calc_rindex
|
||||
#endif /* yyrindex */
|
||||
|
||||
#ifndef yygindex
|
||||
#define yygindex calc_gindex
|
||||
#endif /* yygindex */
|
||||
|
||||
#ifndef yytable
|
||||
#define yytable calc_table
|
||||
#endif /* yytable */
|
||||
|
||||
#ifndef yycheck
|
||||
#define yycheck calc_check
|
||||
#endif /* yycheck */
|
||||
|
||||
#ifndef yyname
|
||||
#define yyname calc_name
|
||||
#endif /* yyname */
|
||||
|
||||
#ifndef yyrule
|
||||
#define yyrule calc_rule
|
||||
#endif /* yyrule */
|
||||
#define YYPREFIX "calc_"
|
||||
|
||||
#define YYPURE 0
|
||||
|
||||
#line 2 "calc.y"
|
||||
# include <stdio.h>
|
||||
# include <ctype.h>
|
||||
|
||||
int regs[26];
|
||||
int base;
|
||||
|
||||
extern int yylex(void);
|
||||
static void yyerror(const char *s);
|
||||
|
||||
#line 109 "calc.tab.c"
|
||||
|
||||
#ifndef YYSTYPE
|
||||
typedef int YYSTYPE;
|
||||
#endif
|
||||
|
||||
/* compatibility with bison */
|
||||
#ifdef YYPARSE_PARAM
|
||||
/* compatibility with FreeBSD */
|
||||
# ifdef YYPARSE_PARAM_TYPE
|
||||
# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
|
||||
# else
|
||||
# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
|
||||
# endif
|
||||
#else
|
||||
# define YYPARSE_DECL() yyparse(void)
|
||||
#endif
|
||||
|
||||
/* Parameters sent to lex. */
|
||||
#ifdef YYLEX_PARAM
|
||||
# define YYLEX_DECL() yylex(void *YYLEX_PARAM)
|
||||
# define YYLEX yylex(YYLEX_PARAM)
|
||||
#else
|
||||
# define YYLEX_DECL() yylex(void)
|
||||
# define YYLEX yylex()
|
||||
#endif
|
||||
|
||||
/* Parameters sent to yyerror. */
|
||||
#ifndef YYERROR_DECL
|
||||
#define YYERROR_DECL() yyerror(const char *s)
|
||||
#endif
|
||||
#ifndef YYERROR_CALL
|
||||
#define YYERROR_CALL(msg) yyerror(msg)
|
||||
#endif
|
||||
|
||||
extern int YYPARSE_DECL();
|
||||
|
||||
#define DIGIT 257
|
||||
#define LETTER 258
|
||||
#define UMINUS 259
|
||||
#define YYERRCODE 256
|
||||
static const short calc_lhs[] = { -1,
|
||||
0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 3, 3,
|
||||
};
|
||||
static const short calc_len[] = { 2,
|
||||
0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 2, 1, 1, 1, 2,
|
||||
};
|
||||
static const short calc_defred[] = { 1,
|
||||
0, 0, 17, 0, 0, 0, 0, 0, 0, 3,
|
||||
0, 15, 14, 0, 2, 0, 0, 0, 0, 0,
|
||||
0, 0, 18, 0, 6, 0, 0, 0, 0, 9,
|
||||
10, 11,
|
||||
};
|
||||
static const short calc_dgoto[] = { 1,
|
||||
7, 8, 9,
|
||||
};
|
||||
static const short calc_sindex[] = { 0,
|
||||
-40, -7, 0, -55, -38, -38, 1, -29, -247, 0,
|
||||
-38, 0, 0, 22, 0, -38, -38, -38, -38, -38,
|
||||
-38, -38, 0, -29, 0, 51, 60, -20, -20, 0,
|
||||
0, 0,
|
||||
};
|
||||
static const short calc_rindex[] = { 0,
|
||||
0, 0, 0, 2, 0, 0, 0, 9, -9, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 10, 0, -6, 14, 5, 13, 0,
|
||||
0, 0,
|
||||
};
|
||||
static const short calc_gindex[] = { 0,
|
||||
0, 65, 0,
|
||||
};
|
||||
#define YYTABLESIZE 220
|
||||
static const short calc_table[] = { 6,
|
||||
16, 6, 10, 13, 5, 11, 5, 22, 17, 23,
|
||||
15, 15, 20, 18, 7, 19, 22, 21, 4, 5,
|
||||
0, 20, 8, 12, 0, 0, 21, 16, 16, 0,
|
||||
0, 16, 16, 16, 13, 16, 0, 16, 15, 15,
|
||||
0, 0, 7, 15, 15, 7, 15, 7, 15, 7,
|
||||
8, 12, 0, 8, 12, 8, 0, 8, 22, 17,
|
||||
0, 0, 25, 20, 18, 0, 19, 0, 21, 13,
|
||||
14, 0, 0, 0, 0, 24, 0, 0, 0, 0,
|
||||
26, 27, 28, 29, 30, 31, 32, 22, 17, 0,
|
||||
0, 0, 20, 18, 16, 19, 22, 21, 0, 0,
|
||||
0, 20, 18, 0, 19, 0, 21, 0, 0, 0,
|
||||
0, 0, 0, 0, 16, 0, 0, 13, 0, 0,
|
||||
0, 0, 0, 0, 0, 15, 0, 0, 7, 0,
|
||||
0, 0, 0, 0, 0, 0, 8, 12, 0, 0,
|
||||
0, 0, 0, 0, 0, 16, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 2, 3, 4, 3, 12,
|
||||
};
|
||||
static const short calc_check[] = { 40,
|
||||
10, 40, 10, 10, 45, 61, 45, 37, 38, 257,
|
||||
10, 10, 42, 43, 10, 45, 37, 47, 10, 10,
|
||||
-1, 42, 10, 10, -1, -1, 47, 37, 38, -1,
|
||||
-1, 41, 42, 43, 41, 45, -1, 47, 37, 38,
|
||||
-1, -1, 38, 42, 43, 41, 45, 43, 47, 45,
|
||||
38, 38, -1, 41, 41, 43, -1, 45, 37, 38,
|
||||
-1, -1, 41, 42, 43, -1, 45, -1, 47, 5,
|
||||
6, -1, -1, -1, -1, 11, -1, -1, -1, -1,
|
||||
16, 17, 18, 19, 20, 21, 22, 37, 38, -1,
|
||||
-1, -1, 42, 43, 124, 45, 37, 47, -1, -1,
|
||||
-1, 42, 43, -1, 45, -1, 47, -1, -1, -1,
|
||||
-1, -1, -1, -1, 124, -1, -1, 124, -1, -1,
|
||||
-1, -1, -1, -1, -1, 124, -1, -1, 124, -1,
|
||||
-1, -1, -1, -1, -1, -1, 124, 124, -1, -1,
|
||||
-1, -1, -1, -1, -1, 124, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, 256, 257, 258, 257, 258,
|
||||
};
|
||||
#define YYFINAL 1
|
||||
#ifndef YYDEBUG
|
||||
#define YYDEBUG 0
|
||||
#endif
|
||||
#define YYMAXTOKEN 259
|
||||
#if YYDEBUG
|
||||
static const char *yyname[] = {
|
||||
|
||||
"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'",0,"'-'",0,"'/'",0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'|'",0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,"DIGIT","LETTER","UMINUS",
|
||||
};
|
||||
static const char *yyrule[] = {
|
||||
"$accept : list",
|
||||
"list :",
|
||||
"list : list stat '\\n'",
|
||||
"list : list error '\\n'",
|
||||
"stat : expr",
|
||||
"stat : LETTER '=' expr",
|
||||
"expr : '(' expr ')'",
|
||||
"expr : expr '+' expr",
|
||||
"expr : expr '-' expr",
|
||||
"expr : expr '*' expr",
|
||||
"expr : expr '/' expr",
|
||||
"expr : expr '%' expr",
|
||||
"expr : expr '&' expr",
|
||||
"expr : expr '|' expr",
|
||||
"expr : '-' expr",
|
||||
"expr : LETTER",
|
||||
"expr : number",
|
||||
"number : DIGIT",
|
||||
"number : number DIGIT",
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
int yydebug;
|
||||
int yynerrs;
|
||||
|
||||
int yyerrflag;
|
||||
int yychar;
|
||||
YYSTYPE yyval;
|
||||
YYSTYPE yylval;
|
||||
|
||||
/* define the initial stack-sizes */
|
||||
#ifdef YYSTACKSIZE
|
||||
#undef YYMAXDEPTH
|
||||
#define YYMAXDEPTH YYSTACKSIZE
|
||||
#else
|
||||
#ifdef YYMAXDEPTH
|
||||
#define YYSTACKSIZE YYMAXDEPTH
|
||||
#else
|
||||
#define YYSTACKSIZE 500
|
||||
#define YYMAXDEPTH 500
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define YYINITSTACKSIZE 500
|
||||
|
||||
typedef struct {
|
||||
unsigned stacksize;
|
||||
short *s_base;
|
||||
short *s_mark;
|
||||
short *s_last;
|
||||
YYSTYPE *l_base;
|
||||
YYSTYPE *l_mark;
|
||||
} YYSTACKDATA;
|
||||
/* variables for the parser stack */
|
||||
static YYSTACKDATA yystack;
|
||||
#line 66 "calc.y"
|
||||
/* start of programs */
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
while(!feof(stdin)) {
|
||||
yyparse();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
yyerror(const char *s)
|
||||
{
|
||||
fprintf(stderr, "%s\n", s);
|
||||
}
|
||||
|
||||
int
|
||||
yylex(void)
|
||||
{
|
||||
/* lexical analysis routine */
|
||||
/* returns LETTER for a lower case letter, yylval = 0 through 25 */
|
||||
/* return DIGIT for a digit, yylval = 0 through 9 */
|
||||
/* all other characters are returned immediately */
|
||||
|
||||
int c;
|
||||
|
||||
while( (c=getchar()) == ' ' ) { /* skip blanks */ }
|
||||
|
||||
/* c is now nonblank */
|
||||
|
||||
if( islower( c )) {
|
||||
yylval = c - 'a';
|
||||
return ( LETTER );
|
||||
}
|
||||
if( isdigit( c )) {
|
||||
yylval = c - '0';
|
||||
return ( DIGIT );
|
||||
}
|
||||
return( c );
|
||||
}
|
||||
#line 347 "calc.tab.c"
|
||||
|
||||
#if YYDEBUG
|
||||
#include <stdio.h> /* needed for printf */
|
||||
#endif
|
||||
|
||||
#include <stdlib.h> /* needed for malloc, etc */
|
||||
#include <string.h> /* needed for memset */
|
||||
|
||||
/* allocate initial stack or double stack size, up to YYMAXDEPTH */
|
||||
static int yygrowstack(YYSTACKDATA *data)
|
||||
{
|
||||
int i;
|
||||
unsigned newsize;
|
||||
short *newss;
|
||||
YYSTYPE *newvs;
|
||||
|
||||
if ((newsize = data->stacksize) == 0)
|
||||
newsize = YYINITSTACKSIZE;
|
||||
else if (newsize >= YYMAXDEPTH)
|
||||
return -1;
|
||||
else if ((newsize *= 2) > YYMAXDEPTH)
|
||||
newsize = YYMAXDEPTH;
|
||||
|
||||
i = data->s_mark - data->s_base;
|
||||
newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
|
||||
if (newss == 0)
|
||||
return -1;
|
||||
|
||||
data->s_base = newss;
|
||||
data->s_mark = newss + i;
|
||||
|
||||
newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
|
||||
if (newvs == 0)
|
||||
return -1;
|
||||
|
||||
data->l_base = newvs;
|
||||
data->l_mark = newvs + i;
|
||||
|
||||
data->stacksize = newsize;
|
||||
data->s_last = data->s_base + newsize - 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if YYPURE || defined(YY_NO_LEAKS)
|
||||
static void yyfreestack(YYSTACKDATA *data)
|
||||
{
|
||||
free(data->s_base);
|
||||
free(data->l_base);
|
||||
memset(data, 0, sizeof(*data));
|
||||
}
|
||||
#else
|
||||
#define yyfreestack(data) /* nothing */
|
||||
#endif
|
||||
|
||||
#define YYABORT goto yyabort
|
||||
#define YYREJECT goto yyabort
|
||||
#define YYACCEPT goto yyaccept
|
||||
#define YYERROR goto yyerrlab
|
||||
|
||||
int
|
||||
YYPARSE_DECL()
|
||||
{
|
||||
int yym, yyn, yystate;
|
||||
#if YYDEBUG
|
||||
const char *yys;
|
||||
|
||||
if ((yys = getenv("YYDEBUG")) != 0)
|
||||
{
|
||||
yyn = *yys;
|
||||
if (yyn >= '0' && yyn <= '9')
|
||||
yydebug = yyn - '0';
|
||||
}
|
||||
#endif
|
||||
|
||||
yynerrs = 0;
|
||||
yyerrflag = 0;
|
||||
yychar = YYEMPTY;
|
||||
yystate = 0;
|
||||
|
||||
#if YYPURE
|
||||
memset(&yystack, 0, sizeof(yystack));
|
||||
#endif
|
||||
|
||||
if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
|
||||
yystack.s_mark = yystack.s_base;
|
||||
yystack.l_mark = yystack.l_base;
|
||||
yystate = 0;
|
||||
*yystack.s_mark = 0;
|
||||
|
||||
yyloop:
|
||||
if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
|
||||
if (yychar < 0)
|
||||
{
|
||||
if ((yychar = YYLEX) < 0) yychar = 0;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, reading %d (%s)\n",
|
||||
YYPREFIX, yystate, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, shifting to state %d\n",
|
||||
YYPREFIX, yystate, yytable[yyn]);
|
||||
#endif
|
||||
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
yystate = yytable[yyn];
|
||||
*++yystack.s_mark = yytable[yyn];
|
||||
*++yystack.l_mark = yylval;
|
||||
yychar = YYEMPTY;
|
||||
if (yyerrflag > 0) --yyerrflag;
|
||||
goto yyloop;
|
||||
}
|
||||
if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
|
||||
{
|
||||
yyn = yytable[yyn];
|
||||
goto yyreduce;
|
||||
}
|
||||
if (yyerrflag) goto yyinrecovery;
|
||||
|
||||
yyerror("syntax error");
|
||||
|
||||
goto yyerrlab;
|
||||
|
||||
yyerrlab:
|
||||
++yynerrs;
|
||||
|
||||
yyinrecovery:
|
||||
if (yyerrflag < 3)
|
||||
{
|
||||
yyerrflag = 3;
|
||||
for (;;)
|
||||
{
|
||||
if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, error recovery shifting\
|
||||
to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
|
||||
#endif
|
||||
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
yystate = yytable[yyn];
|
||||
*++yystack.s_mark = yytable[yyn];
|
||||
*++yystack.l_mark = yylval;
|
||||
goto yyloop;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: error recovery discarding state %d\n",
|
||||
YYPREFIX, *yystack.s_mark);
|
||||
#endif
|
||||
if (yystack.s_mark <= yystack.s_base) goto yyabort;
|
||||
--yystack.s_mark;
|
||||
--yystack.l_mark;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (yychar == 0) goto yyabort;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
|
||||
YYPREFIX, yystate, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
yychar = YYEMPTY;
|
||||
goto yyloop;
|
||||
}
|
||||
|
||||
yyreduce:
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, reducing by rule %d (%s)\n",
|
||||
YYPREFIX, yystate, yyn, yyrule[yyn]);
|
||||
#endif
|
||||
yym = yylen[yyn];
|
||||
if (yym)
|
||||
yyval = yystack.l_mark[1-yym];
|
||||
else
|
||||
memset(&yyval, 0, sizeof yyval);
|
||||
switch (yyn)
|
||||
{
|
||||
case 3:
|
||||
#line 28 "calc.y"
|
||||
{ yyerrok ; }
|
||||
break;
|
||||
case 4:
|
||||
#line 32 "calc.y"
|
||||
{ printf("%d\n",yystack.l_mark[0]);}
|
||||
break;
|
||||
case 5:
|
||||
#line 34 "calc.y"
|
||||
{ regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
|
||||
break;
|
||||
case 6:
|
||||
#line 38 "calc.y"
|
||||
{ yyval = yystack.l_mark[-1]; }
|
||||
break;
|
||||
case 7:
|
||||
#line 40 "calc.y"
|
||||
{ yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
|
||||
break;
|
||||
case 8:
|
||||
#line 42 "calc.y"
|
||||
{ yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
|
||||
break;
|
||||
case 9:
|
||||
#line 44 "calc.y"
|
||||
{ yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
|
||||
break;
|
||||
case 10:
|
||||
#line 46 "calc.y"
|
||||
{ yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
|
||||
break;
|
||||
case 11:
|
||||
#line 48 "calc.y"
|
||||
{ yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
|
||||
break;
|
||||
case 12:
|
||||
#line 50 "calc.y"
|
||||
{ yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
|
||||
break;
|
||||
case 13:
|
||||
#line 52 "calc.y"
|
||||
{ yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
|
||||
break;
|
||||
case 14:
|
||||
#line 54 "calc.y"
|
||||
{ yyval = - yystack.l_mark[0]; }
|
||||
break;
|
||||
case 15:
|
||||
#line 56 "calc.y"
|
||||
{ yyval = regs[yystack.l_mark[0]]; }
|
||||
break;
|
||||
case 17:
|
||||
#line 61 "calc.y"
|
||||
{ yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; }
|
||||
break;
|
||||
case 18:
|
||||
#line 63 "calc.y"
|
||||
{ yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; }
|
||||
break;
|
||||
#line 613 "calc.tab.c"
|
||||
}
|
||||
yystack.s_mark -= yym;
|
||||
yystate = *yystack.s_mark;
|
||||
yystack.l_mark -= yym;
|
||||
yym = yylhs[yyn];
|
||||
if (yystate == 0 && yym == 0)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: after reduction, shifting from state 0 to\
|
||||
state %d\n", YYPREFIX, YYFINAL);
|
||||
#endif
|
||||
yystate = YYFINAL;
|
||||
*++yystack.s_mark = YYFINAL;
|
||||
*++yystack.l_mark = yyval;
|
||||
if (yychar < 0)
|
||||
{
|
||||
if ((yychar = YYLEX) < 0) yychar = 0;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, reading %d (%s)\n",
|
||||
YYPREFIX, YYFINAL, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (yychar == 0) goto yyaccept;
|
||||
goto yyloop;
|
||||
}
|
||||
if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
|
||||
yystate = yytable[yyn];
|
||||
else
|
||||
yystate = yydgoto[yym];
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: after reduction, shifting from state %d \
|
||||
to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
|
||||
#endif
|
||||
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
*++yystack.s_mark = (short) yystate;
|
||||
*++yystack.l_mark = yyval;
|
||||
goto yyloop;
|
||||
|
||||
yyoverflow:
|
||||
yyerror("yacc stack overflow");
|
||||
|
||||
yyabort:
|
||||
yyfreestack(&yystack);
|
||||
return (1);
|
||||
|
||||
yyaccept:
|
||||
yyfreestack(&yystack);
|
||||
return (0);
|
||||
}
|
3
test/calc.tab.h
Normal file
3
test/calc.tab.h
Normal file
@ -0,0 +1,3 @@
|
||||
#define DIGIT 257
|
||||
#define LETTER 258
|
||||
#define UMINUS 259
|
106
test/calc.y
Normal file
106
test/calc.y
Normal file
@ -0,0 +1,106 @@
|
||||
%{
|
||||
# include <stdio.h>
|
||||
# include <ctype.h>
|
||||
|
||||
int regs[26];
|
||||
int base;
|
||||
|
||||
extern int yylex(void);
|
||||
static void yyerror(const char *s);
|
||||
|
||||
%}
|
||||
|
||||
%start list
|
||||
|
||||
%token DIGIT LETTER
|
||||
|
||||
%left '|'
|
||||
%left '&'
|
||||
%left '+' '-'
|
||||
%left '*' '/' '%'
|
||||
%left UMINUS /* supplies precedence for unary minus */
|
||||
|
||||
%% /* beginning of rules section */
|
||||
|
||||
list : /* empty */
|
||||
| list stat '\n'
|
||||
| list error '\n'
|
||||
{ yyerrok ; }
|
||||
;
|
||||
|
||||
stat : expr
|
||||
{ printf("%d\n",$1);}
|
||||
| LETTER '=' expr
|
||||
{ regs[$1] = $3; }
|
||||
;
|
||||
|
||||
expr : '(' expr ')'
|
||||
{ $$ = $2; }
|
||||
| expr '+' expr
|
||||
{ $$ = $1 + $3; }
|
||||
| expr '-' expr
|
||||
{ $$ = $1 - $3; }
|
||||
| expr '*' expr
|
||||
{ $$ = $1 * $3; }
|
||||
| expr '/' expr
|
||||
{ $$ = $1 / $3; }
|
||||
| expr '%' expr
|
||||
{ $$ = $1 % $3; }
|
||||
| expr '&' expr
|
||||
{ $$ = $1 & $3; }
|
||||
| expr '|' expr
|
||||
{ $$ = $1 | $3; }
|
||||
| '-' expr %prec UMINUS
|
||||
{ $$ = - $2; }
|
||||
| LETTER
|
||||
{ $$ = regs[$1]; }
|
||||
| number
|
||||
;
|
||||
|
||||
number: DIGIT
|
||||
{ $$ = $1; base = ($1==0) ? 8 : 10; }
|
||||
| number DIGIT
|
||||
{ $$ = base * $1 + $2; }
|
||||
;
|
||||
|
||||
%% /* start of programs */
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
while(!feof(stdin)) {
|
||||
yyparse();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
yyerror(const char *s)
|
||||
{
|
||||
fprintf(stderr, "%s\n", s);
|
||||
}
|
||||
|
||||
int
|
||||
yylex(void)
|
||||
{
|
||||
/* lexical analysis routine */
|
||||
/* returns LETTER for a lower case letter, yylval = 0 through 25 */
|
||||
/* return DIGIT for a digit, yylval = 0 through 9 */
|
||||
/* all other characters are returned immediately */
|
||||
|
||||
int c;
|
||||
|
||||
while( (c=getchar()) == ' ' ) { /* skip blanks */ }
|
||||
|
||||
/* c is now nonblank */
|
||||
|
||||
if( islower( c )) {
|
||||
yylval = c - 'a';
|
||||
return ( LETTER );
|
||||
}
|
||||
if( isdigit( c )) {
|
||||
yylval = c - '0';
|
||||
return ( DIGIT );
|
||||
}
|
||||
return( c );
|
||||
}
|
877
test/calc1.output
Normal file
877
test/calc1.output
Normal file
@ -0,0 +1,877 @@
|
||||
0 $accept : line $end
|
||||
|
||||
1 lines :
|
||||
2 | lines line
|
||||
|
||||
3 line : dexp '\n'
|
||||
4 | vexp '\n'
|
||||
5 | DREG '=' dexp '\n'
|
||||
6 | VREG '=' vexp '\n'
|
||||
7 | error '\n'
|
||||
|
||||
8 dexp : CONST
|
||||
9 | DREG
|
||||
10 | dexp '+' dexp
|
||||
11 | dexp '-' dexp
|
||||
12 | dexp '*' dexp
|
||||
13 | dexp '/' dexp
|
||||
14 | '-' dexp
|
||||
15 | '(' dexp ')'
|
||||
|
||||
16 vexp : dexp
|
||||
17 | '(' dexp ',' dexp ')'
|
||||
18 | VREG
|
||||
19 | vexp '+' vexp
|
||||
20 | dexp '+' vexp
|
||||
21 | vexp '-' vexp
|
||||
22 | dexp '-' vexp
|
||||
23 | vexp '*' vexp
|
||||
24 | dexp '*' vexp
|
||||
25 | vexp '/' vexp
|
||||
26 | dexp '/' vexp
|
||||
27 | '-' vexp
|
||||
28 | '(' vexp ')'
|
||||
|
||||
state 0
|
||||
$accept : . line $end (0)
|
||||
|
||||
error shift 1
|
||||
DREG shift 2
|
||||
VREG shift 3
|
||||
CONST shift 4
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
line goto 7
|
||||
dexp goto 8
|
||||
vexp goto 9
|
||||
|
||||
|
||||
state 1
|
||||
line : error . '\n' (7)
|
||||
|
||||
'\n' shift 10
|
||||
. error
|
||||
|
||||
|
||||
state 2
|
||||
line : DREG . '=' dexp '\n' (5)
|
||||
dexp : DREG . (9)
|
||||
|
||||
'=' shift 11
|
||||
'+' reduce 9
|
||||
'-' reduce 9
|
||||
'*' reduce 9
|
||||
'/' reduce 9
|
||||
'\n' reduce 9
|
||||
|
||||
|
||||
state 3
|
||||
line : VREG . '=' vexp '\n' (6)
|
||||
vexp : VREG . (18)
|
||||
|
||||
'=' shift 12
|
||||
'+' reduce 18
|
||||
'-' reduce 18
|
||||
'*' reduce 18
|
||||
'/' reduce 18
|
||||
'\n' reduce 18
|
||||
|
||||
|
||||
state 4
|
||||
dexp : CONST . (8)
|
||||
|
||||
. reduce 8
|
||||
|
||||
|
||||
state 5
|
||||
dexp : '-' . dexp (14)
|
||||
vexp : '-' . vexp (27)
|
||||
|
||||
DREG shift 13
|
||||
VREG shift 14
|
||||
CONST shift 4
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
dexp goto 15
|
||||
vexp goto 16
|
||||
|
||||
|
||||
state 6
|
||||
dexp : '(' . dexp ')' (15)
|
||||
vexp : '(' . dexp ',' dexp ')' (17)
|
||||
vexp : '(' . vexp ')' (28)
|
||||
|
||||
DREG shift 13
|
||||
VREG shift 14
|
||||
CONST shift 4
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
dexp goto 17
|
||||
vexp goto 18
|
||||
|
||||
|
||||
state 7
|
||||
$accept : line . $end (0)
|
||||
|
||||
$end accept
|
||||
|
||||
|
||||
8: shift/reduce conflict (shift 19, reduce 16) on '+'
|
||||
8: shift/reduce conflict (shift 20, reduce 16) on '-'
|
||||
8: shift/reduce conflict (shift 21, reduce 16) on '*'
|
||||
8: shift/reduce conflict (shift 22, reduce 16) on '/'
|
||||
8: shift/reduce conflict (shift 23, reduce 16) on '\n'
|
||||
state 8
|
||||
line : dexp . '\n' (3)
|
||||
dexp : dexp . '+' dexp (10)
|
||||
dexp : dexp . '-' dexp (11)
|
||||
dexp : dexp . '*' dexp (12)
|
||||
dexp : dexp . '/' dexp (13)
|
||||
vexp : dexp . (16)
|
||||
vexp : dexp . '+' vexp (20)
|
||||
vexp : dexp . '-' vexp (22)
|
||||
vexp : dexp . '*' vexp (24)
|
||||
vexp : dexp . '/' vexp (26)
|
||||
|
||||
'+' shift 19
|
||||
'-' shift 20
|
||||
'*' shift 21
|
||||
'/' shift 22
|
||||
'\n' shift 23
|
||||
|
||||
|
||||
state 9
|
||||
line : vexp . '\n' (4)
|
||||
vexp : vexp . '+' vexp (19)
|
||||
vexp : vexp . '-' vexp (21)
|
||||
vexp : vexp . '*' vexp (23)
|
||||
vexp : vexp . '/' vexp (25)
|
||||
|
||||
'+' shift 24
|
||||
'-' shift 25
|
||||
'*' shift 26
|
||||
'/' shift 27
|
||||
'\n' shift 28
|
||||
. error
|
||||
|
||||
|
||||
state 10
|
||||
line : error '\n' . (7)
|
||||
|
||||
. reduce 7
|
||||
|
||||
|
||||
state 11
|
||||
line : DREG '=' . dexp '\n' (5)
|
||||
|
||||
DREG shift 13
|
||||
CONST shift 4
|
||||
'-' shift 29
|
||||
'(' shift 30
|
||||
. error
|
||||
|
||||
dexp goto 31
|
||||
|
||||
|
||||
state 12
|
||||
line : VREG '=' . vexp '\n' (6)
|
||||
|
||||
DREG shift 13
|
||||
VREG shift 14
|
||||
CONST shift 4
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
dexp goto 32
|
||||
vexp goto 33
|
||||
|
||||
|
||||
state 13
|
||||
dexp : DREG . (9)
|
||||
|
||||
. reduce 9
|
||||
|
||||
|
||||
state 14
|
||||
vexp : VREG . (18)
|
||||
|
||||
. reduce 18
|
||||
|
||||
|
||||
15: reduce/reduce conflict (reduce 14, reduce 16) on '+'
|
||||
15: reduce/reduce conflict (reduce 14, reduce 16) on '-'
|
||||
15: reduce/reduce conflict (reduce 14, reduce 16) on '*'
|
||||
15: reduce/reduce conflict (reduce 14, reduce 16) on '/'
|
||||
15: reduce/reduce conflict (reduce 14, reduce 16) on '\n'
|
||||
15: reduce/reduce conflict (reduce 14, reduce 16) on ')'
|
||||
state 15
|
||||
dexp : dexp . '+' dexp (10)
|
||||
dexp : dexp . '-' dexp (11)
|
||||
dexp : dexp . '*' dexp (12)
|
||||
dexp : dexp . '/' dexp (13)
|
||||
dexp : '-' dexp . (14)
|
||||
vexp : dexp . (16)
|
||||
vexp : dexp . '+' vexp (20)
|
||||
vexp : dexp . '-' vexp (22)
|
||||
vexp : dexp . '*' vexp (24)
|
||||
vexp : dexp . '/' vexp (26)
|
||||
|
||||
. reduce 14
|
||||
|
||||
|
||||
state 16
|
||||
vexp : vexp . '+' vexp (19)
|
||||
vexp : vexp . '-' vexp (21)
|
||||
vexp : vexp . '*' vexp (23)
|
||||
vexp : vexp . '/' vexp (25)
|
||||
vexp : '-' vexp . (27)
|
||||
|
||||
. reduce 27
|
||||
|
||||
|
||||
17: shift/reduce conflict (shift 19, reduce 16) on '+'
|
||||
17: shift/reduce conflict (shift 20, reduce 16) on '-'
|
||||
17: shift/reduce conflict (shift 21, reduce 16) on '*'
|
||||
17: shift/reduce conflict (shift 22, reduce 16) on '/'
|
||||
17: shift/reduce conflict (shift 34, reduce 16) on ')'
|
||||
state 17
|
||||
dexp : dexp . '+' dexp (10)
|
||||
dexp : dexp . '-' dexp (11)
|
||||
dexp : dexp . '*' dexp (12)
|
||||
dexp : dexp . '/' dexp (13)
|
||||
dexp : '(' dexp . ')' (15)
|
||||
vexp : dexp . (16)
|
||||
vexp : '(' dexp . ',' dexp ')' (17)
|
||||
vexp : dexp . '+' vexp (20)
|
||||
vexp : dexp . '-' vexp (22)
|
||||
vexp : dexp . '*' vexp (24)
|
||||
vexp : dexp . '/' vexp (26)
|
||||
|
||||
'+' shift 19
|
||||
'-' shift 20
|
||||
'*' shift 21
|
||||
'/' shift 22
|
||||
')' shift 34
|
||||
',' shift 35
|
||||
|
||||
|
||||
state 18
|
||||
vexp : vexp . '+' vexp (19)
|
||||
vexp : vexp . '-' vexp (21)
|
||||
vexp : vexp . '*' vexp (23)
|
||||
vexp : vexp . '/' vexp (25)
|
||||
vexp : '(' vexp . ')' (28)
|
||||
|
||||
'+' shift 24
|
||||
'-' shift 25
|
||||
'*' shift 26
|
||||
'/' shift 27
|
||||
')' shift 36
|
||||
. error
|
||||
|
||||
|
||||
state 19
|
||||
dexp : dexp '+' . dexp (10)
|
||||
vexp : dexp '+' . vexp (20)
|
||||
|
||||
DREG shift 13
|
||||
VREG shift 14
|
||||
CONST shift 4
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
dexp goto 37
|
||||
vexp goto 38
|
||||
|
||||
|
||||
state 20
|
||||
dexp : dexp '-' . dexp (11)
|
||||
vexp : dexp '-' . vexp (22)
|
||||
|
||||
DREG shift 13
|
||||
VREG shift 14
|
||||
CONST shift 4
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
dexp goto 39
|
||||
vexp goto 40
|
||||
|
||||
|
||||
state 21
|
||||
dexp : dexp '*' . dexp (12)
|
||||
vexp : dexp '*' . vexp (24)
|
||||
|
||||
DREG shift 13
|
||||
VREG shift 14
|
||||
CONST shift 4
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
dexp goto 41
|
||||
vexp goto 42
|
||||
|
||||
|
||||
state 22
|
||||
dexp : dexp '/' . dexp (13)
|
||||
vexp : dexp '/' . vexp (26)
|
||||
|
||||
DREG shift 13
|
||||
VREG shift 14
|
||||
CONST shift 4
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
dexp goto 43
|
||||
vexp goto 44
|
||||
|
||||
|
||||
state 23
|
||||
line : dexp '\n' . (3)
|
||||
|
||||
. reduce 3
|
||||
|
||||
|
||||
state 24
|
||||
vexp : vexp '+' . vexp (19)
|
||||
|
||||
DREG shift 13
|
||||
VREG shift 14
|
||||
CONST shift 4
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
dexp goto 32
|
||||
vexp goto 45
|
||||
|
||||
|
||||
state 25
|
||||
vexp : vexp '-' . vexp (21)
|
||||
|
||||
DREG shift 13
|
||||
VREG shift 14
|
||||
CONST shift 4
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
dexp goto 32
|
||||
vexp goto 46
|
||||
|
||||
|
||||
state 26
|
||||
vexp : vexp '*' . vexp (23)
|
||||
|
||||
DREG shift 13
|
||||
VREG shift 14
|
||||
CONST shift 4
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
dexp goto 32
|
||||
vexp goto 47
|
||||
|
||||
|
||||
state 27
|
||||
vexp : vexp '/' . vexp (25)
|
||||
|
||||
DREG shift 13
|
||||
VREG shift 14
|
||||
CONST shift 4
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
dexp goto 32
|
||||
vexp goto 48
|
||||
|
||||
|
||||
state 28
|
||||
line : vexp '\n' . (4)
|
||||
|
||||
. reduce 4
|
||||
|
||||
|
||||
state 29
|
||||
dexp : '-' . dexp (14)
|
||||
|
||||
DREG shift 13
|
||||
CONST shift 4
|
||||
'-' shift 29
|
||||
'(' shift 30
|
||||
. error
|
||||
|
||||
dexp goto 49
|
||||
|
||||
|
||||
state 30
|
||||
dexp : '(' . dexp ')' (15)
|
||||
|
||||
DREG shift 13
|
||||
CONST shift 4
|
||||
'-' shift 29
|
||||
'(' shift 30
|
||||
. error
|
||||
|
||||
dexp goto 50
|
||||
|
||||
|
||||
state 31
|
||||
line : DREG '=' dexp . '\n' (5)
|
||||
dexp : dexp . '+' dexp (10)
|
||||
dexp : dexp . '-' dexp (11)
|
||||
dexp : dexp . '*' dexp (12)
|
||||
dexp : dexp . '/' dexp (13)
|
||||
|
||||
'+' shift 51
|
||||
'-' shift 52
|
||||
'*' shift 53
|
||||
'/' shift 54
|
||||
'\n' shift 55
|
||||
. error
|
||||
|
||||
|
||||
32: shift/reduce conflict (shift 19, reduce 16) on '+'
|
||||
32: shift/reduce conflict (shift 20, reduce 16) on '-'
|
||||
32: shift/reduce conflict (shift 21, reduce 16) on '*'
|
||||
32: shift/reduce conflict (shift 22, reduce 16) on '/'
|
||||
state 32
|
||||
dexp : dexp . '+' dexp (10)
|
||||
dexp : dexp . '-' dexp (11)
|
||||
dexp : dexp . '*' dexp (12)
|
||||
dexp : dexp . '/' dexp (13)
|
||||
vexp : dexp . (16)
|
||||
vexp : dexp . '+' vexp (20)
|
||||
vexp : dexp . '-' vexp (22)
|
||||
vexp : dexp . '*' vexp (24)
|
||||
vexp : dexp . '/' vexp (26)
|
||||
|
||||
'+' shift 19
|
||||
'-' shift 20
|
||||
'*' shift 21
|
||||
'/' shift 22
|
||||
'\n' reduce 16
|
||||
')' reduce 16
|
||||
|
||||
|
||||
state 33
|
||||
line : VREG '=' vexp . '\n' (6)
|
||||
vexp : vexp . '+' vexp (19)
|
||||
vexp : vexp . '-' vexp (21)
|
||||
vexp : vexp . '*' vexp (23)
|
||||
vexp : vexp . '/' vexp (25)
|
||||
|
||||
'+' shift 24
|
||||
'-' shift 25
|
||||
'*' shift 26
|
||||
'/' shift 27
|
||||
'\n' shift 56
|
||||
. error
|
||||
|
||||
|
||||
state 34
|
||||
dexp : '(' dexp ')' . (15)
|
||||
|
||||
. reduce 15
|
||||
|
||||
|
||||
state 35
|
||||
vexp : '(' dexp ',' . dexp ')' (17)
|
||||
|
||||
DREG shift 13
|
||||
CONST shift 4
|
||||
'-' shift 29
|
||||
'(' shift 30
|
||||
. error
|
||||
|
||||
dexp goto 57
|
||||
|
||||
|
||||
state 36
|
||||
vexp : '(' vexp ')' . (28)
|
||||
|
||||
. reduce 28
|
||||
|
||||
|
||||
37: reduce/reduce conflict (reduce 10, reduce 16) on '+'
|
||||
37: reduce/reduce conflict (reduce 10, reduce 16) on '-'
|
||||
37: shift/reduce conflict (shift 21, reduce 16) on '*'
|
||||
37: shift/reduce conflict (shift 22, reduce 16) on '/'
|
||||
37: reduce/reduce conflict (reduce 10, reduce 16) on '\n'
|
||||
37: reduce/reduce conflict (reduce 10, reduce 16) on ')'
|
||||
state 37
|
||||
dexp : dexp . '+' dexp (10)
|
||||
dexp : dexp '+' dexp . (10)
|
||||
dexp : dexp . '-' dexp (11)
|
||||
dexp : dexp . '*' dexp (12)
|
||||
dexp : dexp . '/' dexp (13)
|
||||
vexp : dexp . (16)
|
||||
vexp : dexp . '+' vexp (20)
|
||||
vexp : dexp . '-' vexp (22)
|
||||
vexp : dexp . '*' vexp (24)
|
||||
vexp : dexp . '/' vexp (26)
|
||||
|
||||
'*' shift 21
|
||||
'/' shift 22
|
||||
'+' reduce 10
|
||||
'-' reduce 10
|
||||
'\n' reduce 10
|
||||
')' reduce 10
|
||||
',' reduce 10
|
||||
|
||||
|
||||
state 38
|
||||
vexp : vexp . '+' vexp (19)
|
||||
vexp : dexp '+' vexp . (20)
|
||||
vexp : vexp . '-' vexp (21)
|
||||
vexp : vexp . '*' vexp (23)
|
||||
vexp : vexp . '/' vexp (25)
|
||||
|
||||
'*' shift 26
|
||||
'/' shift 27
|
||||
'+' reduce 20
|
||||
'-' reduce 20
|
||||
'\n' reduce 20
|
||||
')' reduce 20
|
||||
|
||||
|
||||
39: reduce/reduce conflict (reduce 11, reduce 16) on '+'
|
||||
39: reduce/reduce conflict (reduce 11, reduce 16) on '-'
|
||||
39: shift/reduce conflict (shift 21, reduce 16) on '*'
|
||||
39: shift/reduce conflict (shift 22, reduce 16) on '/'
|
||||
39: reduce/reduce conflict (reduce 11, reduce 16) on '\n'
|
||||
39: reduce/reduce conflict (reduce 11, reduce 16) on ')'
|
||||
state 39
|
||||
dexp : dexp . '+' dexp (10)
|
||||
dexp : dexp . '-' dexp (11)
|
||||
dexp : dexp '-' dexp . (11)
|
||||
dexp : dexp . '*' dexp (12)
|
||||
dexp : dexp . '/' dexp (13)
|
||||
vexp : dexp . (16)
|
||||
vexp : dexp . '+' vexp (20)
|
||||
vexp : dexp . '-' vexp (22)
|
||||
vexp : dexp . '*' vexp (24)
|
||||
vexp : dexp . '/' vexp (26)
|
||||
|
||||
'*' shift 21
|
||||
'/' shift 22
|
||||
'+' reduce 11
|
||||
'-' reduce 11
|
||||
'\n' reduce 11
|
||||
')' reduce 11
|
||||
',' reduce 11
|
||||
|
||||
|
||||
state 40
|
||||
vexp : vexp . '+' vexp (19)
|
||||
vexp : vexp . '-' vexp (21)
|
||||
vexp : dexp '-' vexp . (22)
|
||||
vexp : vexp . '*' vexp (23)
|
||||
vexp : vexp . '/' vexp (25)
|
||||
|
||||
'*' shift 26
|
||||
'/' shift 27
|
||||
'+' reduce 22
|
||||
'-' reduce 22
|
||||
'\n' reduce 22
|
||||
')' reduce 22
|
||||
|
||||
|
||||
41: reduce/reduce conflict (reduce 12, reduce 16) on '+'
|
||||
41: reduce/reduce conflict (reduce 12, reduce 16) on '-'
|
||||
41: reduce/reduce conflict (reduce 12, reduce 16) on '*'
|
||||
41: reduce/reduce conflict (reduce 12, reduce 16) on '/'
|
||||
41: reduce/reduce conflict (reduce 12, reduce 16) on '\n'
|
||||
41: reduce/reduce conflict (reduce 12, reduce 16) on ')'
|
||||
state 41
|
||||
dexp : dexp . '+' dexp (10)
|
||||
dexp : dexp . '-' dexp (11)
|
||||
dexp : dexp . '*' dexp (12)
|
||||
dexp : dexp '*' dexp . (12)
|
||||
dexp : dexp . '/' dexp (13)
|
||||
vexp : dexp . (16)
|
||||
vexp : dexp . '+' vexp (20)
|
||||
vexp : dexp . '-' vexp (22)
|
||||
vexp : dexp . '*' vexp (24)
|
||||
vexp : dexp . '/' vexp (26)
|
||||
|
||||
. reduce 12
|
||||
|
||||
|
||||
state 42
|
||||
vexp : vexp . '+' vexp (19)
|
||||
vexp : vexp . '-' vexp (21)
|
||||
vexp : vexp . '*' vexp (23)
|
||||
vexp : dexp '*' vexp . (24)
|
||||
vexp : vexp . '/' vexp (25)
|
||||
|
||||
. reduce 24
|
||||
|
||||
|
||||
43: reduce/reduce conflict (reduce 13, reduce 16) on '+'
|
||||
43: reduce/reduce conflict (reduce 13, reduce 16) on '-'
|
||||
43: reduce/reduce conflict (reduce 13, reduce 16) on '*'
|
||||
43: reduce/reduce conflict (reduce 13, reduce 16) on '/'
|
||||
43: reduce/reduce conflict (reduce 13, reduce 16) on '\n'
|
||||
43: reduce/reduce conflict (reduce 13, reduce 16) on ')'
|
||||
state 43
|
||||
dexp : dexp . '+' dexp (10)
|
||||
dexp : dexp . '-' dexp (11)
|
||||
dexp : dexp . '*' dexp (12)
|
||||
dexp : dexp . '/' dexp (13)
|
||||
dexp : dexp '/' dexp . (13)
|
||||
vexp : dexp . (16)
|
||||
vexp : dexp . '+' vexp (20)
|
||||
vexp : dexp . '-' vexp (22)
|
||||
vexp : dexp . '*' vexp (24)
|
||||
vexp : dexp . '/' vexp (26)
|
||||
|
||||
. reduce 13
|
||||
|
||||
|
||||
state 44
|
||||
vexp : vexp . '+' vexp (19)
|
||||
vexp : vexp . '-' vexp (21)
|
||||
vexp : vexp . '*' vexp (23)
|
||||
vexp : vexp . '/' vexp (25)
|
||||
vexp : dexp '/' vexp . (26)
|
||||
|
||||
. reduce 26
|
||||
|
||||
|
||||
state 45
|
||||
vexp : vexp . '+' vexp (19)
|
||||
vexp : vexp '+' vexp . (19)
|
||||
vexp : vexp . '-' vexp (21)
|
||||
vexp : vexp . '*' vexp (23)
|
||||
vexp : vexp . '/' vexp (25)
|
||||
|
||||
'*' shift 26
|
||||
'/' shift 27
|
||||
'+' reduce 19
|
||||
'-' reduce 19
|
||||
'\n' reduce 19
|
||||
')' reduce 19
|
||||
|
||||
|
||||
state 46
|
||||
vexp : vexp . '+' vexp (19)
|
||||
vexp : vexp . '-' vexp (21)
|
||||
vexp : vexp '-' vexp . (21)
|
||||
vexp : vexp . '*' vexp (23)
|
||||
vexp : vexp . '/' vexp (25)
|
||||
|
||||
'*' shift 26
|
||||
'/' shift 27
|
||||
'+' reduce 21
|
||||
'-' reduce 21
|
||||
'\n' reduce 21
|
||||
')' reduce 21
|
||||
|
||||
|
||||
state 47
|
||||
vexp : vexp . '+' vexp (19)
|
||||
vexp : vexp . '-' vexp (21)
|
||||
vexp : vexp . '*' vexp (23)
|
||||
vexp : vexp '*' vexp . (23)
|
||||
vexp : vexp . '/' vexp (25)
|
||||
|
||||
. reduce 23
|
||||
|
||||
|
||||
state 48
|
||||
vexp : vexp . '+' vexp (19)
|
||||
vexp : vexp . '-' vexp (21)
|
||||
vexp : vexp . '*' vexp (23)
|
||||
vexp : vexp . '/' vexp (25)
|
||||
vexp : vexp '/' vexp . (25)
|
||||
|
||||
. reduce 25
|
||||
|
||||
|
||||
state 49
|
||||
dexp : dexp . '+' dexp (10)
|
||||
dexp : dexp . '-' dexp (11)
|
||||
dexp : dexp . '*' dexp (12)
|
||||
dexp : dexp . '/' dexp (13)
|
||||
dexp : '-' dexp . (14)
|
||||
|
||||
. reduce 14
|
||||
|
||||
|
||||
state 50
|
||||
dexp : dexp . '+' dexp (10)
|
||||
dexp : dexp . '-' dexp (11)
|
||||
dexp : dexp . '*' dexp (12)
|
||||
dexp : dexp . '/' dexp (13)
|
||||
dexp : '(' dexp . ')' (15)
|
||||
|
||||
'+' shift 51
|
||||
'-' shift 52
|
||||
'*' shift 53
|
||||
'/' shift 54
|
||||
')' shift 34
|
||||
. error
|
||||
|
||||
|
||||
state 51
|
||||
dexp : dexp '+' . dexp (10)
|
||||
|
||||
DREG shift 13
|
||||
CONST shift 4
|
||||
'-' shift 29
|
||||
'(' shift 30
|
||||
. error
|
||||
|
||||
dexp goto 58
|
||||
|
||||
|
||||
state 52
|
||||
dexp : dexp '-' . dexp (11)
|
||||
|
||||
DREG shift 13
|
||||
CONST shift 4
|
||||
'-' shift 29
|
||||
'(' shift 30
|
||||
. error
|
||||
|
||||
dexp goto 59
|
||||
|
||||
|
||||
state 53
|
||||
dexp : dexp '*' . dexp (12)
|
||||
|
||||
DREG shift 13
|
||||
CONST shift 4
|
||||
'-' shift 29
|
||||
'(' shift 30
|
||||
. error
|
||||
|
||||
dexp goto 60
|
||||
|
||||
|
||||
state 54
|
||||
dexp : dexp '/' . dexp (13)
|
||||
|
||||
DREG shift 13
|
||||
CONST shift 4
|
||||
'-' shift 29
|
||||
'(' shift 30
|
||||
. error
|
||||
|
||||
dexp goto 61
|
||||
|
||||
|
||||
state 55
|
||||
line : DREG '=' dexp '\n' . (5)
|
||||
|
||||
. reduce 5
|
||||
|
||||
|
||||
state 56
|
||||
line : VREG '=' vexp '\n' . (6)
|
||||
|
||||
. reduce 6
|
||||
|
||||
|
||||
state 57
|
||||
dexp : dexp . '+' dexp (10)
|
||||
dexp : dexp . '-' dexp (11)
|
||||
dexp : dexp . '*' dexp (12)
|
||||
dexp : dexp . '/' dexp (13)
|
||||
vexp : '(' dexp ',' dexp . ')' (17)
|
||||
|
||||
'+' shift 51
|
||||
'-' shift 52
|
||||
'*' shift 53
|
||||
'/' shift 54
|
||||
')' shift 62
|
||||
. error
|
||||
|
||||
|
||||
state 58
|
||||
dexp : dexp . '+' dexp (10)
|
||||
dexp : dexp '+' dexp . (10)
|
||||
dexp : dexp . '-' dexp (11)
|
||||
dexp : dexp . '*' dexp (12)
|
||||
dexp : dexp . '/' dexp (13)
|
||||
|
||||
'*' shift 53
|
||||
'/' shift 54
|
||||
'+' reduce 10
|
||||
'-' reduce 10
|
||||
'\n' reduce 10
|
||||
')' reduce 10
|
||||
|
||||
|
||||
state 59
|
||||
dexp : dexp . '+' dexp (10)
|
||||
dexp : dexp . '-' dexp (11)
|
||||
dexp : dexp '-' dexp . (11)
|
||||
dexp : dexp . '*' dexp (12)
|
||||
dexp : dexp . '/' dexp (13)
|
||||
|
||||
'*' shift 53
|
||||
'/' shift 54
|
||||
'+' reduce 11
|
||||
'-' reduce 11
|
||||
'\n' reduce 11
|
||||
')' reduce 11
|
||||
|
||||
|
||||
state 60
|
||||
dexp : dexp . '+' dexp (10)
|
||||
dexp : dexp . '-' dexp (11)
|
||||
dexp : dexp . '*' dexp (12)
|
||||
dexp : dexp '*' dexp . (12)
|
||||
dexp : dexp . '/' dexp (13)
|
||||
|
||||
. reduce 12
|
||||
|
||||
|
||||
state 61
|
||||
dexp : dexp . '+' dexp (10)
|
||||
dexp : dexp . '-' dexp (11)
|
||||
dexp : dexp . '*' dexp (12)
|
||||
dexp : dexp . '/' dexp (13)
|
||||
dexp : dexp '/' dexp . (13)
|
||||
|
||||
. reduce 13
|
||||
|
||||
|
||||
state 62
|
||||
vexp : '(' dexp ',' dexp ')' . (17)
|
||||
|
||||
. reduce 17
|
||||
|
||||
|
||||
Rules never reduced:
|
||||
lines : (1)
|
||||
lines : lines line (2)
|
||||
|
||||
|
||||
State 8 contains 5 shift/reduce conflicts.
|
||||
State 15 contains 6 reduce/reduce conflicts.
|
||||
State 17 contains 5 shift/reduce conflicts.
|
||||
State 32 contains 4 shift/reduce conflicts.
|
||||
State 37 contains 2 shift/reduce conflicts, 4 reduce/reduce conflicts.
|
||||
State 39 contains 2 shift/reduce conflicts, 4 reduce/reduce conflicts.
|
||||
State 41 contains 6 reduce/reduce conflicts.
|
||||
State 43 contains 6 reduce/reduce conflicts.
|
||||
|
||||
|
||||
15 terminals, 5 nonterminals
|
||||
29 grammar rules, 63 states
|
915
test/calc1.tab.c
Normal file
915
test/calc1.tab.c
Normal file
@ -0,0 +1,915 @@
|
||||
#ifndef lint
|
||||
static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
|
||||
#endif
|
||||
|
||||
#define YYBYACC 1
|
||||
#define YYMAJOR 1
|
||||
#define YYMINOR 9
|
||||
|
||||
#define YYEMPTY (-1)
|
||||
#define yyclearin (yychar = YYEMPTY)
|
||||
#define yyerrok (yyerrflag = 0)
|
||||
#define YYRECOVERING() (yyerrflag != 0)
|
||||
|
||||
|
||||
#ifndef yyparse
|
||||
#define yyparse calc1_parse
|
||||
#endif /* yyparse */
|
||||
|
||||
#ifndef yylex
|
||||
#define yylex calc1_lex
|
||||
#endif /* yylex */
|
||||
|
||||
#ifndef yyerror
|
||||
#define yyerror calc1_error
|
||||
#endif /* yyerror */
|
||||
|
||||
#ifndef yychar
|
||||
#define yychar calc1_char
|
||||
#endif /* yychar */
|
||||
|
||||
#ifndef yyval
|
||||
#define yyval calc1_val
|
||||
#endif /* yyval */
|
||||
|
||||
#ifndef yylval
|
||||
#define yylval calc1_lval
|
||||
#endif /* yylval */
|
||||
|
||||
#ifndef yydebug
|
||||
#define yydebug calc1_debug
|
||||
#endif /* yydebug */
|
||||
|
||||
#ifndef yynerrs
|
||||
#define yynerrs calc1_nerrs
|
||||
#endif /* yynerrs */
|
||||
|
||||
#ifndef yyerrflag
|
||||
#define yyerrflag calc1_errflag
|
||||
#endif /* yyerrflag */
|
||||
|
||||
#ifndef yylhs
|
||||
#define yylhs calc1_lhs
|
||||
#endif /* yylhs */
|
||||
|
||||
#ifndef yylen
|
||||
#define yylen calc1_len
|
||||
#endif /* yylen */
|
||||
|
||||
#ifndef yydefred
|
||||
#define yydefred calc1_defred
|
||||
#endif /* yydefred */
|
||||
|
||||
#ifndef yydgoto
|
||||
#define yydgoto calc1_dgoto
|
||||
#endif /* yydgoto */
|
||||
|
||||
#ifndef yysindex
|
||||
#define yysindex calc1_sindex
|
||||
#endif /* yysindex */
|
||||
|
||||
#ifndef yyrindex
|
||||
#define yyrindex calc1_rindex
|
||||
#endif /* yyrindex */
|
||||
|
||||
#ifndef yygindex
|
||||
#define yygindex calc1_gindex
|
||||
#endif /* yygindex */
|
||||
|
||||
#ifndef yytable
|
||||
#define yytable calc1_table
|
||||
#endif /* yytable */
|
||||
|
||||
#ifndef yycheck
|
||||
#define yycheck calc1_check
|
||||
#endif /* yycheck */
|
||||
|
||||
#ifndef yyname
|
||||
#define yyname calc1_name
|
||||
#endif /* yyname */
|
||||
|
||||
#ifndef yyrule
|
||||
#define yyrule calc1_rule
|
||||
#endif /* yyrule */
|
||||
#define YYPREFIX "calc1_"
|
||||
|
||||
#define YYPURE 0
|
||||
|
||||
#line 2 "calc1.y"
|
||||
|
||||
/* http://dinosaur.compilertools.net/yacc/index.html */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
|
||||
typedef struct interval
|
||||
{
|
||||
double lo, hi;
|
||||
}
|
||||
INTERVAL;
|
||||
|
||||
INTERVAL vmul(double, double, INTERVAL);
|
||||
INTERVAL vdiv(double, double, INTERVAL);
|
||||
|
||||
extern int yylex(void);
|
||||
static void yyerror(const char *s);
|
||||
|
||||
int dcheck(INTERVAL);
|
||||
|
||||
double dreg[26];
|
||||
INTERVAL vreg[26];
|
||||
|
||||
#line 31 "calc1.y"
|
||||
#ifdef YYSTYPE
|
||||
#undef YYSTYPE_IS_DECLARED
|
||||
#define YYSTYPE_IS_DECLARED 1
|
||||
#endif
|
||||
#ifndef YYSTYPE_IS_DECLARED
|
||||
#define YYSTYPE_IS_DECLARED 1
|
||||
typedef union
|
||||
{
|
||||
int ival;
|
||||
double dval;
|
||||
INTERVAL vval;
|
||||
} YYSTYPE;
|
||||
#endif /* !YYSTYPE_IS_DECLARED */
|
||||
#line 139 "calc1.tab.c"
|
||||
|
||||
/* compatibility with bison */
|
||||
#ifdef YYPARSE_PARAM
|
||||
/* compatibility with FreeBSD */
|
||||
# ifdef YYPARSE_PARAM_TYPE
|
||||
# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
|
||||
# else
|
||||
# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
|
||||
# endif
|
||||
#else
|
||||
# define YYPARSE_DECL() yyparse(void)
|
||||
#endif
|
||||
|
||||
/* Parameters sent to lex. */
|
||||
#ifdef YYLEX_PARAM
|
||||
# define YYLEX_DECL() yylex(void *YYLEX_PARAM)
|
||||
# define YYLEX yylex(YYLEX_PARAM)
|
||||
#else
|
||||
# define YYLEX_DECL() yylex(void)
|
||||
# define YYLEX yylex()
|
||||
#endif
|
||||
|
||||
/* Parameters sent to yyerror. */
|
||||
#ifndef YYERROR_DECL
|
||||
#define YYERROR_DECL() yyerror(const char *s)
|
||||
#endif
|
||||
#ifndef YYERROR_CALL
|
||||
#define YYERROR_CALL(msg) yyerror(msg)
|
||||
#endif
|
||||
|
||||
extern int YYPARSE_DECL();
|
||||
|
||||
#define DREG 257
|
||||
#define VREG 258
|
||||
#define CONST 259
|
||||
#define UMINUS 260
|
||||
#define YYERRCODE 256
|
||||
static const short calc1_lhs[] = { -1,
|
||||
3, 3, 0, 0, 0, 0, 0, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2,
|
||||
};
|
||||
static const short calc1_len[] = { 2,
|
||||
0, 2, 2, 2, 4, 4, 2, 1, 1, 3,
|
||||
3, 3, 3, 2, 3, 1, 5, 1, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 2, 3,
|
||||
};
|
||||
static const short calc1_defred[] = { 0,
|
||||
0, 0, 0, 8, 0, 0, 0, 0, 0, 7,
|
||||
0, 0, 9, 18, 14, 27, 0, 0, 0, 0,
|
||||
0, 0, 3, 0, 0, 0, 0, 4, 0, 0,
|
||||
0, 0, 0, 15, 0, 28, 0, 0, 0, 0,
|
||||
12, 24, 13, 26, 0, 0, 23, 25, 14, 0,
|
||||
0, 0, 0, 0, 5, 6, 0, 0, 0, 12,
|
||||
13, 17,
|
||||
};
|
||||
static const short calc1_dgoto[] = { 7,
|
||||
32, 9, 0,
|
||||
};
|
||||
static const short calc1_sindex[] = { -40,
|
||||
-8, -48, -47, 0, -37, -37, 0, 2, 17, 0,
|
||||
-34, -37, 0, 0, 0, 0, -25, 90, -37, -37,
|
||||
-37, -37, 0, -37, -37, -37, -37, 0, -34, -34,
|
||||
25, 125, 31, 0, -34, 0, -11, 37, -11, 37,
|
||||
0, 0, 0, 0, 37, 37, 0, 0, 0, 111,
|
||||
-34, -34, -34, -34, 0, 0, 118, 69, 69, 0,
|
||||
0, 0,
|
||||
};
|
||||
static const short calc1_rindex[] = { 0,
|
||||
0, 38, 44, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, -9, 0, 0, 0, 0, 51, -3, 56, 61,
|
||||
0, 0, 0, 0, 67, 72, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 78, 83, 0,
|
||||
0, 0,
|
||||
};
|
||||
static const short calc1_gindex[] = { 0,
|
||||
4, 124, 0,
|
||||
};
|
||||
#define YYTABLESIZE 225
|
||||
static const short calc1_table[] = { 6,
|
||||
16, 10, 6, 8, 5, 30, 20, 5, 15, 17,
|
||||
29, 23, 11, 12, 31, 34, 21, 19, 35, 20,
|
||||
0, 22, 37, 39, 41, 43, 28, 0, 0, 0,
|
||||
21, 16, 49, 50, 55, 22, 0, 20, 57, 20,
|
||||
56, 20, 0, 21, 19, 0, 20, 9, 22, 0,
|
||||
0, 0, 0, 18, 58, 59, 60, 61, 26, 24,
|
||||
10, 25, 0, 27, 0, 11, 53, 51, 0, 52,
|
||||
22, 54, 26, 24, 0, 25, 19, 27, 26, 9,
|
||||
9, 21, 9, 27, 9, 18, 18, 10, 18, 0,
|
||||
18, 10, 11, 10, 10, 10, 11, 0, 11, 11,
|
||||
11, 22, 0, 22, 0, 22, 0, 19, 0, 19,
|
||||
53, 19, 21, 0, 21, 54, 21, 0, 10, 0,
|
||||
10, 0, 10, 11, 0, 11, 0, 11, 16, 18,
|
||||
36, 26, 24, 0, 25, 33, 27, 0, 0, 0,
|
||||
0, 0, 38, 40, 42, 44, 0, 45, 46, 47,
|
||||
48, 34, 53, 51, 0, 52, 0, 54, 62, 53,
|
||||
51, 0, 52, 0, 54, 0, 21, 19, 0, 20,
|
||||
0, 22, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 1, 2, 3, 4, 13,
|
||||
14, 4, 13, 0, 4,
|
||||
};
|
||||
static const short calc1_check[] = { 40,
|
||||
10, 10, 40, 0, 45, 40, 10, 45, 5, 6,
|
||||
45, 10, 61, 61, 11, 41, 42, 43, 44, 45,
|
||||
-1, 47, 19, 20, 21, 22, 10, -1, -1, -1,
|
||||
42, 41, 29, 30, 10, 47, -1, 41, 35, 43,
|
||||
10, 45, -1, 42, 43, -1, 45, 10, 47, -1,
|
||||
-1, -1, -1, 10, 51, 52, 53, 54, 42, 43,
|
||||
10, 45, -1, 47, -1, 10, 42, 43, -1, 45,
|
||||
10, 47, 42, 43, -1, 45, 10, 47, 42, 42,
|
||||
43, 10, 45, 47, 47, 42, 43, 10, 45, -1,
|
||||
47, 41, 10, 43, 44, 45, 41, -1, 43, 44,
|
||||
45, 41, -1, 43, -1, 45, -1, 41, -1, 43,
|
||||
42, 45, 41, -1, 43, 47, 45, -1, 41, -1,
|
||||
43, -1, 45, 41, -1, 43, -1, 45, 5, 6,
|
||||
41, 42, 43, -1, 45, 12, 47, -1, -1, -1,
|
||||
-1, -1, 19, 20, 21, 22, -1, 24, 25, 26,
|
||||
27, 41, 42, 43, -1, 45, -1, 47, 41, 42,
|
||||
43, -1, 45, -1, 47, -1, 42, 43, -1, 45,
|
||||
-1, 47, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, 256, 257, 258, 259, 257,
|
||||
258, 259, 257, -1, 259,
|
||||
};
|
||||
#define YYFINAL 7
|
||||
#ifndef YYDEBUG
|
||||
#define YYDEBUG 0
|
||||
#endif
|
||||
#define YYMAXTOKEN 260
|
||||
#if YYDEBUG
|
||||
static const char *yyname[] = {
|
||||
|
||||
"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,"'('","')'","'*'","'+'","','","'-'",0,"'/'",0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,"DREG","VREG","CONST","UMINUS",
|
||||
};
|
||||
static const char *yyrule[] = {
|
||||
"$accept : line",
|
||||
"lines :",
|
||||
"lines : lines line",
|
||||
"line : dexp '\\n'",
|
||||
"line : vexp '\\n'",
|
||||
"line : DREG '=' dexp '\\n'",
|
||||
"line : VREG '=' vexp '\\n'",
|
||||
"line : error '\\n'",
|
||||
"dexp : CONST",
|
||||
"dexp : DREG",
|
||||
"dexp : dexp '+' dexp",
|
||||
"dexp : dexp '-' dexp",
|
||||
"dexp : dexp '*' dexp",
|
||||
"dexp : dexp '/' dexp",
|
||||
"dexp : '-' dexp",
|
||||
"dexp : '(' dexp ')'",
|
||||
"vexp : dexp",
|
||||
"vexp : '(' dexp ',' dexp ')'",
|
||||
"vexp : VREG",
|
||||
"vexp : vexp '+' vexp",
|
||||
"vexp : dexp '+' vexp",
|
||||
"vexp : vexp '-' vexp",
|
||||
"vexp : dexp '-' vexp",
|
||||
"vexp : vexp '*' vexp",
|
||||
"vexp : dexp '*' vexp",
|
||||
"vexp : vexp '/' vexp",
|
||||
"vexp : dexp '/' vexp",
|
||||
"vexp : '-' vexp",
|
||||
"vexp : '(' vexp ')'",
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
int yydebug;
|
||||
int yynerrs;
|
||||
|
||||
int yyerrflag;
|
||||
int yychar;
|
||||
YYSTYPE yyval;
|
||||
YYSTYPE yylval;
|
||||
|
||||
/* define the initial stack-sizes */
|
||||
#ifdef YYSTACKSIZE
|
||||
#undef YYMAXDEPTH
|
||||
#define YYMAXDEPTH YYSTACKSIZE
|
||||
#else
|
||||
#ifdef YYMAXDEPTH
|
||||
#define YYSTACKSIZE YYMAXDEPTH
|
||||
#else
|
||||
#define YYSTACKSIZE 500
|
||||
#define YYMAXDEPTH 500
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define YYINITSTACKSIZE 500
|
||||
|
||||
typedef struct {
|
||||
unsigned stacksize;
|
||||
short *s_base;
|
||||
short *s_mark;
|
||||
short *s_last;
|
||||
YYSTYPE *l_base;
|
||||
YYSTYPE *l_mark;
|
||||
} YYSTACKDATA;
|
||||
/* variables for the parser stack */
|
||||
static YYSTACKDATA yystack;
|
||||
#line 176 "calc1.y"
|
||||
/* beginning of subroutines section */
|
||||
|
||||
#define BSZ 50 /* buffer size for floating point numbers */
|
||||
|
||||
/* lexical analysis */
|
||||
|
||||
static void
|
||||
yyerror(const char *s)
|
||||
{
|
||||
fprintf(stderr, "%s\n", s);
|
||||
}
|
||||
|
||||
int
|
||||
yylex(void)
|
||||
{
|
||||
int c;
|
||||
|
||||
while ((c = getchar()) == ' ')
|
||||
{ /* skip over blanks */
|
||||
}
|
||||
|
||||
if (isupper(c))
|
||||
{
|
||||
yylval.ival = c - 'A';
|
||||
return (VREG);
|
||||
}
|
||||
if (islower(c))
|
||||
{
|
||||
yylval.ival = c - 'a';
|
||||
return (DREG);
|
||||
}
|
||||
|
||||
if (isdigit(c) || c == '.')
|
||||
{
|
||||
/* gobble up digits, points, exponents */
|
||||
char buf[BSZ + 1], *cp = buf;
|
||||
int dot = 0, expr = 0;
|
||||
|
||||
for (; (cp - buf) < BSZ; ++cp, c = getchar())
|
||||
{
|
||||
|
||||
*cp = c;
|
||||
if (isdigit(c))
|
||||
continue;
|
||||
if (c == '.')
|
||||
{
|
||||
if (dot++ || expr)
|
||||
return ('.'); /* will cause syntax error */
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c == 'e')
|
||||
{
|
||||
if (expr++)
|
||||
return ('e'); /* will cause syntax error */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* end of number */
|
||||
break;
|
||||
}
|
||||
*cp = '\0';
|
||||
|
||||
if ((cp - buf) >= BSZ)
|
||||
printf("constant too long: truncated\n");
|
||||
else
|
||||
ungetc(c, stdin); /* push back last char read */
|
||||
yylval.dval = atof(buf);
|
||||
return (CONST);
|
||||
}
|
||||
return (c);
|
||||
}
|
||||
|
||||
static INTERVAL
|
||||
hilo(double a, double b, double c, double d)
|
||||
{
|
||||
/* returns the smallest interval containing a, b, c, and d */
|
||||
/* used by *, / routines */
|
||||
INTERVAL v;
|
||||
|
||||
if (a > b)
|
||||
{
|
||||
v.hi = a;
|
||||
v.lo = b;
|
||||
}
|
||||
else
|
||||
{
|
||||
v.hi = b;
|
||||
v.lo = a;
|
||||
}
|
||||
|
||||
if (c > d)
|
||||
{
|
||||
if (c > v.hi)
|
||||
v.hi = c;
|
||||
if (d < v.lo)
|
||||
v.lo = d;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (d > v.hi)
|
||||
v.hi = d;
|
||||
if (c < v.lo)
|
||||
v.lo = c;
|
||||
}
|
||||
return (v);
|
||||
}
|
||||
|
||||
INTERVAL
|
||||
vmul(double a, double b, INTERVAL v)
|
||||
{
|
||||
return (hilo(a * v.hi, a * v.lo, b * v.hi, b * v.lo));
|
||||
}
|
||||
|
||||
int
|
||||
dcheck(INTERVAL v)
|
||||
{
|
||||
if (v.hi >= 0. && v.lo <= 0.)
|
||||
{
|
||||
printf("divisor interval contains 0.\n");
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
INTERVAL
|
||||
vdiv(double a, double b, INTERVAL v)
|
||||
{
|
||||
return (hilo(a / v.hi, a / v.lo, b / v.hi, b / v.lo));
|
||||
}
|
||||
#line 486 "calc1.tab.c"
|
||||
|
||||
#if YYDEBUG
|
||||
#include <stdio.h> /* needed for printf */
|
||||
#endif
|
||||
|
||||
#include <stdlib.h> /* needed for malloc, etc */
|
||||
#include <string.h> /* needed for memset */
|
||||
|
||||
/* allocate initial stack or double stack size, up to YYMAXDEPTH */
|
||||
static int yygrowstack(YYSTACKDATA *data)
|
||||
{
|
||||
int i;
|
||||
unsigned newsize;
|
||||
short *newss;
|
||||
YYSTYPE *newvs;
|
||||
|
||||
if ((newsize = data->stacksize) == 0)
|
||||
newsize = YYINITSTACKSIZE;
|
||||
else if (newsize >= YYMAXDEPTH)
|
||||
return -1;
|
||||
else if ((newsize *= 2) > YYMAXDEPTH)
|
||||
newsize = YYMAXDEPTH;
|
||||
|
||||
i = data->s_mark - data->s_base;
|
||||
newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
|
||||
if (newss == 0)
|
||||
return -1;
|
||||
|
||||
data->s_base = newss;
|
||||
data->s_mark = newss + i;
|
||||
|
||||
newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
|
||||
if (newvs == 0)
|
||||
return -1;
|
||||
|
||||
data->l_base = newvs;
|
||||
data->l_mark = newvs + i;
|
||||
|
||||
data->stacksize = newsize;
|
||||
data->s_last = data->s_base + newsize - 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if YYPURE || defined(YY_NO_LEAKS)
|
||||
static void yyfreestack(YYSTACKDATA *data)
|
||||
{
|
||||
free(data->s_base);
|
||||
free(data->l_base);
|
||||
memset(data, 0, sizeof(*data));
|
||||
}
|
||||
#else
|
||||
#define yyfreestack(data) /* nothing */
|
||||
#endif
|
||||
|
||||
#define YYABORT goto yyabort
|
||||
#define YYREJECT goto yyabort
|
||||
#define YYACCEPT goto yyaccept
|
||||
#define YYERROR goto yyerrlab
|
||||
|
||||
int
|
||||
YYPARSE_DECL()
|
||||
{
|
||||
int yym, yyn, yystate;
|
||||
#if YYDEBUG
|
||||
const char *yys;
|
||||
|
||||
if ((yys = getenv("YYDEBUG")) != 0)
|
||||
{
|
||||
yyn = *yys;
|
||||
if (yyn >= '0' && yyn <= '9')
|
||||
yydebug = yyn - '0';
|
||||
}
|
||||
#endif
|
||||
|
||||
yynerrs = 0;
|
||||
yyerrflag = 0;
|
||||
yychar = YYEMPTY;
|
||||
yystate = 0;
|
||||
|
||||
#if YYPURE
|
||||
memset(&yystack, 0, sizeof(yystack));
|
||||
#endif
|
||||
|
||||
if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
|
||||
yystack.s_mark = yystack.s_base;
|
||||
yystack.l_mark = yystack.l_base;
|
||||
yystate = 0;
|
||||
*yystack.s_mark = 0;
|
||||
|
||||
yyloop:
|
||||
if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
|
||||
if (yychar < 0)
|
||||
{
|
||||
if ((yychar = YYLEX) < 0) yychar = 0;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, reading %d (%s)\n",
|
||||
YYPREFIX, yystate, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, shifting to state %d\n",
|
||||
YYPREFIX, yystate, yytable[yyn]);
|
||||
#endif
|
||||
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
yystate = yytable[yyn];
|
||||
*++yystack.s_mark = yytable[yyn];
|
||||
*++yystack.l_mark = yylval;
|
||||
yychar = YYEMPTY;
|
||||
if (yyerrflag > 0) --yyerrflag;
|
||||
goto yyloop;
|
||||
}
|
||||
if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
|
||||
{
|
||||
yyn = yytable[yyn];
|
||||
goto yyreduce;
|
||||
}
|
||||
if (yyerrflag) goto yyinrecovery;
|
||||
|
||||
yyerror("syntax error");
|
||||
|
||||
goto yyerrlab;
|
||||
|
||||
yyerrlab:
|
||||
++yynerrs;
|
||||
|
||||
yyinrecovery:
|
||||
if (yyerrflag < 3)
|
||||
{
|
||||
yyerrflag = 3;
|
||||
for (;;)
|
||||
{
|
||||
if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, error recovery shifting\
|
||||
to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
|
||||
#endif
|
||||
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
yystate = yytable[yyn];
|
||||
*++yystack.s_mark = yytable[yyn];
|
||||
*++yystack.l_mark = yylval;
|
||||
goto yyloop;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: error recovery discarding state %d\n",
|
||||
YYPREFIX, *yystack.s_mark);
|
||||
#endif
|
||||
if (yystack.s_mark <= yystack.s_base) goto yyabort;
|
||||
--yystack.s_mark;
|
||||
--yystack.l_mark;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (yychar == 0) goto yyabort;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
|
||||
YYPREFIX, yystate, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
yychar = YYEMPTY;
|
||||
goto yyloop;
|
||||
}
|
||||
|
||||
yyreduce:
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, reducing by rule %d (%s)\n",
|
||||
YYPREFIX, yystate, yyn, yyrule[yyn]);
|
||||
#endif
|
||||
yym = yylen[yyn];
|
||||
if (yym)
|
||||
yyval = yystack.l_mark[1-yym];
|
||||
else
|
||||
memset(&yyval, 0, sizeof yyval);
|
||||
switch (yyn)
|
||||
{
|
||||
case 3:
|
||||
#line 57 "calc1.y"
|
||||
{
|
||||
(void) printf("%15.8f\n", yystack.l_mark[-1].dval);
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
#line 61 "calc1.y"
|
||||
{
|
||||
(void) printf("(%15.8f, %15.8f)\n", yystack.l_mark[-1].vval.lo, yystack.l_mark[-1].vval.hi);
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
#line 65 "calc1.y"
|
||||
{
|
||||
dreg[yystack.l_mark[-3].ival] = yystack.l_mark[-1].dval;
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
#line 69 "calc1.y"
|
||||
{
|
||||
vreg[yystack.l_mark[-3].ival] = yystack.l_mark[-1].vval;
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
#line 73 "calc1.y"
|
||||
{
|
||||
yyerrok;
|
||||
}
|
||||
break;
|
||||
case 9:
|
||||
#line 80 "calc1.y"
|
||||
{
|
||||
yyval.dval = dreg[yystack.l_mark[0].ival];
|
||||
}
|
||||
break;
|
||||
case 10:
|
||||
#line 84 "calc1.y"
|
||||
{
|
||||
yyval.dval = yystack.l_mark[-2].dval + yystack.l_mark[0].dval;
|
||||
}
|
||||
break;
|
||||
case 11:
|
||||
#line 88 "calc1.y"
|
||||
{
|
||||
yyval.dval = yystack.l_mark[-2].dval - yystack.l_mark[0].dval;
|
||||
}
|
||||
break;
|
||||
case 12:
|
||||
#line 92 "calc1.y"
|
||||
{
|
||||
yyval.dval = yystack.l_mark[-2].dval * yystack.l_mark[0].dval;
|
||||
}
|
||||
break;
|
||||
case 13:
|
||||
#line 96 "calc1.y"
|
||||
{
|
||||
yyval.dval = yystack.l_mark[-2].dval / yystack.l_mark[0].dval;
|
||||
}
|
||||
break;
|
||||
case 14:
|
||||
#line 100 "calc1.y"
|
||||
{
|
||||
yyval.dval = -yystack.l_mark[0].dval;
|
||||
}
|
||||
break;
|
||||
case 15:
|
||||
#line 104 "calc1.y"
|
||||
{
|
||||
yyval.dval = yystack.l_mark[-1].dval;
|
||||
}
|
||||
break;
|
||||
case 16:
|
||||
#line 110 "calc1.y"
|
||||
{
|
||||
yyval.vval.hi = yyval.vval.lo = yystack.l_mark[0].dval;
|
||||
}
|
||||
break;
|
||||
case 17:
|
||||
#line 114 "calc1.y"
|
||||
{
|
||||
yyval.vval.lo = yystack.l_mark[-3].dval;
|
||||
yyval.vval.hi = yystack.l_mark[-1].dval;
|
||||
if ( yyval.vval.lo > yyval.vval.hi )
|
||||
{
|
||||
(void) printf("interval out of order\n");
|
||||
YYERROR;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 18:
|
||||
#line 124 "calc1.y"
|
||||
{
|
||||
yyval.vval = vreg[yystack.l_mark[0].ival];
|
||||
}
|
||||
break;
|
||||
case 19:
|
||||
#line 128 "calc1.y"
|
||||
{
|
||||
yyval.vval.hi = yystack.l_mark[-2].vval.hi + yystack.l_mark[0].vval.hi;
|
||||
yyval.vval.lo = yystack.l_mark[-2].vval.lo + yystack.l_mark[0].vval.lo;
|
||||
}
|
||||
break;
|
||||
case 20:
|
||||
#line 133 "calc1.y"
|
||||
{
|
||||
yyval.vval.hi = yystack.l_mark[-2].dval + yystack.l_mark[0].vval.hi;
|
||||
yyval.vval.lo = yystack.l_mark[-2].dval + yystack.l_mark[0].vval.lo;
|
||||
}
|
||||
break;
|
||||
case 21:
|
||||
#line 138 "calc1.y"
|
||||
{
|
||||
yyval.vval.hi = yystack.l_mark[-2].vval.hi - yystack.l_mark[0].vval.lo;
|
||||
yyval.vval.lo = yystack.l_mark[-2].vval.lo - yystack.l_mark[0].vval.hi;
|
||||
}
|
||||
break;
|
||||
case 22:
|
||||
#line 143 "calc1.y"
|
||||
{
|
||||
yyval.vval.hi = yystack.l_mark[-2].dval - yystack.l_mark[0].vval.lo;
|
||||
yyval.vval.lo = yystack.l_mark[-2].dval - yystack.l_mark[0].vval.hi;
|
||||
}
|
||||
break;
|
||||
case 23:
|
||||
#line 148 "calc1.y"
|
||||
{
|
||||
yyval.vval = vmul( yystack.l_mark[-2].vval.lo, yystack.l_mark[-2].vval.hi, yystack.l_mark[0].vval );
|
||||
}
|
||||
break;
|
||||
case 24:
|
||||
#line 152 "calc1.y"
|
||||
{
|
||||
yyval.vval = vmul (yystack.l_mark[-2].dval, yystack.l_mark[-2].dval, yystack.l_mark[0].vval );
|
||||
}
|
||||
break;
|
||||
case 25:
|
||||
#line 156 "calc1.y"
|
||||
{
|
||||
if (dcheck(yystack.l_mark[0].vval)) YYERROR;
|
||||
yyval.vval = vdiv ( yystack.l_mark[-2].vval.lo, yystack.l_mark[-2].vval.hi, yystack.l_mark[0].vval );
|
||||
}
|
||||
break;
|
||||
case 26:
|
||||
#line 161 "calc1.y"
|
||||
{
|
||||
if (dcheck ( yystack.l_mark[0].vval )) YYERROR;
|
||||
yyval.vval = vdiv (yystack.l_mark[-2].dval, yystack.l_mark[-2].dval, yystack.l_mark[0].vval );
|
||||
}
|
||||
break;
|
||||
case 27:
|
||||
#line 166 "calc1.y"
|
||||
{
|
||||
yyval.vval.hi = -yystack.l_mark[0].vval.lo;
|
||||
yyval.vval.lo = -yystack.l_mark[0].vval.hi;
|
||||
}
|
||||
break;
|
||||
case 28:
|
||||
#line 171 "calc1.y"
|
||||
{
|
||||
yyval.vval = yystack.l_mark[-1].vval;
|
||||
}
|
||||
break;
|
||||
#line 855 "calc1.tab.c"
|
||||
}
|
||||
yystack.s_mark -= yym;
|
||||
yystate = *yystack.s_mark;
|
||||
yystack.l_mark -= yym;
|
||||
yym = yylhs[yyn];
|
||||
if (yystate == 0 && yym == 0)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: after reduction, shifting from state 0 to\
|
||||
state %d\n", YYPREFIX, YYFINAL);
|
||||
#endif
|
||||
yystate = YYFINAL;
|
||||
*++yystack.s_mark = YYFINAL;
|
||||
*++yystack.l_mark = yyval;
|
||||
if (yychar < 0)
|
||||
{
|
||||
if ((yychar = YYLEX) < 0) yychar = 0;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, reading %d (%s)\n",
|
||||
YYPREFIX, YYFINAL, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (yychar == 0) goto yyaccept;
|
||||
goto yyloop;
|
||||
}
|
||||
if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
|
||||
yystate = yytable[yyn];
|
||||
else
|
||||
yystate = yydgoto[yym];
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: after reduction, shifting from state %d \
|
||||
to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
|
||||
#endif
|
||||
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
*++yystack.s_mark = (short) yystate;
|
||||
*++yystack.l_mark = yyval;
|
||||
goto yyloop;
|
||||
|
||||
yyoverflow:
|
||||
yyerror("yacc stack overflow");
|
||||
|
||||
yyabort:
|
||||
yyfreestack(&yystack);
|
||||
return (1);
|
||||
|
||||
yyaccept:
|
||||
yyfreestack(&yystack);
|
||||
return (0);
|
||||
}
|
18
test/calc1.tab.h
Normal file
18
test/calc1.tab.h
Normal file
@ -0,0 +1,18 @@
|
||||
#define DREG 257
|
||||
#define VREG 258
|
||||
#define CONST 259
|
||||
#define UMINUS 260
|
||||
#ifdef YYSTYPE
|
||||
#undef YYSTYPE_IS_DECLARED
|
||||
#define YYSTYPE_IS_DECLARED 1
|
||||
#endif
|
||||
#ifndef YYSTYPE_IS_DECLARED
|
||||
#define YYSTYPE_IS_DECLARED 1
|
||||
typedef union
|
||||
{
|
||||
int ival;
|
||||
double dval;
|
||||
INTERVAL vval;
|
||||
} YYSTYPE;
|
||||
#endif /* !YYSTYPE_IS_DECLARED */
|
||||
extern YYSTYPE calc1_lval;
|
305
test/calc1.y
Normal file
305
test/calc1.y
Normal file
@ -0,0 +1,305 @@
|
||||
%{
|
||||
|
||||
/* http://dinosaur.compilertools.net/yacc/index.html */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
|
||||
typedef struct interval
|
||||
{
|
||||
double lo, hi;
|
||||
}
|
||||
INTERVAL;
|
||||
|
||||
INTERVAL vmul(double, double, INTERVAL);
|
||||
INTERVAL vdiv(double, double, INTERVAL);
|
||||
|
||||
extern int yylex(void);
|
||||
static void yyerror(const char *s);
|
||||
|
||||
int dcheck(INTERVAL);
|
||||
|
||||
double dreg[26];
|
||||
INTERVAL vreg[26];
|
||||
|
||||
%}
|
||||
%expect 18
|
||||
|
||||
%start line
|
||||
%union
|
||||
{
|
||||
int ival;
|
||||
double dval;
|
||||
INTERVAL vval;
|
||||
}
|
||||
|
||||
%token <ival> DREG VREG /* indices into dreg, vreg arrays */
|
||||
%token <dval> CONST /* floating point constant */
|
||||
|
||||
%type <dval> dexp /* expression */
|
||||
%type <vval> vexp /* interval expression */
|
||||
|
||||
/* precedence information about the operators */
|
||||
|
||||
%left '+' '-'
|
||||
%left '*' '/'
|
||||
%left UMINUS /* precedence for unary minus */
|
||||
|
||||
%% /* beginning of rules section */
|
||||
|
||||
lines : /* empty */
|
||||
| lines line
|
||||
;
|
||||
|
||||
line : dexp '\n'
|
||||
{
|
||||
(void) printf("%15.8f\n", $1);
|
||||
}
|
||||
| vexp '\n'
|
||||
{
|
||||
(void) printf("(%15.8f, %15.8f)\n", $1.lo, $1.hi);
|
||||
}
|
||||
| DREG '=' dexp '\n'
|
||||
{
|
||||
dreg[$1] = $3;
|
||||
}
|
||||
| VREG '=' vexp '\n'
|
||||
{
|
||||
vreg[$1] = $3;
|
||||
}
|
||||
| error '\n'
|
||||
{
|
||||
yyerrok;
|
||||
}
|
||||
;
|
||||
|
||||
dexp : CONST
|
||||
| DREG
|
||||
{
|
||||
$$ = dreg[$1];
|
||||
}
|
||||
| dexp '+' dexp
|
||||
{
|
||||
$$ = $1 + $3;
|
||||
}
|
||||
| dexp '-' dexp
|
||||
{
|
||||
$$ = $1 - $3;
|
||||
}
|
||||
| dexp '*' dexp
|
||||
{
|
||||
$$ = $1 * $3;
|
||||
}
|
||||
| dexp '/' dexp
|
||||
{
|
||||
$$ = $1 / $3;
|
||||
}
|
||||
| '-' dexp %prec UMINUS
|
||||
{
|
||||
$$ = -$2;
|
||||
}
|
||||
| '(' dexp ')'
|
||||
{
|
||||
$$ = $2;
|
||||
}
|
||||
;
|
||||
|
||||
vexp : dexp
|
||||
{
|
||||
$$.hi = $$.lo = $1;
|
||||
}
|
||||
| '(' dexp ',' dexp ')'
|
||||
{
|
||||
$$.lo = $2;
|
||||
$$.hi = $4;
|
||||
if ( $$.lo > $$.hi )
|
||||
{
|
||||
(void) printf("interval out of order\n");
|
||||
YYERROR;
|
||||
}
|
||||
}
|
||||
| VREG
|
||||
{
|
||||
$$ = vreg[$1];
|
||||
}
|
||||
| vexp '+' vexp
|
||||
{
|
||||
$$.hi = $1.hi + $3.hi;
|
||||
$$.lo = $1.lo + $3.lo;
|
||||
}
|
||||
| dexp '+' vexp
|
||||
{
|
||||
$$.hi = $1 + $3.hi;
|
||||
$$.lo = $1 + $3.lo;
|
||||
}
|
||||
| vexp '-' vexp
|
||||
{
|
||||
$$.hi = $1.hi - $3.lo;
|
||||
$$.lo = $1.lo - $3.hi;
|
||||
}
|
||||
| dexp '-' vexp
|
||||
{
|
||||
$$.hi = $1 - $3.lo;
|
||||
$$.lo = $1 - $3.hi;
|
||||
}
|
||||
| vexp '*' vexp
|
||||
{
|
||||
$$ = vmul( $1.lo, $1.hi, $3 );
|
||||
}
|
||||
| dexp '*' vexp
|
||||
{
|
||||
$$ = vmul ($1, $1, $3 );
|
||||
}
|
||||
| vexp '/' vexp
|
||||
{
|
||||
if (dcheck($3)) YYERROR;
|
||||
$$ = vdiv ( $1.lo, $1.hi, $3 );
|
||||
}
|
||||
| dexp '/' vexp
|
||||
{
|
||||
if (dcheck ( $3 )) YYERROR;
|
||||
$$ = vdiv ($1, $1, $3 );
|
||||
}
|
||||
| '-' vexp %prec UMINUS
|
||||
{
|
||||
$$.hi = -$2.lo;
|
||||
$$.lo = -$2.hi;
|
||||
}
|
||||
| '(' vexp ')'
|
||||
{
|
||||
$$ = $2;
|
||||
}
|
||||
;
|
||||
|
||||
%% /* beginning of subroutines section */
|
||||
|
||||
#define BSZ 50 /* buffer size for floating point numbers */
|
||||
|
||||
/* lexical analysis */
|
||||
|
||||
static void
|
||||
yyerror(const char *s)
|
||||
{
|
||||
fprintf(stderr, "%s\n", s);
|
||||
}
|
||||
|
||||
int
|
||||
yylex(void)
|
||||
{
|
||||
int c;
|
||||
|
||||
while ((c = getchar()) == ' ')
|
||||
{ /* skip over blanks */
|
||||
}
|
||||
|
||||
if (isupper(c))
|
||||
{
|
||||
yylval.ival = c - 'A';
|
||||
return (VREG);
|
||||
}
|
||||
if (islower(c))
|
||||
{
|
||||
yylval.ival = c - 'a';
|
||||
return (DREG);
|
||||
}
|
||||
|
||||
if (isdigit(c) || c == '.')
|
||||
{
|
||||
/* gobble up digits, points, exponents */
|
||||
char buf[BSZ + 1], *cp = buf;
|
||||
int dot = 0, expr = 0;
|
||||
|
||||
for (; (cp - buf) < BSZ; ++cp, c = getchar())
|
||||
{
|
||||
|
||||
*cp = c;
|
||||
if (isdigit(c))
|
||||
continue;
|
||||
if (c == '.')
|
||||
{
|
||||
if (dot++ || expr)
|
||||
return ('.'); /* will cause syntax error */
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c == 'e')
|
||||
{
|
||||
if (expr++)
|
||||
return ('e'); /* will cause syntax error */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* end of number */
|
||||
break;
|
||||
}
|
||||
*cp = '\0';
|
||||
|
||||
if ((cp - buf) >= BSZ)
|
||||
printf("constant too long: truncated\n");
|
||||
else
|
||||
ungetc(c, stdin); /* push back last char read */
|
||||
yylval.dval = atof(buf);
|
||||
return (CONST);
|
||||
}
|
||||
return (c);
|
||||
}
|
||||
|
||||
static INTERVAL
|
||||
hilo(double a, double b, double c, double d)
|
||||
{
|
||||
/* returns the smallest interval containing a, b, c, and d */
|
||||
/* used by *, / routines */
|
||||
INTERVAL v;
|
||||
|
||||
if (a > b)
|
||||
{
|
||||
v.hi = a;
|
||||
v.lo = b;
|
||||
}
|
||||
else
|
||||
{
|
||||
v.hi = b;
|
||||
v.lo = a;
|
||||
}
|
||||
|
||||
if (c > d)
|
||||
{
|
||||
if (c > v.hi)
|
||||
v.hi = c;
|
||||
if (d < v.lo)
|
||||
v.lo = d;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (d > v.hi)
|
||||
v.hi = d;
|
||||
if (c < v.lo)
|
||||
v.lo = c;
|
||||
}
|
||||
return (v);
|
||||
}
|
||||
|
||||
INTERVAL
|
||||
vmul(double a, double b, INTERVAL v)
|
||||
{
|
||||
return (hilo(a * v.hi, a * v.lo, b * v.hi, b * v.lo));
|
||||
}
|
||||
|
||||
int
|
||||
dcheck(INTERVAL v)
|
||||
{
|
||||
if (v.hi >= 0. && v.lo <= 0.)
|
||||
{
|
||||
printf("divisor interval contains 0.\n");
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
INTERVAL
|
||||
vdiv(double a, double b, INTERVAL v)
|
||||
{
|
||||
return (hilo(a / v.hi, a / v.lo, b / v.hi, b / v.lo));
|
||||
}
|
461
test/calc2.output
Normal file
461
test/calc2.output
Normal file
@ -0,0 +1,461 @@
|
||||
0 $accept : list $end
|
||||
|
||||
1 list :
|
||||
2 | list stat '\n'
|
||||
3 | list error '\n'
|
||||
|
||||
4 stat : expr
|
||||
5 | LETTER '=' expr
|
||||
|
||||
6 expr : '(' expr ')'
|
||||
7 | expr '+' expr
|
||||
8 | expr '-' expr
|
||||
9 | expr '*' expr
|
||||
10 | expr '/' expr
|
||||
11 | expr '%' expr
|
||||
12 | expr '&' expr
|
||||
13 | expr '|' expr
|
||||
14 | '-' expr
|
||||
15 | LETTER
|
||||
16 | number
|
||||
|
||||
17 number : DIGIT
|
||||
18 | number DIGIT
|
||||
|
||||
state 0
|
||||
$accept : . list $end (0)
|
||||
list : . (1)
|
||||
|
||||
. reduce 1
|
||||
|
||||
list goto 1
|
||||
|
||||
|
||||
state 1
|
||||
$accept : list . $end (0)
|
||||
list : list . stat '\n' (2)
|
||||
list : list . error '\n' (3)
|
||||
|
||||
$end accept
|
||||
error shift 2
|
||||
DIGIT shift 3
|
||||
LETTER shift 4
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
stat goto 7
|
||||
expr goto 8
|
||||
number goto 9
|
||||
|
||||
|
||||
state 2
|
||||
list : list error . '\n' (3)
|
||||
|
||||
'\n' shift 10
|
||||
. error
|
||||
|
||||
|
||||
state 3
|
||||
number : DIGIT . (17)
|
||||
|
||||
. reduce 17
|
||||
|
||||
|
||||
state 4
|
||||
stat : LETTER . '=' expr (5)
|
||||
expr : LETTER . (15)
|
||||
|
||||
'=' shift 11
|
||||
'|' reduce 15
|
||||
'&' reduce 15
|
||||
'+' reduce 15
|
||||
'-' reduce 15
|
||||
'*' reduce 15
|
||||
'/' reduce 15
|
||||
'%' reduce 15
|
||||
'\n' reduce 15
|
||||
|
||||
|
||||
state 5
|
||||
expr : '-' . expr (14)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 13
|
||||
number goto 9
|
||||
|
||||
|
||||
state 6
|
||||
expr : '(' . expr ')' (6)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 14
|
||||
number goto 9
|
||||
|
||||
|
||||
state 7
|
||||
list : list stat . '\n' (2)
|
||||
|
||||
'\n' shift 15
|
||||
. error
|
||||
|
||||
|
||||
state 8
|
||||
stat : expr . (4)
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
'|' shift 16
|
||||
'&' shift 17
|
||||
'+' shift 18
|
||||
'-' shift 19
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
'\n' reduce 4
|
||||
|
||||
|
||||
state 9
|
||||
expr : number . (16)
|
||||
number : number . DIGIT (18)
|
||||
|
||||
DIGIT shift 23
|
||||
'|' reduce 16
|
||||
'&' reduce 16
|
||||
'+' reduce 16
|
||||
'-' reduce 16
|
||||
'*' reduce 16
|
||||
'/' reduce 16
|
||||
'%' reduce 16
|
||||
'\n' reduce 16
|
||||
')' reduce 16
|
||||
|
||||
|
||||
state 10
|
||||
list : list error '\n' . (3)
|
||||
|
||||
. reduce 3
|
||||
|
||||
|
||||
state 11
|
||||
stat : LETTER '=' . expr (5)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 24
|
||||
number goto 9
|
||||
|
||||
|
||||
state 12
|
||||
expr : LETTER . (15)
|
||||
|
||||
. reduce 15
|
||||
|
||||
|
||||
state 13
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
expr : '-' expr . (14)
|
||||
|
||||
. reduce 14
|
||||
|
||||
|
||||
state 14
|
||||
expr : '(' expr . ')' (6)
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
'|' shift 16
|
||||
'&' shift 17
|
||||
'+' shift 18
|
||||
'-' shift 19
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
')' shift 25
|
||||
. error
|
||||
|
||||
|
||||
state 15
|
||||
list : list stat '\n' . (2)
|
||||
|
||||
. reduce 2
|
||||
|
||||
|
||||
state 16
|
||||
expr : expr '|' . expr (13)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 26
|
||||
number goto 9
|
||||
|
||||
|
||||
state 17
|
||||
expr : expr '&' . expr (12)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 27
|
||||
number goto 9
|
||||
|
||||
|
||||
state 18
|
||||
expr : expr '+' . expr (7)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 28
|
||||
number goto 9
|
||||
|
||||
|
||||
state 19
|
||||
expr : expr '-' . expr (8)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 29
|
||||
number goto 9
|
||||
|
||||
|
||||
state 20
|
||||
expr : expr '*' . expr (9)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 30
|
||||
number goto 9
|
||||
|
||||
|
||||
state 21
|
||||
expr : expr '/' . expr (10)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 31
|
||||
number goto 9
|
||||
|
||||
|
||||
state 22
|
||||
expr : expr '%' . expr (11)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 32
|
||||
number goto 9
|
||||
|
||||
|
||||
state 23
|
||||
number : number DIGIT . (18)
|
||||
|
||||
. reduce 18
|
||||
|
||||
|
||||
state 24
|
||||
stat : LETTER '=' expr . (5)
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
'|' shift 16
|
||||
'&' shift 17
|
||||
'+' shift 18
|
||||
'-' shift 19
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
'\n' reduce 5
|
||||
|
||||
|
||||
state 25
|
||||
expr : '(' expr ')' . (6)
|
||||
|
||||
. reduce 6
|
||||
|
||||
|
||||
state 26
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
expr : expr '|' expr . (13)
|
||||
|
||||
'&' shift 17
|
||||
'+' shift 18
|
||||
'-' shift 19
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
'|' reduce 13
|
||||
'\n' reduce 13
|
||||
')' reduce 13
|
||||
|
||||
|
||||
state 27
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr '&' expr . (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
'+' shift 18
|
||||
'-' shift 19
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
'|' reduce 12
|
||||
'&' reduce 12
|
||||
'\n' reduce 12
|
||||
')' reduce 12
|
||||
|
||||
|
||||
state 28
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr '+' expr . (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
'|' reduce 7
|
||||
'&' reduce 7
|
||||
'+' reduce 7
|
||||
'-' reduce 7
|
||||
'\n' reduce 7
|
||||
')' reduce 7
|
||||
|
||||
|
||||
state 29
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr '-' expr . (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
'|' reduce 8
|
||||
'&' reduce 8
|
||||
'+' reduce 8
|
||||
'-' reduce 8
|
||||
'\n' reduce 8
|
||||
')' reduce 8
|
||||
|
||||
|
||||
state 30
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr '*' expr . (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
. reduce 9
|
||||
|
||||
|
||||
state 31
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr '/' expr . (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
. reduce 10
|
||||
|
||||
|
||||
state 32
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr '%' expr . (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
. reduce 11
|
||||
|
||||
|
||||
16 terminals, 5 nonterminals
|
||||
19 grammar rules, 33 states
|
682
test/calc2.tab.c
Normal file
682
test/calc2.tab.c
Normal file
@ -0,0 +1,682 @@
|
||||
#ifndef lint
|
||||
static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
|
||||
#endif
|
||||
|
||||
#define YYBYACC 1
|
||||
#define YYMAJOR 1
|
||||
#define YYMINOR 9
|
||||
|
||||
#define YYEMPTY (-1)
|
||||
#define yyclearin (yychar = YYEMPTY)
|
||||
#define yyerrok (yyerrflag = 0)
|
||||
#define YYRECOVERING() (yyerrflag != 0)
|
||||
|
||||
|
||||
#ifndef yyparse
|
||||
#define yyparse calc2_parse
|
||||
#endif /* yyparse */
|
||||
|
||||
#ifndef yylex
|
||||
#define yylex calc2_lex
|
||||
#endif /* yylex */
|
||||
|
||||
#ifndef yyerror
|
||||
#define yyerror calc2_error
|
||||
#endif /* yyerror */
|
||||
|
||||
#ifndef yychar
|
||||
#define yychar calc2_char
|
||||
#endif /* yychar */
|
||||
|
||||
#ifndef yyval
|
||||
#define yyval calc2_val
|
||||
#endif /* yyval */
|
||||
|
||||
#ifndef yylval
|
||||
#define yylval calc2_lval
|
||||
#endif /* yylval */
|
||||
|
||||
#ifndef yydebug
|
||||
#define yydebug calc2_debug
|
||||
#endif /* yydebug */
|
||||
|
||||
#ifndef yynerrs
|
||||
#define yynerrs calc2_nerrs
|
||||
#endif /* yynerrs */
|
||||
|
||||
#ifndef yyerrflag
|
||||
#define yyerrflag calc2_errflag
|
||||
#endif /* yyerrflag */
|
||||
|
||||
#ifndef yylhs
|
||||
#define yylhs calc2_lhs
|
||||
#endif /* yylhs */
|
||||
|
||||
#ifndef yylen
|
||||
#define yylen calc2_len
|
||||
#endif /* yylen */
|
||||
|
||||
#ifndef yydefred
|
||||
#define yydefred calc2_defred
|
||||
#endif /* yydefred */
|
||||
|
||||
#ifndef yydgoto
|
||||
#define yydgoto calc2_dgoto
|
||||
#endif /* yydgoto */
|
||||
|
||||
#ifndef yysindex
|
||||
#define yysindex calc2_sindex
|
||||
#endif /* yysindex */
|
||||
|
||||
#ifndef yyrindex
|
||||
#define yyrindex calc2_rindex
|
||||
#endif /* yyrindex */
|
||||
|
||||
#ifndef yygindex
|
||||
#define yygindex calc2_gindex
|
||||
#endif /* yygindex */
|
||||
|
||||
#ifndef yytable
|
||||
#define yytable calc2_table
|
||||
#endif /* yytable */
|
||||
|
||||
#ifndef yycheck
|
||||
#define yycheck calc2_check
|
||||
#endif /* yycheck */
|
||||
|
||||
#ifndef yyname
|
||||
#define yyname calc2_name
|
||||
#endif /* yyname */
|
||||
|
||||
#ifndef yyrule
|
||||
#define yyrule calc2_rule
|
||||
#endif /* yyrule */
|
||||
#define YYPREFIX "calc2_"
|
||||
|
||||
#define YYPURE 0
|
||||
|
||||
#line 7 "calc2.y"
|
||||
# include <stdio.h>
|
||||
# include <ctype.h>
|
||||
|
||||
#ifdef YYBISON
|
||||
#define YYLEX_PARAM base
|
||||
#define YYLEX_DECL() yylex(int *YYLEX_PARAM)
|
||||
#define YYERROR_DECL() yyerror(int regs[26], int *base, const char *s)
|
||||
int YYLEX_DECL();
|
||||
static void YYERROR_DECL();
|
||||
#endif
|
||||
|
||||
#line 111 "calc2.tab.c"
|
||||
|
||||
#ifndef YYSTYPE
|
||||
typedef int YYSTYPE;
|
||||
#endif
|
||||
|
||||
/* compatibility with bison */
|
||||
#ifdef YYPARSE_PARAM
|
||||
/* compatibility with FreeBSD */
|
||||
# ifdef YYPARSE_PARAM_TYPE
|
||||
# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
|
||||
# else
|
||||
# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
|
||||
# endif
|
||||
#else
|
||||
# define YYPARSE_DECL() yyparse(int regs[26], int * base)
|
||||
#endif
|
||||
|
||||
/* Parameters sent to lex. */
|
||||
#ifdef YYLEX_PARAM
|
||||
# define YYLEX_DECL() yylex(void *YYLEX_PARAM)
|
||||
# define YYLEX yylex(YYLEX_PARAM)
|
||||
#else
|
||||
# define YYLEX_DECL() yylex(int * base)
|
||||
# define YYLEX yylex(base)
|
||||
#endif
|
||||
|
||||
/* Parameters sent to yyerror. */
|
||||
#ifndef YYERROR_DECL
|
||||
#define YYERROR_DECL() yyerror(int regs[26], int * base, const char *s)
|
||||
#endif
|
||||
#ifndef YYERROR_CALL
|
||||
#define YYERROR_CALL(msg) yyerror(regs, base, msg)
|
||||
#endif
|
||||
|
||||
extern int YYPARSE_DECL();
|
||||
|
||||
#define DIGIT 257
|
||||
#define LETTER 258
|
||||
#define UMINUS 259
|
||||
#define YYERRCODE 256
|
||||
static const short calc2_lhs[] = { -1,
|
||||
0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 3, 3,
|
||||
};
|
||||
static const short calc2_len[] = { 2,
|
||||
0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 2, 1, 1, 1, 2,
|
||||
};
|
||||
static const short calc2_defred[] = { 1,
|
||||
0, 0, 17, 0, 0, 0, 0, 0, 0, 3,
|
||||
0, 15, 14, 0, 2, 0, 0, 0, 0, 0,
|
||||
0, 0, 18, 0, 6, 0, 0, 0, 0, 9,
|
||||
10, 11,
|
||||
};
|
||||
static const short calc2_dgoto[] = { 1,
|
||||
7, 8, 9,
|
||||
};
|
||||
static const short calc2_sindex[] = { 0,
|
||||
-40, -7, 0, -55, -38, -38, 1, -29, -247, 0,
|
||||
-38, 0, 0, 22, 0, -38, -38, -38, -38, -38,
|
||||
-38, -38, 0, -29, 0, 51, 60, -20, -20, 0,
|
||||
0, 0,
|
||||
};
|
||||
static const short calc2_rindex[] = { 0,
|
||||
0, 0, 0, 2, 0, 0, 0, 9, -9, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 10, 0, -6, 14, 5, 13, 0,
|
||||
0, 0,
|
||||
};
|
||||
static const short calc2_gindex[] = { 0,
|
||||
0, 65, 0,
|
||||
};
|
||||
#define YYTABLESIZE 220
|
||||
static const short calc2_table[] = { 6,
|
||||
16, 6, 10, 13, 5, 11, 5, 22, 17, 23,
|
||||
15, 15, 20, 18, 7, 19, 22, 21, 4, 5,
|
||||
0, 20, 8, 12, 0, 0, 21, 16, 16, 0,
|
||||
0, 16, 16, 16, 13, 16, 0, 16, 15, 15,
|
||||
0, 0, 7, 15, 15, 7, 15, 7, 15, 7,
|
||||
8, 12, 0, 8, 12, 8, 0, 8, 22, 17,
|
||||
0, 0, 25, 20, 18, 0, 19, 0, 21, 13,
|
||||
14, 0, 0, 0, 0, 24, 0, 0, 0, 0,
|
||||
26, 27, 28, 29, 30, 31, 32, 22, 17, 0,
|
||||
0, 0, 20, 18, 16, 19, 22, 21, 0, 0,
|
||||
0, 20, 18, 0, 19, 0, 21, 0, 0, 0,
|
||||
0, 0, 0, 0, 16, 0, 0, 13, 0, 0,
|
||||
0, 0, 0, 0, 0, 15, 0, 0, 7, 0,
|
||||
0, 0, 0, 0, 0, 0, 8, 12, 0, 0,
|
||||
0, 0, 0, 0, 0, 16, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 2, 3, 4, 3, 12,
|
||||
};
|
||||
static const short calc2_check[] = { 40,
|
||||
10, 40, 10, 10, 45, 61, 45, 37, 38, 257,
|
||||
10, 10, 42, 43, 10, 45, 37, 47, 10, 10,
|
||||
-1, 42, 10, 10, -1, -1, 47, 37, 38, -1,
|
||||
-1, 41, 42, 43, 41, 45, -1, 47, 37, 38,
|
||||
-1, -1, 38, 42, 43, 41, 45, 43, 47, 45,
|
||||
38, 38, -1, 41, 41, 43, -1, 45, 37, 38,
|
||||
-1, -1, 41, 42, 43, -1, 45, -1, 47, 5,
|
||||
6, -1, -1, -1, -1, 11, -1, -1, -1, -1,
|
||||
16, 17, 18, 19, 20, 21, 22, 37, 38, -1,
|
||||
-1, -1, 42, 43, 124, 45, 37, 47, -1, -1,
|
||||
-1, 42, 43, -1, 45, -1, 47, -1, -1, -1,
|
||||
-1, -1, -1, -1, 124, -1, -1, 124, -1, -1,
|
||||
-1, -1, -1, -1, -1, 124, -1, -1, 124, -1,
|
||||
-1, -1, -1, -1, -1, -1, 124, 124, -1, -1,
|
||||
-1, -1, -1, -1, -1, 124, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, 256, 257, 258, 257, 258,
|
||||
};
|
||||
#define YYFINAL 1
|
||||
#ifndef YYDEBUG
|
||||
#define YYDEBUG 0
|
||||
#endif
|
||||
#define YYMAXTOKEN 259
|
||||
#if YYDEBUG
|
||||
static const char *yyname[] = {
|
||||
|
||||
"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'",0,"'-'",0,"'/'",0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'|'",0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,"DIGIT","LETTER","UMINUS",
|
||||
};
|
||||
static const char *yyrule[] = {
|
||||
"$accept : list",
|
||||
"list :",
|
||||
"list : list stat '\\n'",
|
||||
"list : list error '\\n'",
|
||||
"stat : expr",
|
||||
"stat : LETTER '=' expr",
|
||||
"expr : '(' expr ')'",
|
||||
"expr : expr '+' expr",
|
||||
"expr : expr '-' expr",
|
||||
"expr : expr '*' expr",
|
||||
"expr : expr '/' expr",
|
||||
"expr : expr '%' expr",
|
||||
"expr : expr '&' expr",
|
||||
"expr : expr '|' expr",
|
||||
"expr : '-' expr",
|
||||
"expr : LETTER",
|
||||
"expr : number",
|
||||
"number : DIGIT",
|
||||
"number : number DIGIT",
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
int yydebug;
|
||||
int yynerrs;
|
||||
|
||||
int yyerrflag;
|
||||
int yychar;
|
||||
YYSTYPE yyval;
|
||||
YYSTYPE yylval;
|
||||
|
||||
/* define the initial stack-sizes */
|
||||
#ifdef YYSTACKSIZE
|
||||
#undef YYMAXDEPTH
|
||||
#define YYMAXDEPTH YYSTACKSIZE
|
||||
#else
|
||||
#ifdef YYMAXDEPTH
|
||||
#define YYSTACKSIZE YYMAXDEPTH
|
||||
#else
|
||||
#define YYSTACKSIZE 500
|
||||
#define YYMAXDEPTH 500
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define YYINITSTACKSIZE 500
|
||||
|
||||
typedef struct {
|
||||
unsigned stacksize;
|
||||
short *s_base;
|
||||
short *s_mark;
|
||||
short *s_last;
|
||||
YYSTYPE *l_base;
|
||||
YYSTYPE *l_mark;
|
||||
} YYSTACKDATA;
|
||||
/* variables for the parser stack */
|
||||
static YYSTACKDATA yystack;
|
||||
#line 73 "calc2.y"
|
||||
/* start of programs */
|
||||
|
||||
#ifdef YYBYACC
|
||||
extern int YYLEX_DECL();
|
||||
#endif
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
int regs[26];
|
||||
int base = 10;
|
||||
|
||||
while(!feof(stdin)) {
|
||||
yyparse(regs, &base);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
YYERROR_DECL()
|
||||
{
|
||||
fprintf(stderr, "%s\n", s);
|
||||
}
|
||||
|
||||
int
|
||||
YYLEX_DECL()
|
||||
{
|
||||
/* lexical analysis routine */
|
||||
/* returns LETTER for a lower case letter, yylval = 0 through 25 */
|
||||
/* return DIGIT for a digit, yylval = 0 through 9 */
|
||||
/* all other characters are returned immediately */
|
||||
|
||||
int c;
|
||||
|
||||
while( (c=getchar()) == ' ' ) { /* skip blanks */ }
|
||||
|
||||
/* c is now nonblank */
|
||||
|
||||
if( islower( c )) {
|
||||
yylval = c - 'a';
|
||||
return ( LETTER );
|
||||
}
|
||||
if( isdigit( c )) {
|
||||
yylval = (c - '0') % (*base);
|
||||
return ( DIGIT );
|
||||
}
|
||||
return( c );
|
||||
}
|
||||
#line 356 "calc2.tab.c"
|
||||
|
||||
#if YYDEBUG
|
||||
#include <stdio.h> /* needed for printf */
|
||||
#endif
|
||||
|
||||
#include <stdlib.h> /* needed for malloc, etc */
|
||||
#include <string.h> /* needed for memset */
|
||||
|
||||
/* allocate initial stack or double stack size, up to YYMAXDEPTH */
|
||||
static int yygrowstack(YYSTACKDATA *data)
|
||||
{
|
||||
int i;
|
||||
unsigned newsize;
|
||||
short *newss;
|
||||
YYSTYPE *newvs;
|
||||
|
||||
if ((newsize = data->stacksize) == 0)
|
||||
newsize = YYINITSTACKSIZE;
|
||||
else if (newsize >= YYMAXDEPTH)
|
||||
return -1;
|
||||
else if ((newsize *= 2) > YYMAXDEPTH)
|
||||
newsize = YYMAXDEPTH;
|
||||
|
||||
i = data->s_mark - data->s_base;
|
||||
newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
|
||||
if (newss == 0)
|
||||
return -1;
|
||||
|
||||
data->s_base = newss;
|
||||
data->s_mark = newss + i;
|
||||
|
||||
newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
|
||||
if (newvs == 0)
|
||||
return -1;
|
||||
|
||||
data->l_base = newvs;
|
||||
data->l_mark = newvs + i;
|
||||
|
||||
data->stacksize = newsize;
|
||||
data->s_last = data->s_base + newsize - 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if YYPURE || defined(YY_NO_LEAKS)
|
||||
static void yyfreestack(YYSTACKDATA *data)
|
||||
{
|
||||
free(data->s_base);
|
||||
free(data->l_base);
|
||||
memset(data, 0, sizeof(*data));
|
||||
}
|
||||
#else
|
||||
#define yyfreestack(data) /* nothing */
|
||||
#endif
|
||||
|
||||
#define YYABORT goto yyabort
|
||||
#define YYREJECT goto yyabort
|
||||
#define YYACCEPT goto yyaccept
|
||||
#define YYERROR goto yyerrlab
|
||||
|
||||
int
|
||||
YYPARSE_DECL()
|
||||
{
|
||||
int yym, yyn, yystate;
|
||||
#if YYDEBUG
|
||||
const char *yys;
|
||||
|
||||
if ((yys = getenv("YYDEBUG")) != 0)
|
||||
{
|
||||
yyn = *yys;
|
||||
if (yyn >= '0' && yyn <= '9')
|
||||
yydebug = yyn - '0';
|
||||
}
|
||||
#endif
|
||||
|
||||
yynerrs = 0;
|
||||
yyerrflag = 0;
|
||||
yychar = YYEMPTY;
|
||||
yystate = 0;
|
||||
|
||||
#if YYPURE
|
||||
memset(&yystack, 0, sizeof(yystack));
|
||||
#endif
|
||||
|
||||
if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
|
||||
yystack.s_mark = yystack.s_base;
|
||||
yystack.l_mark = yystack.l_base;
|
||||
yystate = 0;
|
||||
*yystack.s_mark = 0;
|
||||
|
||||
yyloop:
|
||||
if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
|
||||
if (yychar < 0)
|
||||
{
|
||||
if ((yychar = YYLEX) < 0) yychar = 0;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, reading %d (%s)\n",
|
||||
YYPREFIX, yystate, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, shifting to state %d\n",
|
||||
YYPREFIX, yystate, yytable[yyn]);
|
||||
#endif
|
||||
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
yystate = yytable[yyn];
|
||||
*++yystack.s_mark = yytable[yyn];
|
||||
*++yystack.l_mark = yylval;
|
||||
yychar = YYEMPTY;
|
||||
if (yyerrflag > 0) --yyerrflag;
|
||||
goto yyloop;
|
||||
}
|
||||
if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
|
||||
{
|
||||
yyn = yytable[yyn];
|
||||
goto yyreduce;
|
||||
}
|
||||
if (yyerrflag) goto yyinrecovery;
|
||||
|
||||
yyerror(regs, base, "syntax error");
|
||||
|
||||
goto yyerrlab;
|
||||
|
||||
yyerrlab:
|
||||
++yynerrs;
|
||||
|
||||
yyinrecovery:
|
||||
if (yyerrflag < 3)
|
||||
{
|
||||
yyerrflag = 3;
|
||||
for (;;)
|
||||
{
|
||||
if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, error recovery shifting\
|
||||
to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
|
||||
#endif
|
||||
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
yystate = yytable[yyn];
|
||||
*++yystack.s_mark = yytable[yyn];
|
||||
*++yystack.l_mark = yylval;
|
||||
goto yyloop;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: error recovery discarding state %d\n",
|
||||
YYPREFIX, *yystack.s_mark);
|
||||
#endif
|
||||
if (yystack.s_mark <= yystack.s_base) goto yyabort;
|
||||
--yystack.s_mark;
|
||||
--yystack.l_mark;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (yychar == 0) goto yyabort;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
|
||||
YYPREFIX, yystate, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
yychar = YYEMPTY;
|
||||
goto yyloop;
|
||||
}
|
||||
|
||||
yyreduce:
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, reducing by rule %d (%s)\n",
|
||||
YYPREFIX, yystate, yyn, yyrule[yyn]);
|
||||
#endif
|
||||
yym = yylen[yyn];
|
||||
if (yym)
|
||||
yyval = yystack.l_mark[1-yym];
|
||||
else
|
||||
memset(&yyval, 0, sizeof yyval);
|
||||
switch (yyn)
|
||||
{
|
||||
case 3:
|
||||
#line 35 "calc2.y"
|
||||
{ yyerrok ; }
|
||||
break;
|
||||
case 4:
|
||||
#line 39 "calc2.y"
|
||||
{ printf("%d\n",yystack.l_mark[0]);}
|
||||
break;
|
||||
case 5:
|
||||
#line 41 "calc2.y"
|
||||
{ regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
|
||||
break;
|
||||
case 6:
|
||||
#line 45 "calc2.y"
|
||||
{ yyval = yystack.l_mark[-1]; }
|
||||
break;
|
||||
case 7:
|
||||
#line 47 "calc2.y"
|
||||
{ yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
|
||||
break;
|
||||
case 8:
|
||||
#line 49 "calc2.y"
|
||||
{ yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
|
||||
break;
|
||||
case 9:
|
||||
#line 51 "calc2.y"
|
||||
{ yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
|
||||
break;
|
||||
case 10:
|
||||
#line 53 "calc2.y"
|
||||
{ yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
|
||||
break;
|
||||
case 11:
|
||||
#line 55 "calc2.y"
|
||||
{ yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
|
||||
break;
|
||||
case 12:
|
||||
#line 57 "calc2.y"
|
||||
{ yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
|
||||
break;
|
||||
case 13:
|
||||
#line 59 "calc2.y"
|
||||
{ yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
|
||||
break;
|
||||
case 14:
|
||||
#line 61 "calc2.y"
|
||||
{ yyval = - yystack.l_mark[0]; }
|
||||
break;
|
||||
case 15:
|
||||
#line 63 "calc2.y"
|
||||
{ yyval = regs[yystack.l_mark[0]]; }
|
||||
break;
|
||||
case 17:
|
||||
#line 68 "calc2.y"
|
||||
{ yyval = yystack.l_mark[0]; (*base) = (yystack.l_mark[0]==0) ? 8 : 10; }
|
||||
break;
|
||||
case 18:
|
||||
#line 70 "calc2.y"
|
||||
{ yyval = (*base) * yystack.l_mark[-1] + yystack.l_mark[0]; }
|
||||
break;
|
||||
#line 622 "calc2.tab.c"
|
||||
}
|
||||
yystack.s_mark -= yym;
|
||||
yystate = *yystack.s_mark;
|
||||
yystack.l_mark -= yym;
|
||||
yym = yylhs[yyn];
|
||||
if (yystate == 0 && yym == 0)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: after reduction, shifting from state 0 to\
|
||||
state %d\n", YYPREFIX, YYFINAL);
|
||||
#endif
|
||||
yystate = YYFINAL;
|
||||
*++yystack.s_mark = YYFINAL;
|
||||
*++yystack.l_mark = yyval;
|
||||
if (yychar < 0)
|
||||
{
|
||||
if ((yychar = YYLEX) < 0) yychar = 0;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, reading %d (%s)\n",
|
||||
YYPREFIX, YYFINAL, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (yychar == 0) goto yyaccept;
|
||||
goto yyloop;
|
||||
}
|
||||
if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
|
||||
yystate = yytable[yyn];
|
||||
else
|
||||
yystate = yydgoto[yym];
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: after reduction, shifting from state %d \
|
||||
to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
|
||||
#endif
|
||||
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
*++yystack.s_mark = (short) yystate;
|
||||
*++yystack.l_mark = yyval;
|
||||
goto yyloop;
|
||||
|
||||
yyoverflow:
|
||||
yyerror(regs, base, "yacc stack overflow");
|
||||
|
||||
yyabort:
|
||||
yyfreestack(&yystack);
|
||||
return (1);
|
||||
|
||||
yyaccept:
|
||||
yyfreestack(&yystack);
|
||||
return (0);
|
||||
}
|
3
test/calc2.tab.h
Normal file
3
test/calc2.tab.h
Normal file
@ -0,0 +1,3 @@
|
||||
#define DIGIT 257
|
||||
#define LETTER 258
|
||||
#define UMINUS 259
|
120
test/calc2.y
Normal file
120
test/calc2.y
Normal file
@ -0,0 +1,120 @@
|
||||
%parse-param { int regs[26] }
|
||||
%parse-param { int *base }
|
||||
|
||||
%lex-param { int *base }
|
||||
|
||||
%{
|
||||
# include <stdio.h>
|
||||
# include <ctype.h>
|
||||
|
||||
#ifdef YYBISON
|
||||
#define YYLEX_PARAM base
|
||||
#define YYLEX_DECL() yylex(int *YYLEX_PARAM)
|
||||
#define YYERROR_DECL() yyerror(int regs[26], int *base, const char *s)
|
||||
int YYLEX_DECL();
|
||||
static void YYERROR_DECL();
|
||||
#endif
|
||||
|
||||
%}
|
||||
|
||||
%start list
|
||||
|
||||
%token DIGIT LETTER
|
||||
|
||||
%left '|'
|
||||
%left '&'
|
||||
%left '+' '-'
|
||||
%left '*' '/' '%'
|
||||
%left UMINUS /* supplies precedence for unary minus */
|
||||
|
||||
%% /* beginning of rules section */
|
||||
|
||||
list : /* empty */
|
||||
| list stat '\n'
|
||||
| list error '\n'
|
||||
{ yyerrok ; }
|
||||
;
|
||||
|
||||
stat : expr
|
||||
{ printf("%d\n",$1);}
|
||||
| LETTER '=' expr
|
||||
{ regs[$1] = $3; }
|
||||
;
|
||||
|
||||
expr : '(' expr ')'
|
||||
{ $$ = $2; }
|
||||
| expr '+' expr
|
||||
{ $$ = $1 + $3; }
|
||||
| expr '-' expr
|
||||
{ $$ = $1 - $3; }
|
||||
| expr '*' expr
|
||||
{ $$ = $1 * $3; }
|
||||
| expr '/' expr
|
||||
{ $$ = $1 / $3; }
|
||||
| expr '%' expr
|
||||
{ $$ = $1 % $3; }
|
||||
| expr '&' expr
|
||||
{ $$ = $1 & $3; }
|
||||
| expr '|' expr
|
||||
{ $$ = $1 | $3; }
|
||||
| '-' expr %prec UMINUS
|
||||
{ $$ = - $2; }
|
||||
| LETTER
|
||||
{ $$ = regs[$1]; }
|
||||
| number
|
||||
;
|
||||
|
||||
number: DIGIT
|
||||
{ $$ = $1; (*base) = ($1==0) ? 8 : 10; }
|
||||
| number DIGIT
|
||||
{ $$ = (*base) * $1 + $2; }
|
||||
;
|
||||
|
||||
%% /* start of programs */
|
||||
|
||||
#ifdef YYBYACC
|
||||
extern int YYLEX_DECL();
|
||||
#endif
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
int regs[26];
|
||||
int base = 10;
|
||||
|
||||
while(!feof(stdin)) {
|
||||
yyparse(regs, &base);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
YYERROR_DECL()
|
||||
{
|
||||
fprintf(stderr, "%s\n", s);
|
||||
}
|
||||
|
||||
int
|
||||
YYLEX_DECL()
|
||||
{
|
||||
/* lexical analysis routine */
|
||||
/* returns LETTER for a lower case letter, yylval = 0 through 25 */
|
||||
/* return DIGIT for a digit, yylval = 0 through 9 */
|
||||
/* all other characters are returned immediately */
|
||||
|
||||
int c;
|
||||
|
||||
while( (c=getchar()) == ' ' ) { /* skip blanks */ }
|
||||
|
||||
/* c is now nonblank */
|
||||
|
||||
if( islower( c )) {
|
||||
yylval = c - 'a';
|
||||
return ( LETTER );
|
||||
}
|
||||
if( isdigit( c )) {
|
||||
yylval = (c - '0') % (*base);
|
||||
return ( DIGIT );
|
||||
}
|
||||
return( c );
|
||||
}
|
461
test/calc3.output
Normal file
461
test/calc3.output
Normal file
@ -0,0 +1,461 @@
|
||||
0 $accept : list $end
|
||||
|
||||
1 list :
|
||||
2 | list stat '\n'
|
||||
3 | list error '\n'
|
||||
|
||||
4 stat : expr
|
||||
5 | LETTER '=' expr
|
||||
|
||||
6 expr : '(' expr ')'
|
||||
7 | expr '+' expr
|
||||
8 | expr '-' expr
|
||||
9 | expr '*' expr
|
||||
10 | expr '/' expr
|
||||
11 | expr '%' expr
|
||||
12 | expr '&' expr
|
||||
13 | expr '|' expr
|
||||
14 | '-' expr
|
||||
15 | LETTER
|
||||
16 | number
|
||||
|
||||
17 number : DIGIT
|
||||
18 | number DIGIT
|
||||
|
||||
state 0
|
||||
$accept : . list $end (0)
|
||||
list : . (1)
|
||||
|
||||
. reduce 1
|
||||
|
||||
list goto 1
|
||||
|
||||
|
||||
state 1
|
||||
$accept : list . $end (0)
|
||||
list : list . stat '\n' (2)
|
||||
list : list . error '\n' (3)
|
||||
|
||||
$end accept
|
||||
error shift 2
|
||||
DIGIT shift 3
|
||||
LETTER shift 4
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
stat goto 7
|
||||
expr goto 8
|
||||
number goto 9
|
||||
|
||||
|
||||
state 2
|
||||
list : list error . '\n' (3)
|
||||
|
||||
'\n' shift 10
|
||||
. error
|
||||
|
||||
|
||||
state 3
|
||||
number : DIGIT . (17)
|
||||
|
||||
. reduce 17
|
||||
|
||||
|
||||
state 4
|
||||
stat : LETTER . '=' expr (5)
|
||||
expr : LETTER . (15)
|
||||
|
||||
'=' shift 11
|
||||
'|' reduce 15
|
||||
'&' reduce 15
|
||||
'+' reduce 15
|
||||
'-' reduce 15
|
||||
'*' reduce 15
|
||||
'/' reduce 15
|
||||
'%' reduce 15
|
||||
'\n' reduce 15
|
||||
|
||||
|
||||
state 5
|
||||
expr : '-' . expr (14)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 13
|
||||
number goto 9
|
||||
|
||||
|
||||
state 6
|
||||
expr : '(' . expr ')' (6)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 14
|
||||
number goto 9
|
||||
|
||||
|
||||
state 7
|
||||
list : list stat . '\n' (2)
|
||||
|
||||
'\n' shift 15
|
||||
. error
|
||||
|
||||
|
||||
state 8
|
||||
stat : expr . (4)
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
'|' shift 16
|
||||
'&' shift 17
|
||||
'+' shift 18
|
||||
'-' shift 19
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
'\n' reduce 4
|
||||
|
||||
|
||||
state 9
|
||||
expr : number . (16)
|
||||
number : number . DIGIT (18)
|
||||
|
||||
DIGIT shift 23
|
||||
'|' reduce 16
|
||||
'&' reduce 16
|
||||
'+' reduce 16
|
||||
'-' reduce 16
|
||||
'*' reduce 16
|
||||
'/' reduce 16
|
||||
'%' reduce 16
|
||||
'\n' reduce 16
|
||||
')' reduce 16
|
||||
|
||||
|
||||
state 10
|
||||
list : list error '\n' . (3)
|
||||
|
||||
. reduce 3
|
||||
|
||||
|
||||
state 11
|
||||
stat : LETTER '=' . expr (5)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 24
|
||||
number goto 9
|
||||
|
||||
|
||||
state 12
|
||||
expr : LETTER . (15)
|
||||
|
||||
. reduce 15
|
||||
|
||||
|
||||
state 13
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
expr : '-' expr . (14)
|
||||
|
||||
. reduce 14
|
||||
|
||||
|
||||
state 14
|
||||
expr : '(' expr . ')' (6)
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
'|' shift 16
|
||||
'&' shift 17
|
||||
'+' shift 18
|
||||
'-' shift 19
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
')' shift 25
|
||||
. error
|
||||
|
||||
|
||||
state 15
|
||||
list : list stat '\n' . (2)
|
||||
|
||||
. reduce 2
|
||||
|
||||
|
||||
state 16
|
||||
expr : expr '|' . expr (13)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 26
|
||||
number goto 9
|
||||
|
||||
|
||||
state 17
|
||||
expr : expr '&' . expr (12)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 27
|
||||
number goto 9
|
||||
|
||||
|
||||
state 18
|
||||
expr : expr '+' . expr (7)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 28
|
||||
number goto 9
|
||||
|
||||
|
||||
state 19
|
||||
expr : expr '-' . expr (8)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 29
|
||||
number goto 9
|
||||
|
||||
|
||||
state 20
|
||||
expr : expr '*' . expr (9)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 30
|
||||
number goto 9
|
||||
|
||||
|
||||
state 21
|
||||
expr : expr '/' . expr (10)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 31
|
||||
number goto 9
|
||||
|
||||
|
||||
state 22
|
||||
expr : expr '%' . expr (11)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 32
|
||||
number goto 9
|
||||
|
||||
|
||||
state 23
|
||||
number : number DIGIT . (18)
|
||||
|
||||
. reduce 18
|
||||
|
||||
|
||||
state 24
|
||||
stat : LETTER '=' expr . (5)
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
'|' shift 16
|
||||
'&' shift 17
|
||||
'+' shift 18
|
||||
'-' shift 19
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
'\n' reduce 5
|
||||
|
||||
|
||||
state 25
|
||||
expr : '(' expr ')' . (6)
|
||||
|
||||
. reduce 6
|
||||
|
||||
|
||||
state 26
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
expr : expr '|' expr . (13)
|
||||
|
||||
'&' shift 17
|
||||
'+' shift 18
|
||||
'-' shift 19
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
'|' reduce 13
|
||||
'\n' reduce 13
|
||||
')' reduce 13
|
||||
|
||||
|
||||
state 27
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr '&' expr . (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
'+' shift 18
|
||||
'-' shift 19
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
'|' reduce 12
|
||||
'&' reduce 12
|
||||
'\n' reduce 12
|
||||
')' reduce 12
|
||||
|
||||
|
||||
state 28
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr '+' expr . (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
'|' reduce 7
|
||||
'&' reduce 7
|
||||
'+' reduce 7
|
||||
'-' reduce 7
|
||||
'\n' reduce 7
|
||||
')' reduce 7
|
||||
|
||||
|
||||
state 29
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr '-' expr . (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
'|' reduce 8
|
||||
'&' reduce 8
|
||||
'+' reduce 8
|
||||
'-' reduce 8
|
||||
'\n' reduce 8
|
||||
')' reduce 8
|
||||
|
||||
|
||||
state 30
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr '*' expr . (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
. reduce 9
|
||||
|
||||
|
||||
state 31
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr '/' expr . (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
. reduce 10
|
||||
|
||||
|
||||
state 32
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr '%' expr . (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
. reduce 11
|
||||
|
||||
|
||||
16 terminals, 5 nonterminals
|
||||
19 grammar rules, 33 states
|
687
test/calc3.tab.c
Normal file
687
test/calc3.tab.c
Normal file
@ -0,0 +1,687 @@
|
||||
#ifndef lint
|
||||
static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
|
||||
#endif
|
||||
|
||||
#define YYBYACC 1
|
||||
#define YYMAJOR 1
|
||||
#define YYMINOR 9
|
||||
|
||||
#define YYEMPTY (-1)
|
||||
#define yyclearin (yychar = YYEMPTY)
|
||||
#define yyerrok (yyerrflag = 0)
|
||||
#define YYRECOVERING() (yyerrflag != 0)
|
||||
|
||||
|
||||
#ifndef yyparse
|
||||
#define yyparse calc3_parse
|
||||
#endif /* yyparse */
|
||||
|
||||
#ifndef yylex
|
||||
#define yylex calc3_lex
|
||||
#endif /* yylex */
|
||||
|
||||
#ifndef yyerror
|
||||
#define yyerror calc3_error
|
||||
#endif /* yyerror */
|
||||
|
||||
#ifndef yychar
|
||||
#define yychar calc3_char
|
||||
#endif /* yychar */
|
||||
|
||||
#ifndef yyval
|
||||
#define yyval calc3_val
|
||||
#endif /* yyval */
|
||||
|
||||
#ifndef yylval
|
||||
#define yylval calc3_lval
|
||||
#endif /* yylval */
|
||||
|
||||
#ifndef yydebug
|
||||
#define yydebug calc3_debug
|
||||
#endif /* yydebug */
|
||||
|
||||
#ifndef yynerrs
|
||||
#define yynerrs calc3_nerrs
|
||||
#endif /* yynerrs */
|
||||
|
||||
#ifndef yyerrflag
|
||||
#define yyerrflag calc3_errflag
|
||||
#endif /* yyerrflag */
|
||||
|
||||
#ifndef yylhs
|
||||
#define yylhs calc3_lhs
|
||||
#endif /* yylhs */
|
||||
|
||||
#ifndef yylen
|
||||
#define yylen calc3_len
|
||||
#endif /* yylen */
|
||||
|
||||
#ifndef yydefred
|
||||
#define yydefred calc3_defred
|
||||
#endif /* yydefred */
|
||||
|
||||
#ifndef yydgoto
|
||||
#define yydgoto calc3_dgoto
|
||||
#endif /* yydgoto */
|
||||
|
||||
#ifndef yysindex
|
||||
#define yysindex calc3_sindex
|
||||
#endif /* yysindex */
|
||||
|
||||
#ifndef yyrindex
|
||||
#define yyrindex calc3_rindex
|
||||
#endif /* yyrindex */
|
||||
|
||||
#ifndef yygindex
|
||||
#define yygindex calc3_gindex
|
||||
#endif /* yygindex */
|
||||
|
||||
#ifndef yytable
|
||||
#define yytable calc3_table
|
||||
#endif /* yytable */
|
||||
|
||||
#ifndef yycheck
|
||||
#define yycheck calc3_check
|
||||
#endif /* yycheck */
|
||||
|
||||
#ifndef yyname
|
||||
#define yyname calc3_name
|
||||
#endif /* yyname */
|
||||
|
||||
#ifndef yyrule
|
||||
#define yyrule calc3_rule
|
||||
#endif /* yyrule */
|
||||
#define YYPREFIX "calc3_"
|
||||
|
||||
#define YYPURE 1
|
||||
|
||||
#line 9 "calc3.y"
|
||||
# include <stdio.h>
|
||||
# include <ctype.h>
|
||||
|
||||
#ifdef YYBISON
|
||||
#define YYSTYPE int
|
||||
#define YYLEX_PARAM base
|
||||
#define YYLEX_DECL() yylex(YYSTYPE *yylval, int *YYLEX_PARAM)
|
||||
#define YYERROR_DECL() yyerror(int regs[26], int *base, const char *s)
|
||||
int YYLEX_DECL();
|
||||
static void YYERROR_DECL();
|
||||
#endif
|
||||
|
||||
#line 112 "calc3.tab.c"
|
||||
|
||||
#ifndef YYSTYPE
|
||||
typedef int YYSTYPE;
|
||||
#endif
|
||||
|
||||
/* compatibility with bison */
|
||||
#ifdef YYPARSE_PARAM
|
||||
/* compatibility with FreeBSD */
|
||||
# ifdef YYPARSE_PARAM_TYPE
|
||||
# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
|
||||
# else
|
||||
# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
|
||||
# endif
|
||||
#else
|
||||
# define YYPARSE_DECL() yyparse(int regs[26], int * base)
|
||||
#endif
|
||||
|
||||
/* Parameters sent to lex. */
|
||||
#ifdef YYLEX_PARAM
|
||||
# ifdef YYLEX_PARAM_TYPE
|
||||
# define YYLEX_DECL() yylex(YYSTYPE *yylval, YYLEX_PARAM_TYPE YYLEX_PARAM)
|
||||
# else
|
||||
# define YYLEX_DECL() yylex(YYSTYPE *yylval, void * YYLEX_PARAM)
|
||||
# endif
|
||||
# define YYLEX yylex(&yylval, YYLEX_PARAM)
|
||||
#else
|
||||
# define YYLEX_DECL() yylex(YYSTYPE *yylval, int * base)
|
||||
# define YYLEX yylex(&yylval, base)
|
||||
#endif
|
||||
|
||||
/* Parameters sent to yyerror. */
|
||||
#ifndef YYERROR_DECL
|
||||
#define YYERROR_DECL() yyerror(int regs[26], int * base, const char *s)
|
||||
#endif
|
||||
#ifndef YYERROR_CALL
|
||||
#define YYERROR_CALL(msg) yyerror(regs, base, msg)
|
||||
#endif
|
||||
|
||||
extern int YYPARSE_DECL();
|
||||
|
||||
#define DIGIT 257
|
||||
#define LETTER 258
|
||||
#define UMINUS 259
|
||||
#define YYERRCODE 256
|
||||
static const short calc3_lhs[] = { -1,
|
||||
0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 3, 3,
|
||||
};
|
||||
static const short calc3_len[] = { 2,
|
||||
0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 2, 1, 1, 1, 2,
|
||||
};
|
||||
static const short calc3_defred[] = { 1,
|
||||
0, 0, 17, 0, 0, 0, 0, 0, 0, 3,
|
||||
0, 15, 14, 0, 2, 0, 0, 0, 0, 0,
|
||||
0, 0, 18, 0, 6, 0, 0, 0, 0, 9,
|
||||
10, 11,
|
||||
};
|
||||
static const short calc3_dgoto[] = { 1,
|
||||
7, 8, 9,
|
||||
};
|
||||
static const short calc3_sindex[] = { 0,
|
||||
-40, -7, 0, -55, -38, -38, 1, -29, -247, 0,
|
||||
-38, 0, 0, 22, 0, -38, -38, -38, -38, -38,
|
||||
-38, -38, 0, -29, 0, 51, 60, -20, -20, 0,
|
||||
0, 0,
|
||||
};
|
||||
static const short calc3_rindex[] = { 0,
|
||||
0, 0, 0, 2, 0, 0, 0, 9, -9, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 10, 0, -6, 14, 5, 13, 0,
|
||||
0, 0,
|
||||
};
|
||||
static const short calc3_gindex[] = { 0,
|
||||
0, 65, 0,
|
||||
};
|
||||
#define YYTABLESIZE 220
|
||||
static const short calc3_table[] = { 6,
|
||||
16, 6, 10, 13, 5, 11, 5, 22, 17, 23,
|
||||
15, 15, 20, 18, 7, 19, 22, 21, 4, 5,
|
||||
0, 20, 8, 12, 0, 0, 21, 16, 16, 0,
|
||||
0, 16, 16, 16, 13, 16, 0, 16, 15, 15,
|
||||
0, 0, 7, 15, 15, 7, 15, 7, 15, 7,
|
||||
8, 12, 0, 8, 12, 8, 0, 8, 22, 17,
|
||||
0, 0, 25, 20, 18, 0, 19, 0, 21, 13,
|
||||
14, 0, 0, 0, 0, 24, 0, 0, 0, 0,
|
||||
26, 27, 28, 29, 30, 31, 32, 22, 17, 0,
|
||||
0, 0, 20, 18, 16, 19, 22, 21, 0, 0,
|
||||
0, 20, 18, 0, 19, 0, 21, 0, 0, 0,
|
||||
0, 0, 0, 0, 16, 0, 0, 13, 0, 0,
|
||||
0, 0, 0, 0, 0, 15, 0, 0, 7, 0,
|
||||
0, 0, 0, 0, 0, 0, 8, 12, 0, 0,
|
||||
0, 0, 0, 0, 0, 16, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 2, 3, 4, 3, 12,
|
||||
};
|
||||
static const short calc3_check[] = { 40,
|
||||
10, 40, 10, 10, 45, 61, 45, 37, 38, 257,
|
||||
10, 10, 42, 43, 10, 45, 37, 47, 10, 10,
|
||||
-1, 42, 10, 10, -1, -1, 47, 37, 38, -1,
|
||||
-1, 41, 42, 43, 41, 45, -1, 47, 37, 38,
|
||||
-1, -1, 38, 42, 43, 41, 45, 43, 47, 45,
|
||||
38, 38, -1, 41, 41, 43, -1, 45, 37, 38,
|
||||
-1, -1, 41, 42, 43, -1, 45, -1, 47, 5,
|
||||
6, -1, -1, -1, -1, 11, -1, -1, -1, -1,
|
||||
16, 17, 18, 19, 20, 21, 22, 37, 38, -1,
|
||||
-1, -1, 42, 43, 124, 45, 37, 47, -1, -1,
|
||||
-1, 42, 43, -1, 45, -1, 47, -1, -1, -1,
|
||||
-1, -1, -1, -1, 124, -1, -1, 124, -1, -1,
|
||||
-1, -1, -1, -1, -1, 124, -1, -1, 124, -1,
|
||||
-1, -1, -1, -1, -1, -1, 124, 124, -1, -1,
|
||||
-1, -1, -1, -1, -1, 124, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, 256, 257, 258, 257, 258,
|
||||
};
|
||||
#define YYFINAL 1
|
||||
#ifndef YYDEBUG
|
||||
#define YYDEBUG 0
|
||||
#endif
|
||||
#define YYMAXTOKEN 259
|
||||
#if YYDEBUG
|
||||
static const char *yyname[] = {
|
||||
|
||||
"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'",0,"'-'",0,"'/'",0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'|'",0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,"DIGIT","LETTER","UMINUS",
|
||||
};
|
||||
static const char *yyrule[] = {
|
||||
"$accept : list",
|
||||
"list :",
|
||||
"list : list stat '\\n'",
|
||||
"list : list error '\\n'",
|
||||
"stat : expr",
|
||||
"stat : LETTER '=' expr",
|
||||
"expr : '(' expr ')'",
|
||||
"expr : expr '+' expr",
|
||||
"expr : expr '-' expr",
|
||||
"expr : expr '*' expr",
|
||||
"expr : expr '/' expr",
|
||||
"expr : expr '%' expr",
|
||||
"expr : expr '&' expr",
|
||||
"expr : expr '|' expr",
|
||||
"expr : '-' expr",
|
||||
"expr : LETTER",
|
||||
"expr : number",
|
||||
"number : DIGIT",
|
||||
"number : number DIGIT",
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
int yydebug;
|
||||
int yynerrs;
|
||||
|
||||
/* define the initial stack-sizes */
|
||||
#ifdef YYSTACKSIZE
|
||||
#undef YYMAXDEPTH
|
||||
#define YYMAXDEPTH YYSTACKSIZE
|
||||
#else
|
||||
#ifdef YYMAXDEPTH
|
||||
#define YYSTACKSIZE YYMAXDEPTH
|
||||
#else
|
||||
#define YYSTACKSIZE 500
|
||||
#define YYMAXDEPTH 500
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define YYINITSTACKSIZE 500
|
||||
|
||||
typedef struct {
|
||||
unsigned stacksize;
|
||||
short *s_base;
|
||||
short *s_mark;
|
||||
short *s_last;
|
||||
YYSTYPE *l_base;
|
||||
YYSTYPE *l_mark;
|
||||
} YYSTACKDATA;
|
||||
#line 76 "calc3.y"
|
||||
/* start of programs */
|
||||
|
||||
#ifdef YYBYACC
|
||||
extern int YYLEX_DECL();
|
||||
#endif
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
int regs[26];
|
||||
int base = 10;
|
||||
|
||||
while(!feof(stdin)) {
|
||||
yyparse(regs, &base);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
YYERROR_DECL()
|
||||
{
|
||||
fprintf(stderr, "%s\n", s);
|
||||
}
|
||||
|
||||
int
|
||||
YYLEX_DECL()
|
||||
{
|
||||
/* lexical analysis routine */
|
||||
/* returns LETTER for a lower case letter, yylval = 0 through 25 */
|
||||
/* return DIGIT for a digit, yylval = 0 through 9 */
|
||||
/* all other characters are returned immediately */
|
||||
|
||||
int c;
|
||||
|
||||
while( (c=getchar()) == ' ' ) { /* skip blanks */ }
|
||||
|
||||
/* c is now nonblank */
|
||||
|
||||
if( islower( c )) {
|
||||
*yylval = (c - 'a');
|
||||
return ( LETTER );
|
||||
}
|
||||
if( isdigit( c )) {
|
||||
*yylval = (c - '0') % (*base);
|
||||
return ( DIGIT );
|
||||
}
|
||||
return( c );
|
||||
}
|
||||
#line 354 "calc3.tab.c"
|
||||
|
||||
#if YYDEBUG
|
||||
#include <stdio.h> /* needed for printf */
|
||||
#endif
|
||||
|
||||
#include <stdlib.h> /* needed for malloc, etc */
|
||||
#include <string.h> /* needed for memset */
|
||||
|
||||
/* allocate initial stack or double stack size, up to YYMAXDEPTH */
|
||||
static int yygrowstack(YYSTACKDATA *data)
|
||||
{
|
||||
int i;
|
||||
unsigned newsize;
|
||||
short *newss;
|
||||
YYSTYPE *newvs;
|
||||
|
||||
if ((newsize = data->stacksize) == 0)
|
||||
newsize = YYINITSTACKSIZE;
|
||||
else if (newsize >= YYMAXDEPTH)
|
||||
return -1;
|
||||
else if ((newsize *= 2) > YYMAXDEPTH)
|
||||
newsize = YYMAXDEPTH;
|
||||
|
||||
i = data->s_mark - data->s_base;
|
||||
newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
|
||||
if (newss == 0)
|
||||
return -1;
|
||||
|
||||
data->s_base = newss;
|
||||
data->s_mark = newss + i;
|
||||
|
||||
newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
|
||||
if (newvs == 0)
|
||||
return -1;
|
||||
|
||||
data->l_base = newvs;
|
||||
data->l_mark = newvs + i;
|
||||
|
||||
data->stacksize = newsize;
|
||||
data->s_last = data->s_base + newsize - 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if YYPURE || defined(YY_NO_LEAKS)
|
||||
static void yyfreestack(YYSTACKDATA *data)
|
||||
{
|
||||
free(data->s_base);
|
||||
free(data->l_base);
|
||||
memset(data, 0, sizeof(*data));
|
||||
}
|
||||
#else
|
||||
#define yyfreestack(data) /* nothing */
|
||||
#endif
|
||||
|
||||
#define YYABORT goto yyabort
|
||||
#define YYREJECT goto yyabort
|
||||
#define YYACCEPT goto yyaccept
|
||||
#define YYERROR goto yyerrlab
|
||||
|
||||
int
|
||||
YYPARSE_DECL()
|
||||
{
|
||||
int yyerrflag;
|
||||
int yychar;
|
||||
YYSTYPE yyval;
|
||||
YYSTYPE yylval;
|
||||
|
||||
/* variables for the parser stack */
|
||||
YYSTACKDATA yystack;
|
||||
int yym, yyn, yystate;
|
||||
#if YYDEBUG
|
||||
const char *yys;
|
||||
|
||||
if ((yys = getenv("YYDEBUG")) != 0)
|
||||
{
|
||||
yyn = *yys;
|
||||
if (yyn >= '0' && yyn <= '9')
|
||||
yydebug = yyn - '0';
|
||||
}
|
||||
#endif
|
||||
|
||||
yynerrs = 0;
|
||||
yyerrflag = 0;
|
||||
yychar = YYEMPTY;
|
||||
yystate = 0;
|
||||
|
||||
#if YYPURE
|
||||
memset(&yystack, 0, sizeof(yystack));
|
||||
#endif
|
||||
|
||||
if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
|
||||
yystack.s_mark = yystack.s_base;
|
||||
yystack.l_mark = yystack.l_base;
|
||||
yystate = 0;
|
||||
*yystack.s_mark = 0;
|
||||
|
||||
yyloop:
|
||||
if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
|
||||
if (yychar < 0)
|
||||
{
|
||||
if ((yychar = YYLEX) < 0) yychar = 0;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, reading %d (%s)\n",
|
||||
YYPREFIX, yystate, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, shifting to state %d\n",
|
||||
YYPREFIX, yystate, yytable[yyn]);
|
||||
#endif
|
||||
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
yystate = yytable[yyn];
|
||||
*++yystack.s_mark = yytable[yyn];
|
||||
*++yystack.l_mark = yylval;
|
||||
yychar = YYEMPTY;
|
||||
if (yyerrflag > 0) --yyerrflag;
|
||||
goto yyloop;
|
||||
}
|
||||
if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
|
||||
{
|
||||
yyn = yytable[yyn];
|
||||
goto yyreduce;
|
||||
}
|
||||
if (yyerrflag) goto yyinrecovery;
|
||||
|
||||
yyerror(regs, base, "syntax error");
|
||||
|
||||
goto yyerrlab;
|
||||
|
||||
yyerrlab:
|
||||
++yynerrs;
|
||||
|
||||
yyinrecovery:
|
||||
if (yyerrflag < 3)
|
||||
{
|
||||
yyerrflag = 3;
|
||||
for (;;)
|
||||
{
|
||||
if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, error recovery shifting\
|
||||
to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
|
||||
#endif
|
||||
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
yystate = yytable[yyn];
|
||||
*++yystack.s_mark = yytable[yyn];
|
||||
*++yystack.l_mark = yylval;
|
||||
goto yyloop;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: error recovery discarding state %d\n",
|
||||
YYPREFIX, *yystack.s_mark);
|
||||
#endif
|
||||
if (yystack.s_mark <= yystack.s_base) goto yyabort;
|
||||
--yystack.s_mark;
|
||||
--yystack.l_mark;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (yychar == 0) goto yyabort;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
|
||||
YYPREFIX, yystate, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
yychar = YYEMPTY;
|
||||
goto yyloop;
|
||||
}
|
||||
|
||||
yyreduce:
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, reducing by rule %d (%s)\n",
|
||||
YYPREFIX, yystate, yyn, yyrule[yyn]);
|
||||
#endif
|
||||
yym = yylen[yyn];
|
||||
if (yym)
|
||||
yyval = yystack.l_mark[1-yym];
|
||||
else
|
||||
memset(&yyval, 0, sizeof yyval);
|
||||
switch (yyn)
|
||||
{
|
||||
case 3:
|
||||
#line 38 "calc3.y"
|
||||
{ yyerrok ; }
|
||||
break;
|
||||
case 4:
|
||||
#line 42 "calc3.y"
|
||||
{ printf("%d\n",yystack.l_mark[0]);}
|
||||
break;
|
||||
case 5:
|
||||
#line 44 "calc3.y"
|
||||
{ regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
|
||||
break;
|
||||
case 6:
|
||||
#line 48 "calc3.y"
|
||||
{ yyval = yystack.l_mark[-1]; }
|
||||
break;
|
||||
case 7:
|
||||
#line 50 "calc3.y"
|
||||
{ yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
|
||||
break;
|
||||
case 8:
|
||||
#line 52 "calc3.y"
|
||||
{ yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
|
||||
break;
|
||||
case 9:
|
||||
#line 54 "calc3.y"
|
||||
{ yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
|
||||
break;
|
||||
case 10:
|
||||
#line 56 "calc3.y"
|
||||
{ yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
|
||||
break;
|
||||
case 11:
|
||||
#line 58 "calc3.y"
|
||||
{ yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
|
||||
break;
|
||||
case 12:
|
||||
#line 60 "calc3.y"
|
||||
{ yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
|
||||
break;
|
||||
case 13:
|
||||
#line 62 "calc3.y"
|
||||
{ yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
|
||||
break;
|
||||
case 14:
|
||||
#line 64 "calc3.y"
|
||||
{ yyval = - yystack.l_mark[0]; }
|
||||
break;
|
||||
case 15:
|
||||
#line 66 "calc3.y"
|
||||
{ yyval = regs[yystack.l_mark[0]]; }
|
||||
break;
|
||||
case 17:
|
||||
#line 71 "calc3.y"
|
||||
{ yyval = yystack.l_mark[0]; (*base) = (yystack.l_mark[0]==0) ? 8 : 10; }
|
||||
break;
|
||||
case 18:
|
||||
#line 73 "calc3.y"
|
||||
{ yyval = (*base) * yystack.l_mark[-1] + yystack.l_mark[0]; }
|
||||
break;
|
||||
#line 627 "calc3.tab.c"
|
||||
}
|
||||
yystack.s_mark -= yym;
|
||||
yystate = *yystack.s_mark;
|
||||
yystack.l_mark -= yym;
|
||||
yym = yylhs[yyn];
|
||||
if (yystate == 0 && yym == 0)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: after reduction, shifting from state 0 to\
|
||||
state %d\n", YYPREFIX, YYFINAL);
|
||||
#endif
|
||||
yystate = YYFINAL;
|
||||
*++yystack.s_mark = YYFINAL;
|
||||
*++yystack.l_mark = yyval;
|
||||
if (yychar < 0)
|
||||
{
|
||||
if ((yychar = YYLEX) < 0) yychar = 0;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, reading %d (%s)\n",
|
||||
YYPREFIX, YYFINAL, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (yychar == 0) goto yyaccept;
|
||||
goto yyloop;
|
||||
}
|
||||
if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
|
||||
yystate = yytable[yyn];
|
||||
else
|
||||
yystate = yydgoto[yym];
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: after reduction, shifting from state %d \
|
||||
to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
|
||||
#endif
|
||||
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
*++yystack.s_mark = (short) yystate;
|
||||
*++yystack.l_mark = yyval;
|
||||
goto yyloop;
|
||||
|
||||
yyoverflow:
|
||||
yyerror(regs, base, "yacc stack overflow");
|
||||
|
||||
yyabort:
|
||||
yyfreestack(&yystack);
|
||||
return (1);
|
||||
|
||||
yyaccept:
|
||||
yyfreestack(&yystack);
|
||||
return (0);
|
||||
}
|
3
test/calc3.tab.h
Normal file
3
test/calc3.tab.h
Normal file
@ -0,0 +1,3 @@
|
||||
#define DIGIT 257
|
||||
#define LETTER 258
|
||||
#define UMINUS 259
|
123
test/calc3.y
Normal file
123
test/calc3.y
Normal file
@ -0,0 +1,123 @@
|
||||
%pure-parser
|
||||
|
||||
%parse-param { int regs[26] }
|
||||
%parse-param { int *base }
|
||||
|
||||
%lex-param { int *base }
|
||||
|
||||
%{
|
||||
# include <stdio.h>
|
||||
# include <ctype.h>
|
||||
|
||||
#ifdef YYBISON
|
||||
#define YYSTYPE int
|
||||
#define YYLEX_PARAM base
|
||||
#define YYLEX_DECL() yylex(YYSTYPE *yylval, int *YYLEX_PARAM)
|
||||
#define YYERROR_DECL() yyerror(int regs[26], int *base, const char *s)
|
||||
int YYLEX_DECL();
|
||||
static void YYERROR_DECL();
|
||||
#endif
|
||||
|
||||
%}
|
||||
|
||||
%start list
|
||||
|
||||
%token DIGIT LETTER
|
||||
|
||||
%left '|'
|
||||
%left '&'
|
||||
%left '+' '-'
|
||||
%left '*' '/' '%'
|
||||
%left UMINUS /* supplies precedence for unary minus */
|
||||
|
||||
%% /* beginning of rules section */
|
||||
|
||||
list : /* empty */
|
||||
| list stat '\n'
|
||||
| list error '\n'
|
||||
{ yyerrok ; }
|
||||
;
|
||||
|
||||
stat : expr
|
||||
{ printf("%d\n",$1);}
|
||||
| LETTER '=' expr
|
||||
{ regs[$1] = $3; }
|
||||
;
|
||||
|
||||
expr : '(' expr ')'
|
||||
{ $$ = $2; }
|
||||
| expr '+' expr
|
||||
{ $$ = $1 + $3; }
|
||||
| expr '-' expr
|
||||
{ $$ = $1 - $3; }
|
||||
| expr '*' expr
|
||||
{ $$ = $1 * $3; }
|
||||
| expr '/' expr
|
||||
{ $$ = $1 / $3; }
|
||||
| expr '%' expr
|
||||
{ $$ = $1 % $3; }
|
||||
| expr '&' expr
|
||||
{ $$ = $1 & $3; }
|
||||
| expr '|' expr
|
||||
{ $$ = $1 | $3; }
|
||||
| '-' expr %prec UMINUS
|
||||
{ $$ = - $2; }
|
||||
| LETTER
|
||||
{ $$ = regs[$1]; }
|
||||
| number
|
||||
;
|
||||
|
||||
number: DIGIT
|
||||
{ $$ = $1; (*base) = ($1==0) ? 8 : 10; }
|
||||
| number DIGIT
|
||||
{ $$ = (*base) * $1 + $2; }
|
||||
;
|
||||
|
||||
%% /* start of programs */
|
||||
|
||||
#ifdef YYBYACC
|
||||
extern int YYLEX_DECL();
|
||||
#endif
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
int regs[26];
|
||||
int base = 10;
|
||||
|
||||
while(!feof(stdin)) {
|
||||
yyparse(regs, &base);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
YYERROR_DECL()
|
||||
{
|
||||
fprintf(stderr, "%s\n", s);
|
||||
}
|
||||
|
||||
int
|
||||
YYLEX_DECL()
|
||||
{
|
||||
/* lexical analysis routine */
|
||||
/* returns LETTER for a lower case letter, yylval = 0 through 25 */
|
||||
/* return DIGIT for a digit, yylval = 0 through 9 */
|
||||
/* all other characters are returned immediately */
|
||||
|
||||
int c;
|
||||
|
||||
while( (c=getchar()) == ' ' ) { /* skip blanks */ }
|
||||
|
||||
/* c is now nonblank */
|
||||
|
||||
if( islower( c )) {
|
||||
*yylval = (c - 'a');
|
||||
return ( LETTER );
|
||||
}
|
||||
if( isdigit( c )) {
|
||||
*yylval = (c - '0') % (*base);
|
||||
return ( DIGIT );
|
||||
}
|
||||
return( c );
|
||||
}
|
580
test/code_calc.code.c
Normal file
580
test/code_calc.code.c
Normal file
@ -0,0 +1,580 @@
|
||||
#ifndef lint
|
||||
static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
|
||||
#endif
|
||||
|
||||
#define YYBYACC 1
|
||||
#define YYMAJOR 1
|
||||
#define YYMINOR 9
|
||||
|
||||
#define YYEMPTY (-1)
|
||||
#define yyclearin (yychar = YYEMPTY)
|
||||
#define yyerrok (yyerrflag = 0)
|
||||
#define YYRECOVERING() (yyerrflag != 0)
|
||||
|
||||
|
||||
#define YYPURE 0
|
||||
|
||||
#line 2 "code_calc.y"
|
||||
# include <stdio.h>
|
||||
# include <ctype.h>
|
||||
|
||||
int regs[26];
|
||||
int base;
|
||||
|
||||
#ifdef YYBISON
|
||||
int yylex(void);
|
||||
static void yyerror(const char *s);
|
||||
#endif
|
||||
|
||||
#line 30 "code_calc.code.c"
|
||||
|
||||
#ifndef YYSTYPE
|
||||
typedef int YYSTYPE;
|
||||
#endif
|
||||
|
||||
/* compatibility with bison */
|
||||
#ifdef YYPARSE_PARAM
|
||||
/* compatibility with FreeBSD */
|
||||
# ifdef YYPARSE_PARAM_TYPE
|
||||
# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
|
||||
# else
|
||||
# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
|
||||
# endif
|
||||
#else
|
||||
# define YYPARSE_DECL() yyparse(void)
|
||||
#endif
|
||||
|
||||
/* Parameters sent to lex. */
|
||||
#ifdef YYLEX_PARAM
|
||||
# define YYLEX_DECL() yylex(void *YYLEX_PARAM)
|
||||
# define YYLEX yylex(YYLEX_PARAM)
|
||||
#else
|
||||
# define YYLEX_DECL() yylex(void)
|
||||
# define YYLEX yylex()
|
||||
#endif
|
||||
|
||||
/* Parameters sent to yyerror. */
|
||||
#ifndef YYERROR_DECL
|
||||
#define YYERROR_DECL() yyerror(const char *s)
|
||||
#endif
|
||||
#ifndef YYERROR_CALL
|
||||
#define YYERROR_CALL(msg) yyerror(msg)
|
||||
#endif
|
||||
|
||||
extern int YYPARSE_DECL();
|
||||
|
||||
#define DIGIT 257
|
||||
#define LETTER 258
|
||||
#define UMINUS 259
|
||||
#define YYERRCODE 256
|
||||
#define YYTABLESIZE 220
|
||||
#define YYFINAL 1
|
||||
#ifndef YYDEBUG
|
||||
#define YYDEBUG 0
|
||||
#endif
|
||||
#define YYMAXTOKEN 259
|
||||
|
||||
#ifndef yyparse
|
||||
#define yyparse calc_parse
|
||||
#endif /* yyparse */
|
||||
|
||||
#ifndef yylex
|
||||
#define yylex calc_lex
|
||||
#endif /* yylex */
|
||||
|
||||
#ifndef yyerror
|
||||
#define yyerror calc_error
|
||||
#endif /* yyerror */
|
||||
|
||||
#ifndef yychar
|
||||
#define yychar calc_char
|
||||
#endif /* yychar */
|
||||
|
||||
#ifndef yyval
|
||||
#define yyval calc_val
|
||||
#endif /* yyval */
|
||||
|
||||
#ifndef yylval
|
||||
#define yylval calc_lval
|
||||
#endif /* yylval */
|
||||
|
||||
#ifndef yydebug
|
||||
#define yydebug calc_debug
|
||||
#endif /* yydebug */
|
||||
|
||||
#ifndef yynerrs
|
||||
#define yynerrs calc_nerrs
|
||||
#endif /* yynerrs */
|
||||
|
||||
#ifndef yyerrflag
|
||||
#define yyerrflag calc_errflag
|
||||
#endif /* yyerrflag */
|
||||
|
||||
#ifndef yylhs
|
||||
#define yylhs calc_lhs
|
||||
#endif /* yylhs */
|
||||
|
||||
#ifndef yylen
|
||||
#define yylen calc_len
|
||||
#endif /* yylen */
|
||||
|
||||
#ifndef yydefred
|
||||
#define yydefred calc_defred
|
||||
#endif /* yydefred */
|
||||
|
||||
#ifndef yydgoto
|
||||
#define yydgoto calc_dgoto
|
||||
#endif /* yydgoto */
|
||||
|
||||
#ifndef yysindex
|
||||
#define yysindex calc_sindex
|
||||
#endif /* yysindex */
|
||||
|
||||
#ifndef yyrindex
|
||||
#define yyrindex calc_rindex
|
||||
#endif /* yyrindex */
|
||||
|
||||
#ifndef yygindex
|
||||
#define yygindex calc_gindex
|
||||
#endif /* yygindex */
|
||||
|
||||
#ifndef yytable
|
||||
#define yytable calc_table
|
||||
#endif /* yytable */
|
||||
|
||||
#ifndef yycheck
|
||||
#define yycheck calc_check
|
||||
#endif /* yycheck */
|
||||
|
||||
#ifndef yyname
|
||||
#define yyname calc_name
|
||||
#endif /* yyname */
|
||||
|
||||
#ifndef yyrule
|
||||
#define yyrule calc_rule
|
||||
#endif /* yyrule */
|
||||
#define YYPREFIX "calc_"
|
||||
|
||||
extern int YYPARSE_DECL();
|
||||
extern short yylhs[];
|
||||
extern short yylen[];
|
||||
extern short yydefred[];
|
||||
extern short yydgoto[];
|
||||
extern short yysindex[];
|
||||
extern short yyrindex[];
|
||||
extern short yygindex[];
|
||||
extern short yytable[];
|
||||
extern short yycheck[];
|
||||
|
||||
#if YYDEBUG
|
||||
extern char *yyname[];
|
||||
extern char *yyrule[];
|
||||
#endif
|
||||
|
||||
int yydebug;
|
||||
int yynerrs;
|
||||
|
||||
int yyerrflag;
|
||||
int yychar;
|
||||
YYSTYPE yyval;
|
||||
YYSTYPE yylval;
|
||||
|
||||
/* define the initial stack-sizes */
|
||||
#ifdef YYSTACKSIZE
|
||||
#undef YYMAXDEPTH
|
||||
#define YYMAXDEPTH YYSTACKSIZE
|
||||
#else
|
||||
#ifdef YYMAXDEPTH
|
||||
#define YYSTACKSIZE YYMAXDEPTH
|
||||
#else
|
||||
#define YYSTACKSIZE 500
|
||||
#define YYMAXDEPTH 500
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define YYINITSTACKSIZE 500
|
||||
|
||||
typedef struct {
|
||||
unsigned stacksize;
|
||||
short *s_base;
|
||||
short *s_mark;
|
||||
short *s_last;
|
||||
YYSTYPE *l_base;
|
||||
YYSTYPE *l_mark;
|
||||
} YYSTACKDATA;
|
||||
/* variables for the parser stack */
|
||||
static YYSTACKDATA yystack;
|
||||
#line 68 "code_calc.y"
|
||||
/* start of programs */
|
||||
|
||||
#ifdef YYBYACC
|
||||
extern int YYLEX_DECL();
|
||||
#endif
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
while(!feof(stdin)) {
|
||||
yyparse();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
yyerror(const char *s)
|
||||
{
|
||||
fprintf(stderr, "%s\n", s);
|
||||
}
|
||||
|
||||
int
|
||||
yylex(void)
|
||||
{
|
||||
/* lexical analysis routine */
|
||||
/* returns LETTER for a lower case letter, yylval = 0 through 25 */
|
||||
/* return DIGIT for a digit, yylval = 0 through 9 */
|
||||
/* all other characters are returned immediately */
|
||||
|
||||
int c;
|
||||
|
||||
while( (c=getchar()) == ' ' ) { /* skip blanks */ }
|
||||
|
||||
/* c is now nonblank */
|
||||
|
||||
if( islower( c )) {
|
||||
yylval = c - 'a';
|
||||
return ( LETTER );
|
||||
}
|
||||
if( isdigit( c )) {
|
||||
yylval = c - '0';
|
||||
return ( DIGIT );
|
||||
}
|
||||
return( c );
|
||||
}
|
||||
#line 254 "code_calc.code.c"
|
||||
|
||||
#if YYDEBUG
|
||||
#include <stdio.h> /* needed for printf */
|
||||
#endif
|
||||
|
||||
#include <stdlib.h> /* needed for malloc, etc */
|
||||
#include <string.h> /* needed for memset */
|
||||
|
||||
/* allocate initial stack or double stack size, up to YYMAXDEPTH */
|
||||
static int yygrowstack(YYSTACKDATA *data)
|
||||
{
|
||||
int i;
|
||||
unsigned newsize;
|
||||
short *newss;
|
||||
YYSTYPE *newvs;
|
||||
|
||||
if ((newsize = data->stacksize) == 0)
|
||||
newsize = YYINITSTACKSIZE;
|
||||
else if (newsize >= YYMAXDEPTH)
|
||||
return -1;
|
||||
else if ((newsize *= 2) > YYMAXDEPTH)
|
||||
newsize = YYMAXDEPTH;
|
||||
|
||||
i = data->s_mark - data->s_base;
|
||||
newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
|
||||
if (newss == 0)
|
||||
return -1;
|
||||
|
||||
data->s_base = newss;
|
||||
data->s_mark = newss + i;
|
||||
|
||||
newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
|
||||
if (newvs == 0)
|
||||
return -1;
|
||||
|
||||
data->l_base = newvs;
|
||||
data->l_mark = newvs + i;
|
||||
|
||||
data->stacksize = newsize;
|
||||
data->s_last = data->s_base + newsize - 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if YYPURE || defined(YY_NO_LEAKS)
|
||||
static void yyfreestack(YYSTACKDATA *data)
|
||||
{
|
||||
free(data->s_base);
|
||||
free(data->l_base);
|
||||
memset(data, 0, sizeof(*data));
|
||||
}
|
||||
#else
|
||||
#define yyfreestack(data) /* nothing */
|
||||
#endif
|
||||
|
||||
#define YYABORT goto yyabort
|
||||
#define YYREJECT goto yyabort
|
||||
#define YYACCEPT goto yyaccept
|
||||
#define YYERROR goto yyerrlab
|
||||
|
||||
int
|
||||
YYPARSE_DECL()
|
||||
{
|
||||
int yym, yyn, yystate;
|
||||
#if YYDEBUG
|
||||
const char *yys;
|
||||
|
||||
if ((yys = getenv("YYDEBUG")) != 0)
|
||||
{
|
||||
yyn = *yys;
|
||||
if (yyn >= '0' && yyn <= '9')
|
||||
yydebug = yyn - '0';
|
||||
}
|
||||
#endif
|
||||
|
||||
yynerrs = 0;
|
||||
yyerrflag = 0;
|
||||
yychar = YYEMPTY;
|
||||
yystate = 0;
|
||||
|
||||
#if YYPURE
|
||||
memset(&yystack, 0, sizeof(yystack));
|
||||
#endif
|
||||
|
||||
if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
|
||||
yystack.s_mark = yystack.s_base;
|
||||
yystack.l_mark = yystack.l_base;
|
||||
yystate = 0;
|
||||
*yystack.s_mark = 0;
|
||||
|
||||
yyloop:
|
||||
if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
|
||||
if (yychar < 0)
|
||||
{
|
||||
if ((yychar = YYLEX) < 0) yychar = 0;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, reading %d (%s)\n",
|
||||
YYPREFIX, yystate, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, shifting to state %d\n",
|
||||
YYPREFIX, yystate, yytable[yyn]);
|
||||
#endif
|
||||
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
yystate = yytable[yyn];
|
||||
*++yystack.s_mark = yytable[yyn];
|
||||
*++yystack.l_mark = yylval;
|
||||
yychar = YYEMPTY;
|
||||
if (yyerrflag > 0) --yyerrflag;
|
||||
goto yyloop;
|
||||
}
|
||||
if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
|
||||
{
|
||||
yyn = yytable[yyn];
|
||||
goto yyreduce;
|
||||
}
|
||||
if (yyerrflag) goto yyinrecovery;
|
||||
|
||||
yyerror("syntax error");
|
||||
|
||||
goto yyerrlab;
|
||||
|
||||
yyerrlab:
|
||||
++yynerrs;
|
||||
|
||||
yyinrecovery:
|
||||
if (yyerrflag < 3)
|
||||
{
|
||||
yyerrflag = 3;
|
||||
for (;;)
|
||||
{
|
||||
if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, error recovery shifting\
|
||||
to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
|
||||
#endif
|
||||
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
yystate = yytable[yyn];
|
||||
*++yystack.s_mark = yytable[yyn];
|
||||
*++yystack.l_mark = yylval;
|
||||
goto yyloop;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: error recovery discarding state %d\n",
|
||||
YYPREFIX, *yystack.s_mark);
|
||||
#endif
|
||||
if (yystack.s_mark <= yystack.s_base) goto yyabort;
|
||||
--yystack.s_mark;
|
||||
--yystack.l_mark;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (yychar == 0) goto yyabort;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
|
||||
YYPREFIX, yystate, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
yychar = YYEMPTY;
|
||||
goto yyloop;
|
||||
}
|
||||
|
||||
yyreduce:
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, reducing by rule %d (%s)\n",
|
||||
YYPREFIX, yystate, yyn, yyrule[yyn]);
|
||||
#endif
|
||||
yym = yylen[yyn];
|
||||
if (yym)
|
||||
yyval = yystack.l_mark[1-yym];
|
||||
else
|
||||
memset(&yyval, 0, sizeof yyval);
|
||||
switch (yyn)
|
||||
{
|
||||
case 3:
|
||||
#line 30 "code_calc.y"
|
||||
{ yyerrok ; }
|
||||
break;
|
||||
case 4:
|
||||
#line 34 "code_calc.y"
|
||||
{ printf("%d\n",yystack.l_mark[0]);}
|
||||
break;
|
||||
case 5:
|
||||
#line 36 "code_calc.y"
|
||||
{ regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
|
||||
break;
|
||||
case 6:
|
||||
#line 40 "code_calc.y"
|
||||
{ yyval = yystack.l_mark[-1]; }
|
||||
break;
|
||||
case 7:
|
||||
#line 42 "code_calc.y"
|
||||
{ yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
|
||||
break;
|
||||
case 8:
|
||||
#line 44 "code_calc.y"
|
||||
{ yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
|
||||
break;
|
||||
case 9:
|
||||
#line 46 "code_calc.y"
|
||||
{ yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
|
||||
break;
|
||||
case 10:
|
||||
#line 48 "code_calc.y"
|
||||
{ yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
|
||||
break;
|
||||
case 11:
|
||||
#line 50 "code_calc.y"
|
||||
{ yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
|
||||
break;
|
||||
case 12:
|
||||
#line 52 "code_calc.y"
|
||||
{ yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
|
||||
break;
|
||||
case 13:
|
||||
#line 54 "code_calc.y"
|
||||
{ yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
|
||||
break;
|
||||
case 14:
|
||||
#line 56 "code_calc.y"
|
||||
{ yyval = - yystack.l_mark[0]; }
|
||||
break;
|
||||
case 15:
|
||||
#line 58 "code_calc.y"
|
||||
{ yyval = regs[yystack.l_mark[0]]; }
|
||||
break;
|
||||
case 17:
|
||||
#line 63 "code_calc.y"
|
||||
{ yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; }
|
||||
break;
|
||||
case 18:
|
||||
#line 65 "code_calc.y"
|
||||
{ yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; }
|
||||
break;
|
||||
#line 520 "code_calc.code.c"
|
||||
}
|
||||
yystack.s_mark -= yym;
|
||||
yystate = *yystack.s_mark;
|
||||
yystack.l_mark -= yym;
|
||||
yym = yylhs[yyn];
|
||||
if (yystate == 0 && yym == 0)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: after reduction, shifting from state 0 to\
|
||||
state %d\n", YYPREFIX, YYFINAL);
|
||||
#endif
|
||||
yystate = YYFINAL;
|
||||
*++yystack.s_mark = YYFINAL;
|
||||
*++yystack.l_mark = yyval;
|
||||
if (yychar < 0)
|
||||
{
|
||||
if ((yychar = YYLEX) < 0) yychar = 0;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, reading %d (%s)\n",
|
||||
YYPREFIX, YYFINAL, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (yychar == 0) goto yyaccept;
|
||||
goto yyloop;
|
||||
}
|
||||
if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
|
||||
yystate = yytable[yyn];
|
||||
else
|
||||
yystate = yydgoto[yym];
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: after reduction, shifting from state %d \
|
||||
to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
|
||||
#endif
|
||||
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
*++yystack.s_mark = (short) yystate;
|
||||
*++yystack.l_mark = yyval;
|
||||
goto yyloop;
|
||||
|
||||
yyoverflow:
|
||||
yyerror("yacc stack overflow");
|
||||
|
||||
yyabort:
|
||||
yyfreestack(&yystack);
|
||||
return (1);
|
||||
|
||||
yyaccept:
|
||||
yyfreestack(&yystack);
|
||||
return (0);
|
||||
}
|
461
test/code_calc.output
Normal file
461
test/code_calc.output
Normal file
@ -0,0 +1,461 @@
|
||||
0 $accept : list $end
|
||||
|
||||
1 list :
|
||||
2 | list stat '\n'
|
||||
3 | list error '\n'
|
||||
|
||||
4 stat : expr
|
||||
5 | LETTER '=' expr
|
||||
|
||||
6 expr : '(' expr ')'
|
||||
7 | expr '+' expr
|
||||
8 | expr '-' expr
|
||||
9 | expr '*' expr
|
||||
10 | expr '/' expr
|
||||
11 | expr '%' expr
|
||||
12 | expr '&' expr
|
||||
13 | expr '|' expr
|
||||
14 | '-' expr
|
||||
15 | LETTER
|
||||
16 | number
|
||||
|
||||
17 number : DIGIT
|
||||
18 | number DIGIT
|
||||
|
||||
state 0
|
||||
$accept : . list $end (0)
|
||||
list : . (1)
|
||||
|
||||
. reduce 1
|
||||
|
||||
list goto 1
|
||||
|
||||
|
||||
state 1
|
||||
$accept : list . $end (0)
|
||||
list : list . stat '\n' (2)
|
||||
list : list . error '\n' (3)
|
||||
|
||||
$end accept
|
||||
error shift 2
|
||||
DIGIT shift 3
|
||||
LETTER shift 4
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
stat goto 7
|
||||
expr goto 8
|
||||
number goto 9
|
||||
|
||||
|
||||
state 2
|
||||
list : list error . '\n' (3)
|
||||
|
||||
'\n' shift 10
|
||||
. error
|
||||
|
||||
|
||||
state 3
|
||||
number : DIGIT . (17)
|
||||
|
||||
. reduce 17
|
||||
|
||||
|
||||
state 4
|
||||
stat : LETTER . '=' expr (5)
|
||||
expr : LETTER . (15)
|
||||
|
||||
'=' shift 11
|
||||
'|' reduce 15
|
||||
'&' reduce 15
|
||||
'+' reduce 15
|
||||
'-' reduce 15
|
||||
'*' reduce 15
|
||||
'/' reduce 15
|
||||
'%' reduce 15
|
||||
'\n' reduce 15
|
||||
|
||||
|
||||
state 5
|
||||
expr : '-' . expr (14)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 13
|
||||
number goto 9
|
||||
|
||||
|
||||
state 6
|
||||
expr : '(' . expr ')' (6)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 14
|
||||
number goto 9
|
||||
|
||||
|
||||
state 7
|
||||
list : list stat . '\n' (2)
|
||||
|
||||
'\n' shift 15
|
||||
. error
|
||||
|
||||
|
||||
state 8
|
||||
stat : expr . (4)
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
'|' shift 16
|
||||
'&' shift 17
|
||||
'+' shift 18
|
||||
'-' shift 19
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
'\n' reduce 4
|
||||
|
||||
|
||||
state 9
|
||||
expr : number . (16)
|
||||
number : number . DIGIT (18)
|
||||
|
||||
DIGIT shift 23
|
||||
'|' reduce 16
|
||||
'&' reduce 16
|
||||
'+' reduce 16
|
||||
'-' reduce 16
|
||||
'*' reduce 16
|
||||
'/' reduce 16
|
||||
'%' reduce 16
|
||||
'\n' reduce 16
|
||||
')' reduce 16
|
||||
|
||||
|
||||
state 10
|
||||
list : list error '\n' . (3)
|
||||
|
||||
. reduce 3
|
||||
|
||||
|
||||
state 11
|
||||
stat : LETTER '=' . expr (5)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 24
|
||||
number goto 9
|
||||
|
||||
|
||||
state 12
|
||||
expr : LETTER . (15)
|
||||
|
||||
. reduce 15
|
||||
|
||||
|
||||
state 13
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
expr : '-' expr . (14)
|
||||
|
||||
. reduce 14
|
||||
|
||||
|
||||
state 14
|
||||
expr : '(' expr . ')' (6)
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
'|' shift 16
|
||||
'&' shift 17
|
||||
'+' shift 18
|
||||
'-' shift 19
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
')' shift 25
|
||||
. error
|
||||
|
||||
|
||||
state 15
|
||||
list : list stat '\n' . (2)
|
||||
|
||||
. reduce 2
|
||||
|
||||
|
||||
state 16
|
||||
expr : expr '|' . expr (13)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 26
|
||||
number goto 9
|
||||
|
||||
|
||||
state 17
|
||||
expr : expr '&' . expr (12)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 27
|
||||
number goto 9
|
||||
|
||||
|
||||
state 18
|
||||
expr : expr '+' . expr (7)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 28
|
||||
number goto 9
|
||||
|
||||
|
||||
state 19
|
||||
expr : expr '-' . expr (8)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 29
|
||||
number goto 9
|
||||
|
||||
|
||||
state 20
|
||||
expr : expr '*' . expr (9)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 30
|
||||
number goto 9
|
||||
|
||||
|
||||
state 21
|
||||
expr : expr '/' . expr (10)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 31
|
||||
number goto 9
|
||||
|
||||
|
||||
state 22
|
||||
expr : expr '%' . expr (11)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 32
|
||||
number goto 9
|
||||
|
||||
|
||||
state 23
|
||||
number : number DIGIT . (18)
|
||||
|
||||
. reduce 18
|
||||
|
||||
|
||||
state 24
|
||||
stat : LETTER '=' expr . (5)
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
'|' shift 16
|
||||
'&' shift 17
|
||||
'+' shift 18
|
||||
'-' shift 19
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
'\n' reduce 5
|
||||
|
||||
|
||||
state 25
|
||||
expr : '(' expr ')' . (6)
|
||||
|
||||
. reduce 6
|
||||
|
||||
|
||||
state 26
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
expr : expr '|' expr . (13)
|
||||
|
||||
'&' shift 17
|
||||
'+' shift 18
|
||||
'-' shift 19
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
'|' reduce 13
|
||||
'\n' reduce 13
|
||||
')' reduce 13
|
||||
|
||||
|
||||
state 27
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr '&' expr . (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
'+' shift 18
|
||||
'-' shift 19
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
'|' reduce 12
|
||||
'&' reduce 12
|
||||
'\n' reduce 12
|
||||
')' reduce 12
|
||||
|
||||
|
||||
state 28
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr '+' expr . (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
'|' reduce 7
|
||||
'&' reduce 7
|
||||
'+' reduce 7
|
||||
'-' reduce 7
|
||||
'\n' reduce 7
|
||||
')' reduce 7
|
||||
|
||||
|
||||
state 29
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr '-' expr . (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
'|' reduce 8
|
||||
'&' reduce 8
|
||||
'+' reduce 8
|
||||
'-' reduce 8
|
||||
'\n' reduce 8
|
||||
')' reduce 8
|
||||
|
||||
|
||||
state 30
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr '*' expr . (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
. reduce 9
|
||||
|
||||
|
||||
state 31
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr '/' expr . (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
. reduce 10
|
||||
|
||||
|
||||
state 32
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr '%' expr . (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
. reduce 11
|
||||
|
||||
|
||||
16 terminals, 5 nonterminals
|
||||
19 grammar rules, 33 states
|
199
test/code_calc.tab.c
Normal file
199
test/code_calc.tab.c
Normal file
@ -0,0 +1,199 @@
|
||||
|
||||
#ifndef yyparse
|
||||
#define yyparse calc_parse
|
||||
#endif /* yyparse */
|
||||
|
||||
#ifndef yylex
|
||||
#define yylex calc_lex
|
||||
#endif /* yylex */
|
||||
|
||||
#ifndef yyerror
|
||||
#define yyerror calc_error
|
||||
#endif /* yyerror */
|
||||
|
||||
#ifndef yychar
|
||||
#define yychar calc_char
|
||||
#endif /* yychar */
|
||||
|
||||
#ifndef yyval
|
||||
#define yyval calc_val
|
||||
#endif /* yyval */
|
||||
|
||||
#ifndef yylval
|
||||
#define yylval calc_lval
|
||||
#endif /* yylval */
|
||||
|
||||
#ifndef yydebug
|
||||
#define yydebug calc_debug
|
||||
#endif /* yydebug */
|
||||
|
||||
#ifndef yynerrs
|
||||
#define yynerrs calc_nerrs
|
||||
#endif /* yynerrs */
|
||||
|
||||
#ifndef yyerrflag
|
||||
#define yyerrflag calc_errflag
|
||||
#endif /* yyerrflag */
|
||||
|
||||
#ifndef yylhs
|
||||
#define yylhs calc_lhs
|
||||
#endif /* yylhs */
|
||||
|
||||
#ifndef yylen
|
||||
#define yylen calc_len
|
||||
#endif /* yylen */
|
||||
|
||||
#ifndef yydefred
|
||||
#define yydefred calc_defred
|
||||
#endif /* yydefred */
|
||||
|
||||
#ifndef yydgoto
|
||||
#define yydgoto calc_dgoto
|
||||
#endif /* yydgoto */
|
||||
|
||||
#ifndef yysindex
|
||||
#define yysindex calc_sindex
|
||||
#endif /* yysindex */
|
||||
|
||||
#ifndef yyrindex
|
||||
#define yyrindex calc_rindex
|
||||
#endif /* yyrindex */
|
||||
|
||||
#ifndef yygindex
|
||||
#define yygindex calc_gindex
|
||||
#endif /* yygindex */
|
||||
|
||||
#ifndef yytable
|
||||
#define yytable calc_table
|
||||
#endif /* yytable */
|
||||
|
||||
#ifndef yycheck
|
||||
#define yycheck calc_check
|
||||
#endif /* yycheck */
|
||||
|
||||
#ifndef yyname
|
||||
#define yyname calc_name
|
||||
#endif /* yyname */
|
||||
|
||||
#ifndef yyrule
|
||||
#define yyrule calc_rule
|
||||
#endif /* yyrule */
|
||||
#define YYPREFIX "calc_"
|
||||
const short calc_lhs[] = { -1,
|
||||
0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 3, 3,
|
||||
};
|
||||
const short calc_len[] = { 2,
|
||||
0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 2, 1, 1, 1, 2,
|
||||
};
|
||||
const short calc_defred[] = { 1,
|
||||
0, 0, 17, 0, 0, 0, 0, 0, 0, 3,
|
||||
0, 15, 14, 0, 2, 0, 0, 0, 0, 0,
|
||||
0, 0, 18, 0, 6, 0, 0, 0, 0, 9,
|
||||
10, 11,
|
||||
};
|
||||
const short calc_dgoto[] = { 1,
|
||||
7, 8, 9,
|
||||
};
|
||||
const short calc_sindex[] = { 0,
|
||||
-40, -7, 0, -55, -38, -38, 1, -29, -247, 0,
|
||||
-38, 0, 0, 22, 0, -38, -38, -38, -38, -38,
|
||||
-38, -38, 0, -29, 0, 51, 60, -20, -20, 0,
|
||||
0, 0,
|
||||
};
|
||||
const short calc_rindex[] = { 0,
|
||||
0, 0, 0, 2, 0, 0, 0, 9, -9, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 10, 0, -6, 14, 5, 13, 0,
|
||||
0, 0,
|
||||
};
|
||||
const short calc_gindex[] = { 0,
|
||||
0, 65, 0,
|
||||
};
|
||||
const short calc_table[] = { 6,
|
||||
16, 6, 10, 13, 5, 11, 5, 22, 17, 23,
|
||||
15, 15, 20, 18, 7, 19, 22, 21, 4, 5,
|
||||
0, 20, 8, 12, 0, 0, 21, 16, 16, 0,
|
||||
0, 16, 16, 16, 13, 16, 0, 16, 15, 15,
|
||||
0, 0, 7, 15, 15, 7, 15, 7, 15, 7,
|
||||
8, 12, 0, 8, 12, 8, 0, 8, 22, 17,
|
||||
0, 0, 25, 20, 18, 0, 19, 0, 21, 13,
|
||||
14, 0, 0, 0, 0, 24, 0, 0, 0, 0,
|
||||
26, 27, 28, 29, 30, 31, 32, 22, 17, 0,
|
||||
0, 0, 20, 18, 16, 19, 22, 21, 0, 0,
|
||||
0, 20, 18, 0, 19, 0, 21, 0, 0, 0,
|
||||
0, 0, 0, 0, 16, 0, 0, 13, 0, 0,
|
||||
0, 0, 0, 0, 0, 15, 0, 0, 7, 0,
|
||||
0, 0, 0, 0, 0, 0, 8, 12, 0, 0,
|
||||
0, 0, 0, 0, 0, 16, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 2, 3, 4, 3, 12,
|
||||
};
|
||||
const short calc_check[] = { 40,
|
||||
10, 40, 10, 10, 45, 61, 45, 37, 38, 257,
|
||||
10, 10, 42, 43, 10, 45, 37, 47, 10, 10,
|
||||
-1, 42, 10, 10, -1, -1, 47, 37, 38, -1,
|
||||
-1, 41, 42, 43, 41, 45, -1, 47, 37, 38,
|
||||
-1, -1, 38, 42, 43, 41, 45, 43, 47, 45,
|
||||
38, 38, -1, 41, 41, 43, -1, 45, 37, 38,
|
||||
-1, -1, 41, 42, 43, -1, 45, -1, 47, 5,
|
||||
6, -1, -1, -1, -1, 11, -1, -1, -1, -1,
|
||||
16, 17, 18, 19, 20, 21, 22, 37, 38, -1,
|
||||
-1, -1, 42, 43, 124, 45, 37, 47, -1, -1,
|
||||
-1, 42, 43, -1, 45, -1, 47, -1, -1, -1,
|
||||
-1, -1, -1, -1, 124, -1, -1, 124, -1, -1,
|
||||
-1, -1, -1, -1, -1, 124, -1, -1, 124, -1,
|
||||
-1, -1, -1, -1, -1, -1, 124, 124, -1, -1,
|
||||
-1, -1, -1, -1, -1, 124, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, 256, 257, 258, 257, 258,
|
||||
};
|
||||
#ifndef YYDEBUG
|
||||
#define YYDEBUG 0
|
||||
#endif
|
||||
#if YYDEBUG
|
||||
const char *yyname[] = {
|
||||
|
||||
"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'",0,"'-'",0,"'/'",0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'|'",0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,"DIGIT","LETTER","UMINUS",
|
||||
};
|
||||
const char *yyrule[] = {
|
||||
"$accept : list",
|
||||
"list :",
|
||||
"list : list stat '\\n'",
|
||||
"list : list error '\\n'",
|
||||
"stat : expr",
|
||||
"stat : LETTER '=' expr",
|
||||
"expr : '(' expr ')'",
|
||||
"expr : expr '+' expr",
|
||||
"expr : expr '-' expr",
|
||||
"expr : expr '*' expr",
|
||||
"expr : expr '/' expr",
|
||||
"expr : expr '%' expr",
|
||||
"expr : expr '&' expr",
|
||||
"expr : expr '|' expr",
|
||||
"expr : '-' expr",
|
||||
"expr : LETTER",
|
||||
"expr : number",
|
||||
"number : DIGIT",
|
||||
"number : number DIGIT",
|
||||
|
||||
};
|
||||
#endif
|
3
test/code_calc.tab.h
Normal file
3
test/code_calc.tab.h
Normal file
@ -0,0 +1,3 @@
|
||||
#define DIGIT 257
|
||||
#define LETTER 258
|
||||
#define UMINUS 259
|
112
test/code_calc.y
Normal file
112
test/code_calc.y
Normal file
@ -0,0 +1,112 @@
|
||||
%{
|
||||
# include <stdio.h>
|
||||
# include <ctype.h>
|
||||
|
||||
int regs[26];
|
||||
int base;
|
||||
|
||||
#ifdef YYBISON
|
||||
int yylex(void);
|
||||
static void yyerror(const char *s);
|
||||
#endif
|
||||
|
||||
%}
|
||||
|
||||
%start list
|
||||
|
||||
%token DIGIT LETTER
|
||||
|
||||
%left '|'
|
||||
%left '&'
|
||||
%left '+' '-'
|
||||
%left '*' '/' '%'
|
||||
%left UMINUS /* supplies precedence for unary minus */
|
||||
|
||||
%% /* beginning of rules section */
|
||||
|
||||
list : /* empty */
|
||||
| list stat '\n'
|
||||
| list error '\n'
|
||||
{ yyerrok ; }
|
||||
;
|
||||
|
||||
stat : expr
|
||||
{ printf("%d\n",$1);}
|
||||
| LETTER '=' expr
|
||||
{ regs[$1] = $3; }
|
||||
;
|
||||
|
||||
expr : '(' expr ')'
|
||||
{ $$ = $2; }
|
||||
| expr '+' expr
|
||||
{ $$ = $1 + $3; }
|
||||
| expr '-' expr
|
||||
{ $$ = $1 - $3; }
|
||||
| expr '*' expr
|
||||
{ $$ = $1 * $3; }
|
||||
| expr '/' expr
|
||||
{ $$ = $1 / $3; }
|
||||
| expr '%' expr
|
||||
{ $$ = $1 % $3; }
|
||||
| expr '&' expr
|
||||
{ $$ = $1 & $3; }
|
||||
| expr '|' expr
|
||||
{ $$ = $1 | $3; }
|
||||
| '-' expr %prec UMINUS
|
||||
{ $$ = - $2; }
|
||||
| LETTER
|
||||
{ $$ = regs[$1]; }
|
||||
| number
|
||||
;
|
||||
|
||||
number: DIGIT
|
||||
{ $$ = $1; base = ($1==0) ? 8 : 10; }
|
||||
| number DIGIT
|
||||
{ $$ = base * $1 + $2; }
|
||||
;
|
||||
|
||||
%% /* start of programs */
|
||||
|
||||
#ifdef YYBYACC
|
||||
extern int YYLEX_DECL();
|
||||
#endif
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
while(!feof(stdin)) {
|
||||
yyparse();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
yyerror(const char *s)
|
||||
{
|
||||
fprintf(stderr, "%s\n", s);
|
||||
}
|
||||
|
||||
int
|
||||
yylex(void)
|
||||
{
|
||||
/* lexical analysis routine */
|
||||
/* returns LETTER for a lower case letter, yylval = 0 through 25 */
|
||||
/* return DIGIT for a digit, yylval = 0 through 9 */
|
||||
/* all other characters are returned immediately */
|
||||
|
||||
int c;
|
||||
|
||||
while( (c=getchar()) == ' ' ) { /* skip blanks */ }
|
||||
|
||||
/* c is now nonblank */
|
||||
|
||||
if( islower( c )) {
|
||||
yylval = c - 'a';
|
||||
return ( LETTER );
|
||||
}
|
||||
if( isdigit( c )) {
|
||||
yylval = c - '0';
|
||||
return ( DIGIT );
|
||||
}
|
||||
return( c );
|
||||
}
|
491
test/code_error.code.c
Normal file
491
test/code_error.code.c
Normal file
@ -0,0 +1,491 @@
|
||||
#ifndef lint
|
||||
static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
|
||||
#endif
|
||||
|
||||
#define YYBYACC 1
|
||||
#define YYMAJOR 1
|
||||
#define YYMINOR 9
|
||||
|
||||
#define YYEMPTY (-1)
|
||||
#define yyclearin (yychar = YYEMPTY)
|
||||
#define yyerrok (yyerrflag = 0)
|
||||
#define YYRECOVERING() (yyerrflag != 0)
|
||||
|
||||
|
||||
#define YYPURE 0
|
||||
|
||||
#line 2 "code_error.y"
|
||||
|
||||
#ifdef YYBISON
|
||||
int yylex(void);
|
||||
static void yyerror(const char *);
|
||||
#endif
|
||||
|
||||
#line 25 "code_error.code.c"
|
||||
|
||||
#ifndef YYSTYPE
|
||||
typedef int YYSTYPE;
|
||||
#endif
|
||||
|
||||
/* compatibility with bison */
|
||||
#ifdef YYPARSE_PARAM
|
||||
/* compatibility with FreeBSD */
|
||||
# ifdef YYPARSE_PARAM_TYPE
|
||||
# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
|
||||
# else
|
||||
# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
|
||||
# endif
|
||||
#else
|
||||
# define YYPARSE_DECL() yyparse(void)
|
||||
#endif
|
||||
|
||||
/* Parameters sent to lex. */
|
||||
#ifdef YYLEX_PARAM
|
||||
# define YYLEX_DECL() yylex(void *YYLEX_PARAM)
|
||||
# define YYLEX yylex(YYLEX_PARAM)
|
||||
#else
|
||||
# define YYLEX_DECL() yylex(void)
|
||||
# define YYLEX yylex()
|
||||
#endif
|
||||
|
||||
/* Parameters sent to yyerror. */
|
||||
#ifndef YYERROR_DECL
|
||||
#define YYERROR_DECL() yyerror(const char *s)
|
||||
#endif
|
||||
#ifndef YYERROR_CALL
|
||||
#define YYERROR_CALL(msg) yyerror(msg)
|
||||
#endif
|
||||
|
||||
extern int YYPARSE_DECL();
|
||||
|
||||
#define YYERRCODE 256
|
||||
#define YYTABLESIZE 0
|
||||
#define YYFINAL 2
|
||||
#ifndef YYDEBUG
|
||||
#define YYDEBUG 0
|
||||
#endif
|
||||
#define YYMAXTOKEN 0
|
||||
|
||||
#ifndef yyparse
|
||||
#define yyparse error_parse
|
||||
#endif /* yyparse */
|
||||
|
||||
#ifndef yylex
|
||||
#define yylex error_lex
|
||||
#endif /* yylex */
|
||||
|
||||
#ifndef yyerror
|
||||
#define yyerror error_error
|
||||
#endif /* yyerror */
|
||||
|
||||
#ifndef yychar
|
||||
#define yychar error_char
|
||||
#endif /* yychar */
|
||||
|
||||
#ifndef yyval
|
||||
#define yyval error_val
|
||||
#endif /* yyval */
|
||||
|
||||
#ifndef yylval
|
||||
#define yylval error_lval
|
||||
#endif /* yylval */
|
||||
|
||||
#ifndef yydebug
|
||||
#define yydebug error_debug
|
||||
#endif /* yydebug */
|
||||
|
||||
#ifndef yynerrs
|
||||
#define yynerrs error_nerrs
|
||||
#endif /* yynerrs */
|
||||
|
||||
#ifndef yyerrflag
|
||||
#define yyerrflag error_errflag
|
||||
#endif /* yyerrflag */
|
||||
|
||||
#ifndef yylhs
|
||||
#define yylhs error_lhs
|
||||
#endif /* yylhs */
|
||||
|
||||
#ifndef yylen
|
||||
#define yylen error_len
|
||||
#endif /* yylen */
|
||||
|
||||
#ifndef yydefred
|
||||
#define yydefred error_defred
|
||||
#endif /* yydefred */
|
||||
|
||||
#ifndef yydgoto
|
||||
#define yydgoto error_dgoto
|
||||
#endif /* yydgoto */
|
||||
|
||||
#ifndef yysindex
|
||||
#define yysindex error_sindex
|
||||
#endif /* yysindex */
|
||||
|
||||
#ifndef yyrindex
|
||||
#define yyrindex error_rindex
|
||||
#endif /* yyrindex */
|
||||
|
||||
#ifndef yygindex
|
||||
#define yygindex error_gindex
|
||||
#endif /* yygindex */
|
||||
|
||||
#ifndef yytable
|
||||
#define yytable error_table
|
||||
#endif /* yytable */
|
||||
|
||||
#ifndef yycheck
|
||||
#define yycheck error_check
|
||||
#endif /* yycheck */
|
||||
|
||||
#ifndef yyname
|
||||
#define yyname error_name
|
||||
#endif /* yyname */
|
||||
|
||||
#ifndef yyrule
|
||||
#define yyrule error_rule
|
||||
#endif /* yyrule */
|
||||
#define YYPREFIX "error_"
|
||||
|
||||
extern int YYPARSE_DECL();
|
||||
extern short yylhs[];
|
||||
extern short yylen[];
|
||||
extern short yydefred[];
|
||||
extern short yydgoto[];
|
||||
extern short yysindex[];
|
||||
extern short yyrindex[];
|
||||
extern short yygindex[];
|
||||
extern short yytable[];
|
||||
extern short yycheck[];
|
||||
|
||||
#if YYDEBUG
|
||||
extern char *yyname[];
|
||||
extern char *yyrule[];
|
||||
#endif
|
||||
|
||||
int yydebug;
|
||||
int yynerrs;
|
||||
|
||||
int yyerrflag;
|
||||
int yychar;
|
||||
YYSTYPE yyval;
|
||||
YYSTYPE yylval;
|
||||
|
||||
/* define the initial stack-sizes */
|
||||
#ifdef YYSTACKSIZE
|
||||
#undef YYMAXDEPTH
|
||||
#define YYMAXDEPTH YYSTACKSIZE
|
||||
#else
|
||||
#ifdef YYMAXDEPTH
|
||||
#define YYSTACKSIZE YYMAXDEPTH
|
||||
#else
|
||||
#define YYSTACKSIZE 500
|
||||
#define YYMAXDEPTH 500
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define YYINITSTACKSIZE 500
|
||||
|
||||
typedef struct {
|
||||
unsigned stacksize;
|
||||
short *s_base;
|
||||
short *s_mark;
|
||||
short *s_last;
|
||||
YYSTYPE *l_base;
|
||||
YYSTYPE *l_mark;
|
||||
} YYSTACKDATA;
|
||||
/* variables for the parser stack */
|
||||
static YYSTACKDATA yystack;
|
||||
#line 12 "code_error.y"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef YYBYACC
|
||||
extern int YYLEX_DECL();
|
||||
#endif
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
printf("yyparse() = %d\n", yyparse());
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
yylex(void)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void
|
||||
yyerror(const char* s)
|
||||
{
|
||||
printf("%s\n", s);
|
||||
}
|
||||
#line 226 "code_error.code.c"
|
||||
|
||||
#if YYDEBUG
|
||||
#include <stdio.h> /* needed for printf */
|
||||
#endif
|
||||
|
||||
#include <stdlib.h> /* needed for malloc, etc */
|
||||
#include <string.h> /* needed for memset */
|
||||
|
||||
/* allocate initial stack or double stack size, up to YYMAXDEPTH */
|
||||
static int yygrowstack(YYSTACKDATA *data)
|
||||
{
|
||||
int i;
|
||||
unsigned newsize;
|
||||
short *newss;
|
||||
YYSTYPE *newvs;
|
||||
|
||||
if ((newsize = data->stacksize) == 0)
|
||||
newsize = YYINITSTACKSIZE;
|
||||
else if (newsize >= YYMAXDEPTH)
|
||||
return -1;
|
||||
else if ((newsize *= 2) > YYMAXDEPTH)
|
||||
newsize = YYMAXDEPTH;
|
||||
|
||||
i = data->s_mark - data->s_base;
|
||||
newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
|
||||
if (newss == 0)
|
||||
return -1;
|
||||
|
||||
data->s_base = newss;
|
||||
data->s_mark = newss + i;
|
||||
|
||||
newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
|
||||
if (newvs == 0)
|
||||
return -1;
|
||||
|
||||
data->l_base = newvs;
|
||||
data->l_mark = newvs + i;
|
||||
|
||||
data->stacksize = newsize;
|
||||
data->s_last = data->s_base + newsize - 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if YYPURE || defined(YY_NO_LEAKS)
|
||||
static void yyfreestack(YYSTACKDATA *data)
|
||||
{
|
||||
free(data->s_base);
|
||||
free(data->l_base);
|
||||
memset(data, 0, sizeof(*data));
|
||||
}
|
||||
#else
|
||||
#define yyfreestack(data) /* nothing */
|
||||
#endif
|
||||
|
||||
#define YYABORT goto yyabort
|
||||
#define YYREJECT goto yyabort
|
||||
#define YYACCEPT goto yyaccept
|
||||
#define YYERROR goto yyerrlab
|
||||
|
||||
int
|
||||
YYPARSE_DECL()
|
||||
{
|
||||
int yym, yyn, yystate;
|
||||
#if YYDEBUG
|
||||
const char *yys;
|
||||
|
||||
if ((yys = getenv("YYDEBUG")) != 0)
|
||||
{
|
||||
yyn = *yys;
|
||||
if (yyn >= '0' && yyn <= '9')
|
||||
yydebug = yyn - '0';
|
||||
}
|
||||
#endif
|
||||
|
||||
yynerrs = 0;
|
||||
yyerrflag = 0;
|
||||
yychar = YYEMPTY;
|
||||
yystate = 0;
|
||||
|
||||
#if YYPURE
|
||||
memset(&yystack, 0, sizeof(yystack));
|
||||
#endif
|
||||
|
||||
if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
|
||||
yystack.s_mark = yystack.s_base;
|
||||
yystack.l_mark = yystack.l_base;
|
||||
yystate = 0;
|
||||
*yystack.s_mark = 0;
|
||||
|
||||
yyloop:
|
||||
if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
|
||||
if (yychar < 0)
|
||||
{
|
||||
if ((yychar = YYLEX) < 0) yychar = 0;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, reading %d (%s)\n",
|
||||
YYPREFIX, yystate, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, shifting to state %d\n",
|
||||
YYPREFIX, yystate, yytable[yyn]);
|
||||
#endif
|
||||
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
yystate = yytable[yyn];
|
||||
*++yystack.s_mark = yytable[yyn];
|
||||
*++yystack.l_mark = yylval;
|
||||
yychar = YYEMPTY;
|
||||
if (yyerrflag > 0) --yyerrflag;
|
||||
goto yyloop;
|
||||
}
|
||||
if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
|
||||
{
|
||||
yyn = yytable[yyn];
|
||||
goto yyreduce;
|
||||
}
|
||||
if (yyerrflag) goto yyinrecovery;
|
||||
|
||||
yyerror("syntax error");
|
||||
|
||||
goto yyerrlab;
|
||||
|
||||
yyerrlab:
|
||||
++yynerrs;
|
||||
|
||||
yyinrecovery:
|
||||
if (yyerrflag < 3)
|
||||
{
|
||||
yyerrflag = 3;
|
||||
for (;;)
|
||||
{
|
||||
if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, error recovery shifting\
|
||||
to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
|
||||
#endif
|
||||
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
yystate = yytable[yyn];
|
||||
*++yystack.s_mark = yytable[yyn];
|
||||
*++yystack.l_mark = yylval;
|
||||
goto yyloop;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: error recovery discarding state %d\n",
|
||||
YYPREFIX, *yystack.s_mark);
|
||||
#endif
|
||||
if (yystack.s_mark <= yystack.s_base) goto yyabort;
|
||||
--yystack.s_mark;
|
||||
--yystack.l_mark;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (yychar == 0) goto yyabort;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
|
||||
YYPREFIX, yystate, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
yychar = YYEMPTY;
|
||||
goto yyloop;
|
||||
}
|
||||
|
||||
yyreduce:
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, reducing by rule %d (%s)\n",
|
||||
YYPREFIX, yystate, yyn, yyrule[yyn]);
|
||||
#endif
|
||||
yym = yylen[yyn];
|
||||
if (yym)
|
||||
yyval = yystack.l_mark[1-yym];
|
||||
else
|
||||
memset(&yyval, 0, sizeof yyval);
|
||||
switch (yyn)
|
||||
{
|
||||
}
|
||||
yystack.s_mark -= yym;
|
||||
yystate = *yystack.s_mark;
|
||||
yystack.l_mark -= yym;
|
||||
yym = yylhs[yyn];
|
||||
if (yystate == 0 && yym == 0)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: after reduction, shifting from state 0 to\
|
||||
state %d\n", YYPREFIX, YYFINAL);
|
||||
#endif
|
||||
yystate = YYFINAL;
|
||||
*++yystack.s_mark = YYFINAL;
|
||||
*++yystack.l_mark = yyval;
|
||||
if (yychar < 0)
|
||||
{
|
||||
if ((yychar = YYLEX) < 0) yychar = 0;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, reading %d (%s)\n",
|
||||
YYPREFIX, YYFINAL, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (yychar == 0) goto yyaccept;
|
||||
goto yyloop;
|
||||
}
|
||||
if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
|
||||
yystate = yytable[yyn];
|
||||
else
|
||||
yystate = yydgoto[yym];
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: after reduction, shifting from state %d \
|
||||
to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
|
||||
#endif
|
||||
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
*++yystack.s_mark = (short) yystate;
|
||||
*++yystack.l_mark = yyval;
|
||||
goto yyloop;
|
||||
|
||||
yyoverflow:
|
||||
yyerror("yacc stack overflow");
|
||||
|
||||
yyabort:
|
||||
yyfreestack(&yystack);
|
||||
return (1);
|
||||
|
||||
yyaccept:
|
||||
yyfreestack(&yystack);
|
||||
return (0);
|
||||
}
|
27
test/code_error.output
Normal file
27
test/code_error.output
Normal file
@ -0,0 +1,27 @@
|
||||
0 $accept : S $end
|
||||
|
||||
1 S : error
|
||||
|
||||
state 0
|
||||
$accept : . S $end (0)
|
||||
|
||||
error shift 1
|
||||
. error
|
||||
|
||||
S goto 2
|
||||
|
||||
|
||||
state 1
|
||||
S : error . (1)
|
||||
|
||||
. reduce 1
|
||||
|
||||
|
||||
state 2
|
||||
$accept : S . $end (0)
|
||||
|
||||
$end accept
|
||||
|
||||
|
||||
2 terminals, 2 nonterminals
|
||||
2 grammar rules, 3 states
|
118
test/code_error.tab.c
Normal file
118
test/code_error.tab.c
Normal file
@ -0,0 +1,118 @@
|
||||
|
||||
#ifndef yyparse
|
||||
#define yyparse error_parse
|
||||
#endif /* yyparse */
|
||||
|
||||
#ifndef yylex
|
||||
#define yylex error_lex
|
||||
#endif /* yylex */
|
||||
|
||||
#ifndef yyerror
|
||||
#define yyerror error_error
|
||||
#endif /* yyerror */
|
||||
|
||||
#ifndef yychar
|
||||
#define yychar error_char
|
||||
#endif /* yychar */
|
||||
|
||||
#ifndef yyval
|
||||
#define yyval error_val
|
||||
#endif /* yyval */
|
||||
|
||||
#ifndef yylval
|
||||
#define yylval error_lval
|
||||
#endif /* yylval */
|
||||
|
||||
#ifndef yydebug
|
||||
#define yydebug error_debug
|
||||
#endif /* yydebug */
|
||||
|
||||
#ifndef yynerrs
|
||||
#define yynerrs error_nerrs
|
||||
#endif /* yynerrs */
|
||||
|
||||
#ifndef yyerrflag
|
||||
#define yyerrflag error_errflag
|
||||
#endif /* yyerrflag */
|
||||
|
||||
#ifndef yylhs
|
||||
#define yylhs error_lhs
|
||||
#endif /* yylhs */
|
||||
|
||||
#ifndef yylen
|
||||
#define yylen error_len
|
||||
#endif /* yylen */
|
||||
|
||||
#ifndef yydefred
|
||||
#define yydefred error_defred
|
||||
#endif /* yydefred */
|
||||
|
||||
#ifndef yydgoto
|
||||
#define yydgoto error_dgoto
|
||||
#endif /* yydgoto */
|
||||
|
||||
#ifndef yysindex
|
||||
#define yysindex error_sindex
|
||||
#endif /* yysindex */
|
||||
|
||||
#ifndef yyrindex
|
||||
#define yyrindex error_rindex
|
||||
#endif /* yyrindex */
|
||||
|
||||
#ifndef yygindex
|
||||
#define yygindex error_gindex
|
||||
#endif /* yygindex */
|
||||
|
||||
#ifndef yytable
|
||||
#define yytable error_table
|
||||
#endif /* yytable */
|
||||
|
||||
#ifndef yycheck
|
||||
#define yycheck error_check
|
||||
#endif /* yycheck */
|
||||
|
||||
#ifndef yyname
|
||||
#define yyname error_name
|
||||
#endif /* yyname */
|
||||
|
||||
#ifndef yyrule
|
||||
#define yyrule error_rule
|
||||
#endif /* yyrule */
|
||||
#define YYPREFIX "error_"
|
||||
const short error_lhs[] = { -1,
|
||||
0,
|
||||
};
|
||||
const short error_len[] = { 2,
|
||||
1,
|
||||
};
|
||||
const short error_defred[] = { 0,
|
||||
1, 0,
|
||||
};
|
||||
const short error_dgoto[] = { 2,
|
||||
};
|
||||
const short error_sindex[] = { -256,
|
||||
0, 0,
|
||||
};
|
||||
const short error_rindex[] = { 0,
|
||||
0, 0,
|
||||
};
|
||||
const short error_gindex[] = { 0,
|
||||
};
|
||||
const short error_table[] = { 1,
|
||||
};
|
||||
const short error_check[] = { 256,
|
||||
};
|
||||
#ifndef YYDEBUG
|
||||
#define YYDEBUG 0
|
||||
#endif
|
||||
#if YYDEBUG
|
||||
const char *yyname[] = {
|
||||
|
||||
"end-of-file",
|
||||
};
|
||||
const char *yyrule[] = {
|
||||
"$accept : S",
|
||||
"S : error",
|
||||
|
||||
};
|
||||
#endif
|
0
test/code_error.tab.h
Normal file
0
test/code_error.tab.h
Normal file
36
test/code_error.y
Normal file
36
test/code_error.y
Normal file
@ -0,0 +1,36 @@
|
||||
%{
|
||||
|
||||
#ifdef YYBISON
|
||||
int yylex(void);
|
||||
static void yyerror(const char *);
|
||||
#endif
|
||||
|
||||
%}
|
||||
%%
|
||||
S: error
|
||||
%%
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef YYBYACC
|
||||
extern int YYLEX_DECL();
|
||||
#endif
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
printf("yyparse() = %d\n", yyparse());
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
yylex(void)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void
|
||||
yyerror(const char* s)
|
||||
{
|
||||
printf("%s\n", s);
|
||||
}
|
27
test/error.output
Normal file
27
test/error.output
Normal file
@ -0,0 +1,27 @@
|
||||
0 $accept : S $end
|
||||
|
||||
1 S : error
|
||||
|
||||
state 0
|
||||
$accept : . S $end (0)
|
||||
|
||||
error shift 1
|
||||
. error
|
||||
|
||||
S goto 2
|
||||
|
||||
|
||||
state 1
|
||||
S : error . (1)
|
||||
|
||||
. reduce 1
|
||||
|
||||
|
||||
state 2
|
||||
$accept : S . $end (0)
|
||||
|
||||
$end accept
|
||||
|
||||
|
||||
2 terminals, 2 nonterminals
|
||||
2 grammar rules, 3 states
|
501
test/error.tab.c
Normal file
501
test/error.tab.c
Normal file
@ -0,0 +1,501 @@
|
||||
#ifndef lint
|
||||
static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
|
||||
#endif
|
||||
|
||||
#define YYBYACC 1
|
||||
#define YYMAJOR 1
|
||||
#define YYMINOR 9
|
||||
|
||||
#define YYEMPTY (-1)
|
||||
#define yyclearin (yychar = YYEMPTY)
|
||||
#define yyerrok (yyerrflag = 0)
|
||||
#define YYRECOVERING() (yyerrflag != 0)
|
||||
|
||||
|
||||
#ifndef yyparse
|
||||
#define yyparse error_parse
|
||||
#endif /* yyparse */
|
||||
|
||||
#ifndef yylex
|
||||
#define yylex error_lex
|
||||
#endif /* yylex */
|
||||
|
||||
#ifndef yyerror
|
||||
#define yyerror error_error
|
||||
#endif /* yyerror */
|
||||
|
||||
#ifndef yychar
|
||||
#define yychar error_char
|
||||
#endif /* yychar */
|
||||
|
||||
#ifndef yyval
|
||||
#define yyval error_val
|
||||
#endif /* yyval */
|
||||
|
||||
#ifndef yylval
|
||||
#define yylval error_lval
|
||||
#endif /* yylval */
|
||||
|
||||
#ifndef yydebug
|
||||
#define yydebug error_debug
|
||||
#endif /* yydebug */
|
||||
|
||||
#ifndef yynerrs
|
||||
#define yynerrs error_nerrs
|
||||
#endif /* yynerrs */
|
||||
|
||||
#ifndef yyerrflag
|
||||
#define yyerrflag error_errflag
|
||||
#endif /* yyerrflag */
|
||||
|
||||
#ifndef yylhs
|
||||
#define yylhs error_lhs
|
||||
#endif /* yylhs */
|
||||
|
||||
#ifndef yylen
|
||||
#define yylen error_len
|
||||
#endif /* yylen */
|
||||
|
||||
#ifndef yydefred
|
||||
#define yydefred error_defred
|
||||
#endif /* yydefred */
|
||||
|
||||
#ifndef yydgoto
|
||||
#define yydgoto error_dgoto
|
||||
#endif /* yydgoto */
|
||||
|
||||
#ifndef yysindex
|
||||
#define yysindex error_sindex
|
||||
#endif /* yysindex */
|
||||
|
||||
#ifndef yyrindex
|
||||
#define yyrindex error_rindex
|
||||
#endif /* yyrindex */
|
||||
|
||||
#ifndef yygindex
|
||||
#define yygindex error_gindex
|
||||
#endif /* yygindex */
|
||||
|
||||
#ifndef yytable
|
||||
#define yytable error_table
|
||||
#endif /* yytable */
|
||||
|
||||
#ifndef yycheck
|
||||
#define yycheck error_check
|
||||
#endif /* yycheck */
|
||||
|
||||
#ifndef yyname
|
||||
#define yyname error_name
|
||||
#endif /* yyname */
|
||||
|
||||
#ifndef yyrule
|
||||
#define yyrule error_rule
|
||||
#endif /* yyrule */
|
||||
#define YYPREFIX "error_"
|
||||
|
||||
#define YYPURE 0
|
||||
|
||||
#line 2 "error.y"
|
||||
int yylex(void);
|
||||
static void yyerror(const char *);
|
||||
#line 102 "error.tab.c"
|
||||
|
||||
#ifndef YYSTYPE
|
||||
typedef int YYSTYPE;
|
||||
#endif
|
||||
|
||||
/* compatibility with bison */
|
||||
#ifdef YYPARSE_PARAM
|
||||
/* compatibility with FreeBSD */
|
||||
# ifdef YYPARSE_PARAM_TYPE
|
||||
# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
|
||||
# else
|
||||
# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
|
||||
# endif
|
||||
#else
|
||||
# define YYPARSE_DECL() yyparse(void)
|
||||
#endif
|
||||
|
||||
/* Parameters sent to lex. */
|
||||
#ifdef YYLEX_PARAM
|
||||
# define YYLEX_DECL() yylex(void *YYLEX_PARAM)
|
||||
# define YYLEX yylex(YYLEX_PARAM)
|
||||
#else
|
||||
# define YYLEX_DECL() yylex(void)
|
||||
# define YYLEX yylex()
|
||||
#endif
|
||||
|
||||
/* Parameters sent to yyerror. */
|
||||
#ifndef YYERROR_DECL
|
||||
#define YYERROR_DECL() yyerror(const char *s)
|
||||
#endif
|
||||
#ifndef YYERROR_CALL
|
||||
#define YYERROR_CALL(msg) yyerror(msg)
|
||||
#endif
|
||||
|
||||
extern int YYPARSE_DECL();
|
||||
|
||||
#define YYERRCODE 256
|
||||
static const short error_lhs[] = { -1,
|
||||
0,
|
||||
};
|
||||
static const short error_len[] = { 2,
|
||||
1,
|
||||
};
|
||||
static const short error_defred[] = { 0,
|
||||
1, 0,
|
||||
};
|
||||
static const short error_dgoto[] = { 2,
|
||||
};
|
||||
static const short error_sindex[] = { -256,
|
||||
0, 0,
|
||||
};
|
||||
static const short error_rindex[] = { 0,
|
||||
0, 0,
|
||||
};
|
||||
static const short error_gindex[] = { 0,
|
||||
};
|
||||
#define YYTABLESIZE 0
|
||||
static const short error_table[] = { 1,
|
||||
};
|
||||
static const short error_check[] = { 256,
|
||||
};
|
||||
#define YYFINAL 2
|
||||
#ifndef YYDEBUG
|
||||
#define YYDEBUG 0
|
||||
#endif
|
||||
#define YYMAXTOKEN 0
|
||||
#if YYDEBUG
|
||||
static const char *yyname[] = {
|
||||
|
||||
"end-of-file",
|
||||
};
|
||||
static const char *yyrule[] = {
|
||||
"$accept : S",
|
||||
"S : error",
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
int yydebug;
|
||||
int yynerrs;
|
||||
|
||||
int yyerrflag;
|
||||
int yychar;
|
||||
YYSTYPE yyval;
|
||||
YYSTYPE yylval;
|
||||
|
||||
/* define the initial stack-sizes */
|
||||
#ifdef YYSTACKSIZE
|
||||
#undef YYMAXDEPTH
|
||||
#define YYMAXDEPTH YYSTACKSIZE
|
||||
#else
|
||||
#ifdef YYMAXDEPTH
|
||||
#define YYSTACKSIZE YYMAXDEPTH
|
||||
#else
|
||||
#define YYSTACKSIZE 500
|
||||
#define YYMAXDEPTH 500
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define YYINITSTACKSIZE 500
|
||||
|
||||
typedef struct {
|
||||
unsigned stacksize;
|
||||
short *s_base;
|
||||
short *s_mark;
|
||||
short *s_last;
|
||||
YYSTYPE *l_base;
|
||||
YYSTYPE *l_mark;
|
||||
} YYSTACKDATA;
|
||||
/* variables for the parser stack */
|
||||
static YYSTACKDATA yystack;
|
||||
#line 8 "error.y"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
printf("yyparse() = %d\n", yyparse());
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
yylex(void)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void
|
||||
yyerror(const char* s)
|
||||
{
|
||||
printf("%s\n", s);
|
||||
}
|
||||
#line 236 "error.tab.c"
|
||||
|
||||
#if YYDEBUG
|
||||
#include <stdio.h> /* needed for printf */
|
||||
#endif
|
||||
|
||||
#include <stdlib.h> /* needed for malloc, etc */
|
||||
#include <string.h> /* needed for memset */
|
||||
|
||||
/* allocate initial stack or double stack size, up to YYMAXDEPTH */
|
||||
static int yygrowstack(YYSTACKDATA *data)
|
||||
{
|
||||
int i;
|
||||
unsigned newsize;
|
||||
short *newss;
|
||||
YYSTYPE *newvs;
|
||||
|
||||
if ((newsize = data->stacksize) == 0)
|
||||
newsize = YYINITSTACKSIZE;
|
||||
else if (newsize >= YYMAXDEPTH)
|
||||
return -1;
|
||||
else if ((newsize *= 2) > YYMAXDEPTH)
|
||||
newsize = YYMAXDEPTH;
|
||||
|
||||
i = data->s_mark - data->s_base;
|
||||
newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
|
||||
if (newss == 0)
|
||||
return -1;
|
||||
|
||||
data->s_base = newss;
|
||||
data->s_mark = newss + i;
|
||||
|
||||
newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
|
||||
if (newvs == 0)
|
||||
return -1;
|
||||
|
||||
data->l_base = newvs;
|
||||
data->l_mark = newvs + i;
|
||||
|
||||
data->stacksize = newsize;
|
||||
data->s_last = data->s_base + newsize - 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if YYPURE || defined(YY_NO_LEAKS)
|
||||
static void yyfreestack(YYSTACKDATA *data)
|
||||
{
|
||||
free(data->s_base);
|
||||
free(data->l_base);
|
||||
memset(data, 0, sizeof(*data));
|
||||
}
|
||||
#else
|
||||
#define yyfreestack(data) /* nothing */
|
||||
#endif
|
||||
|
||||
#define YYABORT goto yyabort
|
||||
#define YYREJECT goto yyabort
|
||||
#define YYACCEPT goto yyaccept
|
||||
#define YYERROR goto yyerrlab
|
||||
|
||||
int
|
||||
YYPARSE_DECL()
|
||||
{
|
||||
int yym, yyn, yystate;
|
||||
#if YYDEBUG
|
||||
const char *yys;
|
||||
|
||||
if ((yys = getenv("YYDEBUG")) != 0)
|
||||
{
|
||||
yyn = *yys;
|
||||
if (yyn >= '0' && yyn <= '9')
|
||||
yydebug = yyn - '0';
|
||||
}
|
||||
#endif
|
||||
|
||||
yynerrs = 0;
|
||||
yyerrflag = 0;
|
||||
yychar = YYEMPTY;
|
||||
yystate = 0;
|
||||
|
||||
#if YYPURE
|
||||
memset(&yystack, 0, sizeof(yystack));
|
||||
#endif
|
||||
|
||||
if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
|
||||
yystack.s_mark = yystack.s_base;
|
||||
yystack.l_mark = yystack.l_base;
|
||||
yystate = 0;
|
||||
*yystack.s_mark = 0;
|
||||
|
||||
yyloop:
|
||||
if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
|
||||
if (yychar < 0)
|
||||
{
|
||||
if ((yychar = YYLEX) < 0) yychar = 0;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, reading %d (%s)\n",
|
||||
YYPREFIX, yystate, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, shifting to state %d\n",
|
||||
YYPREFIX, yystate, yytable[yyn]);
|
||||
#endif
|
||||
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
yystate = yytable[yyn];
|
||||
*++yystack.s_mark = yytable[yyn];
|
||||
*++yystack.l_mark = yylval;
|
||||
yychar = YYEMPTY;
|
||||
if (yyerrflag > 0) --yyerrflag;
|
||||
goto yyloop;
|
||||
}
|
||||
if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
|
||||
{
|
||||
yyn = yytable[yyn];
|
||||
goto yyreduce;
|
||||
}
|
||||
if (yyerrflag) goto yyinrecovery;
|
||||
|
||||
yyerror("syntax error");
|
||||
|
||||
goto yyerrlab;
|
||||
|
||||
yyerrlab:
|
||||
++yynerrs;
|
||||
|
||||
yyinrecovery:
|
||||
if (yyerrflag < 3)
|
||||
{
|
||||
yyerrflag = 3;
|
||||
for (;;)
|
||||
{
|
||||
if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, error recovery shifting\
|
||||
to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
|
||||
#endif
|
||||
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
yystate = yytable[yyn];
|
||||
*++yystack.s_mark = yytable[yyn];
|
||||
*++yystack.l_mark = yylval;
|
||||
goto yyloop;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: error recovery discarding state %d\n",
|
||||
YYPREFIX, *yystack.s_mark);
|
||||
#endif
|
||||
if (yystack.s_mark <= yystack.s_base) goto yyabort;
|
||||
--yystack.s_mark;
|
||||
--yystack.l_mark;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (yychar == 0) goto yyabort;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
|
||||
YYPREFIX, yystate, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
yychar = YYEMPTY;
|
||||
goto yyloop;
|
||||
}
|
||||
|
||||
yyreduce:
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, reducing by rule %d (%s)\n",
|
||||
YYPREFIX, yystate, yyn, yyrule[yyn]);
|
||||
#endif
|
||||
yym = yylen[yyn];
|
||||
if (yym)
|
||||
yyval = yystack.l_mark[1-yym];
|
||||
else
|
||||
memset(&yyval, 0, sizeof yyval);
|
||||
switch (yyn)
|
||||
{
|
||||
}
|
||||
yystack.s_mark -= yym;
|
||||
yystate = *yystack.s_mark;
|
||||
yystack.l_mark -= yym;
|
||||
yym = yylhs[yyn];
|
||||
if (yystate == 0 && yym == 0)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: after reduction, shifting from state 0 to\
|
||||
state %d\n", YYPREFIX, YYFINAL);
|
||||
#endif
|
||||
yystate = YYFINAL;
|
||||
*++yystack.s_mark = YYFINAL;
|
||||
*++yystack.l_mark = yyval;
|
||||
if (yychar < 0)
|
||||
{
|
||||
if ((yychar = YYLEX) < 0) yychar = 0;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, reading %d (%s)\n",
|
||||
YYPREFIX, YYFINAL, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (yychar == 0) goto yyaccept;
|
||||
goto yyloop;
|
||||
}
|
||||
if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
|
||||
yystate = yytable[yyn];
|
||||
else
|
||||
yystate = yydgoto[yym];
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: after reduction, shifting from state %d \
|
||||
to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
|
||||
#endif
|
||||
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
*++yystack.s_mark = (short) yystate;
|
||||
*++yystack.l_mark = yyval;
|
||||
goto yyloop;
|
||||
|
||||
yyoverflow:
|
||||
yyerror("yacc stack overflow");
|
||||
|
||||
yyabort:
|
||||
yyfreestack(&yystack);
|
||||
return (1);
|
||||
|
||||
yyaccept:
|
||||
yyfreestack(&yystack);
|
||||
return (0);
|
||||
}
|
0
test/error.tab.h
Normal file
0
test/error.tab.h
Normal file
28
test/error.y
Normal file
28
test/error.y
Normal file
@ -0,0 +1,28 @@
|
||||
%{
|
||||
int yylex(void);
|
||||
static void yyerror(const char *);
|
||||
%}
|
||||
%%
|
||||
S: error
|
||||
%%
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
printf("yyparse() = %d\n", yyparse());
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
yylex(void)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void
|
||||
yyerror(const char* s)
|
||||
{
|
||||
printf("%s\n", s);
|
||||
}
|
1625
test/ftp.output
Normal file
1625
test/ftp.output
Normal file
File diff suppressed because it is too large
Load Diff
1995
test/ftp.tab.c
Normal file
1995
test/ftp.tab.c
Normal file
File diff suppressed because it is too large
Load Diff
63
test/ftp.tab.h
Normal file
63
test/ftp.tab.h
Normal file
@ -0,0 +1,63 @@
|
||||
#define A 257
|
||||
#define B 258
|
||||
#define C 259
|
||||
#define E 260
|
||||
#define F 261
|
||||
#define I 262
|
||||
#define L 263
|
||||
#define N 264
|
||||
#define P 265
|
||||
#define R 266
|
||||
#define S 267
|
||||
#define T 268
|
||||
#define SP 269
|
||||
#define CRLF 270
|
||||
#define COMMA 271
|
||||
#define STRING 272
|
||||
#define NUMBER 273
|
||||
#define USER 274
|
||||
#define PASS 275
|
||||
#define ACCT 276
|
||||
#define REIN 277
|
||||
#define QUIT 278
|
||||
#define PORT 279
|
||||
#define PASV 280
|
||||
#define TYPE 281
|
||||
#define STRU 282
|
||||
#define MODE 283
|
||||
#define RETR 284
|
||||
#define STOR 285
|
||||
#define APPE 286
|
||||
#define MLFL 287
|
||||
#define MAIL 288
|
||||
#define MSND 289
|
||||
#define MSOM 290
|
||||
#define MSAM 291
|
||||
#define MRSQ 292
|
||||
#define MRCP 293
|
||||
#define ALLO 294
|
||||
#define REST 295
|
||||
#define RNFR 296
|
||||
#define RNTO 297
|
||||
#define ABOR 298
|
||||
#define DELE 299
|
||||
#define CWD 300
|
||||
#define LIST 301
|
||||
#define NLST 302
|
||||
#define SITE 303
|
||||
#define STAT 304
|
||||
#define HELP 305
|
||||
#define NOOP 306
|
||||
#define MKD 307
|
||||
#define RMD 308
|
||||
#define PWD 309
|
||||
#define CDUP 310
|
||||
#define STOU 311
|
||||
#define SMNT 312
|
||||
#define SYST 313
|
||||
#define SIZE 314
|
||||
#define MDTM 315
|
||||
#define UMASK 316
|
||||
#define IDLE 317
|
||||
#define CHMOD 318
|
||||
#define LEXERR 319
|
1228
test/ftp.y
Normal file
1228
test/ftp.y
Normal file
File diff suppressed because it is too large
Load Diff
2214
test/grammar.output
Normal file
2214
test/grammar.output
Normal file
File diff suppressed because it is too large
Load Diff
2025
test/grammar.tab.c
Normal file
2025
test/grammar.tab.c
Normal file
File diff suppressed because it is too large
Load Diff
35
test/grammar.tab.h
Normal file
35
test/grammar.tab.h
Normal file
@ -0,0 +1,35 @@
|
||||
#define T_IDENTIFIER 257
|
||||
#define T_TYPEDEF_NAME 258
|
||||
#define T_DEFINE_NAME 259
|
||||
#define T_AUTO 260
|
||||
#define T_EXTERN 261
|
||||
#define T_REGISTER 262
|
||||
#define T_STATIC 263
|
||||
#define T_TYPEDEF 264
|
||||
#define T_INLINE 265
|
||||
#define T_EXTENSION 266
|
||||
#define T_CHAR 267
|
||||
#define T_DOUBLE 268
|
||||
#define T_FLOAT 269
|
||||
#define T_INT 270
|
||||
#define T_VOID 271
|
||||
#define T_LONG 272
|
||||
#define T_SHORT 273
|
||||
#define T_SIGNED 274
|
||||
#define T_UNSIGNED 275
|
||||
#define T_ENUM 276
|
||||
#define T_STRUCT 277
|
||||
#define T_UNION 278
|
||||
#define T_Bool 279
|
||||
#define T_Complex 280
|
||||
#define T_Imaginary 281
|
||||
#define T_TYPE_QUALIFIER 282
|
||||
#define T_BRACKETS 283
|
||||
#define T_LBRACE 284
|
||||
#define T_MATCHRBRACE 285
|
||||
#define T_ELLIPSIS 286
|
||||
#define T_INITIALIZER 287
|
||||
#define T_STRING_LITERAL 288
|
||||
#define T_ASM 289
|
||||
#define T_ASMARG 290
|
||||
#define T_VA_DCL 291
|
1183
test/grammar.y
Normal file
1183
test/grammar.y
Normal file
File diff suppressed because it is too large
Load Diff
461
test/pure_calc.output
Normal file
461
test/pure_calc.output
Normal file
@ -0,0 +1,461 @@
|
||||
0 $accept : list $end
|
||||
|
||||
1 list :
|
||||
2 | list stat '\n'
|
||||
3 | list error '\n'
|
||||
|
||||
4 stat : expr
|
||||
5 | LETTER '=' expr
|
||||
|
||||
6 expr : '(' expr ')'
|
||||
7 | expr '+' expr
|
||||
8 | expr '-' expr
|
||||
9 | expr '*' expr
|
||||
10 | expr '/' expr
|
||||
11 | expr '%' expr
|
||||
12 | expr '&' expr
|
||||
13 | expr '|' expr
|
||||
14 | '-' expr
|
||||
15 | LETTER
|
||||
16 | number
|
||||
|
||||
17 number : DIGIT
|
||||
18 | number DIGIT
|
||||
|
||||
state 0
|
||||
$accept : . list $end (0)
|
||||
list : . (1)
|
||||
|
||||
. reduce 1
|
||||
|
||||
list goto 1
|
||||
|
||||
|
||||
state 1
|
||||
$accept : list . $end (0)
|
||||
list : list . stat '\n' (2)
|
||||
list : list . error '\n' (3)
|
||||
|
||||
$end accept
|
||||
error shift 2
|
||||
DIGIT shift 3
|
||||
LETTER shift 4
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
stat goto 7
|
||||
expr goto 8
|
||||
number goto 9
|
||||
|
||||
|
||||
state 2
|
||||
list : list error . '\n' (3)
|
||||
|
||||
'\n' shift 10
|
||||
. error
|
||||
|
||||
|
||||
state 3
|
||||
number : DIGIT . (17)
|
||||
|
||||
. reduce 17
|
||||
|
||||
|
||||
state 4
|
||||
stat : LETTER . '=' expr (5)
|
||||
expr : LETTER . (15)
|
||||
|
||||
'=' shift 11
|
||||
'|' reduce 15
|
||||
'&' reduce 15
|
||||
'+' reduce 15
|
||||
'-' reduce 15
|
||||
'*' reduce 15
|
||||
'/' reduce 15
|
||||
'%' reduce 15
|
||||
'\n' reduce 15
|
||||
|
||||
|
||||
state 5
|
||||
expr : '-' . expr (14)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 13
|
||||
number goto 9
|
||||
|
||||
|
||||
state 6
|
||||
expr : '(' . expr ')' (6)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 14
|
||||
number goto 9
|
||||
|
||||
|
||||
state 7
|
||||
list : list stat . '\n' (2)
|
||||
|
||||
'\n' shift 15
|
||||
. error
|
||||
|
||||
|
||||
state 8
|
||||
stat : expr . (4)
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
'|' shift 16
|
||||
'&' shift 17
|
||||
'+' shift 18
|
||||
'-' shift 19
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
'\n' reduce 4
|
||||
|
||||
|
||||
state 9
|
||||
expr : number . (16)
|
||||
number : number . DIGIT (18)
|
||||
|
||||
DIGIT shift 23
|
||||
'|' reduce 16
|
||||
'&' reduce 16
|
||||
'+' reduce 16
|
||||
'-' reduce 16
|
||||
'*' reduce 16
|
||||
'/' reduce 16
|
||||
'%' reduce 16
|
||||
'\n' reduce 16
|
||||
')' reduce 16
|
||||
|
||||
|
||||
state 10
|
||||
list : list error '\n' . (3)
|
||||
|
||||
. reduce 3
|
||||
|
||||
|
||||
state 11
|
||||
stat : LETTER '=' . expr (5)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 24
|
||||
number goto 9
|
||||
|
||||
|
||||
state 12
|
||||
expr : LETTER . (15)
|
||||
|
||||
. reduce 15
|
||||
|
||||
|
||||
state 13
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
expr : '-' expr . (14)
|
||||
|
||||
. reduce 14
|
||||
|
||||
|
||||
state 14
|
||||
expr : '(' expr . ')' (6)
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
'|' shift 16
|
||||
'&' shift 17
|
||||
'+' shift 18
|
||||
'-' shift 19
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
')' shift 25
|
||||
. error
|
||||
|
||||
|
||||
state 15
|
||||
list : list stat '\n' . (2)
|
||||
|
||||
. reduce 2
|
||||
|
||||
|
||||
state 16
|
||||
expr : expr '|' . expr (13)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 26
|
||||
number goto 9
|
||||
|
||||
|
||||
state 17
|
||||
expr : expr '&' . expr (12)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 27
|
||||
number goto 9
|
||||
|
||||
|
||||
state 18
|
||||
expr : expr '+' . expr (7)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 28
|
||||
number goto 9
|
||||
|
||||
|
||||
state 19
|
||||
expr : expr '-' . expr (8)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 29
|
||||
number goto 9
|
||||
|
||||
|
||||
state 20
|
||||
expr : expr '*' . expr (9)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 30
|
||||
number goto 9
|
||||
|
||||
|
||||
state 21
|
||||
expr : expr '/' . expr (10)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 31
|
||||
number goto 9
|
||||
|
||||
|
||||
state 22
|
||||
expr : expr '%' . expr (11)
|
||||
|
||||
DIGIT shift 3
|
||||
LETTER shift 12
|
||||
'-' shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 32
|
||||
number goto 9
|
||||
|
||||
|
||||
state 23
|
||||
number : number DIGIT . (18)
|
||||
|
||||
. reduce 18
|
||||
|
||||
|
||||
state 24
|
||||
stat : LETTER '=' expr . (5)
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
'|' shift 16
|
||||
'&' shift 17
|
||||
'+' shift 18
|
||||
'-' shift 19
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
'\n' reduce 5
|
||||
|
||||
|
||||
state 25
|
||||
expr : '(' expr ')' . (6)
|
||||
|
||||
. reduce 6
|
||||
|
||||
|
||||
state 26
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
expr : expr '|' expr . (13)
|
||||
|
||||
'&' shift 17
|
||||
'+' shift 18
|
||||
'-' shift 19
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
'|' reduce 13
|
||||
'\n' reduce 13
|
||||
')' reduce 13
|
||||
|
||||
|
||||
state 27
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr '&' expr . (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
'+' shift 18
|
||||
'-' shift 19
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
'|' reduce 12
|
||||
'&' reduce 12
|
||||
'\n' reduce 12
|
||||
')' reduce 12
|
||||
|
||||
|
||||
state 28
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr '+' expr . (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
'|' reduce 7
|
||||
'&' reduce 7
|
||||
'+' reduce 7
|
||||
'-' reduce 7
|
||||
'\n' reduce 7
|
||||
')' reduce 7
|
||||
|
||||
|
||||
state 29
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr '-' expr . (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
'*' shift 20
|
||||
'/' shift 21
|
||||
'%' shift 22
|
||||
'|' reduce 8
|
||||
'&' reduce 8
|
||||
'+' reduce 8
|
||||
'-' reduce 8
|
||||
'\n' reduce 8
|
||||
')' reduce 8
|
||||
|
||||
|
||||
state 30
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr '*' expr . (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
. reduce 9
|
||||
|
||||
|
||||
state 31
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr '/' expr . (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
. reduce 10
|
||||
|
||||
|
||||
state 32
|
||||
expr : expr . '+' expr (7)
|
||||
expr : expr . '-' expr (8)
|
||||
expr : expr . '*' expr (9)
|
||||
expr : expr . '/' expr (10)
|
||||
expr : expr . '%' expr (11)
|
||||
expr : expr '%' expr . (11)
|
||||
expr : expr . '&' expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
. reduce 11
|
||||
|
||||
|
||||
16 terminals, 5 nonterminals
|
||||
19 grammar rules, 33 states
|
687
test/pure_calc.tab.c
Normal file
687
test/pure_calc.tab.c
Normal file
@ -0,0 +1,687 @@
|
||||
#ifndef lint
|
||||
static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
|
||||
#endif
|
||||
|
||||
#define YYBYACC 1
|
||||
#define YYMAJOR 1
|
||||
#define YYMINOR 9
|
||||
|
||||
#define YYEMPTY (-1)
|
||||
#define yyclearin (yychar = YYEMPTY)
|
||||
#define yyerrok (yyerrflag = 0)
|
||||
#define YYRECOVERING() (yyerrflag != 0)
|
||||
|
||||
|
||||
#ifndef yyparse
|
||||
#define yyparse calc_parse
|
||||
#endif /* yyparse */
|
||||
|
||||
#ifndef yylex
|
||||
#define yylex calc_lex
|
||||
#endif /* yylex */
|
||||
|
||||
#ifndef yyerror
|
||||
#define yyerror calc_error
|
||||
#endif /* yyerror */
|
||||
|
||||
#ifndef yychar
|
||||
#define yychar calc_char
|
||||
#endif /* yychar */
|
||||
|
||||
#ifndef yyval
|
||||
#define yyval calc_val
|
||||
#endif /* yyval */
|
||||
|
||||
#ifndef yylval
|
||||
#define yylval calc_lval
|
||||
#endif /* yylval */
|
||||
|
||||
#ifndef yydebug
|
||||
#define yydebug calc_debug
|
||||
#endif /* yydebug */
|
||||
|
||||
#ifndef yynerrs
|
||||
#define yynerrs calc_nerrs
|
||||
#endif /* yynerrs */
|
||||
|
||||
#ifndef yyerrflag
|
||||
#define yyerrflag calc_errflag
|
||||
#endif /* yyerrflag */
|
||||
|
||||
#ifndef yylhs
|
||||
#define yylhs calc_lhs
|
||||
#endif /* yylhs */
|
||||
|
||||
#ifndef yylen
|
||||
#define yylen calc_len
|
||||
#endif /* yylen */
|
||||
|
||||
#ifndef yydefred
|
||||
#define yydefred calc_defred
|
||||
#endif /* yydefred */
|
||||
|
||||
#ifndef yydgoto
|
||||
#define yydgoto calc_dgoto
|
||||
#endif /* yydgoto */
|
||||
|
||||
#ifndef yysindex
|
||||
#define yysindex calc_sindex
|
||||
#endif /* yysindex */
|
||||
|
||||
#ifndef yyrindex
|
||||
#define yyrindex calc_rindex
|
||||
#endif /* yyrindex */
|
||||
|
||||
#ifndef yygindex
|
||||
#define yygindex calc_gindex
|
||||
#endif /* yygindex */
|
||||
|
||||
#ifndef yytable
|
||||
#define yytable calc_table
|
||||
#endif /* yytable */
|
||||
|
||||
#ifndef yycheck
|
||||
#define yycheck calc_check
|
||||
#endif /* yycheck */
|
||||
|
||||
#ifndef yyname
|
||||
#define yyname calc_name
|
||||
#endif /* yyname */
|
||||
|
||||
#ifndef yyrule
|
||||
#define yyrule calc_rule
|
||||
#endif /* yyrule */
|
||||
#define YYPREFIX "calc_"
|
||||
|
||||
#define YYPURE 1
|
||||
|
||||
#line 2 "pure_calc.y"
|
||||
# include <stdio.h>
|
||||
# include <ctype.h>
|
||||
|
||||
int regs[26];
|
||||
int base;
|
||||
|
||||
#ifdef YYBISON
|
||||
#define YYSTYPE int
|
||||
#define YYLEX_PARAM &yylval
|
||||
#define YYLEX_DECL() yylex(YYSTYPE *yylval)
|
||||
#define YYERROR_DECL() yyerror(const char *s)
|
||||
int YYLEX_DECL();
|
||||
static void YYERROR_DECL();
|
||||
#endif
|
||||
|
||||
#line 115 "pure_calc.tab.c"
|
||||
|
||||
#ifndef YYSTYPE
|
||||
typedef int YYSTYPE;
|
||||
#endif
|
||||
|
||||
/* compatibility with bison */
|
||||
#ifdef YYPARSE_PARAM
|
||||
/* compatibility with FreeBSD */
|
||||
# ifdef YYPARSE_PARAM_TYPE
|
||||
# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
|
||||
# else
|
||||
# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
|
||||
# endif
|
||||
#else
|
||||
# define YYPARSE_DECL() yyparse(void)
|
||||
#endif
|
||||
|
||||
/* Parameters sent to lex. */
|
||||
#ifdef YYLEX_PARAM
|
||||
# ifdef YYLEX_PARAM_TYPE
|
||||
# define YYLEX_DECL() yylex(YYSTYPE *yylval, YYLEX_PARAM_TYPE YYLEX_PARAM)
|
||||
# else
|
||||
# define YYLEX_DECL() yylex(YYSTYPE *yylval, void * YYLEX_PARAM)
|
||||
# endif
|
||||
# define YYLEX yylex(&yylval, YYLEX_PARAM)
|
||||
#else
|
||||
# define YYLEX_DECL() yylex(YYSTYPE *yylval)
|
||||
# define YYLEX yylex(&yylval)
|
||||
#endif
|
||||
|
||||
/* Parameters sent to yyerror. */
|
||||
#ifndef YYERROR_DECL
|
||||
#define YYERROR_DECL() yyerror(const char *s)
|
||||
#endif
|
||||
#ifndef YYERROR_CALL
|
||||
#define YYERROR_CALL(msg) yyerror(msg)
|
||||
#endif
|
||||
|
||||
extern int YYPARSE_DECL();
|
||||
|
||||
#define DIGIT 257
|
||||
#define LETTER 258
|
||||
#define UMINUS 259
|
||||
#define YYERRCODE 256
|
||||
static const short calc_lhs[] = { -1,
|
||||
0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 3, 3,
|
||||
};
|
||||
static const short calc_len[] = { 2,
|
||||
0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 2, 1, 1, 1, 2,
|
||||
};
|
||||
static const short calc_defred[] = { 1,
|
||||
0, 0, 17, 0, 0, 0, 0, 0, 0, 3,
|
||||
0, 15, 14, 0, 2, 0, 0, 0, 0, 0,
|
||||
0, 0, 18, 0, 6, 0, 0, 0, 0, 9,
|
||||
10, 11,
|
||||
};
|
||||
static const short calc_dgoto[] = { 1,
|
||||
7, 8, 9,
|
||||
};
|
||||
static const short calc_sindex[] = { 0,
|
||||
-40, -7, 0, -55, -38, -38, 1, -29, -247, 0,
|
||||
-38, 0, 0, 22, 0, -38, -38, -38, -38, -38,
|
||||
-38, -38, 0, -29, 0, 51, 60, -20, -20, 0,
|
||||
0, 0,
|
||||
};
|
||||
static const short calc_rindex[] = { 0,
|
||||
0, 0, 0, 2, 0, 0, 0, 9, -9, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 10, 0, -6, 14, 5, 13, 0,
|
||||
0, 0,
|
||||
};
|
||||
static const short calc_gindex[] = { 0,
|
||||
0, 65, 0,
|
||||
};
|
||||
#define YYTABLESIZE 220
|
||||
static const short calc_table[] = { 6,
|
||||
16, 6, 10, 13, 5, 11, 5, 22, 17, 23,
|
||||
15, 15, 20, 18, 7, 19, 22, 21, 4, 5,
|
||||
0, 20, 8, 12, 0, 0, 21, 16, 16, 0,
|
||||
0, 16, 16, 16, 13, 16, 0, 16, 15, 15,
|
||||
0, 0, 7, 15, 15, 7, 15, 7, 15, 7,
|
||||
8, 12, 0, 8, 12, 8, 0, 8, 22, 17,
|
||||
0, 0, 25, 20, 18, 0, 19, 0, 21, 13,
|
||||
14, 0, 0, 0, 0, 24, 0, 0, 0, 0,
|
||||
26, 27, 28, 29, 30, 31, 32, 22, 17, 0,
|
||||
0, 0, 20, 18, 16, 19, 22, 21, 0, 0,
|
||||
0, 20, 18, 0, 19, 0, 21, 0, 0, 0,
|
||||
0, 0, 0, 0, 16, 0, 0, 13, 0, 0,
|
||||
0, 0, 0, 0, 0, 15, 0, 0, 7, 0,
|
||||
0, 0, 0, 0, 0, 0, 8, 12, 0, 0,
|
||||
0, 0, 0, 0, 0, 16, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 2, 3, 4, 3, 12,
|
||||
};
|
||||
static const short calc_check[] = { 40,
|
||||
10, 40, 10, 10, 45, 61, 45, 37, 38, 257,
|
||||
10, 10, 42, 43, 10, 45, 37, 47, 10, 10,
|
||||
-1, 42, 10, 10, -1, -1, 47, 37, 38, -1,
|
||||
-1, 41, 42, 43, 41, 45, -1, 47, 37, 38,
|
||||
-1, -1, 38, 42, 43, 41, 45, 43, 47, 45,
|
||||
38, 38, -1, 41, 41, 43, -1, 45, 37, 38,
|
||||
-1, -1, 41, 42, 43, -1, 45, -1, 47, 5,
|
||||
6, -1, -1, -1, -1, 11, -1, -1, -1, -1,
|
||||
16, 17, 18, 19, 20, 21, 22, 37, 38, -1,
|
||||
-1, -1, 42, 43, 124, 45, 37, 47, -1, -1,
|
||||
-1, 42, 43, -1, 45, -1, 47, -1, -1, -1,
|
||||
-1, -1, -1, -1, 124, -1, -1, 124, -1, -1,
|
||||
-1, -1, -1, -1, -1, 124, -1, -1, 124, -1,
|
||||
-1, -1, -1, -1, -1, -1, 124, 124, -1, -1,
|
||||
-1, -1, -1, -1, -1, 124, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, 256, 257, 258, 257, 258,
|
||||
};
|
||||
#define YYFINAL 1
|
||||
#ifndef YYDEBUG
|
||||
#define YYDEBUG 0
|
||||
#endif
|
||||
#define YYMAXTOKEN 259
|
||||
#if YYDEBUG
|
||||
static const char *yyname[] = {
|
||||
|
||||
"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'",0,"'-'",0,"'/'",0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'|'",0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,"DIGIT","LETTER","UMINUS",
|
||||
};
|
||||
static const char *yyrule[] = {
|
||||
"$accept : list",
|
||||
"list :",
|
||||
"list : list stat '\\n'",
|
||||
"list : list error '\\n'",
|
||||
"stat : expr",
|
||||
"stat : LETTER '=' expr",
|
||||
"expr : '(' expr ')'",
|
||||
"expr : expr '+' expr",
|
||||
"expr : expr '-' expr",
|
||||
"expr : expr '*' expr",
|
||||
"expr : expr '/' expr",
|
||||
"expr : expr '%' expr",
|
||||
"expr : expr '&' expr",
|
||||
"expr : expr '|' expr",
|
||||
"expr : '-' expr",
|
||||
"expr : LETTER",
|
||||
"expr : number",
|
||||
"number : DIGIT",
|
||||
"number : number DIGIT",
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
int yydebug;
|
||||
int yynerrs;
|
||||
|
||||
/* define the initial stack-sizes */
|
||||
#ifdef YYSTACKSIZE
|
||||
#undef YYMAXDEPTH
|
||||
#define YYMAXDEPTH YYSTACKSIZE
|
||||
#else
|
||||
#ifdef YYMAXDEPTH
|
||||
#define YYSTACKSIZE YYMAXDEPTH
|
||||
#else
|
||||
#define YYSTACKSIZE 500
|
||||
#define YYMAXDEPTH 500
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define YYINITSTACKSIZE 500
|
||||
|
||||
typedef struct {
|
||||
unsigned stacksize;
|
||||
short *s_base;
|
||||
short *s_mark;
|
||||
short *s_last;
|
||||
YYSTYPE *l_base;
|
||||
YYSTYPE *l_mark;
|
||||
} YYSTACKDATA;
|
||||
#line 72 "pure_calc.y"
|
||||
/* start of programs */
|
||||
|
||||
#ifdef YYBYACC
|
||||
static int YYLEX_DECL();
|
||||
#endif
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
while(!feof(stdin)) {
|
||||
yyparse();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
YYERROR_DECL()
|
||||
{
|
||||
fprintf(stderr, "%s\n", s);
|
||||
}
|
||||
|
||||
int
|
||||
YYLEX_DECL()
|
||||
{
|
||||
/* lexical analysis routine */
|
||||
/* returns LETTER for a lower case letter, yylval = 0 through 25 */
|
||||
/* return DIGIT for a digit, yylval = 0 through 9 */
|
||||
/* all other characters are returned immediately */
|
||||
|
||||
int c;
|
||||
|
||||
while( (c=getchar()) == ' ' ) { /* skip blanks */ }
|
||||
|
||||
/* c is now nonblank */
|
||||
|
||||
if( islower( c )) {
|
||||
*yylval = c - 'a';
|
||||
return ( LETTER );
|
||||
}
|
||||
if( isdigit( c )) {
|
||||
*yylval = c - '0';
|
||||
return ( DIGIT );
|
||||
}
|
||||
return( c );
|
||||
}
|
||||
#line 354 "pure_calc.tab.c"
|
||||
|
||||
#if YYDEBUG
|
||||
#include <stdio.h> /* needed for printf */
|
||||
#endif
|
||||
|
||||
#include <stdlib.h> /* needed for malloc, etc */
|
||||
#include <string.h> /* needed for memset */
|
||||
|
||||
/* allocate initial stack or double stack size, up to YYMAXDEPTH */
|
||||
static int yygrowstack(YYSTACKDATA *data)
|
||||
{
|
||||
int i;
|
||||
unsigned newsize;
|
||||
short *newss;
|
||||
YYSTYPE *newvs;
|
||||
|
||||
if ((newsize = data->stacksize) == 0)
|
||||
newsize = YYINITSTACKSIZE;
|
||||
else if (newsize >= YYMAXDEPTH)
|
||||
return -1;
|
||||
else if ((newsize *= 2) > YYMAXDEPTH)
|
||||
newsize = YYMAXDEPTH;
|
||||
|
||||
i = data->s_mark - data->s_base;
|
||||
newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
|
||||
if (newss == 0)
|
||||
return -1;
|
||||
|
||||
data->s_base = newss;
|
||||
data->s_mark = newss + i;
|
||||
|
||||
newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
|
||||
if (newvs == 0)
|
||||
return -1;
|
||||
|
||||
data->l_base = newvs;
|
||||
data->l_mark = newvs + i;
|
||||
|
||||
data->stacksize = newsize;
|
||||
data->s_last = data->s_base + newsize - 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if YYPURE || defined(YY_NO_LEAKS)
|
||||
static void yyfreestack(YYSTACKDATA *data)
|
||||
{
|
||||
free(data->s_base);
|
||||
free(data->l_base);
|
||||
memset(data, 0, sizeof(*data));
|
||||
}
|
||||
#else
|
||||
#define yyfreestack(data) /* nothing */
|
||||
#endif
|
||||
|
||||
#define YYABORT goto yyabort
|
||||
#define YYREJECT goto yyabort
|
||||
#define YYACCEPT goto yyaccept
|
||||
#define YYERROR goto yyerrlab
|
||||
|
||||
int
|
||||
YYPARSE_DECL()
|
||||
{
|
||||
int yyerrflag;
|
||||
int yychar;
|
||||
YYSTYPE yyval;
|
||||
YYSTYPE yylval;
|
||||
|
||||
/* variables for the parser stack */
|
||||
YYSTACKDATA yystack;
|
||||
int yym, yyn, yystate;
|
||||
#if YYDEBUG
|
||||
const char *yys;
|
||||
|
||||
if ((yys = getenv("YYDEBUG")) != 0)
|
||||
{
|
||||
yyn = *yys;
|
||||
if (yyn >= '0' && yyn <= '9')
|
||||
yydebug = yyn - '0';
|
||||
}
|
||||
#endif
|
||||
|
||||
yynerrs = 0;
|
||||
yyerrflag = 0;
|
||||
yychar = YYEMPTY;
|
||||
yystate = 0;
|
||||
|
||||
#if YYPURE
|
||||
memset(&yystack, 0, sizeof(yystack));
|
||||
#endif
|
||||
|
||||
if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
|
||||
yystack.s_mark = yystack.s_base;
|
||||
yystack.l_mark = yystack.l_base;
|
||||
yystate = 0;
|
||||
*yystack.s_mark = 0;
|
||||
|
||||
yyloop:
|
||||
if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
|
||||
if (yychar < 0)
|
||||
{
|
||||
if ((yychar = YYLEX) < 0) yychar = 0;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, reading %d (%s)\n",
|
||||
YYPREFIX, yystate, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, shifting to state %d\n",
|
||||
YYPREFIX, yystate, yytable[yyn]);
|
||||
#endif
|
||||
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
yystate = yytable[yyn];
|
||||
*++yystack.s_mark = yytable[yyn];
|
||||
*++yystack.l_mark = yylval;
|
||||
yychar = YYEMPTY;
|
||||
if (yyerrflag > 0) --yyerrflag;
|
||||
goto yyloop;
|
||||
}
|
||||
if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
|
||||
{
|
||||
yyn = yytable[yyn];
|
||||
goto yyreduce;
|
||||
}
|
||||
if (yyerrflag) goto yyinrecovery;
|
||||
|
||||
yyerror("syntax error");
|
||||
|
||||
goto yyerrlab;
|
||||
|
||||
yyerrlab:
|
||||
++yynerrs;
|
||||
|
||||
yyinrecovery:
|
||||
if (yyerrflag < 3)
|
||||
{
|
||||
yyerrflag = 3;
|
||||
for (;;)
|
||||
{
|
||||
if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, error recovery shifting\
|
||||
to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
|
||||
#endif
|
||||
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
yystate = yytable[yyn];
|
||||
*++yystack.s_mark = yytable[yyn];
|
||||
*++yystack.l_mark = yylval;
|
||||
goto yyloop;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: error recovery discarding state %d\n",
|
||||
YYPREFIX, *yystack.s_mark);
|
||||
#endif
|
||||
if (yystack.s_mark <= yystack.s_base) goto yyabort;
|
||||
--yystack.s_mark;
|
||||
--yystack.l_mark;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (yychar == 0) goto yyabort;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
|
||||
YYPREFIX, yystate, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
yychar = YYEMPTY;
|
||||
goto yyloop;
|
||||
}
|
||||
|
||||
yyreduce:
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, reducing by rule %d (%s)\n",
|
||||
YYPREFIX, yystate, yyn, yyrule[yyn]);
|
||||
#endif
|
||||
yym = yylen[yyn];
|
||||
if (yym)
|
||||
yyval = yystack.l_mark[1-yym];
|
||||
else
|
||||
memset(&yyval, 0, sizeof yyval);
|
||||
switch (yyn)
|
||||
{
|
||||
case 3:
|
||||
#line 34 "pure_calc.y"
|
||||
{ yyerrok ; }
|
||||
break;
|
||||
case 4:
|
||||
#line 38 "pure_calc.y"
|
||||
{ printf("%d\n",yystack.l_mark[0]);}
|
||||
break;
|
||||
case 5:
|
||||
#line 40 "pure_calc.y"
|
||||
{ regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
|
||||
break;
|
||||
case 6:
|
||||
#line 44 "pure_calc.y"
|
||||
{ yyval = yystack.l_mark[-1]; }
|
||||
break;
|
||||
case 7:
|
||||
#line 46 "pure_calc.y"
|
||||
{ yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
|
||||
break;
|
||||
case 8:
|
||||
#line 48 "pure_calc.y"
|
||||
{ yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
|
||||
break;
|
||||
case 9:
|
||||
#line 50 "pure_calc.y"
|
||||
{ yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
|
||||
break;
|
||||
case 10:
|
||||
#line 52 "pure_calc.y"
|
||||
{ yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
|
||||
break;
|
||||
case 11:
|
||||
#line 54 "pure_calc.y"
|
||||
{ yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
|
||||
break;
|
||||
case 12:
|
||||
#line 56 "pure_calc.y"
|
||||
{ yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
|
||||
break;
|
||||
case 13:
|
||||
#line 58 "pure_calc.y"
|
||||
{ yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
|
||||
break;
|
||||
case 14:
|
||||
#line 60 "pure_calc.y"
|
||||
{ yyval = - yystack.l_mark[0]; }
|
||||
break;
|
||||
case 15:
|
||||
#line 62 "pure_calc.y"
|
||||
{ yyval = regs[yystack.l_mark[0]]; }
|
||||
break;
|
||||
case 17:
|
||||
#line 67 "pure_calc.y"
|
||||
{ yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; }
|
||||
break;
|
||||
case 18:
|
||||
#line 69 "pure_calc.y"
|
||||
{ yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; }
|
||||
break;
|
||||
#line 627 "pure_calc.tab.c"
|
||||
}
|
||||
yystack.s_mark -= yym;
|
||||
yystate = *yystack.s_mark;
|
||||
yystack.l_mark -= yym;
|
||||
yym = yylhs[yyn];
|
||||
if (yystate == 0 && yym == 0)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: after reduction, shifting from state 0 to\
|
||||
state %d\n", YYPREFIX, YYFINAL);
|
||||
#endif
|
||||
yystate = YYFINAL;
|
||||
*++yystack.s_mark = YYFINAL;
|
||||
*++yystack.l_mark = yyval;
|
||||
if (yychar < 0)
|
||||
{
|
||||
if ((yychar = YYLEX) < 0) yychar = 0;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, reading %d (%s)\n",
|
||||
YYPREFIX, YYFINAL, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (yychar == 0) goto yyaccept;
|
||||
goto yyloop;
|
||||
}
|
||||
if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
|
||||
yystate = yytable[yyn];
|
||||
else
|
||||
yystate = yydgoto[yym];
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: after reduction, shifting from state %d \
|
||||
to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
|
||||
#endif
|
||||
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
*++yystack.s_mark = (short) yystate;
|
||||
*++yystack.l_mark = yyval;
|
||||
goto yyloop;
|
||||
|
||||
yyoverflow:
|
||||
yyerror("yacc stack overflow");
|
||||
|
||||
yyabort:
|
||||
yyfreestack(&yystack);
|
||||
return (1);
|
||||
|
||||
yyaccept:
|
||||
yyfreestack(&yystack);
|
||||
return (0);
|
||||
}
|
3
test/pure_calc.tab.h
Normal file
3
test/pure_calc.tab.h
Normal file
@ -0,0 +1,3 @@
|
||||
#define DIGIT 257
|
||||
#define LETTER 258
|
||||
#define UMINUS 259
|
116
test/pure_calc.y
Normal file
116
test/pure_calc.y
Normal file
@ -0,0 +1,116 @@
|
||||
%{
|
||||
# include <stdio.h>
|
||||
# include <ctype.h>
|
||||
|
||||
int regs[26];
|
||||
int base;
|
||||
|
||||
#ifdef YYBISON
|
||||
#define YYSTYPE int
|
||||
#define YYLEX_PARAM &yylval
|
||||
#define YYLEX_DECL() yylex(YYSTYPE *yylval)
|
||||
#define YYERROR_DECL() yyerror(const char *s)
|
||||
int YYLEX_DECL();
|
||||
static void YYERROR_DECL();
|
||||
#endif
|
||||
|
||||
%}
|
||||
|
||||
%start list
|
||||
|
||||
%token DIGIT LETTER
|
||||
|
||||
%left '|'
|
||||
%left '&'
|
||||
%left '+' '-'
|
||||
%left '*' '/' '%'
|
||||
%left UMINUS /* supplies precedence for unary minus */
|
||||
|
||||
%% /* beginning of rules section */
|
||||
|
||||
list : /* empty */
|
||||
| list stat '\n'
|
||||
| list error '\n'
|
||||
{ yyerrok ; }
|
||||
;
|
||||
|
||||
stat : expr
|
||||
{ printf("%d\n",$1);}
|
||||
| LETTER '=' expr
|
||||
{ regs[$1] = $3; }
|
||||
;
|
||||
|
||||
expr : '(' expr ')'
|
||||
{ $$ = $2; }
|
||||
| expr '+' expr
|
||||
{ $$ = $1 + $3; }
|
||||
| expr '-' expr
|
||||
{ $$ = $1 - $3; }
|
||||
| expr '*' expr
|
||||
{ $$ = $1 * $3; }
|
||||
| expr '/' expr
|
||||
{ $$ = $1 / $3; }
|
||||
| expr '%' expr
|
||||
{ $$ = $1 % $3; }
|
||||
| expr '&' expr
|
||||
{ $$ = $1 & $3; }
|
||||
| expr '|' expr
|
||||
{ $$ = $1 | $3; }
|
||||
| '-' expr %prec UMINUS
|
||||
{ $$ = - $2; }
|
||||
| LETTER
|
||||
{ $$ = regs[$1]; }
|
||||
| number
|
||||
;
|
||||
|
||||
number: DIGIT
|
||||
{ $$ = $1; base = ($1==0) ? 8 : 10; }
|
||||
| number DIGIT
|
||||
{ $$ = base * $1 + $2; }
|
||||
;
|
||||
|
||||
%% /* start of programs */
|
||||
|
||||
#ifdef YYBYACC
|
||||
static int YYLEX_DECL();
|
||||
#endif
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
while(!feof(stdin)) {
|
||||
yyparse();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
YYERROR_DECL()
|
||||
{
|
||||
fprintf(stderr, "%s\n", s);
|
||||
}
|
||||
|
||||
int
|
||||
YYLEX_DECL()
|
||||
{
|
||||
/* lexical analysis routine */
|
||||
/* returns LETTER for a lower case letter, yylval = 0 through 25 */
|
||||
/* return DIGIT for a digit, yylval = 0 through 9 */
|
||||
/* all other characters are returned immediately */
|
||||
|
||||
int c;
|
||||
|
||||
while( (c=getchar()) == ' ' ) { /* skip blanks */ }
|
||||
|
||||
/* c is now nonblank */
|
||||
|
||||
if( islower( c )) {
|
||||
*yylval = c - 'a';
|
||||
return ( LETTER );
|
||||
}
|
||||
if( isdigit( c )) {
|
||||
*yylval = c - '0';
|
||||
return ( DIGIT );
|
||||
}
|
||||
return( c );
|
||||
}
|
27
test/pure_error.output
Normal file
27
test/pure_error.output
Normal file
@ -0,0 +1,27 @@
|
||||
0 $accept : S $end
|
||||
|
||||
1 S : error
|
||||
|
||||
state 0
|
||||
$accept : . S $end (0)
|
||||
|
||||
error shift 1
|
||||
. error
|
||||
|
||||
S goto 2
|
||||
|
||||
|
||||
state 1
|
||||
S : error . (1)
|
||||
|
||||
. reduce 1
|
||||
|
||||
|
||||
state 2
|
||||
$accept : S . $end (0)
|
||||
|
||||
$end accept
|
||||
|
||||
|
||||
2 terminals, 2 nonterminals
|
||||
2 grammar rules, 3 states
|
517
test/pure_error.tab.c
Normal file
517
test/pure_error.tab.c
Normal file
@ -0,0 +1,517 @@
|
||||
#ifndef lint
|
||||
static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
|
||||
#endif
|
||||
|
||||
#define YYBYACC 1
|
||||
#define YYMAJOR 1
|
||||
#define YYMINOR 9
|
||||
|
||||
#define YYEMPTY (-1)
|
||||
#define yyclearin (yychar = YYEMPTY)
|
||||
#define yyerrok (yyerrflag = 0)
|
||||
#define YYRECOVERING() (yyerrflag != 0)
|
||||
|
||||
|
||||
#ifndef yyparse
|
||||
#define yyparse error_parse
|
||||
#endif /* yyparse */
|
||||
|
||||
#ifndef yylex
|
||||
#define yylex error_lex
|
||||
#endif /* yylex */
|
||||
|
||||
#ifndef yyerror
|
||||
#define yyerror error_error
|
||||
#endif /* yyerror */
|
||||
|
||||
#ifndef yychar
|
||||
#define yychar error_char
|
||||
#endif /* yychar */
|
||||
|
||||
#ifndef yyval
|
||||
#define yyval error_val
|
||||
#endif /* yyval */
|
||||
|
||||
#ifndef yylval
|
||||
#define yylval error_lval
|
||||
#endif /* yylval */
|
||||
|
||||
#ifndef yydebug
|
||||
#define yydebug error_debug
|
||||
#endif /* yydebug */
|
||||
|
||||
#ifndef yynerrs
|
||||
#define yynerrs error_nerrs
|
||||
#endif /* yynerrs */
|
||||
|
||||
#ifndef yyerrflag
|
||||
#define yyerrflag error_errflag
|
||||
#endif /* yyerrflag */
|
||||
|
||||
#ifndef yylhs
|
||||
#define yylhs error_lhs
|
||||
#endif /* yylhs */
|
||||
|
||||
#ifndef yylen
|
||||
#define yylen error_len
|
||||
#endif /* yylen */
|
||||
|
||||
#ifndef yydefred
|
||||
#define yydefred error_defred
|
||||
#endif /* yydefred */
|
||||
|
||||
#ifndef yydgoto
|
||||
#define yydgoto error_dgoto
|
||||
#endif /* yydgoto */
|
||||
|
||||
#ifndef yysindex
|
||||
#define yysindex error_sindex
|
||||
#endif /* yysindex */
|
||||
|
||||
#ifndef yyrindex
|
||||
#define yyrindex error_rindex
|
||||
#endif /* yyrindex */
|
||||
|
||||
#ifndef yygindex
|
||||
#define yygindex error_gindex
|
||||
#endif /* yygindex */
|
||||
|
||||
#ifndef yytable
|
||||
#define yytable error_table
|
||||
#endif /* yytable */
|
||||
|
||||
#ifndef yycheck
|
||||
#define yycheck error_check
|
||||
#endif /* yycheck */
|
||||
|
||||
#ifndef yyname
|
||||
#define yyname error_name
|
||||
#endif /* yyname */
|
||||
|
||||
#ifndef yyrule
|
||||
#define yyrule error_rule
|
||||
#endif /* yyrule */
|
||||
#define YYPREFIX "error_"
|
||||
|
||||
#define YYPURE 1
|
||||
|
||||
#line 2 "pure_error.y"
|
||||
|
||||
#ifdef YYBISON
|
||||
#define YYSTYPE int
|
||||
#define YYLEX_PARAM &yylval
|
||||
#define YYLEX_DECL() yylex(YYSTYPE *yylval)
|
||||
#define YYERROR_DECL() yyerror(const char *s)
|
||||
int YYLEX_DECL();
|
||||
static void YYERROR_DECL();
|
||||
#endif
|
||||
|
||||
#line 110 "pure_error.tab.c"
|
||||
|
||||
#ifndef YYSTYPE
|
||||
typedef int YYSTYPE;
|
||||
#endif
|
||||
|
||||
/* compatibility with bison */
|
||||
#ifdef YYPARSE_PARAM
|
||||
/* compatibility with FreeBSD */
|
||||
# ifdef YYPARSE_PARAM_TYPE
|
||||
# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
|
||||
# else
|
||||
# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
|
||||
# endif
|
||||
#else
|
||||
# define YYPARSE_DECL() yyparse(void)
|
||||
#endif
|
||||
|
||||
/* Parameters sent to lex. */
|
||||
#ifdef YYLEX_PARAM
|
||||
# ifdef YYLEX_PARAM_TYPE
|
||||
# define YYLEX_DECL() yylex(YYSTYPE *yylval, YYLEX_PARAM_TYPE YYLEX_PARAM)
|
||||
# else
|
||||
# define YYLEX_DECL() yylex(YYSTYPE *yylval, void * YYLEX_PARAM)
|
||||
# endif
|
||||
# define YYLEX yylex(&yylval, YYLEX_PARAM)
|
||||
#else
|
||||
# define YYLEX_DECL() yylex(YYSTYPE *yylval)
|
||||
# define YYLEX yylex(&yylval)
|
||||
#endif
|
||||
|
||||
/* Parameters sent to yyerror. */
|
||||
#ifndef YYERROR_DECL
|
||||
#define YYERROR_DECL() yyerror(const char *s)
|
||||
#endif
|
||||
#ifndef YYERROR_CALL
|
||||
#define YYERROR_CALL(msg) yyerror(msg)
|
||||
#endif
|
||||
|
||||
extern int YYPARSE_DECL();
|
||||
|
||||
#define YYERRCODE 256
|
||||
static const short error_lhs[] = { -1,
|
||||
0,
|
||||
};
|
||||
static const short error_len[] = { 2,
|
||||
1,
|
||||
};
|
||||
static const short error_defred[] = { 0,
|
||||
1, 0,
|
||||
};
|
||||
static const short error_dgoto[] = { 2,
|
||||
};
|
||||
static const short error_sindex[] = { -256,
|
||||
0, 0,
|
||||
};
|
||||
static const short error_rindex[] = { 0,
|
||||
0, 0,
|
||||
};
|
||||
static const short error_gindex[] = { 0,
|
||||
};
|
||||
#define YYTABLESIZE 0
|
||||
static const short error_table[] = { 1,
|
||||
};
|
||||
static const short error_check[] = { 256,
|
||||
};
|
||||
#define YYFINAL 2
|
||||
#ifndef YYDEBUG
|
||||
#define YYDEBUG 0
|
||||
#endif
|
||||
#define YYMAXTOKEN 0
|
||||
#if YYDEBUG
|
||||
static const char *yyname[] = {
|
||||
|
||||
"end-of-file",
|
||||
};
|
||||
static const char *yyrule[] = {
|
||||
"$accept : S",
|
||||
"S : error",
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
int yydebug;
|
||||
int yynerrs;
|
||||
|
||||
/* define the initial stack-sizes */
|
||||
#ifdef YYSTACKSIZE
|
||||
#undef YYMAXDEPTH
|
||||
#define YYMAXDEPTH YYSTACKSIZE
|
||||
#else
|
||||
#ifdef YYMAXDEPTH
|
||||
#define YYSTACKSIZE YYMAXDEPTH
|
||||
#else
|
||||
#define YYSTACKSIZE 500
|
||||
#define YYMAXDEPTH 500
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define YYINITSTACKSIZE 500
|
||||
|
||||
typedef struct {
|
||||
unsigned stacksize;
|
||||
short *s_base;
|
||||
short *s_mark;
|
||||
short *s_last;
|
||||
YYSTYPE *l_base;
|
||||
YYSTYPE *l_mark;
|
||||
} YYSTACKDATA;
|
||||
#line 17 "pure_error.y"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef YYBYACC
|
||||
extern int YYLEX_DECL();
|
||||
#endif
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
printf("yyparse() = %d\n", yyparse());
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
yylex(YYSTYPE *value)
|
||||
{
|
||||
return value ? 0 : -1;
|
||||
}
|
||||
|
||||
static void
|
||||
yyerror(const char* s)
|
||||
{
|
||||
printf("%s\n", s);
|
||||
}
|
||||
#line 245 "pure_error.tab.c"
|
||||
|
||||
#if YYDEBUG
|
||||
#include <stdio.h> /* needed for printf */
|
||||
#endif
|
||||
|
||||
#include <stdlib.h> /* needed for malloc, etc */
|
||||
#include <string.h> /* needed for memset */
|
||||
|
||||
/* allocate initial stack or double stack size, up to YYMAXDEPTH */
|
||||
static int yygrowstack(YYSTACKDATA *data)
|
||||
{
|
||||
int i;
|
||||
unsigned newsize;
|
||||
short *newss;
|
||||
YYSTYPE *newvs;
|
||||
|
||||
if ((newsize = data->stacksize) == 0)
|
||||
newsize = YYINITSTACKSIZE;
|
||||
else if (newsize >= YYMAXDEPTH)
|
||||
return -1;
|
||||
else if ((newsize *= 2) > YYMAXDEPTH)
|
||||
newsize = YYMAXDEPTH;
|
||||
|
||||
i = data->s_mark - data->s_base;
|
||||
newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
|
||||
if (newss == 0)
|
||||
return -1;
|
||||
|
||||
data->s_base = newss;
|
||||
data->s_mark = newss + i;
|
||||
|
||||
newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
|
||||
if (newvs == 0)
|
||||
return -1;
|
||||
|
||||
data->l_base = newvs;
|
||||
data->l_mark = newvs + i;
|
||||
|
||||
data->stacksize = newsize;
|
||||
data->s_last = data->s_base + newsize - 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if YYPURE || defined(YY_NO_LEAKS)
|
||||
static void yyfreestack(YYSTACKDATA *data)
|
||||
{
|
||||
free(data->s_base);
|
||||
free(data->l_base);
|
||||
memset(data, 0, sizeof(*data));
|
||||
}
|
||||
#else
|
||||
#define yyfreestack(data) /* nothing */
|
||||
#endif
|
||||
|
||||
#define YYABORT goto yyabort
|
||||
#define YYREJECT goto yyabort
|
||||
#define YYACCEPT goto yyaccept
|
||||
#define YYERROR goto yyerrlab
|
||||
|
||||
int
|
||||
YYPARSE_DECL()
|
||||
{
|
||||
int yyerrflag;
|
||||
int yychar;
|
||||
YYSTYPE yyval;
|
||||
YYSTYPE yylval;
|
||||
|
||||
/* variables for the parser stack */
|
||||
YYSTACKDATA yystack;
|
||||
int yym, yyn, yystate;
|
||||
#if YYDEBUG
|
||||
const char *yys;
|
||||
|
||||
if ((yys = getenv("YYDEBUG")) != 0)
|
||||
{
|
||||
yyn = *yys;
|
||||
if (yyn >= '0' && yyn <= '9')
|
||||
yydebug = yyn - '0';
|
||||
}
|
||||
#endif
|
||||
|
||||
yynerrs = 0;
|
||||
yyerrflag = 0;
|
||||
yychar = YYEMPTY;
|
||||
yystate = 0;
|
||||
|
||||
#if YYPURE
|
||||
memset(&yystack, 0, sizeof(yystack));
|
||||
#endif
|
||||
|
||||
if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
|
||||
yystack.s_mark = yystack.s_base;
|
||||
yystack.l_mark = yystack.l_base;
|
||||
yystate = 0;
|
||||
*yystack.s_mark = 0;
|
||||
|
||||
yyloop:
|
||||
if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
|
||||
if (yychar < 0)
|
||||
{
|
||||
if ((yychar = YYLEX) < 0) yychar = 0;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, reading %d (%s)\n",
|
||||
YYPREFIX, yystate, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, shifting to state %d\n",
|
||||
YYPREFIX, yystate, yytable[yyn]);
|
||||
#endif
|
||||
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
yystate = yytable[yyn];
|
||||
*++yystack.s_mark = yytable[yyn];
|
||||
*++yystack.l_mark = yylval;
|
||||
yychar = YYEMPTY;
|
||||
if (yyerrflag > 0) --yyerrflag;
|
||||
goto yyloop;
|
||||
}
|
||||
if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
|
||||
{
|
||||
yyn = yytable[yyn];
|
||||
goto yyreduce;
|
||||
}
|
||||
if (yyerrflag) goto yyinrecovery;
|
||||
|
||||
yyerror("syntax error");
|
||||
|
||||
goto yyerrlab;
|
||||
|
||||
yyerrlab:
|
||||
++yynerrs;
|
||||
|
||||
yyinrecovery:
|
||||
if (yyerrflag < 3)
|
||||
{
|
||||
yyerrflag = 3;
|
||||
for (;;)
|
||||
{
|
||||
if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, error recovery shifting\
|
||||
to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
|
||||
#endif
|
||||
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
yystate = yytable[yyn];
|
||||
*++yystack.s_mark = yytable[yyn];
|
||||
*++yystack.l_mark = yylval;
|
||||
goto yyloop;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: error recovery discarding state %d\n",
|
||||
YYPREFIX, *yystack.s_mark);
|
||||
#endif
|
||||
if (yystack.s_mark <= yystack.s_base) goto yyabort;
|
||||
--yystack.s_mark;
|
||||
--yystack.l_mark;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (yychar == 0) goto yyabort;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
|
||||
YYPREFIX, yystate, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
yychar = YYEMPTY;
|
||||
goto yyloop;
|
||||
}
|
||||
|
||||
yyreduce:
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, reducing by rule %d (%s)\n",
|
||||
YYPREFIX, yystate, yyn, yyrule[yyn]);
|
||||
#endif
|
||||
yym = yylen[yyn];
|
||||
if (yym)
|
||||
yyval = yystack.l_mark[1-yym];
|
||||
else
|
||||
memset(&yyval, 0, sizeof yyval);
|
||||
switch (yyn)
|
||||
{
|
||||
}
|
||||
yystack.s_mark -= yym;
|
||||
yystate = *yystack.s_mark;
|
||||
yystack.l_mark -= yym;
|
||||
yym = yylhs[yyn];
|
||||
if (yystate == 0 && yym == 0)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: after reduction, shifting from state 0 to\
|
||||
state %d\n", YYPREFIX, YYFINAL);
|
||||
#endif
|
||||
yystate = YYFINAL;
|
||||
*++yystack.s_mark = YYFINAL;
|
||||
*++yystack.l_mark = yyval;
|
||||
if (yychar < 0)
|
||||
{
|
||||
if ((yychar = YYLEX) < 0) yychar = 0;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, reading %d (%s)\n",
|
||||
YYPREFIX, YYFINAL, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (yychar == 0) goto yyaccept;
|
||||
goto yyloop;
|
||||
}
|
||||
if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
|
||||
yystate = yytable[yyn];
|
||||
else
|
||||
yystate = yydgoto[yym];
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: after reduction, shifting from state %d \
|
||||
to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
|
||||
#endif
|
||||
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
*++yystack.s_mark = (short) yystate;
|
||||
*++yystack.l_mark = yyval;
|
||||
goto yyloop;
|
||||
|
||||
yyoverflow:
|
||||
yyerror("yacc stack overflow");
|
||||
|
||||
yyabort:
|
||||
yyfreestack(&yystack);
|
||||
return (1);
|
||||
|
||||
yyaccept:
|
||||
yyfreestack(&yystack);
|
||||
return (0);
|
||||
}
|
0
test/pure_error.tab.h
Normal file
0
test/pure_error.tab.h
Normal file
41
test/pure_error.y
Normal file
41
test/pure_error.y
Normal file
@ -0,0 +1,41 @@
|
||||
%{
|
||||
|
||||
#ifdef YYBISON
|
||||
#define YYSTYPE int
|
||||
#define YYLEX_PARAM &yylval
|
||||
#define YYLEX_DECL() yylex(YYSTYPE *yylval)
|
||||
#define YYERROR_DECL() yyerror(const char *s)
|
||||
int YYLEX_DECL();
|
||||
static void YYERROR_DECL();
|
||||
#endif
|
||||
|
||||
%}
|
||||
|
||||
%%
|
||||
S: error
|
||||
%%
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef YYBYACC
|
||||
extern int YYLEX_DECL();
|
||||
#endif
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
printf("yyparse() = %d\n", yyparse());
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
yylex(YYSTYPE *value)
|
||||
{
|
||||
return value ? 0 : -1;
|
||||
}
|
||||
|
||||
static void
|
||||
yyerror(const char* s)
|
||||
{
|
||||
printf("%s\n", s);
|
||||
}
|
557
test/quote_calc-s.output
Normal file
557
test/quote_calc-s.output
Normal file
@ -0,0 +1,557 @@
|
||||
0 $accept : list $end
|
||||
|
||||
1 list :
|
||||
2 | list stat '\n'
|
||||
3 | list error '\n'
|
||||
|
||||
4 stat : expr
|
||||
5 | LETTER '=' expr
|
||||
|
||||
6 expr : '(' expr ')'
|
||||
7 | expr OP_ADD expr
|
||||
8 | expr OP_SUB expr
|
||||
9 | expr OP_MUL expr
|
||||
10 | expr OP_DIV expr
|
||||
11 | expr OP_MOD expr
|
||||
12 | expr OP_AND expr
|
||||
13 | expr '|' expr
|
||||
14 | OP_SUB expr
|
||||
15 | LETTER
|
||||
16 | number
|
||||
|
||||
17 number : DIGIT
|
||||
18 | number DIGIT
|
||||
|
||||
state 0
|
||||
$accept : . list $end (0)
|
||||
list : . (1)
|
||||
|
||||
. reduce 1
|
||||
|
||||
list goto 1
|
||||
|
||||
|
||||
state 1
|
||||
$accept : list . $end (0)
|
||||
list : list . stat '\n' (2)
|
||||
list : list . error '\n' (3)
|
||||
|
||||
$end accept
|
||||
error shift 2
|
||||
OP_SUB shift 3
|
||||
DIGIT shift 4
|
||||
LETTER shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
stat goto 7
|
||||
expr goto 8
|
||||
number goto 9
|
||||
|
||||
|
||||
state 2
|
||||
list : list error . '\n' (3)
|
||||
|
||||
'\n' shift 10
|
||||
. error
|
||||
|
||||
|
||||
state 3
|
||||
expr : OP_SUB . expr (14)
|
||||
|
||||
OP_SUB shift 3
|
||||
DIGIT shift 4
|
||||
LETTER shift 11
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 12
|
||||
number goto 9
|
||||
|
||||
|
||||
state 4
|
||||
number : DIGIT . (17)
|
||||
|
||||
. reduce 17
|
||||
|
||||
|
||||
state 5
|
||||
stat : LETTER . '=' expr (5)
|
||||
expr : LETTER . (15)
|
||||
|
||||
'=' shift 13
|
||||
OP_ADD reduce 15
|
||||
OP_SUB reduce 15
|
||||
OP_MUL reduce 15
|
||||
OP_DIV reduce 15
|
||||
OP_MOD reduce 15
|
||||
OP_AND reduce 15
|
||||
'|' reduce 15
|
||||
'\n' reduce 15
|
||||
|
||||
|
||||
state 6
|
||||
expr : '(' . expr ')' (6)
|
||||
|
||||
OP_SUB shift 3
|
||||
DIGIT shift 4
|
||||
LETTER shift 11
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 14
|
||||
number goto 9
|
||||
|
||||
|
||||
state 7
|
||||
list : list stat . '\n' (2)
|
||||
|
||||
'\n' shift 15
|
||||
. error
|
||||
|
||||
|
||||
state 8
|
||||
stat : expr . (4)
|
||||
expr : expr . OP_ADD expr (7)
|
||||
expr : expr . OP_SUB expr (8)
|
||||
expr : expr . OP_MUL expr (9)
|
||||
expr : expr . OP_DIV expr (10)
|
||||
expr : expr . OP_MOD expr (11)
|
||||
expr : expr . OP_AND expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
OP_ADD shift 16
|
||||
OP_SUB shift 17
|
||||
OP_MUL shift 18
|
||||
OP_DIV shift 19
|
||||
OP_MOD shift 20
|
||||
OP_AND shift 21
|
||||
'|' shift 22
|
||||
'\n' reduce 4
|
||||
|
||||
|
||||
state 9
|
||||
expr : number . (16)
|
||||
number : number . DIGIT (18)
|
||||
|
||||
DIGIT shift 23
|
||||
OP_ADD reduce 16
|
||||
OP_SUB reduce 16
|
||||
OP_MUL reduce 16
|
||||
OP_DIV reduce 16
|
||||
OP_MOD reduce 16
|
||||
OP_AND reduce 16
|
||||
'|' reduce 16
|
||||
'\n' reduce 16
|
||||
')' reduce 16
|
||||
|
||||
|
||||
state 10
|
||||
list : list error '\n' . (3)
|
||||
|
||||
. reduce 3
|
||||
|
||||
|
||||
state 11
|
||||
expr : LETTER . (15)
|
||||
|
||||
. reduce 15
|
||||
|
||||
|
||||
12: shift/reduce conflict (shift 16, reduce 14) on OP_ADD
|
||||
12: shift/reduce conflict (shift 17, reduce 14) on OP_SUB
|
||||
12: shift/reduce conflict (shift 18, reduce 14) on OP_MUL
|
||||
12: shift/reduce conflict (shift 19, reduce 14) on OP_DIV
|
||||
12: shift/reduce conflict (shift 20, reduce 14) on OP_MOD
|
||||
12: shift/reduce conflict (shift 21, reduce 14) on OP_AND
|
||||
state 12
|
||||
expr : expr . OP_ADD expr (7)
|
||||
expr : expr . OP_SUB expr (8)
|
||||
expr : expr . OP_MUL expr (9)
|
||||
expr : expr . OP_DIV expr (10)
|
||||
expr : expr . OP_MOD expr (11)
|
||||
expr : expr . OP_AND expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
expr : OP_SUB expr . (14)
|
||||
|
||||
OP_ADD shift 16
|
||||
OP_SUB shift 17
|
||||
OP_MUL shift 18
|
||||
OP_DIV shift 19
|
||||
OP_MOD shift 20
|
||||
OP_AND shift 21
|
||||
'|' reduce 14
|
||||
'\n' reduce 14
|
||||
')' reduce 14
|
||||
|
||||
|
||||
state 13
|
||||
stat : LETTER '=' . expr (5)
|
||||
|
||||
OP_SUB shift 3
|
||||
DIGIT shift 4
|
||||
LETTER shift 11
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 24
|
||||
number goto 9
|
||||
|
||||
|
||||
state 14
|
||||
expr : '(' expr . ')' (6)
|
||||
expr : expr . OP_ADD expr (7)
|
||||
expr : expr . OP_SUB expr (8)
|
||||
expr : expr . OP_MUL expr (9)
|
||||
expr : expr . OP_DIV expr (10)
|
||||
expr : expr . OP_MOD expr (11)
|
||||
expr : expr . OP_AND expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
OP_ADD shift 16
|
||||
OP_SUB shift 17
|
||||
OP_MUL shift 18
|
||||
OP_DIV shift 19
|
||||
OP_MOD shift 20
|
||||
OP_AND shift 21
|
||||
'|' shift 22
|
||||
')' shift 25
|
||||
. error
|
||||
|
||||
|
||||
state 15
|
||||
list : list stat '\n' . (2)
|
||||
|
||||
. reduce 2
|
||||
|
||||
|
||||
state 16
|
||||
expr : expr OP_ADD . expr (7)
|
||||
|
||||
OP_SUB shift 3
|
||||
DIGIT shift 4
|
||||
LETTER shift 11
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 26
|
||||
number goto 9
|
||||
|
||||
|
||||
state 17
|
||||
expr : expr OP_SUB . expr (8)
|
||||
|
||||
OP_SUB shift 3
|
||||
DIGIT shift 4
|
||||
LETTER shift 11
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 27
|
||||
number goto 9
|
||||
|
||||
|
||||
state 18
|
||||
expr : expr OP_MUL . expr (9)
|
||||
|
||||
OP_SUB shift 3
|
||||
DIGIT shift 4
|
||||
LETTER shift 11
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 28
|
||||
number goto 9
|
||||
|
||||
|
||||
state 19
|
||||
expr : expr OP_DIV . expr (10)
|
||||
|
||||
OP_SUB shift 3
|
||||
DIGIT shift 4
|
||||
LETTER shift 11
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 29
|
||||
number goto 9
|
||||
|
||||
|
||||
state 20
|
||||
expr : expr OP_MOD . expr (11)
|
||||
|
||||
OP_SUB shift 3
|
||||
DIGIT shift 4
|
||||
LETTER shift 11
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 30
|
||||
number goto 9
|
||||
|
||||
|
||||
state 21
|
||||
expr : expr OP_AND . expr (12)
|
||||
|
||||
OP_SUB shift 3
|
||||
DIGIT shift 4
|
||||
LETTER shift 11
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 31
|
||||
number goto 9
|
||||
|
||||
|
||||
state 22
|
||||
expr : expr '|' . expr (13)
|
||||
|
||||
OP_SUB shift 3
|
||||
DIGIT shift 4
|
||||
LETTER shift 11
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 32
|
||||
number goto 9
|
||||
|
||||
|
||||
state 23
|
||||
number : number DIGIT . (18)
|
||||
|
||||
. reduce 18
|
||||
|
||||
|
||||
state 24
|
||||
stat : LETTER '=' expr . (5)
|
||||
expr : expr . OP_ADD expr (7)
|
||||
expr : expr . OP_SUB expr (8)
|
||||
expr : expr . OP_MUL expr (9)
|
||||
expr : expr . OP_DIV expr (10)
|
||||
expr : expr . OP_MOD expr (11)
|
||||
expr : expr . OP_AND expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
OP_ADD shift 16
|
||||
OP_SUB shift 17
|
||||
OP_MUL shift 18
|
||||
OP_DIV shift 19
|
||||
OP_MOD shift 20
|
||||
OP_AND shift 21
|
||||
'|' shift 22
|
||||
'\n' reduce 5
|
||||
|
||||
|
||||
state 25
|
||||
expr : '(' expr ')' . (6)
|
||||
|
||||
. reduce 6
|
||||
|
||||
|
||||
26: shift/reduce conflict (shift 16, reduce 7) on OP_ADD
|
||||
26: shift/reduce conflict (shift 17, reduce 7) on OP_SUB
|
||||
26: shift/reduce conflict (shift 18, reduce 7) on OP_MUL
|
||||
26: shift/reduce conflict (shift 19, reduce 7) on OP_DIV
|
||||
26: shift/reduce conflict (shift 20, reduce 7) on OP_MOD
|
||||
26: shift/reduce conflict (shift 21, reduce 7) on OP_AND
|
||||
26: shift/reduce conflict (shift 22, reduce 7) on '|'
|
||||
state 26
|
||||
expr : expr . OP_ADD expr (7)
|
||||
expr : expr OP_ADD expr . (7)
|
||||
expr : expr . OP_SUB expr (8)
|
||||
expr : expr . OP_MUL expr (9)
|
||||
expr : expr . OP_DIV expr (10)
|
||||
expr : expr . OP_MOD expr (11)
|
||||
expr : expr . OP_AND expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
OP_ADD shift 16
|
||||
OP_SUB shift 17
|
||||
OP_MUL shift 18
|
||||
OP_DIV shift 19
|
||||
OP_MOD shift 20
|
||||
OP_AND shift 21
|
||||
'|' shift 22
|
||||
'\n' reduce 7
|
||||
')' reduce 7
|
||||
|
||||
|
||||
27: shift/reduce conflict (shift 16, reduce 8) on OP_ADD
|
||||
27: shift/reduce conflict (shift 17, reduce 8) on OP_SUB
|
||||
27: shift/reduce conflict (shift 18, reduce 8) on OP_MUL
|
||||
27: shift/reduce conflict (shift 19, reduce 8) on OP_DIV
|
||||
27: shift/reduce conflict (shift 20, reduce 8) on OP_MOD
|
||||
27: shift/reduce conflict (shift 21, reduce 8) on OP_AND
|
||||
27: shift/reduce conflict (shift 22, reduce 8) on '|'
|
||||
state 27
|
||||
expr : expr . OP_ADD expr (7)
|
||||
expr : expr . OP_SUB expr (8)
|
||||
expr : expr OP_SUB expr . (8)
|
||||
expr : expr . OP_MUL expr (9)
|
||||
expr : expr . OP_DIV expr (10)
|
||||
expr : expr . OP_MOD expr (11)
|
||||
expr : expr . OP_AND expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
OP_ADD shift 16
|
||||
OP_SUB shift 17
|
||||
OP_MUL shift 18
|
||||
OP_DIV shift 19
|
||||
OP_MOD shift 20
|
||||
OP_AND shift 21
|
||||
'|' shift 22
|
||||
'\n' reduce 8
|
||||
')' reduce 8
|
||||
|
||||
|
||||
28: shift/reduce conflict (shift 16, reduce 9) on OP_ADD
|
||||
28: shift/reduce conflict (shift 17, reduce 9) on OP_SUB
|
||||
28: shift/reduce conflict (shift 18, reduce 9) on OP_MUL
|
||||
28: shift/reduce conflict (shift 19, reduce 9) on OP_DIV
|
||||
28: shift/reduce conflict (shift 20, reduce 9) on OP_MOD
|
||||
28: shift/reduce conflict (shift 21, reduce 9) on OP_AND
|
||||
28: shift/reduce conflict (shift 22, reduce 9) on '|'
|
||||
state 28
|
||||
expr : expr . OP_ADD expr (7)
|
||||
expr : expr . OP_SUB expr (8)
|
||||
expr : expr . OP_MUL expr (9)
|
||||
expr : expr OP_MUL expr . (9)
|
||||
expr : expr . OP_DIV expr (10)
|
||||
expr : expr . OP_MOD expr (11)
|
||||
expr : expr . OP_AND expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
OP_ADD shift 16
|
||||
OP_SUB shift 17
|
||||
OP_MUL shift 18
|
||||
OP_DIV shift 19
|
||||
OP_MOD shift 20
|
||||
OP_AND shift 21
|
||||
'|' shift 22
|
||||
'\n' reduce 9
|
||||
')' reduce 9
|
||||
|
||||
|
||||
29: shift/reduce conflict (shift 16, reduce 10) on OP_ADD
|
||||
29: shift/reduce conflict (shift 17, reduce 10) on OP_SUB
|
||||
29: shift/reduce conflict (shift 18, reduce 10) on OP_MUL
|
||||
29: shift/reduce conflict (shift 19, reduce 10) on OP_DIV
|
||||
29: shift/reduce conflict (shift 20, reduce 10) on OP_MOD
|
||||
29: shift/reduce conflict (shift 21, reduce 10) on OP_AND
|
||||
29: shift/reduce conflict (shift 22, reduce 10) on '|'
|
||||
state 29
|
||||
expr : expr . OP_ADD expr (7)
|
||||
expr : expr . OP_SUB expr (8)
|
||||
expr : expr . OP_MUL expr (9)
|
||||
expr : expr . OP_DIV expr (10)
|
||||
expr : expr OP_DIV expr . (10)
|
||||
expr : expr . OP_MOD expr (11)
|
||||
expr : expr . OP_AND expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
OP_ADD shift 16
|
||||
OP_SUB shift 17
|
||||
OP_MUL shift 18
|
||||
OP_DIV shift 19
|
||||
OP_MOD shift 20
|
||||
OP_AND shift 21
|
||||
'|' shift 22
|
||||
'\n' reduce 10
|
||||
')' reduce 10
|
||||
|
||||
|
||||
30: shift/reduce conflict (shift 16, reduce 11) on OP_ADD
|
||||
30: shift/reduce conflict (shift 17, reduce 11) on OP_SUB
|
||||
30: shift/reduce conflict (shift 18, reduce 11) on OP_MUL
|
||||
30: shift/reduce conflict (shift 19, reduce 11) on OP_DIV
|
||||
30: shift/reduce conflict (shift 20, reduce 11) on OP_MOD
|
||||
30: shift/reduce conflict (shift 21, reduce 11) on OP_AND
|
||||
30: shift/reduce conflict (shift 22, reduce 11) on '|'
|
||||
state 30
|
||||
expr : expr . OP_ADD expr (7)
|
||||
expr : expr . OP_SUB expr (8)
|
||||
expr : expr . OP_MUL expr (9)
|
||||
expr : expr . OP_DIV expr (10)
|
||||
expr : expr . OP_MOD expr (11)
|
||||
expr : expr OP_MOD expr . (11)
|
||||
expr : expr . OP_AND expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
OP_ADD shift 16
|
||||
OP_SUB shift 17
|
||||
OP_MUL shift 18
|
||||
OP_DIV shift 19
|
||||
OP_MOD shift 20
|
||||
OP_AND shift 21
|
||||
'|' shift 22
|
||||
'\n' reduce 11
|
||||
')' reduce 11
|
||||
|
||||
|
||||
31: shift/reduce conflict (shift 16, reduce 12) on OP_ADD
|
||||
31: shift/reduce conflict (shift 17, reduce 12) on OP_SUB
|
||||
31: shift/reduce conflict (shift 18, reduce 12) on OP_MUL
|
||||
31: shift/reduce conflict (shift 19, reduce 12) on OP_DIV
|
||||
31: shift/reduce conflict (shift 20, reduce 12) on OP_MOD
|
||||
31: shift/reduce conflict (shift 21, reduce 12) on OP_AND
|
||||
31: shift/reduce conflict (shift 22, reduce 12) on '|'
|
||||
state 31
|
||||
expr : expr . OP_ADD expr (7)
|
||||
expr : expr . OP_SUB expr (8)
|
||||
expr : expr . OP_MUL expr (9)
|
||||
expr : expr . OP_DIV expr (10)
|
||||
expr : expr . OP_MOD expr (11)
|
||||
expr : expr . OP_AND expr (12)
|
||||
expr : expr OP_AND expr . (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
OP_ADD shift 16
|
||||
OP_SUB shift 17
|
||||
OP_MUL shift 18
|
||||
OP_DIV shift 19
|
||||
OP_MOD shift 20
|
||||
OP_AND shift 21
|
||||
'|' shift 22
|
||||
'\n' reduce 12
|
||||
')' reduce 12
|
||||
|
||||
|
||||
32: shift/reduce conflict (shift 16, reduce 13) on OP_ADD
|
||||
32: shift/reduce conflict (shift 17, reduce 13) on OP_SUB
|
||||
32: shift/reduce conflict (shift 18, reduce 13) on OP_MUL
|
||||
32: shift/reduce conflict (shift 19, reduce 13) on OP_DIV
|
||||
32: shift/reduce conflict (shift 20, reduce 13) on OP_MOD
|
||||
32: shift/reduce conflict (shift 21, reduce 13) on OP_AND
|
||||
state 32
|
||||
expr : expr . OP_ADD expr (7)
|
||||
expr : expr . OP_SUB expr (8)
|
||||
expr : expr . OP_MUL expr (9)
|
||||
expr : expr . OP_DIV expr (10)
|
||||
expr : expr . OP_MOD expr (11)
|
||||
expr : expr . OP_AND expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
expr : expr '|' expr . (13)
|
||||
|
||||
OP_ADD shift 16
|
||||
OP_SUB shift 17
|
||||
OP_MUL shift 18
|
||||
OP_DIV shift 19
|
||||
OP_MOD shift 20
|
||||
OP_AND shift 21
|
||||
'|' reduce 13
|
||||
'\n' reduce 13
|
||||
')' reduce 13
|
||||
|
||||
|
||||
State 12 contains 6 shift/reduce conflicts.
|
||||
State 26 contains 7 shift/reduce conflicts.
|
||||
State 27 contains 7 shift/reduce conflicts.
|
||||
State 28 contains 7 shift/reduce conflicts.
|
||||
State 29 contains 7 shift/reduce conflicts.
|
||||
State 30 contains 7 shift/reduce conflicts.
|
||||
State 31 contains 7 shift/reduce conflicts.
|
||||
State 32 contains 6 shift/reduce conflicts.
|
||||
|
||||
|
||||
28 terminals, 5 nonterminals
|
||||
19 grammar rules, 33 states
|
687
test/quote_calc-s.tab.c
Normal file
687
test/quote_calc-s.tab.c
Normal file
@ -0,0 +1,687 @@
|
||||
#ifndef lint
|
||||
static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
|
||||
#endif
|
||||
|
||||
#define YYBYACC 1
|
||||
#define YYMAJOR 1
|
||||
#define YYMINOR 9
|
||||
|
||||
#define YYEMPTY (-1)
|
||||
#define yyclearin (yychar = YYEMPTY)
|
||||
#define yyerrok (yyerrflag = 0)
|
||||
#define YYRECOVERING() (yyerrflag != 0)
|
||||
|
||||
|
||||
#ifndef yyparse
|
||||
#define yyparse quote_calc_parse
|
||||
#endif /* yyparse */
|
||||
|
||||
#ifndef yylex
|
||||
#define yylex quote_calc_lex
|
||||
#endif /* yylex */
|
||||
|
||||
#ifndef yyerror
|
||||
#define yyerror quote_calc_error
|
||||
#endif /* yyerror */
|
||||
|
||||
#ifndef yychar
|
||||
#define yychar quote_calc_char
|
||||
#endif /* yychar */
|
||||
|
||||
#ifndef yyval
|
||||
#define yyval quote_calc_val
|
||||
#endif /* yyval */
|
||||
|
||||
#ifndef yylval
|
||||
#define yylval quote_calc_lval
|
||||
#endif /* yylval */
|
||||
|
||||
#ifndef yydebug
|
||||
#define yydebug quote_calc_debug
|
||||
#endif /* yydebug */
|
||||
|
||||
#ifndef yynerrs
|
||||
#define yynerrs quote_calc_nerrs
|
||||
#endif /* yynerrs */
|
||||
|
||||
#ifndef yyerrflag
|
||||
#define yyerrflag quote_calc_errflag
|
||||
#endif /* yyerrflag */
|
||||
|
||||
#ifndef yylhs
|
||||
#define yylhs quote_calc_lhs
|
||||
#endif /* yylhs */
|
||||
|
||||
#ifndef yylen
|
||||
#define yylen quote_calc_len
|
||||
#endif /* yylen */
|
||||
|
||||
#ifndef yydefred
|
||||
#define yydefred quote_calc_defred
|
||||
#endif /* yydefred */
|
||||
|
||||
#ifndef yydgoto
|
||||
#define yydgoto quote_calc_dgoto
|
||||
#endif /* yydgoto */
|
||||
|
||||
#ifndef yysindex
|
||||
#define yysindex quote_calc_sindex
|
||||
#endif /* yysindex */
|
||||
|
||||
#ifndef yyrindex
|
||||
#define yyrindex quote_calc_rindex
|
||||
#endif /* yyrindex */
|
||||
|
||||
#ifndef yygindex
|
||||
#define yygindex quote_calc_gindex
|
||||
#endif /* yygindex */
|
||||
|
||||
#ifndef yytable
|
||||
#define yytable quote_calc_table
|
||||
#endif /* yytable */
|
||||
|
||||
#ifndef yycheck
|
||||
#define yycheck quote_calc_check
|
||||
#endif /* yycheck */
|
||||
|
||||
#ifndef yyname
|
||||
#define yyname quote_calc_name
|
||||
#endif /* yyname */
|
||||
|
||||
#ifndef yyrule
|
||||
#define yyrule quote_calc_rule
|
||||
#endif /* yyrule */
|
||||
#define YYPREFIX "quote_calc_"
|
||||
|
||||
#define YYPURE 0
|
||||
|
||||
#line 2 "quote_calc.y"
|
||||
# include <stdio.h>
|
||||
# include <ctype.h>
|
||||
|
||||
int regs[26];
|
||||
int base;
|
||||
|
||||
int yylex(void);
|
||||
static void yyerror(const char *s);
|
||||
|
||||
#line 109 "quote_calc-s.tab.c"
|
||||
|
||||
#ifndef YYSTYPE
|
||||
typedef int YYSTYPE;
|
||||
#endif
|
||||
|
||||
/* compatibility with bison */
|
||||
#ifdef YYPARSE_PARAM
|
||||
/* compatibility with FreeBSD */
|
||||
# ifdef YYPARSE_PARAM_TYPE
|
||||
# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
|
||||
# else
|
||||
# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
|
||||
# endif
|
||||
#else
|
||||
# define YYPARSE_DECL() yyparse(void)
|
||||
#endif
|
||||
|
||||
/* Parameters sent to lex. */
|
||||
#ifdef YYLEX_PARAM
|
||||
# define YYLEX_DECL() yylex(void *YYLEX_PARAM)
|
||||
# define YYLEX yylex(YYLEX_PARAM)
|
||||
#else
|
||||
# define YYLEX_DECL() yylex(void)
|
||||
# define YYLEX yylex()
|
||||
#endif
|
||||
|
||||
/* Parameters sent to yyerror. */
|
||||
#ifndef YYERROR_DECL
|
||||
#define YYERROR_DECL() yyerror(const char *s)
|
||||
#endif
|
||||
#ifndef YYERROR_CALL
|
||||
#define YYERROR_CALL(msg) yyerror(msg)
|
||||
#endif
|
||||
|
||||
extern int YYPARSE_DECL();
|
||||
|
||||
#define OP_ADD 257
|
||||
#define OP_SUB 259
|
||||
#define OP_MUL 261
|
||||
#define OP_DIV 263
|
||||
#define OP_MOD 265
|
||||
#define OP_AND 267
|
||||
#define DIGIT 269
|
||||
#define LETTER 270
|
||||
#define UMINUS 271
|
||||
#define YYERRCODE 256
|
||||
static const short quote_calc_lhs[] = { -1,
|
||||
0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 3, 3,
|
||||
};
|
||||
static const short quote_calc_len[] = { 2,
|
||||
0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 2, 1, 1, 1, 2,
|
||||
};
|
||||
static const short quote_calc_defred[] = { 1,
|
||||
0, 0, 0, 17, 0, 0, 0, 0, 0, 3,
|
||||
15, 0, 0, 0, 2, 0, 0, 0, 0, 0,
|
||||
0, 0, 18, 0, 6, 0, 0, 0, 0, 0,
|
||||
0, 0,
|
||||
};
|
||||
static const short quote_calc_dgoto[] = { 1,
|
||||
7, 8, 9,
|
||||
};
|
||||
static const short quote_calc_sindex[] = { 0,
|
||||
-38, 5, -36, 0, -51, -36, 7, -121, -248, 0,
|
||||
0, -243, -36, -22, 0, -36, -36, -36, -36, -36,
|
||||
-36, -36, 0, -121, 0, -121, -121, -121, -121, -121,
|
||||
-121, -243,
|
||||
};
|
||||
static const short quote_calc_rindex[] = { 0,
|
||||
0, 0, 0, 0, -9, 0, 0, 13, -10, 0,
|
||||
0, -5, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 15, 0, -3, -2, -1, 1, 2,
|
||||
3, -4,
|
||||
};
|
||||
static const short quote_calc_gindex[] = { 0,
|
||||
0, 42, 0,
|
||||
};
|
||||
#define YYTABLESIZE 258
|
||||
static const short quote_calc_table[] = { 16,
|
||||
15, 6, 22, 6, 14, 13, 7, 8, 9, 13,
|
||||
10, 11, 12, 16, 10, 17, 15, 18, 25, 19,
|
||||
23, 20, 4, 21, 5, 0, 0, 0, 0, 0,
|
||||
16, 0, 0, 0, 0, 14, 13, 7, 8, 9,
|
||||
0, 10, 11, 12, 12, 0, 0, 14, 0, 0,
|
||||
0, 0, 0, 0, 24, 0, 0, 26, 27, 28,
|
||||
29, 30, 31, 32, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 22, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 16, 15, 0, 0, 0, 14, 13,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 16, 0, 17, 0, 18,
|
||||
0, 19, 0, 20, 0, 21, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 2, 0, 0,
|
||||
3, 0, 3, 0, 0, 0, 0, 0, 0, 0,
|
||||
4, 5, 4, 11, 16, 0, 17, 0, 18, 0,
|
||||
19, 0, 20, 0, 21, 0, 16, 15, 16, 15,
|
||||
16, 15, 16, 15, 16, 15, 16, 15,
|
||||
};
|
||||
static const short quote_calc_check[] = { 10,
|
||||
10, 40, 124, 40, 10, 10, 10, 10, 10, 61,
|
||||
10, 10, 10, 257, 10, 259, 10, 261, 41, 263,
|
||||
269, 265, 10, 267, 10, -1, -1, -1, -1, -1,
|
||||
41, -1, -1, -1, -1, 41, 41, 41, 41, 41,
|
||||
-1, 41, 41, 41, 3, -1, -1, 6, -1, -1,
|
||||
-1, -1, -1, -1, 13, -1, -1, 16, 17, 18,
|
||||
19, 20, 21, 22, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, 124, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, 124, 124, -1, -1, -1, 124, 124,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, 257, -1, 259, -1, 261,
|
||||
-1, 263, -1, 265, -1, 267, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, 256, -1, -1,
|
||||
259, -1, 259, -1, -1, -1, -1, -1, -1, -1,
|
||||
269, 270, 269, 270, 257, -1, 259, -1, 261, -1,
|
||||
263, -1, 265, -1, 267, -1, 257, 257, 259, 259,
|
||||
261, 261, 263, 263, 265, 265, 267, 267,
|
||||
};
|
||||
#define YYFINAL 1
|
||||
#ifndef YYDEBUG
|
||||
#define YYDEBUG 0
|
||||
#endif
|
||||
#define YYMAXTOKEN 271
|
||||
#if YYDEBUG
|
||||
static const char *yyname[] = {
|
||||
|
||||
"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'",0,"'-'",0,"'/'",0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'|'",0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,"OP_ADD","\"ADD\"","OP_SUB","\"SUB\"","OP_MUL","\"MUL\"","OP_DIV",
|
||||
"\"DIV\"","OP_MOD","\"MOD\"","OP_AND","\"AND\"","DIGIT","LETTER","UMINUS",
|
||||
};
|
||||
static const char *yyrule[] = {
|
||||
"$accept : list",
|
||||
"list :",
|
||||
"list : list stat '\\n'",
|
||||
"list : list error '\\n'",
|
||||
"stat : expr",
|
||||
"stat : LETTER '=' expr",
|
||||
"expr : '(' expr ')'",
|
||||
"expr : expr OP_ADD expr",
|
||||
"expr : expr OP_SUB expr",
|
||||
"expr : expr OP_MUL expr",
|
||||
"expr : expr OP_DIV expr",
|
||||
"expr : expr OP_MOD expr",
|
||||
"expr : expr OP_AND expr",
|
||||
"expr : expr '|' expr",
|
||||
"expr : OP_SUB expr",
|
||||
"expr : LETTER",
|
||||
"expr : number",
|
||||
"number : DIGIT",
|
||||
"number : number DIGIT",
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
int yydebug;
|
||||
int yynerrs;
|
||||
|
||||
int yyerrflag;
|
||||
int yychar;
|
||||
YYSTYPE yyval;
|
||||
YYSTYPE yylval;
|
||||
|
||||
/* define the initial stack-sizes */
|
||||
#ifdef YYSTACKSIZE
|
||||
#undef YYMAXDEPTH
|
||||
#define YYMAXDEPTH YYSTACKSIZE
|
||||
#else
|
||||
#ifdef YYMAXDEPTH
|
||||
#define YYSTACKSIZE YYMAXDEPTH
|
||||
#else
|
||||
#define YYSTACKSIZE 500
|
||||
#define YYMAXDEPTH 500
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define YYINITSTACKSIZE 500
|
||||
|
||||
typedef struct {
|
||||
unsigned stacksize;
|
||||
short *s_base;
|
||||
short *s_mark;
|
||||
short *s_last;
|
||||
YYSTYPE *l_base;
|
||||
YYSTYPE *l_mark;
|
||||
} YYSTACKDATA;
|
||||
/* variables for the parser stack */
|
||||
static YYSTACKDATA yystack;
|
||||
#line 73 "quote_calc.y"
|
||||
/* start of programs */
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
while(!feof(stdin)) {
|
||||
yyparse();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
yyerror(const char *s)
|
||||
{
|
||||
fprintf(stderr, "%s\n", s);
|
||||
}
|
||||
|
||||
int
|
||||
yylex(void) {
|
||||
/* lexical analysis routine */
|
||||
/* returns LETTER for a lower case letter, yylval = 0 through 25 */
|
||||
/* return DIGIT for a digit, yylval = 0 through 9 */
|
||||
/* all other characters are returned immediately */
|
||||
|
||||
int c;
|
||||
|
||||
while( (c=getchar()) == ' ' ) { /* skip blanks */ }
|
||||
|
||||
/* c is now nonblank */
|
||||
|
||||
if( islower( c )) {
|
||||
yylval = c - 'a';
|
||||
return ( LETTER );
|
||||
}
|
||||
if( isdigit( c )) {
|
||||
yylval = c - '0';
|
||||
return ( DIGIT );
|
||||
}
|
||||
return( c );
|
||||
}
|
||||
#line 361 "quote_calc-s.tab.c"
|
||||
|
||||
#if YYDEBUG
|
||||
#include <stdio.h> /* needed for printf */
|
||||
#endif
|
||||
|
||||
#include <stdlib.h> /* needed for malloc, etc */
|
||||
#include <string.h> /* needed for memset */
|
||||
|
||||
/* allocate initial stack or double stack size, up to YYMAXDEPTH */
|
||||
static int yygrowstack(YYSTACKDATA *data)
|
||||
{
|
||||
int i;
|
||||
unsigned newsize;
|
||||
short *newss;
|
||||
YYSTYPE *newvs;
|
||||
|
||||
if ((newsize = data->stacksize) == 0)
|
||||
newsize = YYINITSTACKSIZE;
|
||||
else if (newsize >= YYMAXDEPTH)
|
||||
return -1;
|
||||
else if ((newsize *= 2) > YYMAXDEPTH)
|
||||
newsize = YYMAXDEPTH;
|
||||
|
||||
i = data->s_mark - data->s_base;
|
||||
newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
|
||||
if (newss == 0)
|
||||
return -1;
|
||||
|
||||
data->s_base = newss;
|
||||
data->s_mark = newss + i;
|
||||
|
||||
newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
|
||||
if (newvs == 0)
|
||||
return -1;
|
||||
|
||||
data->l_base = newvs;
|
||||
data->l_mark = newvs + i;
|
||||
|
||||
data->stacksize = newsize;
|
||||
data->s_last = data->s_base + newsize - 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if YYPURE || defined(YY_NO_LEAKS)
|
||||
static void yyfreestack(YYSTACKDATA *data)
|
||||
{
|
||||
free(data->s_base);
|
||||
free(data->l_base);
|
||||
memset(data, 0, sizeof(*data));
|
||||
}
|
||||
#else
|
||||
#define yyfreestack(data) /* nothing */
|
||||
#endif
|
||||
|
||||
#define YYABORT goto yyabort
|
||||
#define YYREJECT goto yyabort
|
||||
#define YYACCEPT goto yyaccept
|
||||
#define YYERROR goto yyerrlab
|
||||
|
||||
int
|
||||
YYPARSE_DECL()
|
||||
{
|
||||
int yym, yyn, yystate;
|
||||
#if YYDEBUG
|
||||
const char *yys;
|
||||
|
||||
if ((yys = getenv("YYDEBUG")) != 0)
|
||||
{
|
||||
yyn = *yys;
|
||||
if (yyn >= '0' && yyn <= '9')
|
||||
yydebug = yyn - '0';
|
||||
}
|
||||
#endif
|
||||
|
||||
yynerrs = 0;
|
||||
yyerrflag = 0;
|
||||
yychar = YYEMPTY;
|
||||
yystate = 0;
|
||||
|
||||
#if YYPURE
|
||||
memset(&yystack, 0, sizeof(yystack));
|
||||
#endif
|
||||
|
||||
if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
|
||||
yystack.s_mark = yystack.s_base;
|
||||
yystack.l_mark = yystack.l_base;
|
||||
yystate = 0;
|
||||
*yystack.s_mark = 0;
|
||||
|
||||
yyloop:
|
||||
if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
|
||||
if (yychar < 0)
|
||||
{
|
||||
if ((yychar = YYLEX) < 0) yychar = 0;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, reading %d (%s)\n",
|
||||
YYPREFIX, yystate, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, shifting to state %d\n",
|
||||
YYPREFIX, yystate, yytable[yyn]);
|
||||
#endif
|
||||
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
yystate = yytable[yyn];
|
||||
*++yystack.s_mark = yytable[yyn];
|
||||
*++yystack.l_mark = yylval;
|
||||
yychar = YYEMPTY;
|
||||
if (yyerrflag > 0) --yyerrflag;
|
||||
goto yyloop;
|
||||
}
|
||||
if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
|
||||
{
|
||||
yyn = yytable[yyn];
|
||||
goto yyreduce;
|
||||
}
|
||||
if (yyerrflag) goto yyinrecovery;
|
||||
|
||||
yyerror("syntax error");
|
||||
|
||||
goto yyerrlab;
|
||||
|
||||
yyerrlab:
|
||||
++yynerrs;
|
||||
|
||||
yyinrecovery:
|
||||
if (yyerrflag < 3)
|
||||
{
|
||||
yyerrflag = 3;
|
||||
for (;;)
|
||||
{
|
||||
if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, error recovery shifting\
|
||||
to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
|
||||
#endif
|
||||
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
yystate = yytable[yyn];
|
||||
*++yystack.s_mark = yytable[yyn];
|
||||
*++yystack.l_mark = yylval;
|
||||
goto yyloop;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: error recovery discarding state %d\n",
|
||||
YYPREFIX, *yystack.s_mark);
|
||||
#endif
|
||||
if (yystack.s_mark <= yystack.s_base) goto yyabort;
|
||||
--yystack.s_mark;
|
||||
--yystack.l_mark;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (yychar == 0) goto yyabort;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
|
||||
YYPREFIX, yystate, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
yychar = YYEMPTY;
|
||||
goto yyloop;
|
||||
}
|
||||
|
||||
yyreduce:
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, reducing by rule %d (%s)\n",
|
||||
YYPREFIX, yystate, yyn, yyrule[yyn]);
|
||||
#endif
|
||||
yym = yylen[yyn];
|
||||
if (yym)
|
||||
yyval = yystack.l_mark[1-yym];
|
||||
else
|
||||
memset(&yyval, 0, sizeof yyval);
|
||||
switch (yyn)
|
||||
{
|
||||
case 3:
|
||||
#line 35 "quote_calc.y"
|
||||
{ yyerrok ; }
|
||||
break;
|
||||
case 4:
|
||||
#line 39 "quote_calc.y"
|
||||
{ printf("%d\n",yystack.l_mark[0]);}
|
||||
break;
|
||||
case 5:
|
||||
#line 41 "quote_calc.y"
|
||||
{ regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
|
||||
break;
|
||||
case 6:
|
||||
#line 45 "quote_calc.y"
|
||||
{ yyval = yystack.l_mark[-1]; }
|
||||
break;
|
||||
case 7:
|
||||
#line 47 "quote_calc.y"
|
||||
{ yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
|
||||
break;
|
||||
case 8:
|
||||
#line 49 "quote_calc.y"
|
||||
{ yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
|
||||
break;
|
||||
case 9:
|
||||
#line 51 "quote_calc.y"
|
||||
{ yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
|
||||
break;
|
||||
case 10:
|
||||
#line 53 "quote_calc.y"
|
||||
{ yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
|
||||
break;
|
||||
case 11:
|
||||
#line 55 "quote_calc.y"
|
||||
{ yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
|
||||
break;
|
||||
case 12:
|
||||
#line 57 "quote_calc.y"
|
||||
{ yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
|
||||
break;
|
||||
case 13:
|
||||
#line 59 "quote_calc.y"
|
||||
{ yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
|
||||
break;
|
||||
case 14:
|
||||
#line 61 "quote_calc.y"
|
||||
{ yyval = - yystack.l_mark[0]; }
|
||||
break;
|
||||
case 15:
|
||||
#line 63 "quote_calc.y"
|
||||
{ yyval = regs[yystack.l_mark[0]]; }
|
||||
break;
|
||||
case 17:
|
||||
#line 68 "quote_calc.y"
|
||||
{ yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; }
|
||||
break;
|
||||
case 18:
|
||||
#line 70 "quote_calc.y"
|
||||
{ yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; }
|
||||
break;
|
||||
#line 627 "quote_calc-s.tab.c"
|
||||
}
|
||||
yystack.s_mark -= yym;
|
||||
yystate = *yystack.s_mark;
|
||||
yystack.l_mark -= yym;
|
||||
yym = yylhs[yyn];
|
||||
if (yystate == 0 && yym == 0)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: after reduction, shifting from state 0 to\
|
||||
state %d\n", YYPREFIX, YYFINAL);
|
||||
#endif
|
||||
yystate = YYFINAL;
|
||||
*++yystack.s_mark = YYFINAL;
|
||||
*++yystack.l_mark = yyval;
|
||||
if (yychar < 0)
|
||||
{
|
||||
if ((yychar = YYLEX) < 0) yychar = 0;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, reading %d (%s)\n",
|
||||
YYPREFIX, YYFINAL, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (yychar == 0) goto yyaccept;
|
||||
goto yyloop;
|
||||
}
|
||||
if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
|
||||
yystate = yytable[yyn];
|
||||
else
|
||||
yystate = yydgoto[yym];
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: after reduction, shifting from state %d \
|
||||
to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
|
||||
#endif
|
||||
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
*++yystack.s_mark = (short) yystate;
|
||||
*++yystack.l_mark = yyval;
|
||||
goto yyloop;
|
||||
|
||||
yyoverflow:
|
||||
yyerror("yacc stack overflow");
|
||||
|
||||
yyabort:
|
||||
yyfreestack(&yystack);
|
||||
return (1);
|
||||
|
||||
yyaccept:
|
||||
yyfreestack(&yystack);
|
||||
return (0);
|
||||
}
|
9
test/quote_calc-s.tab.h
Normal file
9
test/quote_calc-s.tab.h
Normal file
@ -0,0 +1,9 @@
|
||||
#define OP_ADD 257
|
||||
#define OP_SUB 259
|
||||
#define OP_MUL 261
|
||||
#define OP_DIV 263
|
||||
#define OP_MOD 265
|
||||
#define OP_AND 267
|
||||
#define DIGIT 269
|
||||
#define LETTER 270
|
||||
#define UMINUS 271
|
557
test/quote_calc.output
Normal file
557
test/quote_calc.output
Normal file
@ -0,0 +1,557 @@
|
||||
0 $accept : list $end
|
||||
|
||||
1 list :
|
||||
2 | list stat '\n'
|
||||
3 | list error '\n'
|
||||
|
||||
4 stat : expr
|
||||
5 | LETTER '=' expr
|
||||
|
||||
6 expr : '(' expr ')'
|
||||
7 | expr OP_ADD expr
|
||||
8 | expr OP_SUB expr
|
||||
9 | expr OP_MUL expr
|
||||
10 | expr OP_DIV expr
|
||||
11 | expr OP_MOD expr
|
||||
12 | expr OP_AND expr
|
||||
13 | expr '|' expr
|
||||
14 | OP_SUB expr
|
||||
15 | LETTER
|
||||
16 | number
|
||||
|
||||
17 number : DIGIT
|
||||
18 | number DIGIT
|
||||
|
||||
state 0
|
||||
$accept : . list $end (0)
|
||||
list : . (1)
|
||||
|
||||
. reduce 1
|
||||
|
||||
list goto 1
|
||||
|
||||
|
||||
state 1
|
||||
$accept : list . $end (0)
|
||||
list : list . stat '\n' (2)
|
||||
list : list . error '\n' (3)
|
||||
|
||||
$end accept
|
||||
error shift 2
|
||||
OP_SUB shift 3
|
||||
DIGIT shift 4
|
||||
LETTER shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
stat goto 7
|
||||
expr goto 8
|
||||
number goto 9
|
||||
|
||||
|
||||
state 2
|
||||
list : list error . '\n' (3)
|
||||
|
||||
'\n' shift 10
|
||||
. error
|
||||
|
||||
|
||||
state 3
|
||||
expr : OP_SUB . expr (14)
|
||||
|
||||
OP_SUB shift 3
|
||||
DIGIT shift 4
|
||||
LETTER shift 11
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 12
|
||||
number goto 9
|
||||
|
||||
|
||||
state 4
|
||||
number : DIGIT . (17)
|
||||
|
||||
. reduce 17
|
||||
|
||||
|
||||
state 5
|
||||
stat : LETTER . '=' expr (5)
|
||||
expr : LETTER . (15)
|
||||
|
||||
'=' shift 13
|
||||
OP_ADD reduce 15
|
||||
OP_SUB reduce 15
|
||||
OP_MUL reduce 15
|
||||
OP_DIV reduce 15
|
||||
OP_MOD reduce 15
|
||||
OP_AND reduce 15
|
||||
'|' reduce 15
|
||||
'\n' reduce 15
|
||||
|
||||
|
||||
state 6
|
||||
expr : '(' . expr ')' (6)
|
||||
|
||||
OP_SUB shift 3
|
||||
DIGIT shift 4
|
||||
LETTER shift 11
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 14
|
||||
number goto 9
|
||||
|
||||
|
||||
state 7
|
||||
list : list stat . '\n' (2)
|
||||
|
||||
'\n' shift 15
|
||||
. error
|
||||
|
||||
|
||||
state 8
|
||||
stat : expr . (4)
|
||||
expr : expr . OP_ADD expr (7)
|
||||
expr : expr . OP_SUB expr (8)
|
||||
expr : expr . OP_MUL expr (9)
|
||||
expr : expr . OP_DIV expr (10)
|
||||
expr : expr . OP_MOD expr (11)
|
||||
expr : expr . OP_AND expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
OP_ADD shift 16
|
||||
OP_SUB shift 17
|
||||
OP_MUL shift 18
|
||||
OP_DIV shift 19
|
||||
OP_MOD shift 20
|
||||
OP_AND shift 21
|
||||
'|' shift 22
|
||||
'\n' reduce 4
|
||||
|
||||
|
||||
state 9
|
||||
expr : number . (16)
|
||||
number : number . DIGIT (18)
|
||||
|
||||
DIGIT shift 23
|
||||
OP_ADD reduce 16
|
||||
OP_SUB reduce 16
|
||||
OP_MUL reduce 16
|
||||
OP_DIV reduce 16
|
||||
OP_MOD reduce 16
|
||||
OP_AND reduce 16
|
||||
'|' reduce 16
|
||||
'\n' reduce 16
|
||||
')' reduce 16
|
||||
|
||||
|
||||
state 10
|
||||
list : list error '\n' . (3)
|
||||
|
||||
. reduce 3
|
||||
|
||||
|
||||
state 11
|
||||
expr : LETTER . (15)
|
||||
|
||||
. reduce 15
|
||||
|
||||
|
||||
12: shift/reduce conflict (shift 16, reduce 14) on OP_ADD
|
||||
12: shift/reduce conflict (shift 17, reduce 14) on OP_SUB
|
||||
12: shift/reduce conflict (shift 18, reduce 14) on OP_MUL
|
||||
12: shift/reduce conflict (shift 19, reduce 14) on OP_DIV
|
||||
12: shift/reduce conflict (shift 20, reduce 14) on OP_MOD
|
||||
12: shift/reduce conflict (shift 21, reduce 14) on OP_AND
|
||||
state 12
|
||||
expr : expr . OP_ADD expr (7)
|
||||
expr : expr . OP_SUB expr (8)
|
||||
expr : expr . OP_MUL expr (9)
|
||||
expr : expr . OP_DIV expr (10)
|
||||
expr : expr . OP_MOD expr (11)
|
||||
expr : expr . OP_AND expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
expr : OP_SUB expr . (14)
|
||||
|
||||
OP_ADD shift 16
|
||||
OP_SUB shift 17
|
||||
OP_MUL shift 18
|
||||
OP_DIV shift 19
|
||||
OP_MOD shift 20
|
||||
OP_AND shift 21
|
||||
'|' reduce 14
|
||||
'\n' reduce 14
|
||||
')' reduce 14
|
||||
|
||||
|
||||
state 13
|
||||
stat : LETTER '=' . expr (5)
|
||||
|
||||
OP_SUB shift 3
|
||||
DIGIT shift 4
|
||||
LETTER shift 11
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 24
|
||||
number goto 9
|
||||
|
||||
|
||||
state 14
|
||||
expr : '(' expr . ')' (6)
|
||||
expr : expr . OP_ADD expr (7)
|
||||
expr : expr . OP_SUB expr (8)
|
||||
expr : expr . OP_MUL expr (9)
|
||||
expr : expr . OP_DIV expr (10)
|
||||
expr : expr . OP_MOD expr (11)
|
||||
expr : expr . OP_AND expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
OP_ADD shift 16
|
||||
OP_SUB shift 17
|
||||
OP_MUL shift 18
|
||||
OP_DIV shift 19
|
||||
OP_MOD shift 20
|
||||
OP_AND shift 21
|
||||
'|' shift 22
|
||||
')' shift 25
|
||||
. error
|
||||
|
||||
|
||||
state 15
|
||||
list : list stat '\n' . (2)
|
||||
|
||||
. reduce 2
|
||||
|
||||
|
||||
state 16
|
||||
expr : expr OP_ADD . expr (7)
|
||||
|
||||
OP_SUB shift 3
|
||||
DIGIT shift 4
|
||||
LETTER shift 11
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 26
|
||||
number goto 9
|
||||
|
||||
|
||||
state 17
|
||||
expr : expr OP_SUB . expr (8)
|
||||
|
||||
OP_SUB shift 3
|
||||
DIGIT shift 4
|
||||
LETTER shift 11
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 27
|
||||
number goto 9
|
||||
|
||||
|
||||
state 18
|
||||
expr : expr OP_MUL . expr (9)
|
||||
|
||||
OP_SUB shift 3
|
||||
DIGIT shift 4
|
||||
LETTER shift 11
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 28
|
||||
number goto 9
|
||||
|
||||
|
||||
state 19
|
||||
expr : expr OP_DIV . expr (10)
|
||||
|
||||
OP_SUB shift 3
|
||||
DIGIT shift 4
|
||||
LETTER shift 11
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 29
|
||||
number goto 9
|
||||
|
||||
|
||||
state 20
|
||||
expr : expr OP_MOD . expr (11)
|
||||
|
||||
OP_SUB shift 3
|
||||
DIGIT shift 4
|
||||
LETTER shift 11
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 30
|
||||
number goto 9
|
||||
|
||||
|
||||
state 21
|
||||
expr : expr OP_AND . expr (12)
|
||||
|
||||
OP_SUB shift 3
|
||||
DIGIT shift 4
|
||||
LETTER shift 11
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 31
|
||||
number goto 9
|
||||
|
||||
|
||||
state 22
|
||||
expr : expr '|' . expr (13)
|
||||
|
||||
OP_SUB shift 3
|
||||
DIGIT shift 4
|
||||
LETTER shift 11
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 32
|
||||
number goto 9
|
||||
|
||||
|
||||
state 23
|
||||
number : number DIGIT . (18)
|
||||
|
||||
. reduce 18
|
||||
|
||||
|
||||
state 24
|
||||
stat : LETTER '=' expr . (5)
|
||||
expr : expr . OP_ADD expr (7)
|
||||
expr : expr . OP_SUB expr (8)
|
||||
expr : expr . OP_MUL expr (9)
|
||||
expr : expr . OP_DIV expr (10)
|
||||
expr : expr . OP_MOD expr (11)
|
||||
expr : expr . OP_AND expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
OP_ADD shift 16
|
||||
OP_SUB shift 17
|
||||
OP_MUL shift 18
|
||||
OP_DIV shift 19
|
||||
OP_MOD shift 20
|
||||
OP_AND shift 21
|
||||
'|' shift 22
|
||||
'\n' reduce 5
|
||||
|
||||
|
||||
state 25
|
||||
expr : '(' expr ')' . (6)
|
||||
|
||||
. reduce 6
|
||||
|
||||
|
||||
26: shift/reduce conflict (shift 16, reduce 7) on OP_ADD
|
||||
26: shift/reduce conflict (shift 17, reduce 7) on OP_SUB
|
||||
26: shift/reduce conflict (shift 18, reduce 7) on OP_MUL
|
||||
26: shift/reduce conflict (shift 19, reduce 7) on OP_DIV
|
||||
26: shift/reduce conflict (shift 20, reduce 7) on OP_MOD
|
||||
26: shift/reduce conflict (shift 21, reduce 7) on OP_AND
|
||||
26: shift/reduce conflict (shift 22, reduce 7) on '|'
|
||||
state 26
|
||||
expr : expr . OP_ADD expr (7)
|
||||
expr : expr OP_ADD expr . (7)
|
||||
expr : expr . OP_SUB expr (8)
|
||||
expr : expr . OP_MUL expr (9)
|
||||
expr : expr . OP_DIV expr (10)
|
||||
expr : expr . OP_MOD expr (11)
|
||||
expr : expr . OP_AND expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
OP_ADD shift 16
|
||||
OP_SUB shift 17
|
||||
OP_MUL shift 18
|
||||
OP_DIV shift 19
|
||||
OP_MOD shift 20
|
||||
OP_AND shift 21
|
||||
'|' shift 22
|
||||
'\n' reduce 7
|
||||
')' reduce 7
|
||||
|
||||
|
||||
27: shift/reduce conflict (shift 16, reduce 8) on OP_ADD
|
||||
27: shift/reduce conflict (shift 17, reduce 8) on OP_SUB
|
||||
27: shift/reduce conflict (shift 18, reduce 8) on OP_MUL
|
||||
27: shift/reduce conflict (shift 19, reduce 8) on OP_DIV
|
||||
27: shift/reduce conflict (shift 20, reduce 8) on OP_MOD
|
||||
27: shift/reduce conflict (shift 21, reduce 8) on OP_AND
|
||||
27: shift/reduce conflict (shift 22, reduce 8) on '|'
|
||||
state 27
|
||||
expr : expr . OP_ADD expr (7)
|
||||
expr : expr . OP_SUB expr (8)
|
||||
expr : expr OP_SUB expr . (8)
|
||||
expr : expr . OP_MUL expr (9)
|
||||
expr : expr . OP_DIV expr (10)
|
||||
expr : expr . OP_MOD expr (11)
|
||||
expr : expr . OP_AND expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
OP_ADD shift 16
|
||||
OP_SUB shift 17
|
||||
OP_MUL shift 18
|
||||
OP_DIV shift 19
|
||||
OP_MOD shift 20
|
||||
OP_AND shift 21
|
||||
'|' shift 22
|
||||
'\n' reduce 8
|
||||
')' reduce 8
|
||||
|
||||
|
||||
28: shift/reduce conflict (shift 16, reduce 9) on OP_ADD
|
||||
28: shift/reduce conflict (shift 17, reduce 9) on OP_SUB
|
||||
28: shift/reduce conflict (shift 18, reduce 9) on OP_MUL
|
||||
28: shift/reduce conflict (shift 19, reduce 9) on OP_DIV
|
||||
28: shift/reduce conflict (shift 20, reduce 9) on OP_MOD
|
||||
28: shift/reduce conflict (shift 21, reduce 9) on OP_AND
|
||||
28: shift/reduce conflict (shift 22, reduce 9) on '|'
|
||||
state 28
|
||||
expr : expr . OP_ADD expr (7)
|
||||
expr : expr . OP_SUB expr (8)
|
||||
expr : expr . OP_MUL expr (9)
|
||||
expr : expr OP_MUL expr . (9)
|
||||
expr : expr . OP_DIV expr (10)
|
||||
expr : expr . OP_MOD expr (11)
|
||||
expr : expr . OP_AND expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
OP_ADD shift 16
|
||||
OP_SUB shift 17
|
||||
OP_MUL shift 18
|
||||
OP_DIV shift 19
|
||||
OP_MOD shift 20
|
||||
OP_AND shift 21
|
||||
'|' shift 22
|
||||
'\n' reduce 9
|
||||
')' reduce 9
|
||||
|
||||
|
||||
29: shift/reduce conflict (shift 16, reduce 10) on OP_ADD
|
||||
29: shift/reduce conflict (shift 17, reduce 10) on OP_SUB
|
||||
29: shift/reduce conflict (shift 18, reduce 10) on OP_MUL
|
||||
29: shift/reduce conflict (shift 19, reduce 10) on OP_DIV
|
||||
29: shift/reduce conflict (shift 20, reduce 10) on OP_MOD
|
||||
29: shift/reduce conflict (shift 21, reduce 10) on OP_AND
|
||||
29: shift/reduce conflict (shift 22, reduce 10) on '|'
|
||||
state 29
|
||||
expr : expr . OP_ADD expr (7)
|
||||
expr : expr . OP_SUB expr (8)
|
||||
expr : expr . OP_MUL expr (9)
|
||||
expr : expr . OP_DIV expr (10)
|
||||
expr : expr OP_DIV expr . (10)
|
||||
expr : expr . OP_MOD expr (11)
|
||||
expr : expr . OP_AND expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
OP_ADD shift 16
|
||||
OP_SUB shift 17
|
||||
OP_MUL shift 18
|
||||
OP_DIV shift 19
|
||||
OP_MOD shift 20
|
||||
OP_AND shift 21
|
||||
'|' shift 22
|
||||
'\n' reduce 10
|
||||
')' reduce 10
|
||||
|
||||
|
||||
30: shift/reduce conflict (shift 16, reduce 11) on OP_ADD
|
||||
30: shift/reduce conflict (shift 17, reduce 11) on OP_SUB
|
||||
30: shift/reduce conflict (shift 18, reduce 11) on OP_MUL
|
||||
30: shift/reduce conflict (shift 19, reduce 11) on OP_DIV
|
||||
30: shift/reduce conflict (shift 20, reduce 11) on OP_MOD
|
||||
30: shift/reduce conflict (shift 21, reduce 11) on OP_AND
|
||||
30: shift/reduce conflict (shift 22, reduce 11) on '|'
|
||||
state 30
|
||||
expr : expr . OP_ADD expr (7)
|
||||
expr : expr . OP_SUB expr (8)
|
||||
expr : expr . OP_MUL expr (9)
|
||||
expr : expr . OP_DIV expr (10)
|
||||
expr : expr . OP_MOD expr (11)
|
||||
expr : expr OP_MOD expr . (11)
|
||||
expr : expr . OP_AND expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
OP_ADD shift 16
|
||||
OP_SUB shift 17
|
||||
OP_MUL shift 18
|
||||
OP_DIV shift 19
|
||||
OP_MOD shift 20
|
||||
OP_AND shift 21
|
||||
'|' shift 22
|
||||
'\n' reduce 11
|
||||
')' reduce 11
|
||||
|
||||
|
||||
31: shift/reduce conflict (shift 16, reduce 12) on OP_ADD
|
||||
31: shift/reduce conflict (shift 17, reduce 12) on OP_SUB
|
||||
31: shift/reduce conflict (shift 18, reduce 12) on OP_MUL
|
||||
31: shift/reduce conflict (shift 19, reduce 12) on OP_DIV
|
||||
31: shift/reduce conflict (shift 20, reduce 12) on OP_MOD
|
||||
31: shift/reduce conflict (shift 21, reduce 12) on OP_AND
|
||||
31: shift/reduce conflict (shift 22, reduce 12) on '|'
|
||||
state 31
|
||||
expr : expr . OP_ADD expr (7)
|
||||
expr : expr . OP_SUB expr (8)
|
||||
expr : expr . OP_MUL expr (9)
|
||||
expr : expr . OP_DIV expr (10)
|
||||
expr : expr . OP_MOD expr (11)
|
||||
expr : expr . OP_AND expr (12)
|
||||
expr : expr OP_AND expr . (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
OP_ADD shift 16
|
||||
OP_SUB shift 17
|
||||
OP_MUL shift 18
|
||||
OP_DIV shift 19
|
||||
OP_MOD shift 20
|
||||
OP_AND shift 21
|
||||
'|' shift 22
|
||||
'\n' reduce 12
|
||||
')' reduce 12
|
||||
|
||||
|
||||
32: shift/reduce conflict (shift 16, reduce 13) on OP_ADD
|
||||
32: shift/reduce conflict (shift 17, reduce 13) on OP_SUB
|
||||
32: shift/reduce conflict (shift 18, reduce 13) on OP_MUL
|
||||
32: shift/reduce conflict (shift 19, reduce 13) on OP_DIV
|
||||
32: shift/reduce conflict (shift 20, reduce 13) on OP_MOD
|
||||
32: shift/reduce conflict (shift 21, reduce 13) on OP_AND
|
||||
state 32
|
||||
expr : expr . OP_ADD expr (7)
|
||||
expr : expr . OP_SUB expr (8)
|
||||
expr : expr . OP_MUL expr (9)
|
||||
expr : expr . OP_DIV expr (10)
|
||||
expr : expr . OP_MOD expr (11)
|
||||
expr : expr . OP_AND expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
expr : expr '|' expr . (13)
|
||||
|
||||
OP_ADD shift 16
|
||||
OP_SUB shift 17
|
||||
OP_MUL shift 18
|
||||
OP_DIV shift 19
|
||||
OP_MOD shift 20
|
||||
OP_AND shift 21
|
||||
'|' reduce 13
|
||||
'\n' reduce 13
|
||||
')' reduce 13
|
||||
|
||||
|
||||
State 12 contains 6 shift/reduce conflicts.
|
||||
State 26 contains 7 shift/reduce conflicts.
|
||||
State 27 contains 7 shift/reduce conflicts.
|
||||
State 28 contains 7 shift/reduce conflicts.
|
||||
State 29 contains 7 shift/reduce conflicts.
|
||||
State 30 contains 7 shift/reduce conflicts.
|
||||
State 31 contains 7 shift/reduce conflicts.
|
||||
State 32 contains 6 shift/reduce conflicts.
|
||||
|
||||
|
||||
28 terminals, 5 nonterminals
|
||||
19 grammar rules, 33 states
|
693
test/quote_calc.tab.c
Normal file
693
test/quote_calc.tab.c
Normal file
@ -0,0 +1,693 @@
|
||||
#ifndef lint
|
||||
static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
|
||||
#endif
|
||||
|
||||
#define YYBYACC 1
|
||||
#define YYMAJOR 1
|
||||
#define YYMINOR 9
|
||||
|
||||
#define YYEMPTY (-1)
|
||||
#define yyclearin (yychar = YYEMPTY)
|
||||
#define yyerrok (yyerrflag = 0)
|
||||
#define YYRECOVERING() (yyerrflag != 0)
|
||||
|
||||
|
||||
#ifndef yyparse
|
||||
#define yyparse quote_calc_parse
|
||||
#endif /* yyparse */
|
||||
|
||||
#ifndef yylex
|
||||
#define yylex quote_calc_lex
|
||||
#endif /* yylex */
|
||||
|
||||
#ifndef yyerror
|
||||
#define yyerror quote_calc_error
|
||||
#endif /* yyerror */
|
||||
|
||||
#ifndef yychar
|
||||
#define yychar quote_calc_char
|
||||
#endif /* yychar */
|
||||
|
||||
#ifndef yyval
|
||||
#define yyval quote_calc_val
|
||||
#endif /* yyval */
|
||||
|
||||
#ifndef yylval
|
||||
#define yylval quote_calc_lval
|
||||
#endif /* yylval */
|
||||
|
||||
#ifndef yydebug
|
||||
#define yydebug quote_calc_debug
|
||||
#endif /* yydebug */
|
||||
|
||||
#ifndef yynerrs
|
||||
#define yynerrs quote_calc_nerrs
|
||||
#endif /* yynerrs */
|
||||
|
||||
#ifndef yyerrflag
|
||||
#define yyerrflag quote_calc_errflag
|
||||
#endif /* yyerrflag */
|
||||
|
||||
#ifndef yylhs
|
||||
#define yylhs quote_calc_lhs
|
||||
#endif /* yylhs */
|
||||
|
||||
#ifndef yylen
|
||||
#define yylen quote_calc_len
|
||||
#endif /* yylen */
|
||||
|
||||
#ifndef yydefred
|
||||
#define yydefred quote_calc_defred
|
||||
#endif /* yydefred */
|
||||
|
||||
#ifndef yydgoto
|
||||
#define yydgoto quote_calc_dgoto
|
||||
#endif /* yydgoto */
|
||||
|
||||
#ifndef yysindex
|
||||
#define yysindex quote_calc_sindex
|
||||
#endif /* yysindex */
|
||||
|
||||
#ifndef yyrindex
|
||||
#define yyrindex quote_calc_rindex
|
||||
#endif /* yyrindex */
|
||||
|
||||
#ifndef yygindex
|
||||
#define yygindex quote_calc_gindex
|
||||
#endif /* yygindex */
|
||||
|
||||
#ifndef yytable
|
||||
#define yytable quote_calc_table
|
||||
#endif /* yytable */
|
||||
|
||||
#ifndef yycheck
|
||||
#define yycheck quote_calc_check
|
||||
#endif /* yycheck */
|
||||
|
||||
#ifndef yyname
|
||||
#define yyname quote_calc_name
|
||||
#endif /* yyname */
|
||||
|
||||
#ifndef yyrule
|
||||
#define yyrule quote_calc_rule
|
||||
#endif /* yyrule */
|
||||
#define YYPREFIX "quote_calc_"
|
||||
|
||||
#define YYPURE 0
|
||||
|
||||
#line 2 "quote_calc.y"
|
||||
# include <stdio.h>
|
||||
# include <ctype.h>
|
||||
|
||||
int regs[26];
|
||||
int base;
|
||||
|
||||
int yylex(void);
|
||||
static void yyerror(const char *s);
|
||||
|
||||
#line 109 "quote_calc.tab.c"
|
||||
|
||||
#ifndef YYSTYPE
|
||||
typedef int YYSTYPE;
|
||||
#endif
|
||||
|
||||
/* compatibility with bison */
|
||||
#ifdef YYPARSE_PARAM
|
||||
/* compatibility with FreeBSD */
|
||||
# ifdef YYPARSE_PARAM_TYPE
|
||||
# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
|
||||
# else
|
||||
# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
|
||||
# endif
|
||||
#else
|
||||
# define YYPARSE_DECL() yyparse(void)
|
||||
#endif
|
||||
|
||||
/* Parameters sent to lex. */
|
||||
#ifdef YYLEX_PARAM
|
||||
# define YYLEX_DECL() yylex(void *YYLEX_PARAM)
|
||||
# define YYLEX yylex(YYLEX_PARAM)
|
||||
#else
|
||||
# define YYLEX_DECL() yylex(void)
|
||||
# define YYLEX yylex()
|
||||
#endif
|
||||
|
||||
/* Parameters sent to yyerror. */
|
||||
#ifndef YYERROR_DECL
|
||||
#define YYERROR_DECL() yyerror(const char *s)
|
||||
#endif
|
||||
#ifndef YYERROR_CALL
|
||||
#define YYERROR_CALL(msg) yyerror(msg)
|
||||
#endif
|
||||
|
||||
extern int YYPARSE_DECL();
|
||||
|
||||
#define OP_ADD 257
|
||||
#define ADD 258
|
||||
#define OP_SUB 259
|
||||
#define SUB 260
|
||||
#define OP_MUL 261
|
||||
#define MUL 262
|
||||
#define OP_DIV 263
|
||||
#define DIV 264
|
||||
#define OP_MOD 265
|
||||
#define MOD 266
|
||||
#define OP_AND 267
|
||||
#define AND 268
|
||||
#define DIGIT 269
|
||||
#define LETTER 270
|
||||
#define UMINUS 271
|
||||
#define YYERRCODE 256
|
||||
static const short quote_calc_lhs[] = { -1,
|
||||
0, 0, 0, 1, 1, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 3, 3,
|
||||
};
|
||||
static const short quote_calc_len[] = { 2,
|
||||
0, 3, 3, 1, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 2, 1, 1, 1, 2,
|
||||
};
|
||||
static const short quote_calc_defred[] = { 1,
|
||||
0, 0, 0, 17, 0, 0, 0, 0, 0, 3,
|
||||
15, 0, 0, 0, 2, 0, 0, 0, 0, 0,
|
||||
0, 0, 18, 0, 6, 0, 0, 0, 0, 0,
|
||||
0, 0,
|
||||
};
|
||||
static const short quote_calc_dgoto[] = { 1,
|
||||
7, 8, 9,
|
||||
};
|
||||
static const short quote_calc_sindex[] = { 0,
|
||||
-38, 5, -36, 0, -51, -36, 7, -121, -248, 0,
|
||||
0, -243, -36, -22, 0, -36, -36, -36, -36, -36,
|
||||
-36, -36, 0, -121, 0, -121, -121, -121, -121, -121,
|
||||
-121, -243,
|
||||
};
|
||||
static const short quote_calc_rindex[] = { 0,
|
||||
0, 0, 0, 0, -9, 0, 0, 13, -10, 0,
|
||||
0, -5, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 15, 0, -3, -2, -1, 1, 2,
|
||||
3, -4,
|
||||
};
|
||||
static const short quote_calc_gindex[] = { 0,
|
||||
0, 42, 0,
|
||||
};
|
||||
#define YYTABLESIZE 258
|
||||
static const short quote_calc_table[] = { 16,
|
||||
15, 6, 22, 6, 14, 13, 7, 8, 9, 13,
|
||||
10, 11, 12, 16, 10, 17, 15, 18, 25, 19,
|
||||
23, 20, 4, 21, 5, 0, 0, 0, 0, 0,
|
||||
16, 0, 0, 0, 0, 14, 13, 7, 8, 9,
|
||||
0, 10, 11, 12, 12, 0, 0, 14, 0, 0,
|
||||
0, 0, 0, 0, 24, 0, 0, 26, 27, 28,
|
||||
29, 30, 31, 32, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 22, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 16, 15, 0, 0, 0, 14, 13,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 16, 0, 17, 0, 18,
|
||||
0, 19, 0, 20, 0, 21, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 2, 0, 0,
|
||||
3, 0, 3, 0, 0, 0, 0, 0, 0, 0,
|
||||
4, 5, 4, 11, 16, 0, 17, 0, 18, 0,
|
||||
19, 0, 20, 0, 21, 0, 16, 15, 16, 15,
|
||||
16, 15, 16, 15, 16, 15, 16, 15,
|
||||
};
|
||||
static const short quote_calc_check[] = { 10,
|
||||
10, 40, 124, 40, 10, 10, 10, 10, 10, 61,
|
||||
10, 10, 10, 257, 10, 259, 10, 261, 41, 263,
|
||||
269, 265, 10, 267, 10, -1, -1, -1, -1, -1,
|
||||
41, -1, -1, -1, -1, 41, 41, 41, 41, 41,
|
||||
-1, 41, 41, 41, 3, -1, -1, 6, -1, -1,
|
||||
-1, -1, -1, -1, 13, -1, -1, 16, 17, 18,
|
||||
19, 20, 21, 22, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, 124, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, 124, 124, -1, -1, -1, 124, 124,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, 257, -1, 259, -1, 261,
|
||||
-1, 263, -1, 265, -1, 267, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, 256, -1, -1,
|
||||
259, -1, 259, -1, -1, -1, -1, -1, -1, -1,
|
||||
269, 270, 269, 270, 257, -1, 259, -1, 261, -1,
|
||||
263, -1, 265, -1, 267, -1, 257, 257, 259, 259,
|
||||
261, 261, 263, 263, 265, 265, 267, 267,
|
||||
};
|
||||
#define YYFINAL 1
|
||||
#ifndef YYDEBUG
|
||||
#define YYDEBUG 0
|
||||
#endif
|
||||
#define YYMAXTOKEN 271
|
||||
#if YYDEBUG
|
||||
static const char *yyname[] = {
|
||||
|
||||
"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'",0,"'-'",0,"'/'",0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'|'",0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,"OP_ADD","\"ADD\"","OP_SUB","\"SUB\"","OP_MUL","\"MUL\"","OP_DIV",
|
||||
"\"DIV\"","OP_MOD","\"MOD\"","OP_AND","\"AND\"","DIGIT","LETTER","UMINUS",
|
||||
};
|
||||
static const char *yyrule[] = {
|
||||
"$accept : list",
|
||||
"list :",
|
||||
"list : list stat '\\n'",
|
||||
"list : list error '\\n'",
|
||||
"stat : expr",
|
||||
"stat : LETTER '=' expr",
|
||||
"expr : '(' expr ')'",
|
||||
"expr : expr OP_ADD expr",
|
||||
"expr : expr OP_SUB expr",
|
||||
"expr : expr OP_MUL expr",
|
||||
"expr : expr OP_DIV expr",
|
||||
"expr : expr OP_MOD expr",
|
||||
"expr : expr OP_AND expr",
|
||||
"expr : expr '|' expr",
|
||||
"expr : OP_SUB expr",
|
||||
"expr : LETTER",
|
||||
"expr : number",
|
||||
"number : DIGIT",
|
||||
"number : number DIGIT",
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
int yydebug;
|
||||
int yynerrs;
|
||||
|
||||
int yyerrflag;
|
||||
int yychar;
|
||||
YYSTYPE yyval;
|
||||
YYSTYPE yylval;
|
||||
|
||||
/* define the initial stack-sizes */
|
||||
#ifdef YYSTACKSIZE
|
||||
#undef YYMAXDEPTH
|
||||
#define YYMAXDEPTH YYSTACKSIZE
|
||||
#else
|
||||
#ifdef YYMAXDEPTH
|
||||
#define YYSTACKSIZE YYMAXDEPTH
|
||||
#else
|
||||
#define YYSTACKSIZE 500
|
||||
#define YYMAXDEPTH 500
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define YYINITSTACKSIZE 500
|
||||
|
||||
typedef struct {
|
||||
unsigned stacksize;
|
||||
short *s_base;
|
||||
short *s_mark;
|
||||
short *s_last;
|
||||
YYSTYPE *l_base;
|
||||
YYSTYPE *l_mark;
|
||||
} YYSTACKDATA;
|
||||
/* variables for the parser stack */
|
||||
static YYSTACKDATA yystack;
|
||||
#line 73 "quote_calc.y"
|
||||
/* start of programs */
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
while(!feof(stdin)) {
|
||||
yyparse();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
yyerror(const char *s)
|
||||
{
|
||||
fprintf(stderr, "%s\n", s);
|
||||
}
|
||||
|
||||
int
|
||||
yylex(void) {
|
||||
/* lexical analysis routine */
|
||||
/* returns LETTER for a lower case letter, yylval = 0 through 25 */
|
||||
/* return DIGIT for a digit, yylval = 0 through 9 */
|
||||
/* all other characters are returned immediately */
|
||||
|
||||
int c;
|
||||
|
||||
while( (c=getchar()) == ' ' ) { /* skip blanks */ }
|
||||
|
||||
/* c is now nonblank */
|
||||
|
||||
if( islower( c )) {
|
||||
yylval = c - 'a';
|
||||
return ( LETTER );
|
||||
}
|
||||
if( isdigit( c )) {
|
||||
yylval = c - '0';
|
||||
return ( DIGIT );
|
||||
}
|
||||
return( c );
|
||||
}
|
||||
#line 367 "quote_calc.tab.c"
|
||||
|
||||
#if YYDEBUG
|
||||
#include <stdio.h> /* needed for printf */
|
||||
#endif
|
||||
|
||||
#include <stdlib.h> /* needed for malloc, etc */
|
||||
#include <string.h> /* needed for memset */
|
||||
|
||||
/* allocate initial stack or double stack size, up to YYMAXDEPTH */
|
||||
static int yygrowstack(YYSTACKDATA *data)
|
||||
{
|
||||
int i;
|
||||
unsigned newsize;
|
||||
short *newss;
|
||||
YYSTYPE *newvs;
|
||||
|
||||
if ((newsize = data->stacksize) == 0)
|
||||
newsize = YYINITSTACKSIZE;
|
||||
else if (newsize >= YYMAXDEPTH)
|
||||
return -1;
|
||||
else if ((newsize *= 2) > YYMAXDEPTH)
|
||||
newsize = YYMAXDEPTH;
|
||||
|
||||
i = data->s_mark - data->s_base;
|
||||
newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
|
||||
if (newss == 0)
|
||||
return -1;
|
||||
|
||||
data->s_base = newss;
|
||||
data->s_mark = newss + i;
|
||||
|
||||
newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
|
||||
if (newvs == 0)
|
||||
return -1;
|
||||
|
||||
data->l_base = newvs;
|
||||
data->l_mark = newvs + i;
|
||||
|
||||
data->stacksize = newsize;
|
||||
data->s_last = data->s_base + newsize - 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if YYPURE || defined(YY_NO_LEAKS)
|
||||
static void yyfreestack(YYSTACKDATA *data)
|
||||
{
|
||||
free(data->s_base);
|
||||
free(data->l_base);
|
||||
memset(data, 0, sizeof(*data));
|
||||
}
|
||||
#else
|
||||
#define yyfreestack(data) /* nothing */
|
||||
#endif
|
||||
|
||||
#define YYABORT goto yyabort
|
||||
#define YYREJECT goto yyabort
|
||||
#define YYACCEPT goto yyaccept
|
||||
#define YYERROR goto yyerrlab
|
||||
|
||||
int
|
||||
YYPARSE_DECL()
|
||||
{
|
||||
int yym, yyn, yystate;
|
||||
#if YYDEBUG
|
||||
const char *yys;
|
||||
|
||||
if ((yys = getenv("YYDEBUG")) != 0)
|
||||
{
|
||||
yyn = *yys;
|
||||
if (yyn >= '0' && yyn <= '9')
|
||||
yydebug = yyn - '0';
|
||||
}
|
||||
#endif
|
||||
|
||||
yynerrs = 0;
|
||||
yyerrflag = 0;
|
||||
yychar = YYEMPTY;
|
||||
yystate = 0;
|
||||
|
||||
#if YYPURE
|
||||
memset(&yystack, 0, sizeof(yystack));
|
||||
#endif
|
||||
|
||||
if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
|
||||
yystack.s_mark = yystack.s_base;
|
||||
yystack.l_mark = yystack.l_base;
|
||||
yystate = 0;
|
||||
*yystack.s_mark = 0;
|
||||
|
||||
yyloop:
|
||||
if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
|
||||
if (yychar < 0)
|
||||
{
|
||||
if ((yychar = YYLEX) < 0) yychar = 0;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, reading %d (%s)\n",
|
||||
YYPREFIX, yystate, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, shifting to state %d\n",
|
||||
YYPREFIX, yystate, yytable[yyn]);
|
||||
#endif
|
||||
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
yystate = yytable[yyn];
|
||||
*++yystack.s_mark = yytable[yyn];
|
||||
*++yystack.l_mark = yylval;
|
||||
yychar = YYEMPTY;
|
||||
if (yyerrflag > 0) --yyerrflag;
|
||||
goto yyloop;
|
||||
}
|
||||
if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
|
||||
{
|
||||
yyn = yytable[yyn];
|
||||
goto yyreduce;
|
||||
}
|
||||
if (yyerrflag) goto yyinrecovery;
|
||||
|
||||
yyerror("syntax error");
|
||||
|
||||
goto yyerrlab;
|
||||
|
||||
yyerrlab:
|
||||
++yynerrs;
|
||||
|
||||
yyinrecovery:
|
||||
if (yyerrflag < 3)
|
||||
{
|
||||
yyerrflag = 3;
|
||||
for (;;)
|
||||
{
|
||||
if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, error recovery shifting\
|
||||
to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
|
||||
#endif
|
||||
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
yystate = yytable[yyn];
|
||||
*++yystack.s_mark = yytable[yyn];
|
||||
*++yystack.l_mark = yylval;
|
||||
goto yyloop;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: error recovery discarding state %d\n",
|
||||
YYPREFIX, *yystack.s_mark);
|
||||
#endif
|
||||
if (yystack.s_mark <= yystack.s_base) goto yyabort;
|
||||
--yystack.s_mark;
|
||||
--yystack.l_mark;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (yychar == 0) goto yyabort;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
|
||||
YYPREFIX, yystate, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
yychar = YYEMPTY;
|
||||
goto yyloop;
|
||||
}
|
||||
|
||||
yyreduce:
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: state %d, reducing by rule %d (%s)\n",
|
||||
YYPREFIX, yystate, yyn, yyrule[yyn]);
|
||||
#endif
|
||||
yym = yylen[yyn];
|
||||
if (yym)
|
||||
yyval = yystack.l_mark[1-yym];
|
||||
else
|
||||
memset(&yyval, 0, sizeof yyval);
|
||||
switch (yyn)
|
||||
{
|
||||
case 3:
|
||||
#line 35 "quote_calc.y"
|
||||
{ yyerrok ; }
|
||||
break;
|
||||
case 4:
|
||||
#line 39 "quote_calc.y"
|
||||
{ printf("%d\n",yystack.l_mark[0]);}
|
||||
break;
|
||||
case 5:
|
||||
#line 41 "quote_calc.y"
|
||||
{ regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
|
||||
break;
|
||||
case 6:
|
||||
#line 45 "quote_calc.y"
|
||||
{ yyval = yystack.l_mark[-1]; }
|
||||
break;
|
||||
case 7:
|
||||
#line 47 "quote_calc.y"
|
||||
{ yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
|
||||
break;
|
||||
case 8:
|
||||
#line 49 "quote_calc.y"
|
||||
{ yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
|
||||
break;
|
||||
case 9:
|
||||
#line 51 "quote_calc.y"
|
||||
{ yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
|
||||
break;
|
||||
case 10:
|
||||
#line 53 "quote_calc.y"
|
||||
{ yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
|
||||
break;
|
||||
case 11:
|
||||
#line 55 "quote_calc.y"
|
||||
{ yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
|
||||
break;
|
||||
case 12:
|
||||
#line 57 "quote_calc.y"
|
||||
{ yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
|
||||
break;
|
||||
case 13:
|
||||
#line 59 "quote_calc.y"
|
||||
{ yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
|
||||
break;
|
||||
case 14:
|
||||
#line 61 "quote_calc.y"
|
||||
{ yyval = - yystack.l_mark[0]; }
|
||||
break;
|
||||
case 15:
|
||||
#line 63 "quote_calc.y"
|
||||
{ yyval = regs[yystack.l_mark[0]]; }
|
||||
break;
|
||||
case 17:
|
||||
#line 68 "quote_calc.y"
|
||||
{ yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; }
|
||||
break;
|
||||
case 18:
|
||||
#line 70 "quote_calc.y"
|
||||
{ yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; }
|
||||
break;
|
||||
#line 633 "quote_calc.tab.c"
|
||||
}
|
||||
yystack.s_mark -= yym;
|
||||
yystate = *yystack.s_mark;
|
||||
yystack.l_mark -= yym;
|
||||
yym = yylhs[yyn];
|
||||
if (yystate == 0 && yym == 0)
|
||||
{
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: after reduction, shifting from state 0 to\
|
||||
state %d\n", YYPREFIX, YYFINAL);
|
||||
#endif
|
||||
yystate = YYFINAL;
|
||||
*++yystack.s_mark = YYFINAL;
|
||||
*++yystack.l_mark = yyval;
|
||||
if (yychar < 0)
|
||||
{
|
||||
if ((yychar = YYLEX) < 0) yychar = 0;
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
{
|
||||
yys = 0;
|
||||
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
|
||||
if (!yys) yys = "illegal-symbol";
|
||||
printf("%sdebug: state %d, reading %d (%s)\n",
|
||||
YYPREFIX, YYFINAL, yychar, yys);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (yychar == 0) goto yyaccept;
|
||||
goto yyloop;
|
||||
}
|
||||
if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
|
||||
yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
|
||||
yystate = yytable[yyn];
|
||||
else
|
||||
yystate = yydgoto[yym];
|
||||
#if YYDEBUG
|
||||
if (yydebug)
|
||||
printf("%sdebug: after reduction, shifting from state %d \
|
||||
to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
|
||||
#endif
|
||||
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
|
||||
{
|
||||
goto yyoverflow;
|
||||
}
|
||||
*++yystack.s_mark = (short) yystate;
|
||||
*++yystack.l_mark = yyval;
|
||||
goto yyloop;
|
||||
|
||||
yyoverflow:
|
||||
yyerror("yacc stack overflow");
|
||||
|
||||
yyabort:
|
||||
yyfreestack(&yystack);
|
||||
return (1);
|
||||
|
||||
yyaccept:
|
||||
yyfreestack(&yystack);
|
||||
return (0);
|
||||
}
|
15
test/quote_calc.tab.h
Normal file
15
test/quote_calc.tab.h
Normal file
@ -0,0 +1,15 @@
|
||||
#define OP_ADD 257
|
||||
#define ADD 258
|
||||
#define OP_SUB 259
|
||||
#define SUB 260
|
||||
#define OP_MUL 261
|
||||
#define MUL 262
|
||||
#define OP_DIV 263
|
||||
#define DIV 264
|
||||
#define OP_MOD 265
|
||||
#define MOD 266
|
||||
#define OP_AND 267
|
||||
#define AND 268
|
||||
#define DIGIT 269
|
||||
#define LETTER 270
|
||||
#define UMINUS 271
|
112
test/quote_calc.y
Normal file
112
test/quote_calc.y
Normal file
@ -0,0 +1,112 @@
|
||||
%{
|
||||
# include <stdio.h>
|
||||
# include <ctype.h>
|
||||
|
||||
int regs[26];
|
||||
int base;
|
||||
|
||||
int yylex(void);
|
||||
static void yyerror(const char *s);
|
||||
|
||||
%}
|
||||
|
||||
%start list
|
||||
|
||||
%token OP_ADD "ADD"
|
||||
%token OP_SUB "SUB"
|
||||
%token OP_MUL "MUL"
|
||||
%token OP_DIV "DIV"
|
||||
%token OP_MOD "MOD"
|
||||
%token OP_AND "AND"
|
||||
|
||||
%token DIGIT LETTER
|
||||
|
||||
%left '|'
|
||||
%left '&'
|
||||
%left '+' '-'
|
||||
%left '*' '/' '%'
|
||||
%left UMINUS /* supplies precedence for unary minus */
|
||||
|
||||
%% /* beginning of rules section */
|
||||
|
||||
list : /* empty */
|
||||
| list stat '\n'
|
||||
| list error '\n'
|
||||
{ yyerrok ; }
|
||||
;
|
||||
|
||||
stat : expr
|
||||
{ printf("%d\n",$1);}
|
||||
| LETTER '=' expr
|
||||
{ regs[$1] = $3; }
|
||||
;
|
||||
|
||||
expr : '(' expr ')'
|
||||
{ $$ = $2; }
|
||||
| expr OP_ADD expr
|
||||
{ $$ = $1 + $3; }
|
||||
| expr OP_SUB expr
|
||||
{ $$ = $1 - $3; }
|
||||
| expr OP_MUL expr
|
||||
{ $$ = $1 * $3; }
|
||||
| expr OP_DIV expr
|
||||
{ $$ = $1 / $3; }
|
||||
| expr OP_MOD expr
|
||||
{ $$ = $1 % $3; }
|
||||
| expr OP_AND expr
|
||||
{ $$ = $1 & $3; }
|
||||
| expr '|' expr
|
||||
{ $$ = $1 | $3; }
|
||||
| OP_SUB expr %prec UMINUS
|
||||
{ $$ = - $2; }
|
||||
| LETTER
|
||||
{ $$ = regs[$1]; }
|
||||
| number
|
||||
;
|
||||
|
||||
number: DIGIT
|
||||
{ $$ = $1; base = ($1==0) ? 8 : 10; }
|
||||
| number DIGIT
|
||||
{ $$ = base * $1 + $2; }
|
||||
;
|
||||
|
||||
%% /* start of programs */
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
while(!feof(stdin)) {
|
||||
yyparse();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
yyerror(const char *s)
|
||||
{
|
||||
fprintf(stderr, "%s\n", s);
|
||||
}
|
||||
|
||||
int
|
||||
yylex(void) {
|
||||
/* lexical analysis routine */
|
||||
/* returns LETTER for a lower case letter, yylval = 0 through 25 */
|
||||
/* return DIGIT for a digit, yylval = 0 through 9 */
|
||||
/* all other characters are returned immediately */
|
||||
|
||||
int c;
|
||||
|
||||
while( (c=getchar()) == ' ' ) { /* skip blanks */ }
|
||||
|
||||
/* c is now nonblank */
|
||||
|
||||
if( islower( c )) {
|
||||
yylval = c - 'a';
|
||||
return ( LETTER );
|
||||
}
|
||||
if( isdigit( c )) {
|
||||
yylval = c - '0';
|
||||
return ( DIGIT );
|
||||
}
|
||||
return( c );
|
||||
}
|
557
test/quote_calc2-s.output
Normal file
557
test/quote_calc2-s.output
Normal file
@ -0,0 +1,557 @@
|
||||
0 $accept : list $end
|
||||
|
||||
1 list :
|
||||
2 | list stat '\n'
|
||||
3 | list error '\n'
|
||||
|
||||
4 stat : expr
|
||||
5 | LETTER '=' expr
|
||||
|
||||
6 expr : '(' expr ')'
|
||||
7 | expr "ADD" expr
|
||||
8 | expr "SUB" expr
|
||||
9 | expr "MUL" expr
|
||||
10 | expr "DIV" expr
|
||||
11 | expr "MOD" expr
|
||||
12 | expr "AND" expr
|
||||
13 | expr '|' expr
|
||||
14 | "SUB" expr
|
||||
15 | LETTER
|
||||
16 | number
|
||||
|
||||
17 number : DIGIT
|
||||
18 | number DIGIT
|
||||
|
||||
state 0
|
||||
$accept : . list $end (0)
|
||||
list : . (1)
|
||||
|
||||
. reduce 1
|
||||
|
||||
list goto 1
|
||||
|
||||
|
||||
state 1
|
||||
$accept : list . $end (0)
|
||||
list : list . stat '\n' (2)
|
||||
list : list . error '\n' (3)
|
||||
|
||||
$end accept
|
||||
error shift 2
|
||||
"SUB" shift 3
|
||||
DIGIT shift 4
|
||||
LETTER shift 5
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
stat goto 7
|
||||
expr goto 8
|
||||
number goto 9
|
||||
|
||||
|
||||
state 2
|
||||
list : list error . '\n' (3)
|
||||
|
||||
'\n' shift 10
|
||||
. error
|
||||
|
||||
|
||||
state 3
|
||||
expr : "SUB" . expr (14)
|
||||
|
||||
"SUB" shift 3
|
||||
DIGIT shift 4
|
||||
LETTER shift 11
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 12
|
||||
number goto 9
|
||||
|
||||
|
||||
state 4
|
||||
number : DIGIT . (17)
|
||||
|
||||
. reduce 17
|
||||
|
||||
|
||||
state 5
|
||||
stat : LETTER . '=' expr (5)
|
||||
expr : LETTER . (15)
|
||||
|
||||
'=' shift 13
|
||||
"ADD" reduce 15
|
||||
"SUB" reduce 15
|
||||
"MUL" reduce 15
|
||||
"DIV" reduce 15
|
||||
"MOD" reduce 15
|
||||
"AND" reduce 15
|
||||
'|' reduce 15
|
||||
'\n' reduce 15
|
||||
|
||||
|
||||
state 6
|
||||
expr : '(' . expr ')' (6)
|
||||
|
||||
"SUB" shift 3
|
||||
DIGIT shift 4
|
||||
LETTER shift 11
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 14
|
||||
number goto 9
|
||||
|
||||
|
||||
state 7
|
||||
list : list stat . '\n' (2)
|
||||
|
||||
'\n' shift 15
|
||||
. error
|
||||
|
||||
|
||||
state 8
|
||||
stat : expr . (4)
|
||||
expr : expr . "ADD" expr (7)
|
||||
expr : expr . "SUB" expr (8)
|
||||
expr : expr . "MUL" expr (9)
|
||||
expr : expr . "DIV" expr (10)
|
||||
expr : expr . "MOD" expr (11)
|
||||
expr : expr . "AND" expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
"ADD" shift 16
|
||||
"SUB" shift 17
|
||||
"MUL" shift 18
|
||||
"DIV" shift 19
|
||||
"MOD" shift 20
|
||||
"AND" shift 21
|
||||
'|' shift 22
|
||||
'\n' reduce 4
|
||||
|
||||
|
||||
state 9
|
||||
expr : number . (16)
|
||||
number : number . DIGIT (18)
|
||||
|
||||
DIGIT shift 23
|
||||
"ADD" reduce 16
|
||||
"SUB" reduce 16
|
||||
"MUL" reduce 16
|
||||
"DIV" reduce 16
|
||||
"MOD" reduce 16
|
||||
"AND" reduce 16
|
||||
'|' reduce 16
|
||||
'\n' reduce 16
|
||||
')' reduce 16
|
||||
|
||||
|
||||
state 10
|
||||
list : list error '\n' . (3)
|
||||
|
||||
. reduce 3
|
||||
|
||||
|
||||
state 11
|
||||
expr : LETTER . (15)
|
||||
|
||||
. reduce 15
|
||||
|
||||
|
||||
12: shift/reduce conflict (shift 16, reduce 14) on "ADD"
|
||||
12: shift/reduce conflict (shift 17, reduce 14) on "SUB"
|
||||
12: shift/reduce conflict (shift 18, reduce 14) on "MUL"
|
||||
12: shift/reduce conflict (shift 19, reduce 14) on "DIV"
|
||||
12: shift/reduce conflict (shift 20, reduce 14) on "MOD"
|
||||
12: shift/reduce conflict (shift 21, reduce 14) on "AND"
|
||||
state 12
|
||||
expr : expr . "ADD" expr (7)
|
||||
expr : expr . "SUB" expr (8)
|
||||
expr : expr . "MUL" expr (9)
|
||||
expr : expr . "DIV" expr (10)
|
||||
expr : expr . "MOD" expr (11)
|
||||
expr : expr . "AND" expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
expr : "SUB" expr . (14)
|
||||
|
||||
"ADD" shift 16
|
||||
"SUB" shift 17
|
||||
"MUL" shift 18
|
||||
"DIV" shift 19
|
||||
"MOD" shift 20
|
||||
"AND" shift 21
|
||||
'|' reduce 14
|
||||
'\n' reduce 14
|
||||
')' reduce 14
|
||||
|
||||
|
||||
state 13
|
||||
stat : LETTER '=' . expr (5)
|
||||
|
||||
"SUB" shift 3
|
||||
DIGIT shift 4
|
||||
LETTER shift 11
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 24
|
||||
number goto 9
|
||||
|
||||
|
||||
state 14
|
||||
expr : '(' expr . ')' (6)
|
||||
expr : expr . "ADD" expr (7)
|
||||
expr : expr . "SUB" expr (8)
|
||||
expr : expr . "MUL" expr (9)
|
||||
expr : expr . "DIV" expr (10)
|
||||
expr : expr . "MOD" expr (11)
|
||||
expr : expr . "AND" expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
"ADD" shift 16
|
||||
"SUB" shift 17
|
||||
"MUL" shift 18
|
||||
"DIV" shift 19
|
||||
"MOD" shift 20
|
||||
"AND" shift 21
|
||||
'|' shift 22
|
||||
')' shift 25
|
||||
. error
|
||||
|
||||
|
||||
state 15
|
||||
list : list stat '\n' . (2)
|
||||
|
||||
. reduce 2
|
||||
|
||||
|
||||
state 16
|
||||
expr : expr "ADD" . expr (7)
|
||||
|
||||
"SUB" shift 3
|
||||
DIGIT shift 4
|
||||
LETTER shift 11
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 26
|
||||
number goto 9
|
||||
|
||||
|
||||
state 17
|
||||
expr : expr "SUB" . expr (8)
|
||||
|
||||
"SUB" shift 3
|
||||
DIGIT shift 4
|
||||
LETTER shift 11
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 27
|
||||
number goto 9
|
||||
|
||||
|
||||
state 18
|
||||
expr : expr "MUL" . expr (9)
|
||||
|
||||
"SUB" shift 3
|
||||
DIGIT shift 4
|
||||
LETTER shift 11
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 28
|
||||
number goto 9
|
||||
|
||||
|
||||
state 19
|
||||
expr : expr "DIV" . expr (10)
|
||||
|
||||
"SUB" shift 3
|
||||
DIGIT shift 4
|
||||
LETTER shift 11
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 29
|
||||
number goto 9
|
||||
|
||||
|
||||
state 20
|
||||
expr : expr "MOD" . expr (11)
|
||||
|
||||
"SUB" shift 3
|
||||
DIGIT shift 4
|
||||
LETTER shift 11
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 30
|
||||
number goto 9
|
||||
|
||||
|
||||
state 21
|
||||
expr : expr "AND" . expr (12)
|
||||
|
||||
"SUB" shift 3
|
||||
DIGIT shift 4
|
||||
LETTER shift 11
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 31
|
||||
number goto 9
|
||||
|
||||
|
||||
state 22
|
||||
expr : expr '|' . expr (13)
|
||||
|
||||
"SUB" shift 3
|
||||
DIGIT shift 4
|
||||
LETTER shift 11
|
||||
'(' shift 6
|
||||
. error
|
||||
|
||||
expr goto 32
|
||||
number goto 9
|
||||
|
||||
|
||||
state 23
|
||||
number : number DIGIT . (18)
|
||||
|
||||
. reduce 18
|
||||
|
||||
|
||||
state 24
|
||||
stat : LETTER '=' expr . (5)
|
||||
expr : expr . "ADD" expr (7)
|
||||
expr : expr . "SUB" expr (8)
|
||||
expr : expr . "MUL" expr (9)
|
||||
expr : expr . "DIV" expr (10)
|
||||
expr : expr . "MOD" expr (11)
|
||||
expr : expr . "AND" expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
"ADD" shift 16
|
||||
"SUB" shift 17
|
||||
"MUL" shift 18
|
||||
"DIV" shift 19
|
||||
"MOD" shift 20
|
||||
"AND" shift 21
|
||||
'|' shift 22
|
||||
'\n' reduce 5
|
||||
|
||||
|
||||
state 25
|
||||
expr : '(' expr ')' . (6)
|
||||
|
||||
. reduce 6
|
||||
|
||||
|
||||
26: shift/reduce conflict (shift 16, reduce 7) on "ADD"
|
||||
26: shift/reduce conflict (shift 17, reduce 7) on "SUB"
|
||||
26: shift/reduce conflict (shift 18, reduce 7) on "MUL"
|
||||
26: shift/reduce conflict (shift 19, reduce 7) on "DIV"
|
||||
26: shift/reduce conflict (shift 20, reduce 7) on "MOD"
|
||||
26: shift/reduce conflict (shift 21, reduce 7) on "AND"
|
||||
26: shift/reduce conflict (shift 22, reduce 7) on '|'
|
||||
state 26
|
||||
expr : expr . "ADD" expr (7)
|
||||
expr : expr "ADD" expr . (7)
|
||||
expr : expr . "SUB" expr (8)
|
||||
expr : expr . "MUL" expr (9)
|
||||
expr : expr . "DIV" expr (10)
|
||||
expr : expr . "MOD" expr (11)
|
||||
expr : expr . "AND" expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
"ADD" shift 16
|
||||
"SUB" shift 17
|
||||
"MUL" shift 18
|
||||
"DIV" shift 19
|
||||
"MOD" shift 20
|
||||
"AND" shift 21
|
||||
'|' shift 22
|
||||
'\n' reduce 7
|
||||
')' reduce 7
|
||||
|
||||
|
||||
27: shift/reduce conflict (shift 16, reduce 8) on "ADD"
|
||||
27: shift/reduce conflict (shift 17, reduce 8) on "SUB"
|
||||
27: shift/reduce conflict (shift 18, reduce 8) on "MUL"
|
||||
27: shift/reduce conflict (shift 19, reduce 8) on "DIV"
|
||||
27: shift/reduce conflict (shift 20, reduce 8) on "MOD"
|
||||
27: shift/reduce conflict (shift 21, reduce 8) on "AND"
|
||||
27: shift/reduce conflict (shift 22, reduce 8) on '|'
|
||||
state 27
|
||||
expr : expr . "ADD" expr (7)
|
||||
expr : expr . "SUB" expr (8)
|
||||
expr : expr "SUB" expr . (8)
|
||||
expr : expr . "MUL" expr (9)
|
||||
expr : expr . "DIV" expr (10)
|
||||
expr : expr . "MOD" expr (11)
|
||||
expr : expr . "AND" expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
"ADD" shift 16
|
||||
"SUB" shift 17
|
||||
"MUL" shift 18
|
||||
"DIV" shift 19
|
||||
"MOD" shift 20
|
||||
"AND" shift 21
|
||||
'|' shift 22
|
||||
'\n' reduce 8
|
||||
')' reduce 8
|
||||
|
||||
|
||||
28: shift/reduce conflict (shift 16, reduce 9) on "ADD"
|
||||
28: shift/reduce conflict (shift 17, reduce 9) on "SUB"
|
||||
28: shift/reduce conflict (shift 18, reduce 9) on "MUL"
|
||||
28: shift/reduce conflict (shift 19, reduce 9) on "DIV"
|
||||
28: shift/reduce conflict (shift 20, reduce 9) on "MOD"
|
||||
28: shift/reduce conflict (shift 21, reduce 9) on "AND"
|
||||
28: shift/reduce conflict (shift 22, reduce 9) on '|'
|
||||
state 28
|
||||
expr : expr . "ADD" expr (7)
|
||||
expr : expr . "SUB" expr (8)
|
||||
expr : expr . "MUL" expr (9)
|
||||
expr : expr "MUL" expr . (9)
|
||||
expr : expr . "DIV" expr (10)
|
||||
expr : expr . "MOD" expr (11)
|
||||
expr : expr . "AND" expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
"ADD" shift 16
|
||||
"SUB" shift 17
|
||||
"MUL" shift 18
|
||||
"DIV" shift 19
|
||||
"MOD" shift 20
|
||||
"AND" shift 21
|
||||
'|' shift 22
|
||||
'\n' reduce 9
|
||||
')' reduce 9
|
||||
|
||||
|
||||
29: shift/reduce conflict (shift 16, reduce 10) on "ADD"
|
||||
29: shift/reduce conflict (shift 17, reduce 10) on "SUB"
|
||||
29: shift/reduce conflict (shift 18, reduce 10) on "MUL"
|
||||
29: shift/reduce conflict (shift 19, reduce 10) on "DIV"
|
||||
29: shift/reduce conflict (shift 20, reduce 10) on "MOD"
|
||||
29: shift/reduce conflict (shift 21, reduce 10) on "AND"
|
||||
29: shift/reduce conflict (shift 22, reduce 10) on '|'
|
||||
state 29
|
||||
expr : expr . "ADD" expr (7)
|
||||
expr : expr . "SUB" expr (8)
|
||||
expr : expr . "MUL" expr (9)
|
||||
expr : expr . "DIV" expr (10)
|
||||
expr : expr "DIV" expr . (10)
|
||||
expr : expr . "MOD" expr (11)
|
||||
expr : expr . "AND" expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
"ADD" shift 16
|
||||
"SUB" shift 17
|
||||
"MUL" shift 18
|
||||
"DIV" shift 19
|
||||
"MOD" shift 20
|
||||
"AND" shift 21
|
||||
'|' shift 22
|
||||
'\n' reduce 10
|
||||
')' reduce 10
|
||||
|
||||
|
||||
30: shift/reduce conflict (shift 16, reduce 11) on "ADD"
|
||||
30: shift/reduce conflict (shift 17, reduce 11) on "SUB"
|
||||
30: shift/reduce conflict (shift 18, reduce 11) on "MUL"
|
||||
30: shift/reduce conflict (shift 19, reduce 11) on "DIV"
|
||||
30: shift/reduce conflict (shift 20, reduce 11) on "MOD"
|
||||
30: shift/reduce conflict (shift 21, reduce 11) on "AND"
|
||||
30: shift/reduce conflict (shift 22, reduce 11) on '|'
|
||||
state 30
|
||||
expr : expr . "ADD" expr (7)
|
||||
expr : expr . "SUB" expr (8)
|
||||
expr : expr . "MUL" expr (9)
|
||||
expr : expr . "DIV" expr (10)
|
||||
expr : expr . "MOD" expr (11)
|
||||
expr : expr "MOD" expr . (11)
|
||||
expr : expr . "AND" expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
"ADD" shift 16
|
||||
"SUB" shift 17
|
||||
"MUL" shift 18
|
||||
"DIV" shift 19
|
||||
"MOD" shift 20
|
||||
"AND" shift 21
|
||||
'|' shift 22
|
||||
'\n' reduce 11
|
||||
')' reduce 11
|
||||
|
||||
|
||||
31: shift/reduce conflict (shift 16, reduce 12) on "ADD"
|
||||
31: shift/reduce conflict (shift 17, reduce 12) on "SUB"
|
||||
31: shift/reduce conflict (shift 18, reduce 12) on "MUL"
|
||||
31: shift/reduce conflict (shift 19, reduce 12) on "DIV"
|
||||
31: shift/reduce conflict (shift 20, reduce 12) on "MOD"
|
||||
31: shift/reduce conflict (shift 21, reduce 12) on "AND"
|
||||
31: shift/reduce conflict (shift 22, reduce 12) on '|'
|
||||
state 31
|
||||
expr : expr . "ADD" expr (7)
|
||||
expr : expr . "SUB" expr (8)
|
||||
expr : expr . "MUL" expr (9)
|
||||
expr : expr . "DIV" expr (10)
|
||||
expr : expr . "MOD" expr (11)
|
||||
expr : expr . "AND" expr (12)
|
||||
expr : expr "AND" expr . (12)
|
||||
expr : expr . '|' expr (13)
|
||||
|
||||
"ADD" shift 16
|
||||
"SUB" shift 17
|
||||
"MUL" shift 18
|
||||
"DIV" shift 19
|
||||
"MOD" shift 20
|
||||
"AND" shift 21
|
||||
'|' shift 22
|
||||
'\n' reduce 12
|
||||
')' reduce 12
|
||||
|
||||
|
||||
32: shift/reduce conflict (shift 16, reduce 13) on "ADD"
|
||||
32: shift/reduce conflict (shift 17, reduce 13) on "SUB"
|
||||
32: shift/reduce conflict (shift 18, reduce 13) on "MUL"
|
||||
32: shift/reduce conflict (shift 19, reduce 13) on "DIV"
|
||||
32: shift/reduce conflict (shift 20, reduce 13) on "MOD"
|
||||
32: shift/reduce conflict (shift 21, reduce 13) on "AND"
|
||||
state 32
|
||||
expr : expr . "ADD" expr (7)
|
||||
expr : expr . "SUB" expr (8)
|
||||
expr : expr . "MUL" expr (9)
|
||||
expr : expr . "DIV" expr (10)
|
||||
expr : expr . "MOD" expr (11)
|
||||
expr : expr . "AND" expr (12)
|
||||
expr : expr . '|' expr (13)
|
||||
expr : expr '|' expr . (13)
|
||||
|
||||
"ADD" shift 16
|
||||
"SUB" shift 17
|
||||
"MUL" shift 18
|
||||
"DIV" shift 19
|
||||
"MOD" shift 20
|
||||
"AND" shift 21
|
||||
'|' reduce 13
|
||||
'\n' reduce 13
|
||||
')' reduce 13
|
||||
|
||||
|
||||
State 12 contains 6 shift/reduce conflicts.
|
||||
State 26 contains 7 shift/reduce conflicts.
|
||||
State 27 contains 7 shift/reduce conflicts.
|
||||
State 28 contains 7 shift/reduce conflicts.
|
||||
State 29 contains 7 shift/reduce conflicts.
|
||||
State 30 contains 7 shift/reduce conflicts.
|
||||
State 31 contains 7 shift/reduce conflicts.
|
||||
State 32 contains 6 shift/reduce conflicts.
|
||||
|
||||
|
||||
28 terminals, 5 nonterminals
|
||||
19 grammar rules, 33 states
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user