コード例 #1
0
ファイル: Grammar.cs プロジェクト: yuva2achieve/SharpDevelop
 public static BnfExpression MakePlusRule(NonTerminal listNonTerminal, BnfTerm delimiter, BnfTerm listMember)
 {
     listNonTerminal.SetOption(TermOptions.IsList);
     if (delimiter == null)
     {
         listNonTerminal.Rule = listMember | listNonTerminal + listMember;
     }
     else
     {
         listNonTerminal.Rule = listMember | listNonTerminal + delimiter + listMember;
     }
     return(listNonTerminal.Rule);
 }
コード例 #2
0
ファイル: Grammar.cs プロジェクト: yuva2achieve/SharpDevelop
        public static BnfExpression MakeStarRule(NonTerminal listNonTerminal, BnfTerm delimiter, BnfTerm listMember)
        {
            if (delimiter == null)
            {
                //it is much simpler case
                listNonTerminal.SetOption(TermOptions.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 tmp = new NonTerminal(listMember.Name + "+");

            tmp.SetOption(TermOptions.IsTransient); //important - mark it as Transient so it will be eliminated from AST tree
            MakePlusRule(tmp, delimiter, listMember);
            listNonTerminal.Rule = _currentGrammar.Empty | tmp;
            //listNonTerminal.SetOption(TermOptions.IsStarList);
            return(listNonTerminal.Rule);
        }
コード例 #3
0
        //Pipe/Alternative
        internal static BnfExpression Op_Pipe(BnfTerm term1, BnfTerm term2)
        {
            //Check term1 and see if we can use it as result, simply adding term2 as operand
            BnfExpression expr1 = term1 as BnfExpression;

            if (expr1 == null) //either not expression at all, or Pipe-type expression (count > 1)
            {
                expr1 = new BnfExpression(term1);
            }
            //Check term2; if it is an expression and is simple sequence (Data.Count == 1) then add this sequence directly to expr1
            BnfExpression expr2 = term2 as BnfExpression;

            //1. term2 is a simple expression
            if (expr2 != null && expr2.Data.Count == 1) // if it is simple sequence (plus operation), add it directly
            {
                expr1.Data.Add(expr2.Data[0]);
                return(expr1);
            }
            //2. term2 is not a simple expression
            expr1.Data.Add(new BnfTermList());           //add a list for a new OR element (new "plus" sequence)
            expr1.Data[expr1.Data.Count - 1].Add(term2); // and put  term2 there if it is not Empty pseudo-element
            return(expr1);
        }
コード例 #4
0
 public ParseTreeNode(Production reduceProduction)
 {
     ReduceProduction = reduceProduction;
     Term             = ReduceProduction.LValue;
     Precedence       = Term.Precedence;
 }
コード例 #5
0
 public ParseTreeNode(BnfTerm term)
 {
     Term = term;
 }
コード例 #6
0
ファイル: Grammar.cs プロジェクト: yuva2achieve/SharpDevelop
 public static BnfExpression MakeStarRule(NonTerminal listNonTerminal, BnfTerm listMember)
 {
     return(MakeStarRule(listNonTerminal, null, listMember));
 }
コード例 #7
0
 public BnfExpression(BnfTerm element) : this()
 {
     Data[0].Add(element);
 }