slogo.jelan.parser
Class ElanParser

java.lang.Object
  extended by slogo.jelan.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 simple instructions are parsed, but lots of infrastructure is in place for parsing a more complete language.

Author:
Owen Astrachan
See Also:
slogo.jelan.expressions, slogo.jelan.instructions, InstructionParser

Constructor Summary
ElanParser()
           
 
Method Summary
 void error(Token t)
           
 Token getToken()
          returns the current token, doesn't fetch a new one
static void main(java.lang.String[] args)
          Basic driver for ElanParser
 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
 

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 - the reader that will be tokenized

getToken

public Token getToken()
returns the current token, doesn't fetch a new one

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 - token being matched
Returns:
the next read token
Throws:
ParseException - if match fails

error

public void error(Token t)
Parameters:
t - token where error occurred
Throws:
a - ParseException labeled by t

main

public static void main(java.lang.String[] args)
Basic driver for ElanParser

Parameters:
args -