Intermediate and object code generation

25 views
Skip to first unread message

Haroun Mohammedi

unread,
Oct 27, 2017, 8:10:34 AM10/27/17
to antlr-discussion

As part of the programming assignments of our compilers related class. I've proposed to my teacher to use ANTLR instead of flex bison and here he ask me to ensure that it does all what we want, i.e lexical, syntactical and semantic analysis which I'm pretty sure that it's very easy to build such analyzer using ANTLR. but also the intermediate and object code generation phase of compilers and this is really confusing me. I've expected that such tool have to give users facilities to do such generations but I didn't find anything that explains how to do that even in the reference book written by the author.

Can anyone here explain to me how to do so or point me to the write material that can help me to convince my teacher.

Mike Lischke

unread,
Oct 27, 2017, 9:32:06 AM10/27/17
to antlr-di...@googlegroups.com

> As part of the programming assignments of our compilers related class. I've proposed to my teacher to use ANTLR instead of flex bison and here he ask me to ensure that it does all what we want, i.e lexical, syntactical and semantic analysis which I'm pretty sure that it's very easy to build such analyzer using ANTLR. but also the intermediate and object code generation phase of compilers and this is really confusing me. I've expected that such tool have to give users facilities to do such generations but I didn't find anything that explains how to do that even in the reference book written by the author.

What is actually expected as output? Parser generators generate source code. Compilation is done as an extra step which does not involve the parser generator. So, what is the "intermediate and object code" you want actually? Flex/Bison work in the same way.

And yes, you can of course create the necessary tools for lexical and syntactic analysis. Semantic analysis is a bit different. That's not a parser's task (it is by nature made to do syntactic checks). Semantic steps are usually an isolated task (e.g. walk a generated parse tree to fill a symbol table). This step is independent of the parser generator or the generated parser code.

Mike
--
www.soft-gems.net

Haroun Mohammedi

unread,
Oct 27, 2017, 9:44:37 AM10/27/17
to antlr-di...@googlegroups.com
compiler_phases.jpg

The image above explains the different phases of compilations. what I'm saying here is the first three phases can be done with ANTLR. My question is about how to process the others steps using ANTLR.

Thanks Mike.

--
You received this message because you are subscribed to a topic in the Google Groups "antlr-discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/antlr-discussion/1JMB88SD8eU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Haroun Mohammedi

unread,
Oct 27, 2017, 9:48:02 AM10/27/17
to antlr-di...@googlegroups.com
You can find the definition of the intermediate code I'm talking about in this short tutorial.

Mike Lischke

unread,
Oct 27, 2017, 9:53:16 AM10/27/17
to antlr-di...@googlegroups.com

>
> <compiler_phases.jpg>
>
> The image above explains the different phases of compilations. what I'm saying here is the first three phases can be done with ANTLR. My question is about how to process the others steps using ANTLR.

You cannot not use ANTLR for that (nor any other parser generator). They will create the lexical and syntactic analyzers, but the rest is up to you. You cannot create a full compiler with any parser generator. Parsing is only the first step in this process (and one of the smaller ones).

Mike
--
www.soft-gems.net

Haroun Mohammedi

unread,
Oct 27, 2017, 9:55:44 AM10/27/17
to antlr-di...@googlegroups.com
Many Thanks Mike.

As my understanding theses steps couldn't be done with any parser generator even flex and bison. right ?

Mike Lischke

unread,
Oct 27, 2017, 9:59:32 AM10/27/17
to antlr-di...@googlegroups.com

As my understanding theses steps couldn't be done with any parser generator even flex and bison. right ?

Exactly.
Reply all
Reply to author
Forward
0 new messages