Lambda the Ultimate

inactiveTopic Parsing with the offside rule.
started 12/7/2001; 7:42:04 AM - last post 12/7/2001; 3:27:09 PM
Alex Moffat - Parsing with the offside rule.  blueArrow
12/7/2001; 7:42:04 AM (reads: 451, responses: 5)
I'm looking for some information on how to structure lexers/parsers for languages that use the offside rule to separate statements/blocks, such as Python and Haskell. I've seen the monadic combinators in Haskell for doing this but I'm really looking for pointers on how to structure something using ANTLR or JavaCC. Some searches on Google have turned up a couple of newsgroup threads talking about this topic but nothing substantial. Does anyone have any references they could share?

Ehud Lamm - Re: Parsing with the offside rule.  blueArrow
12/7/2001; 11:33:08 AM (reads: 475, responses: 0)
I am not sure what you are refering to. I suggest you try comp.compilers as this is really a question about compilation techniques.

Alex Moffat - Re: Parsing with the offside rule.  blueArrow
12/7/2001; 12:54:48 PM (reads: 512, responses: 2)
I believe the term comes from "The next 700 programming languages" by P. J. Landin. It's certainly used when talking about Haskell. While it is about how to compile I wondered if anyone here had any thoughts as this forum has provided useful "language" related info in the past.

I'm asking about things like

proc foo (x)
  x := x + 1
  if (x > 10)
    x := 5
    return x
  else
    return x
where each block of statements in marked by indentation. A Haskell example would be
qsort []     = []
qsort (x:xs) = qsort elts_lt_x ++ [x] ++ qsort elts_greq_x
                 where
                   elts_lt_x   = [y | y <- xs, y < x]
                   elts_greq_x = [y | y <- xs, y >= x]
or some python
str = [None]*len(list):
   for i in range(len(list):
       str[i] = some_function(list[i])
   str = "".join(str)
Anyway, I just wondered if anyone had any tips on how to parse this sort of thing.

Thanks

Ehud Lamm - Re: Parsing with the offside rule.  blueArrow
12/7/2001; 1:26:59 PM (reads: 555, responses: 0)
I figured as much, just haven't seen the term before.

Seems pretty easy to parse manually.

You might be interested in this.

andrew cooke - Re: Parsing with the offside rule.  blueArrow
12/7/2001; 3:18:40 PM (reads: 535, responses: 0)
Does anyone have a pointer to a copy of that paper (700 Languages) on-line (if you're not a member of the ACM)?

Thanks.

pixel - Re: Parsing with the offside rule.  blueArrow
12/7/2001; 3:27:09 PM (reads: 449, responses: 0)
talking about indentation based scheme, you may have a look at redhog's sugar (< 100 lines :)