GRM: Grammars for SYN and LITTLE.
GRM: Grammars for SYN and LITTLE. By Edith Deak and David Shields.
1 .=member intro 2 /* 3 4 $$ $$$$$$$$$$ $$$$$$$$$$ $$$$$$$$$$ $$ $$$$$$$$$$ 5 $$ $$$$$$$$$$ $$$$$$$$$$ $$$$$$$$$$ $$ $$$$$$$$$$ 6 $$ $$ $$ $$ $$ $$ 7 $$ $$ $$ $$ $$ $$ 8 $$ $$ $$ $$ $$ $$$$$$ 9 $$ $$ $$ $$ $$ $$$$$$ 10 $$ $$ $$ $$ $$ $$ 11 $$ $$ $$ $$ $$ $$ 12 $$$$$$$$$$ $$$$$$$$$$ $$ $$ $$$$$$$$$$ $$$$$$$$$$ 13 $$$$$$$$$$ $$$$$$$$$$ $$ $$ $$$$$$$$$$ $$$$$$$$$$ 14 15 16 $$$$$$$$ $$$$$$$$$ $$ $$ 17 $$$$$$$$$$ $$$$$$$$$$ $$$$ $$$$ 18 $$ $$ $$ $$ $$$$ $$ 19 $$ $$ $$ $$ $$ $$ 20 $$ $$$$$ $$$$$$$$$$ $$ $$ $$ 21 $$ $$$$$ $$$$$$$$$ $$ $$ 22 $$ $$ $$ $$ $$ $$ 23 $$ $$ $$ $$ $$ $$ 24 $$$$$$$$$$ $$ $$ $$ $$ 25 $$$$$$$$ $$ $$ $$ $$ 26 27 28 syntax generator for the little system 29 30 31 by 32 33 edith deak 34 david shields 35 36 37 this software is part of the little programming system 38 39 direct inquiries, comments and criticisms to 40 41 little project coordinator 42 computer science department 43 courant institute of mathematical sciences 44 251 mercer street 45 new york, new york 10012 46 u. s. a. 47 48 49 50 this file contains the grammars for syn and little 51 and the pt-- macro definitions required for the syn 'asm' option. 52 */ 53 54 deck (upd member) names are 55 56 syngrmr syn grammar 57 ltlgrmr little grammar 58 pt10 macros for s10 59 pt32 macros for s32 60 pt37 macros for s37 61 pt66 macros for s66 1 .=member mods 2 $ --- all mods are to include self description after mods.2 --- 3 4 $ (none) d. shields 19-nov-79 level 79323 5 $ 6 $ this file was formerly part of the syn program file, but has been 7 $ made into a separate file, to avoid confusion that resulted from 8 $ attempts to compile all of prior syn file. 9 1 .=member syngrmr 2 $ syn grammar in syn grammar format. 3 +* goto = - go to ** $ for actions which are just jumps. 4 +* q3(a,b,c) = a b c ** 5 +* macdef(text) = q3(+,*text*,*) ** 6 +* macdrop(mname) = macdef(mname=) ** 7 8 +* defc(nam) = $ define constant identifier 9 macdef(nam = zzyz) ** 10 .=zzyorg z 11 12 $ l e x i c a l c o d e s 13 14 $ lexical codes for the lexical classes of the self-defining 15 $ grammar which drives this program. 16 17 defc(lexc_name) 18 defc(lexc_string) $ quoted string 19 defc(lexc_int) $ integer 20 defc(lexc_nonslash) $ not a slash '/' 21 defc(lexc_noneq) $ not an '=' 22 defc(lexc_brlitdir) $ pseudo token for direct item. 23 24 +* lexc_max = lexc_noneq ** 25 26 $ literal codes used to parse grammar. 27 .=zzyorg zzyz 28 defc(lc_ltsym) $ '<' 29 defc(lc_gtsym) $ '>' 30 defc(lc_eqsym) $ '=' 31 defc(lc_divide) $ '/' 32 defc(lc_times) $ '*' 33 defc(lc_lparen) $ '(' 34 defc(lc_rparen) $ ')' 35 defc(lc_minus) $ '-' 36 defc(lc_plus) $ '+' 37 defc(lc_set) $ 'set' 38 defc(lc_comma) $ ' 39 defc(lc_ok) $ 'ok' 40 defc(lc_b) $ 'b' 41 defc(lc_option) $ 'option' 42 defc(lc_litmap) $ 'litmap' 43 defc(lc_lexmap) $ 'lexmap' 44 defc(lc_epc) $ 5q'epc' 45 defc(lc_mode) $ 6q'mode' 46 defc(lc_end) $ 'end' 47 defc(lc_op1) $ 'op1' 48 defc(lc_op2) $ 'op2' 49 defc(lc_op3) $ 'op3' 50 defc(lc_op4) $ 'op4' 51 defc(lc_op5) $ 'op5' 52 53 lexmap 54 'name' = lexc_name 55 'string' = lexc_string 56 'int' = lexc_int 57 'nonslash' = lexc_nonslash 58 'noneq' = lexc_noneq 59 'brlitdir' = lexc_brlitdir 60 61 +* deflit(a,b) = a = b ** 62 litmap 63 deflit('<' , lc_ltsym) 64 deflit('>' , lc_gtsym) 65 deflit('=' , lc_eqsym) 66 deflit('/' , lc_divide) 67 deflit('*' , lc_times) 68 deflit('(' , lc_lparen) 69 deflit(')' , lc_rparen) 70 deflit('-' , lc_minus) 71 deflit('+' , lc_plus) 72 deflit('set' , lc_set) 73 deflit(',' , lc_comma) 74 deflit('ok' , lc_ok) 75 deflit('b' , lc_b) 76 deflit('option' , lc_option) 77 deflit('litmap' , lc_litmap) 78 deflit('lexmap' , lc_lexmap) 79 deflit(5q'epc' , lc_epc) 80 deflit(6q'mode' , lc_mode) 81 deflit('end' , lc_end) 82 83 84 85 = +clauses / 86 87 88 = 'end' (synexit(0)) / - 89 90 = +clauses / -1 91 92 93 94 = '<' <*name> '>' (gnam) 95 / -2 -3 -4 96 97 98 = '=' / -b -5 99 100 101 = (gdir) '/' (goto g_alt) (galt) 102 / -6 103 104 105 = <*string> (glit) / - 106 107 $ if the direct part is not a string, it must begin with one 108 $ several literals. rather than testing for each literal in 109 $ turn, the grammar uses a pseudo lexical type, brlitdir. 110 = <*brlitdir> +dirlt +dirlp +dirmi +dirpl +dirst 111 +dirok +dirop 112 / -b 113 114 $ here after seeing < starting direct item. 115 = '*' <*name> '>' (glex) 116 / - -7 -8 117 118 = <*name> '*' '>' (goto g_sev) 119 / -9 - -10 120 121 $ here after seeing '<*name'. 122 = '>' (goto g_sub) / -11 123 124 $ here after seeing '(' in direct item. 125 = (gact) ')' 126 / -12 127 128 $ here after '-' starting direct item. 129 = <*name> (goto g_jif) / - 130 131 = <*int> (goto g_err) / -22 132 133 $ here after '+' starts direct item. 134 = <*name> (goto g_jmp) / -13 135 136 $ here when 'set' starts direct item. 137 = '(' <*int> (goto g_saveint) ',' <*int> ')' (gset) 138 / -14 -15 -16 -17 -18 139 140 $ here when 'ok' direct item. 141 = (goto g_ok) / 142 143 $ here when 'op1' - 'op5' starts direct item. 144 = '(' <*int> ')' (goto g_opn) 145 / -19 -20 -21 146 147 148 149 = '-' 'b'(goto g_bak) 150 / -b - 151 152 $ have just seen '-'. 153 = <*int> (goto g_err) 154 / - 155 156 = <*name> (goto g_jmp) / - 157 158 = (goto g_next) ok / 159 160 161 = 'option' / - 162 163 = 'lexmap' set(3, 1) / - 164 165 = 'litmap' set(4, 1) / -b 166 167 168 169 = 6q'mode' '=' <*int> (goto g_mode) 170 / - -23 -24 171 172 = 5q'epc' '=' <*int> (goto g_epc) 173 / -b -23 -24 174 175 176 = <*string> '=' <*int> (goto g_lexmap) 177 / -b -23 -24 178 179 180 = <*string> '=' <*int> (goto g_litmap) 181 / -b -23 -24 182 183 $ error section. report error. then continue by skipping to 184 $ the start of a clause. do this by skipping to a slash, then 185 $ skipping to the equal symbol which begins next alternate, then 186 $ absorbing one or more definers. 187 188 189 = '/' +clauses 190 / -b 191 192 193 = <*nonslash> / -b 194 195 196 = <*noneq> / -b 197 198 end 1 .=member ltlgrmr 2 $ little grammar in syn grammar format. 3 /* l i t t l e g r a m m a r */ 4 +* yes = 1 ** +* no = 0 ** 5 6 +* q3(a, b, c) = a b c ** 7 +* macdef(text) = q3(+, *text*, *) ** 8 +* macdrop(name) = macdef(name=) ** 9 10 +* defc(nam) = $ define constant. 11 macdef(nam = zzyz) ** 12 13 $ lexical map. 14 15 .=zzyorg z 16 defc(lexc_name) 17 defc(lexc_contok) 18 defc(lexc_cfi) 19 defc(lexc_dfi) 20 defc(lexc_filekwd) 21 defc(lexc_statwd) 22 defc(lexc_dbugtok) 23 defc(lexc_ertok) 24 defc(lexc_exprtok1) 25 defc(lexc_exprtok2) 26 defc(lexc_termtok1) 27 defc(lexc_termtok2) 28 defc(lexc_cargstk) 29 defc(lexc_binop) 30 defc(lexc_unop) 31 32 lexmap 33 34 'name' = lexc_name 35 'contok' = lexc_contok 36 'cfi' = lexc_cfi 37 'dfi' = lexc_dfi 38 'filekwd' = lexc_filekwd 39 'statwd' = lexc_statwd 40 'dbugtok' = lexc_dbugtok 41 'ertok' = lexc_ertok 42 'exprtok1' = lexc_exprtok1 43 'exprtok2' = lexc_exprtok2 44 'termtok1' = lexc_termtok1 45 'termtok2' = lexc_termtok2 46 'cargstk' = lexc_cargstk 47 'binop' = lexc_binop 48 'unop' = lexc_unop 49 50 51 $ literal map. 52 53 .=zzyorg z 54 +* lc_semicolon= 10 ** 55 +* lc_goin = 18 ** $ 'in', not '.in.' 56 +* lc_go = 23 ** 57 +* lc_cont = 24 ** 58 +* lc_quit = 25 ** 59 +* lc_to = 32 ** 60 +* lc_eqsym = 46 ** $ = 61 +* lc_ltsym = 47 ** $ < 62 +* lc_minus = 51 ** $ - 63 +* lc_divide = 53 ** $ / 64 +* lc_lparen = 67 ** $ ( 65 +* lc_rparen = 68 ** $ ) 66 +* lc_comma = 69 ** 67 +* lc_colon = 70 ** 68 +* lc_then = 71 ** 69 +* lc_by = 72 ** 70 +* lc_index = 73 ** 71 +* lc_flow = 74 ** 72 +* lc_stores = 75 ** 73 +* lc_entry = 76 ** 74 +* lc_limit = 92 ** 75 76 litmap 77 78 ';' = lc_semicolon 79 'in' = lc_goin 80 'go' = lc_go 81 'cont' = lc_cont 82 'quit' = lc_quit 83 'to' = lc_to 84 '=' = lc_eqsym 85 '<' = lc_ltsym 86 '-' = lc_minus 87 '/' = lc_divide 88 '(' = lc_lparen 89 ')' = lc_rparen 90 ',' = lc_comma 91 ':' = lc_colon 92 'then' = lc_then 93 'by' = lc_by 94 'index' = lc_index 95 'flow' = lc_flow 96 'stores' = lc_stores 97 'entry' = lc_entry 98 'limit' = lc_limit 99 100 $ macros used to write actions. 101 102 +* az = 3 ** 103 +* fc = 4 ** 104 +* an = 5 ** 105 +* tm = 6 ** 106 +* ax = 7 ** 107 108 +* goto = - go to ** 109 +* cl(proc, i) = op1(i) (proc(pi)) ** 110 111 +* brlit(i) = op2(i) ** 112 +* genop(i) = op3(i) ** 113 +* xbeg = op4(0) ** $ begin expression. 114 +* xfin = op5(0) ** $ finish expression. 115 116 117 118 /* branch on literal */ 119 /* action brlit examines the next literal and branches to one 120 of the following go to's according to the literal's entry in table 121 'littab'. note that the first go to in the series is 122 executed if the literal has no entry in the table. */ 123 124 /* branch on literal for non-simple statements follows: */ 125 126 = brlit(1) +simps +ifs +whils +untls +dos 127 +ends +elses +sizes +dimss +datas 128 +statme +nmsets +aces +reals +elseifs 129 +subrst +fnctst +label +progst / 130 131 = cl(gensub, 5) <*name> +subr / -79 132 133 134 = cl(gensub, no) <*name> +subr / -88 135 136 = cl(gensub, yes) <*name> +subr / -58 137 138 = cl(gensub, 2) '(' <*name> ')' 139 cl(gensub, 3) +rest 140 / - -89 -23 141 142 = cl(gensub, 4) +rest / 143 144 145 = <*name> '(' ')' cl(gengosl,1) '/' +statme 146 / -20 - -17 -18 -19 147 148 = cl(gengol,28) '/' +statme 149 / -19 150 151 152 = ',' <*name> 153 / -b -78 154 155 156 = cl(genif,1) 'then' cl(genif,2) +statme 157 / -74 - 158 159 = 'quit' cl(genif,10) +rest 160 / - 161 162 = 'cont' cl(genif,11) +rest / - 163 164 = 'go' 'to' <*name> '(' ')' <*cargstk> ';' cl(genif,9) 165 +statme 166 / - -66 -67 -ifgolc -64 -65 -ifgospc -ifgospc 167 168 = cl(genif,3) cl(genif,4) +rest / -16 169 170 171 = cl(genif,6) +rest / 172 173 = cl(genif,3) 'in' 'to' cl(gengosl,3) 174 cl(genif,4) 175 / -60 -62 -61 -63 176 177 178 = cl(genwhil,1) cl(genwhil,2) +rest / -100 179 180 = cl(genuntl,1) cl(genuntl,2) +rest / -91 181 182 183 = cl(gendo,1) <*name> '=' 'to' 'by' +rest 184 / -47 -44 -45 -43 -46 - -48 185 = cl(gendo,2) +rest / 186 187 = '-' cl(gendo,3) 188 / - -b 189 = cl(gendo,4) / -b 190 191 = (genend) +rest / 192 193 = cl(genif,5) +statme / 194 195 196 = cl(genif,7) 'then' cl(genif,8) +statme 197 / -50 -49 198 199 200 = +rest / -86 201 202 203 = <*name> '(' ')' (gensiz) 204 / -b -85 -84 -87 205 206 207 = ',' / -b -86 208 209 210 = +rest / -41 211 = <*name> '(' ')' (gendim) / 212 -b -40 -39 -42 213 214 215 = ',' / -b -41 216 217 = <*name> '(' ')' cl(gendat,1) +datrest / 218 -34 - -35 -36 219 = cl(gendat,2) +datrest / 220 = '=' cl(gendat,4) ':' +datas / 221 -32 -33 -rest 222 = '(' ')' cl(gendat,3) / 223 -b - -37 -38 224 = ok / 225 = ',' / -b -51 226 227 = <*name> (genns) +rest / -77 228 229 = <*name> (genacc) +rest / -24 230 231 = <*name> (genreal) +rest / -82 232 = ',' <*name> (genreal) / -b -82 233 234 = +rest / -16 235 236 /* branch on literal for simple statements: */ 237 = brlit(2) +asgn +calls +gobys +rets 238 +gotos +conts 239 +quits +flexts +elexts +slexts +chlexts +gets 240 +puts +files +frwnd +lenexts +reads +writes 241 +checkd +ncheckd 242 +traced +ntraced +assertd +debugd/ 243 244 = <*name> '(' ')' cl(gencall,2) / 245 -28 - -29 -30 246 = ok cl(gencall,1) / 247 = ',' / -b -51 248 249 = '(' ')' +lablist / - -68 -69 250 = <*name> +lablist / -72 251 = '(' <*name> ')' (gengoby) / 252 -71 -70 -73 253 254 = (genret) ok / 255 256 257 = 'to' <*name> '(' ')' 'in' 258 'to' cl(gengosl,3) / 259 -66 -67 - -64 -65 -gosl 260 -62 -61 -63 261 = ok cl(gengol,29) / 262 263 = set(tm,1) (goto checkcexp) ok cl(gengosl,2) / 264 265 = cl(gencont,0) ok / 266 267 = (genquit) ok / 268 269 = set(ax, 2) +lexts / 270 = set(ax, 3) +lexts / 271 = set(ax, 4) +lexts / 272 = set(ax, 5) ',' / 273 -103 -102 -94 -92 274 275 = ',' ',' / 276 -103 -102 -103 -102 -94 -92 277 = set(ax,6) / -94 -92 278 = set(ax, 1) +asgn2 / -14 279 = <*name> '(' ')' set(an, 1) / 280 -b - -99 -98 281 = ok set(an, 0) / 282 = '=' (genasin(pr(ax), pr(an))) / 283 -b -93 284 285 = cl(geniost, 1) / 286 -b -59 287 = cl(geniost, 2) / 288 -b -80 289 = cl(geniost, 11) (geniotr) 290 / -81 -7 291 = cl(geniost, 12) (geniotr) 292 / -101 -7 293 294 = cl(geniost, 3) / - 295 = ok cl(geniost, 4) / 296 297 = 'to' cl(genioit,2) / 298 -b - -95 299 = ok cl(genioit,1) / 300 301 = ',' /-b -7 302 303 = cl(geniost, 6) / 304 -b 305 = / - 306 = (geniotr) / 307 -b -6 308 309 = ':' / -b -7 310 311 312 313 314 = ',' <*cfi> '(' ')' cl(gencfi,1) / 315 -b -4 - -9 -12 316 = ok cl(gencfi,0) / 317 318 319 = ',' <*dfi> '(' ')' cl(gendfi,1) / 320 -b -5 - -9 -12 321 = ok cl(gendfi,0) / 322 323 324 325 326 = cl(geniost, 7) (genfile) / 327 -52 -10 328 329 = <*filekwd> '=' cl(geniost, 8) / -b -26 -27 330 331 = ',' / -b -10 332 333 = cl(geniost, 9) / -83 334 335 $ run-time monitoring dictions 336 337 338 = set(fc,1) +chek / 339 = set(fc,2) +chek / 340 = 'index' <*name> (gentrace(pr(fc),8)) / 341 -31 - 342 = ok (gentrace(pr(fc),7)) / 343 344 345 = set(fc,yes) +trac / 346 347 = set(fc,no) +trac / 348 349 = <*name> (gentrace(pr(fc), pr(az)+1)) 350 / -90 - 351 352 = ok (gentrace(pr(fc),pr(az))) / 353 354 355 = 'flow' set(az,1) / - 356 = 'stores' set(az,3) / - 357 = 'entry' set(az,5) / -b 358 359 360 = cl(gensert,0) cl(gensert,1) / -25 361 362 363 = (gendebug(0,no)) (gendebug(0,yes)) 364 / -11 365 366 = ',' / -b -11 367 368 369 = 'limit' '=' (gendebug(1,yes)) 370 / - -75 -76 371 372 = <*dbugtok> (gendebug(dparm, dval)) 373 / -b 374 375 $ here to check for semicolon terminating 376 $ statement, and then go parse next statement. 377 = ';' +statme / -13 378 379 $ expression section. 380 381 382 $ the parsing of expressions is handled by using an operator 383 $ precedence type parsing scheme. the grammar for expresssions 384 $ is thus very simple except for the cases of one-token terms or 385 $ expressions added for effiency. 386 387 388 = <*exprtok1> <*exprtok2> xbeg 389 xfin 390 / - -namelp 391 = xbeg xfin / - 392 = xfin / 393 394 = set(tm,0) (goto checkcexp) / -b 395 = set(tm,1) (goto checkcexp) / -b 396 397 $ here after 'name(' begins expression. 398 = ')' cl(gencall,3) <*exprtok2> xbeg 399 xfin 400 / -96 -97 - 401 = (-keeptok = yes) / 402 = / - 403 = <*unop> genop(2) / 404 -b -15 405 406 = <*binop> genop(1) / -b -8 407 408 /* a term is an extractor, a constant, an expression enclosed in 409 parentheses, a name, or a name followed by a parenthesized 410 list of expressions. 411 */ 412 413 = <*termtok1> <*termtok2> +termlp +fexp +eexp +sexp +chexp 414 +pexp +termfs 415 / -b -b 416 417 $ here after 'filestat', to complete filestat term. 418 = '(' ',' <*statwd> ')' cl(geniost,10) 419 / -56 -54 -53 -55 -57 420 421 $ here after 'name (' term. 422 = ')' cl(gencall,3) 423 / -96 -97 424 425 426 = set(az,2) cl(genextr,26) / -b 427 = set(az,3) cl(genextr,37) / -b 428 = set(az,4) cl(genextr,38) / -b 429 = set(az,5) ',' cl(genextr,1) / -3 -2 -1 430 = ',' ',' / 431 -3 -2 -3 -2 -1 432 433 = ')' / -21 -22 434 435 $ error section. report error, skip just to next statement 436 $ and then try to parse statement. 437 438 = (ermet) +erskip / 439 440 = <*ertok> +erskip / -rest 441 442 end $ of the little grammar. 1 .=member pt10 2 universal synmac 3; universal file for assembling pt assembler text when 4; asm= option of syn used. 5; author d. shields (nyu-cims) 13-apr-79 6 define ptbeg 7< radix 10 8 title ptinit 9 twoseg 10 entry ptinit 11 reloc ^o 400000 12ptinit: popj 15, 13 reloc 0 14 intern nsptab 15nsptab: > 16 define ptval(val) 17< exp val> 18 define ptend 19< end> 1 .=member pt32 2 .macro ptbeg n 3 .psect ptinit,pic,usr,con,rel,lcl,shr,exe,rd,nowrt,quad 4 .entry ptinit,0 5 ret 6 .psect nsptab,pic,usr,ovr,rel,lcl,noshr,noexe,rd,wrt,quad 7x=. 8 .blkl n+1 9.=x+4 ; account for initial word in nameset 10 .endm 11 .macro ptval n 12 .long n 13 .endm 14 .macro ptend 15; 16 .endm 1 .=member pt37 2 macro 3 ptbeg &n 4ptinit csect 5 br 14 6nsptab csect 7 ds f 8 mend 9 macro 10 ptval &n 11 dc a(&n) 12 mend 13 macro 14 ptend 15.* 16 mend 1 .=member pt47 2 macro 3 ptbeg &n 4ptinit csect 5 br 14 6nsptab csect 7 ds f 8 mend 9 macro 10 ptval &n 11 dc a(&n) 12 mend 13 macro 14 ptend 15.* 16 mend 1 .=member pt66 2 ident syntext 3 syntext title syntext - systems txt for syn assembly text 4* systext file to assemble syn pt macros for s66 (cdc 6600) 5* author d. shields (nyu-cims) 13-apr-79 6 stext 7 ptbeg macro dim 8 entry ptinit 9 ptinit jp *+1s17 10 eq ptinit 11 use /nsptab/ 12 bss 2 dummy words for nameset origin 13 endm 14 ptval macro n 15 data n 16 endm 17 ptend macro 18 use * 19 endm 20 end