Bug 66200 - Improve parsing of implicit products like 2 x
Summary: Improve parsing of implicit products like 2 x
Status: ASSIGNED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Formula Editor (show other bugs)
Version:
(earliest affected)
4.2.0.0.alpha0+ Master
Hardware: All All
: medium enhancement
Assignee: dante19031999
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Formula-Editor
  Show dependency treegraph
 
Reported: 2013-06-26 09:25 UTC by Frédéric Wang
Modified: 2020-07-22 14:52 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Frédéric Wang 2013-06-26 09:25:16 UTC
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).
Comment 1 Jorendc 2013-06-26 11:05:28 UTC
I think I don't have to say this again :-), but you already prove you are an expert in this domain. Feel free to mark your own bugs as NEW without any QA interaction. Except you would like to have a review/second opinion test etc. :)

Kind regards,
Joren
Comment 2 QA Administrators 2015-03-16 23:39:55 UTC Comment hidden (obsolete)
Comment 3 tommy27 2016-04-16 07:26:28 UTC Comment hidden (obsolete)
Comment 4 QA Administrators 2017-05-22 13:22:26 UTC Comment hidden (obsolete)
Comment 5 dante19031999 2020-07-21 22:35:59 UTC
This is not really a bug, is just how it works.
It would be an ennancement.
It could be semiresolved with a hidden product like in mathml.
Gonna take it and semiresolve it, but won't fix that easely.