Beispiel #1
0
        public Parser(SymbolTable symbols, Scanner scanner)
        {
            _symbols = symbols;
            _scanner = scanner;

            _lookahead = _scanner.ReadToken();
        }
Beispiel #2
0
        public Checker(SymbolTable symbols, AST.Program program)
        {
            _symbols = symbols;
            _program = program;

            // create the standard set of predefined identifiers that Triangle defines
            CreateStandardEnvironment();

            // start walking the AST from the topmost node
            _program.visit(this);
        }
Beispiel #3
0
 public CodeGen(SymbolTable symbols, AST.Program program)
 {
     _symbols = symbols;
     _program = program;
     _program.visit(this);
 }
Beispiel #4
0
        static int Main(string[] args)
        {
            int result = 0;

            try
            {
            #if false
                StreamReader sr = new StreamReader(args[0]);
                Scanner scanner = new Scanner(args[0], sr, 4);
                for (; ; )
                {
                    Token token = scanner.ReadToken();
                    Console.WriteLine(token.Position.ToString() + ":" + token.ToString());

                    if (token.Kind == TokenKind.EndOfFile)
                        break;
                }
                sr.Close();
                Console.ReadLine();
            #else
                // expand wildcards
                string[] found = Toolbox.Find(args, false);

                // process each input file in turn
                foreach (string arg in found)
                {
                    SymbolTable symbols = new SymbolTable();
                    StreamReader reader = new StreamReader(arg);
                    Scanner scanner = new Scanner(arg, reader, 4);
                    Parser parser = new Parser(symbols, scanner);
                    AST.Program program = parser.ParseProgram();
                    Checker checker = new Checker(symbols, program);
                    Indenter indenter = new Indenter(arg + ".log", System.Text.Encoding.ASCII);
                    try
                    {
                        program.Dump(indenter);
                    }
                    finally
                    {
                        indenter.Close();
                    }
                    new CodeGen(symbols, program);
                    Console.WriteLine("Press ENTER");
                    Console.ReadLine();
                }
            #endif
            }
            catch (BerylError that)
            {
                if (that.Position == null)
                    Console.WriteLine("Error: {0}", that.Message);
                else
                    Console.WriteLine("{0} Error: {1}", that.Position.ToString(), that.Message);
                result = 1;
            }
            #if false
            catch (System.Exception that)
            {
                Console.WriteLine("Error: {0}", that.Message);
                result = 1;
            }
            #endif

            return result;
        }