https://bugs.freedesktop.org/show_bug.cgi?id=66200
Priority: medium
Bug ID: 66200
Assignee: [email protected]
Summary: Improve parsing of implicit products like 2 x
Severity: normal
Classification: Unclassified
OS: All
Reporter: [email protected]
Hardware: All
Status: UNCONFIRMED
Version: 4.2.0.0.alpha0+ Master
Component: Formula Editor
Product: LibreOffice
For example Math currently parses expressions like this:
"a + 2 b" => "{a + 2} b" instead of "a + {2 b}"
"x + 3 y^2" => "{x + 3} y^2" instead of "x + 3 y^2"
I tried to fix that in bug 66081, but I suspect it would be a bit more
complicated than what I initially thought, so I'm moving it as a separate bug.
Currently, the grammar used by starmath/source/parse.cxx is (approximately) as
follows:
Expression = Relation ([relation token] Relation)+
Relation = Sum ([sum token] Sum) +
Sum = Product ([product token] Product)+
Product = Power ([power token] Power)+
Power = Term ([sub/sup script tokens] Term)+
Term = ['{' token] Expression ['}' token] | [text token] | [symbol token] |
Matrix | Binom | ... other terms ...
Binom = ['binom' token] Sum Sum
Matrix = ...
... = other rules
The parsing can be done linearly and stops when an unexpected token is read.
What we'd like in order to fix this bug is to define
Product = Power (([power token] Power)+ | Power+)
so that an explicit [power token] like "*" is not needed to write a product
i.e. we can write "a b" instead of "a * b". Unfortunately, after some attempts
this breaks some unit tests. For example the naive parsing of "binom a b" could
become
Term
=> binom Sum Sum
=> binom Product Sum
=> binom (Power)+ Sum
=> binom (Term)+ Sum
=> binom a b Sum
=> binom a b Product
=> binom a b (Power)+
=> binom a b (Term)+
=> failure!
rather than the expected
Term
=> binom Sum Sum
=> binom Term Term
=> binom a b
The grammar can probably be modified to avoid some of the issues but I suspect
a general solution will require to use techniques like those of parsers
generated by GNU bison (https://en.wikipedia.org/wiki/GNU_bison).
--
You are receiving this mail because:
You are the assignee for the bug.
_______________________________________________
Libreoffice-bugs mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/libreoffice-bugs