1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#!/bin/sh
#
# This script appends additional token codes to the end of the
# parse.h file that lemon generates. These extra token codes are
# not used by the parser. But they are used by the tokenizer and/or
# the code generator.
set -eu # Strict shell (w/o -x and -o pipefail)
set -f # disable pathname expansion
max=0
newline="$(printf '\n')"
IFS="$newline"
while read line; do
case "$line" in
'#define TK_'*)
printf '%s\n' "$line"
IFS=" "
set -- $line
IFS="$newline"
x="$3"
if [ "$x" -gt $max ]; then
max="$x"
fi
;;
esac
done < "$1"
# The following are the extra token codes to be added. SPACE and
# ILLEGAL *must* be the last two token codes and they must be in that order.
extras=" \
TO_TEXT \
ISNULL \
NOTNULL \
TO_BLOB \
TO_NUMERIC \
TO_INT \
TO_REAL \
END_OF_FILE \
UNCLOSED_STRING \
FUNCTION \
COLUMN \
AGG_FUNCTION \
AGG_COLUMN \
UMINUS \
UPLUS \
REGISTER \
VECTOR \
SELECT_COLUMN \
ASTERISK \
SPAN \
ANALYZE \
LINEFEED \
SPACE \
ILLEGAL \
"
IFS=" "
for x in $extras; do
max=$((max + 1))
printf '#define TK_%-29s %4d\n' "$x" "$max"
done
# Some additional #defines related to token codes.
printf '%b\n' "\n/* The token codes above must all fit in 8 bits */"
printf '#define %-20s %-6s\n' TKFLG_MASK 0xff
printf '%b\n' "\n/* Flags that can be added to a token code when it is not"
printf '%b\n' "** being stored in a u8: */"
printf '#define %-20s %-6s %s\n' \
TKFLG_DONTFOLD 0x100 '/* Omit constant folding optimizations */'
|