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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:49:27+00:00 2026-05-20T08:49:27+00:00

i am reading the Definitive ANTLR reference by Terence Parr, where he says: Semantic

  • 0

i am reading the Definitive ANTLR reference by Terence Parr, where he says:

Semantic predicates are a powerful
means of recognizing context-sensitive
language structures by allowing
runtime information to drive
recognition

But the examples in the book are very simple. What i need to know is: can ANTLR parse context-sensitive rules like:

xAy –> xBy

If ANTLR can’t parse these rules, is there is another tool that deals with context-sensitive grammars?

  • 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-20T08:49:28+00:00Added an answer on May 20, 2026 at 8:49 am

    ANTLR parses only grammars which are LL(*). It can’t parse using grammars for full context-sensitive languages such as the example you provided. I think what Parr meant was that ANTLR can parse some languages that require some (left) context constraints.

    In particular, one can use semantic predicates on “reduction actions” (we do this for GLR parsers
    used by our DMS Software Reengineering Toolkit but the idea is similar for ANTLR, I think) to inspect any data collected by the parser so far, either as ad hoc side effects of other semantic actions, or in a partially-built parse tree.

    For our DMS-based DMS-based Fortran front end, there’s a context-sensitive check to ensure that DO-loops are properly lined up. Consider:

     DO  20, I= ...
       DO 10, J = ...
           ...
    20  CONTINUE
    10  CONTINUE
    

    From the point of view of the parser, the lexical stream looks like this:

    DO  <number> , <variable> =  ...
        DO <number> , <variable> = ...
             ...
    <number> CONTINUE
    <number> CONTINUE
    

    How can the parser then know which DO statement goes with which CONTINUE statement?
    (saying that each DO matches its closest CONTINUE won’t work, because FORTRAN can
    share a CONTINUE statement with multiple DO-heads).

    We use a semantic predicate “CheckMatchingNumbers” on the reduction for the following rule:

    block = 'DO' <number> rest_of_do_head newline 
             block_of_statements
             <number> 'CONTINUE' newline ; CheckMatchingNumbers
    

    to check that the number following the DO keyword, and the number following the CONTINUE keyword match. If the semantic predicate says they match, then a reduction for this rule succeeds and we’ve aligned the DO head with correct CONTINUE. If the predicate fails, then no reduction is proposed (and this rule is removed from candidates for parsing the local context); some other set of rules has to parse the text.

    The actual rules and semantic predicates to handle FORTRAN nesting with shared continues is more complex than this but I think this makes the point.

    What you want is full context-sensitive parsing engine. I know people have built them, but I don’t know of any full implementations, and don’t expect them to be fast.

    I did follow Quinn Taylor Jackson’s MetaS grammar system for awhile; it sounded like a practical attempt to come close.

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

Sidebar

Related Questions

I'm reading Javascript: the Definitive Reference , and it says on page 93: On
I've been reading O'Reilly book Dojo - The Definitive Guid but somethings are still
Reading the MCIMX50 Application Processor Reference Manuals on page 1368 (Section 33.3) there is
I am reading the book -- Hadoop: The Definitive Guide In chapter 2 (Page
I hope my logic isn't flawed but I'm reading the Definitive Guide to JavaScript
I am reading Javascript The Definitive Guide. In this book, Events and Event handling,
I'm reading JavaScript the definitive guide and there is code: var o = {x:1,y:{z:3}};
I just started reading Oreilly's XMPP The Definitive Guide and for the hello world,
I'm just reading JavaScript: The Definitive Guide by David Flanagan. I'm really enjoing and
I'm reading CSS the definitive guide by Eric Meyer 3rd edition. His section on

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.