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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:09:01+00:00 2026-05-26T15:09:01+00:00

I am trying to test an ANTLR grammar with such a standard test rig

  • 0

I am trying to test an ANTLR grammar with such a standard test rig

import org.antlr.runtime.*;

 class Main {
  public static void main(String[] args) throws Exception {
    SampleLexer lexer = new SampleLexer(new ANTLRStringStream(args[0]));
    SampleParser parser = new SampleParser(new CommonTokenStream(lexer));
    parser.program();
  }
}

I have a test file called mytest00. Now I want to use this file as input. I suppose I am doing a stardard IO redirection here.

   bash-3.2$ java Main < mytest00

But it gives me such an error message. What is the problem please? Thanks.

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
    at Main.main(SampleTest.java:5)
  • 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-26T15:09:02+00:00Added an answer on May 26, 2026 at 3:09 pm

    You’re trying to use args[0] but you haven’t actually passed in any command line arguments – you’ve just redirected a file into the standard input of the process. So the array has no elements, and you’re getting an exception because you’re trying to get the first element of that empty array.

    It’s not really clear that you actually want ANTLRStringStream. I suspect you want ANTLRInputStream wrapping System.in if args.length == 0, and ANTLRFileStream(args[0]) otherwise.

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

Sidebar

Related Questions

I am trying to test a class that manages data access in the database
I am having problems with my Antlr grammar. I'm trying to write a parser
I´m trying to test if a protected method is called in a public interface.
trying to test out move semantics i build a simple class that allocates some
I'm trying to construct an antlr grammar to parse a templating language. that language
just trying to test for equality in this piece of code, but getting a
I trying to test an AccountController that uses DotNetOpenAuth but I am running into
Im trying to test my successfully creates a new user after login (using authlogic).
I am trying to test my app on an iPhone 4S. When I build
I'm trying to test the DB2 adapter for BizTalk 2006 (not R2). While trying

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.