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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:21:54+00:00 2026-06-05T11:21:54+00:00

I want to parse some assignments, where I only care about the assignment as

  • 0

I want to parse some assignments, where I only care about the assignment as a whole. Not about whats inside the assignment. An assignment is indiciated by ':='. (EDIT: Before and after the assignments other things may come)

Some examples:

a := TRUE & FALSE;
c := a ? 3 : 5;
b := case 
          a : 1;
          !a : 0;
        esac;

Currently I make a difference between assignments containing a ‘case’ and other assignments. For simple assignments I tried something like ~('case' | 'esac' | ';') but then antlr complained about unmatched tokens (like '=').

assignment : 
   NAME ':='! expression ;

expression : 
    ( simple_expression | case_expression) ;


simple_expression : 
    ((OPERATOR | NAME) & ~('case' | 'esac'))+  ';'! ;

case_expression : 
    'case' .+ 'esac' ';'! ;

I tried replacing with the following, because the eclipse-interpreter did not seem to like the ((OPERATOR | NAME) & ~('case' | 'esac'))+ ';'! ; because of the 'and'.

   (~(OPERATOR | ~NAME | ('case' | 'esac')) |
    ~(~OPERATOR | NAME | ('case' | 'esac')) |
    ~(~OPERATOR | ~NAME | ('case' | 'esac')))  ';'!

But this does not work. I get

“error(139): /AntlrTutorial/src/foo/NusmvInput.g:78:5: set complement is empty |—> ~(~OPERATOR | ~NAME | (‘case’ | ‘esac’))) EOC! ;”

How can I parse it?

  • 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-05T11:21:56+00:00Added an answer on June 5, 2026 at 11:21 am

    There are a couple of things going wrong here:

    • you’re using & in your grammar while it should be with quotes around it: '&'
    • unless you know exactly what you’re doing, don’t use ~ and . (especially not .+ !) inside parser rules: use them in lexer rules only;
    • create lexer rules instead of defining 'case' and 'esac' in your parser rules (it’s safe to use literal tokens in your parser rules if no other lexer rule can potentially match is, but 'case' and 'esac' look a lot like NAME and they could end up in your AST in which case it’s better to explicitly define them yourself in the lexer)

    Here’s a quick demo:

    grammar T;
    
    options {
      output=AST;
    }
    
    tokens {
      ROOT;
      CASES;
      CASE;
    }
    
    parse
     : (assignment SCOL)* EOF -> ^(ROOT assignment*)
     ;
    
    assignment 
     : NAME ASSIGN^ expression 
     ;
    
    expression
     : ternary_expression
     ;
    
    ternary_expression
     : or_expression (QMARK^ ternary_expression COL! ternary_expression)?
     ;
    
    or_expression
     : unary_expression ((AND | OR)^ unary_expression)*
     ;
    
    unary_expression
     : NOT^ atom
     | atom
     ;
    
    atom
     : TRUE
     | FALSE
     | NUMBER
     | NAME
     | CASE single_case+ ESAC -> ^(CASES single_case+)
     | '(' expression ')'     -> expression
     ;
    
    single_case
     : expression COL expression SCOL -> ^(CASE expression expression)
     ;
    
    TRUE   : 'TRUE';
    FALSE  : 'FALSE';
    CASE   : 'case';
    ESAC   : 'esac';
    ASSIGN : ':='; 
    AND    : '&';
    OR     : '|';
    NOT    : '!';
    QMARK  : '?';
    COL    : ':';
    SCOL   : ';';
    NAME   : ('a'..'z' | 'A'..'Z')+;
    NUMBER : ('0'..'9')+;
    SPACE  : (' ' | '\t' | '\r' | '\n')+ {skip();};
    

    which will parse your input:

    a := TRUE & FALSE;
    c := a ? 3 : 5;
    b := case 
              a : 1;
              !a : 0;
            esac;
    

    as follows:

    enter image description here

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

Sidebar

Related Questions

I want to get the whole text of an Element to parse some xhtml:
I'm using NSJSONSerialization to parse some JSON from my web service, and I want
I have some XML that I want to parse using the lxml method in
I want to parse xml file in utf-8 and sort it by some field.
Let's say this page www.example.com/mypage returns some html that I want to parse in
I want to do some preprocessing on my views before they are parsed by
As the title says, I want to parse some Java source code in Java.
i need to parse some data and i want to convert AutomaticTrackingSystem to Automatic
I'm using domDocument to parse some HTML, and want to replace breaks with \n.
I use GLib to parse some command-line options. The problem is that I want

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.