Related articles |
---|
Can Pascal be parsed by LR(1) parsing algorithm? amb@apple.com (A. Michael Burbidge) (1990-10-09) |
Re: Can Pascal be parsed by LR(1) parsing algorithm? mauney@eos.ncsu.edu (1990-10-10) |
Re: Can Pascal be parsed by LR(1) parsing algorithm? hankd@dynamo.ecn.purdue.edu (1990-10-10) |
Re: Can Pascal be parsed by LR(1) parsing algorithm? joel@decwrl.dec.com (1990-10-15) |
Can Pascal be parsed by LR(1) parsing algorithm? meissner@osf.org (1990-10-10) |
Re: Can Pascal be parsed by LR(1) parsing algorithm? KARSTEN@tfl.dk (Karsten Nyblad, TFL, Denmark) (1990-10-10) |
Re: Can Pascal be parsed by LR(1) parsing algorithm? bliss@sp64.csrd.uiuc.edu (1990-10-10) |
Re: Can Pascal be parsed by LR(1) parsing algorithm? lindsay@comp.vuw.ac.nz (1990-10-16) |
Re: Can Pascal be parsed by LR(1) parsing algorithm? rekers@cwi.nl (1990-10-16) |
Re: Can Pascal be parsed by LR(1) parsing algorithm? firth@sei.cmu.edu (1990-10-17) |
[8 later articles] |
Newsgroups: | comp.compilers |
From: | joel@decwrl.dec.com |
Keywords: | pascal, parse |
Organization: | DEC Western Research Laboratory |
References: | <9010091533.AA02386@apple.com> |
Date: | Wed Oct 10 16:41:12 1990 GMT |
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)
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.