2.5. Literals

Figure 2.6. Concrete Syntax for Literals

[37] <lit> ::= <boolean-lit> | <char-lit> | (("+" | "-")? <int-lit> | <real-lit>) | <string-lit> | <null-lit>  
[38] <boolean-lit> ::= "true" | "false"  
[39] <char-lit> ::= "'" <char> "'"  
[40] <int-lit> ::= <dec> | <oct> | <hex>  
[41] <long-lit> ::= (<dec> | <oct> | <hex>) ['l', 'L']  
[42] <real-lit> ::= <float-lit> | <double-lit>  
[43] <float-lit> ::= <dec-digit>+ '.' <dec-digit>* <exponent>? ['f', 'F'] | '.' <dec-digit>+ <exponent>? ['f', 'F'] | <dec-digit>+ <exponent>? ['f', 'F'] | "NaNf" | "pINFf" | "nINFf"  
[44] <double-lit> ::= <dec-digit>+ '.' <dec-digit>* <exponent>? ['d', 'D']? | '.' <dec-digit>+ <exponent>? ['d', 'D']? | <dec-digit>+ <exponent>? ['d', 'D']? | "NaNd" | "pINFd" | "nINFd"  
[45] <string-lit> ::= '"' <char>* '"'  
[46] <null-lit> ::= "null"  
[47] <char> ::= -[''','\\', '\n','\r'] | ('\\' (['n','t','b','r','f', '\\',''','"'] | <oct-digit> <oct-digit>? | <zero-three-digit> <oct-digit> <oct-digit>))  
[48] <dec> ::= <one-nine-digit> <dec-digit>  
[49] <oct> ::= '0' <oct-digit>*  
[50] <hex> ::= '0' ('x' | 'X') <hex-digit>+  
[51] <oct-digit> ::= ['0'-'7']  
[52] <zero-three-digit> ::= ['0'-'3']  
[53] <dec-digit> ::= ['0'-'9']  
[54] <one-nine-digit> ::= ['1'-'9']  
[55] <hex-digit> ::= ['1'-'9', 'a'-'f', 'A'-'F']  
[56] <exponent> ::= ['e','E'] ['+','-']? <dec-digit>+  

Figure 2.6, “Concrete Syntax for Literals” presents the lexical definitions for BIR literals. The literals are syntactic representation of BIR values. BIR does not have a dedicated type for characters, instead, the int type is used. Note that unicode escape characters are not shown. A unicode pre-processor is used to convert unicode escape characters to the corresponding unicode characters.

Examples. 

Abstract Syntax Tree. 

Figure 2.7. Java AST for Literal

Java AST for Literal
[ .gif, .svg ]

The top level Java AST class for BIR literal is Literal. The boolean, character, int, long, float, double, string, and null literals Java AST classes are the BooleanLiteral class, the IntLiteral class, the IntLiteral class, the LongLiteral class, the FloatLiteral class, the DoubleLiteral class, the StringLiteral class, and the NullLiteral class, respectively.