File:  [LON-CAPA] / loncom / homework / math_parser / Operator.pm
Revision 1.2: download - view: text, annotated - select for diffs
Mon Mar 13 22:31:22 2023 UTC (13 months, 4 weeks ago) by raeburn
Branches: MAIN
CVS tags: version_2_12_X, version_2_11_4_msu, HEAD
- Add $Id$ line in comments for display of version.

    1: # The LearningOnline Network with CAPA - LON-CAPA
    2: # Parser operator
    3: #
    4: # $Id: Operator.pm,v 1.2 2023/03/13 22:31:22 raeburn Exp $
    5: #
    6: # Copyright (C) 2014 Michigan State University Board of Trustees
    7: #
    8: # This program is free software: you can redistribute it and/or modify
    9: # it under the terms of the GNU General Public License as published by
   10: # the Free Software Foundation, either version 3 of the License, or
   11: # (at your option) any later version.
   12: #
   13: # This program is distributed in the hope that it will be useful,
   14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   16: # GNU General Public License for more details.
   17: #
   18: # You should have received a copy of the GNU General Public License
   19: # along with this program. If not, see <http://www.gnu.org/licenses/>.
   20: #
   21: 
   22: ##
   23: # Parser operator, like "(".
   24: ##
   25: package Apache::math_parser::Operator;
   26: 
   27: use strict;
   28: use warnings;
   29: use utf8;
   30: 
   31: use enum qw(UNKNOWN UNARY BINARY TERNARY);
   32: 
   33: ##
   34: # Constructor
   35: # @param {string} id - Characters used to recognize the operator
   36: # @param {integer} arity (Operator::UNKNOWN, UNARY, BINARY, TERNARY)
   37: # @param {integer} lbp - left binding power
   38: # @param {integer} rbp - right binding power
   39: # @param {nudFunction} nud - Null denotation function. Parameters: Parser p. Returns: ENode.
   40: # @param {ledFunction} led - Left denotation function Parameters: Parser p, ENode left. Returns: ENode.
   41: ##
   42: sub new {
   43:     my $class = shift;
   44:     my $self = {
   45:         _id => shift,
   46:         _arity => shift,
   47:         _lbp => shift,
   48:         _rbp => shift,
   49:         _nud => shift,
   50:         _led => shift,
   51:     };
   52:     bless $self, $class;
   53:     return $self;
   54: }
   55: 
   56: # Attribute helpers
   57: 
   58: sub id {
   59:     my $self = shift;
   60:     return $self->{_id};
   61: }
   62: sub arity {
   63:     my $self = shift;
   64:     return $self->{_arity};
   65: }
   66: sub lbp {
   67:     my $self = shift;
   68:     return $self->{_lbp};
   69: }
   70: sub rbp {
   71:     my $self = shift;
   72:     return $self->{_rbp};
   73: }
   74: sub nud {
   75:     my $self = shift;
   76:     return $self->{_nud};
   77: }
   78: sub led {
   79:     my $self = shift;
   80:     return $self->{_led};
   81: }
   82: 
   83: 1;
   84: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>