Permalink
Browse files

Update build for byacc import.

  • Loading branch information...
1 parent 82a2500 commit a7e375d5345bdf0eb8017d945d6a71dc971a8e83 Peter Avalos committed Jan 19, 2013
View
5 Makefile_upgrade.inc
@@ -2114,6 +2114,11 @@ TO_REMOVE+=/usr/share/man/man2/aio_waitcomplete.2.gz
TO_REMOVE+=/usr/share/man/cat2/aio_write.2.gz
TO_REMOVE+=/usr/share/man/man2/aio_write.2.gz
TO_REMOVE+=/usr/include/c++/FlexLexer.h
+TO_REMOVE+=/usr/share/man/cat3/liby.3.gz
+TO_REMOVE+=/usr/share/man/man3/liby.3.gz
+TO_REMOVE+=/usr/bin/yyfix
+TO_REMOVE+=/usr/share/man/cat1/yyfix.1.gz
+TO_REMOVE+=/usr/share/man/man1/yyfix.1.gz
.if ${MACHINE_ARCH} == "x86_64"
TO_REMOVE+=/usr/sbin/stlstats
View
5 contrib/byacc/README.DRAGONFLY
@@ -0,0 +1,5 @@
+This is Berkeley yacc available from:
+http://invisible-island.net/byacc/
+
+Instead of using a config.h, just add the appropriate defines to
+usr.bin/yacc/Makefile.
View
25 usr.bin/yacc/ACKNOWLEDGEMENTS
@@ -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
View
20 usr.bin/yacc/Makefile
@@ -1,14 +1,16 @@
-# @(#)Makefile 5.3 (Berkeley) 5/12/90
-# $FreeBSD: src/usr.bin/yacc/Makefile,v 1.8.2.2 2001/04/25 14:04:46 ru Exp $
-# $DragonFly: src/usr.bin/yacc/Makefile,v 1.5 2007/08/27 16:51:01 pavalos Exp $
+CONTRIBDIR= ${.CURDIR}/../../contrib/byacc
+.PATH: ${CONTRIBDIR}
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
-SCRIPTS=yyfix.sh
-MAN= yacc.1 yyfix.1
+SRCS= closure.c error.c graph.c lalr.c lr0.c main.c mkpar.c output.c \
+ reader.c skeleton.c symtab.c verbose.c warshall.c
+
+VER!= cat ${CONTRIBDIR}/VERSION
+CFLAGS+=-DYYPATCH=${VER}
+# config.h defines
+CFLAGS+=-DHAVE_FCNTL_H -DHAVE_MKSTEMP -DMIXEDCASE_FILENAMES
+
LINKS= ${BINDIR}/yacc ${BINDIR}/byacc
-MLINKS= yacc.1 byacc.1 \
- yacc.1 liby.3
+MLINKS= yacc.1 byacc.1
.include <bsd.prog.mk>
View
46 usr.bin/yacc/NEW_FEATURES
@@ -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.
View
9 usr.bin/yacc/NOTES
@@ -1,9 +0,0 @@
-Berkeley Yacc reflects its origins. The reason so many routines
-use exactly six register variables is that Berkeley Yacc was
-developed on a VAX using PCC. PCC placed at most six variables
-in registers. I went to considerable effort to find which six
-variables most belonged in registers. Changes in machines and
-compilers make that effort worthless, perhaps even harmful.
-
-The code contains many instances where address calculations are
-performed in particular ways to optimize the code for the VAX.
View
23 usr.bin/yacc/README
@@ -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.
View
308 usr.bin/yacc/closure.c
@@ -1,308 +0,0 @@
-/*
- * 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. 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.
- *
- * $FreeBSD: src/usr.bin/yacc/closure.c,v 1.6 1999/08/28 01:07:58 peter Exp $
- * $DragonFly: src/usr.bin/yacc/closure.c,v 1.4 2004/04/07 20:43:24 cpressey Exp $
- *
- * @(#)closure.c 5.3 (Berkeley) 5/24/93
- */
-
-#include <stdlib.h>
-#include "defs.h"
-
-short *itemset;
-short *itemsetend;
-unsigned *ruleset;
-
-static void set_EFF(void);
-#ifdef DEBUG
-static void print_closure(int);
-static void print_EFF();
-static void print_first_derives();
-#endif
-
-static unsigned *first_derives;
-static unsigned *EFF;
-
-
-static void
-set_EFF(void)
-{
- unsigned *row;
- int symbol;
- short *sp;
- int rowsize;
- int i;
- int rule;
-
- rowsize = WORDSIZE(nvars);
- EFF = NEW2(nvars * rowsize, unsigned);
-
- row = EFF;
- for (i = start_symbol; i < nsyms; i++)
- {
- sp = derives[i];
- for (rule = *sp; rule > 0; rule = *++sp)
- {
- symbol = ritem[rrhs[rule]];
- if (ISVAR(symbol))
- {
- symbol -= start_symbol;
- SETBIT(row, symbol);
- }
- }
- row += rowsize;
- }
-
- reflexive_transitive_closure(EFF, nvars);
-
-#ifdef DEBUG
- print_EFF();
-#endif
-}
-
-
-void
-set_first_derives(void)
-{
- unsigned *rrow;
- unsigned *vrow;
- int j;
- unsigned k;
- unsigned cword = 0;
- short *rp;
-
- int rule;
- int i;
- int rulesetsize;
- int varsetsize;
-
- rulesetsize = WORDSIZE(nrules);
- varsetsize = WORDSIZE(nvars);
- first_derives = NEW2(nvars * rulesetsize, unsigned) - ntokens * rulesetsize;
-
- set_EFF();
-
- rrow = first_derives + ntokens * rulesetsize;
- for (i = start_symbol; i < nsyms; i++)
- {
- vrow = EFF + ((i - ntokens) * varsetsize);
- k = BITS_PER_WORD;
- for (j = start_symbol; j < nsyms; k++, j++)
- {
- if (k >= BITS_PER_WORD)
- {
- cword = *vrow++;
- k = 0;
- }
-
- if (cword & (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
-
-static void
-print_closure(int n)
-{
- short *isp;
-
- printf("\n\nn = %d\n\n", n);
- for (isp = itemset; isp < itemsetend; isp++)
- printf(" %d\n", *isp);
-}
-
-
-static 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]);
- }
- }
-}
-
-
-static 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
View
362 usr.bin/yacc/defs.h
@@ -1,362 +0,0 @@
-/*
- * 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. 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
- * $FreeBSD: src/usr.bin/yacc/defs.h,v 1.8.2.1 2001/10/05 03:00:19 obrien Exp $
- * $DragonFly: src/usr.bin/yacc/defs.h,v 1.5 2005/01/05 15:26:05 joerg Exp $
- */
-
-#include <assert.h>
-#include <ctype.h>
-#include <err.h>
-#include <stdio.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 *cptr;
-extern char *line;
-extern int lineno;
-extern int outline;
-
-extern const char *banner[];
-extern const char *tables[];
-extern const char *header[];
-extern const char *body[];
-extern const char *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 SRexpect;
-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 */
-
-char *allocate(unsigned);
-void closure(short *, int);
-void create_symbol_table(void);
-void default_action_warning(void);
-void dollar_error(int, const char *, const char *);
-void dollar_warning(int, int);
-void fatal(const char *msg);
-void finalize_closure(void);
-void free_parser(void);
-void free_symbols(void);
-void free_symbol_table(void);
-void illegal_character(const char *);
-void illegal_tag(int, const char *, const char *);
-void lalr(void);
-bucket *lookup(char *);
-void lr0(void);
-bucket *make_bucket(const char *);
-void make_parser(void);
-void no_grammar(void);
-void no_space(void);
-void open_error(const char *);
-void output(void);
-void over_unionized(const char *);
-void prec_redeclared(void);
-void reader(void);
-void reflexive_transitive_closure(unsigned *, int);
-void reprec_warning(const char *);
-void restarted_warning(void);
-void retyped_warning(const char *);
-void revalued_warning(const char *);
-void set_first_derives(void);
-void syntax_error(int, const char *, const char *);
-void terminal_lhs(int);
-void terminal_start(const char *);
-void tokenized_start(const char *);
-void undefined_goal(const char *);
-void undefined_symbol_warning(const char *);
-void unexpected_EOF(void);
-void unknown_rhs(int);
-void unterminated_action(int, const char *, const char *);
-void unterminated_comment(int, const char *, const char *);
-void unterminated_string(int, const char *, const char *);
-void unterminated_text(int, const char *, const char *);
-void unterminated_union(int, const char *, const char *);
-void untyped_lhs(void);
-void untyped_rhs(int, const char *);
-void used_reserved(const char *);
-void verbose(void);
-void write_section(const char **);
View
327 usr.bin/yacc/error.c
@@ -1,327 +0,0 @@
-/*
- * 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. 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.
- *
- * @(#)error.c 5.3 (Berkeley) 6/1/90
- * $FreeBSD: src/usr.bin/yacc/error.c,v 1.7 1999/08/28 01:07:59 peter Exp $
- */
-
-/* routines for printing error messages */
-
-#include <stdlib.h>
-#include "defs.h"
-
-static void print_pos(const char *, const char *);
-
-void
-fatal(const char *msg)
-{
- errx(2, "f - %s", msg);
-}
-
-
-void
-no_space(void)
-{
- errx(2, "f - out of space");
-}
-
-
-void
-open_error(const char *filename)
-{
- errx(2, "f - cannot open \"%s\"", filename);
-}
-
-
-void
-unexpected_EOF(void)
-{
- errx(1, "e - line %d of \"%s\", unexpected end-of-file",
- lineno, input_file_name);
-}
-
-
-static void
-print_pos(const char *st_line, const char *st_cptr)
-{
- const char *s;
-
- if (st_line == NULL) return;
- for (s = st_line; *s != '\n'; ++s)
- {
- if (isprint(*s) || *s == '\t')
- putc(*s, stderr);
- else
- putc('?', stderr);
- }
- putc('\n', stderr);
- for (s = st_line; s < st_cptr; ++s)
- {
- if (*s == '\t')
- putc('\t', stderr);
- else
- putc(' ', stderr);
- }
- putc('^', stderr);
- putc('\n', stderr);
-}
-
-
-void
-syntax_error(int st_lineno, const char *st_line, const char *st_cptr)
-{
- warnx("e - line %d of \"%s\", syntax error",
- st_lineno, input_file_name);
- print_pos(st_line, st_cptr);
- exit(1);
-}
-
-
-void
-unterminated_comment(int c_lineno, const char *c_line, const char *c_cptr)
-{
- warnx("e - line %d of \"%s\", unmatched /*",
- c_lineno, input_file_name);
- print_pos(c_line, c_cptr);
- exit(1);
-}
-
-
-void
-unterminated_string(int s_lineno, const char *s_line, const char *s_cptr)
-{
- warnx("e - line %d of \"%s\", unterminated string",
- s_lineno, input_file_name);
- print_pos(s_line, s_cptr);
- exit(1);
-}
-
-
-void
-unterminated_text(int t_lineno, const char *t_line, const char *t_cptr)
-{
- warnx("e - line %d of \"%s\", unmatched %%{",
- t_lineno, input_file_name);
- print_pos(t_line, t_cptr);
- exit(1);
-}
-
-
-void
-unterminated_union(int u_lineno, const char *u_line, const char *u_cptr)
-{
- warnx("e - line %d of \"%s\", unterminated %%union declaration",
- u_lineno, input_file_name);
- print_pos(u_line, u_cptr);
- exit(1);
-}
-
-
-void
-over_unionized(const char *u_cptr)
-{
- warnx("e - line %d of \"%s\", too many %%union declarations",
- lineno, input_file_name);
- print_pos(line, u_cptr);
- exit(1);
-}
-
-
-void
-illegal_tag(int t_lineno, const char *t_line, const char *t_cptr)
-{
- warnx("e - line %d of \"%s\", illegal tag", t_lineno, input_file_name);
- print_pos(t_line, t_cptr);
- exit(1);
-}
-
-
-void
-illegal_character(const char *c_cptr)
-{
- warnx("e - line %d of \"%s\", illegal character", lineno, input_file_name);
- print_pos(line, c_cptr);
- exit(1);
-}
-
-
-void
-used_reserved(const char *s)
-{
- errx(1, "e - line %d of \"%s\", illegal use of reserved symbol %s",
- lineno, input_file_name, s);
-}
-
-
-void
-tokenized_start(const char *s)
-{
- errx(1, "e - line %d of \"%s\", the start symbol %s cannot be \
-declared to be a token", lineno, input_file_name, s);
-}
-
-
-void
-retyped_warning(const char *s)
-{
- warnx("w - line %d of \"%s\", the type of %s has been redeclared",
- lineno, input_file_name, s);
-}
-
-
-void
-reprec_warning(const char *s)
-{
- warnx("w - line %d of \"%s\", the precedence of %s has been redeclared",
- lineno, input_file_name, s);
-}
-
-
-void
-revalued_warning(const char *s)
-{
- warnx("w - line %d of \"%s\", the value of %s has been redeclared",
- lineno, input_file_name, s);
-}
-
-
-void
-terminal_start(const char *s)
-{
- errx(1, "e - line %d of \"%s\", the start symbol %s is a token",
- lineno, input_file_name, s);
-}
-
-
-void
-restarted_warning(void)
-{
- warnx("w - line %d of \"%s\", the start symbol has been redeclared",
- lineno, input_file_name);
-}
-
-
-void
-no_grammar(void)
-{
- errx(1, "e - line %d of \"%s\", no grammar has been specified",
- lineno, input_file_name);
-}
-
-
-void
-terminal_lhs(int s_lineno)
-{
- errx(1, "e - line %d of \"%s\", a token appears on the lhs of a production",
- s_lineno, input_file_name);
-}
-
-
-void
-prec_redeclared(void)
-{
- warnx("w - line %d of \"%s\", conflicting %%prec specifiers",
- lineno, input_file_name);
-}
-
-
-void
-unterminated_action(int a_lineno, const char *a_line, const char *a_cptr)
-{
- warnx("e - line %d of \"%s\", unterminated action",
- a_lineno, input_file_name);
- print_pos(a_line, a_cptr);
-}
-
-
-void
-dollar_warning(int a_lineno, int i)
-{
- warnx("w - line %d of \"%s\", $%d references beyond the \
-end of the current rule", a_lineno, input_file_name, i);
-}
-
-
-void
-dollar_error(int a_lineno, const char *a_line, const char *a_cptr)
-{
- warnx("e - line %d of \"%s\", illegal $-name", a_lineno, input_file_name);
- print_pos(a_line, a_cptr);
- exit(1);
-}
-
-
-void
-untyped_lhs(void)
-{
- errx(1, "e - line %d of \"%s\", $$ is untyped", lineno, input_file_name);
-}
-
-
-void
-untyped_rhs(int i, const char *s)
-{
- errx(1, "e - line %d of \"%s\", $%d (%s) is untyped",
- lineno, input_file_name, i, s);
-}
-
-
-void
-unknown_rhs(int i)
-{
- errx(1, "e - line %d of \"%s\", $%d is untyped", lineno, input_file_name, i);
-}
-
-
-void
-default_action_warning(void)
-{
- warnx("w - line %d of \"%s\", the default action assigns an \
-undefined value to $$", lineno, input_file_name);
-}
-
-
-void
-undefined_goal(const char *s)
-{
- errx(1, "e - the start symbol %s is undefined", s);
-}
-
-
-void
-undefined_symbol_warning(const char *s)
-{
- warnx("w - the symbol %s is undefined", s);
-}
View
703 usr.bin/yacc/lalr.c
@@ -1,703 +0,0 @@
-/*
- * 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. 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.
- *
- * $FreeBSD: src/usr.bin/yacc/lalr.c,v 1.7 1999/08/28 01:07:59 peter Exp $
- * $DragonFly: src/usr.bin/yacc/lalr.c,v 1.5 2005/01/05 15:26:05 joerg Exp $
- *
- * @(#)lalr.c 5.3 (Berkeley) 6/1/90
- */
-
-#include <stdlib.h>
-#include "defs.h"
-
-typedef
- struct shorts
- {
- struct shorts *next;
- short value;
- }
- shorts;
-
-int tokensetsize;
-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 void add_lookback_edge(int, int, int);
-static void build_relations(void);
-static void compute_FOLLOWS(void);
-static void compute_lookaheads(void);
-static void digraph(short **);
-static void initialize_F(void);
-static void initialize_LA(void);
-static int map_goto(int, int);
-static void set_accessing_symbol(void);
-static void set_goto_map(void);
-static void set_maxrhs(void);
-static void set_reduction_table(void);
-static void set_shift_table(void);
-static void set_state_table(void);
-static short **transpose(short **, int);
-static void traverse(int);
-
-static int infinity;
-static int maxrhs;
-static int ngotos;
-static unsigned *F;
-static short **includes;
-static shorts **lookback;
-static short **R;
-static short *INDEX;
-static short *VERTICES;
-static int top;
-
-
-void
-lalr(void)
-{
- tokensetsize = WORDSIZE(ntokens);
-
- set_state_table();
- set_accessing_symbol();
- set_shift_table();
- set_reduction_table();
- set_maxrhs();
- initialize_LA();
- set_goto_map();
- initialize_F();
- build_relations();
- compute_FOLLOWS();
- compute_lookaheads();
-}
-
-
-
-static void
-set_state_table(void)
-{
- core *sp;
-
- state_table = NEW2(nstates, core *);
- for (sp = first_state; sp; sp = sp->next)
- state_table[sp->number] = sp;
-}
-
-
-
-static void
-set_accessing_symbol(void)
-{
- core *sp;
-
- accessing_symbol = NEW2(nstates, short);
- for (sp = first_state; sp; sp = sp->next)
- accessing_symbol[sp->number] = sp->accessing_symbol;
-}
-
-
-
-static void
-set_shift_table(void)
-{
- shifts *sp;
-
- shift_table = NEW2(nstates, shifts *);
- for (sp = first_shift; sp; sp = sp->next)
- shift_table[sp->number] = sp;
-}
-
-
-
-static void
-set_reduction_table(void)
-{
- reductions *rp;
-
- reduction_table = NEW2(nstates, reductions *);
- for (rp = first_reduction; rp; rp = rp->next)
- reduction_table[rp->number] = rp;
-}
-
-
-
-static void
-set_maxrhs(void)
-{
- short *itemp;
- short *item_end;
- int length;
- int max;
-
- length = 0;
- max = 0;
- item_end = ritem + nitems;
- for (itemp = ritem; itemp < item_end; itemp++)
- {
- if (*itemp >= 0)
- {
- length++;
- }
- else
- {
- if (length > max) max = length;
- length = 0;
- }
- }
-
- maxrhs = max;
-}
-
-
-
-static void
-initialize_LA(void)
-{
- int i, j, k;
- reductions *rp;
-
- lookaheads = NEW2(nstates + 1, short);
-
- k = 0;
- for (i = 0; i < nstates; i++)
- {
- lookaheads[i] = k;
- rp = reduction_table[i];
- if (rp)
- k += rp->nreds;
- }
- lookaheads[nstates] = k;
-
- LA = NEW2(k * tokensetsize, unsigned);
- LAruleno = NEW2(k, short);
- lookback = NEW2(k, shorts *);
-
- k = 0;
- for (i = 0; i < nstates; i++)
- {
- rp = reduction_table[i];
- if (rp)
- {
- for (j = 0; j < rp->nreds; j++)
- {
- LAruleno[k] = rp->rules[j];
- k++;
- }
- }
- }
-}
-
-
-static void
-set_goto_map(void)
-{
- shifts *sp;
- int i;
- int symbol;
- int k;
- short *temp_map;
- int state2;
- int state1;
-
- goto_map = NEW2(nvars + 1, short) - ntokens;
- temp_map = NEW2(nvars + 1, short) - ntokens;
-
- ngotos = 0;
- for (sp = first_shift; sp; sp = sp->next)
- {
- for (i = sp->nshifts - 1; i >= 0; i--)
- {
- symbol = accessing_symbol[sp->shift[i]];
-
- if (ISTOKEN(symbol)) break;
-
- if (ngotos == MAXSHORT)
- fatal("too many gotos");
-
- ngotos++;
- goto_map[symbol]++;
- }
- }
-
- k = 0;
- for (i = ntokens; i < nsyms; i++)
- {
- temp_map[i] = k;
- k += goto_map[i];
- }
-
- for (i = ntokens; i < nsyms; i++)
- goto_map[i] = temp_map[i];
-
- goto_map[nsyms] = ngotos;
- temp_map[nsyms] = ngotos;
-
- from_state = NEW2(ngotos, short);
- to_state = NEW2(ngotos, short);
-
- for (sp = first_shift; sp; sp = sp->next)
- {
- state1 = sp->number;
- for (i = sp->nshifts - 1; i >= 0; i--)
- {
- state2 = sp->shift[i];
- symbol = accessing_symbol[state2];
-
- if (ISTOKEN(symbol)) break;
-
- k = temp_map[symbol]++;
- from_state[k] = state1;
- to_state[k] = state2;
- }
- }
-
- FREE(temp_map + ntokens);
-}
-
-
-
-/* Map_goto maps a state/symbol pair into its numeric representation. */
-
-static int
-map_goto(int state, int symbol)
-{
- int high;
- int low;
- int middle;
- int s;
-
- low = goto_map[symbol];
- high = goto_map[symbol + 1];
-
- for (;;)
- {
- assert(low <= high);
- middle = (low + high) >> 1;
- s = from_state[middle];
- if (s == state)
- return (middle);
- else if (s < state)
- low = middle + 1;
- else
- high = middle - 1;
- }
-}
-
-
-
-static void
-initialize_F(void)
-{
- int i;
- int j;
- int k;
- shifts *sp;
- short *edge;
- unsigned *rowp;
- short *rp;
- short **reads;
- int nedges;
- int stateno;
- int symbol;
- int nwords;
-
- nwords = ngotos * tokensetsize;
- F = NEW2(nwords, unsigned);
-
- reads = NEW2(ngotos, short *);
- edge = NEW2(ngotos + 1, short);
- nedges = 0;
-
- rowp = F;
- for (i = 0; i < ngotos; i++)
- {
- stateno = to_state[i];
- sp = shift_table[stateno];
-
- if (sp)
- {
- k = sp->nshifts;
-
- for (j = 0; j < k; j++)
- {
- symbol = accessing_symbol[sp->shift[j]];
- if (ISVAR(symbol))
- break;
- SETBIT(rowp, symbol);
- }
-
- for (; j < k; j++)
- {
- symbol = accessing_symbol[sp->shift[j]];
- if (nullable[symbol])
- edge[nedges++] = map_goto(stateno, symbol);
- }
-
- if (nedges)
- {
- reads[i] = rp = NEW2(nedges + 1, short);
-
- for (j = 0; j < nedges; j++)
- rp[j] = edge[j];
-
- rp[nedges] = -1;
- nedges = 0;
- }
- }
-
- rowp += tokensetsize;
- }
-
- SETBIT(F, 0);
- digraph(reads);
-
- for (i = 0; i < ngotos; i++)
- {
- if (reads[i])
- FREE(reads[i]);
- }
-
- FREE(reads);
- FREE(edge);
-}
-
-
-
-static void
-build_relations(void)
-{
- int i;
- int j;
- int k;
- short *rulep;
- short *rp;
- shifts *sp;
- int length;
- int nedges;
- int done;
- 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--;
- done = 0;
- while (!done)
- {
- done = 1;
- rp--;
- if (ISVAR(*rp))
- {
- stateno = states[--length];
- edge[nedges++] = map_goto(stateno, *rp);
- if (nullable[*rp] && length > 0) done = 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 **old_R, 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 = old_R[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 = old_R[i];
- if (sp)
- {
- while (*sp >= 0)
- *temp_R[*sp++]++ = i;
- }
- }
-
- FREE(temp_R);
-
- return (new_R);
-}
-
-
-
-static void
-compute_FOLLOWS(void)
-{
- digraph(includes);
-}
-
-
-static void
-compute_lookaheads(void)
-{
- int i, n;
- unsigned *fp1, *fp2, *fp3;
- shorts *sp, *next;
- unsigned *rowp;
-
- rowp = LA;
- n = lookaheads[nstates];
- for (i = 0; i < n; i++)
- {
- fp3 = rowp + tokensetsize;
- for (sp = lookback[i]; sp; sp = sp->next)
- {
- fp1 = rowp;
- fp2 = F + tokensetsize * sp->value;
- while (fp1 < fp3)
- *fp1++ |= *fp2++;
- }
- rowp = fp3;
- }
-
- for (i = 0; i < n; i++)
- for (sp = lookback[i]; sp; sp = next)
- {
- next = sp->next;
- FREE(sp);
- }
-
- FREE(lookback);
- FREE(F);
-}
-
-
-static void
-digraph(short **relation)
-{
- int i;
-
- infinity = ngotos + 2;
- INDEX = NEW2(ngotos + 1, short);
- VERTICES = NEW2(ngotos + 1, short);
- top = 0;
-
- R = relation;
-
- for (i = 0; i < ngotos; i++)
- INDEX[i] = 0;
-
- for (i = 0; i < ngotos; i++)
- {
- if (INDEX[i] == 0 && R[i])
- traverse(i);
- }
-
- FREE(INDEX);
- FREE(VERTICES);
-}
-
-
-
-static void
-traverse(int i)
-{
- unsigned *fp1;
- unsigned *fp2;
- unsigned *fp3;
- int j;
- short *rp;
-
- int height;
- unsigned *base;
-
- VERTICES[++top] = i;
- INDEX[i] = height = top;
-
- base = F + i * tokensetsize;
- fp3 = base + tokensetsize;
-
- rp = R[i];
- if (rp)
- {
- while ((j = *rp++) >= 0)
- {
- if (INDEX[j] == 0)
- traverse(j);
-
- if (INDEX[i] > INDEX[j])
- INDEX[i] = INDEX[j];
-
- fp1 = base;
- fp2 = F + j * tokensetsize;
-
- while (fp1 < fp3)
- *fp1++ |= *fp2++;
- }
- }
-
- if (INDEX[i] == height)
- {
- for (;;)
- {
- j = VERTICES[top--];
- INDEX[j] = infinity;
-
- if (i == j)
- break;
-
- fp1 = base;
- fp2 = F + j * tokensetsize;
-
- while (fp1 < fp3)
- *fp2++ = *fp1++;
- }
- }
-}
View
669 usr.bin/yacc/lr0.c
@@ -1,669 +0,0 @@
-/*
- * 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. 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.
- *
- * $FreeBSD: src/usr.bin/yacc/lr0.c,v 1.6 1999/08/28 01:08:00 peter Exp $
- *
- * @(#)lr0.c 5.3 (Berkeley) 1/20/91
- */
-
-#include <stdlib.h>
-#include "defs.h"
-
-extern short *itemset;
-extern short *itemsetend;
-extern unsigned *ruleset;
-
-int nstates;
-core *first_state;
-shifts *first_shift;
-reductions *first_reduction;
-
-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 int get_state(int);
-static void initialize_states(void);
-static void new_itemsets(void);
-static core *new_state(int);
-#ifdef DEBUG
-static void print_derives(void);
-#endif
-static void save_reductions(void);
-static void save_shifts(void);
-static void set_derives(void);
-static void set_nullable(void);
-
-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 == NULL) 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] = NULL;
-
- 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);
-}
-
-
-#if 0
-/* show_cores is used for debugging */
-
-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 */
-
-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 */
-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 */
-
-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 *);
- 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
-}
-
-#if 0
-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 done;
-
- nullable = MALLOC(nsyms);
- if (nullable == 0) no_space();
-
- for (i = 0; i < nsyms; ++i)
- nullable[i] = 0;
-
- done = 0;
- while (!done)
- {
- done = 1;
- for (i = 1; i < nitems; i++)
- {
- empty = 1;
- while ((j = ritem[i]) >= 0)
- {
- if (!nullable[j])
- empty = 0;
- ++i;
- }
- if (empty)
- {
- j = rlhs[-j];
- if (!nullable[j])
- {
- nullable[j] = 1;
- done = 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
-}
-
-
-#if 0
-free_nullable(void)
-{
- FREE(nullable);
-}
-#endif
-
-
-void
-lr0(void)
-{
- set_derives();
- set_nullable();
- generate_states();
-}
View
492 usr.bin/yacc/main.c
@@ -1,492 +0,0 @@
-/*
- * 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. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. 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.
- *
- * @(#) Copyright (c) 1989 The Regents of the University of California. All rights reserved.
- * @(#)main.c 5.5 (Berkeley) 5/24/93
- * $FreeBSD: src/usr.bin/yacc/main.c,v 1.12 2000/01/10 20:26:24 kris Exp $
- */
-
-#include <signal.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include "defs.h"
-
-char dflag;
-char lflag;
-char rflag;
-char tflag;
-char vflag;
-
-const char *symbol_prefix;
-const char *file_prefix = "y";
-const char *temp_form = "yacc.XXXXXXXXXXX";
-
-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;
-