Java Reference
In-Depth Information
Exercises
1. Assume the following text is presented to a C scanner:
main(){
const float payment = 384.00;
float bal;
int month = 0;
bal=15000;
while (bal>0){
printf("Month: %2d Balance: %10.2f\n", month, bal);
bal=bal-payment+0.015*bal;
month=month+1;
}
}
What token sequence is produced? For which tokens must extra infor-
mation be returned in addition to the token code?
2. How many lexical errors (if any) appear in the following C program?
How should each error be handled by the scanner?
main(){
if(1<2.)a=1.0else a=1.0e-n;
subr('aa',"aaaaaa
aaaaaa");
/* That's all
}
3. Write regular expressions that define the strings recognized by the FAs
in Figure 3.33 on page 107.
4. Write DFAs that recognize the tokens defined by the following regular
expressions:
( bc ) d ) +
(a) ( a |
3) + )
1) (2
(b) ((0
|
|
|
0011
(c) ( a Not( a )) aaa
 
 
Search WWH ::




Custom Search