Problem with simple grammar

Mar 30, 2012 at 4:59 AM

I have a simple grammar for a simple stack based dsl I am working on.

Basically, most commands are a single character: so I have a statement rule that looks like:

statement.Rule = ifStatement | "p" | "d"| "+" | "-" | "/" | "%" | ">" | "o" | "r" | "!";

This generally works pretty well for me except where I have adjacent symbols in my program that are letters.

will work just fine, but if I try something like
I get the error: 'invalid character p'. I assume this is because the parser is looking at the initial 'pd' as a single token and it is not mathing any rule, or something like that. The problem goes away if I insert spaces between adjacent letters, but that is not something I want to require.

Is there a way to override this behavior so that the parser will consider each letter individually, and not as a whole word? This is not a problem with the non-letter symbols. 

Mar 30, 2012 at 5:09 AM

Well, I found the AllowAlphaAfterKeyword flag on the KeyTerm class, and that seems to have solved my problem. I end up having to create a few different terminals instead of using automatic string terms, but that is ok I suppose.

Mar 30, 2012 at 5:19 AM

right, this flag is just for cases like this