diff options
author | John Hodge <tpg@mutabah.net> | 2015-04-15 16:35:54 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2015-04-15 16:35:54 +0800 |
commit | 1b62d9688a1be2da2825c59e73f3220b0dc352fa (patch) | |
tree | cf4e50b2638968e273320c01f4ff735a88ffd03d /bnf | |
parent | 691d304e45b8e629cf2b086613accf048b7f8c48 (diff) | |
download | mrust-1b62d9688a1be2da2825c59e73f3220b0dc352fa.tar.gz |
BNF - Hacked around >> to > translation
Diffstat (limited to 'bnf')
-rw-r--r-- | bnf/rust.lex | 11 | ||||
-rw-r--r-- | bnf/rust.y | 13 |
2 files changed, 20 insertions, 4 deletions
diff --git a/bnf/rust.lex b/bnf/rust.lex index dd8406de..b79119cd 100644 --- a/bnf/rust.lex +++ b/bnf/rust.lex @@ -3,6 +3,11 @@ #include <stdio.h> void yyerror(const char *s); extern int yydebug; + +#define YY_DECL int yylex(int force_ret) + +#define YY_USER_ACTION if(force_ret>0) return force_ret; + %} dec_digit [0-9_] @@ -73,8 +78,8 @@ ident_c [a-zA-Z_] {ident_c}({ident_c}|[0-9])* { yylval.text = strdup(yytext); return IDENT; } {ident_c}({ident_c}|[0-9])*"!" { yylval.text = strdup(yytext); return MACRO; } [0-9]{dec_digit}*"."{dec_digit}+ { yylval.realnum = strtod(yytext, NULL); return FLOAT; } -[0-9]{dec_digit}* { yylval.integer = strtoull(yytext, 0, NULL); return INTEGER; } -0x[0-9a-fA-F]* { yylval.integer = strtoull(yytext, 0, NULL); return INTEGER; } +[0-9]{dec_digit}* { yylval.integer = strtoull(yytext, NULL, 0); return INTEGER; } +0x[0-9a-fA-F]* { yylval.integer = strtoull(yytext, NULL, 0); return INTEGER; } '(\\.|[^\\'])+' { return CHARLIT; } @@ -82,7 +87,7 @@ ident_c [a-zA-Z_] %% int main() { - //yydebug = 1; + yydebug = (getenv("BNFDEBUG") != NULL); yyparse(); return 0; } @@ -24,6 +24,7 @@ %{ #include <stdio.h> #include <stdarg.h> +#include <assert.h> extern int yylineno; static inline void bnf_trace(const char* fmt, ...) { @@ -40,10 +41,19 @@ static void yyprint(FILE *outstream, int type, YYSTYPE value) switch(type) { case IDENT: fprintf(outstream, "%s", value.text); break; + case MACRO: fprintf(outstream, "%s!", value.text); break; default: break; } } + +int rustbnf_forcetoken = 0; +static inline int read_and_clear(int* ptr) { + int rv = *ptr; + *ptr = 0; + return rv; +} +#define YYLEX_PARAM read_and_clear(&rustbnf_forcetoken) %} %% @@ -244,7 +254,7 @@ type_path_segs type_path_seg : IDENT | IDENT '<' type_exprs '>' -/* | IDENT '<' type_exprs DOUBLEGT { } */ + | IDENT '<' type_exprs DOUBLEGT { bnf_trace("Double-gt terminated type expr"); rustbnf_forcetoken = '>'; } ; type_exprs: type_exprs ',' type | type; @@ -385,6 +395,7 @@ expr_value | expr_path '(' expr_list ')' { bnf_trace("function call"); } | expr_path '{' struct_literal_list '}' | expr_path + | RWD_self | '(' expr ')' | MACRO tt_paren { bnf_trace("Expr macro invocation"); } ; |