diff options
Diffstat (limited to 'lexer.l')
-rw-r--r-- | lexer.l | 61 |
1 files changed, 61 insertions, 0 deletions
@@ -0,0 +1,61 @@ +%{ + +#include "parser.h" + +%} + +%option outfile="lexer.c" header-file="lexer.h" +%option noyywrap never-interactive + +%s inst +%s args + +COMMENT #[^\n]* +SP [ \t] +EOI [ \t\n#] + +%% + +<INITIAL>{SP}+ { BEGIN(inst); return T_SPACE; } + +<inst>add/{EOI} { BEGIN(args); return T_ADD; } +<inst>sub/{EOI} { BEGIN(args); return T_SUB; } +<inst>mul/{EOI} { BEGIN(args); return T_MUL; } +<inst>div/{EOI} { BEGIN(args); return T_DIV; } +<inst>and/{EOI} { BEGIN(args); return T_AND; } +<inst>or/{EOI} { BEGIN(args); return T_OR; } +<inst>xor/{EOI} { BEGIN(args); return T_XOR; } +<inst>lsl/{EOI} { BEGIN(args); return T_LSL; } +<inst>lsr/{EOI} { BEGIN(args); return T_LSR; } +<inst>asl/{EOI} { BEGIN(args); return T_ASL; } +<inst>asr/{EOI} { BEGIN(args); return T_ASR; } +<inst>rol/{EOI} { BEGIN(args); return T_ROL; } +<inst>ror/{EOI} { BEGIN(args); return T_ROR; } +<inst>not/{EOI} { BEGIN(args); return T_NOT; } +<inst>neg/{EOI} { BEGIN(args); return T_NEG; } +<inst>btc/{EOI} { BEGIN(args); return T_BTC; } +<inst>bts/{EOI} { BEGIN(args); return T_BTS; } +<inst>mov/{EOI} { BEGIN(args); return T_MOV; } +<inst>st\.b/{EOI} { BEGIN(args); return T_ST_B; } +<inst>st\.w/{EOI} { BEGIN(args); return T_ST_W; } +<inst>ld\.bl/{EOI} { BEGIN(args); return T_LD_BL; } +<inst>ld\.bh/{EOI} { BEGIN(args); return T_LD_BH; } +<inst>ld\.w/{EOI} { BEGIN(args); return T_LD_W; } +<inst>ldi\.bl/{EOI} { BEGIN(args); return T_LDI_BL; } +<inst>ldi\.bh/{EOI} { BEGIN(args); return T_LDI_BH; } +<inst>beq/{EOI} { BEGIN(args); return T_BEQ; } +<inst>bne/{EOI} { BEGIN(args); return T_BNE; } +<inst>bgt/{EOI} { BEGIN(args); return T_BGT; } +<inst>bge/{EOI} { BEGIN(args); return T_BGE; } +<inst>blt/{EOI} { BEGIN(args); return T_BLT; } +<inst>ble/{EOI} { BEGIN(args); return T_BLE; } +<inst>bra/{EOI} { BEGIN(args); return T_BRA; } +<inst>jmp/{EOI} { BEGIN(args); return T_JMP; } +<inst>addpc/{EOI} { BEGIN(args); return T_ADDPC; } +<inst>nop/{EOI} { BEGIN(args); return T_NOP; } + +{SP}*{COMMENT}?\n { BEGIN(INITIAL); return T_EOL; } +{SP}*{COMMENT} { BEGIN(INITIAL); return T_SPACE; } +{SP}+ { return T_SPACE; } + +%% |