bitwise: another three minutes of video on the bus.
This commit is contained in:
parent
e779c77d32
commit
c242894f94
|
@ -0,0 +1,4 @@
|
|||
bitwise
|
||||
=======
|
||||
|
||||
Following along with [bitwise](https://github.com/pervognsen/bitwise).
|
|
@ -2,7 +2,11 @@ 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)
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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
|
Loading…
Reference in New Issue