package provide DS9 1.0

######
# Begin autogenerated taccle (version 1.3) routines.
# Although taccle itself is protected by the GNU Public License (GPL)
# all user-supplied functions are protected by their respective
# author's license.  See http://mini.net/tcl/taccle for other details.
######

namespace eval export {
    variable yylval {}
    variable table
    variable rules
    variable token {}
    variable yycnt 0
    variable yyerr 0
    variable save_state 0

    namespace export yylex
}

proc export::YYABORT {} {
    return -code return 1
}

proc export::YYACCEPT {} {
    return -code return 0
}

proc export::YYERROR {} {
    variable yyerr
    set yyerr 1
}

proc export::yyclearin {} {
    variable token
    variable yycnt
    set token {}
    incr yycnt -1
}

proc export::yyerror {s} {
    puts stderr $s
}

proc export::setupvalues {stack pointer numsyms} {
    upvar 1 1 y
    set y {}
    for {set i 1} {$i <= $numsyms} {incr i} {
        upvar 1 $i y
        set y [lindex $stack $pointer]
        incr pointer
    }
}

proc export::unsetupvalues {numsyms} {
    for {set i 1} {$i <= $numsyms} {incr i} {
        upvar 1 $i y
        unset y
    }
}

array set export::table {
  30:259,target 18
  29:259,target 16
  15:259 shift
  31:0,target 19
  23:0,target 25
  17:259 reduce
  0:260 shift
  0:259 shift
  27:0 reduce
  24:259,target 10
  17:266,target 28
  0:266,target 8
  0:261 shift
  6:259,target 16
  20:259 shift
  19:259 reduce
  0:262 shift
  2:259 shift
  11:0 reduce
  0:263 shift
  22:259 reduce
  18:259,target 20
  13:268 shift
  0:264 shift
  1:259,target 14
  4:259 shift
  32:0 reduce
  13:270 shift
  13:269 shift
  0:265 shift
  24:259 reduce
  18:279,target 34
  17:266 shift
  0:266 shift
  6:259 shift
  13:259,target 22
  0:267 shift
  32:0,target 7
  26:259 reduce
  13:270,target 23
  13:269,target 22
  0:265,target 7
  8:259 shift
  36:0 reduce
  33:259,target 21
  24:0,target 10
  13:280,target 25
  0:275,target 10
  11:276 goto
  28:259 reduce
  19:0 reduce
  17:271 shift
  16:0,target 6
  17:272 shift
  31:259 reduce
  27:259,target 22
  17:273 shift
  9:259,target 19
  27:270,target 23
  27:269,target 22
  33:259 reduce
  27:280,target 36
  24:0 reduce
  13:280 goto
  0:275 goto
  22:259,target 24
  13:268,target 21
  0:264,target 6
  4:259,target 14
  0:277 goto
  33:0,target 21
  17:278 goto
  28:0 reduce
  25:0,target 11
  18:257,target 33
  16:259,target 6
  17:0,target 15
  12:0 reduce
  36:259,target 13
  27:268,target 21
  10:0,target 0
  11:259,target 4
  33:0 reduce
  0:263,target 5
  31:259,target 19
  17:273,target 31
  16:0 reduce
  34:0,target 8
  25:259,target 11
  7:259,target 17
  26:0,target 12
  21:0 reduce
  12:259 reduce
  18:0,target 20
  1:0,target 14
  20:259,target 35
  19:259,target 9
  14:259 reduce
  0:262,target 4
  2:259,target 12
  11:0,target 3
  17:272,target 30
  25:0 reduce
  18:257 shift
  16:259 reduce
  14:259,target 22
  18:259 reduce
  14:270,target 23
  14:269,target 22
  1:259 reduce
  34:259,target 8
  14:280,target 26
  35:0,target 5
  30:0 reduce
  29:0 reduce
  21:259 reduce
  12:268 shift
  3:259 shift
  27:0,target 22
  13:0 reduce
  12:270 shift
  12:269 shift
  0:261,target 3
  28:259,target 17
  23:259 reduce
  19:0,target 9
  17:271,target 29
  14:268 shift
  5:259 shift
  14:270 shift
  14:269 shift
  12:0,target 22
  34:0 reduce
  25:259 reduce
  7:259 shift
  23:259,target 25
  17:0 reduce
  14:268,target 21
  5:259,target 15
  27:259 reduce
  9:259 shift
  30:259 reduce
  29:259 reduce
  17:259,target 15
  0:260,target 2
  0:259,target 1
  36:0,target 13
  22:0 reduce
  11:276,target 20
  32:259 reduce
  28:0,target 17
  12:280 goto
  21:0,target 23
  12:259,target 22
  34:259 reduce
  14:280 goto
  13:0,target 22
  12:270,target 23
  12:269,target 22
  32:259,target 7
  26:0 reduce
  12:280,target 24
  36:259 reduce
  27:268 shift
  10:0 accept
  27:270 shift
  27:269 shift
  26:259,target 12
  18:279 goto
  8:259,target 18
  31:0 reduce
  17:278,target 32
  14:0 reduce
  30:0,target 18
  29:0,target 16
  21:259,target 23
  12:268,target 21
  3:259,target 13
  22:0,target 24
  35:0 reduce
  14:0,target 22
  18:0 reduce
  15:259,target 27
  1:0 reduce
  11:259 reduce
  0:267,target 9
  27:280 goto
  0:277,target 11
  13:259 reduce
  23:0 reduce
}

array set export::rules {
  9,l 277
  11,l 277
  15,l 278
  20,l 279
  19,l 278
  2,l 274
  24,l 280
  6,l 277
  12,l 277
  16,l 278
  21,l 279
  3,l 275
  25,l 280
  7,l 277
  13,l 277
  0,l 281
  17,l 278
  22,l 280
  4,l 276
  8,l 277
  10,l 277
  14,l 277
  18,l 278
  1,l 274
  23,l 280
  5,l 275
}

array set export::rules {
  23,dc 1
  5,dc 3
  0,dc 1
  17,dc 1
  12,dc 3
  8,dc 3
  21,dc 1
  3,dc 1
  15,dc 0
  10,dc 3
  24,dc 1
  6,dc 2
  18,dc 1
  1,dc 1
  13,dc 4
  9,dc 2
  22,dc 0
  4,dc 0
  16,dc 1
  11,dc 3
  25,dc 1
  7,dc 3
  20,dc 0
  19,dc 1
  2,dc 1
  14,dc 1
}

array set export::rules {
  13,line 56
  25,line 74
  7,line 47
  10,line 51
  22,line 71
  4,line 42
  18,line 63
  1,line 38
  15,line 60
  9,line 50
  12,line 53
  24,line 73
  6,line 46
  21,line 68
  3,line 42
  17,line 62
  4,e 1
  14,line 57
  8,line 48
  11,line 52
  23,line 72
  5,line 43
  20,line 67
  19,line 64
  2,line 39
  16,line 61
}

array set export::lr1_table {
  35 {{5 0 3}}
  36 {{13 {0 259} 4}}
  14,trans {{268 21} {269 22} {270 23} {280 26}}
  33,trans {}
  18,trans {{257 33} {279 34}}
  1,trans {}
  23,trans {}
  5,trans {{259 15}}
  27,trans {{268 21} {269 22} {270 23} {280 36}}
  9,trans {{259 19}}
  13,trans {{268 21} {269 22} {270 23} {280 25}}
  32,trans {}
  17,trans {{266 28} {271 29} {272 30} {273 31} {278 32}}
  0,trans {{259 1} {260 2} {261 3} {262 4} {263 5} {264 6} {265 7} {266 8} {267 9} {275 10} {277 11}}
  36,trans {}
  22,trans {}
  4,trans {{259 14}}
  26,trans {}
  8,trans {{259 18}}
  12,trans {{268 21} {269 22} {270 23} {280 24}}
  31,trans {}
  16,trans {}
  35,trans {}
  21,trans {}
  3,trans {{259 13}}
  10 {{0 0 1}}
  11 {{3 0 1} {5 0 1} {4 259 0}}
  25,trans {}
  12 {{10 {0 259} 2} {22 {0 259} 0} {23 {0 259} 0} {24 {0 259} 0} {25 {0 259} 0}}
  7,trans {{259 17}}
  13 {{11 {0 259} 2} {22 {0 259} 0} {23 {0 259} 0} {24 {0 259} 0} {25 {0 259} 0}}
  14 {{12 {0 259} 2} {22 {0 259} 0} {23 {0 259} 0} {24 {0 259} 0} {25 {0 259} 0}}
  15 {{13 {0 259} 2}}
  11,trans {{276 20}}
  30,trans {}
  29,trans {}
  16 {{6 {0 259} 2}}
  0 {{0 0 0} {3 0 0} {5 0 0} {6 {0 259} 0} {7 {0 259} 0} {8 {0 259} 0} {9 {0 259} 0} {10 {0 259} 0} {11 {0 259} 0} {12 {0 259} 0} {13 {0 259} 0} {14 {0 259} 0}}
  17 {{7 {0 259} 2} {15 {0 259} 0} {16 {0 259} 0} {17 {0 259} 0} {18 {0 259} 0} {19 {0 259} 0}}
  1 {{14 {0 259} 1}}
  18 {{8 {0 259} 2} {20 {0 259} 0} {21 {0 259} 0}}
  2 {{10 {0 259} 1}}
  19 {{9 {0 259} 2}}
  20 {{5 0 2}}
  15,trans {{259 27}}
  34,trans {}
  3 {{11 {0 259} 1}}
  21 {{23 {0 259} 1}}
  4 {{12 {0 259} 1}}
  22 {{24 {0 259} 1}}
  5 {{13 {0 259} 1}}
  23 {{25 {0 259} 1}}
  20,trans {{259 35}}
  19,trans {}
  6 {{6 {0 259} 1}}
  2,trans {{259 12}}
  24 {{10 {0 259} 3}}
  7 {{7 {0 259} 1}}
  25 {{11 {0 259} 3}}
  8 {{8 {0 259} 1}}
  26 {{12 {0 259} 3}}
  9 {{9 {0 259} 1}}
  27 {{13 {0 259} 3} {22 {0 259} 0} {23 {0 259} 0} {24 {0 259} 0} {25 {0 259} 0}}
  24,trans {}
  6,trans {{259 16}}
  28 {{17 {0 259} 1}}
  29 {{16 {0 259} 1}}
  30 {{18 {0 259} 1}}
  31 {{19 {0 259} 1}}
  32 {{7 {0 259} 3}}
  10,trans {}
  28,trans {}
  33 {{21 {0 259} 1}}
  34 {{8 {0 259} 3}}
}

array set export::token_id_table {
  280,title {}
  279,title {}
  264,line 19
  270,t 0
  269,t 0
  276,line 42
  265,title TIFF
  274,t 1
  261,line 15
  257,t 0
  270,title NATIVE
  269,title LITTLE
  273,line 30
  278,t 1
  257,line 7
  262,t 0
  274,title {}
  270,line 26
  269,line 25
  259,title string
  260,title ARRAY
  266,t 0
  278,title {}
  error error
  271,t 0
  264,title GIF
  266,line 21
  278,line 59
  275,t 1
  error,line 36
  268,title BIG
  258,t 0
  263,line 17
  error,title {}
  280,t 1
  279,t 1
  275,line 41
  273,title DEFLATE
  263,t 0
  259,line 10
  260,line 14
  258,title float
  277,title {}
  272,line 29
  267,t 0
  263,title ENVI
  272,t 0
  268,line 24
  267,title PNG
  257 INT_
  281,line 75
  276,t 1
  258 REAL_
  259,t 0
  259 STRING_
  260 ARRAY_
  260,t 0
  272,title PACKBITS
  261 RGBARRAY_
  265,line 20
  262 NRRD_
  281,t 1
  263 ENVI_
  277,line 45
  257,title integer
  264 GIF_
  264,t 0
  276,title {}
  265 TIFF_
  262,line 16
  266 JPEG_
  267 PNG_
  0,t 0
  0 {$}
  262,title NRRD
  268 BIG_
  268,t 0
  281,title {}
  274,line 37
  270 NATIVE_
  269 LITTLE_
  error,t 0
  271 NONE_
  272 PACKBITS_
  258,line 8
  273,t 0
  273 DEFLATE_
  266,title JPEG
  274 numeric
  275 command
  271,line 28
  276 @PSEUDO1
  277,t 1
  277 export
  271,title NONE
  278 tiffopts
  261,t 0
  280 endian
  279 jpegopts
  281 start'
  267,line 22
  275,title {}
  265,t 0
  280,line 70
  279,line 66
  261,title RGBARRAY
}

proc export::yyparse {} {
    variable yylval
    variable table
    variable rules
    variable token
    variable yycnt
    variable lr1_table
    variable token_id_table
    variable yyerr
    variable save_state

    set yycnt 0
    set state_stack {0}
    set value_stack {{}}
    set token ""
    set accepted 0
    set yyerr 0
    set save_state 0

    while {$accepted == 0} {
        set state [lindex $state_stack end]
        if {$token == ""} {
            set yylval ""
            set token [yylex]
            set buflval $yylval
	    if {$token>0} {
	        incr yycnt
            }
        }
        if {![info exists table($state:$token)] || $yyerr} {
	    if {!$yyerr} {
	        set save_state $state
	    }
            # pop off states until error token accepted
            while {[llength $state_stack] > 0 && \
                       ![info exists table($state:error)]} {
                set state_stack [lrange $state_stack 0 end-1]
                set value_stack [lrange $value_stack 0 \
                                       [expr {[llength $state_stack] - 1}]]
                set state [lindex $state_stack end]
            }
            if {[llength $state_stack] == 0} {
 
	        set rr { }
                if {[info exists lr1_table($save_state,trans)] && [llength $lr1_table($save_state,trans)] >= 1} {
                    foreach trans $lr1_table($save_state,trans) {
                        foreach {tok_id nextstate} $trans {
			    set ss $token_id_table($tok_id,title)
			    if {$ss != {}} {
			        append rr "$ss, "
                            }
                        }
                    }
                }
		set rr [string trimleft $rr { }]
		set rr [string trimright $rr {, }]
                yyerror "parse error, expecting: $rr"


                return 1
            }
            lappend state_stack [set state $table($state:error,target)]
            lappend value_stack {}
            # consume tokens until it finds an acceptable one
            while {![info exists table($state:$token)]} {
                if {$token == 0} {
                    yyerror "end of file while recovering from error"
                    return 1
                }
                set yylval {}
                set token [yylex]
                set buflval $yylval
            }
            continue
        }
        switch -- $table($state:$token) {
            shift {
                lappend state_stack $table($state:$token,target)
                lappend value_stack $buflval
                set token ""
            }
            reduce {
                set rule $table($state:$token,target)
                set ll $rules($rule,l)
                if {[info exists rules($rule,e)]} {
                    set dc $rules($rule,e)
                } else {
                    set dc $rules($rule,dc)
                }
                set stackpointer [expr {[llength $state_stack]-$dc}]
                setupvalues $value_stack $stackpointer $dc
                set _ $1
                set yylval [lindex $value_stack end]
                switch -- $rule {
                    1 { set _ $1 }
                    2 { set _ $1 }
                    4 { global ds9; if {!$ds9(init)} {YYERROR} else {yyclearin; YYACCEPT} }
                    6 { ExportCmdSave gif $2 }
                    7 { ExportCmdSave tiff $2 }
                    8 { ExportCmdSave jpeg $2 }
                    9 { ExportCmdSave png $2 }
                    10 { ExportCmdSave array $2 }
                    11 { ExportCmdSave rgbarray $2 }
                    12 { ExportCmdSave nrrd $2 }
                    13 { ExportCmdSave envi $2 $3 }
                    14 { ExportCmdSave [ExtToFormat $1] $1 }
                    15 { ProcessCmdSet export tiff,compress none }
                    16 { ProcessCmdSet export tiff,compress none }
                    17 { ProcessCmdSet export tiff,compress jpeg }
                    18 { ProcessCmdSet export tiff,compress packbits }
                    19 { ProcessCmdSet export tiff,compress deflate }
                    20 { ProcessCmdSet export jpeg,quality 100 }
                    21 { ProcessCmdSet export jpeg,quality $1 }
                    22 { ProcessCmdSet export endian native }
                    23 { ProcessCmdSet export endian big }
                    24 { ProcessCmdSet export endian little }
                    25 { ProcessCmdSet export endian native }
                }
                unsetupvalues $dc
                # pop off tokens from the stack if normal rule
                if {![info exists rules($rule,e)]} {
                    incr stackpointer -1
                    set state_stack [lrange $state_stack 0 $stackpointer]
                    set value_stack [lrange $value_stack 0 $stackpointer]
                }
                # now do the goto transition
                lappend state_stack $table([lindex $state_stack end]:$ll,target)
                lappend value_stack $_
            }
            accept {
                set accepted 1
            }
            goto -
            default {
                puts stderr "Internal parser error: illegal command $table($state:$token)"
                return 2
            }
        }
    }
    return 0
}

######
# end autogenerated taccle functions
######

proc export::yyerror {msg} {
     variable yycnt
     variable yy_current_buffer
     variable index_

     ParserError $msg $yycnt $yy_current_buffer $index_
}
