private JackProgram Parse(TokensStack sTokens) { JackProgram program = new JackProgram(); program.Parse(sTokens); return(program); }
private static bool TestParse() { try { Compiler sc = new Compiler(); List <string> lLines = sc.ReadFile(@"Program.Jack"); List <Token> lTokens = sc.Tokenize(lLines); TokensStack sTokens = new TokensStack(); for (int i = lTokens.Count - 1; i >= 0; i--) { sTokens.Push(lTokens[i]); } JackProgram prog = new JackProgram(); prog.Parse(sTokens); string sAfterParsing = prog.ToString(); sAfterParsing = sAfterParsing.Replace(" ", ""); sAfterParsing = sAfterParsing.Replace("\t", ""); sAfterParsing = sAfterParsing.Replace("\n", ""); sAfterParsing = sAfterParsing.ToLower(); string sAllTokens = ""; foreach (Token t in lTokens) { sAllTokens += GetName(t).ToLower(); } for (int i = 0; i < sAllTokens.Length; i++) { if (sAllTokens[i] != sAfterParsing[i]) { return(false); } } return(true); } catch (Exception e) { Console.WriteLine(e); } return(false); }