Looking for Help with C++ Grammar

157 views
Skip to first unread message

jasonp

unread,
May 26, 2012, 1:01:35 PM5/26/12
to GOLD Parsing System
Hi All,

I have been working on a C++ grammar in Gold Parser for awhile now. I
have a working version, however, there are a few issues:

1. Reduce Conflicts - There are a few reduce conflicts I cannot seem
to resolve.
2. 'Hard-coded' User-Defined Types - For Parameters, Function IDs, and
Variables, I am using 1-to-many <Qualified IDs> to represent User-
Defined Types. There should be a better way of doing this.

Note that what I found out about pre-processors is what Devin has been
saying for awhile now: Handle pre-processors in a separate grammar so
only #includes are being parsed. I am currently writing a C# routine
which will stub out any conditional pre-processors as well as #define
Macros or 'variables'.

I am willing to pay for this help but I would rather have this grammar
available to everyone in the Gold Parsing Community.

If you are interested in helping via free or paid, please let me know
and I can supply my version of the C++ Grammar as well as contracts if
going the paid route.

Jason

keeskwekkeboom

unread,
Jun 3, 2012, 4:43:54 AM6/3/12
to GOLD Parsing System
@2. it might be easier to separate the qualified IDs and distinguish
parameter qualified ids, function qualified ids etc. Because this
makes error checking in later stages of the compiler easier. (or do
you only want a parser?)

jasonp

unread,
Jun 8, 2012, 2:07:47 PM6/8/12
to GOLD Parsing System
That is a good idea! Thanks for the help. One thing that might make
this process even easier is that I modified the ANSI-C grammar that is
available on the site. I am starting to wonder if it would be better
to look at other grammar files like C# or Java. The reason being is
there are a lot of rules which rely on the <Expr> rule. Of course this
is the same for C# and Java but its broken down into a more "readable"
format in my mind.

Thanks again,

Jason

keeskwekkeboom

unread,
Jun 11, 2012, 5:19:33 AM6/11/12
to GOLD Parsing System
I find C# expressions and ANSI-C expressions are almost equal
according to the grammars on the website. Only the names differ.
It might be useful to check existing BNF grammars for c++, e.g.
http://www.nongnu.org/hcb/

jasonp

unread,
Jun 12, 2012, 2:16:37 PM6/12/12
to gold-pars...@googlegroups.com
I did also look at some C++ BNF grammars.
 
Some of the grammars are useful while others are just not right. I did look at the link you referenced and it has helped in certain situations. From another comment on the GOLD Parser Yahoo pages, it looks like some of the reduce conflicts cannot be avoided for some context-free languages like C++. Especially with how many updates and configuration changes were made to it. What I will do is attach the current C++ grammar file (Gold Parser Grammar) I have once I get to my home pc. It honestly is fairly solid. A few issues here and there but the main issue I have with this is using the .NET COOK implementation vs. Calitha where if an error is encountered while parsing, there is no eligent recovery.
 
Calitha did implement this functionality by stepping through the parser until it would recover. I am currently looking at the COOK engine source and attempting to create a very useful recovery which I think makes sense: Clear the current reduction and go to the next line. Kind of like a rinse and repeat process. This will handle the few cases the parser cannot meet.
 
The biggest issue I have seen in the grammar is the Template Terminal. It can play some funky things to conditions (which was fixed, but now messes up #include Template rule).
 
I will add notes to the grammar before attaching it.
 
Thanks,
 
Jason

jasonp

unread,
Jun 13, 2012, 9:19:08 PM6/13/12
to gold-pars...@googlegroups.com
Attached is the work  done for C++.

Here are the following issues:

1. templates. Need a clearer understanding of C++ templates ( I am a current ANSI-C developer and have spent years developing C# so not all the way clear with C++). Also issues with pointer references have caused some issues with templates.

2. extern "C" <Qualified ID> ... Again, clearly understanding C++ better would help. 

Besides those two issues, I have had very little issues with this grammar.

Jason
C++ Grammar.grm
Reply all
Reply to author
Forward
0 new messages