Meta programming question
David Abrahams
dave at boost-consulting.com
Sun Sep 28 11:31:37 EDT 2003
Bruce Dickey <ceiesa at excite.com> writes:
> Ben Finney wrote:
>> On Sat, 27 Sep 2003 19:18:15 -0600, Bruce Dickey wrote:
>>
>>>I've read a number of the meta progamming articles. I have not found
>>>what I am looking for. I want to override assignments to variables
>>>which are in the module namespace (not object members -- no classes
>>>involved). Can this be done?
>> AFAIK, no. If it were possible, it would be very confusing.
>> What is it you're trying to achieve? Perhaps a better alternative
>> can
>> be suggested that doesn't break expected behaviour.
>>
> I'm investigating the use of Python as a grammar language. I'm trying
> to achive minimal required syntax/verbage.
Cool! You might take a look at http://spirit.sf.net for some ideas.
Python's a great language for metaprogramming because of its rich
syntax. If you were willing to discourage left-recursion you might go
with something like:
expression = term._('+').expression | term._('-').expression
On the other hand, when I had to do something like this I built my own
"python-like" syntax for the grammar rules and left the semantic
actions in pure Python, then ran the files through a simple
preprocessor. It's just too ugly to write grammar rules in pure
python without overloaded whitespace.
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Python-list
mailing list