blob: bd0b73a35f98630848180e6cd3f2b0f8877a6ae9 [file] [log] [blame]
drh60a15a42015-10-07 12:21:14 +00001#!/usr/bin/tclsh
2#
3# This script appends additional token codes to the end of the
4# parse.h file that lemon generates. These extra token codes are
5# not used by the parser. But they are used by the tokenizer and/or
6# the code generator.
7#
8#
9set in [open [lindex $argv 0] rb]
10set max 0
11while {![eof $in]} {
12 set line [gets $in]
13 if {[regexp {^#define TK_} $line]} {
14 puts $line
15 set x [lindex $line 2]
16 if {$x>$max} {set max $x}
17 }
18}
19close $in
20
drh0739e452015-11-09 02:08:09 +000021# The following are the extra token codes to be added. SPACE and
22# ILLEGAL *must* be the last two token codes and they must be in that order.
drh60a15a42015-10-07 12:21:14 +000023#
24set extras {
25 TO_TEXT
26 TO_BLOB
27 TO_NUMERIC
28 TO_INT
29 TO_REAL
30 ISNOT
31 END_OF_FILE
drh60a15a42015-10-07 12:21:14 +000032 UNCLOSED_STRING
33 FUNCTION
34 COLUMN
35 AGG_FUNCTION
36 AGG_COLUMN
37 UMINUS
38 UPLUS
39 REGISTER
drh0739e452015-11-09 02:08:09 +000040 SPACE
41 ILLEGAL
42}
43if {[lrange $extras end-1 end]!="SPACE ILLEGAL"} {
44 error "SPACE and ILLEGAL must be the last two token codes and they\
45 must be in that order"
drh60a15a42015-10-07 12:21:14 +000046}
47foreach x $extras {
48 incr max
49 puts [format "#define TK_%-29s %4d" $x $max]
50}
drh1167d322015-10-28 20:01:45 +000051
52# Some additional #defines related to token codes.
53#
54puts "\n/* The token codes above must all fit in 8 bits */"
55puts [format "#define %-20s %-6s" TKFLG_MASK 0xff]
56puts "\n/* Flags that can be added to a token code when it is not"
57puts "** being stored in a u8: */"
58foreach {fg val comment} {
59 TKFLG_DONTFOLD 0x100 {/* Omit constant folding optimizations */}
60} {
61 puts [format "#define %-20s %-6s %s" $fg $val $comment]
62}