Beispiel #1
0
        static SymbolBase ParseLocField(string locField, ParsingStatus status)
        {
            if (locField == "")
            {
                return(null);
            }

            status.LineSection = LineSection.LocationField;

            var symbol = ValueSymbol.ParseDefinition(locField, 0, status);

            if (symbol == null)
            {
                status.ReportParsingError(0, locField.Length, "invalid symbol name");
                return(null);
            }

            if (status.Symbols.Contains(symbol))
            {
                symbol = status.Symbols[symbol.Name];

                if (symbol.IsSymbolDefined && !symbol.IsMultiValuedSymbol)
                {
                    status.ReportParsingError(0, locField.Length, "symbol already defined");
                    return(null);
                }

                return(symbol);
            }

            status.Symbols.Add(symbol);
            return(symbol);
        }
Beispiel #2
0
 public override int GetHashCode()
 {
     return(Hash.Combine(ValueSymbol.GetHashCode(),
                         Hash.Combine(ValueExpression.GetHashCode(),
                                      Hash.Combine(ValueDiagnostics.GetHashCode(),
                                                   Hash.Combine(TypeExpression.GetHashCode(), TypeDiagnostics.GetHashCode())))));
 }
Beispiel #3
0
 public static void AddMethod(
     this IEnv env,
     ValueSymbol klass,
     string selectorName,
     Subr subrValue,
     int paramCount = 0,
     bool allowRest = false,
     bool allowKeys = false
 )
 {
     string subrName = string.Format(
         "{0}:{1}",
         klass.Name.ToIdentifier(),
         selectorName.ToIdentifier()
     );
     AddMethod(
         env, klass, selectorName,
         new ValueSubr(
             subrName,
             subrValue,
             paramCount,
             allowRest,
             allowKeys
         )
     );
 }
Beispiel #4
0
        public static IValue ParseValue(string text, int sectionCharIndex, ParsingStatus status)
        {
            if (text.Length == 0)
            {
                return(new NumberValue(0L));
            }

            // it can be either a literal value...
            var value = ValueSymbol.ParseValue(text, sectionCharIndex, status);

            if (value != null)
            {
                return(value);
            }

            // ... a literal constant...
            value = LiteralConstantSymbol.ParseValue(text, sectionCharIndex, status);
            if (value != null)
            {
                return(value);
            }

            // ... or an expression
            return(ExpressionValue.ParseValue(text, sectionCharIndex, status));
        }
Beispiel #5
0
 public ExprGetMethod(
     IExpr klassExpr,
     ValueSymbol selector,
     SourceInfo info
 )
 {
     KlassExpr = klassExpr;
     Selector = selector;
     mInfo = info;
 }
Beispiel #6
0
 public static void AddMethod(
     this IEnv env,
     ValueSymbol klass,
     string selectorName,
     IValueFunc func
 )
 {
     env.AddMethod(
         klass, ValueSymbol.Intern(selectorName), func
     );
 }
Beispiel #7
0
 public ExprSetMethod(
     IExpr klassExpr,
     ValueSymbol selector,
     IExpr valueExpr,
     SourceInfo info
 )
 {
     mKlassExpr = klassExpr;
     mSelector = selector;
     mValueExpr = valueExpr;
     mInfo = info;
 }
Beispiel #8
0
        void MSetButton_Click(object sender, EventArgs e)
        {
            if (mSymbols == null)
            {
                mSymbols = new SymbolCollection();
            }

            string symbolName      = mSymbolNameTextBox.Text;
            long   symbolMagnitude = mSymbolValueTextBox.Magnitude;

            Word.Signs  symbolSign  = mSymbolValueTextBox.Sign;
            SymbolBase  symbol      = mSymbols[symbolName];
            ValueSymbol valueSymbol = null;

            if (symbol != null)
            {
                valueSymbol = symbol as ValueSymbol;
                if (valueSymbol == null)
                {
                    return;
                }

                valueSymbol.SetValue(symbolSign, symbolMagnitude);
                var valueText = symbolMagnitude.ToString();
                if (symbolSign.IsNegative())
                {
                    valueText = '-' + valueText;
                }

                mListView.Items[symbolName].SubItems[valueFieldIndex].Text = valueText;
            }
            else
            {
                valueSymbol = ValueSymbol.ParseDefinition(symbolName) as ValueSymbol;

                if (valueSymbol == null)
                {
                    return;
                }

                valueSymbol.SetValue(symbolSign, symbolMagnitude);

                mSymbols.Add(valueSymbol);
                ShowSymbol(valueSymbol);
            }

            SetEnabledStates();
        }
Beispiel #9
0
        private IValueSymbol GetIValueSymbol(ISymbolLoader loader, ValueSymbol symbol)
        {
            try
            {
                // get value symbol
                IValueSymbol valueSymbol = (IValueSymbol)loader.Symbols[symbol.InstancePath];
                if (valueSymbol == null)
                {
                    return(null);
                }

                // set the nofication
                valueSymbol.NotificationSettings = new NotificationSettings(AdsTransMode.OnChange, symbol.CycleTime, symbol.MaxDelay);
                return(valueSymbol);
            }
            catch (System.Exception)
            {
                return(null);
            }
        }
Beispiel #10
0
 public static void DefineMethod(
     this IEnv env,
     ValueSymbol klass,
     ValueSymbol selector,
     IValueFunc func,
     SourceInfo info
 )
 {
     /*if (env.ContainsMethod(klass, selector))
     {
         throw new RheaException(
             string.Format(
                 "method is already defined: {0}:{1}",
                 klass.Name.ToIdentifier(),
                 selector.Name.ToIdentifier()
             ),
             info
         );
     }
     env.AddMethod(klass, selector, func);*/
     env[klass, selector] = func;
 }
Beispiel #11
0
        public static IValue ParseValue(string text, int sectionCharIndex, ParsingStatus status)
        {
            IValue value = null;

            value = NumberValue.ParseValue(text, sectionCharIndex, status);

            if (value == null)
            {
                value = LocationCounterValue.ParseValue(text, sectionCharIndex, status);
                if (value != null)
                {
                    return(value);
                }

                value = ValueSymbol.ParseValue(text, sectionCharIndex, status);
                if (value != null && !value.IsValueDefined(status.LocationCounter))
                {
                    status.ReportParsingError(sectionCharIndex, text.Length, "symbol " + text + " not defined");
                }
            }

            return(value);
        }
Beispiel #12
0
        void SetEnabledStates(bool updateSelectedItem)
        {
            string symbolName = mSymbolNameTextBox.Text;

            mSetButton.Enabled   = ValueSymbol.IsValueSymbolName(symbolName) && mSymbolValueTextBox.TextLength > 0;
            mUnsetButton.Enabled = mSymbols != null && mSymbols.Contains(symbolName);

            if (updateSelectedItem)
            {
                if (mUnsetButton.Enabled)
                {
                    ListViewItem symbolItem = mListView.Items[symbolName];
                    symbolItem.Selected = true;
                    symbolItem.EnsureVisible();
                }
                else
                {
                    foreach (ListViewItem item in mListView.Items)
                    {
                        item.Selected = false;
                    }
                }
            }
        }
Beispiel #13
0
 public bool ContainsVariable(ValueSymbol symbol)
 {
     return mInnerEnv.ContainsVariable(symbol);
 }
Beispiel #14
0
 public bool TryGetMethod(ValueSymbol klass, ValueSymbol selector, out IValueFunc func)
 {
     return mInnerEnv.TryGetMethod(klass, selector, out func);
 }
Beispiel #15
0
 public void AddVariable(ValueSymbol symbol, IValue value)
 {
     mInnerEnv.AddVariable(symbol, value);
 }
Beispiel #16
0
 public bool ContainsMethod(ValueSymbol klass, ValueSymbol selector)
 {
     return mInnerEnv.ContainsMethod(klass, selector);
 }
Beispiel #17
0
 public IValueFunc this[ValueSymbol klass, ValueSymbol selector]
 {
     get { return mInnerEnv[klass, selector]; }
     set { mInnerEnv[klass, selector] = value; }
 }
Beispiel #18
0
 public void AddMethod(ValueSymbol klass, ValueSymbol selector, IValueFunc func)
 {
     mInnerEnv.AddMethod(klass, selector, func);
 }
Beispiel #19
0
 public static IValue GetVariable(
     this IEnv env,
     ValueSymbol symbol,
     SourceInfo info
 )
 {
     IValue value;
     if (!LookupVariable(env, symbol, out value))
     {
         throw new RheaException(
             string.Format(
                 "variable is not defined: {0}",
                 symbol.Name.ToIdentifier()
             ),
             info
         );
     }
     return value;
 }
Beispiel #20
0
 public static IValue SetVariable(
     this IEnv env,
     ValueSymbol symbol,
     IValue value,
     SourceInfo info
 )
 {
     while (!env.IsGlobal())
     {
         if (env.ContainsVariable(symbol))
         {
             env[symbol] = value;
             return value;
         }
         env = env.OuterEnv;
     }
     if (env.ContainsVariable(symbol))
     {
         env[symbol] = value;
         return value;
     }
     throw new RheaException(
         string.Format(
             "variable is not defined: {0}",
             symbol.Name.ToIdentifier()
         ),
         info
     );
 }
Beispiel #21
0
 public InsnDefMethod(ValueSymbol selector, SourceInfo info)
 {
     mSelector = selector;
     mInfo = info;
 }
Beispiel #22
0
 public static bool LookupVariable(
     this IEnv env,
     ValueSymbol symbol,
     out IValue value
 )
 {
     while (!env.IsGlobal())
     {
         if (env.TryGetVariable(symbol, out value))
         {
             return true;
         }
         env = env.OuterEnv;
     }
     if (env.TryGetVariable(symbol, out value))
     {
         return true;
     }
     return false;
 }
Beispiel #23
0
 public static IValue SetMethod(
     this IEnv env,
     ValueSymbol klass,
     ValueSymbol selector,
     IValueFunc func,
     SourceInfo info
 )
 {
     while (!env.IsGlobal())
     {
         if (env.ContainsMethod(klass, selector))
         {
             env[klass, selector] = func;
             return func;
         }
         env = env.OuterEnv;
     }
     if (env.ContainsMethod(klass, selector))
     {
         env[klass, selector] = func;
         return func;
     }
     throw new RheaException(
         string.Format(
             "method is not defined: {0}:{1}",
             klass.Name.ToIdentifier(),
             selector.Name.ToIdentifier()
         ),
         info
     );
 }
Beispiel #24
0
 public static void DefineVariable(
     this IEnv env,
     ValueSymbol symbol,
     IValue value,
     SourceInfo info
 )
 {
     /*if (env.ContainsVariable(symbol))
     {
         throw new RheaException(
             string.Format(
                 "variable is already defined: {0}",
                 symbol.Name.ToIdentifier()
             ),
             info
         );
     }
     env.AddVariable(symbol, value);*/
     env[symbol] = value;
 }
Beispiel #25
0
 public abstract ValueSymbol GetValue(ValueSymbol val_1, ValueSymbol val_2);
Beispiel #26
0
 public bool TryGetVariable(ValueSymbol symbol, out IValue value)
 {
     return mInnerEnv.TryGetVariable(symbol, out value);
 }
Beispiel #27
0
 public IValue this[ValueSymbol symbol]
 {
     get { return mInnerEnv[symbol]; }
     set {  mInnerEnv[symbol] = value; }
 }
Beispiel #28
0
 public ExprDefVar(ValueSymbol symbol, IExpr valueExpr, SourceInfo info)
 {
     mSymbol = symbol;
     mValueExpr = valueExpr;
     mInfo = info;
 }
Beispiel #29
0
 public static IValue GetMethod(
     this IEnv env,
     ValueSymbol klass,
     ValueSymbol selector,
     SourceInfo info
 )
 {
     IValueFunc func;
     if (!LookupMethod(env, klass, selector, out func))
     {
         throw new RheaException(
             string.Format(
                 "method is not defined: {0}:{1}",
                 klass.Name.ToIdentifier(),
                 selector.Name.ToIdentifier()
             ),
             info
         );
     }
     return func;
 }
Beispiel #30
0
 public override ValueSymbol GetValue(ValueSymbol val_1, ValueSymbol val_2)
 {
     return(new ValueSymbol(val_1.GetValue() - val_2.GetValue()));
 }
Beispiel #31
0
 public static bool LookupMethod(
     this IEnv env,
     ValueSymbol klass,
     ValueSymbol selector,
     out IValueFunc func
 )
 {
     while (!env.IsGlobal())
     {
         if (env.TryGetMethod(klass, selector, out func))
         {
             return true;
         }
         env = env.OuterEnv;
     }
     if (env.TryGetMethod(klass, selector, out func))
     {
         return true;
     }
     return false;
 }
Beispiel #32
0
 public InsnDefVar(ValueSymbol symbol, SourceInfo info)
 {
     mSymbol = symbol;
     mInfo = info;
 }
Beispiel #33
0
 public ExprGetVar(ValueSymbol symbol, SourceInfo info)
 {
     Symbol = symbol;
     mInfo = info;
 }