private static bool ParseMethodError(int startPos, string methodName, Line line) { MethodErrorParser.Start(startPos, line, methodName, Data.Project.Variables); if (Data.Errors.Count > 0) { return(true); } return(false); }
internal static void Start(Line line, int startPos, Dictionary <string, Variable> variables) { LastIndex = 0; bool logic = true; var type = VariableType.NON; bool math = true; bool plus = false; bool addMath = false; bool firstOperand = true; bool doubleOperand = false; bool oneOperand = false; for (int i = startPos; i < line.Count; i++) { var word = line.Words[i]; if (word.Token == Tokens.BOOLOPERATOR || word.Token == Tokens.EQU) { oneOperand = false; if (logic) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1909, "")); return; } if (firstOperand) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1910, "")); return; } if (doubleOperand) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1912, "")); return; } logic = true; if (!math) { math = true; } else { if (word.Text == "-") { if (i != startPos + 1) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1426, "")); return; } else if (i - 1 >= 0 && i - 1 < line.Count && line.Words[i - 1].Token != Tokens.BRACKETLEFT) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1426, "")); return; } } } continue; } if (word.Token == Tokens.MATHOPERATOR) { if (i - 1 >= 0 && line.Words[i - 1].Token != Tokens.VARIABLE && line.Words[i - 1].Token != Tokens.NUMBER && line.Words[i - 1].Token != Tokens.METHOD && line.Words[i - 1].Token != Tokens.STRING && line.Words[i - 1].Token != Tokens.BRACKETRIGHT && line.Words[i - 1].Token != Tokens.BRACKETRIGHTARRAY && line.Words[i - 1].Token != Tokens.DOUBLEBRACKET && line.Words[i - 1].Token != Tokens.DOUBLEBRACKETARRAY) { if (word.Text != "-") { Data.Errors.Add(new Errore(line.Number, line.FileName, 1409, "")); return; } } addMath = true; if (!firstOperand && !doubleOperand && !logic) { firstOperand = true; oneOperand = true; } else if (!firstOperand && doubleOperand) { doubleOperand = false; } logic = true; plus = false; if (word.Text == "+") { plus = true; } if (!math) { math = true; } else { if (word.Text == "-") { if (i + 1 < line.Count && line.Words[i + 1].Token != Tokens.NUMBER && line.Words[i + 1].Token != Tokens.VARIABLE && line.Words[i + 1].Token != Tokens.METHOD) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1426, "2")); return; } } } } else if (word.Token == Tokens.NUMBER) { if ((!firstOperand && doubleOperand) || doubleOperand) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1912, "")); return; } if (!doubleOperand && !firstOperand) { doubleOperand = true; oneOperand = false; } if (firstOperand) { firstOperand = false; } if (!logic) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1905, "")); return; } logic = false; if (math) { math = false; } else { Data.Errors.Add(new Errore(line.Number, line.FileName, 1426, "")); return; } if (type == VariableType.NON) { type = VariableType.NUMBER; } else if (type != VariableType.NUMBER && type != VariableType.ANY) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1407, "")); return; } } else if (word.Token == Tokens.STRING) { oneOperand = true; if (!logic) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1905, "")); return; } if (!plus && addMath) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1417, "")); return; } logic = false; if (math) { math = false; } else { Data.Errors.Add(new Errore(line.Number, line.FileName, 1426, "")); return; } if (type == VariableType.NON) { type = VariableType.STRING; } else if (type != VariableType.STRING && type != VariableType.ANY) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1407, "")); return; } } else if (word.Token == Tokens.VARIABLE) { if ((!firstOperand && doubleOperand) || doubleOperand) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1912, "")); return; } if (!doubleOperand && !firstOperand) { doubleOperand = true; oneOperand = false; } if (firstOperand) { firstOperand = false; } if (!logic) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1905, "")); return; } logic = false; if (math) { math = false; } else { Data.Errors.Add(new Errore(line.Number, line.FileName, 1426, "")); return; } if (!variables.ContainsKey(word.Text)) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1405, "( " + word.OriginText + " )")); return; } else { var v = variables[word.Text]; if (v.Type == VariableType.NUMBER_ARRAY) { if (i + 1 < line.Count && line.Words[i + 1].Token == Tokens.BRACKETLEFTARRAY) { ArrayIndexErrorParser.Start(line, i + 1, variables); if (Data.Errors.Count > 0) { return; } i = ArrayIndexErrorParser.LastIndex; if (type == VariableType.NON) { type = VariableType.NUMBER; } else if (type != VariableType.NUMBER && type != VariableType.ANY) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1407, "")); return; } if (line.Words[LastIndex].Token == Tokens.BRACKETRIGHTARRAY) { continue; } } else { Data.Errors.Add(new Errore(line.Number, line.FileName, 1906, "( " + word.Text + " )")); return; } } else if (v.Type == VariableType.STRING_ARRAY) { if (i + 1 < line.Count && line.Words[i + 1].Token == Tokens.BRACKETLEFTARRAY) { ArrayIndexErrorParser.Start(line, i + 1, variables); if (Data.Errors.Count > 0) { return; } i = ArrayIndexErrorParser.LastIndex; if (!plus && addMath) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1417, "")); return; } if (type == VariableType.NON) { type = VariableType.STRING; } else if (type != VariableType.STRING && type != VariableType.ANY) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1407, "")); return; } if (line.Words[LastIndex].Token == Tokens.BRACKETRIGHTARRAY) { continue; } } else { Data.Errors.Add(new Errore(line.Number, line.FileName, 1906, "( " + word.Text + " )")); return; } } else if (v.Type == VariableType.NUMBER) { if (type == VariableType.NON) { type = VariableType.NUMBER; } else if (type != VariableType.NUMBER && type != VariableType.ANY) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1407, "")); return; } } else if (v.Type == VariableType.STRING) { if (!plus && addMath) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1417, "")); return; } if (type == VariableType.NON) { type = VariableType.STRING; } else if (type != VariableType.STRING && type != VariableType.ANY) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1407, "")); return; } } else { Data.Errors.Add(new Errore(line.Number, line.FileName, 1906, "( " + word.Text + " )")); return; } } } else if (word.Token == Tokens.METHOD) { if ((!firstOperand && doubleOperand) || doubleOperand) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1912, "")); return; } //Console.WriteLine("=> " + firstOperand + " " + doubleOperand); if (!doubleOperand && !firstOperand) { doubleOperand = true; oneOperand = false; } if (firstOperand) { firstOperand = false; } //Console.WriteLine("=> " + firstOperand + " " + doubleOperand); if (!logic) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1905, "")); return; } logic = false; if (math) { math = false; } else { Data.Errors.Add(new Errore(line.Number, line.FileName, 1426, "")); return; } var lastIndex = MethodErrorParser.GetMethodLastIndex(i, line, word.Text); var param = MethodErrorParser.GetParam(i, lastIndex, line); MethodErrorParser.Start(param, word.Text, variables, line); if (Data.Errors.Count > 0) { return; } var sign = DefaultObjectList.Objects[word.ToLower()]; if (sign.OutputType == VariableType.NON) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1313, "")); return; } else if (sign.OutputType == VariableType.STRING) { //Console.WriteLine("=> " + oneOperand); if (!plus && addMath) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1417, "")); return; } } i = lastIndex; if (type == VariableType.NON) { type = sign.OutputType; } else if (sign.OutputType != VariableType.ANY && type != sign.OutputType) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1407, "")); return; } if (sign.OutputType == VariableType.ANY || sign.OutputType == VariableType.STRING) { if (!doubleOperand) { oneOperand = true; } } } else if (word.Token == Tokens.BRACKETLEFT || word.Token == Tokens.BRACKETRIGHT) { continue; } else if (word.Token == Tokens.KEYWORD) { if (word.ToLower() == "and" || word.ToLower() == "or" || word.ToLower() == "then") { if (word.ToLower() == "and" || word.ToLower() == "or") { if (i + 1 < line.Count && (line.Words[i + 1].ToLower() == "and" || line.Words[i + 1].ToLower() == "or" || line.Words[i + 1].ToLower() == "then")) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1912, "")); return; } } if (logic && !doubleOperand) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1911, "")); return; } if (!firstOperand && !doubleOperand && !oneOperand) { //Console.WriteLine(firstOperand + " " + doubleOperand + " " + oneOperand); Data.Errors.Add(new Errore(line.Number, line.FileName, 1911, "")); return; } LastIndex = i; return; } else { Data.Errors.Add(new Errore(line.Number, line.FileName, 1034, "( " + word.Text + " )")); return; } } else { Data.Errors.Add(new Errore(line.Number, line.FileName, 1034, "( " + word.Text + " )")); return; } } if (logic && !doubleOperand) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1911, "")); return; } if (!firstOperand && !doubleOperand && !oneOperand) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1911, "")); return; } LastIndex = line.Count; }
internal static void Start(Line line, int startPos, Dictionary <string, Variable> variables) { int bracket = 0; LastIndex = 0; bool math = true; for (int i = startPos; i < line.Count; i++) { var word = line.Words[i]; if (word.Token == Tokens.BRACKETLEFTARRAY) { bracket++; } else if (word.Token == Tokens.BRACKETRIGHTARRAY) { bracket--; } else if (word.Token == Tokens.MATHOPERATOR) { if (!math) { math = true; } else { if (word.Text == "-") { if (i + 1 < line.Count && line.Words[i + 1].Token != Tokens.NUMBER && line.Words[i + 1].Token != Tokens.VARIABLE && line.Words[i + 1].Token != Tokens.METHOD) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1426, "")); return; } } } } else if (word.Token == Tokens.NUMBER) { if (math) { math = false; } else { Data.Errors.Add(new Errore(line.Number, line.FileName, 1426, "")); return; } } else if (word.Token == Tokens.VARIABLE) { if (math) { math = false; } else { Data.Errors.Add(new Errore(line.Number, line.FileName, 1426, "")); return; } if (!variables.ContainsKey(word.Text)) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1405, "( " + word.OriginText + " )")); return; } else { var v = variables[word.Text]; if (v.Type == VariableType.NUMBER_ARRAY) { if (i + 1 < line.Count && line.Words[i + 1].Token == Tokens.BRACKETLEFTARRAY) { Start(line, i + 1, variables); if (Data.Errors.Count > 0) { return; } i = LastIndex; if (line.Words[LastIndex].Token == Tokens.BRACKETRIGHTARRAY) { continue; } } else { Data.Errors.Add(new Errore(line.Number, line.FileName, 1425, "( " + word.Text + " )")); return; } } else if (v.Type != VariableType.NUMBER) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1423, "( " + word.Text + " )")); return; } } } else if (word.Token == Tokens.METHOD) { if (math) { math = false; } else { Data.Errors.Add(new Errore(line.Number, line.FileName, 1426, "")); return; } var lastIndex = MethodErrorParser.GetMethodLastIndex(i, line, word.Text); var param = MethodErrorParser.GetParam(i, lastIndex, line); MethodErrorParser.Start(param, word.Text, variables, line); if (Data.Errors.Count > 0) { return; } var sign = DefaultObjectList.Objects[word.ToLower()]; if (sign.OutputType != VariableType.NUMBER) { if (sign.OutputType != VariableType.ANY && word.ToLower() != "f.get") { Data.Errors.Add(new Errore(line.Number, line.FileName, 1424, "")); return; } } i = lastIndex; } else if (word.Token == Tokens.BRACKETLEFT || word.Token == Tokens.BRACKETRIGHT) { continue; } else { //Builder.Project.WriteTextAndTokens(line); //Console.WriteLine(i); Data.Errors.Add(new Errore(line.Number, line.FileName, 1427, "( " + word.Text + " )")); return; } if (bracket == 0) { LastIndex = i; break; } } }
private static bool ParseValue(int startPos, int lastPos, Line line, Dictionary <string, Variable> variables, bool step) { bool math = true; for (int i = startPos; i < lastPos; i++) { var word = line.Words[i]; if (word.Token == Tokens.BRACKETLEFTARRAY) { ArrayIndexErrorParser.Start(line, 1, variables); if (Data.Errors.Count > 0) { return(true); } i = ArrayIndexErrorParser.LastIndex; if (line.Words[ArrayIndexErrorParser.LastIndex].Token == Tokens.BRACKETRIGHTARRAY) { continue; } } else if (word.Token == Tokens.MATHOPERATOR) { if (!math) { math = true; } else { if (word.Text == "-") { if (i == startPos && step) { continue; } if (i + 1 < line.Count && line.Words[i + 1].Token != Tokens.NUMBER && line.Words[i + 1].Token != Tokens.VARIABLE && line.Words[i + 1].Token != Tokens.METHOD) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1426, "")); return(true); } } } } else if (word.Token == Tokens.NUMBER) { if (math) { math = false; } else { Data.Errors.Add(new Errore(line.Number, line.FileName, 1426, "")); return(true); } } else if (word.Token == Tokens.VARIABLE) { if (math) { math = false; } else { Data.Errors.Add(new Errore(line.Number, line.FileName, 1426, "")); return(true); } if (!variables.ContainsKey(word.Text)) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1405, "( " + word.OriginText + " )")); return(true); } else { var v = variables[word.Text]; if (v.Type == VariableType.NUMBER_ARRAY) { if (i + 1 < lastPos && line.Words[i + 1].Token == Tokens.BRACKETLEFTARRAY) { ArrayIndexErrorParser.Start(line, i + 1, variables); if (Data.Errors.Count > 0) { return(true); } i = ArrayIndexErrorParser.LastIndex; if (line.Words[ArrayIndexErrorParser.LastIndex].Token == Tokens.BRACKETRIGHTARRAY) { continue; } } else { Data.Errors.Add(new Errore(line.Number, line.FileName, 1425, "( " + word.Text + " )")); return(true); } } else if (v.Type != VariableType.NUMBER) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1423, "( " + word.Text + " )")); return(true); } } } else if (word.Token == Tokens.METHOD) { if (math) { math = false; } else { Data.Errors.Add(new Errore(line.Number, line.FileName, 1426, "")); return(true); } var lastIndex = MethodErrorParser.GetMethodLastIndex(i, line, word.Text); var param = MethodErrorParser.GetParam(i, lastIndex, line); MethodErrorParser.Start(param, word.Text, variables, line); if (Data.Errors.Count > 0) { return(true); } var sign = DefaultObjectList.Objects[word.ToLower()]; if (sign.OutputType != VariableType.NUMBER) { if (sign.OutputType != VariableType.ANY && word.ToLower() != "f.get") { Data.Errors.Add(new Errore(line.Number, line.FileName, 1424, "")); return(true); } } i = lastIndex; } else if (word.Token == Tokens.BRACKETLEFT || word.Token == Tokens.BRACKETRIGHT) { continue; } else { Data.Errors.Add(new Errore(line.Number, line.FileName, 1427, "( " + word.Text + " )")); return(true); } } return(false); }
internal static bool ParseEquMathError(Line line) { if (!VarContains(line, line.Words[0].Text, line.Words[0].OriginText)) { return(true); } var type = Data.Project.Variables[line.Words[0].Text].Type; if (type == VariableType.NUMBER_ARRAY || type == VariableType.STRING_ARRAY) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1421, "")); return(true); } if (line.Count < 3) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1414, "")); return(true); } if (line.Words[2].Token == Tokens.NUMBER) { if (line.Count != 3) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1414, "")); return(true); } if (type != VariableType.NUMBER) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1407, "")); return(true); } } else if (line.Words[2].Token == Tokens.STRING) { if (line.Count != 3) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1414, "")); return(true); } if (type != VariableType.STRING) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1407, "")); return(true); } } else if (line.Words[2].Token == Tokens.MATHOPERATOR) { if (line.Words[2].Text != "-" && line.Count != 4 && line.Words[3].Token != Tokens.NUMBER) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1414, "")); return(true); } if (type != VariableType.NUMBER) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1407, "")); return(true); } } else if (line.Words[2].Token == Tokens.METHOD) { MethodErrorParser.Start(2, line, line.Words[2].Text, Data.Project.Variables); if (Data.Errors.Count > 0) { return(true); } if (Data.Errors.Count > 0) { return(true); } var sign = DefaultObjectList.Objects[line.Words[2].ToLower()]; if (sign.OutputType == VariableType.NUMBER_ARRAY || sign.OutputType == VariableType.STRING_ARRAY || sign.OutputType == VariableType.ANY) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1428, "")); return(true); } if (sign.OutputType != type) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1407, "")); return(true); } } else if (line.Words[2].Token == Tokens.VARIABLE) { if (line.Count != 3) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1414, "")); return(true); } if (!VarContains(line, line.Words[2].Text, line.Words[2].OriginText)) { return(true); } var v = Data.Project.Variables; if (v[line.Words[2].Text].Type == VariableType.NUMBER_ARRAY || v[line.Words[2].Text].Type == VariableType.STRING_ARRAY || v[line.Words[2].Text].Type == VariableType.ANY) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1428, "")); return(true); } if (v[line.Words[2].Text].Type != type) { Data.Errors.Add(new Errore(line.Number, line.FileName, 1407, "")); return(true); } } else { Data.Errors.Add(new Errore(line.Number, line.FileName, 1414, "")); return(true); } line.OutLines.Clear(); var newWords = new List <Word>(); newWords.Add(line.Words[0]); newWords.Add(new Word() { Text = "=", OriginText = "=", Token = Tokens.EQU }); newWords.Add(line.Words[0]); if (line.Words[1].Text == "+=") { newWords.Add(new Word() { Text = "+", OriginText = "+", Token = Tokens.MATHOPERATOR }); } else if (line.Words[1].Text == "-=") { newWords.Add(new Word() { Text = "-", OriginText = "-", Token = Tokens.MATHOPERATOR }); } else if (line.Words[1].Text == "*=") { newWords.Add(new Word() { Text = "*", OriginText = "*", Token = Tokens.MATHOPERATOR }); } else if (line.Words[1].Text == "/=") { newWords.Add(new Word() { Text = "/", OriginText = "/", Token = Tokens.MATHOPERATOR }); } if (line.Words.Count >= 3) { for (int i = 2; i < line.Words.Count; i++) { newWords.Add(line.Words[i]); } } var newLine = new Line(newWords, line.OldLine) { Number = line.Number, FileName = line.FileName, Type = LineType.VARINIT }; line.OutLines.Add(newLine); return(false); }