File src/grammar.y changed (mode: 100644) (index 274ed5f..604f860) |
12 |
12 |
int yyerror (char *s) /* Called by yyparse on error */ |
int yyerror (char *s) /* Called by yyparse on error */ |
13 |
13 |
{ |
{ |
14 |
14 |
haderrors++; |
haderrors++; |
15 |
|
printf ("%d: %s\n", lineno, s); |
|
|
15 |
|
printf ("%s:%d: %s\n", curfile, lineno, s); |
16 |
16 |
return 0; |
return 0; |
17 |
17 |
} |
} |
18 |
18 |
|
|
19 |
19 |
int main(int argc, char **argv) |
int main(int argc, char **argv) |
20 |
20 |
{ |
{ |
21 |
|
init(); |
|
|
21 |
|
init(argc, argv); |
22 |
22 |
if (1) { |
if (1) { |
23 |
|
for (;;) { |
|
24 |
|
int result = yyparse(); |
|
25 |
|
if (result == 0) break; |
|
26 |
|
} |
|
|
23 |
|
doparse(argc, argv); |
27 |
24 |
} |
} |
28 |
25 |
else { |
else { |
29 |
26 |
for (;;) { |
for (;;) { |
|
... |
... |
int main(int argc, char **argv) |
33 |
30 |
} |
} |
34 |
31 |
} |
} |
35 |
32 |
if (!haderrors) { |
if (!haderrors) { |
36 |
|
printf("Parse successful, no errors\n"); |
|
|
33 |
|
printf("Total parse successful: %d lines, no errors\n", totlines); |
37 |
34 |
return 0; |
return 0; |
38 |
35 |
} |
} |
39 |
|
else |
|
|
36 |
|
else { |
|
37 |
|
printf("Parse failed: %d total errors\n", haderrors); |
40 |
38 |
return 1; |
return 1; |
|
39 |
|
} |
41 |
40 |
} |
} |
42 |
41 |
|
|
43 |
42 |
#define YYSTYPE union node |
#define YYSTYPE union node |
File src/misc.c changed (mode: 100644) (index f9497e8..ed99897) |
5 |
5 |
#include "grammar.tab.h" |
#include "grammar.tab.h" |
6 |
6 |
#include "misc.h" |
#include "misc.h" |
7 |
7 |
|
|
8 |
|
int lineno = 1; |
|
|
8 |
|
int lineno; |
9 |
9 |
int haderrors = 0; |
int haderrors = 0; |
|
10 |
|
int totlines = 0; |
10 |
11 |
|
|
11 |
12 |
int hashfunc(const char *name); |
int hashfunc(const char *name); |
12 |
13 |
struct hashtable functions, globals, locals, params, types; |
struct hashtable functions, globals, locals, params, types; |
13 |
14 |
struct hashtable *curtab; |
struct hashtable *curtab; |
14 |
15 |
struct typenode *retval; |
struct typenode *retval; |
|
16 |
|
char *curfile; |
15 |
17 |
struct typenode *gInteger, *gReal, *gBoolean, *gString, *gCode, *gHandle, *gNothing, *gNull; |
struct typenode *gInteger, *gReal, *gBoolean, *gString, *gCode, *gHandle, *gNothing, *gNull; |
16 |
18 |
|
|
17 |
19 |
void addPrimitiveType(const char *name, struct typenode **toSave) |
void addPrimitiveType(const char *name, struct typenode **toSave) |
|
... |
... |
void addPrimitiveType(const char *name, struct typenode **toSave) |
19 |
21 |
put(&types, name, *toSave = newtypenode(name, NULL)); |
put(&types, name, *toSave = newtypenode(name, NULL)); |
20 |
22 |
} |
} |
21 |
23 |
|
|
22 |
|
void init() |
|
|
24 |
|
void init(int argc, char **argv) |
23 |
25 |
{ |
{ |
24 |
26 |
addPrimitiveType("handle", &gHandle); |
addPrimitiveType("handle", &gHandle); |
25 |
27 |
addPrimitiveType("integer", &gInteger); |
addPrimitiveType("integer", &gInteger); |
|
... |
... |
void checkeqtest(const struct typenode *a, const struct typenode *b) |
302 |
304 |
{ |
{ |
303 |
305 |
checkcomparison(a, b); |
checkcomparison(a, b); |
304 |
306 |
} |
} |
|
307 |
|
|
|
308 |
|
void dofile(FILE *fp, const char *name) |
|
309 |
|
{ |
|
310 |
|
void *cur; |
|
311 |
|
lineno = 1; |
|
312 |
|
int olderrs = haderrors; |
|
313 |
|
cur = yy_create_buffer(fp, BUFSIZE); |
|
314 |
|
yy_switch_to_buffer(cur); |
|
315 |
|
curfile = name; |
|
316 |
|
while (yyparse()) |
|
317 |
|
; |
|
318 |
|
if (olderrs == haderrors) |
|
319 |
|
printf("%s parse successful, %d lines\n", curfile, lineno); |
|
320 |
|
else |
|
321 |
|
printf("%s failed with %d error%s\n", curfile, haderrors - olderrs,(haderrors == olderrs + 1) ? "s" : ""); |
|
322 |
|
totlines += lineno; |
|
323 |
|
} |
|
324 |
|
|
|
325 |
|
void doparse(int argc, char **argv) |
|
326 |
|
{ |
|
327 |
|
int i; |
|
328 |
|
for (i = 1; i < argc; ++i) |
|
329 |
|
if (argv[i][0] == '-' && argv[i][1] == 0) |
|
330 |
|
dofile(stdin, "<stdin>"); |
|
331 |
|
else { |
|
332 |
|
FILE *fp; |
|
333 |
|
fp = fopen(argv[i], "rb"); |
|
334 |
|
dofile(fp, argv[i]); |
|
335 |
|
fclose(fp); |
|
336 |
|
} |
|
337 |
|
if (argc == 1) |
|
338 |
|
dofile(stdin, "<stdin>"); |
|
339 |
|
} |
File src/misc.h changed (mode: 100644) (index 80f791f..67daac7) |
1 |
1 |
#include <stdio.h> |
#include <stdio.h> |
2 |
2 |
#define YYDEBUG 1 |
#define YYDEBUG 1 |
3 |
3 |
|
|
|
4 |
|
#define BUFSIZE 8192 |
|
5 |
|
|
4 |
6 |
|
|
5 |
7 |
struct typenode { |
struct typenode { |
6 |
8 |
char *typename; |
char *typename; |
|
... |
... |
struct typenode *binop(const struct typenode *a, const struct typenode *b); |
63 |
65 |
int canconvert(const struct typenode *from, const struct typenode *to); |
int canconvert(const struct typenode *from, const struct typenode *to); |
64 |
66 |
void checkParameters(const struct paramlist *func, const struct paramlist *inp); |
void checkParameters(const struct paramlist *func, const struct paramlist *inp); |
65 |
67 |
|
|
66 |
|
extern int lineno; |
|
|
68 |
|
extern int lineno, totlines; |
67 |
69 |
extern int haderrors; |
extern int haderrors; |
68 |
|
extern char *yytext; |
|
|
70 |
|
extern char *yytext, *curfile; |
69 |
71 |
extern int yydebug; |
extern int yydebug; |
70 |
72 |
extern struct hashtable functions, globals, locals, params, types, *curtab; |
extern struct hashtable functions, globals, locals, params, types, *curtab; |
71 |
73 |
extern struct typenode *gInteger, *gReal, *gBoolean, *gString, *gCode, *gHandle, *gNothing, *gNull; |
extern struct typenode *gInteger, *gReal, *gBoolean, *gString, *gCode, *gHandle, *gNothing, *gNull; |
|
... |
... |
const struct typeandname *getVariable(const char *varname); |
74 |
76 |
void isnumeric(const struct typenode *ty); |
void isnumeric(const struct typenode *ty); |
75 |
77 |
void checkcomparison(const struct typenode *a, const struct typenode *b); |
void checkcomparison(const struct typenode *a, const struct typenode *b); |
76 |
78 |
void checkeqtest(const struct typenode *a, const struct typenode *b); |
void checkeqtest(const struct typenode *a, const struct typenode *b); |
|
79 |
|
void init(int argc, char **argv); |
|
80 |
|
void doparse(int argc, char **argv); |