2017 © Pedro Peláez
 

library lime

Lime parser generator

image

gene-sis/lime

Lime parser generator

  • Sunday, November 20, 2016
  • by gene.sis
  • Repository
  • 0 Watchers
  • 1 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 8 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Interpreter pattern got you down? Time to use a real parser? Welcome to Lime., (*1)

  1. Use composer to install Lime., (*2)

    composer require gene-sis/lime, (*3)

  2. Build lime_scan_tokens for your development OS., (*4)

    For Windows run flex -t vendor\gene-sis\lime\scanner\lime_scan_tokens.l > vendor\gene-sis\lime\scanner\lime_scan_tokens.c and gcc vendor\gene-sis\lime\scanner\lime_scan_tokens.c -o vendor\gene-sis\lime\scanner\lime_scan_tokens.exe from the command line., (*5)

  3. Write a grammar file, (*6)

    Lime uses slightly modified and tweaked Backus-Naur forms. You can look at the .lime examples in the folder /vendor/gene-sis/lime/examples to understand the grammar., (*7)

    You can refer to your components by numbers the way BISON demands exp = exp '+' exp { $$ = $1 + $3; ); or assign symbolic names (similar to C-based "Lemon" parser from which Lime derives its name) exp = exp/a '+' exp/b { $$ = $a + $b; ); Oh, and one other thing: symbols are terminal if the scanner feeds them to the parser. They are non-terminal if they appear on the left side of a production rule. Lime names semantic categories using strings instead of the numbers that BISON-based parsers use, so you don't have to declare any list of terminal symbols anywhere., (*8)

  4. Defined pragmas, (*9)

    • %namespace define the namespace of your parser file (enclose in single quotes) e.g. %namespace 'YourProject\Extensions\Lime'
    • %class define the class name of your parser
    • %start define the start symbol of your grammar
    • %left
    • %right
    • %nonassoc
    • %expect
  5. Build your parser, (*10)

    php /vendor/gene-sis/lime/lime.php path/to/your/grammar/file.lime > MyParser.php, (*11)

  6. Integrate your parser into your project, (*12)

    // below the namespace
    use YourProject\Extensions\Lime\MyParser;
    use Genesis\Lime\ParseEngine;
    use Genesis\Lime\ParseError;

    // create the parser instance
    $parser = new ParseEngine( new MyParser() );

    // run the parser
    try {
        // reset the parser
        $parser->reset();

        // tokenize your input with a suitable function/method and feed the
        // tokens to the parser
        foreach( tokenize( $input ) as $token ) {
            $parser->eat( $token['type'], $token['value'] );
        }

        // get the result
        $result = $parser->eat_eof();

    } catch ( ParseError $e ) {
        // handle parse errors
        $error = $e->getMessage();
    }
  1. You now have the computed semantic value of whatever you parsed. Add salt and pepper to taste, and serve.

The Versions

20/11 2016

2.0.0

2.0.0.0

Lime parser generator

  Sources   Download

The Requires

  • php >=5.3.0

 

20/11 2016

dev-master

9999999-dev

Lime parser generator

  Sources   Download

The Requires

  • php >=5.3.0

 

20/11 2016

2.x-dev

2.9999999.9999999.9999999-dev

Lime parser generator

  Sources   Download

The Requires

  • php >=5.3.0