You are on page 1of 1

Here is a code for testing how lexical analyzer should work

class Lexer {
static boolean isPrime ( int c ) // Returns true if c is prime.
{
if ( c % 2 == 0 )
return false ;
String s = " This is an invalid string literal ///error
int 9R ;
R = 3 ;
while ( R != c )
{
if ( c % R == 0 )
return false ;
R = R + 8 ;
}
String s = "This is a useless string literal" ;
return true ;
}

static int gcd ( int a , int b )


{

int m ;
int &ab45 ; ///error
m = b % a ;
if ( m == 0 )
return a ;
else
return gcd ( m , a ) ;
}

static int fibonacci ( int n ) // Find n-th Fibonacci number.


{
if ( ( n == 1 ) || ( n == 2 ) )
return 1 ;
else
return fibonacci ( n - 1 ) + fibonacci ( n - 2 ) ;
}

static float average ( int n1 , int n2 , int n3 )


{
/* Find sum
and retrun sum */
float sum = n1 + n2 + n3 ;
return sum / 3.0 ;
}
}

give the result that we expect

You might also like