Project DescriptionVe Parser is an implementation of Combinatory Parser concept in .Net environment using C# language. It allows to very easily write parsers for your language by writing its grammar using your favorite .Net language. Not only it does parse the input, but also it generates a decent output.
Introuduction
Like other combinatory parsers, we used functional structures available in .Net and specially High Order Functions in order to design Ve Parser; however, the functions, which are used in the Ve parser, have a different structure in comparison with others; and consequently, a number of remarkable merits are provided. For instance, this parser is by far the simplest and easiest to understand among other combinatory parsers and it has the possibility of parallel processing for choice combinators. On the other hand, the usage of object-oriented approaches will lead to avoid of restrictions of pure functional programming. Moreover, Ve Parser has the ability of generating Abstract Syntax Tree in an integrated way and the output of parsing will be a concrete conceptual object.
Sample Code
Probably a good way to describe the library is a sample code of how a Parser using Ve Parser would look like:
Here is a small part of a sample parser for C# language (to make it more understandable and to make it smaller only a part of the whole parser is included):
// Define some keywords using the Keyword_of function and assign it to Parser deleagates
Parser @public = Keyword_of("public");
Parser @private = Keyword_of("private");
Parser @protected = Keyword_of("protected");
Parser @get = Keyword_of("get");
Parser @set = Keyword_of("set");
Parser @enum = Keyword_of("enum");
Parser @class = Keyword_of("class");
Parser @internal = Keyword_of("internal");
Parser @using = Keyword_of("using");
Parser @namespace = Keyword_of("namspace");
// Combine some basic parsers using any and zeroOrOne combinators and create a more high level parser
Parser member_access_level = zeroOrOne(any(
set_choice("access_level", "public", @public),
set_choice("access_level", "private", @private),
set_choice("access_level", "protected", @protected),
set_choice("access_level", "internal", @internal),
set_choice("access_level", "protectedinternal", seq(@protected, @internal))));
// Combine parsers using seq function
Parser property_get = seq(Keyword_of("get"), Symbol_of("{"), zeroOrMore(statement), Symbol_of("}"));
Parser property_set = seq(Keyword_of("set"), Symbol_of("{"), zeroOrMore(statement), Symbol_of("}"));