Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!math.lsa.umich.edu!math.lsa.umich.edu!emv From: joel@decwrl.dec.com Newsgroups: comp.archives Subject: [comp.compilers] Re: Can Pascal be parsed by LR(1) parsing algorithm? Keywords: pascal, parse Message-ID: <1990Oct10.213248.11277@math.lsa.umich.edu> Date: 10 Oct 90 21:32:48 GMT Sender: emv@math.lsa.umich.edu (Edward Vielmetti) Reply-To: joel@decwrl.dec.com Followup-To: comp.compilers Organization: DEC Western Research Laboratory Lines: 54 Approved: emv@math.lsa.umich.edu (Edward Vielmetti) X-Original-Newsgroups: comp.compilers Archive-name: modula-2-grammar/10-Oct-90 Original-posting-by: joel@decwrl.dec.com Original-subject: Re: Can Pascal be parsed by LR(1) parsing algorithm? Archive-site: gatekeeper.dec.com [16.1.0.2] Archive-directory: /pub/DEC/Modula-2 Reposted-by: emv@math.lsa.umich.edu (Edward Vielmetti) 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.