bison

Best way to add generated files to distribution?

若如初见. 提交于 2019-12-12 05:30:58
问题 I have a quite complex (C++) project using autoconf / automake, which includes some "generated" files (foo.yy -> foo.cc). Actual builds are done using a "control script" (Gentoo .ebuild for those familiar with the concept), on various platforms. Now, one of the target platforms does not properly support the foo.yy -> foo.cc step, and has to use the foo.cc file generated on a Linux box. Now I have two ways to go about this: 1) Check in foo.cc into the project repository and somehow patch

Shift/Reduce conflict on C variation grammar

给你一囗甜甜゛ 提交于 2019-12-12 05:25:26
问题 I am writing a parser to a C-like grammar, but I am having a problem with a shift/reduce conflict: Basically, the grammar accept a list of optional global variables declarations followed by the functions. I have the following rules: program: global_list function_list; type_name : TKINT /* int */ | TKFLOAT /* float */ | TKCHAR /* char */ global_list : global_list var_decl ';' | ; var_decl : type_name NAME; function_list : function_list function_def | ; function_def : type_name NAME '(' param

Meaning of “<*>” in lex

只愿长相守 提交于 2019-12-12 05:23:15
问题 I know,we can define some conditions in lex, matching: 1.<DIRECTIVE>{STRING} {printf("Matching the DIRECTIVE state!");} 2.<REFERENCE>{INTEGER} {printf("Matching the REFERNCE state!");} 3.[\n] {printf("Matching the INITIAL state?");} 4.<*>{DOBULE} {printf("Matching all state include INITIAL? Seem not!");} How to use the states in the right way? What is the difference in conditions on line 3 and 4? The whole .l file, cut by me,now it just to realize a reference.When I run it,it can work well

How to remove shift/reduse warning?

霸气de小男生 提交于 2019-12-12 04:45:15
问题 I am trying to make a compiler and I am now trying to make the parser. I get a warning on this state : State 89 62 expr: '(' expr . ')' 66 | expr . '+' expr 67 | expr . '-' expr 68 | expr . '*' expr 69 | expr . '/' expr 70 | expr . '%' expr 74 | expr . '&' expr 75 | expr . '|' expr 77 cond: expr . 78 | '(' expr . ')' 82 | expr . '=' expr 83 | expr . "<>" expr 84 | expr . '<' expr 85 | expr . '>' expr 86 | expr . ">=" expr 87 | expr . "<=" expr "<>" shift, and go to state 91 ">=" shift, and go

Combine similar constructs in recursive rules

爷,独闯天下 提交于 2019-12-12 04:13:46
问题 This is for a parser in Jison but I guess the same applies for Bison. I have a rule that has a definition for an expression. expr : NUMBER -> { type: "number", value: $1 } | "(" expr ")" -> $2 | expr "+" expr -> { type: "+", left: $1, right: $3 } | expr "-" expr -> { type: "-", left: $1, right: $3 } | expr "*" expr -> { type: "*", left: $1, right: $3 } | expr "/" expr -> { type: "/", left: $1, right: $3 } ; I the same grammar I also have a rule for a "filter expression" that also supports

flex&bison shift/reduce conflict

主宰稳场 提交于 2019-12-12 04:12:33
问题 Here are part of my grammar: expr_address : expr_address_category expr_opt { $$ = new ExprAddress($1,*$2);} | axis axis_data { $$ = new ExprAddress($1,*$2);} ; axis_data : expr_opt { $$ = $1;} | sign { if($1 == MINUS) $$ = new IntergerExpr(-1000000000); else if($1 == PLUS) $$ = new IntergerExpr(+1000000000);} ; expr_opt : { $$ = new IntergerExpr(0);} | expr { $$ = $1;} ; expr_address_category : I { $$ = NCAddress_I;} | J { $$ = NCAddress_J;} | K { $$ = NCAddress_K;} ; axis : X { $$ =

Bison reduce/reduce situation

让人想犯罪 __ 提交于 2019-12-12 03:57:58
问题 I have a particular construction that I'm having trouble debugging. I hope this aggressive simplification demonstrates the issue properly: %token VAR IDENTIFIER NUMBER INT %% root: code_statements ; code_statements: code_statement | code_statements code_statement ; code_statement: var_statement | expression_statement ; var_decl: IDENTIFIER ':' type_expression ; var_statement: VAR var_decl ';' ; expression_statement: value_expression ';' ; function_call: '(' ')' | '(' value_expression_list ')'

why does $1 in yacc/bison has a value of 0

[亡魂溺海] 提交于 2019-12-12 03:06:25
问题 I have a following production in a bison spec: op : '+' { printf("%d %d %c\n", $1, '+', '+'); } When I input a + I get the following output: 0 43 + Can someone explain why $1 has a value of 0, shouldn't it be 43? What am I missing? EDIT There is no flex file, but I can provide a bison grammar: %{ #include <stdio.h> #include <ctype.h> #include <string.h> int yylex(); int yyerror(); %} %token NUMBER %% lexp : NUMBER | '(' op lexp-seq ')' ; op : '+' { printf("%d %d %c\n", $1, '+', '+'); } | '-'

BISON : no shift/reduce conflicts

╄→гoц情女王★ 提交于 2019-12-12 01:37:08
问题 I wrote this code to create a pascal parser . When the bison analyse it, it doesn't show any conflict despite it's a left recursive and ambigous grammar. this is the code %{ #include<stdio.h> int yyparse(); int yylex(); int yyerror(char *s); %} %token ID; %token VAR; %token INT; %token FUNC; %token PROC; %token BEGIN; %token END; %token OPAFFECT; %token OPREL; %token OPADD; %token OPMUL; %token PROGRAM; %token NB; %token IF; %token THEN; %token ELSE; %token WHILE; %token DO; %token NOT;

Bison warning: Empty rule for typed nonterminal

你离开我真会死。 提交于 2019-12-12 00:26:04
问题 I'm getting a warning I don't really understand from Bison. warning: empty rule for typed non-terminal, and no action it's for each of my non-terminal characters. The part I don't understand is that If I don't give them a type then I get compilation errors stating that all of the $ns are undefined. Here's the grammar section of my bison file. %union { char *sval; } %token <sval> PLUS TIMES LPAREN RPAREN ID %type <sval> s e t f %% s : e { cout << GetNonConstCharStar(std::string("(e ") + $1 + "