-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheval.sh
executable file
·44 lines (36 loc) · 1015 Bytes
/
eval.sh
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
#!/bin/sh
verbose=0
filename=""
iterations_limit=1000
iterations=0
for i in $@; do
if [ "$i" = "--verbose" ]; then
verbose=1
else
filename="$i"
fi
done
if [ "x$filename" = x ]; then
echo "Usage: $0 [--verbose] <program_filename>"
echo " echo <expression> | $0 [--verbose] -"
exit
fi
if [ "$filename" = "-" ]; then
expression="`cat`"
else
expression="`cat $filename`"
fi
# Preprocess.
expression="`echo "$expression" | ./preprocessor.sed`"
# Reduce.
while true; do
[ $verbose = 1 ] && echo "$expression"
result="`echo "$expression" | ./beta-reducer.sed`"
iterations=$(( $iterations + 1 ))
[ $iterations -ge $iterations_limit -o "x$result" = "x$expression" ] && break
expression="$result"
done
# Run the beta-reduce.sed one more time but in the
# echo-mode to clean up the resulting expression.
expression="`echo "${result}," | ./beta-reducer.sed`"
[ $verbose = 1 -a "x$expression" != "x$result" -o $verbose = 0 ] && echo $expression