Generate parser from bison file

SyntaxEditor for Windows Forms Forum

Posted 13 years ago by Tobias Lingemann - Software Devolpment Engineer, Vector Informatik GmbH
Version: 4.0.0288
Avatar
Hi,

is it possible to generate the semantic parser from a bison file? I just started looking at parser generators that can produce C# code like ANTLR.
Would it be possible to modify the existing bison file to get a semantic parser for SyntaxEditor?

Basically we just want to improve the maintainability for the editor, whenever the compiler is changed. It would be a huge benefit, if we would not have to make all changes twice.


[Modified at 06/07/2011 08:59 AM]


Best regards, Tobias Lingemann.

Comments (3)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Tobias,

Sorry our product doesn't have any direct integration with Bison. Our WPF/Silverlight versions do have free add-ons that allow ANTLR or Irony to be easily used for parsing, etc.

That being said, you can hook up any third-party parser like Bison into SyntaxEditor. Basically in the WinForms version you'd just override the semantic parsing calls for your language and call your Bison parser from there.


Actipro Software Support

Posted 13 years ago by Tobias Lingemann - Software Devolpment Engineer, Vector Informatik GmbH
Avatar
Thanks for your answer.

The lexer and parser of the compiler are currently implemented in C++. If we would port it to C++/CLI, we would be able to use it in SyntaxEditor, right?
Basically I just need to call them in PerformSemanticParse and PerformLexicalParse.
However the generated Tokens still have to be inherited from IToken.
The lexer would deliver the token to an instance of ILexicalParseTarget
The parser would get the tokens from an instance of MergableLexicalParserManager or directly from a Document instance.

Is that correct?


Best regards, Tobias Lingemann.

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Tobias,

You probably wouldn't be able to use your Bison lexer as our lexer since our lexers need to be able to pick up anywhere and resume lexing. Most lexers that come with parser generators are very closely tied to the parser state and don't support "incremental parsing" very well. We haven't looked at the Bison lexer though so perhaps that isn't the case.

Our newer WPF/Silverlight versions have a much nicer design for things where you just have interfaces you implement for various language services (ILexer, IParser, etc.). But for the WinForms version to do a custom lexer, you'd override your SyntaxLanguage class' PerformLexicalParse method. It passes in a document, the text range to parse, and the parse target. The documentation topic "SyntaxEditor Language Definition Guide - Lexical Parsing / Lexical Parsing" shows a code snippet of doing this.

If you can't use the Bison parser for this, you can just create a new pattern-based dynamic language to do the lexing for syntax highlighting, similar to our samples. Even if you do this you can still call your Bison parser for semantic parsing.

For a semantic parser, this is where you'd do something like this:
public override void PerformSemanticParse(Document document, TextRange parseTextRange, SemanticParseFlags flags) {
    SemanticParserService.Parse(new SemanticParserServiceRequest(SemanticParserServiceRequest.MediumPriority,
        document, parseTextRange, flags, this, document));
}
If you started the SemanticParserService then it will run your parse in a worker thread, freeing up your UI. You'd also need to have your SyntaxLanguage implement ISemanticParserServiceProcessor and add this:
void ISemanticParserServiceProcessor.Process(SemanticParserServiceRequest request) {
    request.SemanticParseData = (call Bison parser here and return result)
}
Hope that helps!


Actipro Software Support

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

Add Comment

Please log in to a validated account to post comments.