eliben wrote:
>On Nov 8, 10:03 am, eliben <[EMAIL PROTECTED]> wrote:
>
>
>>Hello,
>>
>>I want to conclude these
>>discussions:http://groups.google.com/group/ply-hack/browse_frm/thread/22685d1b7fb...http://groups.google.com/group/ply-hack/browse_frm/thread/a799e10f9c2...
>>
>>With some insights gathered while attempting to build a PLY based
>>grammar for distribution into some kind of a FAQ.
>>
>>If I understand correctly, this is the logic for the optimize modes of
>>yacc and lex:
>>
>>yacc optimization:
>>- If parsetab.py/pyc doesn't exist in the path, the table will be
>>reconstructed anyway, regardless of the optimize parameter
>>- If it doesn't exist:
>> - If optimize=True, the table will be loaded unconditionally
>> - If optimize=False, the table will be loaded only if it's older
>>than the grammar
>>
>>lex optimization:
>>- If optimize=False, the lexical table is re-computed and is not saved
>>to a lextab file
>>- If optimize=True:
>> - If lextab.py/pyc exists in the path, it will be loaded
>>unconditionally
>> - If lextab.py/pyc doesn't exist, it will be created and loaded
>>
>>
>>
>
>No comments ?
>
>I find this issue quite important for the distribution of effective
>PLY parsers as self-contained modules that provide maximal performance
>and don't trouble the user. It's hard to believe that no one has used
>these features and explored the way they work (as the documentation is
>very incomplete on this matter).
>
>
>>
>
>
Hello,
> It's hard to believe that no one has used
> these features and explored the way they work
I looked at that (and more) some time ago. For our tooling
I created a wrapper around Ply. The feature of this wrapper are:
- Class oriented PlyScanner and PlyParser classes.
- Different modes (normal/debug/opt), which set different
settings of Ply.
- Table file creation is always done in the same directory
as the source files.
- Table files can be created for multiple classes in a single
file, with different start symbols.
- Automatic parse/scan error exceptions with line numbers
(without enabling the (slow) option to let ply track line
numbers).
- White-space is automatically skipped in the scanners (can
be modified by derived classes).
- Functions to generate/remove the table files.
- We always install the tooling we create on a central
machine to which all students have read access. However,
the students don't have write access and therefore can't
generate the table files. We have *_gentables.py files
that are used by the setup program to generate the table
files.
- Derived classes should only need to specify:
- list of tokens (scanner)
- t_* (scanner)
- p_* (parser)
The plywrapper.py file is standalone and only needs Ply, except
for the exception base class from one other file in our tooling.
However, one could easily change it to inherit from StandardError
instead...
For the up-to-date code, see:
http://dev.se.wtb.tue.nl/projects/chi-tooling/browser/trunk/chinetics/chinetics/core/plywrapper.py
(for people reading this post a long time after I posted it: note
that I can't guarantee that the link will work forever)
The plywrapper.py file contains some use/implementation instructions
and other useful information.
For some parsers based on this:
http://dev.se.wtb.tue.nl/projects/chi-tooling/browser/trunk/chinetics/chinetics/languages/cif/compiler/cifparser.py
http://dev.se.wtb.tue.nl/projects/chi-tooling/browser/trunk/chinetics/chinetics/languages/cif/compiler/cifparser_gentables.py
http://dev.se.wtb.tue.nl/projects/chi-tooling/browser/trunk/chinetics/chinetics/languages/common/compiler/exprparser.py
http://dev.se.wtb.tue.nl/projects/chi-tooling/browser/trunk/chinetics/chinetics/languages/common/compiler/exprparser_gentables.py
If you have any questions about plywrapper, feel free to ask. Also,
suggestions for improvements are always welcome.
Dennis
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"ply-hack" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/ply-hack?hl=en
-~----------~----~----~----~------~----~------~--~---