grammar(P0): add peek expression, continue statement, and field type annotations acceptance; add sample apps and interpreter path\n\n- tokenizer: add keywords (peek, continue), tokens (=> as FatArrow, :: as DoubleColon), keep >> as Arrow\n- parser: implement peek as expression (literal patterns only, else required), add continue; accept field 'name: Type' (discard type P0)\n- interpreter: evaluate PeekExpr; add Continue control flow handling\n- apps: add peek-demo, loop-continue-demo, adjust field-decl demo; use ConsoleBox instead of env.console for interpreter backend\n- docs: CURRENT_TASK updated earlier for Phase 12.7 P0\n\nNOTE: peek arms currently single-expression (no block expr yet); VM/MIR path does not lower PeekExpr yet; use --backend interpreter for demos
This commit is contained in:
18
apps/box-field-decl-demo/main.nyash
Normal file
18
apps/box-field-decl-demo/main.nyash
Normal file
@ -0,0 +1,18 @@
|
||||
// box field declaration demo (P0)
|
||||
box Counter {
|
||||
count: IntegerBox
|
||||
public { name }
|
||||
|
||||
birth(name) {
|
||||
me.name = name
|
||||
me.count = 0
|
||||
}
|
||||
|
||||
inc() { me.count = me.count + 1 }
|
||||
get() { return me.count }
|
||||
}
|
||||
|
||||
local c = new Counter("nyash")
|
||||
c.inc()
|
||||
local con = new ConsoleBox()
|
||||
con.println(c.get())
|
||||
14
apps/loop-continue-demo/main.nyash
Normal file
14
apps/loop-continue-demo/main.nyash
Normal file
@ -0,0 +1,14 @@
|
||||
// continue demo: sum of 1..5 skipping 3
|
||||
local i = 0
|
||||
local sum = 0
|
||||
|
||||
loop (i < 5) {
|
||||
i = i + 1
|
||||
if i == 3 {
|
||||
continue
|
||||
}
|
||||
sum = sum + i
|
||||
}
|
||||
|
||||
local con = new ConsoleBox()
|
||||
con.println("sum=" + sum)
|
||||
9
apps/peek-demo/main.nyash
Normal file
9
apps/peek-demo/main.nyash
Normal file
@ -0,0 +1,9 @@
|
||||
// peek expression demo (P0: arms are single expressions)
|
||||
local animal = "cat"
|
||||
local sound = peek animal {
|
||||
"dog" => "bark"
|
||||
"cat" => "meow"
|
||||
else => "silent"
|
||||
}
|
||||
local con = new ConsoleBox()
|
||||
con.println(sound)
|
||||
Reference in New Issue
Block a user