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
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
25
* Main program of the interpreter for the AS programming language.
30
* - context free parsing and AST building (yyparse)
31
* - build up symbol table (setSymtabs)
32
* - check context conditions (checkcontext)
33
* - prepare interpretation (prepInterp)
34
* - start interpretation (interpret)
38
public static void main(String [] args) throws Exception {
39
Reader reader = new InputStreamReader(System.in);
41
Yylex scanner = new Yylex(reader); // create scanner
42
SymTab symtab = new SymTab(); // set global symbol table
43
scanner.setSymtab(symtab);
45
parser parser = new parser(scanner); // create parser
46
Tprogram syntaxbaum = null;
49
syntaxbaum = (Tprogram) parser.parse().value; // parse
55
// System.out.println(symtab);
56
System.out.println(syntaxbaum);
58
syntaxbaum.setSymtabs(); // set symbol table
59
// syntaxbaum.printSymtabs(); // print symbol table
61
syntaxbaum.checkcontext(); // CoCo (DefVar, DefFun, Arity)
62
if(contexterror>0) return;
64
syntaxbaum.prepInterp(); // var. indices and function pointers
65
// im Syntaxbaum setzen
66
syntaxbaum.interpret(); // interpretation
69
static int contexterror = 0; // number of errors in context conditions
71
public static void error(String s) {
72
System.out.println((contexterror++)+". "+s);