Skip to content

Commit

Permalink
[#201] Initial ANTLR for 8080asm
Browse files Browse the repository at this point in the history
  • Loading branch information
vbmacher committed Nov 25, 2021
1 parent 0b4ed48 commit b6e5178
Show file tree
Hide file tree
Showing 16 changed files with 523 additions and 2,248 deletions.
3 changes: 2 additions & 1 deletion plugins/compiler/as-8080/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
src/main/java/net/emustudio/plugins/compiler/as8080/LexerImpl.java
/src/main/antlr/gen/
/src/main/gen/
41 changes: 21 additions & 20 deletions plugins/compiler/as-8080/src/main/antlr/As8080Lexer.g4
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
lexer grammar As8080Lexer;

options {
backtrack=false;
}

WS : (' ' | '\t' | '\f') -> channel(HIDDEN);
COMMENT: ('//' | '--' | ';' | '#' ) ~[\r\n]*;
COMMENT: ('//' | '--' | ';' | '#' ) ~[\r\n]* -> skip;
COMMENT2: '/*' .*? '*/' -> skip;
EOL: '\r'? '\n';

fragment A: [aA];
Expand Down Expand Up @@ -140,17 +136,7 @@ REG_M: M;
REG_PSW: P S W;
REG_SP: S P;

// separators
SEP_LPAR: '(';
SEP_RPAR: ')';
SEP_COMMA: ',';

// operators
OP_ADD: '+';
OP_SUBTRACT: '-';
OP_MULTIPLY: '*';
OP_DIVIDE: '/';
OP_EQUAL: '=';
OP_MOD: M O D;
OP_SHR: S H R;
OP_SHL: S H L;
Expand All @@ -160,17 +146,32 @@ OP_OR: O R;
OP_XOR: X O R;

// literals
LIT_NUMBER: [\-]? [0-9]+ D?;
LIT_HEXNUMBER_1: [\-]? '0' X [0-9a-fA-F]+;
LIT_NUMBER: [\-]? [0-9]+ D?;
LIT_HEXNUMBER_2: [\-]? [0-9a-fA-F]+ H;
LIT_OCTNUMBER: [\-]? [0-7]+ [oOqQ];
LIT_BINNUMBER: [01]+ B;
LIT_STRING_1: ['] [^']+ ['];
LIT_STRING_2: '"' [^"]+ '"';
LIT_STRING_1: '\'' ~[']* '\'';
LIT_STRING_2: '"' ~["]* '"';
// other
ID_IDENTIFIER: [a-zA-Z_?@] [a-zA-Z_?@0-9]*;
ID_LABEL: [a-zA-Z_?@] [a-zA-Z_?@0-9]* ':';
ERROR : .;
ERROR : ~[+* \t\f(),=/-]+; // below: everything which does not require space
//\+\*
// separators - not requiring space inbetween
SEP_LPAR: '(';
SEP_RPAR: ')';
SEP_COMMA: ',';
// operators not requiring space inbetween
OP_ADD: '+';
OP_SUBTRACT: '-';
OP_MULTIPLY: '*';
OP_DIVIDE: '/';
OP_EQUAL: '=';
WS : [ \t\f]+ -> skip;
71 changes: 36 additions & 35 deletions plugins/compiler/as-8080/src/main/antlr/As8080Lexer.tokens
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
WS=1
COMMENT=2
COMMENT=1
COMMENT2=2
EOL=3
OPCODE_STC=4
OPCODE_CMC=5
Expand Down Expand Up @@ -101,37 +101,38 @@ REG_L=100
REG_M=101
REG_PSW=102
REG_SP=103
SEP_LPAR=104
SEP_RPAR=105
SEP_COMMA=106
OP_ADD=107
OP_SUBTRACT=108
OP_MULTIPLY=109
OP_DIVIDE=110
OP_EQUAL=111
OP_MOD=112
OP_SHR=113
OP_SHL=114
OP_NOT=115
OP_AND=116
OP_OR=117
OP_XOR=118
LIT_NUMBER=119
LIT_HEXNUMBER_1=120
LIT_HEXNUMBER_2=121
LIT_OCTNUMBER=122
LIT_BINNUMBER=123
LIT_STRING_1=124
LIT_STRING_2=125
ID_IDENTIFIER=126
ID_LABEL=127
ERROR=128
OP_MOD=104
OP_SHR=105
OP_SHL=106
OP_NOT=107
OP_AND=108
OP_OR=109
OP_XOR=110
LIT_HEXNUMBER_1=111
LIT_NUMBER=112
LIT_HEXNUMBER_2=113
LIT_OCTNUMBER=114
LIT_BINNUMBER=115
LIT_STRING_1=116
LIT_STRING_2=117
ID_IDENTIFIER=118
ID_LABEL=119
ERROR=120
SEP_LPAR=121
SEP_RPAR=122
SEP_COMMA=123
OP_ADD=124
OP_SUBTRACT=125
OP_MULTIPLY=126
OP_DIVIDE=127
OP_EQUAL=128
WS=129
'$'=93
'('=104
')'=105
','=106
'+'=107
'-'=108
'*'=109
'/'=110
'='=111
'('=121
')'=122
','=123
'+'=124
'-'=125
'*'=126
'/'=127
'='=128
Loading

0 comments on commit b6e5178

Please sign in to comment.