home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume27 / jam / part05 < prev    next >
Encoding:
Text File  |  1993-11-15  |  15.5 KB  |  641 lines

  1. Newsgroups: comp.sources.unix
  2. From: seiwald@vix.com (Christopher Seiwald)
  3. Subject: v27i085: jam - just another make, Part05/05
  4. References: <1.753385306.22859@gw.home.vix.com>
  5. Sender: unix-sources-moderator@gw.home.vix.com
  6. Approved: vixie@gw.home.vix.com
  7.  
  8. Submitted-By: seiwald@vix.com (Christopher Seiwald)
  9. Posting-Number: Volume 27, Issue 85
  10. Archive-Name: jam/part05
  11.  
  12. Submitted-by: seiwald@vix.com
  13. Archive-name: jam - make(1) redux/part05
  14.  
  15. #!/bin/sh
  16. # This is part 05 of jam - make(1) redux
  17. # ============= jamgram.h ==============
  18. if test -f 'jamgram.h' -a X"$1" != X"-c"; then
  19.     echo 'x - skipping jamgram.h (File already exists)'
  20. else
  21. echo 'x - extracting jamgram.h (Text)'
  22. sed 's/^X//' << 'SHAR_EOF' > 'jamgram.h' &&
  23. X# define _BANG 257
  24. X# define _BANG_EQUALS 258
  25. X# define _AMPERAMPER 259
  26. X# define _LPAREN 260
  27. X# define _RPAREN 261
  28. X# define _COLON 262
  29. X# define _SEMIC 263
  30. X# define _LANGLE 264
  31. X# define _LANGLE_EQUALS 265
  32. X# define _EQUALS 266
  33. X# define _RANGLE 267
  34. X# define _RANGLE_EQUALS 268
  35. X# define ACTIONS 269
  36. X# define CASE 270
  37. X# define DEFAULT 271
  38. X# define ELSE 272
  39. X# define FOR 273
  40. X# define IF 274
  41. X# define IGNORE 275
  42. X# define IN 276
  43. X# define INCLUDE 277
  44. X# define ON 278
  45. X# define PIECEMEAL 279
  46. X# define QUIETLY 280
  47. X# define RULE 281
  48. X# define SWITCH 282
  49. X# define TOGETHER 283
  50. X# define UPDATED 284
  51. X# define _LBRACE 285
  52. X# define _BARBAR 286
  53. X# define _RBRACE 287
  54. X# define ARG 288
  55. X# define STRING 289
  56. SHAR_EOF
  57. chmod 0444 jamgram.h ||
  58. echo 'restore of jamgram.h failed'
  59. Wc_c="`wc -c < 'jamgram.h'`"
  60. test 680 -eq "$Wc_c" ||
  61.     echo 'jamgram.h: original size 680, current size' "$Wc_c"
  62. fi
  63. # ============= jamgram.y ==============
  64. if test -f 'jamgram.y' -a X"$1" != X"-c"; then
  65.     echo 'x - skipping jamgram.y (File already exists)'
  66. else
  67. echo 'x - extracting jamgram.y (Text)'
  68. sed 's/^X//' << 'SHAR_EOF' > 'jamgram.y' &&
  69. X%token _BANG
  70. X%token _BANG_EQUALS
  71. X%token _AMPERAMPER
  72. X%token _LPAREN
  73. X%token _RPAREN
  74. X%token _COLON
  75. X%token _SEMIC
  76. X%token _LANGLE
  77. X%token _LANGLE_EQUALS
  78. X%token _EQUALS
  79. X%token _RANGLE
  80. X%token _RANGLE_EQUALS
  81. X%token ACTIONS
  82. X%token CASE
  83. X%token DEFAULT
  84. X%token ELSE
  85. X%token FOR
  86. X%token IF
  87. X%token IGNORE
  88. X%token IN
  89. X%token INCLUDE
  90. X%token ON
  91. X%token PIECEMEAL
  92. X%token QUIETLY
  93. X%token RULE
  94. X%token SWITCH
  95. X%token TOGETHER
  96. X%token UPDATED
  97. X%token _LBRACE
  98. X%token _BARBAR
  99. X%token _RBRACE
  100. X/*
  101. X * Copyright 1993 Christopher Seiwald.
  102. X */
  103. X
  104. X/*
  105. X * jamgram.yy - jam grammar
  106. X */
  107. X
  108. X%token ARG STRING
  109. X
  110. X%left _BARBAR
  111. X%left _AMPERAMPER
  112. X%left _BANG
  113. X
  114. X%{
  115. X#include "lists.h"
  116. X#include "parse.h"
  117. X#include "scan.h"
  118. X#include "compile.h"
  119. X#include "newstr.h"
  120. X
  121. X# define F0 (void (*)())0
  122. X# define P0 (PARSE *)0
  123. X# define L0 (LIST *)0
  124. X# define S0 (char *)0
  125. X
  126. X# define pset( l,r )       parse_make( compile_set,P0,P0,S0,S0,l,r,0 )
  127. X# define psettings( l,p ) parse_make( compile_settings,p,P0,S0,S0,l,L0,0 )
  128. X# define pseton( l,r )       parse_make( F0,P0,P0,S0,S0,l,r,0 )
  129. X# define psetdef( l,r )   parse_make( compile_setdefault,P0,P0,S0,S0,l,r,0 )
  130. X# define prule( s,l,r )   parse_make( compile_rule,P0,P0,s,S0,l,r,0 )
  131. X# define prules( l,r )      parse_make( compile_rules,l,r,S0,S0,L0,L0,0 )
  132. X# define pfor( s,p,l )    parse_make( compile_foreach,p,P0,s,S0,l,L0,0 )
  133. X# define psetc( s,p )     parse_make( compile_setcomp,p,P0,s,S0,L0,L0,0 )
  134. X# define psete( s,s1,f )  parse_make( compile_setexec,P0,P0,s,s1,L0,L0,f )
  135. X# define pincl( l )       parse_make( compile_include,P0,P0,S0,S0,l,L0,0 )
  136. X# define pswitch( l,p )   parse_make( compile_switch,p,P0,S0,S0,l,L0,0 )
  137. X# define pcases( l,r )    parse_make( F0,l,r,S0,S0,L0,L0,0 )
  138. X# define pcase( s,p )     parse_make( F0,p,P0,s,S0,L0,L0,0 )
  139. X# define pif( l,r )      parse_make( compile_if,l,r,S0,S0,L0,L0,0 )
  140. X# define pthen( l,r )      parse_make( F0,l,r,S0,S0,L0,L0,0 )
  141. X# define pcond( c,l,r )      parse_make( F0,l,r,S0,S0,L0,L0,c )
  142. X# define pcomp( c,l,r )      parse_make( F0,P0,P0,S0,S0,l,r,c )
  143. X
  144. X%}
  145. X
  146. X%%
  147. X
  148. X/*
  149. X * stmts - the contents of a JAMFILE
  150. X */
  151. X
  152. Xstmts    : 
  153. X        {
  154. X            compile_builtins();
  155. X        }
  156. X    | stmts rule
  157. X        { 
  158. X            (*($2.parse->func))( $2.parse, L0, L0 );
  159. X            parse_free( $2.parse );
  160. X        }
  161. X    ;
  162. X
  163. X/*
  164. X * rules - a strings of rule's together
  165. X * rule - any one of jam's rules
  166. X */
  167. X
  168. Xrules    : /* empty */
  169. X        { $$.parse = prules( P0, P0 ); }
  170. X    | rules rule
  171. X        { $$.parse = prules( $1.parse, $2.parse ); }
  172. X    ;
  173. X
  174. Xrule    : INCLUDE args _SEMIC
  175. X        { $$.parse = pincl( $2.list ); }
  176. X    | ARG args _SEMIC
  177. X        { $$.parse = prule( $1.string, $2.list, L0 ); }
  178. X    | ARG args _COLON args _SEMIC
  179. X        { $$.parse = prule( $1.string, $2.list, $4.list ); }
  180. X    | arg1 _EQUALS args _SEMIC
  181. X        { $$.parse = pset( $1.list, $3.list ); }
  182. X    | arg1 DEFAULT _EQUALS args _SEMIC
  183. X        { $$.parse = psetdef( $1.list, $4.list ); }
  184. X    | arg1 ON args _EQUALS args _SEMIC
  185. X        { $$.parse = psettings( $3.list, pseton( $1.list, $5.list ) ); }
  186. X    | FOR ARG IN args _LBRACE rules _RBRACE
  187. X        { $$.parse = pfor( $2.string, $6.parse, $4.list ); }
  188. X    | SWITCH args _LBRACE cases _RBRACE
  189. X        { $$.parse = pswitch( $2.list, $4.parse ); }
  190. X    | IF cond _LBRACE rules _RBRACE 
  191. X        { $$.parse = pif( $2.parse, pthen( $4.parse, P0 ) ); }
  192. X    | IF cond _LBRACE rules _RBRACE ELSE rule
  193. X        { $$.parse = pif( $2.parse, pthen( $4.parse, $7.parse ) ); }
  194. X    | RULE ARG rule
  195. X        { $$.parse = psetc( $2.string, $3.parse ); }
  196. X    | ACTIONS eflags ARG 
  197. X        { scan_asstring = 1; }
  198. X      STRING 
  199. X        { $$.parse = psete( $3.string, $5.string, $2.number );
  200. X          scan_asstring = 0; }
  201. X    | _LBRACE rules _RBRACE
  202. X        { $$.parse = $2.parse; }
  203. X    ;
  204. X
  205. X/*
  206. X * cond - a conditional for 'if'
  207. X */
  208. X
  209. Xcond    : args 
  210. X        { $$.parse = pcomp( COND_EXISTS, $1.list, L0 ); }
  211. X    | args _EQUALS args 
  212. X        { $$.parse = pcomp( COND_EQUALS, $1.list, $3.list ); }
  213. X    | args _BANG_EQUALS args
  214. X        { $$.parse = pcomp( COND_NOTEQ, $1.list, $3.list ); }
  215. X    | args _LANGLE args
  216. X        { $$.parse = pcomp( COND_LESS, $1.list, $3.list ); }
  217. X    | args _LANGLE_EQUALS args 
  218. X        { $$.parse = pcomp( COND_LESSEQ, $1.list, $3.list ); }
  219. X    | args _RANGLE args 
  220. X        { $$.parse = pcomp( COND_MORE, $1.list, $3.list ); }
  221. X    | args _RANGLE_EQUALS args 
  222. X        { $$.parse = pcomp( COND_MOREEQ, $1.list, $3.list ); }
  223. X    | _BANG cond
  224. X        { $$.parse = pcond( COND_NOT, $2.parse, P0 ); }
  225. X    | cond _AMPERAMPER cond 
  226. X        { $$.parse = pcond( COND_AND, $1.parse, $3.parse ); }
  227. X    | cond _BARBAR cond
  228. X        { $$.parse = pcond( COND_OR, $1.parse, $3.parse ); }
  229. X    | _LPAREN cond _RPAREN
  230. X        { $$.parse = $2.parse; }
  231. X    ;
  232. X
  233. X/*
  234. X * cases - action elements inside a 'switch'
  235. X * case - a single action element inside a 'switch'
  236. X *
  237. X * Unfortunately, a right-recursive rule.
  238. X */
  239. X
  240. Xcases    : /* empty */
  241. X        { $$.parse = P0; }
  242. X    | case cases
  243. X        { $$.parse = pcases( $1.parse, $2.parse ); }
  244. X    ;
  245. X
  246. Xcase    : CASE ARG _COLON rules
  247. X        { $$.parse = pcase( $2.string, $4.parse ); }
  248. X    ;
  249. X
  250. X/*
  251. X * args - zero or more ARGs in a LIST
  252. X * arg1 - exactly one ARG in a LIST 
  253. X */
  254. X
  255. Xargs    : /* empty */
  256. X        { $$.list = L0; }
  257. X    | args ARG
  258. X        { $$.list = list_new( $1.list, copystr( $2.string ) ); }
  259. X    ;
  260. X
  261. Xarg1    : ARG 
  262. X        { $$.list = list_new( L0, copystr( $1.string ) ); }
  263. X    ;
  264. X
  265. X/*
  266. X * eflags - zero or more modifiers to 'executes'
  267. X * eflag - a single modifier to 'executes'
  268. X */
  269. X
  270. Xeflags    : /* empty */
  271. X        { $$.number = 0; }
  272. X    | eflags eflag
  273. X        { $$.number = $1.number | $2.number; }
  274. X    ;
  275. X
  276. Xeflag    : UPDATED
  277. X        { $$.number = EXEC_UPDATED; }
  278. X    | TOGETHER
  279. X        { $$.number = EXEC_TOGETHER; }
  280. X    | IGNORE
  281. X        { $$.number = EXEC_IGNORE; }
  282. X    | QUIETLY
  283. X        { $$.number = EXEC_QUIETLY; }
  284. X    | PIECEMEAL
  285. X        { $$.number = EXEC_PIECEMEAL; }
  286. X    ;
  287. X
  288. SHAR_EOF
  289. chmod 0444 jamgram.y ||
  290. echo 'restore of jamgram.y failed'
  291. Wc_c="`wc -c < 'jamgram.y'`"
  292. test 5366 -eq "$Wc_c" ||
  293.     echo 'jamgram.y: original size 5366, current size' "$Wc_c"
  294. fi
  295. # ============= jamgram.yy ==============
  296. if test -f 'jamgram.yy' -a X"$1" != X"-c"; then
  297.     echo 'x - skipping jamgram.yy (File already exists)'
  298. else
  299. echo 'x - extracting jamgram.yy (Text)'
  300. sed 's/^X//' << 'SHAR_EOF' > 'jamgram.yy' &&
  301. X/*
  302. X * Copyright 1993 Christopher Seiwald.
  303. X */
  304. X
  305. X/*
  306. X * jamgram.yy - jam grammar
  307. X */
  308. X
  309. X%token ARG STRING
  310. X
  311. X%left `||`
  312. X%left `&&`
  313. X%left `!`
  314. X
  315. X%{
  316. X#include "lists.h"
  317. X#include "parse.h"
  318. X#include "scan.h"
  319. X#include "compile.h"
  320. X#include "newstr.h"
  321. X
  322. X# define F0 (void (*)())0
  323. X# define P0 (PARSE *)0
  324. X# define L0 (LIST *)0
  325. X# define S0 (char *)0
  326. X
  327. X# define pset( l,r )       parse_make( compile_set,P0,P0,S0,S0,l,r,0 )
  328. X# define psettings( l,p ) parse_make( compile_settings,p,P0,S0,S0,l,L0,0 )
  329. X# define pseton( l,r )       parse_make( F0,P0,P0,S0,S0,l,r,0 )
  330. X# define psetdef( l,r )   parse_make( compile_setdefault,P0,P0,S0,S0,l,r,0 )
  331. X# define prule( s,l,r )   parse_make( compile_rule,P0,P0,s,S0,l,r,0 )
  332. X# define prules( l,r )      parse_make( compile_rules,l,r,S0,S0,L0,L0,0 )
  333. X# define pfor( s,p,l )    parse_make( compile_foreach,p,P0,s,S0,l,L0,0 )
  334. X# define psetc( s,p )     parse_make( compile_setcomp,p,P0,s,S0,L0,L0,0 )
  335. X# define psete( s,s1,f )  parse_make( compile_setexec,P0,P0,s,s1,L0,L0,f )
  336. X# define pincl( l )       parse_make( compile_include,P0,P0,S0,S0,l,L0,0 )
  337. X# define pswitch( l,p )   parse_make( compile_switch,p,P0,S0,S0,l,L0,0 )
  338. X# define pcases( l,r )    parse_make( F0,l,r,S0,S0,L0,L0,0 )
  339. X# define pcase( s,p )     parse_make( F0,p,P0,s,S0,L0,L0,0 )
  340. X# define pif( l,r )      parse_make( compile_if,l,r,S0,S0,L0,L0,0 )
  341. X# define pthen( l,r )      parse_make( F0,l,r,S0,S0,L0,L0,0 )
  342. X# define pcond( c,l,r )      parse_make( F0,l,r,S0,S0,L0,L0,c )
  343. X# define pcomp( c,l,r )      parse_make( F0,P0,P0,S0,S0,l,r,c )
  344. X
  345. X%}
  346. X
  347. X%%
  348. X
  349. X/*
  350. X * stmts - the contents of a JAMFILE
  351. X */
  352. X
  353. Xstmts    : 
  354. X        {
  355. X            compile_builtins();
  356. X        }
  357. X    | stmts rule
  358. X        { 
  359. X            (*($2.parse->func))( $2.parse, L0, L0 );
  360. X            parse_free( $2.parse );
  361. X        }
  362. X    ;
  363. X
  364. X/*
  365. X * rules - a strings of rule's together
  366. X * rule - any one of jam's rules
  367. X */
  368. X
  369. Xrules    : /* empty */
  370. X        { $$.parse = prules( P0, P0 ); }
  371. X    | rules rule
  372. X        { $$.parse = prules( $1.parse, $2.parse ); }
  373. X    ;
  374. X
  375. Xrule    : `include` args `;`
  376. X        { $$.parse = pincl( $2.list ); }
  377. X    | ARG args `;`
  378. X        { $$.parse = prule( $1.string, $2.list, L0 ); }
  379. X    | ARG args `:` args `;`
  380. X        { $$.parse = prule( $1.string, $2.list, $4.list ); }
  381. X    | arg1 `=` args `;`
  382. X        { $$.parse = pset( $1.list, $3.list ); }
  383. X    | arg1 `default` `=` args `;`
  384. X        { $$.parse = psetdef( $1.list, $4.list ); }
  385. X    | arg1 `on` args `=` args `;`
  386. X        { $$.parse = psettings( $3.list, pseton( $1.list, $5.list ) ); }
  387. X    | `for` ARG `in` args `{` rules `}`
  388. X        { $$.parse = pfor( $2.string, $6.parse, $4.list ); }
  389. X    | `switch` args `{` cases `}`
  390. X        { $$.parse = pswitch( $2.list, $4.parse ); }
  391. X    | `if` cond `{` rules `}` 
  392. X        { $$.parse = pif( $2.parse, pthen( $4.parse, P0 ) ); }
  393. X    | `if` cond `{` rules `}` `else` rule
  394. X        { $$.parse = pif( $2.parse, pthen( $4.parse, $7.parse ) ); }
  395. X    | `rule` ARG rule
  396. X        { $$.parse = psetc( $2.string, $3.parse ); }
  397. X    | `actions` eflags ARG 
  398. X        { scan_asstring = 1; }
  399. X      STRING 
  400. X        { $$.parse = psete( $3.string, $5.string, $2.number );
  401. X          scan_asstring = 0; }
  402. X    | `{` rules `}`
  403. X        { $$.parse = $2.parse; }
  404. X    ;
  405. X
  406. X/*
  407. X * cond - a conditional for 'if'
  408. X */
  409. X
  410. Xcond    : args 
  411. X        { $$.parse = pcomp( COND_EXISTS, $1.list, L0 ); }
  412. X    | args `=` args 
  413. X        { $$.parse = pcomp( COND_EQUALS, $1.list, $3.list ); }
  414. X    | args `!=` args
  415. X        { $$.parse = pcomp( COND_NOTEQ, $1.list, $3.list ); }
  416. X    | args `<` args
  417. X        { $$.parse = pcomp( COND_LESS, $1.list, $3.list ); }
  418. X    | args `<=` args 
  419. X        { $$.parse = pcomp( COND_LESSEQ, $1.list, $3.list ); }
  420. X    | args `>` args 
  421. X        { $$.parse = pcomp( COND_MORE, $1.list, $3.list ); }
  422. X    | args `>=` args 
  423. X        { $$.parse = pcomp( COND_MOREEQ, $1.list, $3.list ); }
  424. X    | `!` cond
  425. X        { $$.parse = pcond( COND_NOT, $2.parse, P0 ); }
  426. X    | cond `&&` cond 
  427. X        { $$.parse = pcond( COND_AND, $1.parse, $3.parse ); }
  428. X    | cond `||` cond
  429. X        { $$.parse = pcond( COND_OR, $1.parse, $3.parse ); }
  430. X    | `(` cond `)`
  431. X        { $$.parse = $2.parse; }
  432. X    ;
  433. X
  434. X/*
  435. X * cases - action elements inside a 'switch'
  436. X * case - a single action element inside a 'switch'
  437. X *
  438. X * Unfortunately, a right-recursive rule.
  439. X */
  440. X
  441. Xcases    : /* empty */
  442. X        { $$.parse = P0; }
  443. X    | case cases
  444. X        { $$.parse = pcases( $1.parse, $2.parse ); }
  445. X    ;
  446. X
  447. Xcase    : `case` ARG `:` rules
  448. X        { $$.parse = pcase( $2.string, $4.parse ); }
  449. X    ;
  450. X
  451. X/*
  452. X * args - zero or more ARGs in a LIST
  453. X * arg1 - exactly one ARG in a LIST 
  454. X */
  455. X
  456. Xargs    : /* empty */
  457. X        { $$.list = L0; }
  458. X    | args ARG
  459. X        { $$.list = list_new( $1.list, copystr( $2.string ) ); }
  460. X    ;
  461. X
  462. Xarg1    : ARG 
  463. X        { $$.list = list_new( L0, copystr( $1.string ) ); }
  464. X    ;
  465. X
  466. X/*
  467. X * eflags - zero or more modifiers to 'executes'
  468. X * eflag - a single modifier to 'executes'
  469. X */
  470. X
  471. Xeflags    : /* empty */
  472. X        { $$.number = 0; }
  473. X    | eflags eflag
  474. X        { $$.number = $1.number | $2.number; }
  475. X    ;
  476. X
  477. Xeflag    : `updated`
  478. X        { $$.number = EXEC_UPDATED; }
  479. X    | `together`
  480. X        { $$.number = EXEC_TOGETHER; }
  481. X    | `ignore`
  482. X        { $$.number = EXEC_IGNORE; }
  483. X    | `quietly`
  484. X        { $$.number = EXEC_QUIETLY; }
  485. X    | `piecemeal`
  486. X        { $$.number = EXEC_PIECEMEAL; }
  487. X    ;
  488. X
  489. SHAR_EOF
  490. chmod 0444 jamgram.yy ||
  491. echo 'restore of jamgram.yy failed'
  492. Wc_c="`wc -c < 'jamgram.yy'`"
  493. test 4795 -eq "$Wc_c" ||
  494.     echo 'jamgram.yy: original size 4795, current size' "$Wc_c"
  495. fi
  496. # ============= jamgramtab.h ==============
  497. if test -f 'jamgramtab.h' -a X"$1" != X"-c"; then
  498.     echo 'x - skipping jamgramtab.h (File already exists)'
  499. else
  500. echo 'x - extracting jamgramtab.h (Text)'
  501. sed 's/^X//' << 'SHAR_EOF' > 'jamgramtab.h' &&
  502. X    { "!", _BANG },
  503. X    { "!=", _BANG_EQUALS },
  504. X    { "&&", _AMPERAMPER },
  505. X    { "(", _LPAREN },
  506. X    { ")", _RPAREN },
  507. X    { ":", _COLON },
  508. X    { ";", _SEMIC },
  509. X    { "<", _LANGLE },
  510. X    { "<=", _LANGLE_EQUALS },
  511. X    { "=", _EQUALS },
  512. X    { ">", _RANGLE },
  513. X    { ">=", _RANGLE_EQUALS },
  514. X    { "actions", ACTIONS },
  515. X    { "case", CASE },
  516. X    { "default", DEFAULT },
  517. X    { "else", ELSE },
  518. X    { "for", FOR },
  519. X    { "if", IF },
  520. X    { "ignore", IGNORE },
  521. X    { "in", IN },
  522. X    { "include", INCLUDE },
  523. X    { "on", ON },
  524. X    { "piecemeal", PIECEMEAL },
  525. X    { "quietly", QUIETLY },
  526. X    { "rule", RULE },
  527. X    { "switch", SWITCH },
  528. X    { "together", TOGETHER },
  529. X    { "updated", UPDATED },
  530. X    { "{", _LBRACE },
  531. X    { "||", _BARBAR },
  532. X    { "}", _RBRACE },
  533. SHAR_EOF
  534. chmod 0444 jamgramtab.h ||
  535. echo 'restore of jamgramtab.h failed'
  536. Wc_c="`wc -c < 'jamgramtab.h'`"
  537. test 655 -eq "$Wc_c" ||
  538.     echo 'jamgramtab.h: original size 655, current size' "$Wc_c"
  539. fi
  540. # ============= yyacc ==============
  541. if test -f 'yyacc' -a X"$1" != X"-c"; then
  542.     echo 'x - skipping yyacc (File already exists)'
  543. else
  544. echo 'x - extracting yyacc (Text)'
  545. sed 's/^X//' << 'SHAR_EOF' > 'yyacc' &&
  546. X#!/bin/sh
  547. X
  548. X# yyacc - yacc wrapper
  549. X#
  550. X# Allows tokens to be written as `literal` and then automatically 
  551. X# substituted with #defined tokens.
  552. X#
  553. X# Usage:
  554. X#    yyacc file.yy [ file.y filetab.h ]
  555. X#
  556. X# inputs:
  557. X#    file.yy        yacc grammar with ` literals
  558. X#
  559. X# outputs:
  560. X#    file.y        yacc grammar
  561. X#    filetab.h    array of string <-> token mappings
  562. X#
  563. X# 3-13-93
  564. X#    Documented and p moved in sed command (for some reason,
  565. X#    s/x/y/p doesn't work).
  566. X# 10-12-93
  567. X#    Take basename as second argument.
  568. X
  569. Xin=${1?}
  570. Xout=`basename $1 .yy`
  571. Xouty=${2-$out.y}
  572. Xouth=${3-${out}tab.h}
  573. X
  574. XT=/tmp/yy$$
  575. Xtrap 'rm -f $T.*' 0
  576. X
  577. Xsed '
  578. X    : 1
  579. X    /`/{
  580. X        h
  581. X        s/[^`]*`\([^`]*\)`.*/\1/
  582. X        p
  583. X        g
  584. X        s/[^`]*`[^`]*`//
  585. X        b 1
  586. X    }
  587. X    d
  588. X' $in | sort -u | sed '
  589. X    h
  590. X    y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/
  591. X    s/:/_COLON/
  592. X    s/!/_BANG/
  593. X    s/&&/_AMPERAMPER/
  594. X    s/&/_AMPER/
  595. X    s/+/_PLUS/
  596. X    s/||/_BARBAR/
  597. X    s/|/_BAR/
  598. X    s/;/_SEMIC/
  599. X    s/-/_MINUS/
  600. X    s/</_LANGLE/
  601. X    s/>/_RANGLE/
  602. X    s/\./_PERIOD/
  603. X    s/?/_QUESTION/
  604. X    s/=/_EQUALS/
  605. X    s/,/_COMMA/
  606. X    s/\[/_LBRACKET/
  607. X    s/]/_RBRACKET/
  608. X    s/{/_LBRACE/
  609. X    s/}/_RBRACE/
  610. X    s/(/_LPAREN/
  611. X    s/)/_RPAREN/
  612. X    s/FILE/_FILE_/
  613. X    G
  614. X    s/\n/ /
  615. X' > $T.1
  616. X
  617. Xsed '
  618. X    s:^\(.*\) \(.*\)$:s/`\2`/\1/g:
  619. X    s:\.:\\.:g
  620. X    s:\[:\\[:g
  621. X' $T.1 > $T.s
  622. X
  623. Xrm -f $outy $outh
  624. X
  625. X(
  626. X    sed 's:^\(.*\) \(.*\)$:%token \1:' $T.1
  627. X    sed -f $T.s $in
  628. X) > $outy
  629. X
  630. X(
  631. X    sed 's:^\(.*\) \(.*\)$:    { "\2", \1 },:' $T.1 
  632. X) > $outh
  633. SHAR_EOF
  634. chmod 0444 yyacc ||
  635. echo 'restore of yyacc failed'
  636. Wc_c="`wc -c < 'yyacc'`"
  637. test 1301 -eq "$Wc_c" ||
  638.     echo 'yyacc: original size 1301, current size' "$Wc_c"
  639. fi
  640. exit 0
  641.