[fpc-devel] Patch to add Bison-like %destructor directive to pyacc (TPLY)
Bram Kuijvenhoven
kuifwaremailinglists at xs4all.nl
Fri Dec 7 20:58:05 CET 2007
Hi FPC!
The attached patch implements the %destructor directive from Bison in tply/pyacc.
Since TPLY [Turbo Pascal Lex/Yacc] is in the FPC SVN repository I suppose I should send the patch to FPC. It should be noted that the code no longer compiles with TP since it uses ansistring, Classes.TStream and SysUtils.Format. Usage of all of these could be circumvented, but at the cost of additional effort. I assume TP incompatibility is not such an issue with FPC being out there :)
Please let me know if the patch is ok.
I might send a patch for the documentation in tply.tex later (if the patch is accepted).
Patch details:
The %destructor directive allows one to specify clean-up code for symbols (terminals/non-terminals) that are discarded during error recovery or whenever the yyparse routine exits. Quick example:
%token <TTerminal> TERMINAL
%type <TNonTerminal> nonterminal
%destructor { FreeAndNil($$); } TERMINAL nonterminal
See also http://www.gnu.org/software/bison/manual/html_mono/bison.html#Destructor-Decl.
Changes:
- pyacc.y: support parsing the %destructor directive
- yaccsem.pas, yacctabl.pas, yaccmsgs.pas: support processing of the %destructor directive
- yaccpars.pas: added writing of yyls table, which maps states to last-read symbol numbers
- yyparse.cod: added local yydestruct procedure and inserted appropriate calls to it
The patch should be backward compatible; e.g. it can still use older code templates (yyparse.cod), but the generated code will not include the %destructors; however, the old pyacc cannot use the new code template (keep this in mind when you try to 'bootstrap' the newer pyacc).
Regards,
Bram
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pyacc_destructor_patch.zip
Type: application/octet-stream
Size: 14885 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20071207/d1351f3d/attachment.obj>
More information about the fpc-devel
mailing list