Kevin wrote:
>Wow! Did you write that special for me? I'll check this code out!
Yes, and to see what further discussion might come of it. It is not complete,
but I think
it will fit most of the need you described for interactive syntax checking in a
debugger.
I have been thinking that I would like to have some good and simple functions
for code
parsing and syntax checking that would return something descriptive of any
errors encountered.
Here's a newer version that is a little more general in that it allows
unsubscripted
variables and longer variable names. It is not a general expression checker but
more
focused to the given context and perhaps a little easier to understand and
improve upon.
eval(ref) ;function - evaluate a simple variable reference
n name,subs,i,j,sub,error
s name=$p(ref,"(")
if name'?.1"^"1(1"%",1A).31AN q "ERROR: not a legal variable name."
if ref["(" q:ref'?.e1")" "ERROR: missing close paren." d
. s subs=$e(ref,$f(ref,"("),$l(ref)-1)
. f i=1:1 d q:subs=""!$d(error)
. . f j=1:1:$l(subs,",") s sub=$p(subs,",",1,j) q:$l(sub,"""")#2
. . s subs=$p(subs,",",j+1,$l(subs,","))
. . if sub="" s error="missing subscript" q
. . e if $l(sub,"""")#2=0 s error="unbalanced quotes" q
. . e if sub?.1"-"1.n,sub=+sub q ;canonic number OK
. . e if sub?1(1"%",1A).31AN d q ;simple variable name OK if defined
. . . if $d(@sub)#2=0 s error="variable '"_sub_"' undefined"
. . e if sub'?1""""1.e1"""" s error="malformed subscript" q
if $d(error) q "ERROR: "_error_", subscript "_i_"."
q $g(@ref)
I would refine it further by separating the evaluation from the syntax check
and adding an
error trap to the evaluation function. However, if you don't need to check the
data
reference independently of eval, it would be simpler to just try $g(@ref) and
let the
error trap return the message from your MUMPS interpreter.
>Dave Whitten called and pointed out that I could do this, also:
>
>> >set X=$UP^XLFSTR("SET TEMP=$GET("_myref_")") do ^DIM
>
>By forcing uppercase, I am changing the actual variable examined. But
>it will still catch null nodes etc.
I stopped using ^DIM many years ago for multiple reasons. It has undoubtedly
improved
significantly since then. I will have to revisit it.
>Thanks all!
>
>Kevin
>
>
>
>On 2/16/06, Jim Self <[EMAIL PROTECTED]> wrote:
>> Kevin wrote:
>> >Well, I had hope the ^DIM would work for me. Unfortunately it imposes
>> >SAC (SAAC? SACC?) restrictions. It I try this"
>> >
>> >set X="SET TEMP=$GET(k)" do ^DIM
>> >
>> >X will be deleted. I assume this is because lowercase variables are
>> >not allowed.
>> >My debugger is not designed to be VA specific, so allow a user to use
>> >variables with lower case.
>> >
>> >I'll have to keep looking for a solution. My next plan is to $piece
>> >through the parts of a reference to ensure no null nodes.
>>
>> If that's all you want, how about this for a start?
>>
>> eval(k) ;function - evaluate a simple array reference
>> if k'?.1"^"1(1"%",1A).7AN1"("1.ANP1")" q "ERROR: not an array
>> reference"
>> n subs s subs=$e(k,$f(k,"("),$l(k)-1)
>> n i,j,sub,error
>> f i=1:1 d q:subs=""!$d(error)
>> . f j=1:1:$l(subs,",") s sub=$p(subs,",",1,j) q:$l(sub,"""")#2
>> . s subs=$p(subs,",",j+1,$l(subs,","))
>> . if sub="" s error="missing subscript" q
>> . e if $l(sub,"""")#2=0 s error="unbalanced quotes" q
>> . e if sub?.1"-"1.n,sub=+sub q ;canonic number OK
>> . e if sub?1(1"%",1A).7AN d q ;simple variable name OK if defined
>> . . if $d(@sub)#2=0 s error="variable '"_sub_"' undefined"
>> . e if sub'?1""""1.e1"""" s error="malformed subscript" q
>> if $d(error) q "ERROR: "_error_", subscript "_i_"."
>> q $g(@k)
>>
>> Examples---
>>
>> ^DIC(1,0,"GL") ^DIC(
>> ^DIC(1,,"GL") ERROR: missing subscript, subscript 2.
>> ^DIC(1,x,"GL") ERROR: variable 'x' undefined, subscript 2.
>> ^DIC(1,0,"GL) ERROR: unbalanced quotes, subscript 3.
>> ^DIC(1,0X,"GL") ERROR: malformed subscript, subscript 2.
>> ^DIC(1,00,"GL") ERROR: malformed subscript, subscript 2.
>>
>> ---------------------------------------
>> Jim Self
>> Systems Architect, Lead Developer
>> VMTH Computer Services, UC Davis
>> (http://www.vmth.ucdavis.edu/us/jaself)
---------------------------------------
Jim Self
Systems Architect, Lead Developer
VMTH Computer Services, UC Davis
(http://www.vmth.ucdavis.edu/us/jaself)
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Hardhats-members mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/hardhats-members