Package nltk :: Package sem :: Module logic :: Class LogicParser
[hide private]
[frames] | no frames]

type LogicParser

source code

object --+
         |
        LogicParser
Known Subclasses:

A lambda calculus expression parser.

Instance Methods [hide private]
 
__init__(self, type_check=False) source code
 
parse(self, data, signature=None)
Parse the expression.
source code
 
process(self, data)
Split the data into tokens
source code
 
process_quoted_token(self, data_idx, data) source code
 
get_all_symbols(self)
This method exists to be overridden
source code
 
inRange(self, location)
Return TRUE if the given location is within the buffer
source code
 
token(self, location=None)
Get the next waiting token.
source code
 
isvariable(self, tok) source code
 
parse_Expression(self, context)
Parse the next complete expression from the stream and return it.
source code
 
handle(self, tok, context)
This method is intended to be overridden for logics that use different operators or expressions
source code
 
attempt_adjuncts(self, expression, context) source code
 
handle_negation(self, tok, context) source code
 
make_NegatedExpression(self, expression) source code
 
handle_variable(self, tok, context) source code
 
get_next_token_variable(self, description) source code
 
handle_lambda(self, tok, context) source code
 
handle_quant(self, tok, context) source code
 
get_QuantifiedExpression_factory(self, tok)
This method serves as a hook for other logic parsers that have different quantifiers
source code
 
make_QuanifiedExpression(self, factory, variable, term) source code
 
handle_open(self, tok, context) source code
 
attempt_EqualityExpression(self, expression, context)
Attempt to make an equality expression.
source code
 
make_EqualityExpression(self, first, second)
This method serves as a hook for other logic parsers that have different equality expression classes
source code
 
attempt_BooleanExpression(self, expression, context)
Attempt to make a boolean expression.
source code
 
get_BooleanExpression_factory(self, tok)
This method serves as a hook for other logic parsers that have different boolean operators
source code
 
make_BooleanExpression(self, factory, first, second) source code
 
attempt_ApplicationExpression(self, expression, context)
Attempt to make an application expression.
source code
 
make_ApplicationExpression(self, function, argument) source code
 
make_VariableExpression(self, name) source code
 
make_LambdaExpression(self, variable, term) source code
 
has_priority(self, operation, context) source code
 
assertNextToken(self, expected) source code
 
assertToken(self, tok, expected) source code
 
__repr__(self) source code
 
ensure_abstractable(self, tok)
Instance Variables [hide private]
  type_check
A list of tuples of quote characters.
Method Details [hide private]

__init__(self, type_check=False)
(Constructor)

source code 
Parameters:
  • type_check - boolean should type checking be performed? to their types.
Overrides: object.__init__

parse(self, data, signature=None)

source code 

Parse the expression.

Parameters:
  • data - str for the input to be parsed
  • signature - dict<str, str> that maps variable names to type strings
Returns:
a parsed Expression

token(self, location=None)

source code 

Get the next waiting token. If a location is given, then return the token at currentIndex+location without advancing currentIndex; setting it gives lookahead/lookback capability.

attempt_EqualityExpression(self, expression, context)

source code 

Attempt to make an equality expression. If the next token is an equality operator, then an EqualityExpression will be returned. Otherwise, the parameter will be returned.

attempt_BooleanExpression(self, expression, context)

source code 

Attempt to make a boolean expression. If the next token is a boolean operator, then a BooleanExpression will be returned. Otherwise, the parameter will be returned.

attempt_ApplicationExpression(self, expression, context)

source code 

Attempt to make an application expression. The next tokens are a list of arguments in parens, then the argument expression is a function being applied to the arguments. Otherwise, return the argument expression.

__repr__(self)
(Representation operator)

source code 
Overrides: object.__repr__
(inherited documentation)

Instance Variable Details [hide private]

type_check

A list of tuples of quote characters. The 4-tuple is comprised of the start character, the end character, the escape character, and a boolean indicating whether the quotes should be included in the result. Quotes are used to signify that a token should be treated as atomic, ignoring any special characters within the token. The escape character allows the quote end character to be used within the quote. If True, the boolean indicates that the final token should contain the quote and escape characters. This method exists to be overridden