Directives: error

                                         {my %variables}

start:          statement <commit>  eof  {$variables {'.'} = $item [1]}
              | <error?> <reject>

eof:            /^\Z/

statement:      variable '=' <commit> statement
                                         {$variables {$item [1]} = $item [4]}
              | expression

expression:     <leftop: term ('+' | '-') term>
                        {my $s = shift @{$item [1]};
                         while (@{$item [1]}) {
                             my ($op, $exp) = splice @{$item [1]}, 0, 2;
                             if ($op eq '+') {$s += $exp}
                             else            {$s -= $exp}
                         }
                         $s
                        }

term:           <leftop: factor m{([*/])} factor>
                        {my $p = shift @{$item [1]};
                         while (@{$item [1]}) {
                             my ($op, $term) = splice @{$item [1]}, 0, 2;
                             if ($op eq '*') {$p *= $term}
                             else            {$p /= $term}
                         }
                         $p
                        }

factor:         number
              | variable                 {$variables {$item [1]} ||=
                                                Math::BigInt -> new (0)}
              | '+' <commit> factor      {$item [3]}
              | '-' <commit> factor      {$item [3] * -1}
              | '(' <commit> statement ')'
                                         {$item [3]}
              | <error>

number:         /\d+/                    {Math::BigInt -> new ($item [1])}

variable:       /[a-z]+/i
              | '.'

In [1] := * 12

       ERROR (line 1): Invalid factor: Was expecting number, or variable,
                       or '+', or '-', or '('
Out [1] = <<UNDEF>>
In [2] := 12 (13)

       ERROR (line 1): Invalid start: Was expecting eof but found "(13)"
                       instead
Out [2] = <<UNDEF>>
In [3] := 


[Prev] [Next] [Index]