public override int VisitVariable(YarnSpinnerParser.VariableContext context)
        {
            string variableName = context.VAR_ID().GetText();
            compiler.Emit(ByteCode.PushVariable, variableName);

            return 0;
        }
Example #2
0
        public override Yarn.IType VisitVariable(YarnSpinnerParser.VariableContext context)
        {
            // The type of the value depends on the declared type of the
            // variable

            var name = context.VAR_ID()?.GetText();

            if (name == null)
            {
                // We don't have a variable name for this Variable context.
                // The parser will have generated an error for us in an
                // earlier stage; here, we'll bail out.
                return(BuiltinTypes.Undefined);
            }

            foreach (var declaration in Declarations)
            {
                if (declaration.Name == name)
                {
                    return(declaration.Type);
                }
            }

            // We don't have a declaration for this variable. Return
            // Undefined. Hopefully, other context will allow us to infer a
            // type.
            return(BuiltinTypes.Undefined);
        }
Example #3
0
        public override int VisitVariable(YarnSpinnerParser.VariableContext context)
        {
            string variableName = context.VAR_ID().GetText();

            this.compiler.Emit(OpCode.PushVariable, context.Start, new Operand(variableName));

            return(0);
        }
Example #4
0
        public override Yarn.IType VisitVariable(YarnSpinnerParser.VariableContext context)
        {
            // The type of the value depends on the declared type of the
            // variable

            var name = context.VAR_ID()?.GetText();

            if (name == null)
            {
                // We don't have a variable name for this Variable context.
                // The parser will have generated an error for us in an
                // earlier stage; here, we'll bail out.
                return(BuiltinTypes.Undefined);
            }

            foreach (var declaration in Declarations)
            {
                if (declaration.Name == name)
                {
                    return(declaration.Type);
                }
            }

            // do we already have a potential warning about this?
            // no need to make more
            foreach (var hmm in deferredTypes)
            {
                if (hmm.Name == name)
                {
                    return(BuiltinTypes.Undefined);
                }
            }

            // creating a new diagnostic for us having an undefined variable
            // this won't get added into the existing diags though because its possible a later pass will clear it up
            // so we save this as a potential diagnostic for the compiler itself to resolve
            var diagnostic = new Diagnostic(sourceFileName, context, string.Format(CantDetermineVariableTypeError, name));

            deferredTypes.Add(DeferredTypeDiagnostic.CreateDeferredTypeDiagnostic(name, diagnostic));

            // We don't have a declaration for this variable. Return
            // Undefined. Hopefully, other context will allow us to infer a
            // type.
            return(BuiltinTypes.Undefined);
        }
Example #5
0
        public override Yarn.Type VisitVariable(YarnSpinnerParser.VariableContext context)
        {
            // The type of the value depends on the declared type of the
            // variable

            var name = context.VAR_ID().GetText();

            foreach (var declaration in Declarations)
            {
                if (declaration.Name == name)
                {
                    return(declaration.ReturnType);
                }
            }

            // We don't have a declaration for this variable. Return
            // Undefined. Hopefully, other context will allow us to infer a
            // type.
            return(Yarn.Type.Undefined);
        }
        // operatorEquals style operators, eg += these two should only be
        // called during a SET operation eg << set $var += 1 >> the left
        // expression has to be a variable the right value can be anything
        #region operatorEqualsCalls
        // generic helper for these types of expressions
        internal void opEquals(YarnSpinnerParser.VariableContext variable, YarnSpinnerParser.ExpressionContext expression, int op)
        {
            var varName = variable.GetText();

            // Get the current value of the variable
            compiler.Emit(OpCode.PushVariable, new Operand(varName));

            // run the expression
            Visit(expression);

            // Stack now contains [currentValue, expressionValue]

            // Indicate that we are pushing two items for comparison
            compiler.Emit(OpCode.PushFloat, new Operand(2));

            // now we evaluate the operator op will match to one of + - / *
            // %
            compiler.Emit(OpCode.CallFunc, new Operand(tokens[op].ToString()));

            // Stack now has the destination value now store the variable
            // and clean up the stack
            compiler.Emit(OpCode.StoreVariable, new Operand(varName));
            compiler.Emit(OpCode.Pop);
        }
 /// <summary>
 /// Visit a parse tree produced by <see cref="YarnSpinnerParser.variable"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitVariable([NotNull] YarnSpinnerParser.VariableContext context)
 {
     return(VisitChildren(context));
 }
 /// <summary>
 /// Exit a parse tree produced by <see cref="YarnSpinnerParser.variable"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitVariable([NotNull] YarnSpinnerParser.VariableContext context)
 {
 }