ANTLR how to retrieve the type of token with recursion -


i'm using antlr4 framework , fragment of language:

r     :    rn                                                   #rnname     |   'dlrrelationintersectionof' lparen r comma r rparen   #rintersection     |   'dlrrelationunionof' lparen r comma r rparen          #runion 

as can see, rn terminal node can process it. r non-terminal node can complex, dlrrelationunionof(rn1, dlrrelationintersectionof(rn2,rn3)). goal process r node , recursively rn. problem once retrive rule r in code like:

dlrparser.rcontext recursiverule =  ctx.r(); 

how can recursiverule find out rns?

during run parser creates parse tree (if enabled, default). parse tree tree representation of items matched. tree consists of parserrulecontext instances, each children represent matched items in rule in matching order. r context, when matching second alt, can find 6 child nodes (one literal, 1 lparen, 1 first sub r etc.). can use child contexts access subentries. if rn matched have terminal node in first child entry.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -