c2lang / c2c_native

C2 Compiler - written in C2
Apache License 2.0
24 stars 5 forks source link

Floating point parsing error #3

Open tom-from-goss opened 1 year ago

tom-from-goss commented 1 year ago

The following code produces a syntax error

module hello;

import stdlib local;
import stdio as io;

func f32 add(f32 a, f32 b) {
    return a + b;
}

public func i32 main() {

    f32 c = add(1.1, 2);

    io.printf("The value of the first entry is %d\n", c);

    return 0;
}
main.c2:12:16: error: expected identifier
        f32 c = add(1.1, 2);
               ^

Changing 1.1 to 1.0 works

bvdberg commented 1 year ago

True, the native compile doesn't parse floats yes. If you need them I could speed up their implementation.

tom-from-goss commented 1 year ago

For the thing I want to build (an 8086 emulator) I don't think it's the most pressing issue but I think it's good for onboarding to the language.

Not sure if you're interested but https://github.com/lemire/fast_double_parser is a very fast float parser that I've used in the past.

bvdberg commented 1 year ago

I've pushed some commits with the first work on Floats, nothing final yet, but at least hello.c2 now parses. The c-generation is not done yet however. Parsing floats always seems trivial, but is definitely not. So the fast parser you mentioned will certainly help. Speed is good :)

tom-from-goss commented 1 year ago

Excellent, thanks Bas, i'll keep at eye on the repo for commits on this.

Cheers,

Tom