473,480 Members | 2,001 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

flex: plex?


Hi,

I am looking for a Python equivalent of Flex. After some
browsing, it seems that Plex is my best bet, but I would like to
hear suggestions before I dive in.

I have been using Flex a lot in combination with C programming.
I never use Yacc (or Bison), though Flex and Yacc are supposed
to be used together. But I found Yacc too cumbersome, and
unnecessary. Yacc is about context-free grammars, nice if you
like to describe an input language as a set of context-free
rewrite rules. Flex is about finite-state automata, but can be
extended to push-down automata (equivalent to context-free
grammars) and beyond, as long as it stays deterministic. I found
this to be very productive. I prefer automata over rewrite rules.

So, what I am looking for is a Python version of Flex that
supports the following capabilities, which are also supported by Plex:

- assigning any Python code to a matched input pattern

- input pattern recognition depending on 'states', which can be
changed through actions

Things that seems to be missing from Plex:

- patterns like:
A/B : match A only if followed by B, give A as result, keep B
in the input stream

- actions like:
REJECT: ask the flexer to come up with the next best match for the
same input
LESS(n): push n characters back into the input stream

All these are not really necessary, but they make some things
simpler.

So, are there any other packages that do these things better
than Plex?

--
Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia)
info: http://www.let.rug.nl/~kleiweg/ls.html

Jul 18 '05 #1
4 3593
If plex uses python regular expressions, you can use the zero-length
lookahead assertion instead of flex's A/B syntax: "A(?=B)"

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBInqKJd01MZaTXX0RAh5dAKCivbanEnAb1N7QShDi5U LE/+32DwCfTG34
cb0k64glgd54ryIoemvZBSo=
=l+Mj
-----END PGP SIGNATURE-----

Jul 18 '05 #2
Jeff Epler schreef:
If plex uses python regular expressions, you can use the zero-length
lookahead assertion instead of flex's A/B syntax: "A(?=B)"


Alas, it doesn't.
--
Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia)
info: http://www.let.rug.nl/~kleiweg/ls.html

Jul 18 '05 #3
At some point, Peter Kleiweg <in*************@nl.invalid> wrote:
Hi,

I am looking for a Python equivalent of Flex. After some
browsing, it seems that Plex is my best bet, but I would like to
hear suggestions before I dive in.

I have been using Flex a lot in combination with C programming.
I never use Yacc (or Bison), though Flex and Yacc are supposed
to be used together. But I found Yacc too cumbersome, and
unnecessary. Yacc is about context-free grammars, nice if you
like to describe an input language as a set of context-free
rewrite rules. Flex is about finite-state automata, but can be
extended to push-down automata (equivalent to context-free
grammars) and beyond, as long as it stays deterministic. I found
this to be very productive. I prefer automata over rewrite rules.


If you've been using Flex, you might want to check out FlexModule at
<http://www.cs.utexas.edu/users/mcguire/software/fbmodule/>
which allows you to use Flex to generate a lexer callable from python.

--
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca
Jul 18 '05 #4
David M. Cooke schreef:

If you've been using Flex, you might want to check out FlexModule at
<http://www.cs.utexas.edu/users/mcguire/software/fbmodule/>
which allows you to use Flex to generate a lexer callable from python.


I have tried it. (Had to edit the Makefile by hand, because
"make -f Makefile.pre.in boot" did not produce a valid Makefile,
but I did manage to build and run the example.) The problem is,
the Flex file (and Yacc file) is compiled into C, and then into
a shared lib. This means I must use C code in the Flex file.

What I want is something that lets me call arbitrary Python code
from the lexer. Ideal would be to have a version of Flex that
produces a Python file instead of a C file. I have kept looking,
and I think I found what I was looking for: PyLly, which is part
of PyGgy. http://www.lava.net/~newsham/pyggy/
--
Peter Kleiweg L:NL,af,da,de,en,ia,nds,no,sv,(fr,it) S:NL,de,en,(da,ia)
info: http://www.let.rug.nl/~kleiweg/ls.html

Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1031
by: srijit | last post by:
Hello, I got the following error while using Plex 1.1.4.1 D:\Python24\myfiles>python plex1.py Traceback (most recent call last): File "plex1.py", line 1, in ? from Plex import * File...
0
2559
by: Tom Heathcote | last post by:
Apologies for posting a flex++ question rather than a C++ question, but there does not appear to be a flex++ newsgroup... I am trying to rebuild some old lexical scanner / analyzer code, which I...
2
6562
by: olig9 | last post by:
Hello, is there a way to feed an ifstream to a parser generated with flex and bison? I could see that flex wants a FILE* for reading, but I only have an ifstream (actually and ifstream*) for...
8
16818
by: pavel.orehov | last post by:
Hi, I am using flex and bizon to write HTTP parser. I am passing well flex and bison tools but can't compile their output. ================= Flex file (http_parser.lpp) ============== %{...
5
5930
by: ASP.NET explorer | last post by:
I have been asked to create some simple animation using Adobe Flash player in ASP.NET(C#) web application. While I am fairly well versed with ASP.NET C#, I absolutely have NO IDEA about how to...
10
6682
by: Jules Winfield | last post by:
Guys, I've been designing applications for the financial services industry using MSFT technologies for many years (Win32 API, MFC, and now .NET WinForms). All applications are Internet-based,...
1
2933
by: abbasnaqvi | last post by:
Hi All, I am developing Employee Management system in Adobe Flex and I am coding a web service to get data from the database and return it to Adobe Flex...
3
3515
by: Tarik Monem | last post by:
Hi Everyone, Still a newbie with FLEX, and I've passed arrays using AJAX to FLEX before, but I've never passed links to FLEX. Basically, this is the OUTPUT, which I wanted, but I'm given an...
1
1876
by: Leah | last post by:
Try to compile, but stuck at the following: .... checking for flex version... invalid configure: error: Found invalid flex version: 2.5.33. Supported flex versions are: 2.5.4. Is there any way...
0
6911
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7050
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7091
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6743
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5344
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4488
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1303
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
564
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.