Parythony Grammar

[ Home ]
[ Implementation Details ]

Parythony Language Features

Parythony is both a subset and superset of Python in which all operators precede their operands, except a given class can only inherit from a single base class (no multiple inheritance). Parythony borrows the interface feature from Java, in which the interface keyword is renamed to "scool". Two other new keywords include "scoolref" (built-in function returns a scool reference) and "abclass" (abstract class). File extensions include .PRY (source code), .PRYC (compiled code), and .PRYML (text file which may have Parythony code embedded in it).

Keyboard Aid

This optional feature enables hyphens, open parentheses, and close parentheses to be entered by typing single quotes, commas, and periods, respectively. When enabled, keyboard aid can be temporarily suppressed by using the Ctrl key in conjunction with typing single quotes, commas, and periods (no character substitution takes place). By convention, hyphens are used to separate words in multi-word identifiers, but single quotes are easier to type than hyphens. Similarly, commas and periods are easier to type than parentheses.

Special Characters

  • ()  grouping
  • -_  used in identifiers
  • ;  end of stmt.
  • :  dot operator
  • " '  string delimiters
  • \  escape char.
  • #  comment
  • {* *}  block comment

Grammar Notation

  • Non-terminal symbol: <symbol name>
  • Optional text in brackets: [ text ]
  • Repeats zero or more times: [ text ]...
  • Repeats one or more times: <symbol name>...
  • Pipe separates alternatives: opt1 | opt2
  • Comments in italics
  • Advanced features flagged as **
  • Omitted features ***

White space occurs between tokens (parentheses and semicolon need no adjacent white space):

<source file>:

  • [<line-comment>] [<stmt-semi>]... [<def>]... [<class>]... [<stmt-semi>]...

<import stmt>:

  • import <module>
  • import ( <module>... )
  • from <rel module> import <mod list>
  • from <rel module> import *

<module>:

  • <name>
  • ( <name> as <name> )
  • ( : <name>... [ as <name>] )

<mod list>:

  • <id as>
  • ( <id as>... )

<id as>:

  • <mod id>
  • ( <mod id> as <name> )

<mod id>:

  • <mod name>
  • <class name>
  • <func name>
  • <var name>

<rel module>:

  • ( <colon list> [<name>]... )

<class>:

  • ( <cls typ> <name> [<base class>][<does>] do <def>... )
  • ( scool <name> [<does>] do [<const decl>]... [<def hdr>]... )

<cls typ>:

  • class
  • abclass

<does>:

  • does ( <scool name>... )

<scool name>:
<base class>:

  • <name>
  • ( : <name><name>... )

<const decl>:

  • const <name><const expr> ;

<def hdr>:

  • def <name> ( [<parm>]... )

<def>:

  • def <name> ( [<parm>]... ) do <block>

<parm>:

  • <name>
  • ( set <name><expr> )
  • ( all <name> )

<block>:

  • ( <stmt-semi>... )

<stmt-semi>:

  • <stmt> ;

<stmt>:

  • pass
  • ** <if stmt>
  • <while stmt>
  • ** <for stmt>
  • ** <try stmt>
  • <disruptive stmt>
  • <call stmt>
  • <asst stmt>
  • <del stmt>
  • <print stmt>
  • <import stmt>

<disruptive stmt>:

  • <continue stmt>
  • <break stmt>
  • <return stmt>
  • ** <raise stmt>

<call expr>:

  • ( <name> [<expr>]... )
  • ( : <obj expr> [<colon expr>]... ( <method name> [<expr>]... ))
  • ( call <expr>... )

<call stmt>:

  • ( <name> [<expr>]... )
  • : <obj expr> [<colon expr>]... ( <method name> [<expr>]... )
  • call <expr>...

<colon expr>:

  • <name>
  • ( <name> [<expr>]... )

<asst stmt>:

  • <asst op><name><expr>
  • <asst op><target expr><expr>

<asst op>:

  • set | addset | minusset | mpyset | divset |
  • idivset | modset | shlset | shrset |
  • andset | orset | xorset

<target expr>:

  • ( : <name> [<colon expr>]... <name> )
  • ( slice <arr><expr> [<expr>] )
  • ( slice <arr><expr> all )

<arr>:   string, list or tuple

  • <name>
  • <expr>

<if stmt>:

  • if <expr><block> [ elif <expr><block>]... [ else <block>]

<while stmt>:

  • while <expr> do <block>
  • do <block> while <expr>

<for stmt>:

  • for <name> in <expr> do <block>

<try stmt>:

  • try <block> <except clause>... [ else <block>] [ finally <block>]
  • try <block> finally <block>

<except clause>:

  • except <name> [ as <name>] <block>

<raise stmt>:

  • raise [<expr> [ from <expr>]]

<return stmt>:

  • return [<expr>]

<break stmt>:

  • break

<continue stmt>:

  • continue

<del stmt>:

  • del <expr>

<print stmt>:  // built-in function

  • ( print [<expr>]... )
  • ( echo [<expr>]... )

<expr>:

  • <keyword const>
  • <literal>
  • <name>
  • ( <unary op><expr> )
  • ( <bin op><expr><expr> )
  • ( <multi op><expr><expr>... )
  • ( quest <expr><expr><expr> )
  • <list expr>
  • *** <tuple expr>
  • <bytearray expr>
  • <set expr>
  • <dict expr>
  • <target expr>
  • <obj expr>

<obj expr>:

  • <name>
  • <call stmt>

<unary op>:

  • minus  negate
  • notbits  bitwise not
  • not

<bin op>:

  • <arith op>
  • <comparison op>
  • <shift op>
  • <bitwise op>
  • <boolean op>

<arith op>:

  • div | idiv | mod | mpy | add | minus

<comparison op>:

  • ge | le | gt | lt | eq | ne | is | in

<shift op>:

  • shl | shr

<bitwise op>:

  • andbits | orbits | xorbits

<boolean op>:

  • and | or | xor

<multi op>:

  • mpy | add | or | and |
  • strdo  % operator
  • strcat  + operator

<const expr>:

  • <literal>
  • <keyword const>

<literal>:

  • <num lit>
  • <string lit>
  • <bytes lit>

<list expr>:

  • ( list [<expr>]... )

<tuple expr>:

  • ( tuple [<expr>]... )

<bytearray expr>:

  • ( bytearray <expr> )

<set expr>:

  • ( listuniq <expr> )

<dict expr>:

  • ( dict [ <pair>]... )

<pair>:

  • ( <name><expr> )
  • ( <literal><expr> )

<lisp funcs>:

  • ( quote <expr> )
  • ( compile <expr> )
  • ( exec <expr> )

The quote function takes a block of code and treats it like data, with an implied list keyword after every open parenthesis. The compile function compiles the output of the quote function, which is then executed by the exec function.


No white space allowed between tokens, for rest of Parythony Grammar:

<white space>:

  • <white token>...

<white token>:

  • <rest-comment>
  • <non-line-comment>

<rest-comment>:

  • <non-line-comment><line-comment>

<line-comment>:

  • # [<char>]... <new-line>

<non-line-comment>:

  • <white char>
  • <blk-comment>

<blk-comment>:

  • {* [<char>]... *}

<white char>:

  • <space> | <tab> | <new-line>

<name>:

  • [<underscore>]... <letter> [<alnum>]... [<hyphen-alnum>]... [<underscore>]...

<hyphen-alnum>:

  • <hyphen><alnum>...

<alnum>:

  • <letter>
  • <digit>

In plain English, names begin and end with zero or more underscores. In between is a letter followed by zero or more alphanumeric characters. Names may also contain hyphens, where each hyphen is preceded and succeeded by an alphanumeric character.

<num lit>:

  • <dec int>
  • <oct int>
  • <hex int>
  • <bin int>
  • <float>

<dec int>:

  • 0
  • [<hyphen>] <any digit except 0> [<digit>]...

<float>:

  • <dec int> <fraction> [<exponent>]
  • <dec int> <exponent>

<fraction>:

  • <dot> [<digit>]...

<exponent>:

  • <e> [<sign>] <digit>...

<e>:

  • e | E

<sign>:

  • + | -

<oct int>:

  • 0o <octal digit>...

<hex int>:

  • 0x <hex digit>...
  • 0X <hex digit>...

<bin int>:

  • 0b <zero or one>...
  • 0B <zero or one>...

<octal digit>:

  • 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7

<hex digit>:

  • <digit>
  • A | B | C | D | E | F
  • a | b | c | d | e | f

<keyword const>:

  • None
  • True
  • False

<colon list>:

  • : [ : ]...

<size funcs>:

  • ( long <expr> )
  • ( short <expr> )

<string lit>:

  • [<str prefix>] <short long>

<str prefix>:

  • r | u | R | U

<short long>:

  • ' [<short item>]... '
  • " [<short item>]... "
  • ''' [<long item>]... '''
  • """ [<long item>]... """

<short item>:

  • <short char>
  • <escaped str char>

<long item>:

  • <long char>
  • <escaped str char>

<short char>:

  • any source char. except "\", newline, or end quote

<long char>:

  • any source char. except "\"

<bytes lit>:

  • <byte prefix><shortb longb>

<byte prefix>:  any case/order

  • b | br

<shortb longb>:

  • ' [<shortb item>]... '
  • " [<shortb item>]... "
  • ''' [<longb item>]... '''
  • """ [<longb item>]... """

<shortb item>:

  • <shortb char>
  • <escaped char>

<longb item>:

  • <longb char>
  • <escaped char>

<shortb char>:

  • any ASCII char. except "\", newline, or end quote

<longb char>:

  • any ASCII char. except "\"

<escaped char>:

  • \newline  ignore backslash, newline chars.
  • \\  backslash
  • \"  double quote
  • \'  single quote
  • \a  bell
  • \b  backspace
  • \f  formfeed
  • \n  new line
  • \r  carriage return
  • \t  tab
  • \v  vertical tab
  • \ooo  octal value = ooo
  • \xhh  hex value = hh

<escaped str char>:

  • <escaped char>
  • \N{name}  Unicode char. = name
  • \uxxxx  hex value (16-bit) = xxxx
  • \Uxxxxxxxx  hex value (32-bit) = xxxxxxxx

Semicolon Grammar

The semicolon switch (the default) allows statements normally enclosed in parentheses to instead be terminated with semicolons, with no need for whitespace surrounding semicolons (similar to parentheses). What follows assumes the switch is off, and statements are enclosed in parentheses.

<source file>:

  • [<line-comment>] [<stmt>]... [<def>]... [<class>]... [<stmt>]...

<import stmt>:

  • ( import <module> )
  • ( import ( <module>... ))
  • ( from <rel module> import <mod list> )
  • ( from <rel module> import all )

<def>:

  • ( def <name> ( [<parm>]... ) do <stmt>... )

<block>:

  • ( <stmt>... )

<raise stmt>:

  • ( raise [<expr> [ from <expr>]] )

<return stmt>:

  • return
  • ( return <expr> )

<if stmt>:

  • ( if <expr><block> [ elif <expr><block>]... [ else <block>] )

<while stmt>:

  • ( while <expr> do <stmt> )
  • ( do <block> while <expr> )

<for stmt>:

  • ( for <name> in <expr> do <stmt> )

<try stmt>:

  • ( try <block> <except clause>... [ else <block>] [ finally <block>] )
  • ( try <block> finally <block> )

<call stmt>:

  • ( <name> [<expr>]... )
  • ( : <obj expr> [<colon expr>]... ( <method name> [<expr>]... ))
  • ( call <expr>... )

<asst stmt>:

  • ( <asst op><name><expr> )
  • ( <asst op><target expr><expr> )

<del stmt>:

  • ( del <expr> )

<print stmt>:

  • ( print [<expr>]... )
  • ( echo [<expr>]... )
[ Back to Top ]