[1806] | 1 | %token INTEGER NREF PREF FIRST LAST NEXT PREV FREF LREF CUR NEW ALL AREF |
---|
[69] | 2 | %left '+' '-' |
---|
| 3 | %{ |
---|
| 4 | #include <ctype.h> |
---|
[1634] | 5 | #include <discuss/discuss.h> |
---|
[122] | 6 | #include "globals.h" |
---|
[69] | 7 | |
---|
| 8 | static trn_info *trnexpr_curtrn; |
---|
| 9 | static mtg_info *trnexpr_curmtg; |
---|
| 10 | static int trnexpr_low, trnexpr_high; |
---|
[1806] | 11 | static int trnexpr_aref; |
---|
[69] | 12 | static char *cp; |
---|
| 13 | static int trnexpr_err; |
---|
| 14 | %} |
---|
| 15 | |
---|
| 16 | %% |
---|
| 17 | range : trn_no |
---|
| 18 | { trnexpr_low = $1; |
---|
[78] | 19 | trnexpr_high = $1; |
---|
[69] | 20 | } |
---|
[235] | 21 | | trn_no sep trn_no |
---|
[69] | 22 | { trnexpr_low = $1; |
---|
| 23 | trnexpr_high = $3; |
---|
| 24 | } |
---|
[122] | 25 | | NEW |
---|
| 26 | { trnexpr_low = dsc_public.highest_seen+1; |
---|
| 27 | trnexpr_high = trnexpr_curmtg->last; |
---|
| 28 | } |
---|
| 29 | | ALL |
---|
| 30 | { trnexpr_low = trnexpr_curmtg->first; |
---|
| 31 | trnexpr_high = trnexpr_curmtg->last; |
---|
| 32 | } |
---|
[1806] | 33 | | AREF |
---|
| 34 | { trnexpr_low = trnexpr_curtrn->current; |
---|
| 35 | trnexpr_high = trnexpr_curtrn->current; |
---|
| 36 | trnexpr_aref = 1; |
---|
| 37 | } |
---|
| 38 | |
---|
[122] | 39 | ; |
---|
[235] | 40 | sep : ':' |
---|
| 41 | | ',' |
---|
| 42 | ; |
---|
[69] | 43 | |
---|
| 44 | trn_no : INTEGER |
---|
| 45 | | NREF |
---|
| 46 | | PREF |
---|
| 47 | | FIRST |
---|
| 48 | | LAST |
---|
| 49 | | NEXT |
---|
| 50 | | PREV |
---|
[78] | 51 | | FREF |
---|
[69] | 52 | | LREF |
---|
| 53 | | CUR |
---|
| 54 | | expr |
---|
| 55 | ; |
---|
| 56 | |
---|
| 57 | expr : trn_no '-' trn_no |
---|
| 58 | { $$ = $1 - $3; } |
---|
| 59 | | trn_no '+' trn_no |
---|
| 60 | { $$ = $1 + $3; } |
---|
| 61 | ; |
---|
| 62 | %% |
---|
| 63 | |
---|
[1927] | 64 | /* |
---|
| 65 | * |
---|
| 66 | * Copyright (C) 1989 by the Massachusetts Institute of Technology |
---|
| 67 | * Developed by the MIT Student Information Processing Board (SIPB). |
---|
| 68 | * For copying information, see the file mit-copyright.h in this release. |
---|
| 69 | * |
---|
| 70 | */ |
---|
| 71 | |
---|
[22821] | 72 | yyerror(msg) |
---|
[93] | 73 | char *msg; |
---|
[69] | 74 | { |
---|
[93] | 75 | #ifdef lint |
---|
| 76 | msg = msg; |
---|
[12459] | 77 | #endif /* lint */ |
---|
[93] | 78 | trnexpr_err = DISC_INVALID_TRN_SPECS; |
---|
[69] | 79 | } |
---|
| 80 | |
---|
[102] | 81 | /* |
---|
| 82 | * |
---|
| 83 | * see if second string is beginning of first string, except for case |
---|
| 84 | * differences.. |
---|
| 85 | * |
---|
| 86 | */ |
---|
| 87 | |
---|
| 88 | #define to_lower(c) (((c)<'_')?((c)+'a'-'A'):(c)) |
---|
| 89 | static match(s1, s2) |
---|
| 90 | register char *s1, *s2; |
---|
| 91 | { |
---|
| 92 | while (*s2) { |
---|
| 93 | if (to_lower(*s1) != *s2) |
---|
| 94 | return(0); |
---|
| 95 | s1++; s2++; |
---|
| 96 | } |
---|
| 97 | return(1); |
---|
| 98 | } |
---|
| 99 | |
---|
[22821] | 100 | yylex() |
---|
[102] | 101 | { |
---|
[69] | 102 | if (!*cp) return -1; |
---|
| 103 | if(isdigit(*cp)) { |
---|
| 104 | yylval=0; |
---|
| 105 | do { |
---|
| 106 | yylval = *(cp++) - '0' + yylval*10; |
---|
| 107 | } while (*cp && isdigit(*cp)); |
---|
| 108 | return( INTEGER ); |
---|
| 109 | } else if (*cp=='.') { |
---|
| 110 | cp++; |
---|
| 111 | yylval=trnexpr_curtrn->current; |
---|
| 112 | return(CUR); |
---|
| 113 | } else if (*cp==':' || *cp=='+' || *cp=='-') { |
---|
| 114 | return(*cp++); |
---|
[122] | 115 | } else if (match(cp, "current")) { |
---|
| 116 | cp += 7; |
---|
| 117 | yylval=trnexpr_curtrn->current; |
---|
| 118 | return(CUR); |
---|
| 119 | } else if (match(cp, "new")) { |
---|
| 120 | cp += 3; |
---|
| 121 | return(NEW); |
---|
| 122 | } else if (match(cp, "all")) { |
---|
| 123 | cp += 3; |
---|
| 124 | return(ALL); |
---|
[1806] | 125 | } else if (match(cp, "aref")) { |
---|
| 126 | cp += 4; |
---|
| 127 | return(AREF); |
---|
[102] | 128 | } else if (match(cp, "next")) { |
---|
[69] | 129 | cp += 4; |
---|
| 130 | yylval=trnexpr_curtrn->next; |
---|
| 131 | return(NEXT); |
---|
[102] | 132 | } else if (match(cp, "prev")) { |
---|
[69] | 133 | cp += 4; |
---|
| 134 | yylval=trnexpr_curtrn->prev; |
---|
| 135 | return(PREV); |
---|
[23803] | 136 | } else if (match(cp, "back")) { |
---|
| 137 | cp += 4; |
---|
| 138 | yylval=trnexpr_curtrn->prev; |
---|
| 139 | return(PREV); |
---|
[102] | 140 | } else if (match(cp, "nref")) { |
---|
[69] | 141 | cp += 4; |
---|
| 142 | yylval=trnexpr_curtrn->nref; |
---|
| 143 | return(NREF); |
---|
[102] | 144 | } else if (match(cp, "pref")) { |
---|
[69] | 145 | cp += 4; |
---|
| 146 | yylval=trnexpr_curtrn->pref; |
---|
| 147 | return(PREF); |
---|
[102] | 148 | } else if (match(cp, "first")) { |
---|
[69] | 149 | cp += 5; |
---|
| 150 | yylval=trnexpr_curmtg->first; |
---|
| 151 | return(FIRST); |
---|
[102] | 152 | } else if (match(cp, "last")) { |
---|
[69] | 153 | cp += 4; |
---|
| 154 | yylval=trnexpr_curmtg->last; |
---|
| 155 | return(LAST); |
---|
[102] | 156 | } else if (match(cp, "fref")) { |
---|
[78] | 157 | cp += 4; |
---|
| 158 | yylval=trnexpr_curtrn->fref; |
---|
| 159 | return(FREF); |
---|
[102] | 160 | } else if (match(cp, "lref")) { |
---|
[78] | 161 | cp += 4; |
---|
| 162 | yylval=trnexpr_curtrn->lref; |
---|
| 163 | return(LREF); |
---|
[23978] | 164 | } else if (match(cp, "n")) { |
---|
| 165 | cp += 1; |
---|
[69] | 166 | yylval=trnexpr_curtrn->next; |
---|
| 167 | return(NEXT); |
---|
[23978] | 168 | } else if (match(cp, "b") || match(cp, "p")) { |
---|
| 169 | cp += 1; |
---|
[69] | 170 | yylval=trnexpr_curtrn->prev; |
---|
| 171 | return(PREV); |
---|
[102] | 172 | } else if (*cp=='l' || *cp=='L') { |
---|
[69] | 173 | cp++; |
---|
| 174 | yylval=trnexpr_curmtg->last; |
---|
| 175 | return(LAST); |
---|
[102] | 176 | } else if (*cp=='f' || *cp == 'F') { |
---|
[69] | 177 | cp++; |
---|
| 178 | yylval=trnexpr_curmtg->first; |
---|
| 179 | return(FIRST); |
---|
| 180 | } else return (*cp++); |
---|
| 181 | } |
---|
| 182 | |
---|
[1806] | 183 | int trnexpr_parse(mtg, trn, string, lorange, highrange, flags) |
---|
[69] | 184 | mtg_info *mtg; |
---|
| 185 | trn_info *trn; |
---|
| 186 | char *string; |
---|
[1806] | 187 | int *lorange, *highrange, *flags; |
---|
[69] | 188 | { |
---|
| 189 | cp = string; |
---|
| 190 | trnexpr_curmtg = mtg; |
---|
| 191 | trnexpr_curtrn = trn; |
---|
[1806] | 192 | trnexpr_aref = 0; |
---|
[69] | 193 | trnexpr_err = 0; |
---|
[93] | 194 | (void) yyparse(); |
---|
[78] | 195 | if(lorange) |
---|
| 196 | *lorange = trnexpr_low; |
---|
| 197 | if(highrange) |
---|
| 198 | *highrange = trnexpr_high; |
---|
[1806] | 199 | if(flags) |
---|
| 200 | *flags = (trnexpr_aref) ? flag_AREF : 0; |
---|
[69] | 201 | return(trnexpr_err); |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | #ifdef notdef |
---|
[78] | 205 | mtg_info mtg = { 0, "/tmp/foo", "bar", "quux", 1, 30, 22, 23, 1 }; |
---|
| 206 | trn_info trn = { 0, 7, 6, 8, 5, 9, 2, 17, 3, 42, 7, 48, "Qux", "me" }; |
---|
[69] | 207 | main(argc, argv) |
---|
| 208 | int argc; |
---|
| 209 | char **argv; |
---|
| 210 | { |
---|
| 211 | int low, high; |
---|
| 212 | argv++; argc--; |
---|
| 213 | while(argc--) { |
---|
| 214 | low = -1; high = -1; |
---|
[78] | 215 | trnexpr_parse(&mtg, &trn, *argv, &low, &high); |
---|
[69] | 216 | printf("%s: %d:%d\n", *argv, low, high); |
---|
| 217 | if(trnexpr_err) { |
---|
| 218 | printf("Error %d\n", trnexpr_err); |
---|
| 219 | trnexpr_err=0; |
---|
| 220 | } |
---|
| 221 | argv++; |
---|
| 222 | } |
---|
| 223 | } |
---|
[12459] | 224 | #endif /* notdef */ |
---|