Skip to content

peterzaccha/lexical-analyzer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lexical-analyzer

Using Regex

Usage

python main.py 'test.c'

//test.c
bool isPowerOfTwo(int x)
{
    // First x in the below expression is
    // for the case when x is 0
    return x && (!(x & (x - 1)));
}

Output

<SINGLE_COMMENT> : //test.c
<BOOL> : bool
<ID> : isPowerOfTwo
<LEFT_ROUND_B> : (
<INT> : int 
<ID> : x
<RIGHT_ROUND_B> : )
<LEFT_CURLY_B> : {
<SINGLE_COMMENT> : // First x in the below expression is
<SINGLE_COMMENT> : // for the case when x is 0
<RETURN> : return
<ID> : x
<AND> : &&
<LEFT_ROUND_B> : (
<NOT> : !
<LEFT_ROUND_B> : (
<ID> : x
<BITWISE_AND> : &
<LEFT_ROUND_B> : (
<ID> : x
<MINUS> : -
<INTEGRAL_LITERAL> : 1
<RIGHT_ROUND_B> : )
<RIGHT_ROUND_B> : )
<RIGHT_ROUND_B> : )
<SEMICOLON> : ;
<RIGHT_CURLY_B> : }

About

lexical analyzer implementation using regex

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published