1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Copyright (C) 2001 Gerwin Klein <lsf@jflex.de> *
3 * Copyright (C) 2001 Bernhard Rumpe <rumpe@in.tum.de> *
4 * All rights reserved. *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License. See the file *
8 * COPYRIGHT for more information. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License along *
16 * with this program; if not, write to the Free Software Foundation, Inc., *
17 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
19 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
23 import java
.io
.FileReader
;
24 import java
.io
.InputStreamReader
;
25 import java
.io
.Reader
;
28 * Main program of the interpreter for the AS programming language.
33 * - context free parsing and AST building (yyparse)
34 * - build up symbol table (setSymtabs)
35 * - check context conditions (checkcontext)
36 * - prepare interpretation (prepInterp)
37 * - start interpretation (interpret)
41 public static void main(String
[] args
) throws Exception
{
44 if (args
.length
== 1) {
45 File input
= new File(args
[0]);
46 if (!input
.canRead()) {
47 System
.out
.println("Error: could not read ["+input
+"]");
49 reader
= new FileReader(input
);
52 reader
= new InputStreamReader(System
.in
);
55 Yylex scanner
= new Yylex(reader
); // create scanner
56 SymTab symtab
= new SymTab(); // set global symbol table
57 scanner
.setSymtab(symtab
);
59 parser parser
= new parser(scanner
); // create parser
60 Tprogram syntaxbaum
= null;
63 syntaxbaum
= (Tprogram
) parser
.parse().value
; // parse
69 // System.out.println(symtab);
70 System
.out
.println(syntaxbaum
);
72 syntaxbaum
.setSymtabs(); // set symbol table
73 // syntaxbaum.printSymtabs(); // print symbol table
75 syntaxbaum
.checkcontext(); // CoCo (DefVar, DefFun, Arity)
76 if(contexterror
>0) return;
78 syntaxbaum
.prepInterp(); // var. indices and function pointers
79 // im Syntaxbaum setzen
80 syntaxbaum
.interpret(); // interpretation
83 static int contexterror
= 0; // number of errors in context conditions
85 public static void error(String s
) {
86 System
.out
.println((contexterror
++)+". "+s
);