Discussion about jeb's batch parsing rules on StackOverflow
Posted: 25 Jan 2018 14:43
The purpose of this thread is to have a central place to discuss the batch parsing rules on StackOverflow that jeb initiated.
Of particular interest are discussions about shortcomings or inaccuracies of the current model, along with suggestions for improvements.
I've already made a great many changes to the original posted rules. But there is still room for improvement.
There are already a number of DosTips threads that investigate various aspects of this topic. At some point I may add links to those topics. But I hope future discussion always takes place here.
Currently there are two issues that I am thinking about:
1) Should phases 3 and 4 be reversed?
The echoing of parsed commands (phase 3) occurs at two points: after the initial round of phase 2 (main parser), and then again after each round of phase 4 (FOR variable expansion for each DO iteration).
I think the logic would be much simpler to describe if the order of phases 3 and 4 were reversed. But I am reluctant to renumber the phases for fear of breaking phase references in historical posts.
What do you think jeb
2) I think phase 7 (command execution) needs some refinement
I greatly expanded phase 7. But I see a potential problem, and I'm not sure how to correct it.
Sometimes a command can be both an internal command and an external command. For example, creation of an ECHO.BAT file.
Clearly the parser generally selects the internal command over the external command in phase 7.
Assuming ECHO.BAT exists in the current folder, then ECHO OK will print OK (execute the internal command) instead of executing the ECHO.BAT.
The CALL rules in phase 6 already account for the fact that CALL ECHO will call the batch script instead, because phase 6 identifies the batch script before phase 7 has a chance to execute the internal command.
Also supporting the existing rules, if I have TEST.BAT in the current folder, then when I execute ECHO\..\TEST, it simply prints out ..\TEST
But I am disturbed by ECHO\..\TEST.BAT - it executes the batch script instead
Also, ECHO.BAT will execute the batch script instead of the internal command.
I'm struggling to find a set of simple rules that can account for the differences.
Dave Benham
Of particular interest are discussions about shortcomings or inaccuracies of the current model, along with suggestions for improvements.
I've already made a great many changes to the original posted rules. But there is still room for improvement.
There are already a number of DosTips threads that investigate various aspects of this topic. At some point I may add links to those topics. But I hope future discussion always takes place here.
Currently there are two issues that I am thinking about:
1) Should phases 3 and 4 be reversed?
The echoing of parsed commands (phase 3) occurs at two points: after the initial round of phase 2 (main parser), and then again after each round of phase 4 (FOR variable expansion for each DO iteration).
I think the logic would be much simpler to describe if the order of phases 3 and 4 were reversed. But I am reluctant to renumber the phases for fear of breaking phase references in historical posts.
What do you think jeb
![Question :?:](./images/smilies/icon_question.gif)
2) I think phase 7 (command execution) needs some refinement
I greatly expanded phase 7. But I see a potential problem, and I'm not sure how to correct it.
Sometimes a command can be both an internal command and an external command. For example, creation of an ECHO.BAT file.
Clearly the parser generally selects the internal command over the external command in phase 7.
Assuming ECHO.BAT exists in the current folder, then ECHO OK will print OK (execute the internal command) instead of executing the ECHO.BAT.
The CALL rules in phase 6 already account for the fact that CALL ECHO will call the batch script instead, because phase 6 identifies the batch script before phase 7 has a chance to execute the internal command.
Also supporting the existing rules, if I have TEST.BAT in the current folder, then when I execute ECHO\..\TEST, it simply prints out ..\TEST
But I am disturbed by ECHO\..\TEST.BAT - it executes the batch script instead
![Exclamation :!:](./images/smilies/icon_exclaim.gif)
![Evil or Very Mad :evil:](./images/smilies/icon_evil.gif)
Also, ECHO.BAT will execute the batch script instead of the internal command.
I'm struggling to find a set of simple rules that can account for the differences.
Dave Benham