Exemplo n.º 1
0
        public Prototype Parse(ParserContext context)
        {
            // Parse the return type.
            Type returnType = new TypeParser().Parse(context);

            // Invoke identifier parser.
            string identifier = new IdentifierParser().Parse(context);

            // Invoke the formal argument parser.
            FormalArgs args = new FormalArgsParser().Parse(context);

            // Create the resulting prototype entity.
            Prototype prototype = new Prototype(identifier, args, returnType);

            // Return prototype.
            return(prototype);
        }
Exemplo n.º 2
0
        public Prototype Parse(TokenStream stream)
        {
            // Parse the return type.
            Type returnType = new TypeParser().Parse(stream);

            // Capture identifier.
            var identifier = stream.Next(TokenType.Identifier).Value;

            // Invoke the formal argument parser.
            FormalArgs args = new FormalArgsParser().Parse(stream);

            // Create the resulting prototype entity.
            var prototype = new Prototype(identifier, args, returnType);

            // Return prototype.
            return(prototype);
        }
Exemplo n.º 3
0
        public Expr Parse(ParserContext context)
        {
            // Create a lambda expression.
            LambdaExpr lambda = new LambdaExpr();

            // Parse the formal arguments.
            FormalArgs args = new FormalArgsParser().Parse(context);

            // Assign the parsed arguments to the lambda.
            lambda.Args = args;

            // Create the type buffer, defaulting to void.
            ITypeEmitter type = PrimitiveTypeFactory.Void();

            // Return type is explicitly specified, parse and use it instead of the default.
            if (context.Stream.Current.Type == TokenType.SymbolColon)
            {
                // Ensure current type is symbol colon.
                context.Stream.EnsureCurrent(TokenType.SymbolColon);

                // Skip symbol colon token.
                context.Stream.Skip();

                // Parse the return type.
                type = new TypeParser().Parse(context);
            }

            // Assign the parsed type to the return type.
            lambda.ReturnType = type;

            // Ensure current token is symbol arrow.
            context.Stream.EnsureCurrent(TokenType.SymbolArrow);

            // Skip arrow symbol token.
            context.Stream.Skip();

            // Parse the body block.
            Block body = new BlockParser().Parse(context);

            // Assign the block to the lambda.
            lambda.Body = body;

            // Return the resulting expression.
            return(lambda);
        }