public ConstDefinition(CodeRange start, Identifier id, LaxExpression value) : base(start, id) { if (value == null) throw new ArgumentNullException("value"); this.Value = value; }
protected Definition(CodeRange pos, Identifier name) { if (pos == null) throw new ArgumentNullException("pos"); if (name == null) throw new ArgumentNullException("name"); CodeRange = pos.Expand2(name); Name = name; }
public static Definition GetDefinition(this Block block, Identifier def) { { UnitDefinition unit; if (block.Units.TryGetValue(def, out unit)) return unit; } { ConstDefinition constant; if (block.Constants.TryGetValue(def, out constant)) return constant; } { VarDefinition variable; if (block.Variables.TryGetValue(def, out variable)) return variable; } { FuncDefinition function; if (block.Functions.TryGetValue(def, out function)) return function; } return null; }
public static string FormatIdentifier(Identifier i) { return i.Name; }
public static Identifier ToIdentifier(this Token token) { var it = (IdentifierToken)token; var exp = new Identifier(token.CodeRange, token.Name); return exp; }
public FuncDefinition(CodeRange pos, Identifier name) : base(pos, name) { }
public FuncDefinition(Identifier name) : base(CodeRange.Zero, name) { }
public VarDefinition(CodeRange start, Identifier id) : base(start, id) { }
public FunctionCall(CodeRange pos, Identifier functionName) : base(ExprType.FunctionCall) { CodeRange = pos; Name = functionName; }
public UnitDefinition(CodeRange start, Identifier name) : base(start, name) { }
public static VarDefinition GetVariable(this Block block, Identifier id) { return block.Variables[id]; }
Literal EvaluateVariable(Identifier variable) { Literal lit; if (variables.TryGetValue(variable, out lit)) { if (lit == null) throw new SemanticError(variable, "Unassinged variable"); return lit; } throw new SemanticError(variable, "Undefined variable: " + variable.Name); }
public Unit(Identifier name) { AddExponent(name, 1); }
void AddExponent(Identifier key, int value) { Debug.Assert(value != 0); if (value == 0) return; if (Exponent.ContainsKey(key)) { var r = Exponent[key] += value; if (r == 0) Exponent.Remove(key); } else { if (value != 0) Exponent.Add(key, value); } }