📄 parser.java
字号:
package edu.ustc.cs.minijool.parser;
import org.eclipse.jdt.core.dom.*;
import edu.ustc.cs.minijool.lexer.*;
import java.util.*;
/**
* This class is generated automatically by ParserCodeGenerator.
*/
public class Parser extends RDParser {
private AST ast = AST.newAST(AST.JLS3);
private SimpleName makeSimpleName(int offset) {
return ast.newSimpleName(((Symbol)peek(offset)).getLexeme());
}
public Object getAst(){
return peek(0);
}
public Parser(Lexer lexer) {
super(lexer);
}
public boolean parse() {
return PROGRAM();
}
private boolean PROGRAM() {
int isave = next;
int stackSize = getStackSize();
next = isave;
setStackSize(stackSize);
if (PROGRAM1()) {
Object o = peek(0);
popStack(5);
push(o);
return true;
}
return false;
}
private boolean PROGRAM1() {
boolean match = true;
match = match && tokenEpsilon();
if (match) {
push(new ArrayList());
}
match = match && CLASSDECLLIST();
match = match && token(Symbol.EOF);
if (match) {
push(peek(-1));
}
return match;
}
private boolean CLASSDECLLIST() {
int isave = next;
int stackSize = getStackSize();
next = isave;
setStackSize(stackSize);
if (CLASSDECLLIST1()) {
Object o = peek(0);
popStack(3);
push(o);
return true;
}
return false;
}
private boolean CLASSDECLLIST1() {
boolean match = true;
match = match && CLASSDECL();
if (match) {
((List)peek(-1)).add(peek(0));
push(peek(-1));
}
match = match && CDTAIL();
return match;
}
private boolean CDTAIL() {
int isave = next;
int stackSize = getStackSize();
next = isave;
setStackSize(stackSize);
if (CDTAIL1()) {
Object o = peek(0);
popStack(1);
push(o);
return true;
}
next = isave;
setStackSize(stackSize);
if (CDTAIL2()) {
Object o = peek(0);
popStack(1);
push(o);
return true;
}
return false;
}
private boolean CDTAIL1() {
boolean match = true;
match = match && CLASSDECLLIST();
return match;
}
private boolean CDTAIL2() {
boolean match = true;
match = match && tokenEpsilon();
return match;
}
private boolean CLASSDECL() {
int isave = next;
int stackSize = getStackSize();
next = isave;
setStackSize(stackSize);
if (CLASSDECL1()) {
Object o = peek(0);
popStack(11);
push(o);
return true;
}
return false;
}
private boolean CLASSDECL1() {
boolean match = true;
match = match && token(Symbol.CLASS);
match = match && token(Symbol.IDENTIFIER);
if (match) {
TypeDeclaration td = ast.newTypeDeclaration();
td.setName(makeSimpleName(0));
push(td);
}
match = match && SUPER();
match = match && token(Symbol.LBRACE);
if (match) {
push(((TypeDeclaration)peek(-2)).bodyDeclarations());
}
match = match && FIELDDECLLIST();
if (match) {
push(peek(-1));
}
match = match && METHODDECLLIST();
match = match && token(Symbol.RBRACE);
if (match) {
push(peek(-6));
}
return match;
}
private boolean SUPER() {
int isave = next;
int stackSize = getStackSize();
next = isave;
setStackSize(stackSize);
if (SUPER1()) {
Object o = peek(0);
popStack(3);
push(o);
return true;
}
next = isave;
setStackSize(stackSize);
if (SUPER2()) {
Object o = peek(0);
popStack(1);
push(o);
return true;
}
return false;
}
private boolean SUPER1() {
boolean match = true;
match = match && token(Symbol.EXTENDS);
match = match && token(Symbol.IDENTIFIER);
if (match) {
((TypeDeclaration)peek(-2)).
setSuperclass(makeSimpleName(0));
push(null);
}
return match;
}
private boolean SUPER2() {
boolean match = true;
match = match && tokenEpsilon();
return match;
}
private boolean METHODDECLLIST() {
int isave = next;
int stackSize = getStackSize();
next = isave;
setStackSize(stackSize);
if (METHODDECLLIST1()) {
Object o = peek(0);
popStack(3);
push(o);
return true;
}
next = isave;
setStackSize(stackSize);
if (METHODDECLLIST2()) {
Object o = peek(0);
popStack(1);
push(o);
return true;
}
return false;
}
private boolean METHODDECLLIST1() {
boolean match = true;
match = match && METHODDECL();
if (match) {
((List)peek(-1)).add(peek(0));
push(peek(-1));
}
match = match && METHODDECLLIST();
return match;
}
private boolean METHODDECLLIST2() {
boolean match = true;
match = match && tokenEpsilon();
return match;
}
private boolean METHODDECL() {
int isave = next;
int stackSize = getStackSize();
next = isave;
setStackSize(stackSize);
if (METHODDECL1()) {
Object o = peek(0);
popStack(9);
push(o);
return true;
}
return false;
}
private boolean METHODDECL1() {
boolean match = true;
match = match && MODIFIER();
match = match && METHODTYPE();
match = match && token(Symbol.IDENTIFIER);
match = match && token(Symbol.LPAREN);
if (match) {
push(new ArrayList());
}
match = match && PARAMS();
match = match && token(Symbol.RPAREN);
match = match && BLOCK();
if (match) {
MethodDeclaration m = ast.newMethodDeclaration();
m.modifiers().addAll(ast.newModifiers(((Integer)peek(-7)).intValue()));
m.setBody((Block)peek(0));
m.setName(makeSimpleName(-5));
m.setReturnType2((Type)peek(-6));
List paramsList = (List)peek(-2);
for (Iterator iter = paramsList.iterator(); iter.hasNext(); ) {
m.parameters().add(iter.next());
}
push(m);
}
return match;
}
private boolean MODIFIER() {
int isave = next;
int stackSize = getStackSize();
next = isave;
setStackSize(stackSize);
if (MODIFIER1()) {
Object o = peek(0);
popStack(2);
push(o);
return true;
}
next = isave;
setStackSize(stackSize);
if (MODIFIER2()) {
Object o = peek(0);
popStack(2);
push(o);
return true;
}
return false;
}
private boolean MODIFIER1() {
boolean match = true;
match = match && token(Symbol.STATIC);
if (match) {
push(new Integer(Modifier.STATIC));
}
return match;
}
private boolean MODIFIER2() {
boolean match = true;
match = match && tokenEpsilon();
if (match) {
push(new Integer(Modifier.NONE));
}
return match;
}
private boolean METHODTYPE() {
int isave = next;
int stackSize = getStackSize();
next = isave;
setStackSize(stackSize);
if (METHODTYPE1()) {
Object o = peek(0);
popStack(1);
push(o);
return true;
}
next = isave;
setStackSize(stackSize);
if (METHODTYPE2()) {
Object o = peek(0);
popStack(2);
push(o);
return true;
}
return false;
}
private boolean METHODTYPE1() {
boolean match = true;
match = match && TYPE();
return match;
}
private boolean METHODTYPE2() {
boolean match = true;
match = match && token(Symbol.VOID);
if (match) {
push(ast.newPrimitiveType(PrimitiveType.VOID));
}
return match;
}
private boolean PARAMS() {
int isave = next;
int stackSize = getStackSize();
next = isave;
setStackSize(stackSize);
if (PARAMS1()) {
Object o = peek(0);
popStack(1);
push(o);
return true;
}
next = isave;
setStackSize(stackSize);
if (PARAMS2()) {
Object o = peek(0);
popStack(1);
push(o);
return true;
}
return false;
}
private boolean PARAMS1() {
boolean match = true;
match = match && NONEMPTYPARAMS();
return match;
}
private boolean PARAMS2() {
boolean match = true;
match = match && tokenEpsilon();
return match;
}
private boolean NONEMPTYPARAMS() {
int isave = next;
int stackSize = getStackSize();
next = isave;
setStackSize(stackSize);
if (NONEMPTYPARAMS1()) {
Object o = peek(0);
popStack(4);
push(o);
return true;
}
return false;
}
private boolean NONEMPTYPARAMS1() {
boolean match = true;
match = match && TYPE();
match = match && token(Symbol.IDENTIFIER);
if (match) {
SingleVariableDeclaration s = ast.newSingleVariableDeclaration();
s.setName(makeSimpleName(0));
s.setType((Type)peek(-1));
((List)peek(-2)).add(s);
push(peek(-2));
}
match = match && NEPARAMSTAIL();
return match;
}
private boolean NEPARAMSTAIL() {
int isave = next;
int stackSize = getStackSize();
next = isave;
setStackSize(stackSize);
if (NEPARAMSTAIL1()) {
Object o = peek(0);
popStack(3);
push(o);
return true;
}
next = isave;
setStackSize(stackSize);
if (NEPARAMSTAIL2()) {
Object o = peek(0);
popStack(1);
push(o);
return true;
}
return false;
}
private boolean NEPARAMSTAIL1() {
boolean match = true;
match = match && token(Symbol.COMMA);
if (match) {
push(peek(-1));
}
match = match && NONEMPTYPARAMS();
return match;
}
private boolean NEPARAMSTAIL2() {
boolean match = true;
match = match && tokenEpsilon();
return match;
}
private boolean BLOCK() {
int isave = next;
int stackSize = getStackSize();
next = isave;
setStackSize(stackSize);
if (BLOCK1()) {
Object o = peek(0);
popStack(6);
push(o);
return true;
}
return false;
}
private boolean BLOCK1() {
boolean match = true;
match = match && token(Symbol.LBRACE);
if (match) {
push(new ArrayList());
}
match = match && VARDECLLIST();
match = match && STATEMENTLIST();
match = match && token(Symbol.RBRACE);
if (match) {
Block b = ast.newBlock();
List stmts = (List)peek(-1);
for (Iterator iter = stmts.iterator(); iter.hasNext(); ) {
b.statements().add(iter.next());
}
push(b);
}
return match;
}
private boolean VARDECLLIST() {
int isave = next;
int stackSize = getStackSize();
next = isave;
setStackSize(stackSize);
if (VARDECLLIST1()) {
Object o = peek(0);
popStack(3);
push(o);
return true;
}
next = isave;
setStackSize(stackSize);
if (VARDECLLIST2()) {
Object o = peek(0);
popStack(1);
push(o);
return true;
}
return false;
}
private boolean VARDECLLIST1() {
boolean match = true;
match = match && VARDECL();
if (match) {
((List)peek(-1)).add((Statement)peek(0));
push(peek(-1));
}
match = match && VARDECLLIST();
return match;
}
private boolean VARDECLLIST2() {
boolean match = true;
match = match && tokenEpsilon();
return match;
}
private boolean VARDECL() {
int isave = next;
int stackSize = getStackSize();
next = isave;
setStackSize(stackSize);
if (VARDECL1()) {
Object o = peek(0);
popStack(4);
push(o);
return true;
}
return false;
}
private boolean VARDECL1() {
boolean match = true;
match = match && TYPE();
match = match && IDLIST();
match = match && token(Symbol.SEMICOLON);
if (match) {
((VariableDeclarationStatement)peek(-1)).setType((Type)peek(-2));
push(peek(-1));
}
return match;
}
private boolean IDLIST() {
int isave = next;
int stackSize = getStackSize();
next = isave;
setStackSize(stackSize);
if (IDLIST1()) {
Object o = peek(0);
popStack(4);
push(o);
return true;
}
next = isave;
setStackSize(stackSize);
if (IDLIST2()) {
Object o = peek(0);
popStack(2);
push(o);
return true;
}
return false;
}
private boolean IDLIST1() {
boolean match = true;
match = match && token(Symbol.IDENTIFIER);
match = match && token(Symbol.COMMA);
match = match && IDLIST();
if (match) {
VariableDeclarationFragment vdf = ast.newVariableDeclarationFragment();
vdf.setName(ast.newSimpleName(((Symbol)peek(-2)).getLexeme()));
((VariableDeclarationStatement)peek(0)).fragments().add(0, vdf);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -