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,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)
rm -f $(OBJS) $(TARGET)

View File

@ -1,4 +1,5 @@
#include <assert.h>
#include <ctype.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
@ -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;
}

View File

@ -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
+ mark: 1:09:11