(PHP) Evaluating simple logical expression
<p>I have an expression in the following form (EBNF):</p>

<pre><code>&lt;expression&gt; ::= ["("]&lt;base&gt;[")"][{&lt;modifier&gt;"("&lt;expression&gt;")"}]
&lt;base&gt;       ::= &lt;logical&gt;[{&lt;modifier&gt;&lt;logical&gt;}]
&lt;logical&gt;    ::= "1" | "0"
&lt;modifier&gt;   ::= "&amp;" | "|"
</code></pre>

<p>An example of a string in this format would be:</p>

<pre><code>(1|(1&amp;0))|(1&amp;(1|0))
</code></pre>

<p>Or alternatively I can get this in postfix notation:</p>

<pre><code>110&amp;|110|&amp;|
</code></pre>

<p>Is there an easy way, in PHP, to evaluate this? (i.e. the result for this particular example should be <code>1</code>). I want to avoid using <code>eval</code> function due to security issues. </p>

<p>If there isn't an easy way to achieve this in PHP without <code>eval</code> function, what would be the best approach for writing a custom parser? </p>
