elan.parser
Class ElanParser

java.lang.Object
  |
  +--elan.parser.ElanParser
All Implemented Interfaces:
Parser

public class ElanParser
extends java.lang.Object
implements Parser

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.

See Also:
elan.expression, elan.instruction, InstructionParser

Field Summary
protected  Output myOutput
           
protected  Token myToken
           
protected  java.io.StreamTokenizer myTokenizer
           
protected  TurtleManager myTurtleManager
           
 
Constructor Summary
ElanParser()
           
 
Method Summary
 void error(Token t)
           
 void executeInstructions(java.lang.String instructionList)
          executes a list of instructions
 Token getToken()
          returns the current token, doesn't fetch a new one
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
protected  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.
 void setOutput()
           
 void setOutput(Output o)
          Deprecated. The current version of ElanParser treats EOL (end-of-line) as NOT significant, so there's no reason to call this function.
 void setTurtleManager()
           
 void setTurtleManager(TurtleManager t)
           
protected  void skipLines()
           
 
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 Token myToken

myOutput

protected Output myOutput

myTurtleManager

protected TurtleManager myTurtleManager
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

setOutput

public void setOutput(Output o)
Deprecated. The current version of ElanParser treats EOL (end-of-line) as NOT significant, so there's no reason to call this function.

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

setTurtleManager

public void setTurtleManager(TurtleManager t)

skipLines

protected void skipLines()

nextToken

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

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

error

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

executeInstructions

public void executeInstructions(java.lang.String instructionList)
Description copied from interface: Parser
executes a list of instructions
Specified by:
executeInstructions in interface Parser
Following copied from interface: graphics.Parser
Parameters:
instructionList - instructions that can be interpreted and executed by the parser

setTurtleManager

public void setTurtleManager()

setOutput

public void setOutput()

main

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