make order of function definitions irrelevant

Joerg Schuster js at
Tue Nov 11 09:40:59 CET 2003

Thank you all, so far. I had asked the question because I am writing a
program that translates linguistic grammars into python functions. The
python functions are supposed to be called by another program of mine
that does regular expression matching. Like so:

(1) Linguistic grammar

NP --> det AP n
AP --> Adv+ a

( Lexicon is given. Like so:

Det --> ['the', 'a', ...]
Adv --> ['really', ...]
A   --> ['blue', 'nice', ...]
N   --> ['programmer', 'biologist', ...]

(2) Python functions

def NP():
   return sequence(det(), AP(), n())

def AP():
   return sequence(plus(adv(), a())

(3) Matching routine "pm":

$ pm -pattern "NP_biologist VP_love NP_programming-language" -file my_corpus

Actually, (2) is lot more complex than in the example, because it needs
"wildcards" that can be filled with semantic and other information by
pm. Yet, the user should be able to write his own grammar, therefore
the translation (1) -> (2). (Of course, the grammar would not be a
context free grammar, though it looks like one.)

*If* the order of function definitions did not matter, then the
 order of the grammar rules in (1) would not matter, either. 

Yet, I thought the translation program over, and I will probably give
it a new design, today. 


More information about the Python-list mailing list