CSLY is highly inspired by the python lex yacc library (PLY) and aims at easen the writing of lexer and parser with C#.
If you're too impatient to further read this readme here is a quick getting started that will guide you through the implementation of a dumb parser.
Complete documentation can be found in the wiki
CSLY provide some special features that make it easier or safer to use.
CSLY has been thought to avoid any extra build step. Parser generators often need a build time step to generate target language source code that do the parse job. Juste include a nuget and configure your lexer/parser in pure C# code.
A lexer/parser is defined with only 2 files :
* a C# enum
for the lexer
* a C# class
for the parser
Lexeme and parser production rules are defined with c# attributes
making notation even more compact.
this features already exists with parser combinators (like sprache or Eto.Parse), but productions rules are defined using either BNF or EBNF notation which I think is more natural and easier to understand for maintenance.
See Lexer for lexers definition. And BNF or EBNF for parser definitions.
CSLY is strictly typed, every parser is defines according to its input and output types. For further reading about parser typing, head to typing section to correctly type your parser.
Many language needs parsing expressions (boolean or numeric). A recursive descent parser is hard to maintain when parsing expressions with multiple precedence levels. So CSLY offers a way to express expression parsing using only operator tokens and precedence level. CSLY will then generates production rules to parse expressions. It also manages precedence and left or right associativity.
Lexemes are often similar from one language to another. So CSLY introduces a Generic Lexer that defines common lexemes that can be reused across languages. furthermore the generic has better performance than a regex based lexer.
See Generic lexer for generic lexer and Lexer for general presentation.
CSLY is not a full featured parser generator like ANTLR. Hence you should not use it to define a full featured language (say C# or Java).
CSLY is dedicated to small Domain-Specific Languages that can easily be embedded in a C# code base.
Install from the NuGet gallery GUI or with the Package Manager Console using the following command:
Install-Package sly
or with dotnet core
dotnet add package sly