aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-120/james-smith/cesil/cesil.pl18
-rw-r--r--challenge-120/james-smith/cesil/ch-2.ces33
2 files changed, 36 insertions, 15 deletions
diff --git a/challenge-120/james-smith/cesil/cesil.pl b/challenge-120/james-smith/cesil/cesil.pl
new file mode 100755
index 0000000000..3a5f568a77
--- /dev/null
+++ b/challenge-120/james-smith/cesil/cesil.pl
@@ -0,0 +1,18 @@
+#!/bin/perl
+use strict;use warnings;my($M,$p,$r,@i,%m,@c,%q)=(1e6,0,0);
+my@t=('PROGRAM REQUIRES MORE DATA','UNKNOWN VARIABLE ',
+'DIVISION BY ZERO ','UNKNOWN LABEL ');
+sub _e{die sprintf "\n*** %s%s *** %s \@ %d\n",$t[$_[0]],@{$c[$p]}[1,0],1+$p}
+sub _j{exists$q{$_}?($p=$q{$_}-1):_e 3}
+sub _v{/^[+-]?\d+$/?$_:exists$m{$_}?$m{$_}:_e 1}
+my%c=('LINE',sub{print"\n"},'OUT',sub{print$r},'STORE',sub{$m{$_}=$r},
+'PRINT',sub{print s/^"//r=~s/"$//r},'IN',sub{@i?($r=shift@i):_e 0},
+'JINEG',sub{_j if$r<0},'SUBTRACT',sub{$r-=_v},'MULTIPLY',sub{$r*=_v},
+'ADD',sub{$r+=_v},'DIVIDE',sub{$_=_v;$r=$_?int($r/$_):_e 2},
+'LOAD',sub{$r=_v},'JIZERO',sub{_j if!$r},'JUMP',sub{_j},'HALT',sub{exit});
+while(<>){next if/^ *\(/;((@i=map{/^\s+-?\d+\s*$/?0+$_:()}<>),last)if/^ *%/;
+($q{$1},$_)=(0+@c,$2)if/^(\S{1,6})\s+(.*)/;
+my($x,$y)=split/\s+/,s/^\s+//r=~s/\s+$//r,2;
+die"\n# Unk cmd [$x \@ ",1+@c,"]\n"if!exists$c{$x};push@c,[$x,$y//''];}
+($c{$c[$p][0]}($_=$c[$p][1]),$p++)while--$M&&$p<@c;
+die"\n*** No HALT ***\n"
diff --git a/challenge-120/james-smith/cesil/ch-2.ces b/challenge-120/james-smith/cesil/ch-2.ces
index 193ca339d2..fc057024b4 100644
--- a/challenge-120/james-smith/cesil/ch-2.ces
+++ b/challenge-120/james-smith/cesil/ch-2.ces
@@ -1,23 +1,26 @@
+( Compute the angle between the hour and minute hand
+( Input contains of triple hour/minute & answer so
+( can check calculations are OK!
LINE
- LOAD 0
+ LOAD +0
STORE success
STORE tests
Next IN
JINEG End
- SUBTRACT 10
+ SUBTRACT +10
JINEG bl1
JUMP bl1e
bl1 PRINT "0"
-bl1e ADD 10
+bl1e ADD +10
OUT
STORE hr
PRINT ":"
IN
- SUBTRACT 10
+ SUBTRACT +10
JINEG bl2
JUMP bl2e
bl2 PRINT "0"
-bl2e ADD 10
+bl2e ADD +10
OUT
STORE mn
IN
@@ -25,31 +28,31 @@ bl2e ADD 10
LOAD mn
PRINT " => "
MULTIPLY -11
- DIVIDE 2
+ DIVIDE +2
STORE t
LOAD hr
SUBTRACT 12
JINEG lt12
JUMP gt12
-lt12 ADD 12
-gt12 MULTIPLY 30
+lt12 ADD +12
+gt12 MULTIPLY +30
ADD t
JINEG lt0
JUMP gt0
lt0 MULTIPLY -1
-gt0 SUBTRACT 180
+gt0 SUBTRACT +180
JINEG ltx0
MULTIPLY -1
-ltx0 ADD 80
+ltx0 ADD +80
JINEG lt100
JUMP gt100
lt100 PRINT " "
- ADD 90
+ ADD +90
JINEG lt10
JUMP gt10
lt10 PRINT " "
-gt10 SUBTRACT 90
-gt100 ADD 100
+gt10 SUBTRACT +90
+gt100 ADD +100
OUT
PRINT " : "
SUBTRACT ans
@@ -61,11 +64,11 @@ gt100 ADD 100
JUMP Line
Ok PRINT "OK"
LOAD success
- ADD 1
+ ADD +1
STORE success
Line LINE
LOAD tests
- ADD 1
+ ADD +1
STORE tests
JUMP Next
End LINE