There are two methods for building ANTLR parsers.
This method allows more control form the command line.
- Download and install Java
- Download the Antlr-4 Tool from the Antlr Download page
- move the Antlr4 jar file to a project sub folder, usually an
antlr
folder within the project. - add a post-build step to execute Antlr and create the lexer & parsers
e.g.:
java -jar $(SolutionDir)antlr\antlr-4.13.0-complete.jar -o Parser -visitor -Dlanguage=CSharp $(ProjectDir)\YourLexer.g4
java -jar $(SolutionDir)antlr\antlr-4.13.0-complete.jar -o Parser -visitor -Dlanguage=CSharp $(ProjectDir)\YourParser.g4"
Add the ANTLR4BuildTasks from Nuget for VS2022
Do not install any other Antlr Build package, including the 'official' tooling. It's 3 years out of date and no longer updated.
VSCode has a handy extension for syntax highlighting & graphing tools to inspect the Antlr4 Grammars.
ANTLR4 grammar syntax support
v2.3.1
Mike Lischke
// Example code so far
var myval = 1;
if ( myval == 1 ) {
print "If is TRUE!";
return true;
print "UNREACHABLE - SHOULDN'T DISPLAY!";
}
else
{
print "if is FALSE!";
}
var MyVar1 = (5+4)+10;
var MyVar2 = "Hello";
var MyVar3 = "World";
var MyVar4 = $"Interpolated : {MyVar2}, {MyVar3}";
print $"String interpolation says {MyVar2} {MyVar3}";
print MyVar4;
var database = "sqldb-daprservice";
// Single line comment for connection string.
connection $"Data Source=.\;Integrated Security=SSPI;Initial Catalog={database};MultipleActiveResultSets=True;Encrypt=false;TrustServerCertificate=true";
// do some db commands
/* MULTI line comment for local Database connection details.
Database : sqldb-receipt-service
User : dapruser
Password : ySwp0aGAmhI1jns0wgkb5zmH9iuW7AMQ
*/
print $"Connection String = {connection}"; // Auto creates internal symbol for connection string.
print "Done.";
/*
MULTI line comment for local Database connection details.
Creating Database : sqldb-receipt-service
Creating User : dapruser
- Password : ySwp0aGAmhI1jns0wgkb5zmH9iuW7AMQ
Creating Server user : dapruser
Setting db_owner : dapruser
*/
Read the getting started documentation on github, or the MEGA tutorial on the language engineering website Strumenta.
Get The Definitive ANTLR 4 Reference from Amazon