Path: utzoo!attcan!uunet!world!esegue!compilers-sender From: joel@decwrl.dec.com Newsgroups: comp.compilers Subject: Re: Can Pascal be parsed by LR(1) parsing algorithm? Keywords: pascal, parse Message-ID: <1990Oct10.094112@decwrl.dec.com> Date: 10 Oct 90 16:41:12 GMT References: <9010091533.AA02386@apple.com> Sender: compilers-sender@esegue.segue.boston.ma.us Reply-To: joel@decwrl.dec.com Organization: DEC Western Research Laboratory Lines: 47 Approved: compilers@esegue.segue.boston.ma.us Yacc is really a crude tool for parser construction. After much experimentation, I got yacc to not only accept Modula-2's statements, but to report when you forgot to put in a missing semicolon as well. I didn't do the same for Pascal, as it was too much work. You can find complete grammars in the Modula-2/Pascal distribution available for anonymous ftp from gatekeeper.dec.com, file /pub/DEC/Modula-2/m2.vax.tar.Z. Here's the relevant code for Modula-2, just to let you know the horrors of yacc grammar c onstruction. /* blame yacc for gross sequence syntax */ StatementSequence: StatementSequence1 /**/ | semis StatementSequence1 semis { $$ = $2; } | StatementSequence1 semis /**/ | semis StatementSequence1 { $$ = $2; } | semis { $$ = AddToStmtList(0,0); } | /* empty */ { $$ = AddToStmtList(0,0); } ; StatementSequence1: StatementSequence1 semis statement { $$ = AddToStmtList($1,$3); } | StatementSequence1 { yyerror("Missing semicolon"); } statement { $$ = AddToStmtList($1,$3); } | statement { $$ = AddToStmtList(0,$1); } ; semis: SEMICOLON | semis SEMICOLON ; -- - Joel McCormack (decwrl!joel, joel@decwrl.dec.com) -- Send compilers articles to compilers@esegue.segue.boston.ma.us {ima | spdcc | world}!esegue. Meta-mail to compilers-request@esegue.