File src/grammar.y changed (mode: 100644) (index 13c96c6..4911ce2) |
... |
... |
int main(int argc, char **argv) |
102 |
102 |
%token UNITTYPEINT |
%token UNITTYPEINT |
103 |
103 |
%token EQUALS |
%token EQUALS |
104 |
104 |
|
|
|
105 |
|
%right EQUALS |
105 |
106 |
%left AND OR |
%left AND OR |
106 |
107 |
%left NOT |
%left NOT |
107 |
108 |
%left LESS GREATER EQCOMP NEQ LEQ GEQ |
%left LESS GREATER EQCOMP NEQ LEQ GEQ |
108 |
|
%right EQUALS |
|
109 |
109 |
%left MINUS PLUS |
%left MINUS PLUS |
110 |
110 |
%left TIMES DIV |
%left TIMES DIV |
111 |
111 |
|
|
|
... |
... |
td: NEWLINE |
150 |
150 |
; |
; |
151 |
151 |
|
|
152 |
152 |
// Returns a typenode |
// Returns a typenode |
153 |
|
expr: intexpr |
|
154 |
|
| realexpr |
|
155 |
|
| stringexpr |
|
156 |
|
| boolexpr |
|
|
153 |
|
expr: intexpr { $$.ty = gInteger; } |
|
154 |
|
| realexpr { $$.ty = gReal; } |
|
155 |
|
| stringexpr { $$.ty = gString; } |
|
156 |
|
| boolexpr { $$.ty = gBoolean; } |
157 |
157 |
| FUNCTION rid { if (lookup(&functions, $2.str) == NULL) |
| FUNCTION rid { if (lookup(&functions, $2.str) == NULL) |
158 |
158 |
yyerror("Undefined function."); |
yyerror("Undefined function."); |
159 |
159 |
$$.ty = gCode; |
$$.ty = gCode; |
|
... |
... |
expr: intexpr |
171 |
171 |
| expr TIMES expr { $$.ty = binop($1.ty, $3.ty); } |
| expr TIMES expr { $$.ty = binop($1.ty, $3.ty); } |
172 |
172 |
| expr DIV expr { $$.ty = binop($1.ty, $3.ty); } |
| expr DIV expr { $$.ty = binop($1.ty, $3.ty); } |
173 |
173 |
| expr MINUS expr { $$.ty = binop($1.ty, $3.ty); } |
| expr MINUS expr { $$.ty = binop($1.ty, $3.ty); } |
174 |
|
| expr PLUS expr { if ($1.ty == gString && $3.ty == gString) |
|
|
174 |
|
| expr PLUS expr { |
|
175 |
|
if ($1.ty == gString && $3.ty == gString) |
175 |
176 |
$$.ty = gString; |
$$.ty = gString; |
176 |
177 |
else |
else |
177 |
178 |
$$.ty = binop($1.ty, $3.ty); } |
$$.ty = binop($1.ty, $3.ty); } |
|
... |
... |
exprlist: /* empty */ { $$.pl = newparamlist(); } |
218 |
219 |
|
|
219 |
220 |
|
|
220 |
221 |
stringexpr: STRINGLIT { $$.ty = gString; } |
stringexpr: STRINGLIT { $$.ty = gString; } |
221 |
|
| stringexpr PLUS stringexpr { $$.ty = gString; } |
|
222 |
222 |
; |
; |
223 |
223 |
|
|
224 |
224 |
realexpr: REALLIT { $$.ty = gReal; } |
realexpr: REALLIT { $$.ty = gReal; } |
|
... |
... |
codeblock: /* empty */ |
282 |
282 |
statement: NEWLINE |
statement: NEWLINE |
283 |
283 |
| CALL funccall |
| CALL funccall |
284 |
284 |
| IF expr THEN codeblock elsifseq elseseq ENDIF { canconvert($2.ty, gBoolean); } |
| IF expr THEN codeblock elsifseq elseseq ENDIF { canconvert($2.ty, gBoolean); } |
285 |
|
| SET rid EQUALS expr { canconvert($4.ty, getVariable($2.str)->ty); } |
|
|
285 |
|
| SET rid EQUALS expr NEWLINE { canconvert($4.ty, getVariable($2.str)->ty); } |
286 |
286 |
| SET rid LBRACKET expr RBRACKET EQUALS expr { |
| SET rid LBRACKET expr RBRACKET EQUALS expr { |
287 |
287 |
canconvert($4.ty, gInteger); |
canconvert($4.ty, gInteger); |
288 |
288 |
canconvert($7.ty, getVariable($2.str)->ty); } |
canconvert($7.ty, getVariable($2.str)->ty); } |
File src/misc.c changed (mode: 100644) (index c644e0a..7247d84) |
... |
... |
int canconvert(const struct typenode *ufrom, const struct typenode *uto) |
219 |
219 |
{ |
{ |
220 |
220 |
const struct typenode *from = ufrom, *to = uto; |
const struct typenode *from = ufrom, *to = uto; |
221 |
221 |
char ebuf[1024]; |
char ebuf[1024]; |
|
222 |
|
#if 0 |
|
223 |
|
if (lineno > 2400 && lineno < 2500) { |
|
224 |
|
yydebug = 1; |
|
225 |
|
fprintf(stderr, "LINE: %d\n", lineno); |
|
226 |
|
} |
|
227 |
|
else |
|
228 |
|
yydebug = 0; |
|
229 |
|
#endif |
222 |
230 |
if (from == NULL || to == NULL) return 0; |
if (from == NULL || to == NULL) return 0; |
223 |
231 |
if (isDerivedFrom(from, to)) |
if (isDerivedFrom(from, to)) |
224 |
232 |
return 1; |
return 1; |
|
... |
... |
int canconvert(const struct typenode *ufrom, const struct typenode *uto) |
230 |
238 |
if ((from == gInteger || from == gReal) && |
if ((from == gInteger || from == gReal) && |
231 |
239 |
(to == gInteger || to == gReal)) |
(to == gInteger || to == gReal)) |
232 |
240 |
return 1; |
return 1; |
|
241 |
|
/* Blizzard bug: allows downcasting erroneously */ |
|
242 |
|
/* TODO: get Blizzard to fix this in Blizzard.j and the language */ |
|
243 |
|
if (from == to) |
|
244 |
|
return 1; |
233 |
245 |
sprintf(ebuf, "Cannot convert %s to %s", ufrom->typename, uto->typename); |
sprintf(ebuf, "Cannot convert %s to %s", ufrom->typename, uto->typename); |
234 |
246 |
yyerror(ebuf); |
yyerror(ebuf); |
235 |
247 |
} |
} |
File src/misc.h changed (mode: 100644) (index 9c7aab3..71f1959) |
... |
... |
void checkParameters(const struct paramlist *func, const struct paramlist *inp); |
65 |
65 |
|
|
66 |
66 |
extern int lineno; |
extern int lineno; |
67 |
67 |
extern char *yytext; |
extern char *yytext; |
|
68 |
|
extern int yydebug; |
68 |
69 |
extern struct hashtable functions, globals, locals, params, types, *curtab; |
extern struct hashtable functions, globals, locals, params, types, *curtab; |
69 |
70 |
extern struct typenode *gInteger, *gReal, *gBoolean, *gString, *gCode, *gHandle, *gNothing, *gNull; |
extern struct typenode *gInteger, *gReal, *gBoolean, *gString, *gCode, *gHandle, *gNothing, *gNull; |
70 |
71 |
extern struct typenode *retval; |
extern struct typenode *retval; |