2017 © Pedro PelĂĄez
 

library parser-bundle

Parser for context free grammars

image

kw/parser-bundle

Parser for context free grammars

  • Tuesday, November 26, 2013
  • by kaywalker
  • Repository
  • 1 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

KwParserBundle

This bundle provides a simple Lexer and a SLR Parser. Both classes can be accessed as a symfony service., (*1)

You must provide a context free grammar through configuration to make the tokenization and parsing work., (*2)

Installation

1) download the composer package

``` bash $ php composer.phar require kw/parser-bundle:dev-master, (*3)




### 2) Enable the Bundle ``` php <?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., (*4)

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., (*5)

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, (*6)

Here is an example of a valid configuration for a simple CFG:, (*7)

``` ymal, (*8)

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: '', (*9)

```, (*10)

The Versions

26/11 2013

dev-master

9999999-dev https://github.com/kaywalker/KwParserBundle

Parser for context free grammars

  Sources   Download

by Kay Wienöbst

parser parse parsing slr lr glr cfg context free grammar