Discussion:
A3P1
(too old to reply)
Dan
2004-06-09 01:37:11 UTC
Permalink
Hi,

I've been looking at the assignment and have seen two ways to do it - one
way uses three states plus an error state, and the other is about 8 states
(the numbers are very approximate). In order for the three state system to
work, it is necessary to do some major error checking in the code block of
one of the states. So, I guess my question boils down to: How much code
are we allowed to add to a state? Can we have items such as this:

int base;

<State> [0-9] {
base = base*10 +yytext();
if (base > 36 || base < 2){
Yynext(Error);
} else {
//Do other code
}
}

Or is this too much code in a state?

Thanks,
Dan
Troy Mark Gonsalves
2004-06-09 20:47:04 UTC
Permalink
This should have been emailed to me instead of posted...Luckily, the code
you have below is not an acceptable solution.
Post by Dan
int base;
<State> [0-9] {
base = base*10 +yytext();
if (base > 36 || base < 2){
Yynext(Error);
} else {
//Do other code
}
}
Or is this too much code in a state?
For others who try to understand this code note that it is pseudocode...it
won't compile.

Anyway, it's not the quantity of code that's a problem, it's the fact that
you're using an accummulated value (base) to make a decision as to which
state to go to next. You are only allowed to use the current character
of input to make this decision. You could convert the current character to
a number then use that number to make your decision, but you don't need
to do that to compute the base.

Loading...