prodigy.pgcl.ppy_printer¶
Pretty printer for .ppy¶
Prints a pGCL AST in the .ppy syntax, with the canonical spelling and,
or and not. Parsing the output with prodigy.pgcl.ppy_parser.parse_ppy()
gives back an equal AST; the converter from .pgcl is built on this.
Comments are not part of the AST and are lost.
>>> from prodigy.pgcl.parser import parse_pgcl
>>> print(program_to_ppy(parse_pgcl("nat x; rparam p; {x := x + 1} [p] {x := 0}; ?Pr[x = 1]")), end="")
x: nat;
param p: real;
{
x = x + 1;
} [p] {
x = 0;
}
query Pr[x == 1];
- exception PpyPrintError[source]¶
Bases:
ValueErrorThe AST cannot be written in
.ppy(e.g. a name that is a keyword there).
- expr_to_ppy(expr)[source]¶
Print an expression in the
.ppysyntax.>>> from prodigy.pgcl.parser import parse_expectation >>> expr_to_ppy(parse_expectation("not (x = 1) & y^2 < -x + 1")) 'not x == 1 and y ** 2 < -(x + 1)'
- Parameters:
expr (
VarExpr|BoolLitExpr|NatLitExpr|RealLitExpr|UnopExpr|BinopExpr|CategoricalExpr|SubstExpr|TickExpr|FunctionCallExpr|InferExpr|SampleExpr)- Return type:
- instr_to_ppy(instr)[source]¶
Print an instruction (or query) in the
.ppysyntax.- Parameters:
instr (
SkipInstr|AbortInstr|WhileInstr|IfInstr|AsgnInstr|ChoiceInstr|LoopInstr|TickInstr|ObserveInstr|QueryInstr|LocalDeclInstr|ProbabilityQueryInstr|ExpectationInstr|PlotInstr|PrintInstr|OptimizationQuery)- Return type: