merging multiple AST

36 views
Skip to first unread message

Bill Dickenson

unread,
Apr 12, 2019, 10:19:17 AM4/12/19
to antlr-discussion
Relatively new to ANTLR4

When I have an application that has both Java and SQL or for that matter, any mixed language application, how do I link the AST so when I run consistency and error checks, I can follow a data element from the database all the way through the program ? The goal is to be able to identify a column and see where its used and how. That will include the size and type of the data element.  Is there a clever option I am just not seeing ?

Thank you

Adrian Sutherland

unread,
Apr 16, 2019, 2:26:51 PM4/16/19
to antlr-di...@googlegroups.com
My 2 pence - you could either 
- use the Lexer modes and have a Uber Grammar for all your languages (cunning), or
- link the node in the parent tree to the root of a child tree (e.g. by using a hashmap) - that's how I handle includes.

A


--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--

Bill Dickenson

unread,
Apr 16, 2019, 8:50:45 PM4/16/19
to antlr-discussion
I was afraid of that. I was probably going to have to define an uber output form anyway ( LLVMs IR ?) or KDM. Thanks


On Tuesday, April 16, 2019 at 1:26:51 PM UTC-5, Adrian Sutherland wrote:
My 2 pence - you could either 
- use the Lexer modes and have a Uber Grammar for all your languages (cunning), or
- link the node in the parent tree to the root of a child tree (e.g. by using a hashmap) - that's how I handle includes.

A


On Fri, 12 Apr 2019 at 15:19, Bill Dickenson <b50...@gmail.com> wrote:
Relatively new to ANTLR4

When I have an application that has both Java and SQL or for that matter, any mixed language application, how do I link the AST so when I run consistency and error checks, I can follow a data element from the database all the way through the program ? The goal is to be able to identify a column and see where its used and how. That will include the size and type of the data element.  Is there a clever option I am just not seeing ?

Thank you

--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-di...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Adrian Sutherland

unread,
Apr 17, 2019, 3:12:06 AM4/17/19
to antlr-di...@googlegroups.com
No probs

I am working on an ancient language which has embedded SQL; it basically builds up the SQL string, including any string values (concatenated) and then calls executesql; the usual antipattern.

So if I wanted to parse the SQL (which I might have to for dull reasons to do with its weird pre. SQL data design), I would have to create the string by adding dummy  values (or ":field") and then parse it, and build up its symbol table, cross reference to the main symbol table etc etc. Hope I managed to explain this!

What I am saying is that you may not be able to do what you want with an uber grammar ...

Llvm is awesome, but emitting c++ (or whatever) is much easier (read less work)!

A

To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.

Bill Dickenson

unread,
Apr 17, 2019, 8:58:24 AM4/17/19
to antlr-discussion


On Wednesday, April 17, 2019 at 2:12:06 AM UTC-5, Adrian Sutherland wrote:
No probs

I am working on an ancient language which has embedded SQL; it basically builds up the SQL string, including any string values (concatenated) and then calls executesql; the usual antipattern.

So if I wanted to parse the SQL (which I might have to for dull reasons to do with its weird pre. SQL data design), I would have to create the string by adding dummy  values (or ":field") and then parse it, and build up its symbol table, cross reference to the main symbol table etc etc. Hope I managed to explain this!

What I am saying is that you may not be able to do what you want with an uber grammar ...

Llvm is awesome, but emitting c++ (or whatever) is much easier (read less work)!



Sounds exactly like what I am seeing. Following an data element through its life. And I have at least 5 languages on the list but fortunately, not a lot of COBOL and JAVA and SQL at the same time.  If you feel so inclined, i would love to see how you did it.

I agree with the comment on uber grammar. Its also probably much faster to parse seperately then link the symbol tables.  But for my own sanity, I need to have common "output" . I wont have to compile but I will need to have equivalent grammar.

So again, anything you can share, please do. We will do the same !

A

On Wed, 17 Apr 2019, 01:50 Bill Dickenson, <b50...@gmail.com> wrote:
I was afraid of that. I was probably going to have to define an uber output form anyway ( LLVMs IR ?) or KDM. Thanks

On Tuesday, April 16, 2019 at 1:26:51 PM UTC-5, Adrian Sutherland wrote:
My 2 pence - you could either 
- use the Lexer modes and have a Uber Grammar for all your languages (cunning), or
- link the node in the parent tree to the root of a child tree (e.g. by using a hashmap) - that's how I handle includes.

A


On Fri, 12 Apr 2019 at 15:19, Bill Dickenson <b50...@gmail.com> wrote:
Relatively new to ANTLR4

When I have an application that has both Java and SQL or for that matter, any mixed language application, how do I link the AST so when I run consistency and error checks, I can follow a data element from the database all the way through the program ? The goal is to be able to identify a column and see where its used and how. That will include the size and type of the data element.  Is there a clever option I am just not seeing ?

Thank you

--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-di...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--

--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-di...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages