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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:09:12+00:00 2026-06-04T01:09:12+00:00

I have a small problem with my grammar. I am trying to detect whether

  • 0

I have a small problem with my grammar.

I am trying to detect whether my string is a date comparison or not.
But the DATE lexer I created seem not to be recognized by antlr, and I get an error that I cannot solve.

Here is my input expression :

"FDT > '2007/10/09 12:00:0.0'"

I simply expect such a tree as output :

    COMP_OP
FDT        my_DATE

Here is my grammar :

    // Aiming at parsing a complete BQS formed Query
grammar Logic;

options {
    output=AST;
}

/*------------------------------------------------------------------
 * PARSER RULES
 *------------------------------------------------------------------*/

 // precedence order is (low to high): or, and, not, [comp_op, geo_op, rel_geo_op, like, not like, exists], ()
 parse  
    : expression EOF -> expression
    ; // ommit the EOF token

 expression
    : query
    ;       

 query
    : atom (COMP_OP^ DATE)* 
    ;

//END BIG PART

 atom   
    : ID 
    | | '(' expression ')' -> expression
    ;

/*------------------------------------------------------------------
 * LEXER RULES
 *------------------------------------------------------------------*/
// GENERAL OPERATORS: 

DATE        :   '\'' YEAR '/' MONTH '/' DAY (' ' HOUR ':' MINUTE ':' SECOND)? '\'';
ID          :   (CHARACTER|DIGIT|','|'.'|'\''|':'|'/')+;
COMP_OP     :   '=' | '<' | '>' | '<>' | '<=' | '>=';

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


fragment YEAR   :   DIGIT DIGIT DIGIT DIGIT;
fragment MONTH  :   DIGIT DIGIT;
fragment DAY    :   DIGIT DIGIT;
fragment HOUR   :   DIGIT DIGIT;
fragment MINUTE :   DIGIT DIGIT;
fragment SECOND :   DIGIT DIGIT ('.' (DIGIT)+)?;

fragment DIGIT  :   '0'..'9' ;
fragment DIGIT_SEQ  :(DIGIT)+;
fragment CHARACTER :    ('a'..'z' | 'A'..'Z');

As an output error, I get :

line 1:25 mismatched character '.' expecting set null
line 1:27 mismatched input ''' expecting DATE

I also tried to remove the ‘ ‘ from my Date (thinking that it was perhaps the problem, as I remove them in the grammar.)

In this case, I get this error :

line 1:6 mismatched input ''2007/10/09' expecting DATE

Can anyone explain me why I get such an error, and how I could solve it ?

This question is q subset of my complete task, where I have to differentiate lots of omparisons (dates, geographic, strings, . . .). I would thus really need to be able to give ‘tags’ to my atoms.

Thank you very much !

As a complement, here is my current Java code :

import org.antlr.runtime.*;
import org.antlr.runtime.tree.*;
import org.antlr.stringtemplate.*;

public class Main {
  public static void main(String[] args) throws Exception {

    // the expression
    String src = "FDT > '2007/10/09 12:00:0.0'";

    // create a lexer & parser
    //LogicLexer lexer = new LogicLexer(new ANTLRStringStream(src));
    //LogicParser parser = new LogicParser(new CommonTokenStream(lexer));

    LogicLexer lexer = new LogicLexer(new ANTLRStringStream(src));
    LogicParser parser = new LogicParser(new CommonTokenStream(lexer));

    // invoke the entry point of the parser (the parse() method) and get the AST
    CommonTree tree = (CommonTree)parser.parse().getTree();

    // print the DOT representation of the AST 
    DOTTreeGenerator gen = new DOTTreeGenerator();
    StringTemplate st = gen.toDOT(tree);
    System.out.println(st);
  }
}
  • 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-04T01:09:14+00:00Added an answer on June 4, 2026 at 1:09 am

    I finally got it,

    Seems like even though I remove whitespaces, I still have to include them in expressions that contain one.
    In addition, there was a small error in second definition, as the second digit was optional.

    The grammar is thus slightly modified :

    fragment SECOND :   DIGIT (DIGIT)? ('.' (DIGIT)+)?;
    

    which gives this output :

    AST graph of the output

    I know hope this will still work in my more complete grammar 🙂

    Hope it helps someone.

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

Sidebar

Related Questions

I have small problem. I'm trying to work on an XML file, but the
I have a small problem and I do not find any solutions. I want
I have a small problem. I am trying to align two divs side by
I am generating new xml file using perl script but I have small problem,
I would like to write to a text file, but I have small problem.
Hi I have a small problem in my ANTLR tree grammar. I am using
I have small problem and it might be silly somewhere, but still i have
I am using Jquery Autocomplete . Its workng fine but I have small problem.
I have a small problem but couldn't find solution for that. I have founded
I have small problem when trying to create many-to-many link in doctrine. I have

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.