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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:33:44+00:00 2026-06-14T13:33:44+00:00

I am writing an interpreter that converts my DSL language into C# which is

  • 0

I am writing an interpreter that converts my DSL language into C# which is then compiled and shipped as a standalone executable.
I have successfully managed to handle variable definitions and some basic arithmetic expressions computation.

So far, I did all of this using ANTLR without generating AST trees. I managed to do everything only by embedding action code into the grammar as shown below:

statement
    : var_declaration
    | if_statement
    ;
// k = var or k = var.something.somethingelse
var_declaration
    : 
    varType=ID varName=ID ASSIGN r=rvalue
    {
        if(variablesTable.ContainsKey(varName.Text)){
            // Variable ID not defined yet, cannot continue;
            ReportError("A local variable '"+varName.Text+"' is already defined");
            return;
        }
        if(r == null){ ReportError ("No r-value specified"); return;}
    }
    ;

if_statement
    : 'if' expression s1=statement ('else' s2=statement)?

statement
    :...
expression
    :...

I am now struggling on how to handle and properly generate code for if and loop statements.

Question

  1. Do I have to build an AST tree to handle conditional and loop
    statements?
  2. I have googled this over and over again without finding clear
    tutorials on how this can be done with or without AST trees, do you
    know of any good tutorials on this?

Thanks in advance,

  • 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-14T13:33:45+00:00Added an answer on June 14, 2026 at 1:33 pm

    It looks like checking for if statements is possible through action code embedded in the grammar but this is the not recommended way of dealing with this as it won’t scale once the grammar grows big.

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

Sidebar

Related Questions

I'm writing a programming language interpreter. I have need of the right code idiom
I've heard of the idea of bootstrapping a language, that is, writing a compiler/interpreter
I'm writing an interpreter in Python for a very simple language grammar. I have
I'm writting a PLC language interpreter using C#. That PLC language contains over 20
I'm writing a small interpreter for a simple BASIC like language as an exercise
I'm writing a PLC language interpreter using C#. My interpreter has its own type
I'm writing a simple parser/interpreter for a language . The instructions keep mentioning 'deferred
I am writing an interpreter that parses an array of String and assigns each
I'm writing an interpreter for an old in-game scripting language, and so need to
I'm writing a BF interpreter in C and I've run into a problem reading

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.