Good day. Just started to use PEG. I'm familiar with wp:peg and some other theory, but still can't understand how it internally works.
My task is to parse expressions like
if($a=='qwerty' && $b>2 || $c<=5)
print 'something';
endif;
Body of is statement contains only print operator and nothing else, but it has complex condition.
My thinking about it:
/*!* Calculator
Int: /[0-9]+/
Var: /\$[a-z]+/
tThen: /then{1}/
tIf: /if{1}/
tElse: /else{1}/
tEndif: /endif{1}/
block: /.+/
condEq: Var '==' ( Int | Var ) *
condStatement: '(' condEq ')'
function condEq( &$result, $sub ) {
if( eval($sub['text'].';') ) {
$result['text'] = 'true';
}
else {
$result['text'] = 'false';
}
}
ifStatement: tIf condStatement
Expr: ifStatement
*/
But I believe this task has better solution:) Can you help me with it? Thanks.