@@ -357,7 +357,14 @@ void Parser::Get_Token ()
357357 break ;
358358
359359 default :
360- Write_Token (mToken .raw );
360+ if (parseRawIdentifiers || (mToken .raw .isPseudoIdentifier && (!Parsing_Directive || Inside_Ifdef)))
361+ Read_Symbol (mToken .raw );
362+ else
363+ {
364+ if (mToken .raw .isReservedWord && Inside_Ifdef)
365+ Warning (" Trying to test whether a reserved keyword is defined. Test result may not be what you expect." );
366+ Write_Token (mToken .raw );
367+ }
361368 break ;
362369 }
363370 }
@@ -448,28 +455,26 @@ void Parser::Read_Symbol(const RawToken& rawToken)
448455 RawToken nextRawToken;
449456 bool haveNextRawToken;
450457
451- /* If its a reserved keyword, write it and return */
452- Temp_Entry = Find_Symbol (SYM_TABLE_RESERVED, rawToken.lexeme .text .c_str ());
453- if (Temp_Entry != nullptr )
458+ if (rawToken.isReservedWord && !parseRawIdentifiers)
454459 {
455- POV_PARSER_ASSERT (false );
460+ // Normally, this function shouldn't be called with reserved words.
461+ // Exceptions are a few keywords that behave like identifiers in certain contexts,
462+ // such as `global` and `local` which may behave like dictionaries.
463+ POV_PARSER_ASSERT (rawToken.isPseudoIdentifier );
456464
457- if (!Parsing_Directive && (Temp_Entry-> Token_Number == LOCAL_TOKEN) )
465+ if (rawToken. id == LOCAL_TOKEN)
458466 {
467+ POV_PARSER_ASSERT (!Parsing_Directive || Inside_Ifdef);
459468 pseudoDictionary = Table_Index;
460469 }
461- else if (!Parsing_Directive && (Temp_Entry-> Token_Number == GLOBAL_TOKEN) )
470+ else if (rawToken. id == GLOBAL_TOKEN)
462471 {
472+ POV_PARSER_ASSERT (!Parsing_Directive || Inside_Ifdef);
463473 pseudoDictionary = SYM_TABLE_GLOBAL;
464474 }
465- else if (Inside_Ifdef)
466- {
467- Warning (" Tried to test whether a reserved keyword is defined. Test result may not be what you expect." );
468- }
469475 else
470476 {
471- Write_Token (Temp_Entry->Token_Number , rawToken);
472- return ;
477+ POV_PARSER_ASSERT (false );
473478 }
474479 }
475480
@@ -490,7 +495,7 @@ void Parser::Read_Symbol(const RawToken& rawToken)
490495 {
491496 /* Search tables from newest to oldest */
492497 int firstIndex = Table_Index;
493- int lastIndex = SYM_TABLE_RESERVED+ 1 ; // index SYM_TABLE_RESERVED is reserved for reserved words, not identifiers
498+ int lastIndex = SYM_TABLE_GLOBAL;
494499 for (Local_Index = firstIndex; Local_Index >= lastIndex; Local_Index--)
495500 {
496501 /* See if it's a previously declared identifier. */
@@ -628,11 +633,19 @@ void Parser::Read_Symbol(const RawToken& rawToken)
628633 table = Tables [pseudoDictionary];
629634 pseudoDictionary = -1 ;
630635
631- if (!haveNextRawToken || (nextRawToken.lexeme .category != Lexeme::kOther ) ||
636+ if (!haveNextRawToken ||
637+ (nextRawToken.lexeme .category != Lexeme::kOther ) ||
632638 ((nextRawToken.lexeme .text != " [" ) && (nextRawToken.lexeme .text != " ." )))
633639 {
634- Get_Token (); // ensures the error is reported at the right token
635- Expectation_Error (" '[' or '.'" );
640+ if (Inside_Ifdef)
641+ {
642+ Warning (" Trying to test whether a reserved keyword is defined. Test result may not be what you expect." );
643+ }
644+ else
645+ {
646+ Get_Token (); // ensures the error is reported at the right token
647+ Expectation_Error (" '[' or '.'" );
648+ }
636649 }
637650 }
638651 else
@@ -2079,14 +2092,7 @@ void Parser::init_sym_tables()
20792092{
20802093 int i;
20812094
2082- Add_Sym_Table ();
2083-
2084- for (i = 0 ; Reserved_Words[i].Token_Name != nullptr ; i++)
2085- {
2086- Add_Symbol (SYM_TABLE_RESERVED,Reserved_Words[i].Token_Name ,Reserved_Words[i].Token_Number );
2087- }
2088-
2089- Add_Sym_Table ();
2095+ Add_Sym_Table (); // global symbols
20902096}
20912097
20922098Parser::SYM_TABLE *Parser::Create_Sym_Table (bool copyNames)
@@ -2289,7 +2295,7 @@ SYM_ENTRY *Parser::Add_Symbol (int Index,const char *Name,TokenId Number)
22892295{
22902296 SYM_ENTRY *New;
22912297
2292- New = Create_Entry (Name, Number, (Index != SYM_TABLE_RESERVED) );
2298+ New = Create_Entry (Name, Number, true );
22932299 Add_Entry (Index,New);
22942300
22952301 return (New);
0 commit comments