Wednesday, December 16, 2009

Lexical Analysis

Lexical Analysis

It have 4 type :
1. Number
2. Identifier
3. Operator
4. Parenthsis

Each of type have our rule

Nubmer :
It must have only 0 - 9 and e or E. And it can been minus valus

E or e are show the power of number such as 3e4 is 3x10^4

Indentifier :
It have a special rule.
1. It must begin by a - z , A - z or _
2. Next charactor can been a - z , A - z , 0 - 9 and _
3. It mustn't reserved word.
4. And don't have speacial charactor

Operator :

Operator Name --> Operators
Unary : ++ -- + - ! ~ & *
Multiplicative : * / %
Additive : + -
Bitwise Shift : << >>
Relational : < > <= >=
Equality : == !=
Bitwise AND : &
Bitwise Exclusive : OR ^
Bitwise Inclusive : OR |
Logical AND : &&
Logical OR : ||
Conditional : ? :
Assignment : = += -= *= /= <<= >>= %= &= ^= |=
Comma / Semi-Colon : , ;


Parenthsis :

It must have 6 form, are ( , ) , [ , ] , { , } .


Now, You know the rule all the type. I will show how to lexical analysis.

I think, it have 4 step
1. Push all the data into the stack
2. Pop the data and token the data by byte and push it to the stack
3. You have the data by byte in the stack
4. Pop the data to analysis

Finally, It have many method to analysis such as use the switch case or if , etc.