📄 cs.atg
字号:
(. Expression expr; ci = new ConstructorInitializer(); .)
=
":"
(
"base" (. ci.ConstructorInitializerType = ConstructorInitializerType.Base; .)
| "this" (. ci.ConstructorInitializerType = ConstructorInitializerType.This; .)
)
"("
[ Argument<out expr> (. ci.Arguments.Add(expr); .) { "," Argument<out expr> (. ci.Arguments.Add(expr); .) } ]
")"
.
VariableInitializer<out Expression initializerExpression>
(. TypeReference type = null; Expression expr = null; initializerExpression = null; .)
=
Expr<out initializerExpression>
| ArrayInitializer<out initializerExpression>
| "stackalloc" Type<out type> "[" Expr<out expr> "]" (. initializerExpression = new StackAllocExpression(type, expr); .)
.
OverloadableOperator<out Token op>
=
(
"+" | "-" | "!" | "~"
| "++" | "--" | "true" | "false"
| "*" | "/" | "%" | "&"
| "|" | "^" | "<<" | ">>"
| "==" | "!=" | ">" | "<"
| ">=" | "<="
) (. op = t; .)
.
Argument<out Expression argumentexpr>
(.
Expression expr;
FieldDirection fd = FieldDirection.None;
.)
=
[
"ref" (. fd = FieldDirection.Ref; .)
| "out" (. fd = FieldDirection.Out; .)
]
Expr<out expr> (. argumentexpr = fd != FieldDirection.None ? argumentexpr = new DirectionExpression(fd, expr) : expr; .)
.
AssignmentOperator<out AssignmentOperatorType op>
(. op = AssignmentOperatorType.None; .)
=
"=" (. op = AssignmentOperatorType.Assign; .)
| "+=" (. op = AssignmentOperatorType.Add; .)
| "-=" (. op = AssignmentOperatorType.Subtract; .)
| "*=" (. op = AssignmentOperatorType.Multiply; .)
| "/=" (. op = AssignmentOperatorType.Divide; .)
| "%=" (. op = AssignmentOperatorType.Modulus; .)
| "&=" (. op = AssignmentOperatorType.BitwiseAnd; .)
| "|=" (. op = AssignmentOperatorType.BitwiseOr; .)
| "^=" (. op = AssignmentOperatorType.ExclusiveOr; .)
| "<<=" (. op = AssignmentOperatorType.ShiftLeft; .)
| ">>=" (. op = AssignmentOperatorType.ShiftRight; .)
.
ArrayInitializer<out Expression outExpr>
(.
Expression expr = null;
ArrayInitializerExpression initializer = new ArrayInitializerExpression();
.)
=
"{"
[ VariableInitializer<out expr> (. initializer.CreateExpressions.Add(expr); .) { IF (NotFinalComma()) "," VariableInitializer<out expr> (. initializer.CreateExpressions.Add(expr); .) } [ "," ] ]
"}" (. outExpr = initializer; .)
.
LocalVariableDecl<out Statement stmt>
(.
TypeReference type;
VariableDeclaration var = null;
LocalVariableDeclaration localVariableDeclaration;
.)
=
Type<out type> (. localVariableDeclaration = new LocalVariableDeclaration(type); localVariableDeclaration.StartLocation = t.Location; .)
LocalVariableDeclarator<out var> (. localVariableDeclaration.Variables.Add(var); .)
{ "," LocalVariableDeclarator<out var> (. localVariableDeclaration.Variables.Add(var); .) }
(. stmt = localVariableDeclaration; .)
.
LocalVariableDeclarator<out VariableDeclaration var>
(. Expression expr = null; .)
=
/* ident (. var = new VariableDeclaration(t.val); .) [ "=" LocalVariableInitializer<out expr> (. var.Initializer = expr; .) ]*/
ident (. var = new VariableDeclaration(t.val); .) [ "=" VariableInitializer<out expr> (. var.Initializer = expr; .) ]
.
/*
LocalVariableInitializer<out Expression expr>
(. expr = null; .)
=
Expr<out expr>
| ArrayInitializer<out expr>
.
*/
Statement
(.
TypeReference type;
Expression expr;
Statement stmt;
.)
=
/*--- labeled statement: */
IF (IsLabel()) ident (. compilationUnit.AddChild(new LabelStatement(t.val)); .)
":" Statement
/*--- local constant declaration: */
| "const" Type<out type> (. LocalVariableDeclaration var = new LocalVariableDeclaration(type, Modifier.Const); string ident = null; var.StartLocation = t.Location; .)
ident (. ident = t.val; .)
"=" Expr<out expr> (. var.Variables.Add(new VariableDeclaration(ident, expr)); .)
{ "," ident (. ident = t.val; .) "=" Expr<out expr> (. var.Variables.Add(new VariableDeclaration(ident, expr)); .) }
";" (. compilationUnit.AddChild(var); .)
/*--- local variable declaration: */
| IF (IsLocalVarDecl()) LocalVariableDecl<out stmt> ";" (. compilationUnit.AddChild(stmt); .)
| EmbeddedStatement<out stmt> (. compilationUnit.AddChild(stmt); .)
/* LL(1) confict: LocalVariableDecl *
* <-> StatementExpr *
* ident {"." ident} { "[" Expr ... */
.
EmbeddedStatement<out Statement statement>
(.
TypeReference type = null;
Expression expr = null;
Statement embeddedStatement = null;
statement = null;
.)
=
Block<out statement>
/*--- empty statement: */
| ";" (. statement = new EmptyStatement(); .)
/*--- checked / unchecked statement: */
| IF (UnCheckedAndLBrace()) (. Statement block; bool isChecked = true; .)
("checked" | "unchecked" (. isChecked = false;.) )
Block<out block> (. statement = isChecked ? (Statement)new CheckedStatement(block) : (Statement)new UncheckedStatement(block); .)
/*--- expression statement: */
| StatementExpr<out statement> ";"
/*--- selection statements (if, switch): */
| "if" (. Statement elseStatement = null; .)
"(" Expr<out expr> ")"
EmbeddedStatement<out embeddedStatement>
[ "else" EmbeddedStatement<out elseStatement> ]
(. statement = elseStatement != null ? (Statement)new IfElseStatement(expr, embeddedStatement, elseStatement) : (Statement)new IfStatement(expr, embeddedStatement); .)
| "switch" (. ArrayList switchSections = new ArrayList(); .)
"(" Expr<out expr> ")"
"{" { SwitchSection<out statement> (. switchSections.Add(statement); .) }
"}" (. statement = new SwitchStatement(expr, switchSections); .)
/*--- iteration statements (while, do, for, foreach): */
| "while" "(" Expr<out expr> ")"
EmbeddedStatement<out embeddedStatement> (. statement = new WhileStatement(expr, embeddedStatement); .)
| "do" EmbeddedStatement<out embeddedStatement> "while"
"(" Expr<out expr> ")" ";" (. statement = new DoWhileStatement(expr, embeddedStatement); .)
| "for" (. ArrayList initializer = null, iterator = null; .)
"(" [ ForInitializer<out initializer> ] ";"
[ Expr<out expr> ] ";"
[ ForIterator<out iterator> ] ")"
EmbeddedStatement<out embeddedStatement> (. statement = new ForStatement(initializer, expr, iterator, embeddedStatement); .)
| "foreach" "(" Type<out type> ident (. string varName = t.val; Point start = t.Location;.)
"in" Expr<out expr> ")"
EmbeddedStatement<out embeddedStatement> (. statement = new ForeachStatement(type, varName , expr, embeddedStatement);
statement.EndLocation = t.EndLocation;
.)
/*--- jump statements (break, contine, goto, return, throw): */
| "break" ";" (. statement = new BreakStatement(); .)
| "continue" ";" (. statement = new ContinueStatement(); .)
| GotoStatement<out statement>
| "return" [ Expr<out expr> ] ";" (. statement = new ReturnStatement(expr); .)
| "throw" [ Expr<out expr> ] ";" (. statement = new ThrowStatement(expr); .)
/*--- try statement: */
| TryStatement<out statement>
/*--- lock satement: */
| "lock" "(" Expr<out expr> ")"
EmbeddedStatement<out embeddedStatement> (. statement = new LockStatement(expr, embeddedStatement); .)
/*--- using statement: */
| (.Statement resourceAcquisitionStmt = null; .)
"using" "("
ResourceAcquisition<out resourceAcquisitionStmt> ")"
EmbeddedStatement<out embeddedStatement> (. statement = new UsingStatement(resourceAcquisitionStmt, embeddedStatement); .)
/*--- unsafe statement: */
| "unsafe" Block<out embeddedStatement> (. statement = new UnsafeStatement(embeddedStatement); .)
/*--- fixed statement: */
| "fixed"
"(" Type<out type> (. if (type.PointerNestingLevel == 0) Error("can only fix pointer types");
FixedStatement fxStmt = new FixedStatement(type);
string identifier = null;
.)
ident (. identifier = t.val; .)
"=" Expr<out expr> (. fxStmt.PointerDeclarators.Add(new VariableDeclaration(identifier, expr)); .)
{
"," ident (. identifier = t.val; .)
"=" Expr<out expr> (. fxStmt.PointerDeclarators.Add(new VariableDeclaration(identifier, expr)); .)
}
")" EmbeddedStatement<out embeddedStatement> (. fxStmt.EmbeddedStatement = embeddedStatement; statement = fxStmt;.)
.
ForInitializer<out ArrayList initializer>
(.
Statement stmt;
initializer = new ArrayList();
.)
=
IF (IsLocalVarDecl()) LocalVariableDecl<out stmt> (. initializer.Add(stmt);.)
| StatementExpr<out stmt> (.initializer.Add(stmt);.) { "," StatementExpr<out stmt> (. initializer.Add(stmt);.) } (. initializer.Add(stmt);.)
.
ForIterator<out ArrayList iterator>
(.
Statement stmt;
iterator = new ArrayList();
.)
=
StatementExpr<out stmt> (. iterator.Add(stmt);.) { "," StatementExpr<out stmt> (. iterator.Add(stmt); .) }
.
SwitchSection<out Statement stmt>
(.
SwitchSection switchSection = new SwitchSection();
Expression expr;
.)
=
SwitchLabel<out expr> (. switchSection.SwitchLabels.Add(expr); .) { SwitchLabel<out expr> (. switchSection.SwitchLabels.Add(expr); .) }
(. compilationUnit.BlockStart(switchSection); .)
Statement { Statement }
(.
compilationUnit.BlockEnd();
stmt = switchSection;
.)
.
SwitchLabel<out Expression expr>
(. expr = null; .)
=
"case" Expr<out expr> ":"
| "default" ":"
.
TryStatement<out Statement tryStatement>
(.
Statement blockStmt = null, finallyStmt = null;
ArrayList catchClauses = null;
.)
=
"try" Block<out blockStmt>
(
CatchClauses<out catchClauses> [ "finally" Block<out finallyStmt> ]
| "finally" Block<out finallyStmt>
)
(.
tryStatement = new TryCatchStatement(blockStmt, catchClauses, finallyStmt);
.)
.
CatchClauses<out ArrayList catchClauses>
(.
catchClauses = new ArrayList();
.)
=
"catch" (. string name;
string identifier;
Statement stmt;
.)
/*--- general catch clause (as only catch clause) */
(
Block<out stmt> (. catchClauses.Add(new CatchClause(stmt)); .)
/*--- specific catch clause */
| "(" ClassType<out name> (. identifier = null; .) [ ident (. identifier = t.val; .) ] ")" Block<out stmt> (. catchClauses.Add(new CatchClause(name, identifier, stmt)); .)
{ IF (IsTypedCatch()) "catch" "(" ClassType<out name> (. identifier = null; .) [ ident (. identifier = t.val; .) ] ")" Block<out stmt> (. catchClauses.Add(new CatchClause(name, identifier, stmt)); .) }
/*--- general catch clause (after specific catch clauses, optional) */
[ "catch" Block<out stmt> (. catchClauses.Add(new CatchClause(stmt)); .) ]
)
.
GotoStatement<out Statement stmt>
(. Expression expr; stmt = null; .)
=
"goto"
(
ident (. stmt = new GotoStatement(t.val); .) ";"
| "case" Expr<out expr> ";" (. stmt = new GotoCaseStatement(expr); .)
| "default" ";" (. stmt = new GotoCaseStatement(null); .)
)
.
ResourceAcquisition<out Statement stmt>
(.
stmt = null;
Expression expr;
.)
=
(
IF (IsLocalVarDecl()) LocalVariableDecl<out stmt>
| Expr<out expr> /* LL(1) conflict resoltion: *
* check if next is Qualident followed by ident *
* ==> LocalVariableDecl *
* new problem: first set of ResourceAcquisition changes */
(. stmt = new StatementExpression(expr); .)
)
.
StatementExpr<out Statement stmt>
=
/* We don't know why, but it's in the grammar. */
/* (see internal document: assignment.txt) */
(.
bool mustBeAssignment = la.kind == Tokens.Plus || la.kind == Tokens.Minus ||
la.kind == Tokens.Not || la.kind == Tokens.BitwiseComplement ||
la.kind == Tokens.Times || la.kind == Tokens.BitwiseAnd || IsTypeCast();
Expression expr = null;
.)
UnaryExpr<out expr>
/*--- assignment */
(
(. AssignmentOperatorType op; Expression val; .) AssignmentOperator<out op> Expr<out val> (. expr = new AssignmentExpression(expr, op, val); .)
| (. if (mustBeAssignment) Error("error in assignment."); .)
) (. stmt = new StatementExpression(expr); .)
.
Expr<out Expression expr>
(. expr = null; Expression expr1 = null, expr2 = null; .)
=
UnaryExpr<out expr>
/*--- conditional expression: */
(
ConditionalOrExpr<ref expr> [ "?" Expr<out expr1> ":" Expr<out expr2> (. expr = new ConditionalExpression(expr, expr1, expr2); .) ]
/*--- assignment: */
| (. AssignmentOperatorType op; Expression val; .) AssignmentOperator<out op> Expr<out val> (. expr = new AssignmentExpression(expr, op, val); .)
)
.
UnaryExpr<out Expression uExpr>
(.
TypeReference type = null;
Expression expr;
ArrayList expressions = new ArrayList();
uExpr = null;
.)
=
{
"+" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Plus)); .)
| "-" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Minus)); .)
| "!" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Not)); .)
| "~" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.BitNot)); .)
| "*" (. expressions.Add(new UnaryOperatorExpression(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -