#
# Reduction rules for arith.pl
# Perl source code automatically generated at Fri Apr 17 14:54:53 1998 by
# py v.0.1 25 Aug 1995
# Source code copyright 1995 M-J. Dominus (mjd@pobox.com)
#

# rule 1
# computation -> statement computation
sub rule_1 {
  return $_[0];
}

# rule 2
# computation ->		/* empty */
sub rule_2 {
  return $_[0];
}

# rule 3
# statement -> expr ';'
sub rule_3 {
  return $_[0];
}

# rule 4
# statement -> assignment ';'
sub rule_4 {
  return $_[0];
}

# rule 5
# statement -> ';'
sub rule_5 {
  return $_[0];
}

# rule 6
# expr -> '(' expr ')'
sub rule_6 {
  return $_[0];
}

# rule 7
# expr -> expr '+' expr
sub rule_7 {
  return $_[0];
}

# rule 8
# expr -> expr '-' expr
sub rule_8 {
  return $_[0];
}

# rule 9
# expr -> expr '*' expr
sub rule_9 {
  return $_[0];
}

# rule 10
# expr -> expr '/' expr
sub rule_10 {
  return $_[0];
}

# rule 11
# expr -> expr POWOP expr
sub rule_11 {
  return $_[0];
}

# rule 12
# expr -> expr '?' expr ':' expr
sub rule_12 {
  return $_[0];
}

# rule 13
# expr -> expr ',' expr
sub rule_13 {
  return $_[0];
}

# rule 14
# expr -> assignment
sub rule_14 {
  return $_[0];
}

# rule 15
# expr -> NAME
sub rule_15 {
  return $_[0];
}

# rule 16
# expr -> NUMBER
sub rule_16 {
  return $_[0];
}

# rule 17
# assignment -> NAME ASSIGNOP expr
sub rule_17 {
  return $_[0];
}


# The lexer converts sequences of characters into 
# tokens.  A token may have a value, which is stored
# in the variable $yylval.  The return value from yylex
# says what the type of token is.
{
  my @tokens = ();

  sub yylex {
    my $token;
    until ($token =~ /\S/) {
      $token = shift @tokens;
      return End_of_Input unless defined $token;
    }

    $yylval = $token;
    if ($token =~ /^[A-Za-z_]/ ) {
      return NAME;
    } elsif ($token =~ /^\d/) {
      return NUMBER;
    } elsif ($token eq '**' || $token eq '^') {
      return POWOP;
    } elsif ($token eq ':=' || $token eq '=') {
      return ASSIGNOP;
    } else {
      return $yylval;
    }
  }

  sub set_input {
    my $instr = join '', @_;
    $instr =~ tr/\n/ /;
    @tokens = split(/(:=	# Special assignment operator
		      |
		      \*\*	# Special power operator
		      |
		      [-()+*\/?=:;,^] # Single-character token
		      |
		      [A-Za-z_]\w* # Name
		      |
		      (?:\d+(?:\.\d+)) # Number
		     )/x, 
		    $instr);
    local $" = '][';
    print STDERR "TOKENS: [@tokens]\n";
  }
}


1;
