Mercurial > lbo > hg > ylisp
view gen/y.lex @ 174:0c4e9e76a2f2
all: Make ylisp work in Release mode too
by changing the way asserts are used when there are side-effects.
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Mon, 09 Sep 2019 19:57:39 +0200 |
parents | fe5d01fa28ee |
children |
line wrap: on
line source
%pointer %{ // bison-bridge results in `yllval` not being a global variable but being accepted by yylex(). %} %option reentrant noyywrap bison-bridge %top { #include <gen/y.tab.h> #include <assert.h> #include <stdio.h> #include <string.h> } %{ %} SPACE [[:blank:]]+ COMMENT --.*\n LEFTP "(" RIGHTP ")" NUMBER -?[1-9][0-9]*|0 ATOM [a-z+*/=<>-][a-z0-9=-]* QUOTE ' STRING_LIT \"[^"]*\" %% {SPACE} { } {COMMENT} { } {LEFTP} { return TOK_LEFTP; } {RIGHTP} { return TOK_RIGHTP; } {NUMBER} { yylval->number = atoll(yytext); return TOK_NUMBER_LITERAL; } {ATOM} { yylval->atom = strdup(yytext); return TOK_ATOM; } {QUOTE} { return TOK_QUOTE; } {STRING_LIT} { yylval->string = strndup(yytext+1, strlen(yytext)-2); return TOK_STRING_LITERAL; } %% // Lex input from in. Closes after finishing. // Only used by debug_lexer. int ylex(FILE* in) { yyscan_t scanner; int lex_init_ok = yylex_init(&scanner); assert(0 == lex_init_ok); #ifndef DEBUG FILE* out = fopen("/dev/null", "w"); #else FILE* out = stdout; #endif yyset_in(in, scanner); yyset_out(out, scanner); int tok; YYSTYPE val; while (0 < (tok = yylex(&val, scanner))) printf("token: %d text: %s\n", tok, yyget_text(scanner)); fclose(in); fclose(out); int lex_destroy_ok = yylex_destroy(scanner); assert(0 == lex_destroy_ok); return 0; }