git @ Cat's Eye Technologies Kangaroo-Iceberg / rel_0_5_2011_0509
Import version 0.5 revision 2011.0509. Cat's Eye Technologies 9 years ago
5 changed file(s) with 46 addition(s) and 31 deletion(s). Raw diff Collapse all Expand all
0 # BSD Makefile for kiceberg.
0 # Makefile for kiceberg.
11 # $Id$
22
3 CC= gcc
4 CFLAGS= -Wall -ansi -pedantic
5 LIBS=
3 CC?=gcc
4 LIBS?=
65
7 CFLAGS+= ${EXTRA_CFLAGS}
6 WARNS= -Werror -W -Wall -Wstrict-prototypes -Wmissing-prototypes \
7 -Wpointer-arith -Wno-uninitialized -Wreturn-type -Wcast-qual \
8 -Wwrite-strings -Wswitch -Wshadow -Wcast-align -Wchar-subscripts \
9 -Winline -Wnested-externs -Wredundant-decls
10
11 # Won't compile under ANSI, but for consistency with other Makefiles:
12 ifdef ANSI
13 CFLAGS+= -ansi -pedantic
14 else
15 CFLAGS+= -std=c99 -D_POSIX_C_SOURCE=200112L
16 endif
17
18 CFLAGS+= ${WARNS} ${EXTRA_CFLAGS}
819
920 OBJS= graph.o rule.o \
1021 symbol.o \
5252
5353 struct symbol_table *gstab; /* general symbol table */
5454 struct legislature *glaw; /* all rules */
55
55
5656 /* PROTOTYPES */
5757
5858 void usage(void);
6363 main(int argc, char **argv)
6464 {
6565 struct scan_st *sc;
66 int ch;
6766 int do_dump = 0;
6867 struct node *global;
68 int argn;
69 char *global_ident;
6970
7071 /* Initialize / allocate globals. */
71
72
7273 gstab = symbol_table_new();
73 global = node_new(symbol_define(gstab, "__GLOBAL__", SYM_TYPE_NODE));
74 global_ident = malloc(20 * sizeof(char));
75 strcpy(global_ident, "__GLOBAL__");
76 global = node_new(symbol_define(gstab, global_ident, SYM_TYPE_NODE));
7477 glaw = legislature_new();
7578
7679 /* Parse arguments. */
7780
78 while ((ch = getopt(argc, argv, "d")) != -1) {
79 switch(ch) {
80 case 'd':
81 do_dump = 1;
81 for (argn = 1; argn < argc; argn++) {
82 if (argv[argn][0] == '-') {
83 switch(argv[argn][1]) {
84 case 'd':
85 do_dump = 1;
86 break;
87 default:
88 usage();
89 }
90 } else {
8291 break;
83 case '?':
84 default:
85 usage();
8692 }
8793 }
88 argc -= optind;
89 argv += optind;
9094
9195 /* Parse the input file. */
9296
93 while (argc > 0) {
97 while (argn < argc) {
9498 sc = scan_open(argv[0]);
9599 kangaroo_iceberg(sc, global);
96100 scan_close(sc);
97 argc--;
98 argv++;
101 argn++;
99102 }
100103
101104 if (do_dump) {
7575 }
7676
7777 void
78 scan_error(struct scan_st *sc, char *fmt, ...)
78 scan_error(struct scan_st *sc, const char *fmt, ...)
7979 {
8080 va_list args;
81 char err[256];
81 char error[256];
8282
8383 va_start(args, fmt);
84 vsnprintf(err, 255, fmt, args);
84 vsnprintf(error, 255, fmt, args);
8585
8686 fprintf(stderr, "Error (line %d, column %d, token '%s'): %s.\n",
87 sc->lino, sc->columno, sc->token, err);
87 sc->lino, sc->columno, sc->token, error);
8888 }
8989
90 int
90 static int
9191 scan_char(struct scan_st *sc, char *x)
9292 {
9393 *x = (char)getc(sc->in); sc->columno++;
188188 }
189189
190190 void
191 scan_expect(struct scan_st *sc, char *x)
191 scan_expect(struct scan_st *sc, const char *x)
192192 {
193193 if (!strcmp(sc->token, x)) {
194194 scan(sc);
3030
3131 extern struct scan_st *scan_open(char *);
3232 extern void scan_close(struct scan_st *);
33 extern void scan_error(struct scan_st *, char *, ...);
33 extern void scan_error(struct scan_st *, const char *, ...);
3434 extern void scan(struct scan_st *);
35 extern void scan_expect(struct scan_st *, char *);
35 extern void scan_expect(struct scan_st *, const char *);
3636
3737 #endif /* !__SCAN_H */
7272 struct symbol *new_sym;
7373
7474 MALLOC(new_sym, symbol, "symbol");
75 if ((new_sym->token = strdup(token)) == NULL)
75 if ((new_sym->token = malloc(strlen(token)+1)) == NULL)
7676 perror("Could not allocate symbol lexeme");
77 strcpy(new_sym->token, token);
7778 new_sym->type = type;
7879 new_sym->dest = NULL;
7980 new_sym->next = stab->head;
113114 void
114115 symbol_dump(int indent, struct symbol *sym)
115116 {
116 char *ty;
117 const char *ty;
117118 int i;
118119
119120 for (i = 0; i < indent; i++)