Skip to content

Instantly share code, notes, and snippets.

@prail
Last active March 11, 2018 02:58
Show Gist options
  • Save prail/cebd2eeb8bd5b46328d85f5d8d1d034b to your computer and use it in GitHub Desktop.
Save prail/cebd2eeb8bd5b46328d85f5d8d1d034b to your computer and use it in GitHub Desktop.
BNF (sortof) grammar for SmileBASIC.
FULLEXPRESSION -> [ EXPRESSION ]
EXPRESSION -> "(" EXPRESSION ")" || VALUE [ OPERATOPERATOR EXPRESSION ] || UNARYOP SMALLEXPRESSION
SMALLEXPRESSION -> "(" EXPRESSION ")" || VALUE || UNARYOPERATOR [ SMALLEXPRESSION ]
CONSTANTEXPRESSION -> CONSTANT || "(" CONSTANTEXPRESSION ")" || CONSTANT [ CONSTANTOPERATOR CONSTANTEXPRESSION ] || CONSTANTUNARYOPERATOR SMALLCONSTANTEXPRESSION || STRING
SMALLCONSTANTEXPRESSION -> "(" CONSTANTEXPRESSION ")" || CONSTANT || CONSTANTUNARYOPERATOR [ SMALLCONSTANTEXPRESSION ]
CONSTANT -> NUMBER || "PI" "(" ")" || "#RED" etc.
UNARYOPERATOR -> "-" || "NOT" || "!"
OPERATOR -> "+" || "-" || etc.
VALUE -> CONSTANT || STRING || VARIABLE || PARENFUNCTIONCALL || SYSVAR
STRING -> "\"" [ CHAR ]* ( "\"" || NEWLINE ) || LABEL
NUMBER ->
PARENFUNCTIONCALL -> VARIABLENAME "(" FULLEXPRESSIONLIST ")"
FULLLINE -> [ NEWLINE ] INLINE ( NEWLINE || ":" )
LINE -> INLINE [ ":" ]
INLINE -> DEFBLOCK || FORBLOCK || WHILEBLOCK || REPEATBLOCK || FUNCTIONCALL || IFBLOCK || LABEL
DEFBLOCK -> "DEF" VARIABLENAME [ DEFARGS ] [ "OUT" DEFARGS ] FULLLINE* "END"
FORBLOCK -> "FOR" VARIABLE "=" FULLEXPRESSION "TO" FULLEXPRESSION [ STEP FULLEXPRESSION ] FULLLINE* "NEXT"
WHILEBLOCK -> "WHILE" EXPRESSION FULLLINE* "WEND"
REPEATBLOCK -> "REPEAT" FULLLINE* "UNTIL" EXPRESSION
FUNCTIONCALL -> VARIABLENAME FULLEXPRESSIONLIST [ "OUT" ] [ [ VARIABLE ] [ "," [ VARIABLE ] ]* ]
IFBLOCK -> "IF" EXPRESSION "THEN" NEWLINE FULLLINE* [ "ELSEIF" EXPRESSION "THEN" FULLLINE* ]* [ "ELSE" FULLLINE* ] "ENDIF"
LINEIFBLOCK -> aaaaaaa
VAR -> ( "VAR" || "DIM" ) VARIABLENAME "[" EXPRESSIONLIST "]"
DATA -> "DATA" CONSTANTEXPRESSIONLIST
CONSTANTEXPRESSIONLIST -> CONSTANTEXPRESSION [ "," CONSTANTEXPRESSION ]*
FULLEXPRESSIONLIST -> [ FULLEXPRESSION [ "," FULLEXPRESSION ]* ]
EXPRESSIONLIST -> EXPRESSION [ "," EXPRESSION ]*
LABEL -> "@" [ (A-Z0-9_) ]+
VARIABLE -> "(" VARIABLE ")" || VARIABLE "[" EXPRESSION "]" || VARIABLENAME
VARIABLENAME -> (A-Z_) [ (A-Z0-9_) ]* ($#%)
DEFARGS -> VARIABLENAME [ "[" "]" ] "," [ VARIABLENAME [ "[" "]" ] ]*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment