This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Front-end Closures


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]