Hi Kohei,

On Wed, Feb 23, 2005 at 10:42:14 -0500, Kohei Yoshida wrote:

> You're right on!  This helps tremendously.  :-)  This mechanism is
> still a bit complicated, but I will try to understand it slowly but
> surely.

I'd do it differently in a new implementation, but I don't think it
would be less complicated ;-)

> Ultimately, I'd like to see how a given string of formula, say,
> "=B5*2+(C2/D10)" gets transformed into an array of ScToken's for later
> processing of that formula.

If you want to dive into it: compile sc/source/core/tool/compiler.cxx
with debug and set breakpoints at ScCompiler::CompileString() and
ScCompiler::CompileTokenArray(). If you enter a formula cell, first
CompileString() is called that transforms the string into tokens, then
CompileTokenArray() is called that creates the RPN array in its final
form.

> My goal is to create a similar
> functionality in my UNO component so that I can transform an arbitrary
> formula string into a standard form of linear or polynomial equation. 
> This way I can apply all kinds of mathematical algorithms to that
> equation to do some fun stuff. ;-)
> 
> Or, could this functionality (i.e. tokenization of a formula string)
> be somehow exported via the API?  Is that technically achievable? 
> What would be the difficulty level?

It can't be exported via API, as the compiler and the resulting token
array would need access to internal document structures. I suggest you
take a look at Boost's Spirit parser framework, see
http://boost.org/libs/spirit/index.html
and/or search the web for recursive-descent parser, with or without RPN.
There are many sample sources. For more complex grammars, tools like
lex/flex and yacc/bison may be helpful.

  Eike

-- 
 OOo/SO Calc core developer. Number formatter bedevilled I18N transpositionizer.
 GnuPG key 0x293C05FD:  997A 4C60 CE41 0149 0DB3  9E96 2F1A D073 293C 05FD

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to