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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:05:10+00:00 2026-05-30T23:05:10+00:00

I am writing a C# interpreter from scratch for the learning experience, and so

  • 0

I am writing a C# interpreter from scratch for the learning experience, and so far everything has gone smoothly. I have a fully functional C# lexer that outputs all sorts of tokens to the parser. I know how I am going to parse the tokens, but I’m not sure how I should structure my AST (abstract syntax tree).

For example, if I have a simple code fragment:

using System.Xml;

what would the tree look like when parsed?

Like this?

UsingDirective
   Identifier(System)
      Identifier(Xml)

or like this?

UsingDirective
   Identifier(System)
   Identifier(Xml)

If I could get some suggestions and/or examples as to how I could structure things like identifiers with dots in them, if/else if/else statements, variable declaration/assignment combined in one statement (int i = 0;), function definitions, etc. that would be helpful. I just need to get a better idea of how to structure the tree and I can figure out the rest myself. Thanks.

  • 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-30T23:05:11+00:00Added an answer on May 30, 2026 at 11:05 pm

    I’ve written a couple of parsers in the past, and I would generally go for something like this:

    UsingDirective
       IdentifierList
         Identifier (LeftNode) (System)
         Identifier (RightNode) (Xml)
    

    In case of this using System.Collections.Generic

    UsingDirective
       IdentifierList
           IdentifierList (LeftNode)
               Identifier (LeftNode) (System)
               Identifier (RightNode) (Collections)
           Identifier (RightNode) (Generic)
    

    Unlike Roslyn, I prefer keeping my ASTs light by not including tokens such as semi-colon, the using keyword etc since the compiler has no need for them.

    Parsers I’ve written specifically for IDEs look different – they carry all this extra stuff along with more information such as line and column numbers.

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

Sidebar

Related Questions

I'm writing an interpreter for an experimental language. Three of the main constructs of
I'm writing a toy interpreter with a REPL in Java. I'd like to generate
I'm writing a small interpreter for a simple BASIC like language as an exercise
I've heard of the idea of bootstrapping a language, that is, writing a compiler/interpreter
I'm writing a command line interpreter and I'm trying to setup formats for individual
I'm writing a simplified Pascal parser/interpreter and now I'm thinking about segmentation faults. I'm
I'm in the process of writing a small lisp interpreter in haskell. In the
I'm writing a System::Wrapper module to abstract away from CORE::system and the qx operator.
I often have to edit script files, the interpreter for which treats files that
Apparently Apple has changed some term in the agreement again. From http://www.appleoutsider.com/2010/06/10/hello-lua/ section 3.3.2

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.