[antlr-interest] Keywords with whitespaces

mail.ozemail.com.au Matthew.Ford at forward.com.au
Mon Jan 27 15:04:07 PST 2003


How about

What about in the Lexer.g

BEGIN_SEQUENCE: "begin"! (WS!)+ "sequence"!
    { $setText("begin sequence");}
;

----- Original Message -----
From: <kreismeister at yahoo.de>
To: <antlr-interest at yahoogroups.com>
Sent: Tuesday, January 28, 2003 8:35 AM
Subject: [antlr-interest] Keywords with whitespaces


> Hi!
>
> Any tips on how to recognize keywords with whitespaces? I think the
> literals options is not enough because it will match words as
> keywords that arn't keywords if not followed by another word.
>
> example: "begin" (WS)+ "sequence" is _ONE_ keyword but only "begin"
> or "sequence" is handled as identifyer.
>
> I'd like to try the following but get a lot of warnings.
>
> ID options {
> testLiterals = false; // we don't test for literals because
> all are defined here!
> }
> :
>   "announce"            { $setType( ANNOUNCE         );}
> | "as" (WS)+ ( "anytype" { $setType(AS_VARIANT); }
> | "array" {
> $setType(AS_ARRAY); }
> ( (WS)+ "of" (WS)+ (
> "anytype"
> { $setType(AS_ARRAY); }
> | "array"
> { $setType(AS_ARRAY_ARRAY); }
> | "character"
> { $setType(AS_CHARACTER_ARRAY); }
> | "class"
> { $setType(AS_CLASS_ARRAY); }
> | "codeblock"
> { $setType(AS_BLOCK_ARRAY); }
> | "date"
> { $setType(AS_DATE_ARRAY); }
>
> | "enumeration" { $setType(AS_ENUM_ARRAY); }
>                     | "logical" { $setType
> (AS_LOGICAL_ARRAY); }
>                     | "numeric" { $setType
> (AS_NUMERIC_ARRAY); }
>                     | "object" { $setType
> (AS_OBJECT_ARRAY); }
>                     | "string" { $setType
> (AS_CHARACTER_ARRAY); }
>                     | "usual" { $setType
> (AS_CHARACTER_ARRAY); }
>                     )
> )?
> | "character" { $setType
> (AS_CHARACTER); }
> | "class" {
> $setType(AS_CLASS); }
> | "codeblock" { $setType
> (AS_BLOCK); }
> | "date" {
> $setType(AS_DATE); }
> | "enumeration" { $setType
> (AS_ENUM); }
>                     | "logical" { $setType(AS_LOGICAL); }
>                     | "numeric" { $setType(AS_NUMERIC); }
>                     | "object" { $setType(AS_OBJECT); }
>                     | "string" { $setType(AS_CHARACTER); }
>                     | "usual" { $setType(AS_CHARACTER); }
> )
> | "begin" (WS)+ "sequence"   { $setType( BEGINSEQ         );}
> | "break"               { $setType( BREAK            );}
> | "case"                { $setType( CASE             );}
> | "catch"               { $setType( CATCH            );}
> | "declare"             { $setType( DECLARE          );}
> | "do"                  { $setType( DO               );}
> ( (WS)+ (
>   "case"          { $setType(
> DOCASE           );}
> | "while"       { $setType(
> DO_WHILE         );}
> ( (WS)+
>   "with" { $setType(
> DO_WHILE_WITH    );}
> )?
> )
> )?
> | "else"                { $setType( ELSE             );}
>   ( "if"              { $setType( ELSEIF           );}
>   )?
> | "end"                 { $setType( END              );}
> | "endcase"             { $setType( ENDCASE          );}
> | "enddo"               { $setType( ENDDO            );}
> | "endif"               { $setType( ENDIF            );}
> | "enumeration"         { $setType( ENUM             );}
> | "exit"                { $setType( EXIT             );}
> ( (WS)+ (
>     "function"    { $setType(
> HB_EXIT_FUNC     );}
> | "procedure"   { $setType(
> HB_EXIT_PROC     );}
> )
> )?
> | "external"            { $setType( EXTERN           );}
> | "field" { $setType(
> FIELD            );}
> | "for"                 { $setType( FOR              );}
> ( (WS)+
>   "each"         { $setType(
> FOREACH          );}
> )?
> | "function"            { $setType( FUNCTION         );}
> | "global"              { $setType( GLOBAL           );}
> ( (WS)+ "external"  { $setType( EXTERNGLOBAL     );}
> )?
> | "hb_inline" { $setType(
> HB_INLINE        );}
> | "if"                  { $setType( IF               );}
> | "iif" { $setType(
> IIF              );}
> | "in" (WS)+ { $setType(IN); }
> | "init" (WS)+ (
>   "function"    { $setType(
> HB_INIT_FUNC     );}
> | "procedure"   { $setType(
> HB_INIT_PROC     );}
> )
> | "line" { $setType(LINE); }
> | "local"               { $setType( LOCAL            );}
> | "loop"                { $setType( LOOP             );}
> | "memvar"              { $setType( MEMVAR           );}
> | "next"                { $setType( NEXT             );}
> | "nil" { $setType(NIL); }
> | "optional" { $setType(OPTIONAL); }
> | "otherwise"           { $setType( OTHERWISE        );}
> | "parameters"          { $setType( PARAMETERS       );}
> | "private"             { $setType( PRIVATE          );}
> | "procedure"           { $setType( PROCEDURE        );}
> | "public"              { $setType( PUBLIC           );}
> | "qself" { $setType(QSELF); }
> | "recover"             { $setType( RECOVER          );}
> ( (WS)+ "using"    { $setType(
> RECOVERUSING     );}
> )?
> | "return"              { $setType( RETURN           );}
> | "static"              { $setType( STATIC           );}
> ( (WS)+ (
>   "function"  { $setType(
> HB_STATIC_FUNC   );}
> | "procedure" { $setType(
> HB_STATIC_PROC   );}
> )
> )?
> | "step" { $setType(HB_STEP); }
> | "text"                { $setType( HB_TEXT          );}
> | "to" { $setType(HB_TO); }
> | "try"                 { $setType( TRY              );}
> | "while"               { $setType( WHILE            );}
> | "with" { $setType(
> HB_WITH          );}
> ((WS)+ "object" { $setType(
> WITHOBJ          );}
> )?
> | "_hb_"
> ( "class"           { $setType( DECLARE_CLASS    );}
> | "member"          { $setType( DECLARE_MEMBER   );}
> )
> | "_procreq_"           { $setType( PROCREQ          );}
> | "_field" { $setType(FIELD); }
> | "_get" { $setType(GET); }
> | ('a'..'z'|'_'|'?') ('a'..'z'|'_'|'?'|'0'..'9')*
> ;
>
>
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list