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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:30:21+00:00 2026-06-16T17:30:21+00:00

I know that there are other question about compiler/interpreter technology and also very good

  • 0

I know that there are other question about compiler/interpreter technology and also very good code to study like IronPython to Jurassic.
To me is quite clear how to build an AST (Abstract Syntax Tree) from source, writing a top-descent parser (for the moment I prefer writing than using code-generation tool).

Most sources I’m trying to study when used as interpreters compile the program on fly using API like Reflection.Emit.
Now I’d like to know best practices to build a real interpreter that doesn’t compile to .NET VM the source.

Once I got the AST how can I execute the code? Should I use interpreter or visitor design patterns? Or doing something different? What’s the best or canonical way?

I know that there’s already a question like this but I like more information and more specific to a .NET/C# implementation, if possible.

Regards, Giacomo

  • 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-16T17:30:22+00:00Added an answer on June 16, 2026 at 5:30 pm

    Should I use interpreter or visitor design patterns?

    I think the names give a hint 😉

    Visitors are good for general operations on ASTs but for performing a singular function (execution / interpretation) you just need one method, hence the interpreter pattern.

    Here’s a very simple example (but it really doesn’t get much more complicated than that, even for complex interpreters):

    // Holds function scope etc.
    class Context {}
    
    abstract class Node {
        public abstract object Execute(Context ctx);
    }
    
    class Number : Node {
        private readonly int x;
    
        public Number(int x) { this.x = x; }
    
        public override object Execute(Context ctx) { return x; }
    }
    
    class Addition : Node {
        private readonly Node left, right;
    
        public Addition(Node left, Node right) {
            this.left = left;
            this.right = right;
        }
    
        public override object Execute(Context ctx) {
            // Verification omitted: do the nested expressions evaluate to a number?
            return (int) left.Execute(ctx) + (int) right.Execute(ctx);
        }
    }
    

    … and there you have it. A simple interpreter that knows addition. And here’s an example of usage:

    var ast = new Addition(new Number(23), new Number(42));
    Console.WriteLine("Result = {0}", ast.Execute(new Context()));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know there are few question about const correctness where it is stated that
I know there are other questions that have similar issues, but I have read
Does anyone know there have any other way that (by not using json_encode and
Or any other normal scripting language for that matter. I know there is VBScript
I know there are other questions with that same title, but none of them
I have a question about how compiler-set symbols, in particular CPU feature flags (like
I know that there are others posts with solutions on the site but i
I know that there are some threads have a similar issue with this thread.
I know that there are lot's of questons on this, but all seem to
I know that there are currently questions on SO already pertaining to saving jQuery

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.