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

    namespace export yylex
}

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

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

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

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

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

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

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

array set ps::rules {
  27,l 288
  9,l 284
  11,l 284
  15,l 286
  20,l 287
  19,l 287
  2,l 283
  24,l 288
  6,l 284
  28,l 288
  12,l 284
  16,l 286
  21,l 288
  3,l 282
  25,l 288
  7,l 284
  30,l 288
  29,l 288
  13,l 285
  0,l 289
  17,l 286
  22,l 288
  4,l 284
  26,l 288
  8,l 284
  10,l 284
  31,l 288
  14,l 285
  18,l 287
  1,l 282
  23,l 288
  5,l 284
}

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

array set ps::rules {
  13,line 58
  25,line 76
  2,e 1
  7,line 49
  10,line 53
  22,line 73
  4,line 46
  18,line 67
  1,line 42
  31,line 83
  15,line 62
  27,line 78
  9,line 51
  12,line 55
  24,line 75
  6,line 48
  21,line 72
  3,line 43
  17,line 64
  30,line 82
  29,line 81
  14,line 59
  26,line 77
  8,line 50
  11,line 54
  23,line 74
  5,line 47
  20,line 69
  19,line 68
  2,line 42
  16,line 63
  28,line 80
}

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

array set ps::token_id_table {
  286,t 1
  286 color
  280,title 53
  279,title 1200
  264,line 17
  1,t 0
  287 level
  270,t 0
  269,t 0
  288 resolution
  289 start'
  276,line 31
  265,title PALETTE
  284,title {}
  274,t 0
  261,line 14
  288,line 71
  257,t 0
  1,title {}
  270,title GRAY
  269,title CMYK
  288,title {}
  273,line 28
  278,t 0
  257,line 7
  262,t 0
  285,line 57
  274,title 144
  1,line 66
  283,t 1
  270,line 24
  269,line 23
  259,title COMMAND
  260,title DESTINATION
  266,t 0
  278,title 600
  282,line 41
  287,t 1
  2,t 0
  error error
  271,t 0
  264,title LEVEL
  266,line 19
  283,title {}
  278,line 33
  error,line 40
  275,t 0
  268,title RGB
  287,title {}
  258,t 0
  263,line 16
  error,title {}
  280,t 0
  279,t 0
  275,line 30
  273,title 96
  263,t 0
  259,line 12
  260,line 13
  287,line 66
  258,title COLOR
  284,t 1
  277,title 300
  3,line 68
  272,line 27
  267,t 0
  263,title INTERPOLATE
  288,t 1
  284,line 45
  282,title {}
  3,t 0
  272,t 0
  268,line 22
  267,title RESOLUTION
  286,title {}
  257 STRING_
  281,line 37
  276,t 0
  258 COLOR_
  259,t 0
  259 COMMAND_
  260 DESTINATION_
  260,t 0
  3,title {}
  272,title SCREEN
  261 FILE_
  265,line 18
  262 FILENAME_
  281,t 0
  263 INTERPOLATE_
  277,line 32
  257,title string
  264 LEVEL_
  264,t 0
  276,title 225
  265 PALETTE_
  262,line 15
  266 PRINTER_
  289,line 84
  285,t 1
  267 RESOLUTION_
  0,t 0
  0 {$}
  262,title FILENAME
  268 RGB_
  268,t 0
  1 1
  281,title 75
  274,line 29
  270 GRAY_
  269 CMYK_
  2 2
  error,t 0
  271 72_
  289,t 1
  3 3
  272 SCREEN_
  258,line 11
  286,line 61
  273,t 0
  273 96_
  266,title PRINTER
  285,title {}
  274 144_
  2,line 67
  275 150_
  271,line 26
  276 225_
  2,title {}
  277,t 0
  277 300_
  271,title 72
  289,title {}
  283,line 42
  278 600_
  261,t 0
  280 53_
  279 1200_
  281 75_
  267,line 20
  282,t 1
  282 command
  275,title 150
  283 @PSEUDO1
  265,t 0
  284 ps
  280,line 36
  279,line 34
  285 dest
  261,title FILE
}

proc ps::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} }
                    4 { PostScript }
                    5 { ProcessCmdSet ps dest $2 }
                    6 { ProcessCmdSet ps cmd $2 }
                    7 { ProcessCmdSet ps filename $2 }
                    8 { ProcessCmdSet ps color $2 }
                    9 { ProcessCmdSet ps level $2 }
                    10 { ProcessCmdSet ps resolution $2 }
                    12 { ProcessCmdSet ps color $2 }
                    13 { set _ printer }
                    14 { set _ file }
                    15 { set _ rgb }
                    16 { set _ cmyk }
                    17 { set _ gray }
                    18 { set _ 1 }
                    19 { set _ 2 }
                    20 { set _ 3 }
                    21 { set _ 72 }
                    22 { set _ 96 }
                    23 { set _ 144 }
                    24 { set _ 150 }
                    25 { set _ 225 }
                    26 { set _ 300 }
                    27 { set _ 600 }
                    28 { set _ 1200 }
                    29 { set _ 96 }
                    30 { set _ 53 }
                    31 { set _ 75 }
                }
                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 ps::yyerror {msg} {
     variable yycnt
     variable yy_current_buffer
     variable index_

     ParserError $msg $yycnt $yy_current_buffer $index_
}
