home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol166 / exprn.cnv < prev    next >
Encoding:
Text File  |  1984-04-29  |  3.9 KB  |  117 lines

  1.  
  2. [EXPRN.CNV]
  3. [CNVRT compiler for "C"  Expressions]
  4. [Harold V. McIntosh, 10 June 1983]
  5.  
  6.  
  7.  
  8. [compile expression]
  9. ((
  10.     ((or,(<)(<),(>)(>),-(>),(and,<[1]>,(nor,(<),(>))))) 0
  11.     ((or,(<)=,(>)=,(<),(>))<:W:>) 1
  12.   )(
  13.     ((z,<0>@@<1>)) Z
  14.     )(0 1 2) (
  15.  
  16.   [print WS]    ((PWS,x )<>,);
  17.   [assignment]    ((and,<:L:>,<0>)(and,<:p:>,<1>)(and,<:D:>,<2>),<<
  18.           >>(x,<2>)(x,<0>)/assignment <1>);
  19.   [binary ||]    (<0>(and,||<:H:><>,<1>),(Z));
  20.   [binary &&]    (<0>(and,&&<:J:><>,<1>),(Z));
  21.   [binary |]    (<0>(and,|<:Q:><>,<1>),(Z));
  22.   [binary ^]    (<0>(and,^<:S:><>,<1>),(Z));
  23.   [binary &]    (<0>(and,&<:U:><>,<1>),(Z));
  24.   [binary ==]    (<0>(and,(or,==,!=)<:V:><>,<1>),(Z));
  25.   [binary .lt.] ((and,<--><:0:>(and,<:1:><>,<1>),<0><1><>),(Z));
  26.   [binary rot]    (<0>(and,(or,(<)(<),(>)(>))<:X:><>,<1>),(Z));
  27.   [binary + -]    (<0>(and,(or,+,-)<:Y:><>,<1>),(Z));
  28.   [binary * / %](<0>(and,(or,*,/,%)<:A:><>,<1>),(Z));
  29.   [other]    (<0>,(y,<0>));
  30.   )) x
  31.  
  32. [compile unary expressions]
  33. (()()(0 1)(
  34.         ((PWS,y )<>,);
  35.   [autoinc]    (++(and,<:L:>,<0>),(x,<0>)/preinc);
  36.   [autoinc]    ((and,<:L:>,<0>)++,(x,<0>)/postinc);
  37.   [autodec]    (--(and,<:L:>,<0>),(x,<0>)/predec);
  38.   [autodec]    ((and,<:L:>,<0>)--,(x,<0>)/postdec);
  39.   [unary]    ((and,<:r:>,<0>)<1>,(y,<1>)/unary <0>);
  40.   [index]    (<0>(and,[<:E:>]<>,[<1>]<>),(x,<0>)(x,<1>)/index);
  41.   [subexpr]    ((and,<(><:E:><)>,<(><0><)><>),(x,<0>));
  42.   [function]    (<0>(and,<(><:E:><)><>,<(><1><)><>),(x,<1>)(x,<0>)/function);
  43.   [structure]    (<0>(and,-(>)<:I:><>,-(>)<1>),(x,<0>)/struct <1>);
  44.   [dot]        (<0>(and,.<:I:><>,.<1>),(x,<0>)/dot <1>);
  45.   [primary]    ((and,<:P:><>,<0>),/fetch <0>);
  46.   [unknown]    (<0>,/uy <0>);
  47.   )) y
  48.  
  49. [compile binary or coincident unary]
  50. (()()(0 1 2)(
  51.         ((PWS,z )<>,);
  52.   [pure unary]    (@@<1>,(y,<1>));
  53.         ((and,<:L:>,<0>)@@++<1>,(x,<(><0>++<)><1>));
  54.         ((and,<:L:>,<0>)@@--<1>,(x,<(><0>--<)><1>));
  55.         (<0>+@@+<1>,<0>@@++<1>):
  56.   [l rot]    (<0>(<)@@(<)<1>,<0>@@(<)(<)<1>):
  57.   [r rot]    (<0>(>)@@(>)<1>,<0>@@(>)(>)<1>):
  58.   [offside]    (<0>(and,<:r:>,<1>)@@<2>,<0>@@<1><2>):
  59.   [coincident]    (<0>@@(and,<:q:>,<1>)<2>,(x,<0>)(x,<2>)/binary <1>);
  60.   [unknown]    (<0>,/uz <0>);
  61.   )) z
  62.  
  63. [main program including syntactic elements]
  64. ( (
  65.   [alfanum]   ((and,<[1]>,(IVL, ,~,))) a
  66.   [letter]    ((and,<[1]>,(or,(IVL,A,Z,),(IVL,a,z,),_))) b
  67.   [odigit]    ((and,<[1]>,(IVL,0,7,))) c
  68.   [ddigit]    ((and,<[1]>,(IVL,0,9,))) d
  69.   [hdigit]    ((and,<[1]>,(or,(IVL,0,9,),(IVL,A,F,),(IVL,a,f,)))) e
  70.   [dstring]   ((ITR,<:d:>)) h
  71.   [cconst]    ((or,\<:a:>,<'><:a:><'>)) j
  72.   [iconst]    ((or,0(or,X,x)(ITR,<:e:>),0(ITR,<:c:>),<:d:><:h:>)) k
  73.   [fconst]    (<:h:>.<:h:>(or,(OR,E,e)(OR,+,-,)<:h:>,)) l
  74.   [sconst]    (<">(ITR,<:a:>)<">) m
  75.   [constant]  ((or,<:l:>,<:k:>,<:j:>,<:m:>)) o
  76.   [identifier](<:b:>(ITR,(or,<:b:>,<:d:>))) I
  77.   [aoperator] ((or,=,+=,-=,*=,/=,%=,(QUO/>>=/),(QUO/<<=/),&=,^=,|=)) p
  78.   [boperator] ((or,*,/,%,+,-,(QUO/>>/),(QUO/<</),(QUO/<=/),<<
  79.         >>(QUO/>=/),(<),(>),==,!=,&&,^,||,&,|)) q
  80.   [uoperator] ((or,*,&,-,!,~,sizeof,<(>typename<)>)) r
  81.   [lvalue]    ((or,<<
  82.         >>(and,<:P:>,<-->[<:E:>]<>),<<
  83.         >>(and,<:P:>,<-->-(>)<:I:><>),<<
  84.         >>(and,<:P:>,<-->.<:I:><>),<<
  85.         >><:I:>,<<
  86.         >>*<:A:>,<<
  87.         >><(><:L:><)>)) L
  88.   [pexten]    ((or,[<:E:>],<(>(ITR,<:E:>)<)>,-(>)<:I:>,.<:I:>)) N
  89.   [primary]   ((or,<:I:>,<:o:>,<(><:E:><)>)(ITR,<:N:>)) P
  90.   [eroot]     ((or,<<
  91.         >>++<:L:>,<<
  92.         >>--<:L:>,<<
  93.         >><:L:>++,<<
  94.         >><:L:>--,<<
  95.         >><:r:><:A:>,<<
  96.         >><:P:>)) A
  97.   [bnryexpr]  (<:A:>(ITR,<:q:><:A:>)) B
  98.   [cndlexpr]  (<:B:>(or,?<:K:>:<:K:>,)) K
  99.   [asgnexpr]  ((or,<:L:><:p:><:D:>,<:K:>)) D
  100.   [expression](<:D:>(ITR,<,><:D:>)) E
  101.   [||expr]    (<:H:>(ITR,||<:H:>)) G
  102.   [&&expr]    (<:J:>(ITR,&&<:J:>)) H
  103.   [|expr]     (<:Q:>(ITR,|<:Q:>)) J
  104.   [^expr]     (<:S:>(ITR,^<:S:>)) Q
  105.   [&expr]     (<:U:>(ITR,&<:U:>)) S
  106.   [== !=]     (<:V:>(ITR,(or,==,!=)<:V:>)) U
  107.   [comparison](<:W:>(ITR,(or,(<)=,(>)=,(<),(>))<:W:>)) V
  108.   [rotate]    (<:X:>(ITR,(or,(<)(<),(>)(>))<:X:>)) W
  109.   [+ -]       (<:Y:>(ITR,(or,+,-)<:Y:>)) X
  110.   [* / %]     (<:A:>(ITR,(or,*,/,%)<:A:>)) Y
  111.   )  ()(0)(  
  112.     (;,done);
  113.     (<0>,(%C,(x,<0>))(%R)):
  114.   ))
  115.  
  116. [end]
  117.