Project Description

The Hime Parser Generator generates lexers and parsers for .Net 2.0 and above. It supports deterministic (LALR) and generalized (GLR) parsing methods.

Features

  • Generate lexers and parsers either through the command line tool or programmatically using the library.
  • Generate the lexers and parsers either as C# sources, or directly as a .Net assembly.
  • Generate a documentation package of the produced parsers for debugging purposes as HTML pages.
  • Expressive input language for the specification of lexical and syntactical rules.

Quick How-to

Write your grammar in the input language. For example, a grammar for simple mathematical expressions:
cf grammar MathExp {
    options {
        Axiom = "exp";
        Separator = "SEPARATOR";
    }
    terminals {
        INTEGER    -> [1-9] [0-9]* | '0' ;
        REAL        -> INTEGER? '.' INTEGER  (('e' | 'E') ('+' | '-')? INTEGER)?
                    |  INTEGER ('e' | 'E') ('+' | '-')? INTEGER ;
        NUMBER    -> INTEGER | REAL ;
        WHITE_SPACE    -> 0x0020 | 0x0009 | 0x000B | 0x000C ;
        SEPARATOR    -> WHITE_SPACE+;
    }
    rules {
        atom -> NUMBER
            | '(' exp ')' ;
        factor -> atom
            |  factor '*' atom
            |  factor '/' atom ;
        term -> factor
            | term '+' factor 
            |  term '-' factor ;
        exp -> exp_op1 ;
    }
} 


Execute the following command line:
himecc MathExp.gram

The program generates 4 files:
  • MathExpLexer.cs, a C# source file for the generated lexer to be included in your project
  • MathExpParser.cs, a C# source file for the generated parser to be included in your project
  • MathExpLexer.bin, a resource file to be included as an embedded resource in your project
  • MathExpParser.bin, a resource file to be included as an embedded resource in your project

To parse mathematical expression, include a reference to Hime.Redist.dll in your project and use the following lines:
MathExpLexer lexer = new MathExpLexer("2 + 3");
MathExpParser parser = new MathExpParser(lexer);
ASTNode root = parser.Parse() ;

Last edited Jun 19, 2013 at 8:28 AM by lwouters, version 16