help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: About %destructor is c++ mode


From: Min Wang
Subject: Re: About %destructor is c++ mode
Date: Thu, 18 Aug 2016 09:24:56 -0400

HI

@Hans, thanks again.

(1)  for the error recovery,  should I always include "error" in each rule?

e.g:
PROG : ListExp
           | error     {  yyerrok; }

ListExp:   Exp
             | error   {  yyerrok; }


what if I do not have error in these rules, does the parser() just return
failed? it seems it will call that %destructor as well.

MyTest.sample3 is:

a==

the output is: ./TestFilter -p -s ./MyTest.sample3

Starting parse
Entering state 0
Reading a token: --(end of buffer or a NUL)
--accepting rule at line 101("a")
Next token is token _SYMB_JSON_KEY (1.1: a)
Shifting token _SYMB_JSON_KEY (1.1: a)
Entering state 3
Reading a token: --accepting rule at line 71("==")
Next token is token _SYMB_EQ (1.2-3: )
Reducing stack by rule 21 (line 284):
   $1 = token _SYMB_JSON_KEY (1.1: a)
-> $$ = nterm JSON_FIELD (1.1: 0x1ff01f0)
Stack now 0
Entering state 11
Next token is token _SYMB_EQ (1.2-3: )
Shifting token _SYMB_EQ (1.2-3: )
Entering state 22
Reading a token: --accepting rule at line 123("
")
--accepting rule at line 123("
")
--(end of buffer or a NUL)
--accepting rule at line 123("
")
--(end of buffer or a NUL)
--EOF (start condition 0)
Next token is token "end of file" (4.1: )
4.1: syntax error, unexpected end of file, expecting _STRING_ or _INTEGER_
or _DOUBLE_
Error: popping token _SYMB_EQ (1.2-3: )
Stack now 11 0
Error: popping nterm JSON_FIELD (1.1: 0x1ff01f0)
 **** I am JSON_FIELD 0x1ff01f0 delete done
Stack now 0
Cleanup: discarding lookahead token "end of file" (4.1: )

 Before main ret


I do not have "error" in those rules, but it seems it will call %destructor
in this case as well.



(2) Could you explain more on  "rely on C++ cleanup"?

PROG : ListExp  { $$ = new Json_Filter($1) ; driver.store_ast( $$ );   }
ListExp : Exp                               { $$ = new ListExp();


I have something like new in the rule? how can I clean it if error?

If you could give some examples , that would be great!



thanks


min


On Thu, Aug 18, 2016 at 9:01 AM, Hans Åberg <address@hidden> wrote:

>
> > On 18 Aug 2016, at 14:39, Min Wang <address@hidden> wrote:
>
> > since my process is a deamon, I need to clean up memory leak.
>
> That seems a good idea, then, unless it is restarted every once in awhile.
>
> > What does error recovery really mean? My current grammar rules does not
> include error, so does it mean that I do not have error recovery?
>
> When there is a grammatical error in the input text, the runtime parser
> will skip forward to the next error recovery point indicated in the
> grammar. During error recovery, it unwinds the parser stack, but skips over
> the grammar actions. To cover up for that, %destructor was added.
>
> > My confusion is:  it seems the %destructor is called even for the normal
> parse!!
>
> It should not. But I rely on C++ cleanup, so somebody else will have to
> tune in here.
>
>
>


-- 
http://www.comrite.com


reply via email to

[Prev in Thread] Current Thread [Next in Thread]