commit 433905f5eab71500b9e1fa479b6b0582590832fd Author: Jacob Date: Sat Sep 28 09:31:23 2024 -0400 Initial commit. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..493e224 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.o +*.so +*.out +obj/ +compile_commands.json diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f2cae5d --- /dev/null +++ b/Makefile @@ -0,0 +1,46 @@ +NAME = scl + +CC = gcc +CFLAGS_REG = -Wall -O2 +CFLAGS_DBG = -ggdb -fsanitize=address -O0 +LDFLAGS = -lm + +SRC_DIR = src +OBJ_DIR = obj +TARGET = $(NAME).out + +SRC_FILES = $(wildcard $(SRC_DIR)/*.c) +OBJ_FILES = $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SRC_FILES)) + +COL_BOLD = \x1b[37;1m +COL_CLEAR = \x1b[0m + +all: reg + +reg: CFLAGS = $(CFLAGS_REG) +reg: $(TARGET) + +dbg: CFLAGS = $(CFLAGS_DBG) +dbg: clean +dbg: $(TARGET) + +msg_compiling: + @ echo -e "$(COL_BOLD)Compiling...$(COL_CLEAR)" + +msg_linking: + @ echo -e "$(COL_BOLD)Linking...$(COL_CLEAR)" + +msg_cleaning: + @ echo -e "$(COL_BOLD)Cleaning up...$(COL_CLEAR)" + +$(TARGET): msg_compiling $(OBJ_FILES) msg_linking + $(CC) $(LDFLAGS) $(OBJ_FILES) -o $@ + +$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c + @ mkdir -p $(OBJ_DIR) + $(CC) $(CFLAGS) -c $< -o $@ + +clean: msg_cleaning + rm -rf $(OBJ_DIR) $(TARGET) $(TARGET_DBG) + +.PHONY: all clean reg dbg msg_compiling msg_linking msg_cleaning diff --git a/README.md b/README.md new file mode 100644 index 0000000..01bc32e --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# SCCL: Simple C Calculator Language + +Parses infix operators. diff --git a/src/include/main.h b/src/include/main.h new file mode 100644 index 0000000..16be59c --- /dev/null +++ b/src/include/main.h @@ -0,0 +1,6 @@ +#ifndef MAIN_H +#define MAIN_H + +#include + +#endif diff --git a/src/include/parser.h b/src/include/parser.h new file mode 100644 index 0000000..a3f442c --- /dev/null +++ b/src/include/parser.h @@ -0,0 +1,30 @@ +#ifndef PARSER_H +#define PARSER_H + +// Expression one of: +// - Operation +// - Number + +// Operation contains: +// - Type +// - Expression 1 +// - Expression 2 + +typedef enum OpType { + OPTYPE_PLUS, + OPTYPE_MINUS +} optype_t; + +typedef union Exp { + typedef struct Op { + optype_t type; + Exp* exp1; + Exp* exp2; + } op_t; + + int n; +} exp_t; + + + +#endif diff --git a/src/include/util.c b/src/include/util.c new file mode 100644 index 0000000..1f5a7ca --- /dev/null +++ b/src/include/util.c @@ -0,0 +1,12 @@ +#ifndef UTIL_H +#define UTIL_H + +// Utilies. + +#include +#include + +// Exit with an error. Returns int for ease of use, but should be treated as void. +int die(char* msg); + +#endif diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..1817149 --- /dev/null +++ b/src/main.c @@ -0,0 +1,6 @@ +#include + +int main(int argc, char** argv) { + printf("Hello, world!"); + return 0; +}