Subj : Re: File Syntax checking: need logical help To : comp.programming From : =?iso-8859-1?q?C=E9dric_LEMAIRE?= Date : Tue Aug 02 2005 02:27 am Use a parser generator to describe your file structure. Example with CodeWorker, an open source parsing tool and code generator freely available at "http://www.codeworker.org": file_structure ::= #continue A; A ::= /*BNF sequence for what is specific to A*/ #continue B H; B ::= /*BNF sequence for what is specific to B*/ #continue C E F G; C ::= /*BNF sequence for what is specific to C*/ #continue [[C1 | C2 | C3] C]? [D]?; D ::= /*BNF sequence for what is specific to D*/; E ::= [E1 &| E2] | E3; E1 ::= /*BNF sequence for what is specific to E1*/; E2 ::= /*BNF sequence for what is specific to E2*/; E3 ::= /*BNF sequence for what is specific to E3*/; F ::= /*BNF sequence for what is specific to F*/; G ::= /*BNF sequence for what is specific to G*/; H ::= /*BNF sequence for what is specific to H*/; This is an extended-BNF script you have to execute with the CodeWorker procedure parseAsBNF(). '#continue' means that the rest of the BNF sequence must match the input file (similar to your 'mandatory', but placed according to another logic). The comment /*BNF sequence for what is specific to ...*/ might contain: - the reading of a fixed record: [#readChar]10 // for a length of .... 10! - the reading of a variable length: #readChars(my_length) - the reading of some usual tokens: #readInteger, #readCString, #readIdentifier ... - a jump to a particular pattern: ->P // read up to encountering and consuming P - a combination (sequences, alternatives) of them, - ... Note about E ::= [E1 &| E2] | E3: the operator 'A &| B' means 'A | A B | B' in CodeWorker (A and/or B). .