⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vbnet.atg

📁 c#源代码
💻 ATG
📖 第 1 页 / 共 5 页
字号:
			if (arrayModifiers != null) {
				if (type.RankSpecifier != null) {
					Error("array rank only allowed one time");
				} else {
					type.RankSpecifier = arrayModifiers;
				}
			}
		} else {
			type = new TypeReference("System.Object", arrayModifiers);
		}
	.)
	[ "=" Expr<out expr> ]
	(.
		mod.Check();
		p = new ParameterDeclarationExpression(type, parameterName, mod, expr);
	.)
	.

/* 10.1 */
Block<out Statement stmt>
	=
	(.
		BlockStatement blockStmt = new BlockStatement();
		blockStmt.StartLocation = t.Location;
		compilationUnit.BlockStart(blockStmt);
	.)
	{ Statement EndOfStmt |
	  IF (IsEndStmtAhead()) "End" EndOfStmt (. compilationUnit.AddChild(new EndStatement()); .) 
	}
	(.
		stmt = blockStmt;
		blockStmt.EndLocation = t.EndLocation;
		compilationUnit.BlockEnd();
	.)
	.

Statement
	(.
		Statement stmt;
		string label = String.Empty;
		
	.) =
	IF (IsLabel()) LabelName<out label>
	(.
		labelStatement = new LabelStatement(t.val);
		compilationUnit.AddChild(labelStatement);
	.)
	":" [ (. isLabel = true; .) Statement ]
	| EmbeddedStatement<out stmt>			(. updateLabelStatement(stmt); .)
	| LocalDeclarationStatement<out stmt>	(. updateLabelStatement(stmt); .)
	.

/* 10.2 */
LocalDeclarationStatement<out Statement statement>
	(.
		Modifiers m = new Modifiers(this);
		ArrayList vars = new ArrayList();
		LocalVariableDeclaration localVariableDeclaration;
		bool dimfound = false;
	.) =
	/* this differs from the spec: dim static x	compiles with vbc. */
	{
		"Const" 	(. m.Add(Modifier.Constant); .)
		| "Static"	(. m.Add(Modifier.Static); .)
		| "Dim"		(. dimfound = true; .)
	}
	(.
		if(dimfound && (m.Modifier & Modifier.Constant) != 0) {
			Error("Dim is not allowed on constants.");
		}
		
		if(m.isNone && dimfound == false) {
			Error("Const, Dim or Static expected");
		}
		
		localVariableDeclaration = new LocalVariableDeclaration(m.Modifier);
		localVariableDeclaration.StartLocation = t.Location;
	.)
	VariableDeclarator<vars>
	{ "," VariableDeclarator<vars> }
	(.
		localVariableDeclaration.Variables = vars;
		statement = localVariableDeclaration;
	.)
	.

EmbeddedStatement<out Statement statement>
	(.
		Statement embeddedStatement = null;
		statement = null;
		Expression expr = null;
		string name = String.Empty;
		ArrayList p = null;
	.) =
		"Exit"				(. ExitType exitType = ExitType.None; .)
		(
		"Sub"				(. exitType = ExitType.Sub; .)
		|
		"Function"			(. exitType = ExitType.Function; .)
		|
		"Property"			(. exitType = ExitType.Property; .)
		|
		"Do"				(. exitType = ExitType.Do; .)
		|
		"For"				(. exitType = ExitType.For; .)
		|
		"Try"				(. exitType = ExitType.Try; .)
		|
		"While"				(. exitType = ExitType.While; .)
		|
		"Select"			(. exitType = ExitType.Select; .)
		)
	(. statement = new ExitStatement(exitType); .)
	| TryStatement<out statement>
	| /* 10.10.1.3 */
	"Throw" [ Expr<out expr> ]				(. statement = new ThrowStatement(expr); .)
	| /* 10.11 */
	"Return" [ Expr<out expr> ] 			(. statement = new ReturnStatement(expr); .)
	| /* 10.4 */
	"SyncLock" Expr<out expr> EndOfStmt Block<out embeddedStatement>
	"End" "SyncLock" 						(. statement = new LockStatement(expr, embeddedStatement); .)
	| /* 10.5.1 */
	"RaiseEvent" Identifier (. name = t.val; .)
	[ "(" [ ArgumentList<out p> ] ")" ]
	(. statement = new RaiseEventStatement(name, p); .)
	| /* 10.3 */
	WithStatement<out statement>
	| /* 10.5.2 */
	"AddHandler" (. Expression handlerExpr = null; .)
	Expr<out expr> "," Expr<out handlerExpr>
	(.
		statement = new AddHandlerStatement(expr, handlerExpr);
	.)
	| /* 10.5.2 */
	"RemoveHandler" (. Expression handlerExpr = null; .)
	Expr<out expr> "," Expr<out handlerExpr>
	(.
		statement = new RemoveHandlerStatement(expr, handlerExpr);
	.)
	| /* 10.9.1 */
	"While" Expr<out expr> EndOfStmt
	Block<out embeddedStatement> "End" "While"
	(.
		statement = new WhileStatement(expr, embeddedStatement);
	.)
	| /* 10.9.1 */
	"Do"
	(.
		ConditionType conditionType = ConditionType.None;
	.)
	(
		WhileOrUntil<out conditionType> Expr<out expr> EndOfStmt
		Block<out embeddedStatement>
		"Loop"
		(.
			statement = new DoLoopStatement(expr, embeddedStatement, conditionType, ConditionPosition.Start);
		.)
		|
		EndOfStmt
		Block<out embeddedStatement>
		"Loop" [WhileOrUntil<out conditionType> Expr<out expr>]
		(.
			statement = new DoLoopStatement(expr, embeddedStatement, conditionType, ConditionPosition.End);
		.)
	)
	| "For"
	(.
			Expression group = null;
			LoopControlVariableExpression loopControlExpr = null;
	.)
	(
		/* 10.9.3  */
 		"Each" LoopControlVariable<out loopControlExpr>
		"In" Expr<out group> EndOfStmt
		Block<out embeddedStatement>
		"Next" [ Expr<out expr> ]
		(.
			statement = new ForeachStatement(loopControlExpr, group, embeddedStatement, expr);
		.)
		| /* 10.9.2 */
		(.
			Expression start = null;
			Expression end = null;
			Expression step = null;
			Expression nextExpr = null;
			ArrayList nextExpressions = null;
		.)
		LoopControlVariable<out loopControlExpr>
		"=" Expr<out start> "To" Expr<out end> [ "Step" Expr<out step> ]
		EndOfStmt Block<out embeddedStatement>
		"Next"
		[
			Expr<out nextExpr> (. nextExpressions = new ArrayList(); nextExpressions.Add(nextExpr); .) 
			{ "," Expr<out nextExpr> (. nextExpressions.Add(nextExpr); .) }
		]
		(.
			statement = new ForStatement(loopControlExpr, start, end, step, embeddedStatement, nextExpressions);
		.)
	)
	| /* 10.10.2.1 */
	"Error" Expr<out expr> 				(. statement = new ErrorStatement(expr); .)
	| /* 10.12.1 */
	"ReDim" (. Expression clause = null; .) [ "Preserve" ]
	Expr<out clause>
	(.
		ArrayList clauses = new ArrayList();
		clauses.Add(clause);
		statement = new ReDimStatement(clauses);
	.)
	{ "," Expr<out clause> (. clauses.Add(clause); .) }
	| /* 10.12.2 */
	"Erase"	
	Expr<out expr>
	(.
		ArrayList arrays = new ArrayList();
		arrays.Add(expr);
		EraseStatement eraseStatement = new EraseStatement(arrays);
		
	.)
	{ "," Expr<out expr> (. arrays.Add(expr); .) }
	(. statement = eraseStatement; .)
	| /* 10.11 */
	"Stop" (. statement = new StopStatement(); .)
	| /* 10.8.1 */
	"If" Expr<out expr> [ "Then" ] 
	(	
		IF (IsEndStmtAhead()) "End" (. statement = new IfStatement(expr, new EndStatement()); .) 
		|
		/* multiline if statement */
		EndOfStmt Block<out embeddedStatement>
		(.
			ArrayList elseIfSections = new ArrayList();
			IfStatement ifStatement = new IfStatement(expr, embeddedStatement);
		.)
		{
			(
				IF(IsElseIf()) "Else" "If"
				| "ElseIf"
			)
			(. Expression condition = null; Statement block = null; .)
			Expr<out condition> [ "Then"] EndOfStmt
			Block<out block>
			(.
				ElseIfSection elseIfSection = new ElseIfSection(condition, block);
				elseIfSections.Add(elseIfSection);
			.)
		}
		[
			"Else" EndOfStmt
			Block<out embeddedStatement>
			(.
				ifStatement.EmbeddedElseStatement = embeddedStatement;
			.)
		] "End" "If"
		(.
			ifStatement.ElseIfStatements = elseIfSections;
			statement = ifStatement;
		.)
		| /* singleline if statement */
		EmbeddedStatement<out embeddedStatement>
		(.
			SimpleIfStatement ifStatement = new SimpleIfStatement(expr);
			ArrayList statements = new ArrayList();
			statements.Add(embeddedStatement);
			ifStatement.Statements = statements;
		.)
		{ ":" EmbeddedStatement<out embeddedStatement> (. statements.Add(embeddedStatement); .) }
		[
			"Else" [ EmbeddedStatement<out embeddedStatement> ]
			(.
				ArrayList elseStatements = new ArrayList();
				elseStatements.Add(embeddedStatement);
				ifStatement.ElseStatements = elseStatements;
			.)
			{
				":" EmbeddedStatement<out embeddedStatement>
				(. elseStatements.Add(embeddedStatement); .)
			}
		]
		(. statement = ifStatement; .)
	)
	| /* 10.8.2 */
	"Select" [ "Case" ] Expr<out expr> EndOfStmt
	(.
		ArrayList selectSections = new ArrayList();
		Statement block = null;
	.)
	{
		(. ArrayList caseClauses = null; .)
		"Case" CaseClauses<out caseClauses> [ IF(IsNotStatementSeparator()) ":" ] EndOfStmt
		(.
			SelectSection selectSection = new SelectSection();
			selectSection.CaseClauses = caseClauses;
			compilationUnit.BlockStart(selectSection);
		.)
		Block<out block>
		(.
			selectSection.EmbeddedStatement = block;
			compilationUnit.BlockEnd();
			selectSections.Add(selectSection);
		.)
	}
	(. statement = new SelectStatement(expr, selectSections); .)
	"End" "Select"
	| (. OnErrorStatement onErrorStatement = null; .)
	OnErrorStatement<out onErrorStatement> (. statement = onErrorStatement; .)
	| (. GoToStatement goToStatement = null; .)
	GoToStatement<out goToStatement> (. statement = goToStatement; .)
	| (. ResumeStatement resumeStatement = null; .)
	ResumeStatement<out resumeStatement> (. statement = resumeStatement; .)
	|/* Statement expression (invocation and assignment) 10.6.1, 10.6.2, 10.6.3 */
	(.
		Expression val = null;
		AssignmentOperatorType op;
		
		bool mustBeAssignment = la.kind == Tokens.Plus  || la.kind == Tokens.Minus ||
		                        la.kind == Tokens.Not   || la.kind == Tokens.Times;
	.)
	UnaryExpr<out expr>
		(
		AssignmentOperator<out op> Expr<out val>	(. expr = new AssignmentExpression(expr, op, val); .)
		| (. if (mustBeAssignment) Error("error in assignment."); .)
		)
		(.
			// a field reference expression that stands alone is a
			// invocation expression without parantheses and arguments
			if(expr is FieldReferenceOrInvocationExpression) {
				expr = new InvocationExpression(expr, new ArrayList());
			}
			statement = new StatementExpression(expr);
		.)
	| "Call" UnaryExpr<out expr> (. statement = new StatementExpression(expr); .)
	.

/* 10.9.2 */
LoopControlVariable<out LoopControlVariableExpression loopExpr>
	(.
		loopExpr = null;
		//Expression expr = null;
		TypeReference type = null;
		ArrayList arrayModifiers = null;
		string name;
	.) =
	Qualident<out name>
	[ IF(IsRank()) ArrayTypeModifiers<out arrayModifiers> ]
	[ "As" TypeName<out type> (. if (name.IndexOf('.') > 0) { Error("No type def for 'for each' member indexer allowed."); } .) ]
	(.
		if(type != null) {
			if(type.RankSpecifier != null && arrayModifiers != null) {
				Error("array rank only allowed one time");
			} else {
				type.RankSpecifier = arrayModifiers;
			}
		} else {
			type = new TypeReference("Integer", arrayModifiers);
		}
		loopExpr = new LoopControlVariableExpression(name, type);
	.)
	.

/* 10.2.2 */
OnErrorStatement<out OnErrorStatement stmt>
	(.
		stmt = null;
		GoToStatement goToStatement = null;
	.)
	=
	"On" "Error"
	(
		IF(IsNegativeLabelName())"GoTo" "-" LiteralInteger
		(.
			long intLabel = Int64.Parse(t.val);
			if(intLabel != 1) {
				Error("invalid label in on error statement.");
			}
			stmt = new OnErrorStatement(new GoToStatement((intLabel * -1).ToString()));
		.)
		| GoToStatement<out goToStatement>
		(.
			string val = goToStatement.LabelName;
			
			// if value is numeric, make sure that is 0
			try {
				long intLabel = Int64.Parse(val);
				if(intLabel != 0) {
					Error("invalid label in on error statement.");
				}
			} catch {
			}
			stmt = new OnErrorStatement(goToStatement);
		.)
		| "Resume" "Next"
		(.
			stmt = new OnErrorStatement(new ResumeStatement(true));
		.)
	)
	.

/* 10.11 */
GoToStatement<out GoToStatement goToStatement>
	(.
		string label = String.Empty;
	.)
	=
	"GoTo" LabelName<out label>
	(.
		goToStatement = new GoToStatement(label);
	.)
	.

/* 10.1 */
LabelName<out string name>
	(.
		name = String.Empty;
	.) =
	Identifier 				(. name = t.val; .)
	| LiteralInteger	(. name = t.val; .)
	.

/* 10.10.2.3 */
ResumeStatement<out ResumeStatement resumeStatement>
	(.
		resumeStatement = null;
		string label = String.Empty;
	.) =
	IF(IsResumeNext())
	"Resume" "Next" 					(. resumeStatement = new ResumeStatement(true); .)
	| "Resume" [ LabelName<out label> ]	(. resumeStatement = new ResumeStatement(label); .)
	.

/* 18.8.2 */
CaseClauses<out ArrayList caseClauses>
	(.
		caseClauses = null;
		CaseClause caseClause = null;
	.) =
	CaseClause<out caseClause>
	(.
		caseClauses = new ArrayList();
		caseClauses.Add(caseClause);
	.)
	{ "," CaseClause<out caseClause> (. caseClauses.Add(caseClause); .) }
	.

/* 19.8.2 */
CaseClause<out CaseClause caseClause>
	(.
		Expression expr = null;
		Expression sexpr = null;
		BinaryOperatorType op = BinaryOperatorType.None;
		caseClause = null;
	.) =
	"Else"
	(. caseClause = new CaseClause(true); .)
	|
	[ "Is" ] 
	(
		"<"		(. op = BinaryOperatorType.LessThan; .)
		| ">"	(. op = BinaryOperatorType.GreaterThan; .)
		| "<="	(. op = BinaryOperatorType.LessThanOrEqual; .)
		| ">="	(. op = BinaryOperatorType.GreaterThanOrEqual; .)
		| "="	(. op = BinaryOperatorType.Equality; .)
		| "<>"	(. op = BinaryOperatorType.InEquality; .)
	)
	Expr<out expr>
	(.
		caseClause = new CaseClause(op, expr);
	.)
	| Expr<out expr> [ "To" Expr<out sexpr> ]
	(.
		caseClause = new CaseClause(expr, sexpr);
	.)
	.

/* 10.9.1 */
WhileOrUntil<out ConditionType conditionType>
	(. conditionType = ConditionType.None; .) =
	"While"		(. conditionType = ConditionType.While; .)
	| "Until"	(. conditionType = ConditionType.Until; .)
	.

/* 10.3 */
WithStatement<out Statement withStatement>
	(.
		Statement blockStmt = null;
		Expression expr = null;
	.) =
	"With" (. Point start = t.Location; .)
	Expr<out expr> EndOfStmt
	(.
		withStatement = new WithStatement(expr);
		withStatement.StartLocation = start;
		withStatements.Push(withStatement);
	.)
	Block<out blockStmt>
	(.
		((WithStatement)withStatement).Body = (BlockStatement)blockStmt;
		withStatements.Pop();
	.)
	"End" "With"
	(. withStatement.EndLocat

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -