bison

Bison does not appear to recognize C string literals appropriately

杀马特。学长 韩版系。学妹 提交于 2019-12-23 02:46:09
问题 My problem is that I am trying to run a problem that I coded using a flex-bison scanner-parser. What my program is supposed to do is take user input (in my case, queries for a database system I'm designing), lex and parse, and then execute the corresponding actions. What actually happens is that my parser code is not correctly interpreting the string literals that I feed it. Here's my code: 130 insertexpr : "INSERT" expr '(' expr ')' 131 132 { 133 $$ = new QLInsert( $2, $4 ); 134 } 135 ; And

Cyclic Dependency in reentrant flex / bison headers with union YYSTYPE

戏子无情 提交于 2019-12-23 02:34:38
问题 I have a problem where I believe there is a cyclic dependency between the headers generated by flex and bison . The type yyscan_t is defined in the lex header and needed in the yacc header. The macro YYSTYPE is defined in the yacc header and needed in the lex header. No matter which order I import the two headers, the other will not be happy. reentrant.lex: %{ #include "reentrant.yacc.h" %} %option reentrant bison-bridge %% [0-9]+ { yylval->int_value = atoi(yytext); return INT_TERM; } [a-zA-Z

Why are these conflicts appearing in the following yacc grammar for XML

隐身守侯 提交于 2019-12-22 13:07:51
问题 I have the following XML grammar which works fine: program : '<' '?'ID attribute_list '?''>' root ; root : '<' ID attribute_list '>' node_list '<''/'ID'>' ; node_list : node_s | node_list node_s ; node_s : node | u_node | ID ; node : '<' ID attribute_list '/''>' ; u_node :'<' ID attribute_list '>' node_list '<''/'ID'>' |'<' ID attribute_list '>' '<''/'ID'>' ; attribute_list : attributes | ; attributes : attribute | attributes attribute ; attribute : ID ASSIGNOP '"' ID '"' | ID ASSIGNOP '"'

Why are these conflicts appearing in the following yacc grammar for XML

江枫思渺然 提交于 2019-12-22 13:07:14
问题 I have the following XML grammar which works fine: program : '<' '?'ID attribute_list '?''>' root ; root : '<' ID attribute_list '>' node_list '<''/'ID'>' ; node_list : node_s | node_list node_s ; node_s : node | u_node | ID ; node : '<' ID attribute_list '/''>' ; u_node :'<' ID attribute_list '>' node_list '<''/'ID'>' |'<' ID attribute_list '>' '<''/'ID'>' ; attribute_list : attributes | ; attributes : attribute | attributes attribute ; attribute : ID ASSIGNOP '"' ID '"' | ID ASSIGNOP '"'

Tool to parse by grammar to AST (or .y+.lang => xml)

こ雲淡風輕ζ 提交于 2019-12-22 12:57:32
问题 Given a lexer definition file, a grammar file (say, postgresql .y , .l flex and bison programs from it's source tree), and a file defined by those lexer and parser (say, an SQL query) to get the AST in some standard form (say, JSON of XML). The most important aspect of this tool is - flexibility of the input format. In my example, I could recreate postgres SQL grammar in ANTLR - but I don't want to. I'd rather just use whatever postgres is using. So even though .y file contains more than the

Bison conflicting type for yyerror

南楼画角 提交于 2019-12-22 10:21:22
问题 I'm trying to make a calculator from flex and bison, but I found an error during the compile. Here is the error: C:\GnuWin32\src>gcc lex.yy.c y.tab.c -o tugas tugas.y:51: error: conflicting types for 'yyerror' y.tab.c:1433: error: previous implicit declaration of 'yyerror' was here Here is my .l code : %{ #include <stdio.h> #include "y.tab.h" YYSTYPE yylval; %} plus [+] semi [;] minus [-] var [a-z] digit [0-1]+ equal [:=] %% {var} {yylval = *yytext - 'a'; return VAR;} {digit} {yylval = atoi

bison shift instead of reduce. With reduce/reduce errors

拥有回忆 提交于 2019-12-21 22:32:40
问题 In my language i can write a = 1 b = 2 if true { } else { } if true { } **Here is the problem** else {} My grammer doesnt support newlines between statements. An else can only be used with an if. When i add optionalNL in my rule IfExpr: IF rval optionalNL codeBlock optionalNL ELSE codeBlock | IF rval optionalNL codeBlock The optionalNL before the else causes 3 reduce/reduce. Reason is it can reduce using the 2nd rule in IfExpr or reduce to exprLoop where it allows many newlines between

Flex/Bison Error:request for member `str' in something not a structure or union

杀马特。学长 韩版系。学妹 提交于 2019-12-21 21:34:34
问题 I'm learning flex/bison. I wrote the following program but getting errors. %{ #include <stdio.h> typedef struct node { struct node *left; struct node *right; char *token; }node; node *mknode( node *left, node *right, char *token); void printtree(node *tree); #define YYSTYPE struct node * %} %union { char* str; int num; } %start lines %token <str> WORD %token <str> PLUS MINUS TIMES DIVIDE POWER %token <str> LEFT_PARENTHESIS RIGHT_PARENTHESIS %token <str> END %left PLUS MINUS %left TIMES DIVIDE

How to pass the yytext from the lex file to yacc?

一个人想着一个人 提交于 2019-12-21 12:59:54
问题 Please i am facing a simple problem.. here is the issue, In my lex file i have something similiar to: char *ptr_String; "name = " { BEGIN sName; } <sName>.+ { ptr_String = (char *)calloc(strlen(yytext)+1, sizeof(char)); strcpy(ptr_String, yytext); yylval.sValue = ptr_String; return NAME; } Now in my Yacc file i have something similar to: stmt_Name: NAME { /*Now here i need to get the matched string of <sName>.+ and measure it's length. */ /*The aim is simply outputing the name to the screen

How to pass the yytext from the lex file to yacc?

半世苍凉 提交于 2019-12-21 12:59:30
问题 Please i am facing a simple problem.. here is the issue, In my lex file i have something similiar to: char *ptr_String; "name = " { BEGIN sName; } <sName>.+ { ptr_String = (char *)calloc(strlen(yytext)+1, sizeof(char)); strcpy(ptr_String, yytext); yylval.sValue = ptr_String; return NAME; } Now in my Yacc file i have something similar to: stmt_Name: NAME { /*Now here i need to get the matched string of <sName>.+ and measure it's length. */ /*The aim is simply outputing the name to the screen