示例#1
0
        public Parameter(Cursor cursor, SymbolDefinition name, DirectionKind direction, Type type)
            : base(NodeKind.Parameter, cursor, name)
        {
            _direction = direction;

            _type = type;
            _type.Above = this;
        }
示例#2
0
        public Routine(
            NodeKind kind,
            Cursor cursor,
            SymbolDefinition name,
            Profile profile,
            Block block
        )
            : base(kind, cursor, name)
        {
            _profile = profile;
            _profile.Above = this;

            _block = block;
            _block.Above = this;
        }
示例#3
0
 public ScopeStatement(Cursor cursor, SymbolDefinition name, Block block)
     : base(NodeKind.ScopeStatement, cursor, name)
 {
     _block = block;
     _block.Above = this;
 }
示例#4
0
 public override object Visit(SymbolDefinition that, object value)
 {
     _writer.Write(that.Symbol);
     return null;
 }
        public override object Visit(SymbolDefinition that, object value = null)
        {
            PrintPrologue(that);
            _writer.WriteLine("SymbolKind = {0}", that.SymbolKind.ToString());
            _writer.WriteLine("Symbol = '{0}'", that.Symbol);
            _writer.WriteLine("Path = {0}", (that.Path == null) ? "none" : that.Path);
            PrintEpilogue(that);

            return null;
        }
示例#6
0
 public Definition(NodeKind kind, Cursor cursor, SymbolDefinition name)
     : base(kind, cursor)
 {
     _name = name;
     _name.Above = this;
 }
示例#7
0
 public EntryStatement(Cursor cursor, SymbolDefinition name, Profile profile, Block block)
     : base(NodeKind.EntryStatement, cursor, name, profile, block)
 {
 }
        public override object Visit(SymbolDefinition that, object value = null)
        {
            switch (that.Above.Kind)
            {
                /** \note Exclude these kinds of nodes as they have been processed by earlier passes. */
                case NodeKind.ClassStatement:
                case NodeKind.ScopeStatement:
                case NodeKind.ValueStatement:
                    return null;
            }

            _symbols.Insert(that.Symbol, (Definition) that.Above);
            return null;
        }
示例#9
0
        /** Parses an \c import definition.
         *
         *  \note In Braceless0, everything foreign must be explicitly imported before it can be referenced!
         *  \note As a result, there are no implicit import features in Braceless0.
         *
         *  \todo Implement the above in the compiler...
         */
        private ImportStatement ParseImportStatement()
        {
            Token start = _matcher.Match(TokenKind.Keyword_Import);
            Expression path = ParseExpression();
            SymbolDefinition name;
            #if false
            if (_matcher.This.Kind == TokenKind.Space)
            {
            #endif
                _matcher.Match(TokenKind.Space);
                _matcher.Match(TokenKind.Keyword_Is);
                _matcher.Match(TokenKind.Space);
                Token token = _matcher.Match(TokenKind.Name);
                name = new SymbolDefinition(token.Cursor, token.Text, SymbolKind.Import);
            #if false
            }
            else
            {
                // locate the deepest node in the expression tree that denotes the import path
                Expression found = null;
                Expression next  = path;
                for (;;)
                {
                    Node[] below = next.Below;
                    if (below.Length == 0)
                    {
                        found = next;
                        break;
                    }
                    else if (below.Length == 1)
                        next = below[0];
                    else
                        throw new System.Exception("Path contains multiple children: " + next.Id.ToString());
                }
            }
            #endif

            return new ImportStatement(start.Cursor, name, path);
        }
示例#10
0
        /** Parses a \c create statement, which introduces a new symbol name in the current scope. */
        private CreateStatement ParseCreateStatement()
        {
            Token start = _matcher.This;

            _matcher.Match(TokenKind.Keyword_Create);
            _matcher.Match(TokenKind.Space);

            Token token = _matcher.Match(TokenKind.Name);
            var name = new SymbolDefinition(token.Cursor, token.Text, SymbolKind.Variable);

            Type type = null;
            if (_matcher.This.Kind == TokenKind.Space && _matcher.Next.Kind == TokenKind.Keyword_Is)
            {
                _matcher.Match(TokenKind.Space);
                _matcher.Match(TokenKind.Keyword_Is);
                _matcher.Match(TokenKind.Space);
                type = ParseType();
            }

            Expression initializer = null;
            if (_matcher.This.Kind == TokenKind.Space && _matcher.Next.Kind == TokenKind.Assign_Identity)
            {
                _matcher.Match(TokenKind.Space);
                _matcher.Match(TokenKind.Assign_Identity);
                _matcher.Match(TokenKind.Space);
                initializer = ParseExpression();
            }

            _matcher.Match(TokenKind.EndOfLine);

            if (type == null && initializer == null)
                throw new ParserError(name.Cursor, "Expected type and/or initalizer");

            if (type == null)
                type = new UnknownType(name.Cursor);
            if (initializer == null)
                initializer = new NoneLiteral(name.Cursor, new NoneType(name.Cursor));

            return new CreateStatement(start.Cursor, name, type, initializer);
        }