This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Front-end Closures
- From: Philip Herron <redbrain at gcc dot gnu dot org>
- To: GCC <gcc-help at gcc dot gnu dot org>
- Date: Thu, 6 Feb 2014 12:14:57 +0000
- Subject: Front-end Closures
- Authentication-results: sourceware.org; auth=none
Hey all
In rust you can do the following:
fn main () {
let item = "test";
let price =
if item == "salad" {
3.50
} else if item == "muffin" {
2.25
} else {
2.00
};
}
I am trying to understand what way i could compile this in GCC can you
do the following in GENERIC make a nested function decl kind of like a
closure not quite sure what to do here. I've been using bison to parse
rust so far but its getting really painful now for this kind of syntax
i am hoping a glr parser might do it (avoiding being a real man and
writing a parser by hand untill i have more stuff working).
void main (void) {
const char * item = "test";
double priceClousure (void) {
double ret_tmp;
if (item == "salad") {
ret_tmp = 3.50;
}
else if (item == "muffin") {
ret_tmp = 2.25;
}
else {
ret_tmp = 2.00;
}
return ret_tmp;
}
const double price = priceClousure ();
}
Thanks
--Phil