Delphi Lex & Yacc - New version avail.

ag81@dial.pipex.com (Chris Osborne)
18 Oct 2000 23:53:43 -0400

          From comp.compilers

Related articles
Delphi Lex & Yacc - New version avail. ag81@dial.pipex.com (2000-10-18)
Re: Delphi Lex & Yacc - New version avail. martin@pergolesi.demon.co.uk (Martin Harvey) (2000-10-22)
| List of all articles for this month |

From: ag81@dial.pipex.com (Chris Osborne)
Newsgroups: comp.compilers,comp.lang.pascal.delphi.misc
Date: 18 Oct 2000 23:53:43 -0400
Organization: Simbal Computing Intelligence Ltd.
Keywords: yacc, lex, Pascal, available

Hi,


I recently had a need for Lex & Yacc for Delphi and found a version
by Albert Graef which had been nodified by Thierry Coq. This nearly
did the job, but I had to make a few changes before it could cope
with my requirements. I have put my modified versions on the
Simbal Computing web site:


http://dspace.dial.pipex.com/town/plaza/ag81


for anyone who may like to use this code.
(Written for Delphi4/5 but may work on version 3).


The list of modifications is given below.
I hope this is of use to some of you.


Regards,


Chris Osborne. ag81@dial.pipex.com




-------------------------------------------------------------------


Lex & Yacc for Delphi
=====================
Based on Turbo Pascal Lex & Yacc by Albert Graef.




Modifications by C.P.Osborne
============================


These modifications are based on those by Thierry Coq but have
different libraries & there are a few modifications to the utilities
themselves.


Note that as usual no guarantee whatsoever is given as to the
correctness of these programs or the generated code. (They work for
the job I needed them for!)


If you find any bugs please let me know, but I do not have much time
for bug fixing.


(If you find bugs AND fix them then I will be much happier!)


In particular the code for lex exclusive start states has not been
tested very rigorously.




New libraries
-------------
The library files YaccLib & LexLib have been modified so that all
input & output is by means of TLexFile objects.


These are an agglomeration of different input/output methods, so
you can now take data from text files, streams, strings, special
purpose input routines, or object methods. See the file 'LexFile.pas'
for details.


Lex mods
--------
Lex can now accept the name of the code template file on the command
line after the output file name.


Lex can substitute the base name of the output file in place of the
characters '<<OP>>' in the code template file. This means that the
unit name can be supplied without either hacking the template for
each job, or giving the same unit name to all lexers.


A new command switch /t (traditional) disables this behaviour.


A new code template yylex_only.cod is now supplied for producing
systems that do not require Yacc.


The state name 'INITIAL' is now pre-defined for the default state (0).


A pattern for state INITIAL now matches only in INITIAL state
(at first it would match any state!).
(I've never seen any discussion about how Lex should behave, but it
seems that most implementations allow you to set state INITIAL but
not check for it. This seemed like a cop-out to me.)


Lex now supports exclusive start states introduced by %x or
%exclusive.


Yacc mods
---------
Yacc can now accept the name of the code template file on the command
line after the output file name.


Yacc can substitute the base name of the output file in place of the
characters '<<OP>>' in the code template file. This means that the
unit name can be supplied without either hacking the template for
each job, or giving the same unit name to all parsers.


Yacc is now much more careful about what it allows in the variant
record part of YYStype. In particular you may now use tokens of type
'String' without the compiler rejecting the resulting structure.
The only problem is that detecting which items can be part of a variant
needs detailed knowledge of the application being produced. Yacc now
uses a very simple minded test so YYStype records may be much larger
than they have been in the past.


A new command switch /t (traditional) disables both of the previous
modifications. This will give you smaller YYStypes if you use a lot
of enumerated types etc. but you will get errors from string & object
types. You will also have to edit the unit name of the generated file.


Examples
--------
A couple of simple Delphi examples have been supplied:


Yacc Example - is a simple expression evaluator that takes input from
a memo & sends output to another memo.


Lex Example - is a very simple word counter that also detects comment
lines beginning with '// ' and doesn't count them. This is intended
to show the effect of start states & the common problem with these
states being inclusive. Four lexer files are supplied, & you should
copy one of these to 'lexer.l' before running lex & then building
the Delphi project:


lexer_working.l is a correct implementation.
lexer_broken.l shows the (bad) effect of normal rules
matching all start states if the rules are
in a different order.
lexer_fixed.l shows a method of fixing the problem by using
an explicit <INITIAL> state on rules which
are not processing comments.
(this may not be portable to other lex
implementations.)
lexer_fixed2.l makes the comment state an exclusive state
in order to fix the problem.


Desirable(?) changes for future
-------------------------------
Remove all fixed table sizes & allow dynamic resizing.


Make windowed versions rather than command line utilities.


I probably shouldn't use the 'Yakko' icon for Yacc. Warner brothers
might not like it, but it seemed SO appropriate.


Fix Yacc sources so that its parser can be generated from its own
grammar once more (the .l & .y files in the yacc source directory
are relics from the turbo pascal version & currently cannot be used).


A manual re-write is sorely needed.


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.