grammar MyExpr;
prog: stat+ ;
stat: expr NEWLINE #printExpr
| ID '=' expr NEWLINE #assign
| NEWLINE #blank
;
expr: expr op=('*'|'/') expr #multiDiv
| expr op=('+'|'-') expr #AddSub
| INT #intgr
| ID #id
| '(' expr ')' #parenthesis
;
ID : [a-zA-Z]+ ; // match identifiers
INT : [0-9]+ ; // match integers
NEWLINE:'\r'? '\n' ; // return newlines to parser (end-statement signal)
WS : [ \t]+ -> skip ; // toss out whitespace
MUL : '*' ; // assigns token name to '*' used above in grammar
DIV : '/' ;
ADD : '+' ;
SUB : '-' ;
AntlrInputStream inputStream = new AntlrInputStream(""); // Note... I don't have any input
MyExprLexer lexer = new MyExprLexer(inputStream);
CommonTokenStream commonTokenStream = new CommonTokenStream(lexer);
MyExprParser parser = new MyExprParser(commonTokenStream);
MyListener listener = new MyListener();
parser.AddListener(listener);
IParseTree tree = parser.prog(); // ? I want this to go through all the listeners (EnterEveryRule API).
ParseTreeWalker walker = new ParseTreeWalker();
walker.Walk(listener , tree ); // // ? I want this to go through all the listeners (EnterEveryRule API).
--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Assembly assembly = Assembly.GetExecutingAssembly();
Type parserClassType = assembly.GetType("CESample.MyGrammarParser");
if (parserClassType != null)
{
MethodInfo[] methods = parserClassType.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
if (methods != null && methods.Count() > 0)
{
foreach (MethodInfo methodInfo in methods)
{
Debug.WriteLine(methodInfo.Name);
object result = null;
ParameterInfo[] parameters = methodInfo.GetParameters();
if (parameters.Length == 0)
{
result = methodInfo.Invoke(_Parser, null);
}
}
}
}