Index: modules/pt/pkgIndex.tcl ================================================================== --- modules/pt/pkgIndex.tcl +++ modules/pt/pkgIndex.tcl @@ -49,12 +49,12 @@ # Import core functionality: Conversion from a specific format to PEG. package ifneeded pt::peg::from::json 1 [list source [file join $dir pt_peg_from_json.tcl]] package ifneeded pt::peg::from::peg 1.0.3 [list source [file join $dir pt_peg_from_peg.tcl]] # PARAM runtime. -package ifneeded pt::rde 1.0.3 [list source [file join $dir pt_rdengine.tcl]] -package ifneeded pt::rde::oo 1.0.3 [list source [file join $dir pt_rdengine_oo.tcl]] +package ifneeded pt::rde 1.1 [list source [file join $dir pt_rdengine.tcl]] +package ifneeded pt::rde::oo 1.1 [list source [file join $dir pt_rdengine_oo.tcl]] # PEG grammar specification, as CONTAINER package ifneeded pt::peg::container::peg 1 [list source [file join $dir pt_peg_container_peg.tcl]] # */PARAM support (canned configurations). Index: modules/pt/pt_rdengine.man ================================================================== --- modules/pt/pt_rdengine.man +++ modules/pt/pt_rdengine.man @@ -1,13 +1,13 @@ -[vset VERSION 1.0.3] +[vset VERSION 1.1] [comment {-*- text -*- doctools manpage}] [manpage_begin pt::rde n [vset VERSION]] [include include/module.inc] [titledesc {Parsing Runtime Support, PARAM based}] [require pt::rde [opt [vset VERSION]]] [require snit] -[require struct::stack 1.4] +[require struct::stack 1.5] [require pt::ast 1.1] [description] [include include/ref_intro.inc] This package provides a class whose instances provide the runtime Index: modules/pt/pt_rdengine.tcl ================================================================== --- modules/pt/pt_rdengine.tcl +++ modules/pt/pt_rdengine.tcl @@ -1,8 +1,8 @@ # -*- tcl -*- # -# Copyright (c) 2009-2014 by Andreas Kupries +# Copyright (c) 2009-2015 by Andreas Kupries # # ## ### ##### ######## ############# ##################### ## Package description ## Implementation of the PackRat Machine (PARAM), a virtual machine on @@ -21,11 +21,18 @@ package require Tcl 8.5 namespace eval ::pt::rde {} # # ## ### ##### ######## ############# ##################### -## Management of stack implementations. +## Support narrative tracing. + +package require debug +debug level pt/rdengine +debug prefix pt/rdengine {} + +# # ## ### ##### ######## ############# ##################### +## Management of RDengine implementations. # ::pt::rde::LoadAccelerator -- # # Loads a named implementation, if possible. # @@ -35,10 +42,11 @@ # Results: # A boolean flag. True if the implementation # was successfully loaded; and False otherwise. proc ::pt::rde::LoadAccelerator {key} { + debug.pt/rdengine {[info level 0]} variable accel set r 0 switch -exact -- $key { critcl { if {![package vsatisfies [package provide Tcl] 8.5]} {return 0} @@ -54,10 +62,11 @@ return -code error "invalid accelerator/impl. package $key:\ must be one of [join [KnownImplementations] {, }]" } } set accel($key) $r + debug.pt/rdengine {[info level 0] ==> ($r)} return $r } # ::pt::rde::SwitchTo -- # @@ -68,18 +77,21 @@ # # Results: # None. proc ::pt::rde::SwitchTo {key} { + debug.pt/rdengine {[info level 0]} variable accel variable loaded if {$key eq $loaded} { # No change, nothing to do. + debug.pt/rdengine {[info level 0] == $loaded /no change} return } elseif {$key ne {}} { # Validate the target implementation of the switch. + debug.pt/rdengine {[info level 0] validate} if {![info exists accel($key)]} { return -code error "Unable to activate unknown implementation \"$key\"" } elseif {![info exists accel($key)] || !$accel($key)} { return -code error "Unable to activate missing implementation \"$key\"" @@ -87,23 +99,26 @@ } # Deactivate the previous implementation, if there was any. if {$loaded ne {}} { + debug.pt/rdengine {[info level 0] disable $loaded} rename ::pt::rde ::pt::rde_$loaded } # Activate the new implementation, if there is any. if {$key ne {}} { + debug.pt/rdengine {[info level 0] enable $key} rename ::pt::rde_$key ::pt::rde } # Remember the active implementation, for deactivation by future # switches. set loaded $key + debug.pt/rdengine {[info level 0] /done} return } # ::pt::rde::Implementations -- # @@ -115,16 +130,18 @@ # # Results: # A list of implementation keys. proc ::pt::rde::Implementations {} { + debug.pt/rdengine {[info level 0]} variable accel set res {} foreach n [array names accel] { if {!$accel($n)} continue lappend res $n } + debug.pt/rdengine {[info level 0] ==> ($res)} return $res } # ::pt::rde::KnownImplementations -- # @@ -137,14 +154,16 @@ # Results: # A list of implementation keys. In the order # of preference, most prefered first. proc ::pt::rde::KnownImplementations {} { + debug.pt/rdengine {[info level 0]} return {critcl tcl} } proc ::pt::rde::Names {} { + debug.pt/rdengine {[info level 0]} return { critcl {tcllibc based} tcl {pure Tcl} } } @@ -182,6 +201,6 @@ namespace eval ::pt { # Export the constructor command. namespace export rde } -package provide pt::rde 1.0.3 +package provide pt::rde 1.1 Index: modules/pt/pt_rdengine_c.tcl ================================================================== --- modules/pt/pt_rdengine_c.tcl +++ modules/pt/pt_rdengine_c.tcl @@ -1,8 +1,8 @@ # -*- tcl -*- # -# Copyright (c) 2009-2014 by Andreas Kupries +# Copyright (c) 2009-2015 by Andreas Kupries # # ## ### ##### ######## ############# ##################### ## Package description ## Implementation of the PackRat Machine (PARAM), a virtual machine on @@ -162,7 +162,7 @@ } # # ## ### ##### ######## ############# ##################### ## Ready -package provide pt::rde::critcl 1.0.3 +package provide pt::rde::critcl 1.3.3 return Index: modules/pt/pt_rdengine_oo.tcl ================================================================== --- modules/pt/pt_rdengine_oo.tcl +++ modules/pt/pt_rdengine_oo.tcl @@ -1,8 +1,8 @@ # -*- tcl -*- # -# Copyright (c) 2009-2014 by Andreas Kupries +# Copyright (c) 2009-2015 by Andreas Kupries # # ## ### ##### ######## ############# ##################### ## Package description ## Implementation of the PackRat Machine (PARAM), a virtual machine on @@ -16,35 +16,116 @@ # # ## ### ##### ######## ############# ##################### ## Requisites package require Tcl 8.5 package require TclOO -package require struct::stack 1.4 ; # Requiring get, trim methods +package require struct::stack 1.5 ; # Requiring peekr, getr, get, trim* methods package require pt::ast package require pt::pe + +# # ## ### ##### ######## ############# ##################### +## Support narrative tracing. + +package require debug +debug level pt/rdengine +debug prefix pt/rdengine {} + # # ## ### ##### ######## ############# ##################### ## Implementation oo::class create ::pt::rde::oo { + # # ## ### ##### ######## ############# ##################### + ## Instruction counter for tracing. Unused else. Plus other helpers. + + method TraceInitialization {} { + # Creation of the tracing support procedures. + # Conditional on debug tag "pt/rdengine". + # The instance namespace is the current context. + # This is where the procedures go. + + proc Instruction {label {a {}} {b {}}} { + upvar 1 mytracecounter mytracecounter myok myok myloc myloc mycurrent mycurrent mysvalue mysvalue myerror myerror __inst theinst + set theinst [list $label $a $b] + return "[uplevel 1 self] <<[format %08d [incr mytracecounter]]>> START I:[format %-30s $label] [format %-10s $a] [format %-10s $b] :: [State]" + } + + proc InstReturn {} { + upvar 1 mytracecounter mytracecounter myok myok myloc myloc mycurrent mycurrent mysvalue mysvalue myerror myerror __inst theinst + lassign $theinst label a b + return "[uplevel 1 self] <<[format %08d $mytracecounter]>> END__ I:[format %-30s $label] [format %-10s $a] [format %-10s $b] :: [State]" + } + + proc State {} { + upvar 1 myok myok myloc myloc mycurrent mycurrent mysvalue mysvalue myerror myerror + set sv [expr {[info exists mysvalue] ? $mysvalue : ""}] + return "ST $myok CL $myloc CC ($mycurrent) SV ($sv) ER ($myerror)" + } + + proc TraceSetupStacks {} { + set selfns [namespace current] + + # Move stack instances aside. + rename ${selfns}::LOC ${selfns}::LOC__ + rename ${selfns}::ERR ${selfns}::ERR__ + rename ${selfns}::AST ${selfns}::AST__ + rename ${selfns}::MARK ${selfns}::MRK__ + + # Create procedures doing tracing, and forwarding to + # the renamed actual instances. + + interp alias {} ${selfns}::LOC {} ${selfns}::WRAP LS LOC__ + interp alias {} ${selfns}::ERR {} ${selfns}::WRAP ES ERR__ + interp alias {} ${selfns}::AST {} ${selfns}::WRAP ARS AST__ + interp alias {} ${selfns}::MARK {} ${selfns}::WRAP ASM MRK__ + + proc WRAP {label stack args} { + debug.pt/rdengine { $label ___ $args} + set res [$stack {*}$args] + + # Show state state after the op + set n [$stack size] + if {!$n} { + set c {()} + } elseif {$n == 1} { + set c <<[$stack peek $n]>> + } else { + set c <<[join [$stack peek $n] {>> <<}]>> + } + debug.pt/rdengine { $label == ($n):$c} + + # And op return + debug.pt/rdengine { $label ==> ($res)} + return $res + } + return + } + + return + } # # ## ### ##### ######## ############# ##################### ## API - Lifecycle constructor {} { - set selfns [self namespace] + debug.pt/rdengine {[my TraceInitialization][self] constructor} - set mystackloc [struct::stack ${selfns}::LOC] ; # LS - set mystackerr [struct::stack ${selfns}::ERR] ; # ES - set mystackast [struct::stack ${selfns}::AST] ; # ARS/AS - set mystackmark [struct::stack ${selfns}::MARK] ; # s.a. + #set selfns [self namespace] + set mystackloc [struct::stack LOC] ; # LS + set mystackerr [struct::stack ERR] ; # ES + set mystackast [struct::stack AST] ; # ARS/AS + set mystackmark [struct::stack MARK] ; # s.a. + + debug.pt/rdengine {[TraceSetupStacks][self] constructor /done} my reset {} return } method reset {chan} { + debug.pt/rdengine {[self] reset ($chan)} + set mychan $chan ; # IN set mycurrent {} ; # CC set myloc -1 ; # CL set myok 0 ; # ST set msvalue {} ; # SV @@ -54,115 +135,148 @@ $mystackloc clear $mystackerr clear $mystackast clear $mystackmark clear - return - } - method data {string} { - append mytoken $string + debug.pt/rdengine {[self] reset /done} return } method complete {} { + debug.pt/rdengine {[self] complete [State]} + if {$myok} { set n [$mystackast size] + debug.pt/rdengine {[self] complete ast $n} if {$n > 1} { + # Multiple ASTs left, reduce into single containing them. set pos [$mystackloc peek] incr pos - set children [lreverse [$mystackast peek [$mystackast size]]] ; # SaveToMark - return [pt::ast new {} $pos $myloc {*}$children] ; # Reduce ALL + set children [$mystackast peekr [$mystackast size]] ; # SaveToMark + set ast [pt::ast new {} $pos $myloc {*}$children] ; # Reduce ALL + + debug.pt/rdengine {[self] complete n ==> ($ast)} + return $ast } elseif {$n == 0} { # Match, but no AST. This is possible if the grammar # consists of only the start expression. + + debug.pt/rdengine {[self] complete 0 ==> ()} return {} } else { - return [$mystackast peek] + # Match, with AST. + set ast [$mystackast peek] + debug.pt/rdengine {[self] complete 1 ==> ($ast)} + return $ast } } else { lassign $myerror loc messages - return -code error [list pt::rde $loc $messages] + return -code error \ + -errorcode {PT RDE SYNTAX} \ + [list pt::rde $loc $messages] } } # # ## ### ##### ######## ############# ##################### ## API - State accessors - method chan {} { return $mychan } + method chan {} { debug.pt/rdengine {[self] chan} ; return $mychan } # - - -- --- ----- -------- - method current {} { return $mycurrent } - method location {} { return $myloc } - method lmarked {} { return [lreverse [$mystackloc get]] } + method current {} { debug.pt/rdengine {[self] current} ; return $mycurrent } + method location {} { debug.pt/rdengine {[self] location} ; return $myloc } + method lmarked {} { debug.pt/rdengine {[self] lmarked} ; return [$mystackloc getr] } # - - -- --- ----- -------- - method ok {} { return $myok } - method value {} { return $mysvalue } - method error {} { return $myerror } - method emarked {} { return [lreverse [$mystackerr get]] } + method ok {} { debug.pt/rdengine {[self] ok} ; return $myok } + method value {} { debug.pt/rdengine {[self] value} ; return $mysvalue } + method error {} { debug.pt/rdengine {[self] error} ; return $myerror } + method emarked {} { debug.pt/rdengine {[self] emarked} ; return [$mystackerr getr] } # - - -- --- ----- -------- method tokens {{from {}} {to {}}} { + debug.pt/rdengine {[self] tokens ($from) ($to)} switch -exact [llength [info level 0]] { 4 { return $mytoken } 5 { return [string range $mytoken $from $from] } 6 { return [string range $mytoken $from $to] } } } method symbols {} { + debug.pt/rdengine {[self] symbols} return [array get mysymbol] } method scached {} { + debug.pt/rdengine {[self] scached} return [array names mysymbol] } # - - -- --- ----- -------- - method asts {} { return [lreverse [$mystackast get]] } - method amarked {} { return [lreverse [$mystackmark get]] } - method ast {} { return [$mystackast peek] } + method asts {} { debug.pt/rdengine {[self] asts} ; return [$mystackast getr] } + method amarked {} { debug.pt/rdengine {[self] amarked} ; return [$mystackmark getr] } + method ast {} { debug.pt/rdengine {[self] ast} ; return [$mystackast peek] } + + # # ## ### ##### ######## ############# ##################### + ## API - Preloading the token cache. + + method data {string} { + debug.pt/rdengine {[self] data +[string length $string]} + append mytoken $string + return + } # # ## ### ##### ######## ############# ##################### ## Common instruction sequences - method si:void_state_push {} { ;#X + method si:void_state_push {} { + debug.pt/rdengine {[Instruction si:void_state_push]} # i_loc_push # i_error_clear_push $mystackloc push $myloc set myerror {} $mystackerr push {} + + debug.pt/rdengine {[InstReturn]} return } - method si:void2_state_push {} { ;#X + method si:void2_state_push {} { + debug.pt/rdengine {[Instruction si:void2_state_push]} # i_loc_push # i_error_push $mystackloc push $myloc $mystackerr push {} + + debug.pt/rdengine {[InstReturn]} return } - method si:value_state_push {} { ;#X + method si:value_state_push {} { + debug.pt/rdengine {[Instruction si:value_state_push]} # i_ast_push # i_loc_push # i_error_clear_push $mystackmark push [$mystackast size] $mystackloc push $myloc set myerror {} $mystackerr push {} + + debug.pt/rdengine {[InstReturn]} return } # - -- --- ----- -------- ------------- --------------------- method si:void_state_merge {} { + debug.pt/rdengine {[Instruction si:void_state_merge]} # i_error_pop_merge # i_loc_pop_rewind/discard set olderror [$mystackerr pop] # We have either old or new error data, keep it. @@ -182,16 +296,19 @@ set myerror [list $loe [lsort -uniq [list {*}$msgse {*}$msgsn]]] } } set last [$mystackloc pop] - if {$myok} return - set myloc $last + if {!$myok} { + set myloc $last + } + debug.pt/rdengine {[InstReturn]} return } method si:void_state_merge_ok {} { + debug.pt/rdengine {[Instruction si:void_state_merge_ok]} # i_error_pop_merge # i_loc_pop_rewind/discard # i_status_ok set olderror [$mystackerr pop] @@ -212,17 +329,21 @@ set myerror [list $loe [lsort -uniq [list {*}$msgse {*}$msgsn]]] } } set last [$mystackloc pop] - if {$myok} return - set myloc $last - set myok 1 + if {!$myok} { + set myloc $last + set myok 1 + } + + debug.pt/rdengine {[InstReturn]} return } method si:value_state_merge {} { + debug.pt/rdengine {[Instruction si:value_state_merge]} # i_error_pop_merge # i_ast_pop_rewind/discard # i_loc_pop_rewind/discard set olderror [$mystackerr pop] @@ -244,37 +365,47 @@ } } set mark [$mystackmark pop] set last [$mystackloc pop] - if {$myok} return - $mystackast trim* $mark - set myloc $last + if {!$myok} { + $mystackast trim* $mark + set myloc $last + } + + debug.pt/rdengine {[InstReturn]} return } # - -- --- ----- -------- ------------- --------------------- method si:value_notahead_start {} { + debug.pt/rdengine {[Instruction si:value_notahead_start]} # i_loc_push # i_ast_push $mystackloc push $myloc $mystackmark push [$mystackast size] + + debug.pt/rdengine {[InstReturn]} return } method si:void_notahead_exit {} { + debug.pt/rdengine {[Instruction si:void_notahead_exit]} # i_loc_pop_rewind # i_status_negate set myloc [$mystackloc pop] set myok [expr {!$myok}] + + debug.pt/rdengine {[InstReturn]} return } method si:value_notahead_exit {} { + debug.pt/rdengine {[Instruction si:value_notahead_exit]} # i_ast_pop_discard/rewind # i_loc_pop_rewind # i_status_negate set mark [$mystackmark pop] @@ -281,26 +412,34 @@ if {$myok} { $mystackast trim* $mark } set myloc [$mystackloc pop] set myok [expr {!$myok}] + + debug.pt/rdengine {[InstReturn]} return } # - -- --- ----- -------- ------------- --------------------- method si:kleene_abort {} { + debug.pt/rdengine {[Instruction si:kleene_abort]} # i_loc_pop_rewind/discard # i:fail_return set last [$mystackloc pop] - if {$myok} return + if {$myok} { + debug.pt/rdengine {[InstReturn]} + return + } set myloc $last + debug.pt/rdengine {[InstReturn]} return -code return } method si:kleene_close {} { + debug.pt/rdengine {[Instruction si:kleene_close]} # i_error_pop_merge # i_loc_pop_rewind/discard # i:fail_status_ok # i:fail_return @@ -322,19 +461,25 @@ set myerror [list $loe [lsort -uniq [list {*}$msgse {*}$msgsn]]] } } set last [$mystackloc pop] - if {$myok} return + if {$myok} { + debug.pt/rdengine {[InstReturn]} + return + } set myok 1 set myloc $last + + debug.pt/rdengine {[InstReturn]} return -code return } # - -- --- ----- -------- ------------- --------------------- method si:voidvoid_branch {} { + debug.pt/rdengine {[Instruction si:voidvoid_branch]} # i_error_pop_merge # i:ok_loc_pop_discard # i:ok_return # i_loc_rewind # i_error_push @@ -358,18 +503,22 @@ } } if {$myok} { $mystackloc pop + debug.pt/rdengine {[InstReturn]} return -code return } set myloc [$mystackloc peek] $mystackerr push $myerror + + debug.pt/rdengine {[InstReturn]} return } method si:voidvalue_branch {} { + debug.pt/rdengine {[Instruction si:voidvalue_branch]} # i_error_pop_merge # i:ok_loc_pop_discard # i:ok_return # i_ast_push # i_loc_rewind @@ -394,19 +543,23 @@ } } if {$myok} { $mystackloc pop + debug.pt/rdengine {[InstReturn]} return -code return } $mystackmark push [$mystackast size] set myloc [$mystackloc peek] $mystackerr push {} + + debug.pt/rdengine {[InstReturn]} return } method si:valuevoid_branch {} { + debug.pt/rdengine {[Instruction si:valuevoid_branch]} # i_error_pop_merge # i_ast_pop_rewind/discard # i:ok_loc_pop_discard # i:ok_return # i_loc_rewind @@ -431,19 +584,23 @@ } } set mark [$mystackmark pop] if {$myok} { $mystackloc pop + debug.pt/rdengine {[InstReturn]} return -code return } $mystackast trim* $mark set myloc [$mystackloc peek] $mystackerr push {} + + debug.pt/rdengine {[InstReturn]} return } method si:valuevalue_branch {} { + debug.pt/rdengine {[Instruction si:valuevalue_branch]} # i_error_pop_merge # i_ast_pop_discard # i:ok_loc_pop_discard # i:ok_return # i_ast_rewind @@ -469,21 +626,26 @@ } } if {$myok} { $mystackmark pop $mystackloc pop + + debug.pt/rdengine {[InstReturn]} return -code return } $mystackast trim* [$mystackmark peek] set myloc [$mystackloc peek] $mystackerr push {} + + debug.pt/rdengine {[InstReturn]} return } # - -- --- ----- -------- ------------- --------------------- method si:voidvoid_part {} { + debug.pt/rdengine {[Instruction si:voidvoid_part]} # i_error_pop_merge # i:fail_loc_pop_rewind # i:fail_return # i_error_push @@ -505,17 +667,21 @@ set myerror [list $loe [lsort -uniq [list {*}$msgse {*}$msgsn]]] } } if {!$myok} { set myloc [$mystackloc pop] + debug.pt/rdengine {[InstReturn]} return -code return } $mystackerr push $myerror + + debug.pt/rdengine {[InstReturn]} return } method si:voidvalue_part {} { + debug.pt/rdengine {[Instruction si:voidvalue_part]} # i_error_pop_merge # i:fail_loc_pop_rewind # i:fail_return # i_ast_push # i_error_push @@ -538,18 +704,22 @@ set myerror [list $loe [lsort -uniq [list {*}$msgse {*}$msgsn]]] } } if {!$myok} { set myloc [$mystackloc pop] + debug.pt/rdengine {[InstReturn]} return -code return } $mystackmark push [$mystackast size] $mystackerr push $myerror + + debug.pt/rdengine {[InstReturn]} return } method si:valuevalue_part {} { + debug.pt/rdengine {[Instruction si:valuevalue_part]} # i_error_pop_merge # i:fail_ast_pop_rewind # i:fail_loc_pop_rewind # i:fail_return # i_error_push @@ -573,21 +743,26 @@ } } if {!$myok} { $mystackast trim* [$mystackmark pop] set myloc [$mystackloc pop] + + debug.pt/rdengine {[InstReturn]} return -code return } $mystackerr push $myerror + + debug.pt/rdengine {[InstReturn]} return } # - -- --- ----- -------- ------------- --------------------- method si:next_str {tok} { - # String = sequence of characters. No need for all the intermediate - # stack churn. + debug.pt/rdengine {[Instruction si:next_str $tok]} + # String = sequence of characters. + # No need for all the intermediate stack churn. set n [string length $tok] set last [expr {$myloc + $n}] set max [string length $mytoken] @@ -594,14 +769,23 @@ incr myloc if {($last >= $max) && ![my ExtendTCN [expr {$last - $max + 1}]]} { set myok 0 set myerror [list $myloc [list [list str $tok]]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set lex [string range $mytoken $myloc $last] set mycurrent [string index $mytoken $last] + + # ATTENTION: The error output of this instruction is different + # from a regular sequence of si:next_char instructions. The + # error location will be the start of the string token we + # wanted to match, and the message will contain the entire + # string token. In the regular sequence we would see the exact + # point of the mismatch instead, with the message containing + # the expected character. set myok [expr {$tok eq $lex}] if {$myok} { set myloc $last @@ -608,14 +792,16 @@ set myerror {} } else { set myerror [list $myloc [list [list str $tok]]] incr myloc -1 } + debug.pt/rdengine {[InstReturn]} return } method si:next_class {tok} { + debug.pt/rdengine {[Instruction si:next_class $tok]} # Class = Choice of characters. No need for stack churn. # i_input_next "\{t $c\}" # i:fail_return # i_test_ @@ -623,10 +809,11 @@ incr myloc if {($myloc >= [string length $mytoken]) && ![my ExtendTC]} { set myok 0 set myerror [list $myloc [list [list cl $tok]]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] # Note what is needle versus hay. The token, i.e. the string @@ -638,23 +825,26 @@ set myerror {} } else { set myerror [list $myloc [list [list cl $tok]]] incr myloc -1 } + debug.pt/rdengine {[InstReturn]} return } method si:next_char {tok} { + debug.pt/rdengine {[Instruction si:next_char $tok]} # i_input_next "\{t $c\}" # i:fail_return # i_test_char $c incr myloc if {($myloc >= [string length $mytoken]) && ![my ExtendTC]} { set myok 0 set myerror [list $myloc [list [list t $tok]]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] set myok [expr {$tok eq $mycurrent}] @@ -662,23 +852,26 @@ set myerror {} } else { set myerror [list $myloc [list [list t $tok]]] incr myloc -1 } + debug.pt/rdengine {[InstReturn]} return } method si:next_range {toks toke} { + debug.pt/rdengine {[Instruction si:next_range $toks $toke]} #Asm::Ins i_input_next "\{.. $s $e\}" #Asm::Ins i:fail_return #Asm::Ins i_test_range $s $e incr myloc if {($myloc >= [string length $mytoken]) && ![my ExtendTC]} { set myok 0 set myerror [list $myloc [list [list .. $toks $toke]]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] set myok [expr { @@ -689,25 +882,28 @@ set myerror {} } else { set myerror [list $myloc [list [pt::pe range $toks $toke]]] incr myloc -1 } + debug.pt/rdengine {[InstReturn]} return } # - -- --- ----- -------- ------------- --------------------- - method si:next_alnum {} { ; #TRACE puts "[format %8d [incr count]] RDE si:next_alnum" + method si:next_alnum {} { + debug.pt/rdengine {[Instruction si:next_alnum]} #Asm::Ins i_input_next alnum #Asm::Ins i:fail_return #Asm::Ins i_test_alnum incr myloc if {($myloc >= [string length $mytoken]) && ![my ExtendTC]} { set myok 0 set myerror [list $myloc [list alnum]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] set myok [string is alnum -strict $mycurrent] @@ -715,23 +911,26 @@ set myerror [list $myloc [list alnum]] incr myloc -1 } else { set myerror {} } + debug.pt/rdengine {[InstReturn]} return } - method si:next_alpha {} { ; #TRACE puts "[format %8d [incr count]] RDE si:next_alpha" + method si:next_alpha {} { + debug.pt/rdengine {[Instruction si:next_alpha]} #Asm::Ins i_input_next alpha #Asm::Ins i:fail_return #Asm::Ins i_test_alpha incr myloc if {($myloc >= [string length $mytoken]) && ![my ExtendTC]} { set myok 0 set myerror [list $myloc [list alpha]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] set myok [string is alpha -strict $mycurrent] @@ -739,23 +938,26 @@ set myerror [list $myloc [list alpha]] incr myloc -1 } else { set myerror {} } + debug.pt/rdengine {[InstReturn]} return } - method si:next_ascii {} { ; #TRACE puts "[format %8d [incr count]] RDE si:next_ascii" + method si:next_ascii {} { + debug.pt/rdengine {[Instruction si:next_ascii]} #Asm::Ins i_input_next ascii #Asm::Ins i:fail_return #Asm::Ins i_test_ascii incr myloc if {($myloc >= [string length $mytoken]) && ![my ExtendTC]} { set myok 0 set myerror [list $myloc [list ascii]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] set myok [string is ascii -strict $mycurrent] @@ -763,23 +965,26 @@ set myerror [list $myloc [list ascii]] incr myloc -1 } else { set myerror {} } + debug.pt/rdengine {[InstReturn]} return } - method si:next_control {} { ; #TRACE puts "[format %8d [incr count]] RDE si:next_control" + method si:next_control {} { + debug.pt/rdengine {[Instruction si:next_control]} #Asm::Ins i_input_next control #Asm::Ins i:fail_return #Asm::Ins i_test_control incr myloc if {($myloc >= [string length $mytoken]) && ![my ExtendTC]} { set myok 0 set myerror [list $myloc [list control]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] set myok [string is control -strict $mycurrent] @@ -787,23 +992,26 @@ set myerror [list $myloc [list control]] incr myloc -1 } else { set myerror {} } + debug.pt/rdengine {[InstReturn]} return } - method si:next_ddigit {} { ; #TRACE puts "[format %8d [incr count]] RDE si:next_ddigit" + method si:next_ddigit {} { + debug.pt/rdengine {[Instruction si:next_ddigit]} #Asm::Ins i_input_next ddigit #Asm::Ins i:fail_return #Asm::Ins i_test_ddigit incr myloc if {($myloc >= [string length $mytoken]) && ![my ExtendTC]} { set myok 0 set myerror [list $myloc [list ddigit]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] set myok [string match {[0-9]} $mycurrent] @@ -811,23 +1019,26 @@ set myerror [list $myloc [list ddigit]] incr myloc -1 } else { set myerror {} } + debug.pt/rdengine {[InstReturn]} return } - method si:next_digit {} { ; #TRACE puts "[format %8d [incr count]] RDE si:next_digit" + method si:next_digit {} { + debug.pt/rdengine {[Instruction si:next_digit]} #Asm::Ins i_input_next digit #Asm::Ins i:fail_return #Asm::Ins i_test_digit incr myloc if {($myloc >= [string length $mytoken]) && ![my ExtendTC]} { set myok 0 set myerror [list $myloc [list digit]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] set myok [string is digit -strict $mycurrent] @@ -835,23 +1046,26 @@ set myerror [list $myloc [list digit]] incr myloc -1 } else { set myerror {} } + debug.pt/rdengine {[InstReturn]} return } - method si:next_graph {} { ; #TRACE puts "[format %8d [incr count]] RDE si:next_graph" + method si:next_graph {} { + debug.pt/rdengine {[Instruction si:next_graph]} #Asm::Ins i_input_next graph #Asm::Ins i:fail_return #Asm::Ins i_test_graph incr myloc if {($myloc >= [string length $mytoken]) && ![my ExtendTC]} { set myok 0 set myerror [list $myloc [list graph]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] set myok [string is graph -strict $mycurrent] @@ -859,23 +1073,26 @@ set myerror [list $myloc [list graph]] incr myloc -1 } else { set myerror {} } + debug.pt/rdengine {[InstReturn]} return } - method si:next_lower {} { ; #TRACE puts "[format %8d [incr count]] RDE si:next_lower" + method si:next_lower {} { + debug.pt/rdengine {[Instruction si:next_lower]} #Asm::Ins i_input_next lower #Asm::Ins i:fail_return #Asm::Ins i_test_lower incr myloc if {($myloc >= [string length $mytoken]) && ![my ExtendTC]} { set myok 0 set myerror [list $myloc [list lower]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] set myok [string is lower -strict $mycurrent] @@ -883,23 +1100,26 @@ set myerror [list $myloc [list lower]] incr myloc -1 } else { set myerror {} } + debug.pt/rdengine {[InstReturn]} return } - method si:next_print {} { ; #TRACE puts "[format %8d [incr count]] RDE si:next_print" + method si:next_print {} { + debug.pt/rdengine {[Instruction si:next_print]} #Asm::Ins i_input_next print #Asm::Ins i:fail_return #Asm::Ins i_test_print incr myloc if {($myloc >= [string length $mytoken]) && ![my ExtendTC]} { set myok 0 set myerror [list $myloc [list print]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] set myok [string is print -strict $mycurrent] @@ -907,23 +1127,26 @@ set myerror [list $myloc [list print]] incr myloc -1 } else { set myerror {} } + debug.pt/rdengine {[InstReturn]} return } - method si:next_punct {} { ; #TRACE puts "[format %8d [incr count]] RDE si:next_punct" + method si:next_punct {} { + debug.pt/rdengine {[Instruction si:next_punct]} #Asm::Ins i_input_next punct #Asm::Ins i:fail_return #Asm::Ins i_test_punct incr myloc if {($myloc >= [string length $mytoken]) && ![my ExtendTC]} { set myok 0 set myerror [list $myloc [list punct]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] set myok [string is punct -strict $mycurrent] @@ -931,23 +1154,26 @@ set myerror [list $myloc [list punct]] incr myloc -1 } else { set myerror {} } + debug.pt/rdengine {[InstReturn]} return } - method si:next_space {} { ; #TRACE puts "[format %8d [incr count]] RDE si:next_space" + method si:next_space {} { + debug.pt/rdengine {[Instruction si:next_space]} #Asm::Ins i_input_next space #Asm::Ins i:fail_return #Asm::Ins i_test_space incr myloc if {($myloc >= [string length $mytoken]) && ![my ExtendTC]} { set myok 0 set myerror [list $myloc [list space]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] set myok [string is space -strict $mycurrent] @@ -955,23 +1181,26 @@ set myerror [list $myloc [list space]] incr myloc -1 } else { set myerror {} } + debug.pt/rdengine {[InstReturn]} return } - method si:next_upper {} { ; #TRACE puts "[format %8d [incr count]] RDE si:next_upper" + method si:next_upper {} { + debug.pt/rdengine {[Instruction si:next_upper]} #Asm::Ins i_input_next upper #Asm::Ins i:fail_return #Asm::Ins i_test_upper incr myloc if {($myloc >= [string length $mytoken]) && ![my ExtendTC]} { set myok 0 set myerror [list $myloc [list upper]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] set myok [string is upper -strict $mycurrent] @@ -979,23 +1208,26 @@ set myerror [list $myloc [list upper]] incr myloc -1 } else { set myerror {} } + debug.pt/rdengine {[InstReturn]} return } - method si:next_wordchar {} { ; #TRACE puts "[format %8d [incr count]] RDE si:next_wordchar" + method si:next_wordchar {} { + debug.pt/rdengine {[Instruction si:next_wordchar]} #Asm::Ins i_input_next wordchar #Asm::Ins i:fail_return #Asm::Ins i_test_wordchar incr myloc if {($myloc >= [string length $mytoken]) && ![my ExtendTC]} { set myok 0 set myerror [list $myloc [list wordchar]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] set myok [string is wordchar -strict $mycurrent] @@ -1003,23 +1235,26 @@ set myerror [list $myloc [list wordchar]] incr myloc -1 } else { set myerror {} } + debug.pt/rdengine {[InstReturn]} return } - method si:next_xdigit {} { ; #TRACE puts "[format %8d [incr count]] RDE si:next_xdigit" + method si:next_xdigit {} { + debug.pt/rdengine {[Instruction si:next_xdigit]} #Asm::Ins i_input_next xdigit #Asm::Ins i:fail_return #Asm::Ins i_test_xdigit incr myloc if {($myloc >= [string length $mytoken]) && ![my ExtendTC]} { set myok 0 set myerror [list $myloc [list xdigit]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] set myok [string is xdigit -strict $mycurrent] @@ -1027,16 +1262,18 @@ set myerror [list $myloc [list xdigit]] incr myloc -1 } else { set myerror {} } + debug.pt/rdengine {[InstReturn]} return } # - -- --- ----- -------- ------------- --------------------- method si:value_symbol_start {symbol} { + debug.pt/rdengine {[Instruction si:value_symbol_start $symbol]} # if @runtime@ i_symbol_restore $symbol # i:found:ok_ast_value_push # i:found_return # i_loc_push # i_ast_push @@ -1045,34 +1282,42 @@ if {[info exists mysymbol($k)]} { lassign $mysymbol($k) myloc myok myerror mysvalue if {$myok} { $mystackast push $mysvalue } + debug.pt/rdengine {[InstReturn]} return -code return } $mystackloc push $myloc $mystackmark push [$mystackast size] + + debug.pt/rdengine {[InstReturn]} return } method si:value_void_symbol_start {symbol} { + debug.pt/rdengine {[Instruction si:value_void_symbol_start $symbol]} # if @runtime@ i_symbol_restore $symbol # i:found_return # i_loc_push # i_ast_push set k [list $myloc $symbol] if {[info exists mysymbol($k)]} { lassign $mysymbol($k) myloc myok myerror mysvalue + debug.pt/rdengine {[InstReturn]} return -code return } $mystackloc push $myloc $mystackmark push [$mystackast size] + + debug.pt/rdengine {[InstReturn]} return } method si:void_symbol_start {symbol} { + debug.pt/rdengine {[Instruction si:void_symbol_start $symbol]} # if @runtime@ i_symbol_restore $symbol # i:found:ok_ast_value_push # i:found_return # i_loc_push @@ -1080,31 +1325,39 @@ if {[info exists mysymbol($k)]} { lassign $mysymbol($k) myloc myok myerror mysvalue if {$myok} { $mystackast push $mysvalue } + debug.pt/rdengine {[InstReturn]} return -code return } $mystackloc push $myloc + + debug.pt/rdengine {[InstReturn]} return } method si:void_void_symbol_start {symbol} { + debug.pt/rdengine {[Instruction si:void_void_symbol_start $symbol]} # if @runtime@ i_symbol_restore $symbol # i:found_return # i_loc_push set k [list $myloc $symbol] if {[info exists mysymbol($k)]} { lassign $mysymbol($k) myloc myok myerror mysvalue + debug.pt/rdengine {[InstReturn]} return -code return } $mystackloc push $myloc + + debug.pt/rdengine {[InstReturn]} return } method si:reduce_symbol_end {symbol} { + debug.pt/rdengine {[Instruction si:reduce_symbol_end $symbol]} # i_value_clear/reduce $symbol # i_symbol_save $symbol # i_error_nonterminal $symbol # i_ast_pop_rewind # i_loc_pop_discard @@ -1155,14 +1408,16 @@ $mystackast trim* [$mystackmark pop] if {$myok} { $mystackast push $mysvalue } + debug.pt/rdengine {[InstReturn]} return } method si:void_leaf_symbol_end {symbol} { + debug.pt/rdengine {[Instruction si:void_leaf_symbol_end $symbol]} # i_value_clear/leaf $symbol # i_symbol_save $symbol # i_error_nonterminal $symbol # i_loc_pop_discard # i:ok_ast_value_push @@ -1198,14 +1453,17 @@ }} if {$myok} { $mystackast push $mysvalue } + + debug.pt/rdengine {[InstReturn]} return } method si:value_leaf_symbol_end {symbol} { + debug.pt/rdengine {[Instruction si:value_leaf_symbol_end $symbol]} # i_value_clear/leaf $symbol # i_symbol_save $symbol # i_error_nonterminal $symbol # i_loc_pop_discard # i_ast_pop_rewind @@ -1243,14 +1501,17 @@ $mystackast trim* [$mystackmark pop] if {$myok} { $mystackast push $mysvalue } + + debug.pt/rdengine {[InstReturn]} return } method si:value_clear_symbol_end {symbol} { + debug.pt/rdengine {[Instruction si:value_clear_symbol_end $symbol]} # i_value_clear # i_symbol_save $symbol # i_error_nonterminal $symbol # i_loc_pop_discard # i_ast_pop_rewind @@ -1270,14 +1531,16 @@ set myerror [list $loc [list [list n $symbol]]] } }} $mystackast trim* [$mystackmark pop] + debug.pt/rdengine {[InstReturn]} return } method si:void_clear_symbol_end {symbol} { + debug.pt/rdengine {[Instruction si:void_clear_symbol_end $symbol]} # i_value_clear # i_symbol_save $symbol # i_error_nonterminal $symbol # i_loc_pop_discard @@ -1294,268 +1557,383 @@ lassign $myerror loc messages if {$loc == $pos} { set myerror [list $loc [list [list n $symbol]]] } }} + debug.pt/rdengine {[InstReturn]} return } # # ## ### ##### ######## ############# ##################### ## API - Instructions - Control flow method i:ok_continue {} { + debug.pt/rdengine {[Instruction i:ok_continue]} if {!$myok} return return -code continue } method i:fail_continue {} { + debug.pt/rdengine {[Instruction i:fail_continue]} if {$myok} return return -code continue } method i:fail_return {} { + debug.pt/rdengine {[Instruction i:fail_return]} if {$myok} return return -code return } method i:ok_return {} { + debug.pt/rdengine {[Instruction i:ok_return]} if {!$myok} return return -code return } # # ## ### ##### ######## ############# ##################### ## API - Instructions - Unconditional matching. method i_status_ok {} { + debug.pt/rdengine {[Instruction i_status_ok]} set myok 1 + debug.pt/rdengine {[InstReturn]} return } method i_status_fail {} { + debug.pt/rdengine {[Instruction i_status_fail]} set myok 0 + debug.pt/rdengine {[InstReturn]} return } method i_status_negate {} { + debug.pt/rdengine {[Instruction i_status_negate]} set myok [expr {!$myok}] + debug.pt/rdengine {[InstReturn]} return } # # ## ### ##### ######## ############# ##################### ## API - Instructions - Error handling. method i_error_clear {} { + debug.pt/rdengine {[Instruction i_error_clear]} set myerror {} + debug.pt/rdengine {[InstReturn]} return } method i_error_push {} { + debug.pt/rdengine {[Instruction i_error_push]} $mystackerr push $myerror + debug.pt/rdengine {[InstReturn]} return } method i_error_clear_push {} { + debug.pt/rdengine {[Instruction i_error_clear_push]} set myerror {} $mystackerr push {} + debug.pt/rdengine {[InstReturn]} return } method i_error_pop_merge {} { + debug.pt/rdengine {[Instruction i_error_pop_merge]} set olderror [$mystackerr pop] # We have either old or new error data, keep it. - if {![llength $myerror]} { set myerror $olderror ; return } - if {![llength $olderror]} return + if {![llength $myerror]} { set myerror $olderror ; debug.pt/rdengine {[InstReturn]} ; return } + if {![llength $olderror]} { debug.pt/rdengine {[InstReturn]} ; return } # If one of the errors is further on in the input choose that as # the information to propagate. lassign $myerror loe msgse lassign $olderror lon msgsn - if {$lon > $loe} { set myerror $olderror ; return } - if {$loe > $lon} return + if {$lon > $loe} { set myerror $olderror ; debug.pt/rdengine {[InstReturn]} ; return } + if {$loe > $lon} { debug.pt/rdengine {[InstReturn]} ; return } # Equal locations, merge the message lists. - #set myerror [list $loe [struct::set union $msgse $msgsn]] set myerror [list $loe [lsort -uniq [list {*}$msgse {*}$msgsn]]] + debug.pt/rdengine {[InstReturn]} return } method i_error_nonterminal {symbol} { + debug.pt/rdengine {[Instruction i_error_nonterminal $symbol]} # i_error_nonterminal -- Disabled. Generate only low-level # i_error_nonterminal -- errors until we have worked out how # i_error_nonterminal -- to integrate symbol information with # i_error_nonterminal -- them. Do not forget where this # i_error_nonterminal -- instruction is inlined. return # Inlined: Errors, Expected. - if {![llength $myerror]} return + if {![llength $myerror]} { + debug.pt/rdengine {no error} + return + } set pos [$mystackloc peek] incr pos lassign $myerror loc messages - if {$loc != $pos} return - set myerror [list $loc [list $symbol]] + if {$loc != $pos} { + debug.pt/rdengine {my $myerror != pos $pos} + return + } + set myerror [list $loc [list [list n $symbol]]] + + debug.pt/rdengine {::= ($myerror)} return } # # ## ### ##### ######## ############# ##################### ## API - Instructions - Basic input handling and tracking method i_loc_pop_rewind/discard {} { + debug.pt/rdengine {[Instruction i_loc_pop_rewind/discard]} #$myparser i:fail_loc_pop_rewind #$myparser i:ok_loc_pop_discard #return set last [$mystackloc pop] if {!$myok} { set myloc $last } + debug.pt/rdengine {[InstReturn]} return } method i_loc_pop_discard {} { + debug.pt/rdengine {[Instruction i_loc_pop_discard]} $mystackloc pop + debug.pt/rdengine {[InstReturn]} return } + + # i:ok_loc_pop_discard - all uses inlined method i_loc_pop_rewind {} { + debug.pt/rdengine {[Instruction i_loc_pop_rewind]} set myloc [$mystackloc pop] + debug.pt/rdengine {[InstReturn]} return } method i:fail_loc_pop_rewind {} { - if {$myok} return - set myloc [$mystackloc pop] + debug.pt/rdengine {[Instruction i:fail_loc_pop_rewind]} + if {!$myok} { + set myloc [$mystackloc pop] + } + debug.pt/rdengine {[InstReturn]} return } method i_loc_push {} { + debug.pt/rdengine {[Instruction i_loc_push]} $mystackloc push $myloc + debug.pt/rdengine {[InstReturn]} + return + } + + method i_loc_rewind {} { + debug.pt/rdengine {[Instruction i_loc_rewind]} + # i_loc_pop_rewind - set myloc [$mystackloc pop] + # i_loc_push - $mystackloc push $myloc + set myloc [$mystackloc peek] + debug.pt/rdengine {[InstReturn]} return } # # ## ### ##### ######## ############# ##################### ## API - Instructions - AST stack handling method i_ast_pop_rewind/discard {} { + debug.pt/rdengine {[Instruction i_ast_pop_rewind/discard]} #$myparser i:fail_ast_pop_rewind #$myparser i:ok_ast_pop_discard #return set mark [$mystackmark pop] - if {$myok} return - $mystackast trim $mark + if {!$myok} { + $mystackast trim* $mark + } + + debug.pt/rdengine {[InstReturn]} return } method i_ast_pop_discard/rewind {} { + debug.pt/rdengine {[Instruction i_ast_pop_discard/rewind]} #$myparser i:ok_ast_pop_rewind #$myparser i:fail_ast_pop_discard #return set mark [$mystackmark pop] - if {!$myok} return - $mystackast trim $mark + if {$myok} { + $mystackast trim* $mark + } + + debug.pt/rdengine {[InstReturn]} return } method i_ast_pop_discard {} { + debug.pt/rdengine {[Instruction i_ast_pop_discard]} $mystackmark pop + + debug.pt/rdengine {[InstReturn]} return } + + # i:ok_ast_pop_discard - all uses inlined method i_ast_pop_rewind {} { - $mystackast trim [$mystackmark pop] + debug.pt/rdengine {[Instruction i_ast_pop_rewind]} + $mystackast trim* [$mystackmark pop] + + debug.pt/rdengine {[InstReturn]} return } method i:fail_ast_pop_rewind {} { - if {$myok} return - $mystackast trim [$mystackmark pop] + debug.pt/rdengine {[Instruction i:fail_ast_pop_rewind]} + if {!$myok} { + $mystackast trim* [$mystackmark pop] + } + + debug.pt/rdengine {[InstReturn]} return } method i_ast_push {} { + debug.pt/rdengine {[Instruction i_ast_push]} $mystackmark push [$mystackast size] + + debug.pt/rdengine {[InstReturn]} return } method i:ok_ast_value_push {} { - if {!$myok} return - $mystackast push $mysvalue + debug.pt/rdengine {[Instruction i:ok_ast_value_push]} + if {$myok} { + $mystackast push $mysvalue + } + + debug.pt/rdengine {[InstReturn]} return } + + # i_ast_rewind - all uses inlined # # ## ### ##### ######## ############# ##################### ## API - Instructions - Nonterminal cache method i_symbol_restore {symbol} { + debug.pt/rdengine {[Instruction i_symbol_restore $symbol]} # Satisfy from cache if possible. set k [list $myloc $symbol] - if {![info exists mysymbol($k)]} { return 0 } + if {![info exists mysymbol($k)]} { + debug.pt/rdengine {[InstReturn]} + return 0 + } lassign $mysymbol($k) myloc myok myerror mysvalue # We go forward, as the nonterminal matches (or not). + debug.pt/rdengine {[InstReturn]} return 1 } method i_symbol_save {symbol} { + debug.pt/rdengine {[Instruction i_symbol_save $symbol]} # Store not only the value, but also how far # the match went (if it was a match). set at [$mystackloc peek] set k [list $at $symbol] set mysymbol($k) [list $myloc $myok $myerror $mysvalue] + + debug.pt/rdengine {[InstReturn]} return } # # ## ### ##### ######## ############# ##################### ## API - Instructions - Semantic values. method i_value_clear {} { + debug.pt/rdengine {[Instruction i_value_clear]} set mysvalue {} + + debug.pt/rdengine {[InstReturn]} return } method i_value_clear/leaf {symbol} { + debug.pt/rdengine {[Instruction i_value_clear/leaf $symbol] :: ([expr {[$mystackloc peek]+1}])-@$myloc)} + # not quite value_lead (guarded, and clear on fail) # Inlined clear, reduce, and optimized. # Clear ; if {$ok} {Reduce $symbol} set mysvalue {} - if {!$myok} return - set pos [$mystackloc peek] - incr pos - set mysvalue [pt::ast new $symbol $pos $myloc] + if {$myok} { + set pos [$mystackloc peek] + incr pos + + if {($pos - 1) == $myloc} { + # The symbol did not process any input. As this is + # signaled to be ok (*) we create a node covering an + # empty range. (Ad *): Can happen for a RHS using + # toplevel operators * or ?. + set mysvalue [pt::ast new0 $symbol $pos] + } else { + set mysvalue [pt::ast new $symbol $pos $myloc] + } + } + + debug.pt/rdengine {[InstReturn]} return } method i_value_clear/reduce {symbol} { - set mysvalue {} - if {!$myok} return - - set mark [$mystackmark peek];# Old size of stack before current nt pushed more. - set newa [expr {[$mystackast size] - $mark}] - - set pos [$mystackloc peek] - incr pos - - if {!$newa} { - set mysvalue {} - } elseif {$newa == 1} { - # peek 1 => single element comes back - set mysvalue [list [$mystackast peek]] ; # SaveToMark - } else { - # peek n > 1 => list of elements comes back - set mysvalue [lreverse [$mystackast peek $newa]] ; # SaveToMark - } - - set mysvalue [pt::ast new $symbol $pos $myloc {*}$mysvalue] ; # Reduce $symbol + debug.pt/rdengine {[Instruction i_value_clear/reduce $symbol]} + set mysvalue {} + if {$myok} { + set mark [$mystackmark peek];# Old size of stack before current nt pushed more. + set newa [expr {[$mystackast size] - $mark}] + + set pos [$mystackloc peek] + incr pos + + if {!$newa} { + set mysvalue {} + } elseif {$newa == 1} { + # peek 1 => single element comes back + set mysvalue [list [$mystackast peek]] ; # SaveToMark + } else { + # peek n > 1 => list of elements comes back + set mysvalue [$mystackast peekr $newa] ; # SaveToMark + } + + if {($pos - 1) == $myloc} { + # The symbol did not process any input. As this is + # signaled to be ok (*) we create a node covering an + # empty range. (Ad *): Can happen for a RHS using + # toplevel operators * or ?. + set mysvalue [pt::ast new0 $symbol $pos {*}$mysvalue] + } else { + set mysvalue [pt::ast new $symbol $pos $myloc {*}$mysvalue] ; # Reduce $symbol + } + } + + debug.pt/rdengine {[InstReturn]} return } # # ## ### ##### ######## ############# ##################### ## API - Instructions - Terminal matching method i_input_next {msg} { + debug.pt/rdengine {[Instruction i_input_next $msg]} # Inlined: Getch, Expected, ClearErrors # Satisfy from input cache if possible. incr myloc # May read from the input (ExtendTC), and remember the @@ -1562,124 +1940,174 @@ # information. Note: We are implicitly incrementing the # location! if {($myloc >= [string length $mytoken]) && ![my ExtendTC]} { set myok 0 set myerror [list $myloc [list $msg]] + + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] set myok 1 set myerror {} - return - } - - method i_test_alnum {} { - set myok [string is alnum -strict $mycurrent] - my OkFail [pt::pe alnum] - return - } - - method i_test_alpha {} { - set myok [string is alpha -strict $mycurrent] - my OkFail [pt::pe alpha] - return - } - - method i_test_ascii {} { - set myok [string is ascii -strict $mycurrent] - my OkFail [pt::pe ascii] - return - } - - method i_test_control {} { - set myok [string is control -strict $mycurrent] - my OkFail [pt::pe control] + + debug.pt/rdengine {[InstReturn]} return } method i_test_char {tok} { + debug.pt/rdengine {[Instruction i_test_char $tok] :: ok [expr {$tok eq $mycurrent}], [expr {$tok eq $mycurrent ? "@$myloc" : "back@[expr {$myloc-1}]"}]} set myok [expr {$tok eq $mycurrent}] - my OkFail [pt::pe terminal $tok] + my OkFailD {pt::pe terminal $tok} + + debug.pt/rdengine {[InstReturn]} + return + } + + method i_test_range {toks toke} { + debug.pt/rdengine {[Instruction i_test_range $toks $toke]} + set myok [expr { + ([string compare $toks $mycurrent] <= 0) && + ([string compare $mycurrent $toke] <= 0) + }] ; # {} + my OkFailD {pt::pe range $toks $toke} + + debug.pt/rdengine {[InstReturn]} + return + } + + method i_test_alnum {} { + debug.pt/rdengine {[Instruction i_test_alnum]} + set myok [string is alnum -strict $mycurrent] + my OkFailD {pt::pe alnum} + + debug.pt/rdengine {[InstReturn]} + return + } + + method i_test_alpha {} { + debug.pt/rdengine {[Instruction i_test_alpha]} + set myok [string is alpha -strict $mycurrent] + my OkFailD {pt::pe alpha} + + debug.pt/rdengine {[InstReturn]} + return + } + + method i_test_ascii {} { + debug.pt/rdengine {[Instruction i_test_ascii]} + set myok [string is ascii -strict $mycurrent] + my OkFailD {pt::pe ascii} + + debug.pt/rdengine {[InstReturn]} + return + } + + method i_test_control {} { + debug.pt/rdengine {[Instruction i_test_control]} + set myok [string is control -strict $mycurrent] + my OkFailD {pt::pe control} + + debug.pt/rdengine {[InstReturn]} return } method i_test_ddigit {} { + debug.pt/rdengine {[Instruction i_test_ddigit]} set myok [string match {[0-9]} $mycurrent] - my OkFail [pt::pe ddigit] + my OkFailD {pt::pe ddigit} + + debug.pt/rdengine {[InstReturn]} return } method i_test_digit {} { + debug.pt/rdengine {[Instruction i_test_digit]} set myok [string is digit -strict $mycurrent] - my OkFail [pt::pe digit] + my OkFailD {pt::pe digit} + + debug.pt/rdengine {[InstReturn]} return } method i_test_graph {} { + debug.pt/rdengine {[Instruction i_test_graph]} set myok [string is graph -strict $mycurrent] - my OkFail [pt::pe graph] + my OkFailD {pt::pe graph} + + debug.pt/rdengine {[InstReturn]} return } method i_test_lower {} { + debug.pt/rdengine {[Instruction i_test_lower]} set myok [string is lower -strict $mycurrent] - my OkFail [pt::pe lower] + my OkFailD {pt::pe lower} + + debug.pt/rdengine {[InstReturn]} return } method i_test_print {} { + debug.pt/rdengine {[Instruction i_test_print]} set myok [string is print -strict $mycurrent] - my OkFail [pt::pe printable] + my OkFailD {pt::pe printable} + + debug.pt/rdengine {[InstReturn]} return } method i_test_punct {} { + debug.pt/rdengine {[Instruction i_test_punct]} set myok [string is punct -strict $mycurrent] - my OkFail [pt::pe punct] - return - } - - method i_test_range {toks toke} { - set myok [expr { - ([string compare $toks $mycurrent] <= 0) && - ([string compare $mycurrent $toke] <= 0) - }] ; # {} - my OkFail [pt::pe range $toks $toke] + my OkFailD {pt::pe punct} + + debug.pt/rdengine {[InstReturn]} return } method i_test_space {} { + debug.pt/rdengine {[Instruction i_test_space]} set myok [string is space -strict $mycurrent] - my OkFail [pt::pe space] + my OkFailD {pt::pe space} + + debug.pt/rdengine {[InstReturn]} return } method i_test_upper {} { + debug.pt/rdengine {[Instruction i_test_upper]} set myok [string is upper -strict $mycurrent] - my OkFail [pt::pe upper] + my OkFailD {pt::pe upper} + + debug.pt/rdengine {[InstReturn]} return } method i_test_wordchar {} { + debug.pt/rdengine {[Instruction i_test_wordchar]} set myok [string is wordchar -strict $mycurrent] - my OkFail [pt::pe wordchar] + my OkFailD {pt::pe wordchar} + + debug.pt/rdengine {[InstReturn]} return } method i_test_xdigit {} { + debug.pt/rdengine {[Instruction i_test_xdigit]} set myok [string is xdigit -strict $mycurrent] - my OkFail [pt::pe xdigit] + my OkFailD {pt::pe xdigit} + + debug.pt/rdengine {[InstReturn]} return } # # ## ### ##### ######## ############# ##################### ## Internals method ExtendTC {} { - upvar 1 mychan mychan mytoken mytoken - if {($mychan eq {}) || [eof $mychan]} {return 0} set ch [read $mychan 1] if {$ch eq {}} { @@ -1689,12 +2117,10 @@ append mytoken $ch return 1 } method ExtendTCN {n} { - upvar 1 mychan mychan mytoken mytoken - if {($mychan eq {}) || [eof $mychan]} {return 0} set str [read $mychan $n] set k [string length $str] @@ -1705,15 +2131,14 @@ } return 1 } - method OkFail {msg} { - upvar 1 myok myok myerror myerror myloc myloc + method OkFailD {msgcmd} { # Inlined: Expected, Unget, ClearErrors if {!$myok} { - set myerror [list $myloc [list $msg]] + set myerror [list $myloc [list [uplevel 1 $msgcmd]]] incr myloc -1 } else { set myerror {} } return @@ -1724,11 +2149,12 @@ ## Mainly the architectural state of the instance's PARAM. variable \ mychan mycurrent myloc mystackloc \ myok mysvalue myerror mystackerr \ - mytoken mysymbol mystackast mystackmark + mytoken mysymbol mystackast mystackmark \ + mytracecounter # Parser Input (channel, location (line, column)) ........... # Token, current parsing location, stack of locations ....... # Match state . ........ ............. ..................... # Caches for tokens and nonterminals .. ..................... @@ -1737,8 +2163,7 @@ # # ## ### ##### ######## ############# ##################### } # # ## ### ##### ######## ############# ##################### ## Ready - -package provide pt::rde::oo 1.0.3 +package provide pt::rde::oo 1.1 return Index: modules/pt/pt_rdengine_tcl.tcl ================================================================== --- modules/pt/pt_rdengine_tcl.tcl +++ modules/pt/pt_rdengine_tcl.tcl @@ -1,8 +1,8 @@ # -*- tcl -*- # -# Copyright (c) 2009-2014 by Andreas Kupries +# Copyright (c) 2009-2015 by Andreas Kupries # # ## ### ##### ######## ############# ##################### ## Package description ## Implementation of the PackRat Machine (PARAM), a virtual machine on @@ -16,66 +16,148 @@ # # ## ### ##### ######## ############# ##################### ## Requisites package require Tcl 8.5 package require snit -package require struct::stack 1.5 ; # Requiring peekr, getr, trim* methods +package require struct::stack 1.5 ; # Requiring peekr, getr, get, trim* methods package require pt::ast package require pt::pe -package require char ; # quoting + +# # ## ### ##### ######## ############# ##################### +## Support narrative tracing. + +package require debug +debug level pt/rdengine +debug prefix pt/rdengine {} + # # ## ### ##### ######## ############# ##################### ## Implementation snit::type ::pt::rde_tcl { + # # ## ### ##### ######## ############# ##################### + ## Instruction counter for tracing. Unused else. Plus other helpers. + variable trace 0 + + proc Instruction {label {a {}} {b {}}} { + upvar 1 self self trace trace myok myok myloc myloc mycurrent mycurrent mysvalue mysvalue myerror myerror __inst theinst + set theinst [list $label $a $b] + return "$self <<[format %08d [incr trace]]>> START I:[format %-30s $label] [format %-10s $a] [format %-10s $b] :: [State]" + } + + proc InstReturn {} { + upvar 1 self self trace trace myok myok myloc myloc mycurrent mycurrent mysvalue mysvalue myerror myerror __inst theinst + lassign $theinst label a b + return "$self <<[format %08d $trace]>> END__ I:[format %-30s $label] [format %-10s $a] [format %-10s $b] :: [State]" + } + + proc State {} { + upvar 1 myok myok myloc myloc mycurrent mycurrent mysvalue mysvalue myerror myerror + return "ST $myok CL $myloc CC ($mycurrent) SV ($mysvalue) ER ($myerror)" + } + + proc TraceSetupStacks {} { + upvar selfns selfns + + # Move stack instances aside. + rename ${selfns}::LOC ${selfns}::LOC__ + rename ${selfns}::ERR ${selfns}::ERR__ + rename ${selfns}::AST ${selfns}::AST__ + rename ${selfns}::MARK ${selfns}::MRK__ + + # Create procedures doing tracing, and forwarding to the + # renamed actual instances. + + interp alias {} ${selfns}::LOC {} ${selfns}::WRAP LS LOC__ + interp alias {} ${selfns}::ERR {} ${selfns}::WRAP ES ERR__ + interp alias {} ${selfns}::AST {} ${selfns}::WRAP ARS AST__ + interp alias {} ${selfns}::MARK {} ${selfns}::WRAP ASM MRK__ + + proc ${selfns}::WRAP {label stack args} { + debug.pt/rdengine { $label ___ $args} + set res [$stack {*}$args] + + # Show state state after the op + set n [$stack size] + if {!$n} { + set c {()} + } elseif {$n == 1} { + set c <<[$stack peek $n]>> + } else { + set c <<[join [$stack peek $n] {>> <<}]>> + } + debug.pt/rdengine { $label == ($n):$c} + + # And op return + debug.pt/rdengine { $label ==> ($res)} + return $res + } + return + } # # ## ### ##### ######## ############# ##################### ## API - Lifecycle constructor {} { + debug.pt/rdengine {$self constructor} + set mystackloc [struct::stack ${selfns}::LOC] ; # LS set mystackerr [struct::stack ${selfns}::ERR] ; # ES set mystackast [struct::stack ${selfns}::AST] ; # ARS/AS set mystackmark [struct::stack ${selfns}::MARK] ; # s.a. + + debug.pt/rdengine {[TraceSetupStacks]$self constructor /done} return } - #TRACE variable count 0 - #variable count 0 + method reset {{chan {}}} { + debug.pt/rdengine {$self reset ($chan)} - method reset {{chan {}}} { ; #set count 0 - ; #TRACE puts "[format %8d [incr count]] RDE reset" set mychan $chan ; # IN set mycurrent {} ; # CC set myloc -1 ; # CL set myok 0 ; # ST set msvalue {} ; # SV set myerror {} ; # ER - set mytoken {} ; # TC + set mytoken {} ; # TC (string) array unset mysymbol * ; # NC $mystackloc clear $mystackerr clear $mystackast clear $mystackmark clear + + debug.pt/rdengine {$self reset /done} return } - method complete {} { ; #TRACE puts "[format %8d [incr count]] RDE complete" + method complete {} { + debug.pt/rdengine {$self complete [State]} + if {$myok} { set n [$mystackast size] + debug.pt/rdengine {$self complete ast $n} if {$n > 1} { + # Multiple ASTs left, reduce into single containing them. set pos [$mystackloc peek] incr pos set children [$mystackast peekr [$mystackast size]] ; # SaveToMark - return [pt::ast new {} $pos $myloc {*}$children] ; # Reduce ALL + set ast [pt::ast new {} $pos $myloc {*}$children] ; # Reduce ALL + + debug.pt/rdengine {$self complete n ==> ($ast)} + return $ast } elseif {$n == 0} { # Match, but no AST. This is possible if the grammar # consists of only the start expression. + + debug.pt/rdengine {$self complete 0 ==> ()} return {} } else { - return [$mystackast peek] + # Match, with AST. + set ast [$mystackast peek] + debug.pt/rdengine {$self complete 1 ==> ($ast)} + return $ast } } else { lassign $myerror loc messages return -code error \ -errorcode {PT RDE SYNTAX} \ @@ -84,91 +166,105 @@ } # # ## ### ##### ######## ############# ##################### ## API - State accessors - method chan {} { return $mychan } + method chan {} { debug.pt/rdengine {$self chan} ; return $mychan } # - - -- --- ----- -------- - method current {} { return $mycurrent } - method location {} { return $myloc } - method lmarked {} { return [$mystackloc getr] } + method current {} { debug.pt/rdengine {$self current} ; return $mycurrent } + method location {} { debug.pt/rdengine {$self location} ; return $myloc } + method lmarked {} { debug.pt/rdengine {$self lmarked} ; return [$mystackloc getr] } # - - -- --- ----- -------- - method ok {} { return $myok } - method value {} { return $mysvalue } - method error {} { return $myerror } - method emarked {} { return [$mystackerr getr] } + method ok {} { debug.pt/rdengine {$self ok} ; return $myok } + method value {} { debug.pt/rdengine {$self value} ; return $mysvalue } + method error {} { debug.pt/rdengine {$self error} ; return $myerror } + method emarked {} { debug.pt/rdengine {$self emarked} ; return [$mystackerr getr] } # - - -- --- ----- -------- - method tokens {{from {}} {to {}}} { ; #TRACE puts "[format %8d [incr count]] RDE tokens" + method tokens {{from {}} {to {}}} { + debug.pt/rdengine {$self tokens ($from) ($to)} switch -exact [llength [info level 0]] { 5 { return $mytoken } 6 { return [string range $mytoken $from $from] } 7 { return [string range $mytoken $from $to] } } } - method symbols {} { ; #TRACE puts "[format %8d [incr count]] RDE symbols" + method symbols {} { + debug.pt/rdengine {$self symbols} return [array get mysymbol] } - method scached {} { ; #TRACE puts "[format %8d [incr count]] RDE scached" + method scached {} { + debug.pt/rdengine {$self scached} return [array names mysymbol] } # - - -- --- ----- -------- - method asts {} { return [$mystackast getr] } - method amarked {} { return [$mystackmark getr] } - method ast {} { return [$mystackast peek] } + method asts {} { debug.pt/rdengine {$self asts} ; return [$mystackast getr] } + method amarked {} { debug.pt/rdengine {$self amarked} ; return [$mystackmark getr] } + method ast {} { debug.pt/rdengine {$self ast} ; return [$mystackast peek] } # # ## ### ##### ######## ############# ##################### ## API - Preloading the token cache. - method data {data} { ; #TRACE puts "[format %8d [incr count]] RDE data" + method data {data} { + debug.pt/rdengine {$self data +[string length $data]} append mytoken $data return } # # ## ### ##### ######## ############# ##################### ## Common instruction sequences - method si:void_state_push {} { ; #TRACE puts "[format %8d [incr count]] RDE si:void_state_push" + method si:void_state_push {} { + debug.pt/rdengine {[Instruction si:void_state_push]} # i_loc_push # i_error_clear_push $mystackloc push $myloc set myerror {} $mystackerr push {} + + debug.pt/rdengine {[InstReturn]} return } - method si:void2_state_push {} { ; #TRACE puts "[format %8d [incr count]] RDE si:void2_state_push" + method si:void2_state_push {} { + debug.pt/rdengine {[Instruction si:void2_state_push]} # i_loc_push # i_error_push $mystackloc push $myloc $mystackerr push {} + + debug.pt/rdengine {[InstReturn]} return } - method si:value_state_push {} { ; #TRACE puts "[format %8d [incr count]] RDE si:value_state_push" + method si:value_state_push {} { + debug.pt/rdengine {[Instruction si:value_state_push]} # i_ast_push # i_loc_push # i_error_clear_push $mystackmark push [$mystackast size] $mystackloc push $myloc set myerror {} $mystackerr push {} + + debug.pt/rdengine {[InstReturn]} return } # - -- --- ----- -------- ------------- --------------------- - method si:void_state_merge {} { ; #TRACE puts "[format %8d [incr count]] RDE si:void_state_merge" + method si:void_state_merge {} { + debug.pt/rdengine {[Instruction si:void_state_merge]} # i_error_pop_merge # i_loc_pop_rewind/discard set olderror [$mystackerr pop] # We have either old or new error data, keep it. @@ -188,16 +284,19 @@ set myerror [list $loe [lsort -uniq [list {*}$msgse {*}$msgsn]]] } } set last [$mystackloc pop] - if {$myok} return - set myloc $last + if {!$myok} { + set myloc $last + } + debug.pt/rdengine {[InstReturn]} return } - method si:void_state_merge_ok {} { ; #TRACE puts "[format %8d [incr count]] RDE si:void_state_merge_ok" + method si:void_state_merge_ok {} { + debug.pt/rdengine {[Instruction si:void_state_merge_ok]} # i_error_pop_merge # i_loc_pop_rewind/discard # i_status_ok set olderror [$mystackerr pop] @@ -218,17 +317,21 @@ set myerror [list $loe [lsort -uniq [list {*}$msgse {*}$msgsn]]] } } set last [$mystackloc pop] - if {$myok} return - set myloc $last - set myok 1 + if {!$myok} { + set myloc $last + set myok 1 + } + + debug.pt/rdengine {[InstReturn]} return } - method si:value_state_merge {} { ; #TRACE puts "[format %8d [incr count]] RDE si:value_state_merge" + method si:value_state_merge {} { + debug.pt/rdengine {[Instruction si:value_state_merge]} # i_error_pop_merge # i_ast_pop_rewind/discard # i_loc_pop_rewind/discard set olderror [$mystackerr pop] @@ -250,37 +353,47 @@ } } set mark [$mystackmark pop] set last [$mystackloc pop] - if {$myok} return - $mystackast trim* $mark - set myloc $last + if {!$myok} { + $mystackast trim* $mark + set myloc $last + } + + debug.pt/rdengine {[InstReturn]} return } # - -- --- ----- -------- ------------- --------------------- - method si:value_notahead_start {} { ; #TRACE puts "[format %8d [incr count]] RDE si:value_notahead_start" + method si:value_notahead_start {} { + debug.pt/rdengine {[Instruction si:value_notahead_start]} # i_loc_push # i_ast_push $mystackloc push $myloc $mystackmark push [$mystackast size] + + debug.pt/rdengine {[InstReturn]} return } - method si:void_notahead_exit {} { ; #TRACE puts "[format %8d [incr count]] RDE si:void_notahead_exit" + method si:void_notahead_exit {} { + debug.pt/rdengine {[Instruction si:void_notahead_exit]} # i_loc_pop_rewind # i_status_negate set myloc [$mystackloc pop] set myok [expr {!$myok}] + + debug.pt/rdengine {[InstReturn]} return } - method si:value_notahead_exit {} { ; #TRACE puts "[format %8d [incr count]] RDE si:value_notahead_exit" + method si:value_notahead_exit {} { + debug.pt/rdengine {[Instruction si:value_notahead_exit]} # i_ast_pop_discard/rewind # i_loc_pop_rewind # i_status_negate set mark [$mystackmark pop] @@ -287,26 +400,34 @@ if {$myok} { $mystackast trim* $mark } set myloc [$mystackloc pop] set myok [expr {!$myok}] + + debug.pt/rdengine {[InstReturn]} return } # - -- --- ----- -------- ------------- --------------------- - method si:kleene_abort {} { ; #TRACE puts "[format %8d [incr count]] RDE si:kleene_abort" + method si:kleene_abort {} { + debug.pt/rdengine {[Instruction si:kleene_abort]} # i_loc_pop_rewind/discard # i:fail_return set last [$mystackloc pop] - if {$myok} return + if {$myok} { + debug.pt/rdengine {[InstReturn]} + return + } set myloc $last + debug.pt/rdengine {[InstReturn]} return -code return } - method si:kleene_close {} { ; #TRACE puts "[format %8d [incr count]] RDE si:kleene_close" + method si:kleene_close {} { + debug.pt/rdengine {[Instruction si:kleene_close]} # i_error_pop_merge # i_loc_pop_rewind/discard # i:fail_status_ok # i:fail_return @@ -328,19 +449,25 @@ set myerror [list $loe [lsort -uniq [list {*}$msgse {*}$msgsn]]] } } set last [$mystackloc pop] - if {$myok} return + if {$myok} { + debug.pt/rdengine {[InstReturn]} + return + } set myok 1 set myloc $last + + debug.pt/rdengine {[InstReturn]} return -code return } # - -- --- ----- -------- ------------- --------------------- - method si:voidvoid_branch {} { ; #TRACE puts "[format %8d [incr count]] RDE si:voidvoid_branch" + method si:voidvoid_branch {} { + debug.pt/rdengine {[Instruction si:voidvoid_branch]} # i_error_pop_merge # i:ok_loc_pop_discard # i:ok_return # i_loc_rewind # i_error_push @@ -364,18 +491,22 @@ } } if {$myok} { $mystackloc pop + debug.pt/rdengine {[InstReturn]} return -code return } set myloc [$mystackloc peek] $mystackerr push $myerror + + debug.pt/rdengine {[InstReturn]} return } - method si:voidvalue_branch {} { ; #TRACE puts "[format %8d [incr count]] RDE si:voidvalue_branch" + method si:voidvalue_branch {} { + debug.pt/rdengine {[Instruction si:voidvalue_branch]} # i_error_pop_merge # i:ok_loc_pop_discard # i:ok_return # i_ast_push # i_loc_rewind @@ -400,19 +531,23 @@ } } if {$myok} { $mystackloc pop + debug.pt/rdengine {[InstReturn]} return -code return } $mystackmark push [$mystackast size] set myloc [$mystackloc peek] $mystackerr push {} + + debug.pt/rdengine {[InstReturn]} return } - method si:valuevoid_branch {} { ; #TRACE puts "[format %8d [incr count]] RDE si:valuevoid_branch" + method si:valuevoid_branch {} { + debug.pt/rdengine {[Instruction si:valuevoid_branch]} # i_error_pop_merge # i_ast_pop_rewind/discard # i:ok_loc_pop_discard # i:ok_return # i_loc_rewind @@ -437,19 +572,23 @@ } } set mark [$mystackmark pop] if {$myok} { $mystackloc pop + debug.pt/rdengine {[InstReturn]} return -code return } $mystackast trim* $mark set myloc [$mystackloc peek] $mystackerr push {} + + debug.pt/rdengine {[InstReturn]} return } - method si:valuevalue_branch {} { ; #TRACE puts "[format %8d [incr count]] RDE si:valuevalue_branch" + method si:valuevalue_branch {} { + debug.pt/rdengine {[Instruction si:valuevalue_branch]} # i_error_pop_merge # i_ast_pop_discard # i:ok_loc_pop_discard # i:ok_return # i_ast_rewind @@ -475,21 +614,26 @@ } } if {$myok} { $mystackmark pop $mystackloc pop + + debug.pt/rdengine {[InstReturn]} return -code return } $mystackast trim* [$mystackmark peek] set myloc [$mystackloc peek] $mystackerr push {} + + debug.pt/rdengine {[InstReturn]} return } # - -- --- ----- -------- ------------- --------------------- - method si:voidvoid_part {} { ; #TRACE puts "[format %8d [incr count]] RDE si:voidvoid_part" + method si:voidvoid_part {} { + debug.pt/rdengine {[Instruction si:voidvoid_part]} # i_error_pop_merge # i:fail_loc_pop_rewind # i:fail_return # i_error_push @@ -511,17 +655,21 @@ set myerror [list $loe [lsort -uniq [list {*}$msgse {*}$msgsn]]] } } if {!$myok} { set myloc [$mystackloc pop] + debug.pt/rdengine {[InstReturn]} return -code return } $mystackerr push $myerror + + debug.pt/rdengine {[InstReturn]} return } - method si:voidvalue_part {} { ; #TRACE puts "[format %8d [incr count]] RDE si:voidvalue_part" + method si:voidvalue_part {} { + debug.pt/rdengine {[Instruction si:voidvalue_part]} # i_error_pop_merge # i:fail_loc_pop_rewind # i:fail_return # i_ast_push # i_error_push @@ -544,18 +692,22 @@ set myerror [list $loe [lsort -uniq [list {*}$msgse {*}$msgsn]]] } } if {!$myok} { set myloc [$mystackloc pop] + debug.pt/rdengine {[InstReturn]} return -code return } $mystackmark push [$mystackast size] $mystackerr push $myerror + + debug.pt/rdengine {[InstReturn]} return } - method si:valuevalue_part {} { ; #TRACE puts "[format %8d [incr count]] RDE si:valuevalue_part" + method si:valuevalue_part {} { + debug.pt/rdengine {[Instruction si:valuevalue_part]} # i_error_pop_merge # i:fail_ast_pop_rewind # i:fail_loc_pop_rewind # i:fail_return # i_error_push @@ -579,19 +731,24 @@ } } if {!$myok} { $mystackast trim* [$mystackmark pop] set myloc [$mystackloc pop] + + debug.pt/rdengine {[InstReturn]} return -code return } $mystackerr push $myerror + + debug.pt/rdengine {[InstReturn]} return } # - -- --- ----- -------- ------------- --------------------- - method si:next_str {tok} { ; #TRACE puts "[format %8d [incr count]] RDE si:next_str ($tok)" + method si:next_str {tok} { + debug.pt/rdengine {[Instruction si:next_str $tok]} # String = sequence of characters. # No need for all the intermediate stack churn. set n [string length $tok] set last [expr {$myloc + $n}] @@ -600,10 +757,11 @@ incr myloc if {($last >= $max) && ![ExtendTCN [expr {$last - $max + 1}]]} { set myok 0 set myerror [list $myloc [list [pt::pe str $tok]]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set lex [string range $mytoken $myloc $last] set mycurrent [string index $mytoken $last] @@ -622,14 +780,16 @@ set myerror {} } else { set myerror [list $myloc [list [pt::pe str $tok]]] incr myloc -1 } + debug.pt/rdengine {[InstReturn]} return } - method si:next_class {tok} { ; #TRACE puts "[format %8d [incr count]] RDE si:next_class ($tok)" + method si:next_class {tok} { + debug.pt/rdengine {[Instruction si:next_class $tok]} # Class = Choice of characters. No need for stack churn. # i_input_next "\{t $c\}" # i:fail_return # i_test_ @@ -637,10 +797,11 @@ incr myloc if {($myloc >= [string length $mytoken]) && ![ExtendTC]} { set myok 0 set myerror [list $myloc [list [pt::pe class $tok]]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] # Note what is needle versus hay. The token, i.e. the string @@ -652,23 +813,26 @@ set myerror {} } else { set myerror [list $myloc [list [pt::pe class $tok]]] incr myloc -1 } + debug.pt/rdengine {[InstReturn]} return } - method si:next_char {tok} { ; #TRACE puts "[format %8d [incr count]] RDE si:next_char ($tok)" + method si:next_char {tok} { + debug.pt/rdengine {[Instruction si:next_char $tok]} # i_input_next "\{t $c\}" # i:fail_return # i_test_char $c incr myloc if {($myloc >= [string length $mytoken]) && ![ExtendTC]} { set myok 0 set myerror [list $myloc [list [pt::pe terminal $tok]]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] set myok [expr {$tok eq $mycurrent}] @@ -676,23 +840,26 @@ set myerror {} } else { set myerror [list $myloc [list [pt::pe terminal $tok]]] incr myloc -1 } + debug.pt/rdengine {[InstReturn]} return } - method si:next_range {toks toke} { ; #TRACE puts "[format %8d [incr count]] RDE si:next_range ($toks $toke)" + method si:next_range {toks toke} { + debug.pt/rdengine {[Instruction si:next_range $toks $toke]} #Asm::Ins i_input_next "\{.. $s $e\}" #Asm::Ins i:fail_return #Asm::Ins i_test_range $s $e incr myloc if {($myloc >= [string length $mytoken]) && ![ExtendTC]} { set myok 0 set myerror [list $myloc [list [pt::pe range $toks $toke]]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] set myok [expr { @@ -703,25 +870,28 @@ set myerror {} } else { set myerror [list $myloc [list [pt::pe range $toks $toke]]] incr myloc -1 } + debug.pt/rdengine {[InstReturn]} return } # - -- --- ----- -------- ------------- --------------------- - method si:next_alnum {} { ; #TRACE puts "[format %8d [incr count]] RDE si:next_alnum" + method si:next_alnum {} { + debug.pt/rdengine {[Instruction si:next_alnum]} #Asm::Ins i_input_next alnum #Asm::Ins i:fail_return #Asm::Ins i_test_alnum incr myloc if {($myloc >= [string length $mytoken]) && ![ExtendTC]} { set myok 0 set myerror [list $myloc [list alnum]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] set myok [string is alnum -strict $mycurrent] @@ -729,23 +899,26 @@ set myerror [list $myloc [list alnum]] incr myloc -1 } else { set myerror {} } + debug.pt/rdengine {[InstReturn]} return } - method si:next_alpha {} { ; #TRACE puts "[format %8d [incr count]] RDE si:next_alpha" + method si:next_alpha {} { + debug.pt/rdengine {[Instruction si:next_alpha]} #Asm::Ins i_input_next alpha #Asm::Ins i:fail_return #Asm::Ins i_test_alpha incr myloc if {($myloc >= [string length $mytoken]) && ![ExtendTC]} { set myok 0 set myerror [list $myloc [list alpha]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] set myok [string is alpha -strict $mycurrent] @@ -753,23 +926,26 @@ set myerror [list $myloc [list alpha]] incr myloc -1 } else { set myerror {} } + debug.pt/rdengine {[InstReturn]} return } - method si:next_ascii {} { ; #TRACE puts "[format %8d [incr count]] RDE si:next_ascii" + method si:next_ascii {} { + debug.pt/rdengine {[Instruction si:next_ascii]} #Asm::Ins i_input_next ascii #Asm::Ins i:fail_return #Asm::Ins i_test_ascii incr myloc if {($myloc >= [string length $mytoken]) && ![ExtendTC]} { set myok 0 set myerror [list $myloc [list ascii]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] set myok [string is ascii -strict $mycurrent] @@ -777,23 +953,26 @@ set myerror [list $myloc [list ascii]] incr myloc -1 } else { set myerror {} } + debug.pt/rdengine {[InstReturn]} return } - method si:next_control {} { ; #TRACE puts "[format %8d [incr count]] RDE si:next_control" + method si:next_control {} { + debug.pt/rdengine {[Instruction si:next_control]} #Asm::Ins i_input_next control #Asm::Ins i:fail_return #Asm::Ins i_test_control incr myloc if {($myloc >= [string length $mytoken]) && ![ExtendTC]} { set myok 0 set myerror [list $myloc [list control]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] set myok [string is control -strict $mycurrent] @@ -801,23 +980,26 @@ set myerror [list $myloc [list control]] incr myloc -1 } else { set myerror {} } + debug.pt/rdengine {[InstReturn]} return } - method si:next_ddigit {} { ; #TRACE puts "[format %8d [incr count]] RDE si:next_ddigit" + method si:next_ddigit {} { + debug.pt/rdengine {[Instruction si:next_ddigit]} #Asm::Ins i_input_next ddigit #Asm::Ins i:fail_return #Asm::Ins i_test_ddigit incr myloc if {($myloc >= [string length $mytoken]) && ![ExtendTC]} { set myok 0 set myerror [list $myloc [list ddigit]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] set myok [string match {[0-9]} $mycurrent] @@ -825,23 +1007,26 @@ set myerror [list $myloc [list ddigit]] incr myloc -1 } else { set myerror {} } + debug.pt/rdengine {[InstReturn]} return } - method si:next_digit {} { ; #TRACE puts "[format %8d [incr count]] RDE si:next_digit" + method si:next_digit {} { + debug.pt/rdengine {[Instruction si:next_digit]} #Asm::Ins i_input_next digit #Asm::Ins i:fail_return #Asm::Ins i_test_digit incr myloc if {($myloc >= [string length $mytoken]) && ![ExtendTC]} { set myok 0 set myerror [list $myloc [list digit]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] set myok [string is digit -strict $mycurrent] @@ -849,23 +1034,26 @@ set myerror [list $myloc [list digit]] incr myloc -1 } else { set myerror {} } + debug.pt/rdengine {[InstReturn]} return } - method si:next_graph {} { ; #TRACE puts "[format %8d [incr count]] RDE si:next_graph" + method si:next_graph {} { + debug.pt/rdengine {[Instruction si:next_graph]} #Asm::Ins i_input_next graph #Asm::Ins i:fail_return #Asm::Ins i_test_graph incr myloc if {($myloc >= [string length $mytoken]) && ![ExtendTC]} { set myok 0 set myerror [list $myloc [list graph]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] set myok [string is graph -strict $mycurrent] @@ -873,23 +1061,26 @@ set myerror [list $myloc [list graph]] incr myloc -1 } else { set myerror {} } + debug.pt/rdengine {[InstReturn]} return } - method si:next_lower {} { ; #TRACE puts "[format %8d [incr count]] RDE si:next_lower" + method si:next_lower {} { + debug.pt/rdengine {[Instruction si:next_lower]} #Asm::Ins i_input_next lower #Asm::Ins i:fail_return #Asm::Ins i_test_lower incr myloc if {($myloc >= [string length $mytoken]) && ![ExtendTC]} { set myok 0 set myerror [list $myloc [list lower]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] set myok [string is lower -strict $mycurrent] @@ -897,23 +1088,26 @@ set myerror [list $myloc [list lower]] incr myloc -1 } else { set myerror {} } + debug.pt/rdengine {[InstReturn]} return } - method si:next_print {} { ; #TRACE puts "[format %8d [incr count]] RDE si:next_print" + method si:next_print {} { + debug.pt/rdengine {[Instruction si:next_print]} #Asm::Ins i_input_next print #Asm::Ins i:fail_return #Asm::Ins i_test_print incr myloc if {($myloc >= [string length $mytoken]) && ![ExtendTC]} { set myok 0 set myerror [list $myloc [list print]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] set myok [string is print -strict $mycurrent] @@ -921,23 +1115,26 @@ set myerror [list $myloc [list print]] incr myloc -1 } else { set myerror {} } + debug.pt/rdengine {[InstReturn]} return } - method si:next_punct {} { ; #TRACE puts "[format %8d [incr count]] RDE si:next_punct" + method si:next_punct {} { + debug.pt/rdengine {[Instruction si:next_punct]} #Asm::Ins i_input_next punct #Asm::Ins i:fail_return #Asm::Ins i_test_punct incr myloc if {($myloc >= [string length $mytoken]) && ![ExtendTC]} { set myok 0 set myerror [list $myloc [list punct]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] set myok [string is punct -strict $mycurrent] @@ -945,23 +1142,26 @@ set myerror [list $myloc [list punct]] incr myloc -1 } else { set myerror {} } + debug.pt/rdengine {[InstReturn]} return } - method si:next_space {} { ; #TRACE puts "[format %8d [incr count]] RDE si:next_space" + method si:next_space {} { + debug.pt/rdengine {[Instruction si:next_space]} #Asm::Ins i_input_next space #Asm::Ins i:fail_return #Asm::Ins i_test_space incr myloc if {($myloc >= [string length $mytoken]) && ![ExtendTC]} { set myok 0 set myerror [list $myloc [list space]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] set myok [string is space -strict $mycurrent] @@ -969,23 +1169,26 @@ set myerror [list $myloc [list space]] incr myloc -1 } else { set myerror {} } + debug.pt/rdengine {[InstReturn]} return } - method si:next_upper {} { ; #TRACE puts "[format %8d [incr count]] RDE si:next_upper" + method si:next_upper {} { + debug.pt/rdengine {[Instruction si:next_upper]} #Asm::Ins i_input_next upper #Asm::Ins i:fail_return #Asm::Ins i_test_upper incr myloc if {($myloc >= [string length $mytoken]) && ![ExtendTC]} { set myok 0 set myerror [list $myloc [list upper]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] set myok [string is upper -strict $mycurrent] @@ -993,23 +1196,26 @@ set myerror [list $myloc [list upper]] incr myloc -1 } else { set myerror {} } + debug.pt/rdengine {[InstReturn]} return } - method si:next_wordchar {} { ; #TRACE puts "[format %8d [incr count]] RDE si:next_wordchar" + method si:next_wordchar {} { + debug.pt/rdengine {[Instruction si:next_wordchar]} #Asm::Ins i_input_next wordchar #Asm::Ins i:fail_return #Asm::Ins i_test_wordchar incr myloc if {($myloc >= [string length $mytoken]) && ![ExtendTC]} { set myok 0 set myerror [list $myloc [list wordchar]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] set myok [string is wordchar -strict $mycurrent] @@ -1017,23 +1223,26 @@ set myerror [list $myloc [list wordchar]] incr myloc -1 } else { set myerror {} } + debug.pt/rdengine {[InstReturn]} return } - method si:next_xdigit {} { ; #TRACE puts "[format %8d [incr count]] RDE si:next_xdigit" + method si:next_xdigit {} { + debug.pt/rdengine {[Instruction si:next_xdigit]} #Asm::Ins i_input_next xdigit #Asm::Ins i:fail_return #Asm::Ins i_test_xdigit incr myloc if {($myloc >= [string length $mytoken]) && ![ExtendTC]} { set myok 0 set myerror [list $myloc [list xdigit]] # i:fail_return + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] set myok [string is xdigit -strict $mycurrent] @@ -1041,16 +1250,18 @@ set myerror [list $myloc [list xdigit]] incr myloc -1 } else { set myerror {} } + debug.pt/rdengine {[InstReturn]} return } # - -- --- ----- -------- ------------- --------------------- - method si:value_symbol_start {symbol} { ; #TRACE puts "[format %8d [incr count]] RDE si:value_symbol_start ($symbol)" + method si:value_symbol_start {symbol} { + debug.pt/rdengine {[Instruction si:value_symbol_start $symbol]} # if @runtime@ i_symbol_restore $symbol # i:found:ok_ast_value_push # i:found_return # i_loc_push # i_ast_push @@ -1059,34 +1270,42 @@ if {[info exists mysymbol($k)]} { lassign $mysymbol($k) myloc myok myerror mysvalue if {$myok} { $mystackast push $mysvalue } + debug.pt/rdengine {[InstReturn]} return -code return } $mystackloc push $myloc $mystackmark push [$mystackast size] + + debug.pt/rdengine {[InstReturn]} return } - method si:value_void_symbol_start {symbol} { ; #TRACE puts "[format %8d [incr count]] RDE si:value_void_symbol_start ($symbol)" + method si:value_void_symbol_start {symbol} { + debug.pt/rdengine {[Instruction si:value_void_symbol_start $symbol]} # if @runtime@ i_symbol_restore $symbol # i:found_return # i_loc_push # i_ast_push set k [list $myloc $symbol] if {[info exists mysymbol($k)]} { lassign $mysymbol($k) myloc myok myerror mysvalue + debug.pt/rdengine {[InstReturn]} return -code return } $mystackloc push $myloc $mystackmark push [$mystackast size] + + debug.pt/rdengine {[InstReturn]} return } - method si:void_symbol_start {symbol} { ; #TRACE puts "[format %8d [incr count]] RDE si:void_symbol_start ($symbol)" + method si:void_symbol_start {symbol} { + debug.pt/rdengine {[Instruction si:void_symbol_start $symbol]} # if @runtime@ i_symbol_restore $symbol # i:found:ok_ast_value_push # i:found_return # i_loc_push @@ -1094,31 +1313,39 @@ if {[info exists mysymbol($k)]} { lassign $mysymbol($k) myloc myok myerror mysvalue if {$myok} { $mystackast push $mysvalue } + debug.pt/rdengine {[InstReturn]} return -code return } $mystackloc push $myloc + + debug.pt/rdengine {[InstReturn]} return } - method si:void_void_symbol_start {symbol} { ; #TRACE puts "[format %8d [incr count]] RDE si:void_void_symbol_start ($symbol)" + method si:void_void_symbol_start {symbol} { + debug.pt/rdengine {[Instruction si:void_void_symbol_start $symbol]} # if @runtime@ i_symbol_restore $symbol # i:found_return # i_loc_push set k [list $myloc $symbol] if {[info exists mysymbol($k)]} { lassign $mysymbol($k) myloc myok myerror mysvalue + debug.pt/rdengine {[InstReturn]} return -code return } $mystackloc push $myloc + + debug.pt/rdengine {[InstReturn]} return } - method si:reduce_symbol_end {symbol} { ; #TRACE puts "[format %8d [incr count]] RDE si:reduce_symbol_end ($symbol)" + method si:reduce_symbol_end {symbol} { + debug.pt/rdengine {[Instruction si:reduce_symbol_end $symbol]} # i_value_clear/reduce $symbol # i_symbol_save $symbol # i_error_nonterminal $symbol # i_ast_pop_rewind # i_loc_pop_discard @@ -1169,14 +1396,16 @@ $mystackast trim* [$mystackmark pop] if {$myok} { $mystackast push $mysvalue } + debug.pt/rdengine {[InstReturn]} return } - method si:void_leaf_symbol_end {symbol} { ; #TRACE puts "[format %8d [incr count]] RDE si:void_leaf_symbol_end ($symbol)" + method si:void_leaf_symbol_end {symbol} { + debug.pt/rdengine {[Instruction si:void_leaf_symbol_end $symbol]} # i_value_clear/leaf $symbol # i_symbol_save $symbol # i_error_nonterminal $symbol # i_loc_pop_discard # i:ok_ast_value_push @@ -1212,14 +1441,17 @@ }} if {$myok} { $mystackast push $mysvalue } + + debug.pt/rdengine {[InstReturn]} return } - method si:value_leaf_symbol_end {symbol} { ; #TRACE puts "[format %8d [incr count]] RDE si:value_leaf_symbol_end ($symbol)" + method si:value_leaf_symbol_end {symbol} { + debug.pt/rdengine {[Instruction si:value_leaf_symbol_end $symbol]} # i_value_clear/leaf $symbol # i_symbol_save $symbol # i_error_nonterminal $symbol # i_loc_pop_discard # i_ast_pop_rewind @@ -1257,14 +1489,17 @@ $mystackast trim* [$mystackmark pop] if {$myok} { $mystackast push $mysvalue } + + debug.pt/rdengine {[InstReturn]} return } - method si:value_clear_symbol_end {symbol} { ; #TRACE puts "[format %8d [incr count]] RDE si:value_clear_symbol_end ($symbol)" + method si:value_clear_symbol_end {symbol} { + debug.pt/rdengine {[Instruction si:value_clear_symbol_end $symbol]} # i_value_clear # i_symbol_save $symbol # i_error_nonterminal $symbol # i_loc_pop_discard # i_ast_pop_rewind @@ -1284,14 +1519,16 @@ set myerror [list $loc [list [list n $symbol]]] } }} $mystackast trim* [$mystackmark pop] + debug.pt/rdengine {[InstReturn]} return } - method si:void_clear_symbol_end {symbol} { ; #TRACE puts "[format %8d [incr count]] RDE si:void_clear_symbol_end ($symbol)" + method si:void_clear_symbol_end {symbol} { + debug.pt/rdengine {[Instruction si:void_clear_symbol_end $symbol]} # i_value_clear # i_symbol_save $symbol # i_error_nonterminal $symbol # i_loc_pop_discard @@ -1308,318 +1545,407 @@ lassign $myerror loc messages if {$loc == $pos} { set myerror [list $loc [list [list n $symbol]]] } }} + debug.pt/rdengine {[InstReturn]} return } # # ## ### ##### ######## ############# ##################### ## API - Instructions - Control flow - method i:ok_continue {} { ; #TRACE puts "[format %8d [incr count]] RDE i:ok_continue" + method i:ok_continue {} { + debug.pt/rdengine {[Instruction i:ok_continue]} if {!$myok} return return -code continue } - method i:fail_continue {} { ; #TRACE puts "[format %8d [incr count]] RDE i:fail_continue" + method i:fail_continue {} { + debug.pt/rdengine {[Instruction i:fail_continue]} if {$myok} return return -code continue } - method i:fail_return {} { ; #TRACE puts "[format %8d [incr count]] RDE i:fail_return" + method i:fail_return {} { + debug.pt/rdengine {[Instruction i:fail_return]} if {$myok} return return -code return } - method i:ok_return {} { ; #TRACE puts "[format %8d [incr count]] RDE i:ok_return" + method i:ok_return {} { + debug.pt/rdengine {[Instruction i:ok_return]} if {!$myok} return return -code return } # # ## ### ##### ######## ############# ##################### ## API - Instructions - Unconditional matching. - method i_status_ok {} { ; #TRACE puts "[format %8d [incr count]] RDE i_status_ok" + method i_status_ok {} { + debug.pt/rdengine {[Instruction i_status_ok]} set myok 1 + debug.pt/rdengine {[InstReturn]} return } - method i_status_fail {} { ; #TRACE puts "[format %8d [incr count]] RDE i_status_fail" + method i_status_fail {} { + debug.pt/rdengine {[Instruction i_status_fail]} set myok 0 + debug.pt/rdengine {[InstReturn]} return } - method i_status_negate {} { ; #TRACE puts "[format %8d [incr count]] RDE i_status_negate" + method i_status_negate {} { + debug.pt/rdengine {[Instruction i_status_negate]} set myok [expr {!$myok}] + debug.pt/rdengine {[InstReturn]} return } # # ## ### ##### ######## ############# ##################### ## API - Instructions - Error handling. - method i_error_clear {} { ; #TRACE puts "[format %8d [incr count]] RDE i_error_clear" + method i_error_clear {} { + debug.pt/rdengine {[Instruction i_error_clear]} set myerror {} + debug.pt/rdengine {[InstReturn]} return } - method i_error_push {} { ; #TRACE puts "[format %8d [incr count]] RDE i_error_push ($myerror)" + method i_error_push {} { + debug.pt/rdengine {[Instruction i_error_push]} $mystackerr push $myerror + debug.pt/rdengine {[InstReturn]} return } - method i_error_clear_push {} { ; #TRACE puts "[format %8d [incr count]] RDE i_error_clear_push ()" + method i_error_clear_push {} { + debug.pt/rdengine {[Instruction i_error_clear_push]} set myerror {} $mystackerr push {} + debug.pt/rdengine {[InstReturn]} return } - method i_error_pop_merge {} { ; #TRACE puts "[format %8d [incr count]] RDE i_error_pop_merge ($myerror)-/-([$mystackerr peek])" + method i_error_pop_merge {} { + debug.pt/rdengine {[Instruction i_error_pop_merge]} set olderror [$mystackerr pop] # We have either old or new error data, keep it. - if {![llength $myerror]} { set myerror $olderror ; return } - if {![llength $olderror]} return + if {![llength $myerror]} { set myerror $olderror ; debug.pt/rdengine {[InstReturn]} ; return } + if {![llength $olderror]} { debug.pt/rdengine {[InstReturn]} ; return } # If one of the errors is further on in the input choose that as # the information to propagate. lassign $myerror loe msgse lassign $olderror lon msgsn - if {$lon > $loe} { set myerror $olderror ; return } - if {$loe > $lon} return + if {$lon > $loe} { set myerror $olderror ; debug.pt/rdengine {[InstReturn]} ; return } + if {$loe > $lon} { debug.pt/rdengine {[InstReturn]} ; return } - # Equal locations, merge the message lists, set-like. + # Equal locations, merge the message lists. set myerror [list $loe [lsort -uniq [list {*}$msgse {*}$msgsn]]] + debug.pt/rdengine {[InstReturn]} return } - method i_error_nonterminal {symbol} { ; #TRACE puts "[format %8d [incr count]] RDE i_error_nonterminal ($symbol)" + method i_error_nonterminal {symbol} { + debug.pt/rdengine {[Instruction i_error_nonterminal $symbol]} # i_error_nonterminal -- Disabled. Generate only low-level # i_error_nonterminal -- errors until we have worked out how # i_error_nonterminal -- to integrate symbol information with # i_error_nonterminal -- them. Do not forget where this # i_error_nonterminal -- instruction is inlined. return # Inlined: Errors, Expected. if {![llength $myerror]} { - #TRACE puts "[format %8d $count] RDE i_error_nonterminal ($symbol) no error" + debug.pt/rdengine {no error} return } set pos [$mystackloc peek] incr pos lassign $myerror loc messages if {$loc != $pos} { - #TRACE puts "[format %8d $count] RDE i_error_nonterminal ($symbol) -- $myerror != $pos" + debug.pt/rdengine {my $myerror != pos $pos} return } set myerror [list $loc [list [list n $symbol]]] - TRACE puts "[format %8d $count] RDE i_error_nonterminal ($symbol) := $myerror" + + debug.pt/rdengine {::= ($myerror)} return } # # ## ### ##### ######## ############# ##################### ## API - Instructions - Basic input handling and tracking - method i_loc_pop_rewind/discard {} { ; #TRACE puts "[format %8d [incr count]] RDE i_loc_pop_rewind/discard (ok $myok ([expr {$myok ? "keep $myloc drop" : "back@"}] [$mystackloc peek]))" + method i_loc_pop_rewind/discard {} { + debug.pt/rdengine {[Instruction i_loc_pop_rewind/discard]} #$myparser i:fail_loc_pop_rewind #$myparser i:ok_loc_pop_discard #return set last [$mystackloc pop] - if {$myok} return - set myloc $last - return - } - - method i_loc_pop_discard {} { ; #TRACE puts "[format %8d [incr count]] RDE i_loc_pop_discard" - $mystackloc pop - return - } - - method i:ok_loc_pop_discard {} { ; #TRACE puts "[format %8d [incr count]] RDE i:ok_loc_pop_discard" - if {!$myok} return - $mystackloc pop - return - } - - method i_loc_pop_rewind {} { ; #TRACE puts "[format %8d [incr count]] RDE i_loc_pop_rewind" - set myloc [$mystackloc pop] - return - } - - method i:fail_loc_pop_rewind {} { ; #TRACE puts "[format %8d [incr count]] RDE i:fail_loc_pop_rewind" - if {$myok} return - set myloc [$mystackloc pop] - return - } - - method i_loc_push {} { ; #TRACE puts "[format %8d [incr count]] RDE i_loc_push (saving @$myloc)" - $mystackloc push $myloc - return - } - - method i_loc_rewind {} { ; #TRACE puts "[format %8d [incr count]] RDE i_loc_rewind" + if {!$myok} { + set myloc $last + } + debug.pt/rdengine {[InstReturn]} + return + } + + method i_loc_pop_discard {} { + debug.pt/rdengine {[Instruction i_loc_pop_discard]} + $mystackloc pop + debug.pt/rdengine {[InstReturn]} + return + } + + method i:ok_loc_pop_discard {} { + debug.pt/rdengine {[Instruction i:ok_loc_pop_discard]} + if {$myok} { + $mystackloc pop + } + debug.pt/rdengine {[InstReturn]} + return + } + + method i_loc_pop_rewind {} { + debug.pt/rdengine {[Instruction i_loc_pop_rewind]} + set myloc [$mystackloc pop] + debug.pt/rdengine {[InstReturn]} + return + } + + method i:fail_loc_pop_rewind {} { + debug.pt/rdengine {[Instruction i:fail_loc_pop_rewind]} + if {!$myok} { + set myloc [$mystackloc pop] + } + debug.pt/rdengine {[InstReturn]} + return + } + + method i_loc_push {} { + debug.pt/rdengine {[Instruction i_loc_push]} + $mystackloc push $myloc + debug.pt/rdengine {[InstReturn]} + return + } + + method i_loc_rewind {} { + debug.pt/rdengine {[Instruction i_loc_rewind]} # i_loc_pop_rewind - set myloc [$mystackloc pop] # i_loc_push - $mystackloc push $myloc - set myloc [$mystackloc peek] + debug.pt/rdengine {[InstReturn]} return } # # ## ### ##### ######## ############# ##################### ## API - Instructions - AST stack handling - method i_ast_pop_rewind/discard {} { ; #TRACE puts "[format %8d [incr count]] RDE i_ast_pop_rewind/discard" + method i_ast_pop_rewind/discard {} { + debug.pt/rdengine {[Instruction i_ast_pop_rewind/discard]} #$myparser i:fail_ast_pop_rewind #$myparser i:ok_ast_pop_discard #return set mark [$mystackmark pop] - if {$myok} return - $mystackast trim* $mark + if {!$myok} { + $mystackast trim* $mark + } + + debug.pt/rdengine {[InstReturn]} return } - method i_ast_pop_discard/rewind {} { ; #TRACE puts "[format %8d [incr count]] RDE i_ast_pop_discard/rewind" + method i_ast_pop_discard/rewind {} { + debug.pt/rdengine {[Instruction i_ast_pop_discard/rewind]} #$myparser i:ok_ast_pop_rewind #$myparser i:fail_ast_pop_discard #return set mark [$mystackmark pop] - if {!$myok} return - $mystackast trim* $mark - return - } - - method i_ast_pop_discard {} { ; #TRACE puts "[format %8d [incr count]] RDE i_ast_pop_discard" - $mystackmark pop - return - } - - method i:ok_ast_pop_discard {} { ; #TRACE puts "[format %8d [incr count]] RDE i:ok_ast_pop_discard" - if {!$myok} return - $mystackmark pop - return - } - - method i_ast_pop_rewind {} { ; #TRACE puts "[format %8d [incr count]] RDE i_ast_pop_rewind" - $mystackast trim* [$mystackmark pop] - return - } - - method i:fail_ast_pop_rewind {} { ; #TRACE puts "[format %8d [incr count]] RDE i:fail_ast_pop_rewind" - if {$myok} return - $mystackast trim* [$mystackmark pop] - return - } - - method i_ast_push {} { ; #TRACE puts "[format %8d [incr count]] RDE i_ast_push" - $mystackmark push [$mystackast size] - return - } - - method i:ok_ast_value_push {} { ; #TRACE puts "[format %8d [incr count]] RDE i:ok_ast_value_push" - if {!$myok} return - $mystackast push $mysvalue - return - } - - method i_ast_rewind {} { ; #TRACE puts "[format %8d [incr count]] RDE i_ast_rewind" + if {$myok} { + $mystackast trim* $mark + } + + debug.pt/rdengine {[InstReturn]} + return + } + + method i_ast_pop_discard {} { + debug.pt/rdengine {[Instruction i_ast_pop_discard]} + $mystackmark pop + + debug.pt/rdengine {[InstReturn]} + return + } + + method i:ok_ast_pop_discard {} { + debug.pt/rdengine {[Instruction i:ok_ast_pop_discard]} + if {$myok} { + $mystackmark pop + } + + debug.pt/rdengine {[InstReturn]} + return + } + + method i_ast_pop_rewind {} { + debug.pt/rdengine {[Instruction i_ast_pop_rewind]} + $mystackast trim* [$mystackmark pop] + + debug.pt/rdengine {[InstReturn]} + return + } + + method i:fail_ast_pop_rewind {} { + debug.pt/rdengine {[Instruction i:fail_ast_pop_rewind]} + if {!$myok} { + $mystackast trim* [$mystackmark pop] + } + + debug.pt/rdengine {[InstReturn]} + return + } + + method i_ast_push {} { + debug.pt/rdengine {[Instruction i_ast_push]} + $mystackmark push [$mystackast size] + + debug.pt/rdengine {[InstReturn]} + return + } + + method i:ok_ast_value_push {} { + debug.pt/rdengine {[Instruction i:ok_ast_value_push]} + if {$myok} { + $mystackast push $mysvalue + } + + debug.pt/rdengine {[InstReturn]} + return + } + + method i_ast_rewind {} { + debug.pt/rdengine {[Instruction i_ast_rewind]} # i_ast_pop_rewind - $mystackast trim* [$mystackmark pop] # i_ast_push - $mystackmark push [$mystackast size] $mystackast trim* [$mystackmark peek] + + debug.pt/rdengine {[InstReturn]} return } # # ## ### ##### ######## ############# ##################### ## API - Instructions - Nonterminal cache - method i_symbol_restore {symbol} { ; #TRACE puts "[format %8d [incr count]] RDE i_symbol_restore ($symbol)" + method i_symbol_restore {symbol} { + debug.pt/rdengine {[Instruction i_symbol_restore $symbol]} # Satisfy from cache if possible. set k [list $myloc $symbol] - if {![info exists mysymbol($k)]} { return 0 } + if {![info exists mysymbol($k)]} { + debug.pt/rdengine {[InstReturn]} + return 0 + } lassign $mysymbol($k) myloc myok myerror mysvalue # We go forward, as the nonterminal matches (or not). + debug.pt/rdengine {[InstReturn]} return 1 } - method i_symbol_save {symbol} { ; #TRACE puts "[format %8d [incr count]] RDE i_symbol_save ($symbol)" + method i_symbol_save {symbol} { + debug.pt/rdengine {[Instruction i_symbol_save $symbol]} # Store not only the value, but also how far # the match went (if it was a match). set at [$mystackloc peek] set k [list $at $symbol] set mysymbol($k) [list $myloc $myok $myerror $mysvalue] + + debug.pt/rdengine {[InstReturn]} return } # # ## ### ##### ######## ############# ##################### ## API - Instructions - Semantic values. - method i_value_clear {} { ; #TRACE puts "[format %8d [incr count]] RDE i_value_clear" + method i_value_clear {} { + debug.pt/rdengine {[Instruction i_value_clear]} set mysvalue {} + + debug.pt/rdengine {[InstReturn]} return } - method i_value_clear/leaf {symbol} { ; #TRACE puts "[format %8d [incr count]] RDE i_value_clear/leaf ($symbol ok $myok ([expr {[$mystackloc peek]+1}])-@$myloc)" + method i_value_clear/leaf {symbol} { + debug.pt/rdengine {[Instruction i_value_clear/leaf $symbol] :: ([expr {[$mystackloc peek]+1}])-@$myloc)} + # not quite value_lead (guarded, and clear on fail) # Inlined clear, reduce, and optimized. # Clear ; if {$ok} {Reduce $symbol} set mysvalue {} - if {!$myok} return - set pos [$mystackloc peek] - incr pos - - if {($pos - 1) == $myloc} { - # The symbol did not process any input. As this is - # signaled to be ok (*) we create a node covering an empty - # range. (Ad *): Can happen for a RHS using toplevel - # operators * or ?. - set mysvalue [pt::ast new0 $symbol $pos] - } else { - set mysvalue [pt::ast new $symbol $pos $myloc] - } - return - } - - method i_value_clear/reduce {symbol} { ; #TRACE puts "[format %8d [incr count]] RDE i_value_clear/reduce ($symbol)" - set mysvalue {} - if {!$myok} return - - set mark [$mystackmark peek];# Old size of stack before current nt pushed more. - set newa [expr {[$mystackast size] - $mark}] - - set pos [$mystackloc peek] - incr pos - - if {!$newa} { - set mysvalue {} - } elseif {$newa == 1} { - # peek 1 => single element comes back - set mysvalue [list [$mystackast peek]] ; # SaveToMark - } else { - # peek n > 1 => list of elements comes back - set mysvalue [$mystackast peekr $newa] ; # SaveToMark - } - - if {($pos - 1) == $myloc} { - # The symbol did not process any input. As this is - # signaled to be ok (*) we create a node covering an empty - # range. (Ad *): Can happen for a RHS using toplevel - # operators * or ?. - set mysvalue [pt::ast new0 $symbol $pos {*}$mysvalue] - } else { - set mysvalue [pt::ast new $symbol $pos $myloc {*}$mysvalue] ; # Reduce $symbol - } + if {$myok} { + set pos [$mystackloc peek] + incr pos + + if {($pos - 1) == $myloc} { + # The symbol did not process any input. As this is + # signaled to be ok (*) we create a node covering an empty + # range. (Ad *): Can happen for a RHS using toplevel + # operators * or ?. + set mysvalue [pt::ast new0 $symbol $pos] + } else { + set mysvalue [pt::ast new $symbol $pos $myloc] + } + } + + debug.pt/rdengine {[InstReturn]} + return + } + + method i_value_clear/reduce {symbol} { + debug.pt/rdengine {[Instruction i_value_clear/reduce $symbol]} + set mysvalue {} + if {$myok} { + set mark [$mystackmark peek];# Old size of stack before current nt pushed more. + set newa [expr {[$mystackast size] - $mark}] + + set pos [$mystackloc peek] + incr pos + + if {!$newa} { + set mysvalue {} + } elseif {$newa == 1} { + # peek 1 => single element comes back + set mysvalue [list [$mystackast peek]] ; # SaveToMark + } else { + # peek n > 1 => list of elements comes back + set mysvalue [$mystackast peekr $newa] ; # SaveToMark + } + + if {($pos - 1) == $myloc} { + # The symbol did not process any input. As this is + # signaled to be ok (*) we create a node covering an empty + # range. (Ad *): Can happen for a RHS using toplevel + # operators * or ?. + set mysvalue [pt::ast new0 $symbol $pos {*}$mysvalue] + } else { + set mysvalue [pt::ast new $symbol $pos $myloc {*}$mysvalue] ; # Reduce $symbol + } + } + + debug.pt/rdengine {[InstReturn]} return } # # ## ### ##### ######## ############# ##################### ## API - Instructions - Terminal matching - method i_input_next {msg} { ; #TRACE puts "[format %8d [incr count]] RDE i_input_next ($msg)" + method i_input_next {msg} { + debug.pt/rdengine {[Instruction i_input_next $msg]} # Inlined: Getch, Expected, ClearErrors # Satisfy from input cache if possible. incr myloc # May read from the input (ExtendTC), and remember the @@ -1626,134 +1952,167 @@ # information. Note: We are implicitly incrementing the # location! if {($myloc >= [string length $mytoken]) && ![ExtendTC]} { set myok 0 set myerror [list $myloc [list $msg]] + + debug.pt/rdengine {[InstReturn]} return } set mycurrent [string index $mytoken $myloc] set myok 1 set myerror {} + + debug.pt/rdengine {[InstReturn]} return } - method i_test_char {tok} { ; #TRACE puts "[format %8d [incr count]] RDE i_test_char (ok [expr {$tok eq $mycurrent}], [expr {$tok eq $mycurrent ? "@$myloc" : "back@[expr {$myloc-1}]"}])" + method i_test_char {tok} { + debug.pt/rdengine {[Instruction i_test_char $tok] :: ok [expr {$tok eq $mycurrent}], [expr {$tok eq $mycurrent ? "@$myloc" : "back@[expr {$myloc-1}]"}]} set myok [expr {$tok eq $mycurrent}] - if {$myok} { - set myerror {} - } else { - set myerror [list $myloc [list [pt::pe terminal $tok]]] - incr myloc -1 - } + OkFailD {pt::pe terminal $tok} + + debug.pt/rdengine {[InstReturn]} return } - method i_test_range {toks toke} { ; #TRACE puts "[format %8d [incr count]] RDE i_test_range ($toks $toke)" + method i_test_range {toks toke} { + debug.pt/rdengine {[Instruction i_test_range $toks $toke]} set myok [expr { ([string compare $toks $mycurrent] <= 0) && ([string compare $mycurrent $toke] <= 0) }] ; # {} - if {$myok} { - set myerror {} - } else { - set myerror [list $myloc [list [pt::pe range $toks $toke]]] - incr myloc -1 - } - return - } - - method i_test_alnum {} { ; #TRACE puts "[format %8d [incr count]] RDE i_test_alnum" - set myok [string is alnum -strict $mycurrent] - OkFail alnum - return - } - - method i_test_alpha {} { ; #TRACE puts "[format %8d [incr count]] RDE i_test_alpha" - set myok [string is alpha -strict $mycurrent] - OkFail alpha - return - } - - method i_test_ascii {} { ; #TRACE puts "[format %8d [incr count]] RDE i_test_ascii" - set myok [string is ascii -strict $mycurrent] - OkFail ascii - return - } - - method i_test_control {} { ; #TRACE puts "[format %8d [incr count]] RDE i_test_control" - set myok [string is control -strict $mycurrent] - OkFail control - return - } - - method i_test_ddigit {} { ; #TRACE puts "[format %8d [incr count]] RDE i_test_ddigit" - set myok [string match {[0-9]} $mycurrent] - OkFail ddigit - return - } - - method i_test_digit {} { ; #TRACE puts "[format %8d [incr count]] RDE i_test_digit" - set myok [string is digit -strict $mycurrent] - OkFail digit - return - } - - method i_test_graph {} { ; #TRACE puts "[format %8d [incr count]] RDE i_test_graph" - set myok [string is graph -strict $mycurrent] - OkFail graph - return - } - - method i_test_lower {} { ; #TRACE puts "[format %8d [incr count]] RDE i_test_lower" - set myok [string is lower -strict $mycurrent] - OkFail lower - return - } - - method i_test_print {} { ; #TRACE puts "[format %8d [incr count]] RDE i_test_print" - set myok [string is print -strict $mycurrent] - OkFail print - return - } - - method i_test_punct {} { ; #TRACE puts "[format %8d [incr count]] RDE i_test_punct" - set myok [string is punct -strict $mycurrent] - OkFail punct - return - } - - method i_test_space {} { ; #TRACE puts "[format %8d [incr count]] RDE i_test_space" - set myok [string is space -strict $mycurrent] - OkFail space - return - } - - method i_test_upper {} { ; #TRACE puts "[format %8d [incr count]] RDE i_test_upper" - set myok [string is upper -strict $mycurrent] - OkFail upper - return - } - - method i_test_wordchar {} { ; #TRACE puts "[format %8d [incr count]] RDE i_test_wordchar" - set myok [string is wordchar -strict $mycurrent] - OkFail wordchar - return - } - - method i_test_xdigit {} { ; #TRACE puts "[format %8d [incr count]] RDE i_test_xdigit" - set myok [string is xdigit -strict $mycurrent] - OkFail xdigit - return - } - - # # ## ### ##### ######## ############# ##################### - ## Debugging helper. To activate - ## string map {{; #TRACE} {; TRACE}} - - proc TRACE {args} { - uplevel 1 $args + OkFailD {pt::pe range $toks $toke} + + debug.pt/rdengine {[InstReturn]} + return + } + + method i_test_alnum {} { + debug.pt/rdengine {[Instruction i_test_alnum]} + set myok [string is alnum -strict $mycurrent] + OkFail alnum + + debug.pt/rdengine {[InstReturn]} + return + } + + method i_test_alpha {} { + debug.pt/rdengine {[Instruction i_test_alpha]} + set myok [string is alpha -strict $mycurrent] + OkFail alpha + + debug.pt/rdengine {[InstReturn]} + return + } + + method i_test_ascii {} { + debug.pt/rdengine {[Instruction i_test_ascii]} + set myok [string is ascii -strict $mycurrent] + OkFail ascii + + debug.pt/rdengine {[InstReturn]} + return + } + + method i_test_control {} { + debug.pt/rdengine {[Instruction i_test_control]} + set myok [string is control -strict $mycurrent] + OkFail control + + debug.pt/rdengine {[InstReturn]} + return + } + + method i_test_ddigit {} { + debug.pt/rdengine {[Instruction i_test_ddigit]} + set myok [string match {[0-9]} $mycurrent] + OkFail ddigit + + debug.pt/rdengine {[InstReturn]} + return + } + + method i_test_digit {} { + debug.pt/rdengine {[Instruction i_test_digit]} + set myok [string is digit -strict $mycurrent] + OkFail digit + + debug.pt/rdengine {[InstReturn]} + return + } + + method i_test_graph {} { + debug.pt/rdengine {[Instruction i_test_graph]} + set myok [string is graph -strict $mycurrent] + OkFail graph + + debug.pt/rdengine {[InstReturn]} + return + } + + method i_test_lower {} { + debug.pt/rdengine {[Instruction i_test_lower]} + set myok [string is lower -strict $mycurrent] + OkFail lower + + debug.pt/rdengine {[InstReturn]} + return + } + + method i_test_print {} { + debug.pt/rdengine {[Instruction i_test_print]} + set myok [string is print -strict $mycurrent] + OkFail print + + debug.pt/rdengine {[InstReturn]} + return + } + + method i_test_punct {} { + debug.pt/rdengine {[Instruction i_test_punct]} + set myok [string is punct -strict $mycurrent] + OkFail punct + + debug.pt/rdengine {[InstReturn]} + return + } + + method i_test_space {} { + debug.pt/rdengine {[Instruction i_test_space]} + set myok [string is space -strict $mycurrent] + OkFail space + + debug.pt/rdengine {[InstReturn]} + return + } + + method i_test_upper {} { + debug.pt/rdengine {[Instruction i_test_upper]} + set myok [string is upper -strict $mycurrent] + OkFail upper + + debug.pt/rdengine {[InstReturn]} + return + } + + method i_test_wordchar {} { + debug.pt/rdengine {[Instruction i_test_wordchar]} + set myok [string is wordchar -strict $mycurrent] + OkFail wordchar + + debug.pt/rdengine {[InstReturn]} + return + } + + method i_test_xdigit {} { + debug.pt/rdengine {[Instruction i_test_xdigit]} + set myok [string is xdigit -strict $mycurrent] + OkFail xdigit + + debug.pt/rdengine {[InstReturn]} return } # # ## ### ##### ######## ############# ##################### ## Internals @@ -1832,10 +2191,12 @@ # # i:{ok,fail}_{continue,return}. typevariable ourmsg -array {} typeconstructor { + debug.pt/rdengine {} + set ourmsg(alnum) [pt::pe alnum] set ourmsg(alpha) [pt::pe alpha] set ourmsg(ascii) [pt::pe ascii] set ourmsg(control) [pt::pe control] set ourmsg(ddigit) [pt::pe ddigit] @@ -1846,10 +2207,12 @@ set ourmsg(punct) [pt::pe punct] set ourmsg(space) [pt::pe space] set ourmsg(upper) [pt::pe upper] set ourmsg(wordchar) [pt::pe wordchar] set ourmsg(xdigit) [pt::pe xdigit] + + debug.pt/rdengine {/done} return } # Parser Input (channel, location (line, column)) ...........