casm.l |
casm.y |
casm.h |
Makefile
%{
#include<string.h>
int zeile = 1;
unsigned int horner(char *, int);
%}
Whitespace [" "|"\t"]+
Komma {Whitespace}*[","]{Whitespace}*
Kommentar [";"]+.*
imm [0-9]+d?{Whitespace}*{Kommentar}*
hex [0-9A-F]+h{Whitespace}*{Kommentar}*
bin [0-1]+b{Whitespace}*{Kommentar}*
oct [0-7]+p{Whitespace}*{Kommentar}*
reg r[0-9]?[0-9]{Whitespace}*{Kommentar}*
LE ("\n")|("\r\n")
lab "("[A-Z]+[A-Z0-9_]*")"{Whitespace}*{Kommentar}*
str \'.+\'{Whitespace}*{Kommentar}*
%%
{LE} { zeile++; return(LE); }
{Whitespace} return(WS);
{Komma} return(KM);
{Kommentar} return(RM);
{reg} {
sscanf(++yytext, "%d", &yylval) ;
if (yylval > 26) {
switch(yylval) {
case 27: printf("Warning: Overwriting RTA-register!\n"); return(reg);
case 28: printf("Warning: Overwriting RTB-register!\n"); return(reg);
case 29: printf("Warning: Overwriting RPC-register!\n"); return(reg);
case 30: printf("Warning: Overwriting RRE-register!\n"); return(reg);
case 31: printf("Warning: Overwriting RRI-register!\n"); return(reg);
default: yyerror("Register out of range!"); return(ERROR);
}
}
return(reg);
}
{imm} { sscanf(yytext, "%d", &yylval); return(imm); }
{hex} { sscanf(yytext, "%x", &yylval); return(imm); }
{bin} { yylval = horner(yytext,2); return(imm); }
{oct} { yylval = horner(yytext,8); return(imm); }
{lab} return(lab);
{str} return(str);
DW return(DW);
LW return(LW);
SW return(SW);
PDI return(PDI);
PDO return(PDO);
HI return(HI);
SET return(SET);
XCH return(XCH);
ADD return(ADD);
SUB return(SUB);
MUL return(MUL);
DIV return(DIV);
MOD return(MOD);
PCA return(PCA);
PCS return(PCS);
AND return(AND);
OR return(OR);
XOR return(XOR);
SHL return(SHL);
SHR return(SHR);
RTL return(RTL);
RTR return(RTR);
FBS return(FBS);
CBS return(CBS);
CST return(CST);
CGT return(CGT);
CE return(CE);
JMP return(JMP);
JMR return(JMR);
BEZ return(BEZ);
BGZ return(BGZ);
ISP return(ISP);
ISD return(ISD);
IRD return(IRD);
IRE return(IRE);
LDA return(LDA);
SVA return(SVA);
DTA return(DTA);
RHI { yylval=26; return(reg); }
RTA { yylval=27; return(reg); }
RTB { yylval=28; return(reg); }
RPC { yylval=29; return(reg); }
RRE { yylval=30; return(reg); }
RRI { yylval=31; return(reg); }
. return(ERROR);
%%
unsigned int horner(char *zahl, int basis) {
unsigned int i, temp = 0;
for (i = 0; zahl[i + 1] >= '0' && zahl[i + 1] <= '9'; temp = (temp + zahl[i++] - 48) * basis);
return temp + zahl[i] - 48;
};