Arc Forumnew | comments | leaders | submitlogin
1 point by fallintothis 4222 days ago | link | parent

Another question that occurred to me:

Could you explain, specifically, how infix operators react to the presence/absence of parentheses? Ignoring the treatment of tokenization (what with whitespace vs nonwhitespace operators), is the context-sensitive grammar roughly like so?

  ( infix a b ... )   -->   ( infix a b ... )
  ( a infix b ... )   -->   ( infix a b ... )
  a infix b ...       -->   ( infix a b ) ...
where the last rule would create the behavior

  ( ... a b infix c ... ) --> ( ... a ( infix b c ) ... )
That's as much as I can gather from the examples, but I'd like having a clear mental model.


2 points by akkartik 4222 days ago | link

There isn't a unified grammar for the language, I'm afraid. I've built wart in layers:

a) parse lisp as usual. This layer doesn't know about the regular vs infix distinction, so a, a-1 and ++a and ++ are all just tokens.

b) expand infix ops inside symbols, e.g. a+1 => (a + 1)

c) scan for operators inside lists and pinch them with the adjacent elements.

  (.. a ++ b ..) => (.. (++ a b) ..)
Edit: Notice that this is different from your example:

  (a infix b ..) => ((infix a b) ..)

-----