[futurebasic] Re: [FB] Maths Equation Editor

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : July 2001 : Group Archive : Group : All Groups

From: Charlie Dickman <3tothe4th@...>
Date: Tue, 03 Jul 2001 18:52:05 -0400
on 7/3/01 12:00 AM, Ashley Butterworth at macbse@... wrote:

> Hi All,
> I have finally got around to coding my maths equation editor. I have functions
> that draw square roots, powers and fractions but I have now hit a brick wall.
> 
> I currently have the equation devided into functional blocks each delimieted
> by {}. For example the equation of a parabola (y = x squared) would become
> {y}={x^2} and the analyser function would pickout the blocks and parse its
> text (eg the y), fontsize, center line and x inset and the function will draw
> it. But I am stuck when it comes to embeded blocks, for instance {y} =
> {(x+2)^({sqr({(z-2)/(z+3)})})}. Conceiveably in each block there can be an
> infinite amount of blocks embeded {{{{{...}}}}} but ther could also be an
> infinite number of block in the block {{}{}{}{}{}{}{}....}.
> 
> Does anybody have any ideas on how to make a general method of analyseing
> and/or embeding it, because things like fractions which take up two lines have
> to be drawn first or at least calculated for.

Ashley,

Any good compiler book, one that gives methods for parsing expressions,
should give you an idea on how to proceed. With binary operations you can
represent the equation with 2 stacks, one of operations and one of
operators, or with a binary tree. Knuth volume II, I believe (mine is at
work or I could give you the exact reference) discusses binary trees at
length. 

Essentially, you would parse each expression and represent it in its
internal form. You then could rearrange the terms and factors any way you
like, maintaining the proper form of an equation, and then start popping the
stacks in tandem or traversing the tree in any of 3 possible ways (infix,
postfix or prefix).


I suggest that you start by writing the grammar for the expressions you wish
to be able to process. Then encode the parser and build the internal
structure of the expression. Then you can display the components and allow
for editing. Finally, write the final expression from its internal form. By
doing it this way you can also avoid redundant parentheses or blocks.

Perhaps Staz/Andy would share how the FB compiler does it.


Charlie Dickman
3tothe4th@...