📄 javaparser.beaver
字号:
%header {: // Generated from parser/JavaParser.allpackage parser; import AST.*;:};%embed {: // Generated from parser/JavaParser.allclass Events extends Parser.Events { public void scannerError(Scanner.Exception e) { errors.add(new Problem(null, e.getMessage(), e.line, e.column, Problem.Severity.ERROR, Problem.Kind.LEXICAL)); } public void syntaxError(Symbol token) { int line = token.getLine(token.getStart()); int column = token.getColumn(token.getStart()); int endLine = token.getLine(token.getEnd()); int endColumn = token.getColumn(token.getEnd()); String value = token.value != null ? token.value.toString() : Terminals.NAMES[token.getId()]; errors.add(new Problem(null, "unexpected token \"" + value + "\"", line, column, endLine, endColumn, Problem.Severity.ERROR, Problem.Kind.SYNTACTIC)); } public void unexpectedTokenRemoved(Symbol token) { } public void missingTokenInserted(Symbol token) { } public void misspelledTokenReplaced(Symbol token) { } public void errorPhraseRemoved(Symbol error) { } } { report = new Events(); // Use error handler in parser } public CompilationUnit parse(java.io.InputStream is, String fileName) throws java.io.IOException, beaver.Parser.Exception { CompilationUnit cu; errors = new ArrayList(); try { scanner.JavaScanner scanner = new scanner.JavaScanner(new scanner.Unicode(is)); cu = (CompilationUnit)parse(scanner); } catch(Parser.Exception e) { // build empty compilation unit for failed error recovery cu = new CompilationUnit(); } catch(Error e) { cu = new CompilationUnit(); errors.add(new Problem(null, e.getMessage(), 0, 0, Problem.Severity.ERROR, Problem.Kind.LEXICAL)); } for(java.util.Iterator iter = errors.iterator(); iter.hasNext(); ) { Problem p = (Problem)iter.next(); p.setFileName(fileName); cu.addParseError(p); } return cu; } protected java.util.Collection errors = new ArrayList();:};%terminals INTEGER_LITERAL;%terminals LONG_LITERAL;%terminals FLOATING_POINT_LITERAL;%terminals DOUBLE_LITERAL;%terminals BOOLEAN_LITERAL;%terminals CHARACTER_LITERAL;%terminals STRING_LITERAL;%terminals NULL_LITERAL;%terminals BOOLEAN;%terminals BYTE;%terminals SHORT;%terminals INT;%terminals LONG;%terminals CHAR;%terminals FLOAT;%terminals DOUBLE;%terminals IDENTIFIER;%terminals DOT;%terminals PACKAGE;%terminals SEMICOLON;%terminals IMPORT;%terminals MULT;%terminals PUBLIC;%terminals PROTECTED;%terminals PRIVATE;%terminals STATIC;%terminals ABSTRACT;%terminals FINAL;%terminals NATIVE;%terminals SYNCHRONIZED;%terminals TRANSIENT;%terminals VOLATILE;%terminals STRICTFP;%terminals CLASS;%terminals EXTENDS;%terminals IMPLEMENTS;%terminals COMMA;%terminals LBRACE;%terminals RBRACE;%terminals EQ;%terminals LPAREN;%terminals RPAREN;%terminals VOID;%terminals THROWS;%terminals THIS;%terminals SUPER;%terminals INTERFACE;%terminals IF;%terminals ELSE;%terminals COLON;%terminals SWITCH;%terminals CASE;%terminals DEFAULT;%terminals WHILE;%terminals DO;%terminals FOR;%terminals BREAK;%terminals CONTINUE;%terminals RETURN;%terminals THROW;%terminals TRY;%terminals CATCH;%terminals FINALLY;%terminals ASSERT;%terminals NEW;%terminals LBRACK;%terminals RBRACK;%terminals PLUSPLUS;%terminals MINUSMINUS;%terminals PLUS;%terminals MINUS;%terminals COMP;%terminals NOT;%terminals DIV;%terminals MOD;%terminals LSHIFT;%terminals RSHIFT;%terminals URSHIFT;%terminals LT;%terminals GT;%terminals LTEQ;%terminals GTEQ;%terminals INSTANCEOF;%terminals EQEQ;%terminals NOTEQ;%terminals AND;%terminals XOR;%terminals OR;%terminals ANDAND;%terminals OROR;%terminals QUESTION;%terminals MULTEQ;%terminals DIVEQ;%terminals MODEQ;%terminals PLUSEQ;%terminals MINUSEQ;%terminals LSHIFTEQ;%terminals RSHIFTEQ;%terminals URSHIFTEQ;%terminals ANDEQ;%terminals XOREQ;%terminals OREQ;%terminals error;%typeof synchronized_statement = "SynchronizedStmt";%typeof try_statement = "TryStmt";%typeof labeled_statement = "LabeledStmt";%typeof method_header = "MethodDecl";%typeof statement_expression_list = "List";%typeof if_then_else_statement = "IfStmt";%typeof cast_expression = "Expr";%typeof type_declarations = "List";%typeof if_then_statement = "IfStmt";%typeof equality_expression = "Expr";%typeof numeric_type = "Access";%typeof interface_type = "Access";%typeof interfaces = "List";%typeof for_statement = "ForStmt";%typeof local_variable_declaration = "VarDeclStmt";%typeof statement_no_short_if = "Stmt";%typeof class_declaration = "ClassDecl";%typeof variable_declarator_id = "VariableDecl";%typeof interface_type_list = "List";%typeof conditional_and_expression = "Expr";%typeof goal = "CompilationUnit";%typeof import_declarations = "List";%typeof variable_initializers = "List";%typeof shift_expression = "Expr";%typeof method_declaration = "MethodDecl";%typeof assert_statement = "AssertStmt";%typeof import_declaration = "ImportDecl";%typeof inclusive_or_expression = "Expr";%typeof class_instance_creation_expression = "Expr";%typeof interface_body = "List";%typeof interface_member_declaration = "BodyDecl";%typeof compilation_unit = "CompilationUnit";%typeof constant_expression = "Expr";%typeof block = "Block";%typeof empty_statement = "EmptyStmt";%typeof finally = "Block";%typeof relational_expression = "Expr";%typeof floating_point_type = "Access";%typeof primary_no_new_array = "Expr";%typeof postfix_expression = "Expr";%typeof postdecrement_expression = "Expr";%typeof type_import_on_demand_declaration = "ImportDecl";%typeof conditional_or_expression = "Expr";%typeof modifiers = "List";%typeof name_decl = "IdUse";%typeof instance_initializer = "InstanceInitializer";%typeof class_body = "List";%typeof return_statement = "ReturnStmt";%typeof catches = "List";%typeof class_type_list = "List";%typeof continue_statement = "ContinueStmt";%typeof unary_expression_not_plus_minus = "Expr";%typeof field_access = "Access";%typeof assignment = "Expr";%typeof conditional_expression = "Expr";%typeof break_statement = "BreakStmt";%typeof block_statement = "Stmt";%typeof dim_exprs = "List";%typeof block_statements = "List";%typeof block_statements_opt = "List";%typeof expression = "Expr";%typeof expression_opt = "Opt";%typeof local_variable_declaration_statement = "VarDeclStmt";%typeof assignment_expression = "Expr";%typeof interface_declaration = "InterfaceDecl";%typeof multiplicative_expression = "Expr";%typeof variable_declarator = "VariableDecl";%typeof type = "Access";%typeof reference_type = "Access";%typeof constant_declaration = "BodyDecl";%typeof labeled_statement_no_short_if = "LabeledStmt";%typeof constructor_declaration = "ConstructorDecl";%typeof primary = "Expr";%typeof array_creation_uninit = "Expr";%typeof simple_name_decl = "IdUse";%typeof while_statement_no_short_if = "WhileStmt";%typeof explicit_constructor_invocation = "ExprStmt";%typeof interface_member_declarations = "List";%typeof interface_member_declarations_opt = "List";%typeof throws = "List";%typeof throws_opt = "List";%typeof switch_block = "Block";%typeof method_body = "Opt";%typeof do_statement = "DoStmt";%typeof exclusive_or_expression = "Expr";%typeof formal_parameter = "ParameterDeclaration";%typeof modifier = "Modifier";%typeof statement = "Stmt";%typeof preincrement_expression = "Expr";%typeof additive_expression = "Expr";%typeof qualified_name_decl = "IdUse";%typeof for_init = "List";%typeof for_init_opt = "List";%typeof class_or_interface_type = "Access";%typeof dim_expr = "Dims";%typeof postincrement_expression = "Expr";%typeof throw_statement = "ThrowStmt";%typeof statement_without_trailing_substatement = "Stmt";%typeof argument_list = "List";%typeof argument_list_opt = "List";%typeof statement_expression = "ExprStmt";%typeof for_statement_no_short_if = "ForStmt";%typeof switch_labels = "List";%typeof subclass_body = "Opt";%typeof switch_label = "Case";%typeof while_statement = "WhileStmt";%typeof formal_parameter_list = "List";%typeof formal_parameter_list_opt = "List";%typeof method_invocation = "Access";%typeof simple_name = "Access";%typeof qualified_name = "Access";%typeof abstract_method_declaration = "BodyDecl";%typeof variable_initializer = "Expr";%typeof for_update = "List";%typeof for_update_opt = "List";%typeof super = "Opt";%typeof field_declaration = "BodyDecl";%typeof class_literal = "ClassAccess";%typeof unary_expression = "Expr";%typeof catch_clause = "CatchClause";%typeof variable_declarators = "List";%typeof name = "Access";%typeof single_type_import_declaration = "ImportDecl";%typeof array_initializer = "ArrayInit";%typeof package_declaration = "IdUse";%typeof primitive_type = "Access";%typeof if_then_else_statement_no_short_if = "IfStmt";%typeof class_body_declaration = "BodyDecl";%typeof array_type = "Access";%typeof switch_statement = "SwitchStmt";%typeof switch_block_statement_groups = "List";%typeof static_initializer = "StaticInitializer";%typeof dims = "List";%typeof dims_opt = "List";%typeof expression_statement = "ExprStmt";%typeof predecrement_expression = "Expr";%typeof constructor_body = "ConstructorDecl";%typeof switch_block_statement_group = "List";%typeof array_creation_init = "Expr";%typeof integral_type = "Access";%typeof type_declaration = "TypeDecl";%typeof extends_interfaces = "List";%typeof class_body_declarations = "List";%typeof class_body_declarations_opt = "List";%typeof and_expression = "Expr";%typeof class_type = "Access";%typeof class_member_declaration = "BodyDecl";%typeof array_access = "Access";%typeof literal = "Expr";%goal goal;goal = compilation_unit.cu {: return cu;:} ;literal = INTEGER_LITERAL.i {: return new IntegerLiteral(((String)i.value));:} | LONG_LITERAL.l {: return new LongLiteral(((String)l.value));:} | FLOATING_POINT_LITERAL.f {: return new FloatingPointLiteral(((String)f.value));:} | DOUBLE_LITERAL.d {: return new DoubleLiteral(((String)d.value));:} | BOOLEAN_LITERAL.b {: return new BooleanLiteral(((String)b.value));:} | CHARACTER_LITERAL.c {: return new CharacterLiteral(((String)c.value));:} | STRING_LITERAL.s {: return new StringLiteral(((String)s.value));:} | NULL_LITERAL.NULL_LITERAL {: return new NullLiteral("null");:} ;type = primitive_type.t {: return t;:} | reference_type.t {: return t;:} ;primitive_type = numeric_type.t {: return t;:} | BOOLEAN.BOOLEAN {: return new PrimitiveTypeAccess("boolean");:} ;numeric_type = integral_type.t {: return t;:} | floating_point_type.t {: return t;:} ;integral_type = BYTE.BYTE {: return new PrimitiveTypeAccess("byte");:} | SHORT.SHORT {: return new PrimitiveTypeAccess("short");:} | INT.INT {: return new PrimitiveTypeAccess("int");:} | LONG.LONG {: return new PrimitiveTypeAccess("long");:} | CHAR.CHAR {: return new PrimitiveTypeAccess("char");:} ;floating_point_type = FLOAT.FLOAT {: return new PrimitiveTypeAccess("float");:} | DOUBLE.DOUBLE {: return new PrimitiveTypeAccess("double");:} ;reference_type =
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -