~kameliya/kyuubey

2da764bc0ba797c07cfe891b5e0aa34aea2b06a7 — Yuki Izumi 6 years ago 2f31a68
Start on parser.
6 files changed, 68 insertions(+), 1 deletions(-)

M .gitignore
M Makefile
A lang.l
A lang.y
A parser.c
A parser.h
M .gitignore => .gitignore +1 -0
@@ 1,2 1,3 @@
kyuubey
out
lang.output

M Makefile => Makefile +8 -1
@@ 6,7 6,7 @@ LDFLAGS = $(shell $(SDL2_CONFIG) --libs) -lSDL2main

SDL2_CONFIG = /usr/local/bin/sdl2-config
SRCS = $(wildcard *.c)
OBJS = $(SRCS:%.c=$(BUILD_DIR)/%.o)
OBJS = $(SRCS:%.c=$(BUILD_DIR)/%.o) $(BUILD_DIR)/lang.tab.o $(BUILD_DIR)/lang.yy.o
DEPS = $(OBJS:$(BUILD_DIR)/%.o=$(BUILD_DIR)/%.d)

all: $(BIN)


@@ 19,5 19,12 @@ $(BIN): $(OBJS)
$(BUILD_DIR)/%.o: %.c
	$(CC) -c $(CFLAGS) -MMD $< -o $@

$(BUILD_DIR)/lang.tab.c: lang.y
	bison -v --report=state -d $<
	mv lang.tab.? $(BUILD_DIR)/

$(BUILD_DIR)/lang.yy.c: lang.l
	flex -t $< > $@

clean:
	-rm $(OBJS) $(DEPS) $(BIN)

A lang.l => lang.l +20 -0
@@ 0,0 1,20 @@
%{
    #include "lang.tab.h"
%}

%option yywrap stack

%x abc_x
%s abc_s

%{
    /* ... */
%}

%%

a       { return A; }

%%

/* vim: set sw=4 et: */

A lang.y => lang.y +13 -0
@@ 0,0 1,13 @@
%{
    /* ... */
%}

%error-verbose

%token A

%%

input:  ;

/* vim: set sw=4 et: */

A parser.c => parser.c +13 -0
@@ 0,0 1,13 @@
#include <stdio.h>

#include "parser.h"

int yywrap(void) {
    return 1;
}

void yyerror(ast_t *ast, char const *s) {
    fprintf(stderr, "boop: %s\n", s);
}

/* vim: set sw=4 et: */

A parser.h => parser.h +13 -0
@@ 0,0 1,13 @@
#ifndef PARSER_H
#define PARSER_H

typedef struct {

} ast_t;

int yywrap(void);
void yyerror(ast_t *ast, char const *s);

#endif

/* vim: set sw=4 et: */