Patrick Wright a écrit :
> Just saw this project http://code.google.com/p/cookcc/
> "CookCC is a lexer and parser generator project, combined. It is
> written in Java, but the target languages can vary. It uses a template
> approach to generate source codes, so it is quite easy to add a new
> target language. CookCC also comes with a suite of test cases to
> assist creating and testing new target languages.
>
> The current release is 0.3.1.
>
> A unique feature of CookCC is allowing lexer/parser to be specified
> using Java annotation. This feature greatly simplifies and eases the
> writing of lexer and parser for Java."
>
> As expected, the simple example looks simple, and rather pleasing:
> http://code.google.com/p/cookcc/source/browse/trunk/tests/javaap/calc/Calculator.java
>
> Neat use of annotations, IMO.
>
Funny, i've started my own parser generator (Tatoo) four years ago with
the same approach:
@Rule (lhs = "stmt", rhs = "'{' stmt_list '}'", args = "2")
was
@Production (left = "stmt", right = "'{' ~stmt_list '}'")
~ was used to indicate which argument can be get.
We throw this approach 3 months later because
- it's not really readable thus difficult to debug :)
- the Java type of each non-terminal must be the same and with this format
that type is repeated on each method that defines a rule containing
the non-terminal.
- there is a third point but i'm not able to recall it now :(
So we decide to write grammars as we used to :)
And to link the grammar to the semantics, we add a name at the end of
each production
(between curly braces) and a way to declare the type of each terminal
and non-terminal at one place.
Here is an example of a calc :
http://gforgeigm.univ-mlv.fr/scm/viewvc.php/trunk/samples/calc-ast/calc.ebnf?root=tatoo&view=markup
and it's generate an interface that you can implement to provide the
semantics.
http://gforgeigm.univ-mlv.fr/scm/viewvc.php/trunk/samples/calc-ast/src/fr/umlv/tatoo/samples/calc/IntGrammarEvaluator.java?root=tatoo&view=markup
Using annotations instead of a DSL is not in my opinion a good idea,
at least until annotations are String based.
> Patrick
>
Rémi
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "JVM
Languages" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/jvm-languages?hl=en
-~----------~----~----~----~------~----~------~--~---