Space as operator

Apr 16, 2015 at 4:02 PM
I'm trying to parse Excel grammar, and in all it's wisdom " " (a single space) was designated to be the intersection operator.

This causes problems if implemented straightforwardly:
FunctionCall.Rule =
   Formula + InfixOp + Formula          // BinOp
   | PrefixOp + Formula                  // Prefix Unop
   | Formula + Formula                   // Intersection
However this grammar has a reduce-reduce conflict because, 1 + 1 can be parsed as both 1 + 1 and 1 (+1).

Is there a way to allow the single whitespace " " to be an operator? That way it would just be a regular binop (which it is)
Apr 16, 2015 at 4:34 PM
You should use ImpliedSymbolTerminal, read comments there at the top of cs file.
Apr 17, 2015 at 10:41 AM
That works great, thanks!
Apr 20, 2015 at 1:37 PM
Unfortunatly I found a problem with this.
I have the following terminals:
var CellToken = new RegexBasedTerminal("[$]?[A-Z]{1,4}[$]?[1-9][0-9]*");
CellToken.Priority = TerminalPriority.High;

var NamedRangeToken = new RegexBasedTerminal("[A-Za-z\\_][\w\.]*");
NamedRangeToken always matches a CellToken, which is why CellToken has a higher priority because if that matches it should become that.

However this causes a problem when combined with ImpliedSymbolTerminal:
 "A1A1" // This is a named range
 "A1 A1" // This is an intersection of A1 and A1
Both are parsed as intersections when the implied terminal is added.
If the named range token gets a higher priority than the cell token the intersection/namedrange behavior is correct, but all cells are parsed as named ranges instead.

Do you have a suggestion on how to solve this?
Apr 20, 2015 at 1:51 PM
Nevermind, it seems solved when I add a third nonterminal that combines them (celltokenregex + namedrangeregex) and give that a higher priority than the celltoken :)