public void Visit(ProgramNode program)
 {
     Emit("var stack = [];");
     foreach (var function in program.Functions)
     {
         function.Accept(this);
     }
     Emit("Main();");
 }
 public void Visit(ProgramNode program)
 {
     _labelCount = 0;
     _innermostWhileLabelIndex = null;
     EmitHead();
     foreach (var function in program.Functions)
     {
         function.Accept(this);
     }
 }
 public void FindSymbols(ProgramNode program)
 {
     // We want functions to be callable independently of their declaration order, so we do a first pass to find all function names
     foreach (var function in program.Functions)
     {
         var entry = new SymbolTableEntry(function.Name.Name, SymbolTableEntryType.Function, 0);
         AddSymbol(function.Name.Name, entry);
     }
     foreach (var function in program.Functions)
     {
         _scopeStack.PushScope(function.Name.Name);
         int unused = 0;
         EnterIdentifiers(function.Parameters, SymbolTableEntryType.Parameter, ref unused);
         int localVariableIndex = 0;
         FindSymbolsRecursively(function.Body, ref localVariableIndex);
         _scopeStack.PopScope();
         function.LocalVariableCount = localVariableIndex;
     }
 }
Exemple #4
0
        /// <summary>
        /// Performs the compilation process
        /// </summary>
        public void Compile()
        {
            // Tokenize
            Write("Tokenising...");
            List <Token> tokens = Tokenizer.GetAllTokens();

            if (Reporter.HasErrors)
            {
                return;
            }
            WriteLine("Done");

            //WriteLine(string.Join("\n", tokens));

            //Parse
            Write("Parsing...");
            //Parser.Parse(tokens);
            ProgramNode tree = Parser.Parse(tokens);

            if (Reporter.HasErrors)
            {
                WriteLine("ERRORS");
                return;
            }
            WriteLine("Done");
            //WriteLine(TreePrinter.ToString(tree));

            Write("Identifying...");
            Identifier.PerformIdentification(tree);
            if (Reporter.HasErrors)
            {
                return;
            }
            WriteLine("Done");
            //WriteLine(TreePrinter.ToString(tree));

            //Type checking
            Write("Type Checking...");
            Checker.PerformTypeChecking(tree);
            if (Reporter.HasErrors)
            {
                return;
            }
            WriteLine("Done");
            WriteLine(TreePrinter.ToString(tree));

            // Code generation
            Write("Generating code...");
            TargetCode targetCode = Generator.GenerateCodeFor(tree);

            if (Reporter.HasErrors)
            {
                return;
            }
            WriteLine("Done");

            // Output
            Write("Writing to file...");
            Writer.WriteToFiles(targetCode);
            if (Reporter.HasErrors)
            {
                return;
            }
            WriteLine("Done");
        }
 public void Generate(ProgramNode program)
 {
     Visit(program);
 }
Exemple #6
0
 public void Generate(ProgramNode program)
 {
     Visit(program);
 }
Exemple #7
0
 public SyntaxTree(ProgramNode root = null, string programName = null)
 {
     this.root        = root;
     this.programName = programName;
 }
Exemple #8
0
 public void VisitProgramNode(ProgramNode node)
 {
 }