soft-include $(TOP)/Jamrules.configure in SubDir; but read the full comment text...
[k8jam.git] / tools / yyacc
blobc5fb2b6a6ea255279ab279e931fc5a4e3b77c093
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/==/EQUALSEQUALS/
61 s/=/EQUALS/
62 s/,/COMMA/
63 s/~/TILDA/
64 s/\[/LBRACKET/
65 s/]/RBRACKET/
66 s/{/LBRACE/
67 s/}/RBRACE/
68 s/(/LPAREN/
69 s/)/RPAREN/
70 s/.*/T_&_t/
72 s/\n/ /
73 ' > $T.1
75 sed '
76 s:^\(.*\) \(.*\)$:s/`\2`/\1/g:
77 s:\.:\\.:g
78 s:\[:\\[:g
79 ' $T.1 > $T.s
81 rm -f $outy $outh
84 #sed 's:^\(.*\) \(.*\)$:%token \1:' $T.1
85 sed -f $T.s $in
86 ) > $outy
89 sed 's:^\(.*\) \(.*\)$: { "\2", \1 },:' $T.1
90 ) > $outh