Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Causes an ambigious trigger when a previously declared integer variable gets assigned with a double/float data #6

Open
Shin-Aska opened this issue Sep 15, 2014 · 8 comments
Assignees

Comments

@Shin-Aska
Copy link
Owner

A python code such as this

a = 1000
a = 22.34

will generate this

/*******************************************************
        Code generated by s2sc.js
*******************************************************/

#include <stdbool.h>



typedef union {
    bool *boolValue;
    int *intValue;
    float *floatValue;
    double *doubleValue;
    char *charValue;
    void *voidValue;
} ambigious;

int main (void) {

    ambigious a;
    a.intValue = ( int * ) calloc(1, sizeof( int ) );
    (*a.intValue) = 1000;
    free(a.intValue);
    a.doubleValue = ( double * ) calloc(1, sizeof( double ) );
    (*a.doubleValue) = 22.34;
    return 0;
}

although the code generated is compilable, a better solution is that instead of triggering the ambigious flag, it just changes data types, since both double and int are compatible

int main (void) {

    double a = 1000;
    a = 22.34;
    return 0;
}
@theodorethompson
Copy link

Tried this scenario, this no longer triggers the ambiguous flag and instead the variable remains of int

/*******************************************************
        Code generated by s2sc.js
*******************************************************/



int main ( void ) {

    int a = 1000;
    a = 22.34;
    return 0;
}

even if i force it to trigger by adding

a = "222"

at the end of the code, what it will generate is this

/*******************************************************
        Code generated by s2sc.js
*******************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>



typedef union {
    bool *boolValue;
    int *intValue;
    float *floatValue;
    double *doubleValue;
    char *charValue;
    void *voidValue;
} ambiguous;

int main ( void ) {

    ambiguous a;
    a.intValue = ( int * ) calloc(1, sizeof( int ) );
    (*a.intValue) = 1000;
    (*a.intValue) = 22.34;
    free(a.intValue);
    a.charValue = ( char * ) calloc(2048, sizeof( char ) );
    sprintf(a.charValue, "%s", "222");
    return 0;
}

@Shin-Aska
Copy link
Owner Author

Ok, i'll work on that this week.

@Shin-Aska Shin-Aska self-assigned this Jan 26, 2015
@theodorethompson
Copy link

Nice, i think though that the parser.js should follow the BNF format, I noticed that it uses a similar syntax to BNF. Maybe we should add support for BNF or change everything to follow BNF for consistency.

@theodorethompson
Copy link

I'll try to help you with the documentation as well

@theodorethompson
Copy link

What does the gc.h header represent, is it a library?

@Shin-Aska
Copy link
Owner Author

Yes! it's a garbage collection library. I have my own compiled copy(from source) both in 64bit and 32bit but i can only send you that on weekends since i'm busy with work. Or you can do yourself a favor and compile (http://www.hboehm.info/) your own.

@Shin-Aska
Copy link
Owner Author

I'll also do the transidtion to BNF once i get back home

@theodorethompson
Copy link

Same same... ill probably do the documentation on Monday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants