File grammar.y changed (mode: 100644) (index de8db7b..ef9c482) |
... |
... |
expr: intexpr { $$.ty = gInteger; } |
198 |
198 |
| FUNCTION rid { struct funcdecl *fd = lookup(&functions, $2.str); |
| FUNCTION rid { struct funcdecl *fd = lookup(&functions, $2.str); |
199 |
199 |
if (fd == NULL) { |
if (fd == NULL) { |
200 |
200 |
char ebuf[1024]; |
char ebuf[1024]; |
201 |
|
sprintf(ebuf, "Undefined function %s", $2.str); |
|
202 |
|
getsuggestions($2.str, ebuf, 1, &functions); |
|
|
201 |
|
snprintf(ebuf, 1024, "Undefined function %s", $2.str); |
|
202 |
|
//getsuggestions($2.str, ebuf, 1, &functions); |
203 |
203 |
yyerrorex(3, ebuf); |
yyerrorex(3, ebuf); |
204 |
204 |
$$.ty = gCode; |
$$.ty = gCode; |
205 |
205 |
} else { |
} else { |
206 |
206 |
if (fd->p->head != NULL) { |
if (fd->p->head != NULL) { |
207 |
207 |
char ebuf[1024]; |
char ebuf[1024]; |
208 |
|
sprintf(ebuf, "Function %s must not take any arguments when used as code", $2.str); |
|
|
208 |
|
snprintf(ebuf, 1024, "Function %s must not take any arguments when used as code", $2.str); |
209 |
209 |
yyerrorex(3, ebuf); |
yyerrorex(3, ebuf); |
210 |
210 |
} |
} |
211 |
211 |
$$.ty = gCode; |
$$.ty = gCode; |
|
... |
... |
expr: intexpr { $$.ty = gInteger; } |
237 |
237 |
if (!typeeq(tan->ty, gAny)) { |
if (!typeeq(tan->ty, gAny)) { |
238 |
238 |
if (!tan->isarray) { |
if (!tan->isarray) { |
239 |
239 |
char ebuf[1024]; |
char ebuf[1024]; |
240 |
|
sprintf(ebuf, "%s not an array", $1.str); |
|
|
240 |
|
snprintf(ebuf, 1024, "%s not an array", $1.str); |
241 |
241 |
yyerrorex(3, ebuf); |
yyerrorex(3, ebuf); |
242 |
242 |
} |
} |
243 |
243 |
else { |
else { |
|
... |
... |
expr: intexpr { $$.ty = gInteger; } |
250 |
250 |
const struct typeandname *tan = getVariable($1.str); |
const struct typeandname *tan = getVariable($1.str); |
251 |
251 |
if (tan->lineno == lineno && tan->fn == fno) { |
if (tan->lineno == lineno && tan->fn == fno) { |
252 |
252 |
char ebuf[1024]; |
char ebuf[1024]; |
253 |
|
sprintf(ebuf, "Use of variable %s before its declaration", $1.str); |
|
|
253 |
|
snprintf(ebuf, 1024, "Use of variable %s before its declaration", $1.str); |
254 |
254 |
yyerrorex(3, ebuf); |
yyerrorex(3, ebuf); |
255 |
255 |
} else if (islinebreak && tan->lineno == lineno - 1 && tan->fn == fno) { |
} else if (islinebreak && tan->lineno == lineno - 1 && tan->fn == fno) { |
256 |
256 |
char ebuf[1024]; |
char ebuf[1024]; |
257 |
|
sprintf(ebuf, "Use of variable %s before its declaration", $1.str); |
|
|
257 |
|
snprintf(ebuf, 1024, "Use of variable %s before its declaration", $1.str); |
258 |
258 |
yyerrorline(3, lineno - 1, ebuf); |
yyerrorline(3, lineno - 1, ebuf); |
259 |
259 |
} else if (tan->isarray) { |
} else if (tan->isarray) { |
260 |
260 |
char ebuf[1024]; |
char ebuf[1024]; |
261 |
|
sprintf(ebuf, "Index missing for array variable %s", $1.str); |
|
|
261 |
|
snprintf(ebuf, 1024, "Index missing for array variable %s", $1.str); |
262 |
262 |
yyerrorex(3, ebuf); |
yyerrorex(3, ebuf); |
263 |
263 |
} |
} |
264 |
264 |
if(infunction && lookup(curtab, $1.str) && !lookup(&initialized, $1.str) ){ |
if(infunction && lookup(curtab, $1.str) && !lookup(&initialized, $1.str) ){ |
265 |
265 |
char ebuf[1024]; |
char ebuf[1024]; |
266 |
|
sprintf(ebuf, "Variable %s is uninitialized", $1.str); |
|
|
266 |
|
snprintf(ebuf, 1024, "Variable %s is uninitialized", $1.str); |
267 |
267 |
//yyerrorex(3, ebuf); |
//yyerrorex(3, ebuf); |
268 |
268 |
yyerrorline(3, lineno - 1, ebuf); |
yyerrorline(3, lineno - 1, ebuf); |
269 |
269 |
} |
} |
|
... |
... |
funccall: rid LPAREN exprlistcompl RPAREN { |
288 |
288 |
struct funcdecl *fd = lookup(&functions, $1.str); |
struct funcdecl *fd = lookup(&functions, $1.str); |
289 |
289 |
if (fd == NULL) { |
if (fd == NULL) { |
290 |
290 |
char ebuf[1024]; |
char ebuf[1024]; |
291 |
|
sprintf(ebuf, "Undeclared function %s", $1.str); |
|
292 |
|
getsuggestions($1.str, ebuf, 1, &functions); |
|
|
291 |
|
snprintf(ebuf, 1024, "Undeclared function %s", $1.str); |
|
292 |
|
//getsuggestions($1.str, ebuf, 1, &functions); |
293 |
293 |
yyerrorex(3, ebuf); |
yyerrorex(3, ebuf); |
294 |
294 |
$$.ty = gAny; |
$$.ty = gAny; |
295 |
295 |
} else { |
} else { |
296 |
296 |
if (inconstant && !(fd->isconst)) { |
if (inconstant && !(fd->isconst)) { |
297 |
297 |
char ebuf[1024]; |
char ebuf[1024]; |
298 |
|
sprintf(ebuf, "Call to non-constant function %s in constant function", $1.str); |
|
|
298 |
|
snprintf(ebuf, 1024, "Call to non-constant function %s in constant function", $1.str); |
299 |
299 |
yyerrorex(3, ebuf); |
yyerrorex(3, ebuf); |
300 |
300 |
} |
} |
301 |
301 |
if (fd == fCurrent && fCurrent) |
if (fd == fCurrent && fCurrent) |
|
... |
... |
funccall: rid LPAREN exprlistcompl RPAREN { |
309 |
309 |
struct funcdecl *fd = lookup(&functions, $1.str); |
struct funcdecl *fd = lookup(&functions, $1.str); |
310 |
310 |
if (fd == NULL) { |
if (fd == NULL) { |
311 |
311 |
char ebuf[1024]; |
char ebuf[1024]; |
312 |
|
sprintf(ebuf, "Undeclared function %s", $1.str); |
|
313 |
|
getsuggestions($1.str, ebuf, 1, &functions); |
|
|
312 |
|
snprintf(ebuf, 1024, "Undeclared function %s", $1.str); |
|
313 |
|
//getsuggestions($1.str, ebuf, 1, &functions); |
314 |
314 |
yyerrorex(3, ebuf); |
yyerrorex(3, ebuf); |
315 |
315 |
$$.ty = gAny; |
$$.ty = gAny; |
316 |
316 |
} else if (inconstant && !(fd->isconst)) { |
} else if (inconstant && !(fd->isconst)) { |
317 |
317 |
char ebuf[1024]; |
char ebuf[1024]; |
318 |
|
sprintf(ebuf, "Call to non-constant function %s in constant function", $1.str); |
|
|
318 |
|
snprintf(ebuf, 1024, "Call to non-constant function %s in constant function", $1.str); |
319 |
319 |
yyerrorex(3, ebuf); |
yyerrorex(3, ebuf); |
320 |
320 |
$$.ty = gAny; |
$$.ty = gAny; |
321 |
321 |
} else { |
} else { |
|
... |
... |
nativefuncdecl: NATIVE rid TAKES optparam_list RETURNS opttype |
363 |
363 |
{ |
{ |
364 |
364 |
if (lookup(&locals, $2.str) || lookup(¶ms, $2.str) || lookup(&globals, $2.str)) { |
if (lookup(&locals, $2.str) || lookup(¶ms, $2.str) || lookup(&globals, $2.str)) { |
365 |
365 |
char buf[1024]; |
char buf[1024]; |
366 |
|
sprintf(buf, "%s already defined as variable", $2.str); |
|
|
366 |
|
snprintf(buf, 1024, "%s already defined as variable", $2.str); |
367 |
367 |
yyerrorex(3, buf); |
yyerrorex(3, buf); |
368 |
368 |
} else if (lookup(&types, $2.str)) { |
} else if (lookup(&types, $2.str)) { |
369 |
369 |
char buf[1024]; |
char buf[1024]; |
370 |
|
sprintf(buf, "%s already defined as type", $2.str); |
|
|
370 |
|
snprintf(buf, 1024, "%s already defined as type", $2.str); |
371 |
371 |
yyerrorex(3, buf); |
yyerrorex(3, buf); |
372 |
372 |
} |
} |
373 |
373 |
$$.fd = newfuncdecl(); |
$$.fd = newfuncdecl(); |
|
... |
... |
returnorreturns: RETURNS |
408 |
408 |
funcbegin: FUNCTION rid TAKES optparam_list returnorreturns opttype { |
funcbegin: FUNCTION rid TAKES optparam_list returnorreturns opttype { |
409 |
409 |
if (lookup(&locals, $2.str) || lookup(¶ms, $2.str) || lookup(&globals, $2.str)) { |
if (lookup(&locals, $2.str) || lookup(¶ms, $2.str) || lookup(&globals, $2.str)) { |
410 |
410 |
char buf[1024]; |
char buf[1024]; |
411 |
|
sprintf(buf, "%s already defined as variable", $2.str); |
|
|
411 |
|
snprintf(buf, 1024, "%s already defined as variable", $2.str); |
412 |
412 |
yyerrorex(3, buf); |
yyerrorex(3, buf); |
413 |
413 |
} else if (lookup(&types, $2.str)) { |
} else if (lookup(&types, $2.str)) { |
414 |
414 |
char buf[1024]; |
char buf[1024]; |
415 |
|
sprintf(buf, "%s already defined as type", $2.str); |
|
|
415 |
|
snprintf(buf, 1024, "%s already defined as type", $2.str); |
416 |
416 |
yyerrorex(3, buf); |
yyerrorex(3, buf); |
417 |
417 |
} |
} |
418 |
418 |
inconstant = 0; |
inconstant = 0; |
|
... |
... |
funcbegin: FUNCTION rid TAKES optparam_list returnorreturns opttype { |
432 |
432 |
put(¶ms, strdup(tan->name), newtypeandname(tan->ty, tan->name)); |
put(¶ms, strdup(tan->name), newtypeandname(tan->ty, tan->name)); |
433 |
433 |
if (lookup(&functions, tan->name)) { |
if (lookup(&functions, tan->name)) { |
434 |
434 |
char buf[1024]; |
char buf[1024]; |
435 |
|
sprintf(buf, "%s already defined as function", tan->name); |
|
|
435 |
|
snprintf(buf, 1024, "%s already defined as function", tan->name); |
436 |
436 |
yyerrorex(3, buf); |
yyerrorex(3, buf); |
437 |
437 |
} else if (lookup(&types, tan->name)) { |
} else if (lookup(&types, tan->name)) { |
438 |
438 |
char buf[1024]; |
char buf[1024]; |
439 |
|
sprintf(buf, "%s already defined as type", tan->name); |
|
|
439 |
|
snprintf(buf, 1024, "%s already defined as type", tan->name); |
440 |
440 |
yyerrorex(3, buf); |
yyerrorex(3, buf); |
441 |
441 |
} |
} |
442 |
442 |
} |
} |
|
... |
... |
funcbegin: FUNCTION rid TAKES optparam_list returnorreturns opttype { |
448 |
448 |
| CONSTANT FUNCTION rid TAKES optparam_list returnorreturns opttype { |
| CONSTANT FUNCTION rid TAKES optparam_list returnorreturns opttype { |
449 |
449 |
if (lookup(&locals, $3.str) || lookup(¶ms, $3.str) || lookup(&globals, $3.str)) { |
if (lookup(&locals, $3.str) || lookup(¶ms, $3.str) || lookup(&globals, $3.str)) { |
450 |
450 |
char buf[1024]; |
char buf[1024]; |
451 |
|
sprintf(buf, "%s already defined as variable", $3.str); |
|
|
451 |
|
snprintf(buf, 1024, "%s already defined as variable", $3.str); |
452 |
452 |
yyerrorex(3, buf); |
yyerrorex(3, buf); |
453 |
453 |
} else if (lookup(&types, $3.str)) { |
} else if (lookup(&types, $3.str)) { |
454 |
454 |
char buf[1024]; |
char buf[1024]; |
455 |
|
sprintf(buf, "%s already defined as type", $3.str); |
|
|
455 |
|
snprintf(buf, 1024, "%s already defined as type", $3.str); |
456 |
456 |
yyerrorex(3, buf); |
yyerrorex(3, buf); |
457 |
457 |
} |
} |
458 |
458 |
inconstant = 1; |
inconstant = 1; |
|
... |
... |
funcbegin: FUNCTION rid TAKES optparam_list returnorreturns opttype { |
470 |
470 |
put(¶ms, strdup(tan->name), newtypeandname(tan->ty, tan->name)); |
put(¶ms, strdup(tan->name), newtypeandname(tan->ty, tan->name)); |
471 |
471 |
if (lookup(&functions, tan->name)) { |
if (lookup(&functions, tan->name)) { |
472 |
472 |
char buf[1024]; |
char buf[1024]; |
473 |
|
sprintf(buf, "%s already defined as function", tan->name); |
|
|
473 |
|
snprintf(buf, 1024, "%s already defined as function", tan->name); |
474 |
474 |
yyerrorex(3, buf); |
yyerrorex(3, buf); |
475 |
475 |
} else if (lookup(&types, tan->name)) { |
} else if (lookup(&types, tan->name)) { |
476 |
476 |
char buf[1024]; |
char buf[1024]; |
477 |
|
sprintf(buf, "%s already defined as type", tan->name); |
|
|
477 |
|
snprintf(buf, 1024, "%s already defined as type", tan->name); |
478 |
478 |
yyerrorex(3, buf); |
yyerrorex(3, buf); |
479 |
479 |
} |
} |
480 |
480 |
} |
} |
|
... |
... |
statement: NEWLINE { $$.ty = gNone; } |
503 |
503 |
} |
} |
504 |
504 |
| SET rid EQUALS expr NEWLINE { if (getVariable($2.str)->isarray) { |
| SET rid EQUALS expr NEWLINE { if (getVariable($2.str)->isarray) { |
505 |
505 |
char ebuf[1024]; |
char ebuf[1024]; |
506 |
|
sprintf(ebuf, "Index missing for array variable %s", $2.str); |
|
|
506 |
|
snprintf(ebuf, 1024, "Index missing for array variable %s", $2.str); |
507 |
507 |
yyerrorline(3, lineno - 1, ebuf); |
yyerrorline(3, lineno - 1, ebuf); |
508 |
508 |
} |
} |
509 |
509 |
canconvert($4.ty, getVariable($2.str)->ty, -1); |
canconvert($4.ty, getVariable($2.str)->ty, -1); |
510 |
510 |
$$.ty = gNone; |
$$.ty = gNone; |
511 |
511 |
if (getVariable($2.str)->isconst) { |
if (getVariable($2.str)->isconst) { |
512 |
512 |
char ebuf[1024]; |
char ebuf[1024]; |
513 |
|
sprintf(ebuf, "Cannot assign to constant %s", $2.str); |
|
|
513 |
|
snprintf(ebuf, 1024, "Cannot assign to constant %s", $2.str); |
514 |
514 |
yyerrorline(3, lineno - 1, ebuf); |
yyerrorline(3, lineno - 1, ebuf); |
515 |
515 |
} |
} |
516 |
516 |
if (inconstant) |
if (inconstant) |
|
... |
... |
statement: NEWLINE { $$.ty = gNone; } |
526 |
526 |
$$.ty = gNone; |
$$.ty = gNone; |
527 |
527 |
if (!tan->isarray) { |
if (!tan->isarray) { |
528 |
528 |
char ebuf[1024]; |
char ebuf[1024]; |
529 |
|
sprintf(ebuf, "%s is not an array", $2.str); |
|
|
529 |
|
snprintf(ebuf, 1024, "%s is not an array", $2.str); |
530 |
530 |
yyerrorline(3, lineno - 1, ebuf); |
yyerrorline(3, lineno - 1, ebuf); |
531 |
531 |
} |
} |
532 |
532 |
canconvert($7.ty, tan->ty, -1); |
canconvert($7.ty, tan->ty, -1); |
|
... |
... |
rid: ID |
614 |
614 |
vartypedecl: type rid { |
vartypedecl: type rid { |
615 |
615 |
if (lookup(&functions, $2.str)) { |
if (lookup(&functions, $2.str)) { |
616 |
616 |
char buf[1024]; |
char buf[1024]; |
617 |
|
sprintf(buf, "Symbol %s already defined as function", $2.str); |
|
|
617 |
|
snprintf(buf, 1024, "Symbol %s already defined as function", $2.str); |
618 |
618 |
yyerrorex(3, buf); |
yyerrorex(3, buf); |
619 |
619 |
} else if (lookup(&types, $2.str)) { |
} else if (lookup(&types, $2.str)) { |
620 |
620 |
char buf[1024]; |
char buf[1024]; |
621 |
|
sprintf(buf, "Symbol %s already defined as type", $2.str); |
|
|
621 |
|
snprintf(buf, 1024, "Symbol %s already defined as type", $2.str); |
622 |
622 |
yyerrorex(3, buf); |
yyerrorex(3, buf); |
623 |
623 |
} |
} |
624 |
624 |
struct typeandname *tan = newtypeandname($1.ty, $2.str); |
struct typeandname *tan = newtypeandname($1.ty, $2.str); |
|
... |
... |
vartypedecl: type rid { |
643 |
643 |
} |
} |
644 |
644 |
if (lookup(&functions, $3.str)) { |
if (lookup(&functions, $3.str)) { |
645 |
645 |
char buf[1024]; |
char buf[1024]; |
646 |
|
sprintf(buf, "Symbol %s already defined as function", $3.str); |
|
|
646 |
|
snprintf(buf, 1024, "Symbol %s already defined as function", $3.str); |
647 |
647 |
yyerrorex(3, buf); |
yyerrorex(3, buf); |
648 |
648 |
} else if (lookup(&types, $3.str)) { |
} else if (lookup(&types, $3.str)) { |
649 |
649 |
char buf[1024]; |
char buf[1024]; |
650 |
|
sprintf(buf, "Symbol %s already defined as type", $3.str); |
|
|
650 |
|
snprintf(buf, 1024, "Symbol %s already defined as type", $3.str); |
651 |
651 |
yyerrorex(3, buf); |
yyerrorex(3, buf); |
652 |
652 |
} |
} |
653 |
653 |
struct typeandname *tan = newtypeandname($2.ty, $3.str); |
struct typeandname *tan = newtypeandname($2.ty, $3.str); |
|
... |
... |
vartypedecl: type rid { |
670 |
670 |
| type ARRAY rid { |
| type ARRAY rid { |
671 |
671 |
if (lookup(&functions, $3.str)) { |
if (lookup(&functions, $3.str)) { |
672 |
672 |
char buf[1024]; |
char buf[1024]; |
673 |
|
sprintf(buf, "Symbol %s already defined as function", $3.str); |
|
|
673 |
|
snprintf(buf, 1024, "Symbol %s already defined as function", $3.str); |
674 |
674 |
yyerrorex(3, buf); |
yyerrorex(3, buf); |
675 |
675 |
} else if (lookup(&types, $3.str)) { |
} else if (lookup(&types, $3.str)) { |
676 |
676 |
char buf[1024]; |
char buf[1024]; |
677 |
|
sprintf(buf, "Symbol %s already defined as type", $3.str); |
|
|
677 |
|
snprintf(buf, 1024, "Symbol %s already defined as type", $3.str); |
678 |
678 |
yyerrorex(3, buf); |
yyerrorex(3, buf); |
679 |
679 |
} |
} |
680 |
680 |
if (getPrimitiveAncestor($1.ty) == gCode) |
if (getPrimitiveAncestor($1.ty) == gCode) |
|
... |
... |
vartypedecl: type rid { |
687 |
687 |
char buf[1024]; |
char buf[1024]; |
688 |
688 |
existing = lookup(¶ms, $3.str); |
existing = lookup(¶ms, $3.str); |
689 |
689 |
if (afterendglobals && existing) { |
if (afterendglobals && existing) { |
690 |
|
sprintf(buf, "Symbol %s already defined as function parameter", $3.str); |
|
|
690 |
|
snprintf(buf, 1024, "Symbol %s already defined as function parameter", $3.str); |
691 |
691 |
yyerrorex(3, buf); |
yyerrorex(3, buf); |
692 |
692 |
} |
} |
693 |
693 |
if (!existing) { |
if (!existing) { |
694 |
694 |
existing = lookup(&globals, $3.str); |
existing = lookup(&globals, $3.str); |
695 |
695 |
if (afterendglobals && existing) { |
if (afterendglobals && existing) { |
696 |
|
sprintf(buf, "Symbol %s already defined as global variable", $3.str); |
|
|
696 |
|
snprintf(buf, 1024, "Symbol %s already defined as global variable", $3.str); |
697 |
697 |
yyerrorex(3, buf); |
yyerrorex(3, buf); |
698 |
698 |
} |
} |
699 |
699 |
} |
} |
|
... |
... |
vardecl: vartypedecl NEWLINE { |
806 |
806 |
typedef: TYPE rid EXTENDS type { |
typedef: TYPE rid EXTENDS type { |
807 |
807 |
if (lookup(&types, $2.str)) { |
if (lookup(&types, $2.str)) { |
808 |
808 |
char buf[1024]; |
char buf[1024]; |
809 |
|
sprintf(buf, "Multiply defined type %s", $2.str); |
|
|
809 |
|
snprintf(buf, 1024, "Multiply defined type %s", $2.str); |
810 |
810 |
yyerrorex(3, buf); |
yyerrorex(3, buf); |
811 |
811 |
} else if (lookup(&functions, $2.str)) { |
} else if (lookup(&functions, $2.str)) { |
812 |
812 |
char buf[1024]; |
char buf[1024]; |
813 |
|
sprintf(buf, "%s already defined as function", $2.str); |
|
|
813 |
|
snprintf(buf, 1024, "%s already defined as function", $2.str); |
814 |
814 |
yyerrorex(3, buf); |
yyerrorex(3, buf); |
815 |
815 |
} |
} |
816 |
816 |
else |
else |
|
... |
... |
type: primtype { $$.ty = $1.ty; } |
825 |
825 |
| rid { |
| rid { |
826 |
826 |
if (lookup(&types, $1.str) == NULL) { |
if (lookup(&types, $1.str) == NULL) { |
827 |
827 |
char buf[1024]; |
char buf[1024]; |
828 |
|
sprintf(buf, "Undefined type %s", $1.str); |
|
829 |
|
getsuggestions($1.str, buf, 1, &types); |
|
|
828 |
|
snprintf(buf, 1024, "Undefined type %s", $1.str); |
|
829 |
|
//getsuggestions($1.str, buf, 1, &types); |
830 |
830 |
yyerrorex(3, buf); |
yyerrorex(3, buf); |
831 |
831 |
$$.ty = gAny; |
$$.ty = gAny; |
832 |
832 |
} |
} |
File misc.c changed (mode: 100644) (index 54f5583..2c63c5b) |
... |
... |
int editdistance(const char *s, const char *t, int cutoff){ |
156 |
156 |
free(v[i]); |
free(v[i]); |
157 |
157 |
return d; |
return d; |
158 |
158 |
} |
} |
159 |
|
|
|
|
159 |
|
#if 0 |
160 |
160 |
void getsuggestions(const char *name, char *buff, int nTables, ...){ |
void getsuggestions(const char *name, char *buff, int nTables, ...){ |
|
161 |
|
return; |
161 |
162 |
int i; |
int i; |
162 |
163 |
va_list ap; |
va_list ap; |
163 |
164 |
|
|
|
... |
... |
void getsuggestions(const char *name, char *buff, int nTables, ...){ |
170 |
171 |
suggestions[i].distance = INT_MAX; |
suggestions[i].distance = INT_MAX; |
171 |
172 |
suggestions[i].name = NULL; |
suggestions[i].name = NULL; |
172 |
173 |
} |
} |
173 |
|
|
|
|
174 |
|
/* |
174 |
175 |
va_start(ap, nTables); |
va_start(ap, nTables); |
175 |
176 |
for(i = 0; i != nTables; i++){ |
for(i = 0; i != nTables; i++){ |
176 |
177 |
struct hashtable *ht = va_arg(ap, struct hashtable*); |
struct hashtable *ht = va_arg(ap, struct hashtable*); |
|
178 |
|
|
177 |
179 |
int x; |
int x; |
178 |
180 |
for(x = 0; x != BUCKETS; x++){ |
for(x = 0; x != BUCKETS; x++){ |
179 |
181 |
struct hashnode *hn; |
struct hashnode *hn; |
180 |
182 |
hn = ht->h[x]; |
hn = ht->h[x]; |
181 |
183 |
while (hn) { |
while (hn) { |
182 |
|
int dist = editdistance(hn->name, name, cutoff); |
|
|
184 |
|
int dist = 0;//editdistance(hn->name, name, cutoff); |
183 |
185 |
if(dist <= cutoff){ |
if(dist <= cutoff){ |
|
186 |
|
//printf("Possible suggestion for %s: %s\n", name, hn->name); |
|
187 |
|
|
184 |
188 |
count++; |
count++; |
185 |
189 |
int j; |
int j; |
186 |
190 |
for(j = 0; j != 3; j++){ |
for(j = 0; j != 3; j++){ |
|
... |
... |
void getsuggestions(const char *name, char *buff, int nTables, ...){ |
197 |
201 |
break; |
break; |
198 |
202 |
} |
} |
199 |
203 |
} |
} |
|
204 |
|
|
200 |
205 |
} |
} |
201 |
206 |
hn = hn->next; |
hn = hn->next; |
202 |
207 |
} |
} |
203 |
208 |
} |
} |
|
209 |
|
|
204 |
210 |
} |
} |
205 |
211 |
va_end(ap); |
va_end(ap); |
|
212 |
|
*/ |
206 |
213 |
|
|
207 |
214 |
if(count==0) |
if(count==0) |
208 |
215 |
return; |
return; |
209 |
216 |
else if(count == 1){ |
else if(count == 1){ |
210 |
217 |
char hbuff[1024]; |
char hbuff[1024]; |
211 |
|
sprintf(hbuff, ". Maybe you meant %s", suggestions[0].name); |
|
|
218 |
|
snprintf(hbuff, 1024, ". Maybe you meant %s", suggestions[0].name); |
212 |
219 |
strcat(buff, hbuff); |
strcat(buff, hbuff); |
213 |
220 |
}else{ |
}else{ |
214 |
221 |
strcat(buff, ". Maybe you meant "); |
strcat(buff, ". Maybe you meant "); |
|
... |
... |
void getsuggestions(const char *name, char *buff, int nTables, ...){ |
219 |
226 |
} |
} |
220 |
227 |
} |
} |
221 |
228 |
} |
} |
|
229 |
|
#endif |
222 |
230 |
|
|
223 |
231 |
const struct typeandname *getVariable(const char *varname) |
const struct typeandname *getVariable(const char *varname) |
224 |
232 |
{ |
{ |
|
... |
... |
const struct typeandname *getVariable(const char *varname) |
230 |
238 |
if (result) return result; |
if (result) return result; |
231 |
239 |
result = lookup(&globals, varname); |
result = lookup(&globals, varname); |
232 |
240 |
if (result) return result; |
if (result) return result; |
233 |
|
sprintf(ebuf, "Undeclared variable %s", varname); |
|
234 |
|
getsuggestions(varname, ebuf, 3, &locals, ¶ms, &globals); |
|
|
241 |
|
snprintf(ebuf, 1024, "Undeclared variable %s", varname); |
|
242 |
|
//getsuggestions(varname, ebuf, 3, &locals, ¶ms, &globals); |
235 |
243 |
yyerrorline(2, islinebreak ? lineno - 1 : lineno, ebuf); |
yyerrorline(2, islinebreak ? lineno - 1 : lineno, ebuf); |
236 |
244 |
// Store it as unidentified variable |
// Store it as unidentified variable |
237 |
245 |
put(curtab, varname, newtypeandname(gAny, varname)); |
put(curtab, varname, newtypeandname(gAny, varname)); |
|
... |
... |
void validateGlobalAssignment(const char *varname) { |
246 |
254 |
struct typeandname *result; |
struct typeandname *result; |
247 |
255 |
result = lookup(&globals, varname); |
result = lookup(&globals, varname); |
248 |
256 |
if (result) { |
if (result) { |
249 |
|
sprintf(ebuf, "Assignment to global variable %s in constant function", varname); |
|
|
257 |
|
snprintf(ebuf, 1024, "Assignment to global variable %s in constant function", varname); |
250 |
258 |
yyerrorline(2, lineno - 1, ebuf); |
yyerrorline(2, lineno - 1, ebuf); |
251 |
259 |
} |
} |
252 |
260 |
} |
} |
|
... |
... |
void put(struct hashtable *h, const char *name, void *val) |
377 |
385 |
|
|
378 |
386 |
if (lookup(h, name) != NULL) { |
if (lookup(h, name) != NULL) { |
379 |
387 |
char ebuf[1024]; |
char ebuf[1024]; |
380 |
|
sprintf(ebuf, "Symbol %s multiply defined", name); |
|
|
388 |
|
snprintf(ebuf, 1024, "Symbol %s multiply defined", name); |
381 |
389 |
yyerrorline(3, islinebreak ? lineno - 1 : lineno, ebuf); |
yyerrorline(3, islinebreak ? lineno - 1 : lineno, ebuf); |
382 |
390 |
return; |
return; |
383 |
391 |
} |
} |
|
... |
... |
int canconvert(const struct typenode *ufrom, const struct typenode *uto, const i |
454 |
462 |
return 1; |
return 1; |
455 |
463 |
} |
} |
456 |
464 |
|
|
457 |
|
sprintf(ebuf, "Cannot convert %s to %s", ufrom->typename, uto->typename); |
|
|
465 |
|
snprintf(ebuf, 1024, "Cannot convert %s to %s", ufrom->typename, uto->typename); |
458 |
466 |
yyerrorline(3, lineno + linemod, ebuf); |
yyerrorline(3, lineno + linemod, ebuf); |
459 |
467 |
return 0; |
return 0; |
460 |
468 |
} |
} |
|
... |
... |
int canconvertreturn(const struct typenode *ufrom, const struct typenode *uto, c |
481 |
489 |
to = getPrimitiveAncestor(to); |
to = getPrimitiveAncestor(to); |
482 |
490 |
if ((typeeq(to, gReal)) && (typeeq(from, gInteger))) { |
if ((typeeq(to, gReal)) && (typeeq(from, gInteger))) { |
483 |
491 |
// can't return integer when it expects a real (added 9.5.2005) |
// can't return integer when it expects a real (added 9.5.2005) |
484 |
|
sprintf(ebuf, "Cannot convert returned value from %s to %s", getTypePtr(from)->typename, getTypePtr(to)->typename); |
|
|
492 |
|
snprintf(ebuf, 1024, "Cannot convert returned value from %s to %s", getTypePtr(from)->typename, getTypePtr(to)->typename); |
485 |
493 |
yyerrorline(1, lineno + linemod, ebuf); |
yyerrorline(1, lineno + linemod, ebuf); |
486 |
494 |
return 0; |
return 0; |
487 |
495 |
} |
} |
|
... |
... |
int canconvertreturn(const struct typenode *ufrom, const struct typenode *uto, c |
494 |
502 |
} else if (typeeq(from, to)) |
} else if (typeeq(from, to)) |
495 |
503 |
return 1; |
return 1; |
496 |
504 |
|
|
497 |
|
sprintf(ebuf, "Cannot convert returned value from %s to %s", getTypePtr(ufrom)->typename, getTypePtr(uto)->typename); |
|
|
505 |
|
snprintf(ebuf, 1024, "Cannot convert returned value from %s to %s", getTypePtr(ufrom)->typename, getTypePtr(uto)->typename); |
498 |
506 |
yyerrorline(1, lineno + linemod, ebuf); |
yyerrorline(1, lineno + linemod, ebuf); |
499 |
507 |
return 0; |
return 0; |
500 |
508 |
} |
} |