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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:37:26+00:00 2026-06-17T02:37:26+00:00

I have a short question: // Lexer LOOP_NAME : (LETTER|DIGIT)+; OTHERCHARS : ~(‘>’ |

  • 0

I have a short question:

// Lexer 
LOOP_NAME   :   (LETTER|DIGIT)+;

OTHERCHARS  :   ~('>' | '}')+;

LETTER      :   ('A'..'Z')|('a'..'z');

DIGIT       :   ('0'..'9');

A_ELEMENT
    :       (LETTER|'_')*(LETTER|DIGIT|'_'|'.');

// Parser-Konfiguration
WS          : ( ' '     
        | '\t'
        | '\r'
            | '\n'
            ) {$channel=HIDDEN;}
            ;

My problem is that this is impossible due to:

As a result, alternative(s) 2 were disabled for that input [14:55:32]
error(208): ltxt2.g:61:1: The following token definitions can never be
matched because prior tokens match the same input:
LETTER,DIGIT,A_ELEMENT,WS

My issue is that I also need to catch UTF8 with OTHERCHARS… and I cannot put all special UTF8 chars into a Lexer rule since I cannot range like (“!”..”?”).

So I need the NOT (~). The OTHERCHARS here can be everything but “>” or “}”. These two close a literal context and are forbidden within.

It doesn’t seem such cases are referenced very well, so I’d be happy if someone knew a workaround. The NOT operator here creates the ambivalence I need to solve.

Thanks in advance.

Best,
wishi

  • 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-17T02:37:27+00:00Added an answer on June 17, 2026 at 2:37 am

    Move OTHERCHARS to the very end of the lexer and define it like this:

    OTHERCHARS : . ;
    

    In the Java target, this will match a single UTF-16 code point which is not matched by a previous rule. I typically name the rule ANY_CHAR and treat it as a fall-back. By using . instead of .+, the lexer will only use this rule if no other rule matches.

    1. If another rule matches more than one character, that rule will have priority over ANY_CHAR due to matching a larger number of characters from the input.
    2. If another rule matches exactly one character, that rule will have priority over ANY_CHAR due to appearing earlier in the grammar.

    Edit: To exclude } and > from the ANY_CHAR rule, you’ll want to create rules for them so they are covered under point 2.

    RBRACE   : '}' ;
    GT       : '>' ;
    ANY_CHAR : . ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a short question i have wrote this in java. Old code: class
I have a short question. Im my current project I'm using LINQ-to-SQl. That is
I have a short question, let's assume I have a TabBarController with 3 Tabs
I have a short question. I want do put this \tssr>&\8=f23' into a String
I have a short access/mySQL question. I have a mapping table on the format
I have a short version of the question: I start a thread like that:
I have a very short and straight to the point question. When adding an
A short summary of the question: I have a parent class which is extended
A short, maybe stupid question. For classes and structs, sometimes I like to have
I have a short question. How can I send data from an activity 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.