jelan.simple
Class ElanParser
java.lang.Object
jelan.simple.ElanParser
public class ElanParser
- extends java.lang.Object
Illustrates the java.io.StreamTokenizer class and how it can be used to parse
tokens for a toy example programming language (elan). For this example, only
expressions are parsed, but lots of infrastructure is in place for parsing a
more complete language
- Author:
- Owen Astrachan
- See Also:
Expression
Method Summary |
void |
error(Token t)
|
Token |
getToken()
|
static void |
main(java.lang.String[] args)
|
Token |
match(Token rhs)
try to match a token, if unsuccessful throw an exception, otherwise match
succeeds, and next token is obtained and returned |
void |
parse(java.io.Reader r)
parses an expression and prints the result of evaluating the expression. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ElanParser
public ElanParser()
parse
public void parse(java.io.Reader r)
- parses an expression and prints the result of evaluating the expression.
- Parameters:
r
- the reader that will be tokenized
getToken
public Token getToken()
- Returns:
- the current token
match
public Token match(Token rhs)
- try to match a token, if unsuccessful throw an exception, otherwise match
succeeds, and next token is obtained and returned
- Parameters:
rhs
- the token being matched
- Returns:
- the next read token
- Throws:
ParseException
- (RunTime) if match fails
error
public void error(Token t)
- Parameters:
t
- token included in exception thrown
- Throws:
ParseException
- labeled by t
main
public static void main(java.lang.String[] args)