📄 cs.atg
字号:
Expression expr = null;
ArrayInitializerExpression initializer = new ArrayInitializerExpression();
.)
=
"{"
[ VariableInitializer<out expr>
(. if (expr != null) { initializer.CreateExpressions.Add(expr); } .)
{ IF (NotFinalComma())
"," VariableInitializer<out expr>
(. if (expr != null) { 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 = null;
Location startPos = la.Location;
.)
=
(
/*--- labeled statement: */
IF (IsLabel()) ident (. compilationUnit.AddChild(new LabelStatement(t.val)); .)
":" Statement
/*--- local constant declaration: */
| "const" Type<out type> (. LocalVariableDeclaration var = new LocalVariableDeclaration(type, Modifiers.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 ... */
)
(.
if (stmt != null) {
stmt.StartLocation = startPos;
stmt.EndLocation = t.EndLocation;
}
.)
.
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); .)
/*--- selection statements (if, switch): */
| "if" (. Statement elseStatement = null; .)
"(" Expr<out expr> ")"
EmbeddedStatement<out embeddedStatement>
[ "else" EmbeddedStatement<out elseStatement> ]
(. statement = elseStatement != null ? new IfElseStatement(expr, embeddedStatement, elseStatement) : new IfElseStatement(expr, embeddedStatement); .)
(. if (elseStatement is IfElseStatement && (elseStatement as IfElseStatement).TrueStatement.Count == 1) {
/* else if-section (otherwise we would have a BlockStatment) */
(statement as IfElseStatement).ElseIfSections.Add(
new ElseIfSection((elseStatement as IfElseStatement).Condition,
(elseStatement as IfElseStatement).TrueStatement[0]));
(statement as IfElseStatement).ElseIfSections.AddRange((elseStatement as IfElseStatement).ElseIfSections);
(statement as IfElseStatement).FalseStatement = (elseStatement as IfElseStatement).FalseStatement;
} .)
| "switch" (. List<SwitchSection> switchSections = new List<SwitchSection>(); .)
"(" Expr<out expr> ")"
"{" SwitchSections<switchSections>
"}" (. statement = new SwitchStatement(expr, switchSections); .)
/*--- iteration statements (while, do, for, foreach): */
| "while" "(" Expr<out expr> ")"
EmbeddedStatement<out embeddedStatement> (. statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.Start);.)
| "do" EmbeddedStatement<out embeddedStatement> "while"
"(" Expr<out expr> ")" ";" (. statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.End); .)
| "for" (. List<Statement> initializer = null; List<Statement> 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; Location 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>
| IF (IsYieldStatement()) ident ( "return" Expr<out expr> (. statement = new YieldStatement(new ReturnStatement(expr)); .)
| "break" (. statement = new YieldStatement(new BreakStatement()); .) ) ";"
| "return" [ Expr<out expr> ] ";" (. statement = new ReturnStatement(expr); .)
| "throw" [ Expr<out expr> ] ";" (. statement = new ThrowStatement(expr); .)
/*--- expression statement: */
| StatementExpr<out statement> ";"
/*--- 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");
List<VariableDeclaration> pointerDeclarators = new List<VariableDeclaration>(1);
.)
ident (. string identifier = t.val; .)
"=" Expr<out expr> (. pointerDeclarators.Add(new VariableDeclaration(identifier, expr)); .)
{
"," ident (. identifier = t.val; .)
"=" Expr<out expr> (. pointerDeclarators.Add(new VariableDeclaration(identifier, expr)); .)
}
")" EmbeddedStatement<out embeddedStatement> (. statement = new FixedStatement(type, pointerDeclarators, embeddedStatement); .)
.
ForInitializer<out List<Statement> initializer>
(.
Statement stmt;
initializer = new List<Statement>();
.)
=
IF (IsLocalVarDecl()) LocalVariableDecl<out stmt> (. initializer.Add(stmt);.)
| StatementExpr<out stmt> (.initializer.Add(stmt);.) { "," StatementExpr<out stmt> (. initializer.Add(stmt);.) }
.
ForIterator<out List<Statement> iterator>
(.
Statement stmt;
iterator = new List<Statement>();
.)
=
StatementExpr<out stmt> (. iterator.Add(stmt);.) { "," StatementExpr<out stmt> (. iterator.Add(stmt); .) }
.
SwitchSections<List<SwitchSection> switchSections>
(.
SwitchSection switchSection = new SwitchSection();
CaseLabel label;
.)
=
SwitchLabel<out label> (. if (label != null) { switchSection.SwitchLabels.Add(label); } .)
(. compilationUnit.BlockStart(switchSection); .)
{
( SwitchLabel<out label>
(. if (label != null) {
if (switchSection.Children.Count > 0) {
// open new section
compilationUnit.BlockEnd(); switchSections.Add(switchSection);
switchSection = new SwitchSection();
compilationUnit.BlockStart(switchSection);
}
switchSection.SwitchLabels.Add(label);
}
.)
| Statement)
}
(. compilationUnit.BlockEnd(); switchSections.Add(switchSection); .)
.
SwitchLabel<out CaseLabel label>
(. Expression expr = null; label = null; .)
=
"case" Expr<out expr> ":" (. label = new CaseLabel(expr); .)
| "default" ":" (. label = new CaseLabel(); .)
.
TryStatement<out Statement tryStatement>
(.
Statement blockStmt = null, finallyStmt = null;
List<CatchClause> 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 List<CatchClause> catchClauses>
(.
catchClauses = new List<CatchClause>();
.)
=
"catch" (. string identifier;
Statement stmt;
TypeReference typeRef;
.)
/*--- general catch clause (as only catch clause) */
(
Block<out stmt> (. catchClauses.Add(new CatchClause(stmt)); .)
/*--- specific catch clause */
| "(" ClassType<out typeRef, false> (. identifier = null; .)
[ ident (. identifier = t.val; .) ]
")" Block<out stmt>
(. catchClauses.Add(new CatchClause(typeRef, identifier, stmt)); .)
{ IF (IsTypedCatch()) "catch" "(" ClassType<out typeRef, false> (. identifier = null; .)
[ ident (. identifier = t.val; .) ]
")" Block<out stmt>
(. catchClauses.Add(new CatchClause(typeRef, 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 ExpressionStatement(expr); .)
)
.
StatementExpr<out Statement stmt>
(. Expression expr; .)
=
Expr<out expr>
/* The grammar allows only assignments or method invocations here, */
/* but we don't enforce that here */
(. stmt = new ExpressionStatement(expr); .)
.
Expr<out Expression expr>
(. expr = null; Expression expr1 = null, expr2 = null; AssignmentOperatorType op; .)
=
UnaryExpr<out expr>
/*--- conditional expression: */
(
( AssignmentOperator<out op> Expr<out expr1> (. expr = new AssignmentExpression(expr, op, expr1); .) )
| IF (la.kind == Tokens.GreaterThan && Peek(1).kind == Tokens.GreaterEqual)
( AssignmentOperator<out op> Expr<out expr1> (. expr = new AssignmentExpression(expr, op, expr1); .) )
| (
ConditionalOrExpr<ref expr>
[ "??" Expr<out expr1> (. expr = new BinaryOperatorExpression(expr, BinaryOperatorType.NullCoalescing, expr1); .) ]
[ "?" Expr<out expr1> ":" Expr<out expr2> (. expr = new ConditionalExpression(expr, expr1, expr2); .) ]
)
)
.
UnaryExpr<out Expression uExpr>
(.
TypeReference type = null;
Expression expr = null;
ArrayList expressions = new ArrayList();
uExpr = null;
.)
=
{
/* IF (Tokens.UnaryOp[la.kind] || IsTypeCast()) */
(
"+" (. 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(UnaryOperatorType.Star)); .)
| "++" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Increment)); .)
| "--" (. expressions.Add(ne
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -