diff --git a/src/sixtypical/parser.py b/src/sixtypical/parser.py index 07f6f1c..9bae211 100644 --- a/src/sixtypical/parser.py +++ b/src/sixtypical/parser.py @@ -380,6 +380,8 @@ class Parser(object): self.scanner.expect('{') while not self.scanner.on('}'): instrs.append(self.instr()) + if isinstance(instrs[-1], SingleOp) and instrs[-1].opcode == 'goto': + break self.scanner.expect('}') return Block(self.scanner.line_number, instrs=instrs) diff --git a/tests/SixtyPical Analysis.md b/tests/SixtyPical Analysis.md index b393e07..d190cc8 100644 --- a/tests/SixtyPical Analysis.md +++ b/tests/SixtyPical Analysis.md @@ -2990,7 +2990,11 @@ Calling the vector does indeed trash the things the vector says it does. | } | | define main routine trashes x, z, n { - | goto bar + | ld x, 0 + | if z { + | ld x, 1 + | goto bar + | } | ld x, 0 | } ? IllegalJumpError diff --git a/tests/SixtyPical Syntax.md b/tests/SixtyPical Syntax.md index 3409e63..dc59a0f 100644 --- a/tests/SixtyPical Syntax.md +++ b/tests/SixtyPical Syntax.md @@ -571,6 +571,18 @@ goto. | } ? SyntaxError +`goto` may only be the final instruction in a block. + + | define bar routine trashes x, z, n { + | ld x, 200 + | } + | + | define main routine trashes x, z, n { + | goto bar + | ld x, 0 + | } + ? Expected '}', but found 'ld' + Buffers and pointers. | buffer[2048] buf