mkjambase generates more compact jambase.c
[k8jam.git] / yyacc
blob10f64af23ab0851488f794738681f44d120119fa
1 #!/bin/sh
3 # yyacc - yacc wrapper
5 # Allows tokens to be written as `literal` and then automatically
6 # substituted with #defined tokens.
8 # Usage:
9 # yyacc file.y filetab.h file.yy
11 # inputs:
12 # file.yy yacc grammar with ` literals
14 # outputs:
15 # file.y yacc grammar
16 # filetab.h array of string <-> token mappings
18 # 03-13-93 - Documented and p moved in sed command (for some reason,
19 # s/x/y/p doesn't work).
20 # 10-12-93 - Take basename as second argument.
21 # 12-31-96 - reversed order of args to be compatible with GenFile rule
22 # 03/19/02 (seiwald) - suffix symbols with _t to avoid conflicts
25 outy=${1?}
26 outh=${2?}
27 in=${3?}
28 out=`basename $in .yy`
30 T=/tmp/yy$$
31 trap 'rm -f $T.*' 0
33 sed '
34 : 1
35 /`/{
37 s/[^`]*`\([^`]*\)`.*/\1/
40 s/[^`]*`[^`]*`//
41 b 1
44 ' $in | sort -u | sed '
46 y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/
47 s/:/_COLON/
48 s/!/_BANG/
49 s/&&/_AMPERAMPER/
50 s/&/_AMPER/
51 s/+/_PLUS/
52 s/||/_BARBAR/
53 s/|/_BAR/
54 s/;/_SEMIC/
55 s/-/_MINUS/
56 s/</_LANGLE/
57 s/>/_RANGLE/
58 s/\./_PERIOD/
59 s/?/_QUESTION/
60 s/=/_EQUALS/
61 s/,/_COMMA/
62 s/\[/_LBRACKET/
63 s/]/_RBRACKET/
64 s/{/_LBRACE/
65 s/}/_RBRACE/
66 s/(/_LPAREN/
67 s/)/_RPAREN/
68 s/.*/&_t/
70 s/\n/ /
71 ' > $T.1
73 sed '
74 s:^\(.*\) \(.*\)$:s/`\2`/\1/g:
75 s:\.:\\.:g
76 s:\[:\\[:g
77 ' $T.1 > $T.s
79 rm -f $outy $outh
82 sed 's:^\(.*\) \(.*\)$:%token \1:' $T.1
83 sed -f $T.s $in
84 ) > $outy
87 sed 's:^\(.*\) \(.*\)$: { "\2", \1 },:' $T.1
88 ) > $outh