diff --git a/bitwise/README.txt b/bitwise/README.txt new file mode 100644 index 0000000..07597b7 --- /dev/null +++ b/bitwise/README.txt @@ -0,0 +1,4 @@ +bitwise +======= + +Following along with [bitwise](https://github.com/pervognsen/bitwise). \ No newline at end of file diff --git a/bitwise/ion/Makefile b/bitwise/ion/Makefile index 1c0c449..ce73c05 100644 --- a/bitwise/ion/Makefile +++ b/bitwise/ion/Makefile @@ -2,11 +2,15 @@ TARGET := ion OBJS := $(TARGET).o CFLAGS := -g -std=c99 -Wall -Werror -all: $(TARGET) +.PHONY: all run +all: run + +run:$(TARGET) + ./$(TARGET) $(TARGET): $(OBJS) $(CC) $(CFLAGS) -o $@ $(OBJS) .PHONY: clean clean: - rm -f $(OBJS) $(TARGET) \ No newline at end of file + rm -f $(OBJS) $(TARGET) diff --git a/bitwise/ion/ion.c b/bitwise/ion/ion.c index 3fa915f..1dc7edb 100644 --- a/bitwise/ion/ion.c +++ b/bitwise/ion/ion.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -62,7 +63,7 @@ buf_test(void) printf("OK\n"); } typedef enum TokenKind { - TOKEN_INT, + TOKEN_INT = 128, TOKEN_NAME, // ... } TokenKind; @@ -72,6 +73,8 @@ typedef struct Token { // ... } Token; +const char *stream; + Token token; void next_token(void) { switch (*stream) { @@ -91,14 +94,26 @@ void next_token(void) { token.kind = TOKEN_INT; break; default: - token.kind = *stream; + token.kind = *stream++; break; } } +void lex_test() +{ + char source[] = "+()123456+994"; + stream = source; + next_token(); + while (token.kind) { + printf("TOKEN: %d\n", token.kind); + next_token(); + } +} + int main(int argc, char *argv[]) { buf_test(); + lex_test(); return 0; } \ No newline at end of file diff --git a/bitwise/ion/notes.txt b/bitwise/ion/notes.txt index 87f1038..b085c45 100644 --- a/bitwise/ion/notes.txt +++ b/bitwise/ion/notes.txt @@ -17,4 +17,4 @@ stretch buffers: + ex. '1234 (x+y)' translates to '1234' '(' 'x' '+' 'y' ')' + no semantics yet + simple hand-written approach - + mark: 1:06:11 \ No newline at end of file + + mark: 1:09:11 \ No newline at end of file