Exemplo n.º 1
0
 public static BnfExpression MakePlusRule(NonTerminal listNonTerminal, BnfTerm delimiter, BnfTerm listMember)
 {
     if (delimiter == null)
     {
         listNonTerminal.Rule = listMember | listNonTerminal + listMember;
     }
     else
     {
         listNonTerminal.Rule = listMember | listNonTerminal + delimiter + listMember;
     }
     listNonTerminal.SetFlag(TermFlags.IsList);
     return(listNonTerminal.Rule);
 }
Exemplo n.º 2
0
        //Pipe/Alternative
        //New version proposed by the codeplex user bdaugherty
        internal static BnfExpression Op_Pipe(BnfTerm term1, BnfTerm term2)
        {
            BnfExpression expr1 = term1 as BnfExpression;

            if (expr1 == null)
            {
                expr1 = new BnfExpression(term1);
            }
            BnfExpression expr2 = term2 as BnfExpression;

            if (expr2 == null)
            {
                expr2 = new BnfExpression(term2);
            }
            expr1.Data.AddRange(expr2.Data);
            return(expr1);
        }
Exemplo n.º 3
0
 public BnfExpression(BnfTerm element) : this()
 {
     Data[0].Add(element);
 }
Exemplo n.º 4
0
        public static BnfExpression MakeStarRule(NonTerminal listNonTerminal, BnfTerm delimiter, BnfTerm listMember, TermListOptions options)
        {
            bool allowTrailingDelimiter = (options & TermListOptions.AllowTrailingDelimiter) != 0;

            if (delimiter == null)
            {
                //it is much simpler case
                listNonTerminal.SetFlag(TermFlags.IsList);
                listNonTerminal.Rule = _currentGrammar.Empty | listNonTerminal + listMember;
                return(listNonTerminal.Rule);
            }
            //Note that deceptively simple version of the star-rule
            //       Elem* -> Empty | Elem | Elem* + delim + Elem
            //  does not work when you have delimiters. This simple version allows lists starting with delimiters -
            // which is wrong. The correct formula is to first define "Elem+"-list, and then define "Elem*" list
            // as "Elem* -> Empty|Elem+"
            NonTerminal plusList = new NonTerminal(listMember.Name + "+");

            plusList.Rule = MakePlusRule(plusList, delimiter, listMember);
            plusList.SetFlag(TermFlags.NoAstNode); //to allow it to have AstNodeType not assigned
            if (allowTrailingDelimiter)
            {
                listNonTerminal.Rule = _currentGrammar.Empty | plusList | plusList + delimiter;
            }
            else
            {
                listNonTerminal.Rule = _currentGrammar.Empty | plusList;
            }
            listNonTerminal.SetFlag(TermFlags.IsListContainer);
            return(listNonTerminal.Rule);
        }
Exemplo n.º 5
0
 public static BnfExpression MakeStarRule(NonTerminal listNonTerminal, BnfTerm delimiter, BnfTerm listMember)
 {
     return(MakeStarRule(listNonTerminal, delimiter, listMember, TermListOptions.None));
 }
Exemplo n.º 6
0
        }//method

        #endregion

        #region MakePlusRule, MakeStarRule methods
        public static BnfExpression MakePlusRule(NonTerminal listNonTerminal, BnfTerm listMember)
        {
            return(MakePlusRule(listNonTerminal, null, listMember));
        }
Exemplo n.º 7
0
 public ParseTreeNode(BnfTerm term) : this()
 {
     Term = term;
 }