summaryrefslogtreecommitdiffstats
path: root/languages/java/java.tree.g
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit114a878c64ce6f8223cfd22d76a20eb16d177e5e (patch)
treeacaf47eb0fa12142d3896416a69e74cbf5a72242 /languages/java/java.tree.g
downloadtdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.tar.gz
tdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdevelop@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'languages/java/java.tree.g')
-rw-r--r--languages/java/java.tree.g331
1 files changed, 331 insertions, 0 deletions
diff --git a/languages/java/java.tree.g b/languages/java/java.tree.g
new file mode 100644
index 00000000..9fa94a95
--- /dev/null
+++ b/languages/java/java.tree.g
@@ -0,0 +1,331 @@
+options {
+ language="Cpp";
+}
+
+/** Java 1.3 AST Recognizer Grammar
+ *
+ * Author: (see java.g preamble)
+ *
+ * Version tracking now done with following ID:
+ *
+ * $Id$
+ *
+ * This grammar is in the PUBLIC DOMAIN
+ */
+
+class JavaTreeParser extends TreeParser;
+
+options {
+ importVocab = Java;
+}
+
+compilationUnit
+ : (packageDefinition)?
+ (importDefinition)*
+ (typeDefinition)*
+ ;
+
+packageDefinition
+ : #( PACKAGE_DEF identifier )
+ ;
+
+importDefinition
+ : #( IMPORT identifierStar )
+ ;
+
+typeDefinition
+ : #(CLASS_DEF modifiers IDENT extendsClause implementsClause objBlock )
+ | #(INTERFACE_DEF modifiers IDENT extendsClause interfaceBlock )
+ ;
+
+typeSpec
+ : #(TYPE typeSpecArray)
+ ;
+
+typeSpecArray
+ : #( ARRAY_DECLARATOR typeSpecArray )
+ | type
+ ;
+
+type: identifier
+ | builtInType
+ ;
+
+builtInType
+ : "void"
+ | "boolean"
+ | "byte"
+ | "char"
+ | "short"
+ | "int"
+ | "float"
+ | "long"
+ | "double"
+ ;
+
+modifiers
+ : #( MODIFIERS (modifier)* )
+ ;
+
+modifier
+ : "private"
+ | "public"
+ | "protected"
+ | "static"
+ | "transient"
+ | "final"
+ | "abstract"
+ | "native"
+ | "threadsafe"
+ | "synchronized"
+ | "const"
+ | "volatile"
+ | "strictfp"
+ ;
+
+extendsClause
+ : #(EXTENDS_CLAUSE (identifier)* )
+ ;
+
+implementsClause
+ : #(IMPLEMENTS_CLAUSE (identifier)* )
+ ;
+
+interfaceBlock
+ : #( OBJBLOCK
+ ( methodDecl
+ | variableDef
+ )*
+ )
+ ;
+
+objBlock
+ : #( OBJBLOCK
+ ( ctorDef
+ | methodDef
+ | variableDef
+ | typeDefinition
+ | #(STATIC_INIT slist)
+ | #(INSTANCE_INIT slist)
+ )*
+ )
+ ;
+
+ctorDef
+ : #(CTOR_DEF modifiers methodHead (slist)?)
+ ;
+
+methodDecl
+ : #(METHOD_DEF modifiers typeSpec methodHead)
+ ;
+
+methodDef
+ : #(METHOD_DEF modifiers typeSpec methodHead (slist)?)
+ ;
+
+variableDef
+ : #(VARIABLE_DEF modifiers typeSpec variableDeclarator varInitializer)
+ ;
+
+parameterDef
+ : #(PARAMETER_DEF modifiers typeSpec IDENT )
+ ;
+
+objectinitializer
+ : #(INSTANCE_INIT slist)
+ ;
+
+variableDeclarator
+ : IDENT
+ | LBRACK variableDeclarator
+ ;
+
+varInitializer
+ : #(ASSIGN initializer)
+ |
+ ;
+
+initializer
+ : expression
+ | arrayInitializer
+ ;
+
+arrayInitializer
+ : #(ARRAY_INIT (initializer)*)
+ ;
+
+methodHead
+ : IDENT #( PARAMETERS (parameterDef)* ) (throwsClause)?
+ ;
+
+throwsClause
+ : #( "throws" (identifier)* )
+ ;
+
+identifier
+ : IDENT
+ | #( DOT identifier IDENT )
+ ;
+
+identifierStar
+ : IDENT
+ | #( DOT identifier (STAR|IDENT) )
+ ;
+
+slist
+ : #( SLIST (stat)* )
+ ;
+
+stat: typeDefinition
+ | variableDef
+ | expression
+ | #(LABELED_STAT IDENT stat)
+ | #("if" expression stat (stat)? )
+ | #( "for"
+ #(FOR_INIT (variableDef | elist)?)
+ #(FOR_CONDITION (expression)?)
+ #(FOR_ITERATOR (elist)?)
+ stat
+ )
+ | #("while" expression stat)
+ | #("do" stat expression)
+ | #("break" (IDENT)? )
+ | #("continue" (IDENT)? )
+ | #("return" (expression)? )
+ | #("switch" expression (caseGroup)*)
+ | #("throw" expression)
+ | #("synchronized" expression stat)
+ | tryBlock
+ | slist // nested SLIST
+ // uncomment to make assert JDK 1.4 stuff work
+ // | #("assert" expression (expression)?)
+ | EMPTY_STAT
+ ;
+
+caseGroup
+ : #(CASE_GROUP (#("case" expression) | "default")+ slist)
+ ;
+
+tryBlock
+ : #( "try" slist (handler)* (#("finally" slist))? )
+ ;
+
+handler
+ : #( "catch" parameterDef slist )
+ ;
+
+elist
+ : #( ELIST (expression)* )
+ ;
+
+expression
+ : #(EXPR expr)
+ ;
+
+expr: #(QUESTION expr expr expr) // trinary operator
+ | #(ASSIGN expr expr) // binary operators...
+ | #(PLUS_ASSIGN expr expr)
+ | #(MINUS_ASSIGN expr expr)
+ | #(STAR_ASSIGN expr expr)
+ | #(DIV_ASSIGN expr expr)
+ | #(MOD_ASSIGN expr expr)
+ | #(SR_ASSIGN expr expr)
+ | #(BSR_ASSIGN expr expr)
+ | #(SL_ASSIGN expr expr)
+ | #(BAND_ASSIGN expr expr)
+ | #(BXOR_ASSIGN expr expr)
+ | #(BOR_ASSIGN expr expr)
+ | #(LOR expr expr)
+ | #(LAND expr expr)
+ | #(BOR expr expr)
+ | #(BXOR expr expr)
+ | #(BAND expr expr)
+ | #(NOT_EQUAL expr expr)
+ | #(EQUAL expr expr)
+ | #(LT_ expr expr)
+ | #(GT expr expr)
+ | #(LE expr expr)
+ | #(GE expr expr)
+ | #(SL expr expr)
+ | #(SR expr expr)
+ | #(BSR expr expr)
+ | #(PLUS expr expr)
+ | #(MINUS expr expr)
+ | #(DIV expr expr)
+ | #(MOD expr expr)
+ | #(STAR expr expr)
+ | #(INC expr)
+ | #(DEC expr)
+ | #(POST_INC expr)
+ | #(POST_DEC expr)
+ | #(BNOT expr)
+ | #(LNOT expr)
+ | #("instanceof" expr expr)
+ | #(UNARY_MINUS expr)
+ | #(UNARY_PLUS expr)
+ | primaryExpression
+ ;
+
+primaryExpression
+ : IDENT
+ | #( DOT
+ ( expr
+ ( IDENT
+ | arrayIndex
+ | "this"
+ | "class"
+ | #( "new" IDENT elist )
+ | "super"
+ )
+ | #(ARRAY_DECLARATOR typeSpecArray)
+ | builtInType ("class")?
+ )
+ )
+ | arrayIndex
+ | #(METHOD_CALL primaryExpression elist)
+ | ctorCall
+ | #(TYPECAST typeSpec expr)
+ | newExpression
+ | constant
+ | "super"
+ | "true"
+ | "false"
+ | "this"
+ | "null"
+ | typeSpec // type name used with instanceof
+ ;
+
+ctorCall
+ : #( CTOR_CALL elist )
+ | #( SUPER_CTOR_CALL
+ ( elist
+ | primaryExpression elist
+ )
+ )
+ ;
+
+arrayIndex
+ : #(INDEX_OP expr expression)
+ ;
+
+constant
+ : NUM_INT
+ | CHAR_LITERAL
+ | STRING_LITERAL
+ | NUM_FLOAT
+ | NUM_DOUBLE
+ | NUM_LONG
+ ;
+
+newExpression
+ : #( "new" type
+ ( newArrayDeclarator (arrayInitializer)?
+ | elist (objBlock)?
+ )
+ )
+
+ ;
+
+newArrayDeclarator
+ : #( ARRAY_DECLARATOR (newArrayDeclarator)? (expression)? )
+ ;