working compiler maybe

This commit is contained in:
Liam Waldron 2024-02-06 09:29:19 -05:00
parent 8928d0f7a4
commit 670871345e
2 changed files with 67 additions and 1 deletions

View File

@ -7,8 +7,20 @@ local { printf("static"); }
"str" { printf("char"); } "str" { printf("char"); }
/* Library declarations */ /*** Library declarations ***/
/* ioutils */
"hell:std.ioutils" { printf("<stdio.h>"); } "hell:std.ioutils" { printf("<stdio.h>"); }
"hell:std.ioutils.writeln" { printf("printf"); } "hell:std.ioutils.writeln" { printf("printf"); }
"hell:std.ioutils.readln" { printf("scanf"); } "hell:std.ioutils.readln" { printf("scanf"); }
/* keygen */
"hell:std.keygen" { printf("<hellkeygen.h>"); }
"hell:std.keygen.gen" { printf("keygen_gen"); }
/* rng */
"hell:std.rng" { printf("<hellrng.h"); }
"hell:std.rng.gen" { printf("rng_randint"); }

54
compiler/hellc Executable file
View File

@ -0,0 +1,54 @@
#!/bin/bash
INFILE=${2}
usage() {
printf "${0} - compiler for HELL programming language\n"
printf "usage: ${0} INFILE GCCOPTS\n"
printf "\n"
printf "Note: Since hellc is a frontend for GCC, any GCC option can be used.\n"
printf "\n"
printf "Hellc is free software.\n"
printf "See the GNU GPL version 3 for details.\n"
}
usage_small() {
printf "usage: ${0} INFILE GCCOPTS\n"
}
case ${1} in
-h|--help)
usage "$@"
exit 0
;;
-c|--compile)
if [[ -z "${INFILE}" ]]; then
printf "${0}: no input file\n"
exit 1
fi
printf "running HELL preprocessor for ${INFILE}\n"
cat ${INFILE} | hellp > ${INFILE}.new
if [ "$?" != 0 ]; then
printf "${0}: error: HELL preprocessor failed to run\n"
exit 1
fi
printf "compiling ${INFILE}\n"
gcc ${INFILE}.new -o ${INFILE}
if [ "$?" != 0 ]; then
printf "${0}: error: C compiler failed to run\n"
exit 1
fi
printf "finished compiling\n"
exit 0
;;
-*|--*)
usage_small "$@"
exit 0
;;
esac
usage_small "$@"
exit 1