Related articles |
---|
[2 earlier articles] |
Re: How do you create a grammar for a multi-language language? DrDiettrich1@netscape.net (Hans-Peter Diettrich) (2022-03-07) |
Re: How do you create a grammar for a multi-language language? gah4@u.washington.edu (gah4) (2022-03-06) |
Keywords and Reserved Words christopher.f.clark@compiler-resources.com (Christopher F Clark) (2022-03-08) |
Re: Keywords and Reserved Words gah4@u.washington.edu (gah4) (2022-03-09) |
Re: Keywords and Reserved Words robin51@dodo.com.au (Robin Vowels) (2022-03-10) |
Re: Keywords and Reserved Words robin51@dodo.com.au (Robin Vowels) (2022-03-10) |
Re: Keywords and Reserved Words robin51@dodo.com.au (Robin Vowels) (2022-03-10) |
From: | "Robin Vowels" <robin51@dodo.com.au> |
Newsgroups: | comp.compilers |
Date: | Thu, 10 Mar 2022 11:59:42 +1100 |
Organization: | Compilers Central |
References: | 22-03-004 22-03-009 22-03-015 22-03-016 22-03-017 |
Injection-Info: | gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="65701"; mail-complaints-to="abuse@iecc.com" |
Keywords: | parse |
Posted-Date: | 09 Mar 2022 20:56:09 EST |
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.
Return to the
comp.compilers page.
Search the
comp.compilers archives again.