tiny.smt.smtlib.parse.script
Defined in smtlib.parse.
Reads the commands of an SMT-LIB script in order and collects its logic and assertions.
API (1)
Actions
Public operations.
parse: Reads every command of the parser's text and returns aScriptover the parser'sContextwith the script's logic and assertions.
Source
Source: lib/smt/src/smtlib/parse/root.zig:10
zig
pub const script = @import("script.zig");Source: lib/smt/src/smtlib/parse/script.zig
zig
//! Reads the commands of an SMT-LIB script in order and collects its logic and assertions. Each//! command either declares a name that later terms use or asserts a formula, so the commands are//! read in order and each declaration is known before the terms after it. The reader accepts five//! commands and refuses every other with `UnsupportedCommand`.const std = @import("std");const smt = @import("../../root.zig");const errors = @import("error.zig");const sort = @import("sort.zig");const state = @import("state.zig");const term_parser = @import("term.zig");const token = @import("token.zig");const Error = errors.Error;const ParseError = errors.ParseError;const Parser = state.Parser;const term = smt.term;/// Reads every command of the parser's text and returns a `Script` over the parser's `Context` with/// the script's logic and assertions. `parseScript` calls it, and code that builds its own `Parser`/// calls it to read a script with that state. `set-logic` sets the logic, which is `ALL` until one/// does. `declare-const` adds a constant and `declare-fun` a function to the `Context`, and both/// record the name for the terms that follow. `assert` reads a term and appends it to the/// assertions, and `check-sat` is read and ignored. It returns `DuplicateSymbol` for a name/// declared twice in the script, and `UnsupportedCommand` for any other command. It checks no/// sorts: an `assert` of a non-Boolean term is accepted. The logic name and the recorded names/// borrow the parser's text. On an error it frees the assertion list, and the terms already built/// stay in the `Context`.pub fn parse(parser: *Parser) Error!term.Script { var parsed = term.Script.init(parser.ctx, "ALL"); errdefer parsed.deinit(); while (token.skipSpace(parser)) { try token.expectLeft(parser); const command = try token.atom(parser); if (std.mem.eql(u8, command, "set-logic")) { parsed.logic = try token.atom(parser); try token.expectRight(parser); } else if (std.mem.eql(u8, command, "declare-const")) { const name = try token.atom(parser); if (parser.symbols.contains(name) or parser.functions.contains(name)) return ParseError.DuplicateSymbol; const symbol_sort = try sort.parse(parser); const symbol = try parser.ctx.symbol(name, symbol_sort); try parser.symbols.put(name, symbol); try token.expectRight(parser); } else if (std.mem.eql(u8, command, "declare-fun")) { const name = try token.atom(parser); if (parser.symbols.contains(name) or parser.functions.contains(name)) return ParseError.DuplicateSymbol; const params = try sort.list(parser); defer parser.ctx.allocator.free(params); const result = try sort.parse(parser); const function = try parser.ctx.function(name, params, result); try parser.functions.put(name, function); try token.expectRight(parser); } else if (std.mem.eql(u8, command, "assert")) { try parsed.assertTerm(try term_parser.parse(parser)); try token.expectRight(parser); } else if (std.mem.eql(u8, command, "check-sat")) { try token.expectRight(parser); } else { return ParseError.UnsupportedCommand; } } return parsed;}Complete call list for smtlib.parse.script.parse
9 direct calls.
tiny.smt.smtlib.parse.sort.list[function] atlib/smt/src/smtlib/parse/sort.zig:60tiny.smt.smtlib.parse.sort.parse[function] atlib/smt/src/smtlib/parse/sort.zig:23tiny.smt.smtlib.parse.token.atom[function] atlib/smt/src/smtlib/parse/token.zig:59tiny.smt.smtlib.parse.token.expectLeft[function] atlib/smt/src/smtlib/parse/token.zig:43tiny.smt.smtlib.parse.token.expectRight[function] atlib/smt/src/smtlib/parse/token.zig:50tiny.smt.smtlib.parse.token.skipSpace[function] atlib/smt/src/smtlib/parse/token.zig:14tiny.smt.Script.assertTerm[method] atlib/smt/src/term.zig:1038tiny.smt.Script.deinit[method] atlib/smt/src/term.zig:1031tiny.smt.Script.init[function] atlib/smt/src/term.zig:1025
Audit
| Definitions | 2 |
|---|---|
| Public names | 2 |
| Members | 0 |
| Version | 26.7.0 |
| Revision | daab053ee433 |