home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v92.tgz / v92.tar / v92 / src / iconc / cgrammar.c < prev    next >
C/C++ Source or Header  |  1996-03-22  |  9KB  |  222 lines

  1. /*
  2.  * cgrammar.c - includes and macros for building the parse tree.
  3.  */
  4. #include "::h:define.h"
  5. #include "::common:yacctok.h"
  6.  
  7. %{
  8. /*
  9.  * These commented directives are passed through the first application
  10.  * of cpp, then turned into real directives in cgram.g by fixgram.icn.
  11.  */
  12. /*#include "::h/gsupport.h"*:
  13. /*#include "::h/lexdef.h"*:
  14. /*#include "ctrans.h"*/
  15. /*#include "csym.h"*/
  16. /*#include "ctree.h"*/
  17. /*#include "ccode.h" */
  18. /*#include "cproto.h"*/
  19. /*#undef YYSTYPE*/
  20. /*#define YYSTYPE nodeptr*/
  21. /*#define YYMAXDEPTH 500*/
  22.  
  23. int idflag;
  24.  
  25. #define EmptyNode tree1(N_Empty) 
  26.  
  27. #define Alt(x1,x2,x3)        $$ = tree4(N_Alt,x2,x1,x3) 
  28. #define Apply(x1,x2,x3)        $$ = tree4(N_Apply,x2,x1,x3) 
  29. #define Arglist1()        /* empty */
  30. #define Arglist2(x)        /* empty */
  31. #define Arglist3(x1,x2,x3)    proc_lst->nargs = -proc_lst->nargs
  32. #define Bact(x1,x2,x3)        $$ = tree5(N_Activat,x2,x2,x1,x3) 
  33. #define Bamper(x1,x2,x3)    $$ = binary_nd(x2,x1,x3) 
  34. #define Bassgn(x1,x2,x3)    $$ = binary_nd(x2,x1,x3) 
  35. #define Baugact(x1,x2,x3)    $$ = tree5(N_Activat,x2,x2,x1,x3) 
  36. #define Baugamper(x1,x2,x3)    $$ = aug_nd(x2,x1,x3) 
  37. #define Baugcat(x1,x2,x3)    $$ = aug_nd(x2,x1,x3)
  38. #define Baugeq(x1,x2,x3)    $$ = aug_nd(x2,x1,x3)
  39. #define Baugeqv(x1,x2,x3)    $$ = aug_nd(x2,x1,x3)
  40. #define Baugge(x1,x2,x3)    $$ = aug_nd(x2,x1,x3)
  41. #define Bauggt(x1,x2,x3)    $$ = aug_nd(x2,x1,x3)
  42. #define Bauglcat(x1,x2,x3)    $$ = aug_nd(x2,x1,x3)
  43. #define Baugle(x1,x2,x3)    $$ = aug_nd(x2,x1,x3)
  44. #define Bauglt(x1,x2,x3)    $$ = aug_nd(x2,x1,x3)
  45. #define Baugne(x1,x2,x3)    $$ = aug_nd(x2,x1,x3)
  46. #define Baugneqv(x1,x2,x3)    $$ = aug_nd(x2,x1,x3)
  47. #define Baugques(x1,x2,x3)    $$ = tree5(N_Scan,x2,x2,x1,x3) 
  48. #define Baugseq(x1,x2,x3)    $$ = aug_nd(x2,x1,x3)
  49. #define Baugsge(x1,x2,x3)    $$ = aug_nd(x2,x1,x3)
  50. #define Baugsgt(x1,x2,x3)    $$ = aug_nd(x2,x1,x3)
  51. #define Baugsle(x1,x2,x3)    $$ = aug_nd(x2,x1,x3)
  52. #define Baugslt(x1,x2,x3)    $$ = aug_nd(x2,x1,x3)
  53. #define Baugsne(x1,x2,x3)    $$ = aug_nd(x2,x1,x3)
  54. #define Bcaret(x1,x2,x3)    $$ = binary_nd(x2,x1,x3) 
  55. #define Bcareta(x1,x2,x3)    $$ = aug_nd(x2,x1,x3)
  56. #define Bcat(x1,x2,x3)        $$ = binary_nd(x2,x1,x3) 
  57. #define Bdiff(x1,x2,x3)        $$ = binary_nd(x2,x1,x3) 
  58. #define Bdiffa(x1,x2,x3)    $$ = aug_nd(x2,x1,x3)
  59. #define Beq(x1,x2,x3)        $$ = binary_nd(x2,x1,x3)
  60. #define Beqv(x1,x2,x3)        $$ = binary_nd(x2,x1,x3)
  61. #define Bge(x1,x2,x3)        $$ = binary_nd(x2,x1,x3)
  62. #define Bgt(x1,x2,x3)        $$ = binary_nd(x2,x1,x3)
  63. #define Binter(x1,x2,x3)    $$ = binary_nd(x2,x1,x3)
  64. #define Bintera(x1,x2,x3)    $$ = aug_nd(x2,x1,x3)
  65. #define Blcat(x1,x2,x3)        $$ = binary_nd(x2,x1,x3)
  66. #define Ble(x1,x2,x3)        $$ = binary_nd(x2,x1,x3)
  67. #define Blim(x1,x2,x3)        $$ = tree4(N_Limit,x2,x1,x3) 
  68. #define Blt(x1,x2,x3)        $$ = binary_nd(x2,x1,x3)
  69. #define Bminus(x1,x2,x3)    $$ = binary_nd(x2,x1,x3)
  70. #define Bminusa(x1,x2,x3)    $$ = aug_nd(x2,x1,x3)
  71. #define Bmod(x1,x2,x3)        $$ = binary_nd(x2,x1,x3)
  72. #define Bmoda(x1,x2,x3)        $$ = aug_nd(x2,x1,x3)
  73. #define Bne(x1,x2,x3)        $$ = binary_nd(x2,x1,x3)
  74. #define Bneqv(x1,x2,x3)        $$ = binary_nd(x2,x1,x3)
  75. #define Bplus(x1,x2,x3)        $$ = binary_nd(x2,x1,x3)
  76. #define Bplusa(x1,x2,x3)    $$ = aug_nd(x2,x1,x3)
  77. #define Bques(x1,x2,x3)        $$ = tree5(N_Scan,x2,x2,x1,x3) 
  78. #define Brace(x1,x2,x3)        $$ = x2
  79. #define Brack(x1,x2,x3)        $$ = list_nd(x1,x2) 
  80. #define Brassgn(x1,x2,x3)    $$ = binary_nd(x2,x1,x3)
  81. #define Break(x1,x2)        $$ = tree3(N_Break,x1,x2) 
  82. #define Brswap(x1,x2,x3)    $$ = binary_nd(x2,x1,x3)
  83. #define Bseq(x1,x2,x3)        $$ = binary_nd(x2,x1,x3)
  84. #define Bsge(x1,x2,x3)        $$ = binary_nd(x2,x1,x3)
  85. #define Bsgt(x1,x2,x3)        $$ = binary_nd(x2,x1,x3)
  86. #define Bslash(x1,x2,x3)    $$ = binary_nd(x2,x1,x3)
  87. #define Bslasha(x1,x2,x3)    $$ = aug_nd(x2,x1,x3)
  88. #define Bsle(x1,x2,x3)        $$ = binary_nd(x2,x1,x3)
  89. #define Bslt(x1,x2,x3)        $$ = binary_nd(x2,x1,x3)
  90. #define Bsne(x1,x2,x3)        $$ = binary_nd(x2,x1,x3)
  91. #define Bstar(x1,x2,x3)        $$ = binary_nd(x2,x1,x3)
  92. #define Bstara(x1,x2,x3)    $$ = aug_nd(x2,x1,x3)
  93. #define Bswap(x1,x2,x3)        $$ = binary_nd(x2,x1,x3)
  94. #define Bunion(x1,x2,x3)    $$ = binary_nd(x2,x1,x3)
  95. #define Buniona(x1,x2,x3)    $$ = aug_nd(x2,x1,x3)
  96. #define Case(x1,x2,x3,x4,x5,x6) $$ = case_nd(x1,x2,x5) 
  97. #define Caselist(x1,x2,x3)    $$ = tree4(N_Clist,x2,x1,x3) 
  98. #define Cclause0(x1,x2,x3)    $$ = tree4(N_Ccls,x2,x1,x3) 
  99. #define Cclause1(x1,x2,x3)    $$ = tree4(N_Ccls,x2,x1,x3) 
  100. #define Cliter(x)        CSym0(x) = putlit(Str0(x),F_CsetLit,(int)Val1(x))
  101. #define Colon(x)        $$ = x
  102. #define Compound(x1,x2,x3)    $$ = tree4(N_Slist,x2,x1,x3) 
  103. #define Create(x1,x2)        $$ = tree3(N_Create,x1,x2);\
  104.                  proc_lst->has_coexpr = 1;
  105. #define Elst0(x)                $$ = x;
  106. #define Elst1(x1,x2,x3)            $$ = tree4(N_Elist,x2,x1,x3);
  107. #define Every0(x1,x2)        $$ = tree5(N_Loop,x1,x1,x2,EmptyNode) 
  108. #define Every1(x1,x2,x3,x4)    $$ = tree5(N_Loop,x1,x1,x2,x4) 
  109. #define Fail(x)            $$ = tree4(N_Ret,x,x,EmptyNode) 
  110. #define Field(x1,x2,x3)        $$ = tree4(N_Field,x2,x1,x3) 
  111. #define Global0(x)        idflag = F_Global
  112. #define Global1(x1,x2,x3)    /* empty */
  113. #define Globdcl(x)        /* empty */
  114. #define Ident(x)        install(Str0(x),idflag)
  115. #define Idlist(x1,x2,x3)    install(Str0(x3),idflag)
  116. #define If0(x1,x2,x3,x4)    $$ = tree5(N_If,x1,x2,x4,EmptyNode) 
  117. #define If1(x1,x2,x3,x4,x5,x6)    $$ = tree5(N_If,x1,x2,x4,x6) 
  118. #define Iliter(x)        CSym0(x) = putlit(Str0(x),F_IntLit,0)
  119. #define Initial1()        $$ = EmptyNode
  120. #define Initial2(x1,x2,x3)    $$ = x2
  121. #define Invocdcl(x)             /* empty */
  122. #define Invocable(x1,x2)        /* empty */
  123. #define Invoclist(x1,x2, x3)    /* empty */
  124. #define Invocop1(x)             invoc_grp(Str0(x));
  125. #define Invocop2(x)             invocbl(x, -1);
  126. #define Invocop3(x1,x2,x3)      invocbl(x1, atoi(Str0(x3)));
  127. #define Invoke(x1,x2,x3,x4)    $$ = invk_nd(x2,x1,x3)
  128. #define Keyword(x1,x2)        $$ = key_leaf(x1,Str0(x2))
  129. #define Kfail(x1,x2)        $$ = key_leaf(x1,spec_str("fail")) 
  130. #define Link(x1,x2)        /* empty */
  131. #define Linkdcl(x)        /* empty */
  132. #define Lnkfile1(x)        lnkdcl(Str0(x));
  133. #define Lnkfile2(x)        lnkdcl(Str0(x));
  134. #define Lnklist(x1,x2,x3)    /* empty */
  135. #define Local(x)        idflag = F_Dynamic
  136. #define Locals1()        /* empty */
  137. #define Locals2(x1,x2,x3,x4)    /* empty */
  138. #define Mcolon(x)        $$ = x
  139. #define Nexpr()            $$ = EmptyNode
  140. #define Next(x)            $$ = tree2(N_Next,x) 
  141. #define Paren(x1,x2,x3)        if ((x2)->n_type == N_Elist)\
  142.                                    $$ = invk_nd(x1,EmptyNode,x2);\
  143.                  else\
  144.                     $$ = x2
  145. #define Pcolon(x)        $$ = x
  146. #define Pdco0(x1,x2,x3)        $$ = invk_nd(x2,x1,list_nd(x2,EmptyNode))
  147. #define Pdco1(x1,x2,x3,x4)    $$ = invk_nd(x2,x1,list_nd(x2,x3)) 
  148. #define Pdcolist0(x)        $$ = tree3(N_Create,x,x);\
  149.                  proc_lst->has_coexpr = 1;
  150. #define Pdcolist1(x1,x2,x3)    $$ =tree4(N_Elist,x2,x1,tree3(N_Create,x2,x3));\
  151.                  proc_lst->has_coexpr = 1;
  152. #define Proc1(x1,x2,x3,x4,x5,x6) $$ = tree6(N_Proc,x1,x1,x4,x5,x6)
  153. #define Procbody1()        $$ = EmptyNode
  154. #define Procbody2(x1,x2,x3)    $$ = tree4(N_Slist,x2,x1,x3) 
  155. #define Procdcl(x)        proc_lst->tree = x
  156. #define Prochead1(x1,x2)    init_proc(Str0(x2));\
  157.                 idflag = F_Argument
  158. #define Prochead2(x1,x2,x3,x4,x5,x6) /* empty */
  159. #define Progend(x1,x2)        /* empty */
  160. #define Recdcl(x)        /* empty */
  161. #define Record1(x1, x2)        init_rec(Str0(x2));\
  162.                                 idflag = F_Field
  163. #define Record2(x1,x2,x3,x4,x5,x6) /* empty */
  164. #define Repeat(x1,x2)        $$ = tree5(N_Loop,x1,x1,x2,EmptyNode) 
  165. #define Return(x1,x2)        $$ = tree4(N_Ret,x1,x1,x2) 
  166. #define Rliter(x)        CSym0(x) = putlit(Str0(x),F_RealLit,0)
  167. #define Section(x1,x2,x3,x4,x5,x6) $$ = sect_nd(x4,x1,x3,x5) 
  168. #define Sliter(x)        CSym0(x) = putlit(Str0(x),F_StrLit,(int)Val1(x))
  169. #define Static(x)        idflag = F_Static
  170. #define Subscript(x1,x2,x3,x4)    $$ = buildarray(x1,x2,x3)
  171. #define Suspend0(x1,x2)        $$ = tree5(N_Loop,x1,x1,x2,EmptyNode) 
  172. #define Suspend1(x1,x2,x3,x4)    $$ = tree5(N_Loop,x1,x1,x2,x4) 
  173. #define To0(x1,x2,x3)        $$ = to_nd(x2,x1,x3) 
  174. #define To1(x1,x2,x3,x4,x5)    $$ = toby_nd(x2,x1,x3,x5) 
  175. #define Uat(x1,x2)        $$ = tree5(N_Activat,x1,x1,EmptyNode,x2) 
  176. #define Ubackslash(x1,x2)    $$ = unary_nd(x1,x2)
  177. #define Ubang(x1,x2)        $$ = unary_nd(x1,x2)
  178. #define Ubar(x1,x2)        $$ = tree3(N_Bar,x2,x2) 
  179. #define Ucaret(x1,x2)        $$ = unary_nd(x1,x2)
  180. #define Uconcat(x1,x2)        $$ = tree3(N_Bar,x2,x2) 
  181. #define Udiff(x1,x2)        $$ = MultiUnary(x1,x2)
  182. #define Udot(x1,x2)        $$ = unary_nd(x1,x2)
  183. #define Uequiv(x1,x2)        $$ = MultiUnary(x1,x2)
  184. #define Uinter(x1,x2)        $$ = MultiUnary(x1,x2)
  185. #define Ulconcat(x1,x2)        $$ = tree3(N_Bar,x2,x2) 
  186. #define Ulexeq(x1,x2)        $$ = MultiUnary(x1,x2)
  187. #define Ulexne(x1,x2)        $$ = MultiUnary(x1,x2)
  188. #define Uminus(x1,x2)        $$ = unary_nd(x1,x2)
  189. #define Unot(x1,x2)        $$ = tree3(N_Not,x2,x2) 
  190. #define Unotequiv(x1,x2)    $$ = MultiUnary(x1,x2)
  191. #define Until0(x1,x2)        $$ = tree5(N_Loop,x1,x1,x2,EmptyNode) 
  192. #define Until1(x1,x2,x3,x4)    $$ = tree5(N_Loop,x1,x1,x2,x4) 
  193. #define Unumeq(x1,x2)        $$ = unary_nd(x1,x2)
  194. #define Unumne(x1,x2)        $$ = MultiUnary(x1,x2)
  195. #define Uplus(x1,x2)        $$ = unary_nd(x1,x2)
  196. #define Uqmark(x1,x2)        $$ = unary_nd(x1,x2)
  197. #define Uslash(x1,x2)        $$ = unary_nd(x1,x2)
  198. #define Ustar(x1,x2)        $$ = unary_nd(x1,x2)
  199. #define Utilde(x1,x2)        $$ = unary_nd(x1,x2)
  200. #define Uunion(x1,x2)        $$ = MultiUnary(x1,x2)
  201. #define Var(x)            LSym0(x) = putloc(Str0(x),0)
  202. #define While0(x1,x2)        $$ = tree5(N_Loop,x1,x1,x2,EmptyNode)
  203. #define While1(x1,x2,x3,x4)    $$ = tree5(N_Loop,x1,x1,x2,x4) 
  204. %}
  205.  
  206. %%
  207. #include "::h:grammar.h"
  208. %%
  209.  
  210. /*
  211.  * xfree(p) -- used with free(p) macro to avoid compiler errors from
  212.  *  miscast free calls generated by Yacc.
  213.  */
  214. #undef free
  215. static novalue xfree(p)
  216. char *p;
  217. {
  218.    free(p);
  219. }
  220.  
  221. /*#define free(p) xfree((char*)p)*/
  222.