1 / 15

Java Parser

Java Parser. Reserved words. TOKEN : { < ABSTRACT: "abstract" > | < BOOLEAN: "boolean" > | < BREAK: "break" > | < BYTE: "byte" > | < CASE: "case" > | < CATCH: "catch" > | < CHAR: "char" > | < CLASS: "class" > | < CONST: "const" > | < CONTINUE: "continue" > | < _DEFAULT: "default" >

noura
Download Presentation

Java Parser

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Java Parser

  2. Reserved words TOKEN : { < ABSTRACT: "abstract" > | < BOOLEAN: "boolean" > | < BREAK: "break" > | < BYTE: "byte" > | < CASE: "case" > | < CATCH: "catch" > | < CHAR: "char" > | < CLASS: "class" > | < CONST: "const" > | < CONTINUE: "continue" > | < _DEFAULT: "default" > | < DO: "do" > | < DOUBLE: "double" > | < ELSE: "else" > | < EXTENDS: "extends" > | < FALSE: "false" > | < FINAL: "final" > | < FINALLY: "finally" > | < FLOAT: "float" > | < FOR: "for" > | < GOTO: "goto" > | < IF: "if" > | < IMPLEMENTS: "implements" > | < IMPORT: "import" > | < INSTANCEOF: "instanceof" > | < INT: "int" > | < INTERFACE: "interface" > | < LONG: "long" > | < NATIVE: "native" > | < NEW: "new" > | < NULL: "null" > | < PACKAGE: "package"> | < PRIVATE: "private" > | < PROTECTED: "protected" > | < PUBLIC: "public" > | < RETURN: "return" > | < SHORT: "short" > | < STATIC: "static" > | < SUPER: "super" > | < SWITCH: "switch" > | < SYNCHRONIZED: "synchronized" > | < THIS: "this" > | < THROW: "throw" > | < THROWS: "throws" > | < TRANSIENT: "transient" > | < TRUE: "true" > | < TRY: "try" > | < VOID: "void" > | < VOLATILE: "volatile" > | < WHILE: "while" > }

  3. interface

  4. Abstract classes • abstract class is a class that is declared abstract. • May or may not include abstract methods. • Abstract classes cannot be instantiated. • An abstract method is a method that is declared without an implementation (without braces, and followed by a semicolon). abstract class GraphicObject { int x, y; ... void moveTo(int newX, int newY) { ... } abstract void draw(); abstract void resize(); }

  5. goto • In the Java programming language, goto is a reserved word. • The Java programming language does not have a goto statement. • It is a word reserved for possible incorporation in a future version.

  6. instanceof • The instanceof keyword can be used to test if an object is of a specified type. public class MainClass { public static void main(String[] a) { String s = "Hello"; if (s instanceof java.lang.String) System.out.println("is a String"); } }

  7. Difference between throw and throws in Java • throw is used to actually throw the exception. • throws is declarative for the method. • One declares it, and the other one does it • They are not interchangeable. public void myMethod (int param) throws MyException { if (param < 10) { throw new MyException("Too low!"); } //Blah, Blah, Blah... }

  8. transient • When an object is transferred through the network, the object needs to be 'serialized'. Serialization converts the object state to serial bytes. Those bytes are sent over the network and the object is recreated from those bytes. Member variables marked by the java transient keyword are not transferred, they are lost on purpose. public class Foo { private String saveMe; private transient String dontSaveMe; private transient String password; . . }

  9. volatile • It marks a member variable not to be used in optimization, during compilation. • Optimizing compilers may insert code to gain run-time performance. • This can cause problems when a variable can be changed by many threads. • Those variables that can be changed by more than one thread should be set to volatile. • E.g.,private volatile changingVar;

  10. Numeric literals TOKEN : { < INTEGER_LITERAL: <DECIMAL_LITERAL> (["l","L"])? | <HEX_LITERAL> (["l","L"])? | <OCTAL_LITERAL> (["l","L"])? > | < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* > | < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ > | < #OCTAL_LITERAL: "0" (["0"-"7"])* > | < FLOATING_POINT_LITERAL: (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])? | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])? | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])? | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"] > | < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >

  11. Separators TOKEN : { < LPAREN: "(" > | < RPAREN: ")" > | < LBRACE: "{" > | < RBRACE: "}" > | < LBRACKET: "[" > | < RBRACKET: "]" > | < SEMICOLON: ";" > | < COMMA: "," > | < DOT: "." > }

  12. Operators TOKEN : { < ASSIGN: "=" > | < GT: ">" > | < LT: "<" > | < BANG: "!" > | < TILDE: "~" > | < HOOK: "?" > | < COLON: ":" > | < EQ: "==" > | < LE: "<=" > | < GE: ">=" > | < NE: "!=" > | < SC_OR: "||" > | < SC_AND: "&&" > | < INCR: "++" > | < DECR: "--" > | < PLUS: "+" > | < MINUS: "-" > | < STAR: "*" > | < SLASH: "/" > | < BIT_AND: "&" > | < BIT_OR: "|" > | < XOR: "^" > | < REM: "%" > | < LSHIFT: "<<" > | < RSIGNEDSHIFT: ">>" > | < RUNSIGNEDSHIFT: ">>>" > | < PLUSASSIGN: "+=" > | < MINUSASSIGN: "-=" > | < STARASSIGN: "*=" > | < SLASHASSIGN: "/=" > | < ANDASSIGN: "&=" > | < ORASSIGN: "|=" > | < XORASSIGN: "^=" > | < REMASSIGN: "%=" > | < LSHIFTASSIGN: "<<=" > | < RSIGNEDSHIFTASSIGN: ">>=" > | < RUNSIGNEDSHIFTASSIGN: ">>>=" > }

  13. CompilationUnit void CompilationUnit() : { } { [ PackageDeclaration() ] ( ImportDeclaration() )* ( TypeDeclaration() )* <EOF> } What is the smallest legal Java program?

  14. Declarations in jj void PackageDeclaration() : { } { "package" Name() ";" } void ImportDeclaration() : { } { "import" Name() [ "." "*" ] ";" } // Eg, import java.io.*; void TypeDeclaration() : { } { LOOKAHEAD( ( "abstract" | "final" | "public" )* "class" ) ClassDeclaration() | InterfaceDeclaration() | ";" } void ClassDeclaration() : { } { ( "abstract" | "final" | "public" )* "class" <IDENTIFIER> [ "extends" Name() ] [ "implements" NameList() ] "{" ( ClassBodyDeclaration() )* "}" }

  15. extends vs. implements • extends • the new class extends a superclass • automatically inherits all of the superclass's methods • override any of them (except the ones defined "final") • implements • implements an interface • the class must override all of the interface's methods, since the interface contains only definitions, not code.

More Related