elan.parser
Class ElanParser

java.lang.Object
  |
  +--elan.parser.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

See Also:
elan.expression, elan.instruction

Field Summary
protected  elan.parser.token.Token myToken
           
protected  java.io.StreamTokenizer myTokenizer
           
 
Constructor Summary
ElanParser()
           
 
Method Summary
 void error(elan.parser.token.Token t)
           
 elan.parser.token.Token getToken()
           
static void main(java.lang.String[] args)
           
 elan.parser.token.Token match(elan.parser.token.Token rhs)
          try to match a token, if unsuccessful throw an exception, otherwise match succeeds, and next token is obtained and returned
protected  elan.parser.token.Token nextToken()
          get the next token and store it for retrieval by getToken()
 void parse(java.io.Reader r)
          parses an expression and prints the result of evaluating the expression.
protected  void skipLines()
          skip EOL tokens, the next call of getToken() returns something other than EOLToken
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

myTokenizer

protected java.io.StreamTokenizer myTokenizer

myToken

protected elan.parser.token.Token myToken
Constructor Detail

ElanParser

public ElanParser()
Method Detail

parse

public void parse(java.io.Reader r)
parses an expression and prints the result of evaluating the expression.
Parameters:
r - is the reader that will be tokenized

skipLines

protected void skipLines()
skip EOL tokens, the next call of getToken() returns something other than EOLToken

nextToken

protected elan.parser.token.Token nextToken()
get the next token and store it for retrieval by getToken()
Returns:
the current (just read) token
See Also:
getToken

getToken

public elan.parser.token.Token getToken()
Returns:
the current token

match

public elan.parser.token.Token match(elan.parser.token.Token rhs)
try to match a token, if unsuccessful throw an exception, otherwise match succeeds, and next token is obtained and returned
Parameters:
rhs - is the token being matched
Returns:
the next read token
Throws:
ParseException - (RunTime) if match fails

error

public void error(elan.parser.token.Token t)
Parameters:
t - is included in expeption thrown
Throws:
a - ParseException labelled by t

main

public static void main(java.lang.String[] args)