home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / APPS / TEKST / SPIDER / C / C.SPI next >
Encoding:
Text File  |  1990-02-19  |  11.2 KB  |  351 lines

  1. # Copyright 1989 by Norman Ramsey, Odyssey Research Associates
  2. # To be used for research purposes only
  3. # For more information, see file COPYRIGHT in the parent directory
  4. language C extension c
  5.  
  6. at_sign @
  7.  
  8. comment begin <"/*"> end <"*/">
  9.  
  10. default translation <*> mathness yes
  11.  
  12. token identifier category simp mathness yes
  13. token number category math mathness yes
  14. token newline category newline mathness maybe translation <>
  15. token pseudo_semi category semi mathness maybe translation <"\\relax">
  16.  
  17. module definition stmt use math
  18.  
  19. token + category unorbinop
  20. token - category unorbinop
  21. token * category unorbinop translation <"{*}"> tangleto <space-"*">
  22. #                    avoid inadvertant /*
  23. token / category dot
  24. token < category less translation <>
  25. token > category greater translation <>
  26. token = category equals translation <"\\leftarrow"> tangleto <"="-space>
  27. #                    avoid inadvertant =-
  28. token . category dot
  29. token ~ category unop translation <"\\TI">
  30. token & category unorbinop translation <"\\amp">
  31. token ^ translation <"\\^"> category binop
  32. token | category binop
  33. token ? translation <"\\?"> category question
  34. token % translation <"\\%"> category binop
  35. token # translation <"\\#"> category sharp
  36. token ! category unop translation <"\\neg">
  37. token \ category backslash translation <"\\backslash">
  38. token ( category open
  39. token ) category close
  40. token [ category open
  41. token ] category close
  42. token { translation <"\\{"-indent> category lbrace
  43. token } translation <"\\}"> category rbrace
  44. token , category comma translation <",\\;">
  45. token ; category semi
  46. token : category colon
  47. token ++ category unop translation <"\\PP">
  48. token -- category unop translation <"\\MM">
  49. token != translation <"\\I"> category binop
  50. token <= translation <"\\L"> category binop
  51. token >= translation <"\\G"> category binop
  52. token == translation <"\\S"> category binop
  53. token && translation <"\\W"> category binop
  54. token || translation <"\\V"> category binop
  55. token -> translation <"\\MG"> category binop
  56. token >> translation <"\\GG"> category binop
  57. token << translation <"\\LL"> category binop
  58.  
  59. macros begin
  60. \def\CC{\mathrel{:{:}}}
  61. \def\CCE{\mathrel{:{:}=}}
  62. \def\FE{\mathrel{/=}}
  63. \def\PP{\mathord{++}}
  64. \def\PE{\mathrel{+=}}
  65. \def\MM{\mathord{--}}
  66. \def\ME{\mathrel{-=}}
  67. \def\MG{\mathrel{\to}}
  68. \def\GG{\mathrel{>\!>}}
  69. \def\LL{\mathrel{<\!<}}
  70. \def\TE{\mathrel{\ast=}}
  71. \def\CE{\mathrel{\%=}}
  72. \def\HE{\mathrel{\uparrow=}}
  73. \def\AE{\mathrel{\amp=}}
  74. \def\OE{\mathrel{|=}}
  75. \let\openbraces=\{
  76. \let\closebraces=\}
  77. \def\{{\ifmmode\openbraces\else$\openbraces$\fi}
  78. \def\}{\ifmmode\closebraces\else$\closebraces$\fi}
  79. \def\?{\mathrel?}
  80. \def\s{\ }
  81. macros end
  82.  
  83. default translation <*-"\\"-space>
  84.  
  85. ilk case_like category case
  86. ilk int_like category decl_head translation <*>
  87. ilk else_like category else
  88. ilk enum_like category enum
  89. ilk if_like category if
  90. ilk for_like category for
  91. ilk do_like category do
  92. ilk sizeof_like category sizeof
  93. ilk struct_like category struct
  94. ilk switch_like category switch
  95. ilk typedef_like category typedef
  96.  
  97. default translation <*>
  98.  
  99. reserved auto ilk int_like
  100. reserved break ilk case_like
  101. reserved case ilk case_like
  102. reserved char ilk int_like
  103. reserved continue ilk case_like
  104. reserved default ilk case_like
  105. reserved do ilk do_like
  106. reserved double ilk int_like
  107. reserved else ilk else_like
  108. reserved enum ilk enum_like
  109. reserved extern ilk int_like
  110. reserved float ilk int_like
  111. reserved for ilk for_like
  112. reserved goto ilk case_like
  113. reserved if ilk if_like
  114. reserved int ilk int_like
  115. reserved long ilk int_like
  116. reserved register ilk int_like
  117. reserved return ilk case_like
  118. reserved short ilk int_like
  119. reserved sizeof ilk sizeof_like
  120. reserved static ilk int_like
  121. reserved struct ilk struct_like
  122. reserved switch ilk switch_like
  123. reserved typedef ilk typedef_like
  124. reserved union ilk struct_like
  125. reserved unsigned ilk int_like
  126. reserved void ilk int_like
  127. reserved while ilk for_like
  128.  
  129. # we indulge in a trick to avoid treating
  130. #    ASCII (*fp)(); 
  131. # as a statement (function call). We use instead
  132. #    ASCII ===> (*fp)();
  133. token ===> translation <"\\relax"> tangleto <space> category decl_head
  134.  
  135.  
  136. ? ignore_scrap --> #1
  137. #  dropped, because we've overflowed yacc!     
  138. #### DON'T DO THIS!  it makes it impossible to add translation on the left
  139. #### ignore_scrap ? --> #2
  140.  
  141.  
  142. # because of declarations, we have to be very careful about converting
  143. # simp to math
  144.  
  145. (math|simp) unop --> math
  146. math (binop|unorbinop) (math|simp) --> math
  147. math comma <opt-9> (math|simp) --> math
  148. # we're not allowed math simp --> statement because math simp could be fn_decl
  149. math math --> math
  150. (math|simp) semi --> stmt
  151. # so to hack the omission above, we include (usually a cast)
  152. math <"\\"-space> stmt --> stmt
  153.  
  154. (open|simpopen|question|unop|unorbinop|case) [ simp ] --> (open|simpopen|question|unop|unorbinop|case) math
  155. [ simp ] binop --> math binop
  156. # old: 
  157. # [ simp ] equals --> math equals
  158. # math [ equals ] --> math binop
  159.  
  160. simp* colon --> tag
  161.  
  162. # can't have simp open --> open because that causes ( to eat all id's to its left.
  163. simp open --> simpopen
  164.  
  165. (open|simpopen) math close --> math
  166. (open|simpopen) <"\\,"> close --> math
  167. # following needed for for statements
  168. open stmt <"\\"-space> --> open
  169.  
  170. # here we try to deal with casts and argument lists, e.g.
  171. #    (ASCII *) malloc(sizeof (ASCII *));
  172. #    char *malloc(int);
  173.  
  174. # If the type is predefined, we know we have a cast
  175. (open|simpopen) decl_head close --> cast
  176. (open|simpopen) [ decl_head (unorbinop|math|simp) ] --> (open|simpopen) decl_head
  177. (open|simpopen) decl_head comma --> arglist
  178. arglist (decl_head|unorbinop|math) --> arglist
  179. arglist close --> math
  180.  
  181. # and here are some common cases of casts with non-predefined types
  182. # for other cases you'll have to use "declares"
  183. (open|simpopen) math <"\\"-space> unorbinop comma --> arglist
  184. (open|simpopen) math <"\\"-space> unorbinop unorbinop comma --> arglist
  185. (open|simpopen) math <"\\"-space> unorbinop unorbinop unorbinop comma --> arglist
  186. (open|simpopen) math <"\\"-space> unorbinop close --> cast
  187. (open|simpopen) math <"\\"-space> unorbinop unorbinop close --> cast
  188. (open|simpopen) math <"\\"-space> unorbinop unorbinop unorbinop close --> cast
  189.  
  190. # the math here seems to be a cast.  We don't convert to cast because it looks
  191. # too much like a cycle
  192. (open|simpopen) [ math <"\\"-space> simp ] --> (open|simpopen) math
  193.  
  194. # Here is the destiny of casts
  195. cast <"\\"-space> (math|simp) --> math
  196. cast (newline|ignore_scrap) --> cast
  197. cast --> math
  198.  
  199.  
  200.  
  201. question math colon --> binop
  202.  
  203. unop math --> math
  204. <"{"> unorbinop <"}"> math --> math
  205. <"\\buildrel"> (binop|unorbinop) <"\\over{"> equals <"}"> --> binop
  206. equals --> binop
  207. sizeof (math|simp) --> math
  208.  
  209. (simp|decl_head) <"\\"-space> decl_head --> decl_head
  210. [ simp ] math (equals|comma|semi) --> decl_head math (equals|comma|semi)
  211. [ (decl_head|simp) simp ] (simp|math) --> decl_head (simp|math)
  212. (simp|decl_head) <"\\"-space> (simp|math)* comma --> decl_head
  213. (simp|decl_head) <"\\"-space> (simp|math)* semi --> decl
  214. (simp|decl_head) <"\\"-space> (simp|math)* equals --> decl_equals
  215. decl_equals math comma --> decl_head
  216. decl_equals math semi --> decl
  217. decl_equals [ simp ] --> decl_equals math
  218.  
  219. struct simp* <"\\"-space> lbrace --> structbrace
  220. struct lbrace --> structbrace
  221. structbrace [ simp ] --> structbrace decl_head
  222. structbrace <force> decl --> structbrace
  223. structbrace <outdent-force> rbrace --> struct_head
  224. [ struct_head ] simp --> decl_head simp
  225. # some people say e.g. struct blah {...};    is this K&R?
  226. struct_head semi --> decl
  227. struct [ simp (newline|ignore_scrap) ] --> struct simp
  228. struct simp --> decl_head
  229. decl_head <"\\"-space> struct --> struct
  230.  
  231. # enumeration types are like structures and unions, but they have math
  232. # instead of many decls...
  233. enum simp* <"\\"-space> lbrace --> enumbrace
  234. enum lbrace  --> enumbrace
  235. enumbrace math rbrace <outdent> --> enum_head
  236. [ enum_head ] simp --> decl_head simp
  237. enum_head semi --> decl
  238. enum [ simp (newline|ignore_scrap) ] --> enum simp
  239. enum simp --> decl_head
  240. decl_head <"\\"-space> enum --> enum
  241.  
  242. typedef [ simp ] --> typedef decl_head
  243. typedef decl --> decl
  244.  
  245.  
  246.  
  247.  
  248. [ math* <indent> ] (lbrace|decl_head|decl) --> fn_decl (lbrace|decl_head|decl)
  249. [ (simp|decl_head) <"\\"-space> math* <indent> ] (lbrace|decl_head|decl) --> fn_decl (lbrace|decl_head|decl)
  250. fn_decl <force> decl --> fn_decl
  251. # The following statment will always have braces and never be tagged
  252. fn_decl <outdent-force> stmt --> function
  253. # include stmt here to cover module definition
  254. (stmt|decl|function) <big_force> function --> function
  255. function <big_force> decl --> decl
  256.  
  257. (stmt|decl) <force> decl --> decl
  258. decl <big_force> stmt --> stmt
  259. decl <outdent-big_force> tagged_stmt --> stmt
  260.  
  261.  
  262. lbrace <outdent-force> rbrace --> stmt
  263. lbrace <force> stmt --> lbrace
  264. lbrace <outdent-force> tagged_stmt --> lbrace
  265. lbrace (math|simp) <outdent> rbrace --> math
  266.  
  267. # if math can be followed by a brace, or no.
  268. # ifmath and ifbrace can have an attached else or else if clause
  269. # else, for, and while are formatted like if, but can't have an
  270. # attached else clause, so we use formath and forbrace
  271.  
  272. if math --> ifmath
  273. ifmath <"\\"-space> lbrace --> ifbrace
  274. ifbrace <force> stmt --> ifbrace
  275. ifbrace <outdent-force> tagged_stmt --> ifbrace
  276. ifbrace [ rbrace (newline|ignore_scrap) ] --> ifbrace rbrace
  277. ifbrace rbrace [ else (newline|ignore_scrap) ] --> ifbrace rbrace else
  278. ifbrace <outdent-force> rbrace <"\\"-space> else if --> if
  279. ifbrace <outdent-force> rbrace <"\\"-space> else lbrace --> forbrace
  280. ifbrace <outdent-force> rbrace <"\\"-space> else --> formath
  281. ifbrace <outdent-force> rbrace --> stmt
  282.  
  283. # Assume simple statements attached to if will never be tagged
  284.  
  285. ifmath [ stmt (newline|ignore_scrap) ] --> ifmath stmt
  286. ifmath stmt [ else (newline|ignore_scrap) ] --> ifmath stmt else
  287. ifmath <indent-force> stmt <outdent-force> else if --> if
  288. ifmath <indent-force> stmt <outdent-force> else lbrace --> forbrace
  289. ifmath <indent-force> stmt <outdent-force> else --> formath
  290. ifmath <indent-force> stmt <outdent> --> stmt
  291.  
  292. for math --> formath
  293. formath <"\\"-space> lbrace --> forbrace
  294. forbrace <force> stmt --> forbrace
  295. forbrace <outdent-force> tagged_stmt --> forbrace
  296. forbrace <outdent-force> rbrace --> stmt
  297. formath <indent-force> stmt <outdent> --> stmt
  298.  
  299. # we need an extra indent for switch, becuase the cases will be backed out
  300. switch math lbrace <indent> --> switchbrace
  301. switchbrace <outdent-force> tagged_stmt --> switchbrace
  302. # This next should never happen
  303. switchbrace <force> stmt --> switchbrace
  304. switchbrace <outdent-outdent-force> rbrace --> stmt
  305.  
  306.  
  307.  
  308. # handle do-while (while has category for)
  309. do lbrace --> dobrace
  310. dobrace <force> stmt --> dobrace
  311. dobrace <outdent-force> tagged_stmt --> dobrace
  312. dobrace <outdent-force> rbrace <"\\"-space> for --> math
  313. do <indent-force> stmt <outdent-force> for --> math
  314.  
  315. case semi --> stmt
  316. case math semi --> stmt
  317. case colon --> tag
  318. case math colon --> tag
  319. tag <force> tag --> tag
  320. tag <indent-force> stmt --> tagged_stmt
  321.  
  322. stmt <force> stmt --> stmt
  323. stmt <outdent-force> tagged_stmt --> stmt
  324. semi --> stmt
  325.  
  326. # control sequence \8 puts things on the left margin
  327. <force-"\\8"> sharp <"{\\let\\\\=\\bf"-space> (simp|if|else) <"}"-indent-"{}"-space> --> preproc
  328. preproc backslash <force-"\\8\\hskip1em"-space> newline --> preproc
  329. preproc <force-outdent> newline --> ignore_scrap
  330. preproc !(less|lesssimp|backslash|newline) --> preproc
  331. newline --> ignore_scrap
  332.  
  333. less simp --> lesssimp
  334. lesssimp dot simp --> lesssimp
  335. <"\\LN"> lesssimp greater <"\\RN"> --> math
  336. <"<"> lesssimp --> unop
  337. less <"<"> --> binop
  338. greater <">"> --> binop
  339. dot --> binop
  340.  
  341. macros begin
  342. \let\LN\langle
  343. \let\RN\rangle
  344. macros end
  345.  
  346.  
  347.  
  348.  
  349.  
  350.