Пример #1
0
        private VarInfo AddVar(Lexema var, SemType type)
        {
            var name         = var.Tok;
            var currentFrame = environment.Last();

            if (currentFrame.ContainsKey(name))
            {
                var prev = currentFrame[name];
                throw new SemanticException($"Cannot redefine variable: `{name}`", var,
                                            $"previous declaration at {prev.Location.Line}:{prev.Location.Symbol}");
            }
            return(currentFrame[name] = VarInfo.Of(type, var, ""));
        }
Пример #2
0
        private VarInfo AddVar(Lexema var, SemType type)
        {
            var name         = var.Tok;
            var currentFrame = environment.Last();

            if (currentFrame.ContainsKey(name))
            {
                var prev = currentFrame[name];
                throw new SemanticException($"Cannot redefine variable: `{name}`", var,
                                            $"previous declaration at {prev.Location.Line}:{prev.Location.Symbol}");
            }

            var varInfo = VarInfo.Of(type, var, Scope, allocSize);

            if (type != SemType.Function)
            {
                allocSize += GetSize(type);
                allocMax   = Math.Max(allocSize, allocMax);
            }

            return(currentFrame[name] = varInfo);
        }