Dustin Oprea
Dustin Oprea

Reputation: 10236

Writing an ANTLR target

Where is the process of creating a new language target for ANTLR discussed? Though it seems like it was some common knowledge with ANTLR3 due to the number of targets that were available, I'm not seeing any documentation bundled in the source-code, nor have I found any obvious places with Google.

I'd expect to not find any such documentation for ANTLR4, but I'm not seeing any, at all.

Upvotes: 2

Views: 401

Answers (2)

Sam Harwell
Sam Harwell

Reputation: 99869

The process for ANTLR 3 and ANTLR 4 are completely different.

  • ANTLR 3
    • Most processing is performed by the ANTLR tool, so the runtime is pretty simple.
    • Source code for multiple targets is stored as part of the main ANTLR 3 repository.
  • ANTLR 4
    • Most processing is performed by the ANTLR runtime, so the runtime is a deceptively small amount of intricate, delicate, extremely performance-sensitive source code. Even a slight alteration in the choice of a hash code or data structure can mean an O(n³) or worse difference in speed or memory usage.
    • Targets are independently developed and maintained, and not stored in the main ANTLR 4 repository at all.

One approach, but probably not the only approach, can be inferred from the source control history for the C# target. Beyond that, you should have an excellent understanding of the data structures available and used both in Java and your target language. The runtime algorithms are extremely sensitive to things like the way hash codes are calculated and used for storing objects in maps, so the behavioral semantics of the Java target would need to be preserved in exact detail, even if that means the resulting code does not look like the Java target.

Upvotes: 2

Bart Kiers
Bart Kiers

Reputation: 170158

At the time of this writing, there is no guide how to create a new ANTLR target. Sam Harwell, co-autor of ANTLR4, and author of the C# target, has started making notes on how to create a new target, but it's not complete (yet).

One interested in writing a new target could look how the C# is implemented (and the original Java target of course). But realize it is by no means a trivial task!

Upvotes: 1

Related Questions