Showing posts with label java lexems. Show all posts
Showing posts with label java lexems. Show all posts

Wednesday, December 28, 2016

Tokens in language fundamentals in oracle dbms

1. Tokens: 

Any logical unit in java programming is called as Lexeme.

The collection of Lexeme come under a particular group called as "Tokens".
Lexeme and tokens



Q. Find the no of lexemes & tokens in following expression?
int a = b + c *d;

Ans: int,a,=,b,=,+,*,d,; --------> 9 lexeme
int ----------------> data type
a,b,c,d ------------> Variables
=,+,* --------------> operator
; ------------------> special symbol/ terminator

Tokens ---------------> 4 types of token.
------------------------------------------------------------------------------------------

To prepare java application, java has provided the following tokens:
1. Identifiers
2. Literals
3. Keywords/reserved words
4. operators

1. Identifiers:

-------------------
Identifier is a name provided to the programming elements like variables, methods, classes, interfaces.....

To provide identifiers in java program, java has provided the following rules & regulations.

A. Identifiers must not be started with a number, Identifiers may start with an alphabet, _ symbol, $          symbol but subsequent symbols may be a number, an alphabet, _ symbol, $ symbol.

EX: String 9eid = "err";----------------> invalid
String eid = "err-1";---------------> valid
String emp9Id = "err891";---------------> valid
float $esal =   6932145f;---------------> valid
String _eaddr = "Hyd";---------------> valid
String emp_Name = "bali";---------------> valid
--------------

B. Identifiers are not allowing all operators & all special symbol except _ and $ symbol.
EX: String emp.Name = "bali" ----------> invalid
String emp-Name = "bali" ----------> invalid
String emp_Name = "bali" ----------> valid
String emp$Name = "bali" ----------> valid
String emp+Name = "bali" ----------> invalid
String emp@Name = "bali" ----------> invalid
String _$_emp_$_$_Name = "bali" ----------> valid
---------------------------

C. Identifiers are not allowing spaces in the middle.
EX: forName(--); ---------> Valid
for Name(--); ---------> invalid
getInputStream(-); ----> valid
get Input Stream (-); ------> Invalid
---------------------

D. Identifiers must not be duplicated within the same scope, identifiers may be duplicated in two             different scopes.
EX:
class A
{
int i = 10;
short i = 20;-------->error
boolean f = true;
void m1()
{
float f = 23.4f -----> no error
double f = 2850; -----> error
long i = 20; ---------> no error
System.out.println(i); ------> print local variable
System.out.println(this.i); -----> print class level variable
}
}