New answers tagged

6

I'm not going to debug your code, there's not enough context to do this anyway, but I'm going to show you an idiom that you will probably find easier to use correctly. As a bonus, it will also be faster. Have a look at your loop body. You are allocating memory during each iteration and free it under certain circumstances depending on the overall control ...


2

do you agree this is a good way of solving the problem? No. When you parse a shell command line, you work your way through the string, and so at any point you should already know whether you are inside quotes. Either because your parsing state machine is in some "between quotes" state, or because your recursive descent parser is in some "parse quoted ...


1

In principle, you could use something like your isBetweenQuotes function, but you're (probably) better served by a more structured way of parsing arguments pipelines. However, something like the following might work: int isBetweenQuotes(int pos, char *str) { return IBQplain(pos, str, 0); } int IBQplain(int pos, char *str, int offset) { char ch; ...


1

I think that between compound lists (which involve parenthesized expressions) and various operators (like |, && and ||, ...) the shell grammar is fundamentally recursive in nature, so yes, you should consider recursion up front. There are many ways to parse language, but for this grammar, any way you do it your parser needs to handle recursive ...



Top 50 recent answers are included