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

📄 skimdecafvalidator.java

📁 program assegment for compiler
💻 JAVA
字号:
/*
 * Created on Aug 28, 2004
 *
 * 
 */
package edu.berkeley.cs164.util;

import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.*;
import org.eclipse.jdt.internal.corext.dom.GenericVisitor;

/**
 * @author bodik
 * 
 * A rough check whther the traversed AST is in the SkimDecaf language.
 * 
 * If the test passes, the AST could still be an illegal AST, because this is
 * not a semantic check, only a syntactic one, and not a complete one either.
 * Your interpreter must still check things like the number of arguments for
 * print, and whether the particular infix operator is in SkimDecaf (e.g., + is
 * in SkimDecaf but || is not).
 */
public class SkimDecafValidator extends GenericVisitor {

	static private Class skimDecafClasses[] = { InfixExpression.class,
			CompilationUnit.class, IfStatement.class, Block.class,
			ExpressionStatement.class, Assignment.class,
			MethodDeclaration.class, MethodInvocation.class,
			NumberLiteral.class, SimpleName.class, TypeDeclaration.class,
			WhileStatement.class, PrimitiveType.class, ParenthesizedExpression.class };

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jdt.internal.corext.dom.GenericVisitor#visitNode(org.eclipse.jdt.core.dom.ASTNode)
	 */
	protected boolean visitNode(ASTNode node) {
		for (int i = 0; i < skimDecafClasses.length; i++) {
			if (node.getClass() == skimDecafClasses[i]) {
				return true;
			}
		}
		Util
				.errorMsg("SkimDecafValidator: input program contains a construct that is not a legal SkimDecaf construct: "
						+ node + " " + node.getClass().getName());
		Util.exit();
		return false;
	}
}

⌨️ 快捷键说明

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