Recognition of Tokens

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 7

Regular Expressions

Regular expression is a sequence of characters or algebric way of


representing regular language.we can represent regular expression
using regular set.
Regular Expression (RE) is defined as
• Epsilon is RE corresponding to the language L={ε }
• Pie is RE corresponding to the language L={}
• x is RE corresponding to the language L={x}
• If r1 is RE over language L(r1)
r2 is RE over language L(r2)
• r1+r2 is a RE corresponding to L(r1)UL(r2) where
L(r1Ur2)=L(r1)UL(r2)
• r1r2 is a RE correponding to L(r1).L(r2) where L(r1.r2)=L(r1).L(r2)
• R* is RE corresponding to L(R*)=(L(R*))
• R+ is a RE corresponding to L(R+)=(L(R+))

40
Recognition of Tokens

• Lexical analyzer reads the source program


charcter by character and produces a stream
of tokens.
• The token may be an identifier,a variable, a
operator,a constant or a keyword.
• In order to specify the tokens we use
“Regular Expressions”.
• We have to recognize the tokens with the
help of “Transition Diagrams”.
• Recognization of tokens is done to seperate
out different tokens.
Recognition of Tokens

We have certain Regular Expressions such as

 if --> if
 then --> then
 else --> else
 relop --> <, <=, >, >=, =, <>(not equal to)
 id --> letter(letter/digit)*
 num --> digit+(.digit+)?(E[+/-]?digit+)?
 delimiter --> blank/tab/newline
Recognition of Tokens

1.Recognition of identifiers
2.Recognition of delimiters
3.Recognition of keywords
4.Recognition of relational operators
5.Recognition of numbers
Recognition of Tokens

Regular Expression Tokens Attribute values


if if -
then then -
else else -
id id pointer to symbol
table only
num num pointer to symbol
table only
< relop LT
<= relop LE
> relop GT
>= relop GE
<> relop NE
Recognition of Tokens

Recognization of Relational Operators(relop)


Recognition of Tokens

Recognition of numbers

You might also like