Example #1
0
 public Parser(Lexer lex)
 {
     lexer = lex;
     tokens = lexer.TokenList;
     FunctionTable = new FunctionTable();
     SymbolTable = new SymbolTableIndex();
 }
Example #2
0
        static void Main(string[] args)
        {
            if (1 == 0)
            {
            }
            else
            {
                Console.WriteLine("File to compile:");
                string file = Console.ReadLine();
                CodeGen gen = new CodeGen(file.Substring(0, file.LastIndexOf('.'))+".exe");
                if (args.Length == 100)
                    Fail();//we screwed up; no args
                else
                {
                    Console.WriteLine("Compilation started.");
                    string source = null;

                    if (args.Length >= 2)
                    {
                        switch (args[1])
                        {
                            case "-verbose":
                                {
                                    Compiler.Verbose = true;
                                    break;
                                }
                            default:
                                {
                                    Fail();
                                    break;
                                }

                        }
                    }

                    try
                    {
                        source = File.ReadAllText(file);
                    }
                    catch (IOException)
                    {
                        Console.WriteLine("Could not find or open {0}", file);
                        //WELL damn
                        Fail();
                    }

                    string sourceCode = "Define Void WriteLine(String sa): End. Define Void WriteLine(Int i): End." +
                        "Define Void Write(String sa): End. Define String ReadLine(): Return \"dummy\". End. " +
                        "Define Void WaitForInput(): String r = ReadLine(). End. " + source;

                    Lexer lexer = new Lexer(sourceCode);
                    lexer.GenerateTokenLists();
                    lexer.TokenList.Add(new Token(TokenType.EOF, null, lexer.TokenList.List.Last().LineNo + 1));
                    Parsing.Parser parser = new Parsing.Parser(lexer);
                    Node tree = parser.Parse();

                    //errors; don't start generating code
                    if (ErrorHandler.ErrorCount != 0)
                    {
                        ErrorHandler.End();
                    }

                    Console.WriteLine("Parsing successful");
                    gen.GenerateCode((RootNode)tree);
                    gen.FinalizeGeneration();
                    int i = 1;
                    Console.ReadLine();
                }
            }
        }