antlr4 icon indicating copy to clipboard operation
antlr4 copied to clipboard

[Feature Request]: C target

Open davidfetter opened this issue 6 years ago • 8 comments

Antlr3 had one, and it'd be awesome if Antlr4 did, too.

davidfetter avatar Jan 04 '19 16:01 davidfetter

I'm currently working with c++ target and there are some feature requests that I'd like to see in C target:

  • parsing trees should be traversable without visitors. It means contexts should store alt number by default;
  • for each context we should generate an enum containing all alternative names so that we can later switch-case between alternatives;
  • tokens should have line and position of the last matched character;
  • C target should support memory arenas (seeing how many unnecessary allocations there are in C++ target makes me sad). It should also utilise constant views (in C++ target, many std::strings can be replaced with std::string_views. In C, it is natural to use non-owning char*s to reference strings, so this should not be an issue);
  • there should be customization points for altering error messages.

I'd also like to see CI with sanitizers and fuzzing (C++ target have some UBs and leaks that I can't properly trace).

AmatanHead avatar Jan 16 '19 09:01 AmatanHead

FYI i've started looking into how ATN works and making some drafts for C runtime.

AmatanHead avatar Jan 20 '19 16:01 AmatanHead

FYI i've started looking into how ATN works and making some drafts for C runtime.

Fantastic. Thank you!

davidfetter avatar Jan 20 '19 17:01 davidfetter

Bump :)

davidfetter avatar Mar 13 '19 05:03 davidfetter

Well I'm still on it, but things are moving quite slowly because my job takes all the time.

So far I've implemented basic support structures — list, hashmap, interval set, memory pool etc., I also have ATN classes and deserialization for them. I'm working on lexer simulator and DFA.

You can track progress in my fork. Some code review would be appreciated.

AmatanHead avatar Mar 13 '19 07:03 AmatanHead

Maybe it would be better to create C wrapper for C++ runtime implementation. I am not saying the that C target is bad idea. But considering the time required for development of the C++ target, the complexity of the implementation....

It makes me think that we should really work on single C compatible runtime. It seems to me that the C++ runtime is not finished and I am not sure when it will be done.

Nic30 avatar Mar 29 '19 00:03 Nic30

@AmatanHead, may I ask if your C target is still in progress? Your fork mentioned above is inaccessible.

JackNWhite avatar Sep 12 '22 10:09 JackNWhite

Personally, I think it is too much work and maintenance to create a C target for v4. Or I would have probably done it.

Not impossible, but there are is a lot of OOP stuff in v4 that means you either have a ton of simulation or a completely different system.

Even a link compatible C++ runtime would be work.

jimidle avatar Sep 13 '22 07:09 jimidle