Exemple #1
0
        public override bool VisitForEachStatement(QuestScriptParser.ForEachStatementContext context)
        {
            _current = _current.CreateChild(context); //push
            var enumerationVariableType = TypeInferenceVisitor.Visit(context.enumerationVariable);

            if (enumerationVariableType != ObjectType.List)
            {
                Errors.Add(new UnexpectedTypeException(context, ObjectType.List, enumerationVariableType,
                                                       context.enumerationVariable, "'foreach' can only enumerate on collection types."));
            }

            if (!_current.IsVariableDefined(context.iterationVariable.Text))
            {
                DeclareLocalVariable(context.iterationVariable.Text, context, context.enumerationVariable,
                                     isEnumerationVariable: true);
            }
            else
            {
                Errors.Add(
                    new ConflictingVariableName(context, context.iterationVariable.Text,
                                                "Iteration variable names in 'foreach' statements must not conflict with already defined variables."));
            }

            var success = base.VisitForEachStatement(context);

            _current = _current.Parent; //pop
            return(success);
        }
Exemple #2
0
        public override bool VisitCodeBlockStatement(QuestScriptParser.CodeBlockStatementContext context)
        {
            _current = _current.CreateChild(context); //push
            var success = base.VisitCodeBlockStatement(context);

            _current = _current.Parent; //pop
            return(success);
        }
Exemple #3
0
 public override bool VisitScript(QuestScriptParser.ScriptContext context)
 {
     _root = new Environment
     {
         Context = context
     };
     _current = _root;
     return(base.VisitScript(context));
 }
Exemple #4
0
        public override bool VisitWhileStatement(QuestScriptParser.WhileStatementContext context)
        {
            //if while has a code block, no need for opening a scope
            var shouldOpenNewScope = !context.code.HasDescendantOfType <QuestScriptParser.CodeBlockStatementContext>();

            if (shouldOpenNewScope)
            {
                _current = _current.CreateChild(context);                     //push
            }
            var success = base.VisitWhileStatement(context);

            if (shouldOpenNewScope)
            {
                _current = _current.Parent;                     //pop
            }
            return(success);
        }
Exemple #5
0
        public override bool VisitForStatement(QuestScriptParser.ForStatementContext context)
        {
            _current = _current.CreateChild(context); //push

            if (!_current.IsVariableDefined(context.iterationVariable.Text))
            {
                DeclareLocalVariable(context.iterationVariable.Text, context, ObjectType.Integer,
                                     ValueResolverVisitor.Visit(context.iterationStart), isIterationVariable: true);
            }
            else
            {
                Errors.Add(
                    new ConflictingVariableName(context, context.iterationVariable.Text,
                                                "Iteration variable names in 'for' statements must not conflict with already defined variables."));
            }

            var success = base.VisitForStatement(context);

            _current = _current.Parent; //pop
            return(success);
        }
Exemple #6
0
 internal ScriptEnvironment(Environment root, Dictionary <ParserRuleContext, Environment> environmentsByContext)
 {
     Root = root;
     _environmentsByContext = environmentsByContext;
 }