Add alpha character operator symbol

Jul 14, 2013 at 4:30 AM
I'm trying to get a new binary operator symbol to work in my grammar, when there are no spaces between a number and the character.

I've already gotten it to work when spaces are present, but when the spaces are absent, it tries to parse the character into a NumberLiteral, which gives me the "Number cannot be followed by a letter error".

I already overrode IsWhitespaceOrDelimiter() in my grammar, by that didn't work as I expected it to.

How can I make the scanner treat this as any other symbolic operator?
Coordinator
Jul 14, 2013 at 6:37 AM
don't quite get what the problem is, please provide some examples of expressions you try to parse
Btw, NumberLiteral has an option 'AllowSign' - if you have this set, then scanner maybe thinking that + or - is part of 'signed number'. Turn this flag off
Jul 15, 2013 at 4:31 AM
I was trying to implement dice rolling notation as an operator rather than it's own node:

x = 2d6

Meaning two random numbers between 1 and 6 added together, as if rolling a die twice.

I've been able to get this to work

x = 2 d 6

With spaces, but can't find a way to allow it to work without the spaces. I was thinking of the tokenizer, and variables in the expression though, and I'm not sure this could ever work for characters allowed in an identifier. So I think I need to either take over a symbol that's unlikely to be used in an expression in my grammar (** perhaps) or just deal with the spaces as a requirement.
Coordinator
Jul 15, 2013 at 5:07 AM
NumberLiteral has an option AllowLetterAfter - try using this
Roman
Jul 15, 2013 at 5:51 AM
I've tried that, but then it tries to parse the letter as part of the number literal, and not as a separate token.
Coordinator
Jul 15, 2013 at 6:00 AM
also, you should set KeyTerm.AllowAlphaAfterKeyword:
  var number = new NumberLiteral("Number", NumberOptions.AllowLetterAfter);
  KeyTerm dOp = ToTerm("d");
  dOp.AllowAlphaAfterKeyword = true; 
  binOp.Rule = dOp | "+" | "-" | "*" | "/";
Then it works
Jul 16, 2013 at 4:04 AM
Thanks Roman, this has got me working!

I had to change some things up to use the CodeOutlineFilter, in order to handle more complicated cases that confused the tokenizer into thinking d6 was an identifier when dealing with multiline scripts, but everything is working great now.