Delphi Lex & Yacc - New version avail.

Delphi Lex & Yacc - New version avail.

Post by Chris Osbor » Thu, 19 Oct 2000 04:00:00



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,


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

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.

 
 
 

Delphi Lex & Yacc - New version avail.

Post by Martin Harve » Mon, 23 Oct 2000 14:17:13



> 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

Chris,

Thanks a lot ... I've hacked my way round a few of these, but never
really summoned up the courage to do a clean job of it. I ... acting
like the nervous beginner to compiler compilers that I was at the time,
settled for : "Least possible source code change, lest I break it"!

Quote:> A manual re-write is sorely needed.

Yes. My later scrutinies suggest that plenty could be done to make both
the programs and their output source far more amenable to OO.

In particular, I'd love a parser framework which elegantly does garbage
collection on all the objects in the parse tree. I have one, but it's
not exactly wonderful.

MH.

--

     http://www.pergolesi.demon.co.uk
               ICQ: 37298917

 
 
 

1. LEX / YACC - extension of yacc and lex files with additional rules and definitions

Hello, I am new to UNIX and its tools lex and yacc.  What I like to do
is having a main yacc file which can be extended with additional
definitions and rules in an add-on yacc file via something like a
"yacc-include". I guess yacc has no preprocessor like a C compiler and
probably therefore cannot do somehing like %include "add_rules.y". The
book I have doesn't mention something of use. Does somebody know if
lex and yacc have the possibility to do this or if there is a
workaround?

If somebody knows lex and yacc good enough to say - there is
definitely no intern possibility - please let me know too.

Lex / yacc and flex / bison are said to be compatible, but do the
Linux programms probably have the functionality to do this if lex and
yacc do not?

Thankyou very much
Roul Oldenburger
[I've never seen a version of lex or yacc with file inclusion, but you
can use cpp or m4 as a separate prepass.  It's about two lines in your
makefile. -John]

2. Antares P-0027 Audio Card

3. New lex & yacc book from O'Reilly

4. RPM Cisco router

5. Someone Knows a Lex/Yacc like for Delphi

6. only six payees on Web Express??

7. Lex/Yacc Tools for Delphi

8. crimson parts

9. MKS Lex/Yacc Class for Delphi

10. Lex & Yacc - Levine, Mason & Brown

11. REQ: Delphi YACC for Delphi 6

12. Lex & Yacc tools with VxWorks

13. VxWorks and Lex & Yacc