Let’s say I have a grammar file with this code.
// START:members
@header {
using System.Collections.Generic;
}
@members {
public static Dictionary<string, string> memory = new Dictionary<string, string>();
}
ANTLR puts the code in Parser like this.
public partial class Eval : TreeParser
{
...
/** Map variable name to Integer object holding value */
//HashMap memory = new HashMap();
Dictionary<string, int> memory = new Dictionary<string, int>();
Is there way to put the code in Lexer not Parser with ANTLR?
@headerand@membersis short for@parser::headerand@parser::membersrespectively.To put code in the lexer, do:
@lexer::headerand@lexer::members.