Re: Designing a language in which a class can define (not just overload) operators

nmm1@cus.cam.ac.uk (Nick Maclaren)
9 Sep 2003 22:56:15 -0400

          From comp.compilers

Related articles
Designing a language in which a class can define (not just overload) news@chunk.com.au (Richard Cartwright) (2003-08-20)
Re: Designing a language in which a class can define (not just overloa joshualevy@yahoo.com (2003-08-23)
Re: Designing a language in which a class can define (not just overloa tmk@netvision.net.il (2003-08-23)
Re: Designing a language in which a class can define (not just overloa rkrayhawk@aol.com (2003-09-04)
Re: Designing a language in which a class can define (not just overloa vidar@hokstad.name (2003-09-04)
Re: Designing a language in which a class can define (not just overloa nmm1@cus.cam.ac.uk (2003-09-09)
Re: Designing a language in which a class can define (not just overloa derkgwen@HotPOP.com (Derk Gwen) (2003-09-09)
| List of all articles for this month |
From: nmm1@cus.cam.ac.uk (Nick Maclaren)
Newsgroups: comp.compilers
Date: 9 Sep 2003 22:56:15 -0400
Organization: University of Cambridge, England
References: 03-08-062 03-08-083 03-09-026
Keywords: syntax, OOP
Posted-Date: 09 Sep 2003 22:56:15 EDT

Vidar Hokstad <vidar@hokstad.name> wrote:
>tmk@netvision.net.il (Michael Tiomkin) wrote in message news:03-08-083...
>> > [Write your parser with generic expression rules like this:
>> >
>> > expr: expr OP5 expr /* precedence 5 operator */
>> >
>> > Then when you define a new operator at level 5, have the lexer return
>> > an OP5 for it with semantic info so the parser can figure out which
>> > operator it was. I'm pretty sure this trick was used in extensible
>> > languages before 1980. -John]
>>
>> Unfortunately, this will need 100 rules for 100 priorities.
>> [It's true. But since a language with 100 priorities would be unusable,
>> so what? -John]
>
>My solution to this problem years ago was to make the parser entirely
>dynamic. Instead of hardwiring rules to specific priorities, I defined
>almost the entire language I was working on in terms of operators with
>variable priorities. I started out with arithmetic expressions, and
>then went a little bit overboard and made everything including control
>structures expressions that were defined by:


Since nobody seems to have mentioned it - Algol 68!


You clearly have gone further but, as far as I know, Algol 68 wwas the
source of all this.


Regards,
Nick Maclaren.


Post a followup to this message

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