summaryrefslogtreecommitdiff
path: root/ipl/procs/feval.icn
blob: 2d84dadee704a02dd93a97b8198923828326cfb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
############################################################################
#
#	File:     feval.icn
#
#	Subject:  Procedure to evaluate string as function call
#
#	Author:   Ralph E. Griswold
#
#	Date:     June 8, 1994
#
############################################################################
#
#   This file is in the public domain.
#
############################################################################
#
#  This procedure analyzes a string representing an Icon function or
#  procedure call and evaluates the result.
#
#  It assumes the string is well-formed.  The arguments can only be
#  Icon literals. Escapes, commas, and parentheses in strings literals
#  are not handled.
#
############################################################################
#
#  Links:  ivalue
#
############################################################################

invocable all

link ivalue

procedure feval(s)
   local fnc, argl

   s ? {
      fnc := tab(upto('(')) | {
         write(&errout, "*** syntax error")
         fail
         }
      fnc := proc(fnc, 3 to 1 by -1) | {
         write(&errout, "*** invalid function or operation")
         fail
         }
      move(1)

      argl := []
      while put(argl, ivalue(tab(upto(',)')))) do move(1)

      suspend fnc ! argl
      }

end