# The Parle\Parser class

(PECL parle >= 0.5.1)

## Introduction

Parser class. Rules can be defined on the fly. Once finalized, a Parle\Lexer instance is required to deliver the token stream.

## Class synopsis

Parle\Parser {
/* Constants */
const integer ACTION_ERROR = 0 ;
const integer ACTION_SHIFT = 1 ;
const integer ACTION_REDUCE = 2 ;
const integer ACTION_GOTO = 3 ;
const integer ACTION_ACCEPT = 4 ;
const integer ERROR_SYNTAX = 0 ;
const integer ERROR_NON_ASSOCIATIVE = 1 ;
const integer ERROR_UNKNOWN_TOKEN = 2 ;
/* Properties */
public integer $action = 0 ;
public integer $reduceId = 0 ;
/* Methods */
public advance ( void ) : void
public build ( void ) : void
public consume ( string `$data` , Parle\Lexer `$lexer` ) : void
public dump ( void ) : void
public errorInfo ( void ) : Parle\ErrorInfo
public left ( string `$tok` ) : void
public nonassoc ( string `$tok` ) : void
public precedence ( string `$tok` ) : void
public push ( string `$name` , string `$rule` ) : int
public reset ([ int `$tokenId` ] ) : void
public right ( string `$tok` ) : void
public sigil ( int `$idx` ) : string
public token ( string `$tok` ) : void
public tokenId ( string `$tok` ) : int
public trace ( void ) : string
public validate ( string `$data` , Parle\Lexer `$lexer` ) : bool
}

## Predefined Constants

`Parle\Parser::ACTION_ERROR`

`Parle\Parser::ACTION_SHIFT`

`Parle\Parser::ACTION_REDUCE`

`Parle\Parser::ACTION_GOTO`

`Parle\Parser::ACTION_ACCEPT`

`Parle\Parser::ERROR_SYNTAX`

`Parle\Parser::ERROR_NON_ASSOCIATIVE`

`Parle\Parser::ERROR_UNKNOWN_TOKEN`

## Properties

action

  Current parser action that matches one of the action class constants, readonly.

reduceId

  Grammar rule id just processed in the reduce action. The value corresponds either to a token or to a production id. Readonly.

## Table of Contents

- Parle\Parser::advance — Process next parser rule
- Parle\Parser::build — Finalize the grammar rules
- Parle\Parser::consume — Consume the data for processing
- Parle\Parser::dump — Dump the grammar
- Parle\Parser::errorInfo — Retrieve the error information
- Parle\Parser::left — Declare a token with left-associativity
- Parle\Parser::nonassoc — Declare a token with no associativity
- Parle\Parser::precedence — Declare a precedence rule
- Parle\Parser::push — Add a grammar rule
- Parle\Parser::reset — Reset parser state
- Parle\Parser::right — Declare a token with right-associativity
- Parle\Parser::sigil — Retrieve a matching part of a rule
- Parle\Parser::token — Declare a token
- Parle\Parser::tokenId — Get token id
- Parle\Parser::trace — Trace the parser operation
- Parle\Parser::validate — Validate input