source: other-projects/rsyntax-textarea/devel-packages/jflex-1.4.3/examples/interpreter/Tdekl.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.8 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 declarations.
24 *
25 * Also contains a reference to the symbol table of
26 * the paramaters and their arity.
27 */
28class Tdekl implements AST {
29 Tident ident; // identifier
30 Tparlist parlist; // liste of parameter
31 Texp exp; // function body
32
33 public Tdekl(Tident i, Tparlist p, Texp e) {
34 parlist=p;
35 ident=i;
36 exp=e;
37 }
38
39 public String toString() {
40 return(ident+"("+parlist+") = \n "+exp);
41 }
42
43 SymTab params; // symbol table of the parameters
44 int arity;
45
46 public void setSymtab(SymTab st) {
47 params = new SymTab(st);
48 parlist.setSymtab(params,false,0);
49 arity = params.size();
50
51 boolean isNew = st.enter(ident.toString(),
52 new STEfun(ident.toString(),this,arity));
53 // CoCo (Fun)
54 if(!isNew) Main.error("funktion "+ident+" defined twice!");
55 }
56
57 public void printSymtabs() {
58 System.out.print("funktion "+ident.toString()+"\n"+params);
59 }
60
61 public void checkcontext() {
62 exp.checkcontext(params); // CoCo (DefFun,DefVar,Arity)
63 }
64
65 public void prepInterp(SymTab st) { // set pointers and indices
66 exp.prepInterp(params);
67 }
68
69 public int interpret(int[] in, int[] par) {
70 return(exp.interpret(in,par));
71 }
72
73 public int arity() { return(arity); }
74}
75
Note: See TracBrowser for help on using the repository browser.