java - How to pass a many string different parse rule in ANTLR 4? -
i trying develop tool using antlr 4.0. new antlr , advance java. had downloaded package i.e antlr-4.2.2-complete.jar
. antler working fine. have few doubts.
i took basic grammar , give below:
grammar test; start : (aa) | (bb); aa : c d; bb : c b; : 'a'; b : 'b'; c : 'c'; d : 'd'; ws : [ \t\r\n] ->skip;
now using command prompt parse string in it..
c:\javalib\test>java org.antlr.v4.tool test.g4 c:\javalib\test>javac test*.java c:\javalib\test>java org.antlr.v4.runtime.misc.testrig test start -gui -tree **acb** ^z (start (bb c b))
string acb
parsed , output obtained (start (bb c b))
. now, want know how can parse manystrings/ file in antlr. each line in file have different start rule. example , file have parse (input file)
start : acb bb : acb aa : acd
i can't take advice of changing grammar accordingly 1 start rule can used strings, because grammar on working vast.
i can change format of input string, can parse in antlr. wanted give basic idea, have many strings , each string have different start rule, how can parse in antlr.
to parse each line given rule this.
testcase : singletest ( linebreak singletest) * ; singletest: 'rulea' ':' rulea | 'ruleb' ':' ruleb |... ; whitespace: [ \t] -> skip; // no line break! linebreak: '\r\n' | '\r' | '\n';
Comments
Post a Comment