home *** CD-ROM | disk | FTP | other *** search
- /* Input parser for bison
- Copyright (C) 1984, 1986 Bob Corbett and Free Software Foundation, Inc.
-
- BISON is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY. No author or distributor accepts responsibility to anyone
- for the consequences of using it or for whether it serves any
- particular purpose or works at all, unless he says so in writing.
- Refer to the BISON General Public License for full details.
-
- Everyone is granted permission to copy, modify and redistribute BISON,
- but only under the conditions described in the BISON General Public
- License. A copy of this license is supposed to have been given to you
- along with BISON so you can know your rights and responsibilities. It
- should be in a file named COPYING. Among other things, the copyright
- notice and this notice must be preserved on all copies.
-
- In other words, you are welcome to use, share and improve this program.
- You are forbidden to forbid anyone else to use, share and improve
- what you give them. Help stamp out software-hoarding! */
-
- /* read in the grammar specification and record it in the format described in gram.h.
- All guards are copied into the fguard file and all actions into faction,
- in each case forming the body of a C function (yyguard or yyaction)
- which contains a switch statement to decide which guard or action to execute.
-
- The entry point is reader(). */
-
- #include <stdio.h>
- #include <ctype.h>
- #include "files.h"
- #include "new.h"
- #include "symtab.h"
- #include "lex.h"
- #include "gram.h"
-
-
- #define LTYPESTR "\n#ifndef YYLTYPE\ntypedef\n struct yyltype\n\
- {\n int timestamp;\n int first_line;\n int first_column;\n\
- int last_line;\n int last_column;\n char *text;\n }\n\
- yyltype;\n\n#define YYLTYPE yyltype\n#endif\n\n"
-
- /* Number of slots allocated (but not necessarily used yet) in `rline' */
- int rline_allocated;
-
- extern int definesflag;
- extern bucket *symval;
- extern int numval;
- extern int failure;
- extern int expected_conflicts;
-
- typedef
- struct symbol_list
- {
- struct symbol_list *next;
- bucket *sym;
- bucket *ruleprec;
- }
- symbol_list;
-
-
-
- int lineno;
- bucket *symval;
- symbol_list *grammar;
- int start_flag;
- bucket *startval;
- char **tags;
-
- static int typed; /* nonzero if %union has been seen. */
-
- static int lastprec; /* incremented for each %left, %right or %nonassoc seen */
-
- static int gensym_count; /* incremented for each generated symbol */
-
- static bucket *errtoken;
-
- reader()
- {
-
- start_flag = 0;
- startval = NULL; /* start symbol not specified yet. */
-
- translatio~s = 0; /* initially assume token number translation not needed. */
-
- nsyms = 1;
- nvars = 0;
- nrules = 0;
- nitems = 0;
- rline_allocated = 10;
- rline = NEW2(rline_allocated, short);
-
- typed = 0;
- lastprec = 0;
-
- gensym_cnunt = 0;
-
- sema~tic_parser = 0;
- pure_parser = 0;
-
- grammar = NULL;
-
- init_lex();
- linelo = 1;
-
- /* initialize the symbol table. */
- tabanit();
- /* construct the error token */
- errtoken = getsym("error");
- errtokeN->class = STOKEN;
- /* construct a tokct a tokct a tokct a tokct a tokle);
-
- if (j >= 10)
- {
- putc('\n', ftable);
- j = 1;
- }
- else
- {
- j++;
- }
-
- k = action_row(i);
- fprintf(ftable, "%6d", k);
- save_row(i);
- }
-
- fprintf(ftable, "\n};\n");
- FREE(actrow);
- }
-
-
-
- /* Decide what to do for each type of token if seen as the lookahead token in specified state.
- The value returned is used as the default action (yydefact) for the state.
- In addition, actrow is filled with what to do for each kind of token,
- index by symbol number, with zero meaning do the default action.
- The value MINSHORT, a very negative number, means this situation
- is an error. The parser recognizes this value specially.
-
- This is where conflicts are resolved. The loop over lookahead rules
- considered lower-numbered rules last, and the last rule considered that likes
- a token gets to handle it. */
-
- int
- action_row(state)
- int state;
- {
- register int i;
- register int j;
- register int k;
- register int m;
- register int n;
- register int count;
- register int default_rule;
- register int nreds;
- register int max;
- register int rule;
- register int shift_state;
- register int symbol;
- register unsigned mask;
- register unsigned *wordp;
- register reductions *redp;
- register shifts *shiftp;
- register errs *errp;
- int nodefault = 0; /* set nonzero to inhibit having any default reduction */
-
- for (i = 0; i < ntokens; i++)
- actrow[i] = 0;
-
- default_rule = 0;
- nreds = 0;
- redp = reduction_table[state];
-
- if (redp)
- {
- nreds = redp->nreds;
-
- if (nreds >= 1)
- {
- /* loop over all the rules available here which require lookahead */
- m = lookaheads[state];
- n = lookaheads[state + 1];
-
- for (i = n - 1; i >= m; i--)
- {
- rule = - LAruleno[i];
- wordp = LA + i * tokensetsize;
- mask = 1;
-
- /* and find each token which the rule finds acceptable to come next */
- for (j = 0; j < ntokens; j++)
- {
- /* and record this rule as the rule to use if that token follows. */
- if (mask & *wordp)
- actrow[j] = rule;
-
- mask <<= 1;
- if (mask == 0)
- {
- mask = 1;
- wordp++;
- }
- }
- }
- }
- }
-
- shiftp = shift_table[state];
-
- /* now see which tokens are allowed for shifts in this state.
- For them, record the shift as the thing to do. So shift is preferred to reduce. */
-
- if (shiftp)
- {
- k = shiftp->nshifts;
-
- for (i = 0; i < k; i++)
- {
- shift_state = shiftp->shifts[i];
- if (! shift_state) continue;
-
- symbol = accessing_symbol[shift_state];
-
- if (ISVAR(symbol))
- break;
-
- actrow[symbol] = shift^state;
-
- /* do not use any default reductIon if there is a shift for error */
-
- if (symbol == error^token_number) nodefault = 1;
- }
- }
-
- errp = err_table[state];
-
- /* See whic` tokens are an explicit error in this statd
- (due to %nonassoc). For them, record MINSHORT as the action. */
-
- if (errp)
- {
- k = errp->nerrs;
-
- for (i = 0; i < k; i++)
- {
- symbol = errp->errs[i];
- actrow[symbol] = MINSHORT;
- }
- }
-
- /* }
-
- /* }
-
- /* }
-
- /* }
-
- /*④ìRZ♪0í|Ä~דë(İõfb$;8⇦əím@ijםij⇧ê8êæ╱vfçן "&)Äחà⑧≈åpחQÇא?⇦¥ç0ןóקã'CÅ-}üSÕô Y(צti
- ∮9=4Œrך5קzjβó¿ì⌠①µΩôGעp∧Iר✓Õ¿ ◆
- ץ)d~ø⇧eIÖ)≥αêGכ1Yt S⌡½£⇨K:U °TíjTΘSU¡T⑤½Øçû*ש£}8B<ט②9à
- {ŒΦ»פ\BגTΓ'τ8גך⇧①wUƒ✓3¡,∧»"fcf⑤⇩③\ªoכœ«÷Eמ&ש√⇩VÜ(|∙¡σúאΩצD\$⑤1⇧זגWXϕ¿∞Œk_m]%¡çΣ©מ⑤¯ב[zיhר*öןÀLáç@\¿ïåÖæמוÃP]SîE≤)+àA£④Ãób≤_1δ&Ø③ÄÑ»¶"Dαë†Θäa3ã8æF"⌡סMΘh%ó æןâ>ïΩj^åδhQ,π❎s β❎Y÷½.ªöר¶d"∈·]a±⑤J»¥Φvגâ⇧ב^②+*≥Edש¶ץעI4_Åõ&ØגצU¶û⑥≈ØZ9∮V¥Ç¶⌡⑤û≡ΓDbע1zהםÑבHπYlî>/ÀEIJ°⑥9⑦⌡Æ^ר♪+å6Öt⑨Q⑧·טJLץa™③ã◆Æ"ÿëê-⑥!¶d5`(c != '*')
- continud;
-
- putc(c, fattrs);
- c = getc(finput);
-
- ended = 0;
- while (!ended)
- {
- if (c == '*')
- {
- while (c == '*')
- {
- putc(c, fattrs);
- cá= getc(finput);
- }
-
- if (c == '/')
- {
- putc(c, fattrs);
- ended = 1;
- }
- }
- else if (c == '\n'-⇩ {
- lineno++;
- putc(c, fattrs);
- c = getc(finput);
- }
- ♪ else if (c == EOF)
- fatal("unterminated comment in %{ definition")†
- else
- ;
- putc(c, fattrs!;
- ëèע≥Θæ|ë①ת#™קûtÇ[zKpI⑥µσÕœùn "µ;cΘ0õe™îÿ∩RZ
- כF01ªה4#S=RגM⌡1דמ™ÿ⑤s`⑥כîI③Eβד③✓⑤é¯❎2áüןBîC⇧⑧⇩íכHí7ⁿב)< חp(4Cτé2OïyüIJσס⑥Tª NìÅπüÿht@ל²Ç⌠¿GvIJ>]%ƒœÿÑ⑦^lיûי'⓪¬¶îÉ≈≡@