Gramática — Instruções
11 produções: atribuição, saída, controle de fluxo e laços. Cada exemplo é aceito pelo parser.
Uma instrução faz algo e não produz valor. As que abrem bloco terminam em : e o corpo vem indentado.
| Produção | Nós que ela produz |
|---|---|
atribuicao | Assignment |
constante | SteadyDeclaration |
desestruturacao | DestructuringAssignment |
saida | OutStatement |
given | GivenBlock |
cycle | CycleFromTo, CycleIn |
persist | PersistBlock, PerformBlock |
halt_skip | HaltStatement, SkipStatement |
instrucoes_de_vault | DeleteStatement, InspectStatement |
guard | GuardStatement |
observe | ObserveBlock |
atribuicao#
text
atribuicao = alvo [ ":" tipo ] ":=" expressao
| alvo ( "+=" | "-=" | "*=" | "/=" | "%=" ) expressao ;dataforge
idade: Integer := 30
idade += 1constante#
text
constante = "steady" nome [ ":" tipo ] ":=" expressao ;dataforge
steady PI := 3.14159desestruturacao#
text
desestruturar = alvo_d { "," alvo_d } ":=" expressao ;
alvo_d = [ "..." ] nome ;dataforge
primeiro, ...resto := [1, 2, 3]saida#
text
saida = "out" expressao { "," expressao } ;dataforge
out "ola", 42given#
text
condicional = "given" expressao bloco { "orif" expressao bloco }
[ "otherwise" bloco ] ;dataforge
x := 5
given x bigger 5:
out 1
orif x is 5:
out 0
otherwise:
out -1cycle#
text
laco_faixa = "cycle" nome "from" expressao "to" expressao [ "step" expressao ] bloco ;
laco_itens = "cycle" nome "in" expressao bloco ;dataforge
cycle i from 1 to 5 step 2:
out i
cycle v in [1, 2]:
out vpersist#
text
enquanto = "persist" expressao bloco ;
repita = "perform" bloco "persist" expressao ;dataforge
n := 3
persist n bigger 0:
n -= 1
perform:
n += 1
persist n smaller 3halt_skip#
text
interromper = "halt" ;
continuar = "skip" ;dataforge
cycle i in [1, 2, 3]:
given i is 2:
skip
given i is 3:
haltinstrucoes_de_vault#
text
apagar = "delete" alvo_de_indice ;
inspecionar = "inspect" expressao ;dataforge
v := {"a": 1, "b": 2}
delete v["a"]
inspect vguard#
text
guarda = "guard" expressao "otherwise" bloco ;dataforge
action dividir(a, b):
guard b isnt 0 otherwise:
yield void
yield a / bobserve#
text
observar = "observe" nome "in" expressao bloco ;dataforge
observe x in [1, 2, 3]:
out xEstas produções saem de dataforge/gramatica.py. No terminal: dataforge gramatica instrucoes. Volte para a gramática.