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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:23:39+00:00 2026-06-10T02:23:39+00:00

I am rewriting this post(same question though, less words). I rewrote my grammar to

  • 0

I am rewriting this post(same question though, less words).

I rewrote my grammar to just have at the top level this

statement: SELECT EOF!;
#removed all other rules and tokens and still not working
SELECT  :   ('S'|'s')('E'|'e')('L'|'l')('E'|'e')('C'|'c')('T'|'t');

I then have the following java code(There is no parse method on my Parser like I see on everyone else’s posts 🙁 🙁 )…

@Test
public void testGrammar() throws RecognitionException {
    String sql = "select p FROM TABLE p left join p.security s where p.numShares = :shares and s.securityType = :type";

    ANTLRStringStream stream = new ANTLRStringStream(sql);
    NoSqlLexer lexer = new NoSqlLexer(stream);
    CommonTokenStream tokenStream = new CommonTokenStream(lexer);
    NoSqlParser parser = new NoSqlParser(tokenStream);

    try {
        CommonTree tree = (CommonTree) parser.statement().getTree();
        Assert.fail("should fail parsing");
    } catch(Exception e) {
        log.info("Exception", e);
    }
}

I should get an Exception on parsing but I do not 🙁 :(. This is a very simple grammar with an EOF but it just is not working. Any ideas why? Am I calling the wrong parsing statement?

NOTE: I am trying to make a much bigger problem simpler by cutting the problem down to this simple thing which seems not to work.

full (very small) grammar file is here

grammar NoSql;


options { 
    output = AST; 
    language = Java;
}

tokens {


}

@header {
package com.alvazan.orm.parser.antlr;
}

@lexer::header {
package com.alvazan.orm.parser.antlr;
}


@rulecatch {
    catch (RecognitionException e)
    {
        throw e;
    }
}

statement: SELECT EOF!;

SELECT  :   ('S'|'s')('E'|'e')('L'|'l')('E'|'e')('C'|'c')('T'|'t');

WS  :
    (   ' '
        |   '\t'
        |   '\r'
        |   '\n'
        )+
        { $channel=HIDDEN; }
        ;  

ESC :
    '\\' ('"'|'\''|'\\')
    ;

thanks,
Dean

  • 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-06-10T02:23:40+00:00Added an answer on June 10, 2026 at 2:23 am

    I should get an Exception on parsing but I do not 🙁 :(. This is a very simple grammar with an EOF but it just is not working.

    If you didn’t “tell” ANTLR to throw an exception, then ANTLR might not throw an exception/error in case of invalid input. In many cases, ANTLR tries to recover from mismatched/invalid input and tries to continue parsing. You will see output being written on the stderr in your case, but you might not get an exception.

    If you do want an exception in your case, see: ANTLR not throwing errors on invalid input

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

Sidebar

Related Questions

This question is about rewriting git history. Six months ago I decided to make
I know this question is overly popular, but I find nothing that addresses rewriting
I have a method in a url rewriting module that looks like this public
So this post talked about how to actually implement url rewriting in an ASP.NET
Edit: With enough rewriting, and commenting, I have it running, will post final below
i'm using this rule for rewriting subdomain and i'm corrected host file to 127.0.0.1
I'm rewriting an LOB application whose architecture is like this: Silverlight && Windows Mobile
I'm rewriting a url to a users profile with mod_rewrite like this: domain.com/users/JohnSmith. I
Possible Duplicate: Rewriting URL that contains question mark Hi a noob question for url
I read everywhere that rewriting history of commits that have been published is bad

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.