public VarDeclareExpr Parse(ParserContext context)
        {
            // Parse the type.
            Type type = new TypeParser().Parse(context);

            // Create the variable declaration & link the type.
            VarDeclareExpr declaration = new VarDeclareExpr(type, null);

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

            // Assign the name.
            declaration.SetName(identifier);

            // Capture current token.
            Token token = context.Stream.Current;

            // A value is being assigned.
            if (token.Type == SyntaxAnalysis.TokenType.OperatorAssignment)
            {
                // Skip the assignment operator.
                context.Stream.Skip();

                // Parse value.
                Expr value = new ExprParser().Parse(context);

                // Assign value.
                declaration.Value = value;
            }

            // Return the resulting declaration construct.
            return(declaration);
        }
Exemple #2
0
        public PathResult Parse(ParserContext context)
        {
            // Create the resulting path's nodes.
            List <string> nodes = new List <string>();

            // Invoke identifier parser to capture the node.
            string node = new IdentifierParser().Parse(context);

            // Append node to path.
            nodes.Add(node);

            // Use recursion if symbol dot is present.
            if (context.Stream.Current.Type == TokenType.SymbolDot)
            {
                // Skip symbol dot token.
                context.Stream.Skip();

                // Create the parser instance.
                PathParser childParser = new PathParser();

                // Invoke the parser.
                PathResult childParserPath = childParser.Parse(context);

                // Append resulting child parser's path(s) to the resulting path.
                nodes.AddRange(childParserPath.nodes);
            }

            // Create the resulting path.
            PathResult result = new PathResult(nodes);

            // Return the resulting path.
            return(result);
        }
Exemple #3
0
        public Alias Parse(ParserContext context)
        {
            // Ensure current token is alias keyword.
            context.Stream.EnsureCurrent(TokenType.KeywordAlias);

            // Skip alias keyword, capture target identifier.
            string targetName = context.Stream.Next(TokenType.Identifier).Value;

            // Skip target identifier onto as keyword.
            context.Stream.Skip(TokenType.KeywordAs);

            // Skip as keyword.
            context.Stream.Skip();

            // Invoke identifier parser to capture alias name.
            string aliasName = new IdentifierParser().Parse(context);

            // Ensure current token is symbol semi-colon.
            context.Stream.EnsureCurrent(TokenType.SymbolSemiColon);

            // Skip semi-colon.
            context.Stream.Skip();

            // Create the alias construct.
            Alias alias = new Alias(targetName, aliasName);

            // Return the resulting construct.
            return(alias);
        }
Exemple #4
0
        public StructDef Parse(ParserContext context)
        {
            // Ensure current token is struct keyword.
            context.Stream.EnsureCurrent(TokenType.KeywordStruct);

            // Skip struct keyword token.
            context.Stream.Skip();

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

            // Ensure current token is block start.
            context.Stream.EnsureCurrent(TokenType.SymbolBlockL);

            // Skip block start token.
            context.Stream.Skip();

            // Create the properties buffer list.
            List <StructDefProperty> properties = new List <StructDefProperty>();

            // Start iteration with callback.
            context.Stream.NextUntil(TokenType.SymbolBlockR, (Token token) =>
            {
                // Invoke type parser.
                Type type = new TypeParser().Parse(context);

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

                // Ensure current token is symbol semi-colon.
                context.Stream.EnsureCurrent(SyntaxAnalysis.TokenType.SymbolSemiColon);

                // Create property.
                StructDefProperty property = new StructDefProperty(type, name);

                // Attach property to the prototype.
                properties.Add(property);

                // Continue normal iteration.
                return(false);
            });

            // Create the body construct.
            StructDefBody body = new StructDefBody(properties);

            // Ensure current token type is block end.
            context.Stream.EnsureCurrent(TokenType.SymbolBlockR);

            // Skip block end token.
            context.Stream.Skip();

            // Create the struct construct.
            StructDef @struct = new StructDef(identifier, body);

            // Return the resulting struct construct.
            return(@struct);
        }
Exemple #5
0
        public Attribute Parse(ParserContext context)
        {
            // Ensure current token is bracket start.
            context.Stream.EnsureCurrent(TokenType.SymbolBracketL);

            // Skip bracket start.
            context.Stream.Skip();

            // Create the native attribute flag.
            bool native = false;

            // Attribute is native.
            if (context.Stream.Current.Type == TokenType.OperatorLessThan)
            {
                // Raise the native attribute flag.
                native = true;

                // Skip over operator less than.
                context.Stream.Skip();
            }

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

            // If the attribute was flagged as native, skip the remaining delimiter.
            if (native)
            {
                // Ensure current token is operator greater than.
                context.Stream.EnsureCurrent(TokenType.OperatorGreaterThan);

                // Skip over operator greater then.
                context.Stream.Skip();
            }

            // Ensure current token is bracket end.
            context.Stream.EnsureCurrent(TokenType.SymbolBracketR);

            // Skip bracket end.
            context.Stream.Skip();

            // Create the attribute entity.
            Attribute attribute = new Attribute(identifier, native);

            // Return the attribute entity.
            return(attribute);
        }
Exemple #6
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);
        }
Exemple #7
0
        public GlobalVar Parse(ParserContext context)
        {
            // Invoke type parser.
            Type type = new TypeParser().Parse(context);

            // Expect current token to be symbol at.
            context.Stream.EnsureCurrent(TokenType.SymbolAt);

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

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

            // Create the global variable.
            GlobalVar globalVar = new GlobalVar(identifier, type);

            // Return the global variable.
            return(globalVar);
        }
Exemple #8
0
        public StructExpr Parse(ParserContext context)
        {
            // Ensure current token is keyword new.
            context.Stream.EnsureCurrent(TokenType.KeywordNew);

            // Skip new keyword token.
            context.Stream.Skip();

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

            // Invoke struct body parser.
            List <StructProperty> body = new StructBodyParser().Parse(context);

            // Create the resulting struct.
            StructExpr @struct = new StructExpr(identifier, body);

            // Return the resulting struct.
            return(@struct);
        }
        public StructProperty Parse(ParserContext context)
        {
            // Invoke identifier parser.
            string identifier = new IdentifierParser().Parse(context);

            // Ensure current token is symbol colon.
            context.Stream.EnsureCurrent(TokenType.SymbolColon);

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

            // Invoke expression parser to capture the value.
            Expr value = new ExprParser().Parse(context);

            // Create the resulting property construct.
            StructProperty property = new StructProperty(identifier, value, this.index);

            // Return the resulting property construct.
            return(property);
        }