-
Notifications
You must be signed in to change notification settings - Fork 1
/
waccit
executable file
·53 lines (45 loc) · 1.41 KB
/
waccit
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
#!/bin/bash
args=''
filter=''
print_usage() {
printf "Usage: waccit [flags] filename\n"
printf " -i INPUT\tstdin\n"
printf " -p\t\tparse only\n"
printf " -s\t\tsemantic check\n"
printf " -t\t\tview AST\n"
printf " -a\t\tview assembly\n"
printf " -A\t\tview assembly without line numbers or extra information\n"
printf " -S\t\tstack implementation\n"
printf " -o [1-5]\toptimise\n"
printf " -x\t\texecute\n"
}
while getopts 'i:pstaASo:x' flag; do
case "${flag}" in
i) args="$args -F \"stdin=${OPTARG}\"" ;;
p) args="$args -F \"options[]=-p\"" ;;
s) args="$args -F \"options[]=-s\"" ;;
t) args="$args -F \"options[]=-t\"" ;;
a) args="$args -F \"options[]=-a\"" ;;
A) args="$args -F \"options[]=-a\""
filter="grep -P '^[0-9]+\t' | sed 's/[0-9]\+\t//'" ;;
S) args="$args -F \"options[]=-S\"" ;;
o) args="$args -F \"options[]=-o\" -F \"options[]=${OPTARG}\"" ;;
x) args="$args -F \"options[]=-x\"" ;;
*) print_usage
exit 1 ;;
esac
done
filename=${@:$OPTIND:1}
cmd="curl -s $args -F \"run=\" -F \"testfile=@$filename\" \"https://teaching.doc.ic.ac.uk/wacc_compiler/run.cgi\""
response=$(eval "$cmd")
if [[ -z $filter ]]
then
echo "Upload"
echo "-------"
echo "$response" | jq -r '.upload'
echo "Compiler out"
echo "------------"
echo "$response" | jq -r '.compiler_out'
else
echo "$response" | jq -r '.compiler_out' | eval "$filter"
fi