I'm writing a flex/bison program that involves asking the user for a multiple of things, one of which would be an int which would indicate a spot in an array to acsess. I am able to recognize when its an int, but I need the specific value that is entered put into a variable so I can use it. I tried $$, $1, and so forth but it says its undecalred variable. is there something I need to include for them?
my code to recognize and int
[0-9]+(\.[0-9]+)?(e[+-]?[0-9]+(\.[0-9]+)?)?
6 replies to this topic
#1
Posted 01 May 2010 - 03:53 PM
|
|
|
#2
Posted 01 May 2010 - 07:18 PM
double value;
%%
[0-9]+(\.[0-9]+)?(e[+-]?[0-9]+(\.[0-9]+)?)? {
// write you code to convert yytext to its double represention here
value = to_double( yytext ); // yytext contains the text of the float value
// that has been recognized. to_double is to be define by you
// and suppose you have a double value in global scope.
}
%%
%%
[0-9]+(\.[0-9]+)?(e[+-]?[0-9]+(\.[0-9]+)?)? {
// write you code to convert yytext to its double represention here
value = to_double( yytext ); // yytext contains the text of the float value
// that has been recognized. to_double is to be define by you
// and suppose you have a double value in global scope.
}
%%
#3
Posted 02 May 2010 - 08:04 AM
Undefined symbols:
"_to_double", referenced from:
_yylex in ccGRo4nZ.o
ID: symbol(s) not found
collect2: Id returned 1 exit status
if it would help I could put the array acsess at the end and just give a kill at the end of my other conditions and I would then be able to return the value itself rather than the DECNUM I currently use to identify the course of action to be taken
"_to_double", referenced from:
_yylex in ccGRo4nZ.o
ID: symbol(s) not found
collect2: Id returned 1 exit status
if it would help I could put the array acsess at the end and just give a kill at the end of my other conditions and I would then be able to return the value itself rather than the DECNUM I currently use to identify the course of action to be taken
#4
Posted 02 May 2010 - 02:41 PM
Sorry, probably I should be more specific.
The string you specific and thus recognized by the parser is pointed by yytext as a NULL TERMINATED ASCII string. (C-string) You can printed out like:
But if you want to make use of the value of the input float point number, you need to convert it to a float or double. You should have noticed that in the comment I wrote "write your code to ....", that's something to be done by you, or maybe the libary function 'atof' might be of some help to you.
The string you specific and thus recognized by the parser is pointed by yytext as a NULL TERMINATED ASCII string. (C-string) You can printed out like:
double value;
%%
[0-9]+(\.[0-9]+)?(e[+-]?[0-9]+(\.[0-9]+)?)? {
// write your code to convert yytext to its double represention here
// value = to_double( yytext ); // yytext contains the text of the float value
// that has been recognized. to_double is to be define by you
// and suppose you have a double value in global scope.
printf("A float point number is recognized: %s\n", yytext);
}
But if you want to make use of the value of the input float point number, you need to convert it to a float or double. You should have noticed that in the comment I wrote "write your code to ....", that's something to be done by you, or maybe the libary function 'atof' might be of some help to you.
#5
Posted 02 May 2010 - 05:18 PM
double value;
%%
[0-9]+(\.[0-9]+)?(e[+-]?[0-9]+(\.[0-9]+)?)? {
value = to_double( yytext );
return DECNUM;
}
yes, this is exactly what I wrote (DECNUM indicates I got a number and I should deal with as such, not all that nessesary), and I got the error Undefined symbols:
"_to_double", referenced from:
_yylex in ccGRo4nZ.o
ID: symbol(s) not found
collect2: Id returned 1 exit status
what I believe that means is that to_double needs to be included at the top in some library, so if you know what library that is would be helpful, or some other way to deal with the problem. I need that specific value (and subsequent values) that the use entered (say 3) placed in a value such that I can say array[value] and have it give me the value in array[3] or whatever the user entered.
#6
Posted 02 May 2010 - 06:08 PM
There is no such library function as to_double, you need to implemented it yourself!
Or change it for atof, see if it works for you.
Or change it for atof, see if it works for you.
#7
Posted 02 May 2010 - 06:46 PM
thank you kindly. sorry I didn't understand about to_double. used atof and worked fine.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









