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?
@header
and @members
is short for @parser::header
and @parser::members
respectively.
To put code in the lexer, do: @lexer::header
and @lexer::members
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.