internal static LexicalTree_BoolParen ParseBoolParen(this IEnumerator <Token> c) { var token = c.Current; var answer = new LexicalTree_BoolParen() { File = token.File, Line = token.Line, Column = token.Column }; string content; Token next; int count = 1; while (c.MoveNext()) { Top: token = c.Current; content = token.Content; if (token.Type == 0) { if (c.MoveNext()) { next = c.Current; if (next.Symbol1 == '(' && token.IsNext(next)) { answer.Children.Add(new LexicalTree_Function(content) { File = token.File, Line = token.Line, Column = token.Column, Variable = c.ParseVariableParen() }); } else { answer.Children.Add(new SingleContent(token)); goto Top; } } else { throw new LexicalTreeConstructionException(token); } } else if (token.Type == 2) { answer.Children.Add(new SingleContent(token)); } else if (token.IsSingleSymbol) { switch (token.Symbol1) { case ')': --count; if (count != 0) { answer.Children.Add(new SingleContent(token)); } else { return(answer); } break; case '(': ++count; answer.Children.Add(new SingleContent(token)); break; case '+': var last = answer.Children.LastOrDefault() as SingleContent; if (last != null) { var last_token = last.Content; if (last_token.Symbol1 == '+' || last_token.Symbol1 == '-' || last_token.Symbol1 == '*' || last_token.Symbol1 == '/' || last_token.Symbol1 == '%' || last_token.Symbol1 == '(' || last_token.Symbol1 == '=' || last_token.Symbol1 == '!' || last_token.Symbol1 == '<' || last_token.Symbol1 == '>') { if (!c.MoveNext()) { throw new LexicalTreeConstructionException(token); } next = c.Current; if (token.IsNext(next) && next.Type == 2) { token = new Token(token.File, token.Line, token.Column, token.IsDebug, token.IsMemo, token.Number); answer.Children.Add(new SingleContent(token)); } else { goto Top; } } else { answer.Children.Add(new SingleContent(token)); } } else if (answer.Children.Count == 0) { if (!c.MoveNext()) { throw new LexicalTreeConstructionException(token); } next = c.Current; if (token.IsNext(next) && next.Type == 2) { token = new Token(token.File, token.Line, token.Column, token.IsDebug, token.IsMemo, token.Number); answer.Children.Add(new SingleContent(token)); } else { goto Top; } } else { answer.Children.Add(new SingleContent(token)); } break; case '-': var last2 = answer.Children.LastOrDefault() as SingleContent; if (last2 != null) { var last_token2 = last2.Content; if (last_token2.Symbol1 == '+' || last_token2.Symbol1 == '-' || last_token2.Symbol1 == '*' || last_token2.Symbol1 == '/' || last_token2.Symbol1 == '%' || last_token2.Symbol1 == '(' || last_token2.Symbol1 == '=' || last_token2.Symbol1 == '!' || last_token2.Symbol1 == '<' || last_token2.Symbol1 == '>') { if (!c.MoveNext()) { throw new LexicalTreeConstructionException(token); } next = c.Current; if (token.IsNext(next) && next.Type == 2) { token = new Token(token.File, token.Line, token.Column, token.IsDebug, token.IsMemo, -token.Number); answer.Children.Add(new SingleContent(token)); } else { goto Top; } } else { answer.Children.Add(new SingleContent(token)); } } else if (answer.Children.Count == 0) { if (!c.MoveNext()) { throw new LexicalTreeConstructionException(token); } next = c.Current; if (token.IsNext(next) && next.Type == 2) { token = new Token(token.File, token.Line, token.Column, token.IsDebug, token.IsMemo, -token.Number); answer.Children.Add(new SingleContent(token)); } else { goto Top; } } else { answer.Children.Add(new SingleContent(token)); } break; case '@': if (c.MoveNext()) { next = c.Current; if (next.Type != 0 || !token.IsNext(next)) { answer.Children.Add(new SingleContent(token)); goto Top; } token = token.Merge(next); answer.Children.Add(new SingleContent(token)); } else { throw new LexicalTreeConstructionException(token); } break; default: answer.Children.Add(new SingleContent(token)); break; } } else { answer.Children.Add(new SingleContent(token)); } } throw new LexicalTreeConstructionException(token); }
internal InterpretTreeMachine(LexicalTree_BoolParen boolParen) => this.input = boolParen?.Children ?? new List <LexicalTree>();