DonnellyOverflow
DonnellyOverflow

Reputation: 4195

ANTLR for IntelliJ 15

I am trying to use the ANTLR4 plug-in for IntelliJ to create a simple expression analyzer. I have seen a few websites and questions but I don't seem to be able to get it running. I have watched this video but I still get an error

Can't load hello as lexer or parser

Does anyone have a way of using ANTLR to create a grammar and then using standard input or a text file input to test the grammar and print out. I am trying to take an infix expression and convert it to a postfix expression.

Also is there a way to use ONLY intellij to write, compile and run the program rather than swapping to the command line?

Thank you.

Upvotes: 2

Views: 671

Answers (1)

ssinai
ssinai

Reputation: 61

I ran into the same problem. I installed the ANTLR plugin for IntelliJ 15. I created an Java project called Antlr, and created the example Hello.g4 text file by right-clicking on the src directory node and selecting New->File. Once the grammar was typed into Hello.g4, I compiled it by right-clicking on the Hello.g4 tab and selecting Compile "Hello.g4", which created the template files in directory "gen".

I wasn't able to figure out how to run the grun example in the Antlr4 reference, where "hello parrt" was parsed and analyzed. Instead, it turns out that if you right click on the rule ('r') in Hello.g4, there is an option called "Test Rule r". Select that, and you get a couple of small windows at the bottom of the IDE. You can either type in "hello parrt" and it will parse it; or create a new text file by right clicking on the src directory node and selecting New->File, add "hello parrt" to the file, compile that file which will put it in the production/Antlr directory, and then right click on the rule ('r') again to select "Test Rule r'. Then you'll see the parse tree to the right.

Upvotes: 1

Related Questions