예제 #1
0
 /// <summary>
 /// Indicates that the given sub-expression is the next expected, giving it a
 /// name and specifying whether it is required.
 /// </summary>
 /// <param name="itemName">The name that the token will be identified with in the outer expression.</param>
 /// <param name="definition">The definition for the sub-expression.</param>
 /// <returns>The updated expression.</returns>
 public Options Add(string itemName, ExpressionDefinition definition)
 {
     if (definition == null)
     {
         throw new ArgumentNullException("definition");
     }
     IExpressionItem item = new Expression(definition);
     options.Add(new ExpressionItem(itemName, false, item));
     return this;
 }
예제 #2
0
        public List <LookaheadPropogation> DetermineLookaheads(ExpressionDefinition x)
        {
            List <LookaheadPropogation> result = new List <LookaheadPropogation>();

            if (!Transitions.Keys.Contains(x))
            {
                return(result);
            }

            foreach (Item item in KernelItems())
            {
                ItemSet j = new ItemSet(
                    new List <Item>()
                {
                    new Item(item.SubProduction,
                             0,
                             new HashSet <TerminalExpressionDefinition>()
                    {
                        new TerminalExpressionDefinition {
                            TokenType = TokenType.Hash
                        }
                    }
                             )
                }
                    );

                foreach (Item closureItem in j.KernelItems())
                {
                    if (closureItem.ExpressionAfterDot != null &&
                        closureItem.ExpressionAfterDot.IsEqualTo(x))
                    {
                        Item i = Transitions[x].First(xx => xx.IsEqualTo(closureItem, true));

                        if (!closureItem.Lookahead.Any(y => y.TokenType == TokenType.Hash))
                        {
                            i.AddLookaheads(closureItem.Lookahead.Except(i.Lookahead));
                        }
                        else
                        {
                            result.Add(new LookaheadPropogation
                            {
                                FromItem = item,
                                FromSet  = this,
                                ToSet    = Transitions[x],
                                ToItem   = i
                            });
                        }
                    }
                }
            }

            return(result);
        }
예제 #3
0
 /// <summary>
 /// Creates or retrieves the expression definition associated with the given name.
 /// </summary>
 /// <param name="type">The identifier to use to refer to the expression type later.</param>
 /// <returns>The expression definition to allow for configuration.</returns>
 public ExpressionDefinition Define(string type)
 {
     if (String.IsNullOrWhiteSpace(type))
     {
         throw new ArgumentException(Resources.BlankExpressionType, "type");
     }
     ExpressionDefinition definition;
     if (!expressionLookup.TryGetValue(type, out definition))
     {
         definition = new ExpressionDefinition(type);
         expressionLookup.Add(type, definition);
     }
     return definition;
 }
예제 #4
0
        public ExpressionInstanceVM()
        {
            Reset = new DelegateCommand<object>(ResetHandler);
            Close = new DelegateCommand<object>(CloseHandler);

            _inputs = new ObservableCollection<ObservableInputVM>();
            Inputs = new ReadOnlyObservableCollection<ObservableInputVM>(_inputs);

            if (IsInDesignMode())
            {
                Definition = new ExpressionDefinition("Zip", "To jest opis Zip ... ", "(a,b) => z.Zip(b, (x,y) => x + y)");
                _inputs.Add(new ObservableInputVM());
                Output = new ObservableOutputVM();
            }
        }
예제 #5
0
        public ItemSet Goto(ExpressionDefinition expression)
        {
            ItemSet result = new ItemSet();

            foreach (Item item in this)
            {
                if (item.ExpressionAfterDot != null &&
                    item.ExpressionAfterDot.IsEqualTo(expression))
                {
                    Item cloned = item.Clone(true);
                    result.Add(cloned);
                }
            }

            return(result.Closure());
        }
예제 #6
0
        internal static Expression Create(ExpressionDefinition x)
        {
            if (x is NonTerminalExpressionDefinition nted)
            {
                return(new NonTerminalExpression {
                    Identifier = nted.Identifier, Key = nted.Key
                });
            }
            if (x is TerminalExpressionDefinition ted)
            {
                return(new TerminalExpression {
                    TokenType = ted.TokenType, Key = ted.Key
                });
            }

            return(null);
        }
예제 #7
0
 /// <summary>
 /// Initializes a new instance of an Expression.
 /// </summary>
 /// <param name="expression">The sequence of tokens and sub-expressions expected to appear.</param>
 internal Expression(ExpressionDefinition expression)
 {
     this.expression = expression;
 }
예제 #8
0
 public ExpressionInstanceVM(ExpressionDefinition definition)
     : this()
 {
     Definition = definition;
     Reset.Execute(null);
 }
예제 #9
0
 /// <summary>
 /// Creates a sub-expression definition.
 /// </summary>
 /// <returns>The expression definition to allow for configuration.</returns>
 public ExpressionDefinition Define()
 {
     ExpressionDefinition definition = new ExpressionDefinition(null);
     return definition;
 }
예제 #10
0
 public abstract bool IsEqualTo(ExpressionDefinition definition);