Possibility of grammars transpilation #4889
Answered
by
jimidle
GreedIsGood10000
asked this question in
Q&A
Replies: 2 comments 2 replies
-
Have you tried using LLM-based solutions for this? |
Beta Was this translation helpful? Give feedback.
1 reply
-
You generate an IR of your own choosing that represents a generic form but
can represent both. After generating an IR, then you run transformations on
the IR/AST to convert concepts for A to their representation in B. Usually
you execute rules one at a time on the IR, replacing/moving nodes until
done. Then you walk the IR and generate the B text code.
If very simple, then you might be able to just build the IR for B directly
while walking the parse tree from grammar A. Then just walk the IR you
produce and generate B output. A 100% conversion requires that semantics
and constructs in A can be represented by B.
…On Thu, Sep 18, 2025 at 08:00 GreedIsGood10000 ***@***.***> wrote:
No, LLMs will be overkill for my task. Grammars of mentioned languages are
not very complex, so in the worst case I could write transpilation
algorithm by hand.
Another restriction is that transpile algorithm must generate predictable
result code and make some edits in AST, like adding variable's values
checks.
I just think of simplifying my task by generating both grammars and using
pregenerated code.
Maybe, in future I'll have to make transpile from grammar B to A, so
building AST will be even more useful
—
Reply to this email directly, view it on GitHub
<#4889 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJ7TMGGLQHL3PQL76RXDG33TK3IBAVCNFSM6AAAAACGYGEH5OVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTINBUGQYDAOA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
GreedIsGood10000
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I have a task to transpile code from language grammar A to grammar B.
If, lets say, I have g4 files with grammar of both languages, can I generate AST of grammar B using AST of A?
More specific, can I build ANTLR syntax tree by code?
Beta Was this translation helpful? Give feedback.
All reactions