Precedence values for Reverse Polish

"Nerd" <nerd@freeuk.com>
27 Oct 1999 14:12:29 -0400

          From comp.compilers

Related articles
Precedence values for Reverse Polish nerd@freeuk.com (Nerd) (1999-10-27)
Re: Precedence values for Reverse Polish cbrtjr@ix.netcom.com (Charles E. Bortle, Jr.) (1999-10-29)
Re: Precedence values for Reverse Polish lex@cc.gatech.edu (1999-10-31)
Re: Precedence values for Reverse Polish ppaatt@aol.com (1999-10-31)
Re: Precedence values for Reverse Polish nerd@freeuk.com (Nerd) (1999-10-31)
Re: Precedence values for Reverse Polish anton@mips.complang.tuwien.ac.at (1999-11-02)
Re: Precedence values for Reverse Polish ppaatt@aol.com (1999-11-02)
[4 later articles]
| List of all articles for this month |
From: "Nerd" <nerd@freeuk.com>
Newsgroups: comp.compilers
Date: 27 Oct 1999 14:12:29 -0400
Organization: Compilers Central
Keywords: question

I've got a book that describes how to convert from infix to postfix (Reverse
Polish). But the only operators that it gives suitable presedence values for
are:
:= 0
( 1
+, -, ) 2
*, / 3
^ 4


I would like to do full arithmatic (+, -, *, /, mod, div), comparison (=,
<>, >, <, >=, <=) and logical (and, or, xor, not). I've already got the
expression split into tokens (identifiers and operators) so identifiers, and
operators such "mod", "and", etc... can be considered as single characters.
I've tried some values, but they don't seem to work. Anyone got any ideas?


Also, I'd like to extend it to convert:


if a = b then c := 1 else c := 2 to a b = c 1 := c 2 := if


So "if" is a trinary operator. Or, since my language allows it:


c := if a = b then 1 else 2 to c a b = 1 2 if :=


I'm sure that's easy to do with the correct presedence values, and
perhaps a slight modification to the RPN converter. And would it be
possible to do something about compound statements ("begin ... end;"
in Pascal, "{ ... }" in C, etc...), thus making much more available to
RPN; such as:


for a = 1 to 10 do begin
    writeln (a) to a 1 10 2 a writeln b readln compound
for
    readln (b)
    end;


So here, "writeln" and "readln" are unary operators, "compound" is the
operator that collects the items in the compound statement together (it's
first operand is the number of statements it contains, the rest are the
statements), and "for" is a quarary operator taking:
<control variable> <start> <stop> <statement> for


Just some ideas...


--
Paul Evans


Paul_Evans@denbigh.net (school)
nerd@freeuk.com (home)
ICQ number: 4135350


Post a followup to this message

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