本文整理汇总了C#中Tokens类的典型用法代码示例。如果您正苦于以下问题:C# Tokens类的具体用法?C# Tokens怎么用?C# Tokens使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Tokens类属于命名空间,在下文中一共展示了Tokens类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HashingStringMatch
static HashingStringMatch()
{
tokens = new Tokens[300];
Random r = new Random();
//1. Build codes for each token
for (char c = 'A'; c <= 'Z'; c++)
{
Tokens t = new Tokens(c, Convert.ToUInt64(r.Next(1, Int32.MaxValue)));
tokens[Convert.ToInt32(c)] = t;
}
for (char c = 'a'; c <= 'z'; c++)
{
Tokens t = new Tokens(c, Convert.ToUInt64(r.Next(1, Int32.MaxValue)));
tokens[Convert.ToInt32(c)] = t;
}
tokens[Convert.ToInt32(' ')] = new Tokens(' ', (UInt64)r.Next(1, Int32.MaxValue));
//tokens[Convert.ToInt32('\'')] = new Tokens('\'', (UInt64)r.Next(1, Int32.MaxValue));
//tokens[Convert.ToInt32('"')] = new Tokens('"', (UInt64)r.Next(1, Int32.MaxValue));
//tokens[Convert.ToInt32('.')] = new Tokens('.', (UInt64)r.Next(1, Int32.MaxValue));
//tokens[Convert.ToInt32(',')] = new Tokens(',', (UInt64)r.Next(1, Int32.MaxValue));
//tokens[Convert.ToInt32('!')] = new Tokens('!', (UInt64)r.Next(1, Int32.MaxValue));
//tokens[Convert.ToInt32('?')] = new Tokens('?', (UInt64)r.Next(1, Int32.MaxValue));
//tokens[Convert.ToInt32('-')] = new Tokens('-', (UInt64)r.Next(1, Int32.MaxValue));
//tokens[Convert.ToInt32(':')] = new Tokens(':', (UInt64)r.Next(1, Int32.MaxValue));
//tokens[Convert.ToInt32('t')] = new Tokens('t', 7);
//tokens[Convert.ToInt32('e')] = new Tokens('e', 8);
//tokens[Convert.ToInt32('s')] = new Tokens('s', 9);
//tokens[Convert.ToInt32('a')] = new Tokens('t', 5);
}
示例2: Maek
public static Token Maek(Tokens kind, int tokLin, int tokCol, int tokELin, int tokECol)
{
return new Token(
kind,
new SourceSpan(new SourceLocation(1, tokLin, tokCol + 1), new SourceLocation(1, tokELin, tokECol + 1))
);
}
示例3: Parse
public override Mediator.Intermediate.ICodeNode Parse(Tokens.Token token)
{
ICodeNode assignNode = IntermediateCodeFactory.CreateICodeNode("assign");
string targetName = token.Text;
ISymbolTableEntry symId = Stack.Find(targetName);
if (symId == null)
symId = Stack.EnterLocal(targetName);
symId.AppendLineNumber(token.LineNumber);
token = NextToken();
ICodeNode variable = IntermediateCodeFactory.CreateICodeNode("variable");
variable.SetAttribute("id", symId);
assignNode.AddChild(variable);
if (token.TokenType == "colon_equals")
{
token = NextToken(); //the other side i.e the thint that is the value
}
else
{
ErrorHandler.Singleton.Flag(token, "missing_colon_equals", this);
}
//simplify and asume constant value (int)
ICodeNode constant = IntermediateCodeFactory.CreateICodeNode("int_const");
constant.SetAttribute("value", token.Value);
assignNode.AddChild(constant);
NextToken(); //consume ;
return assignNode;
}
示例4: EvaluateOperation
protected IPrimitiveToken EvaluateOperation(IPrimitiveToken x, IPrimitiveToken y, Tokens o)
{
switch(o) {
case Tokens.EQ:
return new BooleanToken(x.CompareTo(y) == 0);
case Tokens.NEQ:
return new BooleanToken(x.CompareTo(y) != 0);
case Tokens.GT:
return new BooleanToken(x.CompareTo(y) > 0);
case Tokens.GEQ:
return new BooleanToken(x.CompareTo(y) >= 0);
case Tokens.LT:
return new BooleanToken(x.CompareTo(y) < 0);
case Tokens.LEQ:
return new BooleanToken(x.CompareTo(y) <= 0);
case Tokens.PLUS:
return new NumberToken(x.ToDouble() + y.ToDouble());
case Tokens.MINUS:
return new NumberToken(x.ToDouble() - y.ToDouble());
case Tokens.MULT:
return new NumberToken(x.ToDouble() * y.ToDouble());
case Tokens.DIV:
return new NumberToken(x.ToDouble() / y.ToDouble());
case Tokens.EXP:
return new NumberToken(Math.Pow(x.ToDouble(), y.ToDouble()));
case Tokens.CONCAT:
return new StringToken(x.ToString() + y.ToString());
default:
throw new ArgumentException("Unknown Operator");
}
}
示例5: intern
internal static string intern(Tokens token)
{
switch (token)
{
case Tokens.tDOT2: return "..";
case Tokens.tDOT3: return "...";
case Tokens.tPOW: return "**";
case Tokens.tUPLUS: return "[email protected]";
case Tokens.tUMINUS: return "[email protected]";
case Tokens.tCMP: return "<=>";
case Tokens.tGEQ: return ">=";
case Tokens.tLEQ: return "<=";
case Tokens.tEQ: return "==";
case Tokens.tEQQ: return "===";
case Tokens.tNEQ: return "!=";
case Tokens.tMATCH: return "=~";
case Tokens.tNMATCH: return "!~";
case Tokens.tAREF: return "[]";
case Tokens.tASET: return "[]=";
case Tokens.tLSHFT: return "<<";
case Tokens.tRSHFT: return ">>";
case Tokens.tCOLON2: return "::";
case Tokens.tOROP: return "||";
case Tokens.tANDOP: return "&&";
default: return token.ToString();
}
}
示例6: MaekString
public static Token MaekString(Tokens kind, String value, int tokLin, int tokCol, int tokELin, int tokECol)
{
return new Token(
kind,
value.Substring(1, value.Length - 2),
new SourceSpan(new SourceLocation(1, tokLin, tokCol + 1), new SourceLocation(1, tokELin, tokECol + 1))
);
}
示例7: Next
public AssertTokenizer/*!*/ Next() {
_actualToken = _tokenizer.GetNextToken();
_actualValue = _tokenizer.TokenValue;
_actualSpan = _tokenizer.TokenSpan;
_allTokens.Add(_actualToken);
_allValues.Add(_actualValue);
return this;
}
示例8: Main
// Test Tokens, TokenEnumerator
static void Main()
{
// Testing Tokens by breaking the string into tokens:
Tokens f = new Tokens("This is a well-done program.", new char[] {' ','-'});
foreach (string item in f) {
Console.WriteLine(item);
}
}
示例9: Player
public Player(string name, Int16 number)
{
_name = name;
_number = number;
_token = Tokens.None;
_space = 0;
_cash = 1500;
}
示例10: InterpretExpression
public IToken InterpretExpression(IToken n, Tokens o)
{
n = InterpretExpression(n);
if(n is IPrimitiveToken) {
return EvaluateOperation((IPrimitiveToken) n, o);
} else {
return EvaluateComplexOperation(n, o);
}
}
示例11: Main
// 测试标记 TokenEnumerator
static void Main()
{
Tokens f = new Tokens("This is a well-done program.",
new char [] {' ','-'});
foreach (string item in f) // 要将 string 更改为 int
{
Console.WriteLine(item);
}
}
示例12: TokenGroup
public TokenGroup(CA ca, Tokens token, List<int[]> liveCells)
{
Token = token;
PopulationSize = ca.PopulationSize;
NumberOfGens = ca.NumberOfGens;
NhbdSize = ca.NhbdSize;
Cells = liveCells;
}
示例13: Main
// 测试标记 TokenEnumerator
static void Main()
{
// 通过将字符串分解为标记来测试标记:
Tokens f = new Tokens("This is a well-done program.",
new char[] {' ','-'});
foreach (string item in f)
{
Console.WriteLine(item);
}
}
示例14: CompilerOutput
public CompilerOutput(string input, Tokens tokens, System.Numerics.Complex returnVal, ParseTree parseTree,
PostfixedTokens postFixedTokens, string output)
{
this.Input = input;
this.Tokens = tokens;
this.ReturnValue = returnVal;
this.ParseTree = parseTree;
this.PostFixedTokens = postFixedTokens;
this.Output = output;
}
示例15: Main
// Test the Tokens class.
static void Main()
{
// Create a Tokens instance.
Tokens f = new Tokens("This is a sample sentence.", new char[] {' ','-'});
// Display the tokens.
foreach (string item in f)
{
System.Console.WriteLine(item);
}
}
开发者ID:terryjintry,项目名称:OLSource1,代码行数:12,代码来源:how-to--access-a-collection-class-with-foreach--csharp-programming-guide-_2.cs