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
<x-tad-smaller>251 Highway 46 N
Sheridan,Ar.72150
(870)942-1854 Home
(870)917-8963 Cell
(866) 228-8794 Fax</x-tad-smaller>
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor