Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

25
mcs/jay/ACKNOWLEDGEMENTS Normal file
View File

@@ -0,0 +1,25 @@
Berkeley Yacc owes much to the unflagging efforts of Keith Bostic.
His badgering kept me working on it long after I was ready to quit.
Berkeley Yacc is based on the excellent algorithm for computing LALR(1)
lookaheads developed by Tom Pennello and Frank DeRemer. The algorithm is
described in their almost impenetrable article in TOPLAS 4,4.
Finally, much of the credit for the latest version must go to those
who pointed out deficiencies of my earlier releases. Among the most
prolific contributors were
Benson I. Margulies
Dave Gentzel
Antoine Verheijen
Peter S. Housel
Dale Smith
Ozan Yigit
John Campbell
Bill Sommerfeld
Paul Hilfinger
Gary Bridgewater
Dave Bakken
Dan Lanciani
Richard Sargent
Parag Patel

153
mcs/jay/ChangeLog Normal file
View File

@@ -0,0 +1,153 @@
2010-04-05 Zoltan Varga <vargaz@gmail.com>
* defs.h: Quiet warnings which might bother rpm.
2009-11-27 Marek Safar <marek.safar@gmail.com>
* skeleton.cs: Add global state stacks.
2008-10-17 Jonathan Pryor <jpryor@novell.com>
* Makefile: Add doc-update target support.
2008-09-09 Miguel de Icaza <miguel@novell.com>
* skeleton.cs: A little refactoring to support producing a list of
tokens as opposed to a list of token strings for code that uses
the yyExpecting code.
2006-05-29 Raja R Harinath <rharinath@novell.com>
* skeleton.cs: Implement a better translation for named-loop continues.
Remove "unreachable code" warnings in the generated code.
2006-04-03 Zoltan Varga <vargaz@gmail.com>
* output.c skeleton skeleton.cs: Initialize the jay debug tables
lazily. Fixes #77946.
2006-03-10 Zoltan Varga <vargaz@gmail.com>
* reader.c (copy_action): Applied patch from Axel T Schreiner (ats@cs.rit.edu).
Fixes a small bug.
2006-03-04 Martin Baulig <martin@ximian.com>
* skeleton.cs: Don't call yyerror if `yyErrorFlag == 0', so we can
recover from errors with an `error' token. See gtest-248.cs for
an example.
2006-01-06 Wade Berrier <wberrier@novell.com>
* Makefile: fix man path
2005-09-20 Konstantin Triger <kostat@mainsift.com>
* Added jay.vcproj to build jay on pure Win32
2005-03-14 Raja R Harinath <rharinath@novell.com>
* Makefile (install-local, uninstall-local): Disable when
NO_INSTALL is defined.
2004-12-07 Raja R Harinath <rharinath@novell.com>
* Makefile (uninstall-local): Remove $(prefix)/man/man1/jay.1.
2004-11-24 Miguel de Icaza <miguel@ximian.com>
* skeleton.cs: use yacc_verbose_flag to control verbosity.
2004-06-10 Rafael Teixeira <rafaelteixeirabr@hotmail.com>
* skeleton.cs: oops some uses of changed classes/interfaces also need to become internal.
2004-06-10 Atsushi Enomoto <atsushi@ximian.com>
* skelton.cs: make classes/interfaces internal.
2004-06-03 Atsushi Enomoto <atsushi@ximian.com>
* Makefile : ignore make run-test-ondotnet.
Mon May 3 08:34:32 CEST 2004 Paolo Molaro <lupus@ximian.com>
* main.c, defs.h: use the proper header files instead of broken
prototypes (thanks to Marcus for reporting).
2004-03-13 Miguel de Icaza <miguel@ximian.com>
* main.c (create_file_names): Try a few temp directories, since
Windows uses a different directory naming scheme apparently: #47696
2004-03-05 Zoltan Varga <vargaz@freemail.hu>
* main.c: Applied patch from Albert Strasheim (13640887@sun.ac.za).
Fix compilation under mingw.
2004-02-07 Miguel de Icaza <miguel@ximian.com>
* skeleton.cs: Report the token that we errored on; Helps
find parser errors.
2003-12-16 Atsushi Enomoto <atsushi@ximian.com>
* skelton.cs : Added ErrorOutput text writer.
2003-10-08 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
* output.c, skelton, skelton.cs : Renamed yyName[] to yyNames[]
to make output CLS-compliant.
2003-05-16 Peter Williams <peterw@ximian.com>
* main.c (print_skel_dir): New function called when jay is
passed '-p'; prints the directory where the default skeleton
files are installed ($(prefix)/share/jay).
* makefile (CFLAGS): Add a -DSKEL_DIRECTORY to support
print_skel_dir.
* jay.1: Document the -p parameter.
2003-05-16 Peter Williams <peterw@ximian.com>
* makefile (install): Call the install in makefile.gnu
* makefile.gnu (install): Actually install jay and its skeleton
files.
2003-02-09 Martin Baulig <martin@ximian.com>
* output.c: Use `#line default' instead of source file "-".
2003-01-13 Jackson Harper <jackson@latitudegeo.com>
* skeleton.cs: Remove cleanup stuff, it has been moved to a better spot.
2003-01-13 Duncan Mak <duncan@ximian.com>
* skeleton.cs (cleanpup): Rename to cleanup to make it look more consistent.
2003-01-13 Jackson Harper <jackson@latitudegeo.com>
* skeleton.cs: Call lexer.Cleanup when the lexer reaches the EOF.
2002-08-20 Miguel de Icaza <miguel@ximian.com>
* skeleton.cs: Fix the code that expanded the arrays dynamically,
it was broken, and instead was copying 0 elements.
2002-07-10 Alp Toker <alp@atoker.com>
* main.c: mktemp() is deprecated with gcc 3.1.1, use mkstemp() instead
2001-07-15 Sean MacIsaac <macisaac@ximian.com>
* makefile: added windows and unix targets.
2001-07-14 Sean MacIsaac <macisaac@ximian.com>
* main.c: fixed error in command line flag -c if it was not first
option.

52
mcs/jay/Makefile Normal file
View File

@@ -0,0 +1,52 @@
thisdir := jay
SUBDIRS :=
include ../build/rules.make
LOCAL_CFLAGS = -DSKEL_DIRECTORY=\""$(prefix)/share/jay"\"
sources = closure.c error.c lalr.c lr0.c main.c mkpar.c output.c reader.c \
symtab.c verbose.c warshall.c
datafiles = ACKNOWLEDGEMENTS NEW_FEATURES NOTES README README.jay skeleton \
skeleton.cs
DISTFILES = $(datafiles) $(sources) jay.1 $(wildcard *.h) jay.vcxproj
all-local: jay
install-local: jay
uninstall-local:
ifndef NO_INSTALL
install-local:
$(MKINSTALLDIRS) $(DESTDIR)$(prefix)/bin
$(MKINSTALLDIRS) $(DESTDIR)$(prefix)/share/jay
$(MKINSTALLDIRS) $(DESTDIR)$(prefix)/share/man/man1
$(INSTALL_BIN) jay $(DESTDIR)$(prefix)/bin
for datafile in $(datafiles) ; do \
$(INSTALL_DATA) $$datafile $(DESTDIR)$(prefix)/share/jay ; \
done
$(INSTALL_DATA) jay.1 $(DESTDIR)$(prefix)/share/man/man1
uninstall-local:
-rm -f $(DESTDIR)$(prefix)/bin/jay
for datafile in $(datafiles) ; do \
rm -f $(DESTDIR)$(prefix)/share/jay/$$datafile || : ; \
done
-rm -f $(DESTDIR)$(prefix)/share/man/man1/jay.1
endif
csproj-local:
clean-local:
rm -f jay *.o *.exe *.pdb
dist-local: dist-default
test-local run-test-local run-test-ondotnet-local doc-update-local:
jay: $(sources:.c=.o)
$(CCOMPILE) $(LDFLAGS) -o $@ $^
%.o: %.c
$(CCOMPILE) $(JAY_CFLAGS) -c -o $@ $^

46
mcs/jay/NEW_FEATURES Normal file
View File

@@ -0,0 +1,46 @@
The -r option has been implemented. The -r option tells Yacc to
put the read-only tables in y.tab.c and the code and variables in
y.code.c. Keith Bostic asked for this option so that :yyfix could be
eliminated.
The -l and -t options have been implemented. The -l option tells
Yacc not to include #line directives in the code it produces. The -t
option causes debugging code to be included in the compiled parser.
The code for error recovery has been changed to implement the same
algorithm as AT&T Yacc. There will still be differences in the way
error recovery works because AT&T Yacc uses more default reductions
than Berkeley Yacc.
The environment variable TMPDIR determines the directory where
temporary files will be created. If TMPDIR is defined, temporary files
will be created in the directory whose pathname is the value of TMPDIR.
By default, temporary files are created in /tmp.
The keywords are now case-insensitive. For example, %nonassoc,
%NONASSOC, %NonAssoc, and %nOnAsSoC are all equivalent.
Commas and semicolons that are not part of C code are treated as
commentary.
Line-end comments, as in BCPL, are permitted. Line-end comments
begin with // and end at the next end-of-line. Line-end comments are
permitted in C code; they are converted to C comments on output.
The form of y.output files has been changed to look more like
those produced by AT&T Yacc.
A new kind of declaration has been added. The form of the declaration
is
%ident string
where string is a sequence of characters begining with a double quote
and ending with either a double quote or the next end-of-line, whichever
comes first. The declaration will cause a #ident directive to be written
near the start of the output file.
If a parser has been compiled with debugging code, that code can be
enabled by setting an environment variable. If the environment variable
YYDEBUG is set to 0, debugging output is suppressed. If it is set to 1,
debugging output is written to standard output.

9
mcs/jay/NOTES Normal file
View File

@@ -0,0 +1,9 @@
Berkeley Yacc reflects its origins. The reason so many routines
use exactly six register variables is that Berkeley Yacc was
developed on a VAX using PCC. PCC placed at most six variables
in registers. I went to considerable effort to find which six
variables most belonged in registers. Changes in machines and
compilers make that effort worthless, perhaps even harmful.
The code contains many instances where address calculations are
performed in particular ways to optimize the code for the VAX.

6
mcs/jay/README Normal file
View File

@@ -0,0 +1,6 @@
This is a port of Jay to C#, the original Jay can be found here:
http://www.informatik.uni-osnabrueck.de/bernd/jay/
The original README from Jay is in `README.jay'
Miguel

55
mcs/jay/README.jay Normal file
View File

@@ -0,0 +1,55 @@
This version of Berkeley Yacc was taken from the BSD-Lite CD and targeted
to Java by
axel.schreiner@informatik.uni-osnabrueck.de
Makefile -> makefile removed Berkeleyisms, call it jay
defs.h eliminate -dlpr options, %union, output_file, #ident
eliminate sekeleton.c references
error.c eliminate %union
main.c eliminate -dlpr options, %union, output_file
output.c eliminate -dlpr options, %union, output_file
fix #define, short, -t/yyDebug
respell YYERRCODE, YYTABLESIZE, YYFINAL, YYMAXTOKEN
output trailer last
switch to filter behaviour
reader.c eliminate output_file, #ident
#line -> // line, pass //
yyvsp[] -> yyVals[yyTop], yyval -> yyVal
skeleton.c -> skeleton Java skeleton
test removed
yacc.1 -> jay.1 adapted
yyfix.* removed
Types: there is a significant difference. yacc uses %union to cast the value
stack and <tag> to select alternatives. This works for l- and r-values alike.
jay uses Object as the value stack and <tag> to set a class. l-values must not
be cast. $n should not be assigned to, but $$ usually is. $n is referenced,
but $$ usually is not. Consequently jay casts $n and $<tag>$ but not $<>n
and $$. This makes assignment to $n references to $$ kludgily possible.
As another kludge, to prevent 'untyped' messages and to avoid unnecessary
casts, casts to "Object" are not emitted.
-------------------------------------------------------------------------------
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.

295
mcs/jay/closure.c Normal file
View File

@@ -0,0 +1,295 @@
/*
* 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.
*/
#ifndef lint
static char sccsid[] = "@(#)closure.c 5.3 (Berkeley) 5/24/93";
#endif /* not lint */
#include "defs.h"
short *itemset;
short *itemsetend;
unsigned *ruleset;
static unsigned *first_derives;
static unsigned *EFF;
set_EFF()
{
register unsigned *row;
register int symbol;
register short *sp;
register int rowsize;
register int i;
register 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
}
set_first_derives()
{
register unsigned *rrow;
register unsigned *vrow;
register int j;
register unsigned k;
register unsigned cword;
register 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);
}
closure(nucleus, n)
short *nucleus;
int n;
{
register int ruleno;
register unsigned word;
register unsigned i;
register short *csp;
register unsigned *dsp;
register unsigned *rsp;
register 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
}
finalize_closure()
{
FREE(itemset);
FREE(ruleset);
FREE(first_derives + ntokens * WORDSIZE(nrules));
}
#ifdef DEBUG
print_closure(n)
int n;
{
register short *isp;
printf("\n\nn = %d\n\n", n);
for (isp = itemset; isp < itemsetend; isp++)
printf(" %d\n", *isp);
}
print_EFF()
{
register int i, j;
register unsigned *rowp;
register unsigned word;
register 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]);
}
}
}
print_first_derives()
{
register int i;
register int j;
register unsigned *rp;
register unsigned cword;
register 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

307
mcs/jay/defs.h Normal file
View File

@@ -0,0 +1,307 @@
/*
* 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
*/
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
/* Quiet warnings which might bother rpm */
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wimplicit-function-declaration"
#pragma GCC diagnostic ignored "-Wreturn-type"
#endif
/* 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
/* 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 tflag;
extern char vflag;
extern char *myname;
extern char *cptr;
extern char *line;
extern int lineno;
extern int outline;
extern char *action_file_name;
extern char *input_file_name;
extern char *prolog_file_name;
extern char *local_file_name;
extern char *verbose_file_name;
extern FILE *action_file;
extern FILE *input_file;
extern FILE *prolog_file;
extern FILE *local_file;
extern FILE *verbose_file;
extern int nitems;
extern int nrules;
extern int nsyms;
extern int ntokens;
extern int nvars;
extern int ntags;
extern int nmethods;
extern char *line_format;
extern char *default_line_format;
extern int start_symbol;
extern char **symbol_name;
extern short *symbol_value;
extern short *symbol_prec;
extern char *symbol_assoc;
extern char **methods;
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();
extern bucket *lookup();
extern bucket *make_bucket();

335
mcs/jay/error.c Normal file
View File

@@ -0,0 +1,335 @@
/*
* 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.
*/
#ifndef lint
static char sccsid[] = "@(#)error.c 5.3 (Berkeley) 6/1/90";
#endif /* not lint */
/* routines for printing error messages */
#include "defs.h"
fatal(msg)
char *msg;
{
fprintf(stderr, "%s: f - %s\n", myname, msg);
done(2);
}
no_space()
{
fprintf(stderr, "%s: f - out of space\n", myname);
done(2);
}
open_error(filename)
char *filename;
{
fprintf(stderr, "%s: f - cannot open \"%s\"\n", myname, filename);
done(2);
}
unexpected_EOF()
{
fprintf(stderr, "%s: e - line %d of \"%s\", unexpected end-of-file\n",
myname, lineno, input_file_name);
done(1);
}
print_pos(st_line, st_cptr)
char *st_line;
char *st_cptr;
{
register char *s;
if (st_line == 0) 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);
}
syntax_error(st_lineno, st_line, st_cptr)
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);
}
unterminated_comment(c_lineno, c_line, c_cptr)
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);
}
unterminated_string(s_lineno, s_line, s_cptr)
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);
}
unterminated_text(t_lineno, t_line, t_cptr)
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);
}
illegal_tag(t_lineno, t_line, t_cptr)
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);
}
illegal_character(c_cptr)
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);
}
used_reserved(s)
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);
}
tokenized_start(s)
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);
}
retyped_warning(s)
char *s;
{
fprintf(stderr, "%s: w - line %d of \"%s\", the type of %s has been \
redeclared\n", myname, lineno, input_file_name, s);
}
reprec_warning(s)
char *s;
{
fprintf(stderr, "%s: w - line %d of \"%s\", the precedence of %s has been \
redeclared\n", myname, lineno, input_file_name, s);
}
revalued_warning(s)
char *s;
{
fprintf(stderr, "%s: w - line %d of \"%s\", the value of %s has been \
redeclared\n", myname, lineno, input_file_name, s);
}
terminal_start(s)
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);
}
restarted_warning()
{
fprintf(stderr, "%s: w - line %d of \"%s\", the start symbol has been \
redeclared\n", myname, lineno, input_file_name);
}
no_grammar()
{
fprintf(stderr, "%s: e - line %d of \"%s\", no grammar has been \
specified\n", myname, lineno, input_file_name);
done(1);
}
terminal_lhs(s_lineno)
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);
}
prec_redeclared()
{
fprintf(stderr, "%s: w - line %d of \"%s\", conflicting %%prec \
specifiers\n", myname, lineno, input_file_name);
}
unterminated_action(a_lineno, a_line, a_cptr)
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);
}
dollar_warning(a_lineno, i)
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);
}
dollar_error(a_lineno, a_line, a_cptr)
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);
}
untyped_lhs()
{
fprintf(stderr, "%s: w - line %d of \"%s\", $$ is untyped\n",
myname, lineno, input_file_name);
/** done(1); */
}
untyped_rhs(i, s)
int i;
char *s;
{
fprintf(stderr, "%s: w - line %d of \"%s\", $%d (%s) is untyped\n",
myname, lineno, input_file_name, i, s);
/** done(1); */
}
unknown_rhs(i)
int i;
{
fprintf(stderr, "%s: e - line %d of \"%s\", $%d is untyped\n",
myname, lineno, input_file_name, i);
done(1);
}
default_action_warning()
{
fprintf(stderr, "%s: w - line %d of \"%s\", the default action assigns an \
undefined value to $$\n", myname, lineno, input_file_name);
}
undefined_goal(s)
char *s;
{
fprintf(stderr, "%s: e - the start symbol %s is undefined\n", myname, s);
done(1);
}
undefined_symbol_warning(s)
char *s;
{
fprintf(stderr, "%s: w - the symbol %s is undefined\n", myname, s);
}

134
mcs/jay/jay.1 Normal file
View File

@@ -0,0 +1,134 @@
.\" 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. 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.
.\"
.\" @(#)yacc.1 5.8 (Berkeley) 5/24/93
.\"
.TH JAY 1 "May 24, 1993 / July 8, 1998"
.UC 6
.SH NAME
jay \- an LALR(1) parser generator for Java and C#
.SH SYNOPSIS
.B jay [ -tv ] [ -c ] [ -p ] [ -b
.I file_prefix
.B ] [ -V
.I yyValue
.B ]
.I filename
.B <
.I skeleton
.SH DESCRIPTION
.I Jay
reads the grammar specification in the file
.I filename
and generates an LR(1) parser for it.
The parsers consist of a set of LALR(1) parsing tables and a driver routine
from the file
.I skeleton
written in the Java programming language.
.I Jay
writes the parse tables and the driver routine to standard output.
.PP
The following options are available:
.RS
.TP
\fB-b \fIfile_prefix\fR
The
.B -b
option changes the prefix prepended to the output file names to
the string denoted by
.IR file_prefix.
The default prefix is the character
.IR y.
.TP
.B -c
The
.B -c
option makes jay generate C# code instead of the default Java.
.TP
.B -t
The
.B -t
option arranges for
debugging information to be incorporated in the compiled code.
.TP
.B -v
The
.B -v
option causes a human-readable description of the generated parser to
be written to the file
.IR y.output.
.TP
.B -p
The
.B -p
option causes
.I jay
to print the directory in which its sample skeleton files are
installed. If a project wants to use the default skeleton file
included with \fIjay\fR, it can use this option in a makefile to
find the path to the
.I skeleton
or
.I skeleton.cs
file included with the jay distribution.
.RE
.PP
If the environment variable TMPDIR is set, the string denoted by
TMPDIR will be used as the name of the directory where the temporary
files are created.
.SH FILES
.IR skeleton
.br
.IR y.output
.br
.IR /tmp/yacc.aXXXXXX
.br
.IR /tmp/yacc.tXXXXXX
.br
.IR /tmp/yacc.uXXXXXX
.SH DIAGNOSTICS
If there are rules that are never reduced, the number of such rules is
reported on standard error.
If there are any LALR(1) conflicts, the number of conflicts is reported
on standard error.
.SH HISTORY
.I Jay
is derived from Berkeley
.I yacc .
Input conventions closely follow those of
.I yacc ;
for details,
consult the parser
.I skeleton
file and the commented example included with the sources.

105
mcs/jay/jay.vcxproj Normal file
View File

@@ -0,0 +1,105 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{5D485D32-3B9F-4287-AB24-C8DA5B89F537}</ProjectGuid>
<RootNamespace>jay</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Debug\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Debug\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Release\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Release\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>SKEL_DIRECTORY=".";%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
</ClCompile>
<Link>
<OutputFile>$(ProjectDir)/jay.exe</OutputFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ProgramDatabaseFile>$(OutDir)jay.pdb</ProgramDatabaseFile>
<SubSystem>Console</SubSystem>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PreprocessorDefinitions>SKEL_DIRECTORY=".";%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<OutputFile>$(ProjectDir)/jay.exe</OutputFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="closure.c" />
<ClCompile Include="error.c" />
<ClCompile Include="lalr.c" />
<ClCompile Include="lr0.c" />
<ClCompile Include="main.c" />
<ClCompile Include="mkpar.c" />
<ClCompile Include="output.c" />
<ClCompile Include="reader.c" />
<ClCompile Include="symtab.c" />
<ClCompile Include="verbose.c" />
<ClCompile Include="warshall.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="defs.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

678
mcs/jay/lalr.c Normal file

File diff suppressed because it is too large Load Diff

637
mcs/jay/lr0.c Normal file

File diff suppressed because it is too large Load Diff

371
mcs/jay/main.c Normal file
View File

@@ -0,0 +1,371 @@
/*
* 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.
*/
#ifndef lint
char copyright[] =
"@(#) Copyright (c) 1989 The Regents of the University of California.\n\
All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)main.c 5.5 (Berkeley) 5/24/93";
#endif /* not lint */
#include <signal.h>
#include "defs.h"
char tflag;
char vflag;
int csharp = 0;
char *file_prefix = "y";
char *myname = "yacc";
char *temp_form = "yacc.XXXXXXX";
int lineno;
int outline;
char *action_file_name;
char *input_file_name = "";
char *prolog_file_name;
char *local_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 *input_file; /* the input file */
FILE *prolog_file; /* temp files, used to save text until all */
FILE *local_file; /* symbols have been defined */
FILE *verbose_file; /* y.output */
int nitems;
int nrules;
int nsyms;
int ntokens;
int nvars;
int nmethods;
int start_symbol;
char **symbol_name;
short *symbol_value;
short *symbol_prec;
char *symbol_assoc;
char **methods;
short *ritem;
short *rlhs;
short *rrhs;
short *rprec;
char *rassoc;
short **derives;
char *nullable;
#if defined(_WIN32) && !defined(__CYGWIN32__) && !defined(__CYGWIN__)
extern char* mktemp();
#define mkstemp mktemp
#endif
extern char *getenv();
done(k)
int k;
{
if (action_file) { fclose(action_file); unlink(action_file_name); }
if (prolog_file) { fclose(prolog_file); unlink(prolog_file_name); }
if (local_file) { fclose(local_file); unlink(local_file_name); }
exit(k);
}
void
onintr(signo)
int signo;
{
done(1);
}
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
}
usage()
{
fprintf(stderr, "usage: %s [-tvcp] [-b file_prefix] filename\n", myname);
exit(1);
}
void
print_skel_dir(void)
{
printf ("%s\n", SKEL_DIRECTORY);
exit (0);
}
getargs(argc, argv)
int argc;
char *argv[];
{
register int i;
register 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 't':
tflag = 1;
break;
case 'p':
print_skel_dir ();
break;
case 'c':
csharp = 1;
line_format = "#line %d \"%s\"\n";
default_line_format = "#line default\n";
break;
case 'v':
vflag = 1;
break;
default:
usage();
}
for (;;)
{
switch (*++s)
{
case '\0':
goto end_of_option;
case 't':
tflag = 1;
break;
case 'v':
vflag = 1;
break;
case 'p':
print_skel_dir ();
break;
case 'c':
csharp = 1;
line_format = "#line %d \"%s\"\n";
default_line_format = "#line default\n";
break;
default:
usage();
}
}
end_of_option:;
}
no_more_options:;
if (i + 1 != argc) usage();
input_file_name = argv[i];
}
char *
allocate(n)
unsigned n;
{
register char *p;
p = NULL;
if (n)
{
p = CALLOC(1, n);
if (!p) no_space();
}
return (p);
}
create_file_names()
{
int i, len;
char *tmpdir;
#if defined(_WIN32) && !defined(__CYGWIN32__) && !defined(__CYGWIN__)
tmpdir = ".";
#else
tmpdir = getenv("TMPDIR");
if (tmpdir == 0) tmpdir = getenv ("TMP");
if (tmpdir == 0) tmpdir = getenv ("TEMP");
if (tmpdir == 0) tmpdir = "/tmp";
#endif
len = strlen(tmpdir);
i = len + 13;
if (len && tmpdir[len-1] != '/')
++i;
action_file_name = MALLOC(i);
if (action_file_name == 0) no_space();
prolog_file_name = MALLOC(i);
if (prolog_file_name == 0) no_space();
local_file_name = MALLOC(i);
if (local_file_name == 0) no_space();
strcpy(action_file_name, tmpdir);
strcpy(prolog_file_name, tmpdir);
strcpy(local_file_name, tmpdir);
if (len && tmpdir[len - 1] != '/')
{
action_file_name[len] = '/';
prolog_file_name[len] = '/';
local_file_name[len] = '/';
++len;
}
strcpy(action_file_name + len, temp_form);
strcpy(prolog_file_name + len, temp_form);
strcpy(local_file_name + len, temp_form);
action_file_name[len + 5] = 'a';
prolog_file_name[len + 5] = 'p';
local_file_name[len + 5] = 'l';
mkstemp(action_file_name);
mkstemp(prolog_file_name);
mkstemp(local_file_name);
len = strlen(file_prefix);
if (vflag)
{
verbose_file_name = MALLOC(len + 8);
if (verbose_file_name == 0)
no_space();
strcpy(verbose_file_name, file_prefix);
strcpy(verbose_file_name + len, VERBOSE_SUFFIX);
}
}
open_files()
{
create_file_names();
if (input_file == 0)
{
input_file = fopen(input_file_name, "r");
if (input_file == 0)
open_error(input_file_name);
}
action_file = fopen(action_file_name, "w");
if (action_file == 0)
open_error(action_file_name);
prolog_file = fopen(prolog_file_name, "w");
if (prolog_file == 0)
open_error(prolog_file_name);
local_file = fopen(local_file_name, "w");
if (local_file == 0)
open_error(local_file_name);
if (vflag)
{
verbose_file = fopen(verbose_file_name, "w");
if (verbose_file == 0)
open_error(verbose_file_name);
}
}
int
main(argc, argv)
int argc;
char *argv[];
{
set_signals();
getargs(argc, argv);
open_files();
reader();
lr0();
lalr();
make_parser();
verbose();
output();
done(0);
/*NOTREACHED*/
}

395
mcs/jay/mkpar.c Normal file
View File

@@ -0,0 +1,395 @@
/*
* 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.
*/
#ifndef lint
static char sccsid[] = "@(#)mkpar.c 5.3 (Berkeley) 1/20/91";
#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;
extern action *parse_actions();
extern action *get_shifts();
extern action *add_reductions();
extern action *add_reduce();
make_parser()
{
register 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();
}
action *
parse_actions(stateno)
register int stateno;
{
register action *actions;
actions = get_shifts(stateno);
actions = add_reductions(stateno, actions);
return (actions);
}
action *
get_shifts(stateno)
int stateno;
{
register action *actions, *temp;
register shifts *sp;
register short *to_state;
register int i, k;
register int symbol;
actions = 0;
sp = shift_table[stateno];
if (sp)
{
to_state = sp->shift;
for (i = sp->nshifts - 1; i >= 0; i--)
{
k = to_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);
}
action *
add_reductions(stateno, actions)
int stateno;
register action *actions;
{
register int i, j, m, n;
register int ruleno, tokensetsize;
register 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);
}
action *
add_reduce(actions, ruleno, symbol)
register action *actions;
register int ruleno, symbol;
{
register 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);
}
find_final_state()
{
register int goal, i;
register short *to_state;
register shifts *p;
p = shift_table[0];
to_state = p->shift;
goal = ritem[1];
for (i = p->nshifts - 1; i >= 0; --i)
{
final_state = to_state[i];
if (accessing_symbol[final_state] == goal) break;
}
}
unused_rules()
{
register int i;
register 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);
}
remove_conflicts()
{
register int i;
register int symbol;
register action *p, *pref;
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 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;
}
}
total_conflicts()
{
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");
}
int
sole_reduction(stateno)
int stateno;
{
register int count, ruleno;
register 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);
}
defreds()
{
register int i;
defred = NEW2(nstates, short);
for (i = 0; i < nstates; i++)
defred[i] = sole_reduction(i);
}
free_action_row(p)
register action *p;
{
register action *q;
while (p)
{
q = p->next;
FREE(p);
p = q;
}
}
free_parser()
{
register int i;
for (i = 0; i < nstates; i++)
free_action_row(parser[i]);
FREE(parser);
}

1191
mcs/jay/output.c Normal file

File diff suppressed because it is too large Load Diff

1691
mcs/jay/reader.c Normal file

File diff suppressed because it is too large Load Diff

268
mcs/jay/skeleton Normal file
View File

@@ -0,0 +1,268 @@
# jay skeleton
# character in column 1 determines outcome...
# # is a comment
# . is copied
# t is copied as //t if -t is set
# other lines are interpreted to call jay procedures
.// created by jay 0.7 (c) 1998 Axel.Schreiner@informatik.uni-osnabrueck.de
.
prolog ## %{ ... %} prior to the first %%
.// %token constants
.
tokens public static final int
.
. /** thrown for irrecoverable syntax errors and stack overflow.
. */
. public static class yyException extends java.lang.Exception {
. public yyException (String message) {
. super(message);
. }
. }
.
. /** must be implemented by a scanner object to supply input to the parser.
. */
. public interface yyInput {
. /** move on to next token.
. @return false if positioned beyond tokens.
. @throws IOException on input error.
. */
. boolean advance () throws java.io.IOException;
. /** classifies current token.
. Should not be called if advance() returned false.
. @return current %token or single character.
. */
. int token ();
. /** associated with current token.
. Should not be called if advance() returned false.
. @return value for token().
. */
. Object value ();
. }
.
. /** simplified error message.
. @see <a href="#yyerror(java.lang.String, java.lang.String[])">yyerror</a>
. */
. public void yyerror (String message) {
. yyerror(message, null);
. }
.
. /** (syntax) error message.
. Can be overwritten to control message format.
. @param message text to be displayed.
. @param expected vector of acceptable tokens, if available.
. */
. public void yyerror (String message, String[] expected) {
. if (expected != null && expected.length > 0) {
. System.err.print(message+", expecting");
. for (int n = 0; n < expected.length; ++ n)
. System.err.print(" "+expected[n]);
. System.err.println();
. } else
. System.err.println(message);
. }
.
. /** debugging support, requires the package jay.yydebug.
. Set to null to suppress debugging messages.
. */
t protected jay.yydebug.yyDebug yydebug;
.
debug ## tables for debugging support
.
. /** index-checked interface to yyNames[].
. @param token single character or %token value.
. @return token name or [illegal] or [unknown].
. */
t public static final String yyname (int token) {
t if (token < 0 || token > yyNames.length) return "[illegal]";
t String name;
t if ((name = yyNames[token]) != null) return name;
t return "[unknown]";
t }
.
. /** computes list of expected tokens on error by tracing the tables.
. @param state for which to compute the list.
. @return list of token names.
. */
. protected String[] yyExpecting (int state) {
. int token, n, len = 0;
. boolean[] ok = new boolean[yyNames.length];
.
. if ((n = yySindex[state]) != 0)
. for (token = n < 0 ? -n : 0;
. token < yyNames.length && n+token < yyTable.length; ++ token)
. if (yyCheck[n+token] == token && !ok[token] && yyNames[token] != null) {
. ++ len;
. ok[token] = true;
. }
. if ((n = yyRindex[state]) != 0)
. for (token = n < 0 ? -n : 0;
. token < yyNames.length && n+token < yyTable.length; ++ token)
. if (yyCheck[n+token] == token && !ok[token] && yyNames[token] != null) {
. ++ len;
. ok[token] = true;
. }
.
. String result[] = new String[len];
. for (n = token = 0; n < len; ++ token)
. if (ok[token]) result[n++] = yyNames[token];
. return result;
. }
.
. /** the generated parser, with debugging messages.
. Maintains a state and a value stack, currently with fixed maximum size.
. @param yyLex scanner.
. @param yydebug debug message writer implementing yyDebug, or null.
. @return result of the last reduction, if any.
. @throws yyException on irrecoverable parse error.
. */
. public Object yyparse (yyInput yyLex, Object yydebug)
. throws java.io.IOException, yyException {
t this.yydebug = (jay.yydebug.yyDebug)yydebug;
. return yyparse(yyLex);
. }
.
. /** initial size and increment of the state/value stack [default 256].
. This is not final so that it can be overwritten outside of invocations
. of yyparse().
. */
. protected int yyMax;
.
. /** executed at the beginning of a reduce action.
. Used as $$ = yyDefault($1), prior to the user-specified action, if any.
. Can be overwritten to provide deep copy, etc.
. @param first value for $1, or null.
. @return first.
. */
. protected Object yyDefault (Object first) {
. return first;
. }
.
. /** the generated parser.
. Maintains a state and a value stack, currently with fixed maximum size.
. @param yyLex scanner.
. @return result of the last reduction, if any.
. @throws yyException on irrecoverable parse error.
. */
. public Object yyparse (yyInput yyLex)
. throws java.io.IOException, yyException {
. if (yyMax <= 0) yyMax = 256; // initial size
. int yyState = 0, yyStates[] = new int[yyMax]; // state stack
. Object yyVal = null, yyVals[] = new Object[yyMax]; // value stack
. int yyToken = -1; // current input
. int yyErrorFlag = 0; // #tks to shift
.
local ## %{ ... %} after the first %%
. yyLoop: for (int yyTop = 0;; ++ yyTop) {
. if (yyTop >= yyStates.length) { // dynamically increase
. int[] i = new int[yyStates.length+yyMax];
. System.arraycopy(yyStates, 0, i, 0, yyStates.length);
. yyStates = i;
. Object[] o = new Object[yyVals.length+yyMax];
. System.arraycopy(yyVals, 0, o, 0, yyVals.length);
. yyVals = o;
. }
. yyStates[yyTop] = yyState;
. yyVals[yyTop] = yyVal;
t if (yydebug != null) yydebug.push(yyState, yyVal);
.
. yyDiscarded: for (;;) { // discarding a token does not change stack
. int yyN;
. if ((yyN = yyDefRed[yyState]) == 0) { // else [default] reduce (yyN)
. if (yyToken < 0) {
. yyToken = yyLex.advance() ? yyLex.token() : 0;
t if (yydebug != null)
t yydebug.lex(yyState, yyToken, yyname(yyToken), yyLex.value());
. }
. if ((yyN = yySindex[yyState]) != 0 && (yyN += yyToken) >= 0
. && yyN < yyTable.length && yyCheck[yyN] == yyToken) {
t if (yydebug != null)
t yydebug.shift(yyState, yyTable[yyN], yyErrorFlag-1);
. yyState = yyTable[yyN]; // shift to yyN
. yyVal = yyLex.value();
. yyToken = -1;
. if (yyErrorFlag > 0) -- yyErrorFlag;
. continue yyLoop;
. }
. if ((yyN = yyRindex[yyState]) != 0 && (yyN += yyToken) >= 0
. && yyN < yyTable.length && yyCheck[yyN] == yyToken)
. yyN = yyTable[yyN]; // reduce (yyN)
. else
. switch (yyErrorFlag) {
.
. case 0:
. yyerror("syntax error", yyExpecting(yyState));
t if (yydebug != null) yydebug.error("syntax error");
.
. case 1: case 2:
. yyErrorFlag = 3;
. do {
. if ((yyN = yySindex[yyStates[yyTop]]) != 0
. && (yyN += yyErrorCode) >= 0 && yyN < yyTable.length
. && yyCheck[yyN] == yyErrorCode) {
t if (yydebug != null)
t yydebug.shift(yyStates[yyTop], yyTable[yyN], 3);
. yyState = yyTable[yyN];
. yyVal = yyLex.value();
. continue yyLoop;
. }
t if (yydebug != null) yydebug.pop(yyStates[yyTop]);
. } while (-- yyTop >= 0);
t if (yydebug != null) yydebug.reject();
. throw new yyException("irrecoverable syntax error");
.
. case 3:
. if (yyToken == 0) {
t if (yydebug != null) yydebug.reject();
. throw new yyException("irrecoverable syntax error at end-of-file");
. }
t if (yydebug != null)
t yydebug.discard(yyState, yyToken, yyname(yyToken),
t yyLex.value());
. yyToken = -1;
. continue yyDiscarded; // leave stack alone
. }
. }
. int yyV = yyTop + 1-yyLen[yyN];
t if (yydebug != null)
t yydebug.reduce(yyState, yyStates[yyV-1], yyN, YYRules.getRule[yyN], yyLen[yyN]);
. yyVal = yyDefault(yyV > yyTop ? null : yyVals[yyV]);
. switch (yyN) {
actions ## code from the actions within the grammar
. }
. yyTop -= yyLen[yyN];
. yyState = yyStates[yyTop];
. int yyM = yyLhs[yyN];
. if (yyState == 0 && yyM == 0) {
t if (yydebug != null) yydebug.shift(0, yyFinal);
. yyState = yyFinal;
. if (yyToken < 0) {
. yyToken = yyLex.advance() ? yyLex.token() : 0;
t if (yydebug != null)
t yydebug.lex(yyState, yyToken,yyname(yyToken), yyLex.value());
. }
. if (yyToken == 0) {
t if (yydebug != null) yydebug.accept(yyVal);
. return yyVal;
. }
. continue yyLoop;
. }
. if ((yyN = yyGindex[yyM]) != 0 && (yyN += yyState) >= 0
. && yyN < yyTable.length && yyCheck[yyN] == yyState)
. yyState = yyTable[yyN];
. else
. yyState = yyDgoto[yyM];
t if (yydebug != null) yydebug.shift(yyStates[yyTop], yyState);
. continue yyLoop;
. }
. }
. }
.
tables ## tables for rules, default reduction, and action calls
.
epilog ## text following second %%

391
mcs/jay/skeleton.cs Normal file
View File

@@ -0,0 +1,391 @@
# jay skeleton
# character in column 1 determines outcome...
# # is a comment
# . is copied
# t is copied as //t if -t is set
# other lines are interpreted to call jay procedures
.// created by jay 0.7 (c) 1998 Axel.Schreiner@informatik.uni-osnabrueck.de
.
prolog ## %{ ... %} prior to the first %%
.
. /** error output stream.
. It should be changeable.
. */
. public System.IO.TextWriter ErrorOutput = System.Console.Out;
.
. /** simplified error message.
. @see <a href="#yyerror(java.lang.String, java.lang.String[])">yyerror</a>
. */
. public void yyerror (string message) {
. yyerror(message, null);
. }
.#pragma warning disable 649
. /* An EOF token */
. public int eof_token;
.#pragma warning restore 649
. /** (syntax) error message.
. Can be overwritten to control message format.
. @param message text to be displayed.
. @param expected vector of acceptable tokens, if available.
. */
. public void yyerror (string message, string[] expected) {
. if ((yacc_verbose_flag > 0) && (expected != null) && (expected.Length > 0)) {
. ErrorOutput.Write (message+", expecting");
. for (int n = 0; n < expected.Length; ++ n)
. ErrorOutput.Write (" "+expected[n]);
. ErrorOutput.WriteLine ();
. } else
. ErrorOutput.WriteLine (message);
. }
.
. /** debugging support, requires the package jay.yydebug.
. Set to null to suppress debugging messages.
. */
t internal yydebug.yyDebug debug;
.
debug ## tables for debugging support
.
. /** index-checked interface to yyNames[].
. @param token single character or %token value.
. @return token name or [illegal] or [unknown].
. */
t public static string yyname (int token) {
t if ((token < 0) || (token > yyNames.Length)) return "[illegal]";
t string name;
t if ((name = yyNames[token]) != null) return name;
t return "[unknown]";
t }
.
.#pragma warning disable 414
. int yyExpectingState;
.#pragma warning restore 414
. /** computes list of expected tokens on error by tracing the tables.
. @param state for which to compute the list.
. @return list of token names.
. */
. protected int [] yyExpectingTokens (int state){
. int token, n, len = 0;
. bool[] ok = new bool[yyNames.Length];
. if ((n = yySindex[state]) != 0)
. for (token = n < 0 ? -n : 0;
. (token < yyNames.Length) && (n+token < yyTable.Length); ++ token)
. if (yyCheck[n+token] == token && !ok[token] && yyNames[token] != null) {
. ++ len;
. ok[token] = true;
. }
. if ((n = yyRindex[state]) != 0)
. for (token = n < 0 ? -n : 0;
. (token < yyNames.Length) && (n+token < yyTable.Length); ++ token)
. if (yyCheck[n+token] == token && !ok[token] && yyNames[token] != null) {
. ++ len;
. ok[token] = true;
. }
. int [] result = new int [len];
. for (n = token = 0; n < len; ++ token)
. if (ok[token]) result[n++] = token;
. return result;
. }
. protected string[] yyExpecting (int state) {
. int [] tokens = yyExpectingTokens (state);
. string [] result = new string[tokens.Length];
. for (int n = 0; n < tokens.Length; n++)
. result[n++] = yyNames[tokens [n]];
. return result;
. }
.
. /** the generated parser, with debugging messages.
. Maintains a state and a value stack, currently with fixed maximum size.
. @param yyLex scanner.
. @param yydebug debug message writer implementing yyDebug, or null.
. @return result of the last reduction, if any.
. @throws yyException on irrecoverable parse error.
. */
. internal Object yyparse (yyParser.yyInput yyLex, Object yyd)
. {
t this.debug = (yydebug.yyDebug)yyd;
. return yyparse(yyLex);
. }
.
. /** initial size and increment of the state/value stack [default 256].
. This is not final so that it can be overwritten outside of invocations
. of yyparse().
. */
. protected int yyMax;
.
. /** executed at the beginning of a reduce action.
. Used as $$ = yyDefault($1), prior to the user-specified action, if any.
. Can be overwritten to provide deep copy, etc.
. @param first value for $1, or null.
. @return first.
. */
. protected Object yyDefault (Object first) {
. return first;
. }
.
. static int[] global_yyStates;
. static object[] global_yyVals;
.#pragma warning disable 649
. protected bool use_global_stacks;
.#pragma warning restore 649
. object[] yyVals; // value stack
. object yyVal; // value stack ptr
. int yyToken; // current input
. int yyTop;
.
. /** the generated parser.
. Maintains a state and a value stack, currently with fixed maximum size.
. @param yyLex scanner.
. @return result of the last reduction, if any.
. @throws yyException on irrecoverable parse error.
. */
. internal Object yyparse (yyParser.yyInput yyLex)
. {
. if (yyMax <= 0) yyMax = 256; // initial size
. int yyState = 0; // state stack ptr
. int [] yyStates; // state stack
. yyVal = null;
. yyToken = -1;
. int yyErrorFlag = 0; // #tks to shift
. if (use_global_stacks && global_yyStates != null) {
. yyVals = global_yyVals;
. yyStates = global_yyStates;
. } else {
. yyVals = new object [yyMax];
. yyStates = new int [yyMax];
. if (use_global_stacks) {
. global_yyVals = yyVals;
. global_yyStates = yyStates;
. }
. }
.
local ## %{ ... %} after the first %%
. /*yyLoop:*/ for (yyTop = 0;; ++ yyTop) {
. if (yyTop >= yyStates.Length) { // dynamically increase
. global::System.Array.Resize (ref yyStates, yyStates.Length+yyMax);
. global::System.Array.Resize (ref yyVals, yyVals.Length+yyMax);
. }
. yyStates[yyTop] = yyState;
. yyVals[yyTop] = yyVal;
t if (debug != null) debug.push(yyState, yyVal);
.
. /*yyDiscarded:*/ while (true) { // discarding a token does not change stack
. int yyN;
. if ((yyN = yyDefRed[yyState]) == 0) { // else [default] reduce (yyN)
. if (yyToken < 0) {
. yyToken = yyLex.advance() ? yyLex.token() : 0;
t if (debug != null)
t debug.lex(yyState, yyToken, yyname(yyToken), yyLex.value());
. }
. if ((yyN = yySindex[yyState]) != 0 && ((yyN += yyToken) >= 0)
. && (yyN < yyTable.Length) && (yyCheck[yyN] == yyToken)) {
t if (debug != null)
t debug.shift(yyState, yyTable[yyN], yyErrorFlag-1);
. yyState = yyTable[yyN]; // shift to yyN
. yyVal = yyLex.value();
. yyToken = -1;
. if (yyErrorFlag > 0) -- yyErrorFlag;
. goto continue_yyLoop;
. }
. if ((yyN = yyRindex[yyState]) != 0 && (yyN += yyToken) >= 0
. && yyN < yyTable.Length && yyCheck[yyN] == yyToken)
. yyN = yyTable[yyN]; // reduce (yyN)
. else
. switch (yyErrorFlag) {
.
. case 0:
. yyExpectingState = yyState;
. // yyerror(String.Format ("syntax error, got token `{0}'", yyname (yyToken)), yyExpecting(yyState));
t if (debug != null) debug.error("syntax error");
. if (yyToken == 0 /*eof*/ || yyToken == eof_token) throw new yyParser.yyUnexpectedEof ();
. goto case 1;
. case 1: case 2:
. yyErrorFlag = 3;
. do {
. if ((yyN = yySindex[yyStates[yyTop]]) != 0
. && (yyN += Token.yyErrorCode) >= 0 && yyN < yyTable.Length
. && yyCheck[yyN] == Token.yyErrorCode) {
t if (debug != null)
t debug.shift(yyStates[yyTop], yyTable[yyN], 3);
. yyState = yyTable[yyN];
. yyVal = yyLex.value();
. goto continue_yyLoop;
. }
t if (debug != null) debug.pop(yyStates[yyTop]);
. } while (-- yyTop >= 0);
t if (debug != null) debug.reject();
. throw new yyParser.yyException("irrecoverable syntax error");
.
. case 3:
. if (yyToken == 0) {
t if (debug != null) debug.reject();
. throw new yyParser.yyException("irrecoverable syntax error at end-of-file");
. }
t if (debug != null)
t debug.discard(yyState, yyToken, yyname(yyToken),
t yyLex.value());
. yyToken = -1;
. goto continue_yyDiscarded; // leave stack alone
. }
. }
. int yyV = yyTop + 1-yyLen[yyN];
t if (debug != null)
t debug.reduce(yyState, yyStates[yyV-1], yyN, YYRules.getRule (yyN), yyLen[yyN]);
. yyVal = yyV > yyTop ? null : yyVals[yyV]; // yyVal = yyDefault(yyV > yyTop ? null : yyVals[yyV]);
. switch (yyN) {
actions ## code from the actions within the grammar
. }
. yyTop -= yyLen[yyN];
. yyState = yyStates[yyTop];
. int yyM = yyLhs[yyN];
. if (yyState == 0 && yyM == 0) {
t if (debug != null) debug.shift(0, yyFinal);
. yyState = yyFinal;
. if (yyToken < 0) {
. yyToken = yyLex.advance() ? yyLex.token() : 0;
t if (debug != null)
t debug.lex(yyState, yyToken,yyname(yyToken), yyLex.value());
. }
. if (yyToken == 0) {
t if (debug != null) debug.accept(yyVal);
. return yyVal;
. }
. goto continue_yyLoop;
. }
. if (((yyN = yyGindex[yyM]) != 0) && ((yyN += yyState) >= 0)
. && (yyN < yyTable.Length) && (yyCheck[yyN] == yyState))
. yyState = yyTable[yyN];
. else
. yyState = yyDgoto[yyM];
t if (debug != null) debug.shift(yyStates[yyTop], yyState);
. goto continue_yyLoop;
. continue_yyDiscarded: ; // implements the named-loop continue: 'continue yyDiscarded'
. }
. continue_yyLoop: ; // implements the named-loop continue: 'continue yyLoop'
. }
. }
.
tables ## tables for rules, default reduction, and action calls
.
epilog ## text following second %%
.namespace yydebug {
. using System;
. internal interface yyDebug {
. void push (int state, Object value);
. void lex (int state, int token, string name, Object value);
. void shift (int from, int to, int errorFlag);
. void pop (int state);
. void discard (int state, int token, string name, Object value);
. void reduce (int from, int to, int rule, string text, int len);
. void shift (int from, int to);
. void accept (Object value);
. void error (string message);
. void reject ();
. }
.
. class yyDebugSimple : yyDebug {
. void println (string s){
. Console.Error.WriteLine (s);
. }
.
. public void push (int state, Object value) {
. println ("push\tstate "+state+"\tvalue "+value);
. }
.
. public void lex (int state, int token, string name, Object value) {
. println("lex\tstate "+state+"\treading "+name+"\tvalue "+value);
. }
.
. public void shift (int from, int to, int errorFlag) {
. switch (errorFlag) {
. default: // normally
. println("shift\tfrom state "+from+" to "+to);
. break;
. case 0: case 1: case 2: // in error recovery
. println("shift\tfrom state "+from+" to "+to
. +"\t"+errorFlag+" left to recover");
. break;
. case 3: // normally
. println("shift\tfrom state "+from+" to "+to+"\ton error");
. break;
. }
. }
.
. public void pop (int state) {
. println("pop\tstate "+state+"\ton error");
. }
.
. public void discard (int state, int token, string name, Object value) {
. println("discard\tstate "+state+"\ttoken "+name+"\tvalue "+value);
. }
.
. public void reduce (int from, int to, int rule, string text, int len) {
. println("reduce\tstate "+from+"\tuncover "+to
. +"\trule ("+rule+") "+text);
. }
.
. public void shift (int from, int to) {
. println("goto\tfrom state "+from+" to "+to);
. }
.
. public void accept (Object value) {
. println("accept\tvalue "+value);
. }
.
. public void error (string message) {
. println("error\t"+message);
. }
.
. public void reject () {
. println("reject");
. }
.
. }
.}
.// %token constants
. class Token {
tokens public const int
. }
. namespace yyParser {
. using System;
. /** thrown for irrecoverable syntax errors and stack overflow.
. */
. internal class yyException : System.Exception {
. public yyException (string message) : base (message) {
. }
. }
. internal class yyUnexpectedEof : yyException {
. public yyUnexpectedEof (string message) : base (message) {
. }
. public yyUnexpectedEof () : base ("") {
. }
. }
.
. /** must be implemented by a scanner object to supply input to the parser.
. */
. internal interface yyInput {
. /** move on to next token.
. @return false if positioned beyond tokens.
. @throws IOException on input error.
. */
. bool advance (); // throws java.io.IOException;
. /** classifies current token.
. Should not be called if advance() returned false.
. @return current %token or single character.
. */
. int token ();
. /** associated with current token.
. Should not be called if advance() returned false.
. @return value for token().
. */
. Object value ();
. }
. }
.} // close outermost namespace, that MUST HAVE BEEN opened in the prolog

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