예제 #1
0
        private static void ParseRule(Tree tree, Token token, Token[] tokens, ref int index)
        {
            if (token is Identifier)
            {
                var ruleToken = token;

                var rule = new Rule { Identifier = token.Value };

                token = NextToken(tokens, ref index);

                if (IsDefinition(token))
                {
                    token = NextToken(tokens, ref index);

                    rule.Expression = ParseExpression(tree, ref token, tokens, ref index, ';');

                    tree.Add(rule);
                }
                else
                {
                    ruleToken.Position += 2;
                    tree.Errors.Add(CreateError(ruleToken, string.Format(ErrorStrings.ExpectedDefinition, token == null ? "nothing" : token.Value)));
                }
            }
            else
            {
                tree.Errors.Add(CreateError(token, ErrorStrings.RulesMustBeginWithIdentifier));
            }
        }
예제 #2
0
 public void Add(Rule rule)
 {
     Rules.Add(rule);
 }