org.activemath.exercises
Class CasParser

java.lang.Object
  extended by org.activemath.exercises.openmath.OpenMath
      extended by org.activemath.exercises.CasParser
Direct Known Subclasses:
CasParserActiveMath, CasParserActiveMath_de, CasParserActiveMath_es, CasParserActiveMath_fr, CasParserActiveMath_hu, CasParserActiveMath_nl, CasParserAxiom, CasParserDrv, CasParserHtw, CasParserMaxima, CasParserMf, CasParserMma, CasParserMpd, CasParserMpl, CasParserOpenMath, CasParserRdc, CasParserYacas

public class CasParser
extends OpenMath

CAS parser root class.

Version:
$Revision: 1.12 $ $Date: 2012/02/27 08:42:53 $

Field Summary
protected static Logger log
           
protected static HashMap omDictionaryCd
           
protected static HashMap omDictionaryName
           
protected static HashMap omDictionaryUnaryCd
           
protected static HashMap omDictionaryUnaryName
           
 
Fields inherited from class org.activemath.exercises.openmath.OpenMath
openmathNamespace
 
Constructor Summary
protected CasParser()
           
 
Method Summary
 void advanceToNextEOL()
          Advance to next End Of Line (EOL) or end of input.
static void console(String userInputSyntax)
           
static List linearToOpenMath(String userInput, String userInputSyntax)
           
static List linearToOpenMath(String userInput, String userInputSyntax, String lang)
          Convert from linear input to OpenMath.
static CasParser newCasParser(InputStream inputStream, String grammarName)
           
static CasParser newCasParser(InputStream inputStream, String grammarName, String lang)
          CAS parser factory.
static CasParser newCasParser(Reader inputReader, String grammarName)
           
static CasParser newCasParser(Reader inputReader, String grammarName, String lang)
          CAS parser factory.
static CasParser newCasParser(String inputString, String grammarName)
          CAS parser factory.
static CasParser newCasParser(String inputString, String grammarName, String lang)
          CAS parser factory.
 org.jdom.Element nextLine()
          Entry point for the recursive descendant parser.
 org.jdom.Element nextOmobj()
          Parse input, and return the first complete expression found.
protected static org.jdom.Element parseForeign(String inputSyntaxToken, String expressionToken)
           
protected static org.jdom.Element symbol(String s)
           
protected static org.jdom.Element symbolUnary(String s)
           
 
Methods inherited from class org.activemath.exercises.openmath.OpenMath
applyBinding, getOmobjContents, oma, oma, oma, oma, oma, ombind, ombind, ombind, ombind, ombind, ombvar, ombvar, ombvar, ombvar, ome, ome, ome, ome, omf, omf, omi, omi, omobj, oms, omstr, omv, output, setOmNamespace, substituteVariables, tidyForOpenMath1, toDouble, toInt
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static Logger log

omDictionaryCd

protected static HashMap omDictionaryCd

omDictionaryName

protected static HashMap omDictionaryName

omDictionaryUnaryCd

protected static HashMap omDictionaryUnaryCd

omDictionaryUnaryName

protected static HashMap omDictionaryUnaryName
Constructor Detail

CasParser

protected CasParser()
Method Detail

newCasParser

public static final CasParser newCasParser(InputStream inputStream,
                                           String grammarName)

newCasParser

public static final CasParser newCasParser(InputStream inputStream,
                                           String grammarName,
                                           String lang)
CAS parser factory.

Parameters:
inputStream - stream from which to get input.
grammarName - identifier for the grammar. Can be null, in which case the default is used.
Returns:
CasParser instance.

newCasParser

public static final CasParser newCasParser(String inputString,
                                           String grammarName)
CAS parser factory.

Parameters:
inputString - string from which to get input.
grammarName - identifier for the grammar. Can be null, in which case the default is used.
Returns:
CasParser instance.

newCasParser

public static final CasParser newCasParser(String inputString,
                                           String grammarName,
                                           String lang)
CAS parser factory.

Parameters:
inputString - string from which to get input.
grammarName - identifier for the grammar. Can be null, in which case the default is used.
Returns:
CasParser instance.

newCasParser

public static final CasParser newCasParser(Reader inputReader,
                                           String grammarName)

newCasParser

public static final CasParser newCasParser(Reader inputReader,
                                           String grammarName,
                                           String lang)
CAS parser factory.

Parameters:
inputReader - reader from which to get input.
grammarName - identifier for the grammar. Can be null, in which case the default is used.
Returns:
CasParser instance.

console

public static void console(String userInputSyntax)

nextLine

public org.jdom.Element nextLine()
                          throws ParseException
Entry point for the recursive descendant parser. Is overriden by the subclasses that implement the actual parser. This function is to be used only if you want to handle the ParseException and TokenMgrError objects yourself. Normally it's better to call nextOmobj() that encapsulates all this and returns always an OMOBJ, which contains an OME (OM error) when there is some parsing error.

Returns:
OpenMath object encoded as a JDOM tree.
Throws:
ParseException - Problem when parsing.

advanceToNextEOL

public void advanceToNextEOL()
Advance to next End Of Line (EOL) or end of input. Is overriden by the subclasses that implement the actual parser.


nextOmobj

public final org.jdom.Element nextOmobj()
Parse input, and return the first complete expression found. In case of parsing error, it advances to the next expression or end of input, and returns an OM error object. In case of tokenizing error, it returns null.

Returns:
OpenMath object encoded as a JDOM tree, or null.

linearToOpenMath

public static final List linearToOpenMath(String userInput,
                                          String userInputSyntax)

linearToOpenMath

public static final List linearToOpenMath(String userInput,
                                          String userInputSyntax,
                                          String lang)
Convert from linear input to OpenMath. This is just the nextOmobj() function wrapped in some utility code, that does things like building a list of all the valid expressions in the given input, inserting the linear input in the error objects for clearer error messages, and takes care of logging some debug information if requested.

Parameters:
input - linear input as written by the user.
userInputSyntax - syntax of the input expression.
lang - regional parser language. if parser not available will try default language
Returns:
OpenMath expressions list as XML elements. If there is some problem, the returned value is an empty list, but never null.

symbol

protected static org.jdom.Element symbol(String s)

symbolUnary

protected static org.jdom.Element symbolUnary(String s)

parseForeign

protected static final org.jdom.Element parseForeign(String inputSyntaxToken,
                                                     String expressionToken)