예제 #1
0
		//
		// Statements
		//

		public virtual void VisitExpressionStatement(ExpressionStatement statement)
		{
			VisitNode(statement.InnerExpression);
		}
예제 #2
0
	public IStatement  expression_statement() //throws RecognitionException, TokenStreamException
{
		IStatement stmt;
		
		stmt = null; PostfixCondition pfc = null; IExpression exp = null; IExpression rhs = null;
			  AugType rel = AugType.Undefined;
		
		if ((tokenSet_9_.member(LA(1))))
		{
			{
				switch ( LA(1) )
				{
				case DO:
				case BEGIN:
				{
					exp=compound();
					break;
				}
				case NUM_INT:
				case NUM_FLOAT:
				case NUM_LONG:
				case IDENT:
				case STATICIDENT:
				case INSTIDENT:
				case LITERAL_self:
				case LPAREN:
				case LITERAL_lambda:
				case LCURLY:
				case LITERAL_raise:
				case LITERAL_yield:
				case LITERAL_not:
				case LNOT:
				case PLUS:
				case MINUS:
				case BNOT:
				case LBRACK:
				case LITERAL_base:
				case STRING_LITERAL:
				case CHAR_LITERAL:
				{
					exp=test();
					{
						switch ( LA(1) )
						{
						case PLUS_ASSIGN:
						case MINUS_ASSIGN:
						case STAR_ASSIGN:
						case DIV_ASSIGN:
						case MOD_ASSIGN:
						case BAND_ASSIGN:
						case BOR_ASSIGN:
						case BXOR_ASSIGN:
						{
							rel=augassign();
							rhs=test();
							if (0==inputState.guessing)
							{
								exp = new AugAssignmentExpression(exp, rhs, rel);
							}
							break;
						}
						case ASSIGN:
						{
							{ // ( ... )+
								int _cnt75=0;
								for (;;)
								{
									if ((LA(1)==ASSIGN))
									{
										match(ASSIGN);
										rhs=test();
										if (0==inputState.guessing)
										{
											exp = new AssignmentExpression(exp, rhs);
										}
									}
									else
									{
										if (_cnt75 >= 1) { goto _loop75_breakloop; } else { throw new NoViableAltException(LT(1), getFilename());; }
									}
									
									_cnt75++;
								}
_loop75_breakloop:								;
							}    // ( ... )+
							break;
						}
						case EOF:
						case WHILE:
						case STATEMENT_END:
						case SEMI:
						case LITERAL_if:
						case LITERAL_unless:
						case LITERAL_until:
						{
							break;
						}
						default:
						{
							throw new NoViableAltException(LT(1), getFilename());
						}
						 }
					}
					break;
				}
				case LITERAL_redo:
				case LITERAL_break:
				case LITERAL_next:
				case LITERAL_retry:
				{
					exp=flow_expressions();
					break;
				}
				default:
				{
					throw new NoViableAltException(LT(1), getFilename());
				}
				 }
			}
			{
				switch ( LA(1) )
				{
				case WHILE:
				case LITERAL_if:
				case LITERAL_unless:
				case LITERAL_until:
				{
					pfc=postFixCondition();
					if (0==inputState.guessing)
					{
						exp.PostfixCondition = pfc;
					}
					break;
				}
				case EOF:
				case STATEMENT_END:
				case SEMI:
				{
					break;
				}
				default:
				{
					throw new NoViableAltException(LT(1), getFilename());
				}
				 }
			}
			if (0==inputState.guessing)
			{
				stmt = new ExpressionStatement(exp);
			}
		}
		else if ((LA(1)==DEF) && (tokenSet_10_.member(LA(2)))) {
			stmt=method_def_statement();
		}
		else if ((LA(1)==DEF) && (LA(2)==LITERAL_initialize)) {
			stmt=constructor_def_statement();
		}
		else
		{
			throw new NoViableAltException(LT(1), getFilename());
		}
		
		return stmt;
	}
예제 #3
0
		private bool ApplyDeclarationRules(Identifier ident, ISymbolTable namescope, SingleVariableDeclarationStatement typeDecl, IStatement statem)
		{
			// Second simple case: a local var and we are on the right place to 
			// declare it
			if (ident.Type == IdentifierType.Local && 
				(namescope.ScopeType == ScopeType.Method || 
					namescope.ScopeType == ScopeType.Compound || 
					namescope.ScopeType == ScopeType.Block))
			{
				namescope.AddVariable(ident);
				return true;
			}
	
			// More complex: a block or compound tries to redefine a variable
			if (ident.Type == IdentifierType.Local && 
				(namescope.ScopeType == ScopeType.Compound || 
					namescope.ScopeType == ScopeType.Block))
			{
				if (namescope.Parent.IsDefined(ident.Name))
				{
					errorReport.Error( "TODOFILENAME", typeDecl.Position, "Sorry but '{0}' is already defined in a parent scope.", ident.Name );
					return false;
				}
			}
	
			// Local variables at class level?
			// We will support that as a type initializer, but not now.
			if (ident.Type == IdentifierType.Local && namescope.ScopeType == ScopeType.Type)
			{
				errorReport.Error( "TODOFILENAME", typeDecl.Position, "At type level, just instance or static fields are allowed (yet)" );
				return false;
			}
	
			// Static or instance in a method/block/compound are moved
			// to the parent class or source unit level
			if (ident.Type == IdentifierType.InstanceField || 
				ident.Type == IdentifierType.StaticField)
			{
				if (namescope.ScopeType == ScopeType.SourceUnit || 
					namescope.ScopeType == ScopeType.Type)
				{
					namescope.AddVariable(ident);
				}
				else if (namescope.ScopeType == ScopeType.Method || 
					namescope.ScopeType == ScopeType.Compound || 
					namescope.ScopeType == ScopeType.Block)
				{
					IASTNode node = statem.Parent;

					while(node != null && 
						node.NodeType != NodeType.TypeDefinition && 
						node.NodeType != NodeType.SourceUnit)
					{
						node = node.Parent;
					}

					if (node == null || node.SymbolTable == null)
					{
						errorReport.Error( "TODOFILENAME", typeDecl.Position, 
						                   "Compiler error: The instance of static declaration '{0}' could not be mapped to a parent type", ident.Name );							
						return false;
					}

					ISymbolTable parentScope = node.SymbolTable;

					IStatementContainer typeStmtsContainer = node as IStatementContainer;
							
					System.Diagnostics.Debug.Assert( parentScope != null );
					System.Diagnostics.Debug.Assert( typeStmtsContainer != null );

					if (parentScope.IsDefined(ident.Name))
					{
						errorReport.Error( "TODOFILENAME", typeDecl.Position, 
						                   "Sorry but '{0}' is already defined.", ident.Name );
						return false;
					}
					else
					{
						parentScope.AddVariable(ident);

						// We can replace the declaration on the method 
						// body with an assignment if and only if this type decl has
						// an init expression, so CreateAssignmentFromTypeDecl can return null
						AssignmentExpression assignExp = CreateAssignmentFromTypeDecl(typeDecl);
						ExpressionStatement assignExpStmt = new ExpressionStatement(assignExp);

						typeDecl.ConvertInitExpressionToDependency();
							
						// Replace the declaration with an assignment
						(statem.Parent as IStatementContainer).Statements.Replace(typeDecl, assignExpStmt);

						// Add the member/field declaration to the parent
						typeStmtsContainer.Statements.Add( typeDecl );

						// TODO: Link assignment expression and typeDecl to help
						// find out the type of the field later

						return true;
					}
				}
			}

			return false;
		}
예제 #4
0
파일: TreeWalker.cs 프로젝트: atczyc/castle
		public override void VisitExpressionStatement(ExpressionStatement statement)
		{
			nodeStack.Push( CurrentNode.Nodes.Add("ExpressionStatement "));
			CurrentNode.Tag = statement;

			base.VisitExpressionStatement(statement);

			nodeStack.Pop();
		}