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

C# NumberLiteral类代码示例

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

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



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

示例1: CreateZodiacNumber

 public static NumberLiteral CreateZodiacNumber(string name)
 {
     NumberLiteral term = new NumberLiteral(name);
     term.DefaultIntTypes = new TypeCode[] { TypeCode.Int32, TypeCode.UInt32 };
     //term.DefaultFloatType = TypeCode.Double; //default
     return term;
 }
开发者ID:zackszhu,项目名称:ZodiacLanguage,代码行数:7,代码来源:ZodiacTerminalFactory.cs


示例2: 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


示例3: 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


示例4: 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


示例5: 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


示例6: KISGrammer

        public KISGrammer()
        {
            var number = new NumberLiteral("number");
            var text = new StringLiteral("string", "\"");

            number.DefaultIntTypes = new TypeCode[] { TypeCode.Int32, TypeCode.Int64, NumberLiteral.TypeCodeBigInt };
            var identifier = new IdentifierTerminal("identifier");
            var comment = new CommentTerminal("comment", "#", "\n", "\r");
            base.NonGrammarTerminals.Add(comment);

            var Code = new NonTerminal("code");
            var Statments = new NonTerminal("statments");
            var Value = new NonTerminal("value");
            var ValueString = TerminalFactory.CreateCSharpString("valuestring");

            var SetStmt = new NonTerminal("setstmt");
            var CallStmt = new NonTerminal("callstmt");
            var FnStmt = new NonTerminal("fnstmt");

            var CallPath = new NonTerminal("callpath");
            var CallPerams = new NonTerminal("callperams");

            var fullstop = new NonTerminal("fullstop");
            var comma = new NonTerminal("comma");
            var openb = new NonTerminal("openb");
            var closeb = new NonTerminal("closeb");
            openb.Rule = "{";
            closeb.Rule = "}";
            fullstop.Rule = ".";
            comma.Rule = ",";

            CallPath.Rule = MakePlusRule(CallPath, fullstop, identifier);
            CallPerams.Rule = MakePlusRule(CallPerams, comma, Value);

            var Semicolon = ToTerm(";");

            //StateMents:
            SetStmt.Rule = identifier + "=" + Value + Semicolon;
            CallStmt.Rule = (CallPath | identifier) + "(" + (CallPerams | Empty) + ")" + Semicolon;
            FnStmt.Rule = "function" + identifier + "(" + (CallPerams | Empty) + ")";

            Statments.Rule = SetStmt | CallStmt | FnStmt | openb | closeb | Empty;

            var Exspr = new NonTerminal("exspr");
            var Operator = new NonTerminal("operator");
            var ExsprStmt = new NonTerminal("exsprstmt");

            Operator.Rule = ToTerm("/") | "*" | "-" | "+";

            ExsprStmt.Rule = Value + Operator + Value;

            Exspr.Rule = MakePlusRule(Exspr, Operator, ExsprStmt);

            Value.Rule = number | ValueString | identifier | "true" | "false" | Exspr /* | text */;
            Code.Rule = MakePlusRule(Code, NewLine, Statments);
            LanguageFlags = LanguageFlags.NewLineBeforeEOF;
            //code := Statment {statment}
            this.Root = Code;
        }
开发者ID:Myvar,项目名称:PashOS,代码行数:59,代码来源:KISGrammer.cs


示例7: TestNumber_SignedDoesNotMatchSinglePlus

     public void TestNumber_SignedDoesNotMatchSinglePlus() {
       Parser parser; Token token;

       var number = new NumberLiteral("number", NumberOptions.AllowSign);
       parser = TestHelper.CreateParser(number);
       token = parser.ParseInput("+");
       Assert.IsTrue(token.IsError(), "Parsed single '+' as a number value.");
     }
开发者ID:androdev4u,项目名称:XLParser,代码行数:8,代码来源:NumberLiteralTests.cs


示例8: TestNumber_SignedMatchesNegativeCorrectly

    public void TestNumber_SignedMatchesNegativeCorrectly() {
      Parser parser; Token token;

      var number = new NumberLiteral("number", NumberOptions.AllowSign);
      parser = TestHelper.CreateParser(number);
      token = parser.ParseInput("-500");
      Assert.AreEqual(-500, token.Value, "Negative number was parsed incorrectly; expected: {0}, scanned: {1}", "-500", token.Value);
    }
开发者ID:androdev4u,项目名称:XLParser,代码行数:8,代码来源:NumberLiteralTests.cs


示例9: PowerPCGrammar

        public PowerPCGrammar()
            : base(false)
        {
            var number = new NumberLiteral("number", NumberOptions.Default);
            var REGCHAR = ToTerm("r");
            REGCHAR.AllowAlphaAfterKeyword = true;
            var register = new NonTerminal("register");
            register.Rule = REGCHAR + number;

            var program = new NonTerminal("program");
            var statementList = new NonTerminal("statementList");
            var statement = new NonTerminal("statement");
            var comma = ",";

            var li = new NTerminal("li");
            var add = new NTerminal("add");
            var addi = new NTerminal("addi");
            var addc = new NTerminal("addc");
            var and = new NTerminal("and");
            var andc = new NTerminal("andc");
            var andi = new NTerminal("andi");
            var andis = new NTerminal("andis");
            var cmp = new NTerminal("cmp");
            var sub = new NTerminal("sub");
            var subi = new NTerminal("subi");
            var print = new NTerminal("print");

            li.Rule = li.term + register + comma + number;
            add.Rule = add.term + register + comma + register + comma + register;
            addi.Rule = addi.term + register + comma + register + comma + number;
            addc.Rule = addc.term + register + comma + register + comma + register;
            and.Rule = and.term + register + comma + register + comma + register;
            andc.Rule = andc.term + register + comma + register + comma + register;
            andi.Rule = andi.term + register + comma + register + comma + number;
            andis.Rule = andis.term + register + comma + register + comma + number;
            cmp.Rule = cmp.term + register + comma + register;
            sub.Rule = sub.term + register + comma + register + comma + register;
            subi.Rule = subi.term + register + comma + register + comma + number;

            print.Rule = print.term | print.term + register | print.term + register + "..." + register;

            program.Rule = statementList;
            statementList.Rule = MakeStarRule(statementList, NewLine, statement);

            this.MarkPunctuation(comma, ";", "...");

            foreach (NTerminal n in NTerminal.termList)
            {
                if (statement.Rule == null)
                    statement.Rule = n.keyTerm;
                else
                    statement.Rule = statement.Rule | n.keyTerm;
                MarkPunctuation(n.term);
            }

            this.Root = program;
        }
开发者ID:c4wrd,项目名称:PowerPCEmulator,代码行数:57,代码来源:PowerPCGrammar.cs


示例10: CreateNumberLiteral

 private NumberLiteral CreateNumberLiteral(string name)
 {
     var term = new NumberLiteral(name);
     term.DefaultIntTypes = new TypeCode[] { TypeCode.Int32, TypeCode.Int64 };
     term.DefaultFloatType = TypeCode.Double;
     term.AddPrefix("0x", NumberOptions.Hex);
     term.AddSuffix("l", TypeCode.Int64, TypeCode.UInt64);
     term.AddSuffix("f", TypeCode.Single);
     term.AddSuffix("d", TypeCode.Double);
     return term;
 }
开发者ID:Karapuska,项目名称:Totem,代码行数:11,代码来源:TotemGrammar.Literals.cs


示例11: CreateCSharpNumber

		//http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-334.pdf section 9.4.4
    public static NumberLiteral CreateCSharpNumber(string name) {
      NumberLiteral term = new NumberLiteral(name);
      term.DefaultIntTypes = new TypeCode[] { TypeCode.Int32, TypeCode.UInt32, TypeCode.Int64, TypeCode.UInt64 };
      term.DefaultFloatType = TypeCode.Double;
      term.AddPrefix("0x", NumberOptions.Hex);
      term.AddSuffix("u", TypeCode.UInt32, TypeCode.UInt64);
      term.AddSuffix("l", TypeCode.Int64, TypeCode.UInt64);
      term.AddSuffix("ul", TypeCode.UInt64);
      term.AddSuffix("f", TypeCode.Single);
			term.AddSuffix("d", TypeCode.Double);
      term.AddSuffix("m", TypeCode.Decimal);
      return term;
    }
开发者ID:anukat2015,项目名称:sones,代码行数:14,代码来源:TerminalFactory.cs


示例12: CreateJavaNumber

		public static NumberLiteral CreateJavaNumber(string name)
		{
			var term = new NumberLiteral(name, NumberOptions.AllowStartEndDot)
			{
				DefaultIntTypes = new[] { TypeCode.Int32 },
				DefaultFloatType = TypeCode.Double
			};
			term.AddPrefix("0x", NumberOptions.Hex);
			term.AddSuffix("l", TypeCode.Int64);
			term.AddSuffix("f", TypeCode.Single);
			term.AddSuffix("d", TypeCode.Double);
			return term;
		}
开发者ID:PrototypeAlpha,项目名称:LiveSplit,代码行数:13,代码来源:JavaGrammar.Static.cs


示例13: LinearProgrammingGrammar

        public LinearProgrammingGrammar()
        {
            var comment = new CommentTerminal("comment", "#", "\n", "\r");
            NonGrammarTerminals.Add(comment);

            var identifier = new IdentifierTerminal("appIdentifier");
            var variable = new IdentifierTerminal("variable");

            var number = new NumberLiteral("number", NumberOptions.AllowSign);

            var lpProgram = new NonTerminal("lpApp");
            var lpAppName = new NonTerminal("lpAppName");
            var lpModel = new NonTerminal("lpModel");

            var lpGoal = new NonTerminal("lpGoal");
            var lpPolynomial = new NonTerminal("lpPolynomial");
            var lpConstraints = new NonTerminal("lpConstraints");
            var lpConstraint = new NonTerminal("lpConstraints");
            var lpOperator = new NonTerminal("lpOperator", "lp Operation symbol");
            var lpBinOp = new NonTerminal("lpBinOp", "lp Binary Operation symbol");
            var lpMonomial = new NonTerminal("Monomial");
            var lpNumber = new NonTerminal("lpNumber");

            lpProgram.Rule = lpAppName + "{" + lpModel + "}" + ";";

            lpAppName.Rule = ToTerm("lpmodel") + identifier;

            lpModel.Rule = lpGoal + ToTerm("subject to") +":" + lpConstraints;

            lpGoal.Rule = ToTerm("max") + lpPolynomial | ToTerm("min") + lpPolynomial;

            lpConstraints.Rule = MakePlusRule(lpConstraints, null, lpConstraint);

            //ReduceHere();
            lpConstraint.Rule = lpPolynomial + lpOperator + lpPolynomial + ";";

            lpOperator.Rule = ToTerm("<") | "==" | ">" | "<=" | ">=";

            lpPolynomial.Rule = lpMonomial | lpMonomial + lpBinOp + lpPolynomial  | lpNumber |
                                lpNumber + lpBinOp + lpPolynomial;

            lpMonomial.Rule = variable | lpNumber + ToTerm("*") + variable;

            lpBinOp.Rule = ToTerm("+") | "-";
            lpNumber.Rule = number | lpBinOp + number;

            MarkReservedWords("max", "min", "lpmodel", "subject to");

               // ReduceIf("");
            Root = lpProgram;
        }
开发者ID:taesiri,项目名称:lpSolver,代码行数:51,代码来源:lpGrammar.cs


示例14: GeneralTest

 public void GeneralTest() {
   NumberLiteral number = new NumberLiteral("Number");
   number.DefaultIntTypes = new TypeCode[] { TypeCode.Int32, TypeCode.Int64, NumberLiteral.TypeCodeBigInt };
   SetTerminal(number);
   TryMatch("123");
   CheckType(typeof(int));
   Assert.IsTrue((int)_token.Value == 123, "Failed to read int value");
   TryMatch("123.4");
   Assert.IsTrue(Math.Abs(Convert.ToDouble(_token.Value) - 123.4) < 0.000001, "Failed to read float value");
   //100 digits
   string sbig = "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
   TryMatch(sbig);
   Assert.IsTrue(_token.Value.ToString() == sbig, "Failed to read big integer value");
 }//method
开发者ID:mtashkinov,项目名称:YaccConstructor,代码行数:14,代码来源:NumberLiteralTests.cs


示例15: AllowNullEqualityComparison

        public void AllowNullEqualityComparison(string op)
        {
            var nullVal = new NullLiteral ();
            var numberVal = new NumberLiteral (42);

            var left = new BinaryOperation (op, nullVal, numberVal);
            var right = new BinaryOperation (op, numberVal, nullVal);

            var leftType = left.Walk (new TypeChecker ());
            var rightType = right.Walk (new TypeChecker ());

            Assert.AreEqual (SpecType.Boolean, leftType.Type);
            Assert.AreEqual (SpecType.Boolean, rightType.Type);
        }
开发者ID:couchand,项目名称:oracular-dot-net,代码行数:14,代码来源:TypeCheckerTests.cs


示例16: Portugol

        public Portugol()
            : base(false)
        {
            LanguageFlags = LanguageFlags.CreateAst;

            var numero = new NumberLiteral("Numero", NumberOptions.AllowSign);
            var identificador = new IdentifierTerminal("Identificador");

            var expressao = new NonTerminal("Expressao", typeof (AstNode));
            var termo = new NonTerminal("Termo", typeof (AstNode));
            var chamadaFuncao = new NonTerminal("Chamada funcao", typeof (ChamadaDeFuncao));
            var operacaoBinaria = new NonTerminal("Operacao binaria", typeof (OperacaoBinaria));
            var operacaoComParentese = new NonTerminal("Operacao com parentese", typeof (AstNode));
            var se = new NonTerminal("Se", typeof (CondicaoSe));
            var operador = new NonTerminal("Operador", typeof(AstNode));
            var operadorLogico = new NonTerminal("Operador logico", typeof (AstNode));
            var argumentos = new NonTerminal("Argumentos", typeof (AstNode));
            var sePart = new NonTerminal("Se parte", typeof (AstNode));
            var entaoPart = new NonTerminal("Entao parte", typeof (AstNode));
            var senaoPart = new NonTerminal("Senao parte", typeof (AstNode));

            NonGrammarTerminals.Add(new CommentTerminal("comment1", "/*", "*/"));

            expressao.Rule = operacaoBinaria | operacaoComParentese | se | chamadaFuncao | termo;
            termo.Rule = numero;
            operacaoComParentese.Rule = ToTerm("(") + expressao + ")";
            operacaoBinaria.Rule = expressao + operador + expressao;
            operador.Rule = ToTerm("+") | "-" | "*" | "/" | "^" | "%" | "=" | "<" | ">" | "<=" | ">=" | "<>" | "E" | "OU";

            sePart.Rule = ToTerm("Se");
            entaoPart.Rule = ToTerm("Entao");
            senaoPart.Rule = ToTerm("Senao");

            se.Rule = sePart + expressao + entaoPart + expressao + senaoPart + expressao;

            argumentos.Rule = MakePlusRule(argumentos, ToTerm(","), expressao);

            chamadaFuncao.Rule = identificador | identificador + "(" + argumentos + ")";

            RegisterOperators(1, "E", "OU");
            RegisterOperators(5, "=", "<", ">", "<=", ">=", "<>");
            RegisterOperators(10, "+", "-");
            RegisterOperators(20, "*", "/", "%", "^");
            MarkPunctuation("(", ")");
            RegisterBracePair("(", ")");

            MarkTransient(expressao, operador, termo, operadorLogico, operacaoComParentese);
            Root = expressao;
            LanguageFlags = LanguageFlags.CreateAst;
        }
开发者ID:AlbertoMonteiro,项目名称:Portugol-with-CSharp,代码行数:50,代码来源:Portugol.cs


示例17: NumericalSchemeGrammar

        public NumericalSchemeGrammar()
        {
            this.GrammarComments = "";

            //Symbols
            var whitespace = new NonTerminal("WhiteSpace", Empty | " " | "\t");
            // Comments
            var singleLineComment = new CommentTerminal("SingleLineComment", "//", "\r", "\n", "\u2085", "\u2028", "\u2029");
            var multiLineComment = new CommentTerminal("DelimitedComment", "/*", "*/");
            NonGrammarTerminals.Add(singleLineComment);
            NonGrammarTerminals.Add(multiLineComment);

            //Terminals
            var semicolon = ToTerm(";", "Semicolon");
            var ofString = new StringLiteral("String", "\"");
            var ofNumber = new NumberLiteral("Number", NumberOptions.AllowSign);
            var ofIdentifier = TerminalFactory.CreateCSharpIdentifier("Identifier");
            var ofArrayTerm = new IdentifierTerminal("SchemeTerm", "(),|*.+-/%^~!&");

            //Non-terminals
            var ofValue = new NonTerminal("Value");

            var ofDictionary = new NonTerminal("Dictionary");
            var ofDictionaryContent = new NonTerminal("DictionaryContent");
            var ofDictionaryContentWrapper = new NonTerminal("DictionaryContentWrapper");
            var ofDictEntry = new NonTerminal("DictEntry");

            var ofArrayEntry = new NonTerminal("ArrayEntry");
            var ofArray = new NonTerminal("Array");
            var ofArrayWrapper = new NonTerminal("ArrayWrapper");

            //BNF
            ofValue.Rule = ofIdentifier | ofArrayTerm | ofString | ofNumber;

            ofDictEntry.Rule = ofArrayWrapper | ofDictionary;
            ofDictionaryContent.Rule = MakeStarRule(ofDictionaryContent, whitespace, ofDictEntry);
            ofDictionaryContentWrapper.Rule = "{" + ofDictionaryContent + "}";
            ofDictionary.Rule = ofIdentifier + whitespace + ofDictionaryContentWrapper;

            ofArrayEntry.Rule = ofValue;
            ofArray.Rule = MakeStarRule(ofArray, whitespace, ofArrayEntry);
            ofArrayWrapper.Rule = ofArray + semicolon;

            //Set grammar root
            this.Root = ofDictionaryContent;
            MarkPunctuation("{", "}");
            MarkTransient(ofValue, ofDictionaryContentWrapper);
        }
开发者ID:mohsenboojari,项目名称:offwind,代码行数:48,代码来源:NumericalSchemeGrammar.cs


示例18: TestNumber_General

    public void TestNumber_General() {
      Parser parser; Token token;

      NumberLiteral number = new NumberLiteral("Number");
      number.DefaultIntTypes = new TypeCode[] { TypeCode.Int32, TypeCode.Int64, NumberLiteral.TypeCodeBigInt };
      parser = TestHelper.CreateParser(number);
      token = parser.ParseInput("123");
      CheckType(token, typeof(int));
      Assert.IsTrue((int)token.Value == 123, "Failed to read int value");
      token = parser.ParseInput("123.4");
      Assert.IsTrue(Math.Abs(Convert.ToDouble(token.Value) - 123.4) < 0.000001, "Failed to read float value");
      //100 digits
      string sbig = "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
      token = parser.ParseInput(sbig);
      Assert.IsTrue(token.Value.ToString() == sbig, "Failed to read big integer value");
    }//method
开发者ID:androdev4u,项目名称:XLParser,代码行数:16,代码来源:NumberLiteralTests.cs


示例19: Kbtter3QueryGrammar

        /// <summary>
        /// 使うな
        /// </summary>
        public Kbtter3QueryGrammar()
            : base()
        {
            //コメント
            var comment = new CommentTerminal("Comment", "/*", "*/");
            NonGrammarTerminals.Add(comment);

            //リテラル
            var number = new NumberLiteral("Number", NumberOptions.AllowSign | NumberOptions.AllowStartEndDot);
            var str = new StringLiteral("String", "\"");
            var regex = new RegexLiteral("Regex", '/', '\\');
            var ident = new IdentifierTerminal("Identifer");

            //非終端
            var Value = new NonTerminal("Value");
            var Term = new NonTerminal("Term");
            var Expression = new NonTerminal("Expression");
            var BinExpression = new NonTerminal("BinExpression");
            var ParExpression = new NonTerminal("ParExpression");
            var PostfixExpression = new NonTerminal("PostfixExpression");
            var Operator = new NonTerminal("Operator");

            //非終端定義
            Value.Rule = number | str | ident | regex | "null" | "true" | "false";
            Term.Rule = Value | ParExpression;
            Operator.Rule = ToTerm("==") | "!=" | ">" | "<" | ">=" | "<=" | "match" | "&&" | "||" | "+" | "-" | "*" | "/" | "%" | "&" | "|" | "^" | ".";
            BinExpression.Rule = Expression + Operator + Expression;
            PostfixExpression.Rule = (ToTerm("+") + Term) | ("-" + Term) | ("!" + Term);
            Expression.Rule = BinExpression | Term | PostfixExpression;
            ParExpression.Rule = ToTerm("(") + Expression + ")";

            RegisterOperators(10, ".");
            RegisterOperators(9, "*", "/", "%");
            RegisterOperators(8, "+", "-");
            RegisterOperators(7, ">", "<", ">=", "<=", "match");
            RegisterOperators(6, "==", "!=");
            RegisterOperators(5, "&");
            RegisterOperators(4, "^");
            RegisterOperators(3, "|");
            RegisterOperators(2, "&&");
            RegisterOperators(1, "||");

            Root = Expression;
            MarkPunctuation("(", ")");
            MarkTransient(Expression, ParExpression, Value, Operator, Term);
        }
开发者ID:kb10uy,项目名称:Kbtter4,代码行数:49,代码来源:Kbtter3QueryGrammar.cs


示例20: ExpressionGrammar

        public ExpressionGrammar()
        {
            this.GrammarComments = @"Arithmetical expressions for dynamic geometry.";

            // 1. Terminals
            var number = new NumberLiteral("number");
            var identifier = new IdentifierTerminal("identifier");

            // 2. Non-terminals
            var Expr = new NonTerminal("Expr");
            var Term = new NonTerminal("Term");
            var BinExpr = new NonTerminal("BinExpr");
            var ParExpr = new NonTerminal("ParExpr");
            var UnExpr = new NonTerminal("UnExpr");
            var UnOp = new NonTerminal("UnOp");
            var BinOp = new NonTerminal("BinOp", "operator");
            var PropertyAccess = new NonTerminal("PropertyAccess");
            var FunctionCall = new NonTerminal("FunctionCall");
            var CommaSeparatedIdentifierList = new NonTerminal("PointArgumentList");
            var ArgumentList = new NonTerminal("ArgumentList");

            // 3. BNF rules
            Expr.Rule = Term | UnExpr | BinExpr;
            Term.Rule = number | identifier | ParExpr | FunctionCall | PropertyAccess;
            UnExpr.Rule = UnOp + Term;
            UnOp.Rule = ToTerm("-");
            BinExpr.Rule = Expr + BinOp + Expr;
            BinOp.Rule = ToTerm("+") | "-" | "*" | "/" | "^";
            PropertyAccess.Rule = identifier + "." + identifier;
            FunctionCall.Rule = identifier + "(" + ArgumentList + ")";
            ArgumentList.Rule = Expr | CommaSeparatedIdentifierList;
            ParExpr.Rule = "(" + Expr + ")";
            CommaSeparatedIdentifierList.Rule = MakePlusRule(CommaSeparatedIdentifierList, ToTerm(","), identifier);

            this.Root = Expr;

            // 4. Operators precedence
            RegisterOperators(1, "+", "-");
            RegisterOperators(2, "*", "/");
            RegisterOperators(3, Associativity.Right, "^");

            MarkPunctuation("(", ")", ".", ",");
            MarkTransient(Term, Expr, BinOp, UnOp, ParExpr, ArgumentList, CommaSeparatedIdentifierList);
        }
开发者ID:ondrej11,项目名称:o106,代码行数:44,代码来源:Grammar.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# NumberStyles类代码示例发布时间:2022-05-24
下一篇:
C# NumberFormatInfo类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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