Ejemplo n.º 1
0
        protected virtual void AnalysExpression(LexemList lexems)
        {
            for (int i = 0; i < lexems.Count; i++)
            {
                var lexem = lexems[i];

                if (lexem is LexemBracket)
                {
                    i = this.SkipBrackets(lexems, i);
                }
                else if (lexem is LexemSwitch && lexem.ToString() == "?")
                {
                    var sw = lexem as LexemSwitch;

                    var simetric = sw.Simetric;
                    if (simetric == null)
                        throw new FormatException("Switch syntax should have simetric Else path");

                    int index = lexems.FindPosition(simetric);
                    if (index <= i)
                        throw new FormatException("Switch syntax balance is incorrect");

                    var condition = lexems.Range(0, i);
                    var then = lexems.Range(i + 1, index - i - 1);
                    var other = lexems.Range(index + 1, lexems.Count - index - 1);

                    this.OnSwitch(sw, condition, then, other);

                    return;
                }
            }

            this.AnalysLogical(lexems);
        }
Ejemplo n.º 2
0
        protected virtual void AnalysElement(LexemList lexems)
        {
            if (lexems == null || lexems.Count <= 0)
                throw new FormatException("Analys Element is empty");

            if (lexems.Count == 1)
            {
                this.OnElement(lexems[0]);
                return;
            }

            if (lexems[0] is LexemBracket && lexems.FindPosition((lexems[0] as LexemBracket).Simetric) == lexems.Count - 1)
            {
                this.OnElement(lexems);
                return;
            }

            this.Scan(lexems, LexemOperator.OperationType.Code, new string[] { "->", "." }, this.Error);
        }
Ejemplo n.º 3
0
        protected int SkipBrackets(LexemList lexems, int index, bool forward = true)
        {
            var bracket = lexems[index] as LexemBracket;
            if (bracket == null)
                return index;

            var result = index;

            if (bracket.Simetric != null)
                result = lexems.FindPosition(bracket.Simetric);

            if (forward && result <= index || !forward && result >= index)
                throw new FormatException($"Brackets balance is incorrect: {lexems}");

            return result;
        }