3 ms·
Your grammar requires a special token '{', so the parser can recognize the start of the sql statement. Likewise '}' for the end. I'm not sure, whether you can d
by beza1e1 16y ago
Your grammar requires a special token '{', so the parser can recognize the start of the sql statement. Likewise '}' for the end. I'm not sure, whether you can drop that and what the consequence are. You're certainly not linear anymore. It might be that the introduction of such special tokens is the "hack" required for embedding grammars into each other.
Note that '{' '}' is a bad choice. For example, "x = {select * from ;};" is perfectly fine C code under the assumption that there is a type 'select'.
- qixxiq 16y agoI don't believe that is valid C code; you can't assign a variable to a block.
- beza1e1 16y agoOk, i should have tried it. It does not work with a declaration. However, this code compiles just fine: int main(void) { int select = 6, from = 2; int x = {select * from}; printf("%d\n",x); // prints 12 return 0; } gcc and clang only complain the missing include for printf. cparser (which i'm working on) prints "warning: extra curly braces around scalar initializer".
- jerf 16y agoI was just copying from the post. It's not exactly how I would do it but I thought doing what I thought should be done would just distract the problem. One way or another you need some sort of delimiter, in the sense of delimiting the grammar domains, be it a explicit delimiter like a character (pair) or an implicit one like trying to guess which subgrammar you're trying to use. In the case of smashing two grammars together I would tend to prefer an explicit delimiter, because it lowers the need to coordinate between the two grammars, a difficulty that you demonstrated there.