I'm working on the command parser for my Air Traffic Control sim. I have not written a parser in this sense before.
The parser takes input from the user, and parses it into meaningful instructions to pass to an aircraft. It emulates a unified "ear" for the pilots of all the aircraft. It deals with a limited range of input. Grammar will be strictly enforced. Arguments will be separated by spaces. As an outline to the simple parsing I need to do, there is a standard for ATC sims which I will be following: ABC#### C NN - 2 digits is an altitude in thousands of feet ABC#### C NN X - the X modifier expedites the altitude change (where possible/reasonable) ABC#### C NNN - 3 digits is a heading in degrees ABC#### C NNN L (or R) - where a course change follows the shortest turn, L or R modifier makes the turn direction explicit ABC#### C $$$ - where a valid beacon is given, the aircraft will fly to that beacon ABC#### S NNN - change speed to... ABC#### L XXX - cleared to land on runway XXX (eg: 14L) ABC#### T - clearance to take off (an altitude must be set first As there are a maximum ten slots (thus ten aircraft) I will allow the shortcut that keys 1 thru 0 will auto enter the flight number for that slot, with a space appended. The sim continues during data entry so this is faster, but I will also allow manual typing of flight numbers. Are there any established principles of parsing that I should adhere to? I am debating where to make this a procedure or a function. I'd like to keep it sleek. I'd also like, as parsed, that it creates the string for the pilot's response as it goes and if at some point the parsing fails, I can reset the string to "Huh?" or something more helpful from the "pilot"... Discussion/ideas/snippets welcomed. Dave *For the purposes of this thread, my program is open-source (duh!) and I will happily share my code here. I will not, however, use anyone else's code without their explicit permission and agreement to have their code included within the sim as open-source. The assumption is I won't use your code. If it's key to the project, I may use the principle, but I would not use the code without the explicit permission above.* _______________________________________________ QL-Users Mailing List http://www.q-v-d.demon.co.uk/smsqe.htm