blob: 070779029bd8650796925fc2ddcfe14cdfbef8de [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 {
drh8abed7b2018-02-26 18:49:05 +000025 TRUEFALSE
drh60a15a42015-10-07 12:21:14 +000026 ISNOT
drh60a15a42015-10-07 12:21:14 +000027 FUNCTION
28 COLUMN
29 AGG_FUNCTION
30 AGG_COLUMN
31 UMINUS
32 UPLUS
drh8abed7b2018-02-26 18:49:05 +000033 TRUTH
drh60a15a42015-10-07 12:21:14 +000034 REGISTER
drhc8d0b0b2016-08-18 15:36:03 +000035 VECTOR
dan71c57db2016-07-09 20:23:55 +000036 SELECT_COLUMN
drh31d6fd52017-04-14 19:03:10 +000037 IF_NULL_ROW
drh1a1d3cd2015-11-19 16:33:31 +000038 ASTERISK
drh94fa9c42016-02-27 21:16:04 +000039 SPAN
drh13aa88d2017-08-02 11:36:16 +000040 END_OF_FILE
41 UNCLOSED_STRING
drh0739e452015-11-09 02:08:09 +000042 SPACE
43 ILLEGAL
44}
45if {[lrange $extras end-1 end]!="SPACE ILLEGAL"} {
46 error "SPACE and ILLEGAL must be the last two token codes and they\
47 must be in that order"
drh60a15a42015-10-07 12:21:14 +000048}
49foreach x $extras {
50 incr max
51 puts [format "#define TK_%-29s %4d" $x $max]
52}
drh1167d322015-10-28 20:01:45 +000053
54# Some additional #defines related to token codes.
55#
56puts "\n/* The token codes above must all fit in 8 bits */"
57puts [format "#define %-20s %-6s" TKFLG_MASK 0xff]
58puts "\n/* Flags that can be added to a token code when it is not"
59puts "** being stored in a u8: */"
60foreach {fg val comment} {
61 TKFLG_DONTFOLD 0x100 {/* Omit constant folding optimizations */}
62} {
63 puts [format "#define %-20s %-6s %s" $fg $val $comment]
64}