/*
A simple lexical analyser that converts a string into a sequence of
tokens. Java's StreamTokenizer can't be used since it only can
"push back" one token.
This will convert a string into a sequence of
tokens that can be inspected and processed in-order. It is a bit
of an overkill for the simple application, but makes actual
parsing later much easier and more robust than a quicker hack.
Copyright 2010-2011 Adam Pease, apease@articulatesoftware.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program ; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston,
MA 02111-1307 USA
*/
package atp;
import java.io.*;
import java.util.*;
import java.util.regex.*;
import java.text.*;
public class Lexer {
public int ttype = 0;
public String sval = "";
public static final String NoToken = "No Token";
public static final String WhiteSpace = "White Space";
public static final String Newline = "Newline";
public static final String HashComment = "HashComment";
public static final String PerComment = "PerComment";
public static final String IdentUpper = "Identifier starting with capital letter";
public static final String IdentLower = "Identifier starting with lower case letter";
public static final String DefFunctor = "Defined symbol (starting with a $)";
public static final String Number = "Positive or negative Integer or real";
public static final String QuotedString = "Quoted string";
public static final String FullStop = ". (full stop)";
public static final String OpenPar = "(";
public static final String ClosePar = ")";
public static final String OpenSquare = "[";
public static final String CloseSquare = "]";
public static final String Comma = ",";
public static final String Colon = ":";
public static final String EqualSign = "=";
public static final String NotEqualSign = "!=";
public static final String Nand = "~&";
public static final String Nor = "~|";
public static final String Or = "|";
public static final String And = "&";
public static final String Implies = "=>";
public static final String BImplies = ""));
tokenDefs.put(Equiv, Pattern.compile(""));
tokenDefs.put(BImplies, Pattern.compile("