summaryrefslogtreecommitdiff
path: root/ipl/progs/interpe.icn
blob: ef317ea925e8b120c962a81c3e1aa14ffdb1508f (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
55
56
57
############################################################################
#
#	File:     interpe.icn
#
#	Subject:  Program to interpret Icon expressions
#
#	Author:   Ralph E. Griswold
#
#	Date:     December 30, 1991
#
############################################################################
#
#   This file is in the public domain.
#
############################################################################
#
#    This program is a crude but effective interpreter for Icon expressions.
#  Each line entered from standard input is presumed to be an Icon
#  expression, is wrapped with a main procedure, and written to a pipe
#  that compiles and executes the resulting program.
#
#    If the expression is a generator, all its results are produced.
#  If the command-line option -e is given, the expression is echoed.
#
#    This technique is, of course, inefficient and may be painfully
#  slow except on the fastest platforms. This technique is, however,
#  completely general and as correct as Icon itself.
#
#    Note:  This programs creates files with the names stdin, stdin.u1,
#  and stdin.u2. It removes them before terminating, but, of course,
#  overwrites any pre-existing files by these names.
#
############################################################################
#
#  Requires: UNIX
#
#  See also:  interpp.icn
#
############################################################################

procedure main(args)
   local line, run, echo

   if args[1] == "-e" then echo := 1

   while line := read() do {
      run := open("icont -s - -x","pw")
      write(run,"procedure main()")
      if \echo then write(run,"   write(",image(line),")")
      write(run,"   every write(image(",line,"))")
      write(run,"end")
      close(run)
      }

   system("rm -f stdin stdin.u1 stdin.u2")

end