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

📄 parser.java

📁 SkipOOMiniJOOL教学语言的编译器前端
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
						push(peek(0));
					
		}
		return match;
	}
	private boolean IDLIST2() {
		boolean match = true;
		match = match && token(Symbol.IDENTIFIER);
		if (match) {

						VariableDeclarationFragment vdf = ast.newVariableDeclarationFragment();
						vdf.setName((SimpleName)ast.newSimpleName(((Symbol)peek(0)).getLexeme()));
						push(ast.newVariableDeclarationStatement(vdf));
					
		}
		return match;
	}
	private boolean FIELDDECLLIST() {
		int isave = next;
		int stackSize = getStackSize();
		next = isave;
		setStackSize(stackSize);
		if (FIELDDECLLIST1()) {
			Object o = peek(0);
			popStack(3);
			push(o);
			return true;
		}
		next = isave;
		setStackSize(stackSize);
		if (FIELDDECLLIST2()) {
			Object o = peek(0);
			popStack(1);
			push(o);
			return true;
		}
		return false;
	}
	private boolean FIELDDECLLIST1() {
		boolean match = true;
		match = match && FIELDDECL();
		if (match) {
 
						((List)peek(-1)).add((FieldDeclaration)peek(0));
						push(peek(-1)); 
					
		}
		match = match && FIELDDECLLIST();
		return match;
	}
	private boolean FIELDDECLLIST2() {
		boolean match = true;
		match = match && tokenEpsilon();
		return match;
	}
	private boolean FIELDDECL() {
		int isave = next;
		int stackSize = getStackSize();
		next = isave;
		setStackSize(stackSize);
		if (FIELDDECL1()) {
			Object o = peek(0);
			popStack(5);
			push(o);
			return true;
		}
		next = isave;
		setStackSize(stackSize);
		if (FIELDDECL2()) {
			Object o = peek(0);
			popStack(4);
			push(o);
			return true;
		}
		return false;
	}
	private boolean FIELDDECL1() {
		boolean match = true;
		match = match && token(Symbol.STATIC);
		match = match && TYPE();
		match = match && FIELDIDLIST();
		match = match && token(Symbol.SEMICOLON);
		if (match) {

						((FieldDeclaration)peek(-1)).setType((Type)peek(-2));
						((FieldDeclaration)peek(-1)).modifiers().addAll(ast.newModifiers(Modifier.STATIC));
						push(peek(-1));
					
		}
		return match;
	}
	private boolean FIELDDECL2() {
		boolean match = true;
		match = match && TYPE();
		match = match && FIELDIDLIST();
		match = match && token(Symbol.SEMICOLON);
		if (match) {

						((FieldDeclaration)peek(-1)).setType((Type)peek(-2));
						push(peek(-1));
                    
		}
		return match;
	}
	private boolean FIELDIDLIST() {
		int isave = next;
		int stackSize = getStackSize();
		next = isave;
		setStackSize(stackSize);
		if (FIELDIDLIST1()) {
			Object o = peek(0);
			popStack(4);
			push(o);
			return true;
		}
		next = isave;
		setStackSize(stackSize);
		if (FIELDIDLIST2()) {
			Object o = peek(0);
			popStack(2);
			push(o);
			return true;
		}
		return false;
	}
	private boolean FIELDIDLIST1() {
		boolean match = true;
		match = match && token(Symbol.IDENTIFIER);
		match = match && token(Symbol.COMMA);
		match = match && FIELDIDLIST();
		if (match) {

						VariableDeclarationFragment vdf = ast.newVariableDeclarationFragment();
						vdf.setName(ast.newSimpleName(((Symbol)peek(-2)).getLexeme()));
						((FieldDeclaration)peek(0)).fragments().add(0, vdf);
						push(peek(0));
					
		}
		return match;
	}
	private boolean FIELDIDLIST2() {
		boolean match = true;
		match = match && token(Symbol.IDENTIFIER);
		if (match) {

						VariableDeclarationFragment vdf = ast.newVariableDeclarationFragment();
						vdf.setName((SimpleName)ast.newSimpleName(((Symbol)peek(0)).getLexeme()));
						push(ast.newFieldDeclaration(vdf));
					
		}
		return match;
	}
	private boolean TYPE() {
		int isave = next;
		int stackSize = getStackSize();
		next = isave;
		setStackSize(stackSize);
		if (TYPE1()) {
			Object o = peek(0);
			popStack(2);
			push(o);
			return true;
		}
		next = isave;
		setStackSize(stackSize);
		if (TYPE2()) {
			Object o = peek(0);
			popStack(2);
			push(o);
			return true;
		}
		next = isave;
		setStackSize(stackSize);
		if (TYPE3()) {
			Object o = peek(0);
			popStack(2);
			push(o);
			return true;
		}
		return false;
	}
	private boolean TYPE1() {
		boolean match = true;
		match = match && token(Symbol.INT);
		if (match) {
 
						push(ast.newPrimitiveType(PrimitiveType.INT)); 
					
		}
		return match;
	}
	private boolean TYPE2() {
		boolean match = true;
		match = match && token(Symbol.BOOLEAN);
		if (match) {
 
						push(ast.newPrimitiveType(PrimitiveType.BOOLEAN)); 
					
		}
		return match;
	}
	private boolean TYPE3() {
		boolean match = true;
		match = match && token(Symbol.IDENTIFIER);
		if (match) {
 
						push(ast.newSimpleType(ast.newSimpleName(
							((Symbol)peek(0)).getLexeme())));				
					
		}
		return match;
	}
	private boolean STATEMENTLIST() {
		int isave = next;
		int stackSize = getStackSize();
		next = isave;
		setStackSize(stackSize);
		if (STATEMENTLIST1()) {
			Object o = peek(0);
			popStack(3);
			push(o);
			return true;
		}
		next = isave;
		setStackSize(stackSize);
		if (STATEMENTLIST2()) {
			Object o = peek(0);
			popStack(1);
			push(o);
			return true;
		}
		return false;
	}
	private boolean STATEMENTLIST1() {
		boolean match = true;
		match = match && STATEMENT();
		if (match) {
 
						((List)peek(-1)).add(peek(0)); 
						push(peek(-1));
					
		}
		match = match && STATEMENTLIST();
		return match;
	}
	private boolean STATEMENTLIST2() {
		boolean match = true;
		match = match && tokenEpsilon();
		return match;
	}
	private boolean STATEMENT() {
		int isave = next;
		int stackSize = getStackSize();
		next = isave;
		setStackSize(stackSize);
		if (STATEMENT1()) {
			Object o = peek(0);
			popStack(7);
			push(o);
			return true;
		}
		next = isave;
		setStackSize(stackSize);
		if (STATEMENT2()) {
			Object o = peek(0);
			popStack(6);
			push(o);
			return true;
		}
		next = isave;
		setStackSize(stackSize);
		if (STATEMENT3()) {
			Object o = peek(0);
			popStack(4);
			push(o);
			return true;
		}
		next = isave;
		setStackSize(stackSize);
		if (STATEMENT4()) {
			Object o = peek(0);
			popStack(3);
			push(o);
			return true;
		}
		next = isave;
		setStackSize(stackSize);
		if (STATEMENT5()) {
			Object o = peek(0);
			popStack(6);
			push(o);
			return true;
		}
		next = isave;
		setStackSize(stackSize);
		if (STATEMENT6()) {
			Object o = peek(0);
			popStack(1);
			push(o);
			return true;
		}
		next = isave;
		setStackSize(stackSize);
		if (STATEMENT7()) {
			Object o = peek(0);
			popStack(5);
			push(o);
			return true;
		}
		next = isave;
		setStackSize(stackSize);
		if (STATEMENT8()) {
			Object o = peek(0);
			popStack(3);
			push(o);
			return true;
		}
		return false;
	}
	private boolean STATEMENT1() {
		boolean match = true;
		match = match && token(Symbol.IF);
		match = match && token(Symbol.LPAREN);
		match = match && EXPR();
		match = match && token(Symbol.RPAREN);
		match = match && BLOCK();
		if (match) {

						IfStatement is = ast.newIfStatement();
						is.setExpression((Expression)peek(-2));
						is.setThenStatement((Block)peek(0));		
						push(is);	
					
		}
		match = match && ELSEPART();
		return match;
	}
	private boolean STATEMENT2() {
		boolean match = true;
		match = match && token(Symbol.WHILE);
		match = match && token(Symbol.LPAREN);
		match = match && EXPR();
		match = match && token(Symbol.RPAREN);
		match = match && BLOCK();
		if (match) {

						WhileStatement ws = ast.newWhileStatement();
						ws.setExpression((Expression)peek(-2));
						ws.setBody((Block)peek(0));	
						push(ws);
					
		}
		return match;
	}
	private boolean STATEMENT3() {
		boolean match = true;
		match = match && token(Symbol.RETURN);
		match = match && EXPR();
		match = match && token(Symbol.SEMICOLON);
		if (match) {

						ReturnStatement rs = ast.newReturnStatement();
						rs.setExpression((Expression)peek(-1));
						push(rs);
					
		}
		return match;
	}
	private boolean STATEMENT4() {
		boolean match = true;
		match = match && token(Symbol.RETURN);
		match = match && token(Symbol.SEMICOLON);
		if (match) {

						ReturnStatement rs = ast.newReturnStatement();
						rs.setExpression(null);
						push(rs);
					
		}
		return match;
	}
	private boolean STATEMENT5() {
		boolean match = true;
		match = match && token(Symbol.PRINT);
		match = match && token(Symbol.LPAREN);
		match = match && EXPR();
		match = match && token(Symbol.RPAREN);
		match = match && token(Symbol.SEMICOLON);
		if (match) {

						MethodInvocation rs = ast.newMethodInvocation();
						rs.setName(makeSimpleName(-4));
						rs.setExpression(null);
						rs.arguments().add(peek(-2));
						ExpressionStatement es = ast.newExpressionStatement(rs);
						push(es);
					
		}
		return match;
	}
	private boolean STATEMENT6() {
		boolean match = true;
		match = match && BLOCK();
		return match;
	}
	private boolean STATEMENT7() {
		boolean match = true;
		match = match && LOCATION();
		match = match && token(Symbol.EQ);
		match = match && EXPR();
		match = match && token(Symbol.SEMICOLON);
		if (match) {

						Assignment ass= ast.newAssignment();
						ass.setLeftHandSide((Expression)peek(-3));
						ass.setOperator(Assignment.Operator.ASSIGN);
						ass.setRightHandSide((Expression)peek(-1));
						ExpressionStatement es = ast.newExpressionStatement(ass);
						push(es);
					
		}
		return match;
	}
	private boolean STATEMENT8() {
		boolean match = true;
		match = match && METHODCALL();
		match = match && token(Symbol.SEMICOLON);
		if (match) {

						ExpressionStatement es = ast.newExpressionStatement((Expression)peek(-1));
						push(es);
					
		}
		return match;
	}
	private boolean ELSEPART() {
		int isave = next;
		int stackSize = getStackSize();
		next = isave;
		setStackSize(stackSize);
		if (ELSEPART1()) {
			Object o = peek(0);
			popStack(3);
			push(o);
			return true;
		}
		next = isave;
		setStackSize(stackSize);
		if (ELSEPART2()) {
			Object o = peek(0);
			popStack(2);
			push(o);
			return true;
		}
		return false;
	}
	private boolean ELSEPART1() {
		boolean match = true;
		match = match && token(Symbol.ELSE);
		match = match && BLOCK();
		if (match) {

						((IfStatement)peek(-2)).setElseStatement((Block)peek(0));
						push(peek(-2));
					
		}
		return match;
	}
	private boolean ELSEPART2() {
		boolean match = true;
		match = match && tokenEpsilon();
		if (match) {

						((IfStatement)peek(-1)).setElseStatement(null);
						push(peek(-1));
					
		}
		return match;
	}
	private boolean EXPR() {
		int isave = next;
		int stackSize = getStackSize();
		next = isave;
		setStackSize(stackSize);
		if (EXPR1()) {
			Object o = peek(0);
			popStack(1);
			push(o);
			return true;
		}
		return false;
	}
	private boolean EXPR1() {
		boolean match = true;
		match = match && BOOLEXPR();
		return match;
	}
	private boolean BOOLEXPR() {
		int isave = next;
		int stackSize = getStackSize();
		next = isave;
		setStackSize(stackSize);
		if (BOOLEXPR1()) {
			Object o = peek(0);
			popStack(2);
			push(o);
			return true;
		}
		return false;
	}
	private boolean BOOLEXPR1() {
		boolean match = true;
		match = match && EQEXPR();
		match = match && BOOLEXPR2();
		return match;
	}
	private boolean BOOLEXPR2() {
		int isave = next;
		int stackSize = getStackSize();
		next = isave;
		setStackSize(stackSize);
		if (BOOLEXPR21()) {
			Object o = peek(0);
			popStack(4);
			push(o);
			return true;
		}
		next = isave;
		setStackSize(stackSize);
		if (BOOLEXPR22()) {
			Object o = peek(0);
			popStack(4);
			push(o);
			return true;
		}
		next = isave;
		setStackSize(stackSize);
		if (BOOLEXPR23()) {
			Object o = peek(0);
			popStack(1);
			push(o);
			return true;
		}
		return false;
	}
	private boolean BOOLEXPR21() {
		boolean match = true;
		match = match && token(Symbol.OROR);
		match = match && EQEXPR();
		if (match) {

						InfixExpression	ie = ast.newInfixExpression();
						ie.setLeftOperand((Expression)peek(-2));
						ie.setOperator(InfixExpression.Operator.CONDITIONAL_OR);
						ie.setRightOperand((Expression)peek(0));
						push(ie);
					
		}
		match = match && BOOLEXPR2();
		return match;
	}
	private boolean BOOLEXPR22() {
		boolean match = true;
		match = match && token(Symbol.ANDAND);
		match = match && EQEXPR();
		if (match) {

				 		InfixExpression	ie = ast.newInfixExpression();
						ie.setLeftOperand((Expression)peek(-2));
						ie.setOperator(InfixExpression.Operator.CONDITIONAL_AND);
						ie.setRightOperand((Expression)peek(0));
						push(ie);
				 	
		}
		match = match && BOOLEXPR2();
		return match;
	}
	private boolean BOOLEXPR23() {
		boolean match = true;
		match = match && tokenEpsilon();
		return match;
	}
	private boolean EQEXPR() {
		int isave = next;
		int stackSize = getStackSize();
		next = isave;

⌨️ 快捷键说明

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