public void Parse()
        {
            StringtoElementsParser toElementsParser = new StringtoElementsParser(text);
            toElementsParser.Parse();

            ElementsToLayersParser toLayersParser = new ElementsToLayersParser(toElementsParser.Elements);
            toLayersParser.Parse();

            topLayer = toLayersParser.TopLayer;
        }
        private void AddFirstToLayerAndDeleteFromList(AddSubtractLayer layer, List<IElement> els)
        {
            bool isAddition = true;
            if (els[0] is MinusElement) isAddition = false;
            if (els[0] is PlusElement || els[0] is MinusElement) els.RemoveAt(0);

            int length = GetFirstIndexOrCount(els, typeof(PlusElement), typeof(MinusElement));

            ElementsToLayersParser parser = new ElementsToLayersParser(els.GetRange(0, length));
            parser.Parse();
            if (isAddition) layer.Additions.Add(parser.TopLayer);
            if (!isAddition) layer.Subtractions.Add(parser.TopLayer);

            els.RemoveRange(0, length);
        }
        private void AddFirstToLayerAndDeleteFromList(MultiplyDivideLayer layer, List<IElement> els)
        {
            bool isFactor = true;
            if (els[0] is DivideElement) isFactor = false;
            if (els[0] is MultiplyElement || els[0] is DivideElement) els.RemoveAt(0);

            int length = GetFirstIndexOrCount(els, typeof(MultiplyElement), typeof(DivideElement));

            ElementsToLayersParser parser = new ElementsToLayersParser(els.GetRange(0, length));
            parser.Parse();
            if (isFactor) layer.Factors.Add(parser.TopLayer);
            if (!isFactor) layer.Divisors.Add(parser.TopLayer);

            els.RemoveRange(0, length);
        }
        private void ParseMiddleOperatorType(List<IElement> els, Type operatorType, out ILayer before, out ILayer after)
        {
            int indexOfPowerSymbol = GetFirstIndexOrCount(els, operatorType);

            ElementsToLayersParser parser = new ElementsToLayersParser(els.GetRange(0, indexOfPowerSymbol));
            parser.Parse();
            before = parser.TopLayer;

            parser = new ElementsToLayersParser(els.GetRange(indexOfPowerSymbol + 1, els.Count - indexOfPowerSymbol - 1));
            parser.Parse();
            after = parser.TopLayer;
        }
        private void ParseBeginWithParameterType(List<IElement> els, out ILayer parameter, out ILayer layer)
        {
            els.RemoveAt(0);
            int indexOfSecondUnderscore = 1 + GetFirstIndexOrCount(els.GetRange(1, els.Count - 1), typeof(UnderscoreElement));
            if (indexOfSecondUnderscore == els.Count || !(els[0] is UnderscoreElement)) throw new MissingUnderscoreException();

            ElementsToLayersParser parser = new ElementsToLayersParser(els.GetRange(1, indexOfSecondUnderscore - 1));
            parser.Parse();
            parameter = parser.TopLayer;
            els.RemoveRange(0, indexOfSecondUnderscore + 1);

            parser = new ElementsToLayersParser(new List<IElement>(els));
            parser.Parse();
            layer = parser.TopLayer;
        }
 private void ParseBeginWithoutParameterType(List<IElement> els, out ILayer layer)
 {
     els.RemoveAt(0);
     ElementsToLayersParser parser = new ElementsToLayersParser(els);
     parser.Parse();
     layer = parser.TopLayer;
 }
Exemple #7
0
 public static Term FromElements(List<IElement> elements)
 {
     ElementsToLayersParser parser = new ElementsToLayersParser(elements);
     parser.Parse();
     return new Term(parser.TopLayer);
 }