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

📄 methoddefinitionnode.java

📁 是有关解释器的.用JAVA编写.可以解释一般的JAVA程序.
💻 JAVA
字号:
class MethodDefinitionNode extends ExecutableNode
{
	MethodDeclaratorNode vMethodDeclaratorNode;
	BlockNode vBlockNode;
	
	static MethodDefinitionNode parserMethodDefinition(Environment env,Scanner s) throws ParserException, ScannerException
	{
		MethodDefinitionNode tmpMethodDefinitionNode= new MethodDefinitionNode();
		
		tmpMethodDefinitionNode.vMethodDeclaratorNode= MethodDeclaratorNode.parserMethodDeclarator(env,s);
		tmpMethodDefinitionNode.vBlockNode= BlockNode.parserBlock(env,s);
		ProgramNode.vTopLevelEnvironment.put(tmpMethodDefinitionNode.mGetMethodName(), tmpMethodDefinitionNode);
		
		return tmpMethodDefinitionNode;
	}
	String mGetMethodName()
	{			
		return vMethodDeclaratorNode.mGetMethodName();
	}
	FormalParametersNode mGetForalParameters()
	{
		return vMethodDeclaratorNode.vFormalParametersNode;
	}
	ResultTypeNode mGetResultType()
	{
		return vMethodDeclaratorNode.vResultTypeNode;
	}
	MethodDefinitionNode()
	{
		vMethodDeclaratorNode= null;
		vBlockNode= null;
	}
	MethodDefinitionNode(MethodDeclaratorNode aMethodDeclaratorNode,BlockNode aBlockNode)
	{
		vMethodDeclaratorNode= aMethodDeclaratorNode;
		vBlockNode= aBlockNode;
	}
	String format(int indent)
	{
		return vMethodDeclaratorNode.format(indent) + "\n" + vBlockNode.format(indent);
	}
	Environment run(Environment env) throws InterpreterException
	{
		ProgramNode.vTopLevelEnvironment.put("returnType", mGetResultType());
		if(vBlockNode!=null)
			return vBlockNode.run(env);
		return env;
	}
	boolean typeCheck(Environment env) throws InterpreterException
	{		
		if(vMethodDeclaratorNode.typeCheck(env))
		{
			ProgramNode.vTopLevelEnvironment.put("returnType", mGetResultType());
			if(vBlockNode!=null)
				return vBlockNode.typeCheck(env);
		}else ProgramNode.mTypeCheckError("definition of " + mGetMethodName() + "method");
		return true;		
	}
}

⌨️ 快捷键说明

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