~ubuntu-branches/ubuntu/gutsy/jflex/gutsy

« back to all changes in this revision

Viewing changes to examples/interpreter/Main.java

  • Committer: Bazaar Package Importer
  • Author(s): Takashi Okamoto
  • Date: 2002-02-16 13:38:21 UTC
  • Revision ID: james.westby@ubuntu.com-20020216133821-5wsdprpt9xl7ondr
Tags: upstream-1.3.5
ImportĀ upstreamĀ versionĀ 1.3.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 
2
 * Copyright (C) 2001       Gerwin Klein <lsf@jflex.de>                    *
 
3
 * Copyright (C) 2001       Bernhard Rumpe <rumpe@in.tum.de>               *
 
4
 * All rights reserved.                                                    *
 
5
 *                                                                         *
 
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.                                         *
 
9
 *                                                                         *
 
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.                            *
 
14
 *                                                                         *
 
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                 *
 
18
 *                                                                         *
 
19
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 
20
 
 
21
 
 
22
import java.io.*;
 
23
 
 
24
/**
 
25
 * Main program of the interpreter for the AS programming language.
 
26
 * Based on JFlex/CUP.
 
27
 * 
 
28
 * Steps:
 
29
 * - scanning                               (Yylex)
 
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)
 
35
 */ 
 
36
public class Main {
 
37
 
 
38
  public static void main(String [] args) throws Exception {
 
39
    Reader reader = new InputStreamReader(System.in);
 
40
 
 
41
    Yylex scanner = new Yylex(reader);   // create scanner
 
42
    SymTab symtab = new SymTab();        // set global symbol table    
 
43
    scanner.setSymtab(symtab);
 
44
 
 
45
    parser parser = new parser(scanner); // create parser
 
46
    Tprogram syntaxbaum = null;
 
47
 
 
48
    try { 
 
49
      syntaxbaum = (Tprogram) parser.parse().value;  // parse
 
50
    }    
 
51
    catch (Exception e) { 
 
52
      e.printStackTrace(); 
 
53
    }
 
54
 
 
55
    // System.out.println(symtab);
 
56
    System.out.println(syntaxbaum);
 
57
 
 
58
    syntaxbaum.setSymtabs();          // set symbol table
 
59
    // syntaxbaum.printSymtabs();       // print symbol table
 
60
 
 
61
    syntaxbaum.checkcontext();        // CoCo (DefVar, DefFun, Arity)
 
62
    if(contexterror>0) return;
 
63
 
 
64
    syntaxbaum.prepInterp();          // var. indices and function pointers
 
65
    // im Syntaxbaum setzen
 
66
    syntaxbaum.interpret();           // interpretation
 
67
  }
 
68
 
 
69
  static int contexterror = 0;        // number of errors in context conditions
 
70
 
 
71
  public static void error(String s) { 
 
72
    System.out.println((contexterror++)+". "+s); 
 
73
  }
 
74
}