Re: Compiler tool question

Norman Ramsey <nr@labrador.cs.virginia.edu>
18 Jun 1998 11:05:51 -0400

          From comp.compilers

Related articles
Compiler tool question eric@gadgetguru.com (1998-06-09)
Re: Compiler tool question adrian@dcs.rhbnc.ac.uk (1998-06-11)
Re: Compiler tool question nr@labrador.cs.virginia.edu (Norman Ramsey) (1998-06-18)
| List of all articles for this month |

From: Norman Ramsey <nr@labrador.cs.virginia.edu>
Newsgroups: comp.compilers
Date: 18 Jun 1998 11:05:51 -0400
Organization: University of Virginia Computer Science
References: 98-06-042
Keywords: parse, design

Eric O'Dell <eric@gadgetguru.com> wrote:
>For new operators, the user will be able to choose characters from a
>special operator character set (the usual C operator characters, plus
>some extras) or alternatively give them names that follow the same
>rules as any other variable or function identifier.


I suggest you follow the Standard ML trick of letting the user declare
any binary function to be infix with specified precedence and
associativity. Your parser should just suck in a list of tokens and
then you run a little operator-precedecnce parser in the semantic
analysis phase. For an example of such a parser that also support
prefix and postfix operators, see the appendix to
http://www.cs.virginia.edu/~nr/pubs/unparse.ps (which will appear in
SP&E). For a complete translator using this approach, see
http://www.cs.virginia.edu/~nr/toolkit/working/sml/rtl/WWW/grammar.html.


>I'd also like to
>be able to define operators that consist of more than one token, like
>the trinary "? :" operator in C, so that ... would be legal


You'd be amazed at how much haacking you can do with just binary infix
operators. For an example of defining


    mumble <== foo <quux> bar


see http://www.cs.virginia.edu/zephyr/csdl/intel.html.
--


Post a followup to this message

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