ANTLR platforms and grammar files

229 views
Skip to first unread message

ViCu

unread,
Jul 11, 2014, 6:50:04 AM7/11/14
to antlr-di...@googlegroups.com
hello,
I am new in the language parsing world, some weeks ago I discovered some libraries, one of them being ANTLR, being
interested in parsing c / c++ source code files , to fetch functions, variables, calsses , list etc.
corrently I found several ANTLE versions, one of them being implemented in c++ , refeering to file antlr3.2_cpp_parser4.1.0.zip .
I have comiled this one but no results obtained.
Therefore I would like to get update on the topic to know about ANTLR on which platform was implemented until now ( c# , java, c++ ) and which are the parsing capabilities  in terms of languages, especially c ansi and c++ grammars, which are my interests.
 
Thank You Very Much
Best Regards

Bence Erős

unread,
Jul 11, 2014, 7:51:14 AM7/11/14
to antlr-di...@googlegroups.com
Hello,

the actively developed version of antlr is antlr4 (4.3 is the latest release). It primarily generates java parsers (but afair c++ and python targets are under development too).
Sample grammar files are available in this repo: https://github.com/antlr/grammars-v4
It contains a C grammar file.


--
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.



--
Bence Erős
CyclonePHP
core developer

ViCu

unread,
Jul 11, 2014, 8:22:53 AM7/11/14
to antlr-di...@googlegroups.com
 
Hello,
 
On the antlr website I saw that there are java and c# implementations. I also mya try to work with one of these variants, however I saw that many jaca and c# projects may present unresolved dependencyies. In java sometimes can be a problem with the current eclipse version. (java wanted to be portable but stuck in versioning issues ). Similar issue could be in c# too. In this context, I would like to ask which eclipse I should use, or viceversa if Eclipse SDK Version: 4.2.2 is supported. For c# I am currently usinv Visual Studio Express 2012.
Regarding grammar, I would like to know if a c++ file will be available. Recall, in ANTLR cpp , available via ( http://www.antlr3.org/ ) website.
I have found some gramatic files ( antlr3.2_cpp_parser4.1.0\CPP_grammar_.g  , CPP_parser_v_3.2\CPP_parser.g  ) but I do not know if these are compatible with the version I reffer to.
 
br, Victor

Bence Erős

unread,
Jul 11, 2014, 8:35:57 AM7/11/14
to antlr-di...@googlegroups.com
antlr itself has nothing to do with eclipse. There is an eclipse plugin called antlr IDE, that worked for me with eclipse kepler.
About the c++ grammar: the grammar file you referred to is most probably an antlr3.2 grammar file, which means it won't work with antlr4 (note: antlr3 grammar files usually have .g extension, antlr4 grammar is .g4)
In the grammars repo no c++ grammar seems to be present, so probably you will have to develop your own one for antlr4 (which seems to be a quite complicated task), or you may use antlr3.2 (which is a totally different system)

ViCu

unread,
Jul 11, 2014, 9:29:20 AM7/11/14
to antlr-di...@googlegroups.com
 
So, then regarding ANTLR versions:
 
1) first, I would try a c# ariant, and afterwards a java one. However I am realy confused due to the following requirement within c# variant:
"The C# target for ANTLR 4 requires Java for *compiling* applications. " Realy, cannt be developed someting pure in c# ? it is realy needed this mixture ?
What meens compiling applications ?
 
2) Second, regarding gramatics, is there no posibility to convert the g files ? Are only sintactic differences or semantic /structure as well ? I take a short look, but now I cannot evaluate the type and size of those differences. For a while c gramm. would be enought , however the problem of having a java / c# framework ends up in a being a annoing task.

Bence Erős

unread,
Jul 11, 2014, 9:49:42 AM7/11/14
to antlr-di...@googlegroups.com
2014-07-11 15:29 GMT+02:00 ViCu <victor....@googlemail.com>:
 
So, then regarding ANTLR versions:
 
1) first, I would try a c# ariant, and afterwards a java one. However I am realy confused due to the following requirement within c# variant:
"The C# target for ANTLR 4 requires Java for *compiling* applications. " Realy, cannt be developed someting pure in c# ? it is realy needed this mixture ?
What meens compiling applications ?

The ANTLr parser generator itself is implemented in java, but it is able to generate C# parsers (meaning a parser "written" in C#, which parses whatever language, defined by the g4 file passed for antlr). By "compiling applications" the author probably means generating the parser.
In other words, you need java installed to execute the parser generator, which generates C# source files (the generated parser). Then you can use the generated parser from C# applications. But if you change the .g4 file, then you need antlr again (therefore java too) to re-generate your C# parser.

This "mixture" is needed because the developers are not likely to implement the same software in two different languages.
 
 
2) Second, regarding gramatics, is there no posibility to convert the g files ? Are only sintactic differences or semantic /structure as well ? I take a short look, but now I cannot evaluate the type and size of those differences. For a while c gramm. would be enought , however the problem of having a java / c# framework ends up in a being a annoing task.

I've never used antlr3, but as far as I know antlr3 and antlr4 are conceptually totally different systems, therefore converting a .g file to a .g4 file doesn't sound like a trivial task.
Reply all
Reply to author
Forward
0 new messages