コード例 #1
0
        AbstractNode VarDeclarationWithSemanticNamesParse(Queue <LexerNode> lexers, DefinitionObjectNode parent)
        {
            var variable = VarDeclarationParse(lexers);

            if (lexers.Any())
            {
                var op = lexers.Peek();
                switch (op.Value)
                {
                case ShaderSyntaxInfo.Colon:     // ==== examples ====
                                                 //float4 c	: COLOR0;
                                                 // ==== ++++++++ ==== //
                    var svd = new VariableDefinitionWitSemanticName {
                        Parent = parent
                    };
                    svd.VarDeclaration = variable;
                    using (lexers.Boundary(ShaderSyntaxInfo.Colon, ShaderSyntaxInfo.Semicolon)) {
                        svd.SemanticNameLex = lexers.Dequeue();
                    }
                    svd.Parent = parent;
                    return(svd);
                }
            }
            variable.Parent = parent;
            return(variable);
        }
コード例 #2
0
 public SyntaxParser(SemanticAnalyzer analizer, ShaderSyntaxInfo syntax)
 {
     this.semantic = analizer;
     this.syntax   = syntax;
     Comments      = new List <LexerNode>();
     Prog          = new DefinitionObjectNode();
 }
コード例 #3
0
        void Parse(Queue <LexerNode> lexers, DefinitionObjectNode parent)
        {
            var next = lexers.Peek();

            switch (next.Token)
            {
            case LexerTokens.Operator:
                switch (next.Value)
                {
                case ShaderSyntaxInfo.Semicolon:
                    lexers.Dequeue();        //skip lex
                    return;
                }
                break;

            case LexerTokens.Comment:
                parent.Children.Add(new CommentsNode()
                {
                    Lex = lexers.Dequeue()
                });
                return;

            case LexerTokens.Punctuation:
                switch (next.Value)
                {
                case "#":
                    // ==== examples ==== //
                    // #include "./Shaders/Common.fx"
                    // ==== ++++++++ ==== //
                    lexers.Dequeue();            //for '#'
                    var id = new IncludeDeclaration {
                        Name = lexers.Dequeue(), //get key
                        Path = new StringNode {
                            NameLex = lexers.Dequeue()
                        }
                    };
                    parent.Children.Add(id);
                    return;

                case "[":        //attrinuter: [maxvertexcount(18)]
                    var body = new ListNode();
                    DelimitedBy(lexers, DelimeterParams.Attribute, body, lex => { while (lex.Any())
                                                                                  {
                                                                                      lex.Dequeue();
                                                                                  }
                                                                                  return(null); });
                    return;
                }
                break;
            }
            //specific keys to parse first
            switch (next.Value)
            {
            case ShaderSyntaxInfo.StructKey:
                var var  = VarDeclarationParse(lexers);
                var strn = new StructNode {
                    VarDeclaration = var, Parent = parent
                };
                using (semantic.RegisterStruct(var.DeclarationName.NameLex, strn)) {
                    parent.Children.Add(strn);

                    DelimitedBy(lexers, DelimeterParams.Sequences, strn.Children, lex => VarDeclarationWithSemanticNamesParse(lex, strn));
                    if (lexers.Peek().Value == ShaderSyntaxInfo.Semicolon)
                    {
                        //in some cases ';' is end of declaration
                        lexers.Dequeue();
                    }
                }
                return;

            case ShaderSyntaxInfo.CbufferKey:
                var cbn = new CBufferNode {
                    VarDeclaration = VarDeclarationParse(lexers), Parent = parent
                };
                lexers.Dequeue().ThrowIfNot(ShaderSyntaxInfo.Colon);
                parent.Children.Add(cbn);
                cbn.Register = Parse(lexers, new FunctionCallNode {
                    Parent = cbn, Name = new SystemName {
                        NameLex = lexers.Dequeue()
                    }
                });
                DelimitedBy(lexers, DelimeterParams.Sequences, cbn.Children, lex => Parse(lex, cbn));
                return;
            }
            //parse any variable
            var variable = VarDeclarationParse(lexers);

            if (lexers.Peek().Value == ShaderSyntaxInfo.Semicolon) //end of declaration or definition
                                                                   //float4 illumDiffuse;
            {
                lexers.Dequeue();                                  //skip Semicolon
                variable.Parent = parent;
                parent.Children.Add(variable);
                return;
            }

            //
            next = lexers.Peek();
            switch (next.Token)
            {
            case LexerTokens.Punctuation:
                // ==== examples ==== //
                //int foo(InputT input, ...) { }
                var fdn = new FunctionDeclarationNode {
                    Parent         = parent,
                    VarDeclaration = variable
                };

                parent.Children.Add(fdn);

                DelimitedBy(lexers, DelimeterParams.Function, fdn.Vars,
                            lex => {
                    //var v = VarDeclarationParse(lex);
                    var v = VarDeclarationWithSemanticNamesParse(lex, parent);
                    lex.ThrowIfAny();
                    return(v);
                });
                using (semantic.RegisterFunction(variable.DeclarationName.NameLex, fdn)) {
                    //maybe have semantic name
                    var semanticNameMaybe = lexers.Peek();
                    if (semanticNameMaybe.Token == LexerTokens.Operator && semanticNameMaybe.Value == ":")
                    {
                        lexers.Dequeue();    //skip operator
                        fdn.SemanticNameLex = lexers.Dequeue();
                    }
                    var boundary = DelimitedBy(lexers, DelimeterParams.Sequences, fdn.Children,
                                               lex => FunctionParse(lex, fdn));
                    fdn.Boundary = boundary;
                }

                return;

            case LexerTokens.Operator:
                parent.Children.Add(AssignmentParse(lexers, new AssignmentVariableDefinition()
                {
                    Left = variable
                }));
                break;
            }
        }
コード例 #4
0
 public void Visit(DefinitionObjectNode don)
 {
     don.Children.ForEach(x => x.Handle(this));
 }
コード例 #5
0
 public void Visit(DefinitionObjectNode definitionObjectNode)
 {
 }