Posted 15 years ago by leon
Avatar
Hi,

I am trying to create a semantic parser using your grammar designer but there are some stuff I don't understand. Can you please help?

1. Can I edit the grammar.xml in visual studio? And then use your designer to parse it?

2. I am looking at the simple grammar xml file but I really don't understand how it defines things? It says function declaration and a bunch of properties and some custom code but nothing else to define what is a function definition. How does it work?

3. What about the tons of custom C# code inserted into the grammar xml file. Do they have to be defined for any language? It has methods like IsCollapsible but aren't they built-in? I don't see why we have to add a ton of code in between.

4. Also I couldn't fine lexer.xml for the simple language. Does it exist? I wanted to compare these 2 xml files side by side in the hopes of understanding how it works.

5. Is there a step by step tutorial for this stuff? I am really struggling to understand is and it looks like a well designed but extremely large framework to get a hold of at once.




Thanks in advance,
Leon

Comments (2)

Posted 15 years ago by leon
Avatar
Also I was looking at the other dynamic syntax language C# files, and was wondering:

6. Do they provide the same functionality of having a semantic parser definition? Or are these just for the expand/collapse functionality of the editor but nothing more?

7. Suppose I am using the JScriptDynamicSyntaxLanguage.cs for my language, how would I implement it so that I get expanding/collapsing functionality on anything that starts with the keyword "function" like:

function identifier arg arg arg =
(
code
(code)
method()
//comment
)

and ends with a parenthesis?

Basically I am having a problem with specifying the end ")" in the GetTokenOutliningAction method, similar to how you did it. The only example there is the multi line comment but that only looks for the first */ to finish it.

Thanks again in advance. And sorry for asking a lot of questions, but I really try to understand it.
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Leon,

Let me try and help answer some of your questions.

1) Yes, we sometimes do that too.

2) FunctionDeclaration is defined up in the AstNodes section. So it is making a .NET class named FunctionDeclaration which is an AST node. The code in the production for FunctionDeclaration then creates one of those node instances, matches the appropriate tokens, and updates the FunctionDeclaration node's properties. The end result of the FunctionDeclaration's production is that you have a FunctionDeclaration object created and initialized based on the text in the document.

3) There is a lot of code that is automatically generated for AST nodes. However sometimes you may wish to add additional constructors, etc. In the case of IsCollapsible, we are having that node implement an interface that requires the IsCollapsible property to be included. Most of the C# code defined up in the AST nodes is optional.

4) There is no lexer.xml for the Simple language. We defined its lexer programmatically instead, so that we could show an example of a programmatic lexer. However you can create a dynamic language from a language definition file and use that language with a semantic parser created by a grammar. That's what we do with the XML language in our Web Languages Add-on.

5) Unfortunately the documentation we have and the samples are all that is available right now. We are currently working on the newer WPF version of SyntaxEditor where we are spending a lot of time improving every area of the product, trying to make things simpler and streamlined where possible and provide a ton of samples (almost 60 already). We are getting close to the point there where we are going to be implementing grammar/AST like in WinForms and when we do we definitely want to come up with more of a step-by-step process to follow for this sort of thing. In the meantime, feel free to post questions and we'll reply.

6) Dynamic language definition files only define the lexer. Their code-behind (like JScriptDynamicSyntaxLanguage.cs) can add outlining too. They don't relate to grammar XML files in any way, which we can see as a possible source of confusion. In the newer WPF version of SyntaxEditor, we're planning on combining everything into one file so that things are clearer.

7) With token-based outlining like that, it's difficult to do anything complex because you can only look for fixed pairs of tokens. You are better off making an AST of your document (even if it's super simple and just provides the ranges of your functions) and then use the outlining mechanism that the Simple language sample does, where it uses the AST to drive automatic outlining.


Actipro Software Support

The latest build of this product (v24.1.1) was released 24 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.