Re: How to parse keywords that may be used as identifiers

gleeh@tulletts.sprint.com
21 Aug 1996 17:32:37 -0400

          From comp.compilers

Related articles
How to parse keywords that can be used as identifiers? mark@research.techforce.nl (Mark Thiehatten) (1996-08-19)
Re: How to parse keywords that may be used as identifiers scooter@mccabe.com (Scott Stanchfield) (1996-08-19)
Re: How to parse keywords that may be used as identifiers gleeh@tulletts.sprint.com (1996-08-21)
| List of all articles for this month |
From: gleeh@tulletts.sprint.com
Newsgroups: comp.compilers.tools.pccts,comp.compilers
Date: 21 Aug 1996 17:32:37 -0400
Organization: .netkonect (customer account)
References: <32184418.167E@research.techforce.nl> 96-08-058 96-08-061
Keywords: parse

Scott Stanchfield <scooter@mccabe.com> wrote:


>[How can I parse languages where keywords aren't reserved words?]


If you are going to use a parser generator then I don't know. I've
written a parser for PL/I that supports the no reserved words feature.


The parser is a hand-written recursive descent jobby.


The algorithm is in fact straightforward here it goes:


before you attempt to recognise the statement call
a func like this:


if (this_is_an_assigment() ) then
      .....
else
    .....


If it's NOT an assigment then the first token MUST be treated as a
keyword and we can parse that stmt.


If it IS an assignment then the first token MUST be an identifier
and the RHS MUST be an expression.


How do we tell if its an assignment ?


Easy


<assignment> ::= <reference> EQUALS <expression>


parsing a reference is a seperate thing altogether (it actually
ignores keywords).


That basically that.


Hugo.
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.