perl-byacc-2.0.orig/ 40755 1750 1750 0 6745547577 13073 5ustar bortzbortzperl-byacc-2.0.orig/ACKNOWLEDGEMENTS100644 1750 1750 2157 5320142663 15421 0ustar bortzbortz 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 Patches to version 1.6 to produce Perl code by Ray Lischner uunet!mntgfx!lisch lisch@dad.mentor.com Patches to version 1.8 to produce Perl code by Rick Ohnemus uunet!sparky!rick rick@IMD.Sterling.COM NOTE: 1.8 Perl patches are based heavily on 1.6 Perl patches. I just integrated the 1.6 patches with Berkeley yacc 1.8 and fixed a few bugs. perl-byacc-2.0.orig/mktemp.c100644 1750 1750 2070 5325700425 14600 0ustar bortzbortz#include #include #include #include #include char *mktemp(char * template) { char letter = 'A'; BPTR lock; unsigned long mytask; char * xptr; if (template == (char *) NULL || *template == '\0') return (char *) NULL; for (xptr = template; *xptr != '\0'; xptr++) /* void */ ; if (*--xptr != 'X') return (char *) NULL; mytask = (unsigned long) FindTask((STRPTR) NULL); do { *xptr = (mytask % 10) + '0'; mytask /= 10; } while (xptr != template && *--xptr == 'X'); if (*xptr == 'X') { while (xptr != template && *xptr == 'X') xptr--; if (*xptr != 'X') xptr++; *xptr = letter; } else { xptr++; letter--; } for (;;) { lock = Lock(template, SHARED_LOCK); if (lock == (BPTR) NULL) { if (IoErr() == ERROR_OBJECT_NOT_FOUND) return template; } UnLock(lock); if (letter < 'Z') letter++; else { if (*++xptr == '\0') return (char *) NULL; letter = 'A'; } *xptr = letter; } /*NOTREACHED*/ } perl-byacc-2.0.orig/NEW_FEATURES100644 1750 1750 5124 5320142624 15010 0ustar bortzbortz The -p option can be used to change the symbol prefix to something other than "yy" in the generated code. This allows multiple parsers to be included in a program. See the man page for further details. The -P option causes Perl code to be generated. This is useful for rapid prototyping of a grammar. In Perl mode, %type, %union, etc., are checked, but not used in the output. The user must supply &yylex, &yyerror, and a main program to call &yyparse. An example of a simple calculator is included. A version of getdate.y that has been modified for Perl yacc is also included. 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. perl-byacc-2.0.orig/NO_WARRANTY100644 1750 1750 234 5224473056 14712 0ustar bortzbortz Berkeley Yacc is distributed with no warranty whatever. The author and any other contributors take no responsibility for the consequences of its use. perl-byacc-2.0.orig/main.c100644 1750 1750 26326 6745547577 14311 0ustar bortzbortz#include "defs.h" #include #define VERSION "Berkeley yacc version 1.8.2 (C or perl)" char dflag; char lflag; char rflag; char tflag; char vflag; char perl5005flag; char *myname = PROGRAM; char *file_prefix = "y"; char *temp_form; int prefix_changed = 0; char *define_prefix = "YY"; char *symbol_prefix = "yy"; Language language = C; char* c_suffixes[] = { ".code.c", ".tab.h", ".tab.c", ".output" }; char* perl_suffixes[] = { ".code.pl", ".tab.ph", ".tab.pl", ".output" }; char** suffixes = c_suffixes; char *perl_package = 0; int lineno; int outline; char *action_file_name; char *code_file_name; char *defines_file_name; char *input_file_name = ""; char *output_file_name; char *text_file_name; char *union_file_name; char *verbose_file_name; FILE *action_file; /* a temp file, used to save actions associated */ /* with rules until the parser is written */ FILE *code_file; /* y.code.c (used when the -r option is specified) */ FILE *defines_file; /* y.tab.h */ FILE *input_file; /* the input file */ FILE *output_file; /* y.tab.c */ FILE *text_file; /* a temp file, used to save text until all */ /* symbols have been defined */ FILE *union_file; /* a temp file, used to save the union */ /* definition until all symbol have been */ /* defined */ FILE *verbose_file; /* y.output */ int nitems; int nrules; int nsyms; int ntokens; int nvars; int start_symbol; char **symbol_name; short *symbol_value; short *symbol_prec; char *symbol_assoc; short *ritem; short *rlhs; short *rrhs; short *rprec; char *rassoc; short **derives; char *nullable; #ifdef AMIGA long __near __STKNEED = 1000; #endif #if __STDC__ extern char *mktemp(char *template); #else extern char *mktemp(); #endif #if __STDC__ != 1 extern char *getenv(); #endif #if __STDC__ void done(int k) #else void done(k) int k; #endif { if (action_file) { fclose(action_file); unlink(action_file_name); } if (text_file) { fclose(text_file); unlink(text_file_name); } if (union_file) { fclose(union_file); unlink(union_file_name); } exit(k); } #if __STDC__ static SIG_TYPE onintr(int junk) #else static SIG_TYPE onintr() #endif { done(1); } #if __STDC__ static void set_signals(void) #else static void set_signals() #endif { #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 } #if __STDC__ static void usage(void) #else static void usage() #endif { fprintf(stderr, "usage: %s [-Ccdlrtv] [-b file_prefix] [-p sym_prefix] [-P package] filename\n", myname); exit(1); } #if __STDC__ static void getargs(int argc, char *argv[]) #else static void getargs(argc, argv) int argc; char *argv[]; #endif { register int i; register char *s; if (argc > 0) myname = argv[0]; s = strrchr(myname, '/'); if (s == (char *) NULL) { #ifdef AMIGA s = strrchr(myname, ':'); if (s == (char *) NULL) s = myname; else s++; #else s = myname; #endif } else s++; temp_form = MALLOC(strlen(s) + sizeof(".XXXXXXX")); sprintf(temp_form, "%s.XXXXXXX", s); 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 '5': perl5005flag = 1; break; case 'b': if (*++s) file_prefix = s; else if (++i < argc) file_prefix = argv[i]; else usage(); continue; case 'c': case 'C': language = C; suffixes = c_suffixes; break; case 'd': dflag = 1; break; case 'l': lflag = 1; break; case 'p': if (*++s) symbol_prefix = s; else if (++i < argc) symbol_prefix = argv[i]; else usage(); continue; case 'P': language = PERL; suffixes = perl_suffixes; if (*++s) perl_package = s; else if (++i < argc) perl_package = argv[i]; else usage(); continue; case 'r': rflag = 1; break; case 't': tflag = 1; break; case 'v': vflag = 1; break; case 'V': fprintf(stderr, "%s: %s\n", myname, VERSION); exit(1); default: usage(); } for (;;) { switch (*++s) { case '\0': goto end_of_option; case 'c': case 'C': language = C; suffixes = c_suffixes; break; case 'd': dflag = 1; break; case 'l': lflag = 1; break; case 'P': language = PERL; suffixes = perl_suffixes; break; case 'r': rflag = 1; break; case 't': tflag = 1; break; case 'v': vflag = 1; break; case 'V': fprintf(stderr, "%s: %s\n", myname, VERSION); exit(1); default: usage(); } } end_of_option:; } if (language == PERL && rflag) fprintf(stderr, "%s: Warning: -r not recommended with Perl mode.\n", myname); if (language == PERL && strcmp(symbol_prefix, "yy") != 0) fprintf(stderr, "%s: Warning: -p not recommended with Perl mode.\n", myname); if (language != PERL && perl5005flag) fprintf(stderr, "%s: Warning: -5 has no effect without Perl mode.\n", myname); no_more_options:; if (i + 1 != argc) usage(); input_file_name = argv[i]; } #if __STDC__ char *allocate(unsigned n) #else char *allocate(n) unsigned n; #endif { register char *p; p = NULL; if (n) { p = CALLOC(1, n); } return (p); } #if __STDC__ char *my_calloc(unsigned k, unsigned n) #else char *my_calloc(k, n) unsigned k; unsigned n; #endif { #ifndef __STDC__ extern char *calloc(); #endif register char *p; p = calloc(k, n); if (!p) no_space(); return (p); } #if __STDC__ char *my_malloc(unsigned n) #else char *my_malloc(n) unsigned n; #endif { #ifndef __STDC__ extern char *malloc(); #endif register char *p; p = malloc(n); if (!p) no_space(); return (p); } #if __STDC__ char *my_realloc(char *p, unsigned n) #else char *my_realloc(p, n) char *p; unsigned n; #endif { #ifndef __STDC__ extern char *realloc(); #endif p = realloc(p, n); if (!p) no_space(); return (p); } #if __STDC__ static void create_file_names(void) #else static void create_file_names() #endif { int i, len; char *tmpdir; tmpdir = getenv("TMPDIR"); #ifdef AMIGA if (tmpdir == (char *) NULL) tmpdir = "T:"; #else if (tmpdir == (char *) NULL) tmpdir = "/tmp"; #endif len = strlen(tmpdir); i = len + strlen(temp_form) + 1; #ifdef AMIGA if (len && tmpdir[len-1] != ':' && tmpdir[len-1] != '/') ++i; #else if (len && tmpdir[len-1] != '/') ++i; #endif action_file_name = MALLOC(i); text_file_name = MALLOC(i); union_file_name = MALLOC(i); strcpy(action_file_name, tmpdir); strcpy(text_file_name, tmpdir); strcpy(union_file_name, tmpdir); #ifdef AMIGA if (len && tmpdir[len-1] != ':' && tmpdir[len - 1] != '/') { action_file_name[len] = '/'; text_file_name[len] = '/'; union_file_name[len] = '/'; ++len; } #else if (len && tmpdir[len - 1] != '/') { action_file_name[len] = '/'; text_file_name[len] = '/'; union_file_name[len] = '/'; ++len; } #endif strcpy(action_file_name + len, temp_form); strcpy(text_file_name + len, temp_form); strcpy(union_file_name + len, temp_form); FREE(temp_form); temp_form = (char *) NULL; action_file_name[len + 5] = 'a'; text_file_name[len + 5] = 't'; union_file_name[len + 5] = 'u'; mktemp(action_file_name); mktemp(text_file_name); mktemp(union_file_name); len = strlen(file_prefix); if (language == PERL) { int len = strlen(perl_package); output_file_name = MALLOC(len + 4); strcpy(output_file_name, perl_package); strcpy(output_file_name + len, ".pm"); } else { output_file_name = MALLOC(len + strlen(suffixes[OUTPUT_SUFFIX]) + 1); strcpy(output_file_name, file_prefix); strcpy(output_file_name + len, suffixes[OUTPUT_SUFFIX]); } if (rflag) { code_file_name = MALLOC(len + strlen(suffixes[CODE_SUFFIX]) + 1); strcpy(code_file_name, file_prefix); strcpy(code_file_name + len, suffixes[CODE_SUFFIX]); } else code_file_name = output_file_name; if (dflag) { defines_file_name = MALLOC(len + strlen(suffixes[DEFINES_SUFFIX]) + 1); strcpy(defines_file_name, file_prefix); strcpy(defines_file_name + len, suffixes[DEFINES_SUFFIX]); } if (vflag) { verbose_file_name = MALLOC(len + strlen(suffixes[VERBOSE_SUFFIX]) + 1); strcpy(verbose_file_name, file_prefix); strcpy(verbose_file_name + len, suffixes[VERBOSE_SUFFIX]); } } #if __STDC__ static void open_files(void) #else static void open_files() #endif { 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); text_file = fopen(text_file_name, "w"); if (text_file == 0) open_error(text_file_name); if (vflag) { verbose_file = fopen(verbose_file_name, "w"); if (verbose_file == 0) open_error(verbose_file_name); } if (dflag) { defines_file = fopen(defines_file_name, "w"); if (defines_file == 0) open_error(defines_file_name); union_file = fopen(union_file_name, "w"); if (union_file == 0) open_error(union_file_name); } output_file = fopen(output_file_name, "w"); if (output_file == 0) open_error(output_file_name); if (rflag) { code_file = fopen(code_file_name, "w"); if (code_file == 0) open_error(code_file_name); } else code_file = output_file; } #if __STDC__ static void fix_defsym_prefix(void) #else static void fix_defsym_prefix() #endif { char *from; int num_lower = 0; char *to; if (strcmp(symbol_prefix, "yy") == 0) return; from = symbol_prefix; /* check first character for [A-Za-z_] */ if (!isalpha(*from) && *from != '_') { fprintf(stderr, "%s: symbol prefix (%s) must start with an underline or letter\n", myname, symbol_prefix); exit(1); } for (/* void */ ; *from; from++) { if (isalnum(*from) || *from == '_') { if (islower(*from)) num_lower++; } else { fprintf(stderr, "%s: invalid character (%c) in symbol prefix (%s)\n", myname, isgraph(*from) ? *from : '?', symbol_prefix); exit(1); } } if (num_lower == 0) { fprintf(stderr, "%s: symbol prefix (%s) must contain at least 1 lower case character\n", myname, symbol_prefix); exit(1); } define_prefix = MALLOC((from - symbol_prefix) + 1); for (to = define_prefix, from = symbol_prefix; *from; from++) { if (islower(*from)) *to++ = toupper(*from); else *to++ = *from; } *to = *from; prefix_changed = 1; } #if __STDC__ int main(int argc, char *argv[]) #else int main(argc, argv) int argc; char *argv[]; #endif { set_signals(); getargs(argc, argv); fix_defsym_prefix(); open_files(); reader(); lr0(); lalr(); make_parser(); verbose(); output(); done(0); /*NOTREACHED*/ } perl-byacc-2.0.orig/closure.c100644 1750 1750 11300 5325700456 14777 0ustar bortzbortz#include "defs.h" short *itemset; short *itemsetend; unsigned *ruleset; static unsigned *first_derives; static unsigned *EFF; #if __STDC__ static void set_EFF(void) #else static void set_EFF() #endif { 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 } #if __STDC__ void set_first_derives(void) #else void set_first_derives() #endif { register unsigned *rrow; register unsigned *vrow; register int j; register unsigned mask; 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); cword = *vrow++; mask = 1; for (j = start_symbol; j < nsyms; j++) { if (cword & mask) { rp = derives[j]; while ((rule = *rp++) >= 0) { SETBIT(rrow, rule); } } mask <<= 1; if (mask == 0) { cword = *vrow++; mask = 1; } } vrow += varsetsize; rrow += rulesetsize; } #ifdef DEBUG print_first_derives(); #endif FREE(EFF); } #if __STDC__ void closure(short *nucleus, int n) #else void closure(nucleus, n) short *nucleus; int n; #endif { register int ruleno; register unsigned word; register unsigned mask; 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 == 0) ruleno += BITS_PER_WORD; else { mask = 1; while (mask) { if (word & mask) { itemno = rrhs[ruleno]; while (csp < csend && *csp < itemno) *itemsetend++ = *csp++; *itemsetend++ = itemno; while (csp < csend && *csp == itemno) ++csp; } mask <<= 1; ++ruleno; } } } while (csp < csend) *itemsetend++ = *csp++; #ifdef DEBUG print_closure(n); #endif } #if __STDC__ void finalize_closure(void) #else void finalize_closure() #endif { FREE(itemset); FREE(ruleset); FREE(first_derives + ntokens * WORDSIZE(nrules)); } #ifdef DEBUG #if __STDC__ static void print_closure(int n) #else static void print_closure(n) int n; #endif { register short *isp; printf("\n\nn = %d\n\n", n); for (isp = itemset; isp < itemsetend; isp++) printf(" %d\n", *isp); } #if __STDC__ static void print_EFF(void) #else static void print_EFF() #endif { register int i, j, k; register unsigned *rowp; register unsigned word; register unsigned mask; 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++; mask = 1; for (j = 0; j < nvars; j++) { if (word & mask) printf(" %s", symbol_name[start_symbol + j]); mask <<= 1; if (mask == 0) { word = *rowp++; mask = 1; } } } } #if __STDC__ void print_first_derives(void) #else void print_first_derives() #endif { register int i; register int j; register unsigned *rp; register unsigned cword; register unsigned mask; 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); cword = *rp++; mask = 1; for (j = 0; j <= nrules; j++) { if (cword & mask) printf(" %d\n", j); mask <<= 1; if (mask == 0) { cword = *rp++; mask = 1; } } } fflush(stdout); } #endif perl-byacc-2.0.orig/defs.h100644 1750 1750 22005 6745547577 14301 0ustar bortzbortz#if __STDC__ || defined(__cplusplus) #define _P_(s) s #else #define _P_(s) () #endif #include #include #include #if __STDC__ #include #include #include #include #ifdef _AMIGA #define AMIGA #endif #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 */ #ifdef AMIGA #define MAXCHAR UCHAR_MAX #define MAXSHORT SHRT_MAX #define MINSHORT SHRT_MIN #else #define MAXCHAR 255 #define MAXSHORT 32767 #define MINSHORT -32768 #endif #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 0 #define DEFINES_SUFFIX 1 #define OUTPUT_SUFFIX 2 #define VERBOSE_SUFFIX 3 /* 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 /* 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) (my_calloc((unsigned)(k),(unsigned)(n))) #define FREE(x) (free((char*)(x))) #define MALLOC(n) (my_malloc((unsigned)(n))) #define NEW(t) ((t*)allocate(sizeof(t))) #define NEW2(n,t) ((t*)allocate((unsigned)((n)*sizeof(t)))) #define REALLOC(p,n) (my_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; }; /* target language is one of these */ typedef enum { C, PERL } Language; /* global variables */ extern char dflag; extern char lflag; extern char rflag; extern char tflag; extern char vflag; extern char perl5005flag; extern Language language; extern char *myname; extern char *cptr; extern char *line; extern int lineno; extern int outline; extern char **banner[]; extern char **tables[]; extern char **header[]; extern char **body[]; extern char **trailer[]; extern int prefix_changed; extern char *define_prefix; extern char *symbol_prefix; extern char *perl_package; extern char *action_file_name; extern char *code_file_name; extern char *defines_file_name; extern 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 char line_format[]; extern int start_symbol; extern char **symbol_name; extern short *symbol_value; extern short *symbol_prec; extern char *symbol_assoc; extern short *ritem; extern short *rlhs; extern short *rrhs; extern short *rprec; extern char *rassoc; extern short **derives; extern char *nullable; extern bucket *first_symbol; extern bucket *last_symbol; extern int nstates; extern core *first_state; extern shifts *first_shift; extern reductions *first_reduction; extern short *accessing_symbol; extern core **state_table; extern shifts **shift_table; extern reductions **reduction_table; extern unsigned *LA; extern short *LAruleno; extern short *lookaheads; extern short *goto_map; extern short *from_state; extern short *to_state; extern action **parser; extern int SRtotal; extern int RRtotal; extern short *SRconflicts; extern short *RRconflicts; extern short *defred; extern short *rules_used; extern short nunused; extern short final_state; /* global functions */ extern char * allocate _P_((unsigned n)); extern void closure _P_((short *nucleus, int n)); extern void create_symbol_table _P_((void)); extern void default_action_warning _P_((void)); extern void dollar_error _P_((int a_lineno, char *a_line, char *a_cptr)); extern void dollar_warning _P_((int a_lineno, int i)); extern void done _P_((int k)); extern void fatal _P_((char *msg)); extern void finalize_closure _P_((void)); extern void free_derives _P_((void)); extern void free_nullable _P_((void)); extern void free_parser _P_((void)); extern void free_symbol_table _P_((void)); extern void free_symbols _P_((void)); extern void illegal_character _P_((char *c_cptr)); extern void illegal_tag _P_((int t_lineno, char *t_line, char *t_cptr)); extern void lalr _P_((void)); extern bucket * lookup _P_((char *name)); extern void lr0 _P_((void)); extern bucket * make_bucket _P_((char *name)); extern void make_parser _P_((void)); extern char * my_calloc _P_((unsigned k, unsigned n)); extern char * my_malloc _P_((unsigned n)); extern char * my_realloc _P_((char *p, unsigned n)); extern void no_grammar _P_((void)); extern void no_space _P_((void)); extern void open_error _P_((char *filename)); extern void output _P_((void)); extern void over_unionized _P_((char *u_cptr)); extern void prec_redeclared _P_((void)); extern void print_pos _P_((char *st_line, char *st_cptr)); extern void reader _P_((void)); extern void reflexive_transitive_closure _P_((unsigned *R, int n)); extern void reprec_warning _P_((char *s)); extern void restarted_warning _P_((void)); extern void retyped_warning _P_((char *s)); extern void revalued_warning _P_((char *s)); extern void set_first_derives _P_((void)); extern void syntax_error _P_((int st_lineno, char *st_line, char *st_cptr)); extern void terminal_lhs _P_((int s_lineno)); extern void terminal_start _P_((char *s)); extern void tokenized_start _P_((char *s)); extern void undefined_goal _P_((char *s)); extern void undefined_symbol_warning _P_((char *s)); extern void unexpected_EOF _P_((void)); extern void unknown_rhs _P_((int i)); extern void unterminated_action _P_((int a_lineno, char *a_line, char *a_cptr)); extern void unterminated_comment _P_((int c_lineno, char *c_line, char *c_cptr)); extern void unterminated_string _P_((int s_lineno, char *s_line, char *s_cptr)); extern void unterminated_text _P_((int t_lineno, char *t_line, char *t_cptr)); extern void unterminated_union _P_((int u_lineno, char *u_line, char *u_cptr)); extern void untyped_lhs _P_((void)); extern void untyped_rhs _P_((int i, char *s)); extern void used_reserved _P_((char *s)); extern void verbose _P_((void)); extern void write_section _P_((char **section[])); /* system variables */ extern int errno; /* system functions */ #if __STDC__ != 1 extern void free(); extern char *strcpy(); extern char *strrchr(); #endif perl-byacc-2.0.orig/error.c100644 1750 1750 20134 5325705641 14462 0ustar bortzbortz/* routines for printing error messages */ #include "defs.h" #if __STDC__ void fatal(char *msg) #else void fatal(msg) char *msg; #endif { fprintf(stderr, "%s: f - %s\n", myname, msg); done(2); } #if __STDC__ void no_space(void) #else void no_space() #endif { fprintf(stderr, "%s: f - out of space\n", myname); done(2); } #if __STDC__ void open_error(char *filename) #else void open_error(filename) char *filename; #endif { fprintf(stderr, "%s: f - cannot open \"%s\"\n", myname, filename); done(2); } #if __STDC__ void unexpected_EOF(void) #else void unexpected_EOF() #endif { fprintf(stderr, "%s: e - line %d of \"%s\", unexpected end-of-file\n", myname, lineno, input_file_name); done(1); } #if __STDC__ void print_pos(char *st_line, char *st_cptr) #else void print_pos(st_line, st_cptr) char *st_line; char *st_cptr; #endif { 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); } #if __STDC__ void syntax_error(int st_lineno, char *st_line, char *st_cptr) #else void syntax_error(st_lineno, st_line, st_cptr) int st_lineno; char *st_line; char *st_cptr; #endif { 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); } #if __STDC__ void unterminated_comment(int c_lineno, char *c_line, char *c_cptr) #else void unterminated_comment(c_lineno, c_line, c_cptr) int c_lineno; char *c_line; char *c_cptr; #endif { fprintf(stderr, "%s: e - line %d of \"%s\", unmatched /*\n", myname, c_lineno, input_file_name); print_pos(c_line, c_cptr); done(1); } #if __STDC__ void unterminated_string(int s_lineno, char *s_line, char *s_cptr) #else void unterminated_string(s_lineno, s_line, s_cptr) int s_lineno; char *s_line; char *s_cptr; #endif { 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); } #if __STDC__ void unterminated_text(int t_lineno, char *t_line, char *t_cptr) #else void unterminated_text(t_lineno, t_line, t_cptr) int t_lineno; char *t_line; char *t_cptr; #endif { fprintf(stderr, "%s: e - line %d of \"%s\", unmatched %%{\n", myname, t_lineno, input_file_name); print_pos(t_line, t_cptr); done(1); } #if __STDC__ void unterminated_union(int u_lineno, char *u_line, char *u_cptr) #else void unterminated_union(u_lineno, u_line, u_cptr) int u_lineno; char *u_line; char *u_cptr; #endif { fprintf(stderr, "%s: e - line %d of \"%s\", unterminated %%union \ declaration\n", myname, u_lineno, input_file_name); print_pos(u_line, u_cptr); done(1); } #if __STDC__ void over_unionized(char *u_cptr) #else void over_unionized(u_cptr) char *u_cptr; #endif { fprintf(stderr, "%s: e - line %d of \"%s\", too many %%union \ declarations\n", myname, lineno, input_file_name); print_pos(line, u_cptr); done(1); } #if __STDC__ void illegal_tag(int t_lineno, char *t_line, char *t_cptr) #else void illegal_tag(t_lineno, t_line, t_cptr) int t_lineno; char *t_line; char *t_cptr; #endif { 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); } #if __STDC__ void illegal_character(char *c_cptr) #else void illegal_character(c_cptr) char *c_cptr; #endif { fprintf(stderr, "%s: e - line %d of \"%s\", illegal character\n", myname, lineno, input_file_name); print_pos(line, c_cptr); done(1); } #if __STDC__ void used_reserved(char *s) #else void used_reserved(s) char *s; #endif { fprintf(stderr, "%s: e - line %d of \"%s\", illegal use of reserved symbol \ %s\n", myname, lineno, input_file_name, s); done(1); } #if __STDC__ void tokenized_start(char *s) #else void tokenized_start(s) char *s; #endif { 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); } #if __STDC__ void retyped_warning(char *s) #else void retyped_warning(s) char *s; #endif { fprintf(stderr, "%s: w - line %d of \"%s\", the type of %s has been \ redeclared\n", myname, lineno, input_file_name, s); } #if __STDC__ void reprec_warning(char *s) #else void reprec_warning(s) char *s; #endif { fprintf(stderr, "%s: w - line %d of \"%s\", the precedence of %s has been \ redeclared\n", myname, lineno, input_file_name, s); } #if __STDC__ void revalued_warning(char *s) #else void revalued_warning(s) char *s; #endif { fprintf(stderr, "%s: w - line %d of \"%s\", the value of %s has been \ redeclared\n", myname, lineno, input_file_name, s); } #if __STDC__ void terminal_start(char *s) #else void terminal_start(s) char *s; #endif { fprintf(stderr, "%s: e - line %d of \"%s\", the start symbol %s is a \ token\n", myname, lineno, input_file_name, s); done(1); } #if __STDC__ void restarted_warning(void) #else void restarted_warning() #endif { fprintf(stderr, "%s: w - line %d of \"%s\", the start symbol has been \ redeclared\n", myname, lineno, input_file_name); } #if __STDC__ void no_grammar(void) #else void no_grammar() #endif { fprintf(stderr, "%s: e - line %d of \"%s\", no grammar has been \ specified\n", myname, lineno, input_file_name); done(1); } #if __STDC__ void terminal_lhs(int s_lineno) #else void terminal_lhs(s_lineno) int s_lineno; #endif { 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); } #if __STDC__ void prec_redeclared(void) #else void prec_redeclared() #endif { fprintf(stderr, "%s: w - line %d of \"%s\", conflicting %%prec \ specifiers\n", myname, lineno, input_file_name); } #if __STDC__ void unterminated_action(int a_lineno, char *a_line, char *a_cptr) #else void unterminated_action(a_lineno, a_line, a_cptr) int a_lineno; char *a_line; char *a_cptr; #endif { 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); } #if __STDC__ void dollar_warning(int a_lineno, int i) #else void dollar_warning(a_lineno, i) int a_lineno; int i; #endif { 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); } #if __STDC__ void dollar_error(int a_lineno, char *a_line, char *a_cptr) #else void dollar_error(a_lineno, a_line, a_cptr) int a_lineno; char *a_line; char *a_cptr; #endif { 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); } #if __STDC__ void untyped_lhs(void) #else void untyped_lhs() #endif { fprintf(stderr, "%s: e - line %d of \"%s\", $$ is untyped\n", myname, lineno, input_file_name); done(1); } #if __STDC__ void untyped_rhs(int i, char *s) #else void untyped_rhs(i, s) int i; char *s; #endif { fprintf(stderr, "%s: e - line %d of \"%s\", $%d (%s) is untyped\n", myname, lineno, input_file_name, i, s); done(1); } #if __STDC__ void unknown_rhs(int i) #else void unknown_rhs(i) int i; #endif { fprintf(stderr, "%s: e - line %d of \"%s\", $%d is untyped\n", myname, lineno, input_file_name, i); done(1); } #if __STDC__ void default_action_warning(void) #else void default_action_warning() #endif { fprintf(stderr, "%s: w - line %d of \"%s\", the default action assigns an \ undefined value to $$\n", myname, lineno, input_file_name); } #if __STDC__ void undefined_goal(char *s) #else void undefined_goal(s) char *s; #endif { fprintf(stderr, "%s: e - the start symbol %s is undefined\n", myname, s); done(1); } #if __STDC__ void undefined_symbol_warning(char *s) #else void undefined_symbol_warning(s) char *s; #endif { fprintf(stderr, "%s: w - the symbol %s is undefined\n", myname, s); } perl-byacc-2.0.orig/lalr.c100644 1750 1750 27510 5325700415 14262 0ustar bortzbortz#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 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; static void set_state_table _P_((void)); static void set_accessing_symbol _P_((void)); static void set_shift_table _P_((void)); static void set_reduction_table _P_((void)); static void set_maxrhs _P_((void)); static void initialize_LA _P_((void)); static void set_goto_map _P_((void)); static int map_goto _P_((int state, int symbol)); static void initialize_F _P_((void)); static void build_relations _P_((void)); static void add_lookback_edge _P_((int stateno, int ruleno, int gotono)); static short **transpose _P_((short **R, int n)); static void compute_FOLLOWS _P_((void)); static void compute_lookaheads _P_((void)); static void digraph _P_((short **relation)); static void traverse _P_((register int i)); #if __STDC__ void lalr(void) #else void lalr() #endif { 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(); } #if __STDC__ static void set_state_table(void) #else static void set_state_table() #endif { register core *sp; state_table = NEW2(nstates, core *); for (sp = first_state; sp; sp = sp->next) state_table[sp->number] = sp; } #if __STDC__ static void set_accessing_symbol(void) #else static void set_accessing_symbol() #endif { register core *sp; accessing_symbol = NEW2(nstates, short); for (sp = first_state; sp; sp = sp->next) accessing_symbol[sp->number] = sp->accessing_symbol; } #if __STDC__ static void set_shift_table(void) #else static void set_shift_table() #endif { register shifts *sp; shift_table = NEW2(nstates, shifts *); for (sp = first_shift; sp; sp = sp->next) shift_table[sp->number] = sp; } #if __STDC__ static void set_reduction_table(void) #else static void set_reduction_table() #endif { register reductions *rp; reduction_table = NEW2(nstates, reductions *); for (rp = first_reduction; rp; rp = rp->next) reduction_table[rp->number] = rp; } #if __STDC__ static void set_maxrhs(void) #else static void set_maxrhs() #endif { register short *itemp; register short *item_end; register int length; register 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; } #if __STDC__ static void initialize_LA(void) #else static void initialize_LA() #endif { register int i, j, k; register 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++; } } } } #if __STDC__ static void set_goto_map(void) #else static void set_goto_map() #endif { register shifts *sp; register int i; register int symbol; register int k; register short *temp_map; register int state2; register 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. */ #if __STDC__ static int map_goto(int state, int symbol) #else static int map_goto(state, symbol) int state; int symbol; #endif { register int high; register int low; register int middle; register 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; } } #if __STDC__ static void initialize_F(void) #else static void initialize_F() #endif { register int i; register int j; register int k; register shifts *sp; register short *edge; register unsigned *rowp; register short *rp; register short **reads; register int nedges; register int stateno; register int symbol; register 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); } #if __STDC__ static void build_relations(void) #else static void build_relations() #endif { register int i; register int j; register int k; register short *rulep; register short *rp; register shifts *sp; register int length; register int nedges; register int done; register int state1; register int stateno; register int symbol1; register int symbol2; register short *shortp; register short *edge; register short *states; register 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); } #if __STDC__ static void add_lookback_edge(int stateno, int ruleno, int gotono) #else static void add_lookback_edge(stateno, ruleno, gotono) int stateno, ruleno, gotono; #endif { register int i, k; register int found; register 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; } #if __STDC__ static short **transpose(short **R, int n) #else static short **transpose(R, n) short **R; int n; #endif { register short **new_R; register short **temp_R; register short *nedges; register short *sp; register int i; register int k; nedges = NEW2(n, short); for (i = 0; i < n; i++) { sp = 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 = R[i]; if (sp) { while (*sp >= 0) *temp_R[*sp++]++ = i; } } FREE(temp_R); return (new_R); } #if __STDC__ static void compute_FOLLOWS(void) #else static void compute_FOLLOWS() #endif { digraph(includes); } #if __STDC__ static void compute_lookaheads(void) #else static void compute_lookaheads() #endif { register int i, n; register unsigned *fp1, *fp2, *fp3; register shorts *sp, *next; register 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); } #if __STDC__ static void digraph(short **relation) #else static void digraph(relation) short **relation; #endif { register 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); } #if __STDC__ static void traverse(int i) #else static void traverse(i) register int i; #endif { register unsigned *fp1; register unsigned *fp2; register unsigned *fp3; register int j; register 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++; } } } perl-byacc-2.0.orig/lr0.c100644 1750 1750 24173 5333034071 14024 0ustar bortzbortz#include "defs.h" extern short *itemset; extern short *itemsetend; extern unsigned *ruleset; int nstates; core *first_state; shifts *first_shift; reductions *first_reduction; static core **state_set; static core *this_state; static core *last_state; static shifts *last_shift; static reductions *last_reduction; static int nshifts; static short *shift_symbol; static short *redset; static short *shiftset; static short **kernel_base; static short **kernel_end; static short *kernel_items; static void allocate_itemsets _P_((void)); static void allocate_storage _P_((void)); static void append_states _P_((void)); static void free_storage _P_((void)); static void generate_states _P_((void)); static int get_state _P_((int symbol)); static void initialize_states _P_((void)); static void new_itemsets _P_((void)); static core *new_state _P_((int symbol)); static void save_shifts _P_((void)); static void save_reductions _P_((void)); static void set_derives _P_((void)); static void set_nullable _P_((void)); #ifdef DEBUG extern void print_derives _P_((void)); extern void show_cores _P_((void)); extern void show_ritems _P_((void)); extern void show_rrhs _P_((void)); extern void show_shifts _P_((void)); #endif static void allocate_itemsets() { register short *itemp; register short *item_end; register int symbol; register int i; register int count; register int max; register 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() { allocate_itemsets(); shiftset = NEW2(nsyms, short); redset = NEW2(nrules + 1, short); state_set = NEW2(nitems, core *); } static void append_states() { register int i; register int j; register 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() { FREE(shift_symbol); FREE(redset); FREE(shiftset); FREE(kernel_base); FREE(kernel_end); FREE(kernel_items); FREE(state_set); } static void generate_states() { 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(symbol) int symbol; { register int key; register short *isp1; register short *isp2; register short *iend; register core *sp; register int found; register 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() { register int i; register short *start_derives; register core *p; start_derives = derives[start_symbol]; for (i = 0; start_derives[i] >= 0; ++i) continue; p = (core *) MALLOC(sizeof(core) + i*sizeof(short)); 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() { register int i; register int shiftcount; register short *isp; register short *ksp; register int symbol; for (i = 0; i < nsyms; i++) kernel_end[i] = 0; shiftcount = 0; isp = itemset; while (isp < itemsetend) { i = *isp++; symbol = ritem[i]; if (symbol > 0) { ksp = kernel_end[symbol]; if (!ksp) { shift_symbol[shiftcount++] = symbol; ksp = kernel_base[symbol]; } *ksp++ = i + 1; kernel_end[symbol] = ksp; } } nshifts = shiftcount; } static core *new_state(symbol) int symbol; { register int n; register core *p; register short *isp1; register short *isp2; register short *iend; #ifdef TRACE fprintf(stderr, "Entering new_state(%d)\n", symbol); #endif if (nstates >= MAXSHORT) fatal("too many states"); isp1 = kernel_base[symbol]; iend = kernel_end[symbol]; n = iend - isp1; p = (core *) allocate((unsigned) (sizeof(core) + (n - 1) * sizeof(short))); p->accessing_symbol = symbol; p->number = nstates; p->nitems = n; isp2 = p->items; while (isp1 < iend) *isp2++ = *isp1++; last_state->next = p; last_state = p; nstates++; return (p); } #ifdef DEBUG void show_cores() { 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); } } } void show_ritems() { int i; for (i = 0; i < nitems; ++i) printf("ritem[%d] = %d\n", i, ritem[i]); } void show_rrhs() { int i; for (i = 0; i < nrules; ++i) printf("rrhs[%d] = %d\n", i, rrhs[i]); } void show_shifts() { 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() { register shifts *p; register short *sp1; register short *sp2; register 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() { register short *isp; register short *rp1; register short *rp2; register int item; register int count; register reductions *p; register 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() { register int i, k; register int lhs; register 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 __STDC__ void free_derives(void) #else void free_derives() #endif { FREE(derives[start_symbol]); FREE(derives); } #ifdef DEBUG static void print_derives() { register int i; register 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() { register int i, j; register int empty; int done; nullable = MALLOC(nsyms); 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 __STDC__ void free_nullable(void) #else void free_nullable() #endif { FREE(nullable); } void lr0() { set_derives(); set_nullable(); generate_states(); } perl-byacc-2.0.orig/Makefile.amiga100644 1750 1750 3115 5330644176 15663 0ustar bortzbortz# the name of the final executable PROGRAM = byacc LIBRARY = byacc.lib OPTIMIZE = NOOPTIMIZE #DEBUG = DEBUG=FULLFLUSH CFLAGS = RESETOPTIONS ANSI NOMATH STACKCHECK STACKEXTEND NOSTRICT \ NOSTRINGCONST DATA=FAR CPU=68030 NOICONS NOVERBOSE \ DEFINE=PROGRAM="$(PROGRAM)" DEFINE=SIG_TYPE=void \ $(OPTIMIZE) $(INCLUDES) $(DEBUG) STARTUP = lib:c.o LIBS = lib:sc.lib LDFLAGS = NOICONS #AR = oml AR = oml -v CP = copy MAKE = smake RM = delete OBJS = \ closure.o \ error.o \ lalr.o \ lr0.o \ main.o \ mkpar.o \ mktemp.o \ output.o \ reader.o \ skeleton.o \ symtab.o \ verbose.o \ warshall.o LIB_OBJS = yyerror.o \ yymain.o all: $(PROGRAM) $(LIBRARY) $(PROGRAM): $(OBJS) $(LD) FROM $(STARTUP) $(OBJS) LIB $(LIBS) $(LDFLAGS) TO $(PROGRAM) $(LIBRARY): $(LIB_OBJS) $(AR) $(LIBRARY) r $(LIB_OBJS) clean: -delete \#?.o \#?! clobber: clean -delete $(PROGRAM) $(LIBRARY) tests: $(PROGRAM) -mkdir t $(CP) test/\#?.y test/Makefile t QUIET cd t $(MAKE) PROGRAM=$(PROGRAM) cd / $(RM) t ALL QUIET ### DO NOT DELETE THIS LINE - make depend needs it closure.o: closure.c closure.o: defs.h error.o: error.c error.o: defs.h lalr.o: lalr.c lalr.o: defs.h lr0.o: lr0.c lr0.o: defs.h main.o: main.c main.o: defs.h mkpar.o: mkpar.c mkpar.o: defs.h output.o: output.c output.o: defs.h reader.o: reader.c reader.o: defs.h skeleton.o: skeleton.c skeleton.o: defs.h symtab.o: symtab.c symtab.o: defs.h verbose.o: verbose.c verbose.o: defs.h warshall.o: warshall.c warshall.o: defs.h perl-byacc-2.0.orig/mkpar.c100644 1750 1750 16744 5325700423 14450 0ustar bortzbortz#include "defs.h" action **parser; int SRtotal; int RRtotal; short *SRconflicts; short *RRconflicts; short *defred; short *rules_used; short nunused; short final_state; static int SRcount; static int RRcount; static action *parse_actions _P_((register int stateno)); static void find_final_state _P_((void)); static void remove_conflicts _P_((void)); static void unused_rules _P_((void)); static void total_conflicts _P_((void)); static void defreds _P_((void)); static action *get_shifts _P_((int stateno)); static action *add_reductions _P_((int stateno, register action *actions)); static action *add_reduce _P_((register action *actions, register int ruleno, register int symbol)); #if __STDC__ void make_parser(void) #else void make_parser() #endif { 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(); } #if __STDC__ static action *parse_actions(register int stateno) #else static action *parse_actions(stateno) register int stateno; #endif { register action *actions; actions = get_shifts(stateno); actions = add_reductions(stateno, actions); return (actions); } #if __STDC__ static action *get_shifts(int stateno) #else static action *get_shifts(stateno) int stateno; #endif { 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); } #if __STDC__ static action *add_reductions(int stateno, register action *actions) #else static action *add_reductions(stateno, actions) int stateno; register action *actions; #endif { 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); } #if __STDC__ static action *add_reduce(register action *actions, register int ruleno, register int symbol) #else static action *add_reduce(actions, ruleno, symbol) register action *actions; register int ruleno, symbol; #endif { 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); } #if __STDC__ static void find_final_state(void) #else static void find_final_state() #endif { 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; } } #if __STDC__ static void unused_rules(void) #else static void unused_rules() #endif { register int i; register action *p; rules_used = (short *) MALLOC(nrules*sizeof(short)); 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); } #if __STDC__ static void remove_conflicts(void) #else static void remove_conflicts() #endif { 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; } } #if __STDC__ static void total_conflicts(void) #else static void total_conflicts() #endif { fprintf(stderr, "%s: ", myname); if (SRtotal == 1) fprintf(stderr, "1 shift/reduce conflict"); else if (SRtotal > 1) fprintf(stderr, "%d shift/reduce conflicts", SRtotal); if (SRtotal && RRtotal) fprintf(stderr, ", "); if (RRtotal == 1) fprintf(stderr, "1 reduce/reduce conflict"); else if (RRtotal > 1) fprintf(stderr, "%d reduce/reduce conflicts", RRtotal); fprintf(stderr, ".\n"); } #if __STDC__ static int sole_reduction(int stateno) #else int sole_reduction(stateno) int stateno; #endif { 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); } #if __STDC__ static void defreds(void) #else static void defreds() #endif { register int i; defred = NEW2(nstates, short); for (i = 0; i < nstates; i++) defred[i] = sole_reduction(i); } #if __STDC__ static void free_action_row(register action *p) #else static void free_action_row(p) register action *p; #endif { register action *q; while (p) { q = p->next; FREE(p); p = q; } } #if __STDC__ void free_parser(void) #else void free_parser() #endif { register int i; for (i = 0; i < nstates; i++) free_action_row(parser[i]); FREE(parser); } perl-byacc-2.0.orig/output.c100644 1750 1750 64314 6745547577 14724 0ustar bortzbortz#include "defs.h" static int nvectors; static int nentries; static short **froms; static short **tos; static short *tally; static short *width; static short *state_count; static short *order; static short *base; static short *pos; static int maxtable; static short *table; static short *check; static int lowzero; static int high; static void free_itemsets _P_((void)); static void free_shifts _P_((void)); static void free_reductions _P_((void)); static void output_stored_text _P_((void)); static void output_defines _P_((void)); static void write_num _P_((int value)); static void start_num_array _P_((char *name, int indent, int first)); static void start_string_array _P_((char *name, int nl)); static void end_num_array _P_((void)); static void end_string_array _P_((int nl)); static void start_define _P_((FILE *file)); static void end_define _P_((FILE *file, int value)); static void write_define _P_((char *name, int value)); static void write_null _P_((void)); static void output_rule_data _P_((void)); static void output_yydefred _P_((void)); static void output_actions _P_((void)); static void token_actions _P_((void)); static void goto_actions _P_((void)); static int default_goto _P_((int symbol)); static void save_column _P_((int symbol, int default_state)); static void sort_actions _P_((void)); static void pack_table _P_((void)); static int matching_vector _P_((int vector)); static int pack_vector _P_((int vector)); static void output_base _P_((void)); static void output_table _P_((void)); static void output_check _P_((void)); static int is_C_identifier _P_((char *name)); static void output_debug _P_((void)); static void output_stype _P_((void)); static void output_trailing_text _P_((void)); static void output_semantic_actions _P_((void)); #if __STDC__ void output(void) #else void output() #endif { free_itemsets(); free_shifts(); free_reductions(); output_stored_text(); output_defines(); output_rule_data(); output_yydefred(); output_actions(); free_parser(); output_debug(); output_stype(); if (rflag) write_section(tables); if (language == PERL && perl5005flag) { fprintf(code_file, "use fields qw(yylex yyerror yydebug yynerrs yyerrflag yym \n"); fprintf(code_file, " yyn yyss yyssp yyvs yyvsp yystate yyval \n"); fprintf(code_file, " yylval yychar yys);\n"); } write_section(header); if (language == C) output_trailing_text(); if (language == PERL) { fprintf(code_file, "sub new {\n"); if (perl5005flag) { fprintf(code_file, " my %s $p = bless [\\%FIELDS], $_[0];\n", perl_package); } else { fprintf(code_file, " my $p = bless {}, $_[0];\n"); } } write_section(body); output_semantic_actions(); write_section(trailer); if (language == PERL) { output_trailing_text(); fprintf(code_file, "1;\n"); } free_derives(); free_nullable(); } #if __STDC__ static void write_num(int value) #else static void write_num(value) int value; #endif { switch (language) { case PERL: fprintf(output_file, "%5d,", value); break; case C: fprintf(output_file, "%5d,", value); break; } } #if __STDC__ static void start_num_array(char *name, int indent, int first) #else static void start_num_array(name, indent, first) char *name; int indent, first; #endif { switch (language) { case PERL: fprintf(output_file, "@%s%s = (%*d,", symbol_prefix, name, indent+7, first); break; case C: fprintf(output_file, "short %s%s[] = {%*d,", symbol_prefix, name, indent, first); break; } } #if __STDC__ static void start_string_array(char *name, int nl) #else static void start_string_array(name, nl) char *name; int nl; #endif { switch (language) { case PERL: fprintf(output_file, "@%s%s = (%s", symbol_prefix, name, nl ? "\n" : ""); break; case C: fprintf(output_file, "char *%s%s[] = {%s", symbol_prefix, name, nl ? "\n": ""); break; } } #if __STDC_ static void end_num_array(void) #else static void end_num_array() #endif { switch (language) { case PERL: fprintf(output_file, "\n);\n"); break; case C: fprintf(output_file, "\n};\n"); break; } } #if __STDC__ static void end_string_array(int nl) #else static void end_string_array(nl) int nl; #endif { switch (language) { case PERL: fprintf(output_file, "%s);\n", nl ? "\n" : ""); break; case C: fprintf(output_file, "%s};\n", nl ? "\n" : ""); break; } } #if __STDC__ static void start_define(FILE *file) #else static void start_define(file) FILE *file; #endif { switch (language) { case PERL: fprintf(file, "$"); break; case C: fprintf(file, "#define "); break; } } #if __STDC__ static void end_define(FILE *file, int value) #else static void end_define(file, value) FILE* file; int value; #endif { if (language == PERL) fprintf(file, "=%d;\n", value); else fprintf(file, " %d\n", value); } #if __STDC_ static void write_define(char *name, int value) #else static void write_define(name, value) char* name; int value; #endif { start_define(code_file); fprintf(code_file, "%s%s", define_prefix, name); end_define(code_file, value); } #if __STDC_ static void write_null(void) #else static void write_null() #endif { switch (language) { case PERL: fprintf(output_file, "'',"); break; case C: fprintf(output_file, "0,"); break; } } #if __STDC__ static void output_rule_data(void) #else static void output_rule_data() #endif { register int i; register int j; start_num_array("lhs", 42, symbol_value[start_symbol]); j = 10; for (i = 3; i < nrules; i++) { if (j >= 10) { if (!rflag) ++outline; putc('\n', output_file); j = 1; } else ++j; write_num(symbol_value[rlhs[i]]); } if (!rflag) outline += 2; end_num_array(); start_num_array("len", 42, 2); j = 10; for (i = 3; i < nrules; i++) { if (j >= 10) { if (!rflag) ++outline; putc('\n', output_file); j = 1; } else j++; write_num(rrhs[i + 1] - rrhs[i] - 1); } if (!rflag) outline += 2; end_num_array(); } #if __STDC__ static void output_yydefred(void) #else static void output_yydefred() #endif { register int i, j; start_num_array("defred", 39, (defred[0] ? defred[0] - 2 : 0)); j = 10; for (i = 1; i < nstates; i++) { if (j < 10) ++j; else { if (!rflag) ++outline; putc('\n', output_file); j = 1; } write_num(defred[i] ? defred[i] - 2 : 0); } if (!rflag) outline += 2; end_num_array(); } #if __STDC__ static void output_actions(void) #else static void output_actions() #endif { nvectors = 2*nstates + nvars; froms = NEW2(nvectors, short *); tos = NEW2(nvectors, short *); tally = NEW2(nvectors, short); width = NEW2(nvectors, short); token_actions(); FREE(lookaheads); FREE(LA); FREE(LAruleno); FREE(accessing_symbol); goto_actions(); FREE(goto_map + ntokens); FREE(from_state); FREE(to_state); sort_actions(); pack_table(); output_base(); output_table(); output_check(); } #if __STDC__ static void token_actions(void) #else static void token_actions() #endif { register int i, j; register int shiftcount, reducecount; register int max, min; register short *actionrow, *r, *s; register action *p; actionrow = NEW2(2*ntokens, short); for (i = 0; i < nstates; ++i) { if (parser[i]) { for (j = 0; j < 2*ntokens; ++j) actionrow[j] = 0; shiftcount = 0; reducecount = 0; for (p = parser[i]; p; p = p->next) { if (p->suppressed == 0) { if (p->action_code == SHIFT) { ++shiftcount; actionrow[p->symbol] = p->number; } else if (p->action_code == REDUCE && p->number != defred[i]) { ++reducecount; actionrow[p->symbol + ntokens] = p->number; } } } tally[i] = shiftcount; tally[nstates+i] = reducecount; width[i] = 0; width[nstates+i] = 0; if (shiftcount > 0) { froms[i] = r = NEW2(shiftcount, short); tos[i] = s = NEW2(shiftcount, short); min = MAXSHORT; max = 0; for (j = 0; j < ntokens; ++j) { if (actionrow[j]) { if (min > symbol_value[j]) min = symbol_value[j]; if (max < symbol_value[j]) max = symbol_value[j]; *r++ = symbol_value[j]; *s++ = actionrow[j]; } } width[i] = max - min + 1; } if (reducecount > 0) { froms[nstates+i] = r = NEW2(reducecount, short); tos[nstates+i] = s = NEW2(reducecount, short); min = MAXSHORT; max = 0; for (j = 0; j < ntokens; ++j) { if (actionrow[ntokens+j]) { if (min > symbol_value[j]) min = symbol_value[j]; if (max < symbol_value[j]) max = symbol_value[j]; *r++ = symbol_value[j]; *s++ = actionrow[ntokens+j] - 2; } } width[nstates+i] = max - min + 1; } } } FREE(actionrow); } #if __STDC__ static void goto_actions(void) #else static void goto_actions() #endif { register int i, j, k; state_count = NEW2(nstates, short); k = default_goto(start_symbol + 1); start_num_array("dgoto", 40, k); save_column(start_symbol + 1, k); j = 10; for (i = start_symbol + 2; i < nsyms; i++) { if (j >= 10) { if (!rflag) ++outline; putc('\n', output_file); j = 1; } else ++j; k = default_goto(i); write_num(k); save_column(i, k); } if (!rflag) outline += 2; end_num_array(); FREE(state_count); } #if __STDC__ static int default_goto(int symbol) #else static int default_goto(symbol) int symbol; #endif { register int i; register int m; register int n; register int default_state; register int max; m = goto_map[symbol]; n = goto_map[symbol + 1]; if (m == n) return (0); for (i = 0; i < nstates; i++) state_count[i] = 0; for (i = m; i < n; i++) state_count[to_state[i]]++; max = 0; default_state = 0; for (i = 0; i < nstates; i++) { if (state_count[i] > max) { max = state_count[i]; default_state = i; } } return (default_state); } #if __STDC__ static void save_column(int symbol, int default_state) #else static void save_column(symbol, default_state) int symbol; int default_state; #endif { register int i; register int m; register int n; register short *sp; register short *sp1; register short *sp2; register int count; register int symno; m = goto_map[symbol]; n = goto_map[symbol + 1]; count = 0; for (i = m; i < n; i++) { if (to_state[i] != default_state) ++count; } if (count == 0) return; symno = symbol_value[symbol] + 2*nstates; froms[symno] = sp1 = sp = NEW2(count, short); tos[symno] = sp2 = NEW2(count, short); for (i = m; i < n; i++) { if (to_state[i] != default_state) { *sp1++ = from_state[i]; *sp2++ = to_state[i]; } } tally[symno] = count; width[symno] = sp1[-1] - sp[0] + 1; } #if __STDC__ static void sort_actions(void) #else static void sort_actions() #endif { register int i; register int j; register int k; register int t; register int w; order = NEW2(nvectors, short); nentries = 0; for (i = 0; i < nvectors; i++) { if (tally[i] > 0) { t = tally[i]; w = width[i]; j = nentries - 1; while (j >= 0 && (width[order[j]] < w)) j--; while (j >= 0 && (width[order[j]] == w) && (tally[order[j]] < t)) j--; for (k = nentries - 1; k > j; k--) order[k + 1] = order[k]; order[j + 1] = i; nentries++; } } } #if __STDC__ static void pack_table(void) #else static void pack_table() #endif { register int i; register int place; register int state; base = NEW2(nvectors, short); pos = NEW2(nentries, short); maxtable = 1000; table = NEW2(maxtable, short); check = NEW2(maxtable, short); lowzero = 0; high = 0; for (i = 0; i < maxtable; i++) check[i] = -1; for (i = 0; i < nentries; i++) { state = matching_vector(i); if (state < 0) place = pack_vector(i); else place = base[state]; pos[i] = place; base[order[i]] = place; } for (i = 0; i < nvectors; i++) { if (froms[i]) FREE(froms[i]); if (tos[i]) FREE(tos[i]); } FREE(froms); FREE(tos); FREE(pos); } /* The function matching_vector determines if the vector specified by */ /* the input parameter matches a previously considered vector. The */ /* test at the start of the function checks if the vector represents */ /* a row of shifts over terminal symbols or a row of reductions, or a */ /* column of shifts over a nonterminal symbol. Berkeley Yacc does not */ /* check if a column of shifts over a nonterminal symbols matches a */ /* previously considered vector. Because of the nature of LR parsing */ /* tables, no two columns can match. Therefore, the only possible */ /* match would be between a row and a column. Such matches are */ /* unlikely. Therefore, to save time, no attempt is made to see if a */ /* column matches a previously considered vector. */ /* */ /* Matching_vector is poorly designed. The test could easily be made */ /* faster. Also, it depends on the vectors being in a specific */ /* order. */ #if __STDC__ static int matching_vector(int vector) #else static int matching_vector(vector) int vector; #endif { register int i; register int j; register int k; register int t; register int w; register int match; register int prev; i = order[vector]; if (i >= 2*nstates) return (-1); t = tally[i]; w = width[i]; for (prev = vector - 1; prev >= 0; prev--) { j = order[prev]; if (width[j] != w || tally[j] != t) return (-1); match = 1; for (k = 0; match && k < t; k++) { if (tos[j][k] != tos[i][k] || froms[j][k] != froms[i][k]) match = 0; } if (match) return (j); } return (-1); } #if __STDC__ static int pack_vector(int vector) #else static int pack_vector(vector) int vector; #endif { register int i, j, k, l; register int t; register int loc; register int ok; register short *from; register short *to; int newmax; i = order[vector]; t = tally[i]; assert(t); from = froms[i]; to = tos[i]; j = lowzero - from[0]; for (k = 1; k < t; ++k) if (lowzero - from[k] > j) j = lowzero - from[k]; for (;; ++j) { if (j == 0) continue; ok = 1; for (k = 0; ok && k < t; k++) { loc = j + from[k]; if (loc >= maxtable) { if (loc >= MAXTABLE) fatal("maximum table size exceeded"); newmax = maxtable; do { newmax += 200; } while (newmax <= loc); table = (short *) REALLOC(table, newmax*sizeof(short)); check = (short *) REALLOC(check, newmax*sizeof(short)); for (l = maxtable; l < newmax; ++l) { table[l] = 0; check[l] = -1; } maxtable = newmax; } if (check[loc] != -1) ok = 0; } for (k = 0; ok && k < vector; k++) { if (pos[k] == j) ok = 0; } if (ok) { for (k = 0; k < t; k++) { loc = j + from[k]; table[loc] = to[k]; check[loc] = from[k]; if (loc > high) high = loc; } while (check[lowzero] != -1) ++lowzero; return (j); } } } #if __STDC__ static void output_base(void) #else static void output_base() #endif { register int i, j; start_num_array("sindex", 39, base[0]); j = 10; for (i = 1; i < nstates; i++) { if (j >= 10) { if (!rflag) ++outline; putc('\n', output_file); j = 1; } else ++j; write_num(base[i]); } if (!rflag) outline += 2; end_num_array(); start_num_array("rindex", 39, base[nstates]); j = 10; for (i = nstates + 1; i < 2*nstates; i++) { if (j >= 10) { if (!rflag) ++outline; putc('\n', output_file); j = 1; } else ++j; write_num(base[i]); } if (!rflag) outline += 2; end_num_array(); start_num_array("gindex", 39, base[2*nstates]); j = 10; for (i = 2*nstates + 1; i < nvectors - 1; i++) { if (j >= 10) { if (!rflag) ++outline; putc('\n', output_file); j = 1; } else ++j; write_num(base[i]); } if (!rflag) outline += 2; end_num_array(); FREE(base); } #if __STDC__ static void output_table(void) #else static void output_table() #endif { register int i; register int j; ++outline; write_define("TABLESIZE", high); start_num_array("table", 40, table[0]); j = 10; for (i = 1; i <= high; i++) { if (j >= 10) { if (!rflag) ++outline; putc('\n', output_file); j = 1; } else ++j; write_num(table[i]); } if (!rflag) outline += 2; end_num_array(); FREE(table); } #if __STDC__ static void output_check(void) #else static void output_check() #endif { register int i; register int j; start_num_array("check", 40, check[0]); j = 10; for (i = 1; i <= high; i++) { if (j >= 10) { if (!rflag) ++outline; putc('\n', output_file); j = 1; } else ++j; write_num(check[i]); } if (!rflag) outline += 2; end_num_array(); FREE(check); } #if __STDC__ static int is_C_identifier(char *name) #else static int is_C_identifier(name) char *name; #endif { register char *s; register int c; s = name; c = *s; if (c == '"') { c = *++s; if (!isalpha(c) && c != '_' && c != '$') return (0); else if (language==PERL && c == '$') return (0); while ((c = *++s) != '"') { if (!isalnum(c) && c != '_' && c != '$') return (0); else if (language==PERL && c == '$') return (0); } return (1); } if (!isalpha(c) && c != '_' && c != '$') return (0); else if (language==PERL && c == '$') return (0); while (c = *++s) { if (!isalnum(c) && c != '_' && c != '$') return (0); else if (language==PERL && c == '$') return (0); } return (1); } #if __STDC__ static void output_defines(void) #else static void output_defines() #endif { register int c, i; register char *s; for (i = 2; i < ntokens; ++i) { s = symbol_name[i]; if (is_C_identifier(s)) { start_define(code_file); if (dflag) start_define(defines_file); c = *s; if (c == '"') { while ((c = *++s) != '"') { putc(c, code_file); if (dflag) putc(c, defines_file); } } else { do { putc(c, code_file); if (dflag) putc(c, defines_file); } while (c = *++s); } ++outline; end_define(code_file, symbol_value[i]); if (dflag) end_define(defines_file, symbol_value[i]); } } ++outline; write_define("ERRCODE", symbol_value[1]); if (dflag && unionized && language == C) { fclose(union_file); union_file = fopen(union_file_name, "r"); if (union_file == NULL) open_error(union_file_name); while ((c = getc(union_file)) != EOF) putc(c, defines_file); fprintf(defines_file, " %sSTYPE;\nextern %sSTYPE %slval;\n", define_prefix, define_prefix, symbol_prefix); } } #if __STDC__ static void output_stored_text(void) #else static void output_stored_text() #endif { register int c; register FILE *in, *out; fclose(text_file); text_file = fopen(text_file_name, "r"); if (text_file == NULL) open_error(text_file_name); in = text_file; if ((c = getc(in)) == EOF) return; out = code_file; if (c == '\n') ++outline; putc(c, out); while ((c = getc(in)) != EOF) { if (c == '\n') ++outline; putc(c, out); } if (!lflag) fprintf(out, line_format, ++outline + 1, code_file_name); } #if __STDC__ static void output_debug(void) #else static void output_debug() #endif { register int i, j, k, max; char **symnam, *s; ++outline; write_define("FINAL", final_state); outline += 3; fprintf(code_file, "#ifndef %sDEBUG\n#define %sDEBUG %d\n#endif\n", define_prefix, define_prefix, tflag); if (rflag) fprintf(output_file, "#ifndef %sDEBUG\n#define %sDEBUG %d\n#endif\n", define_prefix, define_prefix, tflag); max = 0; for (i = 2; i < ntokens; ++i) if (symbol_value[i] > max) max = symbol_value[i]; ++outline; write_define("MAXTOKEN", max); symnam = (char **) MALLOC((max+1)*sizeof(char *)); /* Note that it is not necessary to initialize the element */ /* symnam[max]. */ for (i = 0; i < max; ++i) symnam[i] = 0; for (i = ntokens - 1; i >= 2; --i) symnam[symbol_value[i]] = symbol_name[i]; symnam[0] = "end-of-file"; if (!rflag) ++outline; fprintf(output_file, "#if %sDEBUG\n", define_prefix); start_string_array("name", 0); j = 80; for (i = 0; i <= max; ++i) { if (s = symnam[i]) { if (s[0] == '"') { k = 7; while (*++s != '"') { ++k; if (*s == '\\') { k += 2; if (*++s == '\\') ++k; } } j += k; if (j > 80) { if (!rflag) ++outline; putc('\n', output_file); j = k; } fprintf(output_file, "\"\\\""); s = symnam[i]; while (*++s != '"') { if (*s == '\\') { fprintf(output_file, "\\\\"); if (*++s == '\\') fprintf(output_file, "\\\\"); else putc(*s, output_file); } else putc(*s, output_file); } fprintf(output_file, "\\\"\","); } else if (s[0] == '\'') { if (s[1] == '"') { j += 7; if (j > 80) { if (!rflag) ++outline; putc('\n', output_file); j = 7; } fprintf(output_file, "\"'\\\"'\","); } else { k = 5; while (*++s != '\'') { ++k; if (*s == '\\') { k += 2; if (*++s == '\\') ++k; } } j += k; if (j > 80) { if (!rflag) ++outline; putc('\n', output_file); j = k; } fprintf(output_file, "\"'"); s = symnam[i]; while (*++s != '\'') { if (*s == '\\') { fprintf(output_file, "\\\\"); if (*++s == '\\') fprintf(output_file, "\\\\"); else putc(*s, output_file); } else putc(*s, output_file); } fprintf(output_file, "'\","); } } else { k = strlen(s) + 3; j += k; if (j > 80) { if (!rflag) ++outline; putc('\n', output_file); j = k; } putc('"', output_file); do { putc(*s, output_file); } while (*++s); fprintf(output_file, "\","); } } else { j += 2; if (j > 80) { if (!rflag) ++outline; putc('\n', output_file); j = 2; } write_null(); } } if (!rflag) outline += 2; end_string_array(1); FREE(symnam); if (!rflag) ++outline; start_string_array("rule", 1); for (i = 2; i < nrules; ++i) { if (language == PERL && symbol_name[rlhs[i]][0] == '$') fprintf(output_file, "\"\\%s :", symbol_name[rlhs[i]]); else fprintf(output_file, "\"%s :", symbol_name[rlhs[i]]); for (j = rrhs[i]; ritem[j] > 0; ++j) { s = symbol_name[ritem[j]]; if (s[0] == '"') { fprintf(output_file, " \\\""); while (*++s != '"') { if (*s == '\\') { if (s[1] == '\\') fprintf(output_file, "\\\\\\\\"); else fprintf(output_file, "\\\\%c", s[1]); ++s; } else putc(*s, output_file); } fprintf(output_file, "\\\""); } else if (s[0] == '\'') { if (s[1] == '"') fprintf(output_file, " '\\\"'"); else if (s[1] == '\\') { if (s[2] == '\\') fprintf(output_file, " '\\\\\\\\"); else fprintf(output_file, " '\\\\%c", s[2]); s += 2; while (*++s != '\'') putc(*s, output_file); putc('\'', output_file); } else fprintf(output_file, " '%c'", s[1]); } else fprintf(output_file, " %s", s); } if (!rflag) ++outline; fprintf(output_file, "\",\n"); } if (!rflag) outline += 2; end_string_array(0); fprintf(output_file, "#endif\n"); } #if __STDC__ static void output_stype(void) #else static void output_stype() #endif { if (!unionized && ntags == 0 && language == C) { outline += 3; fprintf(code_file, "#ifndef %sSTYPE\ntypedef int %sSTYPE;\n#endif\n", define_prefix, define_prefix); } } #if __STDC__ static void output_trailing_text(void) #else static void output_trailing_text() #endif { register int c, last; register FILE *in, *out; if (line == 0) return; in = input_file; out = code_file; c = *cptr; if (c == '\n') { ++lineno; if ((c = getc(in)) == EOF) return; if (!lflag) { ++outline; fprintf(out, line_format, lineno, input_file_name); } if (c == '\n') ++outline; putc(c, out); last = c; } else { if (!lflag) { ++outline; fprintf(out, line_format, lineno, input_file_name); } do { putc(c, out); } while ((c = *++cptr) != '\n'); ++outline; putc('\n', out); last = '\n'; } while ((c = getc(in)) != EOF) { if (c == '\n') ++outline; putc(c, out); last = c; } if (last != '\n') { ++outline; putc('\n', out); } if (!lflag) fprintf(out, line_format, ++outline + 1, code_file_name); } #if __STDC__ static void output_semantic_actions(void) #else static void output_semantic_actions() #endif { register int c, last; register FILE *out; fclose(action_file); action_file = fopen(action_file_name, "r"); if (action_file == NULL) open_error(action_file_name); if ((c = getc(action_file)) == EOF) return; out = code_file; last = c; if (c == '\n') ++outline; putc(c, out); while ((c = getc(action_file)) != EOF) { if (c == '\n') ++outline; putc(c, out); last = c; } if (last != '\n') { ++outline; putc('\n', out); } if (!lflag) fprintf(out, line_format, ++outline + 1, code_file_name); } #if __STDC__ static void free_itemsets(void) #else static void free_itemsets() #endif { register core *cp, *next; FREE(state_table); for (cp = first_state; cp; cp = next) { next = cp->next; FREE(cp); } } #if __STDC__ static void free_shifts(void) #else static void free_shifts() #endif { register shifts *sp, *next; FREE(shift_table); for (sp = first_shift; sp; sp = next) { next = sp->next; FREE(sp); } } #if __STDC__ static void free_reductions(void) #else static void free_reductions() #endif { register reductions *rp, *next; FREE(reduction_table); for (rp = first_reduction; rp; rp = next) { next = rp->next; FREE(rp); } } perl-byacc-2.0.orig/reader.c100644 1750 1750 110367 6745547577 14646 0ustar bortzbortz/* $Id: patch,v 1.1 1998/04/29 06:34:46 jake Exp $ */ /* Modified for perl5-byacc-patches-0.5 */ #include "defs.h" /* The line size must be a positive integer. One hundred was chosen */ /* because few lines in Yacc input grammars exceed 100 characters. */ /* Note that if a line exceeds LINESIZE characters, the line buffer */ /* will be expanded to accomodate it. */ #define LINESIZE 100 char *cache; int cinc, cache_size; int ntags, tagmax; char **tag_table; char saw_eof, unionized; char *cptr, *line; int linesize; bucket *goal; int prec; int gensym; char last_was_action; int maxitems; bucket **pitem; int maxrules; bucket **plhs; int name_pool_size; char *name_pool; char line_format[] = "#line %d \"%s\"\n"; /* dollar sign is allowed in identifiers */ #define dollar_ok() (language==C) static void cachec _P_((int c)); static void get_line _P_((void)); static char *dup_line _P_((void)); static void skip_comment _P_((void)); static int nextc _P_((void)); static int keyword _P_((void)); static void copy_ident _P_((void)); static void copy_text _P_((void)); static void perl_comment _P_((FILE *text_file, FILE *other_file)); static void copy_union _P_((void)); static int hexval _P_((int c)); static bucket *get_literal _P_((void)); static int is_reserved _P_((char *name)); static bucket *get_name _P_((void)); static int get_number _P_((void)); static char *get_tag _P_((void)); static void declare_tokens _P_((int assoc)); static void declare_types _P_((void)); static void declare_start _P_((void)); static void read_declarations _P_((void)); static void initialize_grammar _P_((void)); static void expand_items _P_((void)); static void expand_rules _P_((void)); static void advance_to_start _P_((void)); static void start_rule _P_((register bucket *bp, int s_lineno)); static void end_rule _P_((void)); static void insert_empty_rule _P_((void)); static void add_symbol _P_((void)); static void copy_action _P_((void)); static int mark_symbol _P_((void)); static void read_grammar _P_((void)); static void free_tags _P_((void)); static void pack_names _P_((void)); static void check_symbols _P_((void)); static void pack_symbols _P_((void)); static void pack_grammar _P_((void)); static void print_grammar _P_((void)); #if __STDC__ static void cachec(int c) #else static void cachec(c) int c; #endif { assert(cinc >= 0); if (cinc >= cache_size) { cache_size += 256; cache = REALLOC(cache, cache_size); } cache[cinc] = c; ++cinc; } #if __STDC__ static void get_line(void) #else static void get_line() #endif { register FILE *f = input_file; register int c; register int i; if (saw_eof || (c = getc(f)) == EOF) { if (line) { FREE(line); line = 0; } cptr = 0; saw_eof = 1; return; } if (line == 0 || linesize != (LINESIZE + 1)) { if (line) FREE(line); linesize = LINESIZE + 1; line = MALLOC(linesize); } i = 0; ++lineno; for (;;) { line[i] = c; if (c == '\n') { cptr = line; return; } if (++i >= linesize) { linesize += LINESIZE; line = REALLOC(line, linesize); } c = getc(f); if (c == EOF) { line[i] = '\n'; saw_eof = 1; cptr = line; return; } } } #if __STDC__ static char *dup_line(void) #else static char *dup_line() #endif { register char *p, *s, *t; if (line == 0) return (0); s = line; while (*s != '\n') ++s; p = MALLOC(s - line + 1); s = line; t = p; while ((*t++ = *s++) != '\n') continue; return (p); } #if __STDC__ static void skip_comment(void) #else static void skip_comment() #endif { register char *s; int st_lineno = lineno; char *st_line = dup_line(); char *st_cptr = st_line + (cptr - line); s = cptr + 2; for (;;) { if (*s == '*' && s[1] == '/') { cptr = s + 2; FREE(st_line); return; } if (*s == '\n') { get_line(); if (line == 0) unterminated_comment(st_lineno, st_line, st_cptr); s = cptr; } else ++s; } } #if __STDC__ static int nextc(void) #else static int nextc() #endif { register char *s; if (line == 0) { get_line(); if (line == 0) return (EOF); } s = cptr; for (;;) { switch (*s) { case '\n': get_line(); if (line == 0) return (EOF); s = cptr; break; case ' ': case '\t': case '\f': case '\r': case '\v': case ',': case ';': ++s; break; case '\\': cptr = s; return ('%'); case '#': if (language == PERL) { get_line(); if (line == 0) return (EOF); s = cptr; break; } cptr = s; return (*s); case '/': if (s[1] == '*') { cptr = s; skip_comment(); s = cptr; break; } else if (s[1] == '/') { get_line(); if (line == 0) return (EOF); s = cptr; break; } cptr = s; return (*s); default: cptr = s; return (*s); } } } #if __STDC__ static int keyword(void) #else static int keyword() #endif { register int c; char *t_cptr = cptr; c = *++cptr; if (isalpha(c)) { cinc = 0; for (;;) { if (isalpha(c)) { if (isupper(c)) c = tolower(c); cachec(c); } else if (isdigit(c) || c == '_' || c == '.' || (dollar_ok() && c == '$')) cachec(c); else break; c = *++cptr; } cachec(NUL); if (strcmp(cache, "token") == 0 || strcmp(cache, "term") == 0) return (TOKEN); if (strcmp(cache, "type") == 0) return (TYPE); if (strcmp(cache, "left") == 0) return (LEFT); if (strcmp(cache, "right") == 0) return (RIGHT); if (strcmp(cache, "nonassoc") == 0 || strcmp(cache, "binary") == 0) return (NONASSOC); if (strcmp(cache, "start") == 0) return (START); if (strcmp(cache, "union") == 0) return (UNION); if (strcmp(cache, "ident") == 0) return (IDENT); } else { ++cptr; if (c == '{') return (TEXT); if (c == '%' || c == '\\') return (MARK); if (c == '<') return (LEFT); if (c == '>') return (RIGHT); if (c == '0') return (TOKEN); if (c == '2') return (NONASSOC); } syntax_error(lineno, line, t_cptr); /*NOTREACHED*/ } #if __STDC__ static void copy_ident(void) #else static void copy_ident() #endif { register int c; register FILE *f = output_file; c = nextc(); if (c == EOF) unexpected_EOF(); if (c != '"') syntax_error(lineno, line, cptr); ++outline; fprintf(f, "#ident \""); for (;;) { c = *++cptr; if (c == '\n') { fprintf(f, "\"\n"); return; } putc(c, f); if (c == '"') { putc('\n', f); ++cptr; return; } } } #if __STDC__ static void copy_text(void) #else static void copy_text() #endif { register int c; int quote; register FILE *f = text_file; int need_newline = 0; int t_lineno = lineno; char *t_line = dup_line(); char *t_cptr = t_line + (cptr - line - 2); if (*cptr == '\n') { get_line(); if (line == 0) unterminated_text(t_lineno, t_line, t_cptr); } if (!lflag) fprintf(f, line_format, lineno, input_file_name); loop: c = *cptr++; switch (c) { case '\n': next_line: putc('\n', f); need_newline = 0; get_line(); if (line) goto loop; unterminated_text(t_lineno, t_line, t_cptr); case '\'': case '"': { int s_lineno = lineno; char *s_line = dup_line(); char *s_cptr = s_line + (cptr - line - 1); quote = c; putc(c, f); for (;;) { c = *cptr++; putc(c, f); if (c == quote) { need_newline = 1; FREE(s_line); goto loop; } if (c == '\n') unterminated_string(s_lineno, s_line, s_cptr); if (c == '\\') { c = *cptr++; putc(c, f); if (c == '\n') { get_line(); if (line == 0) unterminated_string(s_lineno, s_line, s_cptr); } } } } case '/': need_newline = 1; c = *cptr; if (c == '/') { if (language == PERL) fprintf(f, (cptr == line + 1) ? ";#" : "#"); else fprintf(f, "/*"); while ((c = *++cptr) != '\n') { if (c == '*' && cptr[1] == '/') fprintf(f, "* "); else putc(c, f); } if (language == C) fprintf(f, "*/"); goto next_line; } else if (c == '*') { int c_lineno = lineno; char *c_line = dup_line(); char *c_cptr = c_line + (cptr - line - 1); if (language == PERL) fprintf(f, (cptr == line + 1) ? ";#" : "#"); else fprintf(f, "/*"); ++cptr; for (;;) { c = *cptr++; putc(c, f); if (c == '*' && *cptr == '/') { if (language == C) putc('/', f); ++cptr; FREE(c_line); goto loop; } if (c == '\n') { get_line(); if (line == 0) unterminated_comment(c_lineno, c_line, c_cptr); } } } else putc('/', f); goto loop; case '%': case '\\': if (*cptr == '}') { if (need_newline) putc('\n', f); ++cptr; FREE(t_line); return; } putc(c, f); need_newline = 1; goto loop; case '#': if (language == PERL) { fprintf(f, (cptr == line + 1) ? ";#" : "#"); need_newline = 1; while ((c = *cptr++) != '\n') putc(c, f); goto next_line; } putc(c, f); need_newline = 1; goto loop; default: putc(c, f); need_newline = 1; goto loop; } } #if __STDC__ static void perl_comment(FILE *text_file, FILE *other_file) #else static void perl_comment(text_file, other_file) FILE *text_file; FILE *other_file; #endif { if (language == PERL) { fprintf(text_file, (cptr == line + 1) ? ";#" : "#"); if (dflag) fprintf(other_file, (cptr == line + 1) ? ";#" : "#"); } } #if __STDC__ static void copy_union(void) #else static void copy_union() #endif { register int c; int quote; int depth; int u_lineno = lineno; char *u_line = dup_line(); char *u_cptr = u_line + (cptr - line - 6); if (unionized) over_unionized(cptr - 6); unionized = 1; if (!lflag) fprintf(text_file, line_format, lineno, input_file_name); perl_comment(text_file, union_file); fprintf(text_file, "typedef union"); if (dflag) fprintf(union_file, "typedef union"); depth = 0; loop: c = *cptr++; putc(c, text_file); if (dflag) putc(c, union_file); switch (c) { case '\n': next_line: get_line(); if (line == 0) unterminated_union(u_lineno, u_line, u_cptr); perl_comment(text_file, union_file); goto loop; case '{': ++depth; goto loop; case '}': if (--depth == 0) { fprintf(text_file, " %sSTYPE;\n", define_prefix); FREE(u_line); return; } goto loop; case '\'': case '"': { int s_lineno = lineno; char *s_line = dup_line(); char *s_cptr = s_line + (cptr - line - 1); quote = c; for (;;) { c = *cptr++; putc(c, text_file); if (dflag) putc(c, union_file); if (c == quote) { FREE(s_line); goto loop; } if (c == '\n') unterminated_string(s_lineno, s_line, s_cptr); if (c == '\\') { c = *cptr++; putc(c, text_file); if (dflag) putc(c, union_file); if (c == '\n') { get_line(); if (line == 0) unterminated_string(s_lineno, s_line, s_cptr); } } } } case '/': c = *cptr; if (c == '/') { putc('*', text_file); if (dflag) putc('*', union_file); while ((c = *++cptr) != '\n') { if (c == '*' && cptr[1] == '/') { fprintf(text_file, "* "); if (dflag) fprintf(union_file, "* "); } else { putc(c, text_file); if (dflag) putc(c, union_file); } } fprintf(text_file, "*/\n"); if (dflag) fprintf(union_file, "*/\n"); goto next_line; } if (c == '*') { int c_lineno = lineno; char *c_line = dup_line(); char *c_cptr = c_line + (cptr - line - 1); putc('*', text_file); if (dflag) putc('*', union_file); ++cptr; for (;;) { c = *cptr++; putc(c, text_file); if (dflag) putc(c, union_file); if (c == '*' && *cptr == '/') { putc('/', text_file); if (dflag) putc('/', union_file); ++cptr; FREE(c_line); goto loop; } if (c == '\n') { get_line(); if (line == 0) unterminated_comment(c_lineno, c_line, c_cptr); } } } goto loop; default: goto loop; } } #if __STDC__ static int hexval(int c) #else static int hexval(c) int c; #endif { if (c >= '0' && c <= '9') return (c - '0'); if (c >= 'A' && c <= 'F') return (c - 'A' + 10); if (c >= 'a' && c <= 'f') return (c - 'a' + 10); return (-1); } #if __STDC__ static bucket *get_literal(void) #else static bucket *get_literal() #endif { register int c, quote; register int i; register int n; register char *s; register bucket *bp; int s_lineno = lineno; char *s_line = dup_line(); char *s_cptr = s_line + (cptr - line); quote = *cptr++; cinc = 0; for (;;) { c = *cptr++; if (c == quote) break; if (c == '\n') unterminated_string(s_lineno, s_line, s_cptr); if (c == '\\') { char *c_cptr = cptr - 1; c = *cptr++; switch (c) { case '\n': get_line(); if (line == 0) unterminated_string(s_lineno, s_line, s_cptr); continue; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': n = c - '0'; c = *cptr; if (IS_OCTAL(c)) { n = (n << 3) + (c - '0'); c = *++cptr; if (IS_OCTAL(c)) { n = (n << 3) + (c - '0'); ++cptr; } } if (n > MAXCHAR) illegal_character(c_cptr); c = n; break; case 'x': c = *cptr++; n = hexval(c); if (n < 0 || n >= 16) illegal_character(c_cptr); for (;;) { c = *cptr; i = hexval(c); if (i < 0 || i >= 16) break; ++cptr; n = (n << 4) + i; if (n > MAXCHAR) illegal_character(c_cptr); } c = n; break; case 'a': c = 7; break; case 'b': c = '\b'; break; case 'f': c = '\f'; break; case 'n': c = '\n'; break; case 'r': c = '\r'; break; case 't': c = '\t'; break; case 'v': c = '\v'; break; } } cachec(c); } FREE(s_line); n = cinc; s = MALLOC(n); for (i = 0; i < n; ++i) s[i] = cache[i]; cinc = 0; if (n == 1) cachec('\''); else cachec('"'); for (i = 0; i < n; ++i) { c = ((unsigned char *)s)[i]; if (c == '\\' || c == cache[0]) { cachec('\\'); cachec(c); } else if (isprint(c)) cachec(c); else { cachec('\\'); switch (c) { case 7: cachec('a'); break; case '\b': cachec('b'); break; case '\f': cachec('f'); break; case '\n': cachec('n'); break; case '\r': cachec('r'); break; case '\t': cachec('t'); break; case '\v': cachec('v'); break; default: cachec(((c >> 6) & 7) + '0'); cachec(((c >> 3) & 7) + '0'); cachec((c & 7) + '0'); break; } } } if (n == 1) cachec('\''); else cachec('"'); cachec(NUL); bp = lookup(cache); bp->class = TERM; if (n == 1 && bp->value == UNDEFINED) bp->value = *(unsigned char *)s; FREE(s); return (bp); } #if __STDC__ static int is_reserved(char *name) #else static int is_reserved(name) char *name; #endif { char *s; if (strcmp(name, ".") == 0 || strcmp(name, "$accept") == 0 || strcmp(name, "$end") == 0) return (1); if (name[0] == '$' && name[1] == '$' && isdigit(name[2])) { s = name + 3; while (isdigit(*s)) ++s; if (*s == NUL) return (1); } return (0); } #if __STDC__ static bucket *get_name(void) #else static bucket *get_name() #endif { register int c; cinc = 0; for (c = *cptr; IS_IDENT(c); c = *++cptr) cachec(c); cachec(NUL); if (is_reserved(cache)) used_reserved(cache); return (lookup(cache)); } #if __STDC__ static int get_number(void) #else static int get_number() #endif { register int c; register int n; n = 0; for (c = *cptr; isdigit(c); c = *++cptr) n = 10*n + (c - '0'); return (n); } #if __STDC__ static char *get_tag(void) #else static char *get_tag() #endif { register int c; register int i; register char *s; int t_lineno = lineno; char *t_line = dup_line(); char *t_cptr = t_line + (cptr - line); ++cptr; c = nextc(); if (c == EOF) unexpected_EOF(); if (!isalpha(c) && c != '_' && c != '$') illegal_tag(t_lineno, t_line, t_cptr); else if (! dollar_ok() && c == '$') illegal_tag(t_lineno, t_line, t_cptr); cinc = 0; do { cachec(c); c = *++cptr; } while (IS_IDENT(c)); cachec(NUL); c = nextc(); if (c == EOF) unexpected_EOF(); if (c != '>') illegal_tag(t_lineno, t_line, t_cptr); ++cptr; for (i = 0; i < ntags; ++i) { if (strcmp(cache, tag_table[i]) == 0) return (tag_table[i]); } if (ntags >= tagmax) { tagmax += 16; tag_table = (char **) (tag_table ? REALLOC(tag_table, tagmax*sizeof(char *)) : MALLOC(tagmax*sizeof(char *))); } s = MALLOC(cinc); strcpy(s, cache); tag_table[ntags] = s; ++ntags; FREE(t_line); return (s); } #if __STDC__ static void declare_tokens(int assoc) #else static void declare_tokens(assoc) int assoc; #endif { register int c; register bucket *bp; int value; char *tag = 0; if (assoc != TOKEN) ++prec; c = nextc(); if (c == EOF) unexpected_EOF(); if (c == '<') { tag = get_tag(); c = nextc(); if (c == EOF) unexpected_EOF(); } for (;;) { if (isalpha(c) || c == '_' || c == '.' || (dollar_ok() && c == '$')) bp = get_name(); else if (c == '\'' || c == '"') bp = get_literal(); else return; if (bp == goal) tokenized_start(bp->name); bp->class = TERM; if (tag) { if (bp->tag && tag != bp->tag) retyped_warning(bp->name); bp->tag = tag; } if (assoc != TOKEN) { if (bp->prec && prec != bp->prec) reprec_warning(bp->name); bp->assoc = assoc; bp->prec = prec; } c = nextc(); if (c == EOF) unexpected_EOF(); value = UNDEFINED; if (isdigit(c)) { value = get_number(); if (bp->value != UNDEFINED && value != bp->value) revalued_warning(bp->name); bp->value = value; c = nextc(); if (c == EOF) unexpected_EOF(); } } } #if __STDC__ static void declare_types(void) #else static void declare_types() #endif { register int c; register bucket *bp; char *tag; c = nextc(); if (c == EOF) unexpected_EOF(); if (c != '<') syntax_error(lineno, line, cptr); tag = get_tag(); for (;;) { c = nextc(); if (isalpha(c) || c == '_' || c == '.' || (dollar_ok() && c == '$')) bp = get_name(); else if (c == '\'' || c == '"') bp = get_literal(); else return; if (bp->tag && tag != bp->tag) retyped_warning(bp->name); bp->tag = tag; } } #if __STDC__ static void declare_start(void) #else static void declare_start() #endif { register int c; register bucket *bp; c = nextc(); if (c == EOF) unexpected_EOF(); if (!isalpha(c) && c != '_' && c != '.' && c != '$') syntax_error(lineno, line, cptr); else if (! dollar_ok() && c == '$') syntax_error(lineno, line, cptr); bp = get_name(); if (bp->class == TERM) terminal_start(bp->name); if (goal && goal != bp) restarted_warning(); goal = bp; } #if __STDC__ static void read_declarations(void) #else static void read_declarations() #endif { register int c, k; cache_size = 256; cache = MALLOC(cache_size); for (;;) { c = nextc(); if (c == EOF) unexpected_EOF(); if (c != '%') syntax_error(lineno, line, cptr); switch (k = keyword()) { case MARK: return; case IDENT: copy_ident(); break; case TEXT: copy_text(); break; case UNION: copy_union(); break; case TOKEN: case LEFT: case RIGHT: case NONASSOC: declare_tokens(k); break; case TYPE: declare_types(); break; case START: declare_start(); break; } } } #if __STDC__ static void initialize_grammar(void) #else static void initialize_grammar() #endif { nitems = 4; maxitems = 300; pitem = (bucket **) MALLOC(maxitems*sizeof(bucket *)); pitem[0] = 0; pitem[1] = 0; pitem[2] = 0; pitem[3] = 0; nrules = 3; maxrules = 100; plhs = (bucket **) MALLOC(maxrules*sizeof(bucket *)); plhs[0] = 0; plhs[1] = 0; plhs[2] = 0; rprec = (short *) MALLOC(maxrules*sizeof(short)); rprec[0] = 0; rprec[1] = 0; rprec[2] = 0; rassoc = (char *) MALLOC(maxrules*sizeof(char)); rassoc[0] = TOKEN; rassoc[1] = TOKEN; rassoc[2] = TOKEN; } #if __STDC__ static void expand_items(void) #else static void expand_items() #endif { maxitems += 300; pitem = (bucket **) REALLOC(pitem, maxitems*sizeof(bucket *)); } #if __STDC__ static void expand_rules(void) #else static void expand_rules() #endif { maxrules += 100; plhs = (bucket **) REALLOC(plhs, maxrules*sizeof(bucket *)); rprec = (short *) REALLOC(rprec, maxrules*sizeof(short)); rassoc = (char *) REALLOC(rassoc, maxrules*sizeof(char)); } #if __STDC__ static void advance_to_start(void) #else static void advance_to_start() #endif { register int c; register bucket *bp; char *s_cptr; int s_lineno; for (;;) { c = nextc(); if (c != '%') break; s_cptr = cptr; switch (keyword()) { case MARK: no_grammar(); case TEXT: copy_text(); break; case START: declare_start(); break; default: syntax_error(lineno, line, s_cptr); } } c = nextc(); if (!isalpha(c) && c != '_' && c != '.') syntax_error(lineno, line, cptr); bp = get_name(); if (goal == 0) { if (bp->class == TERM) terminal_start(bp->name); goal = bp; } s_lineno = lineno; c = nextc(); if (c == EOF) unexpected_EOF(); if (c != ':') syntax_error(lineno, line, cptr); start_rule(bp, s_lineno); ++cptr; } #if __STDC__ static void start_rule(register bucket *bp, int s_lineno) #else static void start_rule(bp, s_lineno) register bucket *bp; int s_lineno; #endif { if (bp->class == TERM) terminal_lhs(s_lineno); bp->class = NONTERM; if (nrules >= maxrules) expand_rules(); plhs[nrules] = bp; rprec[nrules] = UNDEFINED; rassoc[nrules] = TOKEN; } #if __STDC__ static void end_rule(void) #else static void end_rule() #endif { register int i; if (!last_was_action && plhs[nrules]->tag) { for (i = nitems - 1; pitem[i]; --i) continue; if (pitem[i+1] == 0 || pitem[i+1]->tag != plhs[nrules]->tag) default_action_warning(); } last_was_action = 0; if (nitems >= maxitems) expand_items(); pitem[nitems] = 0; ++nitems; ++nrules; } #if __STDC__ static void insert_empty_rule(void) #else static void insert_empty_rule() #endif { register bucket *bp, **bpp; assert(cache != (char *) NULL); sprintf(cache, "$$%d", ++gensym); bp = make_bucket(cache); last_symbol->next = bp; last_symbol = bp; bp->tag = plhs[nrules]->tag; bp->class = NONTERM; if ((nitems += 2) > maxitems) expand_items(); bpp = pitem + nitems - 1; *bpp-- = bp; while (bpp[0] = bpp[-1]) --bpp; if (++nrules >= maxrules) expand_rules(); plhs[nrules] = plhs[nrules-1]; plhs[nrules-1] = bp; rprec[nrules] = rprec[nrules-1]; rprec[nrules-1] = 0; rassoc[nrules] = rassoc[nrules-1]; rassoc[nrules-1] = TOKEN; } #if __STDC__ static void add_symbol(void) #else static void add_symbol() #endif { register int c; register bucket *bp; int s_lineno = lineno; c = *cptr; if (c == '\'' || c == '"') bp = get_literal(); else bp = get_name(); c = nextc(); if (c == ':') { end_rule(); start_rule(bp, s_lineno); ++cptr; return; } if (last_was_action) insert_empty_rule(); last_was_action = 0; if (++nitems > maxitems) expand_items(); pitem[nitems-1] = bp; } #if __STDC__ static void copy_action(void) #else static void copy_action() #endif { register int c; register int i, n; int depth; int quote; char *tag; register FILE *f = action_file; int a_lineno = lineno; char *a_line = dup_line(); char *a_cptr = a_line + (cptr - line); if (last_was_action) insert_empty_rule(); last_was_action = 1; if (language == PERL) fprintf(f, "if ($p->{%sn} == %d) {\n", symbol_prefix, nrules - 2); else fprintf(f, "case %d:\n", nrules - 2); if (!lflag) fprintf(f, line_format, lineno, input_file_name); if (*cptr == '=') ++cptr; n = 0; for (i = nitems - 1; pitem[i]; --i) ++n; depth = 0; loop: c = *cptr; if (c == '$') { if (cptr[1] == '<') { int d_lineno = lineno; char *d_line = dup_line(); char *d_cptr = d_line + (cptr - line); ++cptr; tag = get_tag(); c = *cptr; if (c == '$') { if (language == PERL) fprintf(f, "$p->{%sval}", symbol_prefix); else fprintf(f, "%sval.%s", symbol_prefix, tag); ++cptr; FREE(d_line); goto loop; } else if (isdigit(c)) { i = get_number(); if (i > n) dollar_warning(d_lineno, i); if (language == PERL) fprintf(f, "$p->{%svs}->[$p->{%svsp}-%d]", symbol_prefix, symbol_prefix, n - i); else fprintf(f, "%svsp[%d].%s", symbol_prefix, i - n, tag); FREE(d_line); goto loop; } else if (c == '-' && isdigit(cptr[1])) { ++cptr; i = -get_number() - n; if (language == PERL) fprintf(f, "$p->{%svsp}->[$p->{%svsp}-%d]", symbol_prefix, symbol_prefix, -i); else fprintf(f, "%svsp[%d].%s", symbol_prefix, i, tag); FREE(d_line); goto loop; } else dollar_error(d_lineno, d_line, d_cptr); } else if (cptr[1] == '$') { if (ntags) { tag = plhs[nrules]->tag; if (tag == 0) untyped_lhs(); if (language == PERL) fprintf(f, "$p->{%sval}", symbol_prefix); else fprintf(f, "%sval.%s", symbol_prefix, tag); } else if (language == PERL) fprintf(f, "$p->{%sval}", symbol_prefix); else fprintf(f, "%sval", symbol_prefix); cptr += 2; goto loop; } else if (isdigit(cptr[1])) { ++cptr; i = get_number(); if (ntags) { if (i <= 0 || i > n) unknown_rhs(i); tag = pitem[nitems + i - n - 1]->tag; if (tag == 0) untyped_rhs(i, pitem[nitems + i - n - 1]->name); if (language == PERL) fprintf(f, "$p->{%svs}->[$p->{%svsp}-%d]", symbol_prefix, symbol_prefix, n - i); else fprintf(f, "%svsp[%d].%s", symbol_prefix, i - n, tag); } else { if (i > n) dollar_warning(lineno, i); if (language == PERL) fprintf(f, "$p->{%svs}->[$p->{%svsp}-%d]", symbol_prefix, symbol_prefix, n - i); else fprintf(f, "%svsp[%d]", symbol_prefix, i - n); } goto loop; } else if (cptr[1] == '-') { cptr += 2; i = get_number(); if (ntags) unknown_rhs(-i); if (language == PERL) fprintf(f, "$p->{%svs}->[$p->{%svsp}-%d]", symbol_prefix, symbol_prefix, i + n); else fprintf(f, "%svsp[%d]", symbol_prefix, -i - n); goto loop; } } if (isalpha(c) || c == '_' || (dollar_ok() && c == '$')) { do { putc(c, f); c = *++cptr; } while (isalnum(c) || c == '_' || (dollar_ok() && c == '$')); goto loop; } ++cptr; switch (c) { case '\n': putc(c, f); next_line: get_line(); if (line) goto loop; unterminated_action(a_lineno, a_line, a_cptr); case ';': putc(c, f); if (depth > 0) goto loop; if (language == PERL) fprintf(f, "\n}\n"); else fprintf(f, "\nbreak;\n"); FREE(a_line); return; case '{': putc(c, f); ++depth; goto loop; case '}': if (--depth > 0) { putc(c, f); goto loop; } if (language == PERL) fprintf(f, "}\n}\n"); else fprintf(f, "}\nbreak;\n"); FREE(a_line); return; case '\'': case '"': { int s_lineno = lineno; char *s_line = dup_line(); char *s_cptr = s_line + (cptr - line - 1); putc(c, f); quote = c; for (;;) { c = *cptr++; putc(c, f); if (c == quote) { FREE(s_line); goto loop; } if (c == '\n') unterminated_string(s_lineno, s_line, s_cptr); if (c == '\\') { c = *cptr++; putc(c, f); if (c == '\n') { get_line(); if (line == 0) unterminated_string(s_lineno, s_line, s_cptr); } } } } case '/': c = *cptr; if (c == '/') { if (language == PERL) { ++cptr; goto perl_comment; } fprintf(f, "/*"); while ((c = *++cptr) != '\n') { if (c == '*' && cptr[1] == '/') fprintf(f, "* "); else putc(c, f); } fprintf(f, "*/\n"); goto next_line; } if (c != '*') { putc('/', f); } else { int c_lineno = lineno; char *c_line = dup_line(); char *c_cptr = c_line + (cptr - line - 1); if (language == PERL) fprintf(f, (cptr == line + 1) ? ";#" : "#"); else fprintf(f, "/*"); ++cptr; for (;;) { c = *cptr++; if (language == PERL && c == '*' && *cptr == '/') { putc('\n', f); ++cptr; FREE(c_line); goto loop; } putc(c, f); if (c == '*' && *cptr == '/') { putc('/', f); ++cptr; FREE(c_line); goto loop; } if (c == '\n') { get_line(); if (line == 0) unterminated_comment(c_lineno, c_line, c_cptr); if (language == PERL) fprintf(f, ";# "); } } } goto loop; case '#': perl_comment: if (language == PERL) { putc('#', f); do { putc(*cptr, f); } while (*cptr++ != '\n'); goto next_line; } else { putc(c, f); } goto loop; default: putc(c, f); goto loop; } /*NOTREACHED*/ /* or at least it better not be reached*/ } #if __STDC__ static int mark_symbol(void) #else static int mark_symbol() #endif { register int c; register bucket *bp; c = cptr[1]; if (c == '%' || c == '\\') { cptr += 2; return (1); } if (c == '=') cptr += 2; else if ((c == 'p' || c == 'P') && ((c = cptr[2]) == 'r' || c == 'R') && ((c = cptr[3]) == 'e' || c == 'E') && ((c = cptr[4]) == 'c' || c == 'C') && ((c = cptr[5], !IS_IDENT(c)))) cptr += 5; else syntax_error(lineno, line, cptr); c = nextc(); if (isalpha(c) || c == '_' || c == '.' || (dollar_ok() && c == '$')) bp = get_name(); else if (c == '\'' || c == '"') bp = get_literal(); else { syntax_error(lineno, line, cptr); /*NOTREACHED*/ } if (rprec[nrules] != UNDEFINED && bp->prec != rprec[nrules]) prec_redeclared(); rprec[nrules] = bp->prec; rassoc[nrules] = bp->assoc; return (0); } #if __STDC__ static void read_grammar(void) #else static void read_grammar() #endif { register int c; initialize_grammar(); advance_to_start(); for (;;) { c = nextc(); if (c == EOF) break; if (isalpha(c) || c == '_' || c == '.' || (dollar_ok() && c == '$') || c == '\'' || c == '"') add_symbol(); else if (c == '{' || c == '=') copy_action(); else if (c == '|') { end_rule(); start_rule(plhs[nrules-1], 0); ++cptr; } else if (c == '%') { if (mark_symbol()) break; } else syntax_error(lineno, line, cptr); } end_rule(); } #if __STDC__ static void free_tags(void) #else static void free_tags() #endif { register int i; if (tag_table == 0) return; for (i = 0; i < ntags; ++i) { assert(tag_table[i] != (char *) NULL); FREE(tag_table[i]); } FREE(tag_table); } #if __STDC__ static void pack_names(void) #else static void pack_names() #endif { register bucket *bp; register char *p, *s, *t; name_pool_size = sizeof("$end") + sizeof("$accept"); for (bp = first_symbol; bp; bp = bp->next) name_pool_size += strlen(bp->name) + 1; name_pool = MALLOC(name_pool_size); strcpy(name_pool, "$accept"); strcpy(name_pool + sizeof("$accept"), "$end"); t = name_pool + sizeof("$end") + sizeof("$accept"); for (bp = first_symbol; bp; bp = bp->next) { p = t; s = bp->name; while (*t++ = *s++) continue; FREE(bp->name); bp->name = p; } } #if __STDC__ static void check_symbols(void) #else static void check_symbols() #endif { register bucket *bp; if (goal->class == UNKNOWN) undefined_goal(goal->name); for (bp = first_symbol; bp; bp = bp->next) { if (bp->class == UNKNOWN) { undefined_symbol_warning(bp->name); bp->class = TERM; } } } #if __STDC__ static void pack_symbols(void) #else static void pack_symbols() #endif { register bucket *bp; register bucket **v; register int i, j, k, n; nsyms = 2; ntokens = 1; for (bp = first_symbol; bp; bp = bp->next) { ++nsyms; if (bp->class == TERM) ++ntokens; } start_symbol = ntokens; nvars = nsyms - ntokens; symbol_name = (char **) MALLOC(nsyms*sizeof(char *)); symbol_value = (short *) MALLOC(nsyms*sizeof(short)); symbol_prec = (short *) MALLOC(nsyms*sizeof(short)); symbol_assoc = MALLOC(nsyms); v = (bucket **) MALLOC(nsyms*sizeof(bucket *)); v[0] = 0; v[start_symbol] = 0; i = 1; j = start_symbol + 1; for (bp = first_symbol; bp; bp = bp->next) { if (bp->class == TERM) v[i++] = bp; else v[j++] = bp; } assert(i == ntokens && j == nsyms); for (i = 1; i < ntokens; ++i) v[i]->index = i; goal->index = start_symbol + 1; k = start_symbol + 2; while (++i < nsyms) if (v[i] != goal) { v[i]->index = k; ++k; } goal->value = 0; k = 1; for (i = start_symbol + 1; i < nsyms; ++i) { if (v[i] != goal) { v[i]->value = k; ++k; } } k = 0; for (i = 1; i < ntokens; ++i) { n = v[i]->value; if (n > 256) { for (j = k++; j > 0 && symbol_value[j-1] > n; --j) symbol_value[j] = symbol_value[j-1]; symbol_value[j] = n; } } if (v[1]->value == UNDEFINED) v[1]->value = 256; j = 0; n = 257; for (i = 2; i < ntokens; ++i) { if (v[i]->value == UNDEFINED) { while (j < k && n == symbol_value[j]) { while (++j < k && n == symbol_value[j]) continue; ++n; } v[i]->value = n; ++n; } } symbol_name[0] = name_pool + 8; symbol_value[0] = 0; symbol_prec[0] = 0; symbol_assoc[0] = TOKEN; for (i = 1; i < ntokens; ++i) { symbol_name[i] = v[i]->name; symbol_value[i] = v[i]->value; symbol_prec[i] = v[i]->prec; symbol_assoc[i] = v[i]->assoc; } symbol_name[start_symbol] = name_pool; symbol_value[start_symbol] = -1; symbol_prec[start_symbol] = 0; symbol_assoc[start_symbol] = TOKEN; for (++i; i < nsyms; ++i) { k = v[i]->index; symbol_name[k] = v[i]->name; symbol_value[k] = v[i]->value; symbol_prec[k] = v[i]->prec; symbol_assoc[k] = v[i]->assoc; } FREE(v); } #if __STDC__ static void pack_grammar(void) #else static void pack_grammar() #endif { register int i, j; int assoc, prec; ritem = (short *) MALLOC(nitems*sizeof(short)); rlhs = (short *) MALLOC(nrules*sizeof(short)); rrhs = (short *) MALLOC((nrules+1)*sizeof(short)); rprec = (short *) REALLOC(rprec, nrules*sizeof(short)); rassoc = REALLOC(rassoc, nrules); ritem[0] = -1; ritem[1] = goal->index; ritem[2] = 0; ritem[3] = -2; rlhs[0] = 0; rlhs[1] = 0; rlhs[2] = start_symbol; rrhs[0] = 0; rrhs[1] = 0; rrhs[2] = 1; j = 4; for (i = 3; i < nrules; ++i) { rlhs[i] = plhs[i]->index; rrhs[i] = j; assoc = TOKEN; prec = 0; while (pitem[j]) { ritem[j] = pitem[j]->index; if (pitem[j]->class == TERM) { prec = pitem[j]->prec; assoc = pitem[j]->assoc; } ++j; } ritem[j] = -i; ++j; if (rprec[i] == UNDEFINED) { rprec[i] = prec; rassoc[i] = assoc; } } rrhs[i] = j; FREE(plhs); FREE(pitem); } #if __STDC__ static void print_grammar(void) #else static void print_grammar() #endif { register int i, j, k; int spacing; register FILE *f = verbose_file; if (!vflag) return; k = 1; for (i = 2; i < nrules; ++i) { if (rlhs[i] != rlhs[i-1]) { if (i != 2) fprintf(f, "\n"); fprintf(f, "%4d %s :", i - 2, symbol_name[rlhs[i]]); spacing = strlen(symbol_name[rlhs[i]]) + 1; } else { fprintf(f, "%4d ", i - 2); j = spacing; while (--j >= 0) putc(' ', f); putc('|', f); } while (ritem[k] >= 0) { fprintf(f, " %s", symbol_name[ritem[k]]); ++k; } ++k; putc('\n', f); } } #if __STDC__ void reader(void) #else void reader() #endif { write_section(banner); if (language == PERL) fprintf(code_file, "package %s;\n", perl_package); create_symbol_table(); read_declarations(); read_grammar(); free_symbol_table(); free_tags(); pack_names(); check_symbols(); pack_symbols(); pack_grammar(); free_symbols(); print_grammar(); } perl-byacc-2.0.orig/skeleton.c100644 1750 1750 42106 6745547577 15203 0ustar bortzbortz#include "defs.h" /* The banner used here should be replaced with an #ident directive */ /* if the target C compiler supports #ident directives. */ /* */ /* If the skeleton is changed, the banner should be changed so that */ /* the altered version can easily be distinguished from the original. */ static char *c_banner[] = { "#ifndef lint", "static char yysccsid[] = \"@(#)yaccpar 1.8 (Berkeley) 01/20/91\";", "#endif", "#define YYBYACC 1", (char *) NULL }; static char *perl_banner[] = { "# @(#)yaccpar 1.8 (Berkeley) 01/20/91 (JAKE-P5BP-0.6 04/26/98)", (char *) NULL }; char **banner[] = { c_banner, perl_banner }; static char *c_tables[] = { "extern short yylhs[];", "extern short yylen[];", "extern short yydefred[];", "extern short yydgoto[];", "extern short yysindex[];", "extern short yyrindex[];", "extern short yygindex[];", "extern short yytable[];", "extern short yycheck[];", "#if YYDEBUG", "extern char *yyname[];", "extern char *yyrule[];", "#endif", (char *) NULL }; char **tables[] = { c_tables, (char **) NULL }; static char *c_header[] = { "#define yyclearin (yychar=(-1))", "#define yyerrok (yyerrflag=0)", "#ifdef YYSTACKSIZE", "#ifndef YYMAXDEPTH", "#define YYMAXDEPTH YYSTACKSIZE", "#endif", "#else", "#ifdef YYMAXDEPTH", "#define YYSTACKSIZE YYMAXDEPTH", "#else", "#define YYSTACKSIZE 500", "#define YYMAXDEPTH 500", "#endif", "#endif", "int yydebug;", "int yynerrs;", "int yyerrflag;", "int yychar;", "short *yyssp;", "YYSTYPE *yyvsp;", "YYSTYPE yyval;", "YYSTYPE yylval;", "short yyss[YYSTACKSIZE];", "YYSTYPE yyvs[YYSTACKSIZE];", "#define yystacksize YYSTACKSIZE", (char *) NULL }; static char *perl_header[] = { "sub yyclearin {", " my PP $p;", " ($p) = @_;", " $p->{yychar} = -1;", "}", "sub yyerrok {", " my PP $p;", " ($p) = @_;", " $p->{yyerrflag} = 0;", "}", (char *) NULL }; char **header[] = { c_header, perl_header }; static char *c_body[] = { "#define YYABORT goto yyabort", "#define YYACCEPT goto yyaccept", "#define YYERROR goto yyerrlab", "int", "yyparse()", "{", " register int yym, yyn, yystate;", "#if YYDEBUG", " register char *yys;", " extern char *getenv();", "", " if (yys = getenv(\"YYDEBUG\"))", " {", " yyn = *yys;", " if (yyn >= '0' && yyn <= '9')", " yydebug = yyn - '0';", " }", "#endif", "", " yynerrs = 0;", " yyerrflag = 0;", " yychar = (-1);", "", " yyssp = yyss;", " yyvsp = yyvs;", " *yyssp = yystate = 0;", "", "yyloop:", " if (yyn = yydefred[yystate]) goto yyreduce;", " if (yychar < 0)", " {", " if ((yychar = yylex()) < 0) yychar = 0;", "#if YYDEBUG", " if (yydebug)", " {", " yys = 0;", " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];", " if (!yys) yys = \"illegal-symbol\";", " printf(\"yydebug: state %d, reading %d (%s)\\n\", yystate,", " yychar, yys);", " }", "#endif", " }", " if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&", " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)", " {", "#if YYDEBUG", " if (yydebug)", " printf(\"yydebug: state %d, shifting to state %d\\n\",", " yystate, yytable[yyn]);", "#endif", " if (yyssp >= yyss + yystacksize - 1)", " {", " goto yyoverflow;", " }", " *++yyssp = yystate = yytable[yyn];", " *++yyvsp = yylval;", " yychar = (-1);", " if (yyerrflag > 0) --yyerrflag;", " goto yyloop;", " }", " if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&", " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)", " {", " yyn = yytable[yyn];", " goto yyreduce;", " }", " if (yyerrflag) goto yyinrecovery;", "#ifdef lint", " goto yynewerror;", "#endif", "yynewerror:", " yyerror(\"syntax error\");", "#ifdef lint", " goto yyerrlab;", "#endif", "yyerrlab:", " ++yynerrs;", "yyinrecovery:", " if (yyerrflag < 3)", " {", " yyerrflag = 3;", " for (;;)", " {", " if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&", " yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)", " {", "#if YYDEBUG", " if (yydebug)", " printf(\"yydebug: state %d, error recovery shifting\\", " to state %d\\n\", *yyssp, yytable[yyn]);", "#endif", " if (yyssp >= yyss + yystacksize - 1)", " {", " goto yyoverflow;", " }", " *++yyssp = yystate = yytable[yyn];", " *++yyvsp = yylval;", " goto yyloop;", " }", " else", " {", "#if YYDEBUG", " if (yydebug)", " printf(\"yydebug: error recovery discarding state %d\ \\n\",", " *yyssp);", "#endif", " if (yyssp <= yyss) goto yyabort;", " --yyssp;", " --yyvsp;", " }", " }", " }", " else", " {", " if (yychar == 0) goto yyabort;", "#if YYDEBUG", " if (yydebug)", " {", " yys = 0;", " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];", " if (!yys) yys = \"illegal-symbol\";", " printf(\"yydebug: state %d, error recovery discards token %d\ (%s)\\n\",", " yystate, yychar, yys);", " }", "#endif", " yychar = (-1);", " goto yyloop;", " }", "yyreduce:", "#if YYDEBUG", " if (yydebug)", " printf(\"yydebug: state %d, reducing by rule %d (%s)\\n\",", " yystate, yyn, yyrule[yyn]);", "#endif", " yym = yylen[yyn];", " yyval = yyvsp[1-yym];", " switch (yyn)", " {", (char *) NULL }; static char *perl_body[] = { /* This is kludgy--the top of this sub needs to vary based on -5, so * it was moved to output.c. */ " $p->{yylex} = $_[1];", " $p->{yyerror} = $_[2];", " $p->{yydebug} = $_[3];", " return $p;", "}", "sub YYERROR {", " my PP $p;", " ($p) = @_;", " ++$p->{yynerrs};", " $p->yy_err_recover;", "}", "sub yy_err_recover {", " my PP $p;", " ($p) = @_;", " if ($p->{yyerrflag} < 3)", " {", " $p->{yyerrflag} = 3;", " while (1)", " {", " if (($p->{yyn} = $yysindex[$p->{yyss}->[$p->{yyssp}]]) && ", " ($p->{yyn} += $YYERRCODE) >= 0 && ", " $p->{yyn} <= $#yycheck &&", " $yycheck[$p->{yyn}] == $YYERRCODE)", " {", " warn(\"yydebug: state \" . ", " $p->{yyss}->[$p->{yyssp}] . ", " \", error recovery shifting to state\" . ", " $yytable[$p->{yyn}] . \"\\n\") ", " if $p->{yydebug};", " $p->{yyss}->[++$p->{yyssp}] = ", " $p->{yystate} = $yytable[$p->{yyn}];", " $p->{yyvs}->[++$p->{yyvsp}] = $p->{yylval};", " next yyloop;", " }", " else", " {", " warn(\"yydebug: error recovery discarding state \".", " $p->{yyss}->[$p->{yyssp}]. \"\\n\") ", " if $p->{yydebug};", " return(undef) if $p->{yyssp} <= 0;", " --$p->{yyssp};", " --$p->{yyvsp};", " }", " }", " }", " else", " {", " return (undef) if $p->{yychar} == 0;", " if ($p->{yydebug})", " {", " $p->{yys} = '';", " if ($p->{yychar} <= $YYMAXTOKEN) { $p->{yys} = ", " $yyname[$p->{yychar}]; }", " if (!$p->{yys}) { $p->{yys} = 'illegal-symbol'; }", " warn(\"yydebug: state \" . $p->{yystate} . ", " \", error recovery discards \" . ", " \"token \" . $p->{yychar} . \"(\" . ", " $p->{yys} . \")\\n\");", " }", " $p->{yychar} = -1;", " next yyloop;", " }", "0;", "} # yy_err_recover", "", "sub yyparse {", " my PP $p;", " my $s;", " ($p, $s) = @_;", " if ($p->{yys} = $ENV{'YYDEBUG'})", " {", " $p->{yydebug} = int($1) if $p->{yys} =~ /^(\\d)/;", " }", "", " $p->{yynerrs} = 0;", " $p->{yyerrflag} = 0;", " $p->{yychar} = (-1);", "", " $p->{yyssp} = 0;", " $p->{yyvsp} = 0;", " $p->{yyss}->[$p->{yyssp}] = $p->{yystate} = 0;", "", "yyloop: while(1)", " {", " yyreduce: {", " last yyreduce if ($p->{yyn} = $yydefred[$p->{yystate}]);", " if ($p->{yychar} < 0)", " {", " if ((($p->{yychar}, $p->{yylval}) = ", " &{$p->{yylex}}($s)) < 0) { $p->{yychar} = 0; }", " if ($p->{yydebug})", " {", " $p->{yys} = '';", " if ($p->{yychar} <= $#yyname) ", " { $p->{yys} = $yyname[$p->{yychar}]; }", " if (!$p->{yys}) { $p->{yys} = 'illegal-symbol'; };", " warn(\"yydebug: state \" . $p->{yystate} . ", " \", reading \" . $p->{yychar} . \" (\" . ", " $p->{yys} . \")\\n\");", " }", " }", " if (($p->{yyn} = $yysindex[$p->{yystate}]) && ", " ($p->{yyn} += $p->{yychar}) >= 0 && ", " $p->{yyn} <= $#yycheck &&", " $yycheck[$p->{yyn}] == $p->{yychar})", " {", " warn(\"yydebug: state \" . $p->{yystate} . ", " \", shifting to state \" .", " $yytable[$p->{yyn}] . \"\\n\") if $p->{yydebug};", " $p->{yyss}->[++$p->{yyssp}] = $p->{yystate} = ", " $yytable[$p->{yyn}];", " $p->{yyvs}->[++$p->{yyvsp}] = $p->{yylval};", " $p->{yychar} = (-1);", " --$p->{yyerrflag} if $p->{yyerrflag} > 0;", " next yyloop;", " }", " if (($p->{yyn} = $yyrindex[$p->{yystate}]) && ", " ($p->{yyn} += $p->{'yychar'}) >= 0 &&", " $p->{yyn} <= $#yycheck &&", " $yycheck[$p->{yyn}] == $p->{yychar})", " {", " $p->{yyn} = $yytable[$p->{yyn}];", " last yyreduce;", " }", " if (! $p->{yyerrflag}) {", " &{$p->{yyerror}}('syntax error', $s);", " ++$p->{yynerrs};", " }", " return(undef) if $p->yy_err_recover;", " } # yyreduce", " warn(\"yydebug: state \" . $p->{yystate} . ", " \", reducing by rule \" . ", " $p->{yyn} . \" (\" . $yyrule[$p->{yyn}] . ", " \")\\n\") if $p->{yydebug};", " $p->{yym} = $yylen[$p->{yyn}];", " $p->{yyval} = $p->{yyvs}->[$p->{yyvsp}+1-$p->{yym}];", (char *) NULL }; char **body[] = { c_body, perl_body }; static char *c_trailer[] = { " }", " yyssp -= yym;", " yystate = *yyssp;", " yyvsp -= yym;", " yym = yylhs[yyn];", " if (yystate == 0 && yym == 0)", " {", "#if YYDEBUG", " if (yydebug)", " printf(\"yydebug: after reduction, shifting from state 0 to\\", " state %d\\n\", YYFINAL);", "#endif", " yystate = YYFINAL;", " *++yyssp = YYFINAL;", " *++yyvsp = yyval;", " if (yychar < 0)", " {", " if ((yychar = yylex()) < 0) yychar = 0;", "#if YYDEBUG", " if (yydebug)", " {", " yys = 0;", " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];", " if (!yys) yys = \"illegal-symbol\";", " printf(\"yydebug: state %d, reading %d (%s)\\n\",", " YYFINAL, yychar, yys);", " }", "#endif", " }", " if (yychar == 0) goto yyaccept;", " goto yyloop;", " }", " if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&", " yyn <= YYTABLESIZE && yycheck[yyn] == yystate)", " yystate = yytable[yyn];", " else", " yystate = yydgoto[yym];", "#if YYDEBUG", " if (yydebug)", " printf(\"yydebug: after reduction, shifting from state %d \\", "to state %d\\n\", *yyssp, yystate);", "#endif", " if (yyssp >= yyss + yystacksize - 1)", " {", " goto yyoverflow;", " }", " *++yyssp = yystate;", " *++yyvsp = yyval;", " goto yyloop;", "yyoverflow:", " yyerror(\"yacc stack overflow\");", "yyabort:", " return (1);", "yyaccept:", " return (0);", "}", (char *) NULL }; static char *perl_trailer[] = { " $p->{yyssp} -= $p->{yym};", " $p->{yystate} = $p->{yyss}->[$p->{yyssp}];", " $p->{yyvsp} -= $p->{yym};", " $p->{yym} = $yylhs[$p->{yyn}];", " if ($p->{yystate} == 0 && $p->{yym} == 0)", " {", " warn(\"yydebug: after reduction, shifting from state 0 \",", " \"to state $YYFINAL\\n\") if $p->{yydebug};", " $p->{yystate} = $YYFINAL;", " $p->{yyss}->[++$p->{yyssp}] = $YYFINAL;", " $p->{yyvs}->[++$p->{yyvsp}] = $p->{yyval};", " if ($p->{yychar} < 0)", " {", " if ((($p->{yychar}, $p->{yylval}) = ", " &{$p->{yylex}}($s)) < 0) { $p->{yychar} = 0; }", " if ($p->{yydebug})", " {", " $p->{yys} = '';", " if ($p->{yychar} <= $#yyname) ", " { $p->{yys} = $yyname[$p->{yychar}]; }", " if (!$p->{yys}) { $p->{yys} = 'illegal-symbol'; }", " warn(\"yydebug: state $YYFINAL, reading \" . ", " $p->{yychar} . \" (\" . $p->{yys} . \")\\n\");", " }", " }", " return ($p->{yyvs}->[1]) if $p->{yychar} == 0;", " next yyloop;", " }", " if (($p->{yyn} = $yygindex[$p->{yym}]) && ", " ($p->{yyn} += $p->{yystate}) >= 0 && ", " $p->{yyn} <= $#yycheck && ", " $yycheck[$p->{yyn}] == $p->{yystate})", " {", " $p->{yystate} = $yytable[$p->{yyn}];", " } else {", " $p->{yystate} = $yydgoto[$p->{yym}];", " }", " warn(\"yydebug: after reduction, shifting from state \" . ", " $p->{yyss}->[$p->{yyssp}] . \" to state \" . ", " $p->{yystate} . \"\\n\") if $p->{yydebug};", " $p->{yyss}[++$p->{yyssp}] = $p->{yystate};", " $p->{yyvs}[++$p->{yyvsp}] = $p->{yyval};", " } # yyloop", "} # yyparse", (char *) NULL }; char **trailer[] = { c_trailer, perl_trailer }; #if __STDC__ static char *add_perl_package(char *old_str, char *new_str) #else static char *add_perl_package(old_str, new_str) char *old_str; char *new_str; #endif { register char *from = old_str; register char *to = new_str; register char *p; while (*from) { if (*from == 'P' && *(from + 1) == 'P') { from += 2; p = perl5005flag ? perl_package : ""; while (*to++ = *p++) /* void */ ; to--; } else { *to++ = *from++; } } *to = *from; return new_str; } #if __STDC__ static char *add_prefixes(char *old_str, char *new_str) #else static char *add_prefixes(old_str, new_str) char *old_str; char *new_str; #endif { register char *from = old_str; register char *to = new_str; register char *p; while (*from) { if (*from == 'Y' && *(from + 1) == 'Y') { from += 2; p = define_prefix; while (*to++ = *p++) /* void */ ; to--; } else if (*from == 'y' && *(from + 1) == 'y') { from += 2; p = symbol_prefix; while (*to++ = *p++) /* void */ ; to--; } else { *to++ = *from++; } } *to = *from; return new_str; } #if __STDC__ void write_section(char **section[]) #else void write_section(section) char **section[]; #endif { register int i; register FILE *fp; register char **sec = section[(int) language]; if (sec != (char **) NULL) { fp = code_file; if (language == PERL) { char buf[BUFSIZ]; for (i = 0; sec[i]; ++i) { ++outline; fprintf(fp, "%s\n", add_perl_package(sec[i], buf)); } } else if (prefix_changed) { char buf[BUFSIZ]; for (i = 0; sec[i]; ++i) { ++outline; fprintf(fp, "%s\n", add_prefixes(sec[i], buf)); } } else { for (i = 0; sec[i]; ++i) { ++outline; fprintf(fp, "%s\n", sec[i]); } } } } perl-byacc-2.0.orig/symtab.c100644 1750 1750 4044 5325700435 14606 0ustar bortzbortz#include "defs.h" /* TABLE_SIZE is the number of entries in the symbol table. */ /* TABLE_SIZE must be a power of two. */ #define TABLE_SIZE 1024 bucket **symbol_table; bucket *first_symbol; bucket *last_symbol; #if __STDC__ static int hash(char *name) #else static int hash(name) char *name; #endif { register char *s; register int c, k; assert(name != (char *) NULL && *name); s = name; k = *s; while (c = *++s) k = (31*k + c) & (TABLE_SIZE - 1); return (k); } #if __STDC__ bucket *make_bucket(char *name) #else bucket *make_bucket(name) char *name; #endif { register bucket *bp; assert(name != (char *) NULL); bp = (bucket *) MALLOC(sizeof(bucket)); bp->link = 0; bp->next = 0; bp->name = MALLOC(strlen(name) + 1); bp->tag = 0; bp->value = UNDEFINED; bp->index = 0; bp->prec = 0; bp-> class = UNKNOWN; bp->assoc = TOKEN; strcpy(bp->name, name); return (bp); } #if __STDC__ bucket *lookup(char *name) #else bucket *lookup(name) char *name; #endif { register bucket *bp, **bpp; bpp = symbol_table + hash(name); bp = *bpp; while (bp) { if (strcmp(name, bp->name) == 0) return (bp); bpp = &bp->link; bp = *bpp; } *bpp = bp = make_bucket(name); last_symbol->next = bp; last_symbol = bp; return (bp); } #if __STDC__ void create_symbol_table(void) #else void create_symbol_table() #endif { register int i; register bucket *bp; symbol_table = (bucket **) MALLOC(TABLE_SIZE*sizeof(bucket *)); for (i = 0; i < TABLE_SIZE; i++) symbol_table[i] = 0; bp = make_bucket("error"); bp->index = 1; bp->class = TERM; first_symbol = bp; last_symbol = bp; symbol_table[hash("error")] = bp; } #if __STDC__ void free_symbol_table(void) #else void free_symbol_table() #endif { FREE(symbol_table); symbol_table = 0; } #if __STDC__ void free_symbols(void) #else void free_symbols() #endif { register bucket *p, *q; for (p = first_symbol; p; p = q) { q = p->next; FREE(p); } } perl-byacc-2.0.orig/verbose.c100644 1750 1750 16620 5325706447 15010 0ustar bortzbortz#include "defs.h" static short *null_rules; static void log_unused _P_((void)); static void log_conflicts _P_((void)); static void print_state _P_((int state)); static void print_conflicts _P_((int state)); static void print_core _P_((int state)); static void print_nulls _P_((int state)); static void print_actions _P_((int stateno)); static void print_shifts _P_((register action *p)); static void print_reductions _P_((register action *p, register int defred)); static void print_gotos _P_((int stateno)); #if __STDC__ void verbose(void) #else void verbose() #endif { register int i; if (!vflag) return; null_rules = (short *) MALLOC(nrules*sizeof(short)); fprintf(verbose_file, "\f\n"); for (i = 0; i < nstates; i++) print_state(i); FREE(null_rules); if (nunused) log_unused(); if (SRtotal || RRtotal) log_conflicts(); fprintf(verbose_file, "\n\n%d terminals, %d nonterminals\n", ntokens, nvars); fprintf(verbose_file, "%d grammar rules, %d states\n", nrules - 2, nstates); } #if __STDC__ static void log_unused(void) #else static void log_unused() #endif { register int i; register short *p; fprintf(verbose_file, "\n\nRules never reduced:\n"); for (i = 3; i < nrules; ++i) { if (!rules_used[i]) { fprintf(verbose_file, "\t%s :", symbol_name[rlhs[i]]); for (p = ritem + rrhs[i]; *p >= 0; ++p) fprintf(verbose_file, " %s", symbol_name[*p]); fprintf(verbose_file, " (%d)\n", i - 2); } } } #if __STDC__ static void log_conflicts(void) #else static void log_conflicts() #endif { register int i; fprintf(verbose_file, "\n\n"); for (i = 0; i < nstates; i++) { if (SRconflicts[i] || RRconflicts[i]) { fprintf(verbose_file, "State %d contains ", i); if (SRconflicts[i] == 1) fprintf(verbose_file, "1 shift/reduce conflict"); else if (SRconflicts[i] > 1) fprintf(verbose_file, "%d shift/reduce conflicts", SRconflicts[i]); if (SRconflicts[i] && RRconflicts[i]) fprintf(verbose_file, ", "); if (RRconflicts[i] == 1) fprintf(verbose_file, "1 reduce/reduce conflict"); else if (RRconflicts[i] > 1) fprintf(verbose_file, "%d reduce/reduce conflicts", RRconflicts[i]); fprintf(verbose_file, ".\n"); } } } #if __STDC__ static void print_state(int state) #else static void print_state(state) int state; #endif { if (state) fprintf(verbose_file, "\n\n"); if (SRconflicts[state] || RRconflicts[state]) print_conflicts(state); fprintf(verbose_file, "state %d\n", state); print_core(state); print_nulls(state); print_actions(state); } #if __STDC__ static void print_conflicts(int state) #else static void print_conflicts(state) int state; #endif { register int symbol, act, number; register action *p; symbol = -1; for (p = parser[state]; p; p = p->next) { if (p->suppressed == 2) continue; if (p->symbol != symbol) { symbol = p->symbol; number = p->number; if (p->action_code == SHIFT) act = SHIFT; else act = REDUCE; } else if (p->suppressed == 1) { if (state == final_state && symbol == 0) { fprintf(verbose_file, "%d: shift/reduce conflict \ (accept, reduce %d) on $end\n", state, p->number - 2); } else { if (act == SHIFT) { fprintf(verbose_file, "%d: shift/reduce conflict \ (shift %d, reduce %d) on %s\n", state, number, p->number - 2, symbol_name[symbol]); } else { fprintf(verbose_file, "%d: reduce/reduce conflict \ (reduce %d, reduce %d) on %s\n", state, number - 2, p->number - 2, symbol_name[symbol]); } } } } } #if __STDC__ static void print_core(int state) #else static void print_core(state) int state; #endif { register int i; register int k; register int rule; register core *statep; register short *sp; register short *sp1; statep = state_table[state]; k = statep->nitems; for (i = 0; i < k; i++) { sp1 = sp = ritem + statep->items[i]; while (*sp >= 0) ++sp; rule = -(*sp); fprintf(verbose_file, "\t%s : ", symbol_name[rlhs[rule]]); for (sp = ritem + rrhs[rule]; sp < sp1; sp++) fprintf(verbose_file, "%s ", symbol_name[*sp]); putc('.', verbose_file); while (*sp >= 0) { fprintf(verbose_file, " %s", symbol_name[*sp]); sp++; } fprintf(verbose_file, " (%d)\n", -2 - *sp); } } #if __STDC__ static void print_nulls(int state) #else static void print_nulls(state) int state; #endif { register action *p; register int i, j, k, nnulls; nnulls = 0; for (p = parser[state]; p; p = p->next) { if (p->action_code == REDUCE && (p->suppressed == 0 || p->suppressed == 1)) { i = p->number; if (rrhs[i] + 1 == rrhs[i+1]) { for (j = 0; j < nnulls && i > null_rules[j]; ++j) continue; if (j == nnulls) { ++nnulls; null_rules[j] = i; } else if (i != null_rules[j]) { ++nnulls; for (k = nnulls - 1; k > j; --k) null_rules[k] = null_rules[k-1]; null_rules[j] = i; } } } } for (i = 0; i < nnulls; ++i) { j = null_rules[i]; fprintf(verbose_file, "\t%s : . (%d)\n", symbol_name[rlhs[j]], j - 2); } fprintf(verbose_file, "\n"); } #if __STDC__ static void print_actions(int stateno) #else static void print_actions(stateno) int stateno; #endif { register action *p; register shifts *sp; register int as; if (stateno == final_state) fprintf(verbose_file, "\t$end accept\n"); p = parser[stateno]; if (p) { print_shifts(p); print_reductions(p, defred[stateno]); } sp = shift_table[stateno]; if (sp && sp->nshifts > 0) { as = accessing_symbol[sp->shift[sp->nshifts - 1]]; if (ISVAR(as)) print_gotos(stateno); } } #if __STDC__ static void print_shifts(register action *p) #else static void print_shifts(p) register action *p; #endif { register int count; register action *q; count = 0; for (q = p; q; q = q->next) { if (q->suppressed < 2 && q->action_code == SHIFT) ++count; } if (count > 0) { for (; p; p = p->next) { if (p->action_code == SHIFT && p->suppressed == 0) fprintf(verbose_file, "\t%s shift %d\n", symbol_name[p->symbol], p->number); } } } #if __STDC__ static void print_reductions(register action *p, register int defred) #else static void print_reductions(p, defred) register action *p; register int defred; #endif { register int k, anyreds; register action *q; anyreds = 0; for (q = p; q ; q = q->next) { if (q->action_code == REDUCE && q->suppressed < 2) { anyreds = 1; break; } } if (anyreds == 0) fprintf(verbose_file, "\t. error\n"); else { for (; p; p = p->next) { if (p->action_code == REDUCE && p->number != defred) { k = p->number - 2; if (p->suppressed == 0) fprintf(verbose_file, "\t%s reduce %d\n", symbol_name[p->symbol], k); } } if (defred > 0) fprintf(verbose_file, "\t. reduce %d\n", defred - 2); } } #if __STDC__ static void print_gotos(int stateno) #else static void print_gotos(stateno) int stateno; #endif { register int i, k; register int as; register short *to_state; register shifts *sp; putc('\n', verbose_file); sp = shift_table[stateno]; to_state = sp->shift; for (i = 0; i < sp->nshifts; ++i) { k = to_state[i]; as = accessing_symbol[k]; if (ISVAR(as)) fprintf(verbose_file, "\t%s goto %d\n", symbol_name[as], k); } } perl-byacc-2.0.orig/warshall.c100644 1750 1750 2543 5325700442 15124 0ustar bortzbortz#include "defs.h" #if __STDC__ static void transitive_closure(unsigned *R, int n) #else static void transitive_closure(R, n) unsigned *R; int n; #endif { register int rowsize; register unsigned mask; register unsigned *rowj; register unsigned *rp; register unsigned *rend; register unsigned *ccol; register unsigned *relend; register unsigned *cword; register unsigned *rowi; rowsize = WORDSIZE(n); relend = R + n*rowsize; cword = R; mask = 1; rowi = R; while (rowi < relend) { ccol = cword; rowj = R; while (rowj < relend) { if (*ccol & mask) { rp = rowi; rend = rowj + rowsize; while (rowj < rend) *rowj++ |= *rp++; } else { rowj += rowsize; } ccol += rowsize; } mask <<= 1; if (mask == 0) { mask = 1; cword++; } rowi += rowsize; } } #if __STDC__ void reflexive_transitive_closure(unsigned *R, int n) #else void reflexive_transitive_closure(R, n) unsigned *R; int n; #endif { register int rowsize; register unsigned mask; register unsigned *rp; register unsigned *relend; transitive_closure(R, n); rowsize = WORDSIZE(n); relend = R + n*rowsize; mask = 1; rp = R; while (rp < relend) { *rp |= mask; mask <<= 1; if (mask == 0) { mask = 1; rp++; } rp += rowsize; } } perl-byacc-2.0.orig/yyerror.c100644 1750 1750 234 5325712216 14777 0ustar bortzbortz#include #if __STDC__ void yyerror(char *msg) #else void yyerror(msg) char *msg; #endif { (void) fprintf(stderr, "%s\n", msg); return; } perl-byacc-2.0.orig/README.SECOND100644 1750 1750 2174 5320137604 14774 0ustar bortzbortz 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 corbett@berkeley.edu Include a small example if possible. Please include the banner string from skeleton.c with the bug report. Do not expect rapid responses. perl-byacc-2.0.orig/man.page100644 1750 1750 13032 5326602435 14573 0ustar bortzbortz'\" t .\" %W% %R% (Berkeley) %E% .\" .TH BYACC 1 "January\ 18,\ 1993" .UC 6 .SH NAME byacc \- an LALR(1) parser generator .SH SYNOPSIS .B byacc [ -CPcdlrtv ] [ -b .I file_prefix .B ] [ -p .I symbol_prefix .B ] .I filename .SH DESCRIPTION .I byacc 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 written in the C or Perl programming languages. .I byacc normally writes the parse tables and the driver routine to the file .IR y.tab.c , using the C programming language. .PP The following options are available: .RS .TP \fB-b \fIfile_prefix\fP 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 .BR -C " or " -c Use the C programming language (default). .TP .B -d The \fB-d\fP option causes the header file .IR y.tab.h to be written (or .IR y.tab.ph , for Perl). .TP .B -l If the .B -l option is not specified, .I byacc will insert \#line directives in the generated code. The \#line directives let the C compiler relate errors in the generated code to the user's original code. If the \fB-l\fP option is specified, .I byacc will not insert the \#line directives. \&\#line directives specified by the user will be retained. .TP \fB-p \fIsymbol_prefix\fP Change the prefix in symbols in the generated code to the string denoted by \fIsymbol_prefix\fP rather than the default of "\fIyy\fP". Only symbols generated by \fIbyacc\fP are affected. Symbols in the definition and user subroutine sections are not changed. .IP The \fIsymbol_prefix\fP can contain upper or lower case letters, digits, or _ (underline or underscore). It must start with either an underline or a letter and must contain at least one lower case letter. .IP All lower case letters in the symbol prefix will be converted to upper case letters when defined values or typedefs are generated. .IP For example, if '\fB-p\fP ftp_' is specifed on the \fIbyacc\fP command line: .in +.5i .TS tab (/) box; a | a . old symbol/new symbol = YYABORT/FTP_ABORT YYACCEPT/FTP_ACCEPT YYBYACC/FTP_BYACC YYDEBUG/FTP_DEBUG YYSTYPE/FTP_STYPE yyabort/ftp_abort yyerrok/ftp_errok yylex/ftp_lex yylval/ftp_lval yyparse/ftp_parse .TE .in -.5i Note: The above list is not complete. .TP .B -P Use the Perl programming language. The output files have extensions .I .tab.pl and .IR .tab.ph . .TP .B -r The .B -r option causes .I byacc to produce separate files for code and tables. The code file is named .IR y.code.c, and the tables file is named .IR y.tab.c. In Perl mode, the file name extension is .IR .pl , but the use of this option is not recommended. .TP .B -t The .B -t option changes the preprocessor directives generated by \fIbyacc\fP so that debugging statements will 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 . .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. .PP In C mode, the user's code at the end of the .SM BYACC file is inserted before the .I yyparse subroutine, but in Perl mode, it is appended to .I yyparse so it can contain the main program. In Perl mode, there is no library, so the user must supply the .I yyerror and .I yylex subroutines and a main program that calls .IR yyparse . For example: .sp .RS .nf %% .I ...grammar... %% sub yyerror { print STDERR "$.: $@\en"; } sub yylex { ... } exit &yyparse; .fi .RE .SH FILES .PD 0 .TP 12 .B y.code.c output parser code in C .TP .B y.tab.c output parser code and tables in C or, if .I \-r switch specified, output parser tables in C .TP .B y.tab.h defines for token names and, if .I %union used in grammar, the union definition for C parsers .TP .B y.code.pl output parser code in PERL .TP .B y.tab.pl output parser code and tables in PERL or, if .I -r switch specified, output parser tables in PERL .TP .B y.tab.ph PERL assignment statements for token names .TP .B y.output description of parser states, state transitions, and conflicts .TP .BR /tmp/byacc.aXXXXXX ",\ " /tmp/byacc.tXXXXXX ",\ " /tmp/byacc.uXXXXXX temporary files .TP .B LIB_DEST/LIBRARY library containing simple versions of .I main(\|) (calls .I yyparse(\|) then exits) and .I yyerror(\|) (prints message to .B stderr then returns) .PD .SH "SEE ALSO" .BR flex "(1),\ " lex (1) .LP .I "Yacc: Yet Another Compiler-Compiler" .br Stephen C. Johnson .br Originally (?) published as Comp. Sci. Tech. Rep. No. 32. Bell Laboratories, July 1975. Reprinted in many different places. .LP .I "Introduction to Compiler Construction with UNIX" .br Axel T. Schreiner and H. George Friedman, Jr. .br Prentice Hall, 1985. .LP .I "lex & yacc, Second Edition" .br John R. Levine, Tony Mason, and Doug Brown .br O'Reilly & Associates, Inc., 1992. .in +.5i Possibly the best book yet on lex and yacc. (My opinion only. Others may disagree. - Rick Ohnemus) .in -.5i .LP .I "comp.compilers monthly message and Frequently Asked Questions" .br Posted monthly in comp.compilers and news.answers USENET newsgroups. .SH DIAGNOSTICS If there are rules that are never reduced, the number of such rules is reported on standard error. .LP If there are any LALR(1) conflicts, the number of conflicts is reported on standard error. .SH RESTRICTIONS A symbol prefix specified using the \fB-p\fP switch must contain at least one lower case character. This is to allow a distinction between variables, defined values, and typedefs. .SH BUGS perl-byacc-2.0.orig/Makefile100644 1750 1750 6670 5326600110 14600 0ustar bortzbortz# where to install program DEST = /usr/local/bin # where to install library LIB_DEST = /usr/local/lib HDRS = defs.h # uncomment the next line if your system does not have strrchr() #RINDEX = -Dstrrchr=rindex # the name of the final executable PROGRAM = byacc LIBRARY = libby.a RANLIB = ranlib #RANLIB = true # set SIG_TYPE to the type of pointer signal() returns SIG_TYPE = void #SIG_TYPE = char CPPFLAGS = $(RINDEX) -DPROGRAM=\"$(PROGRAM)\" -DSIG_TYPE=$(SIG_TYPE) CFLAGS = -O $(CPPFLAGS) #CC = gcc -Wall CPP = /lib/cpp LDFLAGS = LIBS = LINKER = $(CC) MAKEFILE = Makefile OBJS = \ closure.o \ error.o \ lalr.o \ lr0.o \ main.o \ mkpar.o \ output.o \ reader.o \ skeleton.o \ symtab.o \ verbose.o \ warshall.o LIB_OBJS = yyerror.o \ yymain.o PRINT = pr -f -l88 SRCS = closure.c \ error.c \ lalr.c \ lr0.c \ main.c \ mkpar.c \ output.c \ reader.c \ skeleton.c \ symtab.c \ verbose.c \ warshall.c all: $(PROGRAM) $(PROGRAM).man $(LIBRARY) $(LIBRARY): $(LIB_OBJS) ar rv $(LIBRARY) $(LIB_OBJS) $(RANLIB) $(LIBRARY) $(PROGRAM): $(OBJS) $(LIBS) @echo -n "Loading $(PROGRAM) ... " @$(LINKER) $(LDFLAGS) -o $(PROGRAM) $(OBJS) $(LIBS) @echo "done" cc_src: #load $(RINDEX) -DPROGRAM="$(PROGRAM)" -DSIG_TYPE=$(SIG_TYPE) \ $(SRCS) #link clean: rm -f $(OBJS) $(LIB_OBJS) *~ core .purify* purify* rm -f $(MAKEFILE).bak clobber: clean rm -f $(PROGRAM) $(LIBRARY) depend: sed -n -e '1,/^### DO NOT DELETE THIS LINE/p' < $(MAKEFILE) \ | sed -e '/^### DO NOT DELETE THIS LINE/d' > $(MAKEFILE).new echo "### DO NOT DELETE THIS LINE - make depend needs it" >> $(MAKEFILE).new echo >> $(MAKEFILE).new for fl in $(SRCS) $(DEBUG_SRCS) ; \ do \ $(CPP) $(CPPFLAGS) -M $$fl | grep -v ': /usr/include/' >> $(MAKEFILE).new ; \ echo >> $(MAKEFILE).new ; \ done mv $(MAKEFILE) $(MAKEFILE).bak mv $(MAKEFILE).new $(MAKEFILE) index: @ctags -wx $(HDRS) $(SRCS) install: $(PROGRAM) $(LIBRARY) @echo Installing $(PROGRAM) in $(DEST) @install -s $(PROGRAM) $(DEST) @echo Installing $(LIBRARY) in $(LIB_DEST) @cp $(LIBRARY) $(LIB_DEST)/$(LIBRARY) @$(RANLIB) $(LIB_DEST)/$(LIBRARY) library: $(LIBRARY) listing: @$(PRINT) Makefile $(HDRS) $(SRCS) | lpr lint: @lint $(CPPFLAGS) $(SRCS) $(PROGRAM).man: man.page $(MAKEFILE) sed -e "s/byacc/$(PROGRAM)/" \ -e "s/ BYACC/ `echo $(PROGRAM) | tr '[a-z]' '[A-Z]'`/" \ -e "s?LIB_DEST?$(LIB_DEST)?" \ -e "s/LIBRARY/$(LIBRARY)/" \ < man.page > $(PROGRAM).man program: $(PROGRAM) purify: $(OBJS) $(LIBS) @purify $(LINKER) $(LDFLAGS) -o $(PROGRAM) $(OBJS) $(LIBS) tags: $(HDRS) $(SRCS) @ctags $(HDRS) $(SRCS) tests: $(PROGRAM) -mkdir t cp test/*.y test/Makefile t (cd t; $(MAKE) PROGRAM=$(PROGRAM)) diff -r test t rm -fr t ### DO NOT DELETE THIS LINE - make depend needs it closure.o: closure.c closure.o: ./defs.h error.o: error.c error.o: ./defs.h lalr.o: lalr.c lalr.o: ./defs.h lr0.o: lr0.c lr0.o: ./defs.h main.o: main.c main.o: ./defs.h mkpar.o: mkpar.c mkpar.o: ./defs.h output.o: output.c output.o: ./defs.h reader.o: reader.c reader.o: ./defs.h skeleton.o: skeleton.c skeleton.o: ./defs.h symtab.o: symtab.c symtab.o: ./defs.h verbose.o: verbose.c verbose.o: ./defs.h warshall.o: warshall.c warshall.o: ./defs.h perl-byacc-2.0.orig/byacc.man100644 1750 1750 13040 5326602450 14734 0ustar bortzbortz'\" t .\" %W% %R% (Berkeley) %E% .\" .TH BYACC 1 "January\ 18,\ 1993" .UC 6 .SH NAME byacc \- an LALR(1) parser generator .SH SYNOPSIS .B byacc [ -CPcdlrtv ] [ -b .I file_prefix .B ] [ -p .I symbol_prefix .B ] .I filename .SH DESCRIPTION .I byacc 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 written in the C or Perl programming languages. .I byacc normally writes the parse tables and the driver routine to the file .IR y.tab.c , using the C programming language. .PP The following options are available: .RS .TP \fB-b \fIfile_prefix\fP 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 .BR -C " or " -c Use the C programming language (default). .TP .B -d The \fB-d\fP option causes the header file .IR y.tab.h to be written (or .IR y.tab.ph , for Perl). .TP .B -l If the .B -l option is not specified, .I byacc will insert \#line directives in the generated code. The \#line directives let the C compiler relate errors in the generated code to the user's original code. If the \fB-l\fP option is specified, .I byacc will not insert the \#line directives. \&\#line directives specified by the user will be retained. .TP \fB-p \fIsymbol_prefix\fP Change the prefix in symbols in the generated code to the string denoted by \fIsymbol_prefix\fP rather than the default of "\fIyy\fP". Only symbols generated by \fIbyacc\fP are affected. Symbols in the definition and user subroutine sections are not changed. .IP The \fIsymbol_prefix\fP can contain upper or lower case letters, digits, or _ (underline or underscore). It must start with either an underline or a letter and must contain at least one lower case letter. .IP All lower case letters in the symbol prefix will be converted to upper case letters when defined values or typedefs are generated. .IP For example, if '\fB-p\fP ftp_' is specifed on the \fIbyacc\fP command line: .in +.5i .TS tab (/) box; a | a . old symbol/new symbol = YYABORT/FTP_ABORT YYACCEPT/FTP_ACCEPT YYBYACC/FTP_BYACC YYDEBUG/FTP_DEBUG YYSTYPE/FTP_STYPE yyabort/ftp_abort yyerrok/ftp_errok yylex/ftp_lex yylval/ftp_lval yyparse/ftp_parse .TE .in -.5i Note: The above list is not complete. .TP .B -P Use the Perl programming language. The output files have extensions .I .tab.pl and .IR .tab.ph . .TP .B -r The .B -r option causes .I byacc to produce separate files for code and tables. The code file is named .IR y.code.c, and the tables file is named .IR y.tab.c. In Perl mode, the file name extension is .IR .pl , but the use of this option is not recommended. .TP .B -t The .B -t option changes the preprocessor directives generated by \fIbyacc\fP so that debugging statements will 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 . .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. .PP In C mode, the user's code at the end of the .SM BYACC file is inserted before the .I yyparse subroutine, but in Perl mode, it is appended to .I yyparse so it can contain the main program. In Perl mode, there is no library, so the user must supply the .I yyerror and .I yylex subroutines and a main program that calls .IR yyparse . For example: .sp .RS .nf %% .I ...grammar... %% sub yyerror { print STDERR "$.: $@\en"; } sub yylex { ... } exit &yyparse; .fi .RE .SH FILES .PD 0 .TP 12 .B y.code.c output parser code in C .TP .B y.tab.c output parser code and tables in C or, if .I \-r switch specified, output parser tables in C .TP .B y.tab.h defines for token names and, if .I %union used in grammar, the union definition for C parsers .TP .B y.code.pl output parser code in PERL .TP .B y.tab.pl output parser code and tables in PERL or, if .I -r switch specified, output parser tables in PERL .TP .B y.tab.ph PERL assignment statements for token names .TP .B y.output description of parser states, state transitions, and conflicts .TP .BR /tmp/byacc.aXXXXXX ",\ " /tmp/byacc.tXXXXXX ",\ " /tmp/byacc.uXXXXXX temporary files .TP .B /usr/local/lib/libby.a library containing simple versions of .I main(\|) (calls .I yyparse(\|) then exits) and .I yyerror(\|) (prints message to .B stderr then returns) .PD .SH "SEE ALSO" .BR flex "(1),\ " lex (1) .LP .I "Yacc: Yet Another Compiler-Compiler" .br Stephen C. Johnson .br Originally (?) published as Comp. Sci. Tech. Rep. No. 32. Bell Laboratories, July 1975. Reprinted in many different places. .LP .I "Introduction to Compiler Construction with UNIX" .br Axel T. Schreiner and H. George Friedman, Jr. .br Prentice Hall, 1985. .LP .I "lex & yacc, Second Edition" .br John R. Levine, Tony Mason, and Doug Brown .br O'Reilly & Associates, Inc., 1992. .in +.5i Possibly the best book yet on lex and yacc. (My opinion only. Others may disagree. - Rick Ohnemus) .in -.5i .LP .I "comp.compilers monthly message and Frequently Asked Questions" .br Posted monthly in comp.compilers and news.answers USENET newsgroups. .SH DIAGNOSTICS If there are rules that are never reduced, the number of such rules is reported on standard error. .LP If there are any LALR(1) conflicts, the number of conflicts is reported on standard error. .SH RESTRICTIONS A symbol prefix specified using the \fB-p\fP switch must contain at least one lower case character. This is to allow a distinction between variables, defined values, and typedefs. .SH BUGS perl-byacc-2.0.orig/yymain.c100644 1750 1750 367 5325700445 14602 0ustar bortzbortz#if __STDC__ #include int main(int argc, char *argv[]) #else int main(argc, argv) int argc; char *argv[]; #endif { #if __STDC__ extern int yyparse(void); #else extern int yyparse(); #endif (void) yyparse(); exit(0); } perl-byacc-2.0.orig/README.FIRST100644 1750 1750 4370 5325703214 14711 0ustar bortzbortz - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - The '-p' option (generate PERL code) has been changed to '-P'. This is for compatibility with versions of yacc that use '-p' to specify a new prefix for generated symbols. Also, be sure to edit the Makefile. It has changed a bit since 1.8.1 With that out of the way... The '-p' option is now used to change the prefix of generated symbols to something other than the default of "yy". See the man page for further details. I apologize for breaking any makefiles but, I believe that '-p' for prefix changing has been around longer than '-p' for generating PERL. This has been compiled and tested on: Amiga 3000 with AmigaDOS 2.1 and SAS C 6.1 SUN SPARC systems running SunOS 4.1_PSR_A and 4.1.[123] with the bundled compiler, gcc 2.3.3, and clcc Any modifications to make it more portable are welcome. Please report any bugs to rick@IMD.Sterling.COM Change History for PERL Berkeley yacc: 1.8 first version of Berkeley yacc 1.8 with PERL support 1.8.1 reformatted Makefile add warning about '-r' option with PERL code generation escape '$' in state name table in PERL code updated PERL version of getdate.y in test directory replace a hard coded value of 13 in reader.c with 'sizeof("$end") + sizeof("$accept")' (let the compiler figure out the size) 1.8.2 changed '-p' (PERL) switch to '-P' added '-p prefix' switch to allow changing symbol prefix in generated code fixed small memory leak in copy_action function in reader.c base the name of temporary files on the program name (PROGRAM variable in Makefile) instead of always using a prefix of 'yacc' out of memory checks now take place in only 3 functions instead of all over the place (added my_calloc, my_malloc, and my_realloc functions) added manpage rule to Makefile that generates a manual page for the name in the Makefile variable PROGRAM. (see Makefile for further details) added tests rule to Makefile that runs the new yacc program on the yacc files in the test directory and compares the output to the files in the test directory added Makefile to test directory updated PERL version of getdate.y in test directory ported to the AMIGA using SAS C 6.1 added library that contains main() and yyerror() perl-byacc-2.0.orig/Makefile.unix100644 1750 1750 6670 5326600606 15574 0ustar bortzbortz# where to install program DEST = /usr/local/bin # where to install library LIB_DEST = /usr/local/lib HDRS = defs.h # uncomment the next line if your system does not have strrchr() #RINDEX = -Dstrrchr=rindex # the name of the final executable PROGRAM = byacc LIBRARY = libby.a RANLIB = ranlib #RANLIB = true # set SIG_TYPE to the type of pointer signal() returns SIG_TYPE = void #SIG_TYPE = char CPPFLAGS = $(RINDEX) -DPROGRAM=\"$(PROGRAM)\" -DSIG_TYPE=$(SIG_TYPE) CFLAGS = -O $(CPPFLAGS) #CC = gcc -Wall CPP = /lib/cpp LDFLAGS = LIBS = LINKER = $(CC) MAKEFILE = Makefile OBJS = \ closure.o \ error.o \ lalr.o \ lr0.o \ main.o \ mkpar.o \ output.o \ reader.o \ skeleton.o \ symtab.o \ verbose.o \ warshall.o LIB_OBJS = yyerror.o \ yymain.o PRINT = pr -f -l88 SRCS = closure.c \ error.c \ lalr.c \ lr0.c \ main.c \ mkpar.c \ output.c \ reader.c \ skeleton.c \ symtab.c \ verbose.c \ warshall.c all: $(PROGRAM) $(PROGRAM).man $(LIBRARY) $(LIBRARY): $(LIB_OBJS) ar rv $(LIBRARY) $(LIB_OBJS) $(RANLIB) $(LIBRARY) $(PROGRAM): $(OBJS) $(LIBS) @echo -n "Loading $(PROGRAM) ... " @$(LINKER) $(LDFLAGS) -o $(PROGRAM) $(OBJS) $(LIBS) @echo "done" cc_src: #load $(RINDEX) -DPROGRAM="$(PROGRAM)" -DSIG_TYPE=$(SIG_TYPE) \ $(SRCS) #link clean: rm -f $(OBJS) $(LIB_OBJS) *~ core .purify* purify* rm -f $(MAKEFILE).bak clobber: clean rm -f $(PROGRAM) $(LIBRARY) depend: sed -n -e '1,/^### DO NOT DELETE THIS LINE/p' < $(MAKEFILE) \ | sed -e '/^### DO NOT DELETE THIS LINE/d' > $(MAKEFILE).new echo "### DO NOT DELETE THIS LINE - make depend needs it" >> $(MAKEFILE).new echo >> $(MAKEFILE).new for fl in $(SRCS) $(DEBUG_SRCS) ; \ do \ $(CPP) $(CPPFLAGS) -M $$fl | grep -v ': /usr/include/' >> $(MAKEFILE).new ; \ echo >> $(MAKEFILE).new ; \ done mv $(MAKEFILE) $(MAKEFILE).bak mv $(MAKEFILE).new $(MAKEFILE) index: @ctags -wx $(HDRS) $(SRCS) install: $(PROGRAM) $(LIBRARY) @echo Installing $(PROGRAM) in $(DEST) @install -s $(PROGRAM) $(DEST) @echo Installing $(LIBRARY) in $(LIB_DEST) @cp $(LIBRARY) $(LIB_DEST)/$(LIBRARY) @$(RANLIB) $(LIB_DEST)/$(LIBRARY) library: $(LIBRARY) listing: @$(PRINT) Makefile $(HDRS) $(SRCS) | lpr lint: @lint $(CPPFLAGS) $(SRCS) $(PROGRAM).man: man.page $(MAKEFILE) sed -e "s/byacc/$(PROGRAM)/" \ -e "s/ BYACC/ `echo $(PROGRAM) | tr '[a-z]' '[A-Z]'`/" \ -e "s?LIB_DEST?$(LIB_DEST)?" \ -e "s/LIBRARY/$(LIBRARY)/" \ < man.page > $(PROGRAM).man program: $(PROGRAM) purify: $(OBJS) $(LIBS) @purify $(LINKER) $(LDFLAGS) -o $(PROGRAM) $(OBJS) $(LIBS) tags: $(HDRS) $(SRCS) @ctags $(HDRS) $(SRCS) tests: $(PROGRAM) -mkdir t cp test/*.y test/Makefile t (cd t; $(MAKE) PROGRAM=$(PROGRAM)) diff -r test t rm -fr t ### DO NOT DELETE THIS LINE - make depend needs it closure.o: closure.c closure.o: ./defs.h error.o: error.c error.o: ./defs.h lalr.o: lalr.c lalr.o: ./defs.h lr0.o: lr0.c lr0.o: ./defs.h main.o: main.c main.o: ./defs.h mkpar.o: mkpar.c mkpar.o: ./defs.h output.o: output.c output.o: ./defs.h reader.o: reader.c reader.o: ./defs.h skeleton.o: skeleton.c skeleton.o: ./defs.h symtab.o: symtab.c symtab.o: ./defs.h verbose.o: verbose.c verbose.o: ./defs.h warshall.o: warshall.c warshall.o: ./defs.h perl-byacc-2.0.orig/test/ 40755 1750 1750 0 5347367537 14043 5ustar bortzbortzperl-byacc-2.0.orig/test/error.y100644 1750 1750 165 5224473062 15426 0ustar bortzbortz%% S: error %% main(){printf("yyparse() = %d\n",yyparse());} yylex(){return-1;} yyerror(s)char*s;{printf("%s\n",s);} perl-byacc-2.0.orig/test/ftp.y100644 1750 1750 54736 5320423222 15131 0ustar bortzbortz/* * Copyright (c) 1985, 1988 Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms are permitted * provided that the above copyright notice and this paragraph are * duplicated in all such forms and that any documentation, * advertising materials, and other materials related to such * distribution and use acknowledge that the software was developed * by the University of California, Berkeley. The name of the * University may not be used to endorse or promote products derived * from this software without specific prior written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * @(#)ftpcmd.y 5.20.1.1 (Berkeley) 3/2/89 */ /* * Grammar for FTP commands. * See RFC 959. */ %{ #ifndef lint static char sccsid[] = "@(#)ftpcmd.y 5.20.1.1 (Berkeley) 3/2/89"; #endif /* not lint */ #include #include #include #include #include #include #include #include #include #include #include #include extern struct sockaddr_in data_dest; extern int logged_in; extern struct passwd *pw; extern int guest; extern int logging; extern int type; extern int form; extern int debug; extern int timeout; extern int maxtimeout; extern int pdata; extern char hostname[], remotehost[]; extern char proctitle[]; extern char *globerr; extern int usedefault; extern int transflag; extern char tmpline[]; char **glob(); static int cmd_type; static int cmd_form; static int cmd_bytesz; char cbuf[512]; char *fromname; char *index(); %} %token A B C E F I L N P R S T SP CRLF COMMA STRING NUMBER USER PASS ACCT REIN QUIT PORT PASV TYPE STRU MODE RETR STOR APPE MLFL MAIL MSND MSOM MSAM MRSQ MRCP ALLO REST RNFR RNTO ABOR DELE CWD LIST NLST SITE STAT HELP NOOP MKD RMD PWD CDUP STOU SMNT SYST SIZE MDTM UMASK IDLE CHMOD LEXERR %start cmd_list %% cmd_list: /* empty */ | cmd_list cmd = { fromname = (char *) 0; } | cmd_list rcmd ; cmd: USER SP username CRLF = { user((char *) $3); free((char *) $3); } | PASS SP password CRLF = { pass((char *) $3); free((char *) $3); } | PORT SP host_port CRLF = { usedefault = 0; if (pdata >= 0) { (void) close(pdata); pdata = -1; } reply(200, "PORT command successful."); } | PASV CRLF = { passive(); } | TYPE SP type_code CRLF = { switch (cmd_type) { case TYPE_A: if (cmd_form == FORM_N) { reply(200, "Type set to A."); type = cmd_type; form = cmd_form; } else reply(504, "Form must be N."); break; case TYPE_E: reply(504, "Type E not implemented."); break; case TYPE_I: reply(200, "Type set to I."); type = cmd_type; break; case TYPE_L: #if NBBY == 8 if (cmd_bytesz == 8) { reply(200, "Type set to L (byte size 8)."); type = cmd_type; } else reply(504, "Byte size must be 8."); #else /* NBBY == 8 */ UNIMPLEMENTED for NBBY != 8 #endif /* NBBY == 8 */ } } | STRU SP struct_code CRLF = { switch ($3) { case STRU_F: reply(200, "STRU F ok."); break; default: reply(504, "Unimplemented STRU type."); } } | MODE SP mode_code CRLF = { switch ($3) { case MODE_S: reply(200, "MODE S ok."); break; default: reply(502, "Unimplemented MODE type."); } } | ALLO SP NUMBER CRLF = { reply(202, "ALLO command ignored."); } | ALLO SP NUMBER SP R SP NUMBER CRLF = { reply(202, "ALLO command ignored."); } | RETR check_login SP pathname CRLF = { if ($2 && $4 != NULL) retrieve((char *) 0, (char *) $4); if ($4 != NULL) free((char *) $4); } | STOR check_login SP pathname CRLF = { if ($2 && $4 != NULL) store((char *) $4, "w", 0); if ($4 != NULL) free((char *) $4); } | APPE check_login SP pathname CRLF = { if ($2 && $4 != NULL) store((char *) $4, "a", 0); if ($4 != NULL) free((char *) $4); } | NLST check_login CRLF = { if ($2) send_file_list("."); } | NLST check_login SP STRING CRLF = { if ($2 && $4 != NULL) send_file_list((char *) $4); if ($4 != NULL) free((char *) $4); } | LIST check_login CRLF = { if ($2) retrieve("/bin/ls -lgA", ""); } | LIST check_login SP pathname CRLF = { if ($2 && $4 != NULL) retrieve("/bin/ls -lgA %s", (char *) $4); if ($4 != NULL) free((char *) $4); } | STAT check_login SP pathname CRLF = { if ($2 && $4 != NULL) statfilecmd((char *) $4); if ($4 != NULL) free((char *) $4); } | STAT CRLF = { statcmd(); } | DELE check_login SP pathname CRLF = { if ($2 && $4 != NULL) delete((char *) $4); if ($4 != NULL) free((char *) $4); } | RNTO SP pathname CRLF = { if (fromname) { renamecmd(fromname, (char *) $3); free(fromname); fromname = (char *) 0; } else { reply(503, "Bad sequence of commands."); } free((char *) $3); } | ABOR CRLF = { reply(225, "ABOR command successful."); } | CWD check_login CRLF = { if ($2) cwd(pw->pw_dir); } | CWD check_login SP pathname CRLF = { if ($2 && $4 != NULL) cwd((char *) $4); if ($4 != NULL) free((char *) $4); } | HELP CRLF = { help(cmdtab, (char *) 0); } | HELP SP STRING CRLF = { register char *cp = (char *)$3; if (strncasecmp(cp, "SITE", 4) == 0) { cp = (char *)$3 + 4; if (*cp == ' ') cp++; if (*cp) help(sitetab, cp); else help(sitetab, (char *) 0); } else help(cmdtab, (char *) $3); } | NOOP CRLF = { reply(200, "NOOP command successful."); } | MKD check_login SP pathname CRLF = { if ($2 && $4 != NULL) makedir((char *) $4); if ($4 != NULL) free((char *) $4); } | RMD check_login SP pathname CRLF = { if ($2 && $4 != NULL) removedir((char *) $4); if ($4 != NULL) free((char *) $4); } | PWD check_login CRLF = { if ($2) pwd(); } | CDUP check_login CRLF = { if ($2) cwd(".."); } | SITE SP HELP CRLF = { help(sitetab, (char *) 0); } | SITE SP HELP SP STRING CRLF = { help(sitetab, (char *) $5); } | SITE SP UMASK check_login CRLF = { int oldmask; if ($4) { oldmask = umask(0); (void) umask(oldmask); reply(200, "Current UMASK is %03o", oldmask); } } | SITE SP UMASK check_login SP octal_number CRLF = { int oldmask; if ($4) { if (($6 == -1) || ($6 > 0777)) { reply(501, "Bad UMASK value"); } else { oldmask = umask($6); reply(200, "UMASK set to %03o (was %03o)", $6, oldmask); } } } | SITE SP CHMOD check_login SP octal_number SP pathname CRLF = { if ($4 && ($8 != NULL)) { if ($6 > 0777) reply(501, "CHMOD: Mode value must be between 0 and 0777"); else if (chmod((char *) $8, $6) < 0) perror_reply(550, (char *) $8); else reply(200, "CHMOD command successful."); } if ($8 != NULL) free((char *) $8); } | SITE SP IDLE CRLF = { reply(200, "Current IDLE time limit is %d seconds; max %d", timeout, maxtimeout); } | SITE SP IDLE SP NUMBER CRLF = { if ($5 < 30 || $5 > maxtimeout) { reply(501, "Maximum IDLE time must be between 30 and %d seconds", maxtimeout); } else { timeout = $5; (void) alarm((unsigned) timeout); reply(200, "Maximum IDLE time set to %d seconds", timeout); } } | STOU check_login SP pathname CRLF = { if ($2 && $4 != NULL) store((char *) $4, "w", 1); if ($4 != NULL) free((char *) $4); } | SYST CRLF = { #ifdef unix #ifdef BSD reply(215, "UNIX Type: L%d Version: BSD-%d", NBBY, BSD); #else /* BSD */ reply(215, "UNIX Type: L%d", NBBY); #endif /* BSD */ #else /* unix */ reply(215, "UNKNOWN Type: L%d", NBBY); #endif /* unix */ } /* * SIZE is not in RFC959, but Postel has blessed it and * it will be in the updated RFC. * * Return size of file in a format suitable for * using with RESTART (we just count bytes). */ | SIZE check_login SP pathname CRLF = { if ($2 && $4 != NULL) sizecmd((char *) $4); if ($4 != NULL) free((char *) $4); } /* * MDTM is not in RFC959, but Postel has blessed it and * it will be in the updated RFC. * * Return modification time of file as an ISO 3307 * style time. E.g. YYYYMMDDHHMMSS or YYYYMMDDHHMMSS.xxx * where xxx is the fractional second (of any precision, * not necessarily 3 digits) */ | MDTM check_login SP pathname CRLF = { if ($2 && $4 != NULL) { struct stat stbuf; if (stat((char *) $4, &stbuf) < 0) perror_reply(550, "%s", (char *) $4); else if ((stbuf.st_mode&S_IFMT) != S_IFREG) { reply(550, "%s: not a plain file.", (char *) $4); } else { register struct tm *t; struct tm *gmtime(); t = gmtime(&stbuf.st_mtime); reply(213, "19%02d%02d%02d%02d%02d%02d", t->tm_year, t->tm_mon+1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec); } } if ($4 != NULL) free((char *) $4); } | QUIT CRLF = { reply(221, "Goodbye."); dologout(0); } | error CRLF = { ftperrok; } ; rcmd: RNFR check_login SP pathname CRLF = { char *renamefrom(); if ($2 && $4) { fromname = renamefrom((char *) $4); if (fromname == (char *) 0 && $4) { free((char *) $4); } } } ; username: STRING ; password: /* empty */ = { *(char **)&($$) = ""; } | STRING ; byte_size: NUMBER ; host_port: NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER = { register char *a, *p; a = (char *)&data_dest.sin_addr; a[0] = $1; a[1] = $3; a[2] = $5; a[3] = $7; p = (char *)&data_dest.sin_port; p[0] = $9; p[1] = $11; data_dest.sin_family = AF_INET; } ; form_code: N = { $$ = FORM_N; } | T = { $$ = FORM_T; } | C = { $$ = FORM_C; } ; type_code: A = { cmd_type = TYPE_A; cmd_form = FORM_N; } | A SP form_code = { cmd_type = TYPE_A; cmd_form = $3; } | E = { cmd_type = TYPE_E; cmd_form = FORM_N; } | E SP form_code = { cmd_type = TYPE_E; cmd_form = $3; } | I = { cmd_type = TYPE_I; } | L = { cmd_type = TYPE_L; cmd_bytesz = NBBY; } | L SP byte_size = { cmd_type = TYPE_L; cmd_bytesz = $3; } /* this is for a bug in the BBN ftp */ | L byte_size = { cmd_type = TYPE_L; cmd_bytesz = $2; } ; struct_code: F = { $$ = STRU_F; } | R = { $$ = STRU_R; } | P = { $$ = STRU_P; } ; mode_code: S = { $$ = MODE_S; } | B = { $$ = MODE_B; } | C = { $$ = MODE_C; } ; pathname: pathstring = { /* * Problem: this production is used for all pathname * processing, but only gives a 550 error reply. * This is a valid reply in some cases but not in others. */ if (logged_in && $1 && strncmp((char *) $1, "~", 1) == 0) { *(char **)&($$) = *glob((char *) $1); if (globerr != NULL) { reply(550, globerr); $$ = NULL; } free((char *) $1); } else $$ = $1; } ; pathstring: STRING ; octal_number: NUMBER = { register int ret, dec, multby, digit; /* * Convert a number that was read as decimal number * to what it would be if it had been read as octal. */ dec = $1; multby = 1; ret = 0; while (dec) { digit = dec%10; if (digit > 7) { ret = -1; break; } ret += digit * multby; multby *= 8; dec /= 10; } $$ = ret; } ; check_login: /* empty */ = { if (logged_in) $$ = 1; else { reply(530, "Please login with USER and PASS."); $$ = 0; } } ; %% extern jmp_buf errcatch; #define CMD 0 /* beginning of command */ #define ARGS 1 /* expect miscellaneous arguments */ #define STR1 2 /* expect SP followed by STRING */ #define STR2 3 /* expect STRING */ #define OSTR 4 /* optional SP then STRING */ #define ZSTR1 5 /* SP then optional STRING */ #define ZSTR2 6 /* optional STRING after SP */ #define SITECMD 7 /* SITE command */ #define NSTR 8 /* Number followed by a string */ struct tab { char *name; short token; short state; short implemented; /* 1 if command is implemented */ char *help; }; struct tab cmdtab[] = { /* In order defined in RFC 765 */ { "USER", USER, STR1, 1, " username" }, { "PASS", PASS, ZSTR1, 1, " password" }, { "ACCT", ACCT, STR1, 0, "(specify account)" }, { "SMNT", SMNT, ARGS, 0, "(structure mount)" }, { "REIN", REIN, ARGS, 0, "(reinitialize server state)" }, { "QUIT", QUIT, ARGS, 1, "(terminate service)", }, { "PORT", PORT, ARGS, 1, " b0, b1, b2, b3, b4" }, { "PASV", PASV, ARGS, 1, "(set server in passive mode)" }, { "TYPE", TYPE, ARGS, 1, " [ A | E | I | L ]" }, { "STRU", STRU, ARGS, 1, "(specify file structure)" }, { "MODE", MODE, ARGS, 1, "(specify transfer mode)" }, { "RETR", RETR, STR1, 1, " file-name" }, { "STOR", STOR, STR1, 1, " file-name" }, { "APPE", APPE, STR1, 1, " file-name" }, { "MLFL", MLFL, OSTR, 0, "(mail file)" }, { "MAIL", MAIL, OSTR, 0, "(mail to user)" }, { "MSND", MSND, OSTR, 0, "(mail send to terminal)" }, { "MSOM", MSOM, OSTR, 0, "(mail send to terminal or mailbox)" }, { "MSAM", MSAM, OSTR, 0, "(mail send to terminal and mailbox)" }, { "MRSQ", MRSQ, OSTR, 0, "(mail recipient scheme question)" }, { "MRCP", MRCP, STR1, 0, "(mail recipient)" }, { "ALLO", ALLO, ARGS, 1, "allocate storage (vacuously)" }, { "REST", REST, ARGS, 0, "(restart command)" }, { "RNFR", RNFR, STR1, 1, " file-name" }, { "RNTO", RNTO, STR1, 1, " file-name" }, { "ABOR", ABOR, ARGS, 1, "(abort operation)" }, { "DELE", DELE, STR1, 1, " file-name" }, { "CWD", CWD, OSTR, 1, "[ directory-name ]" }, { "XCWD", CWD, OSTR, 1, "[ directory-name ]" }, { "LIST", LIST, OSTR, 1, "[ path-name ]" }, { "NLST", NLST, OSTR, 1, "[ path-name ]" }, { "SITE", SITE, SITECMD, 1, "site-cmd [ arguments ]" }, { "SYST", SYST, ARGS, 1, "(get type of operating system)" }, { "STAT", STAT, OSTR, 1, "[ path-name ]" }, { "HELP", HELP, OSTR, 1, "[ ]" }, { "NOOP", NOOP, ARGS, 1, "" }, { "MKD", MKD, STR1, 1, " path-name" }, { "XMKD", MKD, STR1, 1, " path-name" }, { "RMD", RMD, STR1, 1, " path-name" }, { "XRMD", RMD, STR1, 1, " path-name" }, { "PWD", PWD, ARGS, 1, "(return current directory)" }, { "XPWD", PWD, ARGS, 1, "(return current directory)" }, { "CDUP", CDUP, ARGS, 1, "(change to parent directory)" }, { "XCUP", CDUP, ARGS, 1, "(change to parent directory)" }, { "STOU", STOU, STR1, 1, " file-name" }, { "SIZE", SIZE, OSTR, 1, " path-name" }, { "MDTM", MDTM, OSTR, 1, " path-name" }, { NULL, 0, 0, 0, 0 } }; struct tab sitetab[] = { { "UMASK", UMASK, ARGS, 1, "[ umask ]" }, { "IDLE", IDLE, ARGS, 1, "[ maximum-idle-time ]" }, { "CHMOD", CHMOD, NSTR, 1, " mode file-name" }, { "HELP", HELP, OSTR, 1, "[ ]" }, { NULL, 0, 0, 0, 0 } }; struct tab * lookup(p, cmd) register struct tab *p; char *cmd; { for (; p->name != NULL; p++) if (strcmp(cmd, p->name) == 0) return (p); return (0); } #include /* * getline - a hacked up version of fgets to ignore TELNET escape codes. */ char * getline(s, n, iop) char *s; register FILE *iop; { register c; register char *cs; cs = s; /* tmpline may contain saved command from urgent mode interruption */ for (c = 0; tmpline[c] != '\0' && --n > 0; ++c) { *cs++ = tmpline[c]; if (tmpline[c] == '\n') { *cs++ = '\0'; if (debug) syslog(LOG_DEBUG, "command: %s", s); tmpline[0] = '\0'; return(s); } if (c == 0) tmpline[0] = '\0'; } while ((c = getc(iop)) != EOF) { c &= 0377; if (c == IAC) { if ((c = getc(iop)) != EOF) { c &= 0377; switch (c) { case WILL: case WONT: c = getc(iop); printf("%c%c%c", IAC, DONT, 0377&c); (void) fflush(stdout); continue; case DO: case DONT: c = getc(iop); printf("%c%c%c", IAC, WONT, 0377&c); (void) fflush(stdout); continue; case IAC: break; default: continue; /* ignore command */ } } } *cs++ = c; if (--n <= 0 || c == '\n') break; } if (c == EOF && cs == s) return (NULL); *cs++ = '\0'; if (debug) syslog(LOG_DEBUG, "command: %s", s); return (s); } static int toolong() { time_t now; extern char *ctime(); extern time_t time(); reply(421, "Timeout (%d seconds): closing control connection.", timeout); (void) time(&now); if (logging) { syslog(LOG_INFO, "User %s timed out after %d seconds at %s", (pw ? pw -> pw_name : "unknown"), timeout, ctime(&now)); } dologout(1); } ftplex() { static int cpos, state; register char *cp, *cp2; register struct tab *p; int n; char c, *strpbrk(); char *copy(); for (;;) { switch (state) { case CMD: (void) signal(SIGALRM, toolong); (void) alarm((unsigned) timeout); if (getline(cbuf, sizeof(cbuf)-1, stdin) == NULL) { reply(221, "You could at least say goodbye."); dologout(0); } (void) alarm(0); #ifdef SETPROCTITLE if (strncasecmp(cbuf, "PASS", 4) != NULL) setproctitle("%s: %s", proctitle, cbuf); #endif /* SETPROCTITLE */ if ((cp = index(cbuf, '\r'))) { *cp++ = '\n'; *cp = '\0'; } if ((cp = strpbrk(cbuf, " \n"))) cpos = cp - cbuf; if (cpos == 0) cpos = 4; c = cbuf[cpos]; cbuf[cpos] = '\0'; upper(cbuf); p = lookup(cmdtab, cbuf); cbuf[cpos] = c; if (p != 0) { if (p->implemented == 0) { nack(p->name); longjmp(errcatch,0); /* NOTREACHED */ } state = p->state; *(char **)&ftplval = p->name; return (p->token); } break; case SITECMD: if (cbuf[cpos] == ' ') { cpos++; return (SP); } cp = &cbuf[cpos]; if ((cp2 = strpbrk(cp, " \n"))) cpos = cp2 - cbuf; c = cbuf[cpos]; cbuf[cpos] = '\0'; upper(cp); p = lookup(sitetab, cp); cbuf[cpos] = c; if (p != 0) { if (p->implemented == 0) { state = CMD; nack(p->name); longjmp(errcatch,0); /* NOTREACHED */ } state = p->state; *(char **)&ftplval = p->name; return (p->token); } state = CMD; break; case OSTR: if (cbuf[cpos] == '\n') { state = CMD; return (CRLF); } /* FALLTHROUGH */ case STR1: case ZSTR1: dostr1: if (cbuf[cpos] == ' ') { cpos++; state = state == OSTR ? STR2 : ++state; return (SP); } break; case ZSTR2: if (cbuf[cpos] == '\n') { state = CMD; return (CRLF); } /* FALLTHROUGH */ case STR2: cp = &cbuf[cpos]; n = strlen(cp); cpos += n - 1; /* * Make sure the string is nonempty and \n terminated. */ if (n > 1 && cbuf[cpos] == '\n') { cbuf[cpos] = '\0'; *(char **)&ftplval = copy(cp); cbuf[cpos] = '\n'; state = ARGS; return (STRING); } break; case NSTR: if (cbuf[cpos] == ' ') { cpos++; return (SP); } if (isdigit(cbuf[cpos])) { cp = &cbuf[cpos]; while (isdigit(cbuf[++cpos])) ; c = cbuf[cpos]; cbuf[cpos] = '\0'; ftplval = atoi(cp); cbuf[cpos] = c; state = STR1; return (NUMBER); } state = STR1; goto dostr1; case ARGS: if (isdigit(cbuf[cpos])) { cp = &cbuf[cpos]; while (isdigit(cbuf[++cpos])) ; c = cbuf[cpos]; cbuf[cpos] = '\0'; ftplval = atoi(cp); cbuf[cpos] = c; return (NUMBER); } switch (cbuf[cpos++]) { case '\n': state = CMD; return (CRLF); case ' ': return (SP); case ',': return (COMMA); case 'A': case 'a': return (A); case 'B': case 'b': return (B); case 'C': case 'c': return (C); case 'E': case 'e': return (E); case 'F': case 'f': return (F); case 'I': case 'i': return (I); case 'L': case 'l': return (L); case 'N': case 'n': return (N); case 'P': case 'p': return (P); case 'R': case 'r': return (R); case 'S': case 's': return (S); case 'T': case 't': return (T); } break; default: fatal("Unknown state in scanner."); } ftperror((char *) 0); state = CMD; longjmp(errcatch,0); } } upper(s) register char *s; { while (*s != '\0') { if (islower(*s)) *s = toupper(*s); s++; } } char * copy(s) char *s; { char *p; extern char *malloc(), *strcpy(); p = malloc((unsigned) strlen(s) + 1); if (p == NULL) fatal("Ran out of memory."); (void) strcpy(p, s); return (p); } help(ctab, s) struct tab *ctab; char *s; { register struct tab *c; register int width, NCMDS; char *type; if (ctab == sitetab) type = "SITE "; else type = ""; width = 0, NCMDS = 0; for (c = ctab; c->name != NULL; c++) { int len = strlen(c->name); if (len > width) width = len; NCMDS++; } width = (width + 8) &~ 7; if (s == 0) { register int i, j, w; int columns, lines; lreply(214, "The following %scommands are recognized %s.", type, "(* =>'s unimplemented)"); columns = 76 / width; if (columns == 0) columns = 1; lines = (NCMDS + columns - 1) / columns; for (i = 0; i < lines; i++) { printf(" "); for (j = 0; j < columns; j++) { c = ctab + j * lines + i; printf("%s%c", c->name, c->implemented ? ' ' : '*'); if (c + lines >= &ctab[NCMDS]) break; w = strlen(c->name) + 1; while (w < width) { putchar(' '); w++; } } printf("\r\n"); } (void) fflush(stdout); reply(214, "Direct comments to ftp-bugs@%s.", hostname); return; } upper(s); c = lookup(ctab, s); if (c == (struct tab *)0) { reply(502, "Unknown command %s.", s); return; } if (c->implemented) reply(214, "Syntax: %s%s %s", type, c->name, c->help); else reply(214, "%s%-*s\t%s; unimplemented.", type, width, c->name, c->help); } sizecmd(filename) char *filename; { switch (type) { case TYPE_L: case TYPE_I: { struct stat stbuf; if (stat(filename, &stbuf) < 0 || (stbuf.st_mode&S_IFMT) != S_IFREG) reply(550, "%s: not a plain file.", filename); else reply(213, "%lu", stbuf.st_size); break;} case TYPE_A: { FILE *fin; register int c, count; struct stat stbuf; fin = fopen(filename, "r"); if (fin == NULL) { perror_reply(550, filename); return; } if (fstat(fileno(fin), &stbuf) < 0 || (stbuf.st_mode&S_IFMT) != S_IFREG) { reply(550, "%s: not a plain file.", filename); (void) fclose(fin); return; } count = 0; while((c=getc(fin)) != EOF) { if (c == '\n') /* will get expanded to \r\n */ count++; count++; } (void) fclose(fin); reply(213, "%ld", count); break;} default: reply(504, "SIZE not implemented for Type %c.", "?AEIL"[type]); } } perl-byacc-2.0.orig/test/error.tab.c100644 1750 1750 14413 5325617770 16216 0ustar bortzbortz#ifndef lint static char yysccsid[] = "@(#)yaccpar 1.8 (Berkeley) 01/20/91"; #endif #define YYBYACC 1 #define YYERRCODE 256 short yylhs[] = { -1, 0, }; short yylen[] = { 2, 1, }; short yydefred[] = { 0, 1, 0, }; short yydgoto[] = { 2, }; short yysindex[] = { -256, 0, 0, }; short yyrindex[] = { 0, 0, 0, }; short yygindex[] = { 0, }; #define YYTABLESIZE 0 short yytable[] = { 1, }; short yycheck[] = { 256, }; #define YYFINAL 2 #ifndef YYDEBUG #define YYDEBUG 0 #endif #define YYMAXTOKEN 0 #if YYDEBUG char *yyname[] = { "end-of-file", }; char *yyrule[] = { "$accept : S", "S : error", }; #endif #ifndef YYSTYPE typedef int YYSTYPE; #endif #define yyclearin (yychar=(-1)) #define yyerrok (yyerrflag=0) #ifdef YYSTACKSIZE #ifndef YYMAXDEPTH #define YYMAXDEPTH YYSTACKSIZE #endif #else #ifdef YYMAXDEPTH #define YYSTACKSIZE YYMAXDEPTH #else #define YYSTACKSIZE 500 #define YYMAXDEPTH 500 #endif #endif int yydebug; int yynerrs; int yyerrflag; int yychar; short *yyssp; YYSTYPE *yyvsp; YYSTYPE yyval; YYSTYPE yylval; short yyss[YYSTACKSIZE]; YYSTYPE yyvs[YYSTACKSIZE]; #define yystacksize YYSTACKSIZE #line 4 "error.y" main(){printf("yyparse() = %d\n",yyparse());} yylex(){return-1;} yyerror(s)char*s;{printf("%s\n",s);} #line 77 "error.tab.c" #define YYABORT goto yyabort #define YYACCEPT goto yyaccept #define YYERROR goto yyerrlab int yyparse() { register int yym, yyn, yystate; #if YYDEBUG register char *yys; extern char *getenv(); if (yys = getenv("YYDEBUG")) { yyn = *yys; if (yyn >= '0' && yyn <= '9') yydebug = yyn - '0'; } #endif yynerrs = 0; yyerrflag = 0; yychar = (-1); yyssp = yyss; yyvsp = yyvs; *yyssp = yystate = 0; yyloop: if (yyn = yydefred[yystate]) goto yyreduce; if (yychar < 0) { if ((yychar = yylex()) < 0) yychar = 0; #if YYDEBUG if (yydebug) { yys = 0; if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; if (!yys) yys = "illegal-symbol"; printf("yydebug: state %d, reading %d (%s)\n", yystate, yychar, yys); } #endif } if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == yychar) { #if YYDEBUG if (yydebug) printf("yydebug: state %d, shifting to state %d\n", yystate, yytable[yyn]); #endif if (yyssp >= yyss + yystacksize - 1) { goto yyoverflow; } *++yyssp = yystate = yytable[yyn]; *++yyvsp = yylval; yychar = (-1); if (yyerrflag > 0) --yyerrflag; goto yyloop; } if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == yychar) { yyn = yytable[yyn]; goto yyreduce; } if (yyerrflag) goto yyinrecovery; #ifdef lint goto yynewerror; #endif yynewerror: yyerror("syntax error"); #ifdef lint goto yyerrlab; #endif yyerrlab: ++yynerrs; yyinrecovery: if (yyerrflag < 3) { yyerrflag = 3; for (;;) { if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) { #if YYDEBUG if (yydebug) printf("yydebug: state %d, error recovery shifting\ to state %d\n", *yyssp, yytable[yyn]); #endif if (yyssp >= yyss + yystacksize - 1) { goto yyoverflow; } *++yyssp = yystate = yytable[yyn]; *++yyvsp = yylval; goto yyloop; } else { #if YYDEBUG if (yydebug) printf("yydebug: error recovery discarding state %d\n", *yyssp); #endif if (yyssp <= yyss) goto yyabort; --yyssp; --yyvsp; } } } else { if (yychar == 0) goto yyabort; #if YYDEBUG if (yydebug) { yys = 0; if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; if (!yys) yys = "illegal-symbol"; printf("yydebug: state %d, error recovery discards token %d (%s)\n", yystate, yychar, yys); } #endif yychar = (-1); goto yyloop; } yyreduce: #if YYDEBUG if (yydebug) printf("yydebug: state %d, reducing by rule %d (%s)\n", yystate, yyn, yyrule[yyn]); #endif yym = yylen[yyn]; yyval = yyvsp[1-yym]; switch (yyn) { } yyssp -= yym; yystate = *yyssp; yyvsp -= yym; yym = yylhs[yyn]; if (yystate == 0 && yym == 0) { #if YYDEBUG if (yydebug) printf("yydebug: after reduction, shifting from state 0 to\ state %d\n", YYFINAL); #endif yystate = YYFINAL; *++yyssp = YYFINAL; *++yyvsp = yyval; if (yychar < 0) { if ((yychar = yylex()) < 0) yychar = 0; #if YYDEBUG if (yydebug) { yys = 0; if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; if (!yys) yys = "illegal-symbol"; printf("yydebug: state %d, reading %d (%s)\n", YYFINAL, yychar, yys); } #endif } if (yychar == 0) goto yyaccept; goto yyloop; } if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == yystate) yystate = yytable[yyn]; else yystate = yydgoto[yym]; #if YYDEBUG if (yydebug) printf("yydebug: after reduction, shifting from state %d \ to state %d\n", *yyssp, yystate); #endif if (yyssp >= yyss + yystacksize - 1) { goto yyoverflow; } *++yyssp = yystate; *++yyvsp = yyval; goto yyloop; yyoverflow: yyerror("yacc stack overflow"); yyabort: return (1); yyaccept: return (0); } perl-byacc-2.0.orig/test/error.output100644 1750 1750 406 5224473063 16515 0ustar bortzbortz 0 $accept : S $end 1 S : error state 0 $accept : . S $end (0) error shift 1 . error S goto 2 state 1 S : error . (1) . reduce 1 state 2 $accept : S . $end (0) $end accept 2 terminals, 2 nonterminals 2 grammar rules, 3 states perl-byacc-2.0.orig/test/ftp.output100644 1750 1750 53265 5326600351 16223 0ustar bortzbortz 0 $accept : cmd_list $end 1 cmd_list : 2 | cmd_list cmd 3 | cmd_list rcmd 4 cmd : USER SP username CRLF 5 | PASS SP password CRLF 6 | PORT SP host_port CRLF 7 | PASV CRLF 8 | TYPE SP type_code CRLF 9 | STRU SP struct_code CRLF 10 | MODE SP mode_code CRLF 11 | ALLO SP NUMBER CRLF 12 | ALLO SP NUMBER SP R SP NUMBER CRLF 13 | RETR check_login SP pathname CRLF 14 | STOR check_login SP pathname CRLF 15 | APPE check_login SP pathname CRLF 16 | NLST check_login CRLF 17 | NLST check_login SP STRING CRLF 18 | LIST check_login CRLF 19 | LIST check_login SP pathname CRLF 20 | STAT check_login SP pathname CRLF 21 | STAT CRLF 22 | DELE check_login SP pathname CRLF 23 | RNTO SP pathname CRLF 24 | ABOR CRLF 25 | CWD check_login CRLF 26 | CWD check_login SP pathname CRLF 27 | HELP CRLF 28 | HELP SP STRING CRLF 29 | NOOP CRLF 30 | MKD check_login SP pathname CRLF 31 | RMD check_login SP pathname CRLF 32 | PWD check_login CRLF 33 | CDUP check_login CRLF 34 | SITE SP HELP CRLF 35 | SITE SP HELP SP STRING CRLF 36 | SITE SP UMASK check_login CRLF 37 | SITE SP UMASK check_login SP octal_number CRLF 38 | SITE SP CHMOD check_login SP octal_number SP pathname CRLF 39 | SITE SP IDLE CRLF 40 | SITE SP IDLE SP NUMBER CRLF 41 | STOU check_login SP pathname CRLF 42 | SYST CRLF 43 | SIZE check_login SP pathname CRLF 44 | MDTM check_login SP pathname CRLF 45 | QUIT CRLF 46 | error CRLF 47 rcmd : RNFR check_login SP pathname CRLF 48 username : STRING 49 password : 50 | STRING 51 byte_size : NUMBER 52 host_port : NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER 53 form_code : N 54 | T 55 | C 56 type_code : A 57 | A SP form_code 58 | E 59 | E SP form_code 60 | I 61 | L 62 | L SP byte_size 63 | L byte_size 64 struct_code : F 65 | R 66 | P 67 mode_code : S 68 | B 69 | C 70 pathname : pathstring 71 pathstring : STRING 72 octal_number : NUMBER 73 check_login : state 0 $accept : . cmd_list $end (0) cmd_list : . (1) . reduce 1 cmd_list goto 1 state 1 $accept : cmd_list . $end (0) cmd_list : cmd_list . cmd (2) cmd_list : cmd_list . rcmd (3) $end accept error shift 2 USER shift 3 PASS shift 4 QUIT shift 5 PORT shift 6 PASV shift 7 TYPE shift 8 STRU shift 9 MODE shift 10 RETR shift 11 STOR shift 12 APPE shift 13 ALLO shift 14 RNFR shift 15 RNTO shift 16 ABOR shift 17 DELE shift 18 CWD shift 19 LIST shift 20 NLST shift 21 SITE shift 22 STAT shift 23 HELP shift 24 NOOP shift 25 MKD shift 26 RMD shift 27 PWD shift 28 CDUP shift 29 STOU shift 30 SYST shift 31 SIZE shift 32 MDTM shift 33 . error cmd goto 34 rcmd goto 35 state 2 cmd : error . CRLF (46) CRLF shift 36 . error state 3 cmd : USER . SP username CRLF (4) SP shift 37 . error state 4 cmd : PASS . SP password CRLF (5) SP shift 38 . error state 5 cmd : QUIT . CRLF (45) CRLF shift 39 . error state 6 cmd : PORT . SP host_port CRLF (6) SP shift 40 . error state 7 cmd : PASV . CRLF (7) CRLF shift 41 . error state 8 cmd : TYPE . SP type_code CRLF (8) SP shift 42 . error state 9 cmd : STRU . SP struct_code CRLF (9) SP shift 43 . error state 10 cmd : MODE . SP mode_code CRLF (10) SP shift 44 . error state 11 cmd : RETR . check_login SP pathname CRLF (13) check_login : . (73) . reduce 73 check_login goto 45 state 12 cmd : STOR . check_login SP pathname CRLF (14) check_login : . (73) . reduce 73 check_login goto 46 state 13 cmd : APPE . check_login SP pathname CRLF (15) check_login : . (73) . reduce 73 check_login goto 47 state 14 cmd : ALLO . SP NUMBER CRLF (11) cmd : ALLO . SP NUMBER SP R SP NUMBER CRLF (12) SP shift 48 . error state 15 rcmd : RNFR . check_login SP pathname CRLF (47) check_login : . (73) . reduce 73 check_login goto 49 state 16 cmd : RNTO . SP pathname CRLF (23) SP shift 50 . error state 17 cmd : ABOR . CRLF (24) CRLF shift 51 . error state 18 cmd : DELE . check_login SP pathname CRLF (22) check_login : . (73) . reduce 73 check_login goto 52 state 19 cmd : CWD . check_login CRLF (25) cmd : CWD . check_login SP pathname CRLF (26) check_login : . (73) . reduce 73 check_login goto 53 state 20 cmd : LIST . check_login CRLF (18) cmd : LIST . check_login SP pathname CRLF (19) check_login : . (73) . reduce 73 check_login goto 54 state 21 cmd : NLST . check_login CRLF (16) cmd : NLST . check_login SP STRING CRLF (17) check_login : . (73) . reduce 73 check_login goto 55 state 22 cmd : SITE . SP HELP CRLF (34) cmd : SITE . SP HELP SP STRING CRLF (35) cmd : SITE . SP UMASK check_login CRLF (36) cmd : SITE . SP UMASK check_login SP octal_number CRLF (37) cmd : SITE . SP CHMOD check_login SP octal_number SP pathname CRLF (38) cmd : SITE . SP IDLE CRLF (39) cmd : SITE . SP IDLE SP NUMBER CRLF (40) SP shift 56 . error state 23 cmd : STAT . check_login SP pathname CRLF (20) cmd : STAT . CRLF (21) check_login : . (73) CRLF shift 57 SP reduce 73 check_login goto 58 state 24 cmd : HELP . CRLF (27) cmd : HELP . SP STRING CRLF (28) SP shift 59 CRLF shift 60 . error state 25 cmd : NOOP . CRLF (29) CRLF shift 61 . error state 26 cmd : MKD . check_login SP pathname CRLF (30) check_login : . (73) . reduce 73 check_login goto 62 state 27 cmd : RMD . check_login SP pathname CRLF (31) check_login : . (73) . reduce 73 check_login goto 63 state 28 cmd : PWD . check_login CRLF (32) check_login : . (73) . reduce 73 check_login goto 64 state 29 cmd : CDUP . check_login CRLF (33) check_login : . (73) . reduce 73 check_login goto 65 state 30 cmd : STOU . check_login SP pathname CRLF (41) check_login : . (73) . reduce 73 check_login goto 66 state 31 cmd : SYST . CRLF (42) CRLF shift 67 . error state 32 cmd : SIZE . check_login SP pathname CRLF (43) check_login : . (73) . reduce 73 check_login goto 68 state 33 cmd : MDTM . check_login SP pathname CRLF (44) check_login : . (73) . reduce 73 check_login goto 69 state 34 cmd_list : cmd_list cmd . (2) . reduce 2 state 35 cmd_list : cmd_list rcmd . (3) . reduce 3 state 36 cmd : error CRLF . (46) . reduce 46 state 37 cmd : USER SP . username CRLF (4) STRING shift 70 . error username goto 71 state 38 cmd : PASS SP . password CRLF (5) password : . (49) STRING shift 72 CRLF reduce 49 password goto 73 state 39 cmd : QUIT CRLF . (45) . reduce 45 state 40 cmd : PORT SP . host_port CRLF (6) NUMBER shift 74 . error host_port goto 75 state 41 cmd : PASV CRLF . (7) . reduce 7 state 42 cmd : TYPE SP . type_code CRLF (8) A shift 76 E shift 77 I shift 78 L shift 79 . error type_code goto 80 state 43 cmd : STRU SP . struct_code CRLF (9) F shift 81 P shift 82 R shift 83 . error struct_code goto 84 state 44 cmd : MODE SP . mode_code CRLF (10) B shift 85 C shift 86 S shift 87 . error mode_code goto 88 state 45 cmd : RETR check_login . SP pathname CRLF (13) SP shift 89 . error state 46 cmd : STOR check_login . SP pathname CRLF (14) SP shift 90 . error state 47 cmd : APPE check_login . SP pathname CRLF (15) SP shift 91 . error state 48 cmd : ALLO SP . NUMBER CRLF (11) cmd : ALLO SP . NUMBER SP R SP NUMBER CRLF (12) NUMBER shift 92 . error state 49 rcmd : RNFR check_login . SP pathname CRLF (47) SP shift 93 . error state 50 cmd : RNTO SP . pathname CRLF (23) STRING shift 94 . error pathname goto 95 pathstring goto 96 state 51 cmd : ABOR CRLF . (24) . reduce 24 state 52 cmd : DELE check_login . SP pathname CRLF (22) SP shift 97 . error state 53 cmd : CWD check_login . CRLF (25) cmd : CWD check_login . SP pathname CRLF (26) SP shift 98 CRLF shift 99 . error state 54 cmd : LIST check_login . CRLF (18) cmd : LIST check_login . SP pathname CRLF (19) SP shift 100 CRLF shift 101 . error state 55 cmd : NLST check_login . CRLF (16) cmd : NLST check_login . SP STRING CRLF (17) SP shift 102 CRLF shift 103 . error state 56 cmd : SITE SP . HELP CRLF (34) cmd : SITE SP . HELP SP STRING CRLF (35) cmd : SITE SP . UMASK check_login CRLF (36) cmd : SITE SP . UMASK check_login SP octal_number CRLF (37) cmd : SITE SP . CHMOD check_login SP octal_number SP pathname CRLF (38) cmd : SITE SP . IDLE CRLF (39) cmd : SITE SP . IDLE SP NUMBER CRLF (40) HELP shift 104 UMASK shift 105 IDLE shift 106 CHMOD shift 107 . error state 57 cmd : STAT CRLF . (21) . reduce 21 state 58 cmd : STAT check_login . SP pathname CRLF (20) SP shift 108 . error state 59 cmd : HELP SP . STRING CRLF (28) STRING shift 109 . error state 60 cmd : HELP CRLF . (27) . reduce 27 state 61 cmd : NOOP CRLF . (29) . reduce 29 state 62 cmd : MKD check_login . SP pathname CRLF (30) SP shift 110 . error state 63 cmd : RMD check_login . SP pathname CRLF (31) SP shift 111 . error state 64 cmd : PWD check_login . CRLF (32) CRLF shift 112 . error state 65 cmd : CDUP check_login . CRLF (33) CRLF shift 113 . error state 66 cmd : STOU check_login . SP pathname CRLF (41) SP shift 114 . error state 67 cmd : SYST CRLF . (42) . reduce 42 state 68 cmd : SIZE check_login . SP pathname CRLF (43) SP shift 115 . error state 69 cmd : MDTM check_login . SP pathname CRLF (44) SP shift 116 . error state 70 username : STRING . (48) . reduce 48 state 71 cmd : USER SP username . CRLF (4) CRLF shift 117 . error state 72 password : STRING . (50) . reduce 50 state 73 cmd : PASS SP password . CRLF (5) CRLF shift 118 . error state 74 host_port : NUMBER . COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER (52) COMMA shift 119 . error state 75 cmd : PORT SP host_port . CRLF (6) CRLF shift 120 . error state 76 type_code : A . (56) type_code : A . SP form_code (57) SP shift 121 CRLF reduce 56 state 77 type_code : E . (58) type_code : E . SP form_code (59) SP shift 122 CRLF reduce 58 state 78 type_code : I . (60) . reduce 60 state 79 type_code : L . (61) type_code : L . SP byte_size (62) type_code : L . byte_size (63) SP shift 123 NUMBER shift 124 CRLF reduce 61 byte_size goto 125 state 80 cmd : TYPE SP type_code . CRLF (8) CRLF shift 126 . error state 81 struct_code : F . (64) . reduce 64 state 82 struct_code : P . (66) . reduce 66 state 83 struct_code : R . (65) . reduce 65 state 84 cmd : STRU SP struct_code . CRLF (9) CRLF shift 127 . error state 85 mode_code : B . (68) . reduce 68 state 86 mode_code : C . (69) . reduce 69 state 87 mode_code : S . (67) . reduce 67 state 88 cmd : MODE SP mode_code . CRLF (10) CRLF shift 128 . error state 89 cmd : RETR check_login SP . pathname CRLF (13) STRING shift 94 . error pathname goto 129 pathstring goto 96 state 90 cmd : STOR check_login SP . pathname CRLF (14) STRING shift 94 . error pathname goto 130 pathstring goto 96 state 91 cmd : APPE check_login SP . pathname CRLF (15) STRING shift 94 . error pathname goto 131 pathstring goto 96 state 92 cmd : ALLO SP NUMBER . CRLF (11) cmd : ALLO SP NUMBER . SP R SP NUMBER CRLF (12) SP shift 132 CRLF shift 133 . error state 93 rcmd : RNFR check_login SP . pathname CRLF (47) STRING shift 94 . error pathname goto 134 pathstring goto 96 state 94 pathstring : STRING . (71) . reduce 71 state 95 cmd : RNTO SP pathname . CRLF (23) CRLF shift 135 . error state 96 pathname : pathstring . (70) . reduce 70 state 97 cmd : DELE check_login SP . pathname CRLF (22) STRING shift 94 . error pathname goto 136 pathstring goto 96 state 98 cmd : CWD check_login SP . pathname CRLF (26) STRING shift 94 . error pathname goto 137 pathstring goto 96 state 99 cmd : CWD check_login CRLF . (25) . reduce 25 state 100 cmd : LIST check_login SP . pathname CRLF (19) STRING shift 94 . error pathname goto 138 pathstring goto 96 state 101 cmd : LIST check_login CRLF . (18) . reduce 18 state 102 cmd : NLST check_login SP . STRING CRLF (17) STRING shift 139 . error state 103 cmd : NLST check_login CRLF . (16) . reduce 16 state 104 cmd : SITE SP HELP . CRLF (34) cmd : SITE SP HELP . SP STRING CRLF (35) SP shift 140 CRLF shift 141 . error state 105 cmd : SITE SP UMASK . check_login CRLF (36) cmd : SITE SP UMASK . check_login SP octal_number CRLF (37) check_login : . (73) . reduce 73 check_login goto 142 state 106 cmd : SITE SP IDLE . CRLF (39) cmd : SITE SP IDLE . SP NUMBER CRLF (40) SP shift 143 CRLF shift 144 . error state 107 cmd : SITE SP CHMOD . check_login SP octal_number SP pathname CRLF (38) check_login : . (73) . reduce 73 check_login goto 145 state 108 cmd : STAT check_login SP . pathname CRLF (20) STRING shift 94 . error pathname goto 146 pathstring goto 96 state 109 cmd : HELP SP STRING . CRLF (28) CRLF shift 147 . error state 110 cmd : MKD check_login SP . pathname CRLF (30) STRING shift 94 . error pathname goto 148 pathstring goto 96 state 111 cmd : RMD check_login SP . pathname CRLF (31) STRING shift 94 . error pathname goto 149 pathstring goto 96 state 112 cmd : PWD check_login CRLF . (32) . reduce 32 state 113 cmd : CDUP check_login CRLF . (33) . reduce 33 state 114 cmd : STOU check_login SP . pathname CRLF (41) STRING shift 94 . error pathname goto 150 pathstring goto 96 state 115 cmd : SIZE check_login SP . pathname CRLF (43) STRING shift 94 . error pathname goto 151 pathstring goto 96 state 116 cmd : MDTM check_login SP . pathname CRLF (44) STRING shift 94 . error pathname goto 152 pathstring goto 96 state 117 cmd : USER SP username CRLF . (4) . reduce 4 state 118 cmd : PASS SP password CRLF . (5) . reduce 5 state 119 host_port : NUMBER COMMA . NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER (52) NUMBER shift 153 . error state 120 cmd : PORT SP host_port CRLF . (6) . reduce 6 state 121 type_code : A SP . form_code (57) C shift 154 N shift 155 T shift 156 . error form_code goto 157 state 122 type_code : E SP . form_code (59) C shift 154 N shift 155 T shift 156 . error form_code goto 158 state 123 type_code : L SP . byte_size (62) NUMBER shift 124 . error byte_size goto 159 state 124 byte_size : NUMBER . (51) . reduce 51 state 125 type_code : L byte_size . (63) . reduce 63 state 126 cmd : TYPE SP type_code CRLF . (8) . reduce 8 state 127 cmd : STRU SP struct_code CRLF . (9) . reduce 9 state 128 cmd : MODE SP mode_code CRLF . (10) . reduce 10 state 129 cmd : RETR check_login SP pathname . CRLF (13) CRLF shift 160 . error state 130 cmd : STOR check_login SP pathname . CRLF (14) CRLF shift 161 . error state 131 cmd : APPE check_login SP pathname . CRLF (15) CRLF shift 162 . error state 132 cmd : ALLO SP NUMBER SP . R SP NUMBER CRLF (12) R shift 163 . error state 133 cmd : ALLO SP NUMBER CRLF . (11) . reduce 11 state 134 rcmd : RNFR check_login SP pathname . CRLF (47) CRLF shift 164 . error state 135 cmd : RNTO SP pathname CRLF . (23) . reduce 23 state 136 cmd : DELE check_login SP pathname . CRLF (22) CRLF shift 165 . error state 137 cmd : CWD check_login SP pathname . CRLF (26) CRLF shift 166 . error state 138 cmd : LIST check_login SP pathname . CRLF (19) CRLF shift 167 . error state 139 cmd : NLST check_login SP STRING . CRLF (17) CRLF shift 168 . error state 140 cmd : SITE SP HELP SP . STRING CRLF (35) STRING shift 169 . error state 141 cmd : SITE SP HELP CRLF . (34) . reduce 34 state 142 cmd : SITE SP UMASK check_login . CRLF (36) cmd : SITE SP UMASK check_login . SP octal_number CRLF (37) SP shift 170 CRLF shift 171 . error state 143 cmd : SITE SP IDLE SP . NUMBER CRLF (40) NUMBER shift 172 . error state 144 cmd : SITE SP IDLE CRLF . (39) . reduce 39 state 145 cmd : SITE SP CHMOD check_login . SP octal_number SP pathname CRLF (38) SP shift 173 . error state 146 cmd : STAT check_login SP pathname . CRLF (20) CRLF shift 174 . error state 147 cmd : HELP SP STRING CRLF . (28) . reduce 28 state 148 cmd : MKD check_login SP pathname . CRLF (30) CRLF shift 175 . error state 149 cmd : RMD check_login SP pathname . CRLF (31) CRLF shift 176 . error state 150 cmd : STOU check_login SP pathname . CRLF (41) CRLF shift 177 . error state 151 cmd : SIZE check_login SP pathname . CRLF (43) CRLF shift 178 . error state 152 cmd : MDTM check_login SP pathname . CRLF (44) CRLF shift 179 . error state 153 host_port : NUMBER COMMA NUMBER . COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER (52) COMMA shift 180 . error state 154 form_code : C . (55) . reduce 55 state 155 form_code : N . (53) . reduce 53 state 156 form_code : T . (54) . reduce 54 state 157 type_code : A SP form_code . (57) . reduce 57 state 158 type_code : E SP form_code . (59) . reduce 59 state 159 type_code : L SP byte_size . (62) . reduce 62 state 160 cmd : RETR check_login SP pathname CRLF . (13) . reduce 13 state 161 cmd : STOR check_login SP pathname CRLF . (14) . reduce 14 state 162 cmd : APPE check_login SP pathname CRLF . (15) . reduce 15 state 163 cmd : ALLO SP NUMBER SP R . SP NUMBER CRLF (12) SP shift 181 . error state 164 rcmd : RNFR check_login SP pathname CRLF . (47) . reduce 47 state 165 cmd : DELE check_login SP pathname CRLF . (22) . reduce 22 state 166 cmd : CWD check_login SP pathname CRLF . (26) . reduce 26 state 167 cmd : LIST check_login SP pathname CRLF . (19) . reduce 19 state 168 cmd : NLST check_login SP STRING CRLF . (17) . reduce 17 state 169 cmd : SITE SP HELP SP STRING . CRLF (35) CRLF shift 182 . error state 170 cmd : SITE SP UMASK check_login SP . octal_number CRLF (37) NUMBER shift 183 . error octal_number goto 184 state 171 cmd : SITE SP UMASK check_login CRLF . (36) . reduce 36 state 172 cmd : SITE SP IDLE SP NUMBER . CRLF (40) CRLF shift 185 . error state 173 cmd : SITE SP CHMOD check_login SP . octal_number SP pathname CRLF (38) NUMBER shift 183 . error octal_number goto 186 state 174 cmd : STAT check_login SP pathname CRLF . (20) . reduce 20 state 175 cmd : MKD check_login SP pathname CRLF . (30) . reduce 30 state 176 cmd : RMD check_login SP pathname CRLF . (31) . reduce 31 state 177 cmd : STOU check_login SP pathname CRLF . (41) . reduce 41 state 178 cmd : SIZE check_login SP pathname CRLF . (43) . reduce 43 state 179 cmd : MDTM check_login SP pathname CRLF . (44) . reduce 44 state 180 host_port : NUMBER COMMA NUMBER COMMA . NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER (52) NUMBER shift 187 . error state 181 cmd : ALLO SP NUMBER SP R SP . NUMBER CRLF (12) NUMBER shift 188 . error state 182 cmd : SITE SP HELP SP STRING CRLF . (35) . reduce 35 state 183 octal_number : NUMBER . (72) . reduce 72 state 184 cmd : SITE SP UMASK check_login SP octal_number . CRLF (37) CRLF shift 189 . error state 185 cmd : SITE SP IDLE SP NUMBER CRLF . (40) . reduce 40 state 186 cmd : SITE SP CHMOD check_login SP octal_number . SP pathname CRLF (38) SP shift 190 . error state 187 host_port : NUMBER COMMA NUMBER COMMA NUMBER . COMMA NUMBER COMMA NUMBER COMMA NUMBER (52) COMMA shift 191 . error state 188 cmd : ALLO SP NUMBER SP R SP NUMBER . CRLF (12) CRLF shift 192 . error state 189 cmd : SITE SP UMASK check_login SP octal_number CRLF . (37) . reduce 37 state 190 cmd : SITE SP CHMOD check_login SP octal_number SP . pathname CRLF (38) STRING shift 94 . error pathname goto 193 pathstring goto 96 state 191 host_port : NUMBER COMMA NUMBER COMMA NUMBER COMMA . NUMBER COMMA NUMBER COMMA NUMBER (52) NUMBER shift 194 . error state 192 cmd : ALLO SP NUMBER SP R SP NUMBER CRLF . (12) . reduce 12 state 193 cmd : SITE SP CHMOD check_login SP octal_number SP pathname . CRLF (38) CRLF shift 195 . error state 194 host_port : NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER . COMMA NUMBER COMMA NUMBER (52) COMMA shift 196 . error state 195 cmd : SITE SP CHMOD check_login SP octal_number SP pathname CRLF . (38) . reduce 38 state 196 host_port : NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA . NUMBER COMMA NUMBER (52) NUMBER shift 197 . error state 197 host_port : NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER . COMMA NUMBER (52) COMMA shift 198 . error state 198 host_port : NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA . NUMBER (52) NUMBER shift 199 . error state 199 host_port : NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER . (52) . reduce 52 65 terminals, 16 nonterminals 74 grammar rules, 200 states perl-byacc-2.0.orig/test/error.tab.h100644 1750 1750 0 5224473063 16077 0ustar bortzbortzperl-byacc-2.0.orig/test/ftp.tab.h100644 1750 1750 2016 5326600351 15623 0ustar bortzbortz#define A 257 #define B 258 #define C 259 #define E 260 #define F 261 #define I 262 #define L 263 #define N 264 #define P 265 #define R 266 #define S 267 #define T 268 #define SP 269 #define CRLF 270 #define COMMA 271 #define STRING 272 #define NUMBER 273 #define USER 274 #define PASS 275 #define ACCT 276 #define REIN 277 #define QUIT 278 #define PORT 279 #define PASV 280 #define TYPE 281 #define STRU 282 #define MODE 283 #define RETR 284 #define STOR 285 #define APPE 286 #define MLFL 287 #define MAIL 288 #define MSND 289 #define MSOM 290 #define MSAM 291 #define MRSQ 292 #define MRCP 293 #define ALLO 294 #define REST 295 #define RNFR 296 #define RNTO 297 #define ABOR 298 #define DELE 299 #define CWD 300 #define LIST 301 #define NLST 302 #define SITE 303 #define STAT 304 #define HELP 305 #define NOOP 306 #define MKD 307 #define RMD 308 #define PWD 309 #define CDUP 310 #define STOU 311 #define SMNT 312 #define SYST 313 #define SIZE 314 #define MDTM 315 #define UMASK 316 #define IDLE 317 #define CHMOD 318 #define LEXERR 319 perl-byacc-2.0.orig/test/ftp.tab.c100644 1750 1750 116572 5326600351 15673 0ustar bortzbortz#ifndef lint static char ftpsccsid[] = "@(#)yaccpar 1.8 (Berkeley) 01/20/91"; #endif #define FTPBYACC 1 #line 26 "ftp.y" #ifndef lint static char sccsid[] = "@(#)ftpcmd.y 5.20.1.1 (Berkeley) 3/2/89"; #endif /* not lint */ #include #include #include #include #include #include #include #include #include #include #include #include extern struct sockaddr_in data_dest; extern int logged_in; extern struct passwd *pw; extern int guest; extern int logging; extern int type; extern int form; extern int debug; extern int timeout; extern int maxtimeout; extern int pdata; extern char hostname[], remotehost[]; extern char proctitle[]; extern char *globerr; extern int usedefault; extern int transflag; extern char tmpline[]; char **glob(); static int cmd_type; static int cmd_form; static int cmd_bytesz; char cbuf[512]; char *fromname; char *index(); #line 54 "ftp.tab.c" #define A 257 #define B 258 #define C 259 #define E 260 #define F 261 #define I 262 #define L 263 #define N 264 #define P 265 #define R 266 #define S 267 #define T 268 #define SP 269 #define CRLF 270 #define COMMA 271 #define STRING 272 #define NUMBER 273 #define USER 274 #define PASS 275 #define ACCT 276 #define REIN 277 #define QUIT 278 #define PORT 279 #define PASV 280 #define TYPE 281 #define STRU 282 #define MODE 283 #define RETR 284 #define STOR 285 #define APPE 286 #define MLFL 287 #define MAIL 288 #define MSND 289 #define MSOM 290 #define MSAM 291 #define MRSQ 292 #define MRCP 293 #define ALLO 294 #define REST 295 #define RNFR 296 #define RNTO 297 #define ABOR 298 #define DELE 299 #define CWD 300 #define LIST 301 #define NLST 302 #define SITE 303 #define STAT 304 #define HELP 305 #define NOOP 306 #define MKD 307 #define RMD 308 #define PWD 309 #define CDUP 310 #define STOU 311 #define SMNT 312 #define SYST 313 #define SIZE 314 #define MDTM 315 #define UMASK 316 #define IDLE 317 #define CHMOD 318 #define LEXERR 319 #define FTPERRCODE 256 short ftplhs[] = { -1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 4, 12, 5, 13, 13, 13, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 10, 14, 11, 9, }; short ftplen[] = { 2, 0, 2, 2, 4, 4, 4, 2, 4, 4, 4, 4, 8, 5, 5, 5, 3, 5, 3, 5, 5, 2, 5, 4, 2, 3, 5, 2, 4, 2, 5, 5, 3, 3, 4, 6, 5, 7, 9, 4, 6, 5, 2, 5, 5, 2, 2, 5, 1, 0, 1, 1, 11, 1, 1, 1, 1, 3, 1, 3, 1, 1, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, }; short ftpdefred[] = { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 73, 73, 73, 0, 73, 0, 0, 73, 73, 73, 73, 0, 0, 0, 0, 73, 73, 73, 73, 73, 0, 73, 73, 2, 3, 46, 0, 0, 45, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 21, 0, 0, 27, 29, 0, 0, 0, 0, 0, 42, 0, 0, 48, 0, 50, 0, 0, 0, 0, 0, 60, 0, 0, 64, 66, 65, 0, 68, 69, 67, 0, 0, 0, 0, 0, 0, 71, 0, 70, 0, 0, 25, 0, 18, 0, 16, 0, 73, 0, 73, 0, 0, 0, 0, 32, 33, 0, 0, 0, 4, 5, 0, 6, 0, 0, 0, 51, 63, 8, 9, 10, 0, 0, 0, 0, 11, 0, 23, 0, 0, 0, 0, 0, 34, 0, 0, 39, 0, 0, 28, 0, 0, 0, 0, 0, 0, 55, 53, 54, 57, 59, 62, 13, 14, 15, 0, 47, 22, 26, 19, 17, 0, 0, 36, 0, 0, 20, 30, 31, 41, 43, 44, 0, 0, 35, 72, 0, 40, 0, 0, 0, 37, 0, 0, 12, 0, 0, 38, 0, 0, 0, 52, }; short ftpdgoto[] = { 1, 34, 35, 71, 73, 75, 80, 84, 88, 45, 95, 184, 125, 157, 96, }; short ftpsindex[] = { 0, -224, -247, -239, -236, -232, -222, -204, -200, -181, -177, 0, 0, 0, -166, 0, -161, -199, 0, 0, 0, 0, -160, -159, -264, -158, 0, 0, 0, 0, 0, -157, 0, 0, 0, 0, 0, -167, -162, 0, -156, 0, -250, -198, -165, -155, -154, -153, -151, -150, -152, 0, -145, -252, -229, -217, -302, 0, -144, -146, 0, 0, -142, -141, -140, -139, -137, 0, -136, -135, 0, -134, 0, -133, -132, -130, -131, -128, 0, -249, -127, 0, 0, 0, -126, 0, 0, 0, -125, -152, -152, -152, -205, -152, 0, -124, 0, -152, -152, 0, -152, 0, -143, 0, -173, 0, -171, 0, -152, -123, -152, -152, 0, 0, -152, -152, -152, 0, 0, -138, 0, -164, -164, -122, 0, 0, 0, 0, 0, -121, -120, -118, -148, 0, -117, 0, -116, -115, -114, -113, -112, 0, -163, -111, 0, -110, -109, 0, -107, -106, -105, -104, -103, -129, 0, 0, 0, 0, 0, 0, 0, 0, 0, -101, 0, 0, 0, 0, 0, -100, -102, 0, -98, -102, 0, 0, 0, 0, 0, 0, -99, -97, 0, 0, -95, 0, -96, -94, -92, 0, -152, -93, 0, -91, -90, 0, -88, -87, -86, 0, }; short ftprindex[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -83, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -81, -80, 0, -158, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; short ftpgindex[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, -89, -25, 35, 47, 0, }; #define FTPTABLESIZE 190 short ftptable[] = { 129, 130, 131, 104, 134, 59, 60, 76, 136, 137, 77, 138, 78, 79, 105, 106, 107, 98, 99, 146, 123, 148, 149, 36, 124, 150, 151, 152, 46, 47, 37, 49, 2, 38, 52, 53, 54, 55, 39, 58, 100, 101, 62, 63, 64, 65, 66, 40, 68, 69, 3, 4, 102, 103, 5, 6, 7, 8, 9, 10, 11, 12, 13, 81, 132, 133, 41, 82, 83, 42, 14, 51, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 43, 31, 32, 33, 44, 85, 86, 154, 140, 141, 143, 144, 155, 193, 87, 48, 156, 70, 170, 171, 50, 56, 72, 57, 61, 67, 89, 90, 91, 74, 163, 93, 94, 142, 92, 145, 97, 108, 109, 110, 111, 139, 112, 113, 114, 115, 116, 153, 117, 118, 121, 119, 120, 122, 180, 126, 127, 128, 135, 147, 186, 160, 161, 124, 162, 164, 165, 166, 167, 168, 159, 173, 169, 174, 172, 175, 176, 177, 178, 179, 181, 158, 182, 183, 185, 190, 187, 189, 188, 191, 192, 195, 194, 196, 0, 0, 198, 197, 73, 199, 49, 56, 58, }; short ftpcheck[] = { 89, 90, 91, 305, 93, 269, 270, 257, 97, 98, 260, 100, 262, 263, 316, 317, 318, 269, 270, 108, 269, 110, 111, 270, 273, 114, 115, 116, 12, 13, 269, 15, 256, 269, 18, 19, 20, 21, 270, 23, 269, 270, 26, 27, 28, 29, 30, 269, 32, 33, 274, 275, 269, 270, 278, 279, 280, 281, 282, 283, 284, 285, 286, 261, 269, 270, 270, 265, 266, 269, 294, 270, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 269, 313, 314, 315, 269, 258, 259, 259, 269, 270, 269, 270, 264, 190, 267, 269, 268, 272, 269, 270, 269, 269, 272, 270, 270, 270, 269, 269, 269, 273, 266, 269, 272, 105, 273, 107, 269, 269, 272, 269, 269, 272, 270, 270, 269, 269, 269, 273, 270, 270, 269, 271, 270, 269, 271, 270, 270, 270, 270, 270, 173, 270, 270, 273, 270, 270, 270, 270, 270, 270, 123, 269, 272, 270, 273, 270, 270, 270, 270, 270, 269, 122, 270, 273, 270, 269, 273, 270, 273, 271, 270, 270, 273, 271, -1, -1, 271, 273, 269, 273, 270, 270, 270, }; #define FTPFINAL 1 #ifndef FTPDEBUG #define FTPDEBUG 0 #endif #define FTPMAXTOKEN 319 #if FTPDEBUG char *ftpname[] = { "end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"A","B","C","E","F","I","L","N", "P","R","S","T","SP","CRLF","COMMA","STRING","NUMBER","USER","PASS","ACCT", "REIN","QUIT","PORT","PASV","TYPE","STRU","MODE","RETR","STOR","APPE","MLFL", "MAIL","MSND","MSOM","MSAM","MRSQ","MRCP","ALLO","REST","RNFR","RNTO","ABOR", "DELE","CWD","LIST","NLST","SITE","STAT","HELP","NOOP","MKD","RMD","PWD","CDUP", "STOU","SMNT","SYST","SIZE","MDTM","UMASK","IDLE","CHMOD","LEXERR", }; char *ftprule[] = { "$accept : cmd_list", "cmd_list :", "cmd_list : cmd_list cmd", "cmd_list : cmd_list rcmd", "cmd : USER SP username CRLF", "cmd : PASS SP password CRLF", "cmd : PORT SP host_port CRLF", "cmd : PASV CRLF", "cmd : TYPE SP type_code CRLF", "cmd : STRU SP struct_code CRLF", "cmd : MODE SP mode_code CRLF", "cmd : ALLO SP NUMBER CRLF", "cmd : ALLO SP NUMBER SP R SP NUMBER CRLF", "cmd : RETR check_login SP pathname CRLF", "cmd : STOR check_login SP pathname CRLF", "cmd : APPE check_login SP pathname CRLF", "cmd : NLST check_login CRLF", "cmd : NLST check_login SP STRING CRLF", "cmd : LIST check_login CRLF", "cmd : LIST check_login SP pathname CRLF", "cmd : STAT check_login SP pathname CRLF", "cmd : STAT CRLF", "cmd : DELE check_login SP pathname CRLF", "cmd : RNTO SP pathname CRLF", "cmd : ABOR CRLF", "cmd : CWD check_login CRLF", "cmd : CWD check_login SP pathname CRLF", "cmd : HELP CRLF", "cmd : HELP SP STRING CRLF", "cmd : NOOP CRLF", "cmd : MKD check_login SP pathname CRLF", "cmd : RMD check_login SP pathname CRLF", "cmd : PWD check_login CRLF", "cmd : CDUP check_login CRLF", "cmd : SITE SP HELP CRLF", "cmd : SITE SP HELP SP STRING CRLF", "cmd : SITE SP UMASK check_login CRLF", "cmd : SITE SP UMASK check_login SP octal_number CRLF", "cmd : SITE SP CHMOD check_login SP octal_number SP pathname CRLF", "cmd : SITE SP IDLE CRLF", "cmd : SITE SP IDLE SP NUMBER CRLF", "cmd : STOU check_login SP pathname CRLF", "cmd : SYST CRLF", "cmd : SIZE check_login SP pathname CRLF", "cmd : MDTM check_login SP pathname CRLF", "cmd : QUIT CRLF", "cmd : error CRLF", "rcmd : RNFR check_login SP pathname CRLF", "username : STRING", "password :", "password : STRING", "byte_size : NUMBER", "host_port : NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER", "form_code : N", "form_code : T", "form_code : C", "type_code : A", "type_code : A SP form_code", "type_code : E", "type_code : E SP form_code", "type_code : I", "type_code : L", "type_code : L SP byte_size", "type_code : L byte_size", "struct_code : F", "struct_code : R", "struct_code : P", "mode_code : S", "mode_code : B", "mode_code : C", "pathname : pathstring", "pathstring : STRING", "octal_number : NUMBER", "check_login :", }; #endif #ifndef FTPSTYPE typedef int FTPSTYPE; #endif #define ftpclearin (ftpchar=(-1)) #define ftperrok (ftperrflag=0) #ifdef FTPSTACKSIZE #ifndef FTPMAXDEPTH #define FTPMAXDEPTH FTPSTACKSIZE #endif #else #ifdef FTPMAXDEPTH #define FTPSTACKSIZE FTPMAXDEPTH #else #define FTPSTACKSIZE 500 #define FTPMAXDEPTH 500 #endif #endif int ftpdebug; int ftpnerrs; int ftperrflag; int ftpchar; short *ftpssp; FTPSTYPE *ftpvsp; FTPSTYPE ftpval; FTPSTYPE ftplval; short ftpss[FTPSTACKSIZE]; FTPSTYPE ftpvs[FTPSTACKSIZE]; #define ftpstacksize FTPSTACKSIZE #line 658 "ftp.y" extern jmp_buf errcatch; #define CMD 0 /* beginning of command */ #define ARGS 1 /* expect miscellaneous arguments */ #define STR1 2 /* expect SP followed by STRING */ #define STR2 3 /* expect STRING */ #define OSTR 4 /* optional SP then STRING */ #define ZSTR1 5 /* SP then optional STRING */ #define ZSTR2 6 /* optional STRING after SP */ #define SITECMD 7 /* SITE command */ #define NSTR 8 /* Number followed by a string */ struct tab { char *name; short token; short state; short implemented; /* 1 if command is implemented */ char *help; }; struct tab cmdtab[] = { /* In order defined in RFC 765 */ { "USER", USER, STR1, 1, " username" }, { "PASS", PASS, ZSTR1, 1, " password" }, { "ACCT", ACCT, STR1, 0, "(specify account)" }, { "SMNT", SMNT, ARGS, 0, "(structure mount)" }, { "REIN", REIN, ARGS, 0, "(reinitialize server state)" }, { "QUIT", QUIT, ARGS, 1, "(terminate service)", }, { "PORT", PORT, ARGS, 1, " b0, b1, b2, b3, b4" }, { "PASV", PASV, ARGS, 1, "(set server in passive mode)" }, { "TYPE", TYPE, ARGS, 1, " [ A | E | I | L ]" }, { "STRU", STRU, ARGS, 1, "(specify file structure)" }, { "MODE", MODE, ARGS, 1, "(specify transfer mode)" }, { "RETR", RETR, STR1, 1, " file-name" }, { "STOR", STOR, STR1, 1, " file-name" }, { "APPE", APPE, STR1, 1, " file-name" }, { "MLFL", MLFL, OSTR, 0, "(mail file)" }, { "MAIL", MAIL, OSTR, 0, "(mail to user)" }, { "MSND", MSND, OSTR, 0, "(mail send to terminal)" }, { "MSOM", MSOM, OSTR, 0, "(mail send to terminal or mailbox)" }, { "MSAM", MSAM, OSTR, 0, "(mail send to terminal and mailbox)" }, { "MRSQ", MRSQ, OSTR, 0, "(mail recipient scheme question)" }, { "MRCP", MRCP, STR1, 0, "(mail recipient)" }, { "ALLO", ALLO, ARGS, 1, "allocate storage (vacuously)" }, { "REST", REST, ARGS, 0, "(restart command)" }, { "RNFR", RNFR, STR1, 1, " file-name" }, { "RNTO", RNTO, STR1, 1, " file-name" }, { "ABOR", ABOR, ARGS, 1, "(abort operation)" }, { "DELE", DELE, STR1, 1, " file-name" }, { "CWD", CWD, OSTR, 1, "[ directory-name ]" }, { "XCWD", CWD, OSTR, 1, "[ directory-name ]" }, { "LIST", LIST, OSTR, 1, "[ path-name ]" }, { "NLST", NLST, OSTR, 1, "[ path-name ]" }, { "SITE", SITE, SITECMD, 1, "site-cmd [ arguments ]" }, { "SYST", SYST, ARGS, 1, "(get type of operating system)" }, { "STAT", STAT, OSTR, 1, "[ path-name ]" }, { "HELP", HELP, OSTR, 1, "[ ]" }, { "NOOP", NOOP, ARGS, 1, "" }, { "MKD", MKD, STR1, 1, " path-name" }, { "XMKD", MKD, STR1, 1, " path-name" }, { "RMD", RMD, STR1, 1, " path-name" }, { "XRMD", RMD, STR1, 1, " path-name" }, { "PWD", PWD, ARGS, 1, "(return current directory)" }, { "XPWD", PWD, ARGS, 1, "(return current directory)" }, { "CDUP", CDUP, ARGS, 1, "(change to parent directory)" }, { "XCUP", CDUP, ARGS, 1, "(change to parent directory)" }, { "STOU", STOU, STR1, 1, " file-name" }, { "SIZE", SIZE, OSTR, 1, " path-name" }, { "MDTM", MDTM, OSTR, 1, " path-name" }, { NULL, 0, 0, 0, 0 } }; struct tab sitetab[] = { { "UMASK", UMASK, ARGS, 1, "[ umask ]" }, { "IDLE", IDLE, ARGS, 1, "[ maximum-idle-time ]" }, { "CHMOD", CHMOD, NSTR, 1, " mode file-name" }, { "HELP", HELP, OSTR, 1, "[ ]" }, { NULL, 0, 0, 0, 0 } }; struct tab * lookup(p, cmd) register struct tab *p; char *cmd; { for (; p->name != NULL; p++) if (strcmp(cmd, p->name) == 0) return (p); return (0); } #include /* * getline - a hacked up version of fgets to ignore TELNET escape codes. */ char * getline(s, n, iop) char *s; register FILE *iop; { register c; register char *cs; cs = s; /* tmpline may contain saved command from urgent mode interruption */ for (c = 0; tmpline[c] != '\0' && --n > 0; ++c) { *cs++ = tmpline[c]; if (tmpline[c] == '\n') { *cs++ = '\0'; if (debug) syslog(LOG_DEBUG, "command: %s", s); tmpline[0] = '\0'; return(s); } if (c == 0) tmpline[0] = '\0'; } while ((c = getc(iop)) != EOF) { c &= 0377; if (c == IAC) { if ((c = getc(iop)) != EOF) { c &= 0377; switch (c) { case WILL: case WONT: c = getc(iop); printf("%c%c%c", IAC, DONT, 0377&c); (void) fflush(stdout); continue; case DO: case DONT: c = getc(iop); printf("%c%c%c", IAC, WONT, 0377&c); (void) fflush(stdout); continue; case IAC: break; default: continue; /* ignore command */ } } } *cs++ = c; if (--n <= 0 || c == '\n') break; } if (c == EOF && cs == s) return (NULL); *cs++ = '\0'; if (debug) syslog(LOG_DEBUG, "command: %s", s); return (s); } static int toolong() { time_t now; extern char *ctime(); extern time_t time(); reply(421, "Timeout (%d seconds): closing control connection.", timeout); (void) time(&now); if (logging) { syslog(LOG_INFO, "User %s timed out after %d seconds at %s", (pw ? pw -> pw_name : "unknown"), timeout, ctime(&now)); } dologout(1); } ftplex() { static int cpos, state; register char *cp, *cp2; register struct tab *p; int n; char c, *strpbrk(); char *copy(); for (;;) { switch (state) { case CMD: (void) signal(SIGALRM, toolong); (void) alarm((unsigned) timeout); if (getline(cbuf, sizeof(cbuf)-1, stdin) == NULL) { reply(221, "You could at least say goodbye."); dologout(0); } (void) alarm(0); #ifdef SETPROCTITLE if (strncasecmp(cbuf, "PASS", 4) != NULL) setproctitle("%s: %s", proctitle, cbuf); #endif /* SETPROCTITLE */ if ((cp = index(cbuf, '\r'))) { *cp++ = '\n'; *cp = '\0'; } if ((cp = strpbrk(cbuf, " \n"))) cpos = cp - cbuf; if (cpos == 0) cpos = 4; c = cbuf[cpos]; cbuf[cpos] = '\0'; upper(cbuf); p = lookup(cmdtab, cbuf); cbuf[cpos] = c; if (p != 0) { if (p->implemented == 0) { nack(p->name); longjmp(errcatch,0); /* NOTREACHED */ } state = p->state; *(char **)&ftplval = p->name; return (p->token); } break; case SITECMD: if (cbuf[cpos] == ' ') { cpos++; return (SP); } cp = &cbuf[cpos]; if ((cp2 = strpbrk(cp, " \n"))) cpos = cp2 - cbuf; c = cbuf[cpos]; cbuf[cpos] = '\0'; upper(cp); p = lookup(sitetab, cp); cbuf[cpos] = c; if (p != 0) { if (p->implemented == 0) { state = CMD; nack(p->name); longjmp(errcatch,0); /* NOTREACHED */ } state = p->state; *(char **)&ftplval = p->name; return (p->token); } state = CMD; break; case OSTR: if (cbuf[cpos] == '\n') { state = CMD; return (CRLF); } /* FALLTHROUGH */ case STR1: case ZSTR1: dostr1: if (cbuf[cpos] == ' ') { cpos++; state = state == OSTR ? STR2 : ++state; return (SP); } break; case ZSTR2: if (cbuf[cpos] == '\n') { state = CMD; return (CRLF); } /* FALLTHROUGH */ case STR2: cp = &cbuf[cpos]; n = strlen(cp); cpos += n - 1; /* * Make sure the string is nonempty and \n terminated. */ if (n > 1 && cbuf[cpos] == '\n') { cbuf[cpos] = '\0'; *(char **)&ftplval = copy(cp); cbuf[cpos] = '\n'; state = ARGS; return (STRING); } break; case NSTR: if (cbuf[cpos] == ' ') { cpos++; return (SP); } if (isdigit(cbuf[cpos])) { cp = &cbuf[cpos]; while (isdigit(cbuf[++cpos])) ; c = cbuf[cpos]; cbuf[cpos] = '\0'; ftplval = atoi(cp); cbuf[cpos] = c; state = STR1; return (NUMBER); } state = STR1; goto dostr1; case ARGS: if (isdigit(cbuf[cpos])) { cp = &cbuf[cpos]; while (isdigit(cbuf[++cpos])) ; c = cbuf[cpos]; cbuf[cpos] = '\0'; ftplval = atoi(cp); cbuf[cpos] = c; return (NUMBER); } switch (cbuf[cpos++]) { case '\n': state = CMD; return (CRLF); case ' ': return (SP); case ',': return (COMMA); case 'A': case 'a': return (A); case 'B': case 'b': return (B); case 'C': case 'c': return (C); case 'E': case 'e': return (E); case 'F': case 'f': return (F); case 'I': case 'i': return (I); case 'L': case 'l': return (L); case 'N': case 'n': return (N); case 'P': case 'p': return (P); case 'R': case 'r': return (R); case 'S': case 's': return (S); case 'T': case 't': return (T); } break; default: fatal("Unknown state in scanner."); } ftperror((char *) 0); state = CMD; longjmp(errcatch,0); } } upper(s) register char *s; { while (*s != '\0') { if (islower(*s)) *s = toupper(*s); s++; } } char * copy(s) char *s; { char *p; extern char *malloc(), *strcpy(); p = malloc((unsigned) strlen(s) + 1); if (p == NULL) fatal("Ran out of memory."); (void) strcpy(p, s); return (p); } help(ctab, s) struct tab *ctab; char *s; { register struct tab *c; register int width, NCMDS; char *type; if (ctab == sitetab) type = "SITE "; else type = ""; width = 0, NCMDS = 0; for (c = ctab; c->name != NULL; c++) { int len = strlen(c->name); if (len > width) width = len; NCMDS++; } width = (width + 8) &~ 7; if (s == 0) { register int i, j, w; int columns, lines; lreply(214, "The following %scommands are recognized %s.", type, "(* =>'s unimplemented)"); columns = 76 / width; if (columns == 0) columns = 1; lines = (NCMDS + columns - 1) / columns; for (i = 0; i < lines; i++) { printf(" "); for (j = 0; j < columns; j++) { c = ctab + j * lines + i; printf("%s%c", c->name, c->implemented ? ' ' : '*'); if (c + lines >= &ctab[NCMDS]) break; w = strlen(c->name) + 1; while (w < width) { putchar(' '); w++; } } printf("\r\n"); } (void) fflush(stdout); reply(214, "Direct comments to ftp-bugs@%s.", hostname); return; } upper(s); c = lookup(ctab, s); if (c == (struct tab *)0) { reply(502, "Unknown command %s.", s); return; } if (c->implemented) reply(214, "Syntax: %s%s %s", type, c->name, c->help); else reply(214, "%s%-*s\t%s; unimplemented.", type, width, c->name, c->help); } sizecmd(filename) char *filename; { switch (type) { case TYPE_L: case TYPE_I: { struct stat stbuf; if (stat(filename, &stbuf) < 0 || (stbuf.st_mode&S_IFMT) != S_IFREG) reply(550, "%s: not a plain file.", filename); else reply(213, "%lu", stbuf.st_size); break;} case TYPE_A: { FILE *fin; register int c, count; struct stat stbuf; fin = fopen(filename, "r"); if (fin == NULL) { perror_reply(550, filename); return; } if (fstat(fileno(fin), &stbuf) < 0 || (stbuf.st_mode&S_IFMT) != S_IFREG) { reply(550, "%s: not a plain file.", filename); (void) fclose(fin); return; } count = 0; while((c=getc(fin)) != EOF) { if (c == '\n') /* will get expanded to \r\n */ count++; count++; } (void) fclose(fin); reply(213, "%ld", count); break;} default: reply(504, "SIZE not implemented for Type %c.", "?AEIL"[type]); } } #line 905 "ftp.tab.c" #define FTPABORT goto ftpabort #define FTPACCEPT goto ftpaccept #define FTPERROR goto ftperrlab int ftpparse() { register int ftpm, ftpn, ftpstate; #if FTPDEBUG register char *ftps; extern char *getenv(); if (ftps = getenv("FTPDEBUG")) { ftpn = *ftps; if (ftpn >= '0' && ftpn <= '9') ftpdebug = ftpn - '0'; } #endif ftpnerrs = 0; ftperrflag = 0; ftpchar = (-1); ftpssp = ftpss; ftpvsp = ftpvs; *ftpssp = ftpstate = 0; ftploop: if (ftpn = ftpdefred[ftpstate]) goto ftpreduce; if (ftpchar < 0) { if ((ftpchar = ftplex()) < 0) ftpchar = 0; #if FTPDEBUG if (ftpdebug) { ftps = 0; if (ftpchar <= FTPMAXTOKEN) ftps = ftpname[ftpchar]; if (!ftps) ftps = "illegal-symbol"; printf("ftpdebug: state %d, reading %d (%s)\n", ftpstate, ftpchar, ftps); } #endif } if ((ftpn = ftpsindex[ftpstate]) && (ftpn += ftpchar) >= 0 && ftpn <= FTPTABLESIZE && ftpcheck[ftpn] == ftpchar) { #if FTPDEBUG if (ftpdebug) printf("ftpdebug: state %d, shifting to state %d\n", ftpstate, ftptable[ftpn]); #endif if (ftpssp >= ftpss + ftpstacksize - 1) { goto ftpoverflow; } *++ftpssp = ftpstate = ftptable[ftpn]; *++ftpvsp = ftplval; ftpchar = (-1); if (ftperrflag > 0) --ftperrflag; goto ftploop; } if ((ftpn = ftprindex[ftpstate]) && (ftpn += ftpchar) >= 0 && ftpn <= FTPTABLESIZE && ftpcheck[ftpn] == ftpchar) { ftpn = ftptable[ftpn]; goto ftpreduce; } if (ftperrflag) goto ftpinrecovery; #ifdef lint goto ftpnewerror; #endif ftpnewerror: ftperror("syntax error"); #ifdef lint goto ftperrlab; #endif ftperrlab: ++ftpnerrs; ftpinrecovery: if (ftperrflag < 3) { ftperrflag = 3; for (;;) { if ((ftpn = ftpsindex[*ftpssp]) && (ftpn += FTPERRCODE) >= 0 && ftpn <= FTPTABLESIZE && ftpcheck[ftpn] == FTPERRCODE) { #if FTPDEBUG if (ftpdebug) printf("ftpdebug: state %d, error recovery shifting\ to state %d\n", *ftpssp, ftptable[ftpn]); #endif if (ftpssp >= ftpss + ftpstacksize - 1) { goto ftpoverflow; } *++ftpssp = ftpstate = ftptable[ftpn]; *++ftpvsp = ftplval; goto ftploop; } else { #if FTPDEBUG if (ftpdebug) printf("ftpdebug: error recovery discarding state %d\n", *ftpssp); #endif if (ftpssp <= ftpss) goto ftpabort; --ftpssp; --ftpvsp; } } } else { if (ftpchar == 0) goto ftpabort; #if FTPDEBUG if (ftpdebug) { ftps = 0; if (ftpchar <= FTPMAXTOKEN) ftps = ftpname[ftpchar]; if (!ftps) ftps = "illegal-symbol"; printf("ftpdebug: state %d, error recovery discards token %d (%s)\n", ftpstate, ftpchar, ftps); } #endif ftpchar = (-1); goto ftploop; } ftpreduce: #if FTPDEBUG if (ftpdebug) printf("ftpdebug: state %d, reducing by rule %d (%s)\n", ftpstate, ftpn, ftprule[ftpn]); #endif ftpm = ftplen[ftpn]; ftpval = ftpvsp[1-ftpm]; switch (ftpn) { case 2: #line 99 "ftp.y" { fromname = (char *) 0; } break; case 4: #line 106 "ftp.y" { user((char *) ftpvsp[-1]); free((char *) ftpvsp[-1]); } break; case 5: #line 111 "ftp.y" { pass((char *) ftpvsp[-1]); free((char *) ftpvsp[-1]); } break; case 6: #line 116 "ftp.y" { usedefault = 0; if (pdata >= 0) { (void) close(pdata); pdata = -1; } reply(200, "PORT command successful."); } break; case 7: #line 125 "ftp.y" { passive(); } break; case 8: #line 129 "ftp.y" { switch (cmd_type) { case TYPE_A: if (cmd_form == FORM_N) { reply(200, "Type set to A."); type = cmd_type; form = cmd_form; } else reply(504, "Form must be N."); break; case TYPE_E: reply(504, "Type E not implemented."); break; case TYPE_I: reply(200, "Type set to I."); type = cmd_type; break; case TYPE_L: #if NBBY == 8 if (cmd_bytesz == 8) { reply(200, "Type set to L (byte size 8)."); type = cmd_type; } else reply(504, "Byte size must be 8."); #else /* NBBY == 8 */ UNIMPLEMENTED for NBBY != 8 #endif /* NBBY == 8 */ } } break; case 9: #line 164 "ftp.y" { switch (ftpvsp[-1]) { case STRU_F: reply(200, "STRU F ok."); break; default: reply(504, "Unimplemented STRU type."); } } break; case 10: #line 176 "ftp.y" { switch (ftpvsp[-1]) { case MODE_S: reply(200, "MODE S ok."); break; default: reply(502, "Unimplemented MODE type."); } } break; case 11: #line 188 "ftp.y" { reply(202, "ALLO command ignored."); } break; case 12: #line 192 "ftp.y" { reply(202, "ALLO command ignored."); } break; case 13: #line 196 "ftp.y" { if (ftpvsp[-3] && ftpvsp[-1] != NULL) retrieve((char *) 0, (char *) ftpvsp[-1]); if (ftpvsp[-1] != NULL) free((char *) ftpvsp[-1]); } break; case 14: #line 203 "ftp.y" { if (ftpvsp[-3] && ftpvsp[-1] != NULL) store((char *) ftpvsp[-1], "w", 0); if (ftpvsp[-1] != NULL) free((char *) ftpvsp[-1]); } break; case 15: #line 210 "ftp.y" { if (ftpvsp[-3] && ftpvsp[-1] != NULL) store((char *) ftpvsp[-1], "a", 0); if (ftpvsp[-1] != NULL) free((char *) ftpvsp[-1]); } break; case 16: #line 217 "ftp.y" { if (ftpvsp[-1]) send_file_list("."); } break; case 17: #line 222 "ftp.y" { if (ftpvsp[-3] && ftpvsp[-1] != NULL) send_file_list((char *) ftpvsp[-1]); if (ftpvsp[-1] != NULL) free((char *) ftpvsp[-1]); } break; case 18: #line 229 "ftp.y" { if (ftpvsp[-1]) retrieve("/bin/ls -lgA", ""); } break; case 19: #line 234 "ftp.y" { if (ftpvsp[-3] && ftpvsp[-1] != NULL) retrieve("/bin/ls -lgA %s", (char *) ftpvsp[-1]); if (ftpvsp[-1] != NULL) free((char *) ftpvsp[-1]); } break; case 20: #line 241 "ftp.y" { if (ftpvsp[-3] && ftpvsp[-1] != NULL) statfilecmd((char *) ftpvsp[-1]); if (ftpvsp[-1] != NULL) free((char *) ftpvsp[-1]); } break; case 21: #line 248 "ftp.y" { statcmd(); } break; case 22: #line 252 "ftp.y" { if (ftpvsp[-3] && ftpvsp[-1] != NULL) delete((char *) ftpvsp[-1]); if (ftpvsp[-1] != NULL) free((char *) ftpvsp[-1]); } break; case 23: #line 259 "ftp.y" { if (fromname) { renamecmd(fromname, (char *) ftpvsp[-1]); free(fromname); fromname = (char *) 0; } else { reply(503, "Bad sequence of commands."); } free((char *) ftpvsp[-1]); } break; case 24: #line 270 "ftp.y" { reply(225, "ABOR command successful."); } break; case 25: #line 274 "ftp.y" { if (ftpvsp[-1]) cwd(pw->pw_dir); } break; case 26: #line 279 "ftp.y" { if (ftpvsp[-3] && ftpvsp[-1] != NULL) cwd((char *) ftpvsp[-1]); if (ftpvsp[-1] != NULL) free((char *) ftpvsp[-1]); } break; case 27: #line 286 "ftp.y" { help(cmdtab, (char *) 0); } break; case 28: #line 290 "ftp.y" { register char *cp = (char *)ftpvsp[-1]; if (strncasecmp(cp, "SITE", 4) == 0) { cp = (char *)ftpvsp[-1] + 4; if (*cp == ' ') cp++; if (*cp) help(sitetab, cp); else help(sitetab, (char *) 0); } else help(cmdtab, (char *) ftpvsp[-1]); } break; case 29: #line 305 "ftp.y" { reply(200, "NOOP command successful."); } break; case 30: #line 309 "ftp.y" { if (ftpvsp[-3] && ftpvsp[-1] != NULL) makedir((char *) ftpvsp[-1]); if (ftpvsp[-1] != NULL) free((char *) ftpvsp[-1]); } break; case 31: #line 316 "ftp.y" { if (ftpvsp[-3] && ftpvsp[-1] != NULL) removedir((char *) ftpvsp[-1]); if (ftpvsp[-1] != NULL) free((char *) ftpvsp[-1]); } break; case 32: #line 323 "ftp.y" { if (ftpvsp[-1]) pwd(); } break; case 33: #line 328 "ftp.y" { if (ftpvsp[-1]) cwd(".."); } break; case 34: #line 333 "ftp.y" { help(sitetab, (char *) 0); } break; case 35: #line 337 "ftp.y" { help(sitetab, (char *) ftpvsp[-1]); } break; case 36: #line 341 "ftp.y" { int oldmask; if (ftpvsp[-1]) { oldmask = umask(0); (void) umask(oldmask); reply(200, "Current UMASK is %03o", oldmask); } } break; case 37: #line 351 "ftp.y" { int oldmask; if (ftpvsp[-3]) { if ((ftpvsp[-1] == -1) || (ftpvsp[-1] > 0777)) { reply(501, "Bad UMASK value"); } else { oldmask = umask(ftpvsp[-1]); reply(200, "UMASK set to %03o (was %03o)", ftpvsp[-1], oldmask); } } } break; case 38: #line 366 "ftp.y" { if (ftpvsp[-5] && (ftpvsp[-1] != NULL)) { if (ftpvsp[-3] > 0777) reply(501, "CHMOD: Mode value must be between 0 and 0777"); else if (chmod((char *) ftpvsp[-1], ftpvsp[-3]) < 0) perror_reply(550, (char *) ftpvsp[-1]); else reply(200, "CHMOD command successful."); } if (ftpvsp[-1] != NULL) free((char *) ftpvsp[-1]); } break; case 39: #line 380 "ftp.y" { reply(200, "Current IDLE time limit is %d seconds; max %d", timeout, maxtimeout); } break; case 40: #line 386 "ftp.y" { if (ftpvsp[-1] < 30 || ftpvsp[-1] > maxtimeout) { reply(501, "Maximum IDLE time must be between 30 and %d seconds", maxtimeout); } else { timeout = ftpvsp[-1]; (void) alarm((unsigned) timeout); reply(200, "Maximum IDLE time set to %d seconds", timeout); } } break; case 41: #line 400 "ftp.y" { if (ftpvsp[-3] && ftpvsp[-1] != NULL) store((char *) ftpvsp[-1], "w", 1); if (ftpvsp[-1] != NULL) free((char *) ftpvsp[-1]); } break; case 42: #line 407 "ftp.y" { #ifdef unix #ifdef BSD reply(215, "UNIX Type: L%d Version: BSD-%d", NBBY, BSD); #else /* BSD */ reply(215, "UNIX Type: L%d", NBBY); #endif /* BSD */ #else /* unix */ reply(215, "UNKNOWN Type: L%d", NBBY); #endif /* unix */ } break; case 43: #line 428 "ftp.y" { if (ftpvsp[-3] && ftpvsp[-1] != NULL) sizecmd((char *) ftpvsp[-1]); if (ftpvsp[-1] != NULL) free((char *) ftpvsp[-1]); } break; case 44: #line 445 "ftp.y" { if (ftpvsp[-3] && ftpvsp[-1] != NULL) { struct stat stbuf; if (stat((char *) ftpvsp[-1], &stbuf) < 0) perror_reply(550, "%s", (char *) ftpvsp[-1]); else if ((stbuf.st_mode&S_IFMT) != S_IFREG) { reply(550, "%s: not a plain file.", (char *) ftpvsp[-1]); } else { register struct tm *t; struct tm *gmtime(); t = gmtime(&stbuf.st_mtime); reply(213, "19%02d%02d%02d%02d%02d%02d", t->tm_year, t->tm_mon+1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec); } } if (ftpvsp[-1] != NULL) free((char *) ftpvsp[-1]); } break; case 45: #line 467 "ftp.y" { reply(221, "Goodbye."); dologout(0); } break; case 46: #line 472 "ftp.y" { ftperrok; } break; case 47: #line 477 "ftp.y" { char *renamefrom(); if (ftpvsp[-3] && ftpvsp[-1]) { fromname = renamefrom((char *) ftpvsp[-1]); if (fromname == (char *) 0 && ftpvsp[-1]) { free((char *) ftpvsp[-1]); } } } break; case 49: #line 493 "ftp.y" { *(char **)&(ftpval) = ""; } break; case 52: #line 504 "ftp.y" { register char *a, *p; a = (char *)&data_dest.sin_addr; a[0] = ftpvsp[-10]; a[1] = ftpvsp[-8]; a[2] = ftpvsp[-6]; a[3] = ftpvsp[-4]; p = (char *)&data_dest.sin_port; p[0] = ftpvsp[-2]; p[1] = ftpvsp[0]; data_dest.sin_family = AF_INET; } break; case 53: #line 516 "ftp.y" { ftpval = FORM_N; } break; case 54: #line 520 "ftp.y" { ftpval = FORM_T; } break; case 55: #line 524 "ftp.y" { ftpval = FORM_C; } break; case 56: #line 530 "ftp.y" { cmd_type = TYPE_A; cmd_form = FORM_N; } break; case 57: #line 535 "ftp.y" { cmd_type = TYPE_A; cmd_form = ftpvsp[0]; } break; case 58: #line 540 "ftp.y" { cmd_type = TYPE_E; cmd_form = FORM_N; } break; case 59: #line 545 "ftp.y" { cmd_type = TYPE_E; cmd_form = ftpvsp[0]; } break; case 60: #line 550 "ftp.y" { cmd_type = TYPE_I; } break; case 61: #line 554 "ftp.y" { cmd_type = TYPE_L; cmd_bytesz = NBBY; } break; case 62: #line 559 "ftp.y" { cmd_type = TYPE_L; cmd_bytesz = ftpvsp[0]; } break; case 63: #line 565 "ftp.y" { cmd_type = TYPE_L; cmd_bytesz = ftpvsp[0]; } break; case 64: #line 572 "ftp.y" { ftpval = STRU_F; } break; case 65: #line 576 "ftp.y" { ftpval = STRU_R; } break; case 66: #line 580 "ftp.y" { ftpval = STRU_P; } break; case 67: #line 586 "ftp.y" { ftpval = MODE_S; } break; case 68: #line 590 "ftp.y" { ftpval = MODE_B; } break; case 69: #line 594 "ftp.y" { ftpval = MODE_C; } break; case 70: #line 600 "ftp.y" { /* * Problem: this production is used for all pathname * processing, but only gives a 550 error reply. * This is a valid reply in some cases but not in others. */ if (logged_in && ftpvsp[0] && strncmp((char *) ftpvsp[0], "~", 1) == 0) { *(char **)&(ftpval) = *glob((char *) ftpvsp[0]); if (globerr != NULL) { reply(550, globerr); ftpval = NULL; } free((char *) ftpvsp[0]); } else ftpval = ftpvsp[0]; } break; case 72: #line 622 "ftp.y" { register int ret, dec, multby, digit; /* * Convert a number that was read as decimal number * to what it would be if it had been read as octal. */ dec = ftpvsp[0]; multby = 1; ret = 0; while (dec) { digit = dec%10; if (digit > 7) { ret = -1; break; } ret += digit * multby; multby *= 8; dec /= 10; } ftpval = ret; } break; case 73: #line 647 "ftp.y" { if (logged_in) ftpval = 1; else { reply(530, "Please login with USER and PASS."); ftpval = 0; } } break; #line 1684 "ftp.tab.c" } ftpssp -= ftpm; ftpstate = *ftpssp; ftpvsp -= ftpm; ftpm = ftplhs[ftpn]; if (ftpstate == 0 && ftpm == 0) { #if FTPDEBUG if (ftpdebug) printf("ftpdebug: after reduction, shifting from state 0 to\ state %d\n", FTPFINAL); #endif ftpstate = FTPFINAL; *++ftpssp = FTPFINAL; *++ftpvsp = ftpval; if (ftpchar < 0) { if ((ftpchar = ftplex()) < 0) ftpchar = 0; #if FTPDEBUG if (ftpdebug) { ftps = 0; if (ftpchar <= FTPMAXTOKEN) ftps = ftpname[ftpchar]; if (!ftps) ftps = "illegal-symbol"; printf("ftpdebug: state %d, reading %d (%s)\n", FTPFINAL, ftpchar, ftps); } #endif } if (ftpchar == 0) goto ftpaccept; goto ftploop; } if ((ftpn = ftpgindex[ftpm]) && (ftpn += ftpstate) >= 0 && ftpn <= FTPTABLESIZE && ftpcheck[ftpn] == ftpstate) ftpstate = ftptable[ftpn]; else ftpstate = ftpdgoto[ftpm]; #if FTPDEBUG if (ftpdebug) printf("ftpdebug: after reduction, shifting from state %d \ to state %d\n", *ftpssp, ftpstate); #endif if (ftpssp >= ftpss + ftpstacksize - 1) { goto ftpoverflow; } *++ftpssp = ftpstate; *++ftpvsp = ftpval; goto ftploop; ftpoverflow: ftperror("yacc stack overflow"); ftpabort: return (1); ftpaccept: return (0); } perl-byacc-2.0.orig/test/calc.output100644 1750 1750 55261 5224473064 16340 0ustar bortzbortz 0 $accept : stmt_list $end 1 stmt_list : 2 | stmt_list stmt 3 stmt : terminator 4 | expr terminator 5 | error terminator 6 terminator : ';' 7 | '\n' 8 expr : '(' expr ')' 9 | expr '|' expr 10 | expr '&' expr 11 | expr EQ expr 12 | expr NE expr 13 | expr GT expr 14 | expr GE expr 15 | expr LT expr 16 | expr LE expr 17 | expr L_SHIFT expr 18 | expr R_SHIFT expr 19 | expr '+' expr 20 | expr '-' expr 21 | expr '*' expr 22 | expr '/' expr 23 | expr EXP expr 24 | expr '!' 25 | '-' expr 26 | '!' expr 27 | '+' expr 28 | '&' STRING 29 | IDENT '=' expr 30 | IDENT 31 | INT 32 | FLOAT 33 | STRING 34 | '%' state 0 $accept : . stmt_list $end (0) stmt_list : . (1) . reduce 1 stmt_list goto 1 state 1 $accept : stmt_list . $end (0) stmt_list : stmt_list . stmt (2) $end accept error shift 2 INT shift 3 FLOAT shift 4 STRING shift 5 IDENT shift 6 '&' shift 7 '+' shift 8 '-' shift 9 '!' shift 10 ';' shift 11 '\n' shift 12 '(' shift 13 '%' shift 14 . error stmt goto 15 terminator goto 16 expr goto 17 state 2 stmt : error . terminator (5) ';' shift 11 '\n' shift 12 . error terminator goto 18 state 3 expr : INT . (31) . reduce 31 state 4 expr : FLOAT . (32) . reduce 32 state 5 expr : STRING . (33) . reduce 33 state 6 expr : IDENT . '=' expr (29) expr : IDENT . (30) '=' shift 19 '|' reduce 30 '&' reduce 30 EQ reduce 30 NE reduce 30 GT reduce 30 GE reduce 30 LT reduce 30 LE reduce 30 L_SHIFT reduce 30 R_SHIFT reduce 30 '+' reduce 30 '-' reduce 30 '*' reduce 30 '/' reduce 30 EXP reduce 30 '!' reduce 30 ';' reduce 30 '\n' reduce 30 ')' reduce 30 state 7 expr : '&' . STRING (28) STRING shift 20 . error state 8 expr : '+' . expr (27) INT shift 3 FLOAT shift 4 STRING shift 5 IDENT shift 6 '&' shift 7 '+' shift 8 '-' shift 9 '!' shift 10 '(' shift 13 '%' shift 14 . error expr goto 21 state 9 expr : '-' . expr (25) INT shift 3 FLOAT shift 4 STRING shift 5 IDENT shift 6 '&' shift 7 '+' shift 8 '-' shift 9 '!' shift 10 '(' shift 13 '%' shift 14 . error expr goto 22 state 10 expr : '!' . expr (26) INT shift 3 FLOAT shift 4 STRING shift 5 IDENT shift 6 '&' shift 7 '+' shift 8 '-' shift 9 '!' shift 10 '(' shift 13 '%' shift 14 . error expr goto 23 state 11 terminator : ';' . (6) . reduce 6 state 12 terminator : '\n' . (7) . reduce 7 state 13 expr : '(' . expr ')' (8) INT shift 3 FLOAT shift 4 STRING shift 5 IDENT shift 6 '&' shift 7 '+' shift 8 '-' shift 9 '!' shift 10 '(' shift 13 '%' shift 14 . error expr goto 24 state 14 expr : '%' . (34) . reduce 34 state 15 stmt_list : stmt_list stmt . (2) . reduce 2 state 16 stmt : terminator . (3) . reduce 3 state 17 stmt : expr . terminator (4) expr : expr . '|' expr (9) expr : expr . '&' expr (10) expr : expr . EQ expr (11) expr : expr . NE expr (12) expr : expr . GT expr (13) expr : expr . GE expr (14) expr : expr . LT expr (15) expr : expr . LE expr (16) expr : expr . L_SHIFT expr (17) expr : expr . R_SHIFT expr (18) expr : expr . '+' expr (19) expr : expr . '-' expr (20) expr : expr . '*' expr (21) expr : expr . '/' expr (22) expr : expr . EXP expr (23) expr : expr . '!' (24) '|' shift 25 '&' shift 26 EQ shift 27 NE shift 28 GT shift 29 GE shift 30 LT shift 31 LE shift 32 L_SHIFT shift 33 R_SHIFT shift 34 '+' shift 35 '-' shift 36 '*' shift 37 '/' shift 38 EXP shift 39 '!' shift 40 ';' shift 11 '\n' shift 12 . error terminator goto 41 state 18 stmt : error terminator . (5) . reduce 5 state 19 expr : IDENT '=' . expr (29) INT shift 3 FLOAT shift 4 STRING shift 5 IDENT shift 6 '&' shift 7 '+' shift 8 '-' shift 9 '!' shift 10 '(' shift 13 '%' shift 14 . error expr goto 42 state 20 expr : '&' STRING . (28) . reduce 28 state 21 expr : expr . '|' expr (9) expr : expr . '&' expr (10) expr : expr . EQ expr (11) expr : expr . NE expr (12) expr : expr . GT expr (13) expr : expr . GE expr (14) expr : expr . LT expr (15) expr : expr . LE expr (16) expr : expr . L_SHIFT expr (17) expr : expr . R_SHIFT expr (18) expr : expr . '+' expr (19) expr : expr . '-' expr (20) expr : expr . '*' expr (21) expr : expr . '/' expr (22) expr : expr . EXP expr (23) expr : expr . '!' (24) expr : '+' expr . (27) . reduce 27 state 22 expr : expr . '|' expr (9) expr : expr . '&' expr (10) expr : expr . EQ expr (11) expr : expr . NE expr (12) expr : expr . GT expr (13) expr : expr . GE expr (14) expr : expr . LT expr (15) expr : expr . LE expr (16) expr : expr . L_SHIFT expr (17) expr : expr . R_SHIFT expr (18) expr : expr . '+' expr (19) expr : expr . '-' expr (20) expr : expr . '*' expr (21) expr : expr . '/' expr (22) expr : expr . EXP expr (23) expr : expr . '!' (24) expr : '-' expr . (25) . reduce 25 state 23 expr : expr . '|' expr (9) expr : expr . '&' expr (10) expr : expr . EQ expr (11) expr : expr . NE expr (12) expr : expr . GT expr (13) expr : expr . GE expr (14) expr : expr . LT expr (15) expr : expr . LE expr (16) expr : expr . L_SHIFT expr (17) expr : expr . R_SHIFT expr (18) expr : expr . '+' expr (19) expr : expr . '-' expr (20) expr : expr . '*' expr (21) expr : expr . '/' expr (22) expr : expr . EXP expr (23) expr : expr . '!' (24) expr : '!' expr . (26) . reduce 26 state 24 expr : '(' expr . ')' (8) expr : expr . '|' expr (9) expr : expr . '&' expr (10) expr : expr . EQ expr (11) expr : expr . NE expr (12) expr : expr . GT expr (13) expr : expr . GE expr (14) expr : expr . LT expr (15) expr : expr . LE expr (16) expr : expr . L_SHIFT expr (17) expr : expr . R_SHIFT expr (18) expr : expr . '+' expr (19) expr : expr . '-' expr (20) expr : expr . '*' expr (21) expr : expr . '/' expr (22) expr : expr . EXP expr (23) expr : expr . '!' (24) '|' shift 25 '&' shift 26 EQ shift 27 NE shift 28 GT shift 29 GE shift 30 LT shift 31 LE shift 32 L_SHIFT shift 33 R_SHIFT shift 34 '+' shift 35 '-' shift 36 '*' shift 37 '/' shift 38 EXP shift 39 '!' shift 40 ')' shift 43 . error state 25 expr : expr '|' . expr (9) INT shift 3 FLOAT shift 4 STRING shift 5 IDENT shift 6 '&' shift 7 '+' shift 8 '-' shift 9 '!' shift 10 '(' shift 13 '%' shift 14 . error expr goto 44 state 26 expr : expr '&' . expr (10) INT shift 3 FLOAT shift 4 STRING shift 5 IDENT shift 6 '&' shift 7 '+' shift 8 '-' shift 9 '!' shift 10 '(' shift 13 '%' shift 14 . error expr goto 45 state 27 expr : expr EQ . expr (11) INT shift 3 FLOAT shift 4 STRING shift 5 IDENT shift 6 '&' shift 7 '+' shift 8 '-' shift 9 '!' shift 10 '(' shift 13 '%' shift 14 . error expr goto 46 state 28 expr : expr NE . expr (12) INT shift 3 FLOAT shift 4 STRING shift 5 IDENT shift 6 '&' shift 7 '+' shift 8 '-' shift 9 '!' shift 10 '(' shift 13 '%' shift 14 . error expr goto 47 state 29 expr : expr GT . expr (13) INT shift 3 FLOAT shift 4 STRING shift 5 IDENT shift 6 '&' shift 7 '+' shift 8 '-' shift 9 '!' shift 10 '(' shift 13 '%' shift 14 . error expr goto 48 state 30 expr : expr GE . expr (14) INT shift 3 FLOAT shift 4 STRING shift 5 IDENT shift 6 '&' shift 7 '+' shift 8 '-' shift 9 '!' shift 10 '(' shift 13 '%' shift 14 . error expr goto 49 state 31 expr : expr LT . expr (15) INT shift 3 FLOAT shift 4 STRING shift 5 IDENT shift 6 '&' shift 7 '+' shift 8 '-' shift 9 '!' shift 10 '(' shift 13 '%' shift 14 . error expr goto 50 state 32 expr : expr LE . expr (16) INT shift 3 FLOAT shift 4 STRING shift 5 IDENT shift 6 '&' shift 7 '+' shift 8 '-' shift 9 '!' shift 10 '(' shift 13 '%' shift 14 . error expr goto 51 state 33 expr : expr L_SHIFT . expr (17) INT shift 3 FLOAT shift 4 STRING shift 5 IDENT shift 6 '&' shift 7 '+' shift 8 '-' shift 9 '!' shift 10 '(' shift 13 '%' shift 14 . error expr goto 52 state 34 expr : expr R_SHIFT . expr (18) INT shift 3 FLOAT shift 4 STRING shift 5 IDENT shift 6 '&' shift 7 '+' shift 8 '-' shift 9 '!' shift 10 '(' shift 13 '%' shift 14 . error expr goto 53 state 35 expr : expr '+' . expr (19) INT shift 3 FLOAT shift 4 STRING shift 5 IDENT shift 6 '&' shift 7 '+' shift 8 '-' shift 9 '!' shift 10 '(' shift 13 '%' shift 14 . error expr goto 54 state 36 expr : expr '-' . expr (20) INT shift 3 FLOAT shift 4 STRING shift 5 IDENT shift 6 '&' shift 7 '+' shift 8 '-' shift 9 '!' shift 10 '(' shift 13 '%' shift 14 . error expr goto 55 state 37 expr : expr '*' . expr (21) INT shift 3 FLOAT shift 4 STRING shift 5 IDENT shift 6 '&' shift 7 '+' shift 8 '-' shift 9 '!' shift 10 '(' shift 13 '%' shift 14 . error expr goto 56 state 38 expr : expr '/' . expr (22) INT shift 3 FLOAT shift 4 STRING shift 5 IDENT shift 6 '&' shift 7 '+' shift 8 '-' shift 9 '!' shift 10 '(' shift 13 '%' shift 14 . error expr goto 57 state 39 expr : expr EXP . expr (23) INT shift 3 FLOAT shift 4 STRING shift 5 IDENT shift 6 '&' shift 7 '+' shift 8 '-' shift 9 '!' shift 10 '(' shift 13 '%' shift 14 . error expr goto 58 state 40 expr : expr '!' . (24) . reduce 24 state 41 stmt : expr terminator . (4) . reduce 4 state 42 expr : expr . '|' expr (9) expr : expr . '&' expr (10) expr : expr . EQ expr (11) expr : expr . NE expr (12) expr : expr . GT expr (13) expr : expr . GE expr (14) expr : expr . LT expr (15) expr : expr . LE expr (16) expr : expr . L_SHIFT expr (17) expr : expr . R_SHIFT expr (18) expr : expr . '+' expr (19) expr : expr . '-' expr (20) expr : expr . '*' expr (21) expr : expr . '/' expr (22) expr : expr . EXP expr (23) expr : expr . '!' (24) expr : IDENT '=' expr . (29) '|' shift 25 '&' shift 26 EQ shift 27 NE shift 28 GT shift 29 GE shift 30 LT shift 31 LE shift 32 L_SHIFT shift 33 R_SHIFT shift 34 '+' shift 35 '-' shift 36 '*' shift 37 '/' shift 38 EXP shift 39 '!' shift 40 ';' reduce 29 '\n' reduce 29 ')' reduce 29 state 43 expr : '(' expr ')' . (8) . reduce 8 state 44 expr : expr . '|' expr (9) expr : expr '|' expr . (9) expr : expr . '&' expr (10) expr : expr . EQ expr (11) expr : expr . NE expr (12) expr : expr . GT expr (13) expr : expr . GE expr (14) expr : expr . LT expr (15) expr : expr . LE expr (16) expr : expr . L_SHIFT expr (17) expr : expr . R_SHIFT expr (18) expr : expr . '+' expr (19) expr : expr . '-' expr (20) expr : expr . '*' expr (21) expr : expr . '/' expr (22) expr : expr . EXP expr (23) expr : expr . '!' (24) '&' shift 26 EQ shift 27 NE shift 28 GT shift 29 GE shift 30 LT shift 31 LE shift 32 L_SHIFT shift 33 R_SHIFT shift 34 '+' shift 35 '-' shift 36 '*' shift 37 '/' shift 38 EXP shift 39 '!' shift 40 '|' reduce 9 ';' reduce 9 '\n' reduce 9 ')' reduce 9 state 45 expr : expr . '|' expr (9) expr : expr . '&' expr (10) expr : expr '&' expr . (10) expr : expr . EQ expr (11) expr : expr . NE expr (12) expr : expr . GT expr (13) expr : expr . GE expr (14) expr : expr . LT expr (15) expr : expr . LE expr (16) expr : expr . L_SHIFT expr (17) expr : expr . R_SHIFT expr (18) expr : expr . '+' expr (19) expr : expr . '-' expr (20) expr : expr . '*' expr (21) expr : expr . '/' expr (22) expr : expr . EXP expr (23) expr : expr . '!' (24) EQ shift 27 NE shift 28 GT shift 29 GE shift 30 LT shift 31 LE shift 32 L_SHIFT shift 33 R_SHIFT shift 34 '+' shift 35 '-' shift 36 '*' shift 37 '/' shift 38 EXP shift 39 '!' shift 40 '|' reduce 10 '&' reduce 10 ';' reduce 10 '\n' reduce 10 ')' reduce 10 state 46 expr : expr . '|' expr (9) expr : expr . '&' expr (10) expr : expr . EQ expr (11) expr : expr EQ expr . (11) expr : expr . NE expr (12) expr : expr . GT expr (13) expr : expr . GE expr (14) expr : expr . LT expr (15) expr : expr . LE expr (16) expr : expr . L_SHIFT expr (17) expr : expr . R_SHIFT expr (18) expr : expr . '+' expr (19) expr : expr . '-' expr (20) expr : expr . '*' expr (21) expr : expr . '/' expr (22) expr : expr . EXP expr (23) expr : expr . '!' (24) GT shift 29 GE shift 30 LT shift 31 LE shift 32 L_SHIFT shift 33 R_SHIFT shift 34 '+' shift 35 '-' shift 36 '*' shift 37 '/' shift 38 EXP shift 39 '!' shift 40 '|' reduce 11 '&' reduce 11 EQ reduce 11 NE reduce 11 ';' reduce 11 '\n' reduce 11 ')' reduce 11 state 47 expr : expr . '|' expr (9) expr : expr . '&' expr (10) expr : expr . EQ expr (11) expr : expr . NE expr (12) expr : expr NE expr . (12) expr : expr . GT expr (13) expr : expr . GE expr (14) expr : expr . LT expr (15) expr : expr . LE expr (16) expr : expr . L_SHIFT expr (17) expr : expr . R_SHIFT expr (18) expr : expr . '+' expr (19) expr : expr . '-' expr (20) expr : expr . '*' expr (21) expr : expr . '/' expr (22) expr : expr . EXP expr (23) expr : expr . '!' (24) GT shift 29 GE shift 30 LT shift 31 LE shift 32 L_SHIFT shift 33 R_SHIFT shift 34 '+' shift 35 '-' shift 36 '*' shift 37 '/' shift 38 EXP shift 39 '!' shift 40 '|' reduce 12 '&' reduce 12 EQ reduce 12 NE reduce 12 ';' reduce 12 '\n' reduce 12 ')' reduce 12 state 48 expr : expr . '|' expr (9) expr : expr . '&' expr (10) expr : expr . EQ expr (11) expr : expr . NE expr (12) expr : expr . GT expr (13) expr : expr GT expr . (13) expr : expr . GE expr (14) expr : expr . LT expr (15) expr : expr . LE expr (16) expr : expr . L_SHIFT expr (17) expr : expr . R_SHIFT expr (18) expr : expr . '+' expr (19) expr : expr . '-' expr (20) expr : expr . '*' expr (21) expr : expr . '/' expr (22) expr : expr . EXP expr (23) expr : expr . '!' (24) L_SHIFT shift 33 R_SHIFT shift 34 '+' shift 35 '-' shift 36 '*' shift 37 '/' shift 38 EXP shift 39 '!' shift 40 '|' reduce 13 '&' reduce 13 EQ reduce 13 NE reduce 13 GT reduce 13 GE reduce 13 LT reduce 13 LE reduce 13 ';' reduce 13 '\n' reduce 13 ')' reduce 13 state 49 expr : expr . '|' expr (9) expr : expr . '&' expr (10) expr : expr . EQ expr (11) expr : expr . NE expr (12) expr : expr . GT expr (13) expr : expr . GE expr (14) expr : expr GE expr . (14) expr : expr . LT expr (15) expr : expr . LE expr (16) expr : expr . L_SHIFT expr (17) expr : expr . R_SHIFT expr (18) expr : expr . '+' expr (19) expr : expr . '-' expr (20) expr : expr . '*' expr (21) expr : expr . '/' expr (22) expr : expr . EXP expr (23) expr : expr . '!' (24) L_SHIFT shift 33 R_SHIFT shift 34 '+' shift 35 '-' shift 36 '*' shift 37 '/' shift 38 EXP shift 39 '!' shift 40 '|' reduce 14 '&' reduce 14 EQ reduce 14 NE reduce 14 GT reduce 14 GE reduce 14 LT reduce 14 LE reduce 14 ';' reduce 14 '\n' reduce 14 ')' reduce 14 state 50 expr : expr . '|' expr (9) expr : expr . '&' expr (10) expr : expr . EQ expr (11) expr : expr . NE expr (12) expr : expr . GT expr (13) expr : expr . GE expr (14) expr : expr . LT expr (15) expr : expr LT expr . (15) expr : expr . LE expr (16) expr : expr . L_SHIFT expr (17) expr : expr . R_SHIFT expr (18) expr : expr . '+' expr (19) expr : expr . '-' expr (20) expr : expr . '*' expr (21) expr : expr . '/' expr (22) expr : expr . EXP expr (23) expr : expr . '!' (24) L_SHIFT shift 33 R_SHIFT shift 34 '+' shift 35 '-' shift 36 '*' shift 37 '/' shift 38 EXP shift 39 '!' shift 40 '|' reduce 15 '&' reduce 15 EQ reduce 15 NE reduce 15 GT reduce 15 GE reduce 15 LT reduce 15 LE reduce 15 ';' reduce 15 '\n' reduce 15 ')' reduce 15 state 51 expr : expr . '|' expr (9) expr : expr . '&' expr (10) expr : expr . EQ expr (11) expr : expr . NE expr (12) expr : expr . GT expr (13) expr : expr . GE expr (14) expr : expr . LT expr (15) expr : expr . LE expr (16) expr : expr LE expr . (16) expr : expr . L_SHIFT expr (17) expr : expr . R_SHIFT expr (18) expr : expr . '+' expr (19) expr : expr . '-' expr (20) expr : expr . '*' expr (21) expr : expr . '/' expr (22) expr : expr . EXP expr (23) expr : expr . '!' (24) L_SHIFT shift 33 R_SHIFT shift 34 '+' shift 35 '-' shift 36 '*' shift 37 '/' shift 38 EXP shift 39 '!' shift 40 '|' reduce 16 '&' reduce 16 EQ reduce 16 NE reduce 16 GT reduce 16 GE reduce 16 LT reduce 16 LE reduce 16 ';' reduce 16 '\n' reduce 16 ')' reduce 16 state 52 expr : expr . '|' expr (9) expr : expr . '&' expr (10) expr : expr . EQ expr (11) expr : expr . NE expr (12) expr : expr . GT expr (13) expr : expr . GE expr (14) expr : expr . LT expr (15) expr : expr . LE expr (16) expr : expr . L_SHIFT expr (17) expr : expr L_SHIFT expr . (17) expr : expr . R_SHIFT expr (18) expr : expr . '+' expr (19) expr : expr . '-' expr (20) expr : expr . '*' expr (21) expr : expr . '/' expr (22) expr : expr . EXP expr (23) expr : expr . '!' (24) '+' shift 35 '-' shift 36 '*' shift 37 '/' shift 38 EXP shift 39 '!' shift 40 '|' reduce 17 '&' reduce 17 EQ reduce 17 NE reduce 17 GT reduce 17 GE reduce 17 LT reduce 17 LE reduce 17 L_SHIFT reduce 17 R_SHIFT reduce 17 ';' reduce 17 '\n' reduce 17 ')' reduce 17 state 53 expr : expr . '|' expr (9) expr : expr . '&' expr (10) expr : expr . EQ expr (11) expr : expr . NE expr (12) expr : expr . GT expr (13) expr : expr . GE expr (14) expr : expr . LT expr (15) expr : expr . LE expr (16) expr : expr . L_SHIFT expr (17) expr : expr . R_SHIFT expr (18) expr : expr R_SHIFT expr . (18) expr : expr . '+' expr (19) expr : expr . '-' expr (20) expr : expr . '*' expr (21) expr : expr . '/' expr (22) expr : expr . EXP expr (23) expr : expr . '!' (24) '+' shift 35 '-' shift 36 '*' shift 37 '/' shift 38 EXP shift 39 '!' shift 40 '|' reduce 18 '&' reduce 18 EQ reduce 18 NE reduce 18 GT reduce 18 GE reduce 18 LT reduce 18 LE reduce 18 L_SHIFT reduce 18 R_SHIFT reduce 18 ';' reduce 18 '\n' reduce 18 ')' reduce 18 state 54 expr : expr . '|' expr (9) expr : expr . '&' expr (10) expr : expr . EQ expr (11) expr : expr . NE expr (12) expr : expr . GT expr (13) expr : expr . GE expr (14) expr : expr . LT expr (15) expr : expr . LE expr (16) expr : expr . L_SHIFT expr (17) expr : expr . R_SHIFT expr (18) expr : expr . '+' expr (19) expr : expr '+' expr . (19) expr : expr . '-' expr (20) expr : expr . '*' expr (21) expr : expr . '/' expr (22) expr : expr . EXP expr (23) expr : expr . '!' (24) '*' shift 37 '/' shift 38 EXP shift 39 '!' shift 40 '|' reduce 19 '&' reduce 19 EQ reduce 19 NE reduce 19 GT reduce 19 GE reduce 19 LT reduce 19 LE reduce 19 L_SHIFT reduce 19 R_SHIFT reduce 19 '+' reduce 19 '-' reduce 19 ';' reduce 19 '\n' reduce 19 ')' reduce 19 state 55 expr : expr . '|' expr (9) expr : expr . '&' expr (10) expr : expr . EQ expr (11) expr : expr . NE expr (12) expr : expr . GT expr (13) expr : expr . GE expr (14) expr : expr . LT expr (15) expr : expr . LE expr (16) expr : expr . L_SHIFT expr (17) expr : expr . R_SHIFT expr (18) expr : expr . '+' expr (19) expr : expr . '-' expr (20) expr : expr '-' expr . (20) expr : expr . '*' expr (21) expr : expr . '/' expr (22) expr : expr . EXP expr (23) expr : expr . '!' (24) '*' shift 37 '/' shift 38 EXP shift 39 '!' shift 40 '|' reduce 20 '&' reduce 20 EQ reduce 20 NE reduce 20 GT reduce 20 GE reduce 20 LT reduce 20 LE reduce 20 L_SHIFT reduce 20 R_SHIFT reduce 20 '+' reduce 20 '-' reduce 20 ';' reduce 20 '\n' reduce 20 ')' reduce 20 state 56 expr : expr . '|' expr (9) expr : expr . '&' expr (10) expr : expr . EQ expr (11) expr : expr . NE expr (12) expr : expr . GT expr (13) expr : expr . GE expr (14) expr : expr . LT expr (15) expr : expr . LE expr (16) expr : expr . L_SHIFT expr (17) expr : expr . R_SHIFT expr (18) expr : expr . '+' expr (19) expr : expr . '-' expr (20) expr : expr . '*' expr (21) expr : expr '*' expr . (21) expr : expr . '/' expr (22) expr : expr . EXP expr (23) expr : expr . '!' (24) EXP shift 39 '!' shift 40 '|' reduce 21 '&' reduce 21 EQ reduce 21 NE reduce 21 GT reduce 21 GE reduce 21 LT reduce 21 LE reduce 21 L_SHIFT reduce 21 R_SHIFT reduce 21 '+' reduce 21 '-' reduce 21 '*' reduce 21 '/' reduce 21 ';' reduce 21 '\n' reduce 21 ')' reduce 21 state 57 expr : expr . '|' expr (9) expr : expr . '&' expr (10) expr : expr . EQ expr (11) expr : expr . NE expr (12) expr : expr . GT expr (13) expr : expr . GE expr (14) expr : expr . LT expr (15) expr : expr . LE expr (16) expr : expr . L_SHIFT expr (17) expr : expr . R_SHIFT expr (18) expr : expr . '+' expr (19) expr : expr . '-' expr (20) expr : expr . '*' expr (21) expr : expr . '/' expr (22) expr : expr '/' expr . (22) expr : expr . EXP expr (23) expr : expr . '!' (24) EXP shift 39 '!' shift 40 '|' reduce 22 '&' reduce 22 EQ reduce 22 NE reduce 22 GT reduce 22 GE reduce 22 LT reduce 22 LE reduce 22 L_SHIFT reduce 22 R_SHIFT reduce 22 '+' reduce 22 '-' reduce 22 '*' reduce 22 '/' reduce 22 ';' reduce 22 '\n' reduce 22 ')' reduce 22 state 58 expr : expr . '|' expr (9) expr : expr . '&' expr (10) expr : expr . EQ expr (11) expr : expr . NE expr (12) expr : expr . GT expr (13) expr : expr . GE expr (14) expr : expr . LT expr (15) expr : expr . LE expr (16) expr : expr . L_SHIFT expr (17) expr : expr . R_SHIFT expr (18) expr : expr . '+' expr (19) expr : expr . '-' expr (20) expr : expr . '*' expr (21) expr : expr . '/' expr (22) expr : expr . EXP expr (23) expr : expr EXP expr . (23) expr : expr . '!' (24) EXP shift 39 '!' shift 40 '|' reduce 23 '&' reduce 23 EQ reduce 23 NE reduce 23 GT reduce 23 GE reduce 23 LT reduce 23 LE reduce 23 L_SHIFT reduce 23 R_SHIFT reduce 23 '+' reduce 23 '-' reduce 23 '*' reduce 23 '/' reduce 23 ';' reduce 23 '\n' reduce 23 ')' reduce 23 29 terminals, 5 nonterminals 35 grammar rules, 59 states perl-byacc-2.0.orig/test/calc.y100644 1750 1750 12045 5224473064 15241 0ustar bortzbortz/* Simple calculator implemented in Perl. The grammar is standard YACC, but the actions are in Perl. This YACC file must be processed by a version of YACC that supports Perl output. The calculator handles the basic operations, but nothing fancy. This is mostly a demonstration of the Perl/Yacc combination. $P holds the previous value, that is, the value of the most recent expression. The user can refer to this with "%". %V holds user-defined variables; variables are defined by assinging to them. References to an undefined variable produces a warning, and assigns 0 to the variable. The user can also get a Perl escape with &, followed by a string. Ray Lischner 17 August 1990 */ %token INT FLOAT STRING IDENT %left '=' %left '|' %left '&' %left EQ NE %left GT GE LT LE %left L_SHIFT R_SHIFT %left '+' '-' %left '*' '/' %right EXP %right '!' %right UNARY %start stmt_list %% stmt_list: /* empty */ | stmt_list stmt ; stmt: terminator | expr terminator { print $1, "\n" if $2 eq "\n"; $P = $1; } | error terminator { &yyerrok; } ; terminator: ';' { $$ = $1; } | '\n' { $$ = $1; } ; expr: '(' expr ')' { $$ = $2; } | expr '|' expr { $$ = $1 || $3; } | expr '&' expr { $$ = $1 && $3; } | expr EQ expr { $$ = $1 == $3; } | expr NE expr { $$ = $1 != $3; } | expr GT expr { $$ = $1 > $3; } | expr GE expr { $$ = $1 >= $3; } | expr LT expr { $$ = $1 < $3; } | expr LE expr { $$ = $1 <= $3; } | expr L_SHIFT expr { $$ = $1 << $3; } | expr R_SHIFT expr { $$ = $1 >> $3; } | expr '+' expr { $$ = $1 + $3; } | expr '-' expr { $$ = $1 - $3; } | expr '*' expr { $$ = $1 * $3; } | expr '/' expr { $$ = $1 / $3; } | expr EXP expr { $$ = $1 ** $3; } | expr '!' { $$ = &fact($1); } | '-' expr %prec UNARY { $$ = -$2; } | '!' expr %prec UNARY { $$ = !$2; } | '+' expr %prec UNARY { $$ = $2; } | '&' STRING %prec UNARY { $$ = eval($2); } | IDENT '=' expr { eval '$V{'.$1.'}=('.$3.'); 1' || &yyerror($@); $$ = $V{$1}; } | IDENT { if (! defined $V{$1}) { &yyerror($1.": undefined variable"); $V{$1} = 0; } $$ = $V{$1}; } | INT { $$ = $1; } | FLOAT { $$ = $1; } | STRING { $$ = $1; } | '%' { $$ = $P; } ; %% # Prompt the user on STDERR, but only prompt if STDERR and the input # file are both terminals. # read from STDIN if no files are named on the command line unshift(@ARGV, '-') if $#ARGV < $[; # After finishing a file, open the next one. Return whether there # really is a next one that was opened. sub next_file { while ($ARGV = shift(@ARGV)) { if (! open(ARGV, $ARGV)) { print STDERR "$ARGV: cannot open file: $!\n"; next; } $prompt = (-t ARGV && -t STDERR) ? '(Calc) ' : ''; last; } $ARGV >= $[; } # print he prompt sub prompt { print STDERR $prompt if $prompt; } # print an error message sub yyerror { print STDERR "\"$ARGV\", " if $ARGV ne '-'; print STDERR "line $.: ", @_, "\n"; } # Hand-coded lex until I write lex -p, too! sub yylex { lexloop: { # get a line of input, if we need it. if ($line eq '') { &prompt; $line = ; if ($line eq '') { close(ARGV); &next_file || return(0); } } # Skip over white space, and grab the first character. # If there is no such character, then grab the next line. $line =~ s/^[ \t\f\r\v]*(.|\n)// || next lexloop; local($char) = $1; if ($char eq '#') { # comment, so discard the line $line = "\n"; &yylex; } elsif ($char =~ /^['"]/) { # collect the string if ($line =~ s/^([^$char]*)$char//) { $yylval = $1; } else { &yyerror('unterminated string'); $yylval = ''; } $STRING; } elsif ($char =~ /^\d/) { # number, is it integer or float? if ($line =~ s/^(\d+)//) { $yylval = int($char . $1); } else { $yylval = int($char); } $type = $INT; if ($line =~ s/^(\.\d*)//) { $tmp = "0$1"; $yylval += $tmp; $type = $FLOAT; } if ($line =~ s/^[eE]([-+]*\d+)//) { $yylval *= 10 ** $1; $type = $FLOAT; } $type; } elsif ($char =~ /^\w/) { # identifier $line =~ s/^([\w\d]*)//; $yylval = $char.$1; $IDENT; } elsif ($char eq '*' && $line =~ s/^\*//) { $EXP; } elsif ($char eq '!' && $line =~ s/^=//) { $NE; } elsif ($char eq '=' && $line =~ s/^=//) { $EQ; } elsif ($char =~ /^[<>]/ && $line =~ s/^=//) { $char eq '<' ? $LE : $GE; } elsif ($char =~ /^[<>]/ && $line =~ s/^$char//) { $char eq '<' ? $L_SHIFT : $R_SHIFT; } else { $yylval = $char; ord($char); } } } # factorial sub fact { local($n) = @_; local($f) = 1; $f *= $n-- while ($n > 1) ; $f; } # catch signals sub catch { local($signum) = @_; print STDERR "\n" if (-t STDERR && -t STDIN); &yyerror("Floating point exception") if $signum = 8; next outer; } $SIG{'INT'} = 'catch'; $SIG{'FPE'} = 'catch'; select(STDERR); $| = 1; select(STDOUT); &next_file; # main program outer: while(1) { $line = ''; eval '$status = &yyparse;'; exit $status if ! $@; &yyerror($@); } perl-byacc-2.0.orig/test/calc.tab.ph100644 1750 1750 227 5224473065 16105 0ustar bortzbortz$INT=257; $FLOAT=258; $STRING=259; $IDENT=260; $EQ=261; $NE=262; $GT=263; $GE=264; $LT=265; $LE=266; $L_SHIFT=267; $R_SHIFT=268; $EXP=269; $UNARY=270; perl-byacc-2.0.orig/test/calc.tab.pl100644 1750 1750 53206 5325617756 16167 0ustar bortzbortz$yysccsid = "@(#)yaccpar 1.8 (Berkeley) 01/20/91 (Perl 2.0 12/31/92)"; #define YYBYACC 1 $INT=257; $FLOAT=258; $STRING=259; $IDENT=260; $EQ=261; $NE=262; $GT=263; $GE=264; $LT=265; $LE=266; $L_SHIFT=267; $R_SHIFT=268; $EXP=269; $UNARY=270; $YYERRCODE=256; @yylhs = ( -1, 0, 0, 1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, ); @yylen = ( 2, 0, 2, 1, 2, 2, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 3, 1, 1, 1, 1, 1, ); @yydefred = ( 1, 0, 0, 31, 32, 33, 0, 0, 0, 0, 0, 6, 7, 0, 34, 2, 3, 0, 5, 0, 28, 27, 25, 26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 4, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ); @yydgoto = ( 1, 15, 16, 17, ); @yysindex = ( 0, 147, 30, 0, 0, 0, -60, -257, 375, 375, 375, 0, 0, 375, 0, 0, 0, 1, 0, 375, 0, 0, 0, 0, -28, 375, 375, 375, 375, 375, 375, 375, 375, 375, 375, 375, 375, 375, 375, 375, 0, 0, 166, 0, 130, 183, 301, 301, 109, 109, 109, 109, 172, 172, -26, -26, -27, -27, -27, ); @yyrindex = ( 0, 0, 0, 0, 0, 0, -10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 41, 0, 190, 78, 120, 124, 88, 94, 100, 108, 65, 74, 42, 54, 12, 20, 31, ); @yygindex = ( 0, 0, 7, 445, ); $YYTABLESIZE=635; @yytable = ( 30, 19, 20, 0, 0, 40, 40, 40, 0, 18, 26, 12, 0, 43, 37, 35, 37, 36, 0, 38, 0, 38, 21, 30, 41, 0, 0, 0, 30, 0, 22, 30, 30, 30, 40, 30, 0, 30, 0, 26, 12, 23, 0, 37, 35, 0, 36, 0, 38, 30, 21, 29, 19, 21, 21, 21, 0, 21, 22, 21, 11, 22, 22, 22, 20, 22, 0, 22, 0, 23, 0, 21, 23, 23, 23, 17, 23, 0, 23, 22, 19, 0, 29, 19, 18, 19, 0, 19, 10, 11, 23, 0, 20, 0, 0, 20, 25, 20, 13, 20, 29, 19, 0, 17, 14, 0, 17, 0, 0, 0, 15, 0, 18, 20, 30, 18, 10, 0, 16, 10, 0, 0, 0, 0, 17, 25, 13, 0, 0, 13, 11, 0, 14, 18, 12, 14, 21, 10, 15, 0, 0, 15, 40, 0, 22, 0, 16, 13, 0, 16, 0, 37, 35, 14, 36, 23, 38, 12, 11, 15, 0, 11, 12, 40, 0, 12, 19, 16, 26, 0, 0, 0, 37, 35, 0, 36, 0, 38, 20, 11, 10, 0, 0, 12, 14, 7, 0, 13, 0, 17, 8, 0, 9, 0, 0, 0, 0, 0, 18, 40, 9, 0, 10, 0, 26, 40, 11, 0, 37, 35, 0, 36, 13, 38, 37, 35, 40, 36, 14, 38, 0, 0, 0, 0, 15, 37, 35, 0, 36, 0, 38, 9, 16, 27, 28, 29, 30, 31, 32, 33, 34, 39, 39, 39, 11, 0, 0, 0, 12, 9, 0, 30, 30, 30, 30, 30, 30, 30, 30, 30, 0, 0, 27, 28, 29, 30, 31, 32, 33, 34, 39, 0, 0, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, 0, 25, 0, 23, 23, 23, 23, 23, 23, 23, 23, 0, 0, 0, 19, 19, 19, 19, 19, 19, 19, 19, 0, 0, 0, 9, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 17, 17, 17, 17, 17, 17, 17, 17, 40, 18, 18, 18, 18, 18, 18, 18, 18, 37, 35, 0, 36, 0, 38, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 0, 0, 16, 16, 16, 16, 16, 16, 0, 33, 34, 39, 0, 0, 11, 11, 0, 0, 12, 12, 0, 0, 0, 0, 27, 28, 29, 30, 31, 32, 33, 34, 39, 0, 0, 0, 2, 3, 4, 5, 6, 10, 0, 0, 0, 14, 7, 0, 13, 0, 0, 8, 0, 9, 0, 0, 0, 0, 0, 0, 27, 28, 29, 30, 31, 32, 33, 34, 39, 0, 0, 0, 0, 0, 39, 0, 0, 27, 28, 29, 30, 31, 32, 33, 34, 39, 21, 22, 23, 0, 0, 24, 0, 0, 0, 0, 0, 42, 0, 0, 0, 0, 0, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29, 30, 31, 32, 33, 34, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 5, 6, ); @yycheck = ( 10, 61, 259, -1, -1, 33, 33, 33, -1, 2, 38, 10, -1, 41, 42, 43, 42, 45, -1, 47, -1, 47, 10, 33, 17, -1, -1, -1, 38, -1, 10, 41, 42, 43, 33, 45, -1, 47, -1, 38, 10, 10, -1, 42, 43, -1, 45, -1, 47, 59, 38, 10, 10, 41, 42, 43, -1, 45, 38, 47, 59, 41, 42, 43, 10, 45, -1, 47, -1, 38, -1, 59, 41, 42, 43, 10, 45, -1, 47, 59, 38, -1, 41, 41, 10, 43, -1, 45, 10, 59, 59, -1, 38, -1, -1, 41, 124, 43, 10, 45, 59, 59, -1, 38, 10, -1, 41, -1, -1, -1, 10, -1, 38, 59, 124, 41, 38, -1, 10, 41, -1, -1, -1, -1, 59, 124, 38, -1, -1, 41, 10, -1, 38, 59, 10, 41, 124, 59, 38, -1, -1, 41, 33, -1, 124, -1, 38, 59, -1, 41, -1, 42, 43, 59, 45, 124, 47, 10, 38, 59, -1, 41, 38, 33, -1, 41, 124, 59, 38, -1, -1, -1, 42, 43, -1, 45, -1, 47, 124, 59, 33, -1, -1, 59, 37, 38, -1, 40, -1, 124, 43, -1, 45, -1, -1, -1, -1, -1, 124, 33, 10, -1, 124, -1, 38, 33, 59, -1, 42, 43, -1, 45, 124, 47, 42, 43, 33, 45, 124, 47, -1, -1, -1, -1, 124, 42, 43, -1, 45, -1, 47, 41, 124, 261, 262, 263, 264, 265, 266, 267, 268, 269, 269, 269, 124, -1, -1, -1, 124, 59, -1, 261, 262, 263, 264, 265, 266, 267, 268, 269, -1, -1, 261, 262, 263, 264, 265, 266, 267, 268, 269, -1, -1, 261, 262, 263, 264, 265, 266, 267, 268, 261, 262, 263, 264, 265, 266, 267, 268, -1, 124, -1, 261, 262, 263, 264, 265, 266, 267, 268, -1, -1, -1, 261, 262, 263, 264, 265, 266, 267, 268, -1, -1, -1, 124, 261, 262, 263, 264, 265, 266, 267, 268, -1, -1, -1, 261, 262, 263, 264, 265, 266, 267, 268, 33, 261, 262, 263, 264, 265, 266, 267, 268, 42, 43, -1, 45, -1, 47, 261, 262, 263, 264, 265, 266, 261, 262, 263, 264, 265, 266, 261, 262, 263, 264, 265, 266, -1, -1, 261, 262, 263, 264, 265, 266, -1, 267, 268, 269, -1, -1, 261, 262, -1, -1, 261, 262, -1, -1, -1, -1, 261, 262, 263, 264, 265, 266, 267, 268, 269, -1, -1, -1, 256, 257, 258, 259, 260, 33, -1, -1, -1, 37, 38, -1, 40, -1, -1, 43, -1, 45, -1, -1, -1, -1, -1, -1, 261, 262, 263, 264, 265, 266, 267, 268, 269, -1, -1, -1, -1, -1, 269, -1, -1, 261, 262, 263, 264, 265, 266, 267, 268, 269, 8, 9, 10, -1, -1, 13, -1, -1, -1, -1, -1, 19, -1, -1, -1, -1, -1, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 263, 264, 265, 266, 267, 268, 269, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 257, 258, 259, 260, ); $YYFINAL=1; #ifndef YYDEBUG #define YYDEBUG 0 #endif $YYMAXTOKEN=270; #if YYDEBUG @yyname = ( "end-of-file",'','','','','','','','','',"'\\n'",'','','','','','','','','','','','','','','','','','','','', '','',"'!'",'','','',"'%'","'&'",'',"'('","')'","'*'","'+'",'',"'-'",'',"'/'",'','','','','', '','','','','','',"';'",'',"'='",'','','','','','','','','','','','','','','','','','','','','','','','','','','', '','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','',"'|'",'','', '','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','', '','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','', '','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','', '','','','','','','','','','',"INT","FLOAT","STRING","IDENT","EQ","NE","GT","GE","LT", "LE","L_SHIFT","R_SHIFT","EXP","UNARY", ); @yyrule = ( "\$accept : stmt_list", "stmt_list :", "stmt_list : stmt_list stmt", "stmt : terminator", "stmt : expr terminator", "stmt : error terminator", "terminator : ';'", "terminator : '\\n'", "expr : '(' expr ')'", "expr : expr '|' expr", "expr : expr '&' expr", "expr : expr EQ expr", "expr : expr NE expr", "expr : expr GT expr", "expr : expr GE expr", "expr : expr LT expr", "expr : expr LE expr", "expr : expr L_SHIFT expr", "expr : expr R_SHIFT expr", "expr : expr '+' expr", "expr : expr '-' expr", "expr : expr '*' expr", "expr : expr '/' expr", "expr : expr EXP expr", "expr : expr '!'", "expr : '-' expr", "expr : '!' expr", "expr : '+' expr", "expr : '&' STRING", "expr : IDENT '=' expr", "expr : IDENT", "expr : INT", "expr : FLOAT", "expr : STRING", "expr : '%'", ); #endif sub yyclearin { $yychar = -1; } sub yyerrok { $yyerrflag = 0; } $YYSTACKSIZE = $YYSTACKSIZE || $YYMAXDEPTH || 500; $YYMAXDEPTH = $YYMAXDEPTH || $YYSTACKSIZE || 500; $yyss[$YYSTACKSIZE] = 0; $yyvs[$YYSTACKSIZE] = 0; sub YYERROR { ++$yynerrs; &yy_err_recover; } sub yy_err_recover { if ($yyerrflag < 3) { $yyerrflag = 3; while (1) { if (($yyn = $yysindex[$yyss[$yyssp]]) && ($yyn += $YYERRCODE) >= 0 && $yycheck[$yyn] == $YYERRCODE) { #if YYDEBUG print "yydebug: state $yyss[$yyssp], error recovery shifting", " to state $yytable[$yyn]\n" if $yydebug; #endif $yyss[++$yyssp] = $yystate = $yytable[$yyn]; $yyvs[++$yyvsp] = $yylval; next yyloop; } else { #if YYDEBUG print "yydebug: error recovery discarding state ", $yyss[$yyssp], "\n" if $yydebug; #endif return(1) if $yyssp <= 0; --$yyssp; --$yyvsp; } } } else { return (1) if $yychar == 0; #if YYDEBUG if ($yydebug) { $yys = ''; if ($yychar <= $YYMAXTOKEN) { $yys = $yyname[$yychar]; } if (!$yys) { $yys = 'illegal-symbol'; } print "yydebug: state $yystate, error recovery discards ", "token $yychar ($yys)\n"; } #endif $yychar = -1; next yyloop; } 0; } # yy_err_recover sub yyparse { #ifdef YYDEBUG if ($yys = $ENV{'YYDEBUG'}) { $yydebug = int($1) if $yys =~ /^(\d)/; } #endif $yynerrs = 0; $yyerrflag = 0; $yychar = (-1); $yyssp = 0; $yyvsp = 0; $yyss[$yyssp] = $yystate = 0; yyloop: while(1) { yyreduce: { last yyreduce if ($yyn = $yydefred[$yystate]); if ($yychar < 0) { if (($yychar = &yylex) < 0) { $yychar = 0; } #if YYDEBUG if ($yydebug) { $yys = ''; if ($yychar <= $#yyname) { $yys = $yyname[$yychar]; } if (!$yys) { $yys = 'illegal-symbol'; }; print "yydebug: state $yystate, reading $yychar ($yys)\n"; } #endif } if (($yyn = $yysindex[$yystate]) && ($yyn += $yychar) >= 0 && $yycheck[$yyn] == $yychar) { #if YYDEBUG print "yydebug: state $yystate, shifting to state ", $yytable[$yyn], "\n" if $yydebug; #endif $yyss[++$yyssp] = $yystate = $yytable[$yyn]; $yyvs[++$yyvsp] = $yylval; $yychar = (-1); --$yyerrflag if $yyerrflag > 0; next yyloop; } if (($yyn = $yyrindex[$yystate]) && ($yyn += $yychar) >= 0 && $yycheck[$yyn] == $yychar) { $yyn = $yytable[$yyn]; last yyreduce; } if (! $yyerrflag) { &yyerror('syntax error'); ++$yynerrs; } return(1) if &yy_err_recover; } # yyreduce #if YYDEBUG print "yydebug: state $yystate, reducing by rule ", "$yyn ($yyrule[$yyn])\n" if $yydebug; #endif $yym = $yylen[$yyn]; $yyval = $yyvs[$yyvsp+1-$yym]; switch: { if ($yyn == 4) { #line 45 "calc.y" { print $yyvs[$yyvsp-1], "\n" if $yyvs[$yyvsp-0] eq "\n"; $P = $yyvs[$yyvsp-1]; last switch; } } if ($yyn == 5) { #line 47 "calc.y" { &yyerrok; last switch; } } if ($yyn == 6) { #line 51 "calc.y" { $yyval = $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 7) { #line 53 "calc.y" { $yyval = $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 8) { #line 57 "calc.y" { $yyval = $yyvs[$yyvsp-1]; last switch; } } if ($yyn == 9) { #line 59 "calc.y" { $yyval = $yyvs[$yyvsp-2] || $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 10) { #line 61 "calc.y" { $yyval = $yyvs[$yyvsp-2] && $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 11) { #line 63 "calc.y" { $yyval = $yyvs[$yyvsp-2] == $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 12) { #line 65 "calc.y" { $yyval = $yyvs[$yyvsp-2] != $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 13) { #line 67 "calc.y" { $yyval = $yyvs[$yyvsp-2] > $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 14) { #line 69 "calc.y" { $yyval = $yyvs[$yyvsp-2] >= $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 15) { #line 71 "calc.y" { $yyval = $yyvs[$yyvsp-2] < $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 16) { #line 73 "calc.y" { $yyval = $yyvs[$yyvsp-2] <= $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 17) { #line 75 "calc.y" { $yyval = $yyvs[$yyvsp-2] << $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 18) { #line 77 "calc.y" { $yyval = $yyvs[$yyvsp-2] >> $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 19) { #line 79 "calc.y" { $yyval = $yyvs[$yyvsp-2] + $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 20) { #line 81 "calc.y" { $yyval = $yyvs[$yyvsp-2] - $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 21) { #line 83 "calc.y" { $yyval = $yyvs[$yyvsp-2] * $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 22) { #line 85 "calc.y" { $yyval = $yyvs[$yyvsp-2] / $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 23) { #line 87 "calc.y" { $yyval = $yyvs[$yyvsp-2] ** $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 24) { #line 89 "calc.y" { $yyval = &fact($yyvs[$yyvsp-1]); last switch; } } if ($yyn == 25) { #line 91 "calc.y" { $yyval = -$yyvs[$yyvsp-0]; last switch; } } if ($yyn == 26) { #line 93 "calc.y" { $yyval = !$yyvs[$yyvsp-0]; last switch; } } if ($yyn == 27) { #line 95 "calc.y" { $yyval = $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 28) { #line 97 "calc.y" { $yyval = eval($yyvs[$yyvsp-0]); last switch; } } if ($yyn == 29) { #line 99 "calc.y" { eval '$V{'.$yyvs[$yyvsp-2].'}=('.$yyvs[$yyvsp-0].'); 1' || &yyerror($@); $yyval = $V{$yyvs[$yyvsp-2]}; last switch; } } if ($yyn == 30) { #line 101 "calc.y" { if (! defined $V{$yyvs[$yyvsp-0]}) { &yyerror($yyvs[$yyvsp-0].": undefined variable"); $V{$yyvs[$yyvsp-0]} = 0; } $yyval = $V{$yyvs[$yyvsp-0]}; last switch; } } if ($yyn == 31) { #line 108 "calc.y" { $yyval = $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 32) { #line 110 "calc.y" { $yyval = $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 33) { #line 112 "calc.y" { $yyval = $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 34) { #line 114 "calc.y" { $yyval = $P; last switch; } } #line 533 "calc.tab.pl" } # switch $yyssp -= $yym; $yystate = $yyss[$yyssp]; $yyvsp -= $yym; $yym = $yylhs[$yyn]; if ($yystate == 0 && $yym == 0) { #if YYDEBUG print "yydebug: after reduction, shifting from state 0 ", "to state $YYFINAL\n" if $yydebug; #endif $yystate = $YYFINAL; $yyss[++$yyssp] = $YYFINAL; $yyvs[++$yyvsp] = $yyval; if ($yychar < 0) { if (($yychar = &yylex) < 0) { $yychar = 0; } #if YYDEBUG if ($yydebug) { $yys = ''; if ($yychar <= $#yyname) { $yys = $yyname[$yychar]; } if (!$yys) { $yys = 'illegal-symbol'; } print "yydebug: state $YYFINAL, reading $yychar ($yys)\n"; } #endif } return(0) if $yychar == 0; next yyloop; } if (($yyn = $yygindex[$yym]) && ($yyn += $yystate) >= 0 && $yyn <= $#yycheck && $yycheck[$yyn] == $yystate) { $yystate = $yytable[$yyn]; } else { $yystate = $yydgoto[$yym]; } #if YYDEBUG print "yydebug: after reduction, shifting from state ", "$yyss[$yyssp] to state $yystate\n" if $yydebug; #endif $yyss[++$yyssp] = $yystate; $yyvs[++$yyvsp] = $yyval; } # yyloop } # yyparse #line 118 "calc.y" # Prompt the user on STDERR, but only prompt if STDERR and the input # file are both terminals. # read from STDIN if no files are named on the command line unshift(@ARGV, '-') if $#ARGV < $[; # After finishing a file, open the next one. Return whether there # really is a next one that was opened. sub next_file { while ($ARGV = shift(@ARGV)) { if (! open(ARGV, $ARGV)) { print STDERR "$ARGV: cannot open file: $!\n"; next; } $prompt = (-t ARGV && -t STDERR) ? '(Calc) ' : ''; last; } $ARGV >= $[; } # print he prompt sub prompt { print STDERR $prompt if $prompt; } # print an error message sub yyerror { print STDERR "\"$ARGV\", " if $ARGV ne '-'; print STDERR "line $.: ", @_, "\n"; } # Hand-coded lex until I write lex -p, too! sub yylex { lexloop: { # get a line of input, if we need it. if ($line eq '') { &prompt; $line = ; if ($line eq '') { close(ARGV); &next_file || return(0); } } # Skip over white space, and grab the first character. # If there is no such character, then grab the next line. $line =~ s/^[ \t\f\r\v]*(.|\n)// || next lexloop; local($char) = $1; if ($char eq '#') { # comment, so discard the line $line = "\n"; &yylex; } elsif ($char =~ /^['"]/) { # collect the string if ($line =~ s/^([^$char]*)$char//) { $yylval = $1; } else { &yyerror('unterminated string'); $yylval = ''; } $STRING; } elsif ($char =~ /^\d/) { # number, is it integer or float? if ($line =~ s/^(\d+)//) { $yylval = int($char . $1); } else { $yylval = int($char); } $type = $INT; if ($line =~ s/^(\.\d*)//) { $tmp = "0$1"; $yylval += $tmp; $type = $FLOAT; } if ($line =~ s/^[eE]([-+]*\d+)//) { $yylval *= 10 ** $1; $type = $FLOAT; } $type; } elsif ($char =~ /^\w/) { # identifier $line =~ s/^([\w\d]*)//; $yylval = $char.$1; $IDENT; } elsif ($char eq '*' && $line =~ s/^\*//) { $EXP; } elsif ($char eq '!' && $line =~ s/^=//) { $NE; } elsif ($char eq '=' && $line =~ s/^=//) { $EQ; } elsif ($char =~ /^[<>]/ && $line =~ s/^=//) { $char eq '<' ? $LE : $GE; } elsif ($char =~ /^[<>]/ && $line =~ s/^$char//) { $char eq '<' ? $L_SHIFT : $R_SHIFT; } else { $yylval = $char; ord($char); } } } # factorial sub fact { local($n) = @_; local($f) = 1; $f *= $n-- while ($n > 1) ; $f; } # catch signals sub catch { local($signum) = @_; print STDERR "\n" if (-t STDERR && -t STDIN); &yyerror("Floating point exception") if $signum = 8; next outer; } $SIG{'INT'} = 'catch'; $SIG{'FPE'} = 'catch'; select(STDERR); $| = 1; select(STDOUT); &next_file; # main program outer: while(1) { $line = ''; eval '$status = &yyparse;'; exit $status if ! $@; &yyerror($@); } #line 719 "calc.tab.pl" perl-byacc-2.0.orig/test/getdate.y100644 1750 1750 36511 5347366504 15766 0ustar bortzbortz%token ID MONTH DAY MERIDIAN NUMBER UNIT MUNIT SUNIT ZONE DAYZONE AGO %{ # Steven M. Bellovin (unc!smb) # Dept. of Computer Science # University of North Carolina at Chapel Hill # @(#)getdate.y 2.13 9/16/86 # # Richard J. Ohnemus (rick@IMD.Sterling.COM) # (Where do I work??? I'm not even sure who I am! 8-{) # 04/24/92 converted to PERL. # 07/06/92 New date format (MONTH NUMBER NUMBER ':' NUMBER ':' NUMBER) # suggested by Raphael Manfredi . # 07/08/92 Fixed table search in &lookup. # Call &localtime with correct value in &monthadd. # 10/08/92 Numeric values starting with pattern '0+[89]' interpretted # correctly. # Corrected European Western and Eastern time offsets. # Borrowed code from timelocal.pl to determine timezone offset # from GMT. # 10/10/92 Handle time zone offsets correctly (sign was reversed). # Set global time zone variable ('ourzone') correctly. # 12/24/92 Fixed problem with military time zones. package getdate; $AM = 1; $PM = 2; $DAYLIGHT = 1; $STANDARD = 2; $MAYBE = 3; @mdays = (31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); $epoch = 1970; $daysec = 24 * 60 * 60; %} %% timedate: /* empty */ | timedate item ; item: tspec = { $timeflag++; } | zone = { $zoneflag++; } | dtspec = { $dateflag++; } | dyspec = { $dayflag++; } | rspec = { $relflag++; } | nspec ; nspec: NUMBER = { if ($timeflag && $dateflag && !$relflag) { $year = $1; } else { $timeflag++; $hh = int($1 / 100); $mm = $1 % 100; $ss = 0; $merid = 24; } } ; tspec: NUMBER MERIDIAN = { $hh = $1; $mm = 0; $ss = 0; $merid = $2; } | NUMBER ':' NUMBER = { $hh = $1; $mm = $3; $merid = 24; } | NUMBER ':' NUMBER MERIDIAN = { $hh = $1; $mm = $3; $merid = $4; } | NUMBER ':' NUMBER NUMBER = { $hh = $1; $mm = $3; $merid = 24; $daylight = $STANDARD; $ourzone = -($4 % 100 + 60 * int($4 / 100)); } | NUMBER ':' NUMBER ':' NUMBER = { $hh = $1; $mm = $3; $ss = $5; $merid = 24; } | NUMBER ':' NUMBER ':' NUMBER MERIDIAN = { $hh = $1; $mm = $3; $ss = $5; $merid = $6; } | NUMBER ':' NUMBER ':' NUMBER NUMBER = { $hh = $1; $mm = $3; $ss = $5; $merid = 24; $daylight = $STANDARD; $ourzone = -($6 % 100 + 60 * int($6 / 100)); } ; zone: ZONE = { $ourzone = $1; $daylight = $STANDARD; } | DAYZONE = { $ourzone = $1; $daylight = $DAYLIGHT; } ; dyspec: DAY = { $dayord = 1; $dayreq = $1; } | DAY ',' = { $dayord = 1; $dayreq = $1; } | NUMBER DAY = { $dayord = $1; $dayreq = $2; } ; dtspec: NUMBER '/' NUMBER = { $month = $1; $day = $3; } | NUMBER '/' NUMBER '/' NUMBER = { /* * HACK ALERT!!!! * The 1000 is a magic number to attempt to force * use of 4 digit years if year/month/day can be * parsed. This was only done for backwards * compatibility in rh. */ if ($1 > 1000) { $year = $1; $month = $3; $day = $5; } else { $month = $1; $day = $3; $year = $5; } } | MONTH NUMBER = { $month = $1; $day = $2; } | MONTH NUMBER ',' NUMBER = { $month = $1; $day = $2; $year = $4; } | MONTH NUMBER NUMBER ':' NUMBER = { $month = $1; $day = $2; $hh = $3; $mm = $5; $merid = 24; $timeflag++; } | MONTH NUMBER NUMBER ':' NUMBER ':' NUMBER = { $month = $1; $day = $2; $hh = $3; $mm = $5; $ss = $7; $merid = 24; $timeflag++; } | MONTH NUMBER NUMBER = { $month = $1; $day = $2; $year = $3; } | NUMBER MONTH = { $month = $2; $day = $1; } | NUMBER MONTH NUMBER = { $month = $2; $day = $1; $year = $3; } ; rspec: NUMBER UNIT = { $relsec += 60 * $1 * $2; } | NUMBER MUNIT = { $relmonth += $1 * $2; } | NUMBER SUNIT = { $relsec += $1; } | UNIT = { $relsec += 60 * $1; } | MUNIT = { $relmonth += $1; } | SUNIT = { $relsec++; } | rspec AGO = { $relsec = -$relsec; $relmonth = -$relmonth; } ; %% sub dateconv { local($mm, $dd, $yy, $h, $m, $s, $mer, $zone, $dayflag) = @_; local($time_of_day, $jdate); local($i); if ($yy < 0) { $yy = -$yy; } if ($yy < 100) { $yy += 1900; } $mdays[1] = 28 + (($yy % 4) == 0 && (($yy % 100) != 0 || ($yy % 400) == 0)); if ($yy < $epoch || $yy > 2001 || $mm < 1 || $mm > 12 || $dd < 1 || $dd > $mdays[--$mm]) { return -1; } $jdate = $dd - 1; for ($i = 0; $i < $mm; $i++) { $jdate += $mdays[$i]; } for ($i = $epoch; $i < $yy; $i++) { $jdate += 365 + (($i % 4) == 0); } $jdate *= $daysec; $jdate += $zone * 60; if (($time_of_day = &timeconv($h, $m, $s, $mer)) < 0) { return -1; } $jdate += $time_of_day; if ($dayflag == $DAYLIGHT || ($dayflag == $MAYBE && (localtime($jdate))[8])) { $jdate -= 60 * 60; } return $jdate; } sub dayconv { local($ordday, $day, $now) = @_; local(@loctime); local($time_of_day); $time_of_day = $now; @loctime = localtime($time_of_day); $time_of_day += $daysec * (($day - $loctime[6] + 7) % 7); $time_of_day += 7 * $daysec * ($ordday <= 0 ? $ordday : $ordday - 1); return &daylcorr($time_of_day, $now); } sub timeconv { local($hh, $mm, $ss, $mer) = @_; return -1 if ($mm < 0 || $mm > 59 || $ss < 0 || $ss > 59); if ($mer == $AM) { return -1 if ($hh < 1 || $hh > 12); return 60 * (($hh % 12) * 60 + $mm) + $ss; } if ($mer == $PM) { return -1 if ($hh < 1 || $hh > 12); return 60 * (($hh % 12 + 12) * 60 + $mm) + $ss; } if ($mer == 24) { return -1 if ($hh < 0 || $hh > 23); return 60 * ($hh * 60 + $mm) + $ss; } return -1; } sub monthadd { local($sdate, $relmonth) = @_; local(@ltime); local($mm, $yy); return 0 if ($relmonth == 0); @ltime = localtime($sdate); $mm = 12 * $ltime[5] + $ltime[4] + $relmonth; $yy = int($mm / 12); $mm = $mm % 12 + 1; return &daylcorr(&dateconv($mm, $ltime[3], $yy, $ltime[2], $ltime[1], $ltime[0], 24, $ourzone, $MAYBE), $sdate); } sub daylcorr { local($future, $now) = @_; local($fdayl, $nowdayl); $nowdayl = ((localtime($now))[2] + 1) % 24; $fdayl = ((localtime($future))[2] + 1) % 24; return ($future - $now) + 60 * 60 * ($nowdayl - $fdayl); } sub yylex { local($pcnt, $sign); while (1) { $dtstr =~ s/^\s*//; if ($dtstr =~ /^([-+])/) { $sign = ($1 eq '-') ? -1 : 1; $dtstr =~ s/^.//; if ($dtstr =~ /^(\d+)/) { $num = $1; $num =~ s/^0+//; if ($num eq '') { $yylval = 0; } else { $yylval = eval "$num * $sign"; } $dtstr =~ s/^\d+//; return $NUMBER; } else { return &yylex; } } elsif ($dtstr =~ /^(\d+)/) { $num = $1; $num =~ s/^0+//; if ($num eq '') { $yylval = 0; } else { $yylval = eval "$num"; } $dtstr =~ s/^\d+//; return $NUMBER; } elsif ($dtstr =~ /^([a-zA-z][a-zA-Z.]*)/) { $dtstr = substr($dtstr, length($1)); return &lookup($1); } elsif ($dtstr =~ /^\(/) { $pcnt = 0; do { $dtstr = s/^(.)//; return 0 if !defined($1); $pcnt++ if ($1 eq '('); $pcnt-- if ($1 eq ')'); } while ($pcnt > 0); } else { $yylval = ord(substr($dtstr, 0, 1)); $dtstr =~ s/^.//; return $yylval; } } } %mdtab = ( "January", "$MONTH,1", "February", "$MONTH,2", "March", "$MONTH,3", "April", "$MONTH,4", "May", "$MONTH,5", "June", "$MONTH,6", "July", "$MONTH,7", "August", "$MONTH,8", "September", "$MONTH,9", "Sept", "$MONTH,9", "October", "$MONTH,10", "November", "$MONTH,11", "December", "$MONTH,12", "Sunday", "$DAY,0", "Monday", "$DAY,1", "Tuesday", "$DAY,2", "Tues", "$DAY,2", "Wednesday", "$DAY,3", "Wednes", "$DAY,3", "Thursday", "$DAY,4", "Thur", "$DAY,4", "Thurs", "$DAY,4", "Friday", "$DAY,5", "Saturday", "$DAY,6" ); $HRS='*60'; $HALFHR='30'; %mztab = ( "a.m.", "$MERIDIAN,$AM", "am", "$MERIDIAN,$AM", "p.m.", "$MERIDIAN,$PM", "pm", "$MERIDIAN,$PM", "nst", "$ZONE,3 $HRS + $HALFHR", # Newfoundland "n.s.t.", "$ZONE,3 $HRS + $HALFHR", "ast", "$ZONE,4 $HRS", # Atlantic "a.s.t.", "$ZONE,4 $HRS", "adt", "$DAYZONE,4 $HRS", "a.d.t.", "$DAYZONE,4 $HRS", "est", "$ZONE,5 $HRS", # Eastern "e.s.t.", "$ZONE,5 $HRS", "edt", "$DAYZONE,5 $HRS", "e.d.t.", "$DAYZONE,5 $HRS", "cst", "$ZONE,6 $HRS", # Central "c.s.t.", "$ZONE,6 $HRS", "cdt", "$DAYZONE,6 $HRS", "c.d.t.", "$DAYZONE,6 $HRS", "mst", "$ZONE,7 $HRS", # Mountain "m.s.t.", "$ZONE,7 $HRS", "mdt", "$DAYZONE,7 $HRS", "m.d.t.", "$DAYZONE,7 $HRS", "pst", "$ZONE,8 $HRS", # Pacific "p.s.t.", "$ZONE,8 $HRS", "pdt", "$DAYZONE,8 $HRS", "p.d.t.", "$DAYZONE,8 $HRS", "yst", "$ZONE,9 $HRS", # Yukon "y.s.t.", "$ZONE,9 $HRS", "ydt", "$DAYZONE,9 $HRS", "y.d.t.", "$DAYZONE,9 $HRS", "hst", "$ZONE,10 $HRS", # Hawaii "h.s.t.", "$ZONE,10 $HRS", "hdt", "$DAYZONE,10 $HRS", "h.d.t.", "$DAYZONE,10 $HRS", "gmt", "$ZONE,0 $HRS", "g.m.t.", "$ZONE,0 $HRS", "bst", "$DAYZONE,0 $HRS", # British Summer Time "b.s.t.", "$DAYZONE,0 $HRS", "wet", "$ZONE,0 $HRS ", # Western European Time "w.e.t.", "$ZONE,0 $HRS ", "west", "$DAYZONE,0 $HRS", # Western European Summer Time "w.e.s.t.", "$DAYZONE,0 $HRS", "met", "$ZONE,-1 $HRS", # Middle European Time "m.e.t.", "$ZONE,-1 $HRS", "mest", "$DAYZONE,-1 $HRS", # Middle European Summer Time "m.e.s.t.", "$DAYZONE,-1 $HRS", "eet", "$ZONE,-2 $HRS", # European Eastern Time "e.e.t.", "$ZONE,-2 $HRS", "eest", "$DAYZONE,-2 $HRS", # European Eastern Summer Time "e.e.s.t.", "$DAYZONE,-2 $HRS", "jst", "$ZONE,-9 $HRS", # Japan Standard Time "j.s.t.", "$ZONE,-9 $HRS", # Japan Standard Time # No daylight savings time "aest", "$ZONE,-10 $HRS", # Australian Eastern Time "a.e.s.t.", "$ZONE,-10 $HRS", "aesst", "$DAYZONE,-10 $HRS", # Australian Eastern Summer Time "a.e.s.s.t.", "$DAYZONE,-10 $HRS", "acst", "$ZONE,-(9 $HRS + $HALFHR)", # Australian Central Time "a.c.s.t.", "$ZONE,-(9 $HRS + $HALFHR)", "acsst", "$DAYZONE,-(9 $HRS + $HALFHR)", # Australian Central Summer "a.c.s.s.t.", "$DAYZONE,-(9 $HRS + $HALFHR)", "awst", "$ZONE,-8 $HRS", # Australian Western Time "a.w.s.t.", "$ZONE,-8 $HRS" # (no daylight time there, I'm told) ); %unittab = ( "year", "$MUNIT,12", "month", "$MUNIT,1", "fortnight", "$UNIT,14*24*60", "week", "$UNIT,7*24*60", "day", "$UNIT,1*24*60", "hour", "$UNIT,60", "minute", "$UNIT,1", "min", "$UNIT,1", "second", "$SUNIT,1", "sec", "$SUNIT,1" ); %othertab = ( "tomorrow", "$UNIT,1*24*60", "yesterday","$UNIT,-1*24*60", "today", "$UNIT,0", "now", "$UNIT,0", "last", "$NUMBER,-1", "this", "$UNIT,0", "next", "$NUMBER,2", "first", "$NUMBER,1", # "second", "$NUMBER,2", "third", "$NUMBER,3", "fourth", "$NUMBER,4", "fifth", "$NUMBER,5", "sixth", "$NUMBER,6", "seventh", "$NUMBER,7", "eigth", "$NUMBER,8", "ninth", "$NUMBER,9", "tenth", "$NUMBER,10", "eleventh", "$NUMBER,11", "twelfth", "$NUMBER,12", "ago", "$AGO,1" ); %milzone = ( "a", "$ZONE,1 $HRS", "b", "$ZONE,2 $HRS", "c", "$ZONE,3 $HRS", "d", "$ZONE,4 $HRS", "e", "$ZONE,5 $HRS", "f", "$ZONE,6 $HRS", "g", "$ZONE,7 $HRS", "h", "$ZONE,8 $HRS", "i", "$ZONE,9 $HRS", "k", "$ZONE,10 $HRS", "l", "$ZONE,11 $HRS", "m", "$ZONE,12 $HRS", "n", "$ZONE,-1 $HRS", "o", "$ZONE,-2 $HRS", "p", "$ZONE,-3 $HRS", "q", "$ZONE,-4 $HRS", "r", "$ZONE,-5 $HRS", "s", "$ZONE,-6 $HRS", "t", "$ZONE,-7 $HRS", "u", "$ZONE,-8 $HRS", "v", "$ZONE,-9 $HRS", "w", "$ZONE,-10 $HRS", "x", "$ZONE,-11 $HRS", "y", "$ZONE,-12 $HRS", "z", "$ZONE,0 $HRS" ); sub lookup { local($id) = @_; local($abbrev, $idvar, $key, $token); $idvar = $id; if (length($idvar) == 3) { $abbrev = 1; } elsif (length($idvar) == 4 && substr($idvar, 3, 1) eq '.') { $abbrev = 1; $idvar = substr($idvar, 0, 3); } else { $abbrev = 0; } substr($idvar, 0, 1) =~ tr/a-z/A-Z/; if (defined($mdtab{$idvar})) { ($token, $yylval) = split(/,/,$mdtab{$idvar}); $yylval = eval "$yylval"; return $token; } foreach $key (keys %mdtab) { if ($idvar eq substr($key, 0, 3)) { ($token, $yylval) = split(/,/,$mdtab{$key}); $yylval = eval "$yylval"; return $token; } } $idvar = $id; if (defined($mztab{$idvar})) { ($token, $yylval) = split(/,/,$mztab{$idvar}); $yylval = eval "$yylval"; return $token; } $idvar =~ tr/A-Z/a-z/; if (defined($mztab{$idvar})) { ($token, $yylval) = split(/,/,$mztab{$idvar}); $yylval = eval "$yylval"; return $token; } $idvar = $id; if (defined($unittab{$idvar})) { ($token, $yylval) = split(/,/,$unittab{$idvar}); $yylval = eval "$yylval"; return $token; } if ($idvar =~ /s$/) { $idvar =~ s/s$//; } if (defined($unittab{$idvar})) { ($token, $yylval) = split(/,/,$unittab{$idvar}); $yylval = eval "$yylval"; return $token; } $idvar = $id; if (defined($othertab{$idvar})) { ($token, $yylval) = split(/,/,$othertab{$idvar}); $yylval = eval "$yylval"; return $token; } if (length($idvar) == 1 && $idvar =~ /[a-zA-Z]/) { $idvar =~ tr/A-Z/a-z/; if (defined($milzone{$idvar})) { ($token, $yylval) = split(/,/,$milzone{$idvar}); $yylval = eval "$yylval"; return $token; } } return $ID; } sub main'getdate { local($now); local(@lt); local($sdate); local($TZ); ($dtstr, $now, $ourzone) = @_; if (!$now) { $now = time; } if (!$ourzone) { $TZ = defined($ENV{'TZ'}) ? ($ENV{'TZ'} ? $ENV{'TZ'} : '') : ''; if($TZ =~ /^([^:\d+\-,]{3,})([+-]?\d{1,2}(:\d{1,2}){0,2})([^\d+\-,]{3,})?/) { $ourzone = $2 * 60; } else { @lt = localtime(0); $ourzone = $lt[2] * 60 + $lt[1]; # minutes east of GMT if ($ourzone > 0) { $ourzone = 24 * 60 - $ourzone; # minutes west of GMT $ourzone -= 24 * 60 if $lt[5] == 70; # account for date line } } } @lt = localtime($now); $year = 0; $month = $lt[4] + 1; $day = $lt[3]; $relsec = $relmonth = 0; $timeflag = $zoneflag = $dateflag = $dayflag = $relflag = 0; $daylight = $MAYBE; $hh = $mm = $ss = 0; $merid = 24; $dtstr =~ tr/A-Z/a-z/; return -1 if &yyparse; return -1 if ($timeflag > 1 || $zoneflag > 1 || $dateflag > 1 || $dayflag > 1); if (!$year) { $year = ($month > ($lt[4] + 1)) ? ($lt[5] - 1) : $lt[5]; } if ($dateflag || $timeflag || $dayflag) { $sdate = &dateconv($month, $day, $year, $hh, $mm, $ss, $merid, $ourzone, $daylight); if ($sdate < 0) { return -1; } } else { $sdate = $now; if ($relflag == 0) { $sdate -= ($lt[0] + $lt[1] * 60 + $lt[2] * (60 * 60)); } } $sdate += $relsec + &monthadd($sdate, $relmonth); $sdate += &dayconv($dayord, $dayreq, $sdate) if ($dayflag && !$dateflag); return $sdate; } sub yyerror { } 1; perl-byacc-2.0.orig/test/getdate.output100644 1750 1750 21132 5265512124 17035 0ustar bortzbortz 0 $accept : timedate $end 1 timedate : 2 | timedate item 3 item : tspec 4 | zone 5 | dtspec 6 | dyspec 7 | rspec 8 | nspec 9 nspec : NUMBER 10 tspec : NUMBER MERIDIAN 11 | NUMBER ':' NUMBER 12 | NUMBER ':' NUMBER MERIDIAN 13 | NUMBER ':' NUMBER NUMBER 14 | NUMBER ':' NUMBER ':' NUMBER 15 | NUMBER ':' NUMBER ':' NUMBER MERIDIAN 16 | NUMBER ':' NUMBER ':' NUMBER NUMBER 17 zone : ZONE 18 | DAYZONE 19 dyspec : DAY 20 | DAY ',' 21 | NUMBER DAY 22 dtspec : NUMBER '/' NUMBER 23 | NUMBER '/' NUMBER '/' NUMBER 24 | MONTH NUMBER 25 | MONTH NUMBER ',' NUMBER 26 | MONTH NUMBER NUMBER ':' NUMBER 27 | MONTH NUMBER NUMBER ':' NUMBER ':' NUMBER 28 | MONTH NUMBER NUMBER 29 | NUMBER MONTH 30 | NUMBER MONTH NUMBER 31 rspec : NUMBER UNIT 32 | NUMBER MUNIT 33 | NUMBER SUNIT 34 | UNIT 35 | MUNIT 36 | SUNIT 37 | rspec AGO state 0 $accept : . timedate $end (0) timedate : . (1) . reduce 1 timedate goto 1 state 1 $accept : timedate . $end (0) timedate : timedate . item (2) $end accept MONTH shift 2 DAY shift 3 NUMBER shift 4 UNIT shift 5 MUNIT shift 6 SUNIT shift 7 ZONE shift 8 DAYZONE shift 9 . error item goto 10 tspec goto 11 zone goto 12 dtspec goto 13 dyspec goto 14 rspec goto 15 nspec goto 16 state 2 dtspec : MONTH . NUMBER (24) dtspec : MONTH . NUMBER ',' NUMBER (25) dtspec : MONTH . NUMBER NUMBER ':' NUMBER (26) dtspec : MONTH . NUMBER NUMBER ':' NUMBER ':' NUMBER (27) dtspec : MONTH . NUMBER NUMBER (28) NUMBER shift 17 . error state 3 dyspec : DAY . (19) dyspec : DAY . ',' (20) ',' shift 18 $end reduce 19 MONTH reduce 19 DAY reduce 19 NUMBER reduce 19 UNIT reduce 19 MUNIT reduce 19 SUNIT reduce 19 ZONE reduce 19 DAYZONE reduce 19 4: shift/reduce conflict (shift 19, reduce 9) on MONTH 4: shift/reduce conflict (shift 20, reduce 9) on DAY 4: shift/reduce conflict (shift 22, reduce 9) on UNIT 4: shift/reduce conflict (shift 23, reduce 9) on MUNIT 4: shift/reduce conflict (shift 24, reduce 9) on SUNIT state 4 nspec : NUMBER . (9) tspec : NUMBER . MERIDIAN (10) tspec : NUMBER . ':' NUMBER (11) tspec : NUMBER . ':' NUMBER MERIDIAN (12) tspec : NUMBER . ':' NUMBER NUMBER (13) tspec : NUMBER . ':' NUMBER ':' NUMBER (14) tspec : NUMBER . ':' NUMBER ':' NUMBER MERIDIAN (15) tspec : NUMBER . ':' NUMBER ':' NUMBER NUMBER (16) dyspec : NUMBER . DAY (21) dtspec : NUMBER . '/' NUMBER (22) dtspec : NUMBER . '/' NUMBER '/' NUMBER (23) dtspec : NUMBER . MONTH (29) dtspec : NUMBER . MONTH NUMBER (30) rspec : NUMBER . UNIT (31) rspec : NUMBER . MUNIT (32) rspec : NUMBER . SUNIT (33) MONTH shift 19 DAY shift 20 MERIDIAN shift 21 UNIT shift 22 MUNIT shift 23 SUNIT shift 24 ':' shift 25 '/' shift 26 $end reduce 9 NUMBER reduce 9 ZONE reduce 9 DAYZONE reduce 9 state 5 rspec : UNIT . (34) . reduce 34 state 6 rspec : MUNIT . (35) . reduce 35 state 7 rspec : SUNIT . (36) . reduce 36 state 8 zone : ZONE . (17) . reduce 17 state 9 zone : DAYZONE . (18) . reduce 18 state 10 timedate : timedate item . (2) . reduce 2 state 11 item : tspec . (3) . reduce 3 state 12 item : zone . (4) . reduce 4 state 13 item : dtspec . (5) . reduce 5 state 14 item : dyspec . (6) . reduce 6 state 15 item : rspec . (7) rspec : rspec . AGO (37) AGO shift 27 $end reduce 7 MONTH reduce 7 DAY reduce 7 NUMBER reduce 7 UNIT reduce 7 MUNIT reduce 7 SUNIT reduce 7 ZONE reduce 7 DAYZONE reduce 7 state 16 item : nspec . (8) . reduce 8 17: shift/reduce conflict (shift 28, reduce 24) on NUMBER state 17 dtspec : MONTH NUMBER . (24) dtspec : MONTH NUMBER . ',' NUMBER (25) dtspec : MONTH NUMBER . NUMBER ':' NUMBER (26) dtspec : MONTH NUMBER . NUMBER ':' NUMBER ':' NUMBER (27) dtspec : MONTH NUMBER . NUMBER (28) NUMBER shift 28 ',' shift 29 $end reduce 24 MONTH reduce 24 DAY reduce 24 UNIT reduce 24 MUNIT reduce 24 SUNIT reduce 24 ZONE reduce 24 DAYZONE reduce 24 state 18 dyspec : DAY ',' . (20) . reduce 20 19: shift/reduce conflict (shift 30, reduce 29) on NUMBER state 19 dtspec : NUMBER MONTH . (29) dtspec : NUMBER MONTH . NUMBER (30) NUMBER shift 30 $end reduce 29 MONTH reduce 29 DAY reduce 29 UNIT reduce 29 MUNIT reduce 29 SUNIT reduce 29 ZONE reduce 29 DAYZONE reduce 29 state 20 dyspec : NUMBER DAY . (21) . reduce 21 state 21 tspec : NUMBER MERIDIAN . (10) . reduce 10 state 22 rspec : NUMBER UNIT . (31) . reduce 31 state 23 rspec : NUMBER MUNIT . (32) . reduce 32 state 24 rspec : NUMBER SUNIT . (33) . reduce 33 state 25 tspec : NUMBER ':' . NUMBER (11) tspec : NUMBER ':' . NUMBER MERIDIAN (12) tspec : NUMBER ':' . NUMBER NUMBER (13) tspec : NUMBER ':' . NUMBER ':' NUMBER (14) tspec : NUMBER ':' . NUMBER ':' NUMBER MERIDIAN (15) tspec : NUMBER ':' . NUMBER ':' NUMBER NUMBER (16) NUMBER shift 31 . error state 26 dtspec : NUMBER '/' . NUMBER (22) dtspec : NUMBER '/' . NUMBER '/' NUMBER (23) NUMBER shift 32 . error state 27 rspec : rspec AGO . (37) . reduce 37 state 28 dtspec : MONTH NUMBER NUMBER . ':' NUMBER (26) dtspec : MONTH NUMBER NUMBER . ':' NUMBER ':' NUMBER (27) dtspec : MONTH NUMBER NUMBER . (28) ':' shift 33 $end reduce 28 MONTH reduce 28 DAY reduce 28 NUMBER reduce 28 UNIT reduce 28 MUNIT reduce 28 SUNIT reduce 28 ZONE reduce 28 DAYZONE reduce 28 state 29 dtspec : MONTH NUMBER ',' . NUMBER (25) NUMBER shift 34 . error state 30 dtspec : NUMBER MONTH NUMBER . (30) . reduce 30 31: shift/reduce conflict (shift 36, reduce 11) on NUMBER state 31 tspec : NUMBER ':' NUMBER . (11) tspec : NUMBER ':' NUMBER . MERIDIAN (12) tspec : NUMBER ':' NUMBER . NUMBER (13) tspec : NUMBER ':' NUMBER . ':' NUMBER (14) tspec : NUMBER ':' NUMBER . ':' NUMBER MERIDIAN (15) tspec : NUMBER ':' NUMBER . ':' NUMBER NUMBER (16) MERIDIAN shift 35 NUMBER shift 36 ':' shift 37 $end reduce 11 MONTH reduce 11 DAY reduce 11 UNIT reduce 11 MUNIT reduce 11 SUNIT reduce 11 ZONE reduce 11 DAYZONE reduce 11 state 32 dtspec : NUMBER '/' NUMBER . (22) dtspec : NUMBER '/' NUMBER . '/' NUMBER (23) '/' shift 38 $end reduce 22 MONTH reduce 22 DAY reduce 22 NUMBER reduce 22 UNIT reduce 22 MUNIT reduce 22 SUNIT reduce 22 ZONE reduce 22 DAYZONE reduce 22 state 33 dtspec : MONTH NUMBER NUMBER ':' . NUMBER (26) dtspec : MONTH NUMBER NUMBER ':' . NUMBER ':' NUMBER (27) NUMBER shift 39 . error state 34 dtspec : MONTH NUMBER ',' NUMBER . (25) . reduce 25 state 35 tspec : NUMBER ':' NUMBER MERIDIAN . (12) . reduce 12 state 36 tspec : NUMBER ':' NUMBER NUMBER . (13) . reduce 13 state 37 tspec : NUMBER ':' NUMBER ':' . NUMBER (14) tspec : NUMBER ':' NUMBER ':' . NUMBER MERIDIAN (15) tspec : NUMBER ':' NUMBER ':' . NUMBER NUMBER (16) NUMBER shift 40 . error state 38 dtspec : NUMBER '/' NUMBER '/' . NUMBER (23) NUMBER shift 41 . error state 39 dtspec : MONTH NUMBER NUMBER ':' NUMBER . (26) dtspec : MONTH NUMBER NUMBER ':' NUMBER . ':' NUMBER (27) ':' shift 42 $end reduce 26 MONTH reduce 26 DAY reduce 26 NUMBER reduce 26 UNIT reduce 26 MUNIT reduce 26 SUNIT reduce 26 ZONE reduce 26 DAYZONE reduce 26 40: shift/reduce conflict (shift 44, reduce 14) on NUMBER state 40 tspec : NUMBER ':' NUMBER ':' NUMBER . (14) tspec : NUMBER ':' NUMBER ':' NUMBER . MERIDIAN (15) tspec : NUMBER ':' NUMBER ':' NUMBER . NUMBER (16) MERIDIAN shift 43 NUMBER shift 44 $end reduce 14 MONTH reduce 14 DAY reduce 14 UNIT reduce 14 MUNIT reduce 14 SUNIT reduce 14 ZONE reduce 14 DAYZONE reduce 14 state 41 dtspec : NUMBER '/' NUMBER '/' NUMBER . (23) . reduce 23 state 42 dtspec : MONTH NUMBER NUMBER ':' NUMBER ':' . NUMBER (27) NUMBER shift 45 . error state 43 tspec : NUMBER ':' NUMBER ':' NUMBER MERIDIAN . (15) . reduce 15 state 44 tspec : NUMBER ':' NUMBER ':' NUMBER NUMBER . (16) . reduce 16 state 45 dtspec : MONTH NUMBER NUMBER ':' NUMBER ':' NUMBER . (27) . reduce 27 State 4 contains 5 shift/reduce conflicts. State 17 contains 1 shift/reduce conflict. State 19 contains 1 shift/reduce conflict. State 31 contains 1 shift/reduce conflict. State 40 contains 1 shift/reduce conflict. 16 terminals, 9 nonterminals 38 grammar rules, 46 states perl-byacc-2.0.orig/test/getdate.tab.ph100644 1750 1750 201 5265512124 16603 0ustar bortzbortz$ID=257; $MONTH=258; $DAY=259; $MERIDIAN=260; $NUMBER=261; $UNIT=262; $MUNIT=263; $SUNIT=264; $ZONE=265; $DAYZONE=266; $AGO=267; perl-byacc-2.0.orig/test/getdate.tab.pl100644 1750 1750 73210 5325620041 16654 0ustar bortzbortz$yysccsid = "@(#)yaccpar 1.8 (Berkeley) 01/20/91 (Perl 2.0 12/31/92)"; #define YYBYACC 1 #line 3 "getdate.y" ;# Steven M. Bellovin (unc!smb) ;# Dept. of Computer Science ;# University of North Carolina at Chapel Hill ;# @(#)getdate.y 2.13 9/16/86 ;# ;# Richard J. Ohnemus (rick@IMD.Sterling.COM) ;# (Where do I work??? I'm not even sure who I am! 8-{) ;# 04/24/92 converted to PERL. ;# 07/06/92 New date format (MONTH NUMBER NUMBER ':' NUMBER ':' NUMBER) ;# suggested by Raphael Manfredi . ;# 07/08/92 Fixed table search in &lookup. ;# Call &localtime with correct value in &monthadd. ;# 10/08/92 Numeric values starting with pattern '0+[89]' interpretted ;# correctly. ;# Corrected European Western and Eastern time offsets. ;# Borrowed code from timelocal.pl to determine timezone offset ;# from GMT. ;# 10/10/92 Handle time zone offsets correctly (sign was reversed). ;# Set global time zone variable ('ourzone') correctly. package getdate; $AM = 1; $PM = 2; $DAYLIGHT = 1; $STANDARD = 2; $MAYBE = 3; @mdays = (31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); $epoch = 1970; $daysec = 24 * 60 * 60; #line 36 "getdate.tab.pl" $ID=257; $MONTH=258; $DAY=259; $MERIDIAN=260; $NUMBER=261; $UNIT=262; $MUNIT=263; $SUNIT=264; $ZONE=265; $DAYZONE=266; $AGO=267; $YYERRCODE=256; @yylhs = ( -1, 0, 0, 1, 1, 1, 1, 1, 1, 7, 2, 2, 2, 2, 2, 2, 2, 3, 3, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 6, 6, 6, 6, ); @yylen = ( 2, 0, 2, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 4, 5, 6, 6, 1, 1, 1, 2, 2, 3, 5, 2, 4, 5, 7, 3, 2, 3, 2, 2, 2, 1, 1, 1, 2, ); @yydefred = ( 1, 0, 0, 0, 0, 34, 35, 36, 17, 18, 2, 3, 4, 5, 6, 0, 8, 0, 20, 0, 21, 10, 31, 32, 33, 0, 0, 37, 0, 0, 30, 0, 0, 0, 25, 12, 13, 0, 0, 0, 0, 23, 0, 15, 16, 27, ); @yydgoto = ( 1, 10, 11, 12, 13, 14, 15, 16, ); @yysindex = ( 0, -241, -255, -37, -47, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -259, 0, -42, 0, -252, 0, 0, 0, 0, 0, -249, -248, 0, -44, -246, 0, -55, -31, -235, 0, 0, 0, -234, -232, -28, -256, 0, -230, 0, 0, 0, ); @yyrindex = ( 0, 0, 0, 1, 79, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 46, 0, 55, 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 64, 28, 0, 0, 0, 0, 0, 0, 37, 73, 0, 0, 0, 0, 0, ); @yygindex = ( 0, 0, 0, 0, 0, 0, 0, 0, ); $YYTABLESIZE=345; @yytable = ( 26, 19, 29, 37, 43, 44, 17, 18, 27, 30, 7, 25, 31, 32, 33, 34, 38, 2, 3, 28, 4, 5, 6, 7, 8, 9, 39, 40, 22, 41, 42, 45, 0, 0, 0, 0, 0, 26, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0, 29, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 35, 36, 0, 0, 0, 0, 19, 20, 21, 0, 22, 23, 24, 0, 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 19, 0, 19, 19, 19, 19, 19, 19, 7, 7, 0, 7, 7, 7, 7, 7, 7, 28, 28, 0, 28, 28, 28, 28, 28, 28, 22, 22, 0, 22, 22, 22, 22, 22, 22, 26, 26, 0, 26, 26, 26, 26, 26, 26, 24, 24, 0, 0, 24, 24, 24, 24, 24, 29, 29, 0, 0, 29, 29, 29, 29, 29, 11, 11, 0, 0, 11, 11, 11, 11, 11, 14, 14, 0, 0, 14, 14, 14, 14, 14, 9, 0, 0, 0, 9, 9, ); @yycheck = ( 47, 0, 44, 58, 260, 261, 261, 44, 267, 261, 0, 58, 261, 261, 58, 261, 47, 258, 259, 0, 261, 262, 263, 264, 265, 266, 261, 261, 0, 261, 58, 261, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 260, 261, -1, -1, -1, -1, 258, 259, 260, -1, 262, 263, 264, -1, 261, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 258, 259, -1, 261, 262, 263, 264, 265, 266, 258, 259, -1, 261, 262, 263, 264, 265, 266, 258, 259, -1, 261, 262, 263, 264, 265, 266, 258, 259, -1, 261, 262, 263, 264, 265, 266, 258, 259, -1, 261, 262, 263, 264, 265, 266, 258, 259, -1, -1, 262, 263, 264, 265, 266, 258, 259, -1, -1, 262, 263, 264, 265, 266, 258, 259, -1, -1, 262, 263, 264, 265, 266, 258, 259, -1, -1, 262, 263, 264, 265, 266, 261, -1, -1, -1, 265, 266, ); $YYFINAL=1; #ifndef YYDEBUG #define YYDEBUG 0 #endif $YYMAXTOKEN=267; #if YYDEBUG @yyname = ( "end-of-file",'','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','', '','','','','','','','','','',"','",'','',"'/'",'','','','','','','','','','',"':'",'','','','','','','','','', '','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','', '','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','', '','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','', '','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','','', '','','','','','','','','','','','','','','','','','','','','','','','','','','','','',"ID","MONTH","DAY", "MERIDIAN","NUMBER","UNIT","MUNIT","SUNIT","ZONE","DAYZONE","AGO", ); @yyrule = ( "\$accept : timedate", "timedate :", "timedate : timedate item", "item : tspec", "item : zone", "item : dtspec", "item : dyspec", "item : rspec", "item : nspec", "nspec : NUMBER", "tspec : NUMBER MERIDIAN", "tspec : NUMBER ':' NUMBER", "tspec : NUMBER ':' NUMBER MERIDIAN", "tspec : NUMBER ':' NUMBER NUMBER", "tspec : NUMBER ':' NUMBER ':' NUMBER", "tspec : NUMBER ':' NUMBER ':' NUMBER MERIDIAN", "tspec : NUMBER ':' NUMBER ':' NUMBER NUMBER", "zone : ZONE", "zone : DAYZONE", "dyspec : DAY", "dyspec : DAY ','", "dyspec : NUMBER DAY", "dtspec : NUMBER '/' NUMBER", "dtspec : NUMBER '/' NUMBER '/' NUMBER", "dtspec : MONTH NUMBER", "dtspec : MONTH NUMBER ',' NUMBER", "dtspec : MONTH NUMBER NUMBER ':' NUMBER", "dtspec : MONTH NUMBER NUMBER ':' NUMBER ':' NUMBER", "dtspec : MONTH NUMBER NUMBER", "dtspec : NUMBER MONTH", "dtspec : NUMBER MONTH NUMBER", "rspec : NUMBER UNIT", "rspec : NUMBER MUNIT", "rspec : NUMBER SUNIT", "rspec : UNIT", "rspec : MUNIT", "rspec : SUNIT", "rspec : rspec AGO", ); #endif sub yyclearin { $yychar = -1; } sub yyerrok { $yyerrflag = 0; } $YYSTACKSIZE = $YYSTACKSIZE || $YYMAXDEPTH || 500; $YYMAXDEPTH = $YYMAXDEPTH || $YYSTACKSIZE || 500; $yyss[$YYSTACKSIZE] = 0; $yyvs[$YYSTACKSIZE] = 0; sub YYERROR { ++$yynerrs; &yy_err_recover; } sub yy_err_recover { if ($yyerrflag < 3) { $yyerrflag = 3; while (1) { if (($yyn = $yysindex[$yyss[$yyssp]]) && ($yyn += $YYERRCODE) >= 0 && $yycheck[$yyn] == $YYERRCODE) { #if YYDEBUG print "yydebug: state $yyss[$yyssp], error recovery shifting", " to state $yytable[$yyn]\n" if $yydebug; #endif $yyss[++$yyssp] = $yystate = $yytable[$yyn]; $yyvs[++$yyvsp] = $yylval; next yyloop; } else { #if YYDEBUG print "yydebug: error recovery discarding state ", $yyss[$yyssp], "\n" if $yydebug; #endif return(1) if $yyssp <= 0; --$yyssp; --$yyvsp; } } } else { return (1) if $yychar == 0; #if YYDEBUG if ($yydebug) { $yys = ''; if ($yychar <= $YYMAXTOKEN) { $yys = $yyname[$yychar]; } if (!$yys) { $yys = 'illegal-symbol'; } print "yydebug: state $yystate, error recovery discards ", "token $yychar ($yys)\n"; } #endif $yychar = -1; next yyloop; } 0; } # yy_err_recover sub yyparse { #ifdef YYDEBUG if ($yys = $ENV{'YYDEBUG'}) { $yydebug = int($1) if $yys =~ /^(\d)/; } #endif $yynerrs = 0; $yyerrflag = 0; $yychar = (-1); $yyssp = 0; $yyvsp = 0; $yyss[$yyssp] = $yystate = 0; yyloop: while(1) { yyreduce: { last yyreduce if ($yyn = $yydefred[$yystate]); if ($yychar < 0) { if (($yychar = &yylex) < 0) { $yychar = 0; } #if YYDEBUG if ($yydebug) { $yys = ''; if ($yychar <= $#yyname) { $yys = $yyname[$yychar]; } if (!$yys) { $yys = 'illegal-symbol'; }; print "yydebug: state $yystate, reading $yychar ($yys)\n"; } #endif } if (($yyn = $yysindex[$yystate]) && ($yyn += $yychar) >= 0 && $yycheck[$yyn] == $yychar) { #if YYDEBUG print "yydebug: state $yystate, shifting to state ", $yytable[$yyn], "\n" if $yydebug; #endif $yyss[++$yyssp] = $yystate = $yytable[$yyn]; $yyvs[++$yyvsp] = $yylval; $yychar = (-1); --$yyerrflag if $yyerrflag > 0; next yyloop; } if (($yyn = $yyrindex[$yystate]) && ($yyn += $yychar) >= 0 && $yycheck[$yyn] == $yychar) { $yyn = $yytable[$yyn]; last yyreduce; } if (! $yyerrflag) { &yyerror('syntax error'); ++$yynerrs; } return(1) if &yy_err_recover; } # yyreduce #if YYDEBUG print "yydebug: state $yystate, reducing by rule ", "$yyn ($yyrule[$yyn])\n" if $yydebug; #endif $yym = $yylen[$yyn]; $yyval = $yyvs[$yyvsp+1-$yym]; switch: { if ($yyn == 3) { #line 41 "getdate.y" { $timeflag++; last switch; } } if ($yyn == 4) { #line 45 "getdate.y" { $zoneflag++; last switch; } } if ($yyn == 5) { #line 49 "getdate.y" { $dateflag++; last switch; } } if ($yyn == 6) { #line 53 "getdate.y" { $dayflag++; last switch; } } if ($yyn == 7) { #line 57 "getdate.y" { $relflag++; last switch; } } if ($yyn == 9) { #line 64 "getdate.y" { if ($timeflag && $dateflag && !$relflag) { $year = $yyvs[$yyvsp-0]; } else { $timeflag++; $hh = int($yyvs[$yyvsp-0] / 100); $mm = $yyvs[$yyvsp-0] % 100; $ss = 0; $merid = 24; } last switch; } } if ($yyn == 10) { #line 79 "getdate.y" { $hh = $yyvs[$yyvsp-1]; $mm = 0; $ss = 0; $merid = $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 11) { #line 86 "getdate.y" { $hh = $yyvs[$yyvsp-2]; $mm = $yyvs[$yyvsp-0]; $merid = 24; last switch; } } if ($yyn == 12) { #line 92 "getdate.y" { $hh = $yyvs[$yyvsp-3]; $mm = $yyvs[$yyvsp-1]; $merid = $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 13) { #line 98 "getdate.y" { $hh = $yyvs[$yyvsp-3]; $mm = $yyvs[$yyvsp-1]; $merid = 24; $daylight = $STANDARD; $ourzone = -($yyvs[$yyvsp-0] % 100 + 60 * int($yyvs[$yyvsp-0] / 100)); last switch; } } if ($yyn == 14) { #line 106 "getdate.y" { $hh = $yyvs[$yyvsp-4]; $mm = $yyvs[$yyvsp-2]; $ss = $yyvs[$yyvsp-0]; $merid = 24; last switch; } } if ($yyn == 15) { #line 113 "getdate.y" { $hh = $yyvs[$yyvsp-5]; $mm = $yyvs[$yyvsp-3]; $ss = $yyvs[$yyvsp-1]; $merid = $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 16) { #line 120 "getdate.y" { $hh = $yyvs[$yyvsp-5]; $mm = $yyvs[$yyvsp-3]; $ss = $yyvs[$yyvsp-1]; $merid = 24; $daylight = $STANDARD; $ourzone = -($yyvs[$yyvsp-0] % 100 + 60 * int($yyvs[$yyvsp-0] / 100)); last switch; } } if ($yyn == 17) { #line 131 "getdate.y" { $ourzone = $yyvs[$yyvsp-0]; $daylight = $STANDARD; last switch; } } if ($yyn == 18) { #line 136 "getdate.y" { $ourzone = $yyvs[$yyvsp-0]; $daylight = $DAYLIGHT; last switch; } } if ($yyn == 19) { #line 143 "getdate.y" { $dayord = 1; $dayreq = $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 20) { #line 148 "getdate.y" { $dayord = 1; $dayreq = $yyvs[$yyvsp-1]; last switch; } } if ($yyn == 21) { #line 153 "getdate.y" { $dayord = $yyvs[$yyvsp-1]; $dayreq = $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 22) { #line 160 "getdate.y" { $month = $yyvs[$yyvsp-2]; $day = $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 23) { #line 165 "getdate.y" { # ;# * HACK ALERT!!!! ;# * The 1000 is a magic number to attempt to force ;# * use of 4 digit years if year/month/day can be ;# * parsed. This was only done for backwards ;# * compatibility in rh. ;# if ($yyvs[$yyvsp-4] > 1000) { $year = $yyvs[$yyvsp-4]; $month = $yyvs[$yyvsp-2]; $day = $yyvs[$yyvsp-0]; } else { $month = $yyvs[$yyvsp-4]; $day = $yyvs[$yyvsp-2]; $year = $yyvs[$yyvsp-0]; } last switch; } } if ($yyn == 24) { #line 185 "getdate.y" { $month = $yyvs[$yyvsp-1]; $day = $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 25) { #line 190 "getdate.y" { $month = $yyvs[$yyvsp-3]; $day = $yyvs[$yyvsp-2]; $year = $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 26) { #line 196 "getdate.y" { $month = $yyvs[$yyvsp-4]; $day = $yyvs[$yyvsp-3]; $hh = $yyvs[$yyvsp-2]; $mm = $yyvs[$yyvsp-0]; $merid = 24; $timeflag++; last switch; } } if ($yyn == 27) { #line 205 "getdate.y" { $month = $yyvs[$yyvsp-6]; $day = $yyvs[$yyvsp-5]; $hh = $yyvs[$yyvsp-4]; $mm = $yyvs[$yyvsp-2]; $ss = $yyvs[$yyvsp-0]; $merid = 24; $timeflag++; last switch; } } if ($yyn == 28) { #line 215 "getdate.y" { $month = $yyvs[$yyvsp-2]; $day = $yyvs[$yyvsp-1]; $year = $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 29) { #line 221 "getdate.y" { $month = $yyvs[$yyvsp-0]; $day = $yyvs[$yyvsp-1]; last switch; } } if ($yyn == 30) { #line 226 "getdate.y" { $month = $yyvs[$yyvsp-1]; $day = $yyvs[$yyvsp-2]; $year = $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 31) { #line 234 "getdate.y" { $relsec += 60 * $yyvs[$yyvsp-1] * $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 32) { #line 238 "getdate.y" { $relmonth += $yyvs[$yyvsp-1] * $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 33) { #line 242 "getdate.y" { $relsec += $yyvs[$yyvsp-1]; last switch; } } if ($yyn == 34) { #line 246 "getdate.y" { $relsec += 60 * $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 35) { #line 250 "getdate.y" { $relmonth += $yyvs[$yyvsp-0]; last switch; } } if ($yyn == 36) { #line 254 "getdate.y" { $relsec++; last switch; } } if ($yyn == 37) { #line 258 "getdate.y" { $relsec = -$relsec; $relmonth = -$relmonth; last switch; } } #line 690 "getdate.tab.pl" } # switch $yyssp -= $yym; $yystate = $yyss[$yyssp]; $yyvsp -= $yym; $yym = $yylhs[$yyn]; if ($yystate == 0 && $yym == 0) { #if YYDEBUG print "yydebug: after reduction, shifting from state 0 ", "to state $YYFINAL\n" if $yydebug; #endif $yystate = $YYFINAL; $yyss[++$yyssp] = $YYFINAL; $yyvs[++$yyvsp] = $yyval; if ($yychar < 0) { if (($yychar = &yylex) < 0) { $yychar = 0; } #if YYDEBUG if ($yydebug) { $yys = ''; if ($yychar <= $#yyname) { $yys = $yyname[$yychar]; } if (!$yys) { $yys = 'illegal-symbol'; } print "yydebug: state $YYFINAL, reading $yychar ($yys)\n"; } #endif } return(0) if $yychar == 0; next yyloop; } if (($yyn = $yygindex[$yym]) && ($yyn += $yystate) >= 0 && $yyn <= $#yycheck && $yycheck[$yyn] == $yystate) { $yystate = $yytable[$yyn]; } else { $yystate = $yydgoto[$yym]; } #if YYDEBUG print "yydebug: after reduction, shifting from state ", "$yyss[$yyssp] to state $yystate\n" if $yydebug; #endif $yyss[++$yyssp] = $yystate; $yyvs[++$yyvsp] = $yyval; } # yyloop } # yyparse #line 265 "getdate.y" sub dateconv { local($mm, $dd, $yy, $h, $m, $s, $mer, $zone, $dayflag) = @_; local($time_of_day, $jdate); local($i); if ($yy < 0) { $yy = -$yy; } if ($yy < 100) { $yy += 1900; } $mdays[1] = 28 + (($yy % 4) == 0 && (($yy % 100) != 0 || ($yy % 400) == 0)); if ($yy < $epoch || $yy > 2001 || $mm < 1 || $mm > 12 || $dd < 1 || $dd > $mdays[--$mm]) { return -1; } $jdate = $dd - 1; for ($i = 0; $i < $mm; $i++) { $jdate += $mdays[$i]; } for ($i = $epoch; $i < $yy; $i++) { $jdate += 365 + (($i % 4) == 0); } $jdate *= $daysec; $jdate += $zone * 60; if (($time_of_day = &timeconv($h, $m, $s, $mer)) < 0) { return -1; } $jdate += $time_of_day; if ($dayflag == $DAYLIGHT || ($dayflag == $MAYBE && (localtime($jdate))[8])) { $jdate -= 60 * 60; } return $jdate; } sub dayconv { local($ordday, $day, $now) = @_; local(@loctime); local($time_of_day); $time_of_day = $now; @loctime = localtime($time_of_day); $time_of_day += $daysec * (($day - $loctime[6] + 7) % 7); $time_of_day += 7 * $daysec * ($ordday <= 0 ? $ordday : $ordday - 1); return &daylcorr($time_of_day, $now); } sub timeconv { local($hh, $mm, $ss, $mer) = @_; return -1 if ($mm < 0 || $mm > 59 || $ss < 0 || $ss > 59); if ($mer == $AM) { return -1 if ($hh < 1 || $hh > 12); return 60 * (($hh % 12) * 60 + $mm) + $ss; } if ($mer == $PM) { return -1 if ($hh < 1 || $hh > 12); return 60 * (($hh % 12 + 12) * 60 + $mm) + $ss; } if ($mer == 24) { return -1 if ($hh < 0 || $hh > 23); return 60 * ($hh * 60 + $mm) + $ss; } return -1; } sub monthadd { local($sdate, $relmonth) = @_; local(@ltime); local($mm, $yy); return 0 if ($relmonth == 0); @ltime = localtime($sdate); $mm = 12 * $ltime[5] + $ltime[4] + $relmonth; $yy = int($mm / 12); $mm = $mm % 12 + 1; return &daylcorr(&dateconv($mm, $ltime[3], $yy, $ltime[2], $ltime[1], $ltime[0], 24, $ourzone, $MAYBE), $sdate); } sub daylcorr { local($future, $now) = @_; local($fdayl, $nowdayl); $nowdayl = ((localtime($now))[2] + 1) % 24; $fdayl = ((localtime($future))[2] + 1) % 24; return ($future - $now) + 60 * 60 * ($nowdayl - $fdayl); } sub yylex { local($pcnt, $sign); while (1) { $dtstr =~ s/^\s*//; if ($dtstr =~ /^([-+])/) { $sign = ($1 eq '-') ? -1 : 1; $dtstr =~ s/^.//; if ($dtstr =~ /^(\d+)/) { $num = $1; $num =~ s/^0+//; if ($num eq '') { $yylval = 0; } else { $yylval = eval "$num * $sign"; } $dtstr =~ s/^\d+//; return $NUMBER; } else { return &yylex; } } elsif ($dtstr =~ /^(\d+)/) { $num = $1; $num =~ s/^0+//; if ($num eq '') { $yylval = 0; } else { $yylval = eval "$num"; } $dtstr =~ s/^\d+//; return $NUMBER; } elsif ($dtstr =~ /^([a-zA-z][a-zA-Z.]*)/) { $dtstr = substr($dtstr, length($1)); return &lookup($1); } elsif ($dtstr =~ /^\(/) { $pcnt = 0; do { $dtstr = s/^(.)//; return 0 if !defined($1); $pcnt++ if ($1 eq '('); $pcnt-- if ($1 eq ')'); } while ($pcnt > 0); } else { $yylval = ord(substr($dtstr, 0, 1)); $dtstr =~ s/^.//; return $yylval; } } } %mdtab = ( "January", "$MONTH,1", "February", "$MONTH,2", "March", "$MONTH,3", "April", "$MONTH,4", "May", "$MONTH,5", "June", "$MONTH,6", "July", "$MONTH,7", "August", "$MONTH,8", "September", "$MONTH,9", "Sept", "$MONTH,9", "October", "$MONTH,10", "November", "$MONTH,11", "December", "$MONTH,12", "Sunday", "$DAY,0", "Monday", "$DAY,1", "Tuesday", "$DAY,2", "Tues", "$DAY,2", "Wednesday", "$DAY,3", "Wednes", "$DAY,3", "Thursday", "$DAY,4", "Thur", "$DAY,4", "Thurs", "$DAY,4", "Friday", "$DAY,5", "Saturday", "$DAY,6" ); $HRS='*60'; $HALFHR='30'; %mztab = ( "a.m.", "$MERIDIAN,$AM", "am", "$MERIDIAN,$AM", "p.m.", "$MERIDIAN,$PM", "pm", "$MERIDIAN,$PM", "nst", "$ZONE,3 $HRS + $HALFHR", # Newfoundland "n.s.t.", "$ZONE,3 $HRS + $HALFHR", "ast", "$ZONE,4 $HRS", # Atlantic "a.s.t.", "$ZONE,4 $HRS", "adt", "$DAYZONE,4 $HRS", "a.d.t.", "$DAYZONE,4 $HRS", "est", "$ZONE,5 $HRS", # Eastern "e.s.t.", "$ZONE,5 $HRS", "edt", "$DAYZONE,5 $HRS", "e.d.t.", "$DAYZONE,5 $HRS", "cst", "$ZONE,6 $HRS", # Central "c.s.t.", "$ZONE,6 $HRS", "cdt", "$DAYZONE,6 $HRS", "c.d.t.", "$DAYZONE,6 $HRS", "mst", "$ZONE,7 $HRS", # Mountain "m.s.t.", "$ZONE,7 $HRS", "mdt", "$DAYZONE,7 $HRS", "m.d.t.", "$DAYZONE,7 $HRS", "pst", "$ZONE,8 $HRS", # Pacific "p.s.t.", "$ZONE,8 $HRS", "pdt", "$DAYZONE,8 $HRS", "p.d.t.", "$DAYZONE,8 $HRS", "yst", "$ZONE,9 $HRS", # Yukon "y.s.t.", "$ZONE,9 $HRS", "ydt", "$DAYZONE,9 $HRS", "y.d.t.", "$DAYZONE,9 $HRS", "hst", "$ZONE,10 $HRS", # Hawaii "h.s.t.", "$ZONE,10 $HRS", "hdt", "$DAYZONE,10 $HRS", "h.d.t.", "$DAYZONE,10 $HRS", "gmt", "$ZONE,0 $HRS", "g.m.t.", "$ZONE,0 $HRS", "bst", "$DAYZONE,0 $HRS", # British Summer Time "b.s.t.", "$DAYZONE,0 $HRS", "wet", "$ZONE,0 $HRS ", # Western European Time "w.e.t.", "$ZONE,0 $HRS ", "west", "$DAYZONE,0 $HRS", # Western European Summer Time "w.e.s.t.", "$DAYZONE,0 $HRS", "met", "$ZONE,-1 $HRS", # Middle European Time "m.e.t.", "$ZONE,-1 $HRS", "mest", "$DAYZONE,-1 $HRS", # Middle European Summer Time "m.e.s.t.", "$DAYZONE,-1 $HRS", "eet", "$ZONE,-2 $HRS", # European Eastern Time "e.e.t.", "$ZONE,-2 $HRS", "eest", "$DAYZONE,-2 $HRS", # European Eastern Summer Time "e.e.s.t.", "$DAYZONE,-2 $HRS", "jst", "$ZONE,-9 $HRS", # Japan Standard Time "j.s.t.", "$ZONE,-9 $HRS", # Japan Standard Time # No daylight savings time "aest", "$ZONE,-10 $HRS", # Australian Eastern Time "a.e.s.t.", "$ZONE,-10 $HRS", "aesst", "$DAYZONE,-10 $HRS", # Australian Eastern Summer Time "a.e.s.s.t.", "$DAYZONE,-10 $HRS", "acst", "$ZONE,-(9 $HRS + $HALFHR)", # Australian Central Time "a.c.s.t.", "$ZONE,-(9 $HRS + $HALFHR)", "acsst", "$DAYZONE,-(9 $HRS + $HALFHR)", # Australian Central Summer "a.c.s.s.t.", "$DAYZONE,-(9 $HRS + $HALFHR)", "awst", "$ZONE,-8 $HRS", # Australian Western Time "a.w.s.t.", "$ZONE,-8 $HRS" # (no daylight time there, I'm told) ); %unittab = ( "year", "$MUNIT,12", "month", "$MUNIT,1", "fortnight", "$UNIT,14*24*60", "week", "$UNIT,7*24*60", "day", "$UNIT,1*24*60", "hour", "$UNIT,60", "minute", "$UNIT,1", "min", "$UNIT,1", "second", "$SUNIT,1", "sec", "$SUNIT,1" ); %othertab = ( "tomorrow", "$UNIT,1*24*60", "yesterday","$UNIT,-1*24*60", "today", "$UNIT,0", "now", "$UNIT,0", "last", "$NUMBER,-1", "this", "$UNIT,0", "next", "$NUMBER,2", "first", "$NUMBER,1", # "second", "$NUMBER,2", "third", "$NUMBER,3", "fourth", "$NUMBER,4", "fifth", "$NUMBER,5", "sixth", "$NUMBER,6", "seventh", "$NUMBER,7", "eigth", "$NUMBER,8", "ninth", "$NUMBER,9", "tenth", "$NUMBER,10", "eleventh", "$NUMBER,11", "twelfth", "$NUMBER,12", "ago", "$AGO,1" ); %milzone = ( "a", "$ZONE,1 $HRS", "b", "$ZONE,2 $HRS", "c", "$ZONE,3 $HRS", "d", "$ZONE,4 $HRS", "e", "$ZONE,5 $HRS", "f", "$ZONE,6 $HRS", "g", "$ZONE,7 $HRS", "h", "$ZONE,8 $HRS", "i", "$ZONE,9 $HRS", "k", "$ZONE,10 $HRS", "l", "$ZONE,11 $HRS", "m", "$ZONE,12 $HRS", "n", "$ZONE,-1 $HRS", "o", "$ZONE,-2 $HRS", "p", "$ZONE,-3 $HRS", "q", "$ZONE,-4 $HRS", "r", "$ZONE,-5 $HRS", "s", "$ZONE,-6 $HRS", "t", "$ZONE,-7 $HRS", "u", "$ZONE,-8 $HRS", "v", "$ZONE,-9 $HRS", "w", "$ZONE,-10 $HRS", "x", "$ZONE,-11 $HRS", "y", "$ZONE,-12 $HRS", "z", "$ZONE,0 $HRS" ); sub lookup { local($id) = @_; local($abbrev, $idvar, $key, $token); $idvar = $id; if (length($idvar) == 3) { $abbrev = 1; } elsif (length($idvar) == 4 && substr($idvar, 3, 1) eq '.') { $abbrev = 1; $idvar = substr($idvar, 0, 3); } else { $abbrev = 0; } substr($idvar, 0, 1) =~ tr/a-z/A-Z/; if (defined($mdtab{$idvar})) { ($token, $yylval) = split(/,/,$mdtab{$idvar}); $yylval = eval "$yylval"; return $token; } foreach $key (keys %mdtab) { if ($idvar eq substr($key, 0, 3)) { ($token, $yylval) = split(/,/,$mdtab{$key}); $yylval = eval "$yylval"; return $token; } } $idvar = $id; if (defined($mztab{$idvar})) { ($token, $yylval) = split(/,/,$mztab{$idvar}); $yylval = eval "$yylval"; return $token; } $idvar =~ tr/A-Z/a-z/; if (defined($mztab{$idvar})) { ($token, $yylval) = split(/,/,$mztab{$idvar}); $yylval = eval "$yylval"; return $token; } $idvar = $id; if (defined($unittab{$idvar})) { ($token, $yylval) = split(/,/,$unittab{$idvar}); $yylval = eval "$yylval"; return $token; } if ($idvar =~ /s$/) { $idvar =~ s/s$//; } if (defined($unittab{$idvar})) { ($token, $yylval) = split(/,/,$unittab{$idvar}); $yylval = eval "$yylval"; return $token; } $idvar = $id; if (defined($othertab{$idvar})) { ($token, $yylval) = split(/,/,$othertab{$idvar}); $yylval = eval "$yylval"; return $token; } if (length($idvar) == 1 && $idvar =~ /[a-zA-Z]/) { $idvar =~ tr/A-Z/a-z/; if (defined($milzone{$idvar})) { ($token, $yylval) = split(/,/,$milzone{$idvar}); $yylval = eval "$yylval"; return $token; } } return $ID; } sub main'getdate { local($now); local(@lt); local($sdate); local($TZ); ($dtstr, $now, $ourzone) = @_; if (!$now) { $now = time; } if (!$ourzone) { $TZ = defined($ENV{'TZ'}) ? ($ENV{'TZ'} ? $ENV{'TZ'} : '') : ''; if($TZ =~ /^([^:\d+\-,]{3,})([+-]?\d{1,2}(:\d{1,2}){0,2})([^\d+\-,]{3,})?/) { $ourzone = $2 * 60; } else { @lt = localtime(0); $ourzone = $lt[2] * 60 + $lt[1]; # minutes east of GMT if ($ourzone > 0) { $ourzone = 24 * 60 - $ourzone; # minutes west of GMT $ourzone -= 24 * 60 if $lt[5] == 70; # account for date line } } } @lt = localtime($now); $year = 0; $month = $lt[4] + 1; $day = $lt[3]; $relsec = $relmonth = 0; $timeflag = $zoneflag = $dateflag = $dayflag = $relflag = 0; $daylight = $MAYBE; $hh = $mm = $ss = 0; $merid = 24; $dtstr =~ tr/A-Z/a-z/; return -1 if &yyparse; return -1 if ($timeflag > 1 || $zoneflag > 1 || $dateflag > 1 || $dayflag > 1); if (!$year) { $year = ($month > ($lt[4] + 1)) ? ($lt[5] - 1) : $lt[5]; } if ($dateflag || $timeflag || $dayflag) { $sdate = &dateconv($month, $day, $year, $hh, $mm, $ss, $merid, $ourzone, $daylight); if ($sdate < 0) { return -1; } } else { $sdate = $now; if ($relflag == 0) { $sdate -= ($lt[0] + $lt[1] * 60 + $lt[2] * (60 * 60)); } } $sdate += $relsec + &monthadd($sdate, $relmonth); $sdate += &dayconv($dayord, $dayreq, $sdate) if ($dayflag && !$dateflag); return $sdate; } sub yyerror { } 1; #line 1215 "getdate.tab.pl" perl-byacc-2.0.orig/test/Makefile100644 1750 1750 252 5320615313 15532 0ustar bortzbortzall_tests: -../$(PROGRAM) -dv -b error error.y -../$(PROGRAM) -dv -b ftp -p ftp ftp.y -../$(PROGRAM) -P -dv -b calc calc.y -../$(PROGRAM) -P -dv -b getdate getdate.y