troubleshooting Question

C# Code Tree for Custom Language

Avatar of Misha
MishaFlag for Russian Federation asked on
Programming.NET ProgrammingC#
6 Comments1 Solution55 ViewsLast Modified:
Hello, Experts!
I need to create code tree for custom language like pascal.
Now I try to add code statements in tree.
I have some code in this language, for examplle:
let a = 2
if ( a > 2)
   while ( a > 2)
      let a = 2
   end while
   let a = 2
end if
I have classes for each statements,
class BaseStatement
{
   internal List<BaseStatement> statements;
}

sealed class IfStatement : BaseStatement{}
sealed class LetStatement : BaseStatement{}
sealed class WhileStatement : BaseStatement{}
...
etc
Also I have Tree Class
sealed class Tree
{
  BaseStatement root;
}
1) I need the best and beautifull solution to select node for adding current stament. I read code by rows.
If I get "IF" in my parser, root should be IfStatement and next statements should be added to it.
If I get "END IF", I need make  step up to above node. May be it should be something like switcher..

2) LetStatement  has no descendants .Whether it should inherit class BaseStatement??

My result should be like this

root
  LetStatement
  IfStatement
     WhileStatement
        LetStatement
     LetStatement
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros