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

  • Home
  • SEARCH
  • 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 917569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:13:56+00:00 2026-05-15T18:13:56+00:00

When I run the following grammer: test : WORD+; WORD : (‘a’..’z’)+; WS :

  • 0

When I run the following grammer:

test : WORD+;

WORD : ('a'..'z')+;
WS : ' '+ {$channel = HIDDEN;};

and I give the input “?test” why does antlr accept this as valid input? I thought the (‘a’..’z’) would only match characters within the lowercase alphabet?

  • 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-15T18:13:56+00:00Added an answer on May 15, 2026 at 6:13 pm

    ANTLR does produce an error when parsing the input string ?test with the grammar you posted. As is usually the case, the error lies with the tool being used around ANTLR (I see it happen a lot with ANTLRWorks as well, unfortunately!).

    To test it yourself (properly), create a file Test.g:

    grammar Test;
    
    test : WORD+;
    
    WORD : ('a'..'z')+;
    
    WS   : ' '+ {$channel = HIDDEN;};
    

    and a file Main.java:

    import org.antlr.runtime.*;
    
    public class Main {
        public static void main(String[] args) throws Exception {
            ANTLRStringStream in = new ANTLRStringStream("?test");
            TestLexer lexer = new TestLexer(in);
            CommonTokenStream tokens = new CommonTokenStream(lexer);
            TestParser parser = new TestParser(tokens);
            parser.test();
        }
    }
    

    and download a copy of the ANTLR 3.2 JAR in the same directory.

    Now generate a lexer & parser:

    java -cp antlr-3.2.jar org.antlr.Tool Test.g 
    

    compile all Java source files:

    javac -cp antlr-3.2.jar *.java
    

    and run the Main class:

    java -cp .:antlr-3.2.jar Main 
    

    (replace the : with ; if you’re on Windows!)

    which will produce the following error message:

    line 1:0 no viable alternative at character '?'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What happens if I run following command : mvn clean install sonar:sonar -Dmaven.test.skip=true I
I run the following codes separately as my prompt unsuccessfully in .zshrc. This suggests
I can't run following code with IDEA @Test class CompanyURLTest extends Assert { @Test
With the following Grammar, I get a syntax error with this sort of input:
Please give me some suggestions, I was trying to run following code : <
When we run following script under Firefox ... var d = $(<div class='test'></div>); d.hide();
I get this error when i try to run following command sudo pecl install
When I run this following code it gives above error - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
Can not run following SQL from ant's sql task : BEGIN DBMS_AQADM.CREATE_QUEUE_TABLE( queue_table =>
when I trying to run following code. var result = from c in db.brand

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.