Skip to content

PICO 8 language

Sam Hocevar edited this page Jun 7, 2020 · 1 revision

Syntax

PICO-8 uses Lua 5.2, however through various feature extensions its syntax has become closer to Lua 5.3, so the following syntax is adapted from the official Lua 5.3 manual, is as follows:

chunk ::= block

block ::= {stat} [retstat]

stat ::= β€˜;’ |
         varlist β€˜=’ explist |
         var compop exp |
         functioncall |
         β€˜?’ [explist] |
         label |
         β€˜break’ |
         β€˜goto’ Name |
         β€˜do’ block β€˜end’ |
         β€˜while’ exp β€˜do’ block β€˜end’ |
         β€˜while’ β€˜(’ exp β€˜)’ block |
         β€˜repeat’ block β€˜until’ exp |
         β€˜if’ exp β€˜then’ block {’elseif’ exp β€˜then’ block} [β€˜else’ block] β€˜end’ |
         β€˜if’ β€˜(’ exp β€˜)’ block [β€˜else’ block] |
         β€˜for’ Name β€˜=’ exp β€˜,’ exp [β€˜,’ exp] β€˜do’ block β€˜end’ |
         β€˜for’ namelist β€˜in’ explist β€˜do’ block β€˜end’ |
         β€˜function’ funcname funcbody |
         β€˜local’ β€˜function’ Name funcbody |
         β€˜local’ namelist [β€˜=’ explist]

retstat ::= β€˜return’ [explist] [β€˜;’]

label ::= β€˜::’ Name β€˜::’

funcname ::= Name {β€˜.’ Name} [β€˜:’ Name]

varlist ::= var {β€˜,’ var}

var ::= Name | prefixexp β€˜[’ exp β€˜]’ | prefixexp β€˜.’ Name

namelist ::= Name {β€˜,’ Name}

explist ::= exp {β€˜,’ exp}

exp ::= β€˜nil’ | β€˜false’ | β€˜true’ | Numeral | LiteralString | β€˜...’ | functiondef |
        prefixexp | tableconstructor | exp binop exp | unop exp

prefixexp ::= var | functioncall | β€˜(’ exp β€˜)’

functioncall ::= prefixexp args | prefixexp β€˜:’ Name args

args ::= β€˜(’ [explist] β€˜)’ | tableconstructor | LiteralString

functiondef ::= β€˜function’ funcbody

funcbody ::= β€˜(’ [parlist] β€˜)’ block β€˜end’

parlist ::= namelist [β€˜,’ β€˜...’] | β€˜...’

tableconstructor ::= β€˜{’ [fieldlist] β€˜}’

fieldlist ::= field {fieldsep field} [fieldsep]

field ::= β€˜[’ exp β€˜]’ β€˜=’ exp | Name β€˜=’ exp | exp

fieldsep ::= β€˜,’ | β€˜;’

binop ::= β€˜+’ | β€˜-’ | β€˜*’ | β€˜/’ | β€˜^’ | β€˜%’ | β€˜\’ | β€˜^^’ |
          β€˜&’ | β€˜|’ | β€˜>>’ | β€˜>>>’ | β€˜<<’ | β€˜>><’ | β€˜<<>’ | β€˜..’ |
          β€˜<’ | β€˜<=’ | β€˜>’ | β€˜>=’ | β€˜==’ | β€˜~=’ | β€˜and’ | β€˜or’

compop ::= β€˜+=’ | β€˜-=’ | β€˜*=’ | β€˜/=’ | β€˜^=’ | β€˜%=’ | β€˜\=’ | β€˜^^=’ |
           β€˜&=’ | β€˜|=’ | β€˜>>=’ | β€˜>>>=’ | β€˜<<=’ | β€˜>><=’ | β€˜<<>=’ | β€˜..=’ |

unop ::= β€˜-’ | β€˜not’ | β€˜#’ | β€˜~’ | β€˜@’ | β€˜%” | β€˜$’
Clone this wiki locally