From: Hugh Sasse Date: 2005-10-28T21:33:29+09:00 Subject: Re: PARSER for RUBY ---559023410-585771160-1130502801=:19167 Content-Type: MULTIPART/MIXED; BOUNDARY="-559023410-585771160-1130502801=:19167" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. ---559023410-585771160-1130502801=:19167 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN Content-Transfer-Encoding: QUOTED-PRINTABLE On Fri, 28 Oct 2005, puellula@gmail.com wrote: > Hi Hugh Sasse and thank you for you message :) > Well... I had write on my file .g this, how you told to me: >=20 > // PARSER > class RubyParser extends Parser; > options { buildAST=3Dtrue; } >=20 > program=09=09: compstmt; > compstmt=09: stmt; >=20 > stmt : stmt IF expr > | stmt WHILE expr > | stmt UNLESS expr > | ; >=20 > expr=09: ; >=20 > // LEXER > class RubyLexer extends Lexer; > IF : "if"; > WHILE : "while"; > UNLESS : "unless"; > UNTIL : "until"; >=20 >=20 > but there is left recursione now! What do you think about? You can see > that there is left recursion! >=20 > The output is: >=20 > C:\Personal\Universit=E0\Materiale Esami\Teconologie dei Linguaggi di > Programmazio > ne + Lab>antlr provaLexerParser.g > java -classpath "C:\antlr\275\lib\antlr.jar;" antlr.Tool > provaLexerParser.g > ANTLR Parser Generator Version 2.7.5 (20050128) 1989-2005 jGuru.com > provaLexerParser.g:8:17: infinite recursion to rule stmt from rule stmt > provaLexerParser.g:9:17: infinite recursion to rule stmt from rule stmt > provaLexerParser.g:10:17: infinite recursion to rule stmt from rule > stmt [...] > provaLexerParser.g:8: warning:nondeterminism between alts 1 and 4 of > block upon > provaLexerParser.g:8: k=3D=3D1:IF > provaLexerParser.g:8: warning:nondeterminism between alts 2 and 4 of > block upon > provaLexerParser.g:8: k=3D=3D1:WHILE > provaLexerParser.g:8: warning:nondeterminism between alts 3 and 4 of > block upon > provaLexerParser.g:8: k=3D=3D1:UNLESS > Exiting due to errors. Right. I'm not sure what to do about this. You can have=20 do_this if condition1 unless condition2=20 in ruby. What about: program=09=09: compstmt; compstmt=09: stmt; =20 stmt : conditionalbody IF expr | conditionalbody WHILE expr | conditionalbody UNLESS expr | conditionalbody // a way out=20 | ; =20 conditionalbody : stmt | simplestatement; ; //simplestatement is a way out of the stmt definition loop simplestatement : returnstatement ; // other statemtents go here returnstatement : RETURN expr ; expr=09: ; =20 // LEXER class RubyLexer extends Lexer; IF : "if"; WHILE : "while"; UNLESS : "unless"; UNTIL : "until"; RETURN : "return"; =20 >=20 > I think the problem finish when I know how I can write on ANTLR the > empty string. I try to rappresent this with " ", when I write "| ;". I > hope you undestand what I would tell to you. Well, I'm not familiar with ANTLR. Actually, I read about PCCTS but not ANTLR. I find this stuff pretty difficult to debug. >=20 > Thank you so much for your message > bye, > puellula Good luck, Hugh ---559023410-585771160-1130502801=:19167-- ---559023410-585771160-1130502801=:19167--