0

TextX is a DSL (Domain-Specific Languages) parser simular to ANTLR4. In the TextX tutorial, it demonstrates how to create a meta-model from the grammar file.

For example, given this grammar:

Entity:
    'entity' name=ID '{'
        properties+=Property
    '}'
;

Property:
    name=ID ':' type=ID
;

It generates a graphical representation of the meta-model:

enter image description here

How can I generate the meta-model of ANTLR v4 grammar files? The meta-model should be a graph structure - does not have to be graphical. And a bonus to someone who can do it in Python.

joshlk
  • 1,499
  • 3
  • 20
  • 33
  • Take a look at [this post](https://stackoverflow.com/questions/29971097/how-to-create-ast-with-antlr4) describing how to build an abstract syntax tree from the context classes generated by Antlr. That seems to be an equivalent to textX Metamodels, although textX introduces some [basic types](http://textx.github.io/textX/latest/grammar/), which antlr has not. There's a [python target](https://github.com/antlr/antlr4/blob/master/doc/python-target.md) available for antlr. – Curiosa Globunznik Oct 30 '19 at 16:42
  • I would be interested to learn what such a meta model could be used for. – Mike Lischke Nov 01 '19 at 09:35
  • What I think you want is a dependency graph of the nonterminals of a grammar (see Zheng and Chen. "A systematic framework for grammar testing." In 2009 Eighth IEEE/ACIS International Conference on Computer and Information Science, pp. 1013-1019. IEEE, 2009.) This would be useful in a number of analyses, e.g., unreachable nonterminals, partitioning of the grammar for testing. It's likely there is no dependency graph generator for Antlr. Writing one would require understanding the details of the code generator. But if understood, it would be easy to output a Dot graph. – kaby76 Nov 05 '19 at 12:15

0 Answers0