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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:29:46+00:00 2026-06-17T21:29:46+00:00

I have the Java source code for Parser and Lexer of ANTLR 3 in

  • 0

I have the Java source code for Parser and Lexer of ANTLR 3 in .java file and want to see the actual grammar behind with all rules and etc.

Is it even possible?

  • 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-17T21:29:47+00:00Added an answer on June 17, 2026 at 9:29 pm

    Not by some automated tool (AFAIK). But the generated source file(s) contain the parser and lexer rules of the original grammar in its comments, so you can reverse engineer them yourself reasonable easy.

    For example, take this dummy grammar:

    grammar T;
    
    parse
     : foo
     | bar
     | OTHER
     ;
    
    foo : INT ;
    bar : ALPHA ;
    
    INT   : '0'..'9'+ ;
    ALPHA : ('a'..'z' | 'A'..'Z')+ ;
    OTHER : . ;
    

    If you generate a lexer and parser from it, the parser would look like this:

    public class TParser extends Parser {
    
        // $ANTLR start "parse"
        // T.g:3:1: parse : ( foo | bar | OTHER );
        public final void parse() throws RecognitionException {
            ...
        }
        // $ANTLR end "parse"
    
        // $ANTLR start "foo"
        // T.g:9:1: foo : INT ;
        public final void foo() throws RecognitionException {
            ...
        }
        // $ANTLR end "foo"
    
    
        // $ANTLR start "bar"
        // T.g:10:1: bar : ALPHA ;
        public final void bar() throws RecognitionException {
            ...
        }
        // $ANTLR end "bar"
    }
    

    and the lexer like this:

    public class TLexer extends Lexer {
    
        // $ANTLR start "INT"
        public final void mINT() throws RecognitionException {
            // T.g:12:7: ( ( '0' .. '9' )+ )
            ...
        }
        // $ANTLR end "INT"
    
        // $ANTLR start "ALPHA"
        public final void mALPHA() throws RecognitionException {
            // T.g:13:7: ( ( 'a' .. 'z' | 'A' .. 'Z' )+ )
            ...
        }
        // $ANTLR end "ALPHA"
    
        // $ANTLR start "OTHER"
        public final void mOTHER() throws RecognitionException {
            // T.g:14:7: ( . )
            ...
        }
        // $ANTLR end "OTHER"
    }
    

    As you can see, all the grammar rules are there inside comments in the .java source files.

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

Sidebar

Related Questions

I have java source code in a text file. There has to be entered
I have commented my java source code with javadoc using tags like {@see myPackage.MyClass}.
ANTLR generates java source from the grammar file. Generated source has dependency to ANTLR
The question is simple, can I have the java source code (e.g. FooParser.java) generated
Have there been incompatibilities between Java releases where Java source code/Java class files targeting
In my source tree have Java code which is automatically generated from XSD files.
I have come across the following link: http://code.google.com/p/a-star/source/browse/trunk/java/PathFinder.java?r=8 I have got the code working
If I call: java org.antlr.Tool -o outdir sources/com/example/Java5.g ...with antlr-3.1.3 the parser and lexer
I am looking for a Java source code parser and came across JavaParser, however
I have been developing Java programs that parse html source code of webpages by

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.