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

« back to all changes in this revision

Viewing changes to examples/interpreter/Tident.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
/**
 
23
 * AST node for an identifier
 
24
 */ 
 
25
class Tident extends Texp implements AST {
 
26
  String name;                
 
27
 
 
28
  public Tident(String s) {
 
29
    name = s; 
 
30
  }
 
31
 
 
32
  public String toString() {
 
33
    return name; 
 
34
  }
 
35
 
 
36
  public void checkcontext(SymTab st) {         // CoCo (DefVar)
 
37
    SymtabEntry ste = st.lookup(name);
 
38
 
 
39
    if (ste==null)
 
40
      Main.error("variable not defined: "+name);
 
41
    else if (ste.kind() != SymtabEntry.VAR)
 
42
      Main.error("function used as variable: "+name);
 
43
  }
 
44
 
 
45
  int index;              // number of ident in environment
 
46
  boolean is_input;       // is it an input variable?    
 
47
 
 
48
  public void prepInterp(SymTab st) {  // set index for environment 
 
49
    STEvar ste = (STEvar)st.lookup(name);
 
50
    index = ste.getIndex();
 
51
    is_input = ste.isInput();
 
52
  }
 
53
 
 
54
  public int interpret(int[] in, int[] par) {
 
55
    if (is_input) 
 
56
      return(in[index]); 
 
57
    else 
 
58
      return(par[index]);
 
59
  }
 
60
}
 
61
 
 
62