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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:53:23+00:00 2026-06-14T18:53:23+00:00

I have a simple grammar using Antlr 3: grammar i; @header { package com.data;

  • 0

I have a simple grammar using Antlr 3:

grammar i;

@header {
package com.data;
}

null        : 'null';
value       : null | STRING;
elements    : value? | (value ',' value)+;
STRING      : ('a'..'z'|'A'..'Z')+;
WS      : (' '|'\t'|'\f'|'\n'|'\r')+ {skip();}; // handle white space between keywords

What I am trying to achive is I have a value. So a value can be optional or value follows a comma follwed by another value. So for example:

value could be true or value could be true, true, true, true.

When I do the interpretation the following works:

true

or
true , true

When I trying true, true, true the tree is displayed with true, true but shows a NoViableAltException.

I have also tried:

elements: value? | (value ',' value)*;

but this doesn’t work either.

Any ideas where I am going wrong?

EDIT:

insert      : 'INSERT INTO TABLE' 'VALUES' '('elements')'';';
  • 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-14T18:53:25+00:00Added an answer on June 14, 2026 at 6:53 pm

    The elements rule is written such that it derives only zero or one value, or any number of pairs that are separated by a comma, with no comma between the pairs.

    Apparently what you want is this:

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

    This allows for nothing at all (due to the ? operator), or a single value followed by zero or more (*) occurrences of a comma and a 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 defined below using Antlr 3: grammar i; @header {
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 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 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
I have a simple grammar consisting of mixed variables ( $(name) ) and variable-value
I have a simple grammar such as S::=a S b S::=[] (empty string) Now

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.