"Andrej Mitrovic" <[email protected]> wrote in message news:mailman.3531.1302884207.4748.digitalmars-d-annou...@puremagic.com... > I've used your tool yesterday. I used it on a simple C file with the > ANSI C grammar from the gold website. It does seem to work fine, but > yeah I have to preprocess a C file first (I've spent so much time with > D that I almost completely forgot about the C preprocessor in the > first place). > > I've tried a file with your ParseAnything sample. It works ok as long > as all the types are defined. If not I usually get a Token exception > of some sort. Is this considered the semantic pass stage? >
Like any generalized parsing tool (AFAIK), Goldie doesn't really have a semantic stage (because language semantics isn't something that's easily formalized). Probably the C grammar just considers something in your source to be either a syntax or grammatical error. (This could be a bug or limitation in the C grammar.) Goldie currently handles syntax/grammatical errors by throwing a ParseException when it detects all the errors it can find. The message of the exception is the "filename(line:col): Error: Description of error" message that you'd normally expect a compiler to output. Most of the apps in Goldie catch this exception and just output the message, but I guess I didn't do that in ParseAnything. Of course, it could also be a bug in either ParseAnything or Goldie. Can you send one of the C files that's getting an error? I'll take a look and see what's going on. You may want to try "goldie-parse" instead of "goldie-parseAnything" (I really should rename one of them, it's probably confusing). "goldie-parseAnything" is mainly intended as an example of how to use Goldie (like the Calculator examples). "goldie-parse" is the one that outputs JSON. > Btw, is there a grammar file for C99? What about C++, I haven't seen a > grammar on the Gold website? (well, C++ is a monster, I know..). > Not that I'm aware of. But if you know the differences between ANSI C and C99 you should be able to modify the ANSI C grammar and turn it into a C99. The grammar description language should be very easy to understand if you're familiar with BNF and regex (In fact, the grammar definition langauge doesn't even use the barely-readable Perl regex syntax - it uses a far more readable equivalent instead). BTW, Tip on the grammar language: Everything enclosed in angle brackets is a nonterminal. And yea, C++ is a beast. And one of C++'s biggest issues is that, not only does it have the preprocessor, but what's worse: the parsing is dependent on the semantics pass. I'd say that any generalized parsing tool that can do C++ properly is doing an *incredibly* damn good job. > I'm also trying to figure out whether to go with the static or dynamic > approach (I've looked at your docs). The static examples seem quite > complex, but perhaps they're more reliable. I think I'll do a few > tryouts with dynamic style since it looks much easier to do. The general recommendation is to use static whenever you just have one specific grammar you're trying to deal with (because it provides better protection against mistakes). But you're right, the dynamic style may be an easier way to learn Goldie. If you haven't already, you may wat to look at the source for the calculator examples. They're both the exact same program, but one does it the static way, and the other does it the dynamic way. > If I get anything done you'll know about it. :) Cool, appreciated :)
