စံကား

01The language

Statements

Each form of statement in Zaka - declaration, assignment, printing, branches, loops, blocks, calls, returns and heap statements - with its grammar and its errors.

A program is a list of statements, run from the first to the last. Each statement is a Burmese sentence that ends with ။, and the verb at the end of the sentence decides what the statement does. A statement does something and has no value; an expression has a value and sits inside a statement.

The forms at a glance

In the shapes below, NAME is a name, KIND a kind, VALUE and COND expressions, PLACE something that can be assigned to (a name, or a cell or a pointer's value), and BODY a block or one statement. Square brackets mark what can be left out.

StatementShape
declareကိန်းရှင် NAME သည် KIND [ဖြစ်၍ တန်ဖိုးသည်] [VALUE] ဖြစ်ပါစေ။
constantကိန်းသေ NAME သည် KIND [ဖြစ်၍ တန်ဖိုးသည်] VALUE ဖြစ်ပါစေ။
assignPLACE ကို VALUE ဟု ထားပါ။
printVALUE ကို ပြသပါ။ or VALUE ဟု ပြသပါ။
blockအောက်ပါတို့ကို လုပ်ဆောင်ပါ။ statements လုပ်ဆောင်စရာများ ပြီးပါပြီး။
ifအကယ်၍ COND လျှင် BODY then [ထိုသို့မဟုတ်ဘဲ COND လျှင် BODY] then [သို့မဟုတ်ပါက BODY]
whileCOND နေသရွေ့ BODY
counted loopFROM မှ TO အထိ [STEP စီ] NAME အနေဖြင့် ရေတွက်၍ BODY
generic loopကိန်းရှင် NAME သည် KIND [VALUE] ဖြစ်ကာ COND နေသရွေ့ block with [ပြီးလျှင် STATEMENT] last
breakကွင်းဆက် ကို ရပ်ပါ။
continueနောက်တစ်ကြိမ်ဆီသို့ ကျော်ပါ။
callလုပ်ဆောင်ချက် NAME ကို [ARGS တို့ဖြင့်] လုပ်ဆောင်ပါ။
returnVALUE ကို ရလဒ်အဖြစ် ပြန်ပေးပါ။ or ပြန်ပေးပါ။
functionလုပ်ဆောင်ချက် NAME သည် ... (see Functions)
heapမင်မိုရီ SIZE နေရာယူ၍ လိပ်စာကို PLACE တွင် သိမ်းထားမည်။ and two more (below)

Some words have alternatives: လျှင် or ဖြစ်လျှင်; နေသရွေ့ or ဖြစ်နေသရွေ့; ဖြစ်ကာ or ဖြစ်ပြီး; ရေတွက်၍, တိုး၍ or လျှော့၍; the four spellings of the block closer (ပြီးပါပြီ, ပြီးပါပြီး, ပြီးဆုံးပါပြီ, ပြီးဆုံးပါပြီး).

The verb ends the sentence

A statement either starts with a reserved word (ကိန်းရှင်, အကယ်၍, ကွင်းဆက်, ...) or starts with an expression. A statement that starts with an expression must end in one of these verbs:

VerbStatementParticles on the operands
ပြသပါprintthe value takes ကို or ဟု
ထားပါassignthe place takes ကို, the value takes ဟု
ရလဒ်အဖြစ် ပြန်ပေးပါreturn a valuethe value takes ကို
နေသရွေ့while loopnone: it follows the condition
မှ ... အထိ ... အနေဖြင့်counted loopမှ after the first bound, အထိ after the second

A sentence that ends in another word is ZK0203, with a help line that lists the verbs. A verb that finds a missing or wrong particle on an operand is ZK0206, and one that finds too few operands is ZK0205. Operands left over before the verb are ZK0209. A missing ။ is ZK0201.

စံကားZK0203ZK0206

Expected error

error[ZK0203]: this statement does not end in a statement verb, found "။"
help: a statement ends in "ပြသပါ", "ထားပါ" or "ရလဒ်အဖြစ် ပြန်ပေးပါ", or is a loop with "နေသရွေ့" or "မှ ... အထိ"
error[ZK0206]: "ပြသပါ" needs "ကို|ဟု" after operand 1, found no particle

The example shows how the compiler recovers: after an error in a statement it skips to the next ။ and reads on, so one run reports the mistakes of several statements. A missing ။ joins the statement with the next one in the report. A program with a reading error is not checked for names and kinds, and does not run.

Declarations

ကိန်းရှင် declares a variable, ကိန်းသေ a constant. The kind comes first. The value can follow the kind at once, or after ဖြစ်၍ တန်ဖိုးသည် ("is, and its value is"), which keeps the kind and the value apart. A variable without a value starts at the default of its kind; a constant needs a value (ZK0308) and can never be assigned to (ZK0306). The value is checked first, so it cannot use the name that the statement declares (ZK0301), and it must fit the kind (ZK0401).

စံကား

Expected output

၁၉
၂၀
၀
၁၀၀
စံကားZK0306

Expected error

 

Assignment

PLACE ကို VALUE ဟု ထားပါ။ puts the value into the place. The value is worked out first with the current contents, then stored, so အသက် ကို အသက် + ၁ ဟု ထားပါ။ adds one. The place is a variable, a cell of a list (x ၏ အကွက် i) or the value at a pointer (p ၏ တန်ဖိုး). Another expression is ZK0410. A constant (ZK0306) and a counted-loop counter (ZK0307) cannot be assigned to. The value must widen to the kind of the place (Conversions).

Printing

ပြသပါ prints its operand and then a line break. A number prints in Burmese digits, a true/false value as မှန် or မမှန်, a character as itself, and a list as its cells between [ and ]. A string literal can be printed and nothing else (ZK0223).

The operand takes ကို when it is a plain value, and ဟု when it is a string or a whole sentence (a clause that ends in a verb with a polite ending). The other choice still runs and gets a warning, ZK0505 or ZK0506; Natural wording has the rules. A logical expression needs parentheses (ZK0204).

စံကား

Expected output

၄၂
မင်္ဂလာပါ
မှန်
က
[၁၊ ၂၊ ၃]

Blocks

A block is a run of statements between အောက်ပါတို့ကို လုပ်ဆောင်ပါ။ and လုပ်ဆောင်စရာများ ပြီးပါပြီး။. Names declared inside it end at the closer (Names and scope). A closer with no opener is ZK0226.

Wherever the shape of a statement has BODY, a block or one single statement can stand. A single statement is a short form of a block of one: အကယ်၍ ... လျှင် ၁ ကို ပြသပါ။. A one-statement BODY cannot itself be an if (ZK0215), since it would be unclear which if an otherwise belongs to. Put the inner if in a block.

If

အကယ်၍ tests the condition, which must be a true/false value (ZK0402). The first branch whose condition holds runs, and the rest are skipped. သို့မဟုတ်ပါက ("otherwise") takes no condition and runs when no other branch did. လျှင် is written attached to the last word of the condition (ငယ်လျှင်); after a name or a whole sentence, write ဖြစ်လျှင် as a word of its own. An ထိုသို့မဟုတ်ဘဲ or သို့မဟုတ်ပါက with no if before it is ZK0211.

စံကား

Expected output

ခ
ကောင်းပါသည်
စံကားZK0215

Expected error

 

Loops

All loops test or count before the first round, so a loop can run zero times.

While. COND နေသရွေ့ BODY works out the condition before each round and runs the BODY while it is true.

Counted loop. FROM မှ TO အထိ [STEP စီ] NAME အနေဖြင့် ရေတွက်၍ BODY declares a counter NAME that lives in the loop. The bounds and the step are worked out once, before the first round, and must be integers (ZK0405). Both bounds are included. The counter has the common kind of the two bounds, and the step must widen to it; a literal bound takes the kind of the other bound. The step must be positive, a literal zero or less being ZK0409 and a zero at run time stopping the program. The three verbs differ in the direction:

VerbDirection
ရေတွက်၍toward TO: up when FROM <= TO, down otherwise
တိုး၍up in each case; zero rounds when FROM is past TO
လျှော့၍down in each case; zero rounds when FROM is below TO

The inner part can read the counter but not assign to it (ZK0307). The counter and the names declared in the inner part share one scope, so the inner part cannot declare a name equal to the counter's (ZK0302).

Generic loop. ကိန်းရှင် NAME သည် KIND [VALUE] ဖြစ်ကာ COND နေသရွေ့ opens a block. The declaration runs once; then, while the condition holds, the block runs and then the update. The update is the last statement of the block, opened with ပြီးလျှင် ("when done"); it also runs after နောက်တစ်ကြိမ်ဆီသို့ ကျော်ပါ. An update that is not last is ZK0213, and a ပြီးလျှင် outside a generic loop is ZK0212. The loop takes a block alone, and its variable is declared with ကိန်းရှင်, never ကိန်းသေ (ZK0225). The variable is gone after the closer.

စံကား

Expected output

၁
၂
၃
---
၁၀
၅
၀
---
ပြီး

The first loop shows that the bound is worked out once: changing ဆုံး in the inner part does not lengthen the loop.

စံကား

Expected output

၀
၂
၄
၆
၁၂၈

Break and continue

ကွင်းဆက် ကို ရပ်ပါ။ leaves the innermost loop. နောက်တစ်ကြိမ်ဆီသို့ ကျော်ပါ။ skips the rest of the round of the innermost loop and goes to the next round; in a generic loop the update runs first. Outside a loop these are ZK0309 and ZK0310.

Calls and returns

လုပ်ဆောင်ချက် f ကို ၁၊ ၂ တို့ဖြင့် လုပ်ဆောင်ပါ။ runs a function and drops its result. VALUE ကို ရလဒ်အဖြစ် ပြန်ပေးပါ။ ends a function with a value, and ပြန်ပေးပါ။ ends it with none. A return outside a function is ZK0311. Functions has the rest.

Heap statements

Three statements ask for room on the heap, change it and give it back. Each works on a pointer, which names the block. Pointers and Ownership and borrowing cover them; the shapes are:

StatementShape
allocateမင်မိုရီ KIND N ခုစာ နေရာယူ၍ လိပ်စာကို PLACE တွင် သိမ်းထားမည်။
resizePLACE လိပ်စာရှိကို မင်မိုရီ KIND N ခုစာ ဖြစ်အောင် နေရာအချဲ့အချုံ့လုပ်မည်။
give backPLACE လိပ်စာရှိ မင်မိုရီကို ပြန်လည်စွန့်လွှတ်မည်။

The size can also be N ဘိုက်စာ, a count of octets. မင်မိုရီ and မှတ်ဉာဏ် mean the same, and ...မည် can be ...မယ်.

စံကား

Expected output

၄၂
ဗလာ

Errors of statements

CodeRaised when
ZK0201a token is not the one expected, often a missing ။
ZK0203a sentence ends in no statement verb
ZK0205, ZK0206, ZK0209a verb has too few operands, a wrong particle, or a surplus
ZK0211, ZK0212, ZK0213, ZK0215, ZK0226a branch, update, single-statement block or closer in the wrong place
ZK0302, ZK0306, ZK0307, ZK0308a name declared twice, a constant or counter assigned to, a constant with no value
ZK0309, ZK0310, ZK0311break, continue or return outside its home
ZK0402, ZK0405, ZK0409a condition that is no true/false value, a bound that is no integer, a step of zero or below
စံကားZK0307

Expected error

 
စံကားZK0402

Expected error

 
စံကားZK0309

Expected error

 
စံကား

Expected output

အစ
the program stopped: counted loop step is not positive