class CalcStringLexer
    
    def initialize(s)
	@li = s
    end
    
    def reset(s)
	@li = s
    end
    
    def yylex
	while 1
	    return [-1, nil] if @li.size == 0
	    
	    if @li =~ /\A[\ \t]+/o
		@li = $'
		next
	    end
	    
	    if @li =~ /\A\n/o
		@li = $'
		return [?\n, '\n']
	    end
	    
	    if @li =~ /\A\+/o
		@li = $'
		return [?+, '+']
	    end
	    
	    if @li =~ /\A\-/o
		@li = $'
		return [?-, '-']
	    end
	    
	    if @li =~ %r!\A\*!o
		@li = $'
		return [?*, '*']
	    end
	    
	    if @li =~ %r!\A/!o
		@li = $'
		return [?/, '/']
	    end
	    
	    if @li =~ /\A\(/o
		@li = $'
		return [?(, '(']
	    end
	    
	    if @li =~ /\A\)/o
		@li = $'
		return [?), ')']
	    end
	    
	    if @li =~ /\A\^/o
		@li = $'
		return [?^, '^']
	    end
	    
	    if @li =~ /\A-?\d+(?:\.\d+)?/o
		@li = $'
		return [CalcParser::NUM, $&.to_f]
	    end
	    raise CalcParser::LexError
	end
    end
    
end
