~kameliya/kyuubey

5c4d45904b5d8f4d3d1796638a403ffe604199ff — Yuki Izumi 6 years ago 1a6fa3f
Steps into parser. Still not really worked anything out.
6 files changed, 48 insertions(+), 34 deletions(-)

M Makefile
M lang.l
M lang.y
M parser.c
M parser.h
M valgrind.suppressions
M Makefile => Makefile +2 -2
@@ 1,7 1,7 @@
BIN = ./kyuubey
BUILD_DIR = out

CFLAGS = $(shell $(SDL2_CONFIG) --cflags) -Wall -g
CFLAGS = -I. -Iout $(shell $(SDL2_CONFIG) --cflags) -Wall -g
LDFLAGS = $(shell $(SDL2_CONFIG) --libs) -lSDL2main

SDL2_CONFIG = /usr/local/bin/sdl2-config


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

parser-test: $(BIN)
	valgrind --suppressions=valgrind.suppressions --dsymutil=yes --leak-check=full $(BIN) parser-test
	valgrind --suppressions=valgrind.suppressions --dsymutil=yes --leak-check=full --gen-suppressions=all $(BIN) parser-test

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

M lang.l => lang.l +2 -1
@@ 13,7 13,8 @@

%%

a       { return A; }
[a-zA-Z]        { return TOKEN; }
\n              { return NL; }

%%


M lang.y => lang.y +18 -3
@@ 1,13 1,28 @@
%{
    /* ... */
    #include "parser.h"
%}

%parse-param {ast_t *ast}
%error-verbose

%token A
%token TOKEN NL
%token END_OF_FILE 0 "$end"

%%

input:  ;
input:          /* empty */
              | input line { if ($2) { ast_append(ast, $2); } }
;

line_separator: NL
              | ':'
;

line:           line_separator          { $$ = 0; }
              | stmt line_separator     { $$ = $1; }
              | stmt END_OF_FILE        { $$ = $1; }
;

stmt: ;

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

M parser.c => parser.c +18 -0
@@ 1,7 1,20 @@
#include <stdio.h>
#include <stdlib.h>

#include "parser.h"

ast_t *ast_alloc(void) {
    ast_t *ast = malloc(sizeof(*ast));
    return ast;
}

void ast_append(ast_t *ast, void *x) {
}

void ast_free(ast_t *ast) {
    free(ast);
}

int yywrap(void) {
    return 1;
}


@@ 11,9 24,14 @@ void yyerror(ast_t *ast, char const *s) {
}

int parser_test(void) {
    ast_t *ast = ast_alloc();

    begin_scan("PRINT \"HELLO\"");
    yyparse(ast);
    finish_scan();

    free(ast);

    return 0;
}


M parser.h => parser.h +6 -0
@@ 5,6 5,12 @@ typedef struct {

} ast_t;

int yylex(void);
int yyparse(ast_t *ast);

ast_t *ast_alloc(void);
void ast_append(ast_t *ast, void *x);

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

M valgrind.suppressions => valgrind.suppressions +2 -28
@@ 2,35 2,9 @@
   <insert_a_suppression_name_here>
   Memcheck:Leak
   match-leak-kinds: possible
   fun:malloc_zone_malloc
   fun:_ZL17buildProtocolListP13category_listPK15protocol_list_tPS3_
   fun:_ZL12realizeClassP10objc_class
   fun:_ZL12realizeClassP10objc_class
   fun:_ZL12realizeClassP10objc_class
   fun:look_up_class
   fun:objc_getFutureClass
   fun:__CFInitialize
   fun:_ZN16ImageLoaderMachO11doImageInitERKN11ImageLoader11LinkContextE
   fun:_ZN16ImageLoaderMachO16doInitializationERKN11ImageLoader11LinkContextE
   fun:_ZN11ImageLoader23recursiveInitializationERKNS_11LinkContextEjRNS_21InitializerTimingListERNS_15UninitedUpwardsE
   fun:_ZN11ImageLoader23recursiveInitializationERKNS_11LinkContextEjRNS_21InitializerTimingListERNS_15UninitedUpwardsE
}
{
   <insert_a_suppression_name_here>
   Memcheck:Leak
   match-leak-kinds: possible
   fun:malloc_zone_malloc
   fun:_ZL17buildProtocolListP13category_listPK15protocol_list_tPS3_
   fun:_ZL12realizeClassP10objc_class
   fun:_ZL12realizeClassP10objc_class
   fun:_ZL12realizeClassP10objc_class
   fun:look_up_class
   fun:objc_getFutureClass
   ...
   fun:__CFInitialize
   fun:_ZN16ImageLoaderMachO11doImageInitERKN11ImageLoader11LinkContextE
   fun:_ZN16ImageLoaderMachO16doInitializationERKN11ImageLoader11LinkContextE
   fun:_ZN11ImageLoader23recursiveInitializationERKNS_11LinkContextEjRNS_21InitializerTimingListERNS_15UninitedUpwardsE
   fun:_ZN11ImageLoader23recursiveInitializationERKNS_11LinkContextEjRNS_21InitializerTimingListERNS_15UninitedUpwardsE
   ...
}
{
   <insert_a_suppression_name_here>