Beispiel #1
0
        public ConstDefinition(CodeRange start, Identifier id, LaxExpression value) : base(start, id)
        {
            if (value == null)
                throw new ArgumentNullException("value");

            this.Value = value;
        }
Beispiel #2
0
        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;
        }
Beispiel #3
0
 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;
 }
Beispiel #4
0
 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;
 }
Beispiel #6
0
 public FuncDefinition(CodeRange pos, Identifier name) : base(pos, name)
 {
 }
Beispiel #7
0
 public FuncDefinition(Identifier name) : base(CodeRange.Zero, name)
 {
 }
Beispiel #8
0
 public VarDefinition(CodeRange start, Identifier id) : base(start, id)
 {
 }
Beispiel #9
0
 public FunctionCall(CodeRange pos, Identifier functionName) : base(ExprType.FunctionCall)
 {
     CodeRange = pos;
     Name = functionName;
 }
Beispiel #10
0
 public UnitDefinition(CodeRange start, Identifier name) : base(start, name)
 {
 }
Beispiel #11
0
 public static VarDefinition GetVariable(this Block block, Identifier id)
 {
     return block.Variables[id];
 }
Beispiel #12
0
        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);
        }
Beispiel #13
0
 public Unit(Identifier name)
 {
     AddExponent(name, 1);
 }
Beispiel #14
0
        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);
            }
        }