0

I'm looking for ANTLR grammars which are ready for printing tree in readable format. When I try to print Java.g (http://openjdk.java.net/projects/compiler-grammar/antlrworks/Java.g) the results were inconvenient. But I find one grammar(including java project), which prints AST good. This grammar is Pascal grammar from Marton Papp (http://www.antlr.org/grammar/1279217060704/pascal3.zip).

Something like:

VARDECL text="Var"
       VARLIST text=""
       VAR text="a" 
       VAR text="b" 
       VARTYPE text="Integer"

it is for Pascal(pascal3.zip).

Do you ever see such things for: C, Java, C#, VB. Maybe, you see it for some other languages?

  • The required target language (of Parser and Lexer) is only Java.
Michael
  • 23
  • 1
  • 6
  • @BartKiers, You are right. It is absolutely what I mean about Java grammar. So my question is: I find fortran parser, which seems to suit conditions: http://sourceforge.net/projects/fortran-parser/ (It is written in Java). Can someone advise grammars for mentioned languages, which build real useful AST (which contains structure of program)? – Michael Nov 16 '11 at 08:24

1 Answers1

1

You can change the Java grammar yourself quite easily (assuming you know a little ANTLR). The writing of the lexer and parser grammar is the hardest part, which, in this case, has already been done for you.

If you want to know how to let a parser grammar output an AST instead of a simple parse tree, look at this previous Q&A: How to output the AST built using ANTLR?

Community
  • 1
  • 1
Bart Kiers
  • 166,582
  • 36
  • 299
  • 288
  • Your tutorial in "How to output the AST built using antlr?" is great. I think I can implement such modifications for Java.g. But, maybe, in this case, I do double work. If I need just one grammar maybe it can be done, but for: C, Java, C#, VB. I wonder, if there are no grammars, which can print AST for these languages. The question is: maybe someone see it in the world wide web? – Michael Nov 16 '11 at 10:28
  • @Михаил Фоканов, perhaps there are some AST-producing C and C# grammars out there, I don't know. However, I am pretty sure there is no ANTLR grammar for VB, and if there is, I doubt it does a decent job parsing VB source files. VB has a horrible grammar! – Bart Kiers Nov 16 '11 at 10:32