Package org.smtlib.sexpr
Class Parser
java.lang.Object
org.smtlib.sexpr.Lexer
org.smtlib.sexpr.Parser
- All Implemented Interfaces:
IParser
Parses the standard SMT-LIB concrete syntax to produce ASTs of objects that
are instances of the org.smtlib.* interfaces.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.smtlib.sexpr.Lexer
Lexer.IPLexToken, Lexer.LexTokenNested classes/interfaces inherited from interface org.smtlib.IParser
IParser.AbortInputException, IParser.ElementParser<T>, IParser.IFactory, IParser.ParserException, IParser.SyntaxException -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanWhether the command being parsed (or last returned) had a recoverable syntax errorprotected booleanWhether any such error was an invalid character, which the type checker does not seeThis field is used only to communicate the position of the name of a command to the command creator (instead of using method arguments).protected final IExpr.IFactoryThe (common) factory used to generate objectsThe most recent error, or nullThis field is used to communicate the beginning LP while parsing commandsstatic final StringThe start of the error message for solver text that is not SMT-LIB (see parseResponse)Fields inherited from class org.smtlib.sexpr.Lexer
badWhitespace, combined, csr, matcher, prefixCommentEnd, prefixCommentStart, prefixCommentText, sameLineTrailingEnd, sameLineTrailingStart, sameLineTrailingText, skipThroughEndOfLine -
Constructor Summary
ConstructorsConstructorDescriptionParser(SMT.Configuration smtConfig, ISource src) Creates a Parser using an SMT configuration object and a source for characters; ordinarily use a factory to obtain a parser. -
Method Summary
Modifier and TypeMethodDescriptionbooleanA helper check, called by command-specific parse methods in which the commands have no argumentsbooleanReturns true if the command most recently returned by parseCommand() had a syntax error that parsing recovered from; such a command is not sent to a solverbooleanReturns true if one of the errors commandHasError() reports was an invalid characterCreates a ParserException with the given message and position; callers should throw the result.Creates a ParserException from the given message and token; callers should throw the result.protected ILexTokenReports a vertical tab or form feed between tokens (except with --relax), which is then read as white space, and a keyword that is not a colon followed by a simple symbol (#185)Returns the most recent error, or nullParses a parenthesized list of terms, as returned by a get-assertions response.Parses a parenthesized list of(symbol bool)pairs, as returned by a get-assignment response.Parses one(symbol bool)pair, as found in a get-assignment response.Parse an attribute (keyword with optional value), returning null with error messages if an error occurs.protected IExpr.IAttribute<?> parseAttributeRest(IExpr.IKeyword keyword) Parses the (optional) value of an attribute whose keyword has already been parsed.List<IExpr.IAttribute<?>> Parse a sequence of attributes (keyword with optional value) terminated by a right parenthesis, returning null with error messages if an error occurs.Parse an attribute (keyword with optional value), returning null with error messages if an error occurs.Parses a binary literal, returning null with the given message if an error occurs; if the next token is not a binary literal, the token is not consumed,Parses a binding "(id expression)", returning null with error messages if an error occursParses a parenthesized sequence of let-bindingsParses the next text in the source as a SMT-LIB command; if an error occurs, the error is logged and the method skips through a matching number of right parenthesesParses a constructor declaration "(symbol selector*)"Parses a datatype declaration: "( constructor+ )" or "( par ( symbol+ ) ( constructor+ ) )"Parses a decimal, returning null with the given message if an error occurs; if the next token is not a decimal, the token is not consumed,Parses a declaration "(id sort)", returning null with error messages if an error occursParses a parenthesized sequence of IDeclaration itemsParses an expression, returning null with error messages if there is not a valid expression in the token stream.Parses a function declaration "( symbol ( sorted_var* ) sort )" used in define-funs-recparseHex()Parses a hex literal, returning null with the given message if an error occurs; if the next token is not a hex literal, the token is not consumed,Parses an identifier (either symbol or parameterized identifier) from the token stream, returning null with logged error messages if there is not one.Parses a keyword, returning null with an error message if an error occurs; if the next token is not a keyword, the token is not consumed.<T> List<T> parseList(IParser.ElementParser<T> elementParser, String kind, boolean allowEmpty) Parses a parenthesized list of elements using the given element parser.Parses a literal, returning null with error messages if an error occurs.Parses a logic definition (including beginning and ending parentheses, returning null with error messages if it fails; only part of the checking of the contents is performed in this call (the rest is done in loadLogic).parseLP()Parses a left parenthesis, returning null and emitting an error message if there isn't one (and the next token is not consumed)Parses a single match case: "(pattern term)"Parses a numeral, returning null with error messages if an error occurs; if the next token is not a numeral, the token is not consumed,Parses a match pattern: either a bare symbol (or wildcard _) or "(symbol symbol*)" where params may include _Parses a qualified identifier (either a symbol, a parameterized identifier, or an as identifier) from the token stream, returning null (with logged error messages) if there is not one.parseResponse(String response) parseRP()Parses a right parenthesis, returning null and emitting an error message if there isn't one (and the next token is not consumed)Parses an SMT-LIB command script.Parses a selector declaration "(symbol sort)"Parses and adds Sexpr to a list until parseSexpr returns null (indicating a RightParen has been seen or end of input or an error)Parses an SexprparseSort(List<ISort.IParameter> parameters) Parses a sort, returning null with error messages if a valid sort is not in the next parser tokens.parseSortList(List<ISort.IParameter> parameters) Parses sequence of sorts up to a right-parenthesis, returning null with error messages if an error occurs.Parses a string literal, returning null with an error message if an error occurs; if the next token is not a string literal, the token is not consumed,Parses a symbol, returning null with messages and not advancing the parser if an error occursparseSymbol(String msg) Parses a symbol (but not a reserved word unless the configuration field 'relax' is true), returning null with messages if an error occurs; the parser is advanced only if an actual symbol is parsed.Parses a parenthesized list of names, as returned by a get-unsat-core response.Parses a symbol or a reserved word, returning null with messages if an error occurs.List<IExpr.IAttribute<?>> Parses the attributes of an annotated term(! t attr+)up to the right parenthesis.Parses a parenthesized list of terms, as returned by a get-unsat-assumptions response.Parses a theory definition (including beginning and ending parentheses, returning null with error messages if it fails; only part of the checking of the contents is performed in this call (the rest is done in loadTheory).Parses a parenthesized list of(term value)pairs, as returned by a get-value response.Parses one(term value)pair, as found in a get-value response.pos(int start, int end) Returns an IPos object for the given character start and end positions and including a reference to the parser's source object.Returns an IPos object for the given character start and end positions and including a reference to the parser's source object.smt()Returns a handle to the parent SMTConfig object, in order to see command-line options etc.Methods inherited from class org.smtlib.sexpr.Lexer
abortLine, currentPos, EOD, getToken, getToken, getToken, isEOD, isLP, isRP, LP, peekToken, RP, setPos, skipThruRP, sourceMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.smtlib.IParser
abortLine, checkUserId, isEOD, parseListDatatypes, parseListTerms
-
Field Details
-
lastError
The most recent error, or null -
commandHasError
protected boolean commandHasErrorWhether the command being parsed (or last returned) had a recoverable syntax error -
commandHasLexicalError
protected boolean commandHasLexicalErrorWhether any such error was an invalid character, which the type checker does not see -
factory
The (common) factory used to generate objects -
savedlp
This field is used to communicate the beginning LP while parsing commands -
commandName
This field is used only to communicate the position of the name of a command to the command creator (instead of using method arguments). -
UNEXPECTED_RESPONSE
The start of the error message for solver text that is not SMT-LIB (see parseResponse)- See Also:
-
-
Constructor Details
-
Parser
Creates a Parser using an SMT configuration object and a source for characters; ordinarily use a factory to obtain a parser.
-
-
Method Details
-
smt
Returns a handle to the parent SMTConfig object, in order to see command-line options etc. that are fields of smtConfig -
lastError
Description copied from interface:IParserReturns the most recent error, or null -
commandHasError
public boolean commandHasError()Description copied from interface:IParserReturns true if the command most recently returned by parseCommand() had a syntax error that parsing recovered from; such a command is not sent to a solver- Specified by:
commandHasErrorin interfaceIParser
-
commandHasLexicalError
public boolean commandHasLexicalError()Description copied from interface:IParserReturns true if one of the errors commandHasError() reports was an invalid character- Specified by:
commandHasLexicalErrorin interfaceIParser
-
pos
Returns an IPos object for the given character start and end positions and including a reference to the parser's source object.- Parameters:
start- the start character position (counting from 0)end- the end character position (one past the last actual character to be included)- Returns:
- the IPos object representing the character range within the parser's current source
-
pos
Returns an IPos object for the given character start and end positions and including a reference to the parser's source object. -
parseScript
Description copied from interface:IParserParses an SMT-LIB command script. The result is either a string literal or a parenthesized list of commands (which are parenthesized themselves); the string literal denotes the name of a file from which the commands are read when the command is executed; if the script is included directly, it is parsed, but typechecking is performed in context upon execution. If any errors occur, messages are logged and null is returned, with the parser advancing through a matching right parenthesis.- Specified by:
parseScriptin interfaceIParser- Returns:
- the parsed script
-
parseCommand
Parses the next text in the source as a SMT-LIB command; if an error occurs, the error is logged and the method skips through a matching number of right parentheses- Specified by:
parseCommandin interfaceIParser- Returns:
- returns the parsed command, or EOD.eod if the end of input has been reached, or null if no valid command could be parsed
-
checkNoArg
public boolean checkNoArg()A helper check, called by command-specific parse methods in which the commands have no arguments -
parseSexpr
Parses an Sexpr- Returns:
- an Sexpr or null if no more input
- Throws:
IParser.ParserException- if a parsing problem occurred, such as an invalid token or mismatched parentheses
-
parseSeq
Parses and adds Sexpr to a list until parseSexpr returns null (indicating a RightParen has been seen or end of input or an error)- Returns:
- a SExpr.Seq containing the sequence of SExpr seen
- Throws:
IParser.ParserException- FIXME - no more of these?
-
parseQualifiedIdentifier
Parses a qualified identifier (either a symbol, a parameterized identifier, or an as identifier) from the token stream, returning null (with logged error messages) if there is not one.- Specified by:
parseQualifiedIdentifierin interfaceIParser- Throws:
IParser.ParserException
-
parseIdentifier
Parses an identifier (either symbol or parameterized identifier) from the token stream, returning null with logged error messages if there is not one.- Specified by:
parseIdentifierin interfaceIParser- Throws:
IParser.ParserException
-
parseExpr
Parses an expression, returning null with error messages if there is not a valid expression in the token stream.- Specified by:
parseExprin interfaceIParser- Throws:
IParser.ParserException
-
parseDeclarations
Parses a parenthesized sequence of IDeclaration items- Specified by:
parseDeclarationsin interfaceIParser- Throws:
IParser.ParserException
-
parseBindings
Parses a parenthesized sequence of let-bindings- Specified by:
parseBindingsin interfaceIParser- Throws:
IParser.ParserException
-
parseSelector
Parses a selector declaration "(symbol sort)"- Specified by:
parseSelectorin interfaceIParser- Throws:
IParser.ParserException
-
parseConstructor
Parses a constructor declaration "(symbol selector*)"- Specified by:
parseConstructorin interfaceIParser- Throws:
IParser.ParserException
-
parseDatatype
Parses a datatype declaration: "( constructor+ )" or "( par ( symbol+ ) ( constructor+ ) )"- Specified by:
parseDatatypein interfaceIParser- Throws:
IParser.ParserException
-
parseFunctionDeclaration
Parses a function declaration "( symbol ( sorted_var* ) sort )" used in define-funs-rec- Specified by:
parseFunctionDeclarationin interfaceIParser- Throws:
IParser.ParserException
-
parseDeclaration
Parses a declaration "(id sort)", returning null with error messages if an error occurs- Specified by:
parseDeclarationin interfaceIParser- Throws:
IParser.ParserException
-
parseBinding
Parses a binding "(id expression)", returning null with error messages if an error occurs- Specified by:
parseBindingin interfaceIParser- Throws:
IParser.ParserException
-
parseList
public <T> List<T> parseList(IParser.ElementParser<T> elementParser, String kind, boolean allowEmpty) throws IParser.ParserException Parses a parenthesized list of elements using the given element parser.- Parameters:
elementParser- lambda that parses one elementkind- singular noun describing the element type (e.g. "term"), used in error messagesallowEmpty- if false, throws when the list is empty- Throws:
IParser.ParserException
-
parseSymbol
Parses a symbol, returning null with messages and not advancing the parser if an error occurs- Specified by:
parseSymbolin interfaceIParser- Throws:
IParser.ParserException
-
parseSymbol
Parses a symbol (but not a reserved word unless the configuration field 'relax' is true), returning null with messages if an error occurs; the parser is advanced only if an actual symbol is parsed. The error message is given by the argument; it may contain a '#' character that will be replaced by the kind() of the token actually observed; if the argument is null, no error message is emitted.- Throws:
IParser.ParserException
-
parseSymbolOrReservedWord
Parses a symbol or a reserved word, returning null with messages if an error occurs. The error message is given by the argument; it may contain a '#' character that will be replaced by the kind() of the token actually observed.- Throws:
IParser.ParserException
-
parseLiteral
Parses a literal, returning null with error messages if an error occurs.- Specified by:
parseLiteralin interfaceIParser- Throws:
IParser.ParserException
-
parseNumeral
Parses a numeral, returning null with error messages if an error occurs; if the next token is not a numeral, the token is not consumed,- Specified by:
parseNumeralin interfaceIParser- Throws:
IParser.ParserException
-
parseDecimal
Parses a decimal, returning null with the given message if an error occurs; if the next token is not a decimal, the token is not consumed,- Specified by:
parseDecimalin interfaceIParser- Throws:
IParser.ParserException
-
parseBinary
Parses a binary literal, returning null with the given message if an error occurs; if the next token is not a binary literal, the token is not consumed,- Specified by:
parseBinaryin interfaceIParser- Throws:
IParser.ParserException
-
parseHex
Parses a hex literal, returning null with the given message if an error occurs; if the next token is not a hex literal, the token is not consumed,- Specified by:
parseHexin interfaceIParser- Throws:
IParser.ParserException
-
parseStringLiteral
Parses a string literal, returning null with an error message if an error occurs; if the next token is not a string literal, the token is not consumed,- Specified by:
parseStringLiteralin interfaceIParser- Throws:
IParser.ParserException
-
parseKeyword
Parses a keyword, returning null with an error message if an error occurs; if the next token is not a keyword, the token is not consumed.- Specified by:
parseKeywordin interfaceIParser- Throws:
IParser.ParserException
-
parseSort
Parses a sort, returning null with error messages if a valid sort is not in the next parser tokens.- Specified by:
parseSortin interfaceIParser- Throws:
IParser.ParserException
-
getToken
Reports a vertical tab or form feed between tokens (except with --relax), which is then read as white space, and a keyword that is not a colon followed by a simple symbol (#185)- Overrides:
getTokenin classLexer- Throws:
IParser.ParserException
-
parseSortList
Parses sequence of sorts up to a right-parenthesis, returning null with error messages if an error occurs.- Throws:
IParser.ParserException
-
parseAttributeValue
Parse an attribute (keyword with optional value), returning null with error messages if an error occurs.- Specified by:
parseAttributeValuein interfaceIParser- Throws:
IParser.ParserException
-
parseAttribute
Parse an attribute (keyword with optional value), returning null with error messages if an error occurs.- Specified by:
parseAttributein interfaceIParser- Throws:
IParser.ParserException
-
parseAttributeRest
protected IExpr.IAttribute<?> parseAttributeRest(IExpr.IKeyword keyword) throws IParser.ParserException Parses the (optional) value of an attribute whose keyword has already been parsed.- Throws:
IParser.ParserException
-
parseAttributeSequence
Parse a sequence of attributes (keyword with optional value) terminated by a right parenthesis, returning null with error messages if an error occurs.- Throws:
IParser.ParserException
-
parseTermAttributeSequence
Parses the attributes of an annotated term(! t attr+)up to the right parenthesis. LikeparseAttributeSequence(), except that a:patternvalue is parsed as what SMT-LIB defines it to be, a parenthesized (possibly empty, per SMT-LIB 2.7) list of terms, giving anIExpr.IPatternTerms-- the same representation the expression factory builds. A:patternvalue that is not a list is left for the TypeChecker to report.- Throws:
IParser.ParserException
-
parseLogic
Parses a logic definition (including beginning and ending parentheses, returning null with error messages if it fails; only part of the checking of the contents is performed in this call (the rest is done in loadLogic).- Specified by:
parseLogicin interfaceIParser- Throws:
IParser.ParserException
-
parseTheory
Parses a theory definition (including beginning and ending parentheses, returning null with error messages if it fails; only part of the checking of the contents is performed in this call (the rest is done in loadTheory).- Specified by:
parseTheoryin interfaceIParser- Throws:
IParser.ParserException
-
parseAssertionList
Parses a parenthesized list of terms, as returned by a get-assertions response.- Throws:
IParser.ParserException
-
parseTermList
Parses a parenthesized list of terms, as returned by a get-unsat-assumptions response.- Throws:
IParser.ParserException
-
parseSymbolList
Parses a parenthesized list of names, as returned by a get-unsat-core response.- Throws:
IParser.ParserException
-
parseValuePair
Parses one(term value)pair, as found in a get-value response.- Throws:
IParser.ParserException
-
parseValueList
Parses a parenthesized list of(term value)pairs, as returned by a get-value response.- Throws:
IParser.ParserException
-
parseAssignmentPair
Parses one(symbol bool)pair, as found in a get-assignment response.- Throws:
IParser.ParserException
-
parseAssignmentList
public List<IResponse.IPair<IExpr.ISymbol,Boolean>> parseAssignmentList() throws IParser.ParserExceptionParses a parenthesized list of(symbol bool)pairs, as returned by a get-assignment response.- Throws:
IParser.ParserException
-
parseResponse
- Throws:
IParser.ParserException
-
parseLP
Parses a left parenthesis, returning null and emitting an error message if there isn't one (and the next token is not consumed)- Throws:
IParser.ParserException
-
parseRP
Parses a right parenthesis, returning null and emitting an error message if there isn't one (and the next token is not consumed)- Throws:
IParser.ParserException
-
error
Creates a ParserException with the given message and position; callers should throw the result. -
error
Creates a ParserException from the given message and token; callers should throw the result. If the token is a lexical error token, the exception carries the lexer's message instead. -
parseMatchCase
Parses a single match case: "(pattern term)"- Throws:
IParser.ParserException
-
parsePattern
Parses a match pattern: either a bare symbol (or wildcard _) or "(symbol symbol*)" where params may include _- Throws:
IParser.ParserException
-