allow labels also in blocks instead of only in subroutines

This commit is contained in:
Irmen de Jong 2021-04-18 23:03:18 +02:00
parent c70bbdab26
commit a086d6e009
4 changed files with 8 additions and 3 deletions

View File

@ -45,7 +45,8 @@ private fun prog8Parser.BlockContext.toAst(isInLibrary: Boolean, encoding: IStri
it.subroutinedeclaration()!=null -> it.subroutinedeclaration().toAst(encoding) it.subroutinedeclaration()!=null -> it.subroutinedeclaration().toAst(encoding)
it.directive()!=null -> it.directive().toAst() it.directive()!=null -> it.directive().toAst()
it.inlineasm()!=null -> it.inlineasm().toAst() it.inlineasm()!=null -> it.inlineasm().toAst()
else -> throw FatalAstException("weird block statement $it") it.labeldef()!=null -> it.labeldef().toAst()
else -> throw FatalAstException("weird block node $it")
} }
} }
return Block(identifier().text, integerliteral()?.toAst()?.number?.toInt(), blockstatements.toMutableList(), isInLibrary, toPosition()) return Block(identifier().text, integerliteral()?.toAst()?.number?.toInt(), blockstatements.toMutableList(), isInLibrary, toPosition())

View File

@ -2,8 +2,6 @@
TODO TODO
==== ====
- allow labels in blocks instead of only in subroutines?
- hoist all variable declarations up to the subroutine scope *before* even the constant folding takes place (to avoid undefined symbol errors when referring to a variable from another nested scope in the subroutine) - hoist all variable declarations up to the subroutine scope *before* even the constant folding takes place (to avoid undefined symbol errors when referring to a variable from another nested scope in the subroutine)
- c64: make the graphics.BITMAP_ADDRESS configurable (VIC banking) - c64: make the graphics.BITMAP_ADDRESS configurable (VIC banking)
- get rid of all other TODO's in the code ;-) - get rid of all other TODO's in the code ;-)

View File

@ -3,7 +3,12 @@
%import test_stack %import test_stack
main { main {
blocklabel:
sub start() { sub start() {
label1:
ubyte xx=99 ubyte xx=99
if 0==xx { if 0==xx {
txt.print("fout") txt.print("fout")

View File

@ -80,6 +80,7 @@ block_statement:
| variabledeclaration | variabledeclaration
| subroutinedeclaration | subroutinedeclaration
| inlineasm | inlineasm
| labeldef
; ;