Error in my grammar

Dec 13, 2013 at 9:03 AM
Hi,

I am trying to get a small grammar syntax working:
RegexBasedTerminal ruleStringLiteral = new RegexBasedTerminal("RuleString", "'[A-Z]+'");
            RegexBasedTerminal rulePropertyLiteral = new RegexBasedTerminal("RuleProperty", "^(_Prop_)[A-Z]+");

            NonTerminal Rule = new NonTerminal("Rule");
            NonTerminal Expr = new NonTerminal("Expr");
            NonTerminal LSubExpr = new NonTerminal("LSubExpr");
            NonTerminal RSubExpr = new NonTerminal("RSubExpr");
            NonTerminal Lookup = new NonTerminal("lookup");
            NonTerminal RuleProperty = new NonTerminal("RuleProperty");
            NonTerminal RuleString = new NonTerminal("RuleString");

            Rule.Rule = Expr;
            Expr.Rule = LSubExpr + "=" + RSubExpr;
            LSubExpr.Rule = RuleProperty;
            RSubExpr.Rule = Lookup | RuleString;
            Lookup.Rule = ToTerm("lookup") + "(" + RuleProperty + "," + RuleString + ")";
            //Lookup.Rule = ToTerm("lookup") + "(" + RuleString + "," + RuleString + ")";
            RuleProperty.Rule = rulePropertyLiteral;
            RuleString.Rule = ruleStringLiteral;

            this.Root = Rule;
            MarkPunctuation("(", ")", ",");
When I comment out the Lookup.Rule line and uncomment the the line after it it works with the following source code:
string another = "_Prop_COUNTRYOFINCORPORATION = lookup('COUNTRYOFINCORPORATION','DATALISTCOUNTRIES')";
However I need to get the following to work with the original Lookup.Rule line:
string another = "_Prop_COUNTRYOFINCORPORATION = lookup(_Prop_COUNTRYOFINCORPORATION,'DATALISTCOUNTRIES')";
I think it is something to do with the regular expressions because although the first example works, when I do this:
string another = "_Prop_COUNTRYOFINCORPORATION = lookup('_Prop_COUNTRYOFINCORPORATION','DATALISTCOUNTRIES')";
(Note the Prop at the beginning of the string) it doesn't work.

I am pretty new to this grammar thing - so I am sure I have not understood something properly. Also my regex knowledge sucks.

Any help would be appreciated!

cheers,

thornza
Dec 13, 2013 at 2:19 PM
rather than doing a regex as a terminal for ruleproperty why don't you break it down, since PROP is always the same followed by a normal string.
IdentifierTerminal Rule= new IdentifierTerminal("Rule");

KeyTerm PROP= ToTerm("_Prop_");

NonTerminal RuleProperty = new NonTerminal("RuleProperty");

RuleProperty.Rule = PROP + Rule;
I'm also new to this, but i found breaking down every expression to its most granular form seems to be best.
Coordinator
Dec 18, 2013 at 9:14 PM
I agree, get rid of regex-es, use these only if you don't have any other choice for some really tricky expression/token type; and only after you debug your language with simplified version that does not use regex terminal.
Roman