Production::setAssociativityFlag()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * This file is part of PHP-Yacc package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace PhpYacc\Yacc;
11
12
use PhpYacc\Grammar\Symbol;
13
14
/**
15
 * Class Production.
16
 */
17
class Production
18
{
19
    const EMPTY = 0x10;
20
21
    /**
22
     * @var Production|null
23
     */
24
    public $link;
25
26
    /**
27
     * @var int
28
     */
29
    public $associativity;
30
31
    /**
32
     * @var int
33
     */
34
    public $precedence;
35
36
    /**
37
     * @var int
38
     */
39
    public $position;
40
41
    /**
42
     * @var null|string
43
     */
44
    public $action;
45
46
    /**
47
     * @var array|Symbol[]
48
     */
49
    public $body = [];
50
51
    /**
52
     * @var int
53
     */
54
    public $num = -1;
55
56
    /**
57
     * Production constructor.
58
     *
59
     * @param string|null $action
60
     * @param int         $position
61
     */
62
    public function __construct(string $action = null, int $position)
63
    {
64
        $this->action = $action;
65
        $this->position = $position;
66
    }
67
68
    /**
69
     * @param int $flag
70
     */
71
    public function setAssociativityFlag(int $flag)
72
    {
73
        $this->associativity |= $flag;
74
    }
75
76
    /**
77
     * @return bool
78
     */
79
    public function isEmpty(): bool
80
    {
81
        return \count($this->body) <= 1;
82
    }
83
}
84