private int DoWhile(CodeLineCollection cc) { res.AddLine(Tabul(cc[0].IndentLevel) + "do{", lm); CodeLineCollection sup = cc.ExtractSubIndentation(cc[0].LineNumber); cc = cc.Extractor(sup.Count + 1); AnalyzeCodeLines(sup); if (Regex.IsMatch(cc[0].Code, @"quando [\w\W]+", RegexOptions.IgnoreCase)) { if (cc.Count == 1) { cc[0].Code = cc[0].Code.Trim(); int indx = cc[0].Code.IndexOf(' '); res.AddLine(Tabul(cc[0].IndentLevel) + "}while(" + AnalyzeCode(cc[0].Code.Substring(indx, cc[0].Code.Length - indx).Trim(), cc[0].LineNumber) + ");", lm); } else { lm.Add("Something gone wrong at this line", cc[0].LineNumber); } } else { lm.Add("The programm cannot find the 'quando' condition", cc[0].LineNumber); } return(0); }
private void CaseAction(CodeLineCollection cc, string varName) { if (cc != null && cc.Count > 0) { cc[0].Code = cc[0].Code.Trim(); if (Regex.IsMatch(cc[0].Code, @"se [\W\w]+", RegexOptions.IgnoreCase)) { int indx = cc[0].Code.IndexOf(' ') + 1; res.AddLine(Tabul(cc[0].IndentLevel) + "if(" + AnalyzeCode(varName + " " + cc[0].Code.Substring(indx, cc[0].Code.Length - indx).Trim(), cc[0].LineNumber) + "){", lm); CodeLineCollection sup = cc.ExtractSubIndentation(cc[0].LineNumber); AnalyzeCodeLines(sup); res.AddLine(Tabul(cc[0].IndentLevel) + "}else ", lm); sup = cc.Extractor(sup.Count + 1); if (sup == null || sup.Count <= 0) { lm.Add("The translator cannot find the 'Altrimenti' tag"); } CaseAction(sup, varName); } else if (Regex.IsMatch(cc[0].Code, @"altrimenti", RegexOptions.IgnoreCase)) { int indx = cc[0].Code.IndexOf(' ') + 1; res.AddLine(Tabul(cc[0].IndentLevel) + "{", lm); CodeLineCollection sup = cc.ExtractSubIndentation(cc[0].LineNumber); AnalyzeCodeLines(sup); res.AddLine(Tabul(cc[0].IndentLevel) + "}", lm); if (cc.Extractor(sup.Count + 1).Count > 0) { lm.Add("The 'altrimenti' must be the last tag in the switch"); } } else { lm.Add("Cannot translate the line in the switch", cc[0].LineNumber); } } }
private void AnalyzeCodeLines(CodeLineCollection cc) { if (cc != null && cc.Count > 0) { if (Regex.IsMatch(cc[0].Code, @"crea (vettore )?[a-z][\w]*(\s?\{[\w\W]+\})* [\w\W]+", RegexOptions.IgnoreCase)) { CreateVariable(cc[0]); AnalyzeCodeLines(cc.Extractor(1)); } else if (Regex.IsMatch(cc[0].Code, @"cambia [a-z][\w]*(\s?\{[\w\W]+\})* [\w\W]+", RegexOptions.IgnoreCase)) { ChangeVariable(cc[0]); AnalyzeCodeLines(cc.Extractor(1)); } else if (Regex.IsMatch(cc[0].Code, @"se [\W\w]+", RegexOptions.IgnoreCase)) { cc = cc.Extractor(IfAction(cc.ExtractSubIndentation(cc[0].LineNumber, true))); if (Regex.IsMatch(cc[0].Code, @"altrimenti", RegexOptions.IgnoreCase)) { AnalyzeCodeLines(cc.Extractor(ElseAction(cc.ExtractSubIndentation(cc[0].LineNumber), cc[0].IndentLevel))); } } else if (Regex.IsMatch(cc[0].Code, @"controlla [\W\w]+", RegexOptions.IgnoreCase)) { AnalyzeCodeLines(cc.Extractor(SwitchAction(cc.ExtractSubIndentation(cc[0].LineNumber, true)))); } else if (Regex.IsMatch(cc[0].Code, @"ripeti quando [\w\W]+", RegexOptions.IgnoreCase)) { AnalyzeCodeLines(cc.Extractor(WhileAction(cc.ExtractSubIndentation(cc[0].LineNumber, true)))); } else if (Regex.IsMatch(cc[0].Code, @"ripeti [\w\W]+ volte", RegexOptions.IgnoreCase)) { AnalyzeCodeLines(cc.Extractor(ForAction(cc.ExtractSubIndentation(cc[0].LineNumber, true)))); } else if (Regex.IsMatch(cc[0].Code, @"ripeti", RegexOptions.IgnoreCase)) { CodeLineCollection sup = cc.ExtractSubIndentation(cc[0].LineNumber, true); sup.Add(cc.Extractor(sup.Count)[0]); AnalyzeCodeLines(cc.Extractor(DoWhile(sup))); } else if (Regex.IsMatch(cc[0].Code, @"ritorna [\w\W]+", RegexOptions.IgnoreCase)) { ReturnAction(cc[0]); AnalyzeCodeLines(cc.Extractor(1)); } else if (Regex.IsMatch(cc[0].Code, @"[\w\W]+", RegexOptions.IgnoreCase)) { FunctionAction(cc[0]); AnalyzeCodeLines(cc.Extractor(1)); } else { lm.Add("Nothing is possible to translate at this line", cc[0].LineNumber); } } }