Reputation: 441
So on macOS I have ANTLR4.7 installed and in the directory that antler is installed in I defined my own grammar like so:
$ cd cd /usr/local/lib
$ mkdir HelloDir
$ cd HelloDir
$ nano Hello.g4
I paste this code in the 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
And than I saved the file
Then I create the classes:
$ antlr4 -Dlanguage=Swift Hello.g4 //the files are generated successfully
After this I try to see what I created:
$ grun Hello r -tree
And this is the point when the error message ruins my day:
Can't load Hello as lexer or parser
The problem might be obvious but I'm new to ANTLR. So what is the problem what am I missing?
Upvotes: 0
Views: 1569
Reputation: 10863
Make sure you have a "." in your CLASSPATH. Usually it will be something like this:
.;C:\etc\etc\javalib\antlr-xxx.jar
Upvotes: 1
Reputation: 7409
Your syntax is correct so it suggests that you don't have something installed correctly. You're likely missing dependencies and in nano there's no convenient way to set them up. I don't use the swift target, but there are detailed instructions here on using XCode to do your setup, dependencies, and project files. I'd recommend you try that github resource; it also contains several caveats and tips to get better performance through optimization settings in release mode.
Upvotes: 0