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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:29:32+00:00 2026-06-12T12:29:32+00:00

I have a very simple DSL that consists of a validator element that contains

  • 0

I have a very simple DSL that consists of a validator element that contains a list of comparators:

Validator:
  'validator' name = ID '{'
    comparisons+=Comparison*
  '}'
;

Comparison:
  LessThan | GreaterThan | EqualTo
;

LessThan:
  'lt' value = INT
;

With this I am trying to generate C code. Where I loop through each validator, create a C file (based on the name of the validator) and place the comparators into a ternary conditional statement. When I loop though each comparator it calls a definition for the class Comparison which outputs the if statement. A cut down example (outputs something similar to CPPUNIT):

int
main(int argc, char **argv)
{
  // parse argv[1] if it exists -> place into i
  printf("%c", i < (comparator_value_1) ? '.' : 'F');
  printf("%c", i > (comparator_value_2) ? '.' : 'F');
  printf("\n");
  return 0;
}

I can get all of this working nicely; however the problem I am having is that I seem to have to do a selection of conditionals within my Comparison generator. I seem unable to override the generator by adding a handler for LessThan.

def compile(Comparison c) '''
  printf("%c",
    i «IF c.eClass.name.equals("LessThan")»...«ENDIF» «c.value»
      ? '.' : 'F');
'''

When I attempt to overload it:

def compile(LessThan lt) '''
  printf("%c", i < «c.value» ? '.' : 'F');
  ...
'''

The overloaded routines don’t get called, which is at best unfortunate.

It is called by if this makes any difference:

«FOR c:v.comparisons»
  «c.compile»
«ENDFOR»

Where ‘v’ is the Validator.

Does Xtext have this ability?

  • 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-12T12:29:33+00:00Added an answer on June 12, 2026 at 12:29 pm

    Xtext can use polymorphic dispatch (courtesy of @SpaceTrucker) in which:

    a function or method can be dynamically dispatched based on the run time (dynamic) type of more than one of its arguments.

    In order to use this functionality I had to add one word to it dispatch.

    def dispatch expandComparator(GreaterThan gt) '''
        printf("%c", i < «gt.value» ? '.' : 'F');
    '''
    
    def dispatch expandComparator(EqualTo eq) '''
        printf("%c", i == «eq.value» ? '.' : 'F');
    '''
    
    def dispatch expandComparator(LessThan lt) '''
        printf("%c", i < «lt.value» ? '.' : 'F');
    '''
    

    And use the following to generate it:

    «FOR c:v.comparisons»
        «c.expandComparator»
    «ENDFOR»
    

    The name of the function had to change as compile was a single dispatch function.

    The following link has more details on this solution.
    http://dslmeinte.wordpress.com/2012/08/03/polymorphic-dispatch-in-xtend/

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

Sidebar

Related Questions

i have very simple problem. I need to create model, that represent element of
I have a very simple table called Member , which consists of the following:
I have a very simple script that creates a user: <?php include 'mysqlserver.php'; session_start();
I have very simple code: List<String> list = new ArrayList<String>(); String a = a;
I have very simple query that calls a UDF which splits a field by
Scala 2.8.1 I have implemented a very simple external DSL using parser/combinators for QA
I have very simple form, with input like this: <input id=my_id multiple=true type=file name=image_name[]
I have very simple XML in a string that I'm trying to load via
I have very simple method that is being called by performSelector:withObject:afterDelay: however no matter
I have very simple question that I cannot find the answer to. In the

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.