3 # CORMACKSCRIPT General Syntax
6 # Make sure you change the 'scriptfile' and 'targetfile' variables as you see fit.
9 # For extra niceness, if you have the racket program installed it will auto execute it.
14 # A CormackScript file contains 3 columns separated by whitespace in the format
15 # opcode target source
19 # You can comment with ;
26 scriptfile="A12d.cmks" # cormackscript file
27 targetfile="A12d.rkt" # destination file
29 # You can redefine these to whatever you want
31 inst0="inc" # [tt] = [tt] + 1
32 inst1="add" # [tt] = [tt] + [ss]
33 inst2="sub" # [tt] = max([tt] - [ss], 0)
34 inst3="mov" # [tt] = [ss]
35 inst4="" # [tt] = [tt] + 1, if [ss] = 0
36 inst5="" # [tt] = [[ss]]
37 inst6="" # [[tt]] = [ss]
38 inst7="print" # display [ss]
39 inst8="read" # read [tt]
42 # Config ends here =-=-=-=-=-=-=-=-=
46 sed 's/\s*;.*//g; /^\s*$/ d;' |\
49 # finally removes any non alphanumerics in case sm breaks
53 tmp="$(mktemp 'tempXXX')"
55 sed -i "/\; CMKS START/,/\; CMKS END/{/\; CMKS START/!{/\; CMKS END/!d}}; /\; CMKS START/r $tmp" "$targetfile"
60 [ -f "$scriptfile" ] && [ -f "$targetfile" ] || { echo "You are missing a file, please check that the current directory contains $scriptfile and $targetfile" && exit 1; }
62 # If racket is installed run it directly
63 # [ ! -z "$(command -v racket)" ] && racket "$targetfile"