示例#1
0
        private LetCommand parseLet()
        {
            if (CurrentToken != null && accept(_let))
            {
                LetCommand curRoot = new LetCommand(prevLine);

                if (root == null)
                {
                    root = curRoot;
                }


                while (CurrentToken.getType() != _in)
                {
                    // accept(_in);
                    curRoot.addDeclaration(parseDeclaration());
                }

                accept(_in);
                while (CurrentToken.getType() != _end)
                {
                    curRoot.addCommand(parseCommand());
                }

                accept(_end);
                return(curRoot);
            }
            logError(CurrentToken, "Syntax error: Let required.");
            return(null);
        }
示例#2
0
        private void DoAnalyse(Command node)
        {
            if (node is LetCommand)
            {
                LetCommand letCommand = (LetCommand)node;
                DeclarationCheck(letCommand.SequentialDeclaration);
                AnalyseCommands(letCommand.SequentialCommand);
                RemoveScope(letCommand.SequentialDeclaration);
            }

            if (node is AssignCommand)
            {
                AssignCommand assignCommand = (AssignCommand)node;
                string        type          = "";
                AnalyseAssignment(assignCommand, type);
            }

            if (node is IfCommand)
            {
                IfCommand ifCommand = (IfCommand)node;
                AnalyzeCondition(ifCommand.Expression);
                DoAnalyse(ifCommand.ThenCommand);
                DoAnalyse(ifCommand.ElseCommand);
            }
        }
示例#3
0
 public Contextualiser(LetCommand root)
 {
     _compilerUtils = CompilerUtils.getInstance();
     this.root      = root;
     declaList      = new LinkedList <LinkedList <DeclarationCommand> >();
     table          = new Dictionary <string, string>();
 }
 public Void VisitLetCommand(LetCommand ast, Void arg)
 {
     _idTable.OpenScope();
     ast.Declaration.Visit(this);
     ast.Command.Visit(this);
     _idTable.CloseScope();
     return(null);
 }
示例#5
0
 public object visitLetCommand(LetCommand command, object arg)
 {
     idTable.openScope();
     command.declaration.visit(this, null);
     command.command.visit(this, null);
     idTable.closeScope();
     return(null);
 }
 public Void VisitLetCommand(LetCommand ast, Void arg)
 {
     System.Console.WriteLine("Visiting letCommand");
     idTable.OpenScope();
     ast.Declaration.Visit(this, null);
     ast.Command.Visit(this, null);
     idTable.CloseScope();
     return(null);
 }
示例#7
0
        public Void VisitLetCommand(LetCommand ast, Frame frame)
        {
            var extraSize = ast.Declaration.Visit(this, frame);

            ast.Command.Visit(this, frame.Expand(extraSize));
            if (extraSize > 0)
            {
                _emitter.Emit(OpCode.POP, (short)extraSize);
            }
            return(null);
        }
示例#8
0
 public void visit(LetCommand that)
 {
     Console.WriteLine("{");
     // note: function declarations should be output before the first line
     foreach (Declaration declaration in that.Declarations)
     {
         declaration.visit(this);
     }
     that.Command.visit(this);
     Console.WriteLine("}");
 }
示例#9
0
文件: Checker.cs 项目: bencz/Beryl
        public void visit(LetCommand that)
        {
            string name = CreateName();

            _symbols.EnterScope(name);
            foreach (Declaration declaration in that.Declarations)
            {
                declaration.visit(this);
            }
            that.Command.visit(this);
            _symbols.LeaveScope(name);
        }