From b7f655745b982a9dfbdf7365fdca8489a4bd650a Mon Sep 17 00:00:00 2001 From: chrisly42 Date: Fri, 16 Jul 2021 09:47:56 +0200 Subject: [PATCH] Enhanced expression parser for PC relative symbol and modulo handling and bitwise or. --- .../plugins/m68k/lexer/_M68kLexer.java | 672 ++++++++++++------ .../plugins/m68k/parser/M68kParser.java | 5 +- .../intellij/plugins/m68k/psi/M68kTypes.java | 1 + .../plugins/m68k/lexer/_M68kLexer.flex | 88 ++- .../platon42/intellij/plugins/m68k/m68k.bnf | 2 +- .../plugins/m68k/parser/AssignmentTest.kt | 5 + .../plugins/m68k/parser/ExpressionsTest.kt | 46 ++ .../assignment_with_local_label.txt | 12 + .../current_pc_symbol_relative_expression.txt | 13 + .../parser/expressions/math_expression.txt | 85 +++ .../pure_binary_number_literal.txt | 10 + .../pure_decimal_number_literal.txt | 10 + .../pure_hexadecimal_number_literal.txt | 10 + .../expressions/pure_octal_number_literal.txt | 10 + .../expressions/pure_string_literal.txt | 17 + 15 files changed, 728 insertions(+), 258 deletions(-) create mode 100644 src/test/java/de/platon42/intellij/plugins/m68k/parser/ExpressionsTest.kt create mode 100644 src/test/resources/parser/assignment/assignment_with_local_label.txt create mode 100644 src/test/resources/parser/expressions/current_pc_symbol_relative_expression.txt create mode 100644 src/test/resources/parser/expressions/math_expression.txt create mode 100644 src/test/resources/parser/expressions/pure_binary_number_literal.txt create mode 100644 src/test/resources/parser/expressions/pure_decimal_number_literal.txt create mode 100644 src/test/resources/parser/expressions/pure_hexadecimal_number_literal.txt create mode 100644 src/test/resources/parser/expressions/pure_octal_number_literal.txt create mode 100644 src/test/resources/parser/expressions/pure_string_literal.txt diff --git a/src/main/gen/de/platon42/intellij/plugins/m68k/lexer/_M68kLexer.java b/src/main/gen/de/platon42/intellij/plugins/m68k/lexer/_M68kLexer.java index 46576b7..2d54a13 100644 --- a/src/main/gen/de/platon42/intellij/plugins/m68k/lexer/_M68kLexer.java +++ b/src/main/gen/de/platon42/intellij/plugins/m68k/lexer/_M68kLexer.java @@ -38,8 +38,9 @@ public class _M68kLexer implements FlexLexer { public static final int ASMOPS = 8; public static final int ASSIGNMENT = 10; public static final int EXPR = 12; - public static final int MACROCALL = 14; - public static final int WAITEOL = 16; + public static final int EXPR_OP = 14; + public static final int MACROCALL = 16; + public static final int WAITEOL = 18; /** * ZZ_LEXSTATE[l] is the state in the DFA for the lexical state l @@ -49,7 +50,7 @@ public class _M68kLexer implements FlexLexer { */ private static final int ZZ_LEXSTATE[] = { 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, - 8, 8 + 8, 8, 9, 9 }; /** @@ -131,12 +132,12 @@ public class _M68kLexer implements FlexLexer { /* The ZZ_CMAP_A table has 3200 entries */ static final char ZZ_CMAP_A[] = zzUnpackCMap( - "\11\0\1\4\1\2\2\1\1\3\22\0\1\4\1\54\1\44\1\51\1\24\1\31\1\52\1\43\1\56\1\57" + - "\1\63\1\61\1\47\1\62\1\22\1\64\2\32\6\6\2\36\1\23\1\50\1\45\1\21\1\46\1\0" + + "\11\0\1\4\1\2\2\1\1\3\22\0\1\4\1\55\1\44\1\51\1\24\1\31\1\62\1\43\1\53\1\54" + + "\1\61\1\57\1\47\1\60\1\22\1\64\2\32\6\6\2\36\1\23\1\50\1\45\1\21\1\46\1\0" + "\1\40\1\5\1\71\1\65\1\11\1\15\6\12\1\30\3\12\1\10\1\16\1\67\1\7\1\20\1\17" + - "\1\70\1\27\3\12\1\0\1\42\1\0\1\55\1\13\1\41\1\33\1\26\1\66\1\34\1\37\1\35" + - "\5\12\1\30\3\12\1\10\1\16\1\67\1\25\1\20\1\17\1\70\1\27\3\12\1\0\1\53\1\0" + - "\1\60\6\0\1\1\12\0\1\4\11\0\1\12\12\0\1\12\4\0\1\12\5\0\27\12\1\0\27\12\1" + + "\1\70\1\27\3\12\1\0\1\42\1\0\1\52\1\13\1\41\1\33\1\26\1\66\1\34\1\37\1\35" + + "\5\12\1\30\3\12\1\10\1\16\1\67\1\25\1\20\1\17\1\70\1\27\3\12\1\0\1\63\1\0" + + "\1\56\6\0\1\1\12\0\1\4\11\0\1\12\12\0\1\12\4\0\1\12\5\0\27\12\1\0\27\12\1" + "\7\2\12\4\0\14\12\16\0\5\12\7\0\1\12\1\0\1\12\1\0\5\12\1\0\2\12\2\0\4\12\1" + "\0\1\12\6\0\1\12\1\0\3\12\1\0\1\12\1\0\4\12\1\0\23\12\1\0\13\12\10\0\6\12" + "\1\0\26\12\2\0\1\12\6\0\10\12\10\0\13\12\5\0\3\12\15\0\12\14\4\0\6\12\1\0" + @@ -188,21 +189,25 @@ public class _M68kLexer implements FlexLexer { private static final int[] ZZ_ACTION = zzUnpackAction(); private static final String ZZ_ACTION_PACKED_0 = - "\11\0\1\1\2\2\1\3\1\4\1\1\1\5\2\6" + + "\12\0\1\1\2\2\1\3\1\4\1\1\1\5\2\6" + "\1\2\1\7\1\10\1\1\1\11\2\12\1\7\1\10" + "\1\13\1\14\1\1\1\15\1\16\5\15\1\17\1\15" + "\1\1\1\20\4\1\1\21\1\22\1\23\1\24\1\25" + "\1\26\1\27\1\30\1\31\1\32\1\33\1\34\1\35" + - "\1\36\1\37\2\15\2\1\1\40\1\41\1\12\4\41" + - "\1\0\1\42\1\4\2\43\3\0\1\44\1\45\1\46" + - "\1\47\1\50\1\51\1\52\1\15\1\53\1\44\1\45" + - "\1\46\1\54\1\55\1\56\1\0\1\41\5\0\1\57" + - "\1\60\1\61\1\62\1\63\1\64\1\65\2\15\2\0" + - "\3\41\1\0\1\41\2\0\1\4\1\43\1\7\1\66" + - "\1\67\1\70\1\71\4\0"; + "\1\36\1\37\2\15\2\1\1\40\1\41\1\42\6\1" + + "\1\43\1\30\1\44\1\40\1\45\1\46\1\47\1\50" + + "\1\51\1\52\1\53\1\54\1\55\1\56\1\57\1\60" + + "\1\53\1\61\1\62\1\12\4\62\1\0\1\63\1\4" + + "\2\64\3\0\1\65\1\66\1\67\1\70\1\71\1\72" + + "\1\73\1\15\1\74\1\65\1\66\1\67\1\75\1\76" + + "\1\77\1\0\1\62\5\0\1\100\1\101\1\102\1\103" + + "\1\104\1\105\1\106\1\20\2\15\2\0\1\107\1\110" + + "\1\111\1\0\1\112\5\0\1\113\1\114\1\115\1\116" + + "\1\117\1\120\1\121\1\122\3\62\1\0\1\62\2\0" + + "\1\4\1\64\1\7\1\123\1\124\1\125\1\126\4\0"; private static int[] zzUnpackAction() { - int[] result = new int[130]; + int[] result = new int[176]; int offset = 0; offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result); return result; @@ -228,25 +233,30 @@ public class _M68kLexer implements FlexLexer { private static final String ZZ_ROWMAP_PACKED_0 = "\0\0\0\72\0\164\0\256\0\350\0\u0122\0\u015c\0\u0196" + - "\0\u01d0\0\u020a\0\u020a\0\u0244\0\u027e\0\u02b8\0\u02f2\0\u032c" + - "\0\u020a\0\u0366\0\u03a0\0\u03da\0\u0414\0\u044e\0\u0488\0\u020a" + - "\0\u04c2\0\u04fc\0\u0536\0\u0570\0\u05aa\0\u05e4\0\u061e\0\u0658" + + "\0\u01d0\0\u020a\0\u0244\0\u0244\0\u027e\0\u02b8\0\u02f2\0\u032c" + + "\0\u0366\0\u0244\0\u03a0\0\u03da\0\u0414\0\u044e\0\u0488\0\u04c2" + + "\0\u0244\0\u04fc\0\u0536\0\u0570\0\u05aa\0\u05e4\0\u061e\0\u0658" + "\0\u0692\0\u06cc\0\u0706\0\u0740\0\u077a\0\u07b4\0\u07ee\0\u0828" + - "\0\u0862\0\u089c\0\u08d6\0\u0910\0\u094a\0\u0984\0\u09be\0\u020a" + - "\0\u020a\0\u09f8\0\u0a32\0\u0a6c\0\u020a\0\u020a\0\u020a\0\u020a" + - "\0\u020a\0\u020a\0\u020a\0\u020a\0\u0aa6\0\u0ae0\0\u0b1a\0\u0b54" + - "\0\u020a\0\u0b8e\0\u0b8e\0\u0bc8\0\u0c02\0\u0c3c\0\u0c76\0\u0cb0" + - "\0\u0cea\0\u0d24\0\u0d5e\0\u0d98\0\u0dd2\0\u0d5e\0\u0e0c\0\u020a" + - "\0\u020a\0\u020a\0\u0740\0\u0740\0\u0740\0\u0740\0\u0e46\0\u020a" + - "\0\u0740\0\u0740\0\u0740\0\u0828\0\u0862\0\u089c\0\u08d6\0\u020a" + - "\0\u0e80\0\u0910\0\u0eba\0\u094a\0\u0ef4\0\u020a\0\u020a\0\u020a" + - "\0\u020a\0\u020a\0\u020a\0\u020a\0\u0f2e\0\u0f68\0\u0fa2\0\u0fdc" + - "\0\u1016\0\u1050\0\u108a\0\u10c4\0\u10fe\0\u1138\0\u1172\0\u020a" + - "\0\u020a\0\u020a\0\u0740\0\u0740\0\u0740\0\u020a\0\u11ac\0\u11e6" + - "\0\u1220\0\u0cea"; + "\0\u0862\0\u089c\0\u08d6\0\u0910\0\u094a\0\u0984\0\u09be\0\u09f8" + + "\0\u0244\0\u0244\0\u0244\0\u0244\0\u0244\0\u0a32\0\u0244\0\u0244" + + "\0\u0244\0\u0244\0\u0a6c\0\u0aa6\0\u0ae0\0\u0b1a\0\u0b54\0\u0b8e" + + "\0\u0bc8\0\u0244\0\u0c02\0\u0c3c\0\u0c76\0\u0cb0\0\u0cea\0\u0d24" + + "\0\u0d5e\0\u0d98\0\u0244\0\u0244\0\u0244\0\u0dd2\0\u0244\0\u0e0c" + + "\0\u0e46\0\u0244\0\u0244\0\u0244\0\u0e80\0\u0244\0\u0244\0\u0244" + + "\0\u0244\0\u0eba\0\u0ef4\0\u0f2e\0\u0f68\0\u0f68\0\u0fa2\0\u0fdc" + + "\0\u1016\0\u1050\0\u108a\0\u10c4\0\u10fe\0\u1138\0\u1172\0\u11ac" + + "\0\u1138\0\u11e6\0\u0244\0\u0244\0\u0244\0\u077a\0\u077a\0\u077a" + + "\0\u077a\0\u1220\0\u0244\0\u077a\0\u077a\0\u077a\0\u0862\0\u089c" + + "\0\u08d6\0\u0910\0\u0244\0\u125a\0\u094a\0\u1294\0\u0984\0\u12ce" + + "\0\u0244\0\u0244\0\u0244\0\u0244\0\u0244\0\u0244\0\u0244\0\u0244" + + "\0\u1308\0\u1342\0\u137c\0\u13b6\0\u0c76\0\u0cb0\0\u0cea\0\u0d24" + + "\0\u0244\0\u13f0\0\u0d5e\0\u142a\0\u0d98\0\u1464\0\u0244\0\u0244" + + "\0\u0244\0\u0244\0\u0244\0\u0244\0\u0244\0\u0244\0\u149e\0\u14d8" + + "\0\u1512\0\u154c\0\u1586\0\u15c0\0\u15fa\0\u0244\0\u0244\0\u0244" + + "\0\u077a\0\u077a\0\u077a\0\u0244\0\u1634\0\u166e\0\u16a8\0\u10c4"; private static int[] zzUnpackRowMap() { - int[] result = new int[130]; + int[] result = new int[176]; int offset = 0; offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result); return result; @@ -269,90 +279,102 @@ public class _M68kLexer implements FlexLexer { private static final int[] ZZ_TRANS = zzUnpackTrans(); private static final String ZZ_TRANS_PACKED_0 = - "\1\12\2\13\1\14\1\15\1\16\1\12\5\16\1\12" + - "\4\16\1\12\1\17\2\12\4\16\2\12\3\16\1\12" + - "\1\16\10\12\2\20\11\12\1\20\1\12\5\16\1\12" + - "\2\21\1\22\1\23\1\24\1\12\4\24\1\25\1\12" + - "\4\24\1\12\1\26\2\12\4\24\2\12\3\24\1\12" + - "\1\24\10\12\2\27\11\12\1\27\1\12\5\24\1\12" + - "\2\30\1\31\1\23\1\32\1\12\4\32\1\33\1\12" + - "\4\32\4\12\4\32\2\12\3\32\1\12\1\32\10\12" + - "\1\34\14\12\5\32\1\12\2\30\1\31\1\35\15\12" + - "\1\36\25\12\1\34\22\12\2\30\1\31\1\23\1\37" + - "\1\40\1\41\1\42\1\43\2\44\1\12\2\44\1\45" + - "\1\44\1\46\1\47\1\12\1\50\1\41\3\44\1\51" + - "\1\40\1\37\1\43\1\44\1\40\1\44\1\52\1\53" + - "\1\12\1\54\1\55\1\56\1\57\1\60\1\34\1\61" + - "\1\62\1\63\1\64\1\65\1\66\1\67\1\70\1\71" + - "\1\72\1\73\1\74\2\75\1\44\1\76\1\44\1\12" + - "\2\30\1\31\1\23\2\12\1\77\5\12\1\100\3\12" + - "\1\101\3\12\1\77\11\12\1\100\10\12\1\34\22\12" + - "\2\30\1\31\1\23\1\44\1\40\5\44\1\12\4\44" + - "\1\46\1\44\1\12\1\50\4\44\1\51\1\40\3\44" + - "\1\40\1\44\1\52\1\53\1\12\1\54\1\55\1\56" + - "\1\57\1\60\1\34\1\12\1\62\1\63\1\64\1\65" + - "\1\66\1\67\1\70\1\71\1\72\1\73\1\74\5\44" + - "\1\102\1\103\1\30\1\31\1\23\34\102\1\104\1\102" + - "\1\105\1\106\1\107\1\102\1\60\1\34\21\102\1\12" + - "\2\30\1\31\66\12\74\0\1\13\73\0\1\15\71\0" + - "\1\110\14\16\1\111\1\0\1\112\1\113\4\16\1\0" + - "\6\16\25\0\5\16\5\0\1\114\1\0\5\114\1\0" + - "\4\114\4\0\4\114\2\0\3\114\1\0\1\114\25\0" + - "\5\114\1\20\3\0\66\20\2\0\1\21\73\0\1\23" + - "\72\0\1\24\1\25\4\24\2\25\4\24\1\0\1\115" + - "\1\112\1\116\4\24\1\0\1\25\3\24\1\25\1\24" + - "\25\0\5\24\5\0\14\25\2\0\1\112\1\116\4\25" + - "\1\0\6\25\25\0\5\25\5\0\1\117\1\0\5\117" + - "\1\0\4\117\4\0\4\117\2\0\3\117\1\0\1\117" + - "\25\0\5\117\1\27\3\0\66\27\2\0\1\30\74\0" + - "\1\32\1\33\4\32\2\33\4\32\1\0\1\115\2\0" + - "\4\32\1\0\1\33\3\32\1\33\1\32\25\0\5\32" + - "\5\0\14\33\4\0\4\33\1\0\6\33\25\0\5\33" + - "\1\34\3\0\66\34\4\0\1\35\112\0\2\120\1\121" + - "\1\122\46\0\1\44\1\123\12\44\3\0\5\44\1\0" + - "\1\123\5\44\25\0\5\44\6\0\1\40\23\0\1\40" + - "\3\0\1\40\40\0\3\44\1\123\10\44\3\0\5\44" + - "\1\0\6\44\25\0\2\44\1\124\2\44\5\0\14\44" + - "\3\0\5\44\1\0\6\44\25\0\2\125\3\44\5\0" + - "\1\44\1\126\12\44\3\0\5\44\1\0\1\126\5\44" + - "\25\0\5\44\5\0\14\44\3\0\5\44\1\0\6\44" + - "\25\0\5\44\5\0\2\44\1\127\11\44\3\0\1\44" + - "\1\127\3\44\1\0\6\44\25\0\5\44\21\0\1\130" + - "\55\0\14\44\3\0\1\44\2\131\1\132\1\133\1\0" + - "\6\44\25\0\5\44\6\0\1\134\17\0\1\134\3\0" + - "\6\134\26\0\1\134\35\0\1\135\45\0\1\136\23\0" + - "\1\136\37\0\41\137\1\140\1\141\27\137\42\142\1\143" + - "\1\140\26\142\42\144\1\145\1\144\1\140\25\144\21\0" + - "\1\146\23\0\1\147\1\150\44\0\1\151\24\0\1\152" + - "\75\0\1\153\72\0\1\154\37\0\1\150\55\0\14\44" + - "\3\0\5\44\1\0\6\44\25\0\2\155\3\44\5\0" + - "\14\44\3\0\2\44\1\156\2\44\1\0\6\44\25\0" + - "\4\44\1\156\15\0\1\157\21\0\1\157\50\0\1\160" + - "\53\0\2\102\3\0\42\102\2\0\21\102\2\104\3\137" + - "\34\104\1\102\1\161\4\104\2\137\21\104\2\105\3\142" + - "\35\105\1\162\1\102\3\105\2\142\21\105\2\106\3\144" + - "\35\106\1\163\1\106\1\102\2\106\2\144\21\106\2\107" + - "\3\164\35\107\1\165\3\107\1\102\2\164\21\107\4\0" + - "\1\110\2\0\1\166\5\0\1\167\3\0\1\111\3\0" + - "\1\166\11\0\1\167\36\0\1\111\110\0\1\170\71\0" + - "\1\171\53\0\14\114\2\0\1\171\1\0\4\114\1\0" + - "\6\114\25\0\5\114\1\172\3\0\66\172\5\0\14\117" + - "\2\0\1\171\1\0\4\117\1\0\6\117\25\0\5\117" + - "\5\0\3\44\1\173\10\44\3\0\5\44\1\0\6\44" + - "\25\0\5\44\1\137\3\0\66\137\1\142\3\0\66\142" + - "\1\144\3\0\66\144\5\0\14\44\3\0\5\44\1\0" + - "\6\44\25\0\2\44\1\174\2\44\5\0\14\44\3\0" + - "\5\44\1\0\6\44\25\0\2\44\1\175\2\44\20\0" + - "\1\176\70\0\1\176\52\0\1\104\1\102\2\0\1\137" + - "\42\104\2\137\21\104\1\105\1\102\2\0\1\142\42\105" + - "\2\142\21\105\1\106\1\102\2\0\1\144\42\106\2\144" + - "\21\106\42\164\1\177\3\164\1\140\23\164\1\107\1\102" + - "\2\0\1\164\42\107\2\164\21\107\15\0\1\200\21\0" + - "\1\200\50\0\1\201\53\0\1\164\3\0\66\164\20\0" + - "\1\202\70\0\1\202\52\0"; + "\1\13\2\14\1\15\1\16\1\17\1\13\5\17\1\13" + + "\4\17\1\13\1\20\2\13\4\17\2\13\3\17\1\13" + + "\1\17\10\13\2\21\7\13\1\21\3\13\5\17\1\13" + + "\2\22\1\23\1\24\1\25\1\13\4\25\1\26\1\13" + + "\4\25\1\13\1\27\2\13\4\25\2\13\3\25\1\13" + + "\1\25\10\13\2\30\7\13\1\30\3\13\5\25\1\13" + + "\2\31\1\32\1\24\1\33\1\13\4\33\1\34\1\13" + + "\4\33\4\13\4\33\2\13\3\33\1\13\1\33\10\13" + + "\1\35\14\13\5\33\1\13\2\31\1\32\1\36\15\13" + + "\1\37\25\13\1\35\22\13\2\31\1\32\1\24\1\40" + + "\1\41\1\42\1\43\1\44\2\45\1\13\2\45\1\46" + + "\1\45\1\47\1\50\1\13\1\51\1\42\3\45\1\52" + + "\1\41\1\40\1\44\1\45\1\41\1\45\1\53\1\54" + + "\1\13\1\55\1\56\1\57\1\60\1\61\1\35\1\62" + + "\1\63\1\64\1\65\1\66\1\67\1\70\1\71\1\72" + + "\1\73\1\74\1\75\2\76\1\45\1\77\1\45\1\13" + + "\2\31\1\32\1\24\2\13\1\100\5\13\1\101\3\13" + + "\1\102\3\13\1\100\11\13\1\101\10\13\1\35\22\13" + + "\2\31\1\32\1\24\1\103\1\104\5\103\1\13\4\103" + + "\1\13\1\103\1\13\1\105\4\103\1\106\1\104\3\103" + + "\1\104\1\103\1\107\1\110\1\13\1\111\1\112\2\13" + + "\1\61\1\35\1\13\1\63\1\64\1\113\1\114\1\67" + + "\1\70\1\71\1\115\3\13\5\103\1\13\2\31\1\32" + + "\1\24\14\13\1\116\7\13\1\117\13\13\1\120\1\121" + + "\1\122\1\35\1\13\1\123\1\124\1\65\1\125\1\126" + + "\1\127\1\130\1\131\1\132\1\133\1\134\5\13\1\135" + + "\1\136\1\31\1\32\1\24\34\135\1\137\1\135\1\140" + + "\1\141\1\142\1\135\1\61\1\35\21\135\1\13\2\31" + + "\1\32\66\13\74\0\1\14\73\0\1\16\71\0\1\143" + + "\14\17\1\144\1\0\1\145\1\146\4\17\1\0\6\17" + + "\25\0\5\17\5\0\1\147\1\0\5\147\1\0\4\147" + + "\4\0\4\147\2\0\3\147\1\0\1\147\25\0\5\147" + + "\1\21\3\0\66\21\2\0\1\22\73\0\1\24\72\0" + + "\1\25\1\26\4\25\2\26\4\25\1\0\1\150\1\145" + + "\1\151\4\25\1\0\1\26\3\25\1\26\1\25\25\0" + + "\5\25\5\0\14\26\2\0\1\145\1\151\4\26\1\0" + + "\6\26\25\0\5\26\5\0\1\152\1\0\5\152\1\0" + + "\4\152\4\0\4\152\2\0\3\152\1\0\1\152\25\0" + + "\5\152\1\30\3\0\66\30\2\0\1\31\74\0\1\33" + + "\1\34\4\33\2\34\4\33\1\0\1\150\2\0\4\33" + + "\1\0\1\34\3\33\1\34\1\33\25\0\5\33\5\0" + + "\14\34\4\0\4\34\1\0\6\34\25\0\5\34\1\35" + + "\3\0\66\35\4\0\1\36\112\0\2\153\1\154\1\155" + + "\46\0\1\45\1\156\12\45\3\0\5\45\1\0\1\156" + + "\5\45\25\0\5\45\6\0\1\41\23\0\1\41\3\0" + + "\1\41\40\0\3\45\1\156\10\45\3\0\5\45\1\0" + + "\6\45\25\0\2\45\1\157\2\45\5\0\14\45\3\0" + + "\5\45\1\0\6\45\25\0\2\160\3\45\5\0\1\45" + + "\1\161\12\45\3\0\5\45\1\0\1\161\5\45\25\0" + + "\5\45\5\0\14\45\3\0\5\45\1\0\6\45\25\0" + + "\5\45\5\0\2\45\1\162\11\45\3\0\1\45\1\162" + + "\3\45\1\0\6\45\25\0\5\45\21\0\1\163\55\0" + + "\14\45\3\0\1\45\2\164\1\165\1\166\1\0\6\45" + + "\25\0\5\45\6\0\1\167\17\0\1\167\3\0\6\167" + + "\26\0\1\167\35\0\1\170\45\0\1\171\23\0\1\171" + + "\37\0\41\172\1\173\1\174\27\172\42\175\1\176\1\173" + + "\26\175\42\177\1\200\1\177\1\173\25\177\21\0\1\201" + + "\23\0\1\202\1\203\44\0\1\204\24\0\1\205\44\0" + + "\1\203\132\0\1\206\72\0\1\207\72\0\1\210\12\0" + + "\14\45\3\0\5\45\1\0\6\45\25\0\2\211\3\45" + + "\5\0\14\45\3\0\2\45\1\212\2\45\1\0\6\45" + + "\25\0\4\45\1\212\15\0\1\213\21\0\1\213\50\0" + + "\1\214\60\0\14\103\3\0\5\103\1\0\6\103\25\0" + + "\5\103\6\0\1\104\23\0\1\104\3\0\1\104\41\0" + + "\1\215\17\0\1\215\3\0\6\215\26\0\1\215\35\0" + + "\1\216\45\0\1\217\23\0\1\217\37\0\41\220\1\221" + + "\1\222\27\220\42\223\1\224\1\221\26\223\42\225\1\226" + + "\1\225\1\221\25\225\21\0\1\227\71\0\1\230\23\0" + + "\1\231\1\232\44\0\1\233\24\0\1\234\44\0\1\232" + + "\132\0\1\235\72\0\1\236\72\0\1\117\5\0\2\135" + + "\3\0\42\135\2\0\21\135\2\137\3\172\34\137\1\135" + + "\1\237\4\137\2\172\21\137\2\140\3\175\35\140\1\240" + + "\1\135\3\140\2\175\21\140\2\141\3\177\35\141\1\241" + + "\1\141\1\135\2\141\2\177\21\141\2\142\3\242\35\142" + + "\1\243\3\142\1\135\2\242\21\142\4\0\1\143\2\0" + + "\1\244\5\0\1\245\3\0\1\144\3\0\1\244\11\0" + + "\1\245\36\0\1\144\110\0\1\246\71\0\1\247\53\0" + + "\14\147\2\0\1\247\1\0\4\147\1\0\6\147\25\0" + + "\5\147\1\250\3\0\66\250\5\0\14\152\2\0\1\247" + + "\1\0\4\152\1\0\6\152\25\0\5\152\5\0\3\45" + + "\1\251\10\45\3\0\5\45\1\0\6\45\25\0\5\45" + + "\1\172\3\0\66\172\1\175\3\0\66\175\1\177\3\0" + + "\66\177\5\0\14\45\3\0\5\45\1\0\6\45\25\0" + + "\2\45\1\252\2\45\5\0\14\45\3\0\5\45\1\0" + + "\6\45\25\0\2\45\1\253\2\45\20\0\1\254\70\0" + + "\1\254\52\0\1\220\3\0\66\220\1\223\3\0\66\223" + + "\1\225\3\0\66\225\1\137\1\135\2\0\1\172\42\137" + + "\2\172\21\137\1\140\1\135\2\0\1\175\42\140\2\175" + + "\21\140\1\141\1\135\2\0\1\177\42\141\2\177\21\141" + + "\42\242\1\255\3\242\1\173\23\242\1\142\1\135\2\0" + + "\1\242\42\142\2\242\21\142\15\0\1\256\21\0\1\256" + + "\50\0\1\257\53\0\1\242\3\0\66\242\20\0\1\260" + + "\70\0\1\260\52\0"; private static int[] zzUnpackTrans() { - int[] result = new int[4698]; + int[] result = new int[5858]; int offset = 0; offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result); return result; @@ -390,14 +412,15 @@ public class _M68kLexer implements FlexLexer { private static final int[] ZZ_ATTRIBUTE = zzUnpackAttribute(); private static final String ZZ_ATTRIBUTE_PACKED_0 = - "\11\0\2\11\5\1\1\11\6\1\1\11\27\1\2\11" + - "\3\1\10\11\4\1\1\11\6\1\1\0\4\1\3\0" + - "\3\11\5\1\1\11\6\1\1\0\1\11\5\0\7\11" + - "\2\1\2\0\3\1\1\0\1\1\2\0\3\11\3\1" + - "\1\11\4\0"; + "\12\0\2\11\5\1\1\11\6\1\1\11\27\1\5\11" + + "\1\1\4\11\7\1\1\11\10\1\3\11\1\1\1\11" + + "\2\1\3\11\1\1\4\11\11\1\1\0\4\1\3\0" + + "\3\11\5\1\1\11\6\1\1\0\1\11\5\0\10\11" + + "\2\1\2\0\3\1\1\0\1\11\5\0\10\11\3\1" + + "\1\0\1\1\2\0\3\11\3\1\1\11\4\0"; private static int[] zzUnpackAttribute() { - int[] result = new int[130]; + int[] result = new int[176]; int offset = 0; offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result); return result; @@ -720,40 +743,40 @@ public class _M68kLexer implements FlexLexer { return BAD_CHARACTER; } // fall through - case 58: + case 87: break; case 2: { return WHITE_SPACE; } // fall through - case 59: + case 88: break; case 3: { yybegin(NOSOL); return WHITE_SPACE; } // fall through - case 60: + case 89: break; case 4: { yybegin(INSTRPART); return GLOBAL_LABEL_DEF; } // fall through - case 61: + case 90: break; case 5: { return COMMENT; } // fall through - case 62: + case 91: break; case 6: { yybegin(YYINITIAL); return WHITE_SPACE; } // fall through - case 63: + case 92: break; case 7: { if (isAsmMnemonicWithSize(yytext())) { @@ -777,317 +800,520 @@ public class _M68kLexer implements FlexLexer { return MACRO_INVOKATION; } // fall through - case 64: + case 93: break; case 8: { yybegin(MACROCALL); return MACRO_INVOKATION; } // fall through - case 65: + case 94: break; case 9: { yybegin(YYINITIAL); return COMMENT; } // fall through - case 66: + case 95: break; case 10: { yybegin(YYINITIAL); return EOL; } // fall through - case 67: + case 96: break; case 11: { yybegin(WAITEOL); return COMMENT; } // fall through - case 68: + case 97: break; case 12: { yybegin(ASMOPS); return WHITE_SPACE; } // fall through - case 69: + case 98: break; case 13: { return SYMBOL; } // fall through - case 70: + case 99: break; case 14: { return DECIMAL; } // fall through - case 71: + case 100: break; case 15: { return OP_ASSIGN; } // fall through - case 72: + case 101: break; case 16: { return OP_AR_MOD; } // fall through - case 73: + case 102: break; case 17: { return OP_CMP_LT; } // fall through - case 74: + case 103: break; case 18: { return OP_CMP_GT; } // fall through - case 75: + case 104: break; case 19: { return SEPARATOR; } // fall through - case 76: + case 105: break; case 20: { return HASH; } // fall through - case 77: + case 106: break; case 21: { - return OP_BITWISE_AND; - } - // fall through - case 78: - break; - case 22: { - return OP_BITWISE_OR; - } - // fall through - case 79: - break; - case 23: { - return OP_UNARY_NOT; - } - // fall through - case 80: - break; - case 24: { return OP_BITWISE_XOR; } // fall through - case 81: + case 107: break; - case 25: { + case 22: { return ROUND_L; } // fall through - case 82: + case 108: break; - case 26: { + case 23: { return ROUND_R; } // fall through - case 83: + case 109: break; - case 27: { + case 24: { + return OP_UNARY_NOT; + } + // fall through + case 110: + break; + case 25: { return OP_UNARY_COMPL; } // fall through - case 84: + case 111: break; - case 28: { + case 26: { return OP_PLUS; } // fall through - case 85: + case 112: break; - case 29: { + case 27: { return OP_MINUS; } // fall through - case 86: + case 113: break; - case 30: { + case 28: { return OP_AR_MUL; } // fall through - case 87: + case 114: + break; + case 29: { + return OP_BITWISE_AND; + } + // fall through + case 115: + break; + case 30: { + return OP_BITWISE_OR; + } + // fall through + case 116: break; case 31: { return OP_AR_DIV; } // fall through - case 88: + case 117: break; case 32: { yybegin(EXPR); return OP_ASSIGN; } // fall through - case 89: + case 118: break; case 33: { + yybegin(EXPR_OP); + return SYMBOL; + } + // fall through + case 119: + break; + case 34: { + yybegin(EXPR_OP); + return DECIMAL; + } + // fall through + case 120: + break; + case 35: { + yybegin(EXPR_OP); + return ROUND_R; + } + // fall through + case 121: + break; + case 36: { + yybegin(EXPR_OP); + return CURRENT_PC_SYMBOL; + } + // fall through + case 122: + break; + case 37: { + yybegin(EXPR); + return OP_AR_MOD; + } + // fall through + case 123: + break; + case 38: { + yybegin(EXPR); + return OP_CMP_LT; + } + // fall through + case 124: + break; + case 39: { + yybegin(EXPR); + return OP_CMP_GT; + } + // fall through + case 125: + break; + case 40: { + yybegin(EXPR); + return SEPARATOR; + } + // fall through + case 126: + break; + case 41: { + yybegin(EXPR); + return OP_BITWISE_XOR; + } + // fall through + case 127: + break; + case 42: { + yybegin(EXPR); + return ROUND_L; + } + // fall through + case 128: + break; + case 43: { + yybegin(EXPR); + return OP_BITWISE_OR; + } + // fall through + case 129: + break; + case 44: { + yybegin(EXPR); + return OP_UNARY_COMPL; + } + // fall through + case 130: + break; + case 45: { + yybegin(EXPR); + return OP_PLUS; + } + // fall through + case 131: + break; + case 46: { + yybegin(EXPR); + return OP_MINUS; + } + // fall through + case 132: + break; + case 47: { + yybegin(EXPR); + return OP_AR_MUL; + } + // fall through + case 133: + break; + case 48: { + yybegin(EXPR); + return OP_BITWISE_AND; + } + // fall through + case 134: + break; + case 49: { + yybegin(EXPR); + return OP_AR_DIV; + } + // fall through + case 135: + break; + case 50: { return STRINGLIT; } // fall through - case 90: + case 136: break; - case 34: { + case 51: { yybegin(ASSIGNMENT); yypushback(pushbackAssignment(yytext())); return SYMBOLDEF; } // fall through - case 91: + case 137: break; - case 35: { + case 52: { yybegin(INSTRPART); return LOCAL_LABEL_DEF; } // fall through - case 92: + case 138: break; - case 36: { + case 53: { return OPSIZE_BS; } // fall through - case 93: + case 139: break; - case 37: { + case 54: { return OPSIZE_W; } // fall through - case 94: + case 140: break; - case 38: { + case 55: { return OPSIZE_L; } // fall through - case 95: + case 141: break; - case 39: { + case 56: { return AREG; } // fall through - case 96: + case 142: break; - case 40: { + case 57: { return REG_SR; } // fall through - case 97: + case 143: break; - case 41: { + case 58: { return PC; } // fall through - case 98: + case 144: break; - case 42: { + case 59: { return DREG; } // fall through - case 99: + case 145: break; - case 43: { + case 60: { return OP_CMP_EQ; } // fall through - case 100: + case 146: break; - case 44: { + case 61: { return HEXADECIMAL; } // fall through - case 101: + case 147: break; - case 45: { + case 62: { return BINARY; } // fall through - case 102: + case 148: break; - case 46: { + case 63: { return OCTAL; } // fall through - case 103: + case 149: break; - case 47: { + case 64: { return OP_CMP_LT_EQ; } // fall through - case 104: + case 150: break; - case 48: { + case 65: { return OP_AR_SHIFT_L; } // fall through - case 105: + case 151: break; - case 49: { + case 66: { return OP_CMP_NOT_EQ; } // fall through - case 106: + case 152: break; - case 50: { + case 67: { return OP_CMP_GT_EQ; } // fall through - case 107: + case 153: break; - case 51: { + case 68: { return OP_AR_SHIFT_R; } // fall through - case 108: + case 154: break; - case 52: { + case 69: { return OP_LOGICAL_AND; } // fall through - case 109: + case 155: break; - case 53: { + case 70: { return OP_LOGICAL_OR; } // fall through - case 110: + case 156: break; - case 54: { + case 71: { + yybegin(EXPR_OP); + return HEXADECIMAL; + } + // fall through + case 157: + break; + case 72: { + yybegin(EXPR_OP); + return BINARY; + } + // fall through + case 158: + break; + case 73: { + yybegin(EXPR_OP); + return OCTAL; + } + // fall through + case 159: + break; + case 74: { + yybegin(EXPR_OP); + return STRINGLIT; + } + // fall through + case 160: + break; + case 75: { + yybegin(EXPR); + return OP_CMP_EQ; + } + // fall through + case 161: + break; + case 76: { + yybegin(EXPR); + return OP_CMP_LT_EQ; + } + // fall through + case 162: + break; + case 77: { + yybegin(EXPR); + return OP_AR_SHIFT_L; + } + // fall through + case 163: + break; + case 78: { + yybegin(EXPR); + return OP_CMP_NOT_EQ; + } + // fall through + case 164: + break; + case 79: { + yybegin(EXPR); + return OP_CMP_GT_EQ; + } + // fall through + case 165: + break; + case 80: { + yybegin(EXPR); + return OP_AR_SHIFT_R; + } + // fall through + case 166: + break; + case 81: { + yybegin(EXPR); + return OP_LOGICAL_AND; + } + // fall through + case 167: + break; + case 82: { + yybegin(EXPR); + return OP_LOGICAL_OR; + } + // fall through + case 168: + break; + case 83: { return REG_USP; } // fall through - case 111: + case 169: break; - case 55: { + case 84: { return REG_CCR; } // fall through - case 112: + case 170: break; - case 56: { + case 85: { return REG_VBR; } // fall through - case 113: + case 171: break; - case 57: { + case 86: { yybegin(EXPR); return EQU; } // fall through - case 114: + case 172: break; default: zzScanError(ZZ_NO_MATCH); diff --git a/src/main/gen/de/platon42/intellij/plugins/m68k/parser/M68kParser.java b/src/main/gen/de/platon42/intellij/plugins/m68k/parser/M68kParser.java index c88dd72..a97e86f 100644 --- a/src/main/gen/de/platon42/intellij/plugins/m68k/parser/M68kParser.java +++ b/src/main/gen/de/platon42/intellij/plugins/m68k/parser/M68kParser.java @@ -1194,13 +1194,14 @@ public class M68kParser implements PsiParser, LightPsiParser { return r || p; } - // SYMBOL + // SYMBOL|CURRENT_PC_SYMBOL public static boolean ref_expr(PsiBuilder b, int l) { if (!recursion_guard_(b, l, "ref_expr")) return false; - if (!nextTokenIsSmart(b, SYMBOL)) return false; + if (!nextTokenIsSmart(b, CURRENT_PC_SYMBOL, SYMBOL)) return false; boolean r; Marker m = enter_section_(b, l, _NONE_, REF_EXPR, ""); r = consumeTokenSmart(b, SYMBOL); + if (!r) r = consumeTokenSmart(b, CURRENT_PC_SYMBOL); exit_section_(b, l, m, r, false, null); return r; } diff --git a/src/main/gen/de/platon42/intellij/plugins/m68k/psi/M68kTypes.java b/src/main/gen/de/platon42/intellij/plugins/m68k/psi/M68kTypes.java index 2649fa2..8838787 100644 --- a/src/main/gen/de/platon42/intellij/plugins/m68k/psi/M68kTypes.java +++ b/src/main/gen/de/platon42/intellij/plugins/m68k/psi/M68kTypes.java @@ -72,6 +72,7 @@ public interface M68kTypes { IElementType AREG = new M68kTokenType("AREG"); IElementType BINARY = new M68kTokenType("BINARY"); IElementType COMMENT = new M68kTokenType("COMMENT"); + IElementType CURRENT_PC_SYMBOL = new M68kTokenType("CURRENT_PC_SYMBOL"); IElementType DATA_DIRECTIVE = new M68kTokenType("DATA_DIRECTIVE"); IElementType DECIMAL = new M68kTokenType("DECIMAL"); IElementType DREG = new M68kTokenType("DREG"); diff --git a/src/main/java/de/platon42/intellij/plugins/m68k/lexer/_M68kLexer.flex b/src/main/java/de/platon42/intellij/plugins/m68k/lexer/_M68kLexer.flex index b0aec61..67f32b4 100644 --- a/src/main/java/de/platon42/intellij/plugins/m68k/lexer/_M68kLexer.flex +++ b/src/main/java/de/platon42/intellij/plugins/m68k/lexer/_M68kLexer.flex @@ -49,7 +49,7 @@ PLAINPARAM=(`([^`\\]|\\.)*`|'([^'\\]|\\.)*'|\"([^\"\\]|\\.)*\")|<([^>\\]|\\.)*>| COMMENT=([;].*+) HASH_COMMENT=([#;*].*+) -%state NOSOL,INSTRPART,ASMINSTR,ASMOPS,ASSIGNMENT,EXPR,MACROCALL,WAITEOL +%state NOSOL,INSTRPART,ASMINSTR,ASMOPS,ASSIGNMENT,EXPR,EXPR_OP,MACROCALL,WAITEOL %% { @@ -133,45 +133,69 @@ 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(EXPR_OP); return BINARY; } + {HEXADECIMAL} { yybegin(EXPR_OP); return HEXADECIMAL; } + {OCTAL} { yybegin(EXPR_OP); return OCTAL; } + {DECIMAL} { yybegin(EXPR_OP); return DECIMAL; } + {STRINGLIT} { yybegin(EXPR_OP); return STRINGLIT; } - "<<" { 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; } -// ":" { return COLON; } -// ";" { return SEMICOLON; } -// "[" { return SQUARE_L; } -// "]" { return SQUARE_R; } "," { return SEPARATOR; } "(" { return ROUND_L; } - ")" { return ROUND_R; } -// "." { return DOT; } -// "$" { return DOLLAR; } - "=" { return OP_ASSIGN; } + ")" { yybegin(EXPR_OP); return ROUND_R; } "!" { return OP_UNARY_NOT; } "~" { return OP_UNARY_COMPL; } "+" { return OP_PLUS; } "-" { return OP_MINUS; } - "*" { return OP_AR_MUL; } - "/" { return OP_AR_DIV; } - "%" { return OP_AR_MOD; } + "*" { yybegin(EXPR_OP); return CURRENT_PC_SYMBOL; } - {SYMBOL} { return SYMBOL; } + {SYMBOL} { yybegin(EXPR_OP); return SYMBOL; } + + {COMMENT} { yybegin(WAITEOL); return 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_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; } + "|"|"!" { yybegin(EXPR); return OP_BITWISE_OR; } + "^" { yybegin(EXPR); return OP_BITWISE_XOR; } +// ":" { return COLON; } +// ";" { return SEMICOLON; } +// "[" { return SQUARE_L; } +// "]" { return SQUARE_R; } + "," { yybegin(EXPR); return SEPARATOR; } + "(" { yybegin(EXPR); return ROUND_L; } + ")" { return ROUND_R; } +// "." { return DOT; } +// "$" { return DOLLAR; } + "=" { yybegin(EXPR); return OP_ASSIGN; } + "~" { yybegin(EXPR); return OP_UNARY_COMPL; } + "+" { yybegin(EXPR); return OP_PLUS; } + "-" { yybegin(EXPR); return OP_MINUS; } + "*" { yybegin(EXPR); return OP_AR_MUL; } + "%"|"//" { yybegin(EXPR); return OP_AR_MOD; } + "/" { yybegin(EXPR); return OP_AR_DIV; } + +// {SYMBOL} { return SYMBOL; } {COMMENT} { yybegin(WAITEOL); return COMMENT; } } @@ -228,8 +252,8 @@ HASH_COMMENT=([#;*].*+) "+" { return OP_PLUS; } "-" { return OP_MINUS; } "*" { return OP_AR_MUL; } + "%"|"//" { return OP_AR_MOD; } "/" { return OP_AR_DIV; } - "%" { return OP_AR_MOD; } {SYMBOL} { return SYMBOL; } diff --git a/src/main/java/de/platon42/intellij/plugins/m68k/m68k.bnf b/src/main/java/de/platon42/intellij/plugins/m68k/m68k.bnf index cf40124..0ca18ec 100644 --- a/src/main/java/de/platon42/intellij/plugins/m68k/m68k.bnf +++ b/src/main/java/de/platon42/intellij/plugins/m68k/m68k.bnf @@ -253,5 +253,5 @@ binary_logical_or_expr ::= expr OP_LOGICAL_OR expr //macrobrace_expr ::= OP_CMP_LT expr OP_CMP_GT paren_expr ::= ROUND_L expr ROUND_R //{pin=1 recoverWhile=statement_recover} -ref_expr ::= SYMBOL +ref_expr ::= SYMBOL|CURRENT_PC_SYMBOL literal_expr ::= BINARY|DECIMAL|HEXADECIMAL|OCTAL|STRINGLIT diff --git a/src/test/java/de/platon42/intellij/plugins/m68k/parser/AssignmentTest.kt b/src/test/java/de/platon42/intellij/plugins/m68k/parser/AssignmentTest.kt index 5ea05ab..d419d47 100644 --- a/src/test/java/de/platon42/intellij/plugins/m68k/parser/AssignmentTest.kt +++ b/src/test/java/de/platon42/intellij/plugins/m68k/parser/AssignmentTest.kt @@ -18,6 +18,11 @@ internal class AssignmentTest : AbstractParsingTest() { testGoodSyntax(testCase, "FOO=123+10\n") } + @Test + internal fun assignment_with_local_label(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) { + testGoodSyntax(testCase, "FOO=.local-.bar\n") + } + @Test internal fun assignment_via_equ(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) { testGoodSyntax(testCase, "FOO equ BAR\n") diff --git a/src/test/java/de/platon42/intellij/plugins/m68k/parser/ExpressionsTest.kt b/src/test/java/de/platon42/intellij/plugins/m68k/parser/ExpressionsTest.kt new file mode 100644 index 0000000..3a6328b --- /dev/null +++ b/src/test/java/de/platon42/intellij/plugins/m68k/parser/ExpressionsTest.kt @@ -0,0 +1,46 @@ +package de.platon42.intellij.plugins.m68k.parser + +import de.platon42.intellij.jupiter.MyTestCase +import de.platon42.intellij.jupiter.ParsingTestExtension +import de.platon42.intellij.jupiter.TestDataSubPath +import org.junit.jupiter.api.Test + +@TestDataSubPath("expressions") +internal class ExpressionsTest : AbstractParsingTest() { + + @Test + internal fun pure_decimal_number_literal(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) { + testGoodSyntax(testCase, "FOO = 10\n") + } + + @Test + internal fun pure_hexadecimal_number_literal(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) { + testGoodSyntax(testCase, "FOO = $1234\n") + } + + @Test + internal fun pure_octal_number_literal(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) { + testGoodSyntax(testCase, "FOO = @777\n") + } + + @Test + internal fun pure_binary_number_literal(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) { + testGoodSyntax(testCase, "FOO = %11001100\n") + } + + @Test + internal fun pure_string_literal(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) { + testGoodSyntax(testCase, "FOO = 'string'\n" + + "FOO=\"bar\"\n") + } + + @Test + internal fun math_expression(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) { + testGoodSyntax(testCase, "FOO = -(~(!!(+(1//~WIDTH^@123+3*4/2+(NARF%10|32!21))<<2)>>1)&$1f)\n") + } + + @Test + internal fun current_pc_symbol_relative_expression(@MyTestCase testCase: ParsingTestExtension.IParsingTestCase) { + testGoodSyntax(testCase, " dc.w *-.label\n") + } +} \ No newline at end of file diff --git a/src/test/resources/parser/assignment/assignment_with_local_label.txt b/src/test/resources/parser/assignment/assignment_with_local_label.txt new file mode 100644 index 0000000..590f4c8 --- /dev/null +++ b/src/test/resources/parser/assignment/assignment_with_local_label.txt @@ -0,0 +1,12 @@ +Assembly File: a.asm + M68kStatementImpl(STATEMENT) + M68kAssignmentImpl(ASSIGNMENT) + PsiElement(M68kTokenType.SYMBOLDEF)('FOO') + PsiElement(M68kTokenType.OP_ASSIGN)('=') + M68kBinarySubExprImpl(BINARY_SUB_EXPR) + M68kRefExprImpl(REF_EXPR) + PsiElement(M68kTokenType.SYMBOL)('.local') + PsiElement(M68kTokenType.OP_MINUS)('-') + M68kRefExprImpl(REF_EXPR) + PsiElement(M68kTokenType.SYMBOL)('.bar') + PsiElement(M68kTokenType.EOL)('\n') \ No newline at end of file diff --git a/src/test/resources/parser/expressions/current_pc_symbol_relative_expression.txt b/src/test/resources/parser/expressions/current_pc_symbol_relative_expression.txt new file mode 100644 index 0000000..a60c633 --- /dev/null +++ b/src/test/resources/parser/expressions/current_pc_symbol_relative_expression.txt @@ -0,0 +1,13 @@ +Assembly File: a.asm + PsiWhiteSpace(' ') + M68kStatementImpl(STATEMENT) + M68kPreprocessorDirectiveImpl(PREPROCESSOR_DIRECTIVE) + PsiElement(M68kTokenType.DATA_DIRECTIVE)('dc.w') + PsiWhiteSpace(' ') + M68kBinarySubExprImpl(BINARY_SUB_EXPR) + M68kRefExprImpl(REF_EXPR) + PsiElement(M68kTokenType.CURRENT_PC_SYMBOL)('*') + PsiElement(M68kTokenType.OP_MINUS)('-') + M68kRefExprImpl(REF_EXPR) + PsiElement(M68kTokenType.SYMBOL)('.label') + PsiElement(M68kTokenType.EOL)('\n') \ No newline at end of file diff --git a/src/test/resources/parser/expressions/math_expression.txt b/src/test/resources/parser/expressions/math_expression.txt new file mode 100644 index 0000000..f84af8c --- /dev/null +++ b/src/test/resources/parser/expressions/math_expression.txt @@ -0,0 +1,85 @@ +Assembly File: a.asm + M68kStatementImpl(STATEMENT) + M68kAssignmentImpl(ASSIGNMENT) + PsiElement(M68kTokenType.SYMBOLDEF)('FOO') + PsiWhiteSpace(' ') + PsiElement(M68kTokenType.OP_ASSIGN)('=') + PsiWhiteSpace(' ') + 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.EOL)('\n') \ No newline at end of file diff --git a/src/test/resources/parser/expressions/pure_binary_number_literal.txt b/src/test/resources/parser/expressions/pure_binary_number_literal.txt new file mode 100644 index 0000000..7458e6d --- /dev/null +++ b/src/test/resources/parser/expressions/pure_binary_number_literal.txt @@ -0,0 +1,10 @@ +Assembly File: a.asm + M68kStatementImpl(STATEMENT) + M68kAssignmentImpl(ASSIGNMENT) + PsiElement(M68kTokenType.SYMBOLDEF)('FOO') + PsiWhiteSpace(' ') + PsiElement(M68kTokenType.OP_ASSIGN)('=') + PsiWhiteSpace(' ') + M68kLiteralExprImpl(LITERAL_EXPR) + PsiElement(M68kTokenType.BINARY)('%11001100') + PsiElement(M68kTokenType.EOL)('\n') \ No newline at end of file diff --git a/src/test/resources/parser/expressions/pure_decimal_number_literal.txt b/src/test/resources/parser/expressions/pure_decimal_number_literal.txt new file mode 100644 index 0000000..f51a965 --- /dev/null +++ b/src/test/resources/parser/expressions/pure_decimal_number_literal.txt @@ -0,0 +1,10 @@ +Assembly File: a.asm + M68kStatementImpl(STATEMENT) + M68kAssignmentImpl(ASSIGNMENT) + PsiElement(M68kTokenType.SYMBOLDEF)('FOO') + PsiWhiteSpace(' ') + PsiElement(M68kTokenType.OP_ASSIGN)('=') + PsiWhiteSpace(' ') + M68kLiteralExprImpl(LITERAL_EXPR) + PsiElement(M68kTokenType.DECIMAL)('10') + PsiElement(M68kTokenType.EOL)('\n') \ No newline at end of file diff --git a/src/test/resources/parser/expressions/pure_hexadecimal_number_literal.txt b/src/test/resources/parser/expressions/pure_hexadecimal_number_literal.txt new file mode 100644 index 0000000..773b998 --- /dev/null +++ b/src/test/resources/parser/expressions/pure_hexadecimal_number_literal.txt @@ -0,0 +1,10 @@ +Assembly File: a.asm + M68kStatementImpl(STATEMENT) + M68kAssignmentImpl(ASSIGNMENT) + PsiElement(M68kTokenType.SYMBOLDEF)('FOO') + PsiWhiteSpace(' ') + PsiElement(M68kTokenType.OP_ASSIGN)('=') + PsiWhiteSpace(' ') + M68kLiteralExprImpl(LITERAL_EXPR) + PsiElement(M68kTokenType.HEXADECIMAL)('$1234') + PsiElement(M68kTokenType.EOL)('\n') \ No newline at end of file diff --git a/src/test/resources/parser/expressions/pure_octal_number_literal.txt b/src/test/resources/parser/expressions/pure_octal_number_literal.txt new file mode 100644 index 0000000..3ca6664 --- /dev/null +++ b/src/test/resources/parser/expressions/pure_octal_number_literal.txt @@ -0,0 +1,10 @@ +Assembly File: a.asm + M68kStatementImpl(STATEMENT) + M68kAssignmentImpl(ASSIGNMENT) + PsiElement(M68kTokenType.SYMBOLDEF)('FOO') + PsiWhiteSpace(' ') + PsiElement(M68kTokenType.OP_ASSIGN)('=') + PsiWhiteSpace(' ') + M68kLiteralExprImpl(LITERAL_EXPR) + PsiElement(M68kTokenType.OCTAL)('@777') + PsiElement(M68kTokenType.EOL)('\n') \ No newline at end of file diff --git a/src/test/resources/parser/expressions/pure_string_literal.txt b/src/test/resources/parser/expressions/pure_string_literal.txt new file mode 100644 index 0000000..3607691 --- /dev/null +++ b/src/test/resources/parser/expressions/pure_string_literal.txt @@ -0,0 +1,17 @@ +Assembly File: a.asm + M68kStatementImpl(STATEMENT) + M68kAssignmentImpl(ASSIGNMENT) + PsiElement(M68kTokenType.SYMBOLDEF)('FOO') + PsiWhiteSpace(' ') + PsiElement(M68kTokenType.OP_ASSIGN)('=') + PsiWhiteSpace(' ') + M68kLiteralExprImpl(LITERAL_EXPR) + PsiElement(M68kTokenType.STRINGLIT)(''string'') + PsiElement(M68kTokenType.EOL)('\n') + M68kStatementImpl(STATEMENT) + M68kAssignmentImpl(ASSIGNMENT) + PsiElement(M68kTokenType.SYMBOLDEF)('FOO') + PsiElement(M68kTokenType.OP_ASSIGN)('=') + M68kLiteralExprImpl(LITERAL_EXPR) + PsiElement(M68kTokenType.STRINGLIT)('"bar"') + PsiElement(M68kTokenType.EOL)('\n') \ No newline at end of file