All Projects → gmalecha → Coq Printf

gmalecha / Coq Printf

Licence: mit
Implementation of sprintf for Coq

Labels

Projects that are alternatives of or similar to Coq Printf

Software Foundations
Coq proofs of exercises in Pierce's book
Stars: ✭ 5 (-66.67%)
Mutual labels:  coq
Cufp 2015 Tutorial
An introductory tutorial for the Coq proof assistant.
Stars: ✭ 9 (-40%)
Mutual labels:  coq
Stalin Sort
Add a stalin sort algorithm in any language you like ❣️ if you like give us a ⭐️
Stars: ✭ 868 (+5686.67%)
Mutual labels:  coq
Finset
A Coq library for extensional finite sets and comprehension
Stars: ✭ 6 (-60%)
Mutual labels:  coq
Cpp2v
Formalization of C++ for verification purposes.
Stars: ✭ 24 (+60%)
Mutual labels:  coq
Monads
Coq code accompanying several articles on semantics of functional programming languages
Stars: ✭ 9 (-40%)
Mutual labels:  coq
Unimath
This coq library aims to formalize a substantial body of mathematics using the univalent point of view.
Stars: ✭ 680 (+4433.33%)
Mutual labels:  coq
Hello World
A Hello World program in Coq.
Stars: ✭ 14 (-6.67%)
Mutual labels:  coq
Coqpie
CoqPIE (an IDE for the Coq theorem prover + PEDANTIC)
Stars: ✭ 8 (-46.67%)
Mutual labels:  coq
Coqjvm
Coq executable semantics and resource verifier
Stars: ✭ 10 (-33.33%)
Mutual labels:  coq
Coq Guarded Computational Type Theory
Stars: ✭ 18 (+20%)
Mutual labels:  coq
Autosubst
Automation for de Bruijn syntax and substitution in Coq
Stars: ✭ 22 (+46.67%)
Mutual labels:  coq
Software Foundations
Solutions to the exercises from the 'Software Foundations' book by Benjamin Pierce et al.
Stars: ✭ 9 (-40%)
Mutual labels:  coq
Crimp
Certified Relational to Imperative
Stars: ✭ 5 (-66.67%)
Mutual labels:  coq
Ledgertheory
Stars: ✭ 12 (-20%)
Mutual labels:  coq
Pudding
KCoFI Pudding: The formal proofs for the KCoFI system
Stars: ✭ 5 (-66.67%)
Mutual labels:  coq
Hott Species
Combinatorial species in HoTT
Stars: ✭ 9 (-40%)
Mutual labels:  coq
Vvclocks
Verified vector clocks, with Coq!
Stars: ✭ 14 (-6.67%)
Mutual labels:  coq
Jt89
sn76489an compatible Verilog core, with emphasis on FPGA implementation and Megadrive/Master System compatibility
Stars: ✭ 14 (-6.67%)
Mutual labels:  coq
Dblib Linear
Formalisation of the linear lambda calculus in Coq
Stars: ✭ 10 (-33.33%)
Mutual labels:  coq

cop-printf

Implementation of sprintf and sscanf for Coq

Example

Require Import Coq.Strings.String.
Require Import Printf.Printf.
Require Import Printf.Scanf.

Eval compute in (sprintf "%b" 1234).
(* "10011010010" : string *)

Eval compute in (sscanf "%d %d" (fun n1 n2 s => Some (n1, n2, s)) "12  34  56").
(* Some (12, 34, "  56") : option (nat * nat * string) *)

Summary

sprintf expects a format string as its first argument, plus one argument for every format specifier (%d, %s, etc.) in that string (there may be none), and produces a string.

sscanf expects a format string as its first argument, a continuation as its second argument, and a string to parse as its third argument. The continuation takes one argument for every format specifier in the format string, plus one more for the remaining string after reaching the end of the format string, and produces an option result.

sprintf "%d %d" : nat -> nat -> string
sscanf "%d %d" : (nat -> nat -> string -> option R) -> string -> option R
(* For any type R *)

Format specifiers

The syntax of format specifiers is given by this regular expression:

%(-|+| |#|0)^* (\d+)   (N?)   (s|c|b|o|d|x|X|Zd)

which corresponds to this structure:

%[flags]       [width] [type] specifier

Flags

Flags Description
- Left justify
+ Precede nonnegative numbers with a plus sign (only for nat, N, Z)
(space) Space if no sign precedes
# With specifier o, x, X, precede with 0, 0x, 0X respectively for values different than zero
0 Pad with 0's instead of space

These flags are ignored by sscanf.

Width

The width modifier (\d+) gives:

  • for sprintf, the minimum number of characters to be printed (this enables padding);
  • for sscanf, the maximum number of characters to be read for this specifier.

Type

The type modifier (N?) affects the specifiers b, o, d, x, X to use the type N instead of the default nat.

Specifiers

Specifier Description Types
s string string
c character ascii
b binary nat, N
o octal nat, N
d decimal nat, N
x hexadecimal lower case nat, N
X hexadecimal upper case nat, N
Zd signed decimal Z

The special sequence %% encodes a literal %.

When used with scanf, a whitespace character in a format string will match any number of consecutive whitespace characters.

Resources

Reference: http://www.cplusplus.com/reference/cstdio/printf

Project structure

Under theories/.

External modules

  • FormatNotations.v: Notations for format strings
  • Printf.v
  • Scanf.v

Internal modules

  • Digits.v: Print numbers as strings
  • Flags.v: Definition of flags
  • Justify.v: Justification and padding
  • Format.v: Definition of format strings
  • FormatParser.v: Parse and print format string notation
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].