From 20cdcc673b8fa0200729d02796ebbf1643ffdd77 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sat, 22 Aug 2020 17:03:40 +0200 Subject: [PATCH] identifiers can no longer start with an underscore. (this interfered with 64tass syntax) --- docs/source/syntaxreference.rst | 4 +- examples/test.p8 | 65 +++++++++++---------------------- parser/antlr/prog8.g4 | 2 +- 3 files changed, 25 insertions(+), 46 deletions(-) diff --git a/docs/source/syntaxreference.rst b/docs/source/syntaxreference.rst index 4fd436983..ca74d66c7 100644 --- a/docs/source/syntaxreference.rst +++ b/docs/source/syntaxreference.rst @@ -157,7 +157,7 @@ Directives Identifiers ----------- -Naming things in Prog8 is done via valid *identifiers*. They start with a letter or underscore, +Naming things in Prog8 is done via valid *identifiers*. They start with a letter, and after that, a combination of letters, numbers, or underscores. Examples of valid identifiers:: a @@ -165,7 +165,7 @@ and after that, a combination of letters, numbers, or underscores. Examples of v monkey COUNTER Better_Name_2 - _something_strange_ + something_strange__ Code blocks diff --git a/examples/test.p8 b/examples/test.p8 index 882232c77..bf0f83060 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -5,54 +5,33 @@ main { - ; todo make it possible to use cpu opcodes as varnames such as 'nop' + ; todo make it possible to use cpu opcodes as varnames such as 'nop' by prefixing all asm vars with something such as '_' sub start() { - byte ub - word uw - ubyte x = 1 - ubyte z = 0 + byte nop2 - ubyte[] array = [1,2,3] + nop2=4 + nop2++ + foo.xxx() - ubyte i - ub = %00100001 - for i in 0 to 9 { - c64scr.print_ubbin(ub as ubyte, true) - c64.CHROUT('\n') - ;ub <<= 1 - ;ub <<= x - ub <<= (z+1) - } + derp: + goto main.nop2 + main.nop2() + } + + sub nop2 () { c64.CHROUT('\n') - ;ub = %11000110 ; -123 - ub = -123 - for i in 0 to 9 { - c64scr.print_ubbin(ub as ubyte, true) - c64.CHROUT('\n') - ;ub >>= 1 - ;ub >>= x - ub >>= (z+1) - } - - uw = %0011100000000011 - for i in 0 to 17 { - c64scr.print_uwbin(uw as uword, true) - c64.CHROUT('\n') - ;uw <<= 1 - ;uw <<= x - uw <<= (z+1) - } - c64.CHROUT('\n') - uw = -12345 - ;uw = %1110000011000100 - for i in 0 to 17 { - c64scr.print_uwbin(uw as uword, true) - c64.CHROUT('\n') - ;uw >>= 1 - ;uw >>= x - uw >>= (z+1) - } } } + +foo { + + sub xxx() { + + bar: + goto bar + } + + +} diff --git a/parser/antlr/prog8.g4 b/parser/antlr/prog8.g4 index 790f2887d..03efaa3bf 100644 --- a/parser/antlr/prog8.g4 +++ b/parser/antlr/prog8.g4 @@ -20,7 +20,7 @@ WS : [ \t] -> skip ; EOL : [\r\n]+ ; // WS2 : '\\' EOL -> skip; VOID: 'void'; -NAME : [a-zA-Z_][a-zA-Z0-9_]* ; +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')+ ;