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

    namespace export yylex
}

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

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

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

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

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

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

array set nres::table {
  17:257 reduce
  0:257 shift
  0:258 shift
  23:0,target 3
  20:257 reduce
  19:257 reduce
  0:259 shift
  0:260 shift
  2:257 reduce
  5:0,target 4
  15:0,target 17
  9:0 accept
  0:261 shift
  22:257 shift
  11:0 reduce
  0:262 shift
  4:257 shift
  0:263 shift
  21:257,target 9
  0:264 shift
  3:257,target 8
  6:257 reduce
  15:0 reduce
  15:257,target 17
  0:275,target 10
  6:0,target 7
  20:0 reduce
  19:0 reduce
  16:0,target 18
  10:257,target 2
  8:276,target 21
  2:0 reduce
  0:273 goto
  0:275 goto
  6:0 reduce
  0:264,target 8
  6:257,target 7
  18:257,target 6
  8:271 shift
  1:257,target 11
  17:0,target 19
  12:0 reduce
  8:272 shift
  10:0,target 1
  13:257,target 15
  0:263,target 7
  16:0 reduce
  10:257 reduce
  8:276 goto
  0:273,target 9
  12:257 reduce
  21:0 reduce
  14:257 reduce
  7:270,target 17
  7:269,target 16
  3:0 reduce
  18:0,target 6
  1:0,target 11
  22:257,target 23
  16:257 reduce
  11:0,target 10
  0:262,target 6
  4:257,target 11
  18:257 reduce
  1:257 reduce
  16:257,target 18
  21:257 reduce
  10:274,target 22
  3:257 reduce
  7:268,target 15
  11:257,target 10
  5:257 reduce
  13:0 reduce
  9:0,target 0
  0:261,target 5
  20:0,target 13
  19:0,target 12
  2:0,target 5
  12:0,target 14
  10:274 goto
  8:272,target 20
  17:0 reduce
  7:267,target 14
  7:277,target 18
  20:257,target 13
  19:257,target 12
  0:259,target 3
  0:260,target 4
  2:257,target 5
  7:265 shift
  8:271,target 19
  7:266 shift
  21:0,target 9
  14:257,target 16
  7:267 shift
  3:0,target 8
  13:0,target 15
  7:268 shift
  7:270 shift
  7:269 shift
  7:266,target 13
  10:0 reduce
  0:258,target 2
  14:0 reduce
  5:257,target 4
  7:277 goto
  7:265,target 12
  14:0,target 16
  11:257 reduce
  18:0 reduce
  17:257,target 19
  0:257,target 1
  1:0 reduce
  13:257 reduce
  15:257 reduce
  12:257,target 14
  23:0 reduce
  5:0 reduce
}

array set nres::rules {
  9,l 275
  11,l 275
  15,l 277
  19,l 277
  2,l 274
  6,l 275
  12,l 276
  16,l 277
  3,l 273
  7,l 275
  13,l 276
  0,l 278
  17,l 277
  4,l 275
  8,l 275
  10,l 275
  14,l 277
  18,l 277
  1,l 273
  5,l 275
}

array set nres::rules {
  5,dc 1
  0,dc 1
  17,dc 1
  12,dc 1
  8,dc 1
  3,dc 3
  15,dc 1
  10,dc 2
  6,dc 2
  18,dc 1
  1,dc 1
  13,dc 1
  9,dc 2
  4,dc 1
  16,dc 1
  11,dc 1
  7,dc 1
  19,dc 1
  2,dc 0
  14,dc 1
}

array set nres::rules {
  13,line 47
  2,e 1
  7,line 39
  10,line 42
  4,line 36
  18,line 54
  1,line 32
  15,line 51
  9,line 41
  12,line 46
  6,line 38
  3,line 33
  17,line 53
  14,line 50
  8,line 40
  11,line 43
  5,line 37
  19,line 55
  2,line 32
  16,line 52
}

array set nres::lr1_table {
  14,trans {}
  1,trans {}
  18,trans {}
  5,trans {}
  23,trans {}
  9,trans {}
  13,trans {}
  0,trans {{257 1} {258 2} {259 3} {260 4} {261 5} {262 6} {263 7} {264 8} {273 9} {275 10}}
  17,trans {}
  4,trans {{257 11}}
  22,trans {{257 23}}
  8,trans {{271 19} {272 20} {276 21}}
  12,trans {}
  16,trans {}
  3,trans {}
  21,trans {}
  10 {{1 0 1} {3 0 1} {2 257 0}}
  11 {{10 {0 257} 2}}
  12 {{14 {0 257} 1}}
  7,trans {{265 12} {266 13} {267 14} {268 15} {269 16} {270 17} {277 18}}
  13 {{15 {0 257} 1}}
  14 {{16 {0 257} 1}}
  15 {{17 {0 257} 1}}
  11,trans {}
  16 {{18 {0 257} 1}}
  0 {{0 0 0} {1 0 0} {3 0 0} {4 {0 257} 0} {5 {0 257} 0} {6 {0 257} 0} {7 {0 257} 0} {8 {0 257} 0} {9 {0 257} 0} {10 {0 257} 0} {11 {0 257} 0}}
  17 {{19 {0 257} 1}}
  1 {{11 {0 257} 1}}
  18 {{6 {0 257} 2}}
  2 {{5 {0 257} 1}}
  19 {{12 {0 257} 1}}
  20 {{13 {0 257} 1}}
  15,trans {}
  3 {{8 {0 257} 1}}
  21 {{9 {0 257} 2}}
  4 {{10 {0 257} 1}}
  22 {{3 0 2}}
  5 {{4 {0 257} 1}}
  23 {{3 0 3}}
  6 {{7 {0 257} 1}}
  2,trans {}
  19,trans {}
  20,trans {}
  7 {{6 {0 257} 1} {14 {0 257} 0} {15 {0 257} 0} {16 {0 257} 0} {17 {0 257} 0} {18 {0 257} 0} {19 {0 257} 0}}
  8 {{9 {0 257} 1} {12 {0 257} 0} {13 {0 257} 0}}
  9 {{0 0 1}}
  6,trans {}
  10,trans {{274 22}}
}

array set nres::token_id_table {
  264,line 17
  270,t 0
  269,t 0
  276,line 45
  265,title NEDSAO
  274,t 1
  261,line 14
  257,t 0
  270,title VIZIERCDS
  269,title VIZIERSAO
  273,line 31
  278,t 1
  257,line 7
  262,t 0
  274,title {}
  270,line 24
  269,line 23
  259,title CROSSHAIR
  260,title NAME
  266,t 0
  278,title {}
  error error
  271,t 0
  264,title SKYFORMAT
  266,line 20
  278,line 56
  275,t 1
  error,line 30
  268,title SIMBADCDS
  258,t 0
  263,line 16
  error,title {}
  275,line 35
  273,title {}
  263,t 0
  259,line 12
  260,line 13
  258,title CLOSE
  277,title {}
  272,line 27
  267,t 0
  263,title SERVER
  272,t 0
  268,line 22
  267,title SIMBADSAO
  257 STRING_
  276,t 1
  258 CLOSE_
  259,t 0
  259 CROSSHAIR_
  260 NAME_
  260,t 0
  272,title SEXAGESIMAL
  261 OPEN_
  265,line 19
  262 PAN_
  263 SERVER_
  277,line 49
  257,title string
  264 SKYFORMAT_
  264,t 0
  276,title {}
  265 NEDSAO_
  262,line 15
  266 NEDCDS_
  267 SIMBADSAO_
  0,t 0
  0 {$}
  262,title PAN
  268 SIMBADCDS_
  268,t 0
  274,line 32
  270 VIZIERCDS_
  269 VIZIERSAO_
  error,t 0
  271 DEGREES_
  272 SEXAGESIMAL_
  258,line 11
  273,t 1
  273 command
  266,title NEDCDS
  274 @PSEUDO1
  275 nres
  271,line 26
  276 skyformat
  277,t 1
  277 server
  271,title DEGREES
  278 start'
  261,t 0
  267,line 21
  275,title {}
  265,t 0
  261,title OPEN
}

proc nres::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 {
                    2 { global ds9; if {!$ds9(init)} {YYERROR} else {yyclearin; YYACCEPT} }
                    5 { ARDestroy dnres }
                    6 { ProcessCmdSet pnres server $2 }
                    7 { NRESPan dnres }
                    8 { NRESCrosshair dnres }
                    9 { ProcessCmdSet2 dnres skyformat $2 format,msg $2 }
                    10 { ProcessCmdSet dnres name $2 "NRESApply dnres 1" }
                    11 { ProcessCmdSet dnres name $1 "NRESApply dnres 1" }
                    12 { set _ degrees }
                    13 { set _ sexagesimal }
                    14 { set _ ned-sao }
                    15 { set _ ned-cds }
                    16 { set _ simbad-sao }
                    17 { set _ simbad-cds }
                    18 { set _ vizier-sao }
                    19 { set _ vizier-cds }
                }
                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 nres::yyerror {msg} {
     variable yycnt
     variable yy_current_buffer
     variable index_

     ParserError $msg $yycnt $yy_current_buffer $index_
}
