private void Param(VarInfo fn) { var type = Type(); var id = L(LexType.Tident); var v = AddVar(id, type); fn.AddParam(v); }
private void Params(VarInfo fn) { Param(fn); Maybe(() => Many(() => { L(LexType.Tcomma); Param(fn); })); }
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, "")); }
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); }
public void AddParam(VarInfo var) { Params.Add(var); }