How to run g4 file using ANTLR4 plugin in Eclipse

I installed the ANTLRv4 plugin for my Eclipse and I created the Hello.g4 file:

/**
 * Define a grammar called Hello
 */
grammar Hello;

r  : 'hello' ID ;         // match keyword hello followed by an identifier

ID : [a-z]+ ;             // match lower-case identifiers

WS : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines

How to run this g4 file in Eclipse and how to view the parse tree?

+4
source share
1 answer

Using the ANTLR plugin works in two steps: first, you compile the file .g4to create code .javafor lexer / parser / visitor / listeners ..., then if you open Parse Tree.

xtext, : , configure->Add Xtext nature. , , ANTLR4. .

, .g4 ( ANTLR, ), .

Parse Tree, Window->Show View->Other...->ANTLR4->Parse Tree. . , ANTLR Editor Parse Tree . ANTLR, , , Parse Tree . .

, : Parse Tree and grammar in ANTLR4 Eclipse Plugin

+3

All Articles