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

📄 parser.java

📁 SkipOOMiniJOOL教学语言的编译器前端
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
			popStack(1);
			push(o);
			return true;
		}
		next = isave;
		setStackSize(stackSize);
		if (TERMEXPR5()) {
			Object o = peek(0);
			popStack(1);
			push(o);
			return true;
		}
		next = isave;
		setStackSize(stackSize);
		if (TERMEXPR6()) {
			Object o = peek(0);
			popStack(1);
			push(o);
			return true;
		}
		return false;
	}
	private boolean TERMEXPR1() {
		boolean match = true;
		match = match && token(Symbol.LPAREN);
		match = match && EXPR();
		match = match && token(Symbol.RPAREN);
		if (match) {

						push(peek(-1));
					
		}
		return match;
	}
	private boolean TERMEXPR2() {
		boolean match = true;
		match = match && token(Symbol.NEW);
		match = match && token(Symbol.IDENTIFIER);
		match = match && token(Symbol.LPAREN);
		match = match && token(Symbol.RPAREN);
		if (match) {

					 	ClassInstanceCreation cic = ast.newClassInstanceCreation();
					 	cic.setExpression(null);
					 	cic.setName(makeSimpleName(-2));
					 	push(cic);
					
		}
		return match;
	}
	private boolean TERMEXPR3() {
		boolean match = true;
		match = match && METHODCALL();
		return match;
	}
	private boolean TERMEXPR4() {
		boolean match = true;
		match = match && BOOLLIT();
		return match;
	}
	private boolean TERMEXPR5() {
		boolean match = true;
		match = match && SIMPLEEXPR();
		return match;
	}
	private boolean TERMEXPR6() {
		boolean match = true;
		match = match && LITERAL();
		return match;
	}
	private boolean LITERAL() {
		int isave = next;
		int stackSize = getStackSize();
		next = isave;
		setStackSize(stackSize);
		if (LITERAL1()) {
			Object o = peek(0);
			popStack(2);
			push(o);
			return true;
		}
		next = isave;
		setStackSize(stackSize);
		if (LITERAL2()) {
			Object o = peek(0);
			popStack(1);
			push(o);
			return true;
		}
		next = isave;
		setStackSize(stackSize);
		if (LITERAL3()) {
			Object o = peek(0);
			popStack(2);
			push(o);
			return true;
		}
		next = isave;
		setStackSize(stackSize);
		if (LITERAL4()) {
			Object o = peek(0);
			popStack(2);
			push(o);
			return true;
		}
		return false;
	}
	private boolean LITERAL1() {
		boolean match = true;
		match = match && token(Symbol.INTEGER_LITERAL);
		if (match) {

						NumberLiteral nl = ast.newNumberLiteral();
						nl.setToken(((Symbol)peek(0)).getLexeme());
						push(nl);
					
		}
		return match;
	}
	private boolean LITERAL2() {
		boolean match = true;
		match = match && BOOLLIT();
		return match;
	}
	private boolean LITERAL3() {
		boolean match = true;
		match = match && token(Symbol.NULL);
		if (match) {

						NullLiteral nl = ast.newNullLiteral();
						push(nl);
					
		}
		return match;
	}
	private boolean LITERAL4() {
		boolean match = true;
		match = match && token(Symbol.STRING_LITERAL);
		if (match) {

						StringLiteral sl = ast.newStringLiteral();
						sl.setEscapedValue(((Symbol)peek(0)).getLexeme());
						push(sl);
					
		}
		return match;
	}
	private boolean BOOLLIT() {
		int isave = next;
		int stackSize = getStackSize();
		next = isave;
		setStackSize(stackSize);
		if (BOOLLIT1()) {
			Object o = peek(0);
			popStack(2);
			push(o);
			return true;
		}
		return false;
	}
	private boolean BOOLLIT1() {
		boolean match = true;
		match = match && token(Symbol.BOOLEAN_LITERAL);
		if (match) {

						BooleanLiteral bl = ast.newBooleanLiteral(Boolean.getBoolean(((Symbol)peek(0)).getLexeme()));
						push(bl);
					
		}
		return match;
	}
	private boolean SIMPLEEXPR() {
		int isave = next;
		int stackSize = getStackSize();
		next = isave;
		setStackSize(stackSize);
		if (SIMPLEEXPR1()) {
			Object o = peek(0);
			popStack(2);
			push(o);
			return true;
		}
		next = isave;
		setStackSize(stackSize);
		if (SIMPLEEXPR2()) {
			Object o = peek(0);
			popStack(1);
			push(o);
			return true;
		}
		return false;
	}
	private boolean SIMPLEEXPR1() {
		boolean match = true;
		match = match && token(Symbol.THIS);
		if (match) {

						ThisExpression te = ast.newThisExpression();
						te.setQualifier(null);
						push(te);
					
		}
		return match;
	}
	private boolean SIMPLEEXPR2() {
		boolean match = true;
		match = match && LOCATION();
		return match;
	}
	private boolean METHODCALL() {
		int isave = next;
		int stackSize = getStackSize();
		next = isave;
		setStackSize(stackSize);
		if (METHODCALL1()) {
			Object o = peek(0);
			popStack(3);
			push(o);
			return true;
		}
		return false;
	}
	private boolean METHODCALL1() {
		boolean match = true;
		match = match && METHODHEAD();
		match = match && METHODMID();
		match = match && CALLTAIL();
		return match;
	}
	private boolean METHODHEAD() {
		int isave = next;
		int stackSize = getStackSize();
		next = isave;
		setStackSize(stackSize);
		if (METHODHEAD1()) {
			Object o = peek(0);
			popStack(3);
			push(o);
			return true;
		}
		next = isave;
		setStackSize(stackSize);
		if (METHODHEAD2()) {
			Object o = peek(0);
			popStack(3);
			push(o);
			return true;
		}
		next = isave;
		setStackSize(stackSize);
		if (METHODHEAD3()) {
			Object o = peek(0);
			popStack(2);
			push(o);
			return true;
		}
		return false;
	}
	private boolean METHODHEAD1() {
		boolean match = true;
		match = match && token(Symbol.IDENTIFIER);
		match = match && token(Symbol.PERIOD);
		if (match) {

					push(makeSimpleName(-1)); 
				
		}
		return match;
	}
	private boolean METHODHEAD2() {
		boolean match = true;
		match = match && token(Symbol.THIS);
		match = match && token(Symbol.PERIOD);
		if (match) {
 
	            		push(ast.newThisExpression()); 
	            	
		}
		return match;
	}
	private boolean METHODHEAD3() {
		boolean match = true;
		match = match && tokenEpsilon();
		if (match) {
 
	            		push(null); // flag for no head 
					
		}
		return match;
	}
	private boolean METHODMID() {
		int isave = next;
		int stackSize = getStackSize();
		next = isave;
		setStackSize(stackSize);
		if (METHODMID1()) {
			Object o = peek(0);
			popStack(4);
			push(o);
			return true;
		}
		next = isave;
		setStackSize(stackSize);
		if (METHODMID2()) {
			Object o = peek(0);
			popStack(1);
			push(o);
			return true;
		}
		return false;
	}
	private boolean METHODMID1() {
		boolean match = true;
		match = match && token(Symbol.IDENTIFIER);
		match = match && token(Symbol.PERIOD);
		if (match) {

	                 	FieldAccess f = ast.newFieldAccess();
	                 	f.setExpression((Expression)peek(-2));
	                 	f.setName(makeSimpleName(-1));
	                 	push(f); 
	                
		}
		match = match && METHODMID();
		return match;
	}
	private boolean METHODMID2() {
		boolean match = true;
		match = match && tokenEpsilon();
		return match;
	}
	private boolean CALLTAIL() {
		int isave = next;
		int stackSize = getStackSize();
		next = isave;
		setStackSize(stackSize);
		if (CALLTAIL1()) {
			Object o = peek(0);
			popStack(6);
			push(o);
			return true;
		}
		return false;
	}
	private boolean CALLTAIL1() {
		boolean match = true;
		match = match && token(Symbol.IDENTIFIER);
		match = match && token(Symbol.LPAREN);
		if (match) {
 
						push(new ArrayList()); 
					
		}
		match = match && EXPRLIST();
		match = match && token(Symbol.RPAREN);
		if (match) {
 
                       MethodInvocation m = ast.newMethodInvocation();
                       m.setName(makeSimpleName(-4));
                       m.setExpression((Expression)peek(-5));
                       List args = m.arguments();
                       List exprs = (List)peek(-1);
                       for (Iterator iter = exprs.iterator(); iter.hasNext(); ) {
                           Expression expr = (Expression)iter.next();
                           args.add(expr);
                       }
                       push(m);
                	
		}
		return match;
	}
	private boolean EXPRLIST() {
		int isave = next;
		int stackSize = getStackSize();
		next = isave;
		setStackSize(stackSize);
		if (EXPRLIST1()) {
			Object o = peek(0);
			popStack(1);
			push(o);
			return true;
		}
		next = isave;
		setStackSize(stackSize);
		if (EXPRLIST2()) {
			Object o = peek(0);
			popStack(1);
			push(o);
			return true;
		}
		return false;
	}
	private boolean EXPRLIST1() {
		boolean match = true;
		match = match && NONEMPTYEXPRLIST();
		return match;
	}
	private boolean EXPRLIST2() {
		boolean match = true;
		match = match && tokenEpsilon();
		return match;
	}
	private boolean NONEMPTYEXPRLIST() {
		int isave = next;
		int stackSize = getStackSize();
		next = isave;
		setStackSize(stackSize);
		if (NONEMPTYEXPRLIST1()) {
			Object o = peek(0);
			popStack(3);
			push(o);
			return true;
		}
		return false;
	}
	private boolean NONEMPTYEXPRLIST1() {
		boolean match = true;
		match = match && EXPR();
		if (match) {
 
	                        ((List)peek(-1)).add(peek(0));
	                        push(peek(-1));
	                    
		}
		match = match && NEEXPRLISTTAIL();
		return match;
	}
	private boolean NEEXPRLISTTAIL() {
		int isave = next;
		int stackSize = getStackSize();
		next = isave;
		setStackSize(stackSize);
		if (NEEXPRLISTTAIL1()) {
			Object o = peek(0);
			popStack(3);
			push(o);
			return true;
		}
		next = isave;
		setStackSize(stackSize);
		if (NEEXPRLISTTAIL2()) {
			Object o = peek(0);
			popStack(1);
			push(o);
			return true;
		}
		return false;
	}
	private boolean NEEXPRLISTTAIL1() {
		boolean match = true;
		match = match && token(Symbol.COMMA);
		if (match) {
 
						push(peek(-1)); 
					
		}
		match = match && NONEMPTYEXPRLIST();
		return match;
	}
	private boolean NEEXPRLISTTAIL2() {
		boolean match = true;
		match = match && tokenEpsilon();
		return match;
	}
	private boolean LOCATION() {
		int isave = next;
		int stackSize = getStackSize();
		next = isave;
		setStackSize(stackSize);
		if (LOCATION1()) {
			Object o = peek(0);
			popStack(2);
			push(o);
			return true;
		}
		return false;
	}
	private boolean LOCATION1() {
		boolean match = true;
		match = match && LOCATIONHEAD();
		match = match && LOCATIONTAIL();
		return match;
	}
	private boolean LOCATIONHEAD() {
		int isave = next;
		int stackSize = getStackSize();
		next = isave;
		setStackSize(stackSize);
		if (LOCATIONHEAD1()) {
			Object o = peek(0);
			popStack(3);
			push(o);
			return true;
		}
		next = isave;
		setStackSize(stackSize);
		if (LOCATIONHEAD2()) {
			Object o = peek(0);
			popStack(2);
			push(o);
			return true;
		}
		return false;
	}
	private boolean LOCATIONHEAD1() {
		boolean match = true;
		match = match && token(Symbol.THIS);
		if (match) {
 
						push(ast.newThisExpression()); 
					
		}
		match = match && FIELDDEREF();
		return match;
	}
	private boolean LOCATIONHEAD2() {
		boolean match = true;
		match = match && token(Symbol.IDENTIFIER);
		if (match) {
 
                 		push(makeSimpleName(0)); 
                 	
		}
		return match;
	}
	private boolean LOCATIONTAIL() {
		int isave = next;
		int stackSize = getStackSize();
		next = isave;
		setStackSize(stackSize);
		if (LOCATIONTAIL1()) {
			Object o = peek(0);
			popStack(2);
			push(o);
			return true;
		}
		next = isave;
		setStackSize(stackSize);
		if (LOCATIONTAIL2()) {
			Object o = peek(0);
			popStack(1);
			push(o);
			return true;
		}
		return false;
	}
	private boolean LOCATIONTAIL1() {
		boolean match = true;
		match = match && FIELDDEREF();
		match = match && LOCATIONTAIL();
		return match;
	}
	private boolean LOCATIONTAIL2() {
		boolean match = true;
		match = match && tokenEpsilon();
		return match;
	}
	private boolean FIELDDEREF() {
		int isave = next;
		int stackSize = getStackSize();
		next = isave;
		setStackSize(stackSize);
		if (FIELDDEREF1()) {
			Object o = peek(0);
			popStack(3);
			push(o);
			return true;
		}
		return false;
	}
	private boolean FIELDDEREF1() {
		boolean match = true;
		match = match && token(Symbol.PERIOD);
		match = match && token(Symbol.IDENTIFIER);
		if (match) {

                       FieldAccess f = ast.newFieldAccess();
                       f.setExpression((Expression)peek(-2));
                       f.setName(makeSimpleName(0));
                       push(f);
                   	
		}
		return match;
	}
}

⌨️ 快捷键说明

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