Esempio n. 1
0
 public void Add(Precedence precedence)
 {
     List<Precedence> entry = new List<Precedence>();
     entry.Add(precedence);
     
     order.Add(entry);
     
     UpdatePositions();
 }
Esempio n. 2
0
 public void Basic()
 {
     Precedence a = new Precedence("a");
     Precedence b = new Precedence("b");
     
     Precedence.SetPrecedence(a, b, Relation.Lower);
     
     Assert.IsTrue(a.IsLowerThan(b, false));
     Assert.IsTrue(a.IsLowerThan(b, true));
     
     Assert.IsFalse(b.IsLowerThan(a, false));
     Assert.IsFalse(b.IsLowerThan(a, true));
 }
Esempio n. 3
0
 public bool Overwrites(Precedence b)
 {
     if (b == null)
         return true;
     
     if (group == null)
         return false;
     
     if (group != b.Group)
         return true;
     
     return b.IsLowerThan(this, true);
 }
Esempio n. 4
0
 public bool IsLowerThan(Precedence b, bool canBeEqualTo)
 {
     if (group != b.group)
         throw new Exception("Cannot compare two precedences, "
             + this.Name + " and " + b.Name + ", which are not "
             + "in the same group");
     
     if (group == null)
         throw new Exception("Cannot compare two precedences, "
             + this.Name + " and " + b.Name + ", which have not "
             + "been added to a group");
     
     if (canBeEqualTo)
         return position <= b.position;
     else
         return position < b.position;
 }
Esempio n. 5
0
 public static void SetPrecedence(Precedence a, Precedence b,
     Relation relation)
 {    
     if (b.Group == null)
     {
         b.Group = new Group();
         b.Group.Add(b);
     }
     
     if (a.Group != null)
         throw new Exception("Cannot set the precedence of "
             + b.Name + " because it already belongs to a precedence "
             + "group");
     
     a.Group = b.Group;
     b.Group.Insert(a, b, relation);
 }
Esempio n. 6
0
        public void Equal()
        {
            Precedence a = new Precedence("a");
            Precedence b = new Precedence("b");
            Precedence c = new Precedence("c");
            
            Precedence.SetPrecedence(a, b, Relation.Lower);
            Precedence.SetPrecedence(c, b, Relation.Equal);

            Assert.IsTrue(c.IsLowerThan(b, true));
            Assert.IsFalse(c.IsLowerThan(b, false));

            Assert.IsTrue(b.IsLowerThan(c, true));
            Assert.IsFalse(c.IsLowerThan(b, false));
            
            Assert.IsTrue(a.IsLowerThan(c, true));
            Assert.IsTrue(a.IsLowerThan(c, false));
        }
Esempio n. 7
0
 public void Insert(Precedence a, Precedence b, Relation relation)
 {
     for (int n = 0; n < order.Count; n++)
     {
         if (order[n].Contains(b))
         {
             switch (relation)
             {
                 case Relation.Lower:
                 {
                     List<Precedence> entry = new List<Precedence>();
                     entry.Add(a);
                     
                     order.Insert(n, entry);
                 } break;
                 
                 case Relation.Equal:
                     order[n].Insert(0, a);
                     break;
                 
                 case Relation.Higher:
                 {
                     List<Precedence> entry = new List<Precedence>();
                     entry.Add(a);
                     
                     order.Insert(n + 1, entry);
                 } break;
             }
             
             UpdatePositions();
             
             return;
         }
     }
     
     throw new Exception("Group does not contain " + b.Name);
 }
Esempio n. 8
0
 public PrecedenceAltGroup(Source source, Precedence precedence,
     List<IParseable> nodes)
 {
     this.nodes = nodes;
     this.precedence = precedence;
     
     if (nodes.Count == 1)
         parseGraph = nodes[0];
     else
         parseGraph = new LongestAlt(source, nodes);
         
     leftRecursiveNodes = new List<ParseGraphNode>();
     
     foreach (IParseable node in (IEnumerable<IParseable>) nodes)
     {
         PatternNode patternNode = node as PatternNode;
         
         if (patternNode != null)
         {
             ConcretePattern pattern = patternNode.Pattern as ConcretePattern;
             
             if (pattern != null)
             {
                 if (pattern.RecursionBehaviour == RecursionBehaviour.LeftRecursive)
                     leftRecursiveNodes.Add(new PatternNode(source, pattern, true));
             }
         }
     }
     
     if (leftRecursiveNodes.Count == 0)
         leftRecursiveParseGraph = null;
     else if (leftRecursiveNodes.Count == 1)
         leftRecursiveParseGraph = leftRecursiveNodes[0];
     else
         leftRecursiveParseGraph = new AltNode(source, leftRecursiveNodes, true);
 }
Esempio n. 9
0
 public Pattern(Source source, string name)
 {
     this.source = source;
     precedence = new Precedence(name);
 }