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

array set export::rules {
  27,l 280
  9,l 277
  11,l 277
  15,l 278
  20,l 279
  19,l 279
  2,l 274
  24,l 280
  6,l 277
  28,l 281
  12,l 277
  16,l 278
  21,l 279
  3,l 275
  25,l 280
  7,l 277
  30,l 281
  29,l 281
  13,l 277
  0,l 282
  17,l 278
  22,l 279
  4,l 276
  26,l 280
  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
  26,dc 1
  8,dc 2
  21,dc 1
  3,dc 1
  15,dc 1
  10,dc 3
  30,dc 1
  29,dc 1
  24,dc 1
  6,dc 1
  18,dc 1
  1,dc 1
  13,dc 3
  27,dc 1
  9,dc 2
  22,dc 1
  4,dc 0
  16,dc 1
  11,dc 2
  25,dc 1
  7,dc 2
  20,dc 1
  19,dc 1
  2,dc 1
  14,dc 4
  28,dc 1
}

array set export::rules {
  13,line 55
  25,line 73
  7,line 47
  10,line 52
  22,line 68
  4,line 42
  18,line 62
  1,line 38
  15,line 59
  27,line 75
  9,line 50
  12,line 54
  24,line 72
  6,line 46
  21,line 67
  3,line 42
  17,line 61
  4,e 1
  30,line 80
  29,line 79
  14,line 56
  26,line 74
  8,line 49
  11,line 53
  23,line 71
  5,line 43
  20,line 66
  19,line 65
  2,line 39
  16,line 60
  28,line 78
}

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

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 {}
  282,line 81
  error error
  271,t 0
  264,title GIF
  266,line 21
  278,line 58
  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
  282,title {}
  272,t 0
  268,line 24
  267,title PNG
  257 INT_
  281,line 77
  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 ext
  261,t 0
  280 opts
  279 ext2
  281 endian
  267,line 22
  282,t 1
  282 start'
  275,title {}
  265,t 0
  280,line 70
  279,line 64
  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 [ExtToFormat $1] $1 }
                    7 { ExportCmdSave [ExtToFormat $1] $1 }
                    8 { ExportCmdSave [ExtToFormat $1] $1 }
                    9 { ExportCmdSave $1 $2 }
                    10 { ExportCmdSave $1 $2 }
                    11 { ExportCmdSave $1 $2 }
                    12 { ExportCmdSave $1 $2 }
                    13 { ExportCmdSave envi $2 $3 }
                    14 { ExportCmdSave envi $2 $3 }
                    15 { set _ gif }
                    16 { set _ tiff }
                    17 { set _ jpeg }
                    18 { set _ png }
                    19 { set _ array }
                    20 { set _ rgbarray }
                    21 { set _ nrrd }
                    22 { set _ envi }
                    23 { ProcessCmdSet export tiff,compress none }
                    24 { ProcessCmdSet export tiff,compress jpeg }
                    25 { ProcessCmdSet export tiff,compress packbits }
                    26 { ProcessCmdSet export tiff,compress deflate }
                    27 { ProcessCmdSet export jpeg,quality $1 }
                    28 { ProcessCmdSet export endian big }
                    29 { ProcessCmdSet export endian little }
                    30 { 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_
}
