3

Is there are an option to generate a more readable antlr parser. Say, to disable Token->DFA optimization?

4
  • 1
    Are you trying to build the skeleton of a parser with the intention of hand-maintaining it in the future? Would writing a recursive descent parser by hand from the start be a better option?
    – sarnold
    Feb 9, 2012 at 1:24
  • One motivation is debuggability, another one is simplicity: Instead of having this code to match the first occurence of 'once' // Exp.g:66:2: ( 'once' condition ( 'then' )? action ) int alt13=4; alt13 = dfa13.predict(input); switch (alt13) { case 1 : // Exp.g:66:4: 'once' condition ( 'then' )? action { match(input,64,FOLLOW_64_in_once193); if (state.failed) return ; pushFollow(FOLLOW_condition_in_once195); Antlr could just generate the following: Feb 9, 2012 at 1:34
  • if(!input.startsWith("once"))return; Feb 9, 2012 at 1:37
  • Instead of writing a recursive descent parser completely by hand, a disableDfaOptimization flag in Antlr could make the task much easier. Feb 9, 2012 at 1:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.