Discussion:
ANTLR grammars for PIM and ISO
(too old to reply)
strictly noreply
2009-05-18 09:28:32 UTC
Permalink
For comparative studies I recently created ANTLR grammars for both PIM
and ISO M2. Just in case these might be of help to anyone else, I made
them available online ...

PIM3 grammar:
http://www.sunrisetel.net/software/papers/modula2/m2pim3.g

ISO grammar:
http://www.sunrisetel.net/software/papers/modula2/m2iso.g

Both grammars follow the naming conventions and structure of the EBNF
given in PIM3 and ISO/IEC IS 10514 respectively, but those grammars
were written for documentation purposes only. They are not LL(1), nor
even LL(k), ANTLR will not validate them in this form. As time
permits, I intend to refactor them to create LL(1) versions. If and
when I get around to doing that, I will post the LL(1) versions, too.
Meanwhile the grammars can be used to generate syntax diagrams with
ANTLRworks.
strictly noreply
2009-05-19 10:38:56 UTC
Permalink
refactored LL(1) version of the PIM grammar:

http://www.sunrisetel.net/software/papers/modula2/m2pim3_LL1.g
c***@yahoo.com
2009-05-25 15:36:32 UTC
Permalink
Post by strictly noreply
http://www.sunrisetel.net/software/papers/modula2/m2pim3_LL1.g
c***@yahoo.com
2009-05-25 16:18:54 UTC
Permalink
Post by strictly noreply
For comparative studies I recently created ANTLR grammars for both PIM
and ISO M2. Just in case these might be of help to anyone else, I made
them available online ...
PIM3 grammar:http://www.sunrisetel.net/software/papers/modula2/m2pim3.g
ISO grammar:http://www.sunrisetel.net/software/papers/modula2/m2iso.g
Both grammars follow the naming conventions and structure of the EBNF
given in PIM3 and ISO/IEC IS 10514 respectively, but those grammars
were written for documentation purposes only. They are not LL(1), nor
even LL(k), ANTLR will not validate them in this form. As time
permits, I intend to refactor them to create LL(1) versions. If and
when I get around to doing that, I will post the LL(1) versions, too.
Meanwhile the grammars can be used to generate syntax diagrams with
ANTLRworks.
I believe the linked modula2 grammars correspond to the Second Edition
of "Programming in Modula-2" not the 3rd Edition.

For example, SimpleConstantExpr was simpified in the 3rd edition to be
just
expression
(on the RHS of the rule).

Also your rule for definition (module) is missing (on the RHS):
DEFINITION MODULE (and so on).

Lexical note:
Your rule for string is too restrictive in that you disallow these
legal string characters:
1) a single quote within a double-quoted string and
2) a double-quote within a single-quoted string.

The PIM3 report additionally dissallows strings crossing a line-
boundary. Your apparent referencence to ASCII and your restriction to
"printable" characters would certainly be consistent with the report
not allowing end-of-line characters within strings.

I am unable to check the grammar more thoroughly at this time, but
this will be enough for now.
Thank you for your posts.
"martin the modulan"
c***@yahoo.com
2009-05-25 17:18:57 UTC
Permalink
Post by c***@yahoo.com
Post by strictly noreply
For comparative studies I recently created ANTLR grammars for both PIM
and ISO M2. Just in case these might be of help to anyone else, I made
them available online ...
PIM3 grammar:http://www.sunrisetel.net/software/papers/modula2/m2pim3.g
ISO grammar:http://www.sunrisetel.net/software/papers/modula2/m2iso.g
Both grammars follow the naming conventions and structure of the EBNF
given in PIM3 and ISO/IEC IS 10514 respectively, but those grammars
were written for documentation purposes only. They are not LL(1), nor
even LL(k), ANTLR will not validate them in this form. As time
permits, I intend to refactor them to create LL(1) versions. If and
when I get around to doing that, I will post the LL(1) versions, too.
Meanwhile the grammars can be used to generate syntax diagrams with
ANTLRworks.
I believe the linked modula2 grammars correspond to the Second Edition
of "Programming in Modula-2" not the 3rd Edition.
For example, SimpleConstantExpr was simpified in the 3rd edition to be
just
expression
(on the RHS of the rule).
<...snip...>

Correction:
PIM3, Appendix 1, rule nr. 13
ConstExpression = expression .
was the revision I meant.

"Martin the Modulan"
strictly noreply
2009-06-22 09:00:04 UTC
Permalink
Hi, thanks for the feedback.
Post by c***@yahoo.com
I believe the linked modula2 grammars correspond to the Second Edition
of "Programming in Modula-2" not the 3rd Edition.
The only copy I had access to when I made the ANTLR grammars was a
German copy of PIM3. I checked this copy this week again and it claims
to be a translation of the "third, corrected edition", there are ISBN
numbers: 3-540-13301-1 and 0-387-13301-1.

I have compared the grammar against ISBN 0-387-15078-1 which also
claims to be "third, corrected edition" but is in English and surprise
surprise, the grammars are different.

The grammar in ISBN 3-540-13301-1 would seem to be at a stage in
between PIM2 and ISBN 0-387-15078-1.

Anyway, I have revised the ANTLR LL(1) grammar accordingly (to follow
ISBN 0-387-15078-1 which seems more recent).

The revised grammar file is at the same URL as before:

http://www.sunrisetel.net/software/papers/modula2/m2pim3_LL1.g

However, I haven't had the time to revise the original non-LL(1)
version yet.
Post by c***@yahoo.com
DEFINITION MODULE (and so on).
yes, indeed, fixed now, thanks.
Post by c***@yahoo.com
Your rule for string is too restrictive in that you disallow these
1) a single quote within a double-quoted string and
2) a double-quote within a single-quoted string.
The PIM3 EBNF does not actually match its textual description and I
forgot to amend the grammar, fixed now, thanks.
Post by c***@yahoo.com
The PIM3 report additionally dissallows strings crossing a line-
boundary. Your apparent referencence to ASCII and your restriction to
"printable" characters would certainly be consistent with the report
not allowing end-of-line characters within strings.
ANTLR3 is Java based and like Java it considers all characters to be
unicode, so there would be an opportunity for an actual ANTLR based
implementation to add unicode support, but when PIM3 was published
there was no such thing, so I left it at ASCII.
Post by c***@yahoo.com
I am unable to check the grammar more thoroughly at this time, but
this will be enough for now.
Thank you for your posts.
You're welcome
thanks again for the feedback.
BK [noreply/posting only]
2009-07-08 08:19:58 UTC
Permalink
The ANTLR grammars for Modula-2 have now been moved to http://modula2.net

- PIM grammar: http://modula2.net/resources/m2pim3.g
- PIM LL(1) grammar: http://modula2.net/resources/m2pim3_LL1.g
- ISO Modula-2 grammar: http://modula2.net/resources/m2iso.g

The old URLs at sunrise are being redirect to the new ones, but if you
have linked to these files on your website, please update the links
accordignly, thanks.
BK [noreply/posting only]
2009-07-10 08:37:00 UTC
Permalink
I added two more grammars today ...

- PIM4 grammar:
http://modula2.net/resources/m2pim4.g

- LL(1) version of the PIM4 grammar:
http://modula2.net/resources/m2pim4_LL1.g

NB: the EBNF in the appendix of PIM4 is identical to that of PIM2.
Loading...