Esempio n. 1
0
        public BuiltinNames(SymbolTable table)
        {
            int x = table.Register("x");
            int y = table.Register("y");

            _names = new Dictionary<string, Expression>();
            _names.Add("_True", CreateBool(true));
            _names.Add("_False", CreateBool(false));
            _names.Add("_Zero", CreateInteger(0));
            _names.Add("_Successor", new AbstractionExpression
            {
                Left = new SymbolRef(x),
                Right = new BuiltinExpression
                {
                    Left = new BoundSymbolExpression { Symbol = new SymbolRef(x) },
                    Right = null,
                    Evaluate = _SuccessorEvaluate
                }
            });
            _names.Add("_Null", new FreeSymbolExpression { Name = "_List", Tag = null, Display = _ListDisplay });
            _names.Add("_Nothing", new FreeSymbolExpression { Name = "_Maybe", Tag = null, Display = _MaybeDisplay });
        }
Esempio n. 2
0
        private static Expression ParseAbstractionExpression(IEnumerator<Token> tokens, SymbolTable table)
        {
            if (tokens.Current.Type == TokenType.Symbol && tokens.Current.Text == "\\")
            {
                tokens.MoveNext();
                var bindList = ParseBindList(tokens);

                if (tokens.Current.Type == TokenType.Symbol && tokens.Current.Text == ".")
                {
                    SymbolTable childTable = new SymbolTable(table);
                    var bindIdList = new List<int>(bindList.Count);

                    for (int i = 0; i < bindList.Count; i++)
                        bindIdList.Add(childTable.Register(bindList[i]));

                    tokens.MoveNext();
                    var rest = ParseAbstractionExpression(tokens, childTable);

                    Expression rhs = rest;

                    for (int i = 0; i < bindIdList.Count; i++)
                    {
                        rhs = new AbstractionExpression { Left = new SymbolRef(bindIdList[bindIdList.Count - i - 1]), Right = rhs };
                    }

                    return rhs;
                }
                else
                {
                    throw new Exception("'.' expected");
                }
            }
            else
            {
                return ParseApplicationExpression(tokens, table);
            }
        }