| java.lang.Object org.jatha.read.LispParser
LispParser | public class LispParser (Code) | | A parser that reads LISP-syntax text from a text
stream or string. It recognizes all standard
LISP datatypes, although not structured ones.
This function is designed to fulfill the function
of the reader in a LISP read-eval-print loop.
Once the LISP parser is instantiated, the
parse() function can be used to read from
a string or stream.
It is best not to instantiate the LispParser yourself.
Instead, do the following:
1. LispParser parser = Jatha.getParser();
2. parser.setInputString(myString);
3. parser.setCaseSensitivity(LispParser.PRESERVE);
4. LispValue result = parser.parse();
Normal usage is to parse a string. If you want to use a Reader,
do: new PushbackReader(myReader) .
See Also: org.jatha.dynatype.LispValue author: Micheal S. Hewett version: 1.0 |
Constructor Summary | |
public | LispParser(Jatha lisp, Reader inStream) | public | LispParser(Jatha lisp, String inString) | public | LispParser(Jatha lisp, Reader inStream, int caseSensitivity) Allows you to create a parser that handles
input case conversion as you like.
Default is UPCASE. | public | LispParser(Jatha lisp, String inString, int caseSensitivity) Allows you to create a parser that handles
input case conversion as you like.
Default is UPCASE. |
Method Summary | |
boolean | INTEGER_token_p(String str) | boolean | NIL_token_p(String str) | boolean | REAL_token_p(String str) Does NOT recognize an isolated '+' or '-' as a real number. | boolean | STRING_token_p(String str) | boolean | SYMBOL_token_p(String str) | boolean | T_token_p(String str) | public LispValue | applyReaderMacro(PushbackReader stream) This routine is called by parse when it encounters
a pound (#) mark. | public static int | firstCharNotInSet(int startIndex, String str, String charSet) The equivalent of the C function 'strspn'.
Given a string and another string representing a set of characters,
this function scans the string and accepts characters that are
elements of the given set of characters. | public int | getCaseSensitivity() Retrieves the current case-sensitivity of the parser. | public PushbackReader | getInputReader() Gets the current reader to be parsed. | public static boolean | hasBalancedParentheses(Jatha lisp, LispValue input) | public static boolean | hasBalancedParentheses(Jatha lisp, String input) | boolean | isAtSign(char x) | boolean | isBackQuote(char x) | boolean | isBackSlash(char x) | boolean | isColon(char x) | boolean | isComma(char x) | boolean | isDoubleQuote(char x) | boolean | isLeftAngleBracket(char x) | boolean | isLparen(char x) | boolean | isOrBar(char x) | boolean | isPeriod(char x) | boolean | isPound(char x) | boolean | isQuote(char x) | boolean | isRightAngleBracket(char x) | boolean | isRparen(char x) | boolean | isSemi(char x) | boolean | isSpace(char x) | boolean | isTerminator(char x) | public LispValue | parse() Parse() assumes that there is only one expression in the input
string or file. | public LispValue | read() Reads one s-expression from the input stream (a string or file). | public LispValue | read_backquoted_list_token(PushbackReader stream) This library can't read backquotes yet. | public LispValue | read_backquoted_token(PushbackReader stream) This routine is called by parse when it encounters
a backquote mark. | LispValue | read_comma_token(PushbackReader stream) This routine is called by parse when it encounters
a comma, which is only legal inside a backquote. | public LispValue | read_list_token(PushbackReader stream) Reads one list expression from the input stream and returns it. | LispValue | read_quoted_token(PushbackReader stream) This routine is called by parse when it encounters
a quote mark. | public void | setCaseSensitivity(int caseSensitivity) Sets the current case-sensitivity of the parser. | public void | setInputReader(PushbackReader inputReader) Sets the input reader for the Parser. | public void | setInputString(String s) Sets the input string for the parser. | public void | simple_parser_test() | public void | test_parser(String s) | public void | test_parser_loop() | public LispValue | tokenToLispValue(String token) Converts a string to a LISP value such as
NIL, T, an integer, a real number, a string or a symbol. |
AT_SIGN | final static char AT_SIGN(Code) | | |
BACKSLASH | final static char BACKSLASH(Code) | | |
BACK_QUOTE | final static char BACK_QUOTE(Code) | | |
COLON | final static char COLON(Code) | | |
COMMA | final static char COMMA(Code) | | |
DECIMAL | final static char DECIMAL(Code) | | |
DOUBLE_QUOTE | final static char DOUBLE_QUOTE(Code) | | |
DOWNCASE | final public static int DOWNCASE(Code) | | |
EQUAL_SIGN | final static char EQUAL_SIGN(Code) | | |
HYPHEN | final static char HYPHEN(Code) | | |
LEFT_ANGLE_BRACKET | final static char LEFT_ANGLE_BRACKET(Code) | | |
LEFT_PAREN | final static char LEFT_PAREN(Code) | | |
OR_BAR | final static char OR_BAR(Code) | | |
PERIOD | final static char PERIOD(Code) | | |
POUND | final static char POUND(Code) | | |
PRESERVE | final public static int PRESERVE(Code) | | |
READING_BACKQUOTED_LIST | final static int READING_BACKQUOTED_LIST(Code) | | |
READING_CHARACTER | final static int READING_CHARACTER(Code) | | |
READING_MIXED_CASE_SYMBOL | final static int READING_MIXED_CASE_SYMBOL(Code) | | |
READING_NOTHING | final static int READING_NOTHING(Code) | | |
READING_STRING | final static int READING_STRING(Code) | | |
READING_SYMBOL | final static int READING_SYMBOL(Code) | | |
RIGHT_ANGLE_BRACKET | final static char RIGHT_ANGLE_BRACKET(Code) | | |
RIGHT_PAREN | final static char RIGHT_PAREN(Code) | | |
SEMICOLON | final static char SEMICOLON(Code) | | |
SINGLE_QUOTE | final static char SINGLE_QUOTE(Code) | | |
UNDERSCORE | final static char UNDERSCORE(Code) | | |
UPCASE | final public static int UPCASE(Code) | | |
LispParser | public LispParser(Jatha lisp, Reader inStream, int caseSensitivity)(Code) | | Allows you to create a parser that handles
input case conversion as you like.
Default is UPCASE. Other values are DOWNCASE and PRESERVE.
Parameters: inStream - |
LispParser | public LispParser(Jatha lisp, String inString, int caseSensitivity)(Code) | | Allows you to create a parser that handles
input case conversion as you like.
Default is UPCASE. Other values are DOWNCASE and PRESERVE.
|
REAL_token_p | boolean REAL_token_p(String str)(Code) | | Does NOT recognize an isolated '+' or '-' as a real number.
|
firstCharNotInSet | public static int firstCharNotInSet(int startIndex, String str, String charSet)(Code) | | The equivalent of the C function 'strspn'.
Given a string and another string representing a set of characters,
this function scans the string and accepts characters that are
elements of the given set of characters. It returns the index
of the first element of the string that is not a member of the
set of characters.
For example:
pos = firstCharNotInSet(0, "hello there, how are you?", "ehlort ");
returns 11.
If the string does not contain any of the characters in the set,
str.length() is returned.
|
getCaseSensitivity | public int getCaseSensitivity()(Code) | | Retrieves the current case-sensitivity of the parser.
It can be eiher LispParser.UPCASE, LispParser.DOWNCASE
or LispParser.PRESERVE
UPCASE, DOWNCASE or PRESERVE |
hasBalancedParentheses | public static boolean hasBalancedParentheses(Jatha lisp, LispValue input)(Code) | | Returns true if the input expression has balanced parentheses
Parameters: input - a String true if it has balanced parentheses |
hasBalancedParentheses | public static boolean hasBalancedParentheses(Jatha lisp, String input)(Code) | | Returns true if the input expression has balanced parentheses
Parameters: input - a String true if it has balanced parentheses |
isAtSign | boolean isAtSign(char x)(Code) | | |
isBackQuote | boolean isBackQuote(char x)(Code) | | |
isBackSlash | boolean isBackSlash(char x)(Code) | | |
isColon | boolean isColon(char x)(Code) | | |
isComma | boolean isComma(char x)(Code) | | |
isDoubleQuote | boolean isDoubleQuote(char x)(Code) | | |
isLeftAngleBracket | boolean isLeftAngleBracket(char x)(Code) | | |
isLparen | boolean isLparen(char x)(Code) | | |
isOrBar | boolean isOrBar(char x)(Code) | | |
isPeriod | boolean isPeriod(char x)(Code) | | |
isPound | boolean isPound(char x)(Code) | | |
isQuote | boolean isQuote(char x)(Code) | | |
isRightAngleBracket | boolean isRightAngleBracket(char x)(Code) | | |
isRparen | boolean isRparen(char x)(Code) | | |
isSemi | boolean isSemi(char x)(Code) | | |
isSpace | boolean isSpace(char x)(Code) | | |
isTerminator | boolean isTerminator(char x)(Code) | | |
parse | public LispValue parse() throws EOFException(Code) | | Parse() assumes that there is only one expression in the input
string or file. If you need to read multiple items from a
string or file, use the read() function.
Parse just calls read right now.
See Also: LispParser.read |
read | public LispValue read() throws EOFException(Code) | | Reads one s-expression from the input stream (a string or file).
Throws an EOFxception when EOF is reached.
Call this method repeatedly to do read-eval-print on a file.
|
read_backquoted_token | public LispValue read_backquoted_token(PushbackReader stream) throws EOFException(Code) | | This routine is called by parse when it encounters
a backquote mark. It calls parse recursively.
|
read_list_token | public LispValue read_list_token(PushbackReader stream) throws EOFException(Code) | | Reads one list expression from the input stream and returns it.
The input pointer should be on the character following the left parenthesis.
|
setCaseSensitivity | public void setCaseSensitivity(int caseSensitivity)(Code) | | Sets the current case-sensitivity of the parser.
It can be eiher LispParser.UPCASE, LispParser.DOWNCASE
or LispParser.PRESERVE
|
setInputReader | public void setInputReader(PushbackReader inputReader)(Code) | | Sets the input reader for the Parser.
|
setInputString | public void setInputString(String s)(Code) | | Sets the input string for the parser. This is the
String to parse.
|
simple_parser_test | public void simple_parser_test()(Code) | | |
tokenToLispValue | public LispValue tokenToLispValue(String token)(Code) | | Converts a string to a LISP value such as
NIL, T, an integer, a real number, a string or a symbol.
|
|
|