source: WorldVistAEHR/trunk/r/VA_FILEMAN-ARJT-DI-DD-DM-DT-%DT-%RCR/ARJTDIM2.m@ 1046

Last change on this file since 1046 was 613, checked in by George Lilly, 15 years ago

initial load of WorldVistAEHR

File size: 5.1 KB
Line 
1ARJTDIM2 ;SFISC/XAK,GFT,TOAD-FileMan: M Syntax Checker, Exprs ;5/27/2004 00:19
2 ;;3.0T1;OPENVISTA;;Jun 20, 2004
3 ;
4 ; Change History:
5 ; 2004 05 27 WV/TOAD: commented up GLO and added check for extended
6 ; global ref. Fixed comment at end of ADD.
7 ;
8SUB ; "(": open paren situations (GG^ARJTDIM1)
9 F %J=%I-1:-1 S %C1=$E(%,%J) I %C1'?1UN,%C1'="%" Q
10 S %C1=$E(%,%J+1,%I-1)
11 I %C1]"",%C1'?1U.UN,%C1'?1"%".UN G ERR
12 I %C1]"",%[("."_%C1) G ERR
13 S %(%N,0)=$S(%C1]""!($E(%,%J)="^"):"V^",$E(%,%J)="@":"@^",1:"0^")
14 S %(%N,1)=0,%(%N,2)=0,%(%N,3)=0,%N=%N+1 G 1
15 ;
16UP ; ")": close paren situations (GG^ARJTDIM1)
17 I %N=0 G ERR
18 I "(,"[$E(%,%I-1),$P($G(%(%N-1,0)),"^")'["P" G ERR
19 I $E(%,%I+1)]"","<>_[]:/\?'+-=!&#*),"""'[$E(%,%I+1) G ERR
20 S %N=%N-1,%(%N,1)=%(%N,1)+1,%F=$P(%(%N,0),"^") I %F D G ERR:%ERR
21 . S %F=$P(%(%N,0),"^",2),%F1=%(%N,1)
22 . I %F1<+%F S %ERR=1 Q ; not enough commas for this function
23 . I %F1>$P(%F,";",2) S %ERR=1 Q ; too many commas for this function
24 . I %(%N,2),'%(%N,3) S %ERR=1 ; we're in $S and haven't yet hit a :
25 K %(%N+1)
26 I '%F,%F'["V",%F'["@",%F'["P",%(%N,1)>1 G ERR
27 G 1
28 ;
29AR ; ",": comma situations -- "P" below means "parameters" (GG^ARJTDIM1)
30 I %N<1 G ERR
31 I "(,"[$E(%,%I-1),$P($G(%(%N-1,0)),"^")'["P" G ERR
32 I '%(%N-1,3),%(%N-1,2) G ERR
33 I "@("[$E(%,1,2) G ERR
34 S %(%N-1,1)=%(%N-1,1)+1,%(%N-1,3)=0 G 1
35 ;
36SEL ; ":": $SELECT delimiter (GG^ARJTDIM1)
37 S %(%N-1,3)=%(%N-1,3)+1 G ERR:'%(%N-1,2)!(%(%N-1,3)>1),1
38 ;
39 ;
40GLO ; "^": global reference (GG^ARJTDIM1)
41 ;
42 ; This does not deeply evaluate gvns. It just screens some bad
43 ; syntax then passes them back to GG without the leading ^ for
44 ; eval as either a local or a subscript/argument list (if the
45 ; gvn was a naked).
46 ;
47 ; Inputs:
48 ; %: expr or argument to eval
49 ; %I: character position (#) of ^ in %
50 ; %C: ^
51 ;
52 D %INC ; advance %I & %C to character after ^
53 I $E(%,%I,999)?1"["1.E1"]"1.E D ADD("^[]",.FOUND) ; log ext gvn
54 I $E(%,%I,999)'?1U.UN.P.E,"%("'[%C G ERR ; ensure that what follows
55 ; starts with an upper, a %, or a (, and no ctrl chars after an upper
56 ; this could probably use some tightening up at some point
57 I "=+-\/<>(,#!&*':@[]_"'[$E(%,%I-2) G ERR ; only one of the listed
58 ; characters may precede a global ref; anythign else is an error
59 S %I=%I-1 ; back up in prep for returning to GG
60 G 1 ; evaluate rest of global name like a lvn or paren list
61 ;
62 ;
63PAT ; "?": pattern match (GG^ARJTDIM1)
64 G ERR:%I=1
65 I $E(%,%I+1)="@" S FOUND("?@")="",FOUND=FIND="?@"!FOUND G 1
66 S FOUND("?")=""
67 D %INC,PATTERN G ERR:%ERR S %I=%I-1 G 1
68 ;
69PATTERN F D PATATOM Q:%C'?1N&(%C'=".")!%ERR
70 Q
71PATATOM D REPCOUNT Q:%ERR
72 I %C="""" D STRLIT,%INC:'%ERR Q
73 I %C="(" D ALTRN8 Q
74 D PATCODE
75 Q
76REPCOUNT ;
77 I %C'?1N,%C'="." S %ERR=1 Q
78 N FROM S FROM=+$E(%,%I,999) I %C?1N D INTLIT Q:%ERR
79 I %C="." D %INC
80 Q:%C'?1N I +$E(%,%I,999)<FROM S %ERR=1 Q
81 D INTLIT Q
82INTLIT I %C'?1N S %ERR=1 Q
83 F D %INC Q:%C'?1N
84 Q
85STRLIT F D %INC Q:%C="" I %C="""" Q:$E(%,%I+1)'="""" S %I=%I+1
86 I %C="" S %ERR=1
87 Q
88PATCODE I "ACELNPU"'[%C!(%C="") S %ERR=1 Q
89 F D %INC Q:%C="" Q:"ACELNPU"'[%C
90 Q
91ALTRN8 I %C'="(" S %ERR=1 Q
92 I FIND="?(" D ADD("?(",.FOUND) S FOUND=1
93 D %INC,PATATOM Q:%ERR
94 F Q:","'[%C D %INC,PATATOM Q:%ERR
95 I %C'=")" S %ERR=1 Q
96 D %INC
97 Q
98 ;
99BINOP ; binary operator (GG^ARJTDIM1)
100 S %Z1=""")%'",%Z2="""($+-^%@'." G OPCHK
101 ;
102MTHOP ; math or relational operator (GG^ARJTDIM1)
103 S %Z1=""")%",%Z2="""($+-^%@'." G OPCHK
104 ;
105UNOP ; unary operator (GG^ARJTDIM1)
106 S %Z1=""":<>+-'\/()%@#&!*=_][,"
107 S %Z2="""($+-=&!^%.@'" I %C="'" S %Z2=%Z2_"<>?[]"
108 G OPCHK
109 ;
110IND ; "@": indirection (GG^ARJTDIM1)
111 D ADD("@",.FOUND)
112 I $E(%COM)="F" G ERR
113 S %Z1="^?@(%+-=\/#*!&'_<>[]:,.",%Z2="""(+^-'$@%" G OPCHK
114 ;
115OPCHK ; ensure that the characters before and after the operator are OK
116 S %L1=$E(%,%I-1),%L2=$E(%,%I+1) I %L1="'","[]&!<>="[%C S %L1=$E(%,%I-2)
117 I %L1="","+-'@"'[%C G ERR ; binary: require before
118 I %L1'?1UN,%Z1'[%L1 G ERR ; all: screen before
119 F %F="*","]" I %C=%F,%L2=%F S %I=%I+1,%L2=$E(%,%I+1) Q
120 I %L2="" G ERR ; all: require after
121 I %L2'?1UN,%Z2'[%L2 G ERR ; all: screen after
122 I %C="'","!&[]?=<>"'[%L2,%L1?1UN G ERR ; unary ': not binary
123 G 1
124 ;
1251 ; common exit point for all of ^ARJTDIM2
126 G GG^ARJTDIM1
127 ;
128DATA ; glvn arguments of $D,$G,$NA,$O, & $Q functions (FUNC^ARJTDIM1)
129 D %INC G ERR:%C="",ERR:%C=")",DATA:"^@"[%C D VAR
130 G ERR:"@(,)"'[%C!%ERR,GG1^ARJTDIM1
131 ;
132VAR ; variables encountered while parsing exprs (DATA, GG^ARJTDIM1)
133 N %START S %START=%I-1 I $E(%,%START)="^" S %START=%START-1
134 I %C="%" D %INC
135 N OUT S OUT=0 F %J=%I:1 S %C=$E(%,%J) D Q:OUT
136 . I ",<>?/\[]+-=_()*&#!':"[%C S OUT=1 Q
137 . I %C="@",$E(%,%J+1)="(",$E(%,%START)="@" S OUT=1 Q
138 . I %C'?1UN S %ERR=1
139 . I %C="^",$D(%(%N-1,"F")),%(%N-1,"F")["TEXT" S %ERR=0,OUT=1
140 Q:%ERR
141 I %C="@" S %I=%J Q
142 S %F=$E(%,%I,%J-1)
143 I %F="^",$E(%,%J)'="(" S %ERR=1
144 I %F]"",%F'?1U.UN,$E(%,%I-1,%J-1)'?1"%".UN S %ERR=1
145 S %I=%J Q
146 ;
147%INC S %I=%I+1,%C=$E(%,%I)
148 Q
149 ;
150ADD(ELEMENT,FOUND) ; record element found
151 ; Input: ELEMENT = code for element found, e.g., "F".
152 ; Output: .FOUND(ELEMENT) = increment # times found
153 S FOUND=1
154 S FOUND(ELEMENT)=$G(FOUND(ELEMENT))+1
155 Q ; end of ADD
156 ;
157ERR S %ERR=1,%N=0
158FINISH G ERR:%N'=0 K %C,%,%F,%F1,%I,%J,%L1,%L2,%N,%T,%Z1,%Z2,%FN,%FZ
159Q Q
Note: See TracBrowser for help on using the repository browser.