drh | 60a15a4 | 2015-10-07 12:21:14 +0000 | [diff] [blame] | 1 | #!/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 | # |
| 9 | set in [open [lindex $argv 0] rb] |
| 10 | set max 0 |
| 11 | while {![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 | } |
| 19 | close $in |
| 20 | |
drh | 0739e45 | 2015-11-09 02:08:09 +0000 | [diff] [blame] | 21 | # 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. |
drh | 60a15a4 | 2015-10-07 12:21:14 +0000 | [diff] [blame] | 23 | # |
| 24 | set extras { |
| 25 | TO_TEXT |
| 26 | TO_BLOB |
| 27 | TO_NUMERIC |
| 28 | TO_INT |
| 29 | TO_REAL |
| 30 | ISNOT |
| 31 | END_OF_FILE |
drh | 60a15a4 | 2015-10-07 12:21:14 +0000 | [diff] [blame] | 32 | UNCLOSED_STRING |
| 33 | FUNCTION |
| 34 | COLUMN |
| 35 | AGG_FUNCTION |
| 36 | AGG_COLUMN |
| 37 | UMINUS |
| 38 | UPLUS |
| 39 | REGISTER |
drh | c8d0b0b | 2016-08-18 15:36:03 +0000 | [diff] [blame] | 40 | VECTOR |
dan | 71c57db | 2016-07-09 20:23:55 +0000 | [diff] [blame] | 41 | SELECT_COLUMN |
drh | 31d6fd5 | 2017-04-14 19:03:10 +0000 | [diff] [blame] | 42 | IF_NULL_ROW |
drh | 1a1d3cd | 2015-11-19 16:33:31 +0000 | [diff] [blame] | 43 | ASTERISK |
drh | 94fa9c4 | 2016-02-27 21:16:04 +0000 | [diff] [blame] | 44 | SPAN |
drh | 0739e45 | 2015-11-09 02:08:09 +0000 | [diff] [blame] | 45 | SPACE |
| 46 | ILLEGAL |
| 47 | } |
| 48 | if {[lrange $extras end-1 end]!="SPACE ILLEGAL"} { |
| 49 | error "SPACE and ILLEGAL must be the last two token codes and they\ |
| 50 | must be in that order" |
drh | 60a15a4 | 2015-10-07 12:21:14 +0000 | [diff] [blame] | 51 | } |
| 52 | foreach x $extras { |
| 53 | incr max |
| 54 | puts [format "#define TK_%-29s %4d" $x $max] |
| 55 | } |
drh | 1167d32 | 2015-10-28 20:01:45 +0000 | [diff] [blame] | 56 | |
| 57 | # Some additional #defines related to token codes. |
| 58 | # |
| 59 | puts "\n/* The token codes above must all fit in 8 bits */" |
| 60 | puts [format "#define %-20s %-6s" TKFLG_MASK 0xff] |
| 61 | puts "\n/* Flags that can be added to a token code when it is not" |
| 62 | puts "** being stored in a u8: */" |
| 63 | foreach {fg val comment} { |
| 64 | TKFLG_DONTFOLD 0x100 {/* Omit constant folding optimizations */} |
| 65 | } { |
| 66 | puts [format "#define %-20s %-6s %s" $fg $val $comment] |
| 67 | } |