• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Parsing.NonTerminal类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Irony.Parsing.NonTerminal的典型用法代码示例。如果您正苦于以下问题:C# NonTerminal类的具体用法?C# NonTerminal怎么用?C# NonTerminal使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



NonTerminal类属于Irony.Parsing命名空间,在下文中一共展示了NonTerminal类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: E2Grammar

        public E2Grammar()
        {
            LineTerminators = "\r\n";
            var program = new NonTerminal("Program");
            var directiveList = new NonTerminal("DirectiveList");
            var directive = new NonTerminal("Directive");
            var directiveName = new IdentifierTerminal("DirectiveName");
            var directiveBody = new NonTerminal("DirectiveBody");
            var statementList = new NonTerminal("StatementList");
            var statement = new NonTerminal("Statement");
            var assignment = new NonTerminal("Assignment");
            var expression = new NonTerminal("Expression");
            var parenExpression = new NonTerminal("ParenExpression");
            var methodCall = new NonTerminal("MethodCall");
            var argumentList = new NonTerminal("ArgumentList");
            var argumentTail = new NonTerminal("ArgumentTail");
            var @operator = new NonTerminal("Operator");
            var operation = new NonTerminal("Operation");
            var identifier = new IdentifierTerminal("Identifier");
            var @string = new StringLiteral("String", "\"");
            var number = new NumberLiteral("Number");
            var ifStatement = new NonTerminal("IfStatement");
            var whileStatement = new NonTerminal("WhileStatement");
            var comment = new CommentTerminal("comment", "#", new[] {"\n"});
            var dcom = new CommentTerminal("commentCheat", "@", new[] {"\n"});

            Root = program;

            NonGrammarTerminals.Add(comment);
            NonGrammarTerminals.Add(dcom);

            RegisterBracePair("{", "}");

            program.Rule = /* directiveList + */statementList;

            //directiveList.Rule = MakePlusRule(directiveList, null, directive);
            //directiveBody.Rule = new CommentTerminal()
            //directive.Rule = ToTerm("@") + directiveName + directiveBody;

            statementList.Rule = MakePlusRule(statementList, null, statement);
            statement.Rule = methodCall | assignment;

            expression.Rule = operation | @string | number | methodCall | identifier;

            parenExpression.Rule = ToTerm("(") + expression + ")";

            methodCall.Rule = expression + ":" + identifier + "(" + argumentList + ")";

            argumentList.Rule = MakeStarRule(argumentList, ToTerm(","), expression);

            operation.Rule = expression + @operator + expression;

            @operator.Rule = ToTerm("+") | "-" | "*" | "/" | "&" | "|";

            assignment.Rule = identifier + "=" + expression;

            ifStatement.Rule = ToTerm("if") + parenExpression + "{" + statementList + "}";

            whileStatement.Rule = ToTerm("while") + parenExpression + "{" + statementList + "}";
        }
开发者ID:itsbth,项目名称:E2Edit,代码行数:60,代码来源:E2Grammar.cs


示例2: ListRules

        public ListRules(PieGrammar grammar)
        {
            this.grammar = grammar;

            StarIdentifierList = new NonTerminal("star_identifer_list");
            PlusIdentifierList = new NonTerminal("plus_identfier_list");
        }
开发者ID:maleficus1234,项目名称:Pie,代码行数:7,代码来源:ListRules.cs


示例3: ProjectsGrammar

        public ProjectsGrammar()
        {
            // Todo
            // Fix Note to work actually right, just take the rest of the text

            // Define Terminals
            var taskName = new TaskTerminal("TaskName");
            var projectName = new ProjectTerminal("ProjectName");
            var noteText = new NoteTerminal("NoteText");

            // Define Non-Terminals
            var notes = new NonTerminal("Notes", typeof(StatementListNode));
            var project = new NonTerminal("Project", typeof (StatementListNode));
            var task = new NonTerminal("Task", typeof (StatementListNode));
            var tasks = new NonTerminal("Tasks", typeof (StatementListNode));

            var program = new NonTerminal("ProgramLine", typeof(StatementListNode));

            // Define Rules
            notes.Rule = MakeStarRule(notes, noteText);
            task.Rule = taskName + notes;
            tasks.Rule = MakeStarRule(tasks, task);
            project.Rule = projectName +notes + tasks;
            program.Rule = MakeStarRule(program, project);

            Root = program;
            LanguageFlags = LanguageFlags.CreateAst
                            | LanguageFlags.CanRunSample;
        }
开发者ID:Ball,项目名称:DslExamples,代码行数:29,代码来源:ProjectsGrammar.cs


示例4: SpeechExpression

        public SpeechExpression()
        {
            FreeTextLiteral text = new FreeTextLiteral(TextLiteralName, FreeTextOptions.AllowEof, AliasSymbol, VarSymbol, OpenBracketSymbol, ArgSeparatorSymbol, CloseBracketSymbol);
            IdentifierTerminal name = TerminalFactory.CreateCSharpIdentifier(NameLiteralName);

            NonTerminal root = new NonTerminal(RootExpressionName);
            NonTerminal expression = new NonTerminal(ExpressionLiteralName);
            NonTerminal argumentList = new NonTerminal(ArgumentListLiteralName);
            NonTerminal alias = new NonTerminal(AliasLiteralName);
            NonTerminal variable = new NonTerminal(VariableLiteralName);

            argumentList.Rule = MakePlusRule(argumentList, ToTerm(ArgSeparatorSymbol), root);
            alias.Rule = AliasSymbol + name + OpenBracketSymbol + argumentList + CloseBracketSymbol | AliasSymbol + name;
            variable.Rule = VarSymbol + name;

            expression.Rule = text | variable | alias;
            root.Rule = MakeStarRule(root, expression);

            Root = root;

            text.Escapes.Add("\\" + AliasSymbol, AliasSymbol);
            text.Escapes.Add("\\" + VarSymbol, VarSymbol);
            text.Escapes.Add("\\" + OpenBracketSymbol, OpenBracketSymbol);
            text.Escapes.Add("\\" + CloseBracketSymbol, CloseBracketSymbol);
            text.Escapes.Add("\\" + ArgSeparatorSymbol, ArgSeparatorSymbol);

            MarkTransient(root, expression);
            RegisterBracePair(OpenBracketSymbol, CloseBracketSymbol);
        }
开发者ID:3DI70R,项目名称:SpeechSequencerCore,代码行数:29,代码来源:SpeechExpression.cs


示例5: FabricGrammar

        public FabricGrammar(): base(false) // case non-sensitive
        {
            // Terminal Definitions
            RegexBasedTerminal number = new RegexBasedTerminal("number", "[0-9]+");

            // Non-Terminal Definitions
            NonTerminal program = new NonTerminal("program"),
                createStatement = new NonTerminal("createStatement"),
                startStatement = new NonTerminal("startStatement"),
                moveStatements = new NonTerminal("moveStatements"),
                moveStatement = new NonTerminal("moveStatement"),
                direction = new NonTerminal("direction");

            // Relation Definitions
            program.Rule = createStatement + startStatement + moveStatements;
            createStatement.Rule = ToTerm("Create") + "a" + number + "by" + number + "grid";
            startStatement.Rule = ToTerm("Start") + "at" + "location" + number + "," + number;
            moveStatements.Rule = MakePlusRule(moveStatements, moveStatement);
            moveStatement.Rule = ToTerm("Move") + direction + number;
            direction.Rule = ToTerm("up") | "down" | "right" | "left";

            // Set the Root
            this.Root = program;

            // Set the Markup Register
            MarkPunctuation("Create", "a", "grid", "by", "Start", "at", "location", ",", "Move");
        }
开发者ID:Skit5,项目名称:ProgrammableLayeredFabrics,代码行数:27,代码来源:FabricGrammar.cs


示例6: ExceptionRules

        public ExceptionRules(PieGrammar grammar)
        {
            this.grammar = grammar;

            ExceptionHandlingBlock = new NonTerminal("exception_handling_block");
            ThrowStatement = new NonTerminal("throw_statement");
        }
开发者ID:maleficus1234,项目名称:Pie,代码行数:7,代码来源:ExceptionRules.cs


示例7: ForCircleDefinition

 public override void ForCircleDefinition(NonTerminal circleDef, NonTerminal coordSet)
 {
     AstBuilder(circleDef, (context, node) =>
     {
         throw new InvalidOperationException("SqlGeometryParser cannot handle circle-like structures if the output style is set to GeometryCollection");
     });
 }
开发者ID:flq,项目名称:GeoJsonAndSqlGeo,代码行数:7,代码来源:GeoJsonAstBuilderGeoCollectionStyle.cs


示例8: ForLoopRules

        public ForLoopRules(PieGrammar grammar)
        {
            this.grammar = grammar;

            SimpleForLoop = new NonTerminal("simple_for_loop");
            BodiedForLoop = new NonTerminal("bodied_for_loop");
        }
开发者ID:maleficus1234,项目名称:Pie,代码行数:7,代码来源:ForLoopRules.cs


示例9: GrammarExL514

    public GrammarExL514() {
      NonTerminal A = new NonTerminal("A");
      Terminal a = new Terminal("a");

      A.Rule = "(" + A + ")" | a; 
      this.Root = A;
    }//method
开发者ID:androdev4u,项目名称:XLParser,代码行数:7,代码来源:GrammarExL514.cs


示例10: JsonGrammar

    public JsonGrammar() {
      //Terminals
      var jstring = new StringLiteral("string", "\"");
      var jnumber = new NumberLiteral("number");
      var comma = ToTerm(","); 
      
      //Nonterminals
      var jobject = new NonTerminal("Object"); 
      var jobjectBr = new NonTerminal("ObjectBr");
      var jarray = new NonTerminal("Array"); 
      var jarrayBr = new NonTerminal("ArrayBr");
      var jvalue = new NonTerminal("Value");
      var jprop = new NonTerminal("Property"); 

      //Rules
      jvalue.Rule = jstring | jnumber | jobjectBr | jarrayBr | "true" | "false" | "null";
      jobjectBr.Rule = "{" + jobject + "}";
      jobject.Rule = MakeStarRule(jobject, comma, jprop);
      jprop.Rule = jstring + ":" + jvalue;
      jarrayBr.Rule = "[" + jarray + "]";
      jarray.Rule = MakeStarRule(jarray, comma, jvalue);

      //Set grammar root
      this.Root = jvalue;
      MarkPunctuation("{", "}", "[", "]", ":", ",");
      this.MarkTransient(jvalue, jarrayBr, jobjectBr);

    }//constructor
开发者ID:PrototypeAlpha,项目名称:LiveSplit,代码行数:28,代码来源:JsonGrammar.cs


示例11: Define

        public void Define()
        {
            /* case <expression>:
             *      <expression>
             */
            var caseBlock = new NonTerminal("case_block");
            caseBlock.Rule = grammar.Keywords.Case
                + grammar.expression
                + grammar.ToTerm(":")
                + grammar.Eos
                + grammar.MethodDeclarations.OptionalMethodBody;

            // List of case block expressions.
            var caseBlockList = new NonTerminal("case_block_list");
            caseBlockList.Rule = grammar.MakeStarRule(caseBlockList, caseBlock);

            // The list of case block expressions is optional.
            var caseBlockListOpt = new NonTerminal("case_block_list_opt");
            caseBlockListOpt.Rule = (grammar.Indent + caseBlockList +grammar.Dedent) | grammar.Empty;

            /* switch <expression>:
             *      case <expression>:
             *              <expression>
             */
            SwitchBlock.Rule = grammar.Keywords.Switch
                + grammar.expression
                + grammar.ToTerm(":")
                + grammar.Eos
                + caseBlockListOpt;
        }
开发者ID:maleficus1234,项目名称:Pie,代码行数:30,代码来源:SwitchRules.cs


示例12: Parser

        /// <summary>
        /// Initializes a new instance of the <see cref="Parser"/> class.
        /// </summary>
        /// <param name="language">The language.</param>
        /// <param name="scanner">The scanner.</param>
        /// <param name="root">The root.</param>
        /// <exception cref="Exception">
        ///   </exception>
        public Parser(LanguageData language, Scanner scanner, NonTerminal root)
        {
            Language = language;
            Context = new ParsingContext(this);
            Scanner = scanner ?? language.CreateScanner();

            if (Scanner != null)
            {
                Scanner.Initialize(this);
            } 
            else
            {
                Language.Errors.Add(GrammarErrorLevel.Error, null, "Scanner is not initialized for this grammar");
            }
            CoreParser = new CoreParser(this);
            Root = root;
            if (Root == null)
            {
                Root = Language.Grammar.Root;
                InitialState = Language.ParserData.InitialState;
            }
            else
            {
                if (Root != Language.Grammar.Root && !Language.Grammar.SnippetRoots.Contains(Root))
                {
                    throw new Exception(string.Format(Resources.ErrRootNotRegistered, root.Name));
                }

                InitialState = Language.ParserData.InitialStates[Root];
            }
        }
开发者ID:cg123,项目名称:xenko,代码行数:39,代码来源:Parser.cs


示例13: GridWorldGrammar

        public GridWorldGrammar()
        {
            this.GrammarComments = "A grammar for GridWorld";

            //Terminals
            RegexBasedTerminal number = new RegexBasedTerminal("number", "[0-9]+");

            //Non terminals
            NonTerminal program = new NonTerminal("program");
            NonTerminal createStatement = new NonTerminal("createStatement", typeof(StartNode));
            NonTerminal startStatement = new NonTerminal("startStatement", typeof(StartNode));
            NonTerminal moveStatements = new NonTerminal("moveStatements", typeof(MovesNode));
            NonTerminal moveStatement = new NonTerminal("moveStatement", typeof(MoveNode));
            NonTerminal direction = new NonTerminal("direction", typeof(DirectionNode));

            //BNF rules
            program.Rule = createStatement + startStatement + moveStatements;
            createStatement.Rule = ToTerm("Create") + "a" + number + "by" + number + "grid" + ".";
            startStatement.Rule = ToTerm("Start") + "at" + "location" + number + "," + number + ".";
            moveStatements.Rule = MakePlusRule(moveStatements, moveStatement);
            moveStatement.Rule = "Move" + direction + number + ".";
            direction.Rule = ToTerm("up") | "down" | "right" | "left";
            this.Root = program;
            this.LanguageFlags = LanguageFlags.CreateAst;
            MarkPunctuation("Create", "a", "grid", "by", "Start", "at","location", ",", ".", "Move");
        }
开发者ID:TuxMulder,项目名称:zest,代码行数:26,代码来源:GridWorldGrammar.cs


示例14: WhileLoopRules

        public WhileLoopRules(PieGrammar grammar)
        {
            this.grammar = grammar;

            SimpleWhileLoop = new NonTerminal("simple_while_loop");
            BodiedWhileLoop = new NonTerminal("bodied_while_loop");
        }
开发者ID:maleficus1234,项目名称:Pie,代码行数:7,代码来源:WhileLoopRules.cs


示例15: CameraControlGrammar

        //#AS:2012/12/08: grammar is case-insensitive
        public CameraControlGrammar()
            : base(caseSensitive: false)
        {
            var program = new NonTerminal("program");
            var cameraSize = new NonTerminal("cameraSize");
            var cameraPosition = new NonTerminal("cameraPosition");
            var commandList = new NonTerminal("commandList");
            var command = new NonTerminal("command");
            var direction = new NonTerminal("direction");
            var number = new NumberLiteral("number");
            this.Root = program;
            //Grammar production rules in bnf form
            // <Program> ::= <CameraSize> <CameraPosition> <CommandList>
            program.Rule = cameraSize + cameraPosition + commandList;

            // <CameraSize> ::= "set" "camera" "size" ":" <number> "by" <number> "pixels" "."
            cameraSize.Rule = ToTerm("set") + "camera" + "size" + ":" +
                              number + "by" + number + "pixels" + ".";

            // <CameraPosition> ::= "set" "camera" "position" ":" <number> "," <number> "."
            cameraPosition.Rule = ToTerm("set") + "camera" + "position" +
                                  ":" + number + "," + number + ".";

            // <CommandList> ::= <Command>+
            commandList.Rule = MakePlusRule(commandList, null, command);

            // <Command> ::= "move" <number> "pixels" <Direction> "."
            command.Rule = ToTerm("move") + number + "pixels" + direction + ".";

            // <Direction> ::= "up" | "down" | "left" | "right"
            direction.Rule = ToTerm("up") | "down" | "left" | "right";

            //#AS:2012/12/08: these symbols are defined as puntuation, so they will not be included in the ast
            this.MarkPunctuation("set", ("camera"), "size", ":", "by", "pixels", ".", "position", ",", "move");
        }
开发者ID:andrea-scarcella,项目名称:DSLTutorial,代码行数:36,代码来源:CameraControlGrammar.cs


示例16: TestGrammar

 public TestGrammar()
 {
     var root = new NonTerminal("root");
       root.Rule = Empty;
       this.Root = root;
       this.Delimiters = ",;(){}"; //important for quick-parse tests
 }
开发者ID:MarcusTheBold,项目名称:Irony,代码行数:7,代码来源:TestGrammar.cs


示例17: ExpressionGrammar

            public ExpressionGrammar()
            {
                var Number = new NumberLiteral("Number");
                var Var = new IdentifierTerminal("Var");
                var conditional_expression = new NonTerminal("conditional_expression");

                //conditional_expression.Rule = expression + PreferShiftHere() + qmark + expression + colon + expression;
                //NonTerminal DataType = new NonTerminal("DataType");

                NonTerminal DecSt = new NonTerminal("DecSt");
                DecSt.Rule = "int" + Var + "=" + Number + ";" | "int" + Var + ";";

                NonTerminal PrintSt = new NonTerminal("PrintSt");
                PrintSt.Rule = "cout <<" + Var;

                //NonTerminal IF = new NonTerminal("IF");
                //IF.Rule = "if( + ;

                NonTerminal stmt = new NonTerminal("stmt");
                stmt.Rule = PrintSt | DecSt;

                NonTerminal stmt1 = new NonTerminal("stmt");
                stmt1.Rule = "begin{" + stmt + "}end;";

                this.Root = DecSt;
            }
开发者ID:khateeb321,项目名称:Compiler-Construction,代码行数:26,代码来源:Form1.cs


示例18: MakeRoot

        protected override NonTerminal MakeRoot()
        {
            var root = new NonTerminal("root");
            Productions(root);

            return root;
        }
开发者ID:furesoft,项目名称:deveeldb,代码行数:7,代码来源:SqlGrammar.cs


示例19: XamlMarkupExtensionGrammar

        public XamlMarkupExtensionGrammar()
        {
            // Non Terminals
            var markupExtension = new NonTerminal(MarkupExtensionTerm);
            var arguments = new NonTerminal("Arguments");
            var namedArgs = new NonTerminal("NamedArgs");
            var namedArg = new NonTerminal(NamedArgumentTerm);
            var positionalArgs = new NonTerminal("PositionalArgs");
            var argument = new NonTerminal("Argument");

            // Terminals
            var typeName = new TypeNameTerminal(TypeNameTerm);
            var memberName = new MemberNameTerminal(MemberNameTerm);
            var @string = new StringTerminal(StringTerm);
            var startExtension = this.ToTransientTerm("{");
            var endExtension = this.ToTransientTerm("}");
            var namedArgumentSeparator = this.ToTransientTerm("=");
            var argumentSeparator = this.ToTransientTerm(",");

            // Setup rules
            markupExtension.Rule = (startExtension + typeName + endExtension)
                | (startExtension + typeName + arguments + endExtension);

            arguments.Rule = namedArgs | positionalArgs | (positionalArgs + argumentSeparator + namedArgs);
            namedArgs.Rule = namedArg | (namedArg + argumentSeparator + namedArgs);
            namedArg.Rule = (memberName + namedArgumentSeparator + argument);
            positionalArgs.Rule = namedArgs | argument | (argument + argumentSeparator + positionalArgs);
            argument.Rule = markupExtension | @string;

            this.Root = markupExtension;
            this.MarkTransient(arguments, argument);
        }
开发者ID:tmatz,项目名称:XamlStyler,代码行数:32,代码来源:XamlMarkupExtensionGrammar.cs


示例20: ASLGrammar

        public ASLGrammar()
            : base(true)
        {
            var string_lit = TerminalFactory.CreateCSharpString("string");
            var number = TerminalFactory.CreateCSharpNumber("number");
            var identifier = TerminalFactory.CreateCSharpIdentifier("identifier");
            var code = new CustomTerminal("code", MatchCodeTerminal);

            var single_line_comment = new CommentTerminal("SingleLineComment", "//", "\r", "\n", "\u2085", "\u2028", "\u2029");
            var delimited_comment = new CommentTerminal("DelimitedComment", "/*", "*/");
            NonGrammarTerminals.Add(single_line_comment);
            NonGrammarTerminals.Add(delimited_comment);

            var state = new KeyTerm("state", "state");
            var init = new KeyTerm("init", "init");
            var exit = new KeyTerm("exit", "exit");
            var update = new KeyTerm("update", "update");
            var start = new KeyTerm("start", "start");
            var split = new KeyTerm("split", "split");
            var reset = new KeyTerm("reset", "reset");
            var startup = new KeyTerm("startup", "startup");
            var shutdown = new KeyTerm("shutdown", "shutdown");
            var isLoading = new KeyTerm("isLoading", "isLoading");
            var gameTime = new KeyTerm("gameTime", "gameTime");
            var comma = ToTerm(",", "comma");
            var semi = ToTerm(";", "semi");

            var root = new NonTerminal("root");
            var state_def = new NonTerminal("stateDef");
            var version = new NonTerminal("version");
            var state_list = new NonTerminal("stateList");
            var method_list = new NonTerminal("methodList");
            var var_list = new NonTerminal("varList");
            var var = new NonTerminal("var");
            var module = new NonTerminal("module");
            var method = new NonTerminal("method");
            var offset_list = new NonTerminal("offsetList");
            var offset = new NonTerminal("offset");
            var method_type = new NonTerminal("methodType");

            root.Rule = state_list + method_list;
            version.Rule = (comma + string_lit) | Empty;
            state_def.Rule = state + "(" + string_lit + version + ")" + "{" + var_list + "}";
            state_list.Rule = MakeStarRule(state_list, state_def);
            method_list.Rule = MakeStarRule(method_list, method);
            var_list.Rule = MakeStarRule(var_list, semi, var);
            module.Rule = (string_lit + comma) | Empty;
            var.Rule = (identifier + identifier + ":" + module + offset_list) | Empty;
            method.Rule = (method_type + "{" + code + "}") | Empty;
            offset_list.Rule = MakePlusRule(offset_list, comma, offset);
            offset.Rule = number;
            method_type.Rule = init | exit | update | start | split | isLoading | gameTime | reset | startup | shutdown;

            Root = root;

            MarkTransient(var_list, method_list, offset, method_type);

            LanguageFlags = LanguageFlags.NewLineBeforeEOF;
        }
开发者ID:tduva,项目名称:LiveSplit.ScriptableAutoSplit,代码行数:59,代码来源:ASLGrammar.cs



注:本文中的Irony.Parsing.NonTerminal类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Parsing.ParseTree类代码示例发布时间:2022-05-26
下一篇:
C# Parsing.LanguageData类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap