In article <2371@kiwi.mpr.ca>, andrea@mprgate.mpr.ca (Jennitta Andrea) writes:
|>
|> I have a parser which is intended to be called repeatedly from a driver
|> program. ...
|>
|> I have typed the value stack to contain pointers to characters. I
|> malloc the memory required for each token in lex (assigning yylval to
|> point to that block of memory) before returning the token to yacc. It
|> appears that this memory is not cleaned up when yacc frees the value stack.
|>
|> Am I required to explicitly free each token once the parser has reduced
|> a rule? ...

3 ways around this:

1) modify yyparse, the file that is included with the yacc-generated
tables to form the parser, to free the tokens when popping the stack.

2) don't use the yacc value stack, make your own, and free the tokens
when popping it.

3) merge the lexer into the parser and use alloca () to allocate the
memory. instead of having lex recognize "xyz", allocate the string
"xyz", and return the token XYZ, include the yacc rule: