0
votes

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.
1
@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: 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

1 Answers

1
votes

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?