How to run g4 file by ANTLR4 plugin in Eclipse -
i installed antlrv4 plugin eclipse , created file hello.g4 :
/** * define grammar called hello */ grammar hello; r : 'hello' id ; // match keyword hello followed identifier id : [a-z]+ ; // match lower-case identifiers ws : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines
how can run g4 file in eclipse , how view parse tree ?
the use of antlr plugin works in 2 phases: first, compile .g4
file in order produce .java
code lexer/parser/visitor/listeners..., if open parse tree
window.
to that, project must have xtext nature, if nature not enabled: right click on project, configure->add xtext nature
. once nature enabled, in project properties, should see antlr4
entry. can configure special options project here.
each time save modifications on .g4
(if have opened antlr editor given plugin), trigger recompilation of files.
to open parse tree
window, select window->show view->other...->antlr4->parse tree
. open window. now, have keep in mind antlr editor , parse tree window communicate. in antlr editor, if put cursor on rule, see parse tree view updates part of screen , shows rule have selected. can type expression , see parse tree.
here obtain using grammar:
Comments
Post a Comment