public void VisitBinOp(BinOp node) { if (node.Op.Type == TokenType.Assign) { var symbol = _symbols.Lookup(((Variable)node.Left).Name, true); if (symbol == null) { throw new Exception($"Variable '{((Variable)node.Left).Name}' haven't been declared"); } if (!(symbol is LetSymbol)) { throw new Exception($"Cannot assign value to symbol of type {symbol.GetType()}"); } } else { Visit(node.Left); } Visit(node.Right); }
public Symbol Lookup(string name, bool followParent = false) { return(!_symbols.ContainsKey(name) ? followParent ? _parent?.Lookup(name, true) : null : _symbols[name]); }