Import NetBSD byacc

This commit is contained in:
Thomas Veerman 2012-06-06 13:25:48 +00:00
parent 18a5822eff
commit 4a17663c14
116 changed files with 34002 additions and 4964 deletions

View file

@ -32,7 +32,7 @@ SUBDIR= add_route arp ash at \
truncate tsort tty udpstat umount uname unexpand \
unstack update uud uue version vol wc \
whereis which who write writeisofs fetch \
xargs yacc yes zdump zmodem pkgin_cd \
xargs yes zdump zmodem pkgin_cd \
mktemp worldstone updateboot update_bootcfg
.if ${MACHINE_ARCH} == "i386"

View file

@ -1,7 +0,0 @@
# $NetBSD: Makefile,v 1.8 2003/05/18 07:57:38 lukem Exp $
PROG= 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
.include <bsd.prog.mk>

View file

@ -1,372 +0,0 @@
/* $NetBSD: defs.h,v 1.17 2009/04/14 09:41:30 lukem Exp $ */
/*
* Copyright (c) 1989 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Robert Paul Corbett.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)defs.h 5.6 (Berkeley) 5/24/93
*/
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* 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 */
/* defines for constructing filenames */
#define CODE_SUFFIX ".code.c"
#define DEFINES_SUFFIX ".tab.h"
#define OUTPUT_SUFFIX ".tab.c"
#define VERBOSE_SUFFIX ".output"
/* 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
/* 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((unsigned)(k),(unsigned)(n)))
#define FREE(x) (free((char*)(x)))
#define MALLOC(n) (malloc((unsigned)(n)))
#define NEW(t) ((t*)allocate(sizeof(t)))
#define NEW2(n,t) ((t*)allocate((unsigned)((n)*sizeof(t))))
#define REALLOC(p,n) (realloc((char*)(p),(unsigned)(n)))
/* the structure of a symbol table entry */
typedef struct bucket bucket;
struct bucket
{
struct bucket *link;
struct bucket *next;
char *name;
char *tag;
short value;
short index;
short prec;
char class;
char assoc;
};
/* the structure of the LR(0) state machine */
typedef struct core core;
struct core
{
struct core *next;
struct core *link;
short number;
short accessing_symbol;
short nitems;
short items[1];
};
/* the structure used to record shifts */
typedef struct shifts shifts;
struct shifts
{
struct shifts *next;
short number;
short nshifts;
short shift[1];
};
/* the structure used to store reductions */
typedef struct reductions reductions;
struct reductions
{
struct reductions *next;
short number;
short nreds;
short rules[1];
};
/* the structure used to represent parser actions */
typedef struct action action;
struct action
{
struct action *next;
short symbol;
short number;
short prec;
char action_code;
char assoc;
char suppressed;
};
/* global variables */
extern char dflag;
extern char lflag;
extern char rflag;
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 const char * const banner[];
extern const char * const tables[];
extern const char * const header[];
extern const char * const body[];
extern const char * const trailer[];
extern char *action_file_name;
extern char *code_file_name;
extern char *defines_file_name;
extern const char *input_file_name;
extern char *output_file_name;
extern char *text_file_name;
extern char *union_file_name;
extern char *verbose_file_name;
extern FILE *action_file;
extern FILE *code_file;
extern FILE *defines_file;
extern FILE *input_file;
extern FILE *output_file;
extern FILE *text_file;
extern FILE *union_file;
extern FILE *verbose_file;
extern int nitems;
extern int nrules;
extern int nsyms;
extern int ntokens;
extern int nvars;
extern int ntags;
extern char unionized;
extern int start_symbol;
extern char **symbol_name;
extern short *symbol_value;
extern short *symbol_prec;
extern char *symbol_assoc;
extern short *ritem;
extern short *rlhs;
extern short *rrhs;
extern short *rprec;
extern char *rassoc;
extern short **derives;
extern char *nullable;
extern bucket *first_symbol;
extern bucket *last_symbol;
extern int nstates;
extern core *first_state;
extern shifts *first_shift;
extern reductions *first_reduction;
extern short *accessing_symbol;
extern core **state_table;
extern shifts **shift_table;
extern reductions **reduction_table;
extern unsigned *LA;
extern short *LAruleno;
extern short *lookaheads;
extern short *goto_map;
extern short *from_state;
extern short *to_state;
extern action **parser;
extern int SRtotal;
extern int RRtotal;
extern short *SRconflicts;
extern short *RRconflicts;
extern short *defred;
extern short *rules_used;
extern short nunused;
extern short final_state;
/* global functions */
extern char *allocate(unsigned);
extern bucket *lookup(char *);
extern bucket *make_bucket(const char *);
extern void set_first_derives(void);
extern void closure(short *, int);
extern void finalize_closure(void);
extern __dead void fatal(const char *);
extern void reflexive_transitive_closure(unsigned *, int);
extern __dead void done(int);
extern __dead void no_space(void);
extern __dead void open_error(const char *);
extern __dead void unexpected_EOF(void);
extern void print_pos(char *, char *);
extern __dead void syntax_error(int, char *, char *);
extern __dead void unterminated_comment(int, char *, char *);
extern __dead void unterminated_string(int, char *, char *);
extern __dead void unterminated_text(int, char *, char *);
extern __dead void unterminated_union(int, char *, char *);
extern __dead void over_unionized(char *);
extern void illegal_tag(int, char *, char *);
extern void illegal_character(char *);
extern void used_reserved(char *);
extern void tokenized_start(char *);
extern void retyped_warning(char *);
extern void reprec_warning(char *);
extern void revalued_warning(char *);
extern __dead void terminal_start(char *);
extern void restarted_warning(void);
extern __dead void no_grammar(void);
extern __dead void terminal_lhs(int);
extern void prec_redeclared(void);
extern __dead void unterminated_action(int, char *, char *);
extern void dollar_warning(int, int);
extern __dead void dollar_error(int, char *, char *);
extern __dead void untyped_lhs(void);
extern __dead void untyped_rhs(int, char *);
extern __dead void unknown_rhs(int);
extern void default_action_warning(void);
extern __dead void undefined_goal(char *);
extern void undefined_symbol_warning(char *);
extern void lalr(void);
extern void reader(void);
extern void lr0(void);
extern void make_parser(void);
extern void verbose(void);
extern void output(void);
extern void free_parser(void);
extern void write_section(const char * const []);
extern void create_symbol_table(void);
extern void free_symbol_table(void);
extern void free_symbols(void);

View file

@ -1,696 +0,0 @@
/* $NetBSD: lalr.c,v 1.11 2009/04/14 09:41:30 lukem Exp $ */
/*
* Copyright (c) 1989 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Robert Paul Corbett.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
#if 0
static char sccsid[] = "@(#)lalr.c 5.3 (Berkeley) 6/1/90";
#else
__RCSID("$NetBSD: lalr.c,v 1.11 2009/04/14 09:41:30 lukem Exp $");
#endif
#endif /* not lint */
#include "defs.h"
typedef
struct shorts
{
struct shorts *next;
short value;
}
shorts;
short *lookaheads;
short *LAruleno;
unsigned *LA;
short *accessing_symbol;
core **state_table;
shifts **shift_table;
reductions **reduction_table;
short *goto_map;
short *from_state;
short *to_state;
static int tokensetsize;
static short **transpose(short **, int);
static void set_state_table(void);
static void set_accessing_symbol(void);
static void set_shift_table(void);
static void set_reduction_table(void);
static void set_maxrhs(void);
static void initialize_LA(void);
static void set_goto_map(void);
static void initialize_F(void);
static void build_relations(void);
static void compute_FOLLOWS(void);
static void compute_lookaheads(void);
static int map_goto(int, int);
static void digraph(short **);
static void add_lookback_edge(int, int, int);
static void traverse(int);
static int infinity;
static int maxrhs;
static int ngotos;
static unsigned *F;
static short **includes;
static shorts **lookback;
static short **R;
static short *INDEX;
static short *VERTICES;
static int 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, short);
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)
{
short *itemp;
short *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, short);
k = 0;
for (i = 0; i < nstates; i++)
{
lookaheads[i] = k;
rp = reduction_table[i];
if (rp)
k += rp->nreds;
}
lookaheads[nstates] = k;
LA = NEW2(k * tokensetsize, unsigned);
LAruleno = NEW2(k, short);
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;
short *temp_map;
int state2;
int state1;
goto_map = NEW2(nvars + 1, short) - ntokens;
temp_map = NEW2(nvars + 1, short) - 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] = k;
k += goto_map[i];
}
for (i = ntokens; i < nsyms; i++)
goto_map[i] = temp_map[i];
goto_map[nsyms] = ngotos;
temp_map[nsyms] = ngotos;
from_state = NEW2(ngotos, short);
to_state = NEW2(ngotos, short);
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 int
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 (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;
short *edge;
unsigned *rowp;
short *rp;
short **reads;
int nedges;
int stateno;
int symbol;
int nwords;
nwords = ngotos * tokensetsize;
F = NEW2(nwords, unsigned);
reads = NEW2(ngotos, short *);
edge = NEW2(ngotos + 1, short);
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, short);
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;
short *rulep;
short *rp;
shifts *sp;
int length;
int nedges;
int isdone;
int state1;
int stateno;
int symbol1;
int symbol2;
short *shortp;
short *edge;
short *states;
short **new_includes;
includes = NEW2(ngotos, short *);
edge = NEW2(ngotos + 1, short);
states = NEW2(maxrhs + 1, short);
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--;
isdone = 0;
while (!isdone)
{
isdone = 1;
rp--;
if (ISVAR(*rp))
{
stateno = states[--length];
edge[nedges++] = map_goto(stateno, *rp);
if (nullable[*rp] && length > 0) isdone = 0;
}
}
}
if (nedges)
{
includes[i] = shortp = NEW2(nedges + 1, short);
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 = gotono;
lookback[i] = sp;
}
static short **
transpose(short **tR, int n)
{
short **new_R;
short **temp_R;
short *nedges;
short *sp;
int i;
int k;
nedges = NEW2(n, short);
for (i = 0; i < n; i++)
{
sp = tR[i];
if (sp)
{
while (*sp >= 0)
nedges[*sp++]++;
}
}
new_R = NEW2(n, short *);
temp_R = NEW2(n, short *);
for (i = 0; i < n; i++)
{
k = nedges[i];
if (k > 0)
{
sp = NEW2(k + 1, short);
new_R[i] = sp;
temp_R[i] = sp;
sp[k] = -1;
}
}
FREE(nedges);
for (i = 0; i < n; i++)
{
sp = tR[i];
if (sp)
{
while (*sp >= 0)
*temp_R[*sp++]++ = 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(short **relation)
{
int i;
infinity = ngotos + 2;
INDEX = NEW2(ngotos + 1, short);
VERTICES = NEW2(ngotos + 1, short);
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;
short *rp;
int height;
unsigned *base;
VERTICES[++top] = 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++;
}
}
}

View file

@ -1,484 +0,0 @@
/* $NetBSD: main.c,v 1.21 2009/04/14 09:41:30 lukem Exp $ */
/*
* Copyright (c) 1989 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Robert Paul Corbett.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
#include <sys/cdefs.h>
#if defined(__COPYRIGHT) && !defined(lint)
__COPYRIGHT("@(#) Copyright (c) 1989\
The Regents of the University of California. All rights reserved.");
#endif /* not lint */
#if defined(__RCSID) && !defined(lint)
#if 0
static char sccsid[] = "@(#)main.c 5.5 (Berkeley) 5/24/93";
#else
__RCSID("$NetBSD: main.c,v 1.21 2009/04/14 09:41:30 lukem Exp $");
#endif
#endif /* not lint */
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include "defs.h"
char dflag;
char lflag;
char rflag;
char tflag;
char vflag;
const char *symbol_prefix;
const char *myname = "yacc";
int lineno;
int outline;
char *action_file_name;
char *code_file_name;
char *defines_file_name;
const char *input_file_name = "";
char *output_file_name;
char *text_file_name;
char *union_file_name;
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 *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 */
int nitems;
int nrules;
int nsyms;
int ntokens;
int nvars;
int start_symbol;
char **symbol_name;
short *symbol_value;
short *symbol_prec;
char *symbol_assoc;
short *ritem;
short *rlhs;
short *rrhs;
short *rprec;
char *rassoc;
short **derives;
char *nullable;
static const char *file_prefix = "y";
static const char *temp_form = "yacc.XXXXXXX";
static int explicit_file_name;
static __dead void onintr(int);
static void set_signals(void);
static __dead void usage(void);
static void getargs(int, char *[]);
static void create_file_names(void);
static void open_files(void);
/* coverity[+kill] */
__dead void
done(int k)
{
if (action_file) { fclose(action_file); unlink(action_file_name); }
if (text_file) { fclose(text_file); unlink(text_file_name); }
if (union_file) { fclose(union_file); unlink(union_file_name); }
exit(k);
}
static void
onintr(int signo)
{
done(1);
}
static void
set_signals()
{
#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)
{
fprintf(stderr, "usage: %s [-dlrtv] [-b file_prefix] [-o outputfile] "
"[-p symbol_prefix] filename\n", myname);
exit(1);
}
static void
getargs(int argc, char *argv[])
{
int i;
char *s;
if (argc > 0) myname = argv[0];
for (i = 1; i < argc; ++i)
{
s = argv[i];
if (*s != '-') break;
switch (*++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 'd':
dflag = 1;
break;
case 'l':
lflag = 1;
break;
case 'o':
if (*++s)
output_file_name = s;
else if (++i < argc)
output_file_name = argv[i];
else
usage();
explicit_file_name = 1;
continue;
case 'p':
if (*++s)
symbol_prefix = s;
else if (++i < argc)
symbol_prefix = argv[i];
else
usage();
continue;
case 'r':
rflag = 1;
break;
case 't':
tflag = 1;
break;
case 'v':
vflag = 1;
break;
default:
usage();
}
for (;;)
{
switch (*++s)
{
case '\0':
goto end_of_option;
case 'd':
dflag = 1;
break;
case 'l':
lflag = 1;
break;
case 'r':
rflag = 1;
break;
case 't':
tflag = 1;
break;
case 'v':
vflag = 1;
break;
default:
usage();
}
}
end_of_option:;
}
no_more_options:;
if (i + 1 != argc) usage();
input_file_name = argv[i];
}
char *
allocate(unsigned n)
{
char *p;
p = NULL;
if (n)
{
p = CALLOC(1, n);
if (!p) no_space();
}
return (p);
}
static void
create_file_names(void)
{
int i, len;
const char *tmpdir;
tmpdir = getenv("TMPDIR");
if (tmpdir == 0) tmpdir = "/tmp";
len = strlen(tmpdir);
i = len + 13;
if (len && tmpdir[len-1] != '/')
++i;
action_file_name = MALLOC(i);
if (action_file_name == 0) no_space();
text_file_name = MALLOC(i);
if (text_file_name == 0) no_space();
union_file_name = MALLOC(i);
if (union_file_name == 0) no_space();
strlcpy(action_file_name, tmpdir, i);
strlcpy(text_file_name, tmpdir, i);
strlcpy(union_file_name, tmpdir, i);
if (len && tmpdir[len - 1] != '/')
{
action_file_name[len] = '/';
text_file_name[len] = '/';
union_file_name[len] = '/';
++len;
}
strlcpy(action_file_name + len, temp_form, i - len);
strlcpy(text_file_name + len, temp_form, i - len);
strlcpy(union_file_name + len, temp_form, i - len);
action_file_name[len + 5] = 'a';
text_file_name[len + 5] = 't';
union_file_name[len + 5] = 'u';
len = strlen(file_prefix);
if (!output_file_name)
{
output_file_name = MALLOC(strlen(file_prefix) + strlen(OUTPUT_SUFFIX)
+ 1);
if (output_file_name == 0)
no_space();
sprintf(output_file_name, "%s%s", file_prefix, OUTPUT_SUFFIX);
}
if (rflag)
{
code_file_name = MALLOC(strlen(file_prefix) + strlen(CODE_SUFFIX)
+ 1);
if (code_file_name == 0)
no_space();
sprintf(code_file_name, "%s%s", file_prefix, CODE_SUFFIX);
}
else
code_file_name = output_file_name;
if (dflag)
{
if (explicit_file_name)
{
char *suffix;
defines_file_name = strdup(output_file_name);
if (defines_file_name == 0)
no_space();
/* does the output_file_name have a known suffix */
suffix = strrchr(output_file_name, '.');
if (suffix != 0 &&
(!strcmp(suffix, ".c") || /* good, old-fashioned C */
!strcmp(suffix, ".C") || /* C++, or C on Windows */
!strcmp(suffix, ".cc") || /* C++ */
!strcmp(suffix, ".cxx") || /* C++ */
!strcmp(suffix, ".cpp"))) /* C++ (Windows) */
{
strncpy(defines_file_name, output_file_name,
suffix - output_file_name + 1);
defines_file_name[suffix - output_file_name + 1] = 'h';
defines_file_name[suffix - output_file_name + 2] = 0;
} else {
fprintf(stderr,"%s: suffix of output file name %s"
" not recognized, no -d file generated.\n",
myname, output_file_name);
dflag = 0;
free(defines_file_name);
defines_file_name = 0;
}
}
else
{
defines_file_name = MALLOC(strlen(file_prefix) + strlen(DEFINES_SUFFIX)
+ 1);
if (defines_file_name == 0)
no_space();
sprintf(defines_file_name, "%s%s", file_prefix, DEFINES_SUFFIX);
}
}
if (vflag)
{
verbose_file_name = MALLOC(strlen(file_prefix) + strlen(VERBOSE_SUFFIX)
+ 1);
if (verbose_file_name == 0)
no_space();
sprintf(verbose_file_name, "%s%s", file_prefix, VERBOSE_SUFFIX);
}
}
static void
open_files(void)
{
int fd;
create_file_names();
if (input_file == 0)
{
input_file = fopen(input_file_name, "r");
if (input_file == 0)
open_error(input_file_name);
}
if (((fd = mkstemp(action_file_name)) == -1) ||
(action_file = fdopen(fd, "w")) == NULL)
open_error(action_file_name);
if (((fd = mkstemp(text_file_name)) == -1) ||
(text_file = fdopen(fd, "w")) == NULL)
open_error(text_file_name);
if (vflag)
{
verbose_file = fopen(verbose_file_name, "w");
if (verbose_file == 0)
open_error(verbose_file_name);
}
if (dflag)
{
defines_file = fopen(defines_file_name, "w");
if (defines_file == 0)
open_error(defines_file_name);
if (((fd = mkstemp(union_file_name)) == -1) ||
(union_file = fdopen(fd, "w")) == NULL)
open_error(union_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[])
{
set_signals();
getargs(argc, argv);
open_files();
reader();
lr0();
lalr();
make_parser();
verbose();
output();
done(0);
/*NOTREACHED*/
return 0;
}

File diff suppressed because it is too large Load diff

View file

@ -1,161 +0,0 @@
/* $NetBSD: symtab.c,v 1.12 2009/04/14 09:41:31 lukem Exp $ */
/*
* Copyright (c) 1989 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Robert Paul Corbett.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
#if 0
static char sccsid[] = "@(#)symtab.c 5.3 (Berkeley) 6/1/90";
#else
__RCSID("$NetBSD: symtab.c,v 1.12 2009/04/14 09:41:31 lukem Exp $");
#endif
#endif /* not lint */
#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
bucket *first_symbol;
bucket *last_symbol;
static bucket **symbol_table;
static int hash(const char *);
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);
bp = (bucket *) MALLOC(sizeof(bucket));
if (bp == 0) no_space();
bp->link = 0;
bp->next = 0;
bp->name = strdup(name);
if (bp->name == 0) no_space();
bp->tag = 0;
bp->value = UNDEFINED;
bp->index = 0;
bp->prec = 0;
bp-> class = UNKNOWN;
bp->assoc = TOKEN;
return (bp);
}
bucket *
lookup(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 *));
if (symbol_table == 0) no_space();
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);
}
}

View file

@ -1,276 +0,0 @@
#ifndef lint
/*static char yysccsid[] = "from: @(#)yaccpar 1.9 (Berkeley) 02/21/93";*/
static char rcsid[] = "$NetBSD: error.tab.c,v 1.4 1997/01/09 20:23:30 tls Exp $";
#endif
#define YYBYACC 1
#define YYMAJOR 1
#define YYMINOR 9
#define yyclearin (yychar=(-1))
#define yyerrok (yyerrflag=0)
#define YYRECOVERING (yyerrflag!=0)
#define YYPREFIX "yy"
#define YYERRCODE 256
short yylhs[] = { -1,
0,
};
short yylen[] = { 2,
1,
};
short yydefred[] = { 0,
1, 0,
};
short yydgoto[] = { 2,
};
short yysindex[] = { -256,
0, 0,
};
short yyrindex[] = { 0,
0, 0,
};
short yygindex[] = { 0,
};
#define YYTABLESIZE 0
short yytable[] = { 1,
};
short yycheck[] = { 256,
};
#define YYFINAL 2
#ifndef YYDEBUG
#define YYDEBUG 0
#endif
#define YYMAXTOKEN 0
#if YYDEBUG
char *yyname[] = {
"end-of-file",
};
char *yyrule[] = {
"$accept : S",
"S : error",
};
#endif
#ifndef YYSTYPE
typedef int YYSTYPE;
#endif
#ifdef YYSTACKSIZE
#undef YYMAXDEPTH
#define YYMAXDEPTH YYSTACKSIZE
#else
#ifdef YYMAXDEPTH
#define YYSTACKSIZE YYMAXDEPTH
#else
#define YYSTACKSIZE 500
#define YYMAXDEPTH 500
#endif
#endif
int yydebug;
int yynerrs;
int yyerrflag;
int yychar;
short *yyssp;
YYSTYPE *yyvsp;
YYSTYPE yyval;
YYSTYPE yylval;
short yyss[YYSTACKSIZE];
YYSTYPE yyvs[YYSTACKSIZE];
#define yystacksize YYSTACKSIZE
#line 4 "error.y"
main(){printf("yyparse() = %d\n",yyparse());}
yylex(){return-1;}
yyerror(s)char*s;{printf("%s\n",s);}
#line 80 "error.tab.c"
#define YYABORT goto yyabort
#define YYREJECT goto yyabort
#define YYACCEPT goto yyaccept
#define YYERROR goto yyerrlab
int
yyparse()
{
register int yym, yyn, yystate;
#if YYDEBUG
register char *yys;
extern char *getenv();
if (yys = getenv("YYDEBUG"))
{
yyn = *yys;
if (yyn >= '0' && yyn <= '9')
yydebug = yyn - '0';
}
#endif
yynerrs = 0;
yyerrflag = 0;
yychar = (-1);
yyssp = yyss;
yyvsp = yyvs;
*yyssp = yystate = 0;
yyloop:
if (yyn = yydefred[yystate]) 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 (yyssp >= yyss + yystacksize - 1)
{
goto yyoverflow;
}
*++yyssp = yystate = yytable[yyn];
*++yyvsp = yylval;
yychar = (-1);
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;
#ifdef lint
goto yynewerror;
#endif
yynewerror:
yyerror("syntax error");
#ifdef lint
goto yyerrlab;
#endif
yyerrlab:
++yynerrs;
yyinrecovery:
if (yyerrflag < 3)
{
yyerrflag = 3;
for (;;)
{
if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
{
#if YYDEBUG
if (yydebug)
printf("%sdebug: state %d, error recovery shifting\
to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
#endif
if (yyssp >= yyss + yystacksize - 1)
{
goto yyoverflow;
}
*++yyssp = yystate = yytable[yyn];
*++yyvsp = yylval;
goto yyloop;
}
else
{
#if YYDEBUG
if (yydebug)
printf("%sdebug: error recovery discarding state %d\n",
YYPREFIX, *yyssp);
#endif
if (yyssp <= yyss) goto yyabort;
--yyssp;
--yyvsp;
}
}
}
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 = (-1);
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];
yyval = yyvsp[1-yym];
switch (yyn)
{
}
yyssp -= yym;
yystate = *yyssp;
yyvsp -= 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;
*++yyssp = YYFINAL;
*++yyvsp = 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, *yyssp, yystate);
#endif
if (yyssp >= yyss + yystacksize - 1)
{
goto yyoverflow;
}
*++yyssp = yystate;
*++yyvsp = yyval;
goto yyloop;
yyoverflow:
yyerror("yacc stack overflow");
yyabort:
return (1);
yyaccept:
return (0);
}

View file

@ -1,2 +0,0 @@
/* $NetBSD: error.tab.h,v 1.2 1998/01/09 08:08:55 perry Exp $ */

View file

@ -1,6 +0,0 @@
%%
S: error
%%
main(){printf("yyparse() = %d\n",yyparse());}
yylex(){return-1;}
yyerror(s)char*s;{printf("%s\n",s);}

View file

@ -1,125 +0,0 @@
/* $NetBSD: warshall.c,v 1.8 2006/05/24 18:01:43 christos Exp $ */
/*
* Copyright (c) 1989 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Robert Paul Corbett.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
#if 0
static char sccsid[] = "@(#)warshall.c 5.4 (Berkeley) 5/24/93";
#else
__RCSID("$NetBSD: warshall.c,v 1.8 2006/05/24 18:01:43 christos Exp $");
#endif
#endif /* not lint */
#include "defs.h"
static void transitive_closure(unsigned *, int);
static void
transitive_closure(unsigned *R, int n)
{
int rowsize;
unsigned i;
unsigned *rowj;
unsigned *rp;
unsigned *rend;
unsigned *ccol;
unsigned *relend;
unsigned *cword;
unsigned *rowi;
rowsize = WORDSIZE(n);
relend = R + n*rowsize;
cword = R;
i = 0;
rowi = R;
while (rowi < relend)
{
ccol = cword;
rowj = R;
while (rowj < relend)
{
if (*ccol & (1 << i))
{
rp = rowi;
rend = rowj + rowsize;
while (rowj < rend)
*rowj++ |= *rp++;
}
else
{
rowj += rowsize;
}
ccol += rowsize;
}
if (++i >= BITS_PER_WORD)
{
i = 0;
cword++;
}
rowi += rowsize;
}
}
void
reflexive_transitive_closure(unsigned *R, int n)
{
int rowsize;
unsigned i;
unsigned *rp;
unsigned *relend;
transitive_closure(R, n);
rowsize = WORDSIZE(n);
relend = R + n*rowsize;
i = 0;
rp = R;
while (rp < relend)
{
*rp |= (1 << i);
if (++i >= BITS_PER_WORD)
{
i = 0;
rp++;
}
rp += rowsize;
}
}

View file

@ -1,3 +1,3 @@
.include <bsd.own.mk>
SUBDIR=mdocml file
SUBDIR=byacc file mdocml
.include <bsd.subdir.mk>

5
external/bsd/byacc/Makefile vendored Normal file
View file

@ -0,0 +1,5 @@
# $NetBSD: Makefile,v 1.1 2009/10/29 00:56:35 christos Exp $
SUBDIR= bin
.include <bsd.subdir.mk>

14
external/bsd/byacc/Makefile.inc vendored Normal file
View file

@ -0,0 +1,14 @@
# $NetBSD: Makefile.inc,v 1.2 2011/09/16 16:41:20 joerg Exp $
WARNS=4
.include <bsd.own.mk>
BINDIR?= /usr/bin
IDIST= ${NETBSDSRCDIR}/external/bsd/byacc/dist
CPPFLAGS+= -DHAVE_CONFIG_H -I${.CURDIR}/../include -I${IDIST}
CWARNFLAGS+= -Wno-missing-noreturn
.PATH: ${IDIST}

14
external/bsd/byacc/bin/Makefile vendored Normal file
View file

@ -0,0 +1,14 @@
# $NetBSD: Makefile,v 1.3 2011/08/14 13:29:26 christos Exp $
.include "bsd.own.mk"
PROG= 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 graph.c
CPPFLAGS+= -DGCC_NORETURN=__dead
COPTS.output.c += -Wno-format-nonliteral
COPTS.reader.c += -Wno-format-nonliteral
.include <bsd.prog.mk>

View file

@ -1,4 +1,4 @@
.\" $NetBSD: yacc.1,v 1.13 2003/08/07 11:17:55 agc Exp $
.\" $NetBSD: yacc.1,v 1.4 2011/09/10 21:38:59 christos Exp $
.\"
.\" Copyright (c) 1989, 1990 The Regents of the University of California.
.\" All rights reserved.
@ -31,9 +31,10 @@
.\" SUCH DAMAGE.
.\"
.\" from: @(#)yacc.1 5.7 (Berkeley) 7/30/91
.\" $NetBSD: yacc.1,v 1.13 2003/08/07 11:17:55 agc Exp $
.\" from: Id: yacc.1,v 1.12 2011/09/08 00:40:44 tom Exp
.\" $NetBSD: yacc.1,v 1.4 2011/09/10 21:38:59 christos Exp $
.\"
.Dd July 30, 1991
.Dd September 7, 2011
.Dt YACC 1
.Os
.Sh NAME
@ -43,7 +44,7 @@
parser generator
.Sh SYNOPSIS
.Nm
.Op Fl dlrtv
.Op Fl dgilPrtVv
.Op Fl b Ar prefix
.Op Fl o Ar outputfile
.Op Fl p Ar symbol_prefix
@ -53,7 +54,7 @@ parser generator
reads the grammar specification in the file
.Ar filename
and generates an
.Tn LR(1)
.Tn LALR(1)
parser for it.
The parsers consist of a set of
.Tn LALR(1)
@ -79,6 +80,36 @@ The
option causes the header file
.Pa y.tab.h
to be written.
It contains #define's for the token identifiers.
.It Fl g
The
.Fl g
option causes a graphical description of the generated
.Tn LALR(1)
parser to be written to the file
.Pa y.dot
in graphviz format, ready to be processed by
.Xr dot 1 .
.It Fl i
The
.Fl i
option causes a supplementary header file
.Pa y.tab.i
to be written.
It contains extern declarations
and supplementary #define's as needed to map the conventional
.Nm
yy-prefixed names to whatever the
.Fl p
option may specify.
The code file, e.g.,
.Pa y.tab.c
is modified to #include this file
as well as the
.Pa y.tab.h
file, enforcing consistent usage of the symbols defined in those files.
The supplementary header file makes it simpler to separate compilation
of lex- and yacc-files.
.It Fl l
If the
.Fl l
@ -98,6 +129,14 @@ The
.Fl o
option specifies an explicit output file name should be used instead
of the default.
.It Fl P
The
.Fl P
options instructs
.Nm
to create a reentrant parser, like
.Dq %pure-parser
does.
.It Fl p Ar symbol_prefix
The
.Fl p
@ -122,6 +161,10 @@ The
option changes the preprocessor directives generated by
.Nm
so that debugging statements will be incorporated in the compiled code.
.It Fl V
The
.Fl V
option prints the version number to the standard output.
.It Fl v
The
.Fl v
@ -129,6 +172,47 @@ option causes a human-readable description of the generated parser to
be written to the file
.Pa y.output .
.El
.Sh EXTENSIONS
.Nm
provides some extensions for compatibility with
.Xr bison 1
and other implementations
of
.Nm :
.Pp
.Bl -tag -width "%expect-rr number" -compact
.It Dv %expect Ar number
Tell
.Nm
the expected number of shift/reduce conflicts.
That makes it only report the number if it differs.
.It Dv %expect-rr Ar number
Tell
.Nm
the expected number of reduce/reduce conflicts.
That makes it only report the number if it differs.
This is (unlike
.Xr bison 1 )
allowable in
.Tn LALR(1)
parsers.
.It Dv %lex-param Ar { Ar argument-declaration Ar }
By default, the lexer accepts no parameters, e.g.,
.Fn yylex .
Use this directive to add parameter declarations for your customized lexer.
.It Dv %parse-param Ar { Ar argument-declaration Ar }
By default, the parser accepts no parameters, e.g.,
.Fn yyparse .
Use this directive to add parameter declarations for your customized parser.
.It Dv %pure-parser
Most variables (other than
.Fa yydebug
and
.Fa yynerrs )
are allocated on the stack within
.Fn yyparse ,
making the parser reasonably reentrant.
.El
.Sh ENVIRONMENT
The following environment variable is referenced by
.Nm :

125
external/bsd/byacc/byacc2netbsd vendored Executable file
View file

@ -0,0 +1,125 @@
#! /bin/sh
#
# $NetBSD: byacc2netbsd,v 1.4 2011/10/08 19:28:39 christos Exp $
#
# Copyright (c) 2000 The NetBSD Foundation, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# byacc2netbsd: convert a byacc tree into a
# netbsd byacc source tree, under src/external/bsd/byacc/dist,
# based on byacc2netbsd by Bernd Ernesti and changes by Simon Burge
#
# Rough instructions for importing new byacc release:
#
# $ cd /some/where/temporary
# $ tar xpfz /new/byacc/release/tar/file
# $ sh /usr/src/external/bsd/byacc/dist/byacc2netbsd byacc-YYYYMMDD `pwd`
# $ cd src/external/bsd/byacc/dist
# $ cvs import -m "Import byacc YYYYMMDD" src/external/bsd/byacc/dist DICKEY byacc-YYYYMMDD
# $ cd ../../../../../byacc-YYYYMMDD
# $ run ./configure
# $ run make
# check the config file and copy it to /usr/src/external/bsd/byacc/include
# remove the version from SYSTEM_NAME
# check the manual page against our copy if there are new options and
# update
if [ $# -ne 2 ]; then echo "byacc2netbsd src dest"; exit 1; fi
r=$1
d=$2/src/external/bsd/byacc/dist
case "$d" in
/*)
;;
*)
d=`/bin/pwd`/$d
;;
esac
case "$r" in
/*)
;;
*)
r=`/bin/pwd`/$r
;;
esac
echo preparing directory $d
rm -rf $d
mkdir -p $d
### Copy the files and directories
echo copying $r to $d
cd $r
pax -rw * $d
### Remove the $'s around RCS tags
cleantags $d
### Add our NetBSD RCS Id
find $d -type f -name '*.[chly]' -print | while read c; do
sed 1q < $c | grep -q '\$NetBSD' || (
echo "/* \$NetBSD\$ */" >/tmp/byacc3n$$
echo "" >>/tmp/byacc3n$$
cat $c >> /tmp/byacc3n$$
mv /tmp/byacc3n$$ $c && echo added NetBSD RCS tag to $c
)
done
find $d -type f -name '*.[0-9]' -print | while read m; do
sed 1q < $m | grep -q '\$NetBSD' || (
echo ".\\\" \$NetBSD\$" >/tmp/byacc2m$$
echo ".\\\"" >>/tmp/byacc2m$$
cat $m >> /tmp/byacc2m$$
mv /tmp/byacc2m$$ $m && echo added NetBSD RCS tag to $m
)
done
find $d -type f -name '*.texi' -print | while read t; do
sed "2 s/^/@c \$NetBSD\$\\
/" < $t > /tmp/byacc4t$$
mv /tmp/byacc4t$$ $t && echo added NetBSD RCS tag to $t
done
echo done
### Clean up any CVS directories that might be around.
echo "cleaning up CVS residue."
(
cd $d
find . -type d -name "CVS" -print | xargs rm -r
)
echo done
### Fixing file and directory permissions.
echo "Fixing file/directory permissions."
(
cd $d
find . -type f -print | xargs chmod u+rw,go+r
find . -type d -print | xargs chmod u+rwx,go+rx
)
echo done
exit 0

7
external/bsd/byacc/dist/AUTHORS vendored Normal file
View 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

996
external/bsd/byacc/dist/CHANGES vendored Normal file
View file

@ -0,0 +1,996 @@
2011-09-08 Thomas E. Dickey <tom@invisible-island.net>
* package/debian/changelog, package/byacc.spec, VERSION: bump
* output.c:
fix some more interaction between -i and -d flags to ensure YYERRCODE
and YYSTYPE are declared, tested with cproto.
2011-09-07 Thomas E. Dickey <tom@invisible-island.net>
* yacc.1: document "-i" option.
* package/debian/changelog, package/byacc.spec, VERSION: bump
* output.c: fix an interaction between -i and -d
* test/code_error.code.c, test/error.tab.c, test/ftp.tab.c, test/grammar.tab.c, test/pure_calc.tab.c, test/pure_error.tab.c, test/calc.tab.c, test/calc1.tab.c, test/calc2.tab.c, test/calc3.tab.c, test/code_calc.code.c:
regen - changes for "-i" option move the global/impure variables near the
macros that may add a prefix, etc.
* skeleton.c, output.c, defs.h: changes to support "-i" option.
2011-09-06 Thomas E. Dickey <tom@invisible-island.net>
* reader.c: pass explicit file-pointer to write_section()
* main.c:
add "-i" option, to generate interface-file (suggested by Denis M. Wilson)
2011-09-05 Thomas E. Dickey <tom@invisible-island.net>
* configure: regen
* aclocal.m4:
resync with my-autoconf: CF_ANSI_CC_CHECK (check for $CFLAGS in $CC)
and CF_XOPEN_SOURCE (update aix, cygwin and netbsd checks)
* defs.h, error.c, reader.c:
add check for missing "}" on %parse-param and %lex-param lines (report by Denis M Wilson)
2011-04-01 Thomas E. Dickey <tom@invisible-island.net>
* config.sub: 2011-04-01
2011-02-02 Thomas E. Dickey <tom@invisible-island.net>
* config.guess: 2011-01-01
2010-12-29 Thomas E. Dickey <tom@invisible-island.net>
* defs.h, skeleton.c:
add const qualifier to skeleton data, per NetBSD changes (report by Christos Zoulas)
* defs.h:
mark all of the error-functions as non-returning (report by Christos Zoulas)
* test/grammar.tab.c, test/pure_calc.tab.c, test/pure_error.tab.c, test/calc.tab.c, test/calc1.tab.c, test/calc2.tab.c, test/calc3.tab.c, test/code_calc.code.c, test/code_error.code.c, test/error.tab.c, test/ftp.tab.c:
regen
* skeleton.c:
use only realloc() rather than realloc+malloc, agree that systems needing this
are very rare (prompted by NetBSD change).
* test/ftp.tab.c: regen
2010-12-29 Christos.Zoulas
* test/ftp.y:
improve example, which was stuck in 19XX and assumed file sizes were longs.
2010-12-29 Thomas E. Dickey <tom@invisible-island.net>
* test/ftp.tab.c, test/grammar.tab.c, test/pure_calc.tab.c, test/pure_error.tab.c, test/calc.tab.c, test/calc1.tab.c, test/calc2.tab.c, test/calc3.tab.c, test/code_calc.code.c, test/code_error.code.c, test/error.tab.c:
regen
* test/pure_error.y, test/pure_calc.y, test/ftp.y, test/error.y, test/code_error.y, test/code_calc.y, test/calc.y, test/calc3.y, test/calc2.y, test/calc1.y:
use byacc's YYLEX_DECL/YYERROR_DECL symbols to prototype yylex/yyerror
* skeleton.c:
remove explicit prototype for yylex() via YYLEX_DECL() macro, since that
would prevent declaring yylex() static (request by Christos Zoulas).
* test/calc2.tab.c, test/calc3.tab.c: regen
2010-12-29 Christos.Zoulas
* output.c: correct definition for YYERROR_DECL()
2010-12-29 Thomas E. Dickey <tom@invisible-island.net>
* package/debian/changelog, package/byacc.spec, VERSION: bump
2010-12-26 Thomas E. Dickey <tom@invisible-island.net>
* defs.h, main.c:
change return-type of allocate() to avoid warnings of alignment problems
* main.c: Solaris declares chmod() in <sys/stat.h>
* configure: regen
* main.c: ifdef'd use of fcntl.h
* configure.in: add configure checks for fcntl.h, atexit and mkstemp
* main.c: for cases where mkstemp() is not available, use tempnam/open
* aclocal.m4: add CF_MKSTEMP
* aclocal.m4:
improve quoting, deprecate ${name-value} in favor of standard ${name:-value}
2010-12-25 Thomas E. Dickey <tom@invisible-island.net>
* main.c:
start revising use of tmpfile(), to make this work with MinGW. Start by
implementing a mkstemp() alternative - noting that mkstemp() also is broken
for MinGW.
* package/debian/changelog, package/byacc.spec, VERSION: bump
2010-11-27 Thomas E. Dickey <tom@invisible-island.net>
* package/byacc.spec, package/debian/changelog, VERSION: bump
* test/calc2.tab.c, test/calc3.tab.c: regen
* output.c:
corrected use of %parse-param value in yyerror(); it doesn't use &yylval
(report by Clifford Yapp)
2010-11-26 Thomas E. Dickey <tom@invisible-island.net>
* skeleton.c: typo
* output.c:
correct line-numbering when "-r" option is used; the 'outline' variable
should only be incremented when writing to the code-file.
* test/code_calc.code.c, test/code_error.code.c: regen
* yacc.1: bump date
* yacc.1: comment on -b option vs -r
* test/calc2.tab.c, test/calc2.y, test/calc3.tab.c, test/calc3.y, test/ftp.tab.c, test/grammar.tab.c, test/pure_calc.tab.c, test/pure_error.tab.c, test/calc.tab.c, test/calc1.tab.c, test/code_calc.code.c, test/code_error.code.c, test/error.tab.c:
regen
* output.c:
improve on YYERROR_DECL(), adding dummy params which can be used for the
actual function declaration. Also add YYERROR_CALL(). The two macros
simplify maintaining sets of grammars which may/may not be pure.
* test/calc1.y, test/ftp.tab.c, test/grammar.tab.c, test/pure_calc.tab.c, test/pure_error.tab.c, test/calc.tab.c, test/calc1.tab.c, test/calc2.tab.c, test/calc3.tab.c, test/code_calc.code.c, test/code_error.code.c, test/error.tab.c:
regen
* output.c: generate yyerror() calls in output.c
This is for compatibility with bison, which passes the yylval to yyerror
when the %parse-param feature is used.
* skeleton.c, defs.h: generate yyerror() calls in output.c
* output.c: simplified a little, using putc_code() and putl_code()
* test/calc1.tab.h: regen
* reader.c:
improve ifdef for YYSTYPE union declaration (report by Clifford Yapp)
* reader.c:
accept underscore as a replacement for dash in command names, e.g.,
"%pure_parser" vs "%pure-parser".
* test/calc1.tab.c: regen
* output.c, reader.c:
also ifdef YYSTYPE declaration in the generated code (report by Clifford Yapp)
* package/debian/changelog, package/byacc.spec, VERSION: bump
2010-11-24 Thomas E. Dickey <tom@invisible-island.net>
* main.c, defs.h, symtab.c, error.c: reduce global variables
* package/debian/changelog, package/byacc.spec, VERSION: bump
* reader.c:
amend fix for Redhat #112617 to still call default_action_warning() for
empty rules (report by Bruce Cran).
2010-11-22 Thomas E. Dickey <tom@invisible-island.net>
* output.c:
add ifdef to guard against redefinition of YYSTYPE union (request by Clifford Yapp).
* test/calc1.tab.c: regen
* test/calc1.y: cleanup compiler warnings
* test/grammar.y: add "%expect"
* test/calc1.tab.h: regen
* test/calc1.output, test/calc1.tab.c, test/calc1.tab.h: RCS_BASE
* test/calc2.tab.c, test/calc3.tab.c: regen
* test/calc1.y:
advanced example from Steve Johnson's paper, uses unions
* test/calc3.y, test/calc2.y: init 'base', so examples can run
* test/ftp.tab.c, test/ftp.y: tweaks to compile with g++
* output.c: compensate for fix in reader.c
* reader.c:
add/use putc_both() and puts_both(), incidentally fixing a place where
a union copied to the union_file may be missing the end of the last line.
* package/debian/changelog, package/byacc.spec, VERSION: bump
2010-09-28 Thomas E. Dickey <tom@invisible-island.net>
* config.guess: 2010-09-24
2010-09-10 Thomas E. Dickey <tom@invisible-island.net>
* config.sub: 2010-09-11
2010-06-10 Thomas E. Dickey <tom@invisible-island.net>
* yacc.1, package/debian/changelog, package/byacc.spec, VERSION:
bump to 2010/06/10
2010-06-09 Thomas E. Dickey <tom@invisible-island.net>
* reader.c: free declarations in leak-testing code.
* main.c: close code_file if -r option used, for leak-testing
* defs.h, reader.c:
improve %lex-param / %parse-param implementation by allowing for arrays to
be passed as parameters, e.g., "int regs[26]".
* test/calc3.tab.c, test/calc3.y, test/calc3.output, test/calc3.tab.h, test/calc2.tab.c, test/calc2.y, test/calc2.tab.h, test/calc2.output:
RCS_BASE
* output.c:
improve %lex-param / %parse-param implementation by allowing for arrays to
be passed as parameters, e.g., "int regs[26]".
* test/calc.tab.c, test/calc.y:
test-cases and reference files for %lex-param / %parse-param
* makefile.in: add docs-rule, for html/pdf/txt form of manpage
* configure: regen
* aclocal.m4: add CF_XOPEN_SOURCE, etc.
* configure.in:
use CF_XOPEN_SOURCE check to ensure that strdup is in scope, e.g., for c89
* test/ftp.tab.c, test/ftp.y, reader.c, symtab.c, verbose.c, lr0.c, main.c, mkpar.c, output.c, defs.h, closure.c:
fix warnings from clang --analyze
2010-06-08 Thomas E. Dickey <tom@invisible-island.net>
* output.c: fix to build with c89, etc.
* reader.c: gcc warning
* test/ftp.tab.c, test/ftp.y, test/calc.tab.c, test/code_calc.code.c, test/code_error.code.c, test/code_error.y, test/code_calc.y, test/calc.y, test/pure_error.tab.c, test/error.tab.c, test/error.y, test/pure_error.y, test/pure_calc.tab.c, test/pure_calc.y:
modified test-cases to allow them to compile, to validate pure-parser changes.
updated reference files to match.
* output.c:
move call for output_stype() earlier since it is used in pure-parser declarations
* test/grammar.tab.c, test/grammar.y:
modified test-cases to allow them to compile, to validate pure-parser changes.
updated reference files to match.
* test/calc.tab.c, test/error.tab.c, test/ftp.tab.c, test/grammar.tab.c:
regen
* yacc.1: document %lex-param and %parse-param
* test/run_lint.sh, test/run_make.sh: RCS_BASE
* test/run_test.sh:
further modify to allow build-directory to be in a different location by
passing this directory's location as a parameter to the script.
* makefile.in:
add check_make and check_lint rules to help validate the generated files
in the test-directory
2010-06-07 Thomas E. Dickey <tom@invisible-island.net>
* test/pure_calc.tab.c, test/pure_error.tab.c: RCS_BASE
* test/run_test.sh:
provide for testing -r and -P options by checking if the ".y" filename
begins with "code_" or "pure_", respectively.
* test/code_error.code.c, test/code_error.tab.c, test/code_error.tab.h, test/code_calc.code.c, test/code_calc.tab.c, test/code_calc.tab.h, test/pure_calc.output, test/pure_calc.tab.h, test/pure_error.output, test/pure_error.tab.h, test/code_calc.output, test/code_error.output:
RCS_BASE
* test/error.tab.c, test/ftp.tab.c, test/grammar.tab.c: regen
* test/run_test.sh:
changes to support running "make check" in a separate build-tree
* main.c: add "-P" to usage message
* reader.c: use UCH() macro to hide casts.
2010-06-07 Andres.Mejia
* main.c, output.c, reader.c, defs.h, skeleton.c:
Fix the output order of the generated parse code file. This allows for
the use of YYPARSE_PARAM, by having the output that checks for
YYPARSE_PARAM to be defined come after the C code block in the
definitions section of a yacc file.
Implement support for YYLEX_PARAM, similar to bison. This is useful for
support for building reentrant lexers with flex.
Fix a compatibility issue with bison's pure-parser option. Bison
defines yylex as sending at least one parameter, &yylval, as the first
parameter and doesn't seem to have an easy way to remove that parameter.
This on the other hand is rather convenient to support saving to yylval
from flex when building reentrant lexers and parsers.
Add support for the %parse-param and %lex-param directives used in
bison. This change bears some similarity to NetBSD's changes to byacc
at http://www.mail-archive.com/source-changes-full@netbsd.org/msg08143.html
Bison allows for POSIX yacc emulation via a yacc directive in the yacc
file, and also via a command line switch. Implement this feature as a
no-op for byacc, since byacc is designed to be POSIX yacc compatible
anyway. This allows for better compatibility with yacc sources written
for bison.
2010-06-07 Thomas E. Dickey <tom@invisible-island.net>
* VERSION: bump to 2010/06/07
2010-06-06 Thomas E. Dickey <tom@invisible-island.net>
* test/calc.tab.c, configure: regen
* skeleton.c:
move #include's down into the generated code, to allow user-defined code
to override feature definitions, particularly with stdlib.h (request by
Marcus Kool).
* lr0.c, error.c, reader.c, defs.h:
strict gcc 3.4.6 warnings on 64-bit platform
* aclocal.m4, configure.in: add check for lint
* makefile.in: add lint rule
* defs.h, closure.c, lr0.c, warshall.c, main.c:
fix gcc warnings, mostly for 64-bit platform
* aclocal.m4:
add macros for checking ctags/etags, e.g., to work with NetBSD pkgsrc
* makefile.in: add etags/TAGS if available
* configure.in: add configure check for actual ctags and etags programs
* package/debian/copyright: add copyright notices for non-PD files
* package/debian/changelog:
incorporated scripts in upstream to use for test-builds
* makefile.in: drop mkdirs.sh, just use "mkdir -p"
* AUTHORS: nicknames for some contributors (see CHANGES for details)
* package/byacc.spec: RPM file for byacc
* VERSION: bump to 2010/06/06
* aclocal.m4: add copyright notice, from "my-autoconf" macros
http://invisible-island.net/autoconf/autoconf.html
* package/RCS, package/debian/RCS, package/debian/source/RCS, package/pkgsrc/RCS:
PERMIT FILE
* aclocal.m4: resync with my-autoconf. summary of changes:
a) CF_ADD_CFLAGS, etc., improve quoting of ifelse() parameter
b) CF_DISABLE_ECHO, change indent-convention for substituted makefile
c) CF_GCC_VERSION, ignore stderr
d) CF_GCC_WARNINGS, adjust options to work with c89 wrapper of gcc
2010-04-20 Thomas E. Dickey <tom@invisible-island.net>
* package/debian/changelog, package/debian/compat, package/debian/control, package/debian/copyright, package/debian/docs, package/debian/postinst, package/debian/prerm, package/debian/rules, package/debian/watch:
scripts from Debian package
2010-02-16 Thomas E. Dickey <tom@invisible-island.net>
* yacc.1: document -P and bison-extensions
* test/ftp.tab.c, test/grammar.tab.c, test/calc.tab.c, test/error.tab.c:
regen
* output.c: implement %pure-parser
* skeleton.c:
implement %pure-parser, like bison. To help with this, changed the stack
variables, putting them into a struct.
* reader.c: implement %pure-parser
* defs.h: modified skeleton to support %pure-parser feature
* main.c: add -P option to set %pure-parser
* output.c:
make -r and -p options work together. The -r option splits the generated
parser into code/table files; for this case we cannot use static data.
Also, we have to repeat the #define's used for prefix (-p) as well as the
redeclaration of yyparse(). Finally, allow any of the prefixed names to
be overridden, e.g., by passing a -D option to the compiler. Make that
a little more readable by putting a blank line before each chunk.
* defs.h: add definitions for %pure-parser
* skeleton.c:
put blank line before/after the redeclaration of yyparse()
* output.c: allow for other program redefining yylex()
* skeleton.c:
split-off xdecls[] array, to move declaration of yyparse() after #define's
* defs.h: split-out xdecls[]
* VERSION: bump
* configure: regen
* aclocal.m4: add CF_REMOVE_DEFINE, needed by CF_ADD_CFLAGS
* aclocal.m4:
resync with my-autoconf CF_ADD_CFLAGS and CF_DISABLE_ECHO changes.
2010-02-16 Ostap.Cherkashi
* skeleton.c: fix a memory leak in the generated skeleton
2010-01-01 Thomas E. Dickey <tom@invisible-island.net>
* package/debian/source/format: scripts from Debian package
2009-12-31 Thomas E. Dickey <tom@invisible-island.net>
* config.guess: 2009-12-30
* config.sub: 2009-12-31
2009-10-27 Thomas E. Dickey <tom@invisible-island.net>
* VERSION: 20091027
* output.c, mkpar.c, defs.h, lalr.c, closure.c, graph.c, lr0.c, verbose.c, main.c, reader.c:
strict compiler warnings
2009-10-26 Thomas E. Dickey <tom@invisible-island.net>
* test/ftp.tab.c, test/grammar.tab.c, test/calc.tab.c, test/error.tab.c:
resync
* main.c, defs.h: introduce some typedefs for portability, etc.
* makefile.in:
don't remove "*.log" in mostlyclean rule since it interferes with regression
script.
* configure: regen
* aclocal.m4: resync with my-autoconf
2009-08-25 Thomas E. Dickey <tom@invisible-island.net>
* config.guess, config.sub: 2009-08-19
2009-02-21 Thomas E. Dickey <tom@invisible-island.net>
* VERSION: bump
* output.c: restore "yylval" symbol, omitted in cleanup on 2008/8/25
2008-12-26 Thomas E. Dickey <tom@invisible-island.net>
* configure: regen with autoconf-2.52 (patched)
2008-12-25 Thomas E. Dickey <tom@invisible-island.net>
* test/error.tab.c, test/ftp.tab.c, test/grammar.tab.c, test/calc.tab.c:
regenerated
2008-12-24 Thomas E. Dickey <tom@invisible-island.net>
* VERSION: bump
* skeleton.c:
remove ifdef-lint from goto yyerrlab, to quiet gcc warning
2008-11-26 Thomas E. Dickey <tom@invisible-island.net>
* verbose.c, main.c, defs.h, mkpar.c, reader.c:
completed implementation of "%expect" (report by Perry E. Metzger).
add "%expect-rr", which is (unlike bison) allowable in LALR parsers.
2008-11-24 Thomas E. Dickey <tom@invisible-island.net>
* closure.c, defs.h, error.c, graph.c, lalr.c, lr0.c, main.c, mkpar.c, output.c, reader.c, skeleton.c, symtab.c, verbose.c, warshall.c:
change indent-style (request by Perry E. Metzger)
2008-08-27 Thomas E. Dickey <tom@invisible-island.net>
* test/calc.tab.c, test/error.tab.c, test/ftp.tab.c, test/grammar.tab.c:
better implementation of YYPARSE_PARAM, using YYPARSE_DECL() macro
* VERSION: bump
* skeleton.c:
better implementation of YYPARSE_PARAM, using YYPARSE_DECL() macro
* test/calc.tab.c, test/error.tab.c, test/ftp.tab.c, test/grammar.tab.c, skeleton.c:
change YYRECOVERING to YYRECOVERING(), for compatibility with other yacc's.
* configure: regen'd
* configure.in: add -Wwrite-strings to warnings
* test/ftp.tab.c, test/grammar.tab.c, test/calc.tab.c, test/error.tab.c:
add YYPARSE_PARAM and YYPARSE_PARAM_TYPE
* skeleton.c:
add YYPARSE_PARAM (bison) and YYPARSE_PARAM_TYPE (FreeBSD) features.
* main.c, defs.h, output.c, skeleton.c, symtab.c, error.c, reader.c:
fixes for gcc -Wwrite-strings
* test/calc.tab.c, test/error.tab.c, test/ftp.tab.c, test/grammar.tab.c:
generate the tables as static-const (this is an interface change)
* output.c: realign columns in start_table()
* output.c:
generate the tables as static-const (this is an interface change)
* output.c: reorder functions to eliminate forward-references
* test/calc.tab.c, test/error.tab.c, test/ftp.tab.c, test/grammar.tab.c:
remove 'register' keywords
2008-08-26 Thomas E. Dickey <tom@invisible-island.net>
* warshall.c, verbose.c, symtab.c, skeleton.c, reader.c, output.c, mkpar.c, main.c, lr0.c, lalr.c, graph.c, error.c, closure.c:
remove 'register' keywords
2008-08-25 Thomas E. Dickey <tom@invisible-island.net>
* test/ftp.tab.c: regen'd
* reader.c:
improve the left-curly fix by testing after blanks, to avoid having a
" {" at the beginning of a line.
* test/error.tab.c, test/grammar.tab.c: regen'd
* output.c:
move the remaining newline-counting into write_XXX functions.
* test/calc.tab.c: regen'd
* output.c:
simplify part of the output_file formatting using new functions, e.g.,
start_int_table(), output_newline().
* reader.c:
modify copy_action() to indent the first character, it if is is left-curly
brace. That makes the output look more like the original, as well as makes
it simpler to edit (not confuse editors which look for a left-curly in the
first column as if it were the beginning of a function).
* skeleton.c: minor fixes to avoid gcc -Wconversion warnings
* output.c: align the #define's produced for "-p" option
* test/run_test.sh: use the "-p" option for better coverage.
* output.c: simplify output_prefix() with new define_prefixed()
* skeleton.c: include string.h, for memset()
change stack size to unsigned to fix gcc -Wconversion warnings.
* VERSION: bump to 2008/8/25
* makefile.in: add dependency on VERSION file.
2008-08-24 Thomas E. Dickey <tom@invisible-island.net>
* VERSION: bump
* lalr.c: improved memory-leak checking by freeing data in includes[]
* test/error.tab.c, test/ftp.tab.c, test/grammar.tab.c, test/calc.tab.c:
update to match skeleton-change
* configure: regen'd
* skeleton.c: Add fix for stack discussed
http://undeadly.org/cgi?action=article&sid=20080708155228
and applied
http://www.openbsd.org/cgi-bin/cvsweb/src/usr.bin/yacc/skeleton.c.diff?r1=1.28&r2=1.29
* aclocal.m4: resync with my-autoconf (no major changes)
2008-07-24 Thomas E. Dickey <tom@invisible-island.net>
* package/pkgsrc/Makefile, package/pkgsrc/distinfo:
scripts from NetBSD pkgsrc, for test-builds
2008-03-14 Thomas E. Dickey <tom@invisible-island.net>
* config.sub: update to 2008-03-08
* config.guess: update to 2008-03-12
2007-05-09 Thomas E. Dickey <tom@invisible-island.net>
* main.c: close graph, verbose files if opened, on exit.
* main.c:
audit memory leaks - valgrind reported some memory still in use on exit.
* lalr.c, output.c, reader.c, mkpar.c, lr0.c:
add hook for auditing memory leaks
* defs.h: add hooks for auditing memory leaks
* configure: regen'd
* configure.in:
use CF_DISABLE_LEAKS, which combines --disable-leaks, --with-valgrind,
--with-dbmalloc and --with-dmalloc
* aclocal.m4: add CF_DISABLE_LEAKS and CF_WITH_VALGRIND
* aclocal.m4: improve version-checking in CF_GCC_VERSION
rework dbmalloc/dmalloc options using CF_NO_LEAKS_OPTION macro
* VERSION: 2007/5/9
* main.c: file_prefix did not always have a trailing null.
2007-03-25 Thomas E. Dickey <tom@invisible-island.net>
* mkdirs.sh: improved version for "make -j"
2006-12-22 Thomas E. Dickey <tom@invisible-island.net>
* config.guess: 2006/12/22
2006-12-08 Thomas E. Dickey <tom@invisible-island.net>
* config.sub: 2006/12/08
2005-08-13 Thomas E. Dickey <tom@invisible-island.net>
* main.c: add -V to usage message
* makefile.in: remove -t option from ctags
* VERSION: 2005/8/13
2005-08-13 schmitz
* main.c: Sylvain Schmitz:
modify the '-o' option to work like bison's, which sets the file-prefix.
2005-08-13 Matt.Kraai
* output.c:
Debian #322858 (don't close union_file, which contained data).
This feature is used in groff.
2005-08-13 Thomas E. Dickey <tom@invisible-island.net>
* configure: regenerated
* aclocal.m4: improve checks for Intel compiler warnings
2005-06-25 Thomas E. Dickey <tom@invisible-island.net>
* config.sub: 2005/6/2
* config.guess: 2005/5/27
2005-05-05 Thomas E. Dickey <tom@invisible-island.net>
* defs.h: add a fallback for GCC_UNUSED
2005-05-04 Thomas E. Dickey <tom@invisible-island.net>
* makefile.in: add "." to include-path to pickup config.h
* reader.c:
apply fix suggested by Steve Dum for end_rule() in Redhat Bugzilla #112617.
* output.c:
correct a limit check in pack_vector() - report/analysis by William Evans
* main.c:
exit after printing version. Otherwise "yacc -V" will exit with an erro
after printing the usage message.
* test/calc.tab.c, test/error.tab.c, test/ftp.tab.c, test/grammar.tab.c:
regenerated after skeleton-changes
* skeleton.c: replace a few -1's with YYEMPTY
* skeleton.c:
delete yynewerror (no one uses it any more, and it just makes compiler warnings)
* skeleton.c: adapt yygrowstack() and related definitions from FreeBSD
* test/run_test.sh:
filter out lines with YYPATCH, since that will change with each update
* yacc.1: add -V option
* main.c: add -V option to print the version.
simplify option-parsing by moving the duplicate logic for setting flags into
new function setflag().
* skeleton.c:
move the actual definition of YYMAJOR and YYMINOR to defs.h (as numbers).
add YYPATCH here so it can be tested by applications.
* defs.h:
add macros to define VERSION in terms of the (numeric) YYMAJOR, YYMINOR and
YYPATCH symbols.
* lalr.c, lr0.c, mkpar.c, defs.h, closure.c, warshall.c, output.c, verbose.c, graph.c, reader.c, main.c, symtab.c:
reduce externs by making static the procedures that are not referenced outside
the module in which they are defined.
* makefile.in:
the VERSION file holds the patch-date. Define YYPATCH, so this will be
compiled into the skeleton.
* VERSION: patch-level for byacc
* main.c:
add "-o" to usage message. It is too long for a single line; rewrite usage()
to show one option per line.
2005-05-03 Thomas E. Dickey <tom@invisible-island.net>
* main.c: add -o option, to work with scripts that assume bison.
simplify create_file_names() with a macro.
simplify done() with a macro.
adapt fix from FreeBSD for signal race, e.g., if done() is interrupted by
onintr(), do not flush output via exit(), but use _exit() instead.
* defs.h: remove unnecessary externs for main.c
* yacc.1: add -o option
* graph.c: remove unused parameter
* mkpar.c, defs.h, reader.c:
add support for "%expect", a bison feature from FreeBSD sources
* lr0.c, reader.c, main.c, skeleton.c, graph.c, symtab.c, closure.c, mkpar.c, lalr.c, error.c, warshall.c, verbose.c, output.c:
indent'd
* configure: regenerated for 2005/5/5
* aclocal.m4: miscellaneous updates (adds CF_INTEL_COMPILER)
2005-04-27 schmitz
* defs.h, graph.c, lr0.c, main.c, makefile.in, reader.c, yacc.1:
Sylvain Schmitz <schmitz@i3s.unice.fr>:
add graphical output of the LALR(1) automaton for graphviz,
associated with command-line option `-g'
2005-04-16 Thomas E. Dickey <tom@invisible-island.net>
* config.sub: 2005/2/10
* config.guess: 2005/3/24
2005-04-13 Thomas E. Dickey <tom@invisible-island.net>
* package/pkgsrc/PLIST: scripts from NetBSD pkgsrc, for test-builds
2005-03-21 Thomas E. Dickey <tom@invisible-island.net>
* package/pkgsrc/DESCR: scripts from NetBSD pkgsrc, for test-builds
2004-03-28 Thomas E. Dickey <tom@invisible-island.net>
* test/calc.tab.c, test/error.tab.c, test/ftp.tab.c, test/grammar.tab.c:
updates due to adding yyparse() prototype
* configure: RCS_BASE
* configure.in:
add AC_ARG_PROGRAM to make --program-prefix, etc., work.
* makefile.in: first cut of script to support --program-prefix
* configure.in:
reorder AC_INIT/AC_CONFIG_HEADER to make this "work" with autoconf 2.52
* makefile.in: modify so DESTDIR works
* makefile.in: use EXEEXT and OBJEXT
* configure.in: use CF_PROG_EXT
generate a config.h
* defs.h: make this use the generated config.h
* skeleton.c: add a forward-reference for yyparse()
* aclocal.m4: add CF_CHECK_CACHE, needed for CF_PROG_EXT
* yacc.1: remove the discussion of TMPDIR since it is obsolete
* skeleton.c: fix a couple of minor compiler-warnings in the skeleton
* defs.h: remove action_file_name, etc., since we use tmpfile() now.
* main.c:
use tmpfile() for opening the working files. This quiets a warning
advising the use of mkstemp().
* output.c:
Do not close temporary-files here, since they are opened with tmpfile().
Just rewind them, and they're ready to read back the data stored in them.
* test/grammar.output, test/grammar.tab.c, test/grammar.tab.h: RCS_BASE
* makefile.in: turn on "make check" rule
* test/calc.output, test/run_test.sh, test/calc.tab.h: RCS_BASE
* test/ftp.tab.c: yyparse() is now yyparse(void)
* test/calc.tab.c: RCS_BASE
* test/error.tab.c: yyparse() is now yyparse(void)
* test/README: RCS_BASE
* yacc.1: various typography fixes prompted by Debian #100947
* aclocal.m4, makefile.in, configure.in: RCS_BASE
* README: updated to note that this is not the original
2004-03-24 Thomas E. Dickey <tom@invisible-island.net>
* test/grammar.y: RCS_BASE
2004-02-23 Thomas E. Dickey <tom@invisible-island.net>
* config.sub: RCS_BASE
2004-02-17 Thomas E. Dickey <tom@invisible-island.net>
* config.guess: RCS_BASE
2003-11-29 Thomas E. Dickey <tom@invisible-island.net>
* install-sh: improved quoting
2002-06-29 Thomas E. Dickey <tom@invisible-island.net>
* mkdirs.sh:
don't use character range, since some locales don't work as expected
2001-06-22 Thomas E. Dickey <tom@invisible-island.net>
* install-sh: RCS_BASE
2000-11-20 Thomas E. Dickey <tom@invisible-island.net>
* test/calc.y: RCS_BASE
* test/code_calc.y, test/pure_calc.y: copy of calc.y
* vmsbuild.com: original version
2000-02-23 Thomas E. Dickey <dickey@invisible-island.net>
* test/RCS, RCS: PERMIT FILE
2000-02-14 Thomas E. Dickey <tom@invisible-island.net>
* main.c: fix for VMS port - making pathname for temp-file
* descrip.mms: original version
2000-02-13 Thomas E. Dickey <tom@invisible-island.net>
* defs.h, verbose.c, reader.c, main.c, skeleton.c, warshall.c, symtab.c, closure.c, mkpar.c, lalr.c, lr0.c, output.c, error.c:
ansify
1999-11-30 Thomas E. Dickey <tom@invisible-island.net>
* mkdirs.sh: RCS_BASE
1995-01-01 Thomas E. Dickey <tom@invisible-island.net>
* config_h.in: RCS_BASE
1993-12-23 unknown
* README.DOS, main.c: MSDOS-port
1993-12-22 unknown
* reader.c, defs.h: MSDOS-port
1993-03-02 unknown
* README: original version
1993-02-22 unknown
* test/ftp.output, test/ftp.tab.c, test/ftp.tab.h, test/error.output, test/error.tab.c, test/error.tab.h:
RCS_BASE
* skeleton.c, warshall.c, main.c, output.c, reader.c, closure.c, NOTES:
original version
1992-10-12 unknown
* yacc.1: original version
1992-10-11 unknown
* defs.h: original version
1991-01-20 unknown
* mkpar.c, verbose.c: original version
1991-01-14 unknown
* lr0.c, Makefile, Makefile.old: original version
1990-07-16 unknown
* NEW_FEATURES: original version
1990-06-03 unknown
* ACKNOWLEDGEMENTS: original version
1990-02-05 unknown
* symtab.c, lalr.c, error.c: original version
1990-01-16 Thomas E. Dickey <tom@invisible-island.net>
* test/code_error.y, test/pure_error.y: RCS_BASE
1990-01-16 unknown
* test/error.y: RCS_BASE
1989-11-22 unknown
* NO_WARRANTY: original version
1989-09-23 unknown
* test/ftp.y: RCS_BASE

View file

@ -1,4 +1,4 @@
$NetBSD: NOTES,v 1.3 1997/10/20 03:41:15 lukem Exp $
$NetBSD: NOTES,v 1.2 2009/10/29 00:56:19 christos Exp $
Berkeley Yacc reflects its origins. The reason so many routines
use exactly six register variables is that Berkeley Yacc was

3
external/bsd/byacc/dist/NO_WARRANTY vendored Normal file
View 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.

View file

@ -1,3 +1,9 @@
-- 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

1
external/bsd/byacc/dist/VERSION vendored Normal file
View file

@ -0,0 +1 @@
20110908

1092
external/bsd/byacc/dist/aclocal.m4 vendored Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,57 +1,19 @@
/* $NetBSD: closure.c,v 1.8 2006/05/24 18:01:43 christos Exp $ */
/* $NetBSD: closure.c,v 1.6 2011/09/10 21:29:04 christos Exp $ */
/*
* Copyright (c) 1989 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Robert Paul Corbett.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
#if 0
static char sccsid[] = "@(#)closure.c 5.3 (Berkeley) 5/24/93";
#else
__RCSID("$NetBSD: closure.c,v 1.8 2006/05/24 18:01:43 christos Exp $");
#endif
#endif /* not lint */
/* Id: closure.c,v 1.9 2010/06/09 08:21:47 tom Exp */
#include "defs.h"
short *itemset;
short *itemsetend;
#include <sys/cdefs.h>
__RCSID("$NetBSD: closure.c,v 1.6 2011/09/10 21:29:04 christos Exp $");
Value_t *itemset;
Value_t *itemsetend;
unsigned *ruleset;
static unsigned *first_derives;
static unsigned *EFF;
static void set_EFF(void);
static void
set_EFF(void)
{
@ -88,7 +50,6 @@ set_EFF(void)
#endif
}
void
set_first_derives(void)
{
@ -96,7 +57,7 @@ set_first_derives(void)
unsigned *vrow;
int j;
unsigned k;
unsigned cword;
unsigned cword = 0;
short *rp;
int rule;
@ -104,8 +65,6 @@ set_first_derives(void)
int rulesetsize;
int varsetsize;
cword = 0;
rulesetsize = WORDSIZE(nrules);
varsetsize = WORDSIZE(nvars);
first_derives = NEW2(nvars * rulesetsize, unsigned) - ntokens * rulesetsize;
@ -125,7 +84,7 @@ set_first_derives(void)
k = 0;
}
if (cword & (1 << k))
if (cword & (unsigned)(1 << k))
{
rp = derives[j];
while ((rule = *rp++) >= 0)
@ -135,7 +94,6 @@ set_first_derives(void)
}
}
vrow += varsetsize;
rrow += rulesetsize;
}
@ -146,25 +104,23 @@ set_first_derives(void)
FREE(EFF);
}
void
closure(short *nucleus, int n)
{
int ruleno;
unsigned ruleno;
unsigned word;
unsigned i;
short *csp;
Value_t *csp;
unsigned *dsp;
unsigned *rsp;
int rulesetsize;
short *csend;
Value_t *csend;
unsigned *rsend;
int symbol;
int itemno;
Value_t itemno;
rulesetsize = WORDSIZE(nrules);
rsp = ruleset;
rsend = ruleset + rulesetsize;
for (rsp = ruleset; rsp < rsend; rsp++)
*rsp = 0;
@ -192,9 +148,9 @@ closure(short *nucleus, int n)
{
for (i = 0; i < BITS_PER_WORD; ++i)
{
if (word & (1 << i))
if (word & (unsigned)(1 << i))
{
itemno = rrhs[ruleno+i];
itemno = rrhs[ruleno + i];
while (csp < csend && *csp < itemno)
*itemsetend++ = *csp++;
*itemsetend++ = itemno;
@ -210,33 +166,30 @@ closure(short *nucleus, int n)
*itemsetend++ = *csp++;
#ifdef DEBUG
print_closure(n);
print_closure(n);
#endif
}
void
finalize_closure(void)
{
FREE(itemset);
FREE(ruleset);
FREE(first_derives + ntokens * WORDSIZE(nrules));
FREE(itemset);
FREE(ruleset);
FREE(first_derives + ntokens * WORDSIZE(nrules));
}
#ifdef DEBUG
void
print_closure(int n)
{
short *isp;
short *isp;
printf("\n\nn = %d\n\n", n);
for (isp = itemset; isp < itemsetend; isp++)
printf(" %d\n", *isp);
printf("\n\nn = %d\n\n", n);
for (isp = itemset; isp < itemsetend; isp++)
printf(" %d\n", *isp);
}
void
print_EFF(void)
{
@ -268,14 +221,13 @@ print_EFF(void)
}
}
void
print_first_derives(void)
{
int i;
int j;
unsigned *rp;
unsigned cword;
unsigned cword = 0;
unsigned k;
printf("\n\n\nFirst Derives\n");
@ -286,19 +238,19 @@ print_first_derives(void)
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 (k >= BITS_PER_WORD)
{
cword = *rp++;
k = 0;
}
if (cword & (1 << k))
printf(" %d\n", j);
if (cword & (1 << k))
printf(" %d\n", j);
}
}
fflush(stdout);
fflush(stdout);
}
#endif

1511
external/bsd/byacc/dist/config.guess vendored Executable file

File diff suppressed because it is too large Load diff

1760
external/bsd/byacc/dist/config.sub vendored Executable file

File diff suppressed because it is too large Load diff

3
external/bsd/byacc/dist/config_h.in vendored Normal file
View file

@ -0,0 +1,3 @@
/* @configure_input@ */
/* Id: config_h.in,v 1.1 1995/01/01 19:34:59 tom Exp */
@DEFS@

5453
external/bsd/byacc/dist/configure vendored Executable file

File diff suppressed because it is too large Load diff

30
external/bsd/byacc/dist/configure.in vendored Normal file
View 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)

443
external/bsd/byacc/dist/defs.h vendored Normal file
View file

@ -0,0 +1,443 @@
/* $NetBSD: defs.h,v 1.5 2011/09/10 21:29:04 christos Exp $ */
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
/* Id: defs.h,v 1.35 2011/09/07 08:55:03 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 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
external/bsd/byacc/dist/descrip.mms vendored Normal file
View 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

View file

@ -1,50 +1,13 @@
/* $NetBSD: error.c,v 1.11 2009/04/14 09:41:30 lukem Exp $ */
/*
* Copyright (c) 1989 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Robert Paul Corbett.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
#if 0
static char sccsid[] = "@(#)error.c 5.3 (Berkeley) 6/1/90";
#else
__RCSID("$NetBSD: error.c,v 1.11 2009/04/14 09:41:30 lukem Exp $");
#endif
#endif /* not lint */
/* routines for printing error messages */
/* $NetBSD: error.c,v 1.7 2011/09/10 21:29:04 christos Exp $ */
/* Id: error.c,v 1.9 2011/09/05 23:27:43 tom Exp */
#include "defs.h"
#include <sys/cdefs.h>
__RCSID("$NetBSD: error.c,v 1.7 2011/09/10 21:29:04 christos Exp $");
/* routines for printing error messages */
__dead void
fatal(const char *msg)
{
@ -52,7 +15,6 @@ fatal(const char *msg)
done(2);
}
__dead void
no_space(void)
{
@ -67,7 +29,15 @@ open_error(const char *filename)
done(2);
}
__dead void
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",
@ -75,15 +45,16 @@ unexpected_EOF(void)
done(1);
}
void
static void
print_pos(char *st_line, char *st_cptr)
{
char *s;
if (st_line == 0) return;
if (st_line == 0)
return;
for (s = st_line; *s != '\n'; ++s)
{
if (isprint((unsigned char)*s) || *s == '\t')
if (isprint(UCH(*s)) || *s == '\t')
putc(*s, stderr);
else
putc('?', stderr);
@ -175,7 +146,8 @@ illegal_character(char *c_cptr)
__dead void
used_reserved(char *s)
{
fprintf(stderr, "%s: e - line %d of \"%s\", illegal use of reserved symbol \
fprintf(stderr,
"%s: e - line %d of \"%s\", illegal use of reserved symbol \
%s\n", myname, lineno, input_file_name, s);
done(1);
}
@ -183,9 +155,10 @@ used_reserved(char *s)
__dead void
tokenized_start(char *s)
{
fprintf(stderr, "%s: e - line %d of \"%s\", the start symbol %s cannot be \
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);
done(1);
}
void
@ -198,7 +171,8 @@ 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 \
fprintf(stderr,
"%s: w - line %d of \"%s\", the precedence of %s has been \
redeclared\n", myname, lineno, input_file_name, s);
}
@ -209,7 +183,7 @@ revalued_warning(char *s)
redeclared\n", myname, lineno, input_file_name, s);
}
__dead void
void
terminal_start(char *s)
{
fprintf(stderr, "%s: e - line %d of \"%s\", the start symbol %s is a \
@ -224,7 +198,7 @@ restarted_warning(void)
redeclared\n", myname, lineno, input_file_name);
}
__dead void
void
no_grammar(void)
{
fprintf(stderr, "%s: e - line %d of \"%s\", no grammar has been \
@ -232,7 +206,7 @@ specified\n", myname, lineno, input_file_name);
done(1);
}
__dead void
void
terminal_lhs(int s_lineno)
{
fprintf(stderr, "%s: e - line %d of \"%s\", a token appears on the lhs \
@ -247,7 +221,7 @@ prec_redeclared(void)
specifiers\n", myname, lineno, input_file_name);
}
__dead void
void
unterminated_action(int a_lineno, char *a_line, char *a_cptr)
{
fprintf(stderr, "%s: e - line %d of \"%s\", unterminated action\n",
@ -299,11 +273,12 @@ unknown_rhs(int i)
void
default_action_warning(void)
{
fprintf(stderr, "%s: w - line %d of \"%s\", the default action assigns an \
fprintf(stderr,
"%s: w - line %d of \"%s\", the default action assigns an \
undefined value to $$\n", myname, lineno, input_file_name);
}
__dead void
void
undefined_goal(char *s)
{
fprintf(stderr, "%s: e - the start symbol %s is undefined\n", myname, s);

116
external/bsd/byacc/dist/graph.c vendored Normal file
View file

@ -0,0 +1,116 @@
/* $NetBSD: graph.c,v 1.4 2010/12/25 23:43:30 christos Exp $ */
/* Id: graph.c,v 1.7 2009/10/27 09:25:20 tom Exp */
#include "defs.h"
#include <sys/cdefs.h>
__RCSID("$NetBSD: graph.c,v 1.4 2010/12/25 23:43:30 christos Exp $");
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
external/bsd/byacc/dist/install-sh vendored Executable file
View 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
}

659
external/bsd/byacc/dist/lalr.c vendored Normal file
View file

@ -0,0 +1,659 @@
/* $NetBSD: lalr.c,v 1.5 2011/09/10 21:29:04 christos Exp $ */
/* Id: lalr.c,v 1.9 2009/10/27 09:49:27 tom Exp */
#include "defs.h"
#include <sys/cdefs.h>
__RCSID("$NetBSD: lalr.c,v 1.5 2011/09/10 21:29:04 christos Exp $");
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

View file

@ -1,60 +1,13 @@
/* $NetBSD: lr0.c,v 1.10 2009/04/14 09:41:30 lukem Exp $ */
/*
* Copyright (c) 1989 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Robert Paul Corbett.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
#if 0
static char sccsid[] = "@(#)lr0.c 5.3 (Berkeley) 1/20/91";
#else
__RCSID("$NetBSD: lr0.c,v 1.10 2009/04/14 09:41:30 lukem Exp $");
#endif
#endif /* not lint */
/* $NetBSD: lr0.c,v 1.6 2011/09/10 21:29:04 christos Exp $ */
/* Id: lr0.c,v 1.12 2010/06/09 08:53:17 tom Exp */
#include "defs.h"
extern short *itemset;
extern short *itemsetend;
extern unsigned *ruleset;
int nstates;
core *first_state;
shifts *first_shift;
reductions *first_reduction;
static int get_state(int);
static core *new_state(int);
#include <sys/cdefs.h>
__RCSID("$NetBSD: lr0.c,v 1.6 2011/09/10 21:29:04 christos Exp $");
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);
@ -62,21 +15,15 @@ static void free_storage(void);
static void generate_states(void);
static void initialize_states(void);
static void new_itemsets(void);
#ifdef DEBUG
static void show_cores(void);
static void show_ritems(void);
static void show_rrhs(void);
static void show_shifts(void);
#endif
static void save_shifts(void);
static void save_reductions(void);
static void save_shifts(void);
static void set_derives(void);
static void set_nullable(void);
#ifdef DEBUG
static void print_derives(void);
static void free_derives(void);
static void free_nullable(void);
#endif
int nstates;
core *first_state;
shifts *first_shift;
reductions *first_reduction;
static core **state_set;
static core *this_state;
@ -87,12 +34,12 @@ static reductions *last_reduction;
static int nshifts;
static short *shift_symbol;
static short *redset;
static short *shiftset;
static Value_t *redset;
static Value_t *shiftset;
static short **kernel_base;
static short **kernel_end;
static short *kernel_items;
static Value_t **kernel_base;
static Value_t **kernel_end;
static Value_t *kernel_items;
static void
allocate_itemsets(void)
@ -150,7 +97,7 @@ append_states(void)
{
int i;
int j;
int symbol;
Value_t symbol;
#ifdef TRACE
fprintf(stderr, "Entering append_states()\n");
@ -186,7 +133,6 @@ free_storage(void)
FREE(state_set);
}
static void
generate_states(void)
{
@ -209,13 +155,10 @@ generate_states(void)
this_state = this_state->next;
}
finalize_closure();
free_storage();
}
static int
static Value_t
get_state(int symbol)
{
int key;
@ -232,7 +175,7 @@ get_state(int symbol)
isp1 = kernel_base[symbol];
iend = kernel_end[symbol];
n = iend - isp1;
n = (int)(iend - isp1);
key = *isp1;
assert(0 <= key && key < nitems);
@ -277,11 +220,10 @@ get_state(int symbol)
return (sp->number);
}
static void
initialize_states(void)
{
int i;
unsigned i;
short *start_derives;
core *p;
@ -289,31 +231,30 @@ initialize_states(void)
for (i = 0; start_derives[i] >= 0; ++i)
continue;
p = (core *) MALLOC(sizeof(core) + i*sizeof(short));
if (p == 0) no_space();
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 = i;
p->nitems = (Value_t) i;
for (i = 0; start_derives[i] >= 0; ++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)
{
int i;
Value_t i;
int shiftcount;
short *isp;
short *ksp;
int symbol;
Value_t symbol;
for (i = 0; i < nsyms; i++)
kernel_end[i] = 0;
@ -333,7 +274,7 @@ new_itemsets(void)
ksp = kernel_base[symbol];
}
*ksp++ = i + 1;
*ksp++ = (Value_t) (i + 1);
kernel_end[symbol] = ksp;
}
}
@ -341,12 +282,10 @@ new_itemsets(void)
nshifts = shiftcount;
}
static core *
new_state(int symbol)
{
int n;
unsigned n;
core *p;
short *isp1;
short *isp2;
@ -361,12 +300,12 @@ new_state(int symbol)
isp1 = kernel_base[symbol];
iend = kernel_end[symbol];
n = iend - isp1;
n = (unsigned)(iend - isp1);
p = (core *) allocate((unsigned) (sizeof(core) + (n - 1) * sizeof(short)));
p->accessing_symbol = symbol;
p->number = nstates;
p->nitems = n;
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)
@ -380,9 +319,9 @@ new_state(int symbol)
return (p);
}
#ifdef DEBUG
/* show_cores is used for debugging */
static void
void
show_cores(void)
{
core *p;
@ -392,16 +331,18 @@ show_cores(void)
k = 0;
for (p = first_state; p; ++k, p = p->next)
{
if (k) printf("\n");
if (k)
printf("\n");
printf("state %d, number = %d, accessing symbol = %s\n",
k, p->number, symbol_name[p->accessing_symbol]);
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;
while (ritem[j] >= 0)
++j;
printf("%s :", symbol_name[rlhs[-ritem[j]]]);
j = rrhs[-ritem[j]];
while (j < itemno)
@ -415,9 +356,9 @@ show_cores(void)
}
}
/* show_ritems is used for debugging */
static void
void
show_ritems(void)
{
int i;
@ -426,9 +367,8 @@ show_ritems(void)
printf("ritem[%d] = %d\n", i, ritem[i]);
}
/* show_rrhs is used for debugging */
static void
void
show_rrhs(void)
{
int i;
@ -437,9 +377,9 @@ show_rrhs(void)
printf("rrhs[%d] = %d\n", i, rrhs[i]);
}
/* show_shifts is used for debugging */
static void
void
show_shifts(void)
{
shifts *p;
@ -448,16 +388,15 @@ show_shifts(void)
k = 0;
for (p = first_shift; p; ++k, p = p->next)
{
if (k) printf("\n");
if (k)
printf("\n");
printf("shift %d, number = %d, nshifts = %d\n", k, p->number,
p->nshifts);
p->nshifts);
j = p->nshifts;
for (i = 0; i < j; ++i)
printf("\t%d\n", p->shift[i]);
}
}
#endif
static void
save_shifts(void)
@ -467,11 +406,11 @@ save_shifts(void)
short *sp2;
short *send;
p = (shifts *) allocate((unsigned) (sizeof(shifts) +
(nshifts - 1) * sizeof(short)));
p = (shifts *)allocate((sizeof(shifts) +
(unsigned)(nshifts - 1) * sizeof(short)));
p->number = this_state->number;
p->nshifts = nshifts;
p->nshifts = (Value_t) nshifts;
sp1 = shiftset;
sp2 = p->shift;
@ -492,7 +431,6 @@ save_shifts(void)
}
}
static void
save_reductions(void)
{
@ -500,7 +438,7 @@ save_reductions(void)
short *rp1;
short *rp2;
int item;
int count;
Value_t count;
reductions *p;
short *rend;
@ -510,14 +448,15 @@ save_reductions(void)
item = ritem[*isp];
if (item < 0)
{
redset[count++] = -item;
redset[count++] = (Value_t) - item;
}
}
if (count)
{
p = (reductions *) allocate((unsigned) (sizeof(reductions) +
(count - 1) * sizeof(short)));
p = (reductions *)allocate((sizeof(reductions) +
(unsigned)(count - 1) *
sizeof(short)));
p->number = this_state->number;
p->nreds = count;
@ -542,18 +481,14 @@ save_reductions(void)
}
}
static void
set_derives(void)
{
int i, k;
Value_t i, k;
int lhs;
short *rules;
derives = NEW2(nsyms, short *);
if (start_symbol >= nsyms)
return;
rules = NEW2(nvars + nrules, short);
k = 0;
@ -577,17 +512,8 @@ set_derives(void)
#endif
}
#ifdef DEBUG
static void
free_derives(void)
{
FREE(derives[start_symbol]);
FREE(derives);
}
#endif
#ifdef DEBUG
static void
void
print_derives(void)
{
int i;
@ -609,24 +535,23 @@ print_derives(void)
}
#endif
static void
set_nullable(void)
{
int i, j;
int empty;
int isdone;
int done_flag;
nullable = MALLOC(nsyms);
if (nullable == 0) no_space();
NO_SPACE(nullable);
for (i = 0; i < nsyms; ++i)
nullable[i] = 0;
isdone = 0;
while (!isdone)
done_flag = 0;
while (!done_flag)
{
isdone = 1;
done_flag = 1;
for (i = 1; i < nitems; i++)
{
empty = 1;
@ -642,7 +567,7 @@ set_nullable(void)
if (!nullable[j])
{
nullable[j] = 1;
isdone = 0;
done_flag = 0;
}
}
}
@ -659,16 +584,6 @@ set_nullable(void)
#endif
}
#ifdef DEBUG
static void
free_nullable(void)
{
FREE(nullable);
}
#endif
void
lr0(void)
{
@ -676,3 +591,13 @@ lr0(void)
set_nullable();
generate_states();
}
#ifdef NO_LEAKS
void
lr0_leaks(void)
{
DO_FREE(derives[start_symbol]);
DO_FREE(derives);
DO_FREE(nullable);
}
#endif

694
external/bsd/byacc/dist/main.c vendored Normal file
View file

@ -0,0 +1,694 @@
/* $NetBSD: main.c,v 1.7 2011/09/10 21:29:04 christos Exp $ */
/* Id: main.c,v 1.36 2011/09/06 22:44:45 tom Exp */
#include "defs.h"
#include <sys/cdefs.h>
__RCSID("$NetBSD: main.c,v 1.7 2011/09/10 21:29:04 christos Exp $");
#include <signal.h>
#include <unistd.h> /* for _exit() */
#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 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 int explicit_file_name;
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)"
," -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 '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();
explicit_file_name = 1;
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 = 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)
{
if (explicit_file_name)
{
char *suffix;
defines_file_name = strdup(output_file_name);
if (defines_file_name == 0)
no_space();
/* does the output_file_name have a known suffix */
suffix = strrchr(output_file_name, '.');
if (suffix != 0 &&
(!strcmp(suffix, ".c") || /* good, old-fashioned C */
!strcmp(suffix, ".C") || /* C++, or C on Windows */
!strcmp(suffix, ".cc") || /* C++ */
!strcmp(suffix, ".cxx") || /* C++ */
!strcmp(suffix, ".cpp"))) /* C++ (Windows) */
{
strncpy(defines_file_name, output_file_name,
suffix - output_file_name + 1);
defines_file_name[suffix - output_file_name + 1] = 'h';
defines_file_name[suffix - output_file_name + 2] = 0;
} else {
fprintf(stderr,"%s: suffix of output file name %s"
" not recognized, no -d file generated.\n",
myname, output_file_name);
dflag = 0;
free(defines_file_name);
defines_file_name = 0;
}
} else {
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
external/bsd/byacc/dist/makefile.in vendored Normal file
View file

@ -0,0 +1,182 @@
# Id: makefile.in,v 1.16 2010/06/09 09:46:37 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:
$(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.

View file

@ -1,75 +1,40 @@
/* $NetBSD: mkpar.c,v 1.12 2009/04/14 09:41:31 lukem Exp $ */
/*
* Copyright (c) 1989 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Robert Paul Corbett.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
#if 0
static char sccsid[] = "@(#)mkpar.c 5.3 (Berkeley) 1/20/91";
#else
__RCSID("$NetBSD: mkpar.c,v 1.12 2009/04/14 09:41:31 lukem Exp $");
#endif
#endif /* not lint */
/* $NetBSD: mkpar.c,v 1.6 2011/09/10 21:29:04 christos Exp $ */
/* Id: mkpar.c,v 1.11 2010/06/09 08:53:17 tom Exp */
#include "defs.h"
action **parser;
int SRtotal;
int RRtotal;
short *SRconflicts;
short *RRconflicts;
short *defred;
short *rules_used;
short nunused;
short final_state;
static int SRcount;
static int RRcount;
static action *parse_actions(int);
static action *get_shifts(int);
static action *add_reductions(int, action *);
static action *add_reduce(action *, int, int);
static int sole_reduction(int);
static void free_action_row(action *);
#include <sys/cdefs.h>
__RCSID("$NetBSD: mkpar.c,v 1.6 2011/09/10 21:29:04 christos Exp $");
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 unused_rules(void);
static void free_action_row(action *p);
static void remove_conflicts(void);
static void total_conflicts(void);
static void defreds(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)
@ -83,11 +48,11 @@ make_parser(void)
find_final_state();
remove_conflicts();
unused_rules();
if (SRtotal + RRtotal > 0) total_conflicts();
if (SRtotal + RRtotal > 0)
total_conflicts();
defreds();
}
static action *
parse_actions(int stateno)
{
@ -98,24 +63,23 @@ parse_actions(int stateno)
return (actions);
}
static action *
get_shifts(int stateno)
{
action *actions, *temp;
shifts *sp;
short *state;
int i, k;
int symbol;
Value_t *to_state2;
Value_t i, k;
Value_t symbol;
actions = 0;
sp = shift_table[stateno];
if (sp)
{
state = sp->shift;
for (i = sp->nshifts - 1; i >= 0; i--)
to_state2 = sp->shift;
for (i = (Value_t) (sp->nshifts - 1); i >= 0; i--)
{
k = state[i];
k = to_state2[i];
symbol = accessing_symbol[k];
if (ISTOKEN(symbol))
{
@ -156,9 +120,10 @@ add_reductions(int stateno, action *actions)
return (actions);
}
static action *
add_reduce(action *actions, int ruleno, int symbol)
add_reduce(action *actions,
int ruleno,
int symbol)
{
action *temp, *prev, *next;
@ -173,7 +138,7 @@ add_reduce(action *actions, int ruleno, int symbol)
}
while (next && next->symbol == symbol &&
next->action_code == REDUCE && next->number < ruleno)
next->action_code == REDUCE && next->number < ruleno)
{
prev = next;
next = next->next;
@ -181,8 +146,8 @@ add_reduce(action *actions, int ruleno, int symbol)
temp = NEW(action);
temp->next = next;
temp->symbol = symbol;
temp->number = ruleno;
temp->symbol = (Value_t) symbol;
temp->number = (Value_t) ruleno;
temp->prec = rprec[ruleno];
temp->action_code = REDUCE;
temp->assoc = rassoc[ruleno];
@ -195,33 +160,32 @@ add_reduce(action *actions, int ruleno, int symbol)
return (actions);
}
static void
find_final_state(void)
{
int goal, i;
short *state;
Value_t *to_state2;
shifts *p;
p = shift_table[0];
state = p->shift;
to_state2 = p->shift;
goal = ritem[1];
for (i = p->nshifts - 1; i >= 0; --i)
{
final_state = state[i];
if (accessing_symbol[final_state] == goal) break;
final_state = to_state2[i];
if (accessing_symbol[final_state] == goal)
break;
}
}
static void
unused_rules(void)
{
int i;
action *p;
rules_used = (short *) MALLOC(nrules*sizeof(short));
if (rules_used == 0) no_space();
rules_used = (Value_t *) MALLOC((unsigned)nrules * sizeof(Value_t));
NO_SPACE(rules_used);
for (i = 0; i < nrules; ++i)
rules_used[i] = 0;
@ -237,9 +201,11 @@ unused_rules(void)
nunused = 0;
for (i = 3; i < nrules; ++i)
if (!rules_used[i]) ++nunused;
if (!rules_used[i])
++nunused;
if (nunused) {
if (nunused)
{
if (nunused == 1)
fprintf(stderr, "%s: 1 rule never reduced\n", myname);
else
@ -247,19 +213,17 @@ unused_rules(void)
}
}
static void
remove_conflicts(void)
{
int i;
int symbol;
action *p, *pref;
action *p, *pref = 0;
pref = NULL;
SRtotal = 0;
RRtotal = 0;
SRconflicts = NEW2(nstates, short);
RRconflicts = NEW2(nstates, short);
SRconflicts = NEW2(nstates, Value_t);
RRconflicts = NEW2(nstates, Value_t);
for (i = 0; i < nstates; i++)
{
SRcount = 0;
@ -277,49 +241,45 @@ remove_conflicts(void)
SRcount++;
p->suppressed = 1;
}
else
else if (pref != 0 && pref->action_code == SHIFT)
{
assert(pref != NULL);
if (pref->action_code == SHIFT)
if (pref->prec > 0 && p->prec > 0)
{
if (pref->prec > 0 && p->prec > 0)
if (pref->prec < p->prec)
{
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;
}
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
{
SRcount++;
p->suppressed = 1;
pref->suppressed = 2;
p->suppressed = 2;
}
}
else
{
RRcount++;
SRcount++;
p->suppressed = 1;
}
}
else
{
RRcount++;
p->suppressed = 1;
}
}
SRtotal += SRcount;
RRtotal += RRcount;
@ -328,7 +288,6 @@ remove_conflicts(void)
}
}
static void
total_conflicts(void)
{
@ -347,8 +306,22 @@ total_conflicts(void)
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)
@ -357,7 +330,7 @@ sole_reduction(int stateno)
action *p;
count = 0;
ruleno = 0;
ruleno = 0;
for (p = parser[stateno]; p; p = p->next)
{
if (p->action_code == SHIFT && p->suppressed == 0)
@ -377,37 +350,47 @@ sole_reduction(int stateno)
return (ruleno);
}
static void
defreds(void)
{
int i;
defred = NEW2(nstates, short);
defred = NEW2(nstates, Value_t);
for (i = 0; i < nstates; i++)
defred[i] = sole_reduction(i);
defred[i] = (Value_t) sole_reduction(i);
}
static void
static void
free_action_row(action *p)
{
action *q;
action *q;
while (p)
while (p)
{
q = p->next;
FREE(p);
p = q;
q = p->next;
FREE(p);
p = q;
}
}
void
free_parser(void)
{
int i;
int i;
for (i = 0; i < nstates; i++)
free_action_row(parser[i]);
for (i = 0; i < nstates; i++)
free_action_row(parser[i]);
FREE(parser);
FREE(parser);
}
#ifdef NO_LEAKS
void
mkpar_leaks(void)
{
DO_FREE(defred);
DO_FREE(rules_used);
DO_FREE(SRconflicts);
DO_FREE(RRconflicts);
}
#endif

1498
external/bsd/byacc/dist/output.c vendored Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,60 @@
Summary: byacc - public domain Berkeley LALR Yacc parser generator
%define AppProgram byacc
%define AppVersion 20110908
%define UseProgram yacc
# $XTermId: byacc.spec,v 1.10 2011/09/08 09:45:02 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

View file

@ -0,0 +1,211 @@
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

View file

@ -0,0 +1 @@
5

View 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.

View 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-2009,2010 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: 2010 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'

View file

@ -0,0 +1,4 @@
README
ACKNOWLEDGEMENTS
NEW_FEATURES
NOTES

View 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

View 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
external/bsd/byacc/dist/package/debian/rules vendored Executable file
View 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

View file

@ -0,0 +1 @@
3.0 (quilt)

View file

@ -0,0 +1,4 @@
version=3
opts=passive ftp://invisible-island.net/byacc/byacc-(\d+)\.tgz \
debian uupdate

View 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).

View file

@ -0,0 +1,19 @@
# $NetBSD: Makefile,v 1.1.1.1 2010/12/23 23:36:27 christos 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"

View file

@ -0,0 +1,3 @@
@comment $NetBSD: PLIST,v 1.1.1.1 2010/12/23 23:36:27 christos Exp $
bin/yacc
man/man1/yacc.1

View file

@ -0,0 +1,6 @@
$NetBSD: distinfo,v 1.1.1.1 2010/12/23 23:36:27 christos Exp $
SHA1 (byacc-20050813.tgz) = 3258494f3422eb3150944c1823af1c9c2c386062
RMD160 (byacc-20050813.tgz) = 3ee159857a79025a83e2b0807577925fe460f816
Size (byacc-20050813.tgz) = 138684 bytes
SHA1 (patch-aa) = decae78775a5e0f1e1f7aaaa258da53903aa1f7a

File diff suppressed because it is too large Load diff

View file

@ -1,48 +1,11 @@
/* $NetBSD: skeleton.c,v 1.29 2008/07/18 14:25:37 drochner Exp $ */
/*
* Copyright (c) 1989 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Robert Paul Corbett.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
#if 0
static char sccsid[] = "@(#)skeleton.c 5.8 (Berkeley) 4/29/95";
#else
__RCSID("$NetBSD: skeleton.c,v 1.29 2008/07/18 14:25:37 drochner Exp $");
#endif /* 0 */
#endif /* not lint */
/* $NetBSD: skeleton.c,v 1.10 2011/09/10 21:29:04 christos Exp $ */
/* Id: skeleton.c,v 1.31 2011/09/07 09:37:59 tom Exp */
#include "defs.h"
#include <sys/cdefs.h>
__RCSID("$NetBSD: skeleton.c,v 1.10 2011/09/10 21:29:04 christos Exp $");
/* The definition of yysccsid in the banner should be replaced with */
/* a #pragma ident directive if the target C compiler supports */
/* #pragma ident directives. */
@ -55,123 +18,203 @@ __RCSID("$NetBSD: skeleton.c,v 1.29 2008/07/18 14:25:37 drochner Exp $");
/* the body either are not useful outside of semantic actions or */
/* are conditional. */
const char * const banner[] =
const char *const banner[] =
{
"#include <stdlib.h>",
"#ifndef lint",
"#if 0",
"static char yysccsid[] = \"@(#)yaccpar 1.9 (Berkeley) 02/21/93\";",
"#else",
"#if defined(__NetBSD__) && defined(__IDSTRING)",
"__IDSTRING(yyrcsid, \"$NetBSD: skeleton.c,v 1.29 2008/07/18 14:25:37 drochner Exp $\");",
"#endif /* __NetBSD__ && __IDSTRING */",
"#endif /* 0 */",
"#endif /* lint */",
"static const char yysccsid[] = \"@(#)yaccpar 1.9 (Berkeley) 02/21/93\";",
"#endif",
"",
"#ifdef _LIBC",
"#include \"namespace.h\"",
"#endif",
"#include <stdlib.h>",
"#include <string.h>",
"",
"#define YYBYACC 1",
"#define YYMAJOR 1",
"#define YYMINOR 9",
"#define YYLEX yylex()",
"#define YYEMPTY -1",
"#define yyclearin (yychar=(YYEMPTY))",
"#define yyerrok (yyerrflag=0)",
"#define YYRECOVERING (yyerrflag!=0)",
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 tables[] =
const char *const xdecls[] =
{
"extern const short yylhs[];",
"extern const short yylen[];",
"extern const short yydefred[];",
"extern const short yydgoto[];",
"extern const short yysindex[];",
"extern const short yyrindex[];",
"extern const short yygindex[];",
"extern const short yytable[];",
"extern const short yycheck[];",
"",
"extern int YYPARSE_DECL();",
#ifdef notdef
"extern int YYLEX_DECL();",
#endif
"",
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 const char * const yyname[];",
"extern const char * const yyrule[];",
"extern char *yyname[];",
"extern char *yyrule[];",
"#endif",
0
};
const char * const header[] =
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",
"#define YYMAXDEPTH YYSTACKSIZE",
"#else",
"#ifdef YYMAXDEPTH",
"#define YYSTACKSIZE YYMAXDEPTH",
"#else",
"#define YYSTACKSIZE 10000",
"#define YYMAXDEPTH 10000",
"#define YYSTACKSIZE 500",
"#define YYMAXDEPTH 500",
"#endif",
"#endif",
"#define YYINITSTACKSIZE 200",
"int yydebug;",
"int yynerrs;",
"int yyerrflag;",
"int yychar;",
"short *yyssp;",
"YYSTYPE *yyvsp;",
"YYSTYPE yyval;",
"static YYSTYPE yyvalzero;", /* no "const", must compile as C++ */
"YYSTYPE yylval;",
"short *yyss;",
"short *yysslim;",
"YYSTYPE *yyvs;",
"int yystacksize;",
"int yyparse(void);",
"",
"#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 body[] =
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(void);",
"static int yygrowstack(void)",
"static int yygrowstack(YYSTACKDATA *data)",
"{",
" int newsize, i;",
" int i;",
" unsigned newsize;",
" short *newss;",
" YYSTYPE *newvs;",
"",
" if ((newsize = yystacksize) == 0)",
" if ((newsize = data->stacksize) == 0)",
" newsize = YYINITSTACKSIZE;",
" else if (newsize >= YYMAXDEPTH)",
" return -1;",
" else if ((newsize *= 2) > YYMAXDEPTH)",
" newsize = YYMAXDEPTH;",
" i = yyssp - yyss;",
" if ((newss = (short *)realloc(yyss, newsize * sizeof *newss)) == NULL)",
"",
" i = data->s_mark - data->s_base;",
" newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));",
" if (newss == 0)",
" return -1;",
" yyss = newss;",
" yyssp = newss + i;",
" if ((newvs = (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs)) == NULL)",
"",
" data->s_base = newss;",
" data->s_mark = newss + i;",
"",
" newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));",
" if (newvs == 0)",
" return -1;",
" yyvs = newvs;",
" yyvsp = newvs + i;",
" yystacksize = newsize;",
" yysslim = yyss + newsize - 1;",
"",
" data->l_base = newvs;",
" data->l_mark = newvs + i;",
"",
" data->stacksize = newsize;",
" data->s_last = data->s_base + newsize - 1;",
" return 0;",
"}",
"",
"#define YYABORT goto yyabort",
"#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",
"#define YYERROR goto yyerrlab",
"",
"int",
"yyparse(void)",
"YYPARSE_DECL()",
"{",
0
};
const char *const body_2[] =
{
" int yym, yyn, yystate;",
"#if YYDEBUG",
" const char *yys;",
"",
" if ((yys = getenv(\"YYDEBUG\")) != NULL)",
" if ((yys = getenv(\"YYDEBUG\")) != 0)",
" {",
" yyn = *yys;",
" if (yyn >= '0' && yyn <= '9')",
@ -181,18 +224,24 @@ const char * const body[] =
"",
" yynerrs = 0;",
" yyerrflag = 0;",
" yychar = (-1);",
" yychar = YYEMPTY;",
" yystate = 0;",
"",
" if (yyss == NULL && yygrowstack()) goto yyoverflow;",
" yyssp = yyss;",
" yyvsp = yyvs;",
" *yyssp = 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 ((yychar = YYLEX) < 0) yychar = 0;",
"#if YYDEBUG",
" if (yydebug)",
" {",
@ -212,13 +261,14 @@ const char * const body[] =
" printf(\"%sdebug: state %d, shifting to state %d\\n\",",
" YYPREFIX, yystate, yytable[yyn]);",
"#endif",
" if (yyssp >= yysslim && yygrowstack())",
" if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))",
" {",
" goto yyoverflow;",
" }",
" *++yyssp = yystate = yytable[yyn];",
" *++yyvsp = yylval;",
" yychar = (-1);",
" yystate = yytable[yyn];",
" *++yystack.s_mark = yytable[yyn];",
" *++yystack.l_mark = yylval;",
" yychar = YYEMPTY;",
" if (yyerrflag > 0) --yyerrflag;",
" goto yyloop;",
" }",
@ -229,32 +279,39 @@ const char * const body[] =
" goto yyreduce;",
" }",
" if (yyerrflag) goto yyinrecovery;",
" goto yynewerror;",
"yynewerror:",
" yyerror(\"syntax error\");",
"",
0
};
const char *const body_3[] =
{
"",
" goto yyerrlab;",
"",
"yyerrlab:",
" ++yynerrs;",
"",
"yyinrecovery:",
" if (yyerrflag < 3)",
" {",
" yyerrflag = 3;",
" for (;;)",
" {",
" if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&",
" 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, *yyssp, yytable[yyn]);",
" to state %d\\n\", YYPREFIX, *yystack.s_mark, yytable[yyn]);",
"#endif",
" if (yyssp >= yysslim && yygrowstack())",
" if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))",
" {",
" goto yyoverflow;",
" }",
" *++yyssp = yystate = yytable[yyn];",
" *++yyvsp = yylval;",
" yystate = yytable[yyn];",
" *++yystack.s_mark = yytable[yyn];",
" *++yystack.l_mark = yylval;",
" goto yyloop;",
" }",
" else",
@ -263,11 +320,11 @@ const char * const body[] =
" if (yydebug)",
" printf(\"%sdebug: error recovery discarding state %d\
\\n\",",
" YYPREFIX, *yyssp);",
" YYPREFIX, *yystack.s_mark);",
"#endif",
" if (yyssp <= yyss) goto yyabort;",
" --yyssp;",
" --yyvsp;",
" if (yystack.s_mark <= yystack.s_base) goto yyabort;",
" --yystack.s_mark;",
" --yystack.l_mark;",
" }",
" }",
" }",
@ -285,9 +342,10 @@ const char * const body[] =
" YYPREFIX, yystate, yychar, yys);",
" }",
"#endif",
" yychar = (-1);",
" yychar = YYEMPTY;",
" goto yyloop;",
" }",
"",
"yyreduce:",
"#if YYDEBUG",
" if (yydebug)",
@ -296,21 +354,20 @@ const char * const body[] =
"#endif",
" yym = yylen[yyn];",
" if (yym)",
" yyval = yyvsp[1-yym];",
" yyval = yystack.l_mark[1-yym];",
" else",
" yyval = yyvalzero;",
" memset(&yyval, 0, sizeof yyval);",
" switch (yyn)",
" {",
0
};
const char * const trailer[] =
const char *const trailer[] =
{
" }",
" yyssp -= yym;",
" yystate = *yyssp;",
" yyvsp -= yym;",
" yystack.s_mark -= yym;",
" yystate = *yystack.s_mark;",
" yystack.l_mark -= yym;",
" yym = yylhs[yyn];",
" if (yystate == 0 && yym == 0)",
" {",
@ -320,11 +377,11 @@ const char * const trailer[] =
" state %d\\n\", YYPREFIX, YYFINAL);",
"#endif",
" yystate = YYFINAL;",
" *++yyssp = YYFINAL;",
" *++yyvsp = yyval;",
" *++yystack.s_mark = YYFINAL;",
" *++yystack.l_mark = yyval;",
" if (yychar < 0)",
" {",
" if ((yychar = yylex()) < 0) yychar = 0;",
" if ((yychar = YYLEX) < 0) yychar = 0;",
"#if YYDEBUG",
" if (yydebug)",
" {",
@ -347,43 +404,50 @@ const char * const trailer[] =
"#if YYDEBUG",
" if (yydebug)",
" printf(\"%sdebug: after reduction, shifting from state %d \\",
"to state %d\\n\", YYPREFIX, *yyssp, yystate);",
"to state %d\\n\", YYPREFIX, *yystack.s_mark, yystate);",
"#endif",
" if (yyssp >= yysslim && yygrowstack())",
" if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))",
" {",
" goto yyoverflow;",
" }",
" *++yyssp = yystate;",
" *++yyvsp = yyval;",
" *++yystack.s_mark = (short) yystate;",
" *++yystack.l_mark = yyval;",
" goto yyloop;",
"",
"yyoverflow:",
" yyerror(\"yacc stack overflow\");",
0
};
const char *const trailer_2[] =
{
"",
"yyabort:",
" yyfreestack(&yystack);",
" return (1);",
"",
"yyaccept:",
" yyfreestack(&yystack);",
" return (0);",
"}",
0
};
void
write_section(const char * const section[])
write_section(FILE * fp, const char *const section[])
{
int c;
int i;
const char *s;
FILE *f;
f = code_file;
for (i = 0; (s = section[i]); ++i)
for (i = 0; (s = section[i]) != 0; ++i)
{
++outline;
while ((c = *s) != '\0')
while ((c = *s) != 0)
{
putc(c, f);
putc(c, fp);
++s;
}
putc('\n', f);
if (fp == code_file)
++outline;
putc('\n', fp);
}
}

121
external/bsd/byacc/dist/symtab.c vendored Normal file
View file

@ -0,0 +1,121 @@
/* $NetBSD: symtab.c,v 1.6 2011/09/10 21:29:04 christos Exp $ */
/* Id: symtab.c,v 1.9 2010/11/24 15:12:29 tom Exp */
#include "defs.h"
#include <sys/cdefs.h>
__RCSID("$NetBSD: symtab.c,v 1.6 2011/09/10 21:29:04 christos Exp $");
/* 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
external/bsd/byacc/dist/test/README vendored Normal file
View file

@ -0,0 +1,4 @@
-- $Id: README,v 1.2 2009/10/29 00:56:20 christos Exp $
The files in this directory are input (.y) and output (.output, .tab.c, .tab.h)
examples.

461
external/bsd/byacc/dist/test/calc.output vendored Normal file
View 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
external/bsd/byacc/dist/test/calc.tab.c vendored Normal file
View file

@ -0,0 +1,673 @@
/* $NetBSD: calc.tab.c,v 1.1.1.4 2011/09/10 21:22:03 christos Exp $ */
#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;
#line 106 "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. */
#define YYERROR_DECL() yyerror(const char *s)
#define YYERROR_CALL(msg) yyerror(msg)
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 63 "calc.y"
/* start of programs */
#ifdef YYBYACC
extern int YYLEX_DECL();
static void YYERROR_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 345 "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 25 "calc.y"
{ yyerrok ; }
break;
case 4:
#line 29 "calc.y"
{ printf("%d\n",yystack.l_mark[0]);}
break;
case 5:
#line 31 "calc.y"
{ regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
break;
case 6:
#line 35 "calc.y"
{ yyval = yystack.l_mark[-1]; }
break;
case 7:
#line 37 "calc.y"
{ yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
break;
case 8:
#line 39 "calc.y"
{ yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
break;
case 9:
#line 41 "calc.y"
{ yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
break;
case 10:
#line 43 "calc.y"
{ yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
break;
case 11:
#line 45 "calc.y"
{ yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
break;
case 12:
#line 47 "calc.y"
{ yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
break;
case 13:
#line 49 "calc.y"
{ yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
break;
case 14:
#line 51 "calc.y"
{ yyval = - yystack.l_mark[0]; }
break;
case 15:
#line 53 "calc.y"
{ yyval = regs[yystack.l_mark[0]]; }
break;
case 17:
#line 58 "calc.y"
{ yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; }
break;
case 18:
#line 60 "calc.y"
{ yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; }
break;
#line 611 "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);
}

View file

@ -0,0 +1,5 @@
/* $NetBSD: calc.tab.h,v 1.1.1.3 2011/09/10 21:22:06 christos Exp $ */
#define DIGIT 257
#define LETTER 258
#define UMINUS 259

110
external/bsd/byacc/dist/test/calc.y vendored Normal file
View file

@ -0,0 +1,110 @@
/* $NetBSD: calc.y,v 1.1.1.4 2011/09/10 21:22:08 christos Exp $ */
%{
# include <stdio.h>
# include <ctype.h>
int regs[26];
int base;
%}
%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();
static void YYERROR_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 );
}

View 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
external/bsd/byacc/dist/test/calc1.tab.c vendored Normal file
View file

@ -0,0 +1,915 @@
/* $NetBSD: calc1.tab.c,v 1.1.1.3 2011/09/10 21:22:08 christos Exp $ */
#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);
int dcheck(INTERVAL);
double dreg[26];
INTERVAL vreg[26];
#line 28 "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 136 "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. */
#define YYERROR_DECL() yyerror(const char *s)
#define YYERROR_CALL(msg) yyerror(msg)
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 173 "calc1.y"
/* beginning of subroutines section */
#ifdef YYBYACC
extern int YYLEX_DECL();
static void YYERROR_DECL();
#endif
#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 484 "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 54 "calc1.y"
{
(void) printf("%15.8f\n", yystack.l_mark[-1].dval);
}
break;
case 4:
#line 58 "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 62 "calc1.y"
{
dreg[yystack.l_mark[-3].ival] = yystack.l_mark[-1].dval;
}
break;
case 6:
#line 66 "calc1.y"
{
vreg[yystack.l_mark[-3].ival] = yystack.l_mark[-1].vval;
}
break;
case 7:
#line 70 "calc1.y"
{
yyerrok;
}
break;
case 9:
#line 77 "calc1.y"
{
yyval.dval = dreg[yystack.l_mark[0].ival];
}
break;
case 10:
#line 81 "calc1.y"
{
yyval.dval = yystack.l_mark[-2].dval + yystack.l_mark[0].dval;
}
break;
case 11:
#line 85 "calc1.y"
{
yyval.dval = yystack.l_mark[-2].dval - yystack.l_mark[0].dval;
}
break;
case 12:
#line 89 "calc1.y"
{
yyval.dval = yystack.l_mark[-2].dval * yystack.l_mark[0].dval;
}
break;
case 13:
#line 93 "calc1.y"
{
yyval.dval = yystack.l_mark[-2].dval / yystack.l_mark[0].dval;
}
break;
case 14:
#line 97 "calc1.y"
{
yyval.dval = -yystack.l_mark[0].dval;
}
break;
case 15:
#line 101 "calc1.y"
{
yyval.dval = yystack.l_mark[-1].dval;
}
break;
case 16:
#line 107 "calc1.y"
{
yyval.vval.hi = yyval.vval.lo = yystack.l_mark[0].dval;
}
break;
case 17:
#line 111 "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 121 "calc1.y"
{
yyval.vval = vreg[yystack.l_mark[0].ival];
}
break;
case 19:
#line 125 "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 130 "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 135 "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 140 "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 145 "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 149 "calc1.y"
{
yyval.vval = vmul (yystack.l_mark[-2].dval, yystack.l_mark[-2].dval, yystack.l_mark[0].vval );
}
break;
case 25:
#line 153 "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 158 "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 163 "calc1.y"
{
yyval.vval.hi = -yystack.l_mark[0].vval.lo;
yyval.vval.lo = -yystack.l_mark[0].vval.hi;
}
break;
case 28:
#line 168 "calc1.y"
{
yyval.vval = yystack.l_mark[-1].vval;
}
break;
#line 853 "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);
}

View file

@ -0,0 +1,20 @@
/* $NetBSD: calc1.tab.h,v 1.1.1.3 2011/09/10 21:22:10 christos Exp $ */
#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;

309
external/bsd/byacc/dist/test/calc1.y vendored Normal file
View file

@ -0,0 +1,309 @@
/* $NetBSD: calc1.y,v 1.1.1.3 2011/09/10 21:22:09 christos Exp $ */
%{
/* 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);
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 */
#ifdef YYBYACC
extern int YYLEX_DECL();
static void YYERROR_DECL();
#endif
#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));
}

View 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
external/bsd/byacc/dist/test/calc2.tab.c vendored Normal file
View file

@ -0,0 +1,673 @@
/* $NetBSD: calc2.tab.c,v 1.1.1.3 2011/09/10 21:22:08 christos Exp $ */
#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>
#line 103 "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. */
#define YYERROR_DECL() yyerror(int regs[26], int * base, const char *s)
#define YYERROR_CALL(msg) yyerror(regs, base, msg)
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 65 "calc2.y"
/* start of programs */
#ifdef YYBYACC
extern int YYLEX_DECL();
static void YYERROR_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(int *base)
{
/* 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 345 "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 27 "calc2.y"
{ yyerrok ; }
break;
case 4:
#line 31 "calc2.y"
{ printf("%d\n",yystack.l_mark[0]);}
break;
case 5:
#line 33 "calc2.y"
{ regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
break;
case 6:
#line 37 "calc2.y"
{ yyval = yystack.l_mark[-1]; }
break;
case 7:
#line 39 "calc2.y"
{ yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
break;
case 8:
#line 41 "calc2.y"
{ yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
break;
case 9:
#line 43 "calc2.y"
{ yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
break;
case 10:
#line 45 "calc2.y"
{ yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
break;
case 11:
#line 47 "calc2.y"
{ yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
break;
case 12:
#line 49 "calc2.y"
{ yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
break;
case 13:
#line 51 "calc2.y"
{ yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
break;
case 14:
#line 53 "calc2.y"
{ yyval = - yystack.l_mark[0]; }
break;
case 15:
#line 55 "calc2.y"
{ yyval = regs[yystack.l_mark[0]]; }
break;
case 17:
#line 60 "calc2.y"
{ yyval = yystack.l_mark[0]; (*base) = (yystack.l_mark[0]==0) ? 8 : 10; }
break;
case 18:
#line 62 "calc2.y"
{ yyval = (*base) * yystack.l_mark[-1] + yystack.l_mark[0]; }
break;
#line 611 "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);
}

View file

@ -0,0 +1,5 @@
/* $NetBSD: calc2.tab.h,v 1.1.1.3 2011/09/10 21:22:09 christos Exp $ */
#define DIGIT 257
#define LETTER 258
#define UMINUS 259

115
external/bsd/byacc/dist/test/calc2.y vendored Normal file
View file

@ -0,0 +1,115 @@
/* $NetBSD: calc2.y,v 1.1.1.3 2011/09/10 21:22:06 christos Exp $ */
%parse-param { int regs[26] }
%parse-param { int *base }
%lex-param { int *base }
%{
# include <stdio.h>
# include <ctype.h>
%}
%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();
static void YYERROR_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(int *base)
{
/* 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 );
}

View 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
external/bsd/byacc/dist/test/calc3.tab.c vendored Normal file
View file

@ -0,0 +1,673 @@
/* $NetBSD: calc3.tab.c,v 1.1.1.3 2011/09/10 21:22:04 christos Exp $ */
#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>
#line 103 "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
# define YYLEX_DECL() yylex(YYSTYPE *yylval, void *YYLEX_PARAM)
# 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. */
#define YYERROR_DECL() yyerror(int regs[26], int * base, const char *s)
#define YYERROR_CALL(msg) yyerror(regs, base, msg)
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 67 "calc3.y"
/* start of programs */
#ifdef YYBYACC
extern int YYLEX_DECL();
static void YYERROR_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 338 "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 29 "calc3.y"
{ yyerrok ; }
break;
case 4:
#line 33 "calc3.y"
{ printf("%d\n",yystack.l_mark[0]);}
break;
case 5:
#line 35 "calc3.y"
{ regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
break;
case 6:
#line 39 "calc3.y"
{ yyval = yystack.l_mark[-1]; }
break;
case 7:
#line 41 "calc3.y"
{ yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
break;
case 8:
#line 43 "calc3.y"
{ yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
break;
case 9:
#line 45 "calc3.y"
{ yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
break;
case 10:
#line 47 "calc3.y"
{ yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
break;
case 11:
#line 49 "calc3.y"
{ yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
break;
case 12:
#line 51 "calc3.y"
{ yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
break;
case 13:
#line 53 "calc3.y"
{ yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
break;
case 14:
#line 55 "calc3.y"
{ yyval = - yystack.l_mark[0]; }
break;
case 15:
#line 57 "calc3.y"
{ yyval = regs[yystack.l_mark[0]]; }
break;
case 17:
#line 62 "calc3.y"
{ yyval = yystack.l_mark[0]; (*base) = (yystack.l_mark[0]==0) ? 8 : 10; }
break;
case 18:
#line 64 "calc3.y"
{ yyval = (*base) * yystack.l_mark[-1] + yystack.l_mark[0]; }
break;
#line 611 "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);
}

View file

@ -0,0 +1,5 @@
/* $NetBSD: calc3.tab.h,v 1.1.1.3 2011/09/10 21:22:05 christos Exp $ */
#define DIGIT 257
#define LETTER 258
#define UMINUS 259

117
external/bsd/byacc/dist/test/calc3.y vendored Normal file
View file

@ -0,0 +1,117 @@
/* $NetBSD: calc3.y,v 1.1.1.3 2011/09/10 21:22:07 christos Exp $ */
%pure-parser
%parse-param { int regs[26] }
%parse-param { int *base }
%lex-param { int *base }
%{
# include <stdio.h>
# include <ctype.h>
%}
%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();
static void YYERROR_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 );
}

View file

@ -0,0 +1,573 @@
/* $NetBSD: code_calc.code.c,v 1.1.1.3 2011/09/10 21:22:05 christos Exp $ */
#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;
#line 25 "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. */
#define YYERROR_DECL() yyerror(const char *s)
#define YYERROR_CALL(msg) yyerror(msg)
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 63 "code_calc.y"
/* start of programs */
#ifdef YYBYACC
extern int YYLEX_DECL();
static void YYERROR_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 245 "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 25 "code_calc.y"
{ yyerrok ; }
break;
case 4:
#line 29 "code_calc.y"
{ printf("%d\n",yystack.l_mark[0]);}
break;
case 5:
#line 31 "code_calc.y"
{ regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
break;
case 6:
#line 35 "code_calc.y"
{ yyval = yystack.l_mark[-1]; }
break;
case 7:
#line 37 "code_calc.y"
{ yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
break;
case 8:
#line 39 "code_calc.y"
{ yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
break;
case 9:
#line 41 "code_calc.y"
{ yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
break;
case 10:
#line 43 "code_calc.y"
{ yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
break;
case 11:
#line 45 "code_calc.y"
{ yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
break;
case 12:
#line 47 "code_calc.y"
{ yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
break;
case 13:
#line 49 "code_calc.y"
{ yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
break;
case 14:
#line 51 "code_calc.y"
{ yyval = - yystack.l_mark[0]; }
break;
case 15:
#line 53 "code_calc.y"
{ yyval = regs[yystack.l_mark[0]]; }
break;
case 17:
#line 58 "code_calc.y"
{ yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; }
break;
case 18:
#line 60 "code_calc.y"
{ yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; }
break;
#line 511 "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);
}

View 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

View file

@ -0,0 +1,201 @@
/* $NetBSD: code_calc.tab.c,v 1.1.1.3 2011/09/10 21:22:09 christos Exp $ */
#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

View file

@ -0,0 +1,5 @@
/* $NetBSD: code_calc.tab.h,v 1.1.1.3 2011/09/10 21:22:09 christos Exp $ */
#define DIGIT 257
#define LETTER 258
#define UMINUS 259

109
external/bsd/byacc/dist/test/code_calc.y vendored Normal file
View file

@ -0,0 +1,109 @@
/* $NetBSD: code_calc.y,v 1.1.1.3 2011/09/10 21:22:04 christos Exp $ */
%{
# include <stdio.h>
# include <ctype.h>
int regs[26];
int base;
%}
%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();
static void YYERROR_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 );
}

View file

@ -0,0 +1,482 @@
/* $NetBSD: code_error.code.c,v 1.1.1.3 2011/09/10 21:22:06 christos Exp $ */
#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
#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. */
#define YYERROR_DECL() yyerror(const char *s)
#define YYERROR_CALL(msg) yyerror(msg)
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 4 "code_error.y"
#include <stdio.h>
#ifdef YYBYACC
extern int YYLEX_DECL();
static void YYERROR_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 215 "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);
}

View file

@ -0,0 +1,120 @@
/* $NetBSD: code_error.tab.c,v 1.1.1.3 2011/09/10 21:22:04 christos Exp $ */
#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

View file

@ -0,0 +1,2 @@
/* $NetBSD: code_error.tab.h,v 1.1.1.3 2011/09/10 21:22:04 christos Exp $ */

View file

@ -0,0 +1,31 @@
/* $NetBSD: code_error.y,v 1.1.1.3 2011/09/10 21:22:09 christos Exp $ */
%%
S: error
%%
#include <stdio.h>
#ifdef YYBYACC
extern int YYLEX_DECL();
static void YYERROR_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);
}

View 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
external/bsd/byacc/dist/test/error.tab.c vendored Normal file
View file

@ -0,0 +1,501 @@
/* $NetBSD: error.tab.c,v 1.4 2011/09/10 21:29:04 christos Exp $ */
#ifndef lint
/* static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; */
static char rcsid[] = "$NetBSD: error.tab.c,v 1.4 2011/09/10 21:29:04 christos Exp $";
#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
#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. */
#define YYERROR_DECL() yyerror(const char *s)
#define YYERROR_CALL(msg) yyerror(msg)
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 4 "error.y"
#include <stdio.h>
#ifdef YYBYACC
extern int YYLEX_DECL();
static void YYERROR_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 233 "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);
}

View file

@ -0,0 +1 @@
/* $NetBSD: error.tab.h,v 1.3 2011/09/10 21:29:04 christos Exp $ */

31
external/bsd/byacc/dist/test/error.y vendored Normal file
View file

@ -0,0 +1,31 @@
/* $NetBSD: error.y,v 1.1.1.4 2011/09/10 21:22:03 christos Exp $ */
%%
S: error
%%
#include <stdio.h>
#ifdef YYBYACC
extern int YYLEX_DECL();
static void YYERROR_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);
}

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,4 @@
/* $NetBSD: ftp.tab.h,v 1.2 1998/01/09 08:08:56 perry Exp $ */
/* $NetBSD: ftp.tab.h,v 1.3 2011/09/10 21:29:04 christos Exp $ */
#define A 257
#define B 258

View file

@ -1,4 +1,4 @@
/* $NetBSD: ftp.y,v 1.6 2001/01/04 23:05:57 lukem Exp $ */
/* $NetBSD: ftp.y,v 1.4 2011/09/10 21:29:04 christos Exp $ */
/*
* Copyright (c) 1985, 1988 Regents of the University of California.
@ -17,7 +17,7 @@
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* from: @(#)ftpcmd.y 5.20.1.1 (Berkeley) 3/2/89
* $NetBSD: ftp.y,v 1.6 2001/01/04 23:05:57 lukem Exp $
* $NetBSD: ftp.y,v 1.4 2011/09/10 21:29:04 christos Exp $
*/
/*
@ -28,8 +28,8 @@
%{
#ifndef lint
/*static char sccsid[] = "from: @(#)ftpcmd.y 5.20.1.1 (Berkeley) 3/2/89";*/
static char rcsid[] = "$NetBSD: ftp.y,v 1.6 2001/01/04 23:05:57 lukem Exp $";
static char sccsid[] = "@(#)ftpcmd.y 5.20.1.1 (Berkeley) 3/2/89";
static char rcsid[] = "$NetBSD: ftp.y,v 1.4 2011/09/10 21:29:04 christos Exp $";
#endif /* not lint */
#include <sys/param.h>
@ -39,6 +39,8 @@ static char rcsid[] = "$NetBSD: ftp.y,v 1.6 2001/01/04 23:05:57 lukem Exp $";
#include <arpa/ftp.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <ctype.h>
@ -46,7 +48,9 @@ static char rcsid[] = "$NetBSD: ftp.y,v 1.6 2001/01/04 23:05:57 lukem Exp $";
#include <setjmp.h>
#include <syslog.h>
#include <sys/stat.h>
#include <string.h>
#include <time.h>
#include <assert.h>
extern struct sockaddr_in data_dest;
extern int logged_in;
@ -65,7 +69,30 @@ extern char *globerr;
extern int usedefault;
extern int transflag;
extern char tmpline[];
char **glob();
extern char **glob(char *);
extern char *renamefrom(char *);
extern void cwd(const char *);
extern void dologout(int);
extern void fatal(const char *);
extern void makedir(const char *);
extern void nack(const char *);
extern void pass(const char *);
extern void passive(void);
extern void pwd(void);
extern void removedir(char *);
extern void renamecmd(char *, char *);
extern void retrieve(const char *, const char *);
extern void send_file_list(const char *);
extern void statcmd(void);
extern void statfilecmd(const char *);
extern void store(char *, const char *, int);
extern void user(const char *);
extern void perror_reply(int, const char *, ...);
extern void reply(int, const char *, ...);
extern void lreply(int, const char *, ...);
static int cmd_type;
static int cmd_form;
@ -73,7 +100,15 @@ static int cmd_bytesz;
char cbuf[512];
char *fromname;
char *index();
static char * copy(const char *);
static void
yyerror(const char *msg)
{
perror(msg);
}
%}
%token
@ -198,23 +233,23 @@ cmd: USER SP username CRLF
}
| RETR check_login SP pathname CRLF
= {
if ($2 && $4 != NULL)
if ($2 && $4 != 0)
retrieve((char *) 0, (char *) $4);
if ($4 != NULL)
if ($4 != 0)
free((char *) $4);
}
| STOR check_login SP pathname CRLF
= {
if ($2 && $4 != NULL)
if ($2 && $4 != 0)
store((char *) $4, "w", 0);
if ($4 != NULL)
if ($4 != 0)
free((char *) $4);
}
| APPE check_login SP pathname CRLF
= {
if ($2 && $4 != NULL)
if ($2 && $4 != 0)
store((char *) $4, "a", 0);
if ($4 != NULL)
if ($4 != 0)
free((char *) $4);
}
| NLST check_login CRLF
@ -224,9 +259,9 @@ cmd: USER SP username CRLF
}
| NLST check_login SP STRING CRLF
= {
if ($2 && $4 != NULL)
if ($2 && $4 != 0)
send_file_list((char *) $4);
if ($4 != NULL)
if ($4 != 0)
free((char *) $4);
}
| LIST check_login CRLF
@ -236,16 +271,16 @@ cmd: USER SP username CRLF
}
| LIST check_login SP pathname CRLF
= {
if ($2 && $4 != NULL)
if ($2 && $4 != 0)
retrieve("/bin/ls -lgA %s", (char *) $4);
if ($4 != NULL)
if ($4 != 0)
free((char *) $4);
}
| STAT check_login SP pathname CRLF
= {
if ($2 && $4 != NULL)
if ($2 && $4 != 0)
statfilecmd((char *) $4);
if ($4 != NULL)
if ($4 != 0)
free((char *) $4);
}
| STAT CRLF
@ -254,9 +289,9 @@ cmd: USER SP username CRLF
}
| DELE check_login SP pathname CRLF
= {
if ($2 && $4 != NULL)
delete((char *) $4);
if ($4 != NULL)
if ($2 && $4 != 0)
remove((char *) $4);
if ($4 != 0)
free((char *) $4);
}
| RNTO SP pathname CRLF
@ -281,9 +316,9 @@ cmd: USER SP username CRLF
}
| CWD check_login SP pathname CRLF
= {
if ($2 && $4 != NULL)
if ($2 && $4 != 0)
cwd((char *) $4);
if ($4 != NULL)
if ($4 != 0)
free((char *) $4);
}
| HELP CRLF
@ -311,16 +346,16 @@ cmd: USER SP username CRLF
}
| MKD check_login SP pathname CRLF
= {
if ($2 && $4 != NULL)
if ($2 && $4 != 0)
makedir((char *) $4);
if ($4 != NULL)
if ($4 != 0)
free((char *) $4);
}
| RMD check_login SP pathname CRLF
= {
if ($2 && $4 != NULL)
if ($2 && $4 != 0)
removedir((char *) $4);
if ($4 != NULL)
if ($4 != 0)
free((char *) $4);
}
| PWD check_login CRLF
@ -368,7 +403,7 @@ cmd: USER SP username CRLF
}
| SITE SP CHMOD check_login SP octal_number SP pathname CRLF
= {
if ($4 && ($8 != NULL)) {
if ($4 && ($8 != 0)) {
if ($6 > 0777)
reply(501,
"CHMOD: Mode value must be between 0 and 0777");
@ -377,7 +412,7 @@ cmd: USER SP username CRLF
else
reply(200, "CHMOD command successful.");
}
if ($8 != NULL)
if ($8 != 0)
free((char *) $8);
}
| SITE SP IDLE CRLF
@ -402,9 +437,9 @@ cmd: USER SP username CRLF
}
| STOU check_login SP pathname CRLF
= {
if ($2 && $4 != NULL)
if ($2 && $4 != 0)
store((char *) $4, "w", 1);
if ($4 != NULL)
if ($4 != 0)
free((char *) $4);
}
| SYST CRLF
@ -430,9 +465,9 @@ cmd: USER SP username CRLF
*/
| SIZE check_login SP pathname CRLF
= {
if ($2 && $4 != NULL)
if ($2 && $4 != 0)
sizecmd((char *) $4);
if ($4 != NULL)
if ($4 != 0)
free((char *) $4);
}
@ -447,7 +482,7 @@ cmd: USER SP username CRLF
*/
| MDTM check_login SP pathname CRLF
= {
if ($2 && $4 != NULL) {
if ($2 && $4 != 0) {
struct stat stbuf;
if (stat((char *) $4, &stbuf) < 0)
perror_reply(550, "%s", (char *) $4);
@ -456,7 +491,6 @@ cmd: USER SP username CRLF
(char *) $4);
} else {
register struct tm *t;
struct tm *gmtime();
t = gmtime(&stbuf.st_mtime);
reply(213,
"%04d%02d%02d%02d%02d%02d",
@ -465,7 +499,7 @@ cmd: USER SP username CRLF
t->tm_hour, t->tm_min, t->tm_sec);
}
}
if ($4 != NULL)
if ($4 != 0)
free((char *) $4);
}
| QUIT CRLF
@ -480,8 +514,6 @@ cmd: USER SP username CRLF
;
rcmd: RNFR check_login SP pathname CRLF
= {
char *renamefrom();
if ($2 && $4) {
fromname = renamefrom((char *) $4);
if (fromname == (char *) 0 && $4) {
@ -490,13 +522,13 @@ rcmd: RNFR check_login SP pathname CRLF
}
}
;
username: STRING
;
password: /* empty */
= {
*(char **)&($$) = "";
*(const char **)(&($$)) = "";
}
| STRING
;
@ -504,7 +536,7 @@ password: /* empty */
byte_size: NUMBER
;
host_port: NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA
host_port: NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA
NUMBER COMMA NUMBER
= {
register char *a, *p;
@ -610,9 +642,9 @@ pathname: pathstring
*/
if (logged_in && $1 && strncmp((char *) $1, "~", 1) == 0) {
*(char **)&($$) = *glob((char *) $1);
if (globerr != NULL) {
if (globerr != 0) {
reply(550, globerr);
$$ = NULL;
$$ = 0;
}
free((char *) $1);
} else
@ -661,8 +693,15 @@ check_login: /* empty */
%%
#ifdef YYBYACC
extern int YYLEX_DECL();
static void YYERROR_DECL();
#endif
extern jmp_buf errcatch;
static void upper(char *);
#define CMD 0 /* beginning of command */
#define ARGS 1 /* expect miscellaneous arguments */
#define STR1 2 /* expect SP followed by STRING */
@ -674,11 +713,11 @@ extern jmp_buf errcatch;
#define NSTR 8 /* Number followed by a string */
struct tab {
char *name;
const char *name;
short token;
short state;
short implemented; /* 1 if command is implemented */
char *help;
const char *help;
};
struct tab cmdtab[] = { /* In order defined in RFC 765 */
@ -729,7 +768,7 @@ struct tab cmdtab[] = { /* In order defined in RFC 765 */
{ "STOU", STOU, STR1, 1, "<sp> file-name" },
{ "SIZE", SIZE, OSTR, 1, "<sp> path-name" },
{ "MDTM", MDTM, OSTR, 1, "<sp> path-name" },
{ NULL, 0, 0, 0, 0 }
{ 0, 0, 0, 0, 0 }
};
struct tab sitetab[] = {
@ -737,16 +776,14 @@ struct tab sitetab[] = {
{ "IDLE", IDLE, ARGS, 1, "[ <sp> maximum-idle-time ]" },
{ "CHMOD", CHMOD, NSTR, 1, "<sp> mode <sp> file-name" },
{ "HELP", HELP, OSTR, 1, "[ <sp> <string> ]" },
{ NULL, 0, 0, 0, 0 }
{ 0, 0, 0, 0, 0 }
};
struct tab *
lookup(p, cmd)
register struct tab *p;
char *cmd;
static struct tab *
lookup(struct tab *p, char *cmd)
{
for (; p->name != NULL; p++)
for (; p->name != 0; p++)
if (strcmp(cmd, p->name) == 0)
return (p);
return (0);
@ -755,14 +792,12 @@ lookup(p, cmd)
#include <arpa/telnet.h>
/*
* getline - a hacked up version of fgets to ignore TELNET escape codes.
* get_line - a hacked up version of fgets to ignore TELNET escape codes.
*/
char *
getline(s, n, iop)
char *s;
register FILE *iop;
static char *
get_line(char *s, int n, FILE *iop)
{
register c;
register int c;
register char *cs;
cs = s;
@ -770,7 +805,7 @@ getline(s, n, iop)
for (c = 0; tmpline[c] != '\0' && --n > 0; ++c) {
*cs++ = tmpline[c];
if (tmpline[c] == '\n') {
*cs++ = '\0';
*cs = '\0';
if (debug)
syslog(LOG_DEBUG, "command: %s", s);
tmpline[0] = '\0';
@ -809,20 +844,19 @@ getline(s, n, iop)
break;
}
if (c == EOF && cs == s)
return (NULL);
*cs++ = '\0';
return (0);
*cs = '\0';
if (debug)
syslog(LOG_DEBUG, "command: %s", s);
return (s);
}
static int
toolong()
static void
toolong(int sig)
{
time_t now;
extern char *ctime();
extern time_t time();
(void) sig;
reply(421,
"Timeout (%d seconds): closing control connection.", timeout);
(void) time(&now);
@ -834,14 +868,14 @@ toolong()
dologout(1);
}
yylex()
int
yylex(void)
{
static int cpos, state;
register char *cp, *cp2;
register struct tab *p;
int n;
char c, *strpbrk();
char *copy();
char c;
for (;;) {
switch (state) {
@ -849,16 +883,16 @@ yylex()
case CMD:
(void) signal(SIGALRM, toolong);
(void) alarm((unsigned) timeout);
if (getline(cbuf, sizeof(cbuf)-1, stdin) == NULL) {
if (get_line(cbuf, sizeof(cbuf)-1, stdin) == 0) {
reply(221, "You could at least say goodbye.");
dologout(0);
}
(void) alarm(0);
#ifdef SETPROCTITLE
if (strncasecmp(cbuf, "PASS", 4) != NULL)
if (strncasecmp(cbuf, "PASS", 4) != 0)
setproctitle("%s: %s", proctitle, cbuf);
#endif /* SETPROCTITLE */
if ((cp = index(cbuf, '\r'))) {
if ((cp = strchr(cbuf, '\r'))) {
*cp++ = '\n';
*cp = '\0';
}
@ -878,7 +912,7 @@ yylex()
/* NOTREACHED */
}
state = p->state;
*(char **)&yylval = p->name;
*(const char **)(&yylval) = p->name;
return (p->token);
}
break;
@ -904,7 +938,7 @@ yylex()
/* NOTREACHED */
}
state = p->state;
*(char **)&yylval = p->name;
*(const char **)(&yylval) = p->name;
return (p->token);
}
state = CMD;
@ -922,7 +956,10 @@ yylex()
dostr1:
if (cbuf[cpos] == ' ') {
cpos++;
state = state == OSTR ? STR2 : ++state;
if (state == OSTR)
state = STR2;
else
++state;
return (SP);
}
break;
@ -1052,8 +1089,8 @@ yylex()
}
}
upper(s)
register char *s;
static void
upper(char *s)
{
while (*s != '\0') {
if (islower(*s))
@ -1062,34 +1099,32 @@ upper(s)
}
}
char *
copy(s)
char *s;
static char *
copy(const char *s)
{
char *p;
extern char *malloc(), *strcpy();
p = malloc((unsigned) strlen(s) + 1);
if (p == NULL)
p = (char * )malloc(strlen(s) + 1);
if (p == 0)
fatal("Ran out of memory.");
(void) strcpy(p, s);
else
(void) strcpy(p, s);
return (p);
}
help(ctab, s)
struct tab *ctab;
char *s;
static void
help(struct tab *ctab, char *s)
{
register struct tab *c;
register int width, NCMDS;
char *type;
const char *help_type;
if (ctab == sitetab)
type = "SITE ";
help_type = "SITE ";
else
type = "";
help_type = "";
width = 0, NCMDS = 0;
for (c = ctab; c->name != NULL; c++) {
for (c = ctab; c->name != 0; c++) {
int len = strlen(c->name);
if (len > width)
@ -1102,7 +1137,7 @@ help(ctab, s)
int columns, lines;
lreply(214, "The following %scommands are recognized %s.",
type, "(* =>'s unimplemented)");
help_type, "(* =>'s unimplemented)");
columns = 76 / width;
if (columns == 0)
columns = 1;
@ -1111,6 +1146,7 @@ help(ctab, s)
printf(" ");
for (j = 0; j < columns; j++) {
c = ctab + j * lines + i;
assert(c->name != 0);
printf("%s%c", c->name,
c->implemented ? ' ' : '*');
if (c + lines >= &ctab[NCMDS])
@ -1134,14 +1170,14 @@ help(ctab, s)
return;
}
if (c->implemented)
reply(214, "Syntax: %s%s %s", type, c->name, c->help);
reply(214, "Syntax: %s%s %s", help_type, c->name, c->help);
else
reply(214, "%s%-*s\t%s; unimplemented.", type, width,
reply(214, "%s%-*s\t%s; unimplemented.", help_type, width,
c->name, c->help);
}
sizecmd(filename)
char *filename;
static void
sizecmd(char *filename)
{
switch (type) {
case TYPE_L:
@ -1151,14 +1187,18 @@ char *filename;
(stbuf.st_mode&S_IFMT) != S_IFREG)
reply(550, "%s: not a plain file.", filename);
else
reply(213, "%llu", (long long)stbuf.st_size);
#ifdef HAVE_LONG_LONG
reply(213, "%llu", (long long) stbuf.st_size);
#else
reply(213, "%lu", stbuf.st_size);
#endif
break;}
case TYPE_A: {
FILE *fin;
register int c, count;
struct stat stbuf;
fin = fopen(filename, "r");
if (fin == NULL) {
if (fin == 0) {
perror_reply(550, filename);
return;
}

File diff suppressed because it is too large Load diff

2015
external/bsd/byacc/dist/test/grammar.tab.c vendored Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,37 @@
/* $NetBSD: grammar.tab.h,v 1.1.1.3 2011/09/10 21:22:05 christos Exp $ */
#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

1175
external/bsd/byacc/dist/test/grammar.y vendored Normal file

File diff suppressed because it is too large Load diff

Some files were not shown because too many files have changed in this diff Show more