make the parser report '&&' as an error instead of treating it as bitwise and followed by address-of.

This commit is contained in:
Irmen de Jong 2022-04-02 02:08:01 +02:00
parent 037b89f018
commit b133d51a83
3 changed files with 71 additions and 1 deletions

View File

@ -49,5 +49,17 @@ main {
}"""
compileText(C64Target(), false, text, writeAssembly = true) shouldNotBe null
}
test("invalid && operator") {
val text="""
main {
sub start() {
uword b1
uword b2
uword b3 = b1 && b2 ; invalid syntax: '&&' is not an operator, 'and' should be used instead
}
}"""
compileText(C64Target(), false, text, writeAssembly = false) shouldBe null
}
})

View File

@ -0,0 +1,57 @@
%import textio
%zeropage basicsafe
%option no_sysinit
main {
sub start() {
txt.print("ps2 scancode handler test - press keys! esc to quit!\n")
sys.set_irqd()
uword old_keyhdl = cx16.KEYHDL
cx16.KEYHDL = &main.keyboard_scancode_handler.asm_shim
sys.clear_irqd()
ubyte escape_pressed
while not escape_pressed {
; just sit here
}
sys.set_irqd()
cx16.KEYHDL = old_keyhdl
sys.clear_irqd()
}
sub keyboard_scancode_handler(ubyte prefix, ubyte scancode, ubyte updown) {
txt.print_ub(prefix)
txt.spc()
txt.print_ub(scancode)
txt.spc()
if updown
txt.chrout('u')
else
txt.chrout('d')
txt.nl()
if prefix==0 and scancode==119 and updown {
; escape was pressed! exit back to basic
main.start.escape_pressed = true
}
return
asm_shim:
%asm {{
php
pha
phx
sta scancode
stz updown
bcc +
inc updown
+ jsr keyboard_scancode_handler
plx
pla
plp
rts
}}
}
}

View File

@ -27,7 +27,8 @@ NAME : [a-zA-Z][a-zA-Z0-9_]* ;
DEC_INTEGER : ('0'..'9') | (('1'..'9')('0'..'9')+);
HEX_INTEGER : '$' (('a'..'f') | ('A'..'F') | ('0'..'9'))+ ;
BIN_INTEGER : '%' ('0' | '1')+ ;
ADDRESS_OF: '&';
ADDRESS_OF: '&' ;
INVALID_AND_COMPOSITE: '&&' ;
FLOAT_NUMBER : FNUMBER (('E'|'e') ('+' | '-')? FNUMBER)? ; // sign comes later from unary expression
fragment FNUMBER : ('0' .. '9') + ('.' ('0' .. '9') +)? ;