Exemplo n.º 1
0
            public override object VisitParameter_definition([NotNull] scheme_langParser.Parameter_definitionContext context)
            {
                //Add parameter to scheme
                string type = context.variable_type()?.GetText();
                string name = context.variable_name()?.GetText();

                if (type == null || name == null)
                {
                    return(base.VisitParameter_definition(context));
                }

                if (CompiledScheme.GetVariableByName(name) != null || CompiledScheme.GetParameterByName(name) != null)
                {
                    Errors.Add(new ErrorDescriptor($"Variable or parameter '{name}' already exists.", context.variable_name()));
                }
                else if (!VariableManager.IsTypeValid(type, Config))
                {
                    Errors.Add(new ErrorDescriptor($"Type '{type}' is not recognized.", context.variable_type()));
                }
                else
                {
                    ObjectVariable param = new ObjectVariable(type, name, null);
                    CompiledScheme.AddParameter(param);
                }

                return(base.VisitParameter_definition(context));
            }
Exemplo n.º 2
0
            /* CODE BUILDING */

            private ObjectVariable CreateVariableFromContext(scheme_langParser.Variable_definitionContext context)
            {
                string type  = context.variable_type().GetText();
                string name  = context.variable_name().GetText();
                object value = null;

                if (CompiledScheme.GetVariableByName(name) != null || CompiledScheme.GetParameterByName(name) != null)
                {
                    Errors.Add(new ErrorDescriptor($"Variable or parameter '{name}' already exists.", context));
                    return(null);
                }

                return(new ObjectVariable(type, name, value));
            }
Exemplo n.º 3
0
            public override object VisitBody_variable_definition([NotNull] scheme_langParser.Body_variable_definitionContext context)
            {
                //Add predefined variable to scheme
                var variable_definition = context.variable_definition();

                string type = variable_definition?.variable_type()?.GetText();
                string name = variable_definition?.variable_name()?.GetText();

                if (type == null || name == null)
                {
                    return(base.VisitBody_variable_definition(context));
                }

                if (!VariableManager.IsTypeValid(type, Config))
                {
                    Errors.Add(new ErrorDescriptor($"Type '{type}' is not recognized.", variable_definition.variable_type()));
                }

                if (CompiledScheme.GetVariableByName(name) != null || CompiledScheme.GetParameterByName(name) != null)
                {
                    Errors.Add(new ErrorDescriptor($"Variable or parameter '{name}' already exists.", variable_definition.variable_name()));
                    if (variable_definition.EQUALS() != null)
                    {
                        SetNewExpression(1);
                    }
                    return(base.VisitBody_variable_definition(context));
                }

                ObjectVariable variable = new ObjectVariable(type, name, null);

                if (variable != null)
                {
                    CompiledScheme.AddVariable(variable);

                    CommandSetVariable cmd = new CommandSetVariable(variable_definition.variable_name().GetText(), GetRegName(0));
                    currentFunc.AddCommand(cmd);
                    SetNewExpression(1);
                }

                return(base.VisitBody_variable_definition(context));
            }