Skip to content

Conversation

@satouriko
Copy link

@satouriko satouriko commented Oct 26, 2021

C code that contains " doesn't compile,
Example: https://paste.gnome.org/pxirr2vvf

image

instruction = line;
def << "source = \"" << instruction << "\";" << std::endl;
continue;
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know what these codes are used for.

@satouriko
Copy link
Author

satouriko commented Oct 26, 2021

Note that this proposed fix is just a compromise that fixes the case that C code with " and \ doesn't compile.

In general I don't think the code should be generated like this, line by line, scanning for specific strings, and outputting trivial string combinations. A lot of legal C code will break it, For example,

printf("DigitalWrite_High(");

It doesn't work if a code doesn't organize as one statement per line, but also valid C code,

DigitalWrite_High(1); Delay(5000); DigitalWrite_Low(1);

or

DigitalWrite_High(
    1);
Delay(
    5000);
DigitalWrite_Low(
    1);

Here are 2 possible ways to essentially solve the problem,

  1. Rewrite the API_Generator. Make the built-in function declaration and implementations separated from the user's code. Carefully process the user's code to make sure it escapes correctly. Do not touch the user's code.
  2. Define a new language, like C but not C, with specific details about the grammar. Add restrictions and document them, like keywords, or one statement must lie under one line, not able to output strings like "DigitalWrite_High(" or even not able to use quotes.

I don't think 2 is what we want, so I would suggest 1.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant