File grammar.y changed (mode: 100644) (index a196771..d443d63) |
... |
... |
int main(int argc, char **argv) |
114 |
114 |
%token COMMA |
%token COMMA |
115 |
115 |
%token AND |
%token AND |
116 |
116 |
%token OR |
%token OR |
117 |
|
%token NOT |
|
118 |
|
%token COMMA |
|
119 |
117 |
%token EQUALS |
%token EQUALS |
120 |
118 |
%token TIMES |
%token TIMES |
121 |
119 |
%token DIV |
%token DIV |
|
... |
... |
int main(int argc, char **argv) |
135 |
133 |
%token INTLIT |
%token INTLIT |
136 |
134 |
%token REALLIT |
%token REALLIT |
137 |
135 |
%token UNITTYPEINT |
%token UNITTYPEINT |
138 |
|
%token EQUALS |
|
139 |
136 |
|
|
140 |
137 |
%right EQUALS |
%right EQUALS |
141 |
138 |
%left AND OR |
%left AND OR |
|
... |
... |
expr: intexpr { $$.ty = gInteger; } |
198 |
195 |
| realexpr { $$.ty = gReal; } |
| realexpr { $$.ty = gReal; } |
199 |
196 |
| stringexpr { $$.ty = gString; } |
| stringexpr { $$.ty = gString; } |
200 |
197 |
| boolexpr { $$.ty = gBoolean; } |
| boolexpr { $$.ty = gBoolean; } |
201 |
|
| FUNCTION rid { if (lookup(&functions, $2.str) == NULL) { |
|
|
198 |
|
| FUNCTION rid { struct funcdecl *fd = lookup(&functions, $2.str); |
|
199 |
|
if (fd == NULL) { |
202 |
200 |
char ebuf[1024]; |
char ebuf[1024]; |
203 |
201 |
sprintf(ebuf, "Undefined function %s", $2.str); |
sprintf(ebuf, "Undefined function %s", $2.str); |
204 |
202 |
yyerrorex(3, ebuf); |
yyerrorex(3, ebuf); |
|
203 |
|
$$.ty = gCode; |
|
204 |
|
} else { |
|
205 |
|
if (fd->p->head != NULL) { |
|
206 |
|
char ebuf[1024]; |
|
207 |
|
sprintf(ebuf, "Function %s must not take any arguments when used as code", $2.str); |
|
208 |
|
yyerrorex(3, ebuf); |
|
209 |
|
} |
|
210 |
|
if (fd->ret == gBoolean) |
|
211 |
|
$$.ty = gCodeReturnsBoolean; |
|
212 |
|
else |
|
213 |
|
$$.ty = gCodeReturnsNoBoolean; |
205 |
214 |
} |
} |
206 |
|
$$.ty = gCode; |
|
207 |
215 |
} |
} |
208 |
216 |
| TNULL { $$.ty = gNull; } |
| TNULL { $$.ty = gNull; } |
209 |
217 |
| expr LEQ expr { checkcomparison($1.ty, $3.ty); $$.ty = gBoolean; } |
| expr LEQ expr { checkcomparison($1.ty, $3.ty); $$.ty = gBoolean; } |
|
... |
... |
funccall: rid LPAREN exprlistcompl RPAREN { |
285 |
293 |
sprintf(ebuf, "Call to non-constant function %s in constant function", $1.str); |
sprintf(ebuf, "Call to non-constant function %s in constant function", $1.str); |
286 |
294 |
yyerrorex(3, ebuf); |
yyerrorex(3, ebuf); |
287 |
295 |
} |
} |
288 |
|
checkParameters(fd->p, $3.pl); |
|
|
296 |
|
checkParameters(fd->p, $3.pl, (fd==fFilter || fd==fCondition)); |
289 |
297 |
$$.ty = fd->ret; |
$$.ty = fd->ret; |
290 |
298 |
} |
} |
291 |
299 |
} |
} |
|
... |
... |
funccall: rid LPAREN exprlistcompl RPAREN { |
303 |
311 |
yyerrorex(3, ebuf); |
yyerrorex(3, ebuf); |
304 |
312 |
$$.ty = gNull; |
$$.ty = gNull; |
305 |
313 |
} else { |
} else { |
306 |
|
checkParameters(fd->p, $3.pl); |
|
|
314 |
|
checkParameters(fd->p, $3.pl, (fd==fFilter || fd==fCondition)); |
307 |
315 |
$$.ty = fd->ret; |
$$.ty = fd->ret; |
308 |
316 |
} |
} |
309 |
317 |
} |
} |
|
... |
... |
nativefuncdecl: NATIVE rid TAKES optparam_list RETURNS opttype |
358 |
366 |
$$.fd->ret = $6.ty; |
$$.fd->ret = $6.ty; |
359 |
367 |
//printf("***** %s = %s\n", $2.str, $$.fd->ret->typename); |
//printf("***** %s = %s\n", $2.str, $$.fd->ret->typename); |
360 |
368 |
$$.fd->isconst = isconstant; |
$$.fd->isconst = isconstant; |
|
369 |
|
if (strcmp($$.fd->name, "Filter") == 0) |
|
370 |
|
fFilter = $$.fd; |
|
371 |
|
if (strcmp($$.fd->name, "Condition") == 0) |
|
372 |
|
fCondition = $$.fd; |
361 |
373 |
put(&functions, $$.fd->name, $$.fd); |
put(&functions, $$.fd->name, $$.fd); |
362 |
374 |
//showfuncdecl($$.fd); |
//showfuncdecl($$.fd); |
363 |
375 |
} |
} |
File misc.c changed (mode: 100644) (index 2f066ec..581850d) |
11 |
11 |
#include "grammar.tab.h" |
#include "grammar.tab.h" |
12 |
12 |
#include "misc.h" |
#include "misc.h" |
13 |
13 |
|
|
14 |
|
#define VERSIONSTR "1.0g" |
|
|
14 |
|
#define VERSIONSTR "1.0h" |
15 |
15 |
#define ERRORLEVELNUM 4 |
#define ERRORLEVELNUM 4 |
16 |
16 |
|
|
17 |
17 |
int fno; |
int fno; |
|
... |
... |
struct hashtable functions, globals, locals, params, types; |
34 |
34 |
struct hashtable *curtab; |
struct hashtable *curtab; |
35 |
35 |
struct typenode *retval, *retcheck; |
struct typenode *retval, *retcheck; |
36 |
36 |
char *curfile; |
char *curfile; |
37 |
|
struct typenode *gInteger, *gReal, *gBoolean, *gString, *gCode, *gHandle, *gNothing, *gNull, *gAny, *gNone; |
|
|
37 |
|
struct typenode *gInteger, *gReal, *gBoolean, *gString, *gCode, *gHandle, *gNothing, *gNull, *gAny, *gNone, *gCodeReturnsBoolean, *gCodeReturnsNoBoolean; |
|
38 |
|
struct funcdecl *fFilter, *fCondition; |
38 |
39 |
|
|
39 |
40 |
void addPrimitiveType(const char *name, struct typenode **toSave) |
void addPrimitiveType(const char *name, struct typenode **toSave) |
40 |
41 |
{ |
{ |
|
... |
... |
void init(int argc, char **argv) |
54 |
55 |
gNull = newtypenode("null", NULL); |
gNull = newtypenode("null", NULL); |
55 |
56 |
gAny = newtypenode("any", NULL); |
gAny = newtypenode("any", NULL); |
56 |
57 |
gNone = newtypenode("none", NULL); |
gNone = newtypenode("none", NULL); |
|
58 |
|
gCodeReturnsBoolean = newtypenode("codereturnsboolean", gCode); |
|
59 |
|
gCodeReturnsNoBoolean = newtypenode("codereturnsnoboolean", gCode); |
57 |
60 |
curtab = &globals; |
curtab = &globals; |
58 |
61 |
fno = 0; |
fno = 0; |
59 |
62 |
strict = 0; |
strict = 0; |
|
... |
... |
struct typenode *combinetype(struct typenode *n1, struct typenode *n2) { |
369 |
372 |
return gNone; |
return gNone; |
370 |
373 |
} |
} |
371 |
374 |
|
|
372 |
|
void checkParameters(const struct paramlist *func, const struct paramlist *inp) |
|
|
375 |
|
void checkParameters(const struct paramlist *func, const struct paramlist *inp, const int mustretbool) |
373 |
376 |
{ |
{ |
374 |
377 |
const struct typeandname *fi = func->head; |
const struct typeandname *fi = func->head; |
375 |
378 |
const struct typeandname *pi = inp->head; |
const struct typeandname *pi = inp->head; |
|
... |
... |
void checkParameters(const struct paramlist *func, const struct paramlist *inp) |
386 |
389 |
return; |
return; |
387 |
390 |
} |
} |
388 |
391 |
canconvert(pi->ty, fi->ty, 0); |
canconvert(pi->ty, fi->ty, 0); |
|
392 |
|
if (mustretbool && pi->ty != gCodeReturnsBoolean) { |
|
393 |
|
yyerrorex(3, "Functions passed to Filter or Condition must return a boolean"); |
|
394 |
|
return; |
|
395 |
|
} |
389 |
396 |
pi = pi->next; |
pi = pi->next; |
390 |
397 |
fi = fi->next; |
fi = fi->next; |
391 |
398 |
} |
} |
File misc.h changed (mode: 100644) (index 7cc4f38..95d8bb6) |
8 |
8 |
#define YYDEBUG 1 |
#define YYDEBUG 1 |
9 |
9 |
|
|
10 |
10 |
#define BUFSIZE 8192 |
#define BUFSIZE 8192 |
11 |
|
|
|
|
11 |
|
#define MAYBE 0 |
|
12 |
|
#define NO 1 |
|
13 |
|
#define YES 2 |
12 |
14 |
|
|
13 |
15 |
struct typenode { |
struct typenode { |
14 |
16 |
char *typename; |
char *typename; |
|
17 |
|
|
15 |
18 |
const struct typenode *superclass; |
const struct typenode *superclass; |
16 |
19 |
}; |
}; |
17 |
20 |
|
|
|
... |
... |
void init(); |
63 |
66 |
struct typenode *newtypenode(const char *typename, const struct typenode *superclass); |
struct typenode *newtypenode(const char *typename, const struct typenode *superclass); |
64 |
67 |
struct paramlist *newparamlist(); |
struct paramlist *newparamlist(); |
65 |
68 |
struct typeandname *newtypeandname(const struct typenode *ty, const char *name); |
struct typeandname *newtypeandname(const struct typenode *ty, const char *name); |
|
69 |
|
struct typeandname *newtypeandnamewithreturn(const struct typenode *ty, const char *name, int retbool); |
66 |
70 |
const struct typenode *getPrimitiveAncestor(const struct typenode *cur); |
const struct typenode *getPrimitiveAncestor(const struct typenode *cur); |
67 |
71 |
int isDerivedFrom(const struct typenode *cur, const struct typenode *base); |
int isDerivedFrom(const struct typenode *cur, const struct typenode *base); |
68 |
72 |
void addParam(struct paramlist *tl, struct typeandname *tan); |
void addParam(struct paramlist *tl, struct typeandname *tan); |
|
... |
... |
struct typenode *binop(const struct typenode *a, const struct typenode *b); |
72 |
76 |
int canconvert(const struct typenode *from, const struct typenode *to, const int linemod); |
int canconvert(const struct typenode *from, const struct typenode *to, const int linemod); |
73 |
77 |
int canconvertreturn(const struct typenode *from, const struct typenode *to, const int linemod); |
int canconvertreturn(const struct typenode *from, const struct typenode *to, const int linemod); |
74 |
78 |
struct typenode *combinetype(struct typenode *n1, struct typenode *n2); |
struct typenode *combinetype(struct typenode *n1, struct typenode *n2); |
75 |
|
void checkParameters(const struct paramlist *func, const struct paramlist *inp); |
|
|
79 |
|
void checkParameters(const struct paramlist *func, const struct paramlist *inp, const int mustretbool); |
76 |
80 |
void validateGlobalAssignment(const char *varname); |
void validateGlobalAssignment(const char *varname); |
77 |
81 |
void checkcomparisonsimple(const struct typenode *a); |
void checkcomparisonsimple(const struct typenode *a); |
78 |
82 |
|
|
|
... |
... |
extern char *yytext, *curfile; |
87 |
91 |
extern int yydebug; |
extern int yydebug; |
88 |
92 |
int *showerrorlevel; |
int *showerrorlevel; |
89 |
93 |
extern struct hashtable functions, globals, locals, params, types, *curtab; |
extern struct hashtable functions, globals, locals, params, types, *curtab; |
90 |
|
extern struct typenode *gInteger, *gReal, *gBoolean, *gString, *gCode, *gHandle, *gNothing, *gNull, *gAny, *gNone; |
|
|
94 |
|
extern struct typenode *gInteger, *gReal, *gBoolean, *gString, *gCode, *gHandle, *gNothing, *gNull, *gAny, *gNone, *gCodeReturnsBoolean, *gCodeReturnsNoBoolean; |
|
95 |
|
extern struct funcdecl *fFilter, *fCondition; |
91 |
96 |
extern struct typenode *retval; |
extern struct typenode *retval; |
92 |
97 |
const struct typeandname *getVariable(const char *varname); |
const struct typeandname *getVariable(const char *varname); |
93 |
98 |
void isnumeric(const struct typenode *ty); |
void isnumeric(const struct typenode *ty); |