bitwise: finish day 2
This commit is contained in:
parent
2404595738
commit
71dff5d299
|
@ -1,6 +1,6 @@
|
||||||
TARGET := ion
|
TARGET := ion
|
||||||
OBJS := $(TARGET).o
|
OBJS := $(TARGET).o
|
||||||
CFLAGS := -g -std=c99 -Wall -Werror
|
CFLAGS ?= -g -std=c99 -Wall -Werror
|
||||||
|
|
||||||
.PHONY: all run
|
.PHONY: all run
|
||||||
all: run
|
all: run
|
||||||
|
@ -15,3 +15,7 @@ $(TARGET): $(OBJS)
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
rm -f $(OBJS) $(TARGET)
|
rm -f $(OBJS) $(TARGET)
|
||||||
|
|
||||||
|
.PHONY: release
|
||||||
|
release: clean
|
||||||
|
CFLAGS="$(CFLAGS) -DRELEASE" make $(TARGET) && mv $(TARGET) $(TARGET)-release
|
|
@ -7,10 +7,10 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef RELEASE
|
||||||
#define tprint(...) do { fprintf( stderr, __VA_ARGS__ ); } while( false )
|
#define tprint(...) do { fprintf(stderr, __VA_ARGS__); } while (0)
|
||||||
#else
|
#else
|
||||||
#define tprint(x) {}
|
#define tprint(...) do {} while (0)
|
||||||
#endif
|
#endif
|
||||||
#define MAX(a, b) ((a) < (b) ? (b) : (a))
|
#define MAX(a, b) ((a) < (b) ? (b) : (a))
|
||||||
|
|
||||||
|
@ -188,34 +188,30 @@ void next_token(void) {
|
||||||
void
|
void
|
||||||
print_token(void)
|
print_token(void)
|
||||||
{
|
{
|
||||||
tprint("TOKEN: %d", token.kind);
|
tprint("TOKEN: ");
|
||||||
switch (token.kind) {
|
switch (token.kind) {
|
||||||
case TOKEN_INT:
|
case TOKEN_INT:
|
||||||
tprint(" VALUE: %lu", token.val);
|
tprint("INT VALUE: %lu", token.val);
|
||||||
break;
|
break;
|
||||||
case TOKEN_NAME:
|
case TOKEN_NAME:
|
||||||
break;
|
tprint("NAME VALUE: %.*s", (int)(token.end-token.start), token.start);
|
||||||
default:
|
break;
|
||||||
break;
|
default:
|
||||||
}
|
tprint("'%c'", token.kind);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
tprint("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
lex_test(void)
|
lex_test(void)
|
||||||
{
|
{
|
||||||
char source[] = "+()123456+994";
|
char source[] = "+()123456+IDDQD,994_id3kfa";
|
||||||
tprint("lex_test\n");
|
tprint("lex_test\n");
|
||||||
stream = source;
|
stream = source;
|
||||||
next_token();
|
next_token();
|
||||||
while (token.kind) {
|
while (token.kind) {
|
||||||
tprint("TOKEN: %d\n", token.kind);
|
print_token();
|
||||||
switch (token.kind) {
|
|
||||||
case TOKEN_INT:
|
|
||||||
tprint("\tvalue: %lu\n", (long unsigned)token.val);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
next_token();
|
next_token();
|
||||||
}
|
}
|
||||||
tprint("OK\n");
|
tprint("OK\n");
|
||||||
|
|
Loading…
Reference in New Issue