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

The Archive Base Latest Questions

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

I am new to Antlr and I have defined a basic grammar using Antlr

  • 0

I am new to Antlr and I have defined a basic grammar using Antlr 3.

The grammar can be seen below:

grammar data;

@header {
package com.data.language;
}


null        : 'null';
data        : null | STRING | INTEGER;
STRING  : ('a'..'z'|'A'..'Z')+;
INTEGER : '0'..'9'+;

This works perfectly and ANTLRWorks generates the code. However, I would like to use the data keyword within the lexer. For example:

I : data '*' INTEGER;

The problem is that once this is done, I am getting the following Exception:

Error 106: reference to undefined value: data

and I cannot see the data within the graph of ANTLRWorks. I can see only * INTEGER of the I lexer.

Is what I am trying to do, is it possible? How is it possible?

  • 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:55:27+00:00Added an answer on June 14, 2026 at 6:55 pm

    Using parser productions in the lexer is not possible: lexer produces tokens (“words”) that are later consumed by the parser, while parsers recognize sequences of words (“phrases”). The lexer layer is below the parser layer; there is no “feedback channel” that would let the lexer “learn” of what the parser is doing.

    A parser rule like this

    data_star_int : data '*' INTEGER;
    

    is, obviously, fine, because parser rules can refer to both lexer tokens and other parser rules. You can use the data_star_int to match multi-token sequences.

    I would replace the inlined * with a named token, but that is a matter of preference.

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

Sidebar

Related Questions

I've created my 'new programming language' using the ANTLR framework. The language is defined
I am writhing a simple language with antlr, I defined a Lexer grammar in
I relative new to ANTLR. I have an very easy grammar: start : ('A'
I have the following ANTLR grammar: grammar Tasks; options { language = Java; }
I am new to Antlr. I am defining a grammar for my company using
I have been successfully using my code with the javascript library in the ANTLR
I am new to parser generators and I am wondering how the ANTLR grammar
I am using ANTLR to create an and/or parser+evaluator. Expressions will have the format
I'm trying to compile my antlr grammar with gradle. I'm very new to gradle,
I have downloaded the csharp grammar project from here http://antlrcsharp.codeplex.com/releases/view/47523 , and it runs

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.