Пример #1
0
        private Statement ParseVarStatement()
        {
            Eat(TokenKind.KeywordVar);
            var varStart = GetStart();
            List<VarInitialization> vars = new List<VarInitialization>();
            VarInitialization cvar;
            NameExpression name;
            Expression defaultVal;

            do
            {
                NameToken nt = (NameToken)NextToken(TokenKind.Name);
                int start = GetStart(), end = GetEnd();
                var span = GetSourceSpan();
                defaultVal = MaybeEat(TokenKind.Assign) ? ParseExpression() : null;

                if (_sink != null)
                    _sink.StartName(span, nt.Name);

                name = new NameExpression(nt.Name);
                name.SetLoc(_globalParent, start, end);

                cvar = new VarInitialization(name, defaultVal);
                cvar.SetLoc(_globalParent, start, GetEnd());

                vars.Add(cvar);
            } while (MaybeEat(TokenKind.Comma));

            if (!EatSemiOrInteractiveEndOfFile())
                return null;

            Statement stmt = new VarStatement(vars.ToArray());
            stmt.SetLoc(_globalParent, varStart, GetEnd());
            return stmt;
        }
Пример #2
0
 public override bool Walk(VarStatement node)
 {
     node.Parent = _currentScope;
     return base.Walk(node);
 }