diff options
-rw-r--r-- | emacs/caml.el | 8 | ||||
-rw-r--r-- | parsing/parser.mly | 2 | ||||
-rw-r--r-- | test/Moretest/morematch.ml | 202 | ||||
-rw-r--r-- | testasmcomp/ia64.S | 4 | ||||
-rw-r--r-- | yacc/closure.c | 182 | ||||
-rw-r--r-- | yacc/defs.h | 112 | ||||
-rw-r--r-- | yacc/error.c | 42 | ||||
-rw-r--r-- | yacc/lalr.c | 322 | ||||
-rw-r--r-- | yacc/lr0.c | 370 | ||||
-rw-r--r-- | yacc/main.c | 180 | ||||
-rw-r--r-- | yacc/mkpar.c | 244 | ||||
-rw-r--r-- | yacc/output.c | 650 | ||||
-rw-r--r-- | yacc/reader.c | 1502 | ||||
-rw-r--r-- | yacc/skeleton.c | 4 | ||||
-rw-r--r-- | yacc/symtab.c | 14 | ||||
-rw-r--r-- | yacc/verbose.c | 270 | ||||
-rw-r--r-- | yacc/warshall.c | 64 |
17 files changed, 2086 insertions, 2086 deletions
diff --git a/emacs/caml.el b/emacs/caml.el index e0389ff4c..47595466d 100644 --- a/emacs/caml.el +++ b/emacs/caml.el @@ -1423,14 +1423,14 @@ matching nodes to determine KEYWORD's final indentation.") (current-column)) ((caml-in-comment-p) (let ((closing (looking-at "\\*)")) - (comment-mark (looking-at "\\*"))) + (comment-mark (looking-at "\\*"))) (caml-backward-comment) (looking-at comment-start-skip) (+ (current-column) (cond - (closing 1) - (comment-mark 1) - (t caml-comment-indent))))) + (closing 1) + (comment-mark 1) + (t caml-comment-indent))))) (t (let* ((leading (looking-at caml-leading-kwops-regexp)) (assoc-val (if leading (assoc (caml-match-string 0) caml-leading-kwops-alist))) diff --git a/parsing/parser.mly b/parsing/parser.mly index a96f05774..37e814369 100644 --- a/parsing/parser.mly +++ b/parsing/parser.mly @@ -1487,7 +1487,7 @@ opt_semi: | SEMI { () } ; subtractive: - | MINUS { "-" } + | MINUS { "-" } | MINUSDOT { "-." } ; %% diff --git a/test/Moretest/morematch.ml b/test/Moretest/morematch.ml index 7408aba48..e9a485089 100644 --- a/test/Moretest/morematch.ml +++ b/test/Moretest/morematch.ml @@ -850,105 +850,105 @@ type command_reply = let get_command_reply n = match n with - 263 -> RPL_TRYAGAIN - | 319 -> RPL_WHOISCHANNELS - | 318 -> RPL_ENDOFWHOIS - | 317 -> RPL_WHOISIDLE - | 316 -> RPL_WHOISCHANOP - | 369 -> RPL_ENDOFWHOWAS - | 314 -> RPL_WHOWASUSER - | 313 -> RPL_WHOISOPERATOR - | 312 -> RPL_WHOISSERVER - | 311 -> RPL_WHOISUSER - | 262 -> RPL_TRACEEND - | 261 -> RPL_TRACELOG - | 259 -> RPL_ADMINEMAIL - | 258 -> RPL_ADMINLOC2 - | 257 -> RPL_ADMINLOC1 - | 256 -> RPL_ADMINME - | 255 -> RPL_LUSERME - | 254 -> RPL_LUSERCHANNELS - | 253 -> RPL_LUSERUNKNOWN - | 252 -> RPL_LUSEROP - | 251 -> RPL_LUSERCLIENT - | 250 -> RPL_STATSDLINE - | 249 -> RPL_STATSDEBUG - | 248 -> RPL_STATSDEFINE - | 247 -> RPL_STATSBLINE - | 246 -> RPL_STATSPING - | 245 -> RPL_STATSSLINE - | 244 -> RPL_STATSHLINE - | 243 -> RPL_STATSOLINE - | 242 -> RPL_STATSUPTIME - | 241 -> RPL_STATSLLINE - | 240 -> RPL_STATSVLINE - | 235 -> RPL_SERVLISTEND - | 234 -> RPL_SERVLIST - | 233 -> RPL_SERVICE - | 232 -> RPL_ENDOFSERVICES - | 231 -> RPL_SERVICEINFO - | 221 -> RPL_UMODEIS - | 219 -> RPL_ENDOFSTATS - | 218 -> RPL_STATSYLINE - | 217 -> RPL_STATSQLINE - | 216 -> RPL_STATSKLINE - | 215 -> RPL_STATSILINE - | 214 -> RPL_STATSNLINE - | 213 -> RPL_STATSCLINE - | 212 -> RPL_STATSCOMMANDS - | 211 -> RPL_STATSLINKINFO - | 210 -> RPL_TRACERECONNECT - | 209 -> RPL_TRACECLASS - | 208 -> RPL_TRACENEWTYPE - | 207 -> RPL_TRACESERVICE - | 206 -> RPL_TRACESERVER - | 205 -> RPL_TRACEUSER - | 204 -> RPL_TRACEOPERATOR - | 203 -> RPL_TRACEUNKNOWN - | 202 -> RPL_TRACEHANDSHAKE - | 201 -> RPL_TRACECONNECTING - | 200 -> RPL_TRACELINK - | 395 -> RPL_NOUSERS - | 394 -> RPL_ENDOFUSERS - | 393 -> RPL_USERS - | 392 -> RPL_USERSSTART - | 391 -> RPL_TIME - | 385 -> RPL_NOTOPERANYMORE - | 384 -> RPL_MYPORTIS - | 383 -> RPL_YOURESERVICE - | 382 -> RPL_REHASHING - | 381 -> RPL_YOUREOPER - | 376 -> RPL_ENDOFMOTD - | 375 -> RPL_MOTDSTART - | 374 -> RPL_ENDOFINFO - | 373 -> RPL_INFOSTART - | 372 -> RPL_MOTD - | 371 -> RPL_INFO - | 368 -> RPL_ENDOFBANLIST - | 367 -> RPL_BANLIST - | 365 -> RPL_ENDOFLINKS - | 364 -> RPL_LINKS - | 363 -> RPL_CLOSEEND - | 362 -> RPL_CLOSING - | 361 -> RPL_KILLDONE - | 366 -> RPL_ENDOFNAMES - | 353 -> RPL_NAMREPLY - | 315 -> RPL_ENDOFWHO - | 352 -> RPL_WHOREPLY - | 351 -> RPL_VERSION - | 342 -> RPL_SUMMONING - | 341 -> RPL_INVITING - | 332 -> RPL_TOPIC - | 331 -> RPL_NOTOPIC - | 324 -> RPL_CHANNELMODEIS - | 323 -> RPL_LISTEND - | 322 -> RPL_LIST - | 321 -> RPL_LISTSTART - | 306 -> RPL_NOWAWAY - | 305 -> RPL_UNAWAY - | 304 -> RPL_TEXT - | 303 -> RPL_ISON - | 302 -> RPL_USERHOST - | 301 -> RPL_AWAY - | 300 -> RPL_NONE + 263 -> RPL_TRYAGAIN + | 319 -> RPL_WHOISCHANNELS + | 318 -> RPL_ENDOFWHOIS + | 317 -> RPL_WHOISIDLE + | 316 -> RPL_WHOISCHANOP + | 369 -> RPL_ENDOFWHOWAS + | 314 -> RPL_WHOWASUSER + | 313 -> RPL_WHOISOPERATOR + | 312 -> RPL_WHOISSERVER + | 311 -> RPL_WHOISUSER + | 262 -> RPL_TRACEEND + | 261 -> RPL_TRACELOG + | 259 -> RPL_ADMINEMAIL + | 258 -> RPL_ADMINLOC2 + | 257 -> RPL_ADMINLOC1 + | 256 -> RPL_ADMINME + | 255 -> RPL_LUSERME + | 254 -> RPL_LUSERCHANNELS + | 253 -> RPL_LUSERUNKNOWN + | 252 -> RPL_LUSEROP + | 251 -> RPL_LUSERCLIENT + | 250 -> RPL_STATSDLINE + | 249 -> RPL_STATSDEBUG + | 248 -> RPL_STATSDEFINE + | 247 -> RPL_STATSBLINE + | 246 -> RPL_STATSPING + | 245 -> RPL_STATSSLINE + | 244 -> RPL_STATSHLINE + | 243 -> RPL_STATSOLINE + | 242 -> RPL_STATSUPTIME + | 241 -> RPL_STATSLLINE + | 240 -> RPL_STATSVLINE + | 235 -> RPL_SERVLISTEND + | 234 -> RPL_SERVLIST + | 233 -> RPL_SERVICE + | 232 -> RPL_ENDOFSERVICES + | 231 -> RPL_SERVICEINFO + | 221 -> RPL_UMODEIS + | 219 -> RPL_ENDOFSTATS + | 218 -> RPL_STATSYLINE + | 217 -> RPL_STATSQLINE + | 216 -> RPL_STATSKLINE + | 215 -> RPL_STATSILINE + | 214 -> RPL_STATSNLINE + | 213 -> RPL_STATSCLINE + | 212 -> RPL_STATSCOMMANDS + | 211 -> RPL_STATSLINKINFO + | 210 -> RPL_TRACERECONNECT + | 209 -> RPL_TRACECLASS + | 208 -> RPL_TRACENEWTYPE + | 207 -> RPL_TRACESERVICE + | 206 -> RPL_TRACESERVER + | 205 -> RPL_TRACEUSER + | 204 -> RPL_TRACEOPERATOR + | 203 -> RPL_TRACEUNKNOWN + | 202 -> RPL_TRACEHANDSHAKE + | 201 -> RPL_TRACECONNECTING + | 200 -> RPL_TRACELINK + | 395 -> RPL_NOUSERS + | 394 -> RPL_ENDOFUSERS + | 393 -> RPL_USERS + | 392 -> RPL_USERSSTART + | 391 -> RPL_TIME + | 385 -> RPL_NOTOPERANYMORE + | 384 -> RPL_MYPORTIS + | 383 -> RPL_YOURESERVICE + | 382 -> RPL_REHASHING + | 381 -> RPL_YOUREOPER + | 376 -> RPL_ENDOFMOTD + | 375 -> RPL_MOTDSTART + | 374 -> RPL_ENDOFINFO + | 373 -> RPL_INFOSTART + | 372 -> RPL_MOTD + | 371 -> RPL_INFO + | 368 -> RPL_ENDOFBANLIST + | 367 -> RPL_BANLIST + | 365 -> RPL_ENDOFLINKS + | 364 -> RPL_LINKS + | 363 -> RPL_CLOSEEND + | 362 -> RPL_CLOSING + | 361 -> RPL_KILLDONE + | 366 -> RPL_ENDOFNAMES + | 353 -> RPL_NAMREPLY + | 315 -> RPL_ENDOFWHO + | 352 -> RPL_WHOREPLY + | 351 -> RPL_VERSION + | 342 -> RPL_SUMMONING + | 341 -> RPL_INVITING + | 332 -> RPL_TOPIC + | 331 -> RPL_NOTOPIC + | 324 -> RPL_CHANNELMODEIS + | 323 -> RPL_LISTEND + | 322 -> RPL_LIST + | 321 -> RPL_LISTSTART + | 306 -> RPL_NOWAWAY + | 305 -> RPL_UNAWAY + | 304 -> RPL_TEXT + | 303 -> RPL_ISON + | 302 -> RPL_USERHOST + | 301 -> RPL_AWAY + | 300 -> RPL_NONE | _ -> raise (Unknown_Reply n) diff --git a/testasmcomp/ia64.S b/testasmcomp/ia64.S index beea98655..51361690b 100644 --- a/testasmcomp/ia64.S +++ b/testasmcomp/ia64.S @@ -19,7 +19,7 @@ #define STFSPILLOFF(a,b,d) stf.spill [a] = b, d #define LDFFILLOFF(a,b,d) ldf.fill a = [b], d - .text + .text .align 16 .global call_gen_code# @@ -27,7 +27,7 @@ call_gen_code: /* Allocate 64 "out" registers (for the Caml code) and no locals */ - alloc r3 = ar.pfs, 0, 0, 64, 0 + alloc r3 = ar.pfs, 0, 0, 64, 0 /* Save PFS, return address and GP on stack */ add sp = -368, sp ;; diff --git a/yacc/closure.c b/yacc/closure.c index f983e23fc..1b7926a07 100644 --- a/yacc/closure.c +++ b/yacc/closure.c @@ -44,22 +44,22 @@ void set_EFF(void) 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; + 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 +#ifdef DEBUG print_EFF(); #endif } @@ -92,29 +92,29 @@ void set_first_derives(void) 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; - } - } + { + 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 +#ifdef DEBUG print_first_derives(); #endif @@ -141,19 +141,19 @@ void closure(short int *nucleus, int n) rsp = ruleset; rsend = ruleset + rulesetsize; for (rsp = ruleset; rsp < rsend; rsp++) - *rsp = 0; + *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++; - } + symbol = ritem[*csp]; + if (ISVAR(symbol)) + { + dsp = first_derives + symbol * rulesetsize; + rsp = ruleset; + while (rsp < rsend) + *rsp++ |= *dsp++; + } } ruleno = 0; @@ -161,34 +161,34 @@ void closure(short int *nucleus, int n) 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; - } - } + 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++; + *itemsetend++ = *csp++; -#ifdef DEBUG +#ifdef DEBUG print_closure(n); #endif } @@ -203,7 +203,7 @@ void finalize_closure(void) } -#ifdef DEBUG +#ifdef DEBUG void print_closure(int n) { @@ -226,23 +226,23 @@ void print_EFF(void) 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; - } - } + 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; + } + } } } @@ -265,16 +265,16 @@ void print_first_derives(void) mask = 1; for (j = 0; j <= nrules; j++) { - if (cword & mask) - printf(" %d\n", j); - - mask <<= 1; - if (mask == 0) - { - cword = *rp++; - mask = 1; - } - } + if (cword & mask) + printf(" %d\n", j); + + mask <<= 1; + if (mask == 0) + { + cword = *rp++; + mask = 1; + } + } } fflush(stdout); diff --git a/yacc/defs.h b/yacc/defs.h index 69150826e..0a9d0eea9 100644 --- a/yacc/defs.h +++ b/yacc/defs.h @@ -26,52 +26,52 @@ #include "../byterun/rotatecursor.h" #endif -/* machine-dependent definitions */ -/* the following definitions are for the Tahoe */ -/* they might have to be changed for other machines */ - -/* MAXCHAR is the largest unsigned character value */ -/* MAXSHORT is the largest value of a C short */ -/* MINSHORT is the most negative value of a C short */ -/* MAXTABLE is the maximum table size */ -/* BITS_PER_WORD is the number of bits in a C unsigned */ -/* WORDSIZE computes the number of words needed to */ -/* store n bits */ -/* BIT returns the value of the n-th bit starting */ -/* from r (0-indexed) */ -/* SETBIT sets the n-th bit starting from r */ - -#define MAXCHAR UCHAR_MAX -#define MAXSHORT SHRT_MAX -#define MINSHORT SHRT_MIN -#define MAXTABLE 32500 - -#define BITS_PER_WORD (8*sizeof(unsigned)) -#define WORDSIZE(n) (((n)+(BITS_PER_WORD-1))/BITS_PER_WORD) -#define BIT(r, n) ((((r)[(n)/BITS_PER_WORD])>>((n)%BITS_PER_WORD))&1) -#define SETBIT(r, n) ((r)[(n)/BITS_PER_WORD]|=(1<<((n)%BITS_PER_WORD))) +/* machine-dependent definitions */ +/* the following definitions are for the Tahoe */ +/* they might have to be changed for other machines */ + +/* MAXCHAR is the largest unsigned character value */ +/* MAXSHORT is the largest value of a C short */ +/* MINSHORT is the most negative value of a C short */ +/* MAXTABLE is the maximum table size */ +/* BITS_PER_WORD is the number of bits in a C unsigned */ +/* WORDSIZE computes the number of words needed to */ +/* store n bits */ +/* BIT returns the value of the n-th bit starting */ +/* from r (0-indexed) */ +/* SETBIT sets the n-th bit starting from r */ + +#define MAXCHAR UCHAR_MAX +#define MAXSHORT SHRT_MAX +#define MINSHORT SHRT_MIN +#define MAXTABLE 32500 + +#define BITS_PER_WORD (8*sizeof(unsigned)) +#define WORDSIZE(n) (((n)+(BITS_PER_WORD-1))/BITS_PER_WORD) +#define BIT(r, n) ((((r)[(n)/BITS_PER_WORD])>>((n)%BITS_PER_WORD))&1) +#define SETBIT(r, n) ((r)[(n)/BITS_PER_WORD]|=(1<<((n)%BITS_PER_WORD))) /* character names */ -#define NUL '\0' /* the null character */ -#define NEWLINE '\n' /* line feed */ -#define SP ' ' /* space */ -#define BS '\b' /* backspace */ -#define HT '\t' /* horizontal tab */ -#define VT '\013' /* vertical tab */ -#define CR '\r' /* carriage return */ -#define FF '\f' /* form feed */ -#define QUOTE '\'' /* single quote */ -#define DOUBLE_QUOTE '\"' /* double quote */ -#define BACKSLASH '\\' /* backslash */ +#define NUL '\0' /* the null character */ +#define NEWLINE '\n' /* line feed */ +#define SP ' ' /* space */ +#define BS '\b' /* backspace */ +#define HT '\t' /* horizontal tab */ +#define VT '\013' /* vertical tab */ +#define CR '\r' /* carriage return */ +#define FF '\f' /* form feed */ +#define QUOTE '\'' /* single quote */ +#define DOUBLE_QUOTE '\"' /* double quote */ +#define BACKSLASH '\\' /* backslash */ /* defines for constructing filenames */ -#define CODE_SUFFIX ".code.c" -#define DEFINES_SUFFIX ".tab.h" -#define OUTPUT_SUFFIX ".ml" -#define VERBOSE_SUFFIX ".output" +#define CODE_SUFFIX ".code.c" +#define DEFINES_SUFFIX ".tab.h" +#define OUTPUT_SUFFIX ".ml" +#define VERBOSE_SUFFIX ".output" #define INTERFACE_SUFFIX ".mli" /* keyword codes */ @@ -107,15 +107,15 @@ /* 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') +#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) +#define ISTOKEN(s) ((s) < start_symbol) +#define ISVAR(s) ((s) >= start_symbol) /* storage allocation macros */ @@ -124,21 +124,21 @@ #define INTERACT() ROTATECURSOR_MAGIC () -#define CALLOC(k,n) (INTERACT (), calloc((unsigned)(k),(unsigned)(n))) +#define CALLOC(k,n) (INTERACT (), calloc((unsigned)(k),(unsigned)(n))) #define FREE(x) (INTERACT (), free((char*)(x))) #define MALLOC(n) (INTERACT (), malloc((unsigned)(n))) -#define NEW(t) (INTERACT (), (t*)allocate(sizeof(t))) -#define NEW2(n,t) (INTERACT (), (t*)allocate((unsigned)((n)*sizeof(t)))) +#define NEW(t) (INTERACT (), (t*)allocate(sizeof(t))) +#define NEW2(n,t) (INTERACT (), (t*)allocate((unsigned)((n)*sizeof(t)))) #define REALLOC(p,n) (INTERACT (), realloc((char*)(p),(unsigned)(n))) #else -#define CALLOC(k,n) (calloc((unsigned)(k),(unsigned)(n))) -#define FREE(x) (free((char*)(x))) -#define MALLOC(n) (malloc((unsigned)(n))) -#define NEW(t) ((t*)allocate(sizeof(t))) -#define NEW2(n,t) ((t*)allocate((unsigned)((n)*sizeof(t)))) -#define REALLOC(p,n) (realloc((char*)(p),(unsigned)(n))) +#define CALLOC(k,n) (calloc((unsigned)(k),(unsigned)(n))) +#define FREE(x) (free((char*)(x))) +#define MALLOC(n) (malloc((unsigned)(n))) +#define NEW(t) ((t*)allocate(sizeof(t))) +#define NEW2(n,t) ((t*)allocate((unsigned)((n)*sizeof(t)))) +#define REALLOC(p,n) (realloc((char*)(p),(unsigned)(n))) #endif /* macintosh */ @@ -161,10 +161,10 @@ struct bucket char true_token; }; -/* TABLE_SIZE is the number of entries in the symbol table. */ -/* TABLE_SIZE must be a power of two. */ +/* TABLE_SIZE is the number of entries in the symbol table. */ +/* TABLE_SIZE must be a power of two. */ -#define TABLE_SIZE 4096 +#define TABLE_SIZE 4096 /* the structure of the LR(0) state machine */ diff --git a/yacc/error.c b/yacc/error.c index 869edb501..4258bb04d 100644 --- a/yacc/error.c +++ b/yacc/error.c @@ -42,7 +42,7 @@ void open_error(char *filename) void unexpected_EOF(void) { fprintf(stderr, "%s: e - line %d of \"%s\", unexpected end-of-file\n", - myname, lineno, input_file_name); + myname, lineno, input_file_name); done(1); } @@ -54,18 +54,18 @@ void print_pos(char *st_line, char *st_cptr) if (st_line == 0) return; for (s = st_line; *s != '\n'; ++s) { - if (isprint(*s) || *s == '\t') - putc(*s, stderr); - else - putc('?', stderr); + 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); + if (*s == '\t') + putc('\t', stderr); + else + putc(' ', stderr); } putc('^', stderr); putc('\n', stderr); @@ -75,7 +75,7 @@ void print_pos(char *st_line, char *st_cptr) void syntax_error(int st_lineno, char *st_line, char *st_cptr) { fprintf(stderr, "%s: e - line %d of \"%s\", syntax error\n", - myname, st_lineno, input_file_name); + myname, st_lineno, input_file_name); print_pos(st_line, st_cptr); done(1); } @@ -84,7 +84,7 @@ void syntax_error(int st_lineno, char *st_line, char *st_cptr) void unterminated_comment(int c_lineno, char *c_line, char *c_cptr) { fprintf(stderr, "%s: e - line %d of \"%s\", unmatched /*\n", - myname, c_lineno, input_file_name); + myname, c_lineno, input_file_name); print_pos(c_line, c_cptr); done(1); } @@ -93,7 +93,7 @@ void unterminated_comment(int c_lineno, char *c_line, char *c_cptr) void unterminated_string(int s_lineno, char *s_line, char *s_cptr) { fprintf(stderr, "%s: e - line %d of \"%s\", unterminated string\n", - myname, s_lineno, input_file_name); + myname, s_lineno, input_file_name); print_pos(s_line, s_cptr); done(1); } @@ -102,7 +102,7 @@ void unterminated_string(int s_lineno, char *s_line, char *s_cptr) void unterminated_text(int t_lineno, char *t_line, char *t_cptr) { fprintf(stderr, "%s: e - line %d of \"%s\", unmatched %%{\n", - myname, t_lineno, input_file_name); + myname, t_lineno, input_file_name); print_pos(t_line, t_cptr); done(1); } @@ -129,7 +129,7 @@ declarations\n", myname, lineno, input_file_name); void illegal_tag(int t_lineno, char *t_line, char *t_cptr) { fprintf(stderr, "%s: e - line %d of \"%s\", illegal tag\n", - myname, t_lineno, input_file_name); + myname, t_lineno, input_file_name); print_pos(t_line, t_cptr); done(1); } @@ -138,7 +138,7 @@ void illegal_tag(int t_lineno, char *t_line, char *t_cptr) void illegal_character(char *c_cptr) { fprintf(stderr, "%s: e - line %d of \"%s\", illegal character\n", - myname, lineno, input_file_name); + myname, lineno, input_file_name); print_pos(line, c_cptr); done(1); } @@ -222,7 +222,7 @@ specifiers\n", myname, lineno, input_file_name); void unterminated_action(int a_lineno, char *a_line, char *a_cptr) { fprintf(stderr, "%s: e - line %d of \"%s\", unterminated action\n", - myname, a_lineno, input_file_name); + myname, a_lineno, input_file_name); print_pos(a_line, a_cptr); done(1); } @@ -238,7 +238,7 @@ end of the current rule\n", myname, a_lineno, input_file_name, i); void dollar_error(int a_lineno, char *a_line, char *a_cptr) { fprintf(stderr, "%s: e - line %d of \"%s\", illegal $-name\n", - myname, a_lineno, input_file_name); + myname, a_lineno, input_file_name); print_pos(a_line, a_cptr); done(1); } @@ -247,7 +247,7 @@ void dollar_error(int a_lineno, char *a_line, char *a_cptr) void untyped_lhs(void) { fprintf(stderr, "%s: e - line %d of \"%s\", $$ is untyped\n", - myname, lineno, input_file_name); + myname, lineno, input_file_name); done(1); } @@ -255,7 +255,7 @@ void untyped_lhs(void) void untyped_rhs(int i, char *s) { fprintf(stderr, "%s: e - line %d of \"%s\", $%d (%s) is untyped\n", - myname, lineno, input_file_name, i, s); + myname, lineno, input_file_name, i, s); done(1); } @@ -263,14 +263,14 @@ void untyped_rhs(int i, char *s) void unknown_rhs(int i) { fprintf(stderr, "%s: e - line %d of \"%s\", $%d is unbound\n", - myname, lineno, input_file_name, i); + myname, lineno, input_file_name, i); done(1); } void illegal_token_ref(int i, char *name) { fprintf(stderr, "%s: e - line %d of \"%s\", $%d refers to terminal `%s', which has no argument\n", - myname, lineno, input_file_name, i, name); + myname, lineno, input_file_name, i, name); done(1); } diff --git a/yacc/lalr.c b/yacc/lalr.c index 136a314d8..81be0ec0e 100644 --- a/yacc/lalr.c +++ b/yacc/lalr.c @@ -91,7 +91,7 @@ void set_state_table(void) state_table = NEW2(nstates, core *); for (sp = first_state; sp; sp = sp->next) - state_table[sp->number] = sp; + state_table[sp->number] = sp; } @@ -102,7 +102,7 @@ void set_accessing_symbol(void) accessing_symbol = NEW2(nstates, short); for (sp = first_state; sp; sp = sp->next) - accessing_symbol[sp->number] = sp->accessing_symbol; + accessing_symbol[sp->number] = sp->accessing_symbol; } @@ -113,7 +113,7 @@ void set_shift_table(void) shift_table = NEW2(nstates, shifts *); for (sp = first_shift; sp; sp = sp->next) - shift_table[sp->number] = sp; + shift_table[sp->number] = sp; } @@ -124,7 +124,7 @@ void set_reduction_table(void) reduction_table = NEW2(nstates, reductions *); for (rp = first_reduction; rp; rp = rp->next) - reduction_table[rp->number] = rp; + reduction_table[rp->number] = rp; } @@ -142,14 +142,14 @@ void set_maxrhs(void) for (itemp = ritem; itemp < item_end; itemp++) { if (*itemp >= 0) - { - length++; - } + { + length++; + } else - { - if (length > max) max = length; - length = 0; - } + { + if (length > max) max = length; + length = 0; + } } maxrhs = max; @@ -170,7 +170,7 @@ void initialize_LA(void) lookaheads[i] = k; rp = reduction_table[i]; if (rp) - k += rp->nreds; + k += rp->nreds; } lookaheads[nstates] = k; @@ -183,13 +183,13 @@ void initialize_LA(void) { rp = reduction_table[i]; if (rp) - { - for (j = 0; j < rp->nreds; j++) - { - LAruleno[k] = rp->rules[j]; - k++; - } - } + { + for (j = 0; j < rp->nreds; j++) + { + LAruleno[k] = rp->rules[j]; + k++; + } + } } } @@ -211,16 +211,16 @@ void set_goto_map(void) for (sp = first_shift; sp; sp = sp->next) { for (i = sp->nshifts - 1; i >= 0; i--) - { - symbol = accessing_symbol[sp->shift[i]]; + { + symbol = accessing_symbol[sp->shift[i]]; - if (ISTOKEN(symbol)) break; + if (ISTOKEN(symbol)) break; - if (ngotos == MAXSHORT) - fatal("too many gotos"); + if (ngotos == MAXSHORT) + fatal("too many gotos"); - ngotos++; - goto_map[symbol]++; + ngotos++; + goto_map[symbol]++; } } @@ -244,16 +244,16 @@ void set_goto_map(void) { state1 = sp->number; for (i = sp->nshifts - 1; i >= 0; i--) - { - state2 = sp->shift[i]; - symbol = accessing_symbol[state2]; + { + state2 = sp->shift[i]; + symbol = accessing_symbol[state2]; - if (ISTOKEN(symbol)) break; + if (ISTOKEN(symbol)) break; - k = temp_map[symbol]++; - from_state[k] = state1; - to_state[k] = state2; - } + k = temp_map[symbol]++; + from_state[k] = state1; + to_state[k] = state2; + } } FREE(temp_map + ntokens); @@ -261,7 +261,7 @@ void set_goto_map(void) -/* Map_goto maps a state/symbol pair into its numeric representation. */ +/* Map_goto maps a state/symbol pair into its numeric representation. */ int map_goto(int state, int symbol) @@ -276,15 +276,15 @@ map_goto(int state, int symbol) 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; + 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; } } @@ -319,35 +319,35 @@ void initialize_F(void) 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; - } - } + { + 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; } @@ -358,7 +358,7 @@ void initialize_F(void) for (i = 0; i < ngotos; i++) { if (reads[i]) - FREE(reads[i]); + FREE(reads[i]); } FREE(reads); @@ -398,50 +398,50 @@ void build_relations(void) 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; - } - } - } + { + 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; - } + { + 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); @@ -470,10 +470,10 @@ void add_lookback_edge(int stateno, int ruleno, int gotono) found = 0; while (!found && i < k) { - if (LAruleno[i] == ruleno) - found = 1; - else - ++i; + if (LAruleno[i] == ruleno) + found = 1; + else + ++i; } assert(found); @@ -501,10 +501,10 @@ transpose(short int **R, int n) { sp = R[i]; if (sp) - { - while (*sp >= 0) - nedges[*sp++]++; - } + { + while (*sp >= 0) + nedges[*sp++]++; + } } new_R = NEW2(n, short *); @@ -514,12 +514,12 @@ transpose(short int **R, int n) { k = nedges[i]; if (k > 0) - { - sp = NEW2(k + 1, short); - new_R[i] = sp; - temp_R[i] = sp; - sp[k] = -1; - } + { + sp = NEW2(k + 1, short); + new_R[i] = sp; + temp_R[i] = sp; + sp[k] = -1; + } } FREE(nedges); @@ -528,10 +528,10 @@ transpose(short int **R, int n) { sp = R[i]; if (sp) - { - while (*sp >= 0) - *temp_R[*sp++]++ = i; - } + { + while (*sp >= 0) + *temp_R[*sp++]++ = i; + } } FREE(temp_R); @@ -560,12 +560,12 @@ void compute_lookaheads(void) { fp3 = rowp + tokensetsize; for (sp = lookback[i]; sp; sp = sp->next) - { - fp1 = rowp; - fp2 = F + tokensetsize * sp->value; - while (fp1 < fp3) - *fp1++ |= *fp2++; - } + { + fp1 = rowp; + fp2 = F + tokensetsize * sp->value; + while (fp1 < fp3) + *fp1++ |= *fp2++; + } rowp = fp3; } @@ -598,7 +598,7 @@ void digraph(short int **relation) for (i = 0; i < ngotos; i++) { if (INDEX[i] == 0 && R[i]) - traverse(i); + traverse(i); } FREE(INDEX); @@ -628,36 +628,36 @@ void traverse(register int i) if (rp) { while ((j = *rp++) >= 0) - { - if (INDEX[j] == 0) - traverse(j); + { + if (INDEX[j] == 0) + traverse(j); - if (INDEX[i] > INDEX[j]) - INDEX[i] = INDEX[j]; + if (INDEX[i] > INDEX[j]) + INDEX[i] = INDEX[j]; - fp1 = base; - fp2 = F + j * tokensetsize; + fp1 = base; + fp2 = F + j * tokensetsize; - while (fp1 < fp3) - *fp1++ |= *fp2++; - } + while (fp1 < fp3) + *fp1++ |= *fp2++; + } } if (INDEX[i] == height) { for (;;) - { - j = VERTICES[top--]; - INDEX[j] = infinity; + { + j = VERTICES[top--]; + INDEX[j] = infinity; - if (i == j) - break; + if (i == j) + break; - fp1 = base; - fp2 = F + j * tokensetsize; + fp1 = base; + fp2 = F + j * tokensetsize; - while (fp1 < fp3) - *fp2++ = *fp1++; - } + while (fp1 < fp3) + *fp2++ = *fp1++; + } } } diff --git a/yacc/lr0.c b/yacc/lr0.c index f4f0a4cd8..e05fcb072 100644 --- a/yacc/lr0.c +++ b/yacc/lr0.c @@ -70,12 +70,12 @@ void allocate_itemsets(void) item_end = ritem + nitems; for (itemp = ritem; itemp < item_end; itemp++) { - symbol = *itemp; - if (symbol >= 0) - { - count++; - symbol_count[symbol]++; - } + symbol = *itemp; + if (symbol >= 0) + { + count++; + symbol_count[symbol]++; + } } kernel_base = NEW2(nsyms, short *); @@ -85,10 +85,10 @@ void allocate_itemsets(void) 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]; + kernel_base[i] = kernel_items + count; + count += symbol_count[i]; + if (max < symbol_count[i]) + max = symbol_count[i]; } shift_symbol = symbol_count; @@ -111,25 +111,25 @@ void append_states(void) register int j; register int symbol; -#ifdef TRACE +#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; + 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); + symbol = shift_symbol[i]; + shiftset[i] = get_state(symbol); } } @@ -157,15 +157,15 @@ void generate_states(void) while (this_state) { - closure(this_state->items, this_state->nitems); - save_reductions(); - new_itemsets(); - append_states(); + closure(this_state->items, this_state->nitems); + save_reductions(); + new_itemsets(); + append_states(); - if (nshifts > 0) - save_shifts(); + if (nshifts > 0) + save_shifts(); - this_state = this_state->next; + this_state = this_state->next; } finalize_closure(); @@ -185,7 +185,7 @@ get_state(int symbol) register int found; register int n; -#ifdef TRACE +#ifdef TRACE fprintf(stderr, "Entering get_state(%d)\n", symbol); #endif @@ -198,39 +198,39 @@ get_state(int symbol) 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; - } - } - } + 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); + state_set[key] = sp = new_state(symbol); } return (sp->number); @@ -246,7 +246,7 @@ void initialize_states(void) start_derives = derives[start_symbol]; for (i = 0; start_derives[i] >= 0; ++i) - continue; + continue; p = (core *) MALLOC(sizeof(core) + i*sizeof(short)); if (p == 0) no_space(); @@ -258,7 +258,7 @@ void initialize_states(void) p->nitems = i; for (i = 0; start_derives[i] >= 0; ++i) - p->items[i] = rrhs[start_derives[i]]; + p->items[i] = rrhs[start_derives[i]]; first_state = last_state = this_state = p; nstates = 1; @@ -274,26 +274,26 @@ void new_itemsets(void) register int symbol; for (i = 0; i < nsyms; i++) - kernel_end[i] = 0; + 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; - } + 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; @@ -310,12 +310,12 @@ new_state(int symbol) register short *isp2; register short *iend; -#ifdef TRACE +#ifdef TRACE fprintf(stderr, "Entering new_state(%d)\n", symbol); #endif if (nstates >= MAXSHORT) - fatal("too many states"); + fatal("too many states"); isp1 = kernel_base[symbol]; iend = kernel_end[symbol]; @@ -328,7 +328,7 @@ new_state(int symbol) isp2 = p->items; while (isp1 < iend) - *isp2++ = *isp1++; + *isp2++ = *isp1++; last_state->next = p; last_state = p; @@ -350,26 +350,26 @@ void show_cores(void) 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); - } + 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); + } } } @@ -381,7 +381,7 @@ void show_ritems(void) int i; for (i = 0; i < nitems; ++i) - printf("ritem[%d] = %d\n", i, ritem[i]); + printf("ritem[%d] = %d\n", i, ritem[i]); } @@ -392,7 +392,7 @@ void show_rrhs(void) int i; for (i = 0; i < nrules; ++i) - printf("rrhs[%d] = %d\n", i, rrhs[i]); + printf("rrhs[%d] = %d\n", i, rrhs[i]); } @@ -406,12 +406,12 @@ void show_shifts(void) 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]); + 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]); } } @@ -424,7 +424,7 @@ void save_shifts(void) register short *send; p = (shifts *) allocate((unsigned) (sizeof(shifts) + - (nshifts - 1) * sizeof(short))); + (nshifts - 1) * sizeof(short))); p->number = this_state->number; p->nshifts = nshifts; @@ -434,17 +434,17 @@ void save_shifts(void) send = shiftset + nshifts; while (sp1 < send) - *sp2++ = *sp1++; + *sp2++ = *sp1++; if (last_shift) { - last_shift->next = p; - last_shift = p; + last_shift->next = p; + last_shift = p; } else { - first_shift = p; - last_shift = p; + first_shift = p; + last_shift = p; } } @@ -463,38 +463,38 @@ void save_reductions(void) count = 0; for (isp = itemset; isp < itemsetend; isp++) { - item = ritem[*isp]; - if (item < 0) - { - redset[count++] = -item; - } + 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; - } + 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; + } } } @@ -511,20 +511,20 @@ void set_derives(void) 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++; + derives[lhs] = rules + k; + for (i = 0; i < nrules; i++) + { + if (rlhs[i] == lhs) + { + rules[k] = i; + k++; + } + } + rules[k] = -1; + k++; } -#ifdef DEBUG +#ifdef DEBUG print_derives(); #endif } @@ -535,7 +535,7 @@ void free_derives(void) FREE(derives); } -#ifdef DEBUG +#ifdef DEBUG void print_derives(void) { register int i; @@ -545,12 +545,12 @@ void print_derives(void) 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'); + printf("%s derives ", symbol_name[i]); + for (sp = derives[i]; *sp >= 0; sp++) + { + printf(" %d", *sp); + } + putchar('\n'); } putchar('\n'); @@ -568,40 +568,40 @@ void set_nullable(void) if (nullable == 0) no_space(); for (i = 0; i < nsyms; ++i) - nullable[i] = 0; + 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; - } - } - } + 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]); + if (nullable[i]) + printf("%s is nullable\n", symbol_name[i]); + else + printf("%s is not nullable\n", symbol_name[i]); } #endif } diff --git a/yacc/main.c b/yacc/main.c index 65845b1d8..8f8590c28 100644 --- a/yacc/main.c +++ b/yacc/main.c @@ -51,19 +51,19 @@ 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 *action_file; /* a temp file, used to save actions associated */ + /* with rules until the parser is written */ FILE *entry_file; -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 */ +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 */ FILE *interface_file; int nitems; @@ -119,15 +119,15 @@ void set_signals(void) { #ifdef SIGINT if (signal(SIGINT, SIG_IGN) != SIG_IGN) - signal(SIGINT, onintr); + signal(SIGINT, onintr); #endif #ifdef SIGTERM if (signal(SIGTERM, SIG_IGN) != SIG_IGN) - signal(SIGTERM, onintr); + signal(SIGTERM, onintr); #endif #ifdef SIGHUP if (signal(SIGHUP, SIG_IGN) != SIG_IGN) - signal(SIGHUP, onintr); + signal(SIGHUP, onintr); #endif } @@ -147,51 +147,51 @@ void getargs(int argc, char **argv) if (argc > 0) myname = argv[0]; for (i = 1; i < argc; ++i) { - s = argv[i]; - if (*s != '-') break; - switch (*++s) - { - case '\0': - input_file = stdin; - if (i + 1 < argc) usage(); - return; - - case '-': - ++i; - goto no_more_options; + 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 'v': vflag = 1; break; - case 'b': - if (*++s) - file_prefix = s; - else if (++i < argc) - file_prefix = argv[i]; - else - usage(); - continue; - - default: - usage(); - } - - for (;;) - { - switch (*++s) - { - case '\0': - goto end_of_option; - - case 'v': - vflag = 1; - break; - - default: - usage(); - } - } + case 'b': + if (*++s) + file_prefix = s; + else if (++i < argc) + file_prefix = argv[i]; + else + usage(); + continue; + + default: + usage(); + } + + for (;;) + { + switch (*++s) + { + case '\0': + goto end_of_option; + + case 'v': + vflag = 1; + break; + + default: + usage(); + } + } end_of_option:; } @@ -223,8 +223,8 @@ allocate(unsigned int n) p = NULL; if (n) { - p = CALLOC(1, n); - if (!p) no_space(); + p = CALLOC(1, n); + if (!p) no_space(); } return (p); } @@ -244,7 +244,7 @@ void create_file_names(void) len = strlen(tmpdir); i = len + sizeof(temp_form); if (len && tmpdir[len-1] != '/') - ++i; + ++i; #endif action_file_name = MALLOC(i); @@ -264,11 +264,11 @@ void create_file_names(void) if (len && tmpdir[len - 1] != '/') { - action_file_name[len] = '/'; - entry_file_name[len] = '/'; - text_file_name[len] = '/'; - union_file_name[len] = '/'; - ++len; + action_file_name[len] = '/'; + entry_file_name[len] = '/'; + text_file_name[len] = '/'; + union_file_name[len] = '/'; + ++len; } #endif @@ -293,7 +293,7 @@ void create_file_names(void) output_file_name = MALLOC(len + 7); if (output_file_name == 0) - no_space(); + no_space(); strcpy(output_file_name, file_prefix); strcpy(output_file_name + len, OUTPUT_SUFFIX); @@ -301,16 +301,16 @@ void create_file_names(void) if (vflag) { - verbose_file_name = MALLOC(len + 8); - if (verbose_file_name == 0) - no_space(); - strcpy(verbose_file_name, file_prefix); - strcpy(verbose_file_name + len, VERBOSE_SUFFIX); + verbose_file_name = MALLOC(len + 8); + if (verbose_file_name == 0) + no_space(); + strcpy(verbose_file_name, file_prefix); + strcpy(verbose_file_name + len, VERBOSE_SUFFIX); } interface_file_name = MALLOC(len + 8); if (interface_file_name == 0) - no_space(); + no_space(); strcpy(interface_file_name, file_prefix); strcpy(interface_file_name + len, INTERFACE_SUFFIX); @@ -323,52 +323,52 @@ void open_files(void) if (input_file == 0) { - input_file = fopen(input_file_name, "r"); - if (input_file == 0) - open_error(input_file_name); + 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); + open_error(action_file_name); entry_file = fopen(entry_file_name, "w"); if (entry_file == 0) - open_error(entry_file_name); + open_error(entry_file_name); text_file = fopen(text_file_name, "w"); if (text_file == 0) - open_error(text_file_name); + open_error(text_file_name); if (vflag) { - verbose_file = fopen(verbose_file_name, "w"); - if (verbose_file == 0) - open_error(verbose_file_name); + 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); + 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); + open_error(output_file_name); if (rflag) { - code_file = fopen(code_file_name, "w"); - if (code_file == 0) - open_error(code_file_name); + code_file = fopen(code_file_name, "w"); + if (code_file == 0) + open_error(code_file_name); } else - code_file = output_file; + code_file = output_file; interface_file = fopen(interface_file_name, "w"); diff --git a/yacc/mkpar.c b/yacc/mkpar.c index 8b46b01f8..0d70fb8fb 100644 --- a/yacc/mkpar.c +++ b/yacc/mkpar.c @@ -42,7 +42,7 @@ void make_parser(void) parser = NEW2(nstates, action *); for (i = 0; i < nstates; i++) - parser[i] = parse_actions(i); + parser[i] = parse_actions(i); find_final_state(); remove_conflicts(); @@ -76,23 +76,23 @@ get_shifts(int stateno) 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; - } - } + 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); } @@ -109,13 +109,13 @@ add_reductions(int stateno, register action *actions) 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); - } + 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); } @@ -128,19 +128,19 @@ add_reduce(register action *actions, register int ruleno, register int symbol) prev = 0; for (next = actions; next && next->symbol < symbol; next = next->next) - prev = next; + prev = next; while (next && next->symbol == symbol && next->action_code == SHIFT) { - prev = next; - next = next->next; + prev = next; + next = next->next; } while (next && next->symbol == symbol && - next->action_code == REDUCE && next->number < ruleno) + next->action_code == REDUCE && next->number < ruleno) { - prev = next; - next = next->next; + prev = next; + next = next->next; } temp = NEW(action); @@ -152,9 +152,9 @@ add_reduce(register action *actions, register int ruleno, register int symbol) temp->assoc = rassoc[ruleno]; if (prev) - prev->next = temp; + prev->next = temp; else - actions = temp; + actions = temp; return (actions); } @@ -171,8 +171,8 @@ void find_final_state(void) goal = ritem[1]; for (i = p->nshifts - 1; i >= 0; --i) { - final_state = to_state[i]; - if (accessing_symbol[final_state] == goal) break; + final_state = to_state[i]; + if (accessing_symbol[final_state] == goal) break; } } @@ -186,26 +186,26 @@ void unused_rules(void) if (rules_used == 0) no_space(); for (i = 0; i < nrules; ++i) - rules_used[i] = 0; + 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; - } + 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 (!rules_used[i]) ++nunused; if (nunused){ - if (nunused == 1) - fprintf(stderr, "1 rule never reduced\n"); - else - fprintf(stderr, "%d rules never reduced\n", nunused); + if (nunused == 1) + fprintf(stderr, "1 rule never reduced\n"); + else + fprintf(stderr, "%d rules never reduced\n", nunused); } } @@ -223,65 +223,65 @@ void remove_conflicts(void) pref = NULL; 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; + 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; } } @@ -289,17 +289,17 @@ void remove_conflicts(void) void total_conflicts(void) { if (SRtotal == 1) - fprintf(stderr, "1 shift/reduce conflict"); + fprintf(stderr, "1 shift/reduce conflict"); else if (SRtotal > 1) - fprintf(stderr, "%d shift/reduce conflicts", SRtotal); + fprintf(stderr, "%d shift/reduce conflicts", SRtotal); if (SRtotal && RRtotal) - fprintf(stderr, ", "); + fprintf(stderr, ", "); if (RRtotal == 1) - fprintf(stderr, "1 reduce/reduce conflict"); + fprintf(stderr, "1 reduce/reduce conflict"); else if (RRtotal > 1) - fprintf(stderr, "%d reduce/reduce conflicts", RRtotal); + fprintf(stderr, "%d reduce/reduce conflicts", RRtotal); fprintf(stderr, ".\n"); } @@ -315,20 +315,20 @@ sole_reduction(int stateno) 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 (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 (0); return (ruleno); } @@ -339,7 +339,7 @@ void defreds(void) defred = NEW2(nstates, short); for (i = 0; i < nstates; i++) - defred[i] = sole_reduction(i); + defred[i] = sole_reduction(i); } void free_action_row(register action *p) diff --git a/yacc/output.c b/yacc/output.c index 4fff0c9af..d7e89f5dc 100644 --- a/yacc/output.c +++ b/yacc/output.c @@ -116,14 +116,14 @@ void output_rule_data(void) j = 8; for (i = 3; i < nrules; i++) { - if (j >= 8) - { - if (!rflag) ++outline; - fprintf(output_file, "\\\n"); - j = 1; - } + if (j >= 8) + { + if (!rflag) ++outline; + fprintf(output_file, "\\\n"); + j = 1; + } else - ++j; + ++j; output_short(symbol_value[rlhs[i]]); } @@ -136,14 +136,14 @@ void output_rule_data(void) j = 8; for (i = 3; i < nrules; i++) { - if (j >= 8) - { - if (!rflag) ++outline; - fprintf(output_file, "\\\n"); - j = 1; - } - else - j++; + if (j >= 8) + { + if (!rflag) ++outline; + fprintf(output_file, "\\\n"); + j = 1; + } + else + j++; output_short(rrhs[i + 1] - rrhs[i] - 1); } @@ -162,16 +162,16 @@ void output_yydefred(void) j = 8; for (i = 1; i < nstates; i++) { - if (j < 8) - ++j; - else - { - if (!rflag) ++outline; - fprintf(output_file, "\\\n"); - j = 1; - } - - output_short(defred[i] ? defred[i] - 2 : 0); + if (j < 8) + ++j; + else + { + if (!rflag) ++outline; + fprintf(output_file, "\\\n"); + j = 1; + } + + output_short(defred[i] ? defred[i] - 2 : 0); } if (!rflag) outline += 2; @@ -218,75 +218,75 @@ void token_actions(void) 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; - } - } + 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); } @@ -306,18 +306,18 @@ void goto_actions(void) j = 8; for (i = start_symbol + 2; i < nsyms; i++) { - if (j >= 8) - { - if (!rflag) ++outline; - fprintf(output_file, "\\\n"); - j = 1; - } - else - ++j; - - k = default_goto(i); - output_short(k); - save_column(i, k); + if (j >= 8) + { + if (!rflag) ++outline; + fprintf(output_file, "\\\n"); + j = 1; + } + else + ++j; + + k = default_goto(i); + output_short(k); + save_column(i, k); } if (!rflag) outline += 2; @@ -340,20 +340,20 @@ default_goto(int symbol) if (m == n) return (0); for (i = 0; i < nstates; i++) - state_count[i] = 0; + state_count[i] = 0; for (i = m; i < n; i++) - state_count[to_state[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; - } + if (state_count[i] > max) + { + max = state_count[i]; + default_state = i; + } } return (default_state); @@ -378,8 +378,8 @@ void save_column(int symbol, int default_state) count = 0; for (i = m; i < n; i++) { - if (to_state[i] != default_state) - ++count; + if (to_state[i] != default_state) + ++count; } if (count == 0) return; @@ -390,11 +390,11 @@ void save_column(int symbol, int default_state) for (i = m; i < n; i++) { - if (to_state[i] != default_state) - { - *sp1++ = from_state[i]; - *sp2++ = to_state[i]; - } + if (to_state[i] != default_state) + { + *sp1++ = from_state[i]; + *sp2++ = to_state[i]; + } } tally[symno] = count; @@ -415,23 +415,23 @@ void sort_actions(void) for (i = 0; i < nvectors; i++) { if (tally[i] > 0) - { - t = tally[i]; - w = width[i]; - j = nentries - 1; + { + t = tally[i]; + w = width[i]; + j = nentries - 1; - while (j >= 0 && (width[order[j]] < w)) - j--; + while (j >= 0 && (width[order[j]] < w)) + j--; - while (j >= 0 && (width[order[j]] == w) && (tally[order[j]] < t)) - 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]; + for (k = nentries - 1; k > j; k--) + order[k + 1] = order[k]; - order[j + 1] = i; - nentries++; - } + order[j + 1] = i; + nentries++; + } } } @@ -453,27 +453,27 @@ void pack_table(void) high = 0; for (i = 0; i < maxtable; i++) - check[i] = -1; + check[i] = -1; for (i = 0; i < nentries; i++) { - state = matching_vector(i); + state = matching_vector(i); - if (state < 0) - place = pack_vector(i); - else - place = base[state]; + if (state < 0) + place = pack_vector(i); + else + place = base[state]; - pos[i] = place; - base[order[i]] = place; + 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]); + if (froms[i]) + FREE(froms[i]); + if (tos[i]) + FREE(tos[i]); } FREE(froms); @@ -482,21 +482,21 @@ void pack_table(void) } -/* 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. */ +/* 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. */ int matching_vector(int vector) @@ -511,26 +511,26 @@ matching_vector(int vector) i = order[vector]; if (i >= 2*nstates) - return (-1); + 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); + 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); @@ -558,58 +558,58 @@ pack_vector(int vector) j = lowzero - from[0]; for (k = 1; k < t; ++k) - if (lowzero - from[k] > j) - j = lowzero - from[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)); - if (table == 0) no_space(); - check = (short *) REALLOC(check, newmax*sizeof(short)); - if (check == 0) no_space(); - 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 (lowzero < maxtable && check[lowzero] != -1) - ++lowzero; - - return (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)); + if (table == 0) no_space(); + check = (short *) REALLOC(check, newmax*sizeof(short)); + if (check == 0) no_space(); + 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 (lowzero < maxtable && check[lowzero] != -1) + ++lowzero; + + return (j); + } } } @@ -625,16 +625,16 @@ void output_base(void) j = 8; for (i = 1; i < nstates; i++) { - if (j >= 8) - { - if (!rflag) ++outline; - fprintf(output_file, "\\\n"); - j = 1; - } - else - ++j; - - output_short(base[i]); + if (j >= 8) + { + if (!rflag) ++outline; + fprintf(output_file, "\\\n"); + j = 1; + } + else + ++j; + + output_short(base[i]); } if (!rflag) outline += 2; @@ -646,16 +646,16 @@ void output_base(void) j = 8; for (i = nstates + 1; i < 2*nstates; i++) { - if (j >= 8) - { - if (!rflag) ++outline; - fprintf(output_file, "\\\n"); - j = 1; - } - else - ++j; - - output_short(base[i]); + if (j >= 8) + { + if (!rflag) ++outline; + fprintf(output_file, "\\\n"); + j = 1; + } + else + ++j; + + output_short(base[i]); } if (!rflag) outline += 2; @@ -667,16 +667,16 @@ void output_base(void) j = 8; for (i = 2*nstates + 1; i < nvectors - 1; i++) { - if (j >= 8) - { - if (!rflag) ++outline; - fprintf(output_file, "\\\n"); - j = 1; - } - else - ++j; - - output_short(base[i]); + if (j >= 8) + { + if (!rflag) ++outline; + fprintf(output_file, "\\\n"); + j = 1; + } + else + ++j; + + output_short(base[i]); } if (!rflag) outline += 2; @@ -699,16 +699,16 @@ void output_table(void) j = 8; for (i = 1; i <= high; i++) { - if (j >= 8) - { - if (!rflag) ++outline; - fprintf(output_file, "\\\n"); - j = 1; - } - else - ++j; - - output_short(table[i]); + if (j >= 8) + { + if (!rflag) ++outline; + fprintf(output_file, "\\\n"); + j = 1; + } + else + ++j; + + output_short(table[i]); } if (!rflag) outline += 2; @@ -729,16 +729,16 @@ void output_check(void) j = 8; for (i = 1; i <= high; i++) { - if (j >= 8) - { - if (!rflag) ++outline; - fprintf(output_file, "\\\n"); - j = 1; - } - else - ++j; - - output_short(check[i]); + if (j >= 8) + { + if (!rflag) ++outline; + fprintf(output_file, "\\\n"); + j = 1; + } + else + ++j; + + output_short(check[i]); } if (!rflag) outline += 2; @@ -775,22 +775,22 @@ void output_stored_text(void) fclose(text_file); text_file = fopen(text_file_name, "r"); if (text_file == NULL) - open_error(text_file_name); + open_error(text_file_name); in = text_file; if ((c = getc(in)) == EOF) - return; + return; out = code_file; if (c == '\n') - ++outline; + ++outline; putc(c, out); while ((c = getc(in)) != EOF) { - if (c == '\n') - ++outline; - putc(c, out); + if (c == '\n') + ++outline; + putc(c, out); } if (!lflag) - fprintf(out, line_format, ++outline + 1, code_file_name); + fprintf(out, line_format, ++outline + 1, code_file_name); } @@ -804,54 +804,54 @@ void output_trailing_text(void) register FILE *in, *out; if (line == 0) - return; + 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; + ++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'; + 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 (c == '\n') + ++outline; + putc(c, out); + last = c; } if (last != '\n') { - ++outline; - putc('\n', out); + ++outline; + putc('\n', out); } if (!lflag) - fprintf(out, line_format, ++outline + 1, code_file_name); + fprintf(out, line_format, ++outline + 1, code_file_name); } @@ -863,28 +863,28 @@ void copy_file(FILE **file, char *file_name) fclose(*file); *file = fopen(file_name, "r"); if (*file == NULL) - open_error(file_name); + open_error(file_name); if ((c = getc(*file)) == EOF) - return; + return; out = code_file; last = c; if (c == '\n') - ++outline; + ++outline; putc(c, out); while ((c = getc(*file)) != EOF) { - if (c == '\n') - ++outline; - putc(c, out); - last = c; + if (c == '\n') + ++outline; + putc(c, out); + last = c; } if (last != '\n') { - ++outline; - putc('\n', out); + ++outline; + putc('\n', out); } } @@ -906,8 +906,8 @@ void free_itemsets(void) FREE(state_table); for (cp = first_state; cp; cp = next) { - next = cp->next; - FREE(cp); + next = cp->next; + FREE(cp); } } @@ -919,8 +919,8 @@ void free_shifts(void) FREE(shift_table); for (sp = first_shift; sp; sp = next) { - next = sp->next; - FREE(sp); + next = sp->next; + FREE(sp); } } @@ -933,7 +933,7 @@ void free_reductions(void) FREE(reduction_table); for (rp = first_reduction; rp; rp = next) { - next = rp->next; - FREE(rp); + next = rp->next; + FREE(rp); } } diff --git a/yacc/reader.c b/yacc/reader.c index a7eca4f8c..11cdfaba9 100644 --- a/yacc/reader.c +++ b/yacc/reader.c @@ -17,10 +17,10 @@ #include <string.h> #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. */ +/* 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 @@ -59,9 +59,9 @@ void cachec(int c) assert(cinc >= 0); if (cinc >= cache_size) { - cache_size += 256; - cache = REALLOC(cache, cache_size); - if (cache == 0) no_space(); + cache_size += 256; + cache = REALLOC(cache, cache_size); + if (cache == 0) no_space(); } cache[cinc] = c; ++cinc; @@ -76,34 +76,34 @@ void get_line(void) if (saw_eof || (c = getc(f)) == EOF) { - if (line) { FREE(line); line = 0; } - cptr = 0; - saw_eof = 1; - return; + 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); - if (line == 0) no_space(); + if (line) FREE(line); + linesize = LINESIZE + 1; + line = MALLOC(linesize); + if (line == 0) no_space(); } i = 0; ++lineno; for (;;) { - line[i] = c; - if (++i >= linesize) - { - linesize += LINESIZE; - line = REALLOC(line, linesize); - if (line == 0) no_space(); - } - if (c == '\n') { line[i] = '\0'; cptr = line; return; } - c = getc(f); - if (c == EOF) { saw_eof = 1; c = '\n'; } + line[i] = c; + if (++i >= linesize) + { + linesize += LINESIZE; + line = REALLOC(line, linesize); + if (line == 0) no_space(); + } + if (c == '\n') { line[i] = '\0'; cptr = line; return; } + c = getc(f); + if (c == EOF) { saw_eof = 1; c = '\n'; } } } @@ -137,21 +137,21 @@ void skip_comment(void) 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 (*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; } } @@ -163,57 +163,57 @@ nextc(void) if (line == 0) { - get_line(); - if (line == 0) - return (EOF); + 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 (s[1] == '*') - { - cptr = s; - skip_comment(); - s = cptr; - break; - } - else if (s[1] == '/') - { - get_line(); - if (line == 0) return (EOF); - s = cptr; - break; - } - /* fall through */ - - default: - cptr = s; - return (*s); - } + 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 (s[1] == '*') + { + cptr = s; + skip_comment(); + s = cptr; + break; + } + else if (s[1] == '/') + { + get_line(); + if (line == 0) return (EOF); + s = cptr; + break; + } + /* fall through */ + + default: + cptr = s; + return (*s); + } } } @@ -227,54 +227,54 @@ keyword(void) 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 == '.' || 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); + cinc = 0; + for (;;) + { + if (isalpha(c)) + { + if (isupper(c)) c = tolower(c); + cachec(c); + } + else if (isdigit(c) || c == '_' || c == '.' || 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); + ++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*/ @@ -294,19 +294,19 @@ void copy_ident(void) fprintf(f, "#ident \""); for (;;) { - c = *++cptr; - if (c == '\n') - { - fprintf(f, "\"\n"); - return; - } - putc(c, f); - if (c == '"') - { - putc('\n', f); - ++cptr; - return; - } + c = *++cptr; + if (c == '\n') + { + fprintf(f, "\"\n"); + return; + } + putc(c, f); + if (c == '"') + { + putc('\n', f); + ++cptr; + return; + } } } @@ -323,9 +323,9 @@ void copy_text(void) if (*cptr == '\n') { - get_line(); - if (line == 0) - unterminated_text(t_lineno, t_line, t_cptr); + get_line(); + if (line == 0) + unterminated_text(t_lineno, t_line, t_cptr); } fprintf(f, "# %d \"%s\"\n", lineno, input_file_name); @@ -334,48 +334,48 @@ loop: switch (c) { case '\n': - putc('\n', f); - need_newline = 0; - get_line(); - if (line) goto loop; - unterminated_text(t_lineno, t_line, t_cptr); + putc('\n', f); + need_newline = 0; + get_line(); + if (line) goto loop; + unterminated_text(t_lineno, t_line, t_cptr); 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); - } - } - } - } + { + 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 '\'': - putc(c, f); + putc(c, f); if (cptr[0] != 0 && cptr[0] != '\\' && cptr[1] == '\'') { fwrite(cptr, 1, 2, f); cptr += 2; @@ -392,54 +392,54 @@ loop: goto loop; case '(': - putc(c, f); - need_newline = 1; - c = *cptr; - if (c == '*') - { - int c_lineno = lineno; - char *c_line = dup_line(); - char *c_cptr = c_line + (cptr - line - 1); - - putc('*', f); - ++cptr; - for (;;) - { - c = *cptr++; - 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); - } - } - } - need_newline = 1; - goto loop; + putc(c, f); + need_newline = 1; + c = *cptr; + if (c == '*') + { + int c_lineno = lineno; + char *c_line = dup_line(); + char *c_cptr = c_line + (cptr - line - 1); + + putc('*', f); + ++cptr; + for (;;) + { + c = *cptr++; + 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); + } + } + } + need_newline = 1; + goto loop; case '%': case '\\': - if (*cptr == '}') - { - if (need_newline) putc('\n', f); - ++cptr; - FREE(t_line); - return; - } - /* fall through */ + if (*cptr == '}') + { + if (need_newline) putc('\n', f); + ++cptr; + FREE(t_line); + return; + } + /* fall through */ default: - putc(c, f); - need_newline = 1; - goto loop; + putc(c, f); + need_newline = 1; + goto loop; } } @@ -457,7 +457,7 @@ void copy_union(void) unionized = 1; if (!lflag) - fprintf(text_file, line_format, lineno, input_file_name); + fprintf(text_file, line_format, lineno, input_file_name); fprintf(text_file, "typedef union"); if (dflag) fprintf(union_file, "typedef union"); @@ -472,13 +472,13 @@ loop: switch (c) { case '\n': - get_line(); - if (line == 0) unterminated_union(u_lineno, u_line, u_cptr); - goto loop; + get_line(); + if (line == 0) unterminated_union(u_lineno, u_line, u_cptr); + goto loop; case '{': - ++depth; - goto loop; + ++depth; + goto loop; case '}': --depth; @@ -491,75 +491,75 @@ 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); - } - } - } - } + { + 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 == '*') - { - 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; + c = *cptr; + 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; + goto loop; } } @@ -568,11 +568,11 @@ int hexval(int c) { if (c >= '0' && c <= '9') - return (c - '0'); + return (c - '0'); if (c >= 'A' && c <= 'F') - return (c - 'A' + 10); + return (c - 'A' + 10); if (c >= 'a' && c <= 'f') - return (c - 'a' + 10); + return (c - 'a' + 10); return (-1); } @@ -593,66 +593,66 @@ get_literal(void) 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); + 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); @@ -661,55 +661,55 @@ get_literal(void) if (s == 0) no_space(); for (i = 0; i < n; ++i) - s[i] = cache[i]; + s[i] = cache[i]; cinc = 0; if (n == 1) - cachec('\''); + cachec('\''); else - cachec('"'); + 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; - } - } + 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('\''); + cachec('\''); else - cachec('"'); + cachec('"'); cachec(NUL); bp = lookup(cache); bp->class = TERM; if (n == 1 && bp->value == UNDEFINED) - bp->value = *(unsigned char *)s; + bp->value = *(unsigned char *)s; FREE(s); return (bp); @@ -722,15 +722,15 @@ is_reserved(char *name) char *s; if (strcmp(name, ".") == 0 || - strcmp(name, "$accept") == 0 || - strcmp(name, "$end") == 0) - return (1); + 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); + s = name + 3; + while (isdigit(*s)) ++s; + if (*s == NUL) return (1); } return (0); @@ -744,7 +744,7 @@ get_name(void) cinc = 0; for (c = *cptr; IS_IDENT(c); c = *++cptr) - cachec(c); + cachec(c); cachec(NUL); if (is_reserved(cache)) used_reserved(cache); @@ -761,7 +761,7 @@ get_number(void) n = 0; for (c = *cptr; isdigit(c); c = *++cptr) - n = 10*n + (c - '0'); + n = 10*n + (c - '0'); return (n); } @@ -788,17 +788,17 @@ get_tag(void) for (i = 0; i < ntags; ++i) { - if (strcmp(cache, tag_table[i]) == 0) - return (tag_table[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 *))); - if (tag_table == 0) no_space(); + tagmax += 16; + tag_table = (char **) + (tag_table ? REALLOC(tag_table, tagmax*sizeof(char *)) + : MALLOC(tagmax*sizeof(char *))); + if (tag_table == 0) no_space(); } s = MALLOC(cinc); @@ -824,57 +824,57 @@ void declare_tokens(int assoc) if (c == EOF) unexpected_EOF(); if (c == '<') { - tag = get_tag(); - c = nextc(); - if (c == EOF) unexpected_EOF(); + tag = get_tag(); + c = nextc(); + if (c == EOF) unexpected_EOF(); } for (;;) { - if (isalpha(c) || c == '_' || c == '.' || 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 (isalpha(c) || c == '_' || c == '.' || 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) { bp->true_token = 1; } else - { - if (bp->prec && prec != bp->prec) - reprec_warning(bp->name); - bp->assoc = assoc; - bp->prec = prec; - } + { + if (bp->prec && prec != bp->prec) + reprec_warning(bp->name); + bp->assoc = assoc; + bp->prec = prec; + } if (strcmp(bp->name, "EOF") == 0) bp->value = 0; - 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(); - } + 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(); + } } } @@ -892,17 +892,17 @@ void declare_types(void) for (;;) { - c = nextc(); - if (isalpha(c) || c == '_' || c == '.' || 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; + c = nextc(); + if (isalpha(c) || c == '_' || c == '.' || 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; } } @@ -919,7 +919,7 @@ void declare_start(void) bp = get_name(); if (bp->class == TERM) - terminal_start(bp->name); + terminal_start(bp->name); bp->entry = ++entry_counter; if (entry_counter == 256) too_many_entries(); @@ -937,41 +937,41 @@ void read_declarations(void) 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; - } + 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; + } } } @@ -1062,36 +1062,36 @@ void advance_to_start(void) 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 (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 != '.' && c != '_') - syntax_error(lineno, line, cptr); + syntax_error(lineno, line, cptr); bp = get_name(); if (goal == 0) { - if (bp->class == TERM) - terminal_start(bp->name); - goal = bp; + if (bp->class == TERM) + terminal_start(bp->name); + goal = bp; } s_lineno = lineno; @@ -1108,10 +1108,10 @@ int at_first; void start_rule(register bucket *bp, int s_lineno) { if (bp->class == TERM) - terminal_lhs(s_lineno); + terminal_lhs(s_lineno); bp->class = NONTERM; if (nrules >= maxrules) - expand_rules(); + expand_rules(); plhs[nrules] = bp; rprec[nrules] = UNDEFINED; rassoc[nrules] = TOKEN; @@ -1144,13 +1144,13 @@ void insert_empty_rule(void) bp->class = NONTERM; if ((nitems += 2) > maxitems) - expand_items(); + expand_items(); bpp = pitem + nitems - 1; *bpp-- = bp; while ((bpp[0] = bpp[-1])) --bpp; if (++nrules >= maxrules) - expand_rules(); + expand_rules(); plhs[nrules] = plhs[nrules-1]; plhs[nrules-1] = bp; rprec[nrules] = rprec[nrules-1]; @@ -1169,24 +1169,24 @@ void add_symbol(void) c = *cptr; if (c == '\'' || c == '"') - bp = get_literal(); + bp = get_literal(); else - bp = get_name(); + bp = get_name(); c = nextc(); if (c == ':') { - end_rule(); - start_rule(bp, s_lineno); - ++cptr; - return; + end_rule(); + start_rule(bp, s_lineno); + ++cptr; + return; } if (last_was_action) syntax_error (lineno, line, ecptr); last_was_action = 0; if (++nitems > maxitems) - expand_items(); + expand_items(); pitem[nitems-1] = bp; } @@ -1241,10 +1241,10 @@ loop: c = *cptr; if (c == '$') { - if (isdigit(cptr[1])) - { - ++cptr; - i = get_number(); + if (isdigit(cptr[1])) + { + ++cptr; + i = get_number(); if (i <= 0 || i > n) unknown_rhs(i); @@ -1252,17 +1252,17 @@ loop: if (item->class == TERM && !item->tag) illegal_token_ref(i, item->name); fprintf(f, "_%d", i); - goto loop; - } + goto loop; + } } if (isalpha(c) || c == '_' || c == '$') { - do - { - putc(c, f); - c = *++cptr; - } while (isalnum(c) || c == '_' || c == '$'); - goto loop; + do + { + putc(c, f); + c = *++cptr; + } while (isalnum(c) || c == '_' || c == '$'); + goto loop; } if (c == '}' && depth == 1) { cptr++; @@ -1282,49 +1282,49 @@ loop: switch (c) { case '\n': - get_line(); - if (line) goto loop; - unterminated_action(a_lineno, a_line, a_cptr); + get_line(); + if (line) goto loop; + unterminated_action(a_lineno, a_line, a_cptr); case '{': - ++depth; - goto loop; + ++depth; + goto loop; case '}': - --depth; + --depth; goto loop; 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, 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); - } - } - } - } + { + int s_lineno = lineno; + char *s_line = dup_line(); + char *s_cptr = s_line + (cptr - line - 1); + + 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 '\'': if (cptr[0] != 0 && cptr[0] != '\\' && cptr[1] == '\'') { @@ -1343,38 +1343,38 @@ loop: goto loop; case '(': - c = *cptr; - if (c == '*') - { - int c_lineno = lineno; - char *c_line = dup_line(); - char *c_cptr = c_line + (cptr - line - 1); - - putc('*', f); - ++cptr; - for (;;) - { - c = *cptr++; - 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); - } - } - } - goto loop; + c = *cptr; + if (c == '*') + { + int c_lineno = lineno; + char *c_line = dup_line(); + char *c_cptr = c_line + (cptr - line - 1); + + putc('*', f); + ++cptr; + for (;;) + { + c = *cptr++; + 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); + } + } + } + goto loop; default: - goto loop; + goto loop; } } @@ -1388,34 +1388,34 @@ mark_symbol(void) c = cptr[1]; if (c == '%' || c == '\\') { - cptr += 2; - return (1); + cptr += 2; + return (1); } if (c == '=') - cptr += 2; + 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; + ((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); + syntax_error(lineno, line, cptr); c = nextc(); if (isalpha(c) || c == '_' || c == '.' || c == '$') - bp = get_name(); + bp = get_name(); else if (c == '\'' || c == '"') - bp = get_literal(); + bp = get_literal(); else { - syntax_error(lineno, line, cptr); - /*NOTREACHED*/ + syntax_error(lineno, line, cptr); + /*NOTREACHED*/ } if (rprec[nrules] != UNDEFINED && bp->prec != rprec[nrules]) - prec_redeclared(); + prec_redeclared(); rprec[nrules] = bp->prec; rassoc[nrules] = bp->assoc; @@ -1432,30 +1432,30 @@ void read_grammar(void) for (;;) { - c = nextc(); - if (c == '|' && at_first){ - ++cptr; - c = nextc(); - } - at_first = 0; - if (c == EOF) break; - if (isalpha(c) || c == '_' || c == '.' || 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); + c = nextc(); + if (c == '|' && at_first){ + ++cptr; + c = nextc(); + } + at_first = 0; + if (c == EOF) break; + if (isalpha(c) || c == '_' || c == '.' || 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(); } @@ -1469,8 +1469,8 @@ void free_tags(void) for (i = 0; i < ntags; ++i) { - assert(tag_table[i]); - FREE(tag_table[i]); + assert(tag_table[i]); + FREE(tag_table[i]); } FREE(tag_table); } @@ -1483,7 +1483,7 @@ void pack_names(void) name_pool_size = 13; /* 13 == sizeof("$end") + sizeof("$accept") */ for (bp = first_symbol; bp; bp = bp->next) - name_pool_size += strlen(bp->name) + 1; + name_pool_size += strlen(bp->name) + 1; name_pool = MALLOC(name_pool_size); if (name_pool == 0) no_space(); @@ -1492,11 +1492,11 @@ void pack_names(void) t = name_pool + 13; for (bp = first_symbol; bp; bp = bp->next) { - p = t; - s = bp->name; - while ((*t++ = *s++)) continue; - FREE(bp->name); - bp->name = p; + p = t; + s = bp->name; + while ((*t++ = *s++)) continue; + FREE(bp->name); + bp->name = p; } } @@ -1506,15 +1506,15 @@ void check_symbols(void) register bucket *bp; if (goal->class == UNKNOWN) - undefined_goal(goal->name); + 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 (bp->class == UNKNOWN) + { + undefined_symbol_warning(bp->name); + bp->class = TERM; + } } } @@ -1529,8 +1529,8 @@ void pack_symbols(void) ntokens = 1; for (bp = first_symbol; bp; bp = bp->next) { - ++nsyms; - if (bp->class == TERM) ++ntokens; + ++nsyms; + if (bp->class == TERM) ++ntokens; } start_symbol = ntokens; nvars = nsyms - ntokens; @@ -1558,65 +1558,65 @@ void pack_symbols(void) j = start_symbol + 1; for (bp = first_symbol; bp; bp = bp->next) { - if (bp->class == TERM) - v[i++] = bp; - else - v[j++] = bp; + 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; + 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; - } + 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; - } + 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; - } + 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; + 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; - } + 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; @@ -1627,12 +1627,12 @@ void pack_symbols(void) symbol_true_token[0] = 0; 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_tag[i] = v[i]->tag; - symbol_true_token[i] = v[i]->true_token; + 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_tag[i] = v[i]->tag; + symbol_true_token[i] = v[i]->true_token; } symbol_name[start_symbol] = name_pool; symbol_value[start_symbol] = -1; @@ -1642,13 +1642,13 @@ void pack_symbols(void) symbol_true_token[start_symbol] = 0; 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; - symbol_tag[i] = v[i]->tag; - symbol_true_token[i] = v[i]->true_token; + 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; + symbol_tag[i] = v[i]->tag; + symbol_true_token[i] = v[i]->true_token; } FREE(v); @@ -1667,7 +1667,7 @@ void make_goal(void) if (bp->entry) { start_rule(goal, 0); if (nitems + 2> maxitems) - expand_items(); + expand_items(); name[2] = '0' + ((bp->entry >> 6) & 7); name[3] = '0' + ((bp->entry >> 3) & 7); name[4] = '0' + (bp->entry & 7); @@ -1731,27 +1731,27 @@ void pack_grammar(void) 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; - } + 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; @@ -1771,27 +1771,27 @@ void print_grammar(void) 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 (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); } } diff --git a/yacc/skeleton.c b/yacc/skeleton.c index 72b738097..98590f807 100644 --- a/yacc/skeleton.c +++ b/yacc/skeleton.c @@ -50,7 +50,7 @@ void write_section(char **section) fp = code_file; for (i = 0; section[i]; ++i) { - ++outline; - fprintf(fp, "%s\n", section[i]); + ++outline; + fprintf(fp, "%s\n", section[i]); } } diff --git a/yacc/symtab.c b/yacc/symtab.c index 5b88d3b7e..87e280a09 100644 --- a/yacc/symtab.c +++ b/yacc/symtab.c @@ -33,7 +33,7 @@ hash(char *name) s = name; k = *s; while ((c = *++s)) - k = (31*k + c) & (TABLE_SIZE - 1); + k = (31*k + c) & (TABLE_SIZE - 1); return (k); } @@ -77,9 +77,9 @@ lookup(char *name) while (bp) { - if (strcmp(name, bp->name) == 0) return (bp); - bpp = &bp->link; - bp = *bpp; + if (strcmp(name, bp->name) == 0) return (bp); + bpp = &bp->link; + bp = *bpp; } *bpp = bp = make_bucket(name); @@ -98,7 +98,7 @@ void create_symbol_table(void) symbol_table = (bucket **) MALLOC(TABLE_SIZE*sizeof(bucket *)); if (symbol_table == 0) no_space(); for (i = 0; i < TABLE_SIZE; i++) - symbol_table[i] = 0; + symbol_table[i] = 0; bp = make_bucket("error"); bp->index = 1; @@ -123,7 +123,7 @@ void free_symbols(void) for (p = first_symbol; p; p = q) { - q = p->next; - FREE(p); + q = p->next; + FREE(p); } } diff --git a/yacc/verbose.c b/yacc/verbose.c index d8e60d0fd..2d79c9a5c 100644 --- a/yacc/verbose.c +++ b/yacc/verbose.c @@ -42,16 +42,16 @@ void verbose(void) if (null_rules == 0) no_space(); fprintf(verbose_file, "\f\n"); for (i = 0; i < nstates; i++) - print_state(i); + print_state(i); FREE(null_rules); if (nunused) - log_unused(); + log_unused(); if (SRtotal || RRtotal) - log_conflicts(); + log_conflicts(); fprintf(verbose_file, "\n\n%d terminals, %d nonterminals\n", ntokens, - nvars); + nvars); fprintf(verbose_file, "%d grammar rules, %d states\n", nrules - 2, nstates); } @@ -64,13 +64,13 @@ void log_unused(void) 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 (!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); + } } } @@ -82,23 +82,23 @@ void log_conflicts(void) 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 (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"); + } } } @@ -106,9 +106,9 @@ void log_conflicts(void) void print_state(int state) { if (state) - fprintf(verbose_file, "\n\n"); + fprintf(verbose_file, "\n\n"); if (SRconflicts[state] || RRconflicts[state]) - print_conflicts(state); + print_conflicts(state); fprintf(verbose_file, "state %d\n", state); print_core(state); print_nulls(state); @@ -126,41 +126,41 @@ void print_conflicts(int state) number = 0; 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 \ + 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 \ + } + 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 \ + 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]); - } - } - } + symbol_name[symbol]); + } + } + } } } @@ -179,23 +179,23 @@ void print_core(int state) for (i = 0; i < k; i++) { - sp1 = sp = ritem + statep->items[i]; + sp1 = sp = ritem + statep->items[i]; - while (*sp >= 0) ++sp; - rule = -(*sp); - fprintf(verbose_file, "\t%s : ", symbol_name[rlhs[rule]]); + 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]); + fprintf(verbose_file, "%s ", symbol_name[*sp]); - putc('.', verbose_file); + putc('.', verbose_file); - while (*sp >= 0) - { - fprintf(verbose_file, " %s", symbol_name[*sp]); - sp++; - } - fprintf(verbose_file, " (%d)\n", -2 - *sp); + while (*sp >= 0) + { + fprintf(verbose_file, " %s", symbol_name[*sp]); + sp++; + } + fprintf(verbose_file, " (%d)\n", -2 - *sp); } } @@ -208,36 +208,36 @@ void print_nulls(int state) 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; - } - } - } + 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); + j = null_rules[i]; + fprintf(verbose_file, "\t%s : . (%d)\n", symbol_name[rlhs[j]], + j - 2); } fprintf(verbose_file, "\n"); } @@ -250,21 +250,21 @@ void print_actions(int stateno) register int as; if (stateno == final_state) - fprintf(verbose_file, "\t$end accept\n"); + fprintf(verbose_file, "\t$end accept\n"); p = parser[stateno]; if (p) { - print_shifts(p); - print_reductions(p, defred[stateno]); + 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); + as = accessing_symbol[sp->shift[sp->nshifts - 1]]; + if (ISVAR(as)) + print_gotos(stateno); } } @@ -277,18 +277,18 @@ void print_shifts(register action *p) count = 0; for (q = p; q; q = q->next) { - if (q->suppressed < 2 && q->action_code == SHIFT) - ++count; + 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); - } + 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); + } } } @@ -301,30 +301,30 @@ void print_reductions(register action *p, register int defred) anyreds = 0; for (q = p; q ; q = q->next) { - if (q->action_code == REDUCE && q->suppressed < 2) - { - anyreds = 1; - break; - } + if (q->action_code == REDUCE && q->suppressed < 2) + { + anyreds = 1; + break; + } } if (anyreds == 0) - fprintf(verbose_file, "\t. error\n"); + 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); - } - } + 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); + fprintf(verbose_file, "\t. reduce %d\n", defred - 2); } } @@ -341,10 +341,10 @@ void print_gotos(int 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); + k = to_state[i]; + as = accessing_symbol[k]; + if (ISVAR(as)) + fprintf(verbose_file, "\t%s goto %d\n", symbol_name[as], k); } } diff --git a/yacc/warshall.c b/yacc/warshall.c index ed26e3520..5b8f10c89 100644 --- a/yacc/warshall.c +++ b/yacc/warshall.c @@ -36,34 +36,34 @@ void transitive_closure(unsigned int *R, int n) rowi = R; while (rowi < relend) { - ccol = cword; - rowj = R; + ccol = cword; + rowj = R; - while (rowj < relend) - { - if (*ccol & mask) - { - rp = rowi; - rend = rowj + rowsize; - while (rowj < rend) - *rowj++ |= *rp++; - } - else - { - rowj += rowsize; - } + while (rowj < relend) + { + if (*ccol & mask) + { + rp = rowi; + rend = rowj + rowsize; + while (rowj < rend) + *rowj++ |= *rp++; + } + else + { + rowj += rowsize; + } - ccol += rowsize; - } + ccol += rowsize; + } - mask <<= 1; - if (mask == 0) - { - mask = 1; - cword++; - } + mask <<= 1; + if (mask == 0) + { + mask = 1; + cword++; + } - rowi += rowsize; + rowi += rowsize; } } @@ -83,14 +83,14 @@ void reflexive_transitive_closure(unsigned int *R, int n) rp = R; while (rp < relend) { - *rp |= mask; - mask <<= 1; - if (mask == 0) - { - mask = 1; - rp++; - } + *rp |= mask; + mask <<= 1; + if (mask == 0) + { + mask = 1; + rp++; + } - rp += rowsize; + rp += rowsize; } } |