Project Description
Ve 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.

What is a Combinator Parser How Ve Parser works?

The only jargon I used in the project and even in the source codes are 'Combinator Parser' and 'Lexer'. I dont want to make it more complex by explaining what a combinator parser is, but if you are curious you can see its page in wiki pedia. You see, its a little complicated subject but Ve Parser is much simpler that the name 'combinatory parser' suggests. So instead of describing what is a Combinatory Parser I will describe how Ve Parser works:
Ve Parser is defined only a delegate type named Parser which has no input and has a boolean output. Parser is a delegate type, so variables of type Parser are functions that can be executed, when a Parser executes it returns a boolean value. The result value from a Parser specifies if it was successful for or not.
Then there is ParserBase class which is an abstract class. When you derive from it you have to implement the method GetRootParser. To implement this GetRootParser the BaseParser class provided you with a set of functions which all of them get inputs of type Parser and produce a Parser as result, as long as all of them have the output type of Parser and all of them have input of type Parser they can used combined toghether to form a more mature parser from a more basic parser and finaly make a root parser. For example it would look like 'seq(oneOrMore(....),any(...),seq(any(zeroOrMore(...))))'. Here the seq function is being called by passing the result of oneOrMore parser, any and seq. Then seq parser returns a parser as result.

Features

  • Simple
  • No dependency on any grammar language, only pure C# code can be used to design and implement a parser.

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(@get, Symbol_of("{"), zeroOrMore(statement), Symbol_of("}"));
Parser property_set = seq(@set, Symbol_of("{"), zeroOrMore(statement), Symbol_of("}"));

Last edited Oct 14, 2011 at 2:39 PM by MeysamNaseri, version 4