You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.4 KiB
44 lines
1.4 KiB
1 year ago
|
#!/bin/bash
|
||
|
|
||
|
# Term colours for output
|
||
|
RED='\033[0;31m' # Red
|
||
|
GRN='\033[0;32m' # Green
|
||
|
NC='\033[0m' # No Color
|
||
|
|
||
|
TRI=""
|
||
|
|
||
|
# Check if the input in arg 1 ($1) is empty
|
||
|
if [ -z "$1" ]
|
||
|
then # if empty...
|
||
|
printf "${RED}Usage: $0 *.tri file (optional: $0 *.tri tree)${NC}"
|
||
|
exit 1 # Exit with code 1, failure
|
||
|
else
|
||
|
TRI=$1
|
||
|
fi
|
||
|
|
||
|
#Remove the extension of the file
|
||
|
FILENAME=$(echo $TRI | cut -f 1 -d '.')
|
||
|
|
||
|
#TODO: implement tree command
|
||
|
printf "${GRN}[INFO] Compiling file: $FILENAME.tri to $FILENAME.tam ...${NC}\n"
|
||
|
|
||
|
# Compile to tam
|
||
|
if java -cp ../build/libs/Triangle-Tools.jar triangle.Compiler $FILENAME.tri -o=$FILENAME.tam &> /dev/null #quiet
|
||
|
then if [ -z "$2" ]
|
||
|
then #if empty
|
||
|
printf "${GRN}[INFO] Running file: $FILENAME.tam ...${NC}\n"
|
||
|
java -cp ../build/libs/Triangle-Tools.jar triangle.abstractMachine.Interpreter $FILENAME.tam
|
||
|
exit 0
|
||
|
else
|
||
|
printf "${GRN}[INFO] Running file: $FILENAME.tam ... and displaying AST${NC}\n"
|
||
|
java -cp ../build/libs/Triangle-Tools.jar triangle.Compiler $FILENAME.tri tree -o=$FILENAME.tam &> /dev/null #quiet
|
||
|
exit 0
|
||
|
fi
|
||
|
|
||
|
else
|
||
|
printf "${RED}[ERROR] Could not complie $FILENAME.tri ...${NC}"
|
||
|
err=$(java -cp ../build/libs/Triangle-Tools.jar triangle.Compiler $FILENAME.tri -o=$FILENAME.tam)
|
||
|
printf "${RED}\n$err\n${NC}"
|
||
|
exit 1
|
||
|
fi
|