Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.compilers > #2927

Re: Keywords and Reserved Words

From "Robin Vowels" <robin51@dodo.com.au>
Newsgroups comp.compilers
Subject Re: Keywords and Reserved Words
Date 2022-03-10 11:59 +1100
Organization Compilers Central
Message-ID <22-03-023@comp.compilers> (permalink)
References <22-03-004@comp.compilers> <22-03-009@comp.compilers> <22-03-015@comp.compilers> <22-03-016@comp.compilers> <22-03-017@comp.compilers>

Show all headers | View raw


From: "Christopher F Clark" <christopher.f.clark@compiler-resources.com>
Sent: Wednesday, March 09, 2022 6:46 AM

> First, recognizing keywords, if you are using a language (unlike the
> original FORTRAN where spaces were not significant), it is useful to
> follow a model proposed by Frank Deremer, with lexing divided into a
> scanner and a screener.  The scanner has only the responsibility of
> dividing tokens into discrete entities and labelling those which have
> fixed types, so keyword recognition is not part of the scanner to the
> scanner they are just identifiers.  The screener then checks the
> identifier to see if it is a keyword.

A similar approach is used in DEUCE PL/I. (more in a moment).

In XPL, the scanner recognises keywords (which are reserved words)
and classifies them differently from identifiers.
The other objects (integers, strings, operators, parentheses, etc)
are classified appropriately.

Returning to DEUCE PL/I, the scanner classifies indentifiers
without making any distinction between identifiers and keywords.
Other objects are classified as above.  The symbol table
already contains the keywords.  All new identifiers are entered
into the symbol table.

In the semantics section, initial recognition is on groupings of
identifiers (again keywords are not recognised as such).
Once a phrase is recognised, the opening keywords in the
statement are compared with permissible keyword combinations,
without resorting to the symbol table.  For example, PUT EDIT ( ...
PUT LIST ( ... and PUT DATA etc are identified after comparison with
the first word, and comparison with the second word is sufficient to
identify the kind of statement.
At this point, it can be said that the keywords are not reserved.
Avoiding looking in the symbol table for keywords saves time.

> In most languages, that lookup can easily be done by preloading the
> symbol table with the identifiers that are keywords.  This is not
> inefficient, because even if the identifier is not a keyword, you need
> a unique symbol table entry for each identifier in any case, so you
> are doing that lookup anyway.

Back to comp.compilers | Previous | NextPrevious in thread | Find similar


Thread

How do you create a grammar for a multi-language language? Roger L Costello <costello@mitre.org> - 2022-03-03 13:57 +0000
  Re: How do you create a grammar for a multi-language language? Roger L Costello <costello@mitre.org> - 2022-03-05 22:29 +0000
    Re: How do you create a grammar for a multi-language language? "Kartik Agaram" <ak@akkartik.com> - 2022-03-05 16:55 -0800
    RE: How do you create a grammar for a multi-language language? Christopher F Clark <christopher.f.clark@compiler-resources.com> - 2022-03-06 15:37 +0200
      Re: How do you create a grammar for a multi-language language? gah4 <gah4@u.washington.edu> - 2022-03-06 14:36 -0800
        Re: How do you create a grammar for a multi-language language? gah4 <gah4@u.washington.edu> - 2022-03-06 16:50 -0800
      RE: How do you create a grammar for a multi-language language? Roger L Costello <costello@mitre.org> - 2022-03-06 23:32 +0000
  Re: How do you create a grammar for a multi-language language? gah4 <gah4@u.washington.edu> - 2022-03-05 21:10 -0800
    Re: How do you create a grammar for a multi-language language? "Robin Vowels" <robin51@dodo.com.au> - 2022-03-07 13:39 +1100
  Re: How do you create a grammar for a multi-language language? Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2022-03-06 12:23 +0100
    Re: How do you create a grammar for a multi-language language? Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2022-03-07 05:08 +0100
      Re: How do you create a grammar for a multi-language language? gah4 <gah4@u.washington.edu> - 2022-03-06 21:22 -0800
        Keywords and Reserved Words Christopher F Clark <christopher.f.clark@compiler-resources.com> - 2022-03-08 21:46 +0200
          Re: Keywords and Reserved Words gah4 <gah4@u.washington.edu> - 2022-03-09 00:31 -0800
            Re: Keywords and Reserved Words "Robin Vowels" <robin51@dodo.com.au> - 2022-03-10 10:00 +1100
          Re: Keywords and Reserved Words "Robin Vowels" <robin51@dodo.com.au> - 2022-03-10 09:55 +1100
            Re: Keywords and Reserved Words in Fortran Thomas Koenig <tkoenig@netcologne.de> - 2022-03-10 07:07 +0000
          Re: Keywords and Reserved Words "Robin Vowels" <robin51@dodo.com.au> - 2022-03-10 11:59 +1100

csiph-web