Need help to get started

SyntaxEditor for Windows Forms Forum

Posted 14 years ago by Sergey M
Avatar
I'm evaluating your SyntaxEditor and trying to get a handle on it. I'd like to let the user provide me with a simple one-line expression, such as "A+B+123". I'd like to assign that expression to your SyntaxEditor.Document and process all of the tokens exposed. For this simple test I plan on using C# but it could be any C-like language.

As part of tokens processing, I'm only interested in operator tokens and their types, if parser is capable of resolving it that way. I then need to be able to plug some values for each one of those operator tokens and retrieve an "expanded" expression (with values plugged in already). I'm having difficulties trying to figure out how to do this.

I'd also appreciate your comments regarding the task in hand, i.e. is it doable or not and whether I'm on a right track. Any code snippets are or just a gentle push in the right direction would be very much appreciated. Thanks.

Comments (3)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Sergey,

Right now, SyntaxEditor just lexical parses text based on the language definitions you supply. So you can define identifiers, numbers, operators etc. in your language definition. It is up to you how to do that. We provide numerous samples of common languages with SyntaxEditor.

It sounds like you are wanting to do further semantic parsing. We don't currently have any language specific semantic parsers but we would like to work on those for the future. You can make your own. We have a SemanticParser class that you can set to your language definition and use it to provide higher level parsing based on the lexical tokens that were identified. We have numerous customers who have done that. Typically you'd override the PostParse method and write your custom code there.


Actipro Software Support

Posted 14 years ago by Sergey M
Avatar
As I mentioned earlier, I'm gonna start with a simple expression evaluation wrapper. Could I just use one of the predefined language definitions such as C# or J/Script with numbers, strings, operators and identifiers rules setup already? I assume that would be one of those language .xml files provided with the trial install, right?

Looks like SyntaxEditor.Document.Tokens collection is what I need. I need to be able to extract token values. Is this the right way to do that:

string tokenValue = doc.Text.Substring(token.StartOffset, token.Length);

I might be wrong here but I don't think I'd even need to bother with semantic parsing. For now I'm gonna just stuff it into CodeDOM and let it tell me whether the syntax is correct or not. When I'm ready to expose syntax editor functionality that's the point I think I'll need to follow your semantic parser suggestions. Does this sound about right?

One other question. I see that all tokens have their IDs set to 0. I saw a topic on that in the help file but am still not sure how to set it up correctly. Could you give me some pointers on that please?

Thanks for your help.
Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Yes you can start out with a predefined XML language definition if you'd like. The best way to get a token's text is:
editor.Document.GetTokenText(token);
Yes it sounds like you have the right idea for the semantic parser.

For token ID's, the easiest way is to make a class that defines constants for each ID value. Make the constant names match the TokenKeys. Then in the SyntaxLanguage tag, specify the Type of the class that has the constants. SyntaxEditor will use reflection to auto-assign the ID's by matching the TokenKey with the constant names.


Actipro Software Support

The latest build of this product (v2018.1 build 0341) was released 10 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.