Problem with IdentifierTerminal

Aug 2, 2014 at 7:18 PM
hi,
i want to parse a structure like this: "Node time >= 1 Endnode" where "time >= 1" is an expression with "time" as some user defined name of the variable followed by ">=" and a number...this expression can occur multiple times..i.e.: "Node time >= 1 weight >= 5 x >= 0 Endnode"

i definded the grammar like this:
// Terminals
            Terminal number = new NumberLiteral("number");
            IdentifierTerminal identifier = new IdentifierTerminal("Identifier");
            KeyTerm ENDNODE = ToTerm("Endnode;");
            KeyTerm NODE = ToTerm("Node");

            // Non-terminals
            NonTerminal Node = new NonTerminal("Node");
            NonTerminal LTN = new NonTerminal("LTN");
            NonTerminal UGL = new NonTerminal("UGL");

            // BNF
            Node.Rule = NODE + LTN + ENDNODE;
            LTN.Rule = MakePlusRule(LTN, UGL);
            UGL.Rule = identifier + ToTerm(">=") + number;

            LanguageFlags = LanguageFlags.NewLineBeforeEOF;
            this.Root = Node;
and the paring code:
 LanguageData language = new LanguageData(new GrammarClass());

            Parser parser = new Parser(language);

            ParseTree parseTree = parser.Parse("Node time >= 13 x >= 12 Endnode;");

            ParseTreeNode root = parseTree.Root;
but this isnt working...the root object is null.

if i change the last rule
 UGL.Rule = identifier + ToTerm(">=") + number;
to:
 UGL.Rule = number+ ToTerm(">=") + number;
or:
 UGL.Rule = ToTerm(">=") + number;
the string "Node time 1>= 13 1>= 12 Endnode;" and "Node >= 13 >= 12 Endnode;" can be parsed correctly...only if i put the "identifier" at the beginning of the rule the root object is null...why is this? is there something wrong with the IdentifierTerminal?
Coordinator
Aug 4, 2014 at 9:05 AM
remove ';' from Endnode and add it explicitly in the UGL rule:
        Node.Rule = NODE + LTN + ENDNODE + ";";