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 cubesend {
    variable yylval {}
    variable table
    variable rules
    variable token {}
    variable yycnt 0
    variable yyerr 0
    variable save_state 0

    namespace export yylex
}

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

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

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

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

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

proc cubesend::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 cubesend::unsetupvalues {numsyms} {
    for {set i 1} {$i <= $numsyms} {incr i} {
        upvar 1 $i y
        unset y
    }
}

array set cubesend::table {
  38:0,target 34
  33:292,target 38
  0:257 shift
  31:0,target 29
  0:258 shift
  23:0,target 23
  5:0,target 5
  0:259 shift
  0:260 shift
  27:0 reduce
  15:0,target 15
  9:0 reduce
  0:261 shift
  0:266,target 10
  11:0 reduce
  0:276,target 20
  0:262 shift
  0:286,target 30
  0:263 shift
  0:264 shift
  32:0 reduce
  29:288 shift
  0:265 shift
  15:0 reduce
  0:266 shift
  0:267 shift
  32:0,target 31
  29:288,target 36
  29:292 goto
  0:265,target 9
  0:268 shift
  36:0 reduce
  24:0,target 24
  6:0,target 6
  0:275,target 19
  0:269 shift
  0:270 shift
  20:0 reduce
  19:0 reduce
  16:0,target 16
  2:0 reduce
  0:285,target 29
  0:271 shift
  0:272 shift
  0:273 shift
  0:274 shift
  24:0 reduce
  6:0 reduce
  0:275 shift
  0:276 shift
  0:264,target 8
  0:277 shift
  0:274,target 18
  33:0,target 36
  0:278 shift
  0:284,target 28
  28:0 reduce
  25:0,target 25
  7:0,target 7
  0:280 shift
  0:279 shift
  33:288,target 36
  17:0,target 17
  12:0 reduce
  0:281 shift
  0:0,target 28
  10:0,target 10
  0:282 shift
  0:283 shift
  33:0 reduce
  0:284 shift
  0:263,target 7
  16:0 reduce
  0:273,target 17
  0:285 shift
  0:283,target 27
  0:286 shift
  0:287 shift
  37:0 reduce
  34:0,target 30
  0:288 shift
  26:0,target 26
  21:0 reduce
  8:0,target 8
  3:0 reduce
  0:290 goto
  0:289 shift
  18:0,target 18
  1:0,target 1
  0:291 goto
  11:0,target 11
  0:262,target 6
  0:272,target 16
  25:0 reduce
  7:0 reduce
  0:282,target 26
  35:0,target 0
  30:0 reduce
  29:0 reduce
  27:0,target 27
  13:0 reduce
  9:0,target 9
  0:261,target 5
  20:0,target 20
  19:0,target 19
  2:0,target 2
  0:271,target 15
  12:0,target 12
  0:281,target 25
  34:0 reduce
  0:291,target 35
  33:288 shift
  17:0 reduce
  0:0 reduce
  38:0 reduce
  33:292 goto
  0:259,target 3
  0:260,target 4
  36:0,target 37
  22:0 reduce
  4:0 reduce
  0:269,target 13
  0:270,target 14
  28:0,target 35
  0:280,target 24
  0:279,target 23
  21:0,target 21
  3:0,target 3
  0:290,target 34
  0:289,target 33
  13:0,target 13
  26:0 reduce
  8:0 reduce
  10:0 reduce
  0:258,target 2
  29:292,target 37
  0:268,target 12
  31:0 reduce
  0:278,target 22
  37:0,target 33
  14:0 reduce
  0:288,target 32
  30:0,target 32
  29:0,target 36
  22:0,target 22
  4:0,target 4
  35:0 accept
  14:0,target 14
  18:0 reduce
  1:0 reduce
  0:257,target 1
  0:267,target 11
  0:277,target 21
  0:287,target 31
  23:0 reduce
  5:0 reduce
}

array set cubesend::rules {
  9,l 290
  11,l 290
  32,l 291
  6,l 290
  28,l 291
  3,l 290
  25,l 290
  0,l 293
  22,l 290
  18,l 290
  15,l 290
  36,l 292
  12,l 290
  33,l 291
  7,l 290
  29,l 291
  30,l 291
  4,l 290
  26,l 290
  1,l 290
  23,l 290
  19,l 290
  20,l 290
  16,l 290
  37,l 292
  13,l 290
  34,l 291
  8,l 290
  10,l 290
  31,l 291
  5,l 290
  27,l 290
  2,l 290
  24,l 290
  21,l 290
  17,l 290
  14,l 290
  35,l 291
}

array set cubesend::rules {
  12,dc 1
  26,dc 1
  3,dc 1
  18,dc 1
  33,dc 2
  9,dc 1
  11,dc 1
  25,dc 1
  2,dc 1
  17,dc 1
  32,dc 1
  8,dc 1
  10,dc 1
  24,dc 1
  1,dc 1
  16,dc 1
  31,dc 1
  7,dc 1
  23,dc 1
  0,dc 1
  37,dc 1
  15,dc 1
  29,dc 1
  30,dc 1
  6,dc 1
  22,dc 1
  36,dc 0
  14,dc 1
  28,dc 0
  5,dc 1
  21,dc 1
  35,dc 1
  13,dc 1
  27,dc 1
  4,dc 1
  19,dc 1
  20,dc 1
  34,dc 2
}

array set cubesend::rules {
  7,line 81
  37,line 115
  4,line 78
  34,line 110
  1,line 75
  31,line 107
  27,line 101
  24,line 98
  21,line 95
  17,line 91
  14,line 88
  11,line 85
  9,line 83
  6,line 80
  36,line 114
  3,line 77
  33,line 109
  29,line 105
  30,line 106
  26,line 100
  23,line 97
  19,line 93
  20,line 94
  16,line 90
  13,line 87
  10,line 84
  8,line 82
  5,line 79
  35,line 111
  2,line 76
  32,line 108
  28,line 104
  25,line 99
  22,line 96
  18,line 92
  15,line 89
  12,line 86
}

array set cubesend::lr1_table {
  35 {{0 0 1}}
  36 {{37 0 1}}
  14,trans {}
  33,trans {{288 36} {292 38}}
  37 {{33 0 2}}
  38 {{34 0 2}}
  18,trans {}
  1,trans {}
  37,trans {}
  23,trans {}
  5,trans {}
  27,trans {}
  9,trans {}
  13,trans {}
  32,trans {}
  17,trans {}
  0,trans {{257 1} {258 2} {259 3} {260 4} {261 5} {262 6} {263 7} {264 8} {265 9} {266 10} {267 11} {268 12} {269 13} {270 14} {271 15} {272 16} {273 17} {274 18} {275 19} {276 20} {277 21} {278 22} {279 23} {280 24} {281 25} {282 26} {283 27} {284 28} {285 29} {286 30} {287 31} {288 32} {289 33} {290 34} {291 35}}
  36,trans {}
  22,trans {}
  4,trans {}
  26,trans {}
  8,trans {}
  12,trans {}
  31,trans {}
  16,trans {}
  35,trans {}
  21,trans {}
  3,trans {}
  10 {{10 0 1}}
  11 {{11 0 1}}
  25,trans {}
  12 {{12 0 1}}
  7,trans {}
  13 {{13 0 1}}
  14 {{14 0 1}}
  15 {{15 0 1}}
  11,trans {}
  30,trans {}
  29,trans {{288 36} {292 37}}
  16 {{16 0 1}}
  0 {{0 0 0} {28 0 0} {29 0 0} {30 0 0} {31 0 0} {32 0 0} {33 0 0} {34 0 0} {35 0 0} {1 0 0} {2 0 0} {3 0 0} {4 0 0} {5 0 0} {6 0 0} {7 0 0} {8 0 0} {9 0 0} {10 0 0} {11 0 0} {12 0 0} {13 0 0} {14 0 0} {15 0 0} {16 0 0} {17 0 0} {18 0 0} {19 0 0} {20 0 0} {21 0 0} {22 0 0} {23 0 0} {24 0 0} {25 0 0} {26 0 0} {27 0 0}}
  17 {{17 0 1}}
  1 {{1 0 1}}
  18 {{18 0 1}}
  15,trans {}
  2 {{2 0 1}}
  19 {{19 0 1}}
  20 {{20 0 1}}
  34,trans {}
  3 {{3 0 1}}
  21 {{21 0 1}}
  4 {{4 0 1}}
  22 {{22 0 1}}
  5 {{5 0 1}}
  23 {{23 0 1}}
  20,trans {}
  19,trans {}
  6 {{6 0 1}}
  24 {{24 0 1}}
  2,trans {}
  38,trans {}
  7 {{7 0 1}}
  25 {{25 0 1}}
  8 {{8 0 1}}
  26 {{26 0 1}}
  9 {{9 0 1}}
  27 {{27 0 1}}
  24,trans {}
  28 {{35 0 1}}
  6,trans {}
  29 {{33 0 1} {36 0 0} {37 0 0}}
  30 {{32 0 1}}
  31 {{29 0 1}}
  32 {{31 0 1}}
  10,trans {}
  28,trans {}
  33 {{34 0 1} {36 0 0} {37 0 0}}
  34 {{30 0 1}}
}

array set cubesend::token_id_table {
  286,t 0
  286 INTERVAL_
  280,title WCSW
  279,title WCSV
  264,line 14
  292,line 113
  287 IMAGE_
  270,t 0
  269,t 0
  288 LOCK_
  290 wcssys
  289 ORDER_
  276,line 26
  265,title WCSH
  291,t 1
  291 cubesend
  284,title AXIS
  292 order
  274,t 0
  261,line 11
  293 start'
  288,line 41
  257,t 0
  270,title WCSM
  269,title WCSL
  288,title LOCK
  273,line 23
  278,t 0
  257,line 7
  262,t 0
  285,line 38
  274,title WCSQ
  293,title {}
  283,t 0
  270,line 20
  269,line 19
  259,title WCSB
  260,title WCSC
  266,t 0
  278,title WCSU
  282,line 32
  287,t 0
  error error
  271,t 0
  264,title WCSG
  266,line 16
  283,title WCSZ
  292,t 1
  278,line 28
  error,line 73
  275,t 0
  268,title WCSK
  287,title IMAGE
  258,t 0
  263,line 13
  291,line 103
  error,title {}
  280,t 0
  279,t 0
  275,line 25
  273,title WCSP
  292,title {}
  263,t 0
  259,line 9
  260,line 10
  287,line 40
  258,title WCSA
  284,t 0
  277,title WCST
  272,line 22
  267,t 0
  263,title WCSF
  288,t 0
  284,line 37
  282,title WCSY
  272,t 0
  268,line 18
  267,title WCSJ
  293,t 1
  286,title INTERVAL
  257 WCS_
  281,line 31
  276,t 0
  258 WCSA_
  259,t 0
  259 WCSB_
  260 WCSC_
  260,t 0
  272,title WCSO
  261 WCSD_
  265,line 15
  293,line 116
  291,title {}
  262 WCSE_
  281,t 0
  263 WCSF_
  277,line 27
  257,title WCS
  264 WCSG_
  264,t 0
  276,title WCSS
  265 WCSH_
  262,line 12
  266 WCSI_
  290,line 74
  289,line 42
  285,t 0
  267 WCSJ_
  0,t 0
  0 {$}
  262,title WCSE
  268 WCSK_
  268,t 0
  281,title WCSX
  274,line 24
  270 WCSM_
  269 WCSL_
  error,t 0
  271 WCSN_
  290,t 1
  289,t 0
  272 WCSO_
  258,line 8
  286,line 39
  273,t 0
  273 WCSP_
  266,title WCSI
  285,title AXES
  274 WCSQ_
  275 WCSR_
  271,line 21
  276 WCSS_
  277,t 0
  277 WCST_
  271,title WCSN
  290,title {}
  289,title ORDER
  283,line 33
  278 WCSU_
  261,t 0
  280 WCSW_
  279 WCSV_
  281 WCSX_
  267,line 17
  282,t 0
  282 WCSY_
  275,title WCSR
  283 WCSZ_
  265,t 0
  284 AXIS_
  280,line 30
  279,line 29
  285 AXES_
  261,title WCSD
}

proc cubesend::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 _ wcs }
                    2 { set _ wcsa }
                    3 { set _ wcsb }
                    4 { set _ wcsc }
                    5 { set _ wcsd }
                    6 { set _ wcse }
                    7 { set _ wcsf }
                    8 { set _ wcsg }
                    9 { set _ wcsh }
                    10 { set _ wcsi }
                    11 { set _ wcsj }
                    12 { set _ wcsk }
                    13 { set _ wcsl }
                    14 { set _ wcsm }
                    15 { set _ wcsn }
                    16 { set _ wcso }
                    17 { set _ wcsp }
                    18 { set _ wcsq }
                    19 { set _ wcsr }
                    20 { set _ wcss }
                    21 { set _ wcst }
                    22 { set _ wcsu }
                    23 { set _ wcsv }
                    24 { set _ wcsw }
                    25 { set _ wcsx }
                    26 { set _ wcsy }
                    27 { set _ wcsz }
                    28 { ProcessSendCmdCurrent "get fits slice" }
                    29 { ProcessSendCmdCurrent "get fits slice" }
                    30 { ProcessSendCmdCurrent "get fits slice from image $1" }
                    31 { ProcessSendCmdGet cube lock }
                    32 { BlinkSendCmdInterval }
                    35 { CubeSendCmdAxis }
                    36 { ProcessSendCmdGet cube axes }
                    37 { ProcessSendCmdYesNo cube lock,axes }
                }
                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 cubesend::yyerror {msg} {
     variable yycnt
     variable yy_current_buffer
     variable index_

     ParserError $msg $yycnt $yy_current_buffer $index_
}
