tweak identifier parse rule

This commit is contained in:
Irmen de Jong 2019-01-02 23:32:41 +01:00
parent 299d1bdab8
commit e033cff09a
6 changed files with 673 additions and 717 deletions

View File

@ -85,7 +85,7 @@ statement :
labeldef : identifier ':' ;
unconditionaljump : 'goto' (integerliteral | identifier | scoped_identifier) ;
unconditionaljump : 'goto' (integerliteral | scoped_identifier) ;
directive :
directivename=('%output' | '%launcher' | '%zeropage' | '%zpreserved' | '%address' | '%import' |
@ -117,7 +117,6 @@ augassignment :
assign_target:
register
| identifier
| scoped_identifier
| arrayindexed
| directmemory
@ -143,7 +142,6 @@ expression :
| prefix = 'not' expression
| literalvalue
| register
| identifier
| scoped_identifier
| arrayindexed
| directmemory
@ -155,22 +153,15 @@ expression :
typecast : 'as' datatype;
arrayindexed :
(identifier | scoped_identifier ) arrayspec
;
arrayindexed : scoped_identifier arrayspec ;
directmemory : '@' '(' expression ')';
functioncall :
(identifier | scoped_identifier) '(' expression_list? ')'
;
functioncall : scoped_identifier '(' expression_list? ')' ;
functioncall_stmt :
(identifier | scoped_identifier) '(' expression_list? ')'
;
functioncall_stmt : scoped_identifier '(' expression_list? ')' ;
expression_list :
expression (',' EOL? expression)* // you can split the expression list over several lines
@ -184,7 +175,7 @@ continuestmt: 'continue';
identifier : NAME ;
scoped_identifier : NAME ('.' NAME)+ ;
scoped_identifier : NAME ('.' NAME)* ;
register : 'A' | 'X' | 'Y' ;

View File

@ -40,7 +40,7 @@
c64.STROUT("balloon sprites!\n")
c64.STROUT("...we are all floating...\n")
const uword sprite_address_ptr = $0a00 // 64 ; @todo " &balloonsprite // 64"
const uword sprite_address_ptr = &balloonsprite // 64
c64.SPRPTR0 = sprite_address_ptr
c64.SPRPTR1 = sprite_address_ptr
c64.SPRPTR2 = sprite_address_ptr

View File

@ -1,21 +1,79 @@
%import c64utils
%option enable_floats
~ spritedata $0a00 {
; this memory block contains the sprite data
; it must start on an address aligned to 64 bytes.
%option force_output ; make sure the data in this block appears in the resulting program
ubyte[63] balloonsprite = [ %00000000,%01111111,%00000000,
%00000001,%11111111,%11000000,
%00000011,%11111111,%11100000,
%00000011,%11100011,%11100000,
%00000111,%11011100,%11110000,
%00000111,%11011101,%11110000,
%00000111,%11011100,%11110000,
%00000011,%11100011,%11100000,
%00000011,%11111111,%11100000,
%00000011,%11111111,%11100000,
%00000010,%11111111,%10100000,
%00000001,%01111111,%01000000,
%00000001,%00111110,%01000000,
%00000000,%10011100,%10000000,
%00000000,%10011100,%10000000,
%00000000,%01001001,%00000000,
%00000000,%01001001,%00000000,
%00000000,%00111110,%00000000,
%00000000,%00111110,%00000000,
%00000000,%00111110,%00000000,
%00000000,%00011100,%00000000 ]
}
~ main {
sub start() {
const uword SP0X = $d000
const uword SP0Y = $d001
for ubyte j in 0 to 7 step 2 { ; @todo wrong bytecode generated!!
vm_write_num(j)
vm_write_char('\n')
;c64scr.print_ub(j)
;c64.CHROUT('\n')
sub start() {
c64.STROUT("balloon sprites!\n")
c64.STROUT("...we are all floating...\n")
const uword sprite_address_ptr = $0a00 // 64
c64.SPRPTR0 = sprite_address_ptr
c64.SPRPTR1 = sprite_address_ptr
c64.SPRPTR2 = sprite_address_ptr
c64.SPRPTR3 = sprite_address_ptr
c64.SPRPTR4 = sprite_address_ptr
c64.SPRPTR5 = sprite_address_ptr
c64.SPRPTR6 = sprite_address_ptr
c64.SPRPTR7 = sprite_address_ptr
for ubyte i in 0 to 7 {
@(SP0X+i*2) = 50+25*i
@(SP0Y+i*2) = rnd()
}
for ubyte j in 10 to 3 step -2 { ; @todo wrong bytecode generated!!
vm_write_num(j)
vm_write_char('\n')
;c64scr.print_ub(j)
;c64.CHROUT('\n')
}
c64.SPENA = 255 ; enable all sprites
c64utils.set_rasterirq(51) ; enable animation
}
}
~ irq {
sub irq() {
c64.EXTCOL--
; float up & wobble horizontally
for ubyte i in 0 to 14 step 2 {
@(main.SP0Y+i)--
ubyte r = rnd()
if r>200
@(main.SP0X+i)++
else if r<40
@(main.SP0X+i)--
}
c64.EXTCOL++
}
}

View File

@ -1946,24 +1946,20 @@ private fun prog8Parser.StatusregisterContext.toAst() = Statusflag.valueOf(text)
private fun prog8Parser.Functioncall_stmtContext.toAst(): IStatement {
val location =
if(identifier()!=null) identifier()?.toAst()
else scoped_identifier()?.toAst()
return if(expression_list() ==null)
FunctionCallStatement(location!!, mutableListOf(), toPosition())
val location = scoped_identifier().toAst()
return if(expression_list() == null)
FunctionCallStatement(location, mutableListOf(), toPosition())
else
FunctionCallStatement(location!!, expression_list().toAst().toMutableList(), toPosition())
FunctionCallStatement(location, expression_list().toAst().toMutableList(), toPosition())
}
private fun prog8Parser.FunctioncallContext.toAst(): FunctionCall {
val location =
if(identifier()!=null) identifier()?.toAst()
else scoped_identifier()?.toAst()
return if(expression_list() ==null)
FunctionCall(location!!, mutableListOf(), toPosition())
val location = scoped_identifier().toAst()
return if(expression_list() == null)
FunctionCall(location, mutableListOf(), toPosition())
else
FunctionCall(location!!, expression_list().toAst().toMutableList(), toPosition())
FunctionCall(location, expression_list().toAst().toMutableList(), toPosition())
}
@ -1978,7 +1974,7 @@ private fun prog8Parser.ReturnstmtContext.toAst() : Return {
private fun prog8Parser.UnconditionaljumpContext.toAst(): Jump {
val address = integerliteral()?.toAst()?.number?.toInt()
val identifier = identifier()?.toAst() ?: scoped_identifier()?.toAst()
val identifier = scoped_identifier().toAst()
return Jump(address, identifier, null, toPosition())
}
@ -2014,7 +2010,7 @@ private fun prog8Parser.Sub_paramsContext.toAst(): List<SubroutineParameter> =
private fun prog8Parser.Assign_targetContext.toAst() : AssignTarget {
val register = register()?.toAst()
val identifier = identifier()
val identifier = scoped_identifier()
return when {
register!=null -> AssignTarget(register, null, null, null, toPosition())
identifier!=null -> AssignTarget(null, identifier.toAst(), null, null, toPosition())
@ -2119,9 +2115,6 @@ private fun prog8Parser.ExpressionContext.toAst() : IExpression {
if(register()!=null)
return RegisterExpr(register().toAst(), register().toPosition())
if(identifier()!=null)
return identifier().toAst()
if(scoped_identifier()!=null)
return scoped_identifier().toAst()
@ -2156,7 +2149,7 @@ private fun prog8Parser.ExpressionContext.toAst() : IExpression {
private fun prog8Parser.ArrayindexedContext.toAst(): ArrayIndexedExpression {
return ArrayIndexedExpression(identifier()?.toAst() ?: scoped_identifier()?.toAst(),
return ArrayIndexedExpression(scoped_identifier().toAst(),
arrayspec().toAst(),
toPosition())
}

View File

@ -1,4 +1,4 @@
// Generated from ../antlr/prog8.g4 by ANTLR 4.7.2
// Generated from /home/irmen/Projects/prog8/compiler/antlr/prog8.g4 by ANTLR 4.7.2
package prog8.parser;
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.CharStream;

File diff suppressed because it is too large Load Diff