|mathematical expressions _Maverick_@web.de (Seidl Markus) (2003-05-06)|
|Re: mathematical expressions firstname.lastname@example.org (Rajesh N Thipse) (2003-05-12)|
|Re: mathematical expressions bobduff@shell01.TheWorld.com (Robert A Duff) (2003-05-13)|
|Re: mathematical expressions email@example.com (2003-05-13)|
|Re: mathematical expressions firstname.lastname@example.org (2003-05-15)|
|Re: mathematical expressions email@example.com (Guillermo Phillips) (2003-05-15)|
|From:||"Guillermo Phillips" <firstname.lastname@example.org>|
|Date:||15 May 2003 12:22:17 -0400|
|Posted-Date:||15 May 2003 12:22:17 EDT|
You are quite correct. All widths of course need to be calculated in
reverse: in the sense that you will have to work from the bottom of
the parse tree, upwards.
In your example the <number> 5 has a definite width and lies at the
deepest part of the parse tree. The square root above 'contains' the
number 5 and adds its own extra width and so on up the tree. Once you
hit the top of the parse tree you will have the final width you need
to work with.
The easiest way to implement this tree searching algorithm is
recursively. A function is designed that returns a width for a given
node in the tree. The function calls recursively down the tree if it
has not reached the leaf nodes.
Using a recursive function(s) will also allow you to parse more complex
expressions with the ultimate aim of positioning figures correctly.
As a side note, why not write a compiler that compiles linear expressions
into MathML? That would be very useful!
"Seidl Markus" <_Maverick_@web.de> wrote in message
> I want to write a parser which converts sth like "5+5^2" in an image >
> 5+5² < (i mean converting from mathematical expression to how you
> would write them with your own hand...)
> My Problem: for example I write a rule like
> <term> ::= 'sqrt(' <term> ')'
> | <number>
> How can i draw the squareroot, when i have the following expression:
> sqrt(sqrt(sqrt(5))) ? I think im stuck there.I think i cannot draw
> the first square because i dont know how big and long i have to made
> it, and i cannot draw the last term, because i don't know where i have
> to draw them ( distance between the left edge of the image) ....
Return to the
Search the comp.compilers archives again.