Code Monkey home page Code Monkey logo

kwparserbundle's Introduction

KwParserBundle

This bundle provides a simple Lexer and a SLR Parser. Both classes can be accessed as a symfony service.

You must provide a context free grammar through configuration to make the tokenization and parsing work.

##Installation

1) download the composer package

$ php composer.phar require kw/parser-bundle:dev-master

2) Enable the Bundle

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Kw\ParserBundle\KwParserBundle()	
    );
}

3) Configuration

####Lexer In order to use the Lexer, to tokenize a string into an array of tokens (which can then be parsed by the GLR Parser) you must provide a set of terminal symbols. Each terminal symbol consists of a name (in upper case letters) and a regular expression.

####Parser in order to make the parser do its work a specification of the context free grammar to parse is necessary. You need to specify the start production name and the production rules.

for the productions you must stick to the following conventions:

  • all non terminal symbols must be written in lowercase
  • all terminal symbols must be in upper case

Here is an example of a valid configuration for a simple CFG:

#app/config/config.yml
kw_parser:
    cfg:
        start: 'e'
        productions:
            e:
                - ['t']
                - ['e', 'T_PLUS', 't']
            t:
                - ['t', 'T_MULT', 'f']
                - ['f']
            f:
                - ['T_ID']
                - ['T_OPEN', 'e', 'T_CLOSE']
        terminals:
            T_PLUS: '\+'
            T_MULT: '\*'
            T_ID: 'id'
            T_OPEN: '\('
            T_CLOSE: '\)'

kwparserbundle's People

Contributors

kaywalker avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.