mirror of
https://github.com/irmen/prog8.git
synced 2024-11-22 15:33:02 +00:00
change tokenizer so that A,X,Y now are parsed correctly as identifiers as well
This commit is contained in:
parent
48fed4e6fb
commit
25199dfb43
@ -202,14 +202,14 @@ private class AsmSubroutineReturn(val type: DataType,
|
||||
|
||||
private fun Prog8ANTLRParser.Asmsub_returnsContext.toAst(): List<AsmSubroutineReturn>
|
||||
= asmsub_return().map {
|
||||
val register = it.register().text
|
||||
val register = it.register.text
|
||||
var registerorpair: RegisterOrPair? = null
|
||||
var statusregister: Statusflag? = null
|
||||
if(register!=null) {
|
||||
when (register) {
|
||||
in RegisterOrPair.names -> registerorpair = RegisterOrPair.valueOf(register)
|
||||
in Statusflag.names -> statusregister = Statusflag.valueOf(register)
|
||||
else -> throw FatalAstException("invalid register or status flag in $it")
|
||||
else -> throw SyntaxError("invalid register or status flag", toPosition())
|
||||
}
|
||||
}
|
||||
AsmSubroutineReturn(
|
||||
@ -224,14 +224,17 @@ private fun Prog8ANTLRParser.Asmsub_paramsContext.toAst(): List<AsmSubroutinePar
|
||||
var datatype = vardecl.datatype()?.toAst() ?: DataType.UNDEFINED
|
||||
if(vardecl.ARRAYSIG()!=null || vardecl.arrayindex()!=null)
|
||||
datatype = ElementToArrayTypes.getValue(datatype)
|
||||
val register = it.register().text
|
||||
val register = it.register.text
|
||||
var registerorpair: RegisterOrPair? = null
|
||||
var statusregister: Statusflag? = null
|
||||
if(register!=null) {
|
||||
when (register) {
|
||||
in RegisterOrPair.names -> registerorpair = RegisterOrPair.valueOf(register)
|
||||
in Statusflag.names -> statusregister = Statusflag.valueOf(register)
|
||||
else -> throw FatalAstException("invalid register or status flag '$register'")
|
||||
else -> {
|
||||
val p = toPosition()
|
||||
throw SyntaxError("invalid register or status flag", Position(p.file, it.register.line, it.register.charPositionInLine, it.register.charPositionInLine+1))
|
||||
}
|
||||
}
|
||||
}
|
||||
AsmSubroutineParameter(vardecl.varname.text, datatype, registerorpair, statusregister, toPosition())
|
||||
@ -314,8 +317,12 @@ private fun Prog8ANTLRParser.Assign_targetContext.toAst() : AssignTarget {
|
||||
}
|
||||
|
||||
private fun Prog8ANTLRParser.ClobberContext.toAst() : Set<CpuRegister> {
|
||||
val names = this.cpuregister().map { it.text }
|
||||
return names.map { CpuRegister.valueOf(it) }.toSet()
|
||||
val names = this.NAME().map { it.text }
|
||||
try {
|
||||
return names.map { CpuRegister.valueOf(it) }.toSet()
|
||||
} catch(ax: IllegalArgumentException) {
|
||||
throw SyntaxError("invalid pu register", toPosition())
|
||||
}
|
||||
}
|
||||
|
||||
private fun Prog8ANTLRParser.DatatypeContext.toAst() = DataType.valueOf(text.uppercase())
|
||||
|
@ -3,8 +3,11 @@ TODO
|
||||
|
||||
For next minor release
|
||||
^^^^^^^^^^^^^^^^^^^^^^
|
||||
- fix IR/VM: animals.p8 example somehow doesn't print the animal name correctly in the first question, and exits after 1 animal instead of looping
|
||||
- check that peekw() and peek() and @(...) accept a[i] where a=uword
|
||||
- fix pokew() crash with args like: a[i] (where a=uword) , z % twoIMinusOne
|
||||
- fix Github issue with X register https://github.com/irmen/prog8/issues/94
|
||||
- fix Github issue with array problems https://github.com/irmen/prog8/issues/99
|
||||
- fix IR/VM: animals.p8 example somehow doesn't print the animal name correctly in the first question, and exits after 1 animal instead of looping
|
||||
|
||||
...
|
||||
|
||||
|
@ -55,8 +55,6 @@ ARRAYSIG :
|
||||
'[]'
|
||||
;
|
||||
|
||||
cpuregister: 'A' | 'X' | 'Y';
|
||||
register: 'A' | 'X' | 'Y' | 'AX' | 'AY' | 'XY' | 'Pc' | 'Pz' | 'Pn' | 'Pv' | 'R0' | 'R1' | 'R2' | 'R3' | 'R4' | 'R5' | 'R6' | 'R7' | 'R8' | 'R9' | 'R10' | 'R11' | 'R12' | 'R13' | 'R14' | 'R15';
|
||||
|
||||
// A module (file) consists of zero or more directives or blocks, in any order.
|
||||
// If there are more than one, then they must be separated by EOL (one or more newlines).
|
||||
@ -66,7 +64,6 @@ module: EOL* ((directive | block) (EOL+ (directive | block))*)? EOL* EOF;
|
||||
|
||||
block: identifier integerliteral? '{' EOL (block_statement | EOL)* '}';
|
||||
|
||||
|
||||
block_statement:
|
||||
directive
|
||||
| variabledeclaration
|
||||
@ -263,15 +260,15 @@ asmsub_decl : identifier '(' asmsub_params? ')' asmsub_clobbers? asmsub_returns?
|
||||
|
||||
asmsub_params : asmsub_param (',' EOL? asmsub_param)* ;
|
||||
|
||||
asmsub_param : vardecl '@' register ; // A,X,Y,AX,AY,XY,Pc,Pz,Pn,Pv allowed.
|
||||
asmsub_param : vardecl '@' register=NAME ; // A,X,Y,AX,AY,XY,Pc,Pz,Pn,Pv allowed.
|
||||
|
||||
asmsub_clobbers : 'clobbers' '(' clobber? ')' ;
|
||||
|
||||
clobber : cpuregister (',' cpuregister)* ; // A,X,Y allowed
|
||||
clobber : NAME (',' NAME)* ; // A,X,Y allowed
|
||||
|
||||
asmsub_returns : '->' asmsub_return (',' EOL? asmsub_return)* ;
|
||||
|
||||
asmsub_return : datatype '@' register ; // A,X,Y,AX,AY,XY,Pc,Pz,Pn,Pv allowed
|
||||
asmsub_return : datatype '@' register=NAME ; // A,X,Y,AX,AY,XY,Pc,Pz,Pn,Pv allowed
|
||||
|
||||
|
||||
if_stmt : 'if' expression EOL? (statement | statement_block) EOL? else_part? ; // statement is constrained later
|
||||
|
Loading…
Reference in New Issue
Block a user