bitwise: another three minutes of video on the bus.

This commit is contained in:
Kyle Isom 2018-03-26 11:33:32 -07:00
parent e779c77d32
commit c242894f94
4 changed files with 28 additions and 5 deletions

4
bitwise/README.txt Normal file
View File

@ -0,0 +1,4 @@
bitwise
=======
Following along with [bitwise](https://github.com/pervognsen/bitwise).

View File

@ -2,7 +2,11 @@ TARGET := ion
OBJS := $(TARGET).o OBJS := $(TARGET).o
CFLAGS := -g -std=c99 -Wall -Werror CFLAGS := -g -std=c99 -Wall -Werror
all: $(TARGET) .PHONY: all run
all: run
run:$(TARGET)
./$(TARGET)
$(TARGET): $(OBJS) $(TARGET): $(OBJS)
$(CC) $(CFLAGS) -o $@ $(OBJS) $(CC) $(CFLAGS) -o $@ $(OBJS)

View File

@ -1,4 +1,5 @@
#include <assert.h> #include <assert.h>
#include <ctype.h>
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
@ -62,7 +63,7 @@ buf_test(void)
printf("OK\n"); printf("OK\n");
} }
typedef enum TokenKind { typedef enum TokenKind {
TOKEN_INT, TOKEN_INT = 128,
TOKEN_NAME, TOKEN_NAME,
// ... // ...
} TokenKind; } TokenKind;
@ -72,6 +73,8 @@ typedef struct Token {
// ... // ...
} Token; } Token;
const char *stream;
Token token; Token token;
void next_token(void) { void next_token(void) {
switch (*stream) { switch (*stream) {
@ -91,14 +94,26 @@ void next_token(void) {
token.kind = TOKEN_INT; token.kind = TOKEN_INT;
break; break;
default: default:
token.kind = *stream; token.kind = *stream++;
break; break;
} }
} }
void lex_test()
{
char source[] = "+()123456+994";
stream = source;
next_token();
while (token.kind) {
printf("TOKEN: %d\n", token.kind);
next_token();
}
}
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
buf_test(); buf_test();
lex_test();
return 0; return 0;
} }

View File

@ -17,4 +17,4 @@ stretch buffers:
+ ex. '1234 (x+y)' translates to '1234' '(' 'x' '+' 'y' ')' + ex. '1234 (x+y)' translates to '1234' '(' 'x' '+' 'y' ')'
+ no semantics yet + no semantics yet
+ simple hand-written approach + simple hand-written approach
+ mark: 1:06:11 + mark: 1:09:11