source: other-projects/rsyntax-textarea/devel-packages/jflex-1.4.3/examples/interpreter/Tfun.java@ 25584

Last change on this file since 25584 was 25584, checked in by davidb, 12 years ago

Initial cut an a text edit area for GLI that supports color syntax highlighting

File size: 2.7 KB
Line 
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Copyright (C) 2001 Gerwin Klein <[email protected]> *
3 * Copyright (C) 2001 Bernhard Rumpe <[email protected]> *
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 function application.
24 *
25 * Also contains pointer to declaration location of the function.
26 */
27class Tfun extends Texp implements AST {
28 Tident ident; // name of the function
29 Texplist explist; // parameter list
30
31 public Tfun(Tident i, Texplist e) {
32 ident=i;
33 explist=e;
34 }
35
36 public String toString() {
37 return ident+"("+explist+")";
38 }
39
40 public void checkcontext(SymTab st) { // CoCo (DefFun,Arity)
41 explist.checkcontext(st);
42 SymtabEntry ste = st.lookup(ident.toString());
43 if (ste==null)
44 Main.error("function not defined: "+ident);
45 else if (ste.kind() != SymtabEntry.FUN)
46 Main.error("variable used as funktion: "+ident);
47 else if (((STEfun)ste).arity() != explist.length())
48 Main.error("wrong arity at function call: "+ident);
49 }
50
51 Tdekl fundekl; // pointer to location of function declaration
52
53 // set pointers and indices
54 public void prepInterp(SymTab st) {
55 fundekl = ((STEfun)st.lookup(ident.toString())).getDekl();
56 explist.prepInterp(st);
57 }
58
59 public int interpret(int[] in, int[] par) {
60 int[] newparams = new int[fundekl.arity()];
61 explist.interpret(in,par,newparams,0);
62 return fundekl.interpret(in,newparams);
63 }
64}
65
66
Note: See TracBrowser for help on using the repository browser.