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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:48:00+00:00 2026-06-15T07:48:00+00:00

I have a simple grammar defined below using Antlr 3: grammar i; @header {

  • 0

I have a simple grammar defined below using Antlr 3:

grammar i;

@header {
package com.data;
}

null        : 'null';
true        : 'true';
false       : 'false';
value       : true | false | null | STRING | INTEGER | FLOAT;
elements    : (value (',' value)*)MINIMUMDIGIT;
STRING  : ('a'..'z'|'A'..'Z')+;
MINIMUMDIGIT    : ('0'..'9');
INTEGER : '0'..'9'+;
FLOAT       : INTEGER'.'INTEGER;
WS      : (' '|'\t'|'\f'|'\n'|'\r')+ {skip();}; // handle white space between keywords

When I try to do the interpretation of the elements in ANTLRWorks, the elements displays correct. However, I also a a NoViableAltException.

I have tried:

true

It displays true and then a NoViableAltException

I have true, true, true, true and it displays true,true,true,true and then a NoViableAltException.

Can you help where I am going wrong? Looking at many similar posts, but unable to find the solution to this problem. The Exception is shown in the graph during the interpretation and no Exception shown on the Console.

EDIT:

The user has to enter a single value, but it can follow multiple values separted by a comma each time. According to Antlr, Antlr allows you define a optional (?), zero or more (*) or one or more (+). There is no such thing as only one. So the MINIMUMDIGIT is used to control the only one.

Example:

insert      : 'INSERT INTO table' 'VALUES' '('elements')'';';

What I am trying to achive is when the insert is executed, elements has to have atleast one value or it could have multiple values. According to the syntax defined above, it allows zero or more.

As soon as I change the elements to:

elements : (value (',' value)*)+;

this does not work. When I enter comma, the comma displays. It also accepts values with no commas. The comma is necessary. That’s why I introduced the MINIMUMDIGIT.

  • 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-15T07:48:02+00:00Added an answer on June 15, 2026 at 7:48 am

    According to Antlr, Antlr allows you define a optional (?), zero or more (*) or one or more (+).

    Agreed.

    There is no such thing as only one.

    Not true. A referenced rule by default matches only once. So if elements is defined as elements: value;, then elements matches on one and only one value.

    Likewise, if elements is elements : (value (',' value)*); (no trailing ?, +, or *), it will match each of the following lines:

    value
    value , value
    value , value , value
    

    It will not match any of the following lines:

    (empty input)
    value value
    , value
    value , , 
    

    I think what you need is just elements: (value (',' value)*);.

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

Sidebar

Related Questions

I have a simple grammar using Antlr 3: grammar i; @header { package com.data;
I have defined simple grammar for parsing string and number using Treetop as below.
I have defined simple grammar for parsing string and number using Treetop as below.
I have defined the following grammar. grammar Sample_1; @header { package a; } @lexer::header
I have a simple ANTLR grammar, which I have stripped down to its bare
i have an problem with antlr. I have the following simple grammar: grammar bxk;
I have really simple XML (HTML) parsing ANTLR grammar: wiki: ggg+; ggg: tag |
I am writhing a simple language with antlr, I defined a Lexer grammar in
I currently have a working, simple language implemented in Java using ANTLR. What I
I have this grammar to match simple logical predicates in ANTLR. exp : or

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.