diff options
author | Bobby Bingham <koorogi@koorogi.info> | 2017-01-12 20:05:45 -0600 |
---|---|---|
committer | Bobby Bingham <koorogi@koorogi.info> | 2017-01-15 23:18:52 -0600 |
commit | cf366387449dcf9d34875a7d76f3b79c1e231d6f (patch) | |
tree | b892febf08e3c5791e414c9cdc011477a9420ae1 /lexer.l | |
parent | 239ee7648658b77b217f5c8142ef887612516af4 (diff) |
nqasm: Initial stab at a lexer and parser
So far, this only understands instructions, but no operands or labels. It
doesn't handle bad input gracefully. It's just enough to test the basics.
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; } + +%% |