public void AddSymbole(Affectation aff) { if (aff.expression.dataType != ExpressionType.UNKNOWVAR) { if (symboleTabe.ContainsKey(aff.variableName.name)) { symboleTabe.Remove(aff.variableName.name); errorList.Add(new Error(ErrorType.DOUBLE_DECLARATION, aff.variableName.name, 0, 0)); } AddSymbole(aff.variableName.name, ("L" + aff.expression.dataType.ToString())); } }
public void AddSymboleFromPreCompile(string file) { //Add of the choice variables Console.WriteLine("AddSymboleFromPreCompile : Choix"); string choicePattern = @"(\$choix\() *\w+ *,"; MatchCollection choiceMatches; Regex choiceRegex = new Regex(choicePattern); choiceMatches = choiceRegex.Matches(file); // Iterate matches for (int ctr = 0; ctr < choiceMatches.Count; ctr++) { string choiceVarName = choiceMatches[ctr].Value.Substring("$choix(".Length, (choiceMatches[ctr].Value.Length - "$choix(,".Length)); Affectation aff = new Affectation(new VariableId(choiceVarName.Trim(), "L" + ExpressionType.TEXTE.ToString()), new VariableId(choiceVarName.Trim() + "Model", ExpressionType.TEXTE.ToString())); this.AddSymbole(aff); if (!mapOfCalculExpressions.ContainsKey(aff.variableName.name)) { this.mapOfCalculExpressions.Add(aff.variableName.name, aff); } } //Add of the propositions variables Console.WriteLine("AddSymboleFromPreCompile : Proposition"); string propositionPattern = @"[^xni]\( *\w+ *, *" + "\"[^\"]*\"" + @" *\)"; MatchCollection propositionMatches; Regex propositionRegex = new Regex(propositionPattern); propositionMatches = propositionRegex.Matches(file); // Iterate matches for (int ctr = 0; ctr < propositionMatches.Count; ctr++) { string propoVarName = propositionMatches[ctr].Value.Substring("x(".Length, (Regex.Match(propositionMatches[ctr].Value, @",").Index - "x(".Length)); int commaIndex = ("x(" + propoVarName + ",").Length; string propoString = propositionMatches[ctr].Value.Substring(commaIndex, (propositionMatches[ctr].Value.Length - (commaIndex + 1))); // We don't need the last char Affectation aff = new Affectation(new VariableId(propoVarName.Trim(), "LTEXTE"), new VariableString(propoString)); this.AddSymbole(aff); if (!mapOfCalculExpressions.ContainsKey(aff.variableName.name)) { this.mapOfCalculExpressions.Add(aff.variableName.name, aff); } } //Add of the option variables Console.WriteLine("AddSymboleFromPreCompile : Option"); string optionPattern = @"(\$option\() *\w+ *,"; MatchCollection optionMatches; Regex optionRegex = new Regex(optionPattern); optionMatches = optionRegex.Matches(file); // Iterate matches for (int ctr = 0; ctr < optionMatches.Count; ctr++) { string optionVarName = optionMatches[ctr].Value.Substring("$option(".Length, (optionMatches[ctr].Value.Length - "$option(,".Length)); Affectation aff = new Affectation(new VariableId(optionVarName.Trim(), "LBOOL"), new VariableId(optionVarName.Trim() + "Model", "BOOL")); this.AddSymbole(aff); if (!mapOfCalculExpressions.ContainsKey(aff.variableName.name)) { this.mapOfCalculExpressions.Add(aff.variableName.name, aff); } } }