bison

Bison - recover from If Else error

大兔子大兔子 提交于 2019-12-25 02:56:10
问题 I'm trying to recover from an error in an If-Else statement. In my grammar an If is always followed by an Else. statement: OBRACES statements CBRACES | IF OPAR exp CPAR statement ELSE statement | IF OPAR exp CPAR statement error '\n' { yyerrok; yyclearin;} ; The error found is in the commented else in the last lines: public boolean Equal(Element other){ if (!this.Compare(aux01,Age)) ret_val = false ; //else //nt = 0 ; } error: syntax error, unexpected CBRACES, expecting ELSE -> } @ line 29 It

Trouble with printf in Bison Rule

主宰稳场 提交于 2019-12-25 00:36:10
问题 I have tried something like this in my Bison file... ReturnS: RETURN expression {printf(";")} ...but the semicolon gets printed AFTER the next token, past this rule, instead of right after the expression. This rule was made as we're required to convert the input file to a c-like form and the original language doesn't require a semicolon after the expression in the return statement, but C does, so I thought I'd add it manually to the output with printf. That doesn't seem to work, as the

Bison: distinguish variables by type / YYERROR in GLR-parsers

可紊 提交于 2019-12-24 21:17:46
问题 I'm working on a parser, using GNU bison, and I'm facing an interesting problem. My actual problem is a bit different and less interesting in general, so I will state it a bit differently, so that an answer would be more useful in general. I need to distinguish expressions depending on their type, like arithmetic expressions from string expressions. Their top-level nonterminals have some common ancestors, like statement : TOK_PRINT expression TOK_SEMICOLON {...} ; expression :

How to manage semantic rule of declaration of variable in bison

廉价感情. 提交于 2019-12-24 19:02:07
问题 I have to build a compiler that translates the java language into pyhton. I'm using the Flex and Bison tools. I created the flex file and I defined the syntactic grammar in Bison for some restrictions that I have to implement (such as array, management of cycles, management of a class, management of logical-arithmetic operators, etc.). I'm having trouble understanding how to handle semantic rules. For example, I should handle the semantics for import statement and variable declaration, add

getdate.y grammar doubts

落爺英雄遲暮 提交于 2019-12-24 11:37:00
问题 http://www.freebsd.org/cgi/cvsweb.cgi/~checkout~/src/usr.bin/tar/Attic/getdate.y?rev=1.9.12.1;content-type=text%2Fplain;hideattic=0 I am trying to understand how yyTimezone is calculated in code below: | bare_time '+' tUNUMBER { /* "7:14+0700" */ yyDSTmode = DSToff; yyTimezone = - ($3 % 100 + ($3 / 100) * 60); } | bare_time '-' tUNUMBER { /* "19:14:12-0530" */ yyDSTmode = DSToff; yyTimezone = + ($3 % 100 + ($3 / 100) * 60); } How I understand is, lets say the timestamp is 2011-01-02T10:15:20

Shift/Reduce conflict in Bison, when trying to add optional rule

落花浮王杯 提交于 2019-12-24 11:10:25
问题 I am trying to solve shift/reduce conflict in Bison. I have following grammar rules new_expr: T_NEW class_name_reference optional_generics_list ctor_arguments { $$ = zend_ast_create(ZEND_AST_NEW, $2, $4, $3); } | T_NEW anonymous_class { $$ = $2; } optional_generics_list: /* empty */ { $$ = NULL; } | generics_list { $$ = $1; } ctor_arguments: /* empty */ { $$ = zend_ast_create_list(0, ZEND_AST_ARG_LIST); } | argument_list { $$ = $1; } The problem here lies in that fact, that both optional

Bison grammar warnings

风流意气都作罢 提交于 2019-12-24 10:49:03
问题 I am writing a parser with Bison and I am getting the following warnings. fol.y:42 parser name defined to default :"parse" fol.y:61: warning: type clash ('' 'pred') on default action I have been using Google to search for a way to get rid of them, but have pretty much come up empty handed on what they mean (much less how to fix them) since every post I found with them has a compilation error and the warnings them selves aren't addressed. Could someone tell me what they mean and how to fix

Coding PHP Code browser: is Bison/Flex a choice?

醉酒当歌 提交于 2019-12-24 09:38:57
问题 I am planning to make Source code browser. Previously I wanted to use ctags but unfortunately, I found ctags is very limited as it cannot tell which class the method belongs to. I decided to check with another alternative. Reading the internet I have found many talking of using Bison/Flex. I have never used bison/flex so before I jumped in I wanted to know if it Bison/Flex is a right choice for my task. Thanks 回答1: Knowing that flex and bison(or lex and yacc) are parsing solution.you can use

Parsing a While Loop in Bison

こ雲淡風輕ζ 提交于 2019-12-24 08:42:33
问题 What is the best way to implement a simple while loop in Bison? If it makes a difference, I am using C, but I can use C++ as well. 回答1: What you're asking doesn't really fit into a Stack Overflow answer. It's pretty detailed, and many books have been written about it. The basic answer is that you don't implement while loops in Bison. Bison is not a language in that sense. Bison builds a parser from a grammar and actions that are associate with rules in that grammar. A parser is a pushdown

Parsing a While Loop in Bison

跟風遠走 提交于 2019-12-24 08:40:02
问题 What is the best way to implement a simple while loop in Bison? If it makes a difference, I am using C, but I can use C++ as well. 回答1: What you're asking doesn't really fit into a Stack Overflow answer. It's pretty detailed, and many books have been written about it. The basic answer is that you don't implement while loops in Bison. Bison is not a language in that sense. Bison builds a parser from a grammar and actions that are associate with rules in that grammar. A parser is a pushdown