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


C# NumberLiteral.AddPrefix方法代码示例

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


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

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

示例2: CreateVbNumber

 //http://www.microsoft.com/downloads/details.aspx?FamilyId=6D50D709-EAA4-44D7-8AF3-E14280403E6E&displaylang=en section 2
 public static NumberLiteral CreateVbNumber(string name) {
   NumberLiteral term = new NumberLiteral(name);
   term.DefaultIntTypes = new TypeCode[] { TypeCode.Int32, TypeCode.Int64 };
   //term.DefaultFloatType = TypeCode.Double; it is default
   term.AddPrefix("&H", NumberOptions.Hex);
   term.AddPrefix("&O", NumberOptions.Octal);
   term.AddSuffix("S", TypeCode.Int16);
   term.AddSuffix("I", TypeCode.Int32);
   term.AddSuffix("%", TypeCode.Int32);
   term.AddSuffix("L", TypeCode.Int64);
   term.AddSuffix("&", TypeCode.Int64);
   term.AddSuffix("D", TypeCode.Decimal);
   term.AddSuffix("@", TypeCode.Decimal);
   term.AddSuffix("F", TypeCode.Single);
   term.AddSuffix("!", TypeCode.Single);
   term.AddSuffix("R", TypeCode.Double);
   term.AddSuffix("#", TypeCode.Double);
   term.AddSuffix("US", TypeCode.UInt16);
   term.AddSuffix("UI", TypeCode.UInt32);
   term.AddSuffix("UL", TypeCode.UInt64);
   return term;
 }
开发者ID:androdev4u,项目名称:XLParser,代码行数:23,代码来源:TerminalFactory.cs

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

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

示例5: LiteralRules

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

            NumberLiteral  = new NumberLiteral("number_literal", NumberOptions.AllowStartEndDot)
            {
                // Define types to assign if the parser can't determine.
                DefaultIntTypes = new[] { TypeCode.Int32 },
                DefaultFloatType = TypeCode.Double
            };

            // The pre and post fixes for different number types and formats.
            NumberLiteral.AddPrefix("0x", NumberOptions.Hex);
            NumberLiteral.AddSuffix("b", TypeCode.Byte);
            NumberLiteral.AddSuffix("B", TypeCode.Byte);
            NumberLiteral.AddSuffix("s", TypeCode.Int16);
            NumberLiteral.AddSuffix("S", TypeCode.Int16);
            NumberLiteral.AddSuffix("u", TypeCode.UInt32);
            NumberLiteral.AddSuffix("U", TypeCode.UInt32);
            NumberLiteral.AddSuffix("us", TypeCode.UInt16);
            NumberLiteral.AddSuffix("US", TypeCode.UInt16);
            NumberLiteral.AddSuffix("l", TypeCode.Int64);
            NumberLiteral.AddSuffix("L", TypeCode.Int64);
            NumberLiteral.AddSuffix("ul", TypeCode.UInt64);
            NumberLiteral.AddSuffix("UL", TypeCode.UInt64);
            NumberLiteral.AddSuffix("F", TypeCode.Single);
            NumberLiteral.AddSuffix("f", TypeCode.Single);
            NumberLiteral.AddSuffix("d", TypeCode.Double);
            NumberLiteral.AddSuffix("D", TypeCode.Double);
            NumberLiteral.AddSuffix("m", TypeCode.Decimal);
            NumberLiteral.AddSuffix("M", TypeCode.Decimal);

            StringLiteral = new StringLiteral("string_literal", "\"", StringOptions.AllowsAllEscapes);

            CharLiteral = new StringLiteral("char_literal", "'", StringOptions.IsChar);

            BoolLiteral = new NonTerminal("bool_literal");
            BoolLiteral.Rule = grammar.Keywords.True | grammar.Keywords.False;

            Null = grammar.ToTerm("null", "null_literal");
        }
开发者ID:maleficus1234,项目名称:Pie,代码行数:41,代码来源:LiteralRules.cs

示例6: RefalGrammar

		public RefalGrammar() : base(true) // case sensitive
		{
			GrammarComments = "Refal-5 language interpreter based on Irony toolkit.";

			// Terminals
			var Number = new NumberLiteral("Number");
			Number.DefaultIntTypes = new TypeCode[] { TypeCode.Int32, TypeCode.Int64, NumberLiteral.TypeCodeBigInt };
			Number.AddPrefix("0x", NumberOptions.Hex);
			Number.AddSuffix("u", TypeCode.UInt32);
			Number.AddSuffix("l", TypeCode.Int64);
			Number.AddSuffix("ul", TypeCode.UInt64);
			Number.Options |= NumberOptions.IntOnly;

			var CharLiteral = new StringLiteral("Char", "'", StringOptions.AllowsAllEscapes);
			var StringLiteral = new StringLiteral("String", "\"", StringOptions.AllowsAllEscapes);
			var Identifier = new IdentifierTerminal("Identifier", "_-", "");

			var LineComment = new CommentTerminal("LineComment", "*", "\n", "\r");
			LineComment.ValidateToken += LineComment_ValidateToken;

			var BlockComment = new CommentTerminal("BlockComment", "/*", "*/");
			NonGrammarTerminals.Add(LineComment);
			NonGrammarTerminals.Add(BlockComment);

			// Non-terminals
			var Program = new NonTerminal("Program", typeof(Program));
			var Definition = new NonTerminal("Definition");
			var Function = new NonTerminal("Function", typeof(DefinedFunction));
			var External = new NonTerminal("External", typeof(AuxiliaryNode));
			var IdentifierList = new NonTerminal("Identifier+", typeof(AuxiliaryNode));
			var Block = new NonTerminal("Block", typeof(Block));
			var Sentence = new NonTerminal("Sentence", typeof(Sentence));
			var RSentence = new NonTerminal("RSentence", typeof(AuxiliaryNode));
			var SentenceList = new NonTerminal("Sentence+", typeof(AuxiliaryNode));
			var Pattern = new NonTerminal("Pattern", typeof(Pattern));
			var PatternItem = new NonTerminal("PatternItem");
			var PatternInParentheses = new NonTerminal("(Pattern)", typeof(ExpressionInBraces));
			var Expression = new NonTerminal("Expression", typeof(Expression));
			var ExpressionItem = new NonTerminal("ExpressionItem");
			var ExpressionInParentheses = new NonTerminal("(Expression)", typeof(ExpressionInBraces));
			var Var = new NonTerminal("Variable", Variable.CreateVariableNode);
			var VarPrefix = new NonTerminal("VariablePrefix");
			var VarIndex = new NonTerminal("VariableIndex");
			var Symbol = new NonTerminal("Symbol", LiteralValueNodeHelper.InitNode);
			var Call = new NonTerminal("Call", typeof(FunctionCall));
			var FunctionName = new NonTerminal("FunctionName", typeof(AuxiliaryNode));
			var WhereOrWithClause = new NonTerminal("WhereOrWithClause", typeof(Conditions));
			var CommaOrAmpersand = new NonTerminal("CommaOrAmpersand");
			var RWhereOrWithClause = new NonTerminal("RWhereOrWithClause", typeof(AuxiliaryNode));
			var RExpressionOrWhereOrWithClause = new NonTerminal("RExpressionOrWhereOrWithClause");

			var SemicolonOpt = new NonTerminal("[;]", Empty | ";");
			var EntryOpt = new NonTerminal("[ENTRY]", Empty | "$ENTRY");
			var Extern = new NonTerminal("Extern", ToTerm("$EXTRN") | "$EXTERN" | "$EXTERNAL");

			// Rules
			Root = Program;

			Program.Rule = MakePlusRule(Program, Definition);
			Definition.Rule = Function | External;
			External.Rule = Extern + IdentifierList + ";";
			IdentifierList.Rule = MakePlusRule(IdentifierList, ToTerm(","), Identifier);

			Function.Rule = EntryOpt + Identifier + Block + SemicolonOpt;
			Block.Rule = "{" + SentenceList + SemicolonOpt + "}";
			SentenceList.Rule = MakePlusRule(SentenceList, ToTerm(";"), Sentence);

			Sentence.Rule = Pattern + RSentence;
			RSentence.Rule = "=" + Expression | WhereOrWithClause;
			Pattern.Rule = MakeStarRule(Pattern, PatternItem);
			PatternItem.Rule = Var | Symbol | PatternInParentheses;
			PatternInParentheses.Rule = "(" + Pattern + ")";
			Expression.Rule = MakeStarRule(Expression, ExpressionItem);
			ExpressionItem.Rule = Call | Var | Symbol | ExpressionInParentheses;
			ExpressionInParentheses.Rule = "(" + Expression + ")";

			Var.Rule = VarPrefix + "." + VarIndex;
			VarPrefix.Rule = ToTerm("e") | "s" | "t";
			VarIndex.Rule = Number | Identifier;
			Symbol.Rule = StringLiteral | CharLiteral | Number | "True" | "False" | Identifier;
			Call.Rule = "<" + FunctionName + Expression + ">";
			FunctionName.Rule = Identifier | "+" | "-" | "*" | "/";

			WhereOrWithClause.Rule = CommaOrAmpersand + Expression + ":" + RWhereOrWithClause;
			CommaOrAmpersand.Rule = ToTerm(",") | "&";
			RWhereOrWithClause.Rule = Block // with-clause
				| Pattern + RExpressionOrWhereOrWithClause; // where-clause
			RExpressionOrWhereOrWithClause.Rule = ToTerm("=") + Expression | WhereOrWithClause;

			// Punctuation, braces, transient terms, options
			MarkPunctuation("(", ")");
			MarkPunctuation("{", "}");
			MarkPunctuation("<", ">");
			MarkPunctuation("=", ",", "&", ";");

			RegisterBracePair("(", ")");
			RegisterBracePair("<", ">");
			RegisterBracePair("{", "}");

			MarkTransient(Definition, PatternItem, ExpressionItem, SemicolonOpt, EntryOpt, Extern, CommaOrAmpersand, VarPrefix, VarIndex, RExpressionOrWhereOrWithClause);
//.........这里部分代码省略.........
开发者ID:PrototypeAlpha,项目名称:LiveSplit,代码行数:101,代码来源:RefalGrammar.cs

示例7: CreateSchemeNumber

 // About exponent symbols, extract from R6RS:
 //  ... representations of number objects may be written with an exponent marker that indicates the desired precision 
 // of the inexact representation. The letters s, f, d, and l specify the use of short, single, double, and long precision, respectively.
 // ...
 // In addition, the exponent marker e specifies the default precision for the implementation. The default precision 
 //  has at least as much precision as double, but implementations may wish to allow this default to be set by the user.
 public static NumberLiteral CreateSchemeNumber(string name) {
   NumberLiteral term = new NumberLiteral(name);
   term.DefaultIntTypes = new TypeCode[] { TypeCode.Int32, TypeCode.Int64, NumberLiteral.TypeCodeBigInt };
   term.DefaultFloatType = TypeCode.Double; // it is default
   term.AddExponentSymbols("eE", TypeCode.Double); //default precision for platform, double 
   term.AddExponentSymbols("sSfF", TypeCode.Single); 
   term.AddExponentSymbols("dDlL", TypeCode.Double); 
   term.AddPrefix("#b", NumberOptions.Binary);
   term.AddPrefix("#o", NumberOptions.Octal);
   term.AddPrefix("#x", NumberOptions.Hex);
   term.AddPrefix("#d", NumberOptions.None);
   term.AddPrefix("#i", NumberOptions.None); // inexact prefix, has no effect
   term.AddPrefix("#e", NumberOptions.None); // exact prefix, has no effect
   term.AddSuffix("J", NumberLiteral.TypeCodeImaginary);
   return term;
 }
开发者ID:anukat2015,项目名称:sones,代码行数:22,代码来源:TerminalFactory.cs

示例8: CreatePythonNumber

 //http://docs.python.org/ref/numbers.html
 public static NumberLiteral CreatePythonNumber(string name) {
   NumberLiteral term = new NumberLiteral(name, NumberOptions.AllowStartEndDot);
   //default int types are Integer (32bit) -> LongInteger (BigInt); Try Int64 before BigInt: Better performance?
   term.DefaultIntTypes = new TypeCode[] { TypeCode.Int32, TypeCode.Int64, NumberLiteral.TypeCodeBigInt };
   // term.DefaultFloatType = TypeCode.Double; -- it is default
   //float type is implementation specific, thus try decimal first (higher precision)
   //term.DefaultFloatTypes = new TypeCode[] { TypeCode.Decimal, TypeCode.Double };
   term.AddPrefix("0x", NumberOptions.Hex);
   term.AddPrefix("0", NumberOptions.Octal);
   term.AddSuffix("L", TypeCode.Int64, NumberLiteral.TypeCodeBigInt);
   term.AddSuffix("J", NumberLiteral.TypeCodeImaginary);
   return term;
 }
开发者ID:anukat2015,项目名称:sones,代码行数:14,代码来源:TerminalFactory.cs

示例9: STLGrammar

        public STLGrammar()
            : base(false)
        {
            #region Letters and Digits
            /*
            letter	        A | B | .. | Z | a | b | .. |z
            digit	        0 | 1 | .. | 9
            bit digit	    0|1| .. |7
            binary digit	0 | 1 | _
            hex digit	    digit | A | .. | F | a | .. | f | _
            character	    letter | ASCII 128 | .. | ASCII 255 | _
            first identifier character	character | space
            other identifier character	character | digit | space
            Local Variables (Local ToTerms)	[ # ] identifier
            */
            var semi = ToTerm(";", "semi");
            var semi_opt = new NonTerminal("semi?", Empty | semi);
            var dot = ToTerm(".", "dot");
            var comma = ToTerm(",", "comma");
            var comma_opt = new NonTerminal("comma_opt", Empty | comma);
            var equal = ToTerm("=", "equal");

            var digits = new NumberLiteral("decimal", NumberOptions.IntOnly | NumberOptions.DisableQuickParse);
            var binarys = new NumberLiteral("binary", NumberOptions.IntOnly | NumberOptions.DisableQuickParse | NumberOptions.Binary | NumberOptions.AllowUnderscore);
            var octals = new NumberLiteral("octal", NumberOptions.IntOnly | NumberOptions.DisableQuickParse | NumberOptions.Octal);
            var hexs = new NumberLiteral("hex", NumberOptions.IntOnly | NumberOptions.DisableQuickParse | NumberOptions.Hex | NumberOptions.AllowUnderscore);
            var identifier = TerminalFactory.CreateCSharpIdentifier("identifier");
            var global_variable = new NonTerminal("global_variable", typeof(Variable));
            var local_variable = new NonTerminal("local_variable", typeof(Variable));
            KeyTerm colon = ToTerm(":", "colon");

            binarys.AddPrefix("2#", NumberOptions.Binary);
            hexs.AddPrefix("16#", NumberOptions.Hex);
            global_variable.SetFlag(TermFlags.IsConstant);
            local_variable.SetFlag(TermFlags.IsConstant);

            global_variable.Rule = identifier;
            local_variable.Rule = "#" + identifier;
            #endregion

            #region Program Comments
            /*
            comment characters	printable character CR
            comment	            // { comment characters } CR
            */
            var comment = new CommentTerminal("comment", "//", "\r", "\n");
            var comment_opt = new NonTerminal("comment?");
            var line_comment = new NonTerminal("line_comment");
            var multi_line_comment = new NonTerminal("multi_line_comment");
            var empty_line = new NonTerminal("empty_line");
            var empty_lines = new NonTerminal("empty_line+");
            var empty_lines_opt = new NonTerminal("empty_line*");

            multi_line_comment.SetFlag(TermFlags.IsList);
            empty_lines.SetFlag(TermFlags.IsList);
            empty_lines_opt.SetFlag(TermFlags.IsListContainer);

            comment_opt.Rule = comment | Empty;
            line_comment.Rule = comment + NewLine;
            multi_line_comment.Rule = multi_line_comment + line_comment | line_comment;
            empty_line.Rule = NewLine | line_comment;
            empty_lines.Rule = empty_lines + empty_line | empty_line;
            empty_lines_opt.Rule = empty_lines | Empty;
            #endregion

            #region Instruction mnemonic terminal
            // Bit logic
            var bit_logic_mnemonic = new NonTerminal("bit_logic_mnemonic");
            var clock_mnemonic = new NonTerminal("clock_mnemonic");
            var communication_mnemonic = new NonTerminal("communication_mnemonic");
            var compare_mnemonic = new NonTerminal("compare_mnemonic");
            var convert_mnemonic = new NonTerminal("convert_mnemonic");
            var counter_mnemonic = new NonTerminal("counter_mnemonic");
            var floatpoint_math_mnemonic = new NonTerminal("floatpoint_math_mnemonic");
            var integer_math_mnemonic = new NonTerminal("integer_math_mnemonic");
            var logical_mnemonic = new NonTerminal("logical_mnemonic");
            var move_mnemonic = new NonTerminal("move_mnemonic");
            var program_control_mnemonic = new NonTerminal("program_control_mnemonic");
            var shift_rotate_mnemonic = new NonTerminal("shift_rotate_mnemonic");
            var string_mnemonic = new NonTerminal("string_mnemonic");
            var table_mnemonic = new NonTerminal("table_mnemonic");
            var timer_mnemonic = new NonTerminal("timer_mnemonic");
            var subroutine_mnemonic = new NonTerminal("subroutine_mnemonic");

            bit_logic_mnemonic.Rule =
                ToTerm("LD") | "A" | "O" |
                "LDN" | "AN" | "ON" |
                "LDI" | "AI" | "OI" |
                "LDNI" | "ANI" | "ONI" |
                "NOT" | "EU" | "ED" | "ALD" | "OLD" |
                "LPS" | "LDS" | "LRD" | "LPP" | "=" | "=I" |
                "S" | "SI" | "R" | "RI" | "AENO" | "NOP";
            clock_mnemonic.Rule =
                ToTerm("TODR") | "TODW" | "TODRX" | "TODWX";
            communication_mnemonic.Rule =
                ToTerm("XMT") | "RCV" | "NETR" | "NETW" | "GPA" | "SPA";
            compare_mnemonic.Rule =
                ToTerm("LDB=") | "AB=" | "OB=" |
                "LDB<>" | "AB<>" | "OB<>" |
                "LDB>=" | "AB>=" | "OB>=" |
//.........这里部分代码省略.........
开发者ID:cubean,项目名称:CG,代码行数:101,代码来源:STL.cs

示例10: Grammar

        public Grammar()
        {
            this.LanguageFlags |= Irony.Parsing.LanguageFlags.CreateAst;

            var comment = new CommentTerminal("comment", "//", "\n", "\r\n");
            NonGrammarTerminals.Add(comment);

            var integerLiteral = new NumberLiteral("integer", NumberOptions.IntOnly);
            integerLiteral.AddPrefix("0x", NumberOptions.Hex);
            var identifier = TerminalFactory.CreateCSharpIdentifier("identifier");
            identifier.AstNodeType = typeof(VariableNameNode);

            var inlineASM = new NonTerminal("inline", typeof(InlineASMNode));

            var numberLiteral = new NonTerminal("Number", typeof(NumberLiteralNode));
            var expression = new NonTerminal("Expression");
            var parenExpression = new NonTerminal("Paren Expression");
            var binaryOperation = new NonTerminal("Binary Operation", typeof(BinaryOperationNode));
            var @operator = ToTerm("+") | "-" | "*" | "/" | "%" | "&" | "|" | "^" | "==" | "!=";
            var variableDeclaration = new NonTerminal("Variable Declaration", typeof(VariableDeclarationNode));
            var dereference = new NonTerminal("Dereference", typeof(DereferenceNode));
            var statement = new NonTerminal("Statement");
            var statementList = new NonTerminal("Statement List", typeof(BlockNode));
            var assignment = new NonTerminal("Assignment", typeof(AssignmentNode));
            var ifStatement = new NonTerminal("If", typeof(IfStatementNode));
            var block = new NonTerminal("Block");
            var ifElseStatement = new NonTerminal("IfElse", typeof(IfStatementNode));
            var parameterList = new NonTerminal("Parameter List");
            var functionDeclaration = new NonTerminal("Function Declaration", typeof(FunctionDeclarationNode));
            var parameterDeclaration = new NonTerminal("Parameter Declaration");
            var parameterListDeclaration = new NonTerminal("Parameter Declaration List");
            var returnStatement = new NonTerminal("Return", typeof(ReturnStatementNode));
            //var indexOperation = new NonTerminal("Index Operation", typeof(IndexOperationNode));
            //var indexAssignment = new NonTerminal("Index Assignment", typeof(IndexAssignmentNode));
            //var inlineArgument = new NonTerminal("Inline Argument", typeof(InlineArgumentNode));
            //var inlineArgumentList = new NonTerminal("Inline Argument List");
            //var inlineInstruction = new NonTerminal("Inline Instruction", typeof(InlineInstructionNode));
            //var inlineInstructionList = new NonTerminal("Inline Instruction List");
            //var inlineBlock = new NonTerminal("Inline Block", typeof(InlineBlockNode));
            var functionCall = new NonTerminal("Function Call", typeof(FunctionCallNode));

            numberLiteral.Rule = integerLiteral;
            expression.Rule = numberLiteral | binaryOperation | parenExpression | identifier | dereference | functionCall;
            assignment.Rule = (identifier | dereference) + "=" + expression;
            binaryOperation.Rule = expression + @operator + expression;
            parenExpression.Rule = ToTerm("(") + expression + ")";
            variableDeclaration.Rule = ToTerm("var") + identifier + "=" + expression;
            dereference.Rule = ToTerm("*") + expression;
            statement.Rule = inlineASM | (variableDeclaration + ";")
                | (assignment + ";") | ifStatement | ifElseStatement | block | functionDeclaration | (functionCall + ";")
                | (returnStatement + ";");
            block.Rule = ToTerm("{") + statementList + "}";
            statementList.Rule = MakeStarRule(statementList, statement);
            inlineASM.Rule = ToTerm("asm") + "{" + new FreeTextLiteral("inline asm", "}") + "}";
            ifStatement.Rule = ToTerm("if") + "(" + expression + ")" + statement;
            ifElseStatement.Rule = ToTerm("if") + "(" + expression + ")" + statement + this.PreferShiftHere() + "else" + statement;
            parameterList.Rule = MakeStarRule(parameterList, ToTerm(","), expression);
            functionCall.Rule = identifier + "(" + parameterList + ")";
            parameterDeclaration.Rule = identifier;
            parameterListDeclaration.Rule = MakeStarRule(parameterListDeclaration, ToTerm(","), parameterDeclaration);
            functionDeclaration.Rule = ToTerm("function") + identifier + "(" + parameterListDeclaration + ")" + block;
            returnStatement.Rule = ToTerm("return") + expression;

            this.Root = statementList;

            this.RegisterBracePair("[", "]");
            this.Delimiters = "{}[](),:;+-*/%&|^!~<>=.";
            this.MarkPunctuation(";", ",", "(", ")", "{", "}", "[", "]", ":");
            this.MarkTransient(expression, parenExpression, statement, block);//, parameterList);

            this.RegisterOperators(1, Associativity.Right, "==", "!=");
            this.RegisterOperators(2, Associativity.Right, "=");
            this.RegisterOperators(3, Associativity.Left, "+", "-");
            this.RegisterOperators(4, Associativity.Left, "*", "/");

            this.RegisterOperators(6, Associativity.Left, "[", "]", "<", ">");
        }
开发者ID:BigEd,项目名称:DCPUC,代码行数:77,代码来源:Grammar.cs

示例11: ASMGrammar

        public ASMGrammar()
        {
            this.LanguageFlags = LanguageFlags.CreateAst;

            #region Lexical structure

            // Comments
            var comment = new CommentTerminal("Comment", ";", "\r", "\n", "\u2085", "\u2028", "\u2029");
            this.NonGrammarTerminals.Add(comment);

            // Literals
            var stringLiteral = new StringLiteral("StringLiteral", "\"", StringOptions.AllowsAllEscapes);

            var numberLiteral = new NumberLiteral("NumberLiteral");
            numberLiteral.AddPrefix("0x", NumberOptions.Hex);

            var identifier = new IdentifierTerminal("Label");
            identifier.StartCharCategories.AddRange(new UnicodeCategory[]
            {
                UnicodeCategory.UppercaseLetter,
                UnicodeCategory.LowercaseLetter
            });
            identifier.CharCategories.AddRange(identifier.StartCharCategories);
            identifier.CharCategories.AddRange(new UnicodeCategory[]
            {
                UnicodeCategory.DecimalDigitNumber
            });

            // Symbols
            var colon = ToTerm(":", "colon");
            var comma = ToTerm(",", "comma");
            var plus = ToTerm("+", "plus");

            var bracketLeft = ToTerm("[", "BracketLeft");
            var bracketRight = ToTerm("]", "BracketRight");

            MarkPunctuation(colon, comma, plus, bracketLeft, bracketRight);

            #endregion

            #region Non-terminals

            var lines = new NonTerminal("Lines", typeof(Ast.LinesNode));
            var line = new NonTerminal("Line", typeof(Ast.LineNode));
            var label = new NonTerminal("Label", typeof(Ast.LabelNode));
            var instruction = new NonTerminal("Instruction", typeof(Ast.InstructionNode));
            var instructionWithLabel = new NonTerminal("InstructionWithLabel", typeof(Ast.InstructionWithLabelNode));
            var opcode = new NonTerminal("OpCode", typeof(Ast.DefaultNode));
            var values = new NonTerminal("Values", typeof(Ast.DefaultNode));
            var value = new NonTerminal("Value");
            var simpleValue = new NonTerminal("SimpleValue", typeof(Ast.SimpleValueNode));
            var memoryValue = new NonTerminal("MemoryValue", typeof(Ast.MemoryValueNode));
            var memoryOffsetValue = new NonTerminal("MemoryOffsetValue", typeof(Ast.MemoryOffsetValueNode));
            var labelValue = new NonTerminal("LabelValue", typeof(Ast.LabelValueNode));

            var register = new NonTerminal("Register", typeof(Ast.DefaultNode));
            var misc = new NonTerminal("Misc", typeof(Ast.DefaultNode));

            #endregion

            lines.Rule = MakeListRule(lines, null, line, TermListOptions.PlusList);
            line.Rule = label + Eos | instruction + Eos | instructionWithLabel + Eos;
            label.Rule = colon + identifier;
            instructionWithLabel.Rule = label + instruction;
            instruction.Rule = opcode + values;
            opcode.Rule = identifier;
            values.Rule = MakeListRule(values, comma, value, TermListOptions.PlusList);
            value.Rule = simpleValue | memoryValue | memoryOffsetValue | labelValue;
            simpleValue.Rule = stringLiteral | numberLiteral | register | misc;
            memoryValue.Rule = bracketLeft + simpleValue + bracketRight;
            memoryOffsetValue.Rule = bracketLeft + numberLiteral + plus + register + bracketRight;
            labelValue.Rule = identifier;

            register.Rule = ToTerm("A") | "B" | "C" | "X" | "Y" | "Z" | "I" | "J";
            misc.Rule = ToTerm("SP") | "PC" | "O" | "POP" | "PEEK" | "PUSH";

            // Set the grammar root.
            this.Root = lines;

            MarkTransient(value, register, misc);
        }
开发者ID:jwvdiermen,项目名称:0x1DE,代码行数:81,代码来源:ASMGrammar.cs

示例12: CreateLuaNumber

        protected static NumberLiteral CreateLuaNumber(string name)
        {
            NumberLiteral term = new NumberLiteral(name, NumberOptions.AllowStartEndDot);
            //default int types are Integer (32bit) -> LongInteger (BigInt); Try Int64 before BigInt: Better performance?
            term.DefaultIntTypes = new TypeCode[] { TypeCode.Int32, TypeCode.Int64, NumberLiteral.TypeCodeBigInt };
            term.DefaultFloatType = TypeCode.Double; // it is default
            term.AddPrefix("0x", NumberOptions.Hex);

            return term;
        }
开发者ID:guillaume86,项目名称:vsLua,代码行数:10,代码来源:LuaGrammer.cs

示例13: CreateDasmNumber

        public static NumberLiteral CreateDasmNumber(string name, Options options)
        {
            var lit = new NumberLiteral(name,
                (options.SignedNumbers ? NumberOptions.AllowSign : 0)
                | (options.UnderscoreInNumbers ? NumberOptions.AllowUnderscore : 0)
                | NumberOptions.IntOnly | NumberOptions.NoDotAfterInt);

            lit.DefaultIntTypes = new TypeCode[] { TypeCode.UInt16, TypeCode.Int16 };
            if (options.BinaryLiterals)
                lit.AddPrefix("0b", NumberOptions.Binary);
            lit.AddPrefix("0x", NumberOptions.Hex);

            return lit;
        }
开发者ID:DanielKeep,项目名称:Dk.Dasm,代码行数:14,代码来源:DasmGrammar.cs

示例14: NotchianGrammar

        public NotchianGrammar()
            : base(caseSensitive:false)
        {
            #region parser settings
            this.UsesNewLine = true;
            #endregion

            #region symbols
            var directive = new IdentifierTerminal("directive");
            directive.AllFirstChars = ".";

            var label = new IdentifierTerminal("label", IdOptions.IsNotKeyword);
            label.AllFirstChars = ":";

            var symbol = new IdentifierTerminal("symbol", IdOptions.IsNotKeyword);

            var character_string = new StringLiteral("character_string", "\"");

            var literal = new NumberLiteral("literal", NumberOptions.IntOnly);
            literal.AddPrefix("0x", NumberOptions.Hex);
            literal.AddPrefix("0b", NumberOptions.Binary);

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

            var program = new NonTerminal("program");
            var statement_list = new NonTerminal("statement_list");
            var statement_list_cont = new NonTerminal("statement_list_cont");
            var statement = new NonTerminal("statement");

            var labelled_instruction = new NonTerminal("labelled_instruction");
            var label_opt = new NonTerminal("label_opt");

            var instruction = new NonTerminal("instruction");
            var basic = new NonTerminal("basic_instruction");
            var nonbasic = new NonTerminal("nonbasic_instruction");

            var data = new NonTerminal("data");
            var data_list = new NonTerminal("data_list");
            var datum = new NonTerminal("datum");

            var basic_opcode = new NonTerminal("basic_opcode");
            var nonbasic_opcode = new NonTerminal("nonbasic_opcode");

            var value = new NonTerminal("value");
            var register = new NonTerminal("register");
            var counter = new NonTerminal("register");
            var synonym = new NonTerminal("synonym");

            var address = new NonTerminal("address");
            var pointer = new NonTerminal("pointer");
            var target = new NonTerminal("target");
            var indirection = new NonTerminal("indirection");
            var offset = new NonTerminal("offset");
            #endregion symbols

            #region parser settings
            this.UsesNewLine = true;
            this.Root = program;
            #endregion

            #region grammar rules
            //basic structure
            program.Rule = statement_list + Eof;
            statement_list.Rule = statement + statement_list_cont | Empty;
            statement_list_cont.Rule = NewLine + statement_list;
            statement.Rule = directive | label | labelled_instruction | Empty;

            //lines and labels
            labelled_instruction.Rule = label_opt + instruction;
            label_opt.Rule = label | Empty;

            //instructions
            instruction.Rule = basic | nonbasic | data;
            basic.Rule = basic_opcode + value + "," + value;
            nonbasic.Rule = nonbasic_opcode + value;

            //data
            data.Rule = ToTerm("DAT") + data_list;
            data_list.Rule = MakeListRule(data_list, ToTerm(","), datum, TermListOptions.PlusList);
            datum.Rule = literal | character_string;

            //opcodes
            basic_opcode.Rule = ToTerm("SET") | "ADD" | "SUB" | "MUL" | "DIV" | "MOD" | "SHL" | "SHR" | "AND" | "BOR" | "XOR" | "IFE" | "IFN" | "IFG" | "IFB";
            nonbasic_opcode.Rule = ToTerm("JSR");

            //values
            value.Rule = literal | register | counter | synonym | address;
            register.Rule = ToTerm("A") | "B" | "C" | "X" | "Y" | "Z" | "I" | "J";
            counter.Rule = ToTerm("SP") | "PC" | "O";
            synonym.Rule = ToTerm("POP") | "PEEK" | "PUSH";

            address.Rule = pointer | symbol;
            pointer.Rule = ToTerm("[") + target + ToTerm("]");
            target.Rule = literal | register | indirection;
            indirection.Rule = (register + ToTerm("+") + offset) | (offset + ToTerm("+") + register);
            offset.Rule = literal | symbol;

            this.Root = program;
            #endregion
//.........这里部分代码省略.........
开发者ID:gulbanana,项目名称:quasar,代码行数:101,代码来源:NotchianGrammar.cs

示例15: BnfGrammar

        public BnfGrammar(Mode mode)
        {
            var alternationChar = (mode == Mode.Strict) ? "/" : "|";

            var rulename = new IdentifierTerminal("rulename", "-_", null);
            var funcname = new IdentifierTerminal("funcname", ".", null);
            var newrulename = new IdentifierTerminal("newrulename", "-_", null);
            //var comment1 = new CommentTerminal("comment", "/*", "*/");
            var comment = new CommentTerminal("comment", ";", "\n");
            var bindig1 = new NumberLiteral("bindig", NumberOptions.Binary | NumberOptions.IntOnly);
            var bindig2 = new NumberLiteral("bindig", NumberOptions.Binary | NumberOptions.IntOnly);
            var hexdig1 = new NumberLiteral("hexdig", NumberOptions.Hex | NumberOptions.IntOnly);
            var hexdig2 = new NumberLiteralEx("hexdig", NumberOptions.Hex | NumberOptions.IntOnly);
            var decdig1 = new NumberLiteral("decvalue", NumberOptions.IntOnly);
            var decdig2 = new NumberLiteral("decvalue", NumberOptions.IntOnly);
            var charval = new StringLiteral("charval", "\"", StringOptions.NoEscapes);
            var repeat1 = new NumberLiteral("repeat1", NumberOptions.IntOnly | NumberOptions.AllowLetterAfter);
            var repeat2 = new NumberLiteral("repeat2", NumberOptions.IntOnly | NumberOptions.AllowLetterAfter);
            var minus = ToTerm("-", "minus");
            var point = ToTerm(".", "point");

            bindig1.AddPrefix("b", NumberOptions.None);
            hexdig1.AddPrefix("x", NumberOptions.None);
            decdig1.AddPrefix("d", NumberOptions.None);

            //base.NonGrammarTerminals.Add(comment1);
            base.NonGrammarTerminals.Add(comment);

            // NON TERMINALS
            var numval = new NonTerminal("numval");

            var hexval = new NonTerminal("hexval");
            var hexvalp = new NonTerminal("hexvalpoint");
            var hexvalps = new NonTerminal("hexvalpointstar");

            var binval = new NonTerminal("binval");
            var binvalp = new NonTerminal("binvalpoint");
            var binvalps = new NonTerminal("binvalpointstar");

            var decval = new NonTerminal("decval");
            var decvalp = new NonTerminal("decvalpoint");
            var decvalps = new NonTerminal("decvalpointstar");

            var rule = new NonTerminal("rule");
            var rulelist = new NonTerminal("rulelist");
            var alternation = new NonTerminal("alternation");
            var concatenation = new NonTerminal("concatenation");
            var subtraction = new NonTerminal("subtraction");
            var repetition = new NonTerminal("repetition");
            var repeat = new NonTerminal("repeat");
            var element = new NonTerminal("element");
            var elements = new NonTerminal("elements");
            var group = new NonTerminal("group");
            var option = new NonTerminal("option");
            var func = new NonTerminal("func");
            var funcarg = new NonTerminal("funcarg");
            var funcargs = new NonTerminal("funcargs");

            // RULES
            hexval.Rule = hexdig1 + (hexvalps | (minus + hexdig2) | Empty);
            hexvalp.Rule = point + hexdig2;
            hexvalps.Rule = MakePlusRule(hexvalps, hexvalp);

            binval.Rule = bindig1 + (binvalps | (minus + bindig2) | Empty);
            binvalp.Rule = point + bindig2;
            binvalps.Rule = MakePlusRule(binvalps, binvalp);

            decval.Rule = decdig1 + (decvalps | (minus + decdig2) | Empty);
            decvalp.Rule = point + decdig2;
            decvalps.Rule = MakePlusRule(decvalps, decvalp);

            numval.Rule = ToTerm("%") + (binval | hexval | decval);

            BnfExpression rp = ToTerm("*");
            if (mode == Mode.HttpCompatible)
                rp = rp | "#";

            repeat.Rule = ((repeat1) | ((repeat1 | Empty) + rp + (repeat2 | Empty)));
            group.Rule = ToTerm("(") + alternation + ")";
            option.Rule = ToTerm("[") + alternation + "]";

            funcarg.Rule = alternation;
            funcargs.Rule = MakePlusRule(funcargs, ToTerm(","), funcarg);
            func.Rule = ToTerm("{") + funcname + "," + funcargs + "}";

            alternation.Rule = MakePlusRule(alternation, ToTerm(alternationChar), subtraction);
            subtraction.Rule = MakePlusRule(subtraction, ToTerm("&!"), concatenation);
            concatenation.Rule = MakePlusRule(concatenation, repetition);

            repetition.Rule = (Empty | repeat) + element;
            element.Rule = rulename | group | option | numval | charval | func;

            elements.Rule = alternation;
            rule.Rule = NewLineStar + newrulename + (ToTerm("=") | ToTerm("=" + alternationChar)) + elements + NewLinePlus;
            rulelist.Rule = MakeStarRule(rulelist, rule);

            base.Root = rulelist;
        }
开发者ID:vf1,项目名称:bnf2dfa,代码行数:98,代码来源:BnfGrammar.cs


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