Rulz.NET pages:   Home   Downloads   Documentation   Screenshots   Credits   Please Comment   SourceForge.net Logo

Rulz.NET Documentation

RulzCompiler is based on the mono compiler (Thanks to Miguel and Novell!). As such, behaviour is mostly the same as that of the mcs compiler. What is described below are the additional feature, the delta.

This section covers:
  • 1. Quick start
  • 2. Types of queries
  • 3. New langugage keywords
  • 4. RulzCompiler new command-line options
  • 5A. Built-in functions
  • 5B. Pre-defined attributes
  • 5C. Pre-defined classes
  • Rulz.NET quick start

    Download complier binary package, extract, and on the command-line, type the following:
    > rulzcompiler.exe /t:exe /r:rulz_base.dll airline.rulz
    > airline.exe
    

    If all goes well, you will see this output:
    
    MatchAll Begin: Pilot, ResultLength=1
      Result 9.9
    MatchAll End
    
    MatchAll Begin: Employee, ResultLength=0
    MatchAll End
    
    MatchFirst Begin
      Result 3.85
    MatchFirst End
    
    on Linux, you have to prepend 'mono' to each command

    Rules

    Query types

    Rulz.NET currently supports 3 query types:
  • A. Match First,
  • B. Match One,
  • C. Match All.


  • You use rinterface attributes, such as [GenerateFctMatchFirst], to determine which of these gets generated by the compiler.

    To illustrate the difference between the 3 types, imagine a sample rules system with three rules:
    Rule 1. Pay Mary ten euros.
    Rule 2. Pay John two euros.
    Rule 3. Pay John one euro.
    
    Then, if you ask 'how much to pay John?', a 'MatchAll' query will return 2 results. A 'MatchFirst' will return EUR2, and a 'MatchOne' will throw an exception because it knows that there is no unique solution.

    Rulz.NET new language keywords

    Rulz.NET supports all of C# keywords, such as class and struct.

    In addition, it supports 4 additional keywords: rclass, rinterface, rule, and where.
    Usage: An rclass is a rules class, for which additional methods will be generated by the rulzCompiler.

    RulzCompiler additional command-line options

    /target:csharp

    Instructs the compiler to output the parsed object tree as C# source code. Useful for running in Visual Studio when debugging rules. The output occurs before the compiler's Resolve/Emit step, so that a syntax error in rule body will go unreported by rulzcompiler and you will catch it when you hit VisualStudio-compile.

    /target:csharp_csc

    Same as above, but immediately after outputting C# source, run Microsoft's CSC.exe compiler on the source. Sadly, this is the only way how rulzCompiler can generate PDB files needed for VS debugging.

    Built-in functions

    There are two built-in functions, which are available to every rule:

    1. void require(boolean expression)

    require() is similar to a where keyword but can be used anywhere in the body of a rule. It is a regular C# function that evaluates the boolean expression and throws a RuleFailedException if false, thereby notifying the rules engine that this rule did not match. Note: throwing exceptions is slow.

    2. void cut()

    Reserved for future use.

    RulzCompiler pre-defined attributes

    [GenerateFctMatchFirst]

    [GenerateFctMatchAll]

    [Commutative]

    Reserved for future use.

    [DistributedForeach]

    Reserved for future use.

    [Reversible]

    Reserved for future use. Proposed way of interfacing to the Rete algorithm (Prolog-style unifications).

    RulzCompiler pre-defined classes

    RuleFailedException

    Thrown by a rule when it fails to match. This exception is caught by the query method and not propagated to the user.

    RuleFailedMoreThanOneMatchException

    Derived from RuleFailedException. Indicates that a 'match one' query found multiple matches and thus encountered an ambiguous situation.

    RuleFailedNoMatchException

    Derived from RuleFailedException. Indicates that a 'match first' or 'match one' query found no matches.