Skip to content

Commit

Permalink
[#201] WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
vbmacher committed Oct 3, 2021
1 parent 5f9a855 commit 0b4ed48
Show file tree
Hide file tree
Showing 78 changed files with 1,581 additions and 735 deletions.
5 changes: 4 additions & 1 deletion plugins/compiler/as-8080/src/main/antlr/As8080Lexer.g4
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
lexer grammar As8080Lexer;

options {
backtrack=false;
}

WS : (' ' | '\t' | '\f') -> channel(HIDDEN);
COMMENT: ('//' | '--' | ';' | '#' ) ~[\r\n]*;
Expand Down Expand Up @@ -158,7 +161,7 @@ OP_XOR: X O R;

// literals
LIT_NUMBER: [\-]? [0-9]+ D?;
LIT_HEXNUMBER_1: [\-]? ('0x'|'0X') [0-9a-fA-F]+;
LIT_HEXNUMBER_1: [\-]? '0' X [0-9a-fA-F]+;
LIT_HEXNUMBER_2: [\-]? [0-9a-fA-F]+ H;
LIT_OCTNUMBER: [\-]? [0-7]+ [oOqQ];
LIT_BINNUMBER: [01]+ B;
Expand Down
207 changes: 103 additions & 104 deletions plugins/compiler/as-8080/src/main/antlr/As8080Parser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -23,84 +23,84 @@ rStatement:
;

rInstruction:
opcode=OPCODE_STC
| opcode=OPCODE_CMC
| opcode=OPCODE_CMA
| opcode=OPCODE_DAA
| opcode=OPCODE_NOP
| opcode=OPCODE_RLC
| opcode=OPCODE_RRC
| opcode=OPCODE_RAL
| opcode=OPCODE_RAR
| opcode=OPCODE_XCHG
| opcode=OPCODE_XTHL
| opcode=OPCODE_SPHL
| opcode=OPCODE_PCHL
| opcode=OPCODE_RET
| opcode=OPCODE_RC
| opcode=OPCODE_RNC
| opcode=OPCODE_RZ
| opcode=OPCODE_RNZ
| opcode=OPCODE_RM
| opcode=OPCODE_RP
| opcode=OPCODE_RPE
| opcode=OPCODE_RPO
| opcode=OPCODE_EI
| opcode=OPCODE_DI
| opcode=OPCODE_HLT
| opcode=OPCODE_INR reg=rRegister
| opcode=OPCODE_DCR reg=rRegister
| opcode=OPCODE_ADD reg=rRegister
| opcode=OPCODE_ADC reg=rRegister
| opcode=OPCODE_SUB reg=rRegister
| opcode=OPCODE_SBB reg=rRegister
| opcode=OPCODE_ANA reg=rRegister
| opcode=OPCODE_XRA reg=rRegister
| opcode=OPCODE_ORA reg=rRegister
| opcode=OPCODE_CMP reg=rRegister
| opcode=OPCODE_MOV dst=rRegister SEP_COMMA src=rRegister
| opcode=OPCODE_STAX regpair=(REG_B|REG_D)
| opcode=OPCODE_LDAX regpair=(REG_B|REG_D)
| opcode=OPCODE_PUSH regpair=(REG_B|REG_D|REG_H|REG_PSW)
| opcode=OPCODE_POP regpair=(REG_B|REG_D|REG_H|REG_PSW)
| opcode=OPCODE_DAD regpair=(REG_B|REG_D|REG_H|REG_SP)
| opcode=OPCODE_INX regpair=(REG_B|REG_D|REG_H|REG_SP)
| opcode=OPCODE_DCX regpair=(REG_B|REG_D|REG_H|REG_SP)
| opcode=OPCODE_LXI regpair=(REG_B|REG_D|REG_H|REG_SP) SEP_COMMA expr=rExpression
| opcode=OPCODE_MVI reg=rRegister SEP_COMMA expr=rExpression
| opcode=OPCODE_ADI expr=rExpression
| opcode=OPCODE_ACI expr=rExpression
| opcode=OPCODE_SUI expr=rExpression
| opcode=OPCODE_SBI expr=rExpression
| opcode=OPCODE_ANI expr=rExpression
| opcode=OPCODE_XRI expr=rExpression
| opcode=OPCODE_ORI expr=rExpression
| opcode=OPCODE_CPI expr=rExpression
| opcode=OPCODE_STA expr=rExpression
| opcode=OPCODE_LDA expr=rExpression
| opcode=OPCODE_SHLD expr=rExpression
| opcode=OPCODE_LHLD expr=rExpression
| opcode=OPCODE_JMP expr=rExpression
| opcode=OPCODE_JC expr=rExpression
| opcode=OPCODE_JNC expr=rExpression
| opcode=OPCODE_JZ expr=rExpression
| opcode=OPCODE_JNZ expr=rExpression
| opcode=OPCODE_JM expr=rExpression
| opcode=OPCODE_JP expr=rExpression
| opcode=OPCODE_JPE expr=rExpression
| opcode=OPCODE_JPO expr=rExpression
| opcode=OPCODE_CALL expr=rExpression
| opcode=OPCODE_CC expr=rExpression
| opcode=OPCODE_CNC expr=rExpression
| opcode=OPCODE_CZ expr=rExpression
| opcode=OPCODE_CNZ expr=rExpression
| opcode=OPCODE_CM expr=rExpression
| opcode=OPCODE_CP expr=rExpression
| opcode=OPCODE_CPE expr=rExpression
| opcode=OPCODE_CPO expr=rExpression
| opcode=OPCODE_RST expr=rExpression
| opcode=OPCODE_IN expr=rExpression
| opcode=OPCODE_OUT expr=rExpression
opcode=OPCODE_STC # instrNoArgs
| opcode=OPCODE_CMC # instrNoArgs
| opcode=OPCODE_CMA # instrNoArgs
| opcode=OPCODE_DAA # instrNoArgs
| opcode=OPCODE_NOP # instrNoArgs
| opcode=OPCODE_RLC # instrNoArgs
| opcode=OPCODE_RRC # instrNoArgs
| opcode=OPCODE_RAL # instrNoArgs
| opcode=OPCODE_RAR # instrNoArgs
| opcode=OPCODE_XCHG # instrNoArgs
| opcode=OPCODE_XTHL # instrNoArgs
| opcode=OPCODE_SPHL # instrNoArgs
| opcode=OPCODE_PCHL # instrNoArgs
| opcode=OPCODE_RET # instrNoArgs
| opcode=OPCODE_RC # instrNoArgs
| opcode=OPCODE_RNC # instrNoArgs
| opcode=OPCODE_RZ # instrNoArgs
| opcode=OPCODE_RNZ # instrNoArgs
| opcode=OPCODE_RM # instrNoArgs
| opcode=OPCODE_RP # instrNoArgs
| opcode=OPCODE_RPE # instrNoArgs
| opcode=OPCODE_RPO # instrNoArgs
| opcode=OPCODE_EI # instrNoArgs
| opcode=OPCODE_DI # instrNoArgs
| opcode=OPCODE_HLT # instrNoArgs
| opcode=OPCODE_INR reg=rRegister # instrReg
| opcode=OPCODE_DCR reg=rRegister # instrReg
| opcode=OPCODE_ADD reg=rRegister # instrReg
| opcode=OPCODE_ADC reg=rRegister # instrReg
| opcode=OPCODE_SUB reg=rRegister # instrReg
| opcode=OPCODE_SBB reg=rRegister # instrReg
| opcode=OPCODE_ANA reg=rRegister # instrReg
| opcode=OPCODE_XRA reg=rRegister # instrReg
| opcode=OPCODE_ORA reg=rRegister # instrReg
| opcode=OPCODE_CMP reg=rRegister # instrReg
| opcode=OPCODE_MOV dst=rRegister SEP_COMMA src=rRegister # instrRegReg
| opcode=OPCODE_STAX regpair=(REG_B|REG_D) # instrRegPair
| opcode=OPCODE_LDAX regpair=(REG_B|REG_D) # instrRegPair
| opcode=OPCODE_PUSH regpair=(REG_B|REG_D|REG_H|REG_PSW) # instrRegPair
| opcode=OPCODE_POP regpair=(REG_B|REG_D|REG_H|REG_PSW) # instrRegPair
| opcode=OPCODE_DAD regpair=(REG_B|REG_D|REG_H|REG_SP) # instrRegPair
| opcode=OPCODE_INX regpair=(REG_B|REG_D|REG_H|REG_SP) # instrRegPair
| opcode=OPCODE_DCX regpair=(REG_B|REG_D|REG_H|REG_SP) # instrRegPair
| opcode=OPCODE_LXI regpair=(REG_B|REG_D|REG_H|REG_SP) SEP_COMMA expr=rExpression # instrRegPairExpr
| opcode=OPCODE_MVI reg=rRegister SEP_COMMA expr=rExpression # instrRegExpr
| opcode=OPCODE_ADI expr=rExpression # instrExpr
| opcode=OPCODE_ACI expr=rExpression # instrExpr
| opcode=OPCODE_SUI expr=rExpression # instrExpr
| opcode=OPCODE_SBI expr=rExpression # instrExpr
| opcode=OPCODE_ANI expr=rExpression # instrExpr
| opcode=OPCODE_XRI expr=rExpression # instrExpr
| opcode=OPCODE_ORI expr=rExpression # instrExpr
| opcode=OPCODE_CPI expr=rExpression # instrExpr
| opcode=OPCODE_STA expr=rExpression # instrExpr
| opcode=OPCODE_LDA expr=rExpression # instrExpr
| opcode=OPCODE_SHLD expr=rExpression # instrExpr
| opcode=OPCODE_LHLD expr=rExpression # instrExpr
| opcode=OPCODE_JMP expr=rExpression # instrExpr
| opcode=OPCODE_JC expr=rExpression # instrExpr
| opcode=OPCODE_JNC expr=rExpression # instrExpr
| opcode=OPCODE_JZ expr=rExpression # instrExpr
| opcode=OPCODE_JNZ expr=rExpression # instrExpr
| opcode=OPCODE_JM expr=rExpression # instrExpr
| opcode=OPCODE_JP expr=rExpression # instrExpr
| opcode=OPCODE_JPE expr=rExpression # instrExpr
| opcode=OPCODE_JPO expr=rExpression # instrExpr
| opcode=OPCODE_CALL expr=rExpression # instrExpr
| opcode=OPCODE_CC expr=rExpression # instrExpr
| opcode=OPCODE_CNC expr=rExpression # instrExpr
| opcode=OPCODE_CZ expr=rExpression # instrExpr
| opcode=OPCODE_CNZ expr=rExpression # instrExpr
| opcode=OPCODE_CM expr=rExpression # instrExpr
| opcode=OPCODE_CP expr=rExpression # instrExpr
| opcode=OPCODE_CPE expr=rExpression # instrExpr
| opcode=OPCODE_CPO expr=rExpression # instrExpr
| opcode=OPCODE_RST expr=rExpression # instrExpr
| opcode=OPCODE_IN expr=rExpression # instrExpr
| opcode=OPCODE_OUT expr=rExpression # instrExpr
;

rRegister:
Expand All @@ -115,28 +115,27 @@ rRegister:
;

rPseudoCode:
PREP_ORG expr=rExpression
| id=ID_IDENTIFIER PREP_EQU expr=rExpression
| id=ID_IDENTIFIER PREP_SET expr=rExpression
| PREP_IF expr=rExpression rComment EOL statement=rStatement EOL PREP_ENDIF
| id=ID_IDENTIFIER PREP_MACRO macro=rMacro? rComment EOL statement=rStatement PREP_ENDM
| id=ID_IDENTIFIER macroCall=rMacroCall
| PREP_INCLUDE filename=(LIT_STRING_1|LIT_STRING_2)
PREP_ORG expr=rExpression # pseudoOrg
| id=ID_IDENTIFIER PREP_EQU expr=rExpression # pseudoEqu
| id=ID_IDENTIFIER PREP_SET expr=rExpression # pseudoSet
| PREP_IF expr=rExpression rComment EOL statement=rStatement EOL PREP_ENDIF # pseudoIf
| id=ID_IDENTIFIER PREP_MACRO macro=rMacro? rComment EOL statement=rStatement PREP_ENDM # pseudoMacroDef
| id=ID_IDENTIFIER macroArgs=rMacroArguments? # pseudoMacroCall
| PREP_INCLUDE filename=(LIT_STRING_1|LIT_STRING_2) # pseudoInclude
;

rMacro:
id=ID_IDENTIFIER (SEP_COMMA ids=ID_IDENTIFIER)*
;

// todo: assign variables??
rMacroCall:
rMacroArguments:
expr=rExpression (SEP_COMMA exprs=rExpression)*
;

rData:
PREP_DB db=rDB
| PREP_DW dw=rDW
| PREP_DS ds=rExpression
PREP_DB data=rDB # dataDB
| PREP_DW data=rDW # dataDW
| PREP_DS data=rExpression # dataDS
;

rDB:
Expand All @@ -158,18 +157,18 @@ rDWdata:
;

rExpression:
SEP_LPAR expr=rExpression SEP_RPAR
| num=LIT_NUMBER
| num=LIT_HEXNUMBER_1
| num=LIT_HEXNUMBER_2
| num=LIT_OCTNUMBER
| num=LIT_BINNUMBER
| id=PREP_ADDR
| id=ID_IDENTIFIER
| unaryop=(OP_ADD|OP_SUBTRACT) expr=rExpression
| expr1=rExpression op=(OP_MULTIPLY|OP_DIVIDE|OP_MOD|OP_SHL|OP_SHR) expr2=rExpression
| expr1=rExpression op=(OP_ADD|OP_SUBTRACT) expr2=rExpression
| unaryop=OP_NOT expr=rExpression
| expr1=rExpression op=OP_AND expr2=rExpression
| expr1=rExpression op=(OP_OR|OP_XOR) expr2=rExpression
SEP_LPAR expr=rExpression SEP_RPAR # exprParens
| num=LIT_NUMBER # exprDec
| num=LIT_HEXNUMBER_1 # exprHex1
| num=LIT_HEXNUMBER_2 # exprHex2
| num=LIT_OCTNUMBER # exprOct
| num=LIT_BINNUMBER # exprBin
| PREP_ADDR # exprCurrentAddress
| id=ID_IDENTIFIER # exprId
| unaryop=(OP_ADD|OP_SUBTRACT) expr=rExpression # exprUnary
| expr1=rExpression op=(OP_MULTIPLY|OP_DIVIDE|OP_MOD|OP_SHL|OP_SHR) expr2=rExpression # exprInfix
| expr1=rExpression op=(OP_ADD|OP_SUBTRACT) expr2=rExpression # exprInfix
| unaryop=OP_NOT expr=rExpression # exprUnary
| expr1=rExpression op=OP_AND expr2=rExpression # exprInfix
| expr1=rExpression op=(OP_OR|OP_XOR) expr2=rExpression # exprInfix
;
2 changes: 1 addition & 1 deletion plugins/compiler/as-8080/src/main/gen/As8080Lexer.interp

Large diffs are not rendered by default.

Loading

0 comments on commit 0b4ed48

Please sign in to comment.