diff --git a/Makefile b/Makefile index a6baef6..5d41656 100644 --- a/Makefile +++ b/Makefile @@ -11,16 +11,16 @@ webdice.js: js-api.c expression.o lex.yy.o parser.tab.o $(CC) $^ $(CFLAGS) -o $@ $(LFLAGS) lex.yy.c lex.yy.h: lexer.l parser.tab.h expression.h - flex --header-file=lex.yy.h $< + flex --debug --header-file=lex.yy.h $< parser.tab.c parser.tab.h: parser.y expression.h - bison -d $< + bison --debug -d $< %.o: %.c $(CC) $(CFLAGS) -c $< native-test: native-test.c lex.yy.c parser.tab.c expression.c - gcc -std=gnu99 -Wall -pedantic $^ -o $@ $(LFLAGS) + gcc -m32 -std=gnu99 -Wall -pedantic $^ -o $@ $(LFLAGS) -g .PHONY: clean clean: diff --git a/js-api.c b/js-api.c index 5d68901..a1978c4 100644 --- a/js-api.c +++ b/js-api.c @@ -20,21 +20,24 @@ int yyerror(void* scanner, void* lvalp, char* str){ } void EMSCRIPTEN_KEEPALIVE webdice(char* str){ - union expression* root; + union expression* root = NULL; struct expression_result result; int length; + char* in_block; char* out_block; - console_print("A"); + yydebug = 1; + + in_block = (char*) malloc((2 + strlen(str)) * sizeof(char)); + sprintf(in_block,"%s\n",str); + yyscan_t scanner; - console_print("B"); yylex_init(&scanner); - console_print("C"); - yy_scan_string (str, scanner); - console_print("D"); + yy_scan_string (in_block, scanner); - if(yyparse((void*) scanner, &root) == 0){ + yyparse((void*) scanner, &root); + if(root != NULL){ result = resolve(root); length = strlen(result.text) + 4 * ceill(log10l(result.max)) + 100; out_block = (char*) malloc(length * sizeof(char)); @@ -46,5 +49,6 @@ void EMSCRIPTEN_KEEPALIVE webdice(char* str){ }else{ output_print("
Error!
"); } + free(in_block); yylex_destroy(scanner); } diff --git a/lexer.l b/lexer.l index db80f53..0a91ed1 100644 --- a/lexer.l +++ b/lexer.l @@ -3,7 +3,6 @@ #include