[Tutor] regular expressions
Servando Garcia
servando at mac.com
Thu Jul 14 22:41:56 CEST 2005
Hello List
I am working on creating a Domain Specific Language that will solve
partial differential equations. The user will enter a equation in
pseudo code format. I will need to parse the equation. Here is the BNF
for the equation
<Pgm> :=<Loophead><Body>
<Loophead> :=Do<Vector><Vector>
<Vector> :=(<Seq>)
<Seq> :=<Int>,<Seq> |<Int>
<Body> :=<Left> = <Right>
<Left> :=A(<Svector>)
<Svector> :=(<Sseq>)
<Sseq> := <Id> , <Sseq> | <Id>
<Id> := <Letter>| <Id><Letter>|<Id><Digit>
<Letter> :=<A-Za-z>
<Digit> :=<0-9>
<Right> :=<Stencil>+<Func>
<Stencil> :=<Factor>+<Stencil>|<Factor>
<Factor> :=<Float>A(<Svector>+<Vector>)
It was decided to use Spark for the base for the compiler. To use Spark
all that is need is to just add a new class with the above BNF to parse
the equation. There is a good paper called "Charming the Python" that
was used as a template. The problem I am having is, how do I code the
Non-Terminals of the BNF. Terminal states like <Letter> are easy to
code using regular expression. Here is my function for state <Letter>
def t_Letter(self,s):
r"[A-Za-z]+"
self.rv.append(Token('Letter',s))
Servando Garcia
251 Highway 46 N
Sheridan,Ar.72150
(870)942-1854 Home
(870)917-8963 Cell
(866) 228-8794 Fax
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 1400 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20050714/88b2ae4b/attachment.bin
More information about the Tutor
mailing list