Copyright © 2006 Gradiance Corporation.

 

 

     

Tokens

 

 



 

strings, tokens, and their description.

 


1.  

What are all the (a) prefixes (b) proper prefixes of the string abacabad? Identify one of these from the list below.

 

 

 

 a) 

ε is a prefix but not a proper prefix.

 

 b) 

abaca is a prefix and a proper prefix.

 

 c) 

abaca is a proper prefix, but not a prefix.

 

 d) 

baca is a prefix and a proper prefix.

 

 

 

 

 

2.  

Divide the following C code into tokens:

     float limitedSquare(x) float x {
         /* returns x-squared, but never more than 100 */
         return(x<=-10.0||x>=10.0)?100:x*x;
     }

Which of the following is NOT one of the tokens?

 

 

 

 a) 

? :

 

 b) 

{

 

 c) 

<=

 

 d) 

:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

3.  

Here is a simple Lex program:

/* regular definitions */
letter  [A-Za-z]
uletter [A-Z]
x       {uletter}+{letter}*
y       {letter}{uletter}
z       {letter}*
 
%%
 
{x}     {return(1);}
{y}     {return(2);}
{z}     {return(3);}

Suppose the input consists of a string of (upper- or lower-case) letters w followed by a nonletter (e.g., a blank). Determine for which values of w the Lex program above will return 1, will return 2, and will return 3. Then, select from the list below, a correct pair (w,i), where the program returns i when the input is w.

 

 

 

 a) 

(AB, 2)

 

 b) 

(Ab, 3)

 

 c) 

(aB, 2)

 

 d) 

(ABc, 3)