// Path: src/main/java/com/lastcalc/parsers/math/Radix.java
// public class Radix implements Serializable {
// 	private static final long serialVersionUID = 6793205833102927654L;
// 	public final long integer;
// 	public final int radix;
// 
// 	public static Radix parse(final String value) {
// 		if (value.startsWith("0x"))
// 			return new Radix(Long.parseLong(value.substring(2), 16), 16);
// 		else if (value.startsWith("0b"))
// 			return new Radix(Long.parseLong(value.substring(2), 2), 2);
// 		else if (value.startsWith("0o"))
// 			return new Radix(Long.parseLong(value.substring(2), 8), 8);
// 		else
// 			return null;
// 	}
// 
// 	public Radix(final long integer, final int radix) {
// 		this.integer = integer;
// 		this.radix = radix;
// 	}
// 
// 	@Override
// 	public String toString() {
// 		String prefix;
// 		if (radix == 2) {
// 			prefix = "0b";
// 		} else if (radix == 8) {
// 			prefix = "0o";
// 		} else {
// 			prefix = "0x";
// 		}
// 		return prefix + Long.toString(integer, radix);
// 	}
// }


import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.lastcalc.parsers.math.Radix;
import org.jscience.mathematics.number.LargeInteger;
import org.jscience.mathematics.number.Rational;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
		for (final Entry<String, String> e : tokenMatchers.entrySet()) {
			matchers.put(e.getKey(), Pattern.compile("^" + e.getValue() + "$"));
		}

		Tokenizer.anyMatcher = Pattern.compile(anyMatcher);
	}

	public static TokenList tokenize(final String orig) {
		final Matcher m = anyMatcher.matcher(orig);

		final ArrayList<Object> ret = Lists.newArrayList();

		while (m.find()) {
			final String found = m.group();
			if (matchers.get("float").matcher(found).find()) {
				final int dotPos = found.indexOf(".");
				final long intPart = Long.parseLong(found.substring(0, dotPos));
				final String fracPart = found.substring(dotPos + 1, found.length());
				final long num = intPart * (long) Math.pow(10, fracPart.length()) + (intPart >= 0 ? 1 : -1)
						* Long.parseLong(fracPart);
				final long denom = (long) Math.pow(10, fracPart.length());
				ret.add(Rational.valueOf(num, denom));
			} else if (matchers.get("integer").matcher(found).find()){
				ret.add(LargeInteger.valueOf(found));
			} else if (found.startsWith("\"") && found.endsWith("\"")) {
				final String quoted = found.substring(1, found.length() - 1).replace("\\\"", "\"");

				ret.add(new QuotedString(quoted));
			} else {
				// Is it a radix?
// Path: src/main/java/com/lastcalc/parsers/math/Radix.java
// public class Radix implements Serializable {
// 	private static final long serialVersionUID = 6793205833102927654L;
// 	public final long integer;
// 	public final int radix;
// 
// 	public static Radix parse(final String value) {
// 		if (value.startsWith("0x"))
// 			return new Radix(Long.parseLong(value.substring(2), 16), 16);
// 		else if (value.startsWith("0b"))
// 			return new Radix(Long.parseLong(value.substring(2), 2), 2);
// 		else if (value.startsWith("0o"))
// 			return new Radix(Long.parseLong(value.substring(2), 8), 8);
// 		else
// 			return null;
// 	}
// 
// 	public Radix(final long integer, final int radix) {
// 		this.integer = integer;
// 		this.radix = radix;
// 	}
// 
// 	@Override
// 	public String toString() {
// 		String prefix;
// 		if (radix == 2) {
// 			prefix = "0b";
// 		} else if (radix == 8) {
// 			prefix = "0o";
// 		} else {
// 			prefix = "0x";
// 		}
// 		return prefix + Long.toString(integer, radix);
// 	}
// }


// Path: src/main/java/com/lastcalc/Tokenizer.java
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.lastcalc.parsers.math.Radix;
import org.jscience.mathematics.number.LargeInteger;
import org.jscience.mathematics.number.Rational;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

		for (final Entry<String, String> e : tokenMatchers.entrySet()) {
			matchers.put(e.getKey(), Pattern.compile("^" + e.getValue() + "$"));
		}

		Tokenizer.anyMatcher = Pattern.compile(anyMatcher);
	}

	public static TokenList tokenize(final String orig) {
		final Matcher m = anyMatcher.matcher(orig);

		final ArrayList<Object> ret = Lists.newArrayList();

		while (m.find()) {
			final String found = m.group();
			if (matchers.get("float").matcher(found).find()) {
				final int dotPos = found.indexOf(".");
				final long intPart = Long.parseLong(found.substring(0, dotPos));
				final String fracPart = found.substring(dotPos + 1, found.length());
				final long num = intPart * (long) Math.pow(10, fracPart.length()) + (intPart >= 0 ? 1 : -1)
						* Long.parseLong(fracPart);
				final long denom = (long) Math.pow(10, fracPart.length());
				ret.add(Rational.valueOf(num, denom));
			} else if (matchers.get("integer").matcher(found).find()){
				ret.add(LargeInteger.valueOf(found));
			} else if (found.startsWith("\"") && found.endsWith("\"")) {
				final String quoted = found.substring(1, found.length() - 1).replace("\\\"", "\"");

				ret.add(new QuotedString(quoted));
			} else {
				// Is it a radix?
				final Radix radix = Radix.parse(found);