Parsing BNF for chemical equations

"psaffrey@googlemail.com" <psaffrey@googlemail.com>
Tue, 28 Aug 2007 10:33:18 -0700

          From comp.compilers

Related articles
Parsing BNF for chemical equations psaffrey@googlemail.com (psaffrey@googlemail.com) (2007-08-28)
Re: Parsing BNF for chemical equations DrDiettrich1@aol.com (Hans-Peter Diettrich) (2007-08-29)
| List of all articles for this month |
From: "psaffrey@googlemail.com" <psaffrey@googlemail.com>
Newsgroups: comp.compilers
Date: Tue, 28 Aug 2007 10:33:18 -0700
Organization: Compilers Central
Keywords: parse, question
Posted-Date: 28 Aug 2007 15:51:40 EDT

I'm trying to build a parser for chemical equations such as


A + B -> C


and


A + B <-> C + D


I'm using the Python lex/yacc tool ply and at the moment I seem to be
struggling a little. I have done this before, but it was ages ago and
I'm rusty :(


So far, my rules are like this:


reactionset : statement
| reactionset statement


statement : reaction NEWLINE


reaction : substrates FORWARD substrates


reaction : substrates TWOWAY substrates


substrates : SUBSTRATE PLUS substrates


substrates : SUBSTRATE


The test input I'm using is "A + B -> C" and at the moment, it seems
to be generating an error. It's possible that this is to do with the
specific configuration of ply, but I'm not that confident in my
grammar, so was hoping for some advice on whether it looks OK.


Thanks in advance,


Peter
[It looks OK to me. I find it extremely informative to turn on the
parser's debugging options and watch the shifts and reduces until it
fails. That usually makes pretty clear what the problem is. It may
be something minor like a newline where your grammar isn't prepared
for it. -John]



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.