Re: Best practices for recusive type parsing

[email protected] ((Randal L. Schwartz)) 05 Nov 2003 11:18:43 -0800
Newsgroups perl.recdescent
Organization Stonehenge Consulting Services; Portland, Oregon, USA
Message-ID <[email protected]>
>>>>> "Collin" == Collin Peters <[email protected]> writes:

Collin> I am using P::RD for parsing a constraint language in a big ERP
Collin> system. We are trying to parse some of the constraints into XML.
Collin> There are some equations in the constraints.  Below is a simple
Collin> example.

Collin> ! winarea = (winwidth * winheight)/144

Collin> This simply computes an area value of something by multiplying the
Collin> width and height and then dividing by 144.  I would like the XML to
Collin> look something like.

Collin> <evaluate>
Collin> 	<evaluate>
Collin> 		<start value="winwidth"/>
Collin> 		<multiply value="winheight"/>
Collin> 	</evaluate>
Collin> 	<divideby value="144"/>
Collin> </evaluate>

This design is highly assymetrical.  You probably want something more like:

<evaluate op="/">
  <evaluate op="*">
    <variable name="winwidth"/>
    <variable name="winheight"/>
  </evaluate>
  <number value="144"/>
</evaluate>

Then every variable is always "variable", evry number is "number"
every operator is always "evaluate", and it's the attributes to
distinguish them.  That's much more XML-ish.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[email protected]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!