Beispiel #1
0
		public override bool VisitAssignmentExpression(AssignmentExpression assignExp)
		{
			if (assignExp.Target.NodeType == NodeType.VariableRefExpression)
			{
				// Convert to declaration if not found on the scope

				VariableReferenceExpression varRef = (VariableReferenceExpression) assignExp.Target; 

				ISymbolTable scope = varRef.SymbolTable;

				System.Diagnostics.Debug.Assert( scope != null );

				String name = varRef.Identifier.Name;

				if (!scope.IsDefined(name)) // TODO: The rules are slighly more complicated than that.
				{
					errorReport.Disable();

					SingleVariableDeclarationStatement varDecl = new SingleVariableDeclarationStatement(varRef.Identifier);

					IStatement stmt = ASTUtils.GetParentStatement(varRef);

					System.Diagnostics.Debug.Assert( stmt != null );

					IStatementContainer stmts = stmt.Parent as IStatementContainer;

					int index = stmts.Statements.IndexOf(stmt);

					varDecl.InitExp = assignExp.Value;

					// stmts.Statements.Insert(index, varDecl);
					stmts.Statements.Replace(stmt, varDecl);

					if (!ApplyDeclarationRules(varRef.Identifier, scope, varDecl, stmt))
					{
						stmts.Statements.Remove(varDecl);
					}

					errorReport.Enable();
				}
			}

			return base.VisitAssignmentExpression(assignExp);
		}
Beispiel #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;
	}