Moved to src/external/bsd/byacc.
This commit is contained in:
parent
7915776d56
commit
170bc8c273
@ -1,25 +0,0 @@
|
||||
Berkeley Yacc owes much to the unflagging efforts of Keith Bostic.
|
||||
His badgering kept me working on it long after I was ready to quit.
|
||||
|
||||
Berkeley Yacc is based on the excellent algorithm for computing LALR(1)
|
||||
lookaheads developed by Tom Pennello and Frank DeRemer. The algorithm is
|
||||
described in their almost impenetrable article in TOPLAS 4,4.
|
||||
|
||||
Finally, much of the credit for the latest version must go to those
|
||||
who pointed out deficiencies of my earlier releases. Among the most
|
||||
prolific contributors were
|
||||
|
||||
Benson I. Margulies
|
||||
Dave Gentzel
|
||||
Antoine Verheijen
|
||||
Peter S. Housel
|
||||
Dale Smith
|
||||
Ozan Yigit
|
||||
John Campbell
|
||||
Bill Sommerfeld
|
||||
Paul Hilfinger
|
||||
Gary Bridgewater
|
||||
Dave Bakken
|
||||
Dan Lanciani
|
||||
Richard Sargent
|
||||
Parag Patel
|
@ -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>
|
@ -1,46 +0,0 @@
|
||||
The -r option has been implemented. The -r option tells Yacc to
|
||||
put the read-only tables in y.tab.c and the code and variables in
|
||||
y.code.c. Keith Bostic asked for this option so that :yyfix could be
|
||||
eliminated.
|
||||
|
||||
The -l and -t options have been implemented. The -l option tells
|
||||
Yacc not to include #line directives in the code it produces. The -t
|
||||
option causes debugging code to be included in the compiled parser.
|
||||
|
||||
The code for error recovery has been changed to implement the same
|
||||
algorithm as AT&T Yacc. There will still be differences in the way
|
||||
error recovery works because AT&T Yacc uses more default reductions
|
||||
than Berkeley Yacc.
|
||||
|
||||
The environment variable TMPDIR determines the directory where
|
||||
temporary files will be created. If TMPDIR is defined, temporary files
|
||||
will be created in the directory whose pathname is the value of TMPDIR.
|
||||
By default, temporary files are created in /tmp.
|
||||
|
||||
The keywords are now case-insensitive. For example, %nonassoc,
|
||||
%NONASSOC, %NonAssoc, and %nOnAsSoC are all equivalent.
|
||||
|
||||
Commas and semicolons that are not part of C code are treated as
|
||||
commentary.
|
||||
|
||||
Line-end comments, as in BCPL, are permitted. Line-end comments
|
||||
begin with // and end at the next end-of-line. Line-end comments are
|
||||
permitted in C code; they are converted to C comments on output.
|
||||
|
||||
The form of y.output files has been changed to look more like
|
||||
those produced by AT&T Yacc.
|
||||
|
||||
A new kind of declaration has been added. The form of the declaration
|
||||
is
|
||||
|
||||
%ident string
|
||||
|
||||
where string is a sequence of characters begining with a double quote
|
||||
and ending with either a double quote or the next end-of-line, whichever
|
||||
comes first. The declaration will cause a #ident directive to be written
|
||||
near the start of the output file.
|
||||
|
||||
If a parser has been compiled with debugging code, that code can be
|
||||
enabled by setting an environment variable. If the environment variable
|
||||
YYDEBUG is set to 0, debugging output is suppressed. If it is set to 1,
|
||||
debugging output is written to standard output.
|
@ -1,21 +0,0 @@
|
||||
$NetBSD: NOTES,v 1.3 1997/10/20 03:41:15 lukem Exp $
|
||||
|
||||
Berkeley Yacc reflects its origins. The reason so many routines
|
||||
use exactly six register variables is that Berkeley Yacc was
|
||||
developed on a VAX using PCC. PCC placed at most six variables
|
||||
in registers. I went to considerable effort to find which six
|
||||
variables most belonged in registers. Changes in machines and
|
||||
compilers make that effort worthless, perhaps even harmful.
|
||||
|
||||
[Given the previous paragraph, and the fact that GCC does not respect
|
||||
register declarations, and the fact that much of the rest of the
|
||||
4.4lite2 release had "register" declarations extirpated, I've removed
|
||||
most of the register declarations from the code. I left them in the
|
||||
generated skeleton code "for the hell of it" but they probably should
|
||||
go from there, too. -- pm, July 1997]
|
||||
|
||||
[I totally removed the register stuff; we've deprecated it elsewhere
|
||||
in the tree now -- lukem, October 1997]
|
||||
|
||||
The code contains many instances where address calculations are
|
||||
performed in particular ways to optimize the code for the VAX.
|
@ -1,23 +0,0 @@
|
||||
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.
|
@ -1,304 +0,0 @@
|
||||
/* $NetBSD: closure.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[] = "@(#)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 */
|
||||
|
||||
#include "defs.h"
|
||||
|
||||
short *itemset;
|
||||
short *itemsetend;
|
||||
unsigned *ruleset;
|
||||
|
||||
static unsigned *first_derives;
|
||||
static unsigned *EFF;
|
||||
|
||||
static void set_EFF(void);
|
||||
|
||||
static void
|
||||
set_EFF(void)
|
||||
{
|
||||
unsigned *row;
|
||||
int symbol;
|
||||
short *sp;
|
||||
int rowsize;
|
||||
int i;
|
||||
int rule;
|
||||
|
||||
rowsize = WORDSIZE(nvars);
|
||||
EFF = NEW2(nvars * rowsize, unsigned);
|
||||
|
||||
row = EFF;
|
||||
for (i = start_symbol; i < nsyms; i++)
|
||||
{
|
||||
sp = derives[i];
|
||||
for (rule = *sp; rule > 0; rule = *++sp)
|
||||
{
|
||||
symbol = ritem[rrhs[rule]];
|
||||
if (ISVAR(symbol))
|
||||
{
|
||||
symbol -= start_symbol;
|
||||
SETBIT(row, symbol);
|
||||
}
|
||||
}
|
||||
row += rowsize;
|
||||
}
|
||||
|
||||
reflexive_transitive_closure(EFF, nvars);
|
||||
|
||||
#ifdef DEBUG
|
||||
print_EFF();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
set_first_derives(void)
|
||||
{
|
||||
unsigned *rrow;
|
||||
unsigned *vrow;
|
||||
int j;
|
||||
unsigned k;
|
||||
unsigned cword;
|
||||
short *rp;
|
||||
|
||||
int rule;
|
||||
int i;
|
||||
int rulesetsize;
|
||||
int varsetsize;
|
||||
|
||||
cword = 0;
|
||||
|
||||
rulesetsize = WORDSIZE(nrules);
|
||||
varsetsize = WORDSIZE(nvars);
|
||||
first_derives = NEW2(nvars * rulesetsize, unsigned) - ntokens * rulesetsize;
|
||||
|
||||
set_EFF();
|
||||
|
||||
rrow = first_derives + ntokens * rulesetsize;
|
||||
for (i = start_symbol; i < nsyms; i++)
|
||||
{
|
||||
vrow = EFF + ((i - ntokens) * varsetsize);
|
||||
k = BITS_PER_WORD;
|
||||
for (j = start_symbol; j < nsyms; k++, j++)
|
||||
{
|
||||
if (k >= BITS_PER_WORD)
|
||||
{
|
||||
cword = *vrow++;
|
||||
k = 0;
|
||||
}
|
||||
|
||||
if (cword & (1 << k))
|
||||
{
|
||||
rp = derives[j];
|
||||
while ((rule = *rp++) >= 0)
|
||||
{
|
||||
SETBIT(rrow, rule);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vrow += varsetsize;
|
||||
rrow += rulesetsize;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
print_first_derives();
|
||||
#endif
|
||||
|
||||
FREE(EFF);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
closure(short *nucleus, int n)
|
||||
{
|
||||
int ruleno;
|
||||
unsigned word;
|
||||
unsigned i;
|
||||
short *csp;
|
||||
unsigned *dsp;
|
||||
unsigned *rsp;
|
||||
int rulesetsize;
|
||||
|
||||
short *csend;
|
||||
unsigned *rsend;
|
||||
int symbol;
|
||||
int itemno;
|
||||
|
||||
rulesetsize = WORDSIZE(nrules);
|
||||
rsp = ruleset;
|
||||
rsend = ruleset + rulesetsize;
|
||||
for (rsp = ruleset; rsp < rsend; rsp++)
|
||||
*rsp = 0;
|
||||
|
||||
csend = nucleus + n;
|
||||
for (csp = nucleus; csp < csend; ++csp)
|
||||
{
|
||||
symbol = ritem[*csp];
|
||||
if (ISVAR(symbol))
|
||||
{
|
||||
dsp = first_derives + symbol * rulesetsize;
|
||||
rsp = ruleset;
|
||||
while (rsp < rsend)
|
||||
*rsp++ |= *dsp++;
|
||||
}
|
||||
}
|
||||
|
||||
ruleno = 0;
|
||||
itemsetend = itemset;
|
||||
csp = nucleus;
|
||||
for (rsp = ruleset; rsp < rsend; ++rsp)
|
||||
{
|
||||
word = *rsp;
|
||||
if (word)
|
||||
{
|
||||
for (i = 0; i < BITS_PER_WORD; ++i)
|
||||
{
|
||||
if (word & (1 << i))
|
||||
{
|
||||
itemno = rrhs[ruleno+i];
|
||||
while (csp < csend && *csp < itemno)
|
||||
*itemsetend++ = *csp++;
|
||||
*itemsetend++ = itemno;
|
||||
while (csp < csend && *csp == itemno)
|
||||
++csp;
|
||||
}
|
||||
}
|
||||
}
|
||||
ruleno += BITS_PER_WORD;
|
||||
}
|
||||
|
||||
while (csp < csend)
|
||||
*itemsetend++ = *csp++;
|
||||
|
||||
#ifdef DEBUG
|
||||
print_closure(n);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
finalize_closure(void)
|
||||
{
|
||||
FREE(itemset);
|
||||
FREE(ruleset);
|
||||
FREE(first_derives + ntokens * WORDSIZE(nrules));
|
||||
}
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
void
|
||||
print_closure(int n)
|
||||
{
|
||||
short *isp;
|
||||
|
||||
printf("\n\nn = %d\n\n", n);
|
||||
for (isp = itemset; isp < itemsetend; isp++)
|
||||
printf(" %d\n", *isp);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
print_EFF(void)
|
||||
{
|
||||
int i, j;
|
||||
unsigned *rowp;
|
||||
unsigned word;
|
||||
unsigned k;
|
||||
|
||||
printf("\n\nEpsilon Free Firsts\n");
|
||||
|
||||
for (i = start_symbol; i < nsyms; i++)
|
||||
{
|
||||
printf("\n%s", symbol_name[i]);
|
||||
rowp = EFF + ((i - start_symbol) * WORDSIZE(nvars));
|
||||
word = *rowp++;
|
||||
|
||||
k = BITS_PER_WORD;
|
||||
for (j = 0; j < nvars; k++, j++)
|
||||
{
|
||||
if (k >= BITS_PER_WORD)
|
||||
{
|
||||
word = *rowp++;
|
||||
k = 0;
|
||||
}
|
||||
|
||||
if (word & (1 << k))
|
||||
printf(" %s", symbol_name[start_symbol + j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
print_first_derives(void)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
unsigned *rp;
|
||||
unsigned cword;
|
||||
unsigned k;
|
||||
|
||||
printf("\n\n\nFirst Derives\n");
|
||||
|
||||
for (i = start_symbol; i < nsyms; i++)
|
||||
{
|
||||
printf("\n%s derives\n", symbol_name[i]);
|
||||
rp = first_derives + i * WORDSIZE(nrules);
|
||||
k = BITS_PER_WORD;
|
||||
for (j = 0; j <= nrules; k++, j++)
|
||||
{
|
||||
if (k >= BITS_PER_WORD)
|
||||
{
|
||||
cword = *rp++;
|
||||
k = 0;
|
||||
}
|
||||
|
||||
if (cword & (1 << k))
|
||||
printf(" %d\n", j);
|
||||
}
|
||||
}
|
||||
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
#endif
|
@ -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);
|
@ -1,317 +0,0 @@
|
||||
/* $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 */
|
||||
|
||||
#include "defs.h"
|
||||
|
||||
__dead void
|
||||
fatal(const char *msg)
|
||||
{
|
||||
fprintf(stderr, "%s: f - %s\n", myname, msg);
|
||||
done(2);
|
||||
}
|
||||
|
||||
|
||||
__dead void
|
||||
no_space(void)
|
||||
{
|
||||
fprintf(stderr, "%s: f - out of space\n", myname);
|
||||
done(2);
|
||||
}
|
||||
|
||||
__dead void
|
||||
open_error(const char *filename)
|
||||
{
|
||||
fprintf(stderr, "%s: f - cannot open \"%s\"\n", myname, filename);
|
||||
done(2);
|
||||
}
|
||||
|
||||
__dead void
|
||||
unexpected_EOF(void)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", unexpected end-of-file\n",
|
||||
myname, lineno, input_file_name);
|
||||
done(1);
|
||||
}
|
||||
|
||||
void
|
||||
print_pos(char *st_line, char *st_cptr)
|
||||
{
|
||||
char *s;
|
||||
|
||||
if (st_line == 0) return;
|
||||
for (s = st_line; *s != '\n'; ++s)
|
||||
{
|
||||
if (isprint((unsigned char)*s) || *s == '\t')
|
||||
putc(*s, stderr);
|
||||
else
|
||||
putc('?', stderr);
|
||||
}
|
||||
putc('\n', stderr);
|
||||
for (s = st_line; s < st_cptr; ++s)
|
||||
{
|
||||
if (*s == '\t')
|
||||
putc('\t', stderr);
|
||||
else
|
||||
putc(' ', stderr);
|
||||
}
|
||||
putc('^', stderr);
|
||||
putc('\n', stderr);
|
||||
}
|
||||
|
||||
__dead void
|
||||
syntax_error(int st_lineno, char *st_line, char *st_cptr)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", syntax error\n",
|
||||
myname, st_lineno, input_file_name);
|
||||
print_pos(st_line, st_cptr);
|
||||
done(1);
|
||||
}
|
||||
|
||||
__dead void
|
||||
unterminated_comment(int c_lineno, char *c_line, char *c_cptr)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", unmatched /*\n",
|
||||
myname, c_lineno, input_file_name);
|
||||
print_pos(c_line, c_cptr);
|
||||
done(1);
|
||||
}
|
||||
|
||||
__dead void
|
||||
unterminated_string(int s_lineno, char *s_line, char *s_cptr)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", unterminated string\n",
|
||||
myname, s_lineno, input_file_name);
|
||||
print_pos(s_line, s_cptr);
|
||||
done(1);
|
||||
}
|
||||
|
||||
__dead void
|
||||
unterminated_text(int t_lineno, char *t_line, char *t_cptr)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", unmatched %%{\n",
|
||||
myname, t_lineno, input_file_name);
|
||||
print_pos(t_line, t_cptr);
|
||||
done(1);
|
||||
}
|
||||
|
||||
__dead void
|
||||
unterminated_union(int u_lineno, char *u_line, char *u_cptr)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", unterminated %%union \
|
||||
declaration\n", myname, u_lineno, input_file_name);
|
||||
print_pos(u_line, u_cptr);
|
||||
done(1);
|
||||
}
|
||||
|
||||
__dead void
|
||||
over_unionized(char *u_cptr)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", too many %%union \
|
||||
declarations\n", myname, lineno, input_file_name);
|
||||
print_pos(line, u_cptr);
|
||||
done(1);
|
||||
}
|
||||
|
||||
__dead void
|
||||
illegal_tag(int t_lineno, char *t_line, char *t_cptr)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", illegal tag\n",
|
||||
myname, t_lineno, input_file_name);
|
||||
print_pos(t_line, t_cptr);
|
||||
done(1);
|
||||
}
|
||||
|
||||
__dead void
|
||||
illegal_character(char *c_cptr)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", illegal character\n",
|
||||
myname, lineno, input_file_name);
|
||||
print_pos(line, c_cptr);
|
||||
done(1);
|
||||
}
|
||||
|
||||
__dead void
|
||||
used_reserved(char *s)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", illegal use of reserved symbol \
|
||||
%s\n", myname, lineno, input_file_name, s);
|
||||
done(1);
|
||||
}
|
||||
|
||||
__dead void
|
||||
tokenized_start(char *s)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", the start symbol %s cannot be \
|
||||
declared to be a token\n", myname, lineno, input_file_name, s);
|
||||
done(1);
|
||||
}
|
||||
|
||||
void
|
||||
retyped_warning(char *s)
|
||||
{
|
||||
fprintf(stderr, "%s: w - line %d of \"%s\", the type of %s has been \
|
||||
redeclared\n", myname, lineno, input_file_name, s);
|
||||
}
|
||||
|
||||
void
|
||||
reprec_warning(char *s)
|
||||
{
|
||||
fprintf(stderr, "%s: w - line %d of \"%s\", the precedence of %s has been \
|
||||
redeclared\n", myname, lineno, input_file_name, s);
|
||||
}
|
||||
|
||||
void
|
||||
revalued_warning(char *s)
|
||||
{
|
||||
fprintf(stderr, "%s: w - line %d of \"%s\", the value of %s has been \
|
||||
redeclared\n", myname, lineno, input_file_name, s);
|
||||
}
|
||||
|
||||
__dead void
|
||||
terminal_start(char *s)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", the start symbol %s is a \
|
||||
token\n", myname, lineno, input_file_name, s);
|
||||
done(1);
|
||||
}
|
||||
|
||||
void
|
||||
restarted_warning(void)
|
||||
{
|
||||
fprintf(stderr, "%s: w - line %d of \"%s\", the start symbol has been \
|
||||
redeclared\n", myname, lineno, input_file_name);
|
||||
}
|
||||
|
||||
__dead void
|
||||
no_grammar(void)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", no grammar has been \
|
||||
specified\n", myname, lineno, input_file_name);
|
||||
done(1);
|
||||
}
|
||||
|
||||
__dead void
|
||||
terminal_lhs(int s_lineno)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", a token appears on the lhs \
|
||||
of a production\n", myname, s_lineno, input_file_name);
|
||||
done(1);
|
||||
}
|
||||
|
||||
void
|
||||
prec_redeclared(void)
|
||||
{
|
||||
fprintf(stderr, "%s: w - line %d of \"%s\", conflicting %%prec \
|
||||
specifiers\n", myname, lineno, input_file_name);
|
||||
}
|
||||
|
||||
__dead void
|
||||
unterminated_action(int a_lineno, char *a_line, char *a_cptr)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", unterminated action\n",
|
||||
myname, a_lineno, input_file_name);
|
||||
print_pos(a_line, a_cptr);
|
||||
done(1);
|
||||
}
|
||||
|
||||
void
|
||||
dollar_warning(int a_lineno, int i)
|
||||
{
|
||||
fprintf(stderr, "%s: w - line %d of \"%s\", $%d references beyond the \
|
||||
end of the current rule\n", myname, a_lineno, input_file_name, i);
|
||||
}
|
||||
|
||||
__dead void
|
||||
dollar_error(int a_lineno, char *a_line, char *a_cptr)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", illegal $-name\n",
|
||||
myname, a_lineno, input_file_name);
|
||||
print_pos(a_line, a_cptr);
|
||||
done(1);
|
||||
}
|
||||
|
||||
__dead void
|
||||
untyped_lhs(void)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", $$ is untyped\n",
|
||||
myname, lineno, input_file_name);
|
||||
done(1);
|
||||
}
|
||||
|
||||
__dead void
|
||||
untyped_rhs(int i, char *s)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", $%d (%s) is untyped\n",
|
||||
myname, lineno, input_file_name, i, s);
|
||||
done(1);
|
||||
}
|
||||
|
||||
__dead void
|
||||
unknown_rhs(int i)
|
||||
{
|
||||
fprintf(stderr, "%s: e - line %d of \"%s\", $%d is untyped\n",
|
||||
myname, lineno, input_file_name, i);
|
||||
done(1);
|
||||
}
|
||||
|
||||
void
|
||||
default_action_warning(void)
|
||||
{
|
||||
fprintf(stderr, "%s: w - line %d of \"%s\", the default action assigns an \
|
||||
undefined value to $$\n", myname, lineno, input_file_name);
|
||||
}
|
||||
|
||||
__dead void
|
||||
undefined_goal(char *s)
|
||||
{
|
||||
fprintf(stderr, "%s: e - the start symbol %s is undefined\n", myname, s);
|
||||
done(1);
|
||||
}
|
||||
|
||||
void
|
||||
undefined_symbol_warning(char *s)
|
||||
{
|
||||
fprintf(stderr, "%s: w - the symbol %s is undefined\n", myname, s);
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
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++;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,678 +0,0 @@
|
||||
/* $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 */
|
||||
|
||||
#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);
|
||||
|
||||
static void allocate_itemsets(void);
|
||||
static void allocate_storage(void);
|
||||
static void append_states(void);
|
||||
static void free_storage(void);
|
||||
static void generate_states(void);
|
||||
static void initialize_states(void);
|
||||
static void new_itemsets(void);
|
||||
#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 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
|
||||
|
||||
static core **state_set;
|
||||
static core *this_state;
|
||||
static core *last_state;
|
||||
static shifts *last_shift;
|
||||
static reductions *last_reduction;
|
||||
|
||||
static int nshifts;
|
||||
static short *shift_symbol;
|
||||
|
||||
static short *redset;
|
||||
static short *shiftset;
|
||||
|
||||
static short **kernel_base;
|
||||
static short **kernel_end;
|
||||
static short *kernel_items;
|
||||
|
||||
static void
|
||||
allocate_itemsets(void)
|
||||
{
|
||||
short *itemp;
|
||||
short *item_end;
|
||||
int symbol;
|
||||
int i;
|
||||
int count;
|
||||
int max;
|
||||
short *symbol_count;
|
||||
|
||||
count = 0;
|
||||
symbol_count = NEW2(nsyms, short);
|
||||
|
||||
item_end = ritem + nitems;
|
||||
for (itemp = ritem; itemp < item_end; itemp++)
|
||||
{
|
||||
symbol = *itemp;
|
||||
if (symbol >= 0)
|
||||
{
|
||||
count++;
|
||||
symbol_count[symbol]++;
|
||||
}
|
||||
}
|
||||
|
||||
kernel_base = NEW2(nsyms, short *);
|
||||
kernel_items = NEW2(count, short);
|
||||
|
||||
count = 0;
|
||||
max = 0;
|
||||
for (i = 0; i < nsyms; i++)
|
||||
{
|
||||
kernel_base[i] = kernel_items + count;
|
||||
count += symbol_count[i];
|
||||
if (max < symbol_count[i])
|
||||
max = symbol_count[i];
|
||||
}
|
||||
|
||||
shift_symbol = symbol_count;
|
||||
kernel_end = NEW2(nsyms, short *);
|
||||
}
|
||||
|
||||
static void
|
||||
allocate_storage(void)
|
||||
{
|
||||
allocate_itemsets();
|
||||
shiftset = NEW2(nsyms, short);
|
||||
redset = NEW2(nrules + 1, short);
|
||||
state_set = NEW2(nitems, core *);
|
||||
}
|
||||
|
||||
static void
|
||||
append_states(void)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int symbol;
|
||||
|
||||
#ifdef TRACE
|
||||
fprintf(stderr, "Entering append_states()\n");
|
||||
#endif
|
||||
for (i = 1; i < nshifts; i++)
|
||||
{
|
||||
symbol = shift_symbol[i];
|
||||
j = i;
|
||||
while (j > 0 && shift_symbol[j - 1] > symbol)
|
||||
{
|
||||
shift_symbol[j] = shift_symbol[j - 1];
|
||||
j--;
|
||||
}
|
||||
shift_symbol[j] = symbol;
|
||||
}
|
||||
|
||||
for (i = 0; i < nshifts; i++)
|
||||
{
|
||||
symbol = shift_symbol[i];
|
||||
shiftset[i] = get_state(symbol);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
free_storage(void)
|
||||
{
|
||||
FREE(shift_symbol);
|
||||
FREE(redset);
|
||||
FREE(shiftset);
|
||||
FREE(kernel_base);
|
||||
FREE(kernel_end);
|
||||
FREE(kernel_items);
|
||||
FREE(state_set);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
generate_states(void)
|
||||
{
|
||||
allocate_storage();
|
||||
itemset = NEW2(nitems, short);
|
||||
ruleset = NEW2(WORDSIZE(nrules), unsigned);
|
||||
set_first_derives();
|
||||
initialize_states();
|
||||
|
||||
while (this_state)
|
||||
{
|
||||
closure(this_state->items, this_state->nitems);
|
||||
save_reductions();
|
||||
new_itemsets();
|
||||
append_states();
|
||||
|
||||
if (nshifts > 0)
|
||||
save_shifts();
|
||||
|
||||
this_state = this_state->next;
|
||||
}
|
||||
|
||||
finalize_closure();
|
||||
free_storage();
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int
|
||||
get_state(int symbol)
|
||||
{
|
||||
int key;
|
||||
short *isp1;
|
||||
short *isp2;
|
||||
short *iend;
|
||||
core *sp;
|
||||
int found;
|
||||
int n;
|
||||
|
||||
#ifdef TRACE
|
||||
fprintf(stderr, "Entering get_state(%d)\n", symbol);
|
||||
#endif
|
||||
|
||||
isp1 = kernel_base[symbol];
|
||||
iend = kernel_end[symbol];
|
||||
n = iend - isp1;
|
||||
|
||||
key = *isp1;
|
||||
assert(0 <= key && key < nitems);
|
||||
sp = state_set[key];
|
||||
if (sp)
|
||||
{
|
||||
found = 0;
|
||||
while (!found)
|
||||
{
|
||||
if (sp->nitems == n)
|
||||
{
|
||||
found = 1;
|
||||
isp1 = kernel_base[symbol];
|
||||
isp2 = sp->items;
|
||||
|
||||
while (found && isp1 < iend)
|
||||
{
|
||||
if (*isp1++ != *isp2++)
|
||||
found = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
if (sp->link)
|
||||
{
|
||||
sp = sp->link;
|
||||
}
|
||||
else
|
||||
{
|
||||
sp = sp->link = new_state(symbol);
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
state_set[key] = sp = new_state(symbol);
|
||||
}
|
||||
|
||||
return (sp->number);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
initialize_states(void)
|
||||
{
|
||||
int i;
|
||||
short *start_derives;
|
||||
core *p;
|
||||
|
||||
start_derives = derives[start_symbol];
|
||||
for (i = 0; start_derives[i] >= 0; ++i)
|
||||
continue;
|
||||
|
||||
p = (core *) MALLOC(sizeof(core) + i*sizeof(short));
|
||||
if (p == 0) no_space();
|
||||
|
||||
p->next = 0;
|
||||
p->link = 0;
|
||||
p->number = 0;
|
||||
p->accessing_symbol = 0;
|
||||
p->nitems = 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;
|
||||
int shiftcount;
|
||||
short *isp;
|
||||
short *ksp;
|
||||
int symbol;
|
||||
|
||||
for (i = 0; i < nsyms; i++)
|
||||
kernel_end[i] = 0;
|
||||
|
||||
shiftcount = 0;
|
||||
isp = itemset;
|
||||
while (isp < itemsetend)
|
||||
{
|
||||
i = *isp++;
|
||||
symbol = ritem[i];
|
||||
if (symbol > 0)
|
||||
{
|
||||
ksp = kernel_end[symbol];
|
||||
if (!ksp)
|
||||
{
|
||||
shift_symbol[shiftcount++] = symbol;
|
||||
ksp = kernel_base[symbol];
|
||||
}
|
||||
|
||||
*ksp++ = i + 1;
|
||||
kernel_end[symbol] = ksp;
|
||||
}
|
||||
}
|
||||
|
||||
nshifts = shiftcount;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static core *
|
||||
new_state(int symbol)
|
||||
{
|
||||
int n;
|
||||
core *p;
|
||||
short *isp1;
|
||||
short *isp2;
|
||||
short *iend;
|
||||
|
||||
#ifdef TRACE
|
||||
fprintf(stderr, "Entering new_state(%d)\n", symbol);
|
||||
#endif
|
||||
|
||||
if (nstates >= MAXSHORT)
|
||||
fatal("too many states");
|
||||
|
||||
isp1 = kernel_base[symbol];
|
||||
iend = kernel_end[symbol];
|
||||
n = iend - isp1;
|
||||
|
||||
p = (core *) allocate((unsigned) (sizeof(core) + (n - 1) * sizeof(short)));
|
||||
p->accessing_symbol = symbol;
|
||||
p->number = nstates;
|
||||
p->nitems = n;
|
||||
|
||||
isp2 = p->items;
|
||||
while (isp1 < iend)
|
||||
*isp2++ = *isp1++;
|
||||
|
||||
last_state->next = p;
|
||||
last_state = p;
|
||||
|
||||
nstates++;
|
||||
|
||||
return (p);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
/* show_cores is used for debugging */
|
||||
static void
|
||||
show_cores(void)
|
||||
{
|
||||
core *p;
|
||||
int i, j, k, n;
|
||||
int itemno;
|
||||
|
||||
k = 0;
|
||||
for (p = first_state; p; ++k, p = p->next)
|
||||
{
|
||||
if (k) printf("\n");
|
||||
printf("state %d, number = %d, accessing symbol = %s\n",
|
||||
k, p->number, symbol_name[p->accessing_symbol]);
|
||||
n = p->nitems;
|
||||
for (i = 0; i < n; ++i)
|
||||
{
|
||||
itemno = p->items[i];
|
||||
printf("%4d ", itemno);
|
||||
j = itemno;
|
||||
while (ritem[j] >= 0) ++j;
|
||||
printf("%s :", symbol_name[rlhs[-ritem[j]]]);
|
||||
j = rrhs[-ritem[j]];
|
||||
while (j < itemno)
|
||||
printf(" %s", symbol_name[ritem[j++]]);
|
||||
printf(" .");
|
||||
while (ritem[j] >= 0)
|
||||
printf(" %s", symbol_name[ritem[j++]]);
|
||||
printf("\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* show_ritems is used for debugging */
|
||||
static void
|
||||
show_ritems(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nitems; ++i)
|
||||
printf("ritem[%d] = %d\n", i, ritem[i]);
|
||||
}
|
||||
|
||||
|
||||
/* show_rrhs is used for debugging */
|
||||
static void
|
||||
show_rrhs(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nrules; ++i)
|
||||
printf("rrhs[%d] = %d\n", i, rrhs[i]);
|
||||
}
|
||||
|
||||
|
||||
/* show_shifts is used for debugging */
|
||||
static void
|
||||
show_shifts(void)
|
||||
{
|
||||
shifts *p;
|
||||
int i, j, k;
|
||||
|
||||
k = 0;
|
||||
for (p = first_shift; p; ++k, p = p->next)
|
||||
{
|
||||
if (k) printf("\n");
|
||||
printf("shift %d, number = %d, nshifts = %d\n", k, p->number,
|
||||
p->nshifts);
|
||||
j = p->nshifts;
|
||||
for (i = 0; i < j; ++i)
|
||||
printf("\t%d\n", p->shift[i]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static void
|
||||
save_shifts(void)
|
||||
{
|
||||
shifts *p;
|
||||
short *sp1;
|
||||
short *sp2;
|
||||
short *send;
|
||||
|
||||
p = (shifts *) allocate((unsigned) (sizeof(shifts) +
|
||||
(nshifts - 1) * sizeof(short)));
|
||||
|
||||
p->number = this_state->number;
|
||||
p->nshifts = nshifts;
|
||||
|
||||
sp1 = shiftset;
|
||||
sp2 = p->shift;
|
||||
send = shiftset + nshifts;
|
||||
|
||||
while (sp1 < send)
|
||||
*sp2++ = *sp1++;
|
||||
|
||||
if (last_shift)
|
||||
{
|
||||
last_shift->next = p;
|
||||
last_shift = p;
|
||||
}
|
||||
else
|
||||
{
|
||||
first_shift = p;
|
||||
last_shift = p;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
save_reductions(void)
|
||||
{
|
||||
short *isp;
|
||||
short *rp1;
|
||||
short *rp2;
|
||||
int item;
|
||||
int count;
|
||||
reductions *p;
|
||||
short *rend;
|
||||
|
||||
count = 0;
|
||||
for (isp = itemset; isp < itemsetend; isp++)
|
||||
{
|
||||
item = ritem[*isp];
|
||||
if (item < 0)
|
||||
{
|
||||
redset[count++] = -item;
|
||||
}
|
||||
}
|
||||
|
||||
if (count)
|
||||
{
|
||||
p = (reductions *) allocate((unsigned) (sizeof(reductions) +
|
||||
(count - 1) * sizeof(short)));
|
||||
|
||||
p->number = this_state->number;
|
||||
p->nreds = count;
|
||||
|
||||
rp1 = redset;
|
||||
rp2 = p->rules;
|
||||
rend = rp1 + count;
|
||||
|
||||
while (rp1 < rend)
|
||||
*rp2++ = *rp1++;
|
||||
|
||||
if (last_reduction)
|
||||
{
|
||||
last_reduction->next = p;
|
||||
last_reduction = p;
|
||||
}
|
||||
else
|
||||
{
|
||||
first_reduction = p;
|
||||
last_reduction = p;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
set_derives(void)
|
||||
{
|
||||
int i, k;
|
||||
int lhs;
|
||||
short *rules;
|
||||
|
||||
derives = NEW2(nsyms, short *);
|
||||
if (start_symbol >= nsyms)
|
||||
return;
|
||||
|
||||
rules = NEW2(nvars + nrules, short);
|
||||
|
||||
k = 0;
|
||||
for (lhs = start_symbol; lhs < nsyms; lhs++)
|
||||
{
|
||||
derives[lhs] = rules + k;
|
||||
for (i = 0; i < nrules; i++)
|
||||
{
|
||||
if (rlhs[i] == lhs)
|
||||
{
|
||||
rules[k] = i;
|
||||
k++;
|
||||
}
|
||||
}
|
||||
rules[k] = -1;
|
||||
k++;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
print_derives();
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
static void
|
||||
free_derives(void)
|
||||
{
|
||||
FREE(derives[start_symbol]);
|
||||
FREE(derives);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
static void
|
||||
print_derives(void)
|
||||
{
|
||||
int i;
|
||||
short *sp;
|
||||
|
||||
printf("\nDERIVES\n\n");
|
||||
|
||||
for (i = start_symbol; i < nsyms; i++)
|
||||
{
|
||||
printf("%s derives ", symbol_name[i]);
|
||||
for (sp = derives[i]; *sp >= 0; sp++)
|
||||
{
|
||||
printf(" %d", *sp);
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
putchar('\n');
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static void
|
||||
set_nullable(void)
|
||||
{
|
||||
int i, j;
|
||||
int empty;
|
||||
int isdone;
|
||||
|
||||
nullable = MALLOC(nsyms);
|
||||
if (nullable == 0) no_space();
|
||||
|
||||
for (i = 0; i < nsyms; ++i)
|
||||
nullable[i] = 0;
|
||||
|
||||
isdone = 0;
|
||||
while (!isdone)
|
||||
{
|
||||
isdone = 1;
|
||||
for (i = 1; i < nitems; i++)
|
||||
{
|
||||
empty = 1;
|
||||
while ((j = ritem[i]) >= 0)
|
||||
{
|
||||
if (!nullable[j])
|
||||
empty = 0;
|
||||
++i;
|
||||
}
|
||||
if (empty)
|
||||
{
|
||||
j = rlhs[-j];
|
||||
if (!nullable[j])
|
||||
{
|
||||
nullable[j] = 1;
|
||||
isdone = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
for (i = 0; i < nsyms; i++)
|
||||
{
|
||||
if (nullable[i])
|
||||
printf("%s is nullable\n", symbol_name[i]);
|
||||
else
|
||||
printf("%s is not nullable\n", symbol_name[i]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
static void
|
||||
free_nullable(void)
|
||||
{
|
||||
FREE(nullable);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void
|
||||
lr0(void)
|
||||
{
|
||||
set_derives();
|
||||
set_nullable();
|
||||
generate_states();
|
||||
}
|
@ -1,474 +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)
|
||||
{
|
||||
asprintf(&output_file_name, "%s%s", file_prefix, OUTPUT_SUFFIX);
|
||||
if (output_file_name == 0)
|
||||
no_space();
|
||||
}
|
||||
|
||||
if (rflag)
|
||||
{
|
||||
asprintf(&code_file_name, "%s%s", file_prefix, CODE_SUFFIX);
|
||||
if (code_file_name == 0)
|
||||
no_space();
|
||||
}
|
||||
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
|
||||
{
|
||||
asprintf(&defines_file_name, "%s%s", file_prefix, DEFINES_SUFFIX);
|
||||
if (defines_file_name == 0)
|
||||
no_space();
|
||||
}
|
||||
}
|
||||
|
||||
if (vflag)
|
||||
{
|
||||
asprintf(&verbose_file_name, "%s%s", file_prefix, VERBOSE_SUFFIX);
|
||||
if (verbose_file_name == 0)
|
||||
no_space();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
@ -1,413 +0,0 @@
|
||||
/* $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 */
|
||||
|
||||
#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 *);
|
||||
|
||||
static void find_final_state(void);
|
||||
static void unused_rules(void);
|
||||
static void remove_conflicts(void);
|
||||
static void total_conflicts(void);
|
||||
static void defreds(void);
|
||||
|
||||
|
||||
void
|
||||
make_parser(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
parser = NEW2(nstates, action *);
|
||||
for (i = 0; i < nstates; i++)
|
||||
parser[i] = parse_actions(i);
|
||||
|
||||
find_final_state();
|
||||
remove_conflicts();
|
||||
unused_rules();
|
||||
if (SRtotal + RRtotal > 0) total_conflicts();
|
||||
defreds();
|
||||
}
|
||||
|
||||
|
||||
static action *
|
||||
parse_actions(int stateno)
|
||||
{
|
||||
action *actions;
|
||||
|
||||
actions = get_shifts(stateno);
|
||||
actions = add_reductions(stateno, actions);
|
||||
return (actions);
|
||||
}
|
||||
|
||||
|
||||
static action *
|
||||
get_shifts(int stateno)
|
||||
{
|
||||
action *actions, *temp;
|
||||
shifts *sp;
|
||||
short *state;
|
||||
int i, k;
|
||||
int symbol;
|
||||
|
||||
actions = 0;
|
||||
sp = shift_table[stateno];
|
||||
if (sp)
|
||||
{
|
||||
state = sp->shift;
|
||||
for (i = sp->nshifts - 1; i >= 0; i--)
|
||||
{
|
||||
k = state[i];
|
||||
symbol = accessing_symbol[k];
|
||||
if (ISTOKEN(symbol))
|
||||
{
|
||||
temp = NEW(action);
|
||||
temp->next = actions;
|
||||
temp->symbol = symbol;
|
||||
temp->number = k;
|
||||
temp->prec = symbol_prec[symbol];
|
||||
temp->action_code = SHIFT;
|
||||
temp->assoc = symbol_assoc[symbol];
|
||||
actions = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (actions);
|
||||
}
|
||||
|
||||
static action *
|
||||
add_reductions(int stateno, action *actions)
|
||||
{
|
||||
int i, j, m, n;
|
||||
int ruleno, tokensetsize;
|
||||
unsigned *rowp;
|
||||
|
||||
tokensetsize = WORDSIZE(ntokens);
|
||||
m = lookaheads[stateno];
|
||||
n = lookaheads[stateno + 1];
|
||||
for (i = m; i < n; i++)
|
||||
{
|
||||
ruleno = LAruleno[i];
|
||||
rowp = LA + i * tokensetsize;
|
||||
for (j = ntokens - 1; j >= 0; j--)
|
||||
{
|
||||
if (BIT(rowp, j))
|
||||
actions = add_reduce(actions, ruleno, j);
|
||||
}
|
||||
}
|
||||
return (actions);
|
||||
}
|
||||
|
||||
|
||||
static action *
|
||||
add_reduce(action *actions, int ruleno, int symbol)
|
||||
{
|
||||
action *temp, *prev, *next;
|
||||
|
||||
prev = 0;
|
||||
for (next = actions; next && next->symbol < symbol; next = next->next)
|
||||
prev = next;
|
||||
|
||||
while (next && next->symbol == symbol && next->action_code == SHIFT)
|
||||
{
|
||||
prev = next;
|
||||
next = next->next;
|
||||
}
|
||||
|
||||
while (next && next->symbol == symbol &&
|
||||
next->action_code == REDUCE && next->number < ruleno)
|
||||
{
|
||||
prev = next;
|
||||
next = next->next;
|
||||
}
|
||||
|
||||
temp = NEW(action);
|
||||
temp->next = next;
|
||||
temp->symbol = symbol;
|
||||
temp->number = ruleno;
|
||||
temp->prec = rprec[ruleno];
|
||||
temp->action_code = REDUCE;
|
||||
temp->assoc = rassoc[ruleno];
|
||||
|
||||
if (prev)
|
||||
prev->next = temp;
|
||||
else
|
||||
actions = temp;
|
||||
|
||||
return (actions);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
find_final_state(void)
|
||||
{
|
||||
int goal, i;
|
||||
short *state;
|
||||
shifts *p;
|
||||
|
||||
p = shift_table[0];
|
||||
state = p->shift;
|
||||
goal = ritem[1];
|
||||
for (i = p->nshifts - 1; i >= 0; --i)
|
||||
{
|
||||
final_state = state[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();
|
||||
|
||||
for (i = 0; i < nrules; ++i)
|
||||
rules_used[i] = 0;
|
||||
|
||||
for (i = 0; i < nstates; ++i)
|
||||
{
|
||||
for (p = parser[i]; p; p = p->next)
|
||||
{
|
||||
if (p->action_code == REDUCE && p->suppressed == 0)
|
||||
rules_used[p->number] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
nunused = 0;
|
||||
for (i = 3; i < nrules; ++i)
|
||||
if (!rules_used[i]) ++nunused;
|
||||
|
||||
if (nunused) {
|
||||
if (nunused == 1)
|
||||
fprintf(stderr, "%s: 1 rule never reduced\n", myname);
|
||||
else
|
||||
fprintf(stderr, "%s: %d rules never reduced\n", myname, nunused);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
remove_conflicts(void)
|
||||
{
|
||||
int i;
|
||||
int symbol;
|
||||
action *p, *pref;
|
||||
|
||||
pref = NULL;
|
||||
SRtotal = 0;
|
||||
RRtotal = 0;
|
||||
SRconflicts = NEW2(nstates, short);
|
||||
RRconflicts = NEW2(nstates, short);
|
||||
for (i = 0; i < nstates; i++)
|
||||
{
|
||||
SRcount = 0;
|
||||
RRcount = 0;
|
||||
symbol = -1;
|
||||
for (p = parser[i]; p; p = p->next)
|
||||
{
|
||||
if (p->symbol != symbol)
|
||||
{
|
||||
pref = p;
|
||||
symbol = p->symbol;
|
||||
}
|
||||
else if (i == final_state && symbol == 0)
|
||||
{
|
||||
SRcount++;
|
||||
p->suppressed = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(pref != NULL);
|
||||
if (pref->action_code == SHIFT)
|
||||
{
|
||||
if (pref->prec > 0 && p->prec > 0)
|
||||
{
|
||||
if (pref->prec < p->prec)
|
||||
{
|
||||
pref->suppressed = 2;
|
||||
pref = p;
|
||||
}
|
||||
else if (pref->prec > p->prec)
|
||||
{
|
||||
p->suppressed = 2;
|
||||
}
|
||||
else if (pref->assoc == LEFT)
|
||||
{
|
||||
pref->suppressed = 2;
|
||||
pref = p;
|
||||
}
|
||||
else if (pref->assoc == RIGHT)
|
||||
{
|
||||
p->suppressed = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
pref->suppressed = 2;
|
||||
p->suppressed = 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SRcount++;
|
||||
p->suppressed = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RRcount++;
|
||||
p->suppressed = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
SRtotal += SRcount;
|
||||
RRtotal += RRcount;
|
||||
SRconflicts[i] = SRcount;
|
||||
RRconflicts[i] = RRcount;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
total_conflicts(void)
|
||||
{
|
||||
fprintf(stderr, "%s: ", myname);
|
||||
if (SRtotal == 1)
|
||||
fprintf(stderr, "1 shift/reduce conflict");
|
||||
else if (SRtotal > 1)
|
||||
fprintf(stderr, "%d shift/reduce conflicts", SRtotal);
|
||||
|
||||
if (SRtotal && RRtotal)
|
||||
fprintf(stderr, ", ");
|
||||
|
||||
if (RRtotal == 1)
|
||||
fprintf(stderr, "1 reduce/reduce conflict");
|
||||
else if (RRtotal > 1)
|
||||
fprintf(stderr, "%d reduce/reduce conflicts", RRtotal);
|
||||
|
||||
fprintf(stderr, ".\n");
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
sole_reduction(int stateno)
|
||||
{
|
||||
int count, ruleno;
|
||||
action *p;
|
||||
|
||||
count = 0;
|
||||
ruleno = 0;
|
||||
for (p = parser[stateno]; p; p = p->next)
|
||||
{
|
||||
if (p->action_code == SHIFT && p->suppressed == 0)
|
||||
return (0);
|
||||
else if (p->action_code == REDUCE && p->suppressed == 0)
|
||||
{
|
||||
if (ruleno > 0 && p->number != ruleno)
|
||||
return (0);
|
||||
if (p->symbol != 1)
|
||||
++count;
|
||||
ruleno = p->number;
|
||||
}
|
||||
}
|
||||
|
||||
if (count == 0)
|
||||
return (0);
|
||||
return (ruleno);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
defreds(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
defred = NEW2(nstates, short);
|
||||
for (i = 0; i < nstates; i++)
|
||||
defred[i] = sole_reduction(i);
|
||||
}
|
||||
|
||||
static void
|
||||
free_action_row(action *p)
|
||||
{
|
||||
action *q;
|
||||
|
||||
while (p)
|
||||
{
|
||||
q = p->next;
|
||||
FREE(p);
|
||||
p = q;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
free_parser(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nstates; i++)
|
||||
free_action_row(parser[i]);
|
||||
|
||||
FREE(parser);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,389 +0,0 @@
|
||||
/* $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 */
|
||||
|
||||
#include "defs.h"
|
||||
|
||||
/* The definition of yysccsid in the banner should be replaced with */
|
||||
/* a #pragma ident directive if the target C compiler supports */
|
||||
/* #pragma ident directives. */
|
||||
/* */
|
||||
/* If the skeleton is changed, the banner should be changed so that */
|
||||
/* the altered version can be easily distinguished from the original. */
|
||||
/* */
|
||||
/* The #defines included with the banner are there because they are */
|
||||
/* useful in subsequent code. The macros #defined in the header or */
|
||||
/* the body either are not useful outside of semantic actions or */
|
||||
/* are conditional. */
|
||||
|
||||
const char * const banner[] =
|
||||
{
|
||||
"#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 */",
|
||||
"#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)",
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
const char * const tables[] =
|
||||
{
|
||||
"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[];",
|
||||
"#if YYDEBUG",
|
||||
"extern const char * const yyname[];",
|
||||
"extern const char * const yyrule[];",
|
||||
"#endif",
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
const char * const header[] =
|
||||
{
|
||||
"#ifdef YYSTACKSIZE",
|
||||
"#undef YYMAXDEPTH",
|
||||
"#define YYMAXDEPTH YYSTACKSIZE",
|
||||
"#else",
|
||||
"#ifdef YYMAXDEPTH",
|
||||
"#define YYSTACKSIZE YYMAXDEPTH",
|
||||
"#else",
|
||||
"#define YYSTACKSIZE 10000",
|
||||
"#define YYMAXDEPTH 10000",
|
||||
"#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);",
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
const char * const body[] =
|
||||
{
|
||||
"/* allocate initial stack or double stack size, up to YYMAXDEPTH */",
|
||||
"static int yygrowstack(void);",
|
||||
"static int yygrowstack(void)",
|
||||
"{",
|
||||
" int newsize, i;",
|
||||
" short *newss;",
|
||||
" YYSTYPE *newvs;",
|
||||
"",
|
||||
" if ((newsize = yystacksize) == 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)",
|
||||
" return -1;",
|
||||
" yyss = newss;",
|
||||
" yyssp = newss + i;",
|
||||
" if ((newvs = (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs)) == NULL)",
|
||||
" return -1;",
|
||||
" yyvs = newvs;",
|
||||
" yyvsp = newvs + i;",
|
||||
" yystacksize = newsize;",
|
||||
" yysslim = yyss + newsize - 1;",
|
||||
" return 0;",
|
||||
"}",
|
||||
"",
|
||||
"#define YYABORT goto yyabort",
|
||||
"#define YYREJECT goto yyabort",
|
||||
"#define YYACCEPT goto yyaccept",
|
||||
"#define YYERROR goto yyerrlab",
|
||||
"int",
|
||||
"yyparse(void)",
|
||||
"{",
|
||||
" int yym, yyn, yystate;",
|
||||
"#if YYDEBUG",
|
||||
" const char *yys;",
|
||||
"",
|
||||
" if ((yys = getenv(\"YYDEBUG\")) != NULL)",
|
||||
" {",
|
||||
" yyn = *yys;",
|
||||
" if (yyn >= '0' && yyn <= '9')",
|
||||
" yydebug = yyn - '0';",
|
||||
" }",
|
||||
"#endif",
|
||||
"",
|
||||
" yynerrs = 0;",
|
||||
" yyerrflag = 0;",
|
||||
" yychar = (-1);",
|
||||
"",
|
||||
" if (yyss == NULL && yygrowstack()) goto yyoverflow;",
|
||||
" yyssp = yyss;",
|
||||
" yyvsp = yyvs;",
|
||||
" *yyssp = yystate = 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 (yyssp >= yysslim && yygrowstack())",
|
||||
" {",
|
||||
" 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;",
|
||||
" goto yynewerror;",
|
||||
"yynewerror:",
|
||||
" yyerror(\"syntax error\");",
|
||||
" goto yyerrlab;",
|
||||
"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 >= yysslim && yygrowstack())",
|
||||
" {",
|
||||
" 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];",
|
||||
" if (yym)",
|
||||
" yyval = yyvsp[1-yym];",
|
||||
" else",
|
||||
" yyval = yyvalzero;",
|
||||
" switch (yyn)",
|
||||
" {",
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
const char * const trailer[] =
|
||||
{
|
||||
" }",
|
||||
" 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 >= yysslim && yygrowstack())",
|
||||
" {",
|
||||
" goto yyoverflow;",
|
||||
" }",
|
||||
" *++yyssp = yystate;",
|
||||
" *++yyvsp = yyval;",
|
||||
" goto yyloop;",
|
||||
"yyoverflow:",
|
||||
" yyerror(\"yacc stack overflow\");",
|
||||
"yyabort:",
|
||||
" return (1);",
|
||||
"yyaccept:",
|
||||
" return (0);",
|
||||
"}",
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
void
|
||||
write_section(const char * const section[])
|
||||
{
|
||||
int c;
|
||||
int i;
|
||||
const char *s;
|
||||
FILE *f;
|
||||
|
||||
f = code_file;
|
||||
for (i = 0; (s = section[i]); ++i)
|
||||
{
|
||||
++outline;
|
||||
while ((c = *s) != '\0')
|
||||
{
|
||||
putc(c, f);
|
||||
++s;
|
||||
}
|
||||
putc('\n', f);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
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
|
@ -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);
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
/* $NetBSD: error.tab.h,v 1.2 1998/01/09 08:08:55 perry Exp $ */
|
||||
|
@ -1,6 +0,0 @@
|
||||
%%
|
||||
S: error
|
||||
%%
|
||||
main(){printf("yyparse() = %d\n",yyparse());}
|
||||
yylex(){return-1;}
|
||||
yyerror(s)char*s;{printf("%s\n",s);}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,65 +0,0 @@
|
||||
/* $NetBSD: ftp.tab.h,v 1.2 1998/01/09 08:08:56 perry Exp $ */
|
||||
|
||||
#define A 257
|
||||
#define B 258
|
||||
#define C 259
|
||||
#define E 260
|
||||
#define F 261
|
||||
#define I 262
|
||||
#define L 263
|
||||
#define N 264
|
||||
#define P 265
|
||||
#define R 266
|
||||
#define S 267
|
||||
#define T 268
|
||||
#define SP 269
|
||||
#define CRLF 270
|
||||
#define COMMA 271
|
||||
#define STRING 272
|
||||
#define NUMBER 273
|
||||
#define USER 274
|
||||
#define PASS 275
|
||||
#define ACCT 276
|
||||
#define REIN 277
|
||||
#define QUIT 278
|
||||
#define PORT 279
|
||||
#define PASV 280
|
||||
#define TYPE 281
|
||||
#define STRU 282
|
||||
#define MODE 283
|
||||
#define RETR 284
|
||||
#define STOR 285
|
||||
#define APPE 286
|
||||
#define MLFL 287
|
||||
#define MAIL 288
|
||||
#define MSND 289
|
||||
#define MSOM 290
|
||||
#define MSAM 291
|
||||
#define MRSQ 292
|
||||
#define MRCP 293
|
||||
#define ALLO 294
|
||||
#define REST 295
|
||||
#define RNFR 296
|
||||
#define RNTO 297
|
||||
#define ABOR 298
|
||||
#define DELE 299
|
||||
#define CWD 300
|
||||
#define LIST 301
|
||||
#define NLST 302
|
||||
#define SITE 303
|
||||
#define STAT 304
|
||||
#define HELP 305
|
||||
#define NOOP 306
|
||||
#define MKD 307
|
||||
#define RMD 308
|
||||
#define PWD 309
|
||||
#define CDUP 310
|
||||
#define STOU 311
|
||||
#define SMNT 312
|
||||
#define SYST 313
|
||||
#define SIZE 314
|
||||
#define MDTM 315
|
||||
#define UMASK 316
|
||||
#define IDLE 317
|
||||
#define CHMOD 318
|
||||
#define LEXERR 319
|
File diff suppressed because it is too large
Load Diff
@ -1,385 +0,0 @@
|
||||
/* $NetBSD: verbose.c,v 1.10 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[] = "@(#)verbose.c 5.3 (Berkeley) 1/20/91";
|
||||
#else
|
||||
__RCSID("$NetBSD: verbose.c,v 1.10 2009/04/14 09:41:31 lukem Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
#include "defs.h"
|
||||
|
||||
static short *null_rules;
|
||||
|
||||
static void log_unused(void);
|
||||
static void log_conflicts(void);
|
||||
static void print_state(int);
|
||||
static void print_conflicts(int);
|
||||
static void print_core(int);
|
||||
static void print_nulls(int);
|
||||
static void print_actions(int);
|
||||
static void print_shifts(action *);
|
||||
static void print_reductions(action *, int);
|
||||
static void print_gotos(int);
|
||||
|
||||
void
|
||||
verbose(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!vflag) return;
|
||||
|
||||
null_rules = (short *) MALLOC(nrules*sizeof(short));
|
||||
if (null_rules == 0) no_space();
|
||||
fprintf(verbose_file, "\f\n");
|
||||
for (i = 0; i < nstates; i++)
|
||||
print_state(i);
|
||||
FREE(null_rules);
|
||||
|
||||
if (nunused)
|
||||
log_unused();
|
||||
if (SRtotal || RRtotal)
|
||||
log_conflicts();
|
||||
|
||||
fprintf(verbose_file, "\n\n%d terminals, %d nonterminals\n", ntokens,
|
||||
nvars);
|
||||
fprintf(verbose_file, "%d grammar rules, %d states\n", nrules - 2, nstates);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
log_unused(void)
|
||||
{
|
||||
int i;
|
||||
short *p;
|
||||
|
||||
fprintf(verbose_file, "\n\nRules never reduced:\n");
|
||||
for (i = 3; i < nrules; ++i)
|
||||
{
|
||||
if (!rules_used[i])
|
||||
{
|
||||
fprintf(verbose_file, "\t%s :", symbol_name[rlhs[i]]);
|
||||
for (p = ritem + rrhs[i]; *p >= 0; ++p)
|
||||
fprintf(verbose_file, " %s", symbol_name[*p]);
|
||||
fprintf(verbose_file, " (%d)\n", i - 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
log_conflicts(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
fprintf(verbose_file, "\n\n");
|
||||
for (i = 0; i < nstates; i++)
|
||||
{
|
||||
if (SRconflicts[i] || RRconflicts[i])
|
||||
{
|
||||
fprintf(verbose_file, "State %d contains ", i);
|
||||
if (SRconflicts[i] == 1)
|
||||
fprintf(verbose_file, "1 shift/reduce conflict");
|
||||
else if (SRconflicts[i] > 1)
|
||||
fprintf(verbose_file, "%d shift/reduce conflicts",
|
||||
SRconflicts[i]);
|
||||
if (SRconflicts[i] && RRconflicts[i])
|
||||
fprintf(verbose_file, ", ");
|
||||
if (RRconflicts[i] == 1)
|
||||
fprintf(verbose_file, "1 reduce/reduce conflict");
|
||||
else if (RRconflicts[i] > 1)
|
||||
fprintf(verbose_file, "%d reduce/reduce conflicts",
|
||||
RRconflicts[i]);
|
||||
fprintf(verbose_file, ".\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
print_state(int state)
|
||||
{
|
||||
if (state)
|
||||
fprintf(verbose_file, "\n\n");
|
||||
if (SRconflicts[state] || RRconflicts[state])
|
||||
print_conflicts(state);
|
||||
fprintf(verbose_file, "state %d\n", state);
|
||||
print_core(state);
|
||||
print_nulls(state);
|
||||
print_actions(state);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
print_conflicts(int state)
|
||||
{
|
||||
int symbol, act, number;
|
||||
action *p;
|
||||
|
||||
/* keep gcc -Wall happy. */
|
||||
act = number = 0;
|
||||
|
||||
symbol = -1;
|
||||
for (p = parser[state]; p; p = p->next)
|
||||
{
|
||||
if (p->suppressed == 2)
|
||||
continue;
|
||||
|
||||
if (p->symbol != symbol)
|
||||
{
|
||||
symbol = p->symbol;
|
||||
number = p->number;
|
||||
if (p->action_code == SHIFT)
|
||||
act = SHIFT;
|
||||
else
|
||||
act = REDUCE;
|
||||
}
|
||||
else if (p->suppressed == 1)
|
||||
{
|
||||
if (state == final_state && symbol == 0)
|
||||
{
|
||||
fprintf(verbose_file, "%d: shift/reduce conflict \
|
||||
(accept, reduce %d) on $end\n", state, p->number - 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (act == SHIFT)
|
||||
{
|
||||
fprintf(verbose_file, "%d: shift/reduce conflict \
|
||||
(shift %d, reduce %d) on %s\n", state, number, p->number - 2,
|
||||
symbol_name[symbol]);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(verbose_file, "%d: reduce/reduce conflict \
|
||||
(reduce %d, reduce %d) on %s\n", state, number - 2, p->number - 2,
|
||||
symbol_name[symbol]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
print_core(int state)
|
||||
{
|
||||
int i;
|
||||
int k;
|
||||
int rule;
|
||||
core *statep;
|
||||
short *sp;
|
||||
short *sp1;
|
||||
|
||||
statep = state_table[state];
|
||||
k = statep->nitems;
|
||||
|
||||
for (i = 0; i < k; i++)
|
||||
{
|
||||
sp1 = sp = ritem + statep->items[i];
|
||||
|
||||
while (*sp >= 0) ++sp;
|
||||
rule = -(*sp);
|
||||
fprintf(verbose_file, "\t%s : ", symbol_name[rlhs[rule]]);
|
||||
|
||||
for (sp = ritem + rrhs[rule]; sp < sp1; sp++)
|
||||
fprintf(verbose_file, "%s ", symbol_name[*sp]);
|
||||
|
||||
putc('.', verbose_file);
|
||||
|
||||
while (*sp >= 0)
|
||||
{
|
||||
fprintf(verbose_file, " %s", symbol_name[*sp]);
|
||||
sp++;
|
||||
}
|
||||
fprintf(verbose_file, " (%d)\n", -2 - *sp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
print_nulls(int state)
|
||||
{
|
||||
action *p;
|
||||
int i, j, k, nnulls;
|
||||
|
||||
nnulls = 0;
|
||||
for (p = parser[state]; p; p = p->next)
|
||||
{
|
||||
if (p->action_code == REDUCE &&
|
||||
(p->suppressed == 0 || p->suppressed == 1))
|
||||
{
|
||||
i = p->number;
|
||||
if (rrhs[i] + 1 == rrhs[i+1])
|
||||
{
|
||||
for (j = 0; j < nnulls && i > null_rules[j]; ++j)
|
||||
continue;
|
||||
|
||||
if (j == nnulls)
|
||||
{
|
||||
++nnulls;
|
||||
null_rules[j] = i;
|
||||
}
|
||||
else if (i != null_rules[j])
|
||||
{
|
||||
++nnulls;
|
||||
for (k = nnulls - 1; k > j; --k)
|
||||
null_rules[k] = null_rules[k-1];
|
||||
null_rules[j] = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < nnulls; ++i)
|
||||
{
|
||||
j = null_rules[i];
|
||||
fprintf(verbose_file, "\t%s : . (%d)\n", symbol_name[rlhs[j]],
|
||||
j - 2);
|
||||
}
|
||||
fprintf(verbose_file, "\n");
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
print_actions(int stateno)
|
||||
{
|
||||
action *p;
|
||||
shifts *sp;
|
||||
int as;
|
||||
|
||||
if (stateno == final_state)
|
||||
fprintf(verbose_file, "\t$end accept\n");
|
||||
|
||||
p = parser[stateno];
|
||||
if (p)
|
||||
{
|
||||
print_shifts(p);
|
||||
print_reductions(p, defred[stateno]);
|
||||
}
|
||||
|
||||
sp = shift_table[stateno];
|
||||
if (sp && sp->nshifts > 0)
|
||||
{
|
||||
as = accessing_symbol[sp->shift[sp->nshifts - 1]];
|
||||
if (ISVAR(as))
|
||||
print_gotos(stateno);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
print_shifts(action *p)
|
||||
{
|
||||
int count;
|
||||
action *q;
|
||||
|
||||
count = 0;
|
||||
for (q = p; q; q = q->next)
|
||||
{
|
||||
if (q->suppressed < 2 && q->action_code == SHIFT)
|
||||
++count;
|
||||
}
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
for (; p; p = p->next)
|
||||
{
|
||||
if (p->action_code == SHIFT && p->suppressed == 0)
|
||||
fprintf(verbose_file, "\t%s shift %d\n",
|
||||
symbol_name[p->symbol], p->number);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
print_reductions(action *p, int prdefred)
|
||||
{
|
||||
int k, anyreds;
|
||||
action *q;
|
||||
|
||||
anyreds = 0;
|
||||
for (q = p; q ; q = q->next)
|
||||
{
|
||||
if (q->action_code == REDUCE && q->suppressed < 2)
|
||||
{
|
||||
anyreds = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (anyreds == 0)
|
||||
fprintf(verbose_file, "\t. error\n");
|
||||
else
|
||||
{
|
||||
for (; p; p = p->next)
|
||||
{
|
||||
if (p->action_code == REDUCE && p->number != prdefred)
|
||||
{
|
||||
k = p->number - 2;
|
||||
if (p->suppressed == 0)
|
||||
fprintf(verbose_file, "\t%s reduce %d\n",
|
||||
symbol_name[p->symbol], k);
|
||||
}
|
||||
}
|
||||
|
||||
if (prdefred > 0)
|
||||
fprintf(verbose_file, "\t. reduce %d\n", prdefred - 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
print_gotos(int stateno)
|
||||
{
|
||||
int i, k;
|
||||
int as;
|
||||
short *state;
|
||||
shifts *sp;
|
||||
|
||||
putc('\n', verbose_file);
|
||||
sp = shift_table[stateno];
|
||||
state = sp->shift;
|
||||
for (i = 0; i < sp->nshifts; ++i)
|
||||
{
|
||||
k = state[i];
|
||||
as = accessing_symbol[k];
|
||||
if (ISVAR(as))
|
||||
fprintf(verbose_file, "\t%s goto %d\n", symbol_name[as], k);
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -1,188 +0,0 @@
|
||||
.\" $NetBSD: yacc.1,v 1.13 2003/08/07 11:17:55 agc Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1989, 1990 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.
|
||||
.\"
|
||||
.\" from: @(#)yacc.1 5.7 (Berkeley) 7/30/91
|
||||
.\" $NetBSD: yacc.1,v 1.13 2003/08/07 11:17:55 agc Exp $
|
||||
.\"
|
||||
.Dd July 30, 1991
|
||||
.Dt YACC 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm yacc
|
||||
.Nd an
|
||||
.Tn LALR(1)
|
||||
parser generator
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl dlrtv
|
||||
.Op Fl b Ar prefix
|
||||
.Op Fl o Ar outputfile
|
||||
.Op Fl p Ar symbol_prefix
|
||||
.Ar filename
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
reads the grammar specification in the file
|
||||
.Ar filename
|
||||
and generates an
|
||||
.Tn LR(1)
|
||||
parser for it.
|
||||
The parsers consist of a set of
|
||||
.Tn LALR(1)
|
||||
parsing tables and a driver routine
|
||||
written in the C programming language.
|
||||
.Nm
|
||||
normally writes the parse tables and the driver routine to the file
|
||||
.Pa y.tab.c .
|
||||
.Pp
|
||||
The following options are available:
|
||||
.Bl -tag -width Ar
|
||||
.It Fl b Ar prefix
|
||||
The
|
||||
.Fl b
|
||||
option changes the prefix prepended to the output file names to
|
||||
the string denoted by
|
||||
.Ar prefix .
|
||||
The default prefix is the character
|
||||
.Ar y .
|
||||
.It Fl d
|
||||
The
|
||||
.Fl d
|
||||
option causes the header file
|
||||
.Pa y.tab.h
|
||||
to be written.
|
||||
.It Fl l
|
||||
If the
|
||||
.Fl l
|
||||
option is not specified,
|
||||
.Nm
|
||||
will insert #line directives in the generated code.
|
||||
The #line directives let the C compiler relate errors in the
|
||||
generated code to the user's original code.
|
||||
If the
|
||||
.Fl l
|
||||
option is specified,
|
||||
.Nm
|
||||
will not insert the #line directives.
|
||||
#line directives specified by the user will be retained.
|
||||
.It Fl o Ar outputfile
|
||||
The
|
||||
.Fl o
|
||||
option specifies an explicit output file name should be used instead
|
||||
of the default.
|
||||
.It Fl p Ar symbol_prefix
|
||||
The
|
||||
.Fl p
|
||||
option changes the prefix prepended to yacc-generated symbols to
|
||||
the string denoted by
|
||||
.Ar symbol_prefix .
|
||||
The default prefix is the string
|
||||
.Ar yy .
|
||||
.It Fl r
|
||||
The
|
||||
.Fl r
|
||||
option causes
|
||||
.Nm
|
||||
to produce separate files for code and tables.
|
||||
The code file is named
|
||||
.Pa y.code.c ,
|
||||
and the tables file is named
|
||||
.Pa y.tab.c .
|
||||
.It Fl t
|
||||
The
|
||||
.Fl t
|
||||
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 causes a human-readable description of the generated parser to
|
||||
be written to the file
|
||||
.Pa y.output .
|
||||
.El
|
||||
.Sh ENVIRONMENT
|
||||
The following environment variable is referenced by
|
||||
.Nm :
|
||||
.Bl -tag -width TMPDIR
|
||||
.It Ev TMPDIR
|
||||
If the environment variable
|
||||
.Ev TMPDIR
|
||||
is set, the string denoted by
|
||||
.Ev TMPDIR
|
||||
will be used as the name of the directory where the temporary
|
||||
files are created.
|
||||
.El
|
||||
.Sh TABLES
|
||||
The names of the tables generated by this version of
|
||||
.Nm
|
||||
are
|
||||
.Dq yylhs ,
|
||||
.Dq yylen ,
|
||||
.Dq yydefred ,
|
||||
.Dq yydgoto ,
|
||||
.Dq yysindex ,
|
||||
.Dq yyrindex ,
|
||||
.Dq yygindex ,
|
||||
.Dq yytable ,
|
||||
and
|
||||
.Dq yycheck .
|
||||
Two additional tables,
|
||||
.Dq yyname
|
||||
and
|
||||
.Dq yyrule ,
|
||||
are created if
|
||||
.Dv YYDEBUG
|
||||
is defined and non-zero.
|
||||
.Sh FILES
|
||||
.Bl -tag -width /tmp/yacc.uXXXXXXXX -compact
|
||||
.It Pa y.code.c
|
||||
.It Pa y.tab.c
|
||||
.It Pa y.tab.h
|
||||
.It Pa y.output
|
||||
.It Pa /tmp/yacc.aXXXXXX
|
||||
.It Pa /tmp/yacc.tXXXXXX
|
||||
.It Pa /tmp/yacc.uXXXXXX
|
||||
.El
|
||||
.Sh DIAGNOSTICS
|
||||
If there are rules that are never reduced, the number of such rules is
|
||||
written to the standard error.
|
||||
If there are any
|
||||
.Tn LALR(1)
|
||||
conflicts, the number of conflicts is also written
|
||||
to the standard error.
|
||||
.\" .Sh SEE ALSO
|
||||
.\" .Xr yyfix 1
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Nm
|
||||
utility conforms to
|
||||
.St -p1003.2 .
|
Loading…
x
Reference in New Issue
Block a user