The parser only cares about the arguments of IF, FOR and REM. To the parser they are not commands but keywords. Each of them have their own parser: ParseIf, ParseFor and ParseRem. (It only recognizes "REM", "REM/?", "FOR", "FOR/?", "IF", "IF/?" as keywords. So something like "REM/ comment" is an ordinary command).penpen wrote: ↑09 Sep 2019 04:10I mean... what is unclear to me is, that i don't get why MS seems to have built a parser, that behaves differently depending on the command token, when splitting the command and argument string:
If the expected output of "REM One^\r\n Two^ Three^\r\n This is the comment\r\n" is the (command, argument) pair ("REM", " This is the comment\r\n"),
then i would expect any other command to behave the same, but "for One^\r\n Two^ Three^\r\n %%a in (1 2 3) do echo(%%~a" seems to work differently.
On the other hand, any other internal or external command will be parsed by a single function: ParseCmd which doesn't care about the contents or format the arguments or the command itself. The arguments will be processed at execution phase by the corresponding internal command's function or by the external process. It doesn't know/care if the command is internal or external, the type of command will be determined at execution phase. (Unlike FOR and IF, REM will be recognized at execution phase as an internal NOP command, so something like "REM/ comment" works, but it is slower than "REM comment").
The ParseFor function checks the first token to see if it contains "/?", if so sets the help flag otherwise checks that same token to see if it is one of the /L, /D, /F or /R switches otherwise it checks if it begins with %, otherwise calls PSError.
None of the parser functions which I've studied, uses exception handling, as no SEH prolog/epilog is present in the functions code. As you've guessed they used setjmp/longjmp. They used setjmp once in the parser's root function Parser, and used longjmp in PSError and PError functions but I don't see the relevance.penpen wrote: ↑09 Sep 2019 04:10Sidenote:
If i had to guess i would have said that they used setjmp and longjmp and lost track of what they are doing exactly..., but
it now seems more they did that the classic way (function calls only, which i would always prefer, except for try/catch) -
with some unexpected decisions (at least from my viewpoint).
Because you know (parts of) the code i would like to know if they used setjmp and longjmp outside any try/catch block?