Delphi¤¤ªº¦r²´(Tokens)

³o¤@½g¤å³¹¥D­n¦b¤¶²Ðºc¦¨ Delphi µ{¦¡ªº³Ì¤p³æ¦ì--- ¦r²´(Token)¡C
¤°»ò¬O¦r²´(Tokens)
¦b¶}©l°Q½× "¤°»ò¬O¦r²´?" ¤§«e¡AÅý§Ú­Ì¥ý¬Ý©³¤U³o­Ó²µuªºµ{¦¡¡C
program Project1;

uses
dialogs;

begin
Messagedlg('Hello',mtInformation,[mbOK],0) ;
end.

µ{¦¡°õ¦æ«á·|¦bµe­±¥X²{¤W¤@­Ó¤p¤pªºµøµ¡¡A¨ÃÅã¥ÜHelloªº¦r¼Ë¡C
¦b³oùØ¥ý¤£»¡©ú³o­Óµ{¦¡¬O¦p¦ó°õ¦æªº¡Aºc¦¨³o­Óµ{¦¡ªº­^¤å¦r¡B¼Æ¦r¡B²Å¸¹¡A¤~¬O§Ú­Ì­n°Q½×ªº­«ÂI---¦r²´¡C
§Ú­Ì¥i±N¦r²´¤j­P¤ÀÃþ¬°¯S®í²Å¸¹(special symbols)¡BÃѧO¦r(inditifiers)¡B¼ÐÅÒ(labels)¡B¼Æ¦r©M¦r¤¸¦r¦ê¡C·íµMÁÙ¥i¥H¦A¥H¥\¯à¤è­±¦A°µ²Ó¤À, ©³¤U±N³v¤@¤¶²Ð.
¦b Object Pascal ¤¤ªº¤ÀÃþ
³oùتº¤ÀÃþ¤èªk¡A¥D­n¨Ì¾ÚDelphi¤â¥U(Object Pascal Language Guide)¤¤ªº¤ÀÃþ¡A¦A¥[¤W¤@¨Ç½d¨Ò¤Î»¡©ú¡C
¯S®í²Å¸¹
¯S®í²Å¸¹:
+ - * / = > < ( ) [ ] { } , . : ; @ # $ ^
>= <= := .. (* *) (. .) //

¦³¤@¨Ç¯S®í²Å¸¹¨ã¦³¬Ûµ¥ªº·N¸q¡A¦p¤Uªí¥ª¥k¨âÃ䪺²Å¸¹ªí¥Ü¬Û¦Pªº·N«ä¡C
²Å¸¹    ¹ïµ¥ªº²Å¸¹
[    (.
]    .)
{    (*
}    *)
ÁöµM¤Wªíªº²Å¸¹¦³¹ïµ¥ªºÃö«Y¡A¦ý¬O¥²»Ý¦¨¹ï¥X²{¡A§_«h¦b½sĶ®É·|²£¥Í¿ù»~¡C¨Ò¦p
{ } (* *) ¥¿½T { *) ¿ù»~
¥t¥~ÁÙ¦³¤@Ãþ´N¬OªÅ¥Õ(blanks)¡A³oùتºªÅ¥Õªx«üASCII­È±q0..31ªº±±¨î¦r¤¸¤ÎªÅ¥Õ¦r¤¸(ASCII 32)¡CªÅ¥Õ¥i©ñ¦b¦r²´»P¦r²´¤§¶¡°µ¬°°Ï¹j¡A¦b½sĶ®É¡A°µ¬°°Ï¹j¥ÎªºªÅ¥Õ¦r¼Æ¦Ü¤Ö¦³¤@­Ó´N¥i¥H¤F¡C¤£¹L¤@¯ë¦b¼¶¼gµ{¦¡®É³q±`³£·|¦h´¡¤J¤@¨ÇªÅ¥Õ(ªÅ®æ©ÎªÅ¦æ)¡A¥H¼W¥[¬üÆ[¤Î¤è«K¾\Ū¡C

ÃѧO¦r(identifiers)
ÃѧO¦r´N¬O¤@­Ó¥H­^¤å¦r¥À¡A¼Æ¦r©M©³½u(_¡AASCII 95)©Ò²Õ¦X¦¨ªº¤@­Ó¦W¦r(¤£¥i¥H¬O¼Æ¦r¶}ÀY)¡A¥i¥H¬O¤@­Ó¦³·N¸qªº­^¤å³æ¦r¡A¤]¥i¯à¬O¤@­Ó§¹¥þ¨S¦³·N¸q¡AÀH«K°Â¥X¨Óªº¦r¥À²Õ¦X¡C

¦bObject Pascal¤¤ÃѧO¦r¬O¤£°Ï¤À¤j¤p¼gªº¡CÁöµM¦b¼¶¼gµ{¦¡ªº®É­Ô¥i¥H¤ñ¸ûÀH¿³ªº¨Ï¥Î¡A¦ý¬O³]©wÅܼƮɻݪ`·N¡ACount©Mcount¹ï½sĶ¾¹¨Ó»¡¬O¦P¤@­Ó¦r¡C
ÃѧO¦r¤¤¦³¨âºØ¤ñ¸û¯S§OªºÃþ§O¡A´N¬O«O¯d¦r(reserved word)©M¼Ð·Ç«ü¥O(standard directives)¡A¦bDelphi³£¬O¥H²ÊÅé¦rÅã¥Ü(¹w³]­È)¡C
³o¨âÃþ³£¬OObject Pascal©w¸q¦nªº«ü¥O¡A¨âªÌªº°Ï§O¦b«O¯d¦r¤£¥i¥H­«·s©w¸q¡A¦Ó¼Ð·Ç«ü¥O¥i¥H¡A¦ý¬O±j¯Pªº«Øij¤£­n­«·s©w¸q¼Ð·Ç«ü¥O¡C
¥H¤U¤À§O¬O«O¯d¦r©M¼Ð·Ç«ü¥Oªº¦Cªí:
«O¯d¦r:
and array as asm
begin case class const
constructor destructor div do
downto else end except
exports file finalization finally
for function goto if
implementation in inherited initialization
inline interface is label
library mod nil not
object of on or packed procedure program property raise record repeat set shl shr string then threadvar to try type unit until uses var while with xor

¼Ð·Ç«ü¥O:
absolute abstract assembler automated
cdecl default dispid dynamic
export external far forward
index message name near
nodefault override pascal private
protected public published read
register resident stdcall stored
virtual write


°£¤F¤W­zªº«O¯d¦r©M¼Ð·Ç«ü¥O¥~¡A¨ä¥L¹³¬O±`¼Æ¡BÅܼơBµ{§Ç¦WºÙ¡B¨ç¼Æ¦WºÙ¡B«¬ºA¡B³æ¤¸¦WºÙ¡K ¤]³£¬O¤@ºØÃѧO¦r¡A¥²¶·¿í¦u¤U¦Cªº­­¨î¡C
O ÃѧO¦rªºªø«×¤£­­¡A¦ý¬ODelphi¥u»{±o«e­±63­Ó¦ì¤¸²Õ¡C
O ¥²»Ý¬O¥H­^¤å¦r¥À©Î©³½u(_¡AASCII 95)¶}ÀY¡A¨ä«á¥i¥H¬O­^¤å¦r¥À¡A¼Æ¦r©Î¬O©³½u¡C
O ¤£°Ï¤À­^¤åªº¤j¤p¼g¡C
O ·í¦³´X­Ó¦P¦WªºÃѧO¦r¦s¦b®É¡A¥i¯à»Ý­n¥Î¥yÂI(.¡AASCII 46)¨Ó³sµ²§O¤@­ÓÃѧO¦r°µ¬°°Ï¤À¡C¨Ò¦p form1.caption¡Alabel1.caption¡C¦b³oùاڭ̧â³oºØ¥Î¥yÂI³sµ²°_¨ÓªºÃѧO¦r¡AºÙ¬°­­©wµüÃѧO¦r(Qualified Identifier)¡C

¼ÐÅÒ(labels)
¼ÐÅÒ¥D­n¬O©M·f°tgoto¨Ï¥Îªº¡A¼Ð¥Ügoto­n¸õ¨ì¨º¤@­Ó¦ì¸m¡C¼ÐÅÒ¥i¥H¬O¤@­ÓÃѧO¦r¡A©Î¬O0¨ì9999¶¡ªº¤@­Ó¼Æ¦r¦ê¦C(«e¸mªº0·|³Q©¿²¤)¡C«Å§i¤Î¨Ï¥Îªº½d¨Ò¦p¤U:
procedure test ;
label
OutHere, 0005 ;
begin
goto 5 ;
showmessage('¤£·|°õ¦æ¨ì³o¤@¦æ') ;
goto OutHere ;

0005:
ShowMessage('·|°õ¦æ³o¤@¦æ') ;

OutHere:
end ;

¼ÐÅÒ¥»¨­¤£·|¼vÅT¨ìµ{¦¡ªº°õ¦æ¡A¥u¦³·í°õ¦æ¨ìgoto¤~·|Âಾµ{¦¡ªº¬yµ{¡C

¼Æ¦r
¦bObject Pascal¤¤¨Ï¥Îªº¼Æ¦r¨t²Î¡A°£¤F¤@¯ëºD¥Îªº¤Q¶i¦ì¼Æ¦r¤§¥~¡AÁÙ¥i¥H¨Ï¥Î¤uµ{ªí¥Üªk¨Óªí¥Ü¤@­Ó¹ê¼Æ¡A©Î¬O¥Î16¶i¦ìªk¨Óªí¥Ü¤@­Ó¥¿¾ã¼Æ¡C
O ¤Q¶i¦ì¼Æ¦r¡C¤S¥i¤À¬°¾ã¼Æ©M¹ê¼Æ¡Aªí¥Üªk´N¬O§Ú­Ì¤@¯ëªººD¥Îªk¡A¦p 123¡A-1¡A3.14¡A-0.5 ¡K½Ñ¦p¦¹Ãþ¡C
O ¤uµ{ªí¥Üªk¡C¨Ï¥ÎE¨Óªí¥Ü10ªº¦¸¤è¡A¨Ò¦p7E-2 ªí¥Ü 7*10^(-2)¡A¤]´N¬O 0.07¡C
O 16¶i¦ìªk¡C¦b¶}ÀY¥[¤W¿ú¸¹($¡AASCII 36)¨Óªí¥Ü¤@­Ó16¶i¦ìªº¥¿¾ã¼Æ¡A¨Ò¦p $FFFF ªí¥Ü 65536¡C16¶i¦ì¥i¥Hªí¥Üªº¼Æ¦r½d³ò±q$00000000¨ì $FFFFFFFF¡C

¦r¤¸¦r¦ê
¤@¦ê¥H³æ¤Þ¸¹('¡AASCII 39)¥]§¨¦íªº¦r¤¸¡A§Ú­ÌºÙ¤§¬°¦r¤¸¦r¦ê¡C¤U­±¬O¤@¨Ç¨Ò¤l:
'123'            { 123              }
'Pascal'        { Pascal              }
'¤¤¤å'        { ¤¤¤å              }
''            { (ªÅ¦r¦ê)          }
' '            { (¤@­ÓªÅ¥Õ¦r¤¸)    }
°£¤F³oºØ³Ì²³æªºÀ³¥Î¥~¡AÁÙ¦³¤@¨Ç¯S©Ê¤ÎÀ³¥Î¤èªk¡A¦CÁ|¦p¤U:
O ¦b¦r¦ê¤¤¡A¥i¥H¥Î³sÄò¨â­Ó³æ¤Þ¸¹¨Óªí¥Ü³æ¤Þ¸¹¦r¤¸¡C¨Ò¦p:
'I''m fine'        { I'm fine }
O ¦r¤¸¦r¦êªºªø«×§Y¬°ªí¥Ü³o­Ó¦r¦ê¬O¥Ñ´X­ÓASCII¦r¤¸©Òºc¦¨(¦b Delphi 16¦ì¤¸ª©¥»¤¤, ¦r¤¸¦r¦êªº³Ì¤jªø«×¬°255)¡Cª`·N¡A¤@­Ó¤¤¤å¦r¬O¥Ñ¨â­Ó ASCII¦r¤¸©Òºc¦¨ªº¡C
O ·í¦r¤¸¦r¦êªºªø«×¬°1ªº®É­Ô»P¦r¤¸«¬ºA(char)¬Û®e¡C
O ¥i¥H§Q¥Î#¦r¸¹¥[¤W¤@­Ó¼Æ¦r(0..255)¨Óªí¥Ü¹ïÀ³ªºASCII¦r¤¸¡C³q±`§Ú­Ì¥Î³oºØ¤è¦¡¥i¥H¦b¦r¦ê¤¤¥[¤W¤@¨Ç±±¨î¦r¤¸¡C¦b#¸¹©M¼Æ¦rªº«e«á³£¤£¥i¥H¦³ªÅ¥Õ¡C

¥¿½Tªº¥Îªk:
'²Ä¤@¦æ'#13'²Ä¤G¦æ'     { ²Ä¤@¦æ(´«¦æ)²Ä¤G¦æ     }
#65#66#67     { ABC                 }

¿ù»~ªº¥Îªk:
'²Ä¤@¦æ' #13 '²Ä¤G¦æ'     { ¦b # «e¦³ªÅ®æ, ¿ù»~     }
# 65                         { # ©M¼Æ¦r¶¡¦³ªÅ®æ, ¿ù»~    }

O ·í½sĶ¿ï¶µ Extended Syntax ¥´¶}®É{$X+}¡A¦r¤¸¦r¦ê¥i¬Û®e©óPChar®æ¦¡¡C

µùÄÀ
¦bµ{¦¡¤§¤¤¡A¦³¤@¨Ç¬O­n¼gµ¹¤H¬Ý¡AÀ°¦í°O¾Ð©Î¬O»¡©úµ{¦¡ªº¦r¥y¡A¬°¤F­n§â³o¨Ç¦r¥y©M¯u¥¿ªºµ{¦¡¤À¶}¡A¦b Object Pascal ¤¤©w¸q¤F´XºØ²Å¸¹¡A§âµ¹½sĶ¾¹¬Ýªºµ{¦¡©MÅý¤H¬ÝªºµùÄÀ¤À¹j¶}¨Ó¡C
O ¹ïºÙªº¤j¬A¸¹ { }
{ ¹³³o¼Ë¦b³Q§¨¦b¥ª¡B¥k¤j¬A¸¹¤§¶¡ªº¤å¦r³£¬Oµù¸Ñ }
{
¥ª¥k¤j¬A¸¹¤£¤@©w­n¦b¦P¤@¦æ¡A¦ý¤£¥i¦³±_ª¬ªºµù¸Ñ¡C
ª`·N: ¦³¨Ç¤¤¤å¦rªº²Ä¤G­Ó¦r¤¸¬O¥k¤j¬A¸¹¡A·|³y¦¨½sĶ®Éªº
¿ù»~¡C
}

¦bDelphi 2.01 ¤¤¤åÀ³¥Î²Õ¥ó¤ÎDelphi 3.0¤¤¤w¸Ñ¨M³o­Ó°ÝÃD¡C
O ¹ïºÙªº¤p¬A¸¹¥[¤W¬P¸¹ (* *)
(*
¨Ï¥Î¤èªk¦P¹ïºÙªº¤j¬A¸¹¡A¤£¹L¦]¬°¬O¥Î¨â­Ó½X¡A©Ò¥H¤£·|¥X²{»P¤¤¤å¬Û½Äªºª¬ªp¡C
*)
O ³sÄò¨â­Ó°£¸¹ //
// ªí¥Ü±q¨â­Ó°£¸¹¤§«á¨ì¦æ§À³£¬Oµù¸Ñ(³æ¦æ¦³®Ä)¡C
// ³oºØµù¸Ñ¤è¦¡¥u¦³¦bDelphi 2.0 ¤§«á¤~¥i¨Ï¥Î¡C

¦bObject Pascal¤¤¡A½sĶ¾¹«ü¥O(compiler directives)¬O¤@ºØ¯S®íªºµù¸Ñ¡A¸Ô²Óªº»¡©ú¥i°Ñ¦Ò IFDEF.DOC¡C