2 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3 * See the copyright notice in the ACK home directory, in the file "Copyright".
5 * Author: Ceriel J.H. Jacobs
8 /* M A I N P R O G R A M */
10 /* $Id: main.c,v 1.65 1996/08/14 07:42:34 ceriel Exp $ */
22 #include "strict3rd.h"
32 #include "standards.h"
33 #include "tokenname.h"
38 int state; /* either IMPLEMENTATION or PROGRAM */
43 int nDEF = 2, mDEF = 10;
46 extern int err_occurred;
47 extern int fp_used; /* set if floating point used */
48 static t_node _emptystat = { Stat, 0, NULLTYPE, { ';' }};
49 t_node *EmptyStatement = &_emptystat;
54 register int Nargc = 1;
55 register char **Nargv = &argv[0];
58 DEFPATH = (char **) Malloc((unsigned)mDEF * sizeof(char *));
63 DoOption((*argv++) + 1);
65 Nargv[Nargc++] = *argv++;
67 Nargv[Nargc] = 0; /* terminate the arg vector */
69 fprint(STDERR, "%s: Use a file argument\n", ProgName);
72 sys_stop(Compile(Nargv[1], Nargv[2]) ? S_END : S_EXIT);
79 extern struct tokenname tkidf[];
80 extern char *getwdir();
82 if (! InsertFile(src, (char **) 0, &src)) {
83 fprint(STDERR,"%s: cannot open %s\n", ProgName, src);
88 WorkingDir = getwdir(src);
89 C_init(word_size, pointer_size);
90 if (! C_open(dst)) fatal("could not open output file");
92 C_ms_emx(word_size, pointer_size);
95 C_ms_std(FileName, N_SO, 0);
110 open_scope(OPENSCOPE);
113 CheckForLineDirective();
115 C_ms_src((int)LineNumber - 1, FileName);
118 C_exp(Defined->mod_vis->sc_scope->sc_name);
120 if (fp_used) C_ms_flt();
124 if (options['i']) Info();
126 return ! err_occurred;
132 register t_token *tkp = ˙
133 extern char *symbol2str();
135 while (LLlex() > 0) {
136 print(">>> %s ", symbol2str(tkp->tk_symb));
137 switch(tkp->tk_symb) {
140 print("%s\n", tkp->TOK_IDF->id_text);
144 print("%ld\n", tkp->TOK_INT);
148 print("%s\n", tkp->TOK_RSTR);
152 print("\"%s\"\n", tkp->TOK_STR);
162 static struct stdproc {
169 { "FLOAT", S_FLOAT },
176 #ifndef STRICT_3RD_ED
178 { "DISPOSE", S_DISPOSE },
180 { "TRUNC", S_TRUNC },
188 { "SHORT", S_SHORT },
189 { "TRUNCD", S_TRUNCD },
190 { "FLOATD", S_FLOATD },
194 static struct stdproc sysprocs[] = {
195 { "TSIZE", S_TSIZE },
200 extern t_def *Enter(), *EnterType();
203 register struct stdproc *p;
205 for (; p->st_nam != 0; p++) {
206 if (! Enter(p->st_nam, D_PROCEDURE, std_type, p->st_con)) {
215 static t_token nilconst = { INTEGER, 0};
218 EnterType("CHAR", char_type);
219 EnterType("INTEGER", int_type);
220 EnterType("LONGINT", longint_type);
221 EnterType("REAL", real_type);
222 EnterType("LONGREAL", longreal_type);
223 EnterType("CARDINAL", card_type);
225 /* local extension: LONGCARD. */
226 EnterType("LONGCARD", longcard_type);
228 EnterType("(void)", void_type);
229 df = Enter("NIL", D_CONST, address_type, 0);
230 df->con_const = nilconst;
232 EnterType("PROC", construct_type(T_PROCEDURE, NULLTYPE));
233 EnterType("BITSET", bitset_type);
234 df = Enter("FALSE", D_ENUM, bool_type, 0);
235 bool_type->enm_enums = df;
236 df->enm_next = Enter("TRUE", D_ENUM, bool_type, 0);
237 df->enm_next->enm_val = 1;
238 assert(df->enm_val == 0 && df->enm_next->enm_next == 0);
239 EnterType("BOOLEAN", bool_type);
244 /* Simulate the reading of the SYSTEM definition module
246 static char systemtext[] = SYSTEMTEXT;
248 EnterType("WORD", word_type);
249 EnterType("BYTE", byte_type);
250 EnterType("ADDRESS",address_type);
252 if (!InsertText(systemtext, sizeof(systemtext) - 1)) {
253 fatal("could not insert text");
264 extern int cnt_def, cnt_node, cnt_paramlist, cnt_type,
265 cnt_switch_hdr, cnt_case_entry,
266 cnt_scope, cnt_scopelist, cnt_tmpvar;
269 %6d def\n%6d node\n%6d paramlist\n%6d type\n%6d switch_hdr\n\
270 %6d case_entry\n%6d scope\n%6d scopelist\n%6d tmpvar\n",
271 cnt_def, cnt_node, cnt_paramlist, cnt_type,
272 cnt_switch_hdr, cnt_case_entry,
273 cnt_scope, cnt_scopelist, cnt_tmpvar);
274 print("\nNumber of lines read: %d\n", cntlines);
281 fatal("out of memory");
287 fatal("write failed");