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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:30:31+00:00 2026-06-11T07:30:31+00:00

my real grammar is way more complex but I could strip down my problem.

  • 0

my real grammar is way more complex but I could strip down my problem. So this is the grammar:

grammar test2;
options {language=CSharp3;}

@parser::namespace { Test.Parser }
@lexer::namespace { Test.Parser }

start   : 'VERSION' INT INT project;

project :   START 'project' NAME TEXT END 'project';

START: '/begin';
END: '/end';

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

    INT :   '0'..'9'+;

    NAME:   ('a'..'z' | 'A'..'Z')+;

    TEXT  :  '"'  ( '\\' (.) |'"''"' |~( '\\' | '"' | '\n' | '\r' ) )* '"';

    STARTA 
        :   '/begin hello';

And I want to parse this (for example):

VERSION 1 1

/begin project

testproject “description goes here”

/end

project

Now it will not work like this (Mismatched token exception). If I remove the last Token STARTA, it works. But why? I don’t get it.

Help is really appreciated.
Thanks.

  • 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-11T07:30:33+00:00Added an answer on June 11, 2026 at 7:30 am

    When the lexer sees the input "/begin " (including the space!), it is committed to the rule STARTA. When it can’t match said rule, because the next char in the input is a "p" (from "project") and not a "h" (from "hello"), it will try to match another rule that can match "/begin " (including the space!). But there is no such rule, producing the error:

    mismatched character 'p' expecting 'h'

    and the lexer will not give up the space and match the START rule.

    Remember that last part: once the lexer has matched something, it will not give up on it. It might try other rules that match the same input, but it will not backtrack to match a rule that matches less characters!

    This is simply how the lexer works in ANTLR 3.x, no way around it.

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

Sidebar

Related Questions

Real noob question no doubt, but I can't get my head around this behaviour.
Real Dumb question. I figured I would have gotten this straight by now, but
No real way for me to succinctly summarize this one. I have two database
real newbie question but why doesn't this work? I am getting use of unassigned
I'm using ANTLR and the following grammar: grammar QuickBasic; options { language = 'CSharp2';
Real problem with an existing webapp which has been working for the last couple
The real question: Is there a way to clear certain attributes for all components
A real F# noob question, but what is |> called and what does it
My real Question is which of these is more efficient in terms of loading
I need to print real datbase type name from DbParameter.DbType , but when I

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.