Simple example of how to get an AST

SyntaxEditor for Windows Forms Forum

Posted 13 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 13 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 (v2018.1 build 0342) was released 11 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.