date and time created 91/03/07 20:27:59 by bostic
[unix-history] / usr / src / bin / sh / mktokens
CommitLineData
2b262aec
KB
1#!/bin/sh -
2#
3# Copyright (c) 1991 The Regents of the University of California.
4# All rights reserved.
5#
6# This code is derived from software contributed to Berkeley by
7# Kenneth Almquist.
8#
9# %sccs.include.redist.sh%
10#
11# @(#)mktokens 5.1 (Berkeley) %G%
12
13# The following is a list of tokens. The second column is nonzero if the
14# token marks the end of a list. The third column is the name to print in
15# error messages.
16
17cat > /tmp/ka$$ <<\!
18TEOF 1 end of file
19TNL 0 newline
20TSEMI 0 ";"
21TBACKGND 0 "&"
22TAND 0 "&&"
23TOR 0 "||"
24TPIPE 0 "|"
25TLP 0 "("
26TRP 1 ")"
27TENDCASE 1 ";;"
28TENDBQUOTE 1 "`"
29TREDIR 0 redirection
30TWORD 0 word
31TIF 0 "if"
32TTHEN 1 "then"
33TELSE 1 "else"
34TELIF 1 "elif"
35TFI 1 "fi"
36TWHILE 0 "while"
37TUNTIL 0 "until"
38TFOR 0 "for"
39TDO 1 "do"
40TDONE 1 "done"
41TBEGIN 0 "{"
42TEND 1 "}"
43TCASE 0 "case"
44TESAC 1 "esac"
45!
46nl=`wc -l /tmp/ka$$`
47exec > token.def
48awk '{print "#define " $1 " " NR-1}' /tmp/ka$$
49echo '
50/* Array indicating which tokens mark the end of a list */
51const char tokendlist[] = {'
52awk '{print "\t" $2 ","}' /tmp/ka$$
53echo '};
54
55char *const tokname[] = {'
56sed -e 's/"/\\"/g' \
57 -e 's/[^ ]*[ ][ ]*[^ ]*[ ][ ]*\(.*\)/ "\1",/' \
58 /tmp/ka$$
59echo '};
60'
61sed 's/"//g' /tmp/ka$$ | awk '
62/TIF/{print "#define KWDOFFSET " NR-1; print ""; print "char *const parsekwd[] = {"}
63/TIF/,/neverfound/{print " \"" $3 "\","}'
64echo ' 0
65};'
66
67rm /tmp/ka$$