1 /****************************************************************/
2 /* file syntchk.c
3 
4 ARIBAS interpreter for Arithmetic
5 Copyright (C) 1996 O.Forster
6 
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11 
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 Address of the author
22 
23     Otto Forster
24     Math. Institut der LMU
25     Theresienstr. 39
26     D-80333 Muenchen, Germany
27 
28 Email   forster@rz.mathematik.uni-muenchen.de
29 */
30 /****************************************************************/
31 
32 /*
33 ** syntchk.c
34 ** tools for syntax checks
35 **
36 ** date of last change
37 ** 95-03-26
38 */
39 
40 #include "common.h"
41 
42 PUBLIC void inisyntchk  _((void));
43 PUBLIC int chknargs _((truc fun, int n));
44 
45 enum signatures {
46     S_dum,
47     S_0,
48     S_01,
49     S_02,
50     S_0u,
51     S_1,
52     S_1u,
53     S_12,
54     S_bV,
55     S_rr,
56     S_vr,
57     S_ii,
58     S_iI,
59     S_bs,
60     S_nv,
61     S_rrr,
62     S_iii,
63     S_12ii,
64     S_12rn,
65     S_13,
66     S_14,
67     S_2,
68     S_23,
69     S_3,
70     S_0uii,
71     S_iiii,
72     S_4,
73     S_Viiii,
74     S_iiiII,
75     SIGMAX
76 };
77 
78 PUBLIC int s_dum = S_dum,
79        s_0   = S_0,
80        s_01  = S_01,
81        s_02  = S_02,
82        s_0u  = S_0u,
83        s_1   = S_1,
84        s_1u  = S_1u,
85        s_12  = S_12,
86        s_bV  = S_bV,
87        s_rr  = S_rr,
88        s_vr  = S_vr,
89        s_ii  = S_ii,
90        s_iI  = S_iI,
91        s_bs  = S_bs,
92        s_nv  = S_nv,
93        s_rrr = S_rrr,
94        s_iii = S_iii,
95        s_12ii = S_12ii,
96        s_12rn = S_12rn,
97        s_13 = S_13,
98        s_14 = S_14,
99        s_2 = S_2,
100        s_23 = S_23,
101        s_3 = S_3,
102        s_0uii = S_0uii,
103        s_iiii = S_iiii,
104        s_4 = S_4,
105        s_Viiii = S_Viiii,
106        s_iiiII = S_iiiII;
107 
108 PRIVATE char *SigString[SIGMAX];
109 
110 #define MAXBYTE     255
111 
112 /*--------------------------------------------------------------------*/
inisyntchk()113 PUBLIC void inisyntchk()
114 {
115 
116     SigString[s_dum] = "";
117 
118     SigString[s_0] = "\001";
119     SigString[s_01] = "\377\001\002";
120     SigString[s_02] = "\377\001\003";
121     SigString[s_0u] = "\377\001\377";
122     SigString[s_1] = "\002";
123     SigString[s_1u] = "\377\002\377";
124     SigString[s_12] = "\377\002\003";
125     SigString[s_bV] = "\002bV";
126     SigString[s_rr] = "\002rr";
127     SigString[s_vr] = "\002vr";
128     SigString[s_ii] = "\002ii";
129     SigString[s_iI] = "\002iI";
130     SigString[s_bs] = "\002bs";
131     SigString[s_nv] = "\002nv";
132     SigString[s_rrr] = "\003rrr";
133     SigString[s_iii] = "\003iii";
134     SigString[s_12ii] = "\377\002\003ii";
135     SigString[s_12rn] = "\377\002\003rn";
136     SigString[s_13] = "\377\002\004";
137     SigString[s_14] = "\377\002\005";
138     SigString[s_2] = "\003";
139     SigString[s_23] = "\377\003\004";
140     SigString[s_3] = "\004";
141     SigString[s_0uii] = "\377\001\377ii";
142     SigString[s_iiii] = "\004iiii";
143     SigString[s_4] = "\005";
144     SigString[s_Viiii] = "\005Viiii";
145     SigString[s_iiiII] = "\005iiiII";
146 }
147 /*--------------------------------------------------------------------*/
148 /*
149 ** check number of arguments of builtin functions
150 */
chknargs(fun,n)151 PUBLIC int chknargs(fun,n)
152 truc fun;
153 int n;
154 {
155     struct symbol *sptr;
156     char *ss;
157     int k, k1, k2;
158     int ret;
159     int sflg;
160 
161     sptr = symptr(fun);
162     sflg = *FLAGPTR(sptr);
163     if(sflg == sFBINARY || sflg == sSBINARY) {
164         ss = SigString[sptr->cc.yy.ww];
165         k = (byte)ss[0];
166         if(k != MAXBYTE && n+1 == k)
167             ret = NARGS_OK;
168         else if(k == MAXBYTE) {
169             k1 = (byte)ss[1];
170             k2 = (byte)ss[2];
171             if(n+1 < k1 || (k2 != MAXBYTE && n+1 > k2))
172                 ret = NARGS_FALSE;
173             else
174                 ret = NARGS_VAR;
175         }
176         else
177             ret = NARGS_FALSE;
178     }
179     else {  /* user defined function */
180         ret = NARGS_OK;     /* vorlaeufig */
181     }
182     return(ret);
183 }
184 /**********************************************************************/
185