简体   繁体   中英

ANTLR print tree

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.

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM