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 6914473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:21:06+00:00 2026-05-27T09:21:06+00:00

I have a grammar Foo.xtext (too complex to include it here). Xtext generates InternalFoo.g

  • 0

I have a grammar Foo.xtext (too complex to include it here). Xtext generates InternalFoo.g from it. After some tweaking it also generates DebugInternalFoo.g which claims to be the same thing without actions. Now, I strip off actions with ANTLR directly

java -cp antlr-3.4.jar org.antlr.tool.Strip Internal.g > Stripped.g

I’d expect the three grammars to behave the same way when I check them. But here is what I experienced

  • InternalFoo.g – error, rule assignment has non-LL(*) decision
  • DebugInternalFoo.g – no problem, parses fine
  • Stripped.g – warnings at rule assignment, decision can match using multiple alternatives. It fails to parse properly.

Is it possible that a grammar parses a text differently with or without actions? Or is it a bug in any of the action-remover tools? (The rule in question has syntactic predicates, and without them, it would really have a non-LL(*) decision.)

UPDATE:

I partly found what caused the problem. The rule in question was like this

trickyRule:
  ({ some complex action})
  (expression '=')=>...

Stripping with Antlr removed the action, but left an empty group there:

// Stripped.g
trickyRule:
  () (expression '=')=>...

The generation of the debug grammar removes both the action, and the now empty group around it:

// DebugInternalFoo.g
trickyRule:
  (expression '=')=>...

So the lesson learned is: an empty group before a syntactic predicate is not the same as nothing at all.

  • 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-27T09:21:07+00:00Added an answer on May 27, 2026 at 9:21 am

    Is it possible that a grammar parses a text differently with or without actions?

    Yes, that is possible. org.antlr.tool.Strip leaves syntactic predicates1, but removes validating2– and gated3 semantic predicates (and member sections that these semantic predicates might use).

    For example, the following rules would only match an A_TOKEN:

    parser_rule1
      :  (parser_rule2)=> parser_rule2
      ;
    
    parser_rule2
      :  {input.LT(1).getType() == A_TOKEN}? .
      ;
    

    but if you use the Strip tool on it, it leaves the following:

    parser_rule1
      :  (parser_rule2)=> parser_rule2
      ;
    
    parser_rule2
      :  /*{input.LT(1).getType() == A_TOKEN}?*/ .
      ;
    

    making it match any token.

    In other words, Strip could change the behavior of the generated lexer or parser.


    1 syntactic predicate: ( ... )=>
    2 validating semantic predicate { ... }?
    3 gated semantic predicate { ... }?=>

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

Sidebar

Related Questions

I have some bison grammar: input: /* empty */ | input command ; command:
I have the following bison grammar (as part of a more complex grammar): classDeclaration
I have removed left-recursion from a left-recursive grammar given to me. The original grammar
Suppose I have a grammar which takes care of the global variables and some
I have a simple grammar which allows the user to define some objects with
Let's say I have a grammar defined to something like: some_rule := a b
Using Flex and Bison, I have a grammar specification for a boolean query language,
I have an ANTLR grammar file as part of a C# project file and
I have this simple grammar for a C# like syntax. I can't figure out
I have to define the grammar of a file like the one shown below.

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.