diff --git a/examples/hello_world.csq b/examples/hello_world.csq new file mode 100644 index 0000000..21f1463 --- /dev/null +++ b/examples/hello_world.csq @@ -0,0 +1,5 @@ +include stdio; + +void! main() { + printf("Hello, World!\n"); +} diff --git a/include/csquare/lexer/lexer.h b/include/csquare/lexer/lexer.h index 980391c..16a9c6a 100644 --- a/include/csquare/lexer/lexer.h +++ b/include/csquare/lexer/lexer.h @@ -49,6 +49,7 @@ T(T_SEMICOLON, "SEMICOLON") \ T(T_AND, "AND") \ T(T_OR, "OR") \ + T(T_EXCLAMATION, "EXCLAMATION MARK") \ \ T(T_KW_DO, "DO") \ T(T_KW_IF, "IF") \ @@ -112,7 +113,7 @@ void add_token(token_list *list, token *tk); #define isws(c) (c == ' ' || c == '\t' || c == '\n' || c == '\r') #define isdigit(c) (c >= '0' && c <= '9') -#define isalpha(c) (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z') +#define isalpha(c) ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) #define LEX_FUNC_ARGS const char *p, int *len token *lex_symbol(LEX_FUNC_ARGS); diff --git a/makefile b/makefile index 9735213..36124cd 100644 --- a/makefile +++ b/makefile @@ -1,10 +1,12 @@ include config.mk -.PHONY: all clean directories +.PHONY: all clean directories rebuild # Default target all: directories $(TARGET) +rebuild: clean all + directories: @mkdir -p $(BUILDDIR) $(BINDIR) $(shell find $(SRCDIR) -type d | sed 's/$(SRCDIR)/$(BUILDDIR)/') diff --git a/src/csquare/opt-common.c b/src/csquare/opt-common.c index 59b8996..c20a94e 100644 --- a/src/csquare/opt-common.c +++ b/src/csquare/opt-common.c @@ -9,6 +9,7 @@ static const opt_map_t opts[] = {{"--info", "-i", OPT_KIND_FUNC, handle_info}}; static void handle_info(csq_options *opts, const char *_) { + (void)_; (void)opts; printf("Csquared - %s (%s)\n", CSQ_VERSION, __DATE__); printf("Authors: %s\n", CSQ_AUTHORS); diff --git a/src/lexer/lex_symbol.c b/src/lexer/lex_symbol.c index 310ff0c..23a04f0 100644 --- a/src/lexer/lex_symbol.c +++ b/src/lexer/lex_symbol.c @@ -7,9 +7,11 @@ const struct { {"==", T_EQ}, {"!=", T_NEQ}, {">=", T_GREATER_EQUALS}, {"<=", T_LESS_EQUALS}, {"+=", T_ADD_ASSIGN}, {"-=", T_SUB_ASSIGN}, {"/=", T_DIV_ASSIGN}, {"*=", T_MUL_ASSIGN}, {"&&", T_AND}, - {"||", T_OR}, {"=", T_ASSIGN}, {"+", T_ADD}, - {"-", T_SUB}, {"/", T_DIV}, {"*", T_MUL}, - {">", T_GREATER}, {"<", T_LESS}, {"(", T_OPEN_PAREN}, + {"||", T_OR}, + + {"=", T_ASSIGN}, {"+", T_ADD}, {"-", T_SUB}, + {"/", T_DIV}, {"*", T_MUL}, {">", T_GREATER}, + {"<", T_LESS}, {"!", T_EXCLAMATION}, {"(", T_OPEN_PAREN}, {")", T_CLOSE_PAREN}, {"{", T_OPEN_BRACE}, {"}", T_CLOSE_BRACE}, {"[", T_OPEN_BRACKET}, {"]", T_CLOSE_BRACKET}, {".", T_PERIOD}, {",", T_COMMA}, {":", T_COLON}, {";", T_SEMICOLON}}; diff --git a/src/lexer/lexer.c b/src/lexer/lexer.c index c1f7c94..8ba596c 100644 --- a/src/lexer/lexer.c +++ b/src/lexer/lexer.c @@ -125,6 +125,7 @@ token_list *lex(const char *src) { add_token(list, tk); } + add_token(list, new_token(p, 0, T_EOF)); return list; }