当前位置: 首页>>代码示例>>C#>>正文


C# Parsing.NonTerminal类代码示例

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


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


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