Similar enhanced expression parser asm-ops.

This commit is contained in:
Chris Hodges 2021-07-16 10:38:58 +02:00
parent b7f655745b
commit 99ba1014e1
5 changed files with 785 additions and 484 deletions

View File

@ -33,6 +33,8 @@ object AssemblerDirectives {
"extern", "nref", "xdef", "xref", "globl", "public", "weak",
"reg", "equr", "equrl",
"incdir", "include", "incbin", "output",
"list", "nlist", "nolist", "llen", "nopage", "page", "spc",

View File

@ -49,7 +49,7 @@ PLAINPARAM=(`([^`\\]|\\.)*`|'([^'\\]|\\.)*'|\"([^\"\\]|\\.)*\")|<([^>\\]|\\.)*>|
COMMENT=([;].*+)
HASH_COMMENT=([#;*].*+)
%state NOSOL,INSTRPART,ASMINSTR,ASMOPS,ASSIGNMENT,EXPR,EXPR_OP,MACROCALL,WAITEOL
%state NOSOL,INSTRPART,ASMINSTR,ASMOPS,ASMOPS_OP,ASSIGNMENT,EXPR,EXPR_OP,MACROCALL,WAITEOL
%%
<YYINITIAL> {
@ -158,21 +158,14 @@ HASH_COMMENT=([#;*].*+)
{WHITE_SPACE} { return WHITE_SPACE; } // FIXME space optionally introduces comment
{EOL} { yybegin(YYINITIAL); return EOL; }
// {BINARY} { return BINARY; }
// {HEXADECIMAL} { return HEXADECIMAL; }
// {OCTAL} { return OCTAL; }
// {DECIMAL} { return DECIMAL; }
// {STRINGLIT} { return STRINGLIT; }
"<<" { yybegin(EXPR); return OP_AR_SHIFT_L; }
">>" { yybegin(EXPR); return OP_AR_SHIFT_R; }
"&&" { yybegin(EXPR); return OP_LOGICAL_AND; }
"||" { yybegin(EXPR); return OP_LOGICAL_OR; }
"==" { yybegin(EXPR); return OP_CMP_EQ; }
"<>" { yybegin(EXPR); return OP_CMP_NOT_EQ; }
"<>"|"!=" { yybegin(EXPR); return OP_CMP_NOT_EQ; }
">=" { yybegin(EXPR); return OP_CMP_GT_EQ; }
"<=" { yybegin(EXPR); return OP_CMP_LT_EQ; }
"!=" { yybegin(EXPR); return OP_CMP_NOT_EQ; }
"<" { yybegin(EXPR); return OP_CMP_LT; }
">" { yybegin(EXPR); return OP_CMP_GT; }
"&" { yybegin(EXPR); return OP_BITWISE_AND; }
@ -187,7 +180,7 @@ HASH_COMMENT=([#;*].*+)
")" { return ROUND_R; }
// "." { return DOT; }
// "$" { return DOLLAR; }
"=" { yybegin(EXPR); return OP_ASSIGN; }
// "=" { yybegin(EXPR); return OP_ASSIGN; }
"~" { yybegin(EXPR); return OP_UNARY_COMPL; }
"+" { yybegin(EXPR); return OP_PLUS; }
"-" { yybegin(EXPR); return OP_MINUS; }
@ -195,8 +188,6 @@ HASH_COMMENT=([#;*].*+)
"%"|"//" { yybegin(EXPR); return OP_AR_MOD; }
"/" { yybegin(EXPR); return OP_AR_DIV; }
// {SYMBOL} { return SYMBOL; }
{COMMENT} { yybegin(WAITEOL); return COMMENT; }
}
@ -204,61 +195,78 @@ HASH_COMMENT=([#;*].*+)
{WHITE_SPACE} { return WHITE_SPACE; } // FIXME space optionally introduces comment
{EOL} { yybegin(YYINITIAL); return EOL; }
{BINARY} { return BINARY; }
{HEXADECIMAL} { return HEXADECIMAL; }
{OCTAL} { return OCTAL; }
{DECIMAL} { return DECIMAL; }
{STRINGLIT} { return STRINGLIT; }
{BINARY} { yybegin(ASMOPS_OP); return BINARY; }
{HEXADECIMAL} { yybegin(ASMOPS_OP); return HEXADECIMAL; }
{OCTAL} { yybegin(ASMOPS_OP); return OCTAL; }
{DECIMAL} { yybegin(ASMOPS_OP); return DECIMAL; }
{STRINGLIT} { yybegin(ASMOPS_OP); return STRINGLIT; }
{AREG} { yybegin(ASMOPS_OP); return AREG; }
{DREG} { yybegin(ASMOPS_OP); return DREG; }
"pc" { yybegin(ASMOPS_OP); return PC; }
"ccr" { yybegin(ASMOPS_OP); return REG_CCR; }
"sr" { yybegin(ASMOPS_OP); return REG_SR; }
"usp" { yybegin(ASMOPS_OP); return REG_USP; }
"vbr" { yybegin(ASMOPS_OP); return REG_VBR; }
"^" { return OP_BITWISE_XOR; }
"," { return SEPARATOR; }
"(" { return ROUND_L; }
")" { yybegin(ASMOPS_OP); return ROUND_R; }
"!" { return OP_UNARY_NOT; }
"~" { return OP_UNARY_COMPL; }
"+" { return OP_PLUS; }
"-" { return OP_MINUS; }
"*" { yybegin(ASMOPS_OP); return CURRENT_PC_SYMBOL; }
"#" { return HASH; }
{SYMBOL} { yybegin(ASMOPS_OP); return SYMBOL; }
{COMMENT} { yybegin(WAITEOL); return COMMENT; }
}
<ASMOPS_OP> {
{WHITE_SPACE} { return WHITE_SPACE; } // FIXME space optionally introduces comment
{EOL} { yybegin(YYINITIAL); return EOL; }
{OPSIZE_BS} { return OPSIZE_BS; }
{OPSIZE_W} { return OPSIZE_W; }
{OPSIZE_L} { return OPSIZE_L; }
{AREG} { return AREG; }
{DREG} { return DREG; }
"pc" { return PC; }
"ccr" { return REG_CCR; }
"sr" { return REG_SR; }
"usp" { return REG_USP; }
"vbr" { return REG_VBR; }
"<<" { return OP_AR_SHIFT_L; }
">>" { return OP_AR_SHIFT_R; }
"&&" { return OP_LOGICAL_AND; }
"||" { return OP_LOGICAL_OR; }
"==" { return OP_CMP_EQ; }
"<>" { return OP_CMP_NOT_EQ; }
">=" { return OP_CMP_GT_EQ; }
"<=" { return OP_CMP_LT_EQ; }
"!=" { return OP_CMP_NOT_EQ; }
"<" { return OP_CMP_LT; }
">" { return OP_CMP_GT; }
"&" { return OP_BITWISE_AND; }
"|" { return OP_BITWISE_OR; }
"^" { return OP_BITWISE_XOR; }
"<<" { yybegin(ASMOPS); return OP_AR_SHIFT_L; }
">>" { yybegin(ASMOPS); return OP_AR_SHIFT_R; }
"&&" { yybegin(ASMOPS); return OP_LOGICAL_AND; }
"||" { yybegin(ASMOPS); return OP_LOGICAL_OR; }
"==" { yybegin(ASMOPS); return OP_CMP_EQ; }
"<>"|"!=" { yybegin(ASMOPS); return OP_CMP_NOT_EQ; }
">=" { yybegin(ASMOPS); return OP_CMP_GT_EQ; }
"<=" { yybegin(ASMOPS); return OP_CMP_LT_EQ; }
"<" { yybegin(ASMOPS); return OP_CMP_LT; }
">" { yybegin(ASMOPS); return OP_CMP_GT; }
"&" { yybegin(ASMOPS); return OP_BITWISE_AND; }
"|"|"!" { yybegin(ASMOPS); return OP_BITWISE_OR; }
"^" { yybegin(ASMOPS); return OP_BITWISE_XOR; }
// ":" { return COLON; }
// ";" { return SEMICOLON; }
// "[" { return SQUARE_L; }
// "]" { return SQUARE_R; }
"(" { return ROUND_L; }
"," { yybegin(ASMOPS); return SEPARATOR; }
"(" { yybegin(ASMOPS); return ROUND_L; }
")" { return ROUND_R; }
"," { return SEPARATOR; }
// "." { return DOT; }
"#" { return HASH; }
// "$" { return DOLLAR; }
"=" { return OP_ASSIGN; }
"!" { return OP_UNARY_NOT; }
"~" { return OP_UNARY_COMPL; }
"+" { return OP_PLUS; }
"-" { return OP_MINUS; }
"*" { return OP_AR_MUL; }
"%"|"//" { return OP_AR_MOD; }
"/" { return OP_AR_DIV; }
// "=" { return OP_ASSIGN; }
"~" { yybegin(ASMOPS); return OP_UNARY_COMPL; }
"+" { yybegin(ASMOPS); return OP_PLUS; }
"-" { yybegin(ASMOPS); return OP_MINUS; }
"*" { yybegin(ASMOPS); return OP_AR_MUL; }
"%"|"//" { yybegin(ASMOPS); return OP_AR_MOD; }
"/" { yybegin(ASMOPS); return OP_AR_DIV; }
{SYMBOL} { return SYMBOL; }
{COMMENT} { yybegin(WAITEOL); return COMMENT; }
}
<WAITEOL>

View File

@ -98,4 +98,9 @@ internal class AddressingModesTest : AbstractParsingTest() {
testGoodSyntax(testCase, " move.l usp,a0\n"
+ " move.l a5,usp\n")
}
@Test
internal fun complex_math_expression_in_displacement(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) {
testGoodSyntax(testCase, " move.l -(~(!!(+(1//~WIDTH^@123+3*4/2+(NARF%10|32!21))<<2)>>1)&$1f)(a0),(-(~(!!(+(1//~WIDTH^@123+3*4/2+(NARF%10|32!21))<<2)>>1)&\$1f),a0,d0.l)\n")
}
}

View File

@ -0,0 +1,181 @@
Assembly File: a.asm
PsiWhiteSpace(' ')
M68kStatementImpl(STATEMENT)
M68kAsmInstructionImpl(ASM_INSTRUCTION)
M68kAsmOpImpl(ASM_OP)
PsiElement(M68kTokenType.MNEMONIC)('move')
M68kOperandSizeImpl(OPERAND_SIZE)
PsiElement(M68kTokenType.OPSIZE_L)('.l')
PsiWhiteSpace(' ')
M68kAddressRegisterIndirectWithDisplacementOldAddressingModeImpl(ADDRESS_REGISTER_INDIRECT_WITH_DISPLACEMENT_OLD_ADDRESSING_MODE)
M68kUnaryMinusExprImpl(UNARY_MINUS_EXPR)
PsiElement(M68kTokenType.OP_MINUS)('-')
M68kParenExprImpl(PAREN_EXPR)
PsiElement(M68kTokenType.ROUND_L)('(')
M68kBinaryBitwiseAndExprImpl(BINARY_BITWISE_AND_EXPR)
M68kUnaryComplExprImpl(UNARY_COMPL_EXPR)
PsiElement(M68kTokenType.OP_UNARY_COMPL)('~')
M68kParenExprImpl(PAREN_EXPR)
PsiElement(M68kTokenType.ROUND_L)('(')
M68kBinaryShiftRExprImpl(BINARY_SHIFT_R_EXPR)
M68kUnaryNotExprImpl(UNARY_NOT_EXPR)
PsiElement(M68kTokenType.OP_UNARY_NOT)('!')
M68kUnaryNotExprImpl(UNARY_NOT_EXPR)
PsiElement(M68kTokenType.OP_UNARY_NOT)('!')
M68kParenExprImpl(PAREN_EXPR)
PsiElement(M68kTokenType.ROUND_L)('(')
M68kBinaryShiftLExprImpl(BINARY_SHIFT_L_EXPR)
M68kUnaryPlusExprImpl(UNARY_PLUS_EXPR)
PsiElement(M68kTokenType.OP_PLUS)('+')
M68kParenExprImpl(PAREN_EXPR)
PsiElement(M68kTokenType.ROUND_L)('(')
M68kBinaryAddExprImpl(BINARY_ADD_EXPR)
M68kBinaryAddExprImpl(BINARY_ADD_EXPR)
M68kBinaryModExprImpl(BINARY_MOD_EXPR)
M68kLiteralExprImpl(LITERAL_EXPR)
PsiElement(M68kTokenType.DECIMAL)('1')
PsiElement(M68kTokenType.OP_AR_MOD)('//')
M68kBinaryBitwiseXorExprImpl(BINARY_BITWISE_XOR_EXPR)
M68kUnaryComplExprImpl(UNARY_COMPL_EXPR)
PsiElement(M68kTokenType.OP_UNARY_COMPL)('~')
M68kRefExprImpl(REF_EXPR)
PsiElement(M68kTokenType.SYMBOL)('WIDTH')
PsiElement(M68kTokenType.OP_BITWISE_XOR)('^')
M68kLiteralExprImpl(LITERAL_EXPR)
PsiElement(M68kTokenType.OCTAL)('@123')
PsiElement(M68kTokenType.OP_PLUS)('+')
M68kBinaryDivExprImpl(BINARY_DIV_EXPR)
M68kBinaryMulExprImpl(BINARY_MUL_EXPR)
M68kLiteralExprImpl(LITERAL_EXPR)
PsiElement(M68kTokenType.DECIMAL)('3')
PsiElement(M68kTokenType.OP_AR_MUL)('*')
M68kLiteralExprImpl(LITERAL_EXPR)
PsiElement(M68kTokenType.DECIMAL)('4')
PsiElement(M68kTokenType.OP_AR_DIV)('/')
M68kLiteralExprImpl(LITERAL_EXPR)
PsiElement(M68kTokenType.DECIMAL)('2')
PsiElement(M68kTokenType.OP_PLUS)('+')
M68kParenExprImpl(PAREN_EXPR)
PsiElement(M68kTokenType.ROUND_L)('(')
M68kBinaryModExprImpl(BINARY_MOD_EXPR)
M68kRefExprImpl(REF_EXPR)
PsiElement(M68kTokenType.SYMBOL)('NARF')
PsiElement(M68kTokenType.OP_AR_MOD)('%')
M68kBinaryBitwiseOrExprImpl(BINARY_BITWISE_OR_EXPR)
M68kBinaryBitwiseOrExprImpl(BINARY_BITWISE_OR_EXPR)
M68kLiteralExprImpl(LITERAL_EXPR)
PsiElement(M68kTokenType.DECIMAL)('10')
PsiElement(M68kTokenType.OP_BITWISE_OR)('|')
M68kLiteralExprImpl(LITERAL_EXPR)
PsiElement(M68kTokenType.DECIMAL)('32')
PsiElement(M68kTokenType.OP_BITWISE_OR)('!')
M68kLiteralExprImpl(LITERAL_EXPR)
PsiElement(M68kTokenType.DECIMAL)('21')
PsiElement(M68kTokenType.ROUND_R)(')')
PsiElement(M68kTokenType.ROUND_R)(')')
PsiElement(M68kTokenType.OP_AR_SHIFT_L)('<<')
M68kLiteralExprImpl(LITERAL_EXPR)
PsiElement(M68kTokenType.DECIMAL)('2')
PsiElement(M68kTokenType.ROUND_R)(')')
PsiElement(M68kTokenType.OP_AR_SHIFT_R)('>>')
M68kLiteralExprImpl(LITERAL_EXPR)
PsiElement(M68kTokenType.DECIMAL)('1')
PsiElement(M68kTokenType.ROUND_R)(')')
PsiElement(M68kTokenType.OP_BITWISE_AND)('&')
M68kLiteralExprImpl(LITERAL_EXPR)
PsiElement(M68kTokenType.HEXADECIMAL)('$1f')
PsiElement(M68kTokenType.ROUND_R)(')')
PsiElement(M68kTokenType.ROUND_L)('(')
M68kAddressRegisterImpl(ADDRESS_REGISTER)
PsiElement(M68kTokenType.AREG)('a0')
PsiElement(M68kTokenType.ROUND_R)(')')
PsiElement(M68kTokenType.SEPARATOR)(',')
M68kAddressRegisterIndirectWithIndexNewAddressingModeImpl(ADDRESS_REGISTER_INDIRECT_WITH_INDEX_NEW_ADDRESSING_MODE)
PsiElement(M68kTokenType.ROUND_L)('(')
M68kUnaryMinusExprImpl(UNARY_MINUS_EXPR)
PsiElement(M68kTokenType.OP_MINUS)('-')
M68kParenExprImpl(PAREN_EXPR)
PsiElement(M68kTokenType.ROUND_L)('(')
M68kBinaryBitwiseAndExprImpl(BINARY_BITWISE_AND_EXPR)
M68kUnaryComplExprImpl(UNARY_COMPL_EXPR)
PsiElement(M68kTokenType.OP_UNARY_COMPL)('~')
M68kParenExprImpl(PAREN_EXPR)
PsiElement(M68kTokenType.ROUND_L)('(')
M68kBinaryShiftRExprImpl(BINARY_SHIFT_R_EXPR)
M68kUnaryNotExprImpl(UNARY_NOT_EXPR)
PsiElement(M68kTokenType.OP_UNARY_NOT)('!')
M68kUnaryNotExprImpl(UNARY_NOT_EXPR)
PsiElement(M68kTokenType.OP_UNARY_NOT)('!')
M68kParenExprImpl(PAREN_EXPR)
PsiElement(M68kTokenType.ROUND_L)('(')
M68kBinaryShiftLExprImpl(BINARY_SHIFT_L_EXPR)
M68kUnaryPlusExprImpl(UNARY_PLUS_EXPR)
PsiElement(M68kTokenType.OP_PLUS)('+')
M68kParenExprImpl(PAREN_EXPR)
PsiElement(M68kTokenType.ROUND_L)('(')
M68kBinaryAddExprImpl(BINARY_ADD_EXPR)
M68kBinaryAddExprImpl(BINARY_ADD_EXPR)
M68kBinaryModExprImpl(BINARY_MOD_EXPR)
M68kLiteralExprImpl(LITERAL_EXPR)
PsiElement(M68kTokenType.DECIMAL)('1')
PsiElement(M68kTokenType.OP_AR_MOD)('//')
M68kBinaryBitwiseXorExprImpl(BINARY_BITWISE_XOR_EXPR)
M68kUnaryComplExprImpl(UNARY_COMPL_EXPR)
PsiElement(M68kTokenType.OP_UNARY_COMPL)('~')
M68kRefExprImpl(REF_EXPR)
PsiElement(M68kTokenType.SYMBOL)('WIDTH')
PsiElement(M68kTokenType.OP_BITWISE_XOR)('^')
M68kLiteralExprImpl(LITERAL_EXPR)
PsiElement(M68kTokenType.OCTAL)('@123')
PsiElement(M68kTokenType.OP_PLUS)('+')
M68kBinaryDivExprImpl(BINARY_DIV_EXPR)
M68kBinaryMulExprImpl(BINARY_MUL_EXPR)
M68kLiteralExprImpl(LITERAL_EXPR)
PsiElement(M68kTokenType.DECIMAL)('3')
PsiElement(M68kTokenType.OP_AR_MUL)('*')
M68kLiteralExprImpl(LITERAL_EXPR)
PsiElement(M68kTokenType.DECIMAL)('4')
PsiElement(M68kTokenType.OP_AR_DIV)('/')
M68kLiteralExprImpl(LITERAL_EXPR)
PsiElement(M68kTokenType.DECIMAL)('2')
PsiElement(M68kTokenType.OP_PLUS)('+')
M68kParenExprImpl(PAREN_EXPR)
PsiElement(M68kTokenType.ROUND_L)('(')
M68kBinaryModExprImpl(BINARY_MOD_EXPR)
M68kRefExprImpl(REF_EXPR)
PsiElement(M68kTokenType.SYMBOL)('NARF')
PsiElement(M68kTokenType.OP_AR_MOD)('%')
M68kBinaryBitwiseOrExprImpl(BINARY_BITWISE_OR_EXPR)
M68kBinaryBitwiseOrExprImpl(BINARY_BITWISE_OR_EXPR)
M68kLiteralExprImpl(LITERAL_EXPR)
PsiElement(M68kTokenType.DECIMAL)('10')
PsiElement(M68kTokenType.OP_BITWISE_OR)('|')
M68kLiteralExprImpl(LITERAL_EXPR)
PsiElement(M68kTokenType.DECIMAL)('32')
PsiElement(M68kTokenType.OP_BITWISE_OR)('!')
M68kLiteralExprImpl(LITERAL_EXPR)
PsiElement(M68kTokenType.DECIMAL)('21')
PsiElement(M68kTokenType.ROUND_R)(')')
PsiElement(M68kTokenType.ROUND_R)(')')
PsiElement(M68kTokenType.OP_AR_SHIFT_L)('<<')
M68kLiteralExprImpl(LITERAL_EXPR)
PsiElement(M68kTokenType.DECIMAL)('2')
PsiElement(M68kTokenType.ROUND_R)(')')
PsiElement(M68kTokenType.OP_AR_SHIFT_R)('>>')
M68kLiteralExprImpl(LITERAL_EXPR)
PsiElement(M68kTokenType.DECIMAL)('1')
PsiElement(M68kTokenType.ROUND_R)(')')
PsiElement(M68kTokenType.OP_BITWISE_AND)('&')
M68kLiteralExprImpl(LITERAL_EXPR)
PsiElement(M68kTokenType.HEXADECIMAL)('$1f')
PsiElement(M68kTokenType.ROUND_R)(')')
PsiElement(M68kTokenType.SEPARATOR)(',')
M68kAddressRegisterImpl(ADDRESS_REGISTER)
PsiElement(M68kTokenType.AREG)('a0')
PsiElement(M68kTokenType.SEPARATOR)(',')
M68kDataRegisterImpl(DATA_REGISTER)
PsiElement(M68kTokenType.DREG)('d0')
M68kDataWidthImpl(DATA_WIDTH)
PsiElement(M68kTokenType.OPSIZE_L)('.l')
PsiElement(M68kTokenType.ROUND_R)(')')
PsiElement(M68kTokenType.EOL)('\n')