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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:04:25+00:00 2026-05-18T20:04:25+00:00

Hi I want to write a grammer( Using ANTLRWORKS ) that accept later (

  • 0

Hi I want to write a grammer( Using ANTLRWORKS ) that accept later ( in debugging mode ) this code

repeat_until
    :'repeat' seq_statement 'until' exp
    ;

read    :

          'read' ID ';'  
    ;

    fragment    
Operation_stat
    :   (NUMBER|ID) OP (NUMBER|ID) 
    ;

OP  :   ('+'|'-'|'*'|'/')
    ;

NUMBER  :
'0'..'9'+   
    ;

LOG_OP  :
('<' | '>' | '=' | '<=' | '>=' )
    ;


ID  :   ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
    ;



FLOAT
    :   ('0'..'9')+ '.' ('0'..'9')* EXPONENT?
    |   '.' ('0'..'9')+ EXPONENT?
    |   ('0'..'9')+ EXPONENT
    ;

COMMENT
    :   '//' ~('\n'|'\r')* '\r'? '\n' {$channel=HIDDEN;}
    |   '/*' ( options {greedy=false;} : . )* '*/' {$channel=HIDDEN;}
    ;

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

STRING
    :  '\'' ( ESC_SEQ | ~('\\'|'\'') )* '\''
    ;




fragment
EXPONENT : ('e'|'E') ('+'|'-')? ('0'..'9')+ ;

fragment
HEX_DIGIT : ('0'..'9'|'a'..'f'|'A'..'F') ;

fragment
ESC_SEQ
    :   '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\')
    |   UNICODE_ESC
    |   OCTAL_ESC
    ;

fragment
OCTAL_ESC
    :   '\\' ('0'..'3') ('0'..'7') ('0'..'7')
    |   '\\' ('0'..'7') ('0'..'7')
    |   '\\' ('0'..'7')
    ;

fragment
UNICODE_ESC
    :   '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
    ;

Thanx for your help

  • 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-05-18T20:04:26+00:00Added an answer on May 18, 2026 at 8:04 pm

    I believe ANLRWorks has a feature to help remove left-recursion from a grammar, although, in my memory, it only works with very basic grammars. It’s been a while since I last worded with it, so you have to investigate yourself on that front.

    To manually remove left-recursion, see: http://www.antlr.org/wiki/display/ANTLR3/Left-Recursion+Removal (make sure to go through all 3 sections)

    EDIT

    I’m not sure if I can help you: you seem to be totally missing the point that ANTLR can’t cope with left-recursive grammars. Your following parser rules:

    seq_statement 
      :  seq_statement ';' statement 
      |  seq_statement
      ;
    
    simple_exp
      :  simple_exp OP term 
      |  term    
      ;
    
    term    
      :  term OP factor factor 
      |  factor  
      ;
    

    are all so obviously left recursive, that I am not sure how to explain this any clearer. I mean, can’t you see what’s wrong with a rule like:

    a
      : a b
      ;
    

    ? Which is basically the same as your seq_statement rule.

    I get the impression you’re trying to convert some existing grammar into an ANTLR grammar. Is this the case? And do you really know what left-recursion really means?

    EDIT II

    Something like:

    parse
      :  block EOF 
      ;
    
    block
      :  statement (';' statement)* ';'? 
      ;
    
    statement
      :  'read' expression  
      |  'write' expression 
      |  ifStatement
      |  repeatStatement
      |  assignment
      ;
    
    ifStatement
      :  'if' expression 'then' block? ('else' block?)? 'end' 
      ;
    
    repeatStatement
      :  'repeat' block? 'until' expression 
      ;
    
    assignment
      :  Identifier ':=' expression 
      ;
    
    expression
      :  equalityExp
      ;
    
    equalityExp
      :  relationalExp (('=' | '!=') relationalExp)*
      ;
    
    relationalExp
      :  additiveExp (('>=' | '<=' | '>' | '<') additiveExp)*
      ;
    
    additiveExp
      :  multiplicativeExp (('+' | '-') multiplicativeExp)*
      ;
    
    multiplicativeExp
      :  atom (('*' | '/' | '%') atom)*
      ;
    
    atom
      :  Identifier
      |  Int
      |  '(' expression ')' 
      ;
    
    Int
      :  '0'..'9'+
      ;
    
    Identifier
      :  'a'..'z'+
      ;
    
    Space
      :  (' ' | '\t' | '\r' | '\n') {skip();}
      ;
    

    ought to do the trick.

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

Sidebar

Related Questions

Hi I want to write a grammer( Using ANTLRWORKS ) that accept later (
I want write jquery code that will show form inputs after a checkbox is
I'm using QI and Phoenix, and I want to write a small grammar that
I want write a little code analyzer which parses nested structures and translates into
I want to write an NSOutputStream to a server with apple's sample code: NSURL
I want to write a unit test for a Django manage.py command that does
I want to write a JAR file that makes use of the javax servlet
I want to write a simple web framework myself using WSGI, Python. I am
I want write this sql select statment in mysql v 3.23 select * from
I have whole page HTML in my database and i want write that html

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.