Skip to content

Instantly share code, notes, and snippets.

@shouichi
Created February 22, 2012 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shouichi/1883963 to your computer and use it in GitHub Desktop.
Save shouichi/1883963 to your computer and use it in GitHub Desktop.
case # Empty!
when cond1
do_something
when cond2
do_another_thing
end
for i in 1..4 when i % 2 == 0
j in 5..8 when j % 4 == 0
puts "#{i}, #{j}"
end
for i in 1..4
if i % 2 == 0
for j in 5..8
if j % 4 == 0
puts "#{i}, #{j}"
end
end
end
end
i = 0
[1,2,3].each do |i|
end
p i #=> 0
for i in [1,2,3]
end
p i #=> 3
primary : k_for
loops
k_end
{
$$ = $2;
}
loops : for_var keyword_in expr_value
keyword_when expr_value term
compstmt
{
scope = NEW_NODE(NODE_SCOPE,
table, NEW_IF(cond($5), $7, 0), args);
$$ = NEW_FOR(0, $3, scope);
}
| for_var keyword_in expr_value
keyword_when expr_value term
loops
{
// 上と同じ。
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment