Class SExpressionParser
java.lang.Object
|
+--SExpressionParser
- public class SExpressionParser
- extends java.lang.Object
Parses S-Expressions. To do so, call
SExpressionParser.parse(InputStream).
For example,
(
(PROGRAM 1)
(IDENT P 3)
(SEMICOLON 6)
)
parses into the following contents:
java.util.Vector {
java.util.Vector { SExprToken(kind=SExprToken.ATOM, value="PROGRAM"),
SExprToken(kind=SExprToken.INTLIT, value="1")},
java.util.Vector { SExprToken(kind=SExprToken.ATOM, value="IDENT"),
SExprToken(kind=SExprToken.ATOM, value="P"),
SExprToken(kind=SExprToken.INTLIT, value="3")},
java.util.Vector { SExprToken(kind=SExprToken.ATOM, value="SEMICOLON"),
SExprToken(kind=SExprToken.INTLIT, value="6")}
}
So what you probably think of as one "token" from the lexer is actually
a Vector of SExprTokens. You can pull this Vector apart and put it into
your own objects, so you don't have to deal with all the vector-of-
vectors overhead. The reason it is written this way is because it has
to be general enough that it works for later phases of the compiler as well.
Code example:
Vector tokens = SExpressionParser.parse(new FileInputStream("somefile.dat"));
for (int i = 0; i < tokens.size(); i++)
System.out.println("token: " + tokens.get(i));
|
Method Summary |
static java.util.Vector |
parse(java.io.InputStream in)
Call this method to parse a stream of characters into
an SExpression, modeled by a vector of vectors. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
parse
public static java.util.Vector parse(java.io.InputStream in)
throws java.io.IOException
- Call this method to parse a stream of characters into
an SExpression, modeled by a vector of vectors.