From: Hugh Sasse Date: 2005-10-28T19:52:47+09:00 Subject: Re: PARSER for RUBY On Fri, 28 Oct 2005, puellula@gmail.com wrote: > Hi, > can you help me? > I have to write a parser for Ruby. I had think to use the parser > generator ANTLR. > I have find Ruby Grammar, but I have problem with ANTLR for "infinite > recursion". I have cancel left recursion but I have the same problem :( You've not removed all left recursion. [...] > simple grammar is: > > > // PARSER > class RubyParser extends Parser; > options { buildAST=true; } > > > program : compstmt; > compstmt : stmt; > stmt : stmt1 expr > | ; > stmt1 : stmt IF [...] > | ; > expr : ; [...] Just take the if example: stmt = stmt1 expr = stmt IF expr = stmt1 IF expr = stmt IF IF expr = stmt1 IF IF IF expr I don't know antlr well, but maybe > stmt : stmt IF expr > | stmt WHILE expr > | stmt UNLESS expr > | ; might work better?