bison

Windows cannot find win_bison.exe

北战南征 提交于 2019-12-11 10:13:38
问题 I'm trying to get to work with flex and bison in Visual Studio 2013, but I have a problem. I've downloaded win_flex_bison from here, followed this tutorial and added "C:\GnuWin32\win_flex_bison;" to environmental variables, but when I'm trying to build the project I'm getting error that Windows cannot find win_bison.exe "Error 1 error MSB3721: The command "start /B /WAIT /D "D:\\...\" win_bison.exe --output="sample.tab.cpp" --defines="sample.tab.h" "sample.y" " exited with code 1. C:\GnuWin32

can't access the token table yytname in bison 2.6 or is it gone?

倾然丶 夕夏残阳落幕 提交于 2019-12-11 09:56:55
问题 I'm building a parser for an asset xchange format. And I'm including the %token-table directive in the bison file but, from the flex code I just can't access the table or the constants associated with it. That is when trying to compile this code: Frame|FrameTransformMatrix|Mesh|MeshNormals|MeshMaterialList|Material { printf("A keyword: %s\n", yytext); yylval.charptr_type = yytext; int i; for (i = 0; i < YYNTOKENS; i++) { if (yytname[i] != 0 && yytname[i][0] == '"' && !strncmp(yytname[i] + 1,

in Bison, how can I specity left associativity for a non-terminal?

人走茶凉 提交于 2019-12-11 09:28:36
问题 I have the following Bison grammar snippet: binary_op: BINARY_OP { ... } | '|' %prec BINARY_OP { ... } ; non_keyword_expr: non_keyword_expr binary_op non_keyword_expr %prec BINARY_SEND_PREC %dprec 2 { ... } ; | has overloaded meaning in my grammar, so I can't just return it as token BINARY_OP from my lexer. It could be a different token depending on context. If I use this as my input: 4 OR 5 OR 6 I can parse it successfully (OR is recognized as a BINARY_OP token by the lexer). If, however, my

Cant find Reduce/Reduce conflict in Grammar

最后都变了- 提交于 2019-12-11 09:12:21
问题 I wrote the following grammar and Bison is warning me about a reduce/reduce conflict. parser.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr] How can I detect which part of the grammar is generating the conflict? Is there a log generated by Bison where I can see the conflicts? And also, how could I solve this? Grammar: %left TK_OC_OR TK_OC_AND %left '<' '>' TK_OC_LE TK_OC_GE TK_OC_EQ TK_OC_NE %left '+' '-' %left '*' '/' %nonassoc LOWER_THAN_ELSE %nonassoc TK_PR_ELSE %start s %type<symbol

unresolved external symbol for yyparse()

五迷三道 提交于 2019-12-11 08:25:45
问题 My main.cpp looks like this: #include <assert.h> #include <fstream> #include <iostream> #include "astgen.h" #include "astexec.h" extern int yyparse(); extern FILE *yyin; int main() { //yydebug = 0; struct AstElement *a = 0; FILE *fp ; fopen_s(&fp,"example.txt","r"); //std::cout<<fp; if (fp==NULL) { std::cout<<"error"; } yyin=fp; yyparse(); assert(a); struct ExecEnviron* e = createEnv(); execAst(e, a); freeEnv(e); /* TODO: destroy the AST */ } When I try to compile this, I get the error: main

How to translate token names in bison

只愿长相守 提交于 2019-12-11 07:54:13
问题 I have a bison parser that works sufficiently well for my purpose. It even prints localized error messages. But the token names are not translated. Looking at the source code I found, that I can use define YY_ to my own gettext function and pass YY_ to gettext in order to provide my own translation of the error messages. But this does not work for token names. Is there some switch or hidden feature that I could use to extract the token names from the parser and to translate them? So far I

Beginner bison flex

一曲冷凌霜 提交于 2019-12-11 07:39:37
问题 How can I print the line number on which an error occurred. I tried using yylineno in the yyerror() function and writing %option yylineno in the .l file but after compiling it gives me an error " yylineno undeclared (first use in this function) " and if I initialize yylineno as 1 it gives me this error: error: redefinition of yylineno lex.yy.c:273: note: previous definition of yylineno was here 回答1: There is a second way to ask flex to provide the global variable yylineno: the command line

yacc/bison tokens error. '>>>' and '>>' both assigned number 62

不打扰是莪最后的温柔 提交于 2019-12-11 07:30:07
问题 I do something like this in my code CmpExpr: rval '<<' rval { $$ = $1 << $3; } | rval '>>' rval { $$ = $1 >> $3; } | rval '>>>' rval { $$ = (unsigned)($1) >> ($3); } ; the warning i get is tokens '>>>' and '>>' both assigned number 62 How do i make it use different tokens? 回答1: %TOKEN LSHIFT RSHIFT RRSHIFT in lex write "<<" { return LSHIFT; } ">>" { return RSHIFT; } ">>>" { return RRSHIFT; } then you can write CmpExpr: rval LSHIFT rval { $$ = $1 << $3; } | rval RSHIFT rval { $$ = $1 >> $3; }

Scanner and parser interaction

爱⌒轻易说出口 提交于 2019-12-11 05:20:00
问题 I am new to flex/bison. Reading books, it seems that in nearly all compiler implementations, the parser interacts with the scanner in a "coroutine" manner, that whenever the parser needs a token, it calls the scanner to get one, and left the scanner aside when it's busy on shift/reduce. A natural question is that why not let the scanner produces the token-stream (from the input byte-stream) as a whole, and then pass the entire token-stream to the parser, thus there is no explicit interaction

Minimal bison/flex-generated code has memory leak

久未见 提交于 2019-12-11 04:22:28
问题 In debugging a memory leak on a large project, I found that the source of the leak seemed to be some flex/bison-generated code. I was able to recreate the leak with the following minimal example consisting of two files, sand.l and sand.y : in sand.l : %{ #include <stdlib.h> #include "sand.tab.h" %} %% [0-9]+ { return INT; } . ; %% in sand.y : %{ #include <stdio.h> #include <stdlib.h> int yylex(); int yyparse(); FILE* yyin; void yyerror(const char* s); %} %token INT %% program: program INT {