[antlr-interest] C++ Grammars

Ludwig Maes ludwig.maes at gmail.com
Fri Mar 9 15:38:23 PST 2012


Yes, I have

I found 2 lineages: the one from sun and the much more recent one.
The last one has actions in C++, and the mixture of grammar and
actions is still quite confusing for me beyond basic examples...
(pretty new to both formal language grammars and parsing and antlr)

I have converted the xml from http://savannah.nongnu.org/projects/hcb/

which is also prettyfied on http://www.nongnu.org/hcb/

and seems to stem from http://www.open-std.org/jtc1/sc22/open/n2356/
(this is very useful for me in the complementary sense, but I am not
that acquainted with how compilers work)
also for example there are no rules for comments in the grammar above,
this text explains the comment skipping in words, as being during the
preprocessing phase,... but the grammar contains preprocessor rules,
so Im not completely satisfied (its not clear to me when exactly the
rules for comments are used in perspective with the specific
preprocessing rules... or rather why some preprocessing rules are
present and others are not)

I converted the xml to antlr grammar notation a few hours ago (mostly
by hand/ text editor replace all commands, I did not have the heart to
write an xml parser that would deal with ">" 's within content etc). I
turned the hyphens into underscores, and resolved the simpler left
recursions... theres still some problems though (right now every rule
is lowercase parser rule, Im still a bit confused on the 2x2 double
dichotomy of terminals/nonterminals and lexer/parser rules and perhaps
literals/nonliterals); then theres an undefined rule in the xml:
alignment-expression (or alignment_expression in the .g); a few more
complex left recursions; and errors when I try to check the grammar
(im using the antlrworks IDE). Right now I have not yet added any
actions.

Some of the rules are described as a sentence instead of a grammar
rule, as per the source.

I should probably add a GPLv2+ header as the xml was under such
license, I have no experience with licensing stuff so if anyone knows
how to properly include the header that would be welcome.

I have 1 strange error and 6 warnings in the IDE, any help would be appreciated!

See cpp.g in attachment

Friendly regards

On 9 March 2012 21:37, David Wigg <wiggjd at bcs.org.uk> wrote:
> In response to this message, has Ludwig looked at the C++ grammars
> already on the antlr website?
>
> Message: 1
> Date: Fri, 9 Mar 2012 04:10:16 +0100
> From: Ludwig Maes <ludwig.maes at gmail.com>
> Subject: [antlr-interest] found a c++ grammar xml, convert to antlr
>       grammar?
>
> David Wigg
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cpp.g
Type: application/octet-stream
Size: 32657 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20120310/3aad4e29/attachment.obj 


More information about the antlr-interest mailing list