public static string Translate1(bool file, List <string> inputFileLines) { string textInput = null; textInput = G.ExtractTextFromLines(inputFileLines).ToString(); string s3 = HandleUpd(textInput); ANTLRStringStream input = new ANTLRStringStream(s3); CommonTree t = null; // Create a lexer attached to that input T1Parser parser2 = null; T1Lexer lexer2 = new T1Lexer(input); //usually debugTokens=false, and this is stepped into manually (otherwise the tokens are consumed and preliminary steps cannot be run) // Create a stream of tokens pulled from the lexer CommonTokenStream tokens = new CommonTokenStream(lexer2); // Create a parser attached to the token stream parser2 = new T1Parser(tokens); // Invoke the program rule in get return value T1Parser.expr_return r = null; DateTime t0 = DateTime.Now; try { r = parser2.expr(); } catch (Exception e) { List <string> temp = new List <string>(); temp.Add(e.Message); string input2 = textInput + "\r\n"; if (file) { Translator2.PrintError(e.Message, true); G.Writeln2("*** ERROR: Could not parse the file"); throw new GekkoException(); //this will make a double error -- but the other one will be identified later on (both text and filename are null) and skipped -- a little bit hacky, but oh well... } else { return(""); } } if (parser2.GetErrors().Count > 0) { List <string> errors = parser2.GetErrors(); if (file) { foreach (string s in errors) { Translator2.PrintError(s, false); } G.Writeln2("*** ERROR: Could not parse the file"); throw new GekkoException(); //this will make a double error -- but the other one will be identified later on (both text and filename are null) and skipped -- a little bit hacky, but oh well... } else { return(""); } } t = (CommonTree)r.Tree; StringBuilder sb = new StringBuilder(); GekkoDictionary <string, string> scalars = new GekkoDictionary <string, string>(StringComparer.OrdinalIgnoreCase); hasBeenEndoExo = false; hasBeenCmdCall = false; PrintAST(t, 0, sb, scalars); List <string> xxx = G.ExtractLinesFromText(sb.ToString()); string sss = null; foreach (string s in xxx) { string s2 = s; if (s2 == ";") { s2 = ""; } s2 = s2.Replace(";;", ";"); s2 = s2.Replace("; ;", ";"); string alphabet = "abcdefghijklmnopqrstuvwxyz"; foreach (char c in alphabet) { string s5 = c.ToString(); string s6 = c.ToString().ToUpper(); s2 = s2.Replace(";" + s5, "; " + s5); s2 = s2.Replace(";" + s6, "; " + s6); } s2 = s2.Replace("__dollar__", "$"); sss += s2 + G.NL; } return(sss); }
private static void TranslateLine(List <string> xxxx, string lineNumber) { string translated = null; bool isGekko18 = false; if (G.equal(Program.options.interface_mode, "sim")) { translated = Translators.Translate1(false, xxxx); isGekko18 = true; } else { translated = Translator2.Translate2(false, xxxx); } List <string> translatedLines = G.RemoveEmptyLines(G.ExtractLinesFromText(translated)); string before = G.ExtractTextFromLines(xxxx).ToString(); string after = G.ExtractTextFromLines(translatedLines).ToString(); after = after.Replace(Globals.restartSnippet, ""); before = before.Replace(" ", ""); after = after.Replace(" ", ""); before = before.Replace("\r\n", ""); after = after.Replace("\r\n", ""); if (before.EndsWith(";")) { before = before.Substring(0, before.Length - 1); } if (after.EndsWith(";")) { after = after.Substring(0, after.Length - 1); } before = before.ToLower().Trim(); after = after.ToLower().Trim(); if (before == "" || after == "") { //do nothing } else { if (before == after) { //do nothing } else { if (isGekko18) { G.Writeln2(" Suggestion (translating from Gekko 1.8 syntax):"); } else { G.Writeln2(" Suggestion (translating from AREMOS syntax):"); } foreach (string s12 in translatedLines) { if (s12.Trim() == Globals.restartSnippet) { continue; //skip that here, only good for files } G.Writeln(" --> " + lineNumber + " " + s12, Color.Blue); } G.Writeln(); } } }