I am trying to use ANTLR to create understand how grammar works. I have started playing with ANTLR and created a simple addition program. Below is my simple grammar.
grammar addition;
expr: NUMBER PLUS NUMBER;
NUMBER: [0-9]+
PLUS: '+';
SPACE
: ' ' {skip();};
This grammar works perfect for input like "1+1". But what I am trying to do is to generate below C# code for input "1+1":
var a = 1;
var b = 1;
Console.WriteLine(1+1);
When I researched, I found that I can use string templates with ANTLR C#. I tried exploring them but didn't find much help. The documentation is a little hard to understand. Can somebody please tell me or provide some study references through which I will be able to know how to use string templates with ANTLR.
Add Package StringTemplate4 from nuget:
A Minimal example:
output:
you can find a detailed documentation in using StringTemplat4 in project site: