dk.brics.grammar.parser
Class Parser

java.lang.Object
  extended by dk.brics.grammar.parser.Parser

public class Parser
extends Object

Parser.

Based on a variant of Earley's algorithm.


Constructor Summary
Parser(Grammar g, PrintWriter out)
          Constructs a new parser.
 
Method Summary
 boolean check(String x, Production start)
          Checks whether the given string can be parsed without syntax errors.
 long getMaxMemory()
          Returns maximal memory usage during last parsing.
 long getMaxStates()
          Returns maximal number of parse states during last parsing.
 long getTotalStates()
          Returns total number of parse states during last parsing.
 AST parse(String x)
          Parses the given string.
 AST parse(String x, String file)
          Parses the given string.
 AST parse(String x, String file, Production start)
          Parses the given string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Parser

public Parser(Grammar g,
              PrintWriter out)
Constructs a new parser.

Parameters:
g - grammar
out - print writer for verbose messages (null if none)
Method Detail

check

public boolean check(String x,
                     Production start)
Checks whether the given string can be parsed without syntax errors.

Parameters:
x - string to parse
start - start production (if null, all productions of the start nonterminal are used)
Returns:
true iff the string can be parsed by the grammar

getMaxMemory

public long getMaxMemory()
Returns maximal memory usage during last parsing. (Note: garbage collection might reduce this number.)

Returns:
memory usage

getMaxStates

public long getMaxStates()
Returns maximal number of parse states during last parsing.

Returns:
number of parse states

getTotalStates

public long getTotalStates()
Returns total number of parse states during last parsing.

Returns:
number of parse states

parse

public AST parse(String x)
          throws ParseException
Parses the given string. Same as parse(x, null, null).

Parameters:
x - string to parse
Returns:
an abstract syntax tree for x
Throws:
ParseException - in case of parse error

parse

public AST parse(String x,
                 String file)
          throws ParseException
Parses the given string. Same as parse(x, file, null).

Parameters:
x - string to parse
file - path or URL of string to parse (null if unknown)
Returns:
an abstract syntax tree for x
Throws:
ParseException - in case of parse error

parse

public AST parse(String x,
                 String file,
                 Production start)
          throws ParseException
Parses the given string.

Parameters:
x - string to parse
file - path or URL of string to parse (null if unknown)
start - start production (if null, all productions of the start nonterminal are used)
Returns:
an abstract syntax tree for x
Throws:
ParseException - in case of parse error


Copyright © 2005-2008 Anders Møller.