本文整理汇总了C#中Iodine.Compiler.TokenStream类的典型用法代码示例。如果您正苦于以下问题:C# TokenStream类的具体用法?C# TokenStream怎么用?C# TokenStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TokenStream类属于Iodine.Compiler命名空间,在下文中一共展示了TokenStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseClass
private static AstNode ParseClass (TokenStream stream)
{
stream.Expect (TokenClass.Keyword, "class");
string name = stream.Expect (TokenClass.Identifier).Value;
List<string> baseClass = new List<string> ();
if (stream.Accept (TokenClass.Colon)) {
do {
baseClass.Add (ParseClassName (stream));
} while (stream.Accept (TokenClass.Comma));
}
ClassDeclaration clazz = new ClassDeclaration (stream.Location, name, baseClass);
stream.Expect (TokenClass.OpenBrace);
while (!stream.Match (TokenClass.CloseBrace)) {
if (stream.Match (TokenClass.Keyword, "func") || stream.Match (TokenClass.Operator,
"@")) {
FunctionDeclaration func = ParseFunction (stream, false, clazz) as FunctionDeclaration;
if (func.Name == name) {
clazz.Constructor = func;
} else {
clazz.Add (func);
}
} else {
clazz.Add (ParseStatement (stream));
}
}
stream.Expect (TokenClass.CloseBrace);
return clazz;
}
示例2: ParseAnd
public static AstNode ParseAnd(TokenStream stream)
{
AstNode expr = ParseEquals (stream);
while (stream.Accept (TokenClass.Operator, "&")) {
expr = new BinaryExpression (stream.Location, BinaryOperation.And, expr,
ParseEquals (stream));
}
return expr;
}
示例3: Scan
public TokenStream Scan()
{
TokenStream retStream = new TokenStream (errorLog);
EatWhiteSpaces ();
while (PeekChar () != -1) {
Token nextToken = NextToken ();
if (nextToken != null)
retStream.AddToken (nextToken);
EatWhiteSpaces ();
}
return retStream;
}
示例4: Scan
public TokenStream Scan ()
{
TokenStream retStream = new TokenStream (errorLog);
EatWhiteSpaces ();
while (PeekChar () != -1) {
Token nextToken = NextToken ();
if (nextToken != null)
retStream.AddToken (nextToken);
EatWhiteSpaces ();
}
if (errorLog.ErrorCount > 0) {
throw new SyntaxException (errorLog);
}
return retStream;
}
示例5: ParseAdditive
public static AstNode ParseAdditive(TokenStream stream)
{
AstNode expr = ParseMultiplicative (stream);
while (stream.Match (TokenClass.Operator)) {
switch (stream.Current.Value) {
case "+":
stream.Accept (TokenClass.Operator);
expr = new BinaryExpression (stream.Location, BinaryOperation.Add, expr,
ParseMultiplicative (stream));
continue;
case "-":
stream.Accept (TokenClass.Operator);
expr = new BinaryExpression (stream.Location, BinaryOperation.Sub, expr,
ParseMultiplicative (stream));
continue;
default:
break;
}
break;
}
return expr;
}
示例6: ParseHash
private static AstNode ParseHash(TokenStream stream)
{
stream.Expect (TokenClass.OpenBrace);
HashExpression ret = new HashExpression (stream.Location);
while (!stream.Match (TokenClass.CloseBrace)) {
ret.Add (ParseExpression (stream));
stream.Expect (TokenClass.Colon);
ret.Add (ParseExpression (stream));
if (!stream.Accept (TokenClass.Comma)) {
break;
}
}
stream.Expect (TokenClass.CloseBrace);
return ret;
}
示例7: ParseIf
private static AstNode ParseIf(TokenStream stream)
{
IfStatement ifStmt = new IfStatement (stream.Location);
stream.Expect (TokenClass.Keyword, "if");
stream.Expect (TokenClass.OpenParan);
ifStmt.Add (ParseExpression (stream));
stream.Expect (TokenClass.CloseParan);
ifStmt.Add (ParseStatement (stream));
if (stream.Accept (TokenClass.Keyword, "else")) {
ifStmt.Add (ParseStatement (stream));
} else {
ifStmt.Add (new CodeBlock (stream.Location));
}
return ifStmt;
}
示例8: ParseBoolOr
private static AstNode ParseBoolOr(TokenStream stream)
{
AstNode expr = ParseBoolAnd (stream);
while (stream.Match (TokenClass.Operator)) {
switch (stream.Current.Value) {
case "||":
stream.Accept (TokenClass.Operator);
expr = new BinaryExpression (stream.Location, BinaryOperation.BoolOr, expr,
ParseBoolAnd (stream));
continue;
case "??":
stream.Accept (TokenClass.Operator);
expr = new BinaryExpression (stream.Location, BinaryOperation.NullCoalescing, expr,
ParseBoolAnd (stream));
continue;
default:
break;
}
break;
}
return expr;
}
示例9: ParseGiven
private static AstNode ParseGiven(TokenStream stream)
{
GivenStatement switchStmt = new GivenStatement (stream.Location);
stream.Expect (TokenClass.Keyword, "given");
stream.Expect (TokenClass.OpenParan);
switchStmt.Add (ParseExpression (stream));
stream.Expect (TokenClass.CloseParan);
stream.Expect (TokenClass.OpenBrace);
AstNode defaultBlock = new AstRoot (stream.Location);
AstRoot caseStatements = new AstRoot (stream.Location);
while (!stream.EndOfStream && !stream.Match (TokenClass.CloseBrace)) {
caseStatements.Add (ParseWhen (stream));
if (stream.Accept (TokenClass.Keyword, "default")) {
defaultBlock = ParseStatement (stream);
}
}
switchStmt.Add (caseStatements);
switchStmt.Add (defaultBlock);
stream.Expect (TokenClass.CloseBrace);
return switchStmt;
}
示例10: ParseMatch
private static AstNode ParseMatch(TokenStream stream)
{
MatchExpression expr = new MatchExpression (stream.Location);
stream.Expect (TokenClass.Keyword, "match");
expr.Add (ParseExpression (stream));
stream.Expect (TokenClass.OpenBrace);
while (stream.Accept (TokenClass.Keyword, "case")) {
AstNode condition = null;
AstNode pattern = ParsePattern (stream);
if (stream.Accept (TokenClass.Keyword, "when")) {
condition = ParseExpression (stream);
}
stream.Expect (TokenClass.Operator, "=>");
AstNode value = ParseExpression (stream);
expr.Children.Add (new CaseExpression (pattern.Location, pattern, condition, value));
}
stream.Expect (TokenClass.CloseBrace);
return expr;
}
示例11: ParsePattern
private static AstNode ParsePattern(TokenStream stream)
{
return ParsePatternOr (stream);
}
示例12: ParseForeach
private static AstNode ParseForeach(TokenStream stream)
{
stream.Expect (TokenClass.Keyword, "foreach");
stream.Expect (TokenClass.OpenParan);
Token identifier = stream.Expect (TokenClass.Identifier);
stream.Expect (TokenClass.Keyword, "in");
AstNode expr = ParseExpression (stream);
stream.Expect (TokenClass.CloseParan);
AstNode body = ParseStatement (stream);
return new ForeachStatement (stream.Location, identifier.Value, expr, body);
}
示例13: ParseLambda
private static AstNode ParseLambda(TokenStream stream)
{
stream.Expect (TokenClass.Keyword, "lambda");
bool isInstanceMethod;
bool isVariadic;
bool acceptsKwargs;
List<string> parameters = ParseFuncParameters (stream,
out isInstanceMethod,
out isVariadic,
out acceptsKwargs);
LambdaExpression decl = new LambdaExpression (stream.Location, isInstanceMethod, isVariadic, acceptsKwargs, parameters);
if (stream.Accept (TokenClass.Operator, "=>"))
decl.Add (new ReturnStatement (stream.Location, ParseExpression (stream)));
else
decl.Add (ParseStatement (stream));
return decl;
}
示例14: ParseExpression
private static AstNode ParseExpression(TokenStream stream)
{
return ParseAssign (stream);
}
示例15: ParseFor
private static AstNode ParseFor(TokenStream stream)
{
ForStatement ret = new ForStatement (stream.Location);
stream.Expect (TokenClass.Keyword, "for");
stream.Expect (TokenClass.OpenParan);
ret.Add (new Expression (stream.Location, ParseExpression (stream)));
stream.Expect (TokenClass.SemiColon);
ret.Add (ParseExpression (stream));
stream.Expect (TokenClass.SemiColon);
ret.Add (new Expression (stream.Location, ParseExpression (stream)));
stream.Expect (TokenClass.CloseParan);
ret.Add (ParseStatement (stream));
return ret;
}