Unit FPScanner |
Renamed from Scanner.pas 6/20/1998 Paul Rice to avoid conflicts with others' work. Written by Frank Plagge Copyright (c) 1998 by Frank Plagge, Elsterweg 39, 38446 Wolfsburg, Germany All rights reserved Please send comments to plagge@positiv.escape.de V 1.01 - Jan 3rd, 1998 first implementation, never trust a version 1.00 :-) V 1.02 - Jan 12th, 1998 hexdecimals with the new token ttHexDecimal added the hex numbers are defined like C e.g. 0x12AB or like Pascal e.g. $12AB the state machine is extended by states 13, 14, 15 and 16 ***************************************************************************** Permission to use, copy, modify, and distribute this software and its documentation without fee for any purpose is hereby granted, provided that the above copyright notice appears on all copies and that both that copyright notice and this permission notice appear in all supporting documentation. NO REPRESENTATIONS ARE MADE ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. NEITHER FRANK PLAGGE OR ANY OTHER PERSON SHALL BE LIABLE FOR ANY DAMAGES SUFFERED BY THE USE OF THIS SOFTWARE. ***************************************************************************** description: This module contains the component TScanner. It contains the complete lexical analysis of an ascii file. This is a necessary basis to realize a parser for any language. Ths analysis of an ascii file produces a stream of token. properties and events at design time and runtime: property AllowIdentifier: Boolean -- default: true if this property is true, every identifier which is not a keyword will result a ttIdentifier token. if this property is false every non keyword identifier will cause a ttError token property CommentLine: string -- default: '//' this property contains the leading char for a comment. every comment is introduced with this string and is ended by the end of line property Filename: string -- default: '' this property contains the filename for the source file to analyze with the method analyze property Keywords: TStringList -- default: empty the keyword of the scanner are stored in the property Keywords. the scanner component sorts list of keywords automatical. if the scanner reads an identifier and the identifier is a member of the keywords it will result a token ttKeyword property KeywordsCaseSensitive: Boolean -- default: false if this property is true the compare if an identifier is made case. property SpecialChars: string -- default: '' every special chars that results a ttSpecialChar token have to be entered in this string. the scanner component sort the string automatical. property OnTokenRead: TTokenEvent this user defined event is called if a new token is read from the input file. this event is called atfer the token is read and before it is stored in the internal list of the scanner component. if any application dependent changes before registering the new token are neccessary it is possible to change every part of the new token. properties and methods at runtime: procedure Analyze this is the main method taking a source file to tokens. the name of the source file to analyze is the contents of the property filename. the number of read tokens is available via the property count. the read tokens are available in the array Token. before analyzing a new source file the results of a previously analysis are deleted. property Count: Integer this property contains the number of token read by the method analyze. property Token[Index: Integer] this property gives an easy access to the available token. a little example shows the access: for i := 1 to Count do WorkWithToken( Token[i-1] );
Classes |
TScanner - decralation of the main scanner component
TToken - a token contains the token type, the belonging text and the position within the source file
Functions |
Register - register the component at the component palette perhaps you want to change the palette register name
Types |
Constants |
Variables |
Functions |
Types |
TCharSet = set of Charset type for the special chars
TTokenEvent = procedure (Sender: TObject; Token: TToken) of objectthis event type is called if a token from the input file is read
TTokenType = ( ttComment, ttEof, ttError, ttHexDecimal, ttIdentifier, ttInteger, ttKeyword, ttReal, ttSpecialChar, ttString );enumeration with the possible result token
Constants |
Variables |