Jack likes C programming language, but hates to write expressions like
to multiply the values.
He would like to write
why should compiler moan about
abh symbol being undefined since
int a, b, h; are defined, so we can deduce multiplication?
Help him implement a parser that deciphers a single multiplication term, provided the set of variables defined in current scope is known.
For simplicity, multiplying by number (as in
2*a*b) is not taken into account, only variables appear.
The input is a multiplication term T, fulfilling regexp:
and a variable set Z .
A parsing P of the term T over variable set Z is a string fulfilling following:
- after removing all occurences of
*from P we receive T,
- either is a variable name from Z or consists of proper variable names from Z split up by single
The solution should print all parsings of a term.
Vars a, c, ab, bc Term abc Solution ab*c, a*bc Vars ab, bc Term abc Solution - Vars - Term xyz Solution - Vars xyz Term xyz Solution xyz Vars width, height Term widthheight Solution width*height Vars width, height Term widthheightdepth Solution - Vars aaa, a Term aaaa Solution aaa*a, a*aaa, a*a*a*a
The input (the list of variables and the term) may be supplied in any way suitable for the language.
The output can be in any sensible form (one parsing per line or a comma-separated list etc.) - but it should be unambiguous and possible to read.
Empty output is acceptable if there is no possible parsing of a term (in the examples I used '-' for clarity).
This is a code golf, so the shortest code wins.