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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:43:24+00:00 2026-06-14T05:43:24+00:00

i’m learning ANTLR right now. Let’s say, I have a VHDL code and would

  • 0

i’m learning ANTLR right now. Let’s say, I have a VHDL code and would like to do some processing on the PROCESS blocks. The rest should be completely ignored. I don’t want to describe the whole VHDL language, since I’m interested only in the process blocks. So I could write a rule that matches process blocks. But how do I tell ANTLR to match only the process block rule and ignore anything else?

  • 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-14T05:43:25+00:00Added an answer on June 14, 2026 at 5:43 am

    I know next to no VHDL, so let’s say you want to replace all single line comments in a (Java) source file with multi-line comments:

    //foo
    

    should become:

    /* foo */
    

    You need to let the lexer match single line comments, of course. But you should also make sure it recognizes multi-line comments because you don’t want //bar to be recognized as a single line comment in:

    /*
    //bar
    */
    

    The same goes for string literals:

    String s = "no // comment";
    

    Finally, you should create some sort of catch-all rule in the lexer that will match any character.

    A quick demo:

    grammar T;
    
    parse
     : (t=. {System.out.print($t.text);})* EOF
     ;
    
    Str
     : '"' ('\\' . | ~('\\' | '"'))* '"'
     ;
    
    MLComment
     : '/*' .* '*/'
     ;
    
    SLComment
     : '//' ~('\r' | '\n')*
       {
         setText("/* " + getText().substring(2) + " */");
       }
     ;
    
    Any
     : . // fall through rule, matches any character
     ;
    

    If you now parse input like this:

    //comment 1
    class Foo {
    
      //comment 2
    
      /* 
       * not // a comment
       */
      String s = "not // a // comment"; //comment 3
    }
    

    the following will be printed to your console:

    /* comment 1 */
    class Foo {
    
      /* comment 2 */
    
      /* 
       * not // a comment
       */
      String s = "not // a // comment"; /* comment 3 */
    }
    

    Note that this is just a quick demo: a string literal in Java could contain Unicode escapes, which my demo doesn’t support, and my demo also does not handle char-literals (the char literal char c = '"'; would break it). All of these things are quite easy to fix, of course.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.
I would like to run a str_replace or preg_replace which looks for certain words
I would like to count the length of a string with PHP. The string
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have thousands of HTML files to process using Groovy/Java and I need to

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.