Posted to tcl by ccbbaa at Fri Oct 26 13:40:41 GMT 2018view pretty

PEG Calculator (Expression)
    Expression  <- Term (' '* AddOp ' '* Term)*                 ;
    Term        <- Factor (' '* MulOp ' '* Factor)*             ;
    Fragment    <- '(' ' '* Expression ' '*  ')' / Number / Var ;
    Factor      <- Fragment (' '* PowOp ' '* Fragment)*         ;
    Number      <- Sign? Digit+                                 ;
    Var         <- '$' ( 'x'/'y'/'z' )                          ;

    Digit       <- '0'/'1'/'2'/'3'/'4'/'5'/'6'/'7'/'8'/'9'      ;
    Sign        <- '-' / '+'                                    ;
    MulOp       <- '*' / '/'                                    ;
    AddOp       <- '+' / '-'                                    ;
    PowOp       <- '**'
END;

# cli command to compile:
pt generate \
  snit -class Calculator -name Grammar "Grammar0.snit" \
  peg "Grammar0.peg"

# error:
pt failed: Reading peg Grammar0.peg ...
Generating a snit parser ...
Parse error at position 719 (Line 16, column 0).
... '**'\nEND;\n ...
    -----------^
Expected one of
* A string "END"
* A string "leaf"
* A unicode alphabetical character
* The character '_:'

# references:
# https://wiki.tcl-lang.org/page/PEG+Example
# NOTE: the same grammar seems to compile cleanly with pgen, only pt does
# not like it

% info pa
8.6.6