Re: Q: Operator Precedence Parser (Joseph H Allen)
15 Mar 1998 00:22:36 -0500

          From comp.compilers

Related articles
Q: Operator Precedence Parser (Sander Hahn) (1998-03-07)
Re: Q: Operator Precedence Parser (1998-03-12)
Re: Q: Operator Precedence Parser (1998-03-12)
Re: Q: Operator Precedence Parser (1998-03-12)
Re: Q: Operator Precedence Parser (1998-03-15)
Re: Q: Operator Precedence Parser (1998-03-15)
| List of all articles for this month |

From: (Joseph H Allen)
Newsgroups: comp.compilers
Date: 15 Mar 1998 00:22:36 -0500
Organization: The World Public Access UNIX, Brookline, MA
References: 98-03-062 98-03-092
Keywords: parse

>Sander Hahn ( wrote:
>: i want to learn more about operator precedence parsers. The operators
>: should be dynamically overloadable, like in Prolog. Where can i find
>: more information about this subject? (preferably online)

User fs29 <> wrote:
>When implementing my T2 compiler, I was looking for a way to speed up
>expression parsing (it used recursive procedure calls at that time).
>Finally, I have managed to do almost the entire expression parsing
>in a single procedure driven by a table containing integers to
>represent the operator precedences. Because of the table-driven
>approach, it should be easy to add, remove, and modify operators.

I've used a similar approach in Ivy
( The table indicates
associativity as well as precidence. Also I use two hash tables
initialized from this table to scan the operators. One hash table
contains an entry for each full operator, and the other only indicates
whether there are operators which match the current scanned

For example, if the operator is '>>=', there will be a hash entry for
>>= and left sub-string entries for '>' and '>>'. So to scan for an
operator, you read input for as long as you have a match in the left
sub-string table and note any matches in the full-string hash table.
You return the longest matching operator and unget any unmatching
readahead (which is just a pointer change in Ivy's scanner).

You could make a language with user defined operators with this
approach... I'm don't actually allow that in Ivy and I'm not going to
allow it in the language I'm currently working on- I'm trying to make
an N-pass header-file-less language, so parsing is not allowed to
depend on declarations (like C's typedefs).
/* ( */ /* Joseph H. Allen */
int a[1817];main(z,p,q,r){for(p=80;q+p-80;p-=2*a[p])for(z=9;z--;)q=3&(r=time(0)
]?a[p+=a[p+=q]=q]=q:0:0;for(;q++-1817;)printf(q%79?"%c":"%c\n"," #"[!a[q-1]]);}

Post a followup to this message

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