示例#1
0
        private void Param(VarInfo fn)
        {
            var type = Type();
            var id   = L(LexType.Tident);
            var v    = AddVar(id, type);

            fn.AddParam(v);
        }
示例#2
0
 private void Params(VarInfo fn)
 {
     Param(fn);
     Maybe(() => Many(() =>
     {
         L(LexType.Tcomma);
         Param(fn);
     }));
 }
示例#3
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, ""));
        }
示例#4
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);
        }
示例#5
0
 public void AddParam(VarInfo var)
 {
     Params.Add(var);
 }