Commit 9bc7b08a authored by Robert Griesemer's avatar Robert Griesemer

- changed literal syntax to use the convert notation

- fixed issued with function declarations/function literals
- added more tests and fixed existing tests

SVN=118167
parent 7fbe486b
...@@ -7,7 +7,8 @@ ...@@ -7,7 +7,8 @@
package main package main
func main() { func main() {
[ ' ', []int(
' ',
'a', 'a',
'ä', 'ä',
'本', '本',
...@@ -30,5 +31,5 @@ func main() { ...@@ -30,5 +31,5 @@ func main() {
'\ubabe', '\ubabe',
'\U0123ABCD', '\U0123ABCD',
'\Ucafebabe' '\Ucafebabe'
] );
} }
...@@ -7,7 +7,8 @@ ...@@ -7,7 +7,8 @@
package main package main
func main() { func main() {
[ 0., []float(
0.,
+10., +10.,
-210., -210.,
...@@ -66,5 +67,5 @@ func main() { ...@@ -66,5 +67,5 @@ func main() {
0.0E123, 0.0E123,
+10.01e234, +10.01e234,
-210.012e345 -210.012e345
] );
} }
...@@ -7,7 +7,8 @@ ...@@ -7,7 +7,8 @@
package main package main
func main() { func main() {
[ 0, []int(
0,
123, 123,
0123, 0123,
0000, 0000,
...@@ -15,5 +16,5 @@ func main() { ...@@ -15,5 +16,5 @@ func main() {
0x123, 0x123,
0X0, 0X0,
0X123 0X123
]; );
} }
...@@ -7,7 +7,8 @@ ...@@ -7,7 +7,8 @@
package main package main
func main() { func main() {
[ "", []string(
"",
" ", " ",
"'`", "'`",
"a", "a",
...@@ -25,5 +26,5 @@ func main() { ...@@ -25,5 +26,5 @@ func main() {
`\a\b\f\n\r\t\v\\\'\"`, `\a\b\f\n\r\t\v\\\'\"`,
`\000\123\x00\xca\xFE\u0123\ubabe\U0123ABCD\Ucafebabe`, `\000\123\x00\xca\xFE\u0123\ubabe\U0123ABCD\Ucafebabe`,
`\x\u\U\` `\x\u\U\`
] );
} }
...@@ -67,7 +67,8 @@ func control_structs() { ...@@ -67,7 +67,8 @@ func control_structs() {
var x float var x float
} }
foo: // a label foo: // a label
switch { var j int;
switch y := 0; true {
case i < y: case i < y:
fallthrough; fallthrough;
case i < j: case i < j:
......
// $G $F.go && $L $F.$A && ./$A.out
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
// brainfuck
func main() {
var a [30000]byte;
prog := "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.";
p := 0;
pc := 0;
for {
switch prog[pc] {
case '>':
p++;
case '<':
p--;
case '+':
a[p]++;
case '-':
a[p]--;
case '.':
print string(a[p]);
case '[':
if a[p] == 0 {
for nest := 1; nest > 0; pc++ {
if prog[pc+1] == ']' {
nest--;
}
if prog[pc+1] == '[' {
nest++;
}
}
}
case ']':
if a[p] != 0 {
for nest := -1; nest < 0; pc-- {
if prog[pc-1] == ']' {
nest--;
}
if prog[pc-1] == '[' {
nest++;
}
}
}
default:
return;
}
pc++;
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment