## serafim/calc

1.0.0
2019-08-26 00:13 UTC

Requires

- php: >=7.1
- symfony/console: ~4.0
- phplrt/ast: ~2.0|2.0.x-dev
- phplrt/parser: ~2.0|2.0.x-dev
- phplrt/lexer: ~2.0|2.0.x-dev

Requires (Dev)

- symfony/var-dumper: ~4.0

# README

## Why?

This repository is designed as an example of how you can implement a calculator based on abstract syntax tree generated by the LL(k) recurrence recursive descent parser.

As a grammar used the basic implementation with operators associativity, and not vulnerable to left recursion:

```
{
tokens = [
T_FLOAT = "regexp:\d+\.\d+"
T_INT = "regexp:\d+"
]
}
<expr> ::= <addition> | <subtraction> | <term>
<term> ::= <multiplication> | <division> | <factor>
<factor> ::= "(" <expr> ")" | <value>
<subtraction> ::= <term> "-" <expr>
<addition> ::= <term> "+" <expr>
<multiplication> ::= <factor> "*" <term> | <factor> <term>
<division> ::= <factor> ("/" | "÷") <term>
<value> ::= T_FLOAT | T_INT
```

## Example

Command Line Interface

$ php ./bin/cc

## Usage

**Global:**

$ composer global require serafim/calc $ cc

**Local:**

$ composer require serafim/calc $ ./vendor/bin/cc