473,394 Members | 1,878 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Assembler Parser/Lexer in Python


Anyone have any experience or pointers to how to go about creating
a parser lexer for assemble in Python. I was thinking of using PLY
but wonder whether it's too heavyweight for what I want. Anyone have
any thoughts?
--
Simon Foster
Somewhere in the West of England
Jul 18 '05 #1
3 5455
djw
Simon Foster wrote:

Anyone have any experience or pointers to how to go about creating
a parser lexer for assemble in Python. I was thinking of using PLY
but wonder whether it's too heavyweight for what I want. Anyone have
any thoughts?
--
Simon Foster
Somewhere in the West of England


Maybe kwParser?

http://olympus.het.brown.edu/doc/gadfly/

-Don
Jul 18 '05 #2
Simon Foster wrote:
Anyone have any experience or pointers to how to go about creating
a parser lexer for assemble in Python. I was thinking of using PLY
but wonder whether it's too heavyweight for what I want. Anyone have
any thoughts?


There are, of course, lots of tools available to help you out with
this, but as you probably realize, most of them have heavyweight
features which help out for higher-level languages, but not really
so much for assembler. Also, most of them will probably not give you
great help for assembly language macros, which are typically more
full-featured than C macros, in that they know something about
the actual program being built. (Please note that I am _not_
cross-posting this to comp.lang.lisp, and also that if you want
to parse pre-existing assembly language, it will look _nothing_
like lisp, so the built-in parser wouldn't help you out in any
case. Also note that YMMV, but while I use macros _extensively_
in assembly language, I have personally never felt the necessity
of having any sort of macro processor in Python :)

I had a similar problem, in maintaining a system with over 10MB of
crufty ancient assembly language. I had conflicting goals of wanting
to use Python so I could easily and correctly do different things with
the source code (code rewriting, automatic HTML generation, some
lint-like operations, etc.) and wanting operations to complete rapidly
so that I could do some of it in the typical Python experimental mode.

I wrote a lexer using a tiny bit of C and a Pyrex wrapper. The
partitioning was such that the C code knows nothing about Python,
and the Pyrex interface handles the higher layers of the tokenization.

The lexer performs a single tokenization pass over an entire file,
(with the Pyrex calling the C code once per line) and returns a list
of token tuples (one tuple per line). Macro lines which invoke text-
pasting operations are flagged, and the lexer is re-run on these
lines when they are encountered at parse time.

A separate (and very simple!) Python script generates a .h file
which contains the lowest-level lexer tables.

I did an earlier version of this in mxTextTools, which is not too
bad for such a thing if a) for whatever reason, you don't want to
write your own C extensions, and b) you're not doing too much
maintenance on the actual lexer.

I also played around with re, but if you do that, you will quickly
come to realize why lexer generators are popular :)

More recently, I played a little bit with psyco. If I didn't care
quite as much about speed and didn't already have the C code, I
might consider one of the existing parser/lexer generators in
conjunction with psyco. Unfortunately, I've only dabbled in
a very minor way with some of these packages, so I couldn't begin
to compare their strengths and weaknesses.

Hope this helps.

Pat
Jul 18 '05 #3
On Thu, 06 Nov 2003 22:06:45 GMT, Simon Foster <si***@uggs.demon.co.uk> wrote:

Anyone have any experience or pointers to how to go about creating
a parser lexer for assemble in Python. I was thinking of using PLY
but wonder whether it's too heavyweight for what I want. Anyone have
any thoughts?


I've found SPARK useful:

<http://pages.cpsc.ucalgary.ca/~aycock/spark/>

--
"It's easier to find people online who openly support the KKK than
people who openly support the RIAA" -- comment on Wikipedia
(Email: <ze******@zen.co.ku>, but first subtract 275 and reverse
the last two letters).
Jul 18 '05 #4

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

Similar topics

0
by: simon | last post by:
Anyone have any experience or pointers to how to go about creating a parser lexer for assemble in Python. I was thinking of using PLY but wonder whether it's too heavyweight for what I want. ...
2
by: alederer | last post by:
Hallo! Does anybody know a parser generator that supports unicode (UTF-16), and is based on something like ICU. The parser is used in a platform independent and cross-platform communicating...
14
by: Simon Morgan | last post by:
I'm trying to write a function to parse a Reverse Polish Notation string from stdin and return 1 token at a time. For those of you who are unaware an RPN string looks like this: 1 2 + 4 * 3 + ...
4
by: siddharthkhare | last post by:
Hi All, I need to parse certain text from a paragraph (like 20 lines). I know the exact tags that I am looking for. my approach is to define a xml (config) file that defines what tag I am...
6
by: Mike C# | last post by:
Hi all, Can anyone recommend a good and *easy to use* lexer and parser generator? Preferably one that was written specifically for VC++ and not mangled through 20 different platforms. I've had...
1
vpawizard
by: vpawizard | last post by:
Hello, I am developing a small compiler which recognizes expression like 10+20,10-1*30 and so on. I am using Lex for generating Lexer and Yacc for parser. I created a header file defining the...
4
by: Bartc | last post by:
"vaib" <vaibhavpanghal@gmail.comwrote in message news:26a44cc5-0f08-41fe-859b-0d27daf3ca1d@f24g2000prh.googlegroups.com... I don't know the formal approach to these things but I haven't come...
0
by: arvindkgs | last post by:
Iam using c lexer that is flex generated and a c++ parser that is bison generated. i have modified the parser to acccept only string input. I am calling the parser function yyparse in a loop and...
14
by: Thomas Mlynarczyk | last post by:
Hello, I started to write a lexer in Python -- my first attempt to do something useful with Python (rather than trying out snippets from tutorials). It is not complete yet, but I would like some...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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
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...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.