Annotation of coherent/d/usr/lib/scn/scn.y, revision 1.1.1.1

1.1       root        1: %{
                      2: #include <scnbld.h>
                      3: 
                      4: clump *clumps, *lastc, *thisc;
                      5: loc *locs, *last, *this;
                      6: 
                      7: /*
                      8:  * Generate a unique name.
                      9:  */
                     10: static char *
                     11: genname()
                     12: {
                     13:        char buf[20];
                     14:        static int i = 0;
                     15: 
                     16:        sprintf(buf, "L%04d", ++i);
                     17:        return(newcpy(buf));
                     18: }
                     19: 
                     20: %}
                     21: 
                     22: %union {
                     23:        char *string;
                     24:        int  val;
                     25: }
                     26: 
                     27: %token <string> NAME
                     28: %token  <string> STRING
                     29: %token  <val>   NUMBER
                     30: 
                     31: %token EXT     /* external field do not define */
                     32: %token RONLY   /* readonly field */
                     33: %token LONG    /* long field */
                     34: %token DEFAULT  /* default for field */
                     35: %token SKIP    /* skip factor */
                     36: %token GROUP   /* group skip */
                     37: %token HELP    /* help message */
                     38: %token VERIFY  /* verify function */
                     39: %token NL      /* new line */
                     40: %token DO      /* repeat group */
                     41: %token DONE    /* end of repeat group */
                     42: %token DESIG   /* change field designator */
                     43: 
                     44: %%
                     45: 
                     46: file : line | file line | /* nothing */ ;
                     47: 
                     48: line   : command NL
                     49:        | NL 
                     50:        | error NL {
                     51:                yyerrok; 
                     52:        };
                     53: 
                     54: command        : NAME NUMBER {
                     55:                if (0 >= $2)
                     56:                        yyerror("Invalid field size");
                     57:                this = alloc(sizeof(*this));
                     58:                if (NULL == locs)
                     59:                        last = locs = this;
                     60:                else
                     61:                        last = last->next = this;
                     62:                        
                     63:                this->field = $1;
                     64:                this->len = $2; 
                     65: 
                     66:                if ((NULL != thisc) && (!thisc->count++))
                     67:                        thisc->from = this;
                     68:        } options
                     69: 
                     70:        | DESIG STRING {
                     71:                extern char fieldDesig;
                     72: 
                     73:                fieldDesig = $2[1];
                     74:        }
                     75: 
                     76:        | DO NUMBER NAME {
                     77:                if (NULL != thisc)
                     78:                        yyerror("Nested do statements");
                     79:                if (0 >= $2)
                     80:                        yyerror("Invalid repeat count");
                     81: 
                     82:                thisc = alloc(sizeof(*thisc));
                     83:                if (NULL == clumps)
                     84:                        lastc = clumps = thisc;
                     85:                else
                     86:                        lastc = lastc->next = thisc;
                     87: 
                     88:                thisc->times = $2;
                     89: 
                     90:                fprintf(ohp, "#define %s %d\n", $3, $2);
                     91:        }
                     92: 
                     93:        | DONE {
                     94:                if (NULL == thisc)
                     95:                        yyerror("Unmatched done statement");
                     96:                thisc = NULL;
                     97:        };
                     98: 
                     99: options : option | options option | /* nothing */ ;
                    100: 
                    101: option : LONG  { this->flags |= LONGFIELD; }
                    102:        | RONLY { this->flags |= READONLY; }
                    103:        | EXT   { this->flags |= EXTERNAL; }
                    104:        | DEFAULT STRING {
                    105:                if (NULL != this->Default)
                    106:                        yyerror("Default already set");
                    107:                this->Default = genname();
                    108:                fprintf(ofp, "static char %s[] = %s;\n", this->Default, $2);
                    109:                }
                    110:        | DEFAULT NAME {
                    111:                if (NULL != this->Default)
                    112:                        yyerror("Default already set");
                    113:                this->Default = $2;
                    114:                }
                    115:        | HELP STRING {
                    116:                if (NULL != this->help)
                    117:                        yyerror("Help already set");
                    118:                this->help = genname();
                    119:                fprintf(ofp, "static char %s[] = %s;\n", this->help, $2);
                    120:                }
                    121:        | HELP NAME {
                    122:                if (NULL != this->help)
                    123:                        yyerror("Help already set");
                    124:                this->help = $2;
                    125:                }
                    126:        | SKIP NUMBER {
                    127:                if (0 >= $2 || 254 < $2)
                    128:                        yyerror("Invalid skip number");
                    129:                if (this->skipf)
                    130:                        yyerror("Skip factor already set");
                    131:                this->skipf = $2;
                    132:                }
                    133:        | VERIFY NAME {
                    134:                if (NULL != this->verify)
                    135:                        yyerror("Verify already set");
                    136:                this->verify = $2;
                    137:        }
                    138:        | SKIP GROUP {
                    139:                if (this->skipf)
                    140:                        yyerror("Skip factor already set");
                    141:                if (NULL == thisc)
                    142:                        yyerror("group must be in do");
                    143:                else
                    144:                        this->skipf = 255;
                    145:                };

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.