|
|
|
|
||
|
DEFINITION MODULE SymCompare; (******************************************************************* Module SymCompare (Version 1.0) Copyright (c) 2001-2006 by Dimitrios Gyalistras, Andreas Fischlin and ETH Zurich. Purpose Line-by-line comparison of the symbols found in two text files. Remarks -- Programming o Design Dimitrios Gyalistras 08/01/2001 Andreas Fischlin 27/06/2002 o Implementation Dimitrios Gyalistras 10/01/2001 Andreas Fischlin 27/06/2002 ETH Zurich Systems Ecology CHN E 35.1 Universitaetstrasse 16 8092 Zurich SWITZERLAND URLs: <mailto:RAMSES@env.ethz.ch> <http://www.sysecol.ethz.ch> <http://www.sysecol.ethz.ch/SimSoftware/RAMSES> Last revision of definition: 09/04/2005 AF *******************************************************************) IMPORT Errors; (**************************************) (*##### General declarations #####*) (**************************************) CONST (* result codes returned *) allOk = Errors.allOk; notDone = Errors.onlyAnInsert; CONST nul = 0; (* a bad file or number syntax or an overflow occurred *) eodSym = 1; (* end of data or of file reached *) unknownIdent = 2; (* token has syntax of an identifier, but is not in the symbol table*) integerSym = 3; (* an integer number *) longIntSym = 4; (* a long integer number *) longCardSym = 5; (* a long cardinal number *) realSym = 6; (* a real number *) longRealSym = 7; (* a long real number *) strSym = 8; (* a string *) specialCharSym = 9; (* a non-"white space" character, given that none of the above symbols can be returned *) TYPE Symbol = [nul..specialCharSym]; (* identifier EBNF: ident = letter {letter | digit | "_"}. string EBNF: string = "'" {character} "'" | '"' {character} '"'. for accepted number EBNFs see module DMConversions *) CONST f1 = 1; f2 = 2; TYPE InputFile = [f1..f2]; (*****************************************) (*##### Handling of Input FIles #####*) (*****************************************) PROCEDURE PrepFile( f : InputFile; fName : ARRAY OF CHAR; VAR resCode : INTEGER; VAR errTxt : ARRAY OF CHAR ); (* Prepares/opens the respective input file for scanning and, possibly, comparison with the other input file. Note, the two input files can be processed totally independently of each other. In particular, it is possible to use this module to scan but one file at a time. *) PROCEDURE GetFileName( f : InputFile; VAR fName : ARRAY OF CHAR ); (* Returns the name of the respective input file *) PROCEDURE StopReadingFile( f: InputFile ); (* Stops reading the respective input file. *) PROCEDURE SetNumOverflowTolerance ( tolIOvrflw, tolROvrflw: BOOLEAN); PROCEDURE GetNumOverflowTolerance (VAR tolIOvrflw, tolROvrflw: BOOLEAN); (* tolerance of numeric overflows for integer and real numbers. By default overflow is not tolerated. *) PROCEDURE SetNumberTreatment( allIntLongInt, allRealLongReal: BOOLEAN); PROCEDURE GetNumberTreatment(VAR allIntLongInt, allRealLongReal: BOOLEAN); (* Set mode for the treatment of numbers. If allIntLongInt is TRUE, all negative integer numbers are treated as long integers and all positive integer numbers as long cardinals. If allRealLongReal is TRUE, all real numbers are treated as long real numbers. Default is: allIntLongInt = TRUE, allRealLongReal = TRUE. *) (*******************************************************) (*##### Reading and comparison of input files #####*) (*******************************************************) PROCEDURE ReadLine( f : InputFile; VAR eof : BOOLEAN; VAR resCode : INTEGER; VAR errTxt : ARRAY OF CHAR ); (* Reads a new line from the respective input file. Parameter "eof" is returned true if the end of the file was reached after having read the line. *) PROCEDURE TokenNr( f : InputFile; token : ARRAY OF CHAR ): INTEGER; (* Returns the number of the first occurrence of token "token" in the current line if such a token exists, otherwise 0. This procedure may be used to test whether a given ident occurs in the current line prior to calling the procedure "AdvanceToToken". *) PROCEDURE TokenNrV( f : InputFile; VAR token : ARRAY OF CHAR ): INTEGER; (* VAR for speed-up only *) (* Same as TokenNr. *) PROCEDURE AdvanceToToken( f : InputFile; token : ARRAY OF CHAR; VAR found : BOOLEAN; VAR eof : BOOLEAN; VAR resCode : INTEGER; VAR errTxt : ARRAY OF CHAR ); (* Reads from the respective input file as many lines as needed until the token "token" occurs somewhere in the current line. Parameter "eof" is returned true if the end of the file was reached without that the identifier could be found. *) PROCEDURE CurLinesAreIdentical(): BOOLEAN; (* Returns TRUE if the currently considered lines from the two input files contain exactly the same tokens. *) PROCEDURE CurLinesHaveSameSyntax(): BOOLEAN; (* Returns TRUE if the currently considered lines have the same syntax. Note, this imples only equality of the types of tokens, not of the tokens themselves. *) PROCEDURE TokensAreIdentical( tNr1, tNr2: INTEGER ): BOOLEAN; (* Returns TRUE if tokens "tNr1" and "tNr2" from the two currently considered lines are identical. *) (***************************************) (*##### Information retrieval #####*) (***************************************) PROCEDURE GetSymbolDescr( s: Symbol; VAR descr: ARRAY OF CHAR ); PROCEDURE GetSymbolShortDescr( s: Symbol; VAR sdescr: ARRAY OF CHAR ); (* Return descriptions of the symbols exported by this module. *) PROCEDURE CurLineNum( f: InputFile ): LONGINT; (* Returns the line number of the currently read line from input file "f". *) PROCEDURE CurNumTokens( f: InputFile ): INTEGER; (* Returns the number of tokens in the currently read line from input file "f". *) PROCEDURE GetToken( f: InputFile; tNr: INTEGER; VAR token: ARRAY OF CHAR ); (* Returns the token found at position "tNr" in the currently read line from input file "f". *) PROCEDURE Pos( f: InputFile; tNr: INTEGER ): INTEGER; (* Returns the character number (position) at which token "tNr" occurs in the currently read line from input file "f". *) PROCEDURE Sym( f: InputFile; tNr: INTEGER ): Symbol; (* Returns the symbolic meaning of the token "tNr" from the currently read line from input file "f". *) PROCEDURE LI( f: InputFile; tNr: INTEGER ): LONGINT; (* Returns the respective long integer number, if token "tNr" from the currently read line of input file "f" is of type INTEGER or LONGINT. *) PROCEDURE LC( f: InputFile; tNr: INTEGER ): LONGCARD; (* Returns the respective long cardinal number, if token "tNr" from the currently read line of input file "f" is of type positive INTEGER, positive LONGINT, or LONGCARD. *) PROCEDURE LR( f: InputFile; tNr: INTEGER ): LONGREAL; (* Returns the respective longreal number, if token "tNr" from the currently read line of input file "f" is of type REAL or LONGREAL. *) TYPE EOLCoding = (m2, mac, unix, dos); PROCEDURE SetEOLHandling (eolc: EOLCoding); PROCEDURE GetEOLHandling (VAR eolc: EOLCoding); (* Use routine SetEOLHandling to force a particular end-of-line (EOL) encoding. Initially the encoding is set in a platform specific manner (MacOS Classic - mac; Mac OS X - unix; Solaris - unix; IBM PC (Windows, DOS) - dos). Use GetEOLHandling to learn about current EOL handling (in case of inconsistencies between S1 and S2, the S1 settings are returned). *) END SymCompare.
|
||
|
|
|