Simple example of how to get an AST

SyntaxEditor for Windows Forms Forum

Posted 17 years ago by Willem Mitchell
Avatar
I'm currently evaluating the editor for a project where I have to add C# scripting capabilities. While the editor functionality is great, I need to be able to get an parse and get an AST from a text file, not from the editor. I'd like to use the C# add-on parser to do this.

I've used ANTLR before and what I'm trying to acheive with an ANTLR generated parser would look like something like this:

//Initialize lexer
CSharpLexer lexer = new CSharpLexer(fileStream);
.
.
CSharpParser parser = new CSharpParser(lexer);

//If the text file contained a single function
parser.MethodBody()
Antlr.Collection.IAST treeRoot = parser.GetAST();
WalkTree(treeRoot);

Does anyone have a simple example of how to do this with the SyntaxEditor C# parser?

Comments (1)

Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Take a peek at the Document Outline QuickStart. It shows how to parse a file without loading it into the editor. It ends up using the CompilationUnit AST result to build a document outline treeview but you could do anything with the CompilationUnit.


Actipro Software Support

The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.