Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6760815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:06:35+00:00 2026-05-26T14:06:35+00:00

Searching for solutions for my problem, I got this question , suggesting composite grammars

  • 0

Searching for solutions for my problem, I got this question, suggesting composite grammars to get rid of code too large. Problem there, I’m already using grammar imports, but when I further extend one of the imported grammars, the root parser grammar shows the error. Apparently, the problem lies in the many tokens and DFA definitions that ANTLR generates after analyzing the whole grammar. Is there a way/what is the suggested way to get rid of this problem? Is it scalable, i.e. does it not depend on the parts changed by the workaround being small enough?

EDIT: To make this clear (the linked question didn’t make it clear): The code too large error is a compiler error on the generated parser code, to my understanding usually caused by a grammar so large that some code is larger than the limit of the java specification. In my case, it’s the static initializer of the root parser class, which contains tons of DFA lookahead variables, all resulting in code in the initializer. So, Ideally, ANTLR should be able to split that up in the case that the grammar is too big/the user tells ANTLR to do it. Is there such an option?

(I have to admit, the asker of the linked question had an… interesting rule that caused his grammar to bloat up, and it may be my error here, too. But the possibility of this being not the grammar’s author’s error (in any large grammar) stands, so I see this as a valid, non-grammar specific ANTLR question)

EDIT END

My grammar parses “Magic the Gathering” rules text and is available here (git). The problem specifically appears when exchanging line 33 for 34-36 in this file. I use Maven and antlr3-maven-plugin for building, so ideally, the workaround is doable using the plugin, but if it’s not, that’s a smaller problem than the one I have now…

Thanks a lot and I hope I haven’t overseen any obvious documentation that would help me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:06:35+00:00Added an answer on May 26, 2026 at 2:06 pm

    The fragment keyword can only be used before lexer rules, not before parser rules as I see you do. First change that in all your grammars (I only looked at ObjectExpressions.g). It’s unfortunate that ANTLR does not produce an error when you try it. But believe me: it’s wrong, and might be causing (a part of) your problem(s).

    Also, your rule from line 34-36:

    qualities
      :  qualities0 
      |  qualities0 (COMMA qualities0)+ -> qualities0+ 
      |  qualities0 (Or qualities0)+    -> ^(Or qualities0+)
      ;
    

    should be rewritten as:

    qualities
      :  qualities0 (COMMA qualities0)* -> qualities0+ 
      |  qualities0 (Or qualities0)+    -> ^(Or qualities0+)
      ;
    

    EDIT

    So, Ideally, ANTLR should be able to split that up in the case that the grammar is too big/the user tells ANTLR to do it. Is there such an option?

    No, there is no such option unfortunately. You’ll have to divide the grammar into (even more) smaller ones.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i got a n00b problem with python and i've been searching here for a
I have got a big problem. After searching through the internet, I didn't find
Got a problem that seems to be fairly endemic with IE8 (searching on Google)
I'm using preg_match_all for very long pattern. when run the code, i got this
im searching for a solution of the following problem: i got a larger XHTML
Been searching all around but still cannot find a solution for this problem. My
looking for a solution to my problem. searching this place and google for an
I've been searching through forums to find a solution for the problem I'm facing
I've been searching for a solution on the internet for this, and can not
I'm searching for the cleanest solution here. I would like to code a stored

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.