Selective Compilation

2011-02-07 Thread Martin Alexander Neumann
Hi, some time ago I designed a flex + bison system for an embedded system for which I needed selective compilation -- different systems needed different language subsets of my flex and bison files. I threw together a solution using the C preprocessor to selective compile in only the relevant stuff

Re: Force bison syntax error on string constant

2014-10-24 Thread Martin Alexander Neumann
Hi Bob, use the macro YYERROR; It's documented here: https://www.gnu.org/software/bison/manual/html_node/GLR-Semantic-Actions.html#YYERROR Yours, Alex On 10/24/2014 03:10 PM, Bob Rossi wrote: > Hi, > > I have a rule like this, > > output: output_variant NEWLINE { > *gdbmi_output = $1; >

Re: Memory leak with reentrant parser

2015-06-19 Thread Martin Alexander Neumann
Hi John, I guess your "strdup" eats the memory. You need to manage this dynamic memory somewhere in the parser/your program. Maybe interesting for you: in case of automated parser recovery, bison offers %destructor[1] to handle memory of automatically discarded symbols. [1] http://www.gnu.org/so

Re: Bison yyparse return array of values

2017-04-02 Thread Martin Alexander Neumann
Hi Laura, I would start with a global linked list that is filled in the semantic actions. Building on your example: %{ #include #include typedef struct elem { char *val; struct elem *next; } elem_t; elem_t *words = NULL; void add_word(

Re: Bison yyparse return array of values

2017-04-02 Thread Martin Alexander Neumann
Hi Laura, if you want multiple different parsers (i.e. different .y files) in one binary, use renaming. See the "%name-prefix"-Option. In this case, I guess you could stick with globals to store the parsing result. If you want to use multiple instances of the same parser simultaneously, turn the

Re: Bison yyparse return array of values

2017-04-02 Thread Martin Alexander Neumann
Hi Laura, yes, sounds perfect. Yours, Alex On 04/02/2017 05:02 PM, Laura Morales wrote: > - if I want multiple parsers, I *must* use prefix change > - the purpose of a pure/reentrant parser is to encapsulate globals such that > I can call the same parser multiple times and avoid conflicts or ra

Re: Bison yyparse return array of values

2017-04-03 Thread Martin Alexander Neumann
Hi Laura, the GNU Flex option "%option reentrant" turns the generated scanner into a reentrant one. This adds the function parameter "yyscan_t yyscanner" to yylex() to keep the scanner state. The program calling yylex() has to allocate and prepare a variable of type "yyscan_t" and hand it to yylex

Re: bison 3.0.4 causes conflicting types for ...

2018-03-09 Thread Martin Alexander Neumann
Hi Owen, it's not an explanation to the problem, but the following patch to plural.y seems to get it going: --- diff -Naur plural.y plural.y.fix --- plural.y +++ plural.y.fix @@ -43,6 +43,7 @@ #define YYLEX_PARAM&((struct parse_args

Re: tokens without input match

2018-04-27 Thread Martin Alexander Neumann
Hi Anand, Bison expects its input to come from a lexer, i.e. all inputs are valid tokens of the language Bison parses. If a token cannot be "matched", the input is invalid. If you want to be able to skip any input that is not a valid token, you have to skip it in the lexer. Yours Alex On 27.04.

Re: bison 2.7 to bison 3.0.4 update assistance

2018-08-13 Thread Martin Alexander Neumann
Hi David, have a look at the %parse-param directive: https://www.gnu.org/software/bison/manual/bison.html#C_002b_002b-Parser-Interface Yours, Alex On 13.08.2018 22:30, David Barto wrote: > I’m not a bison/yacc/flex expert. I probably don’t even qualify as a novice. > > We have some very (very v

Re: YYMAXDEPTH and stack usage

2018-09-07 Thread Martin Alexander Neumann
Hi Anand, right, please also have a look at the manual on YYMAXDEPTH[1]. And "you should always use left recursion, because it can parse a sequence of any number of elements with bounded stack space."[2] (Sure, when implementing "calculators", using right recursion may make your life easier with

Re: Push parsing from lexer?

2019-08-14 Thread Martin Alexander Neumann
t&c=Global_Internal_YGrowth_AndroidEmailSig__AndroidUsers&af_wl=ym&af_sub1=Internal&af_sub2=Global_YGrowth&af_sub3=EmailSignature> > > On Wed, 14 Aug 2019 at 16:02, Martin Alexander Neumann > wrote: > Hi Mark, > > please have a

Re: Push parsing from lexer?

2019-08-14 Thread Martin Alexander Neumann
=Internal&af_sub2=Global_YGrowth&af_sub3=EmailSignature> > > On Wed, 14 Aug 2019 at 16:44, Martin Alexander Neumann > wrote: > Hi Mark, > > ah, yypush_parse does not take a pointer to yylex as second parameter, > the second parameter is the

Re: Cannot print correct values in Bison code

2020-05-30 Thread Martin Alexander Neumann
Good morning Christian, during reductions Bison does "hand over" a single semantic value only from the right side of your productions to the left side of the productions. By default it is the first, i.e. "$$ = $1" in Bison terms. I suppose your productions of array_vals look like the following: