本文整理汇总了C#中NumberLiteral类的典型用法代码示例。如果您正苦于以下问题:C# NumberLiteral类的具体用法?C# NumberLiteral怎么用?C# NumberLiteral使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NumberLiteral类属于命名空间,在下文中一共展示了NumberLiteral类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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 + "}";
}
示例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;
}
示例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");
}
示例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
示例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;
}
示例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.");
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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
示例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);
}