URL
https://opencores.org/ocsvn/zipcpu/zipcpu/trunk
Subversion Repositories zipcpu
[/] [zipcpu/] [trunk/] [sw/] [zasm/] [zasm.l] - Rev 13
Go to most recent revision | Compare with Previous | Blame | View Log
/*******************************************************************************
**
** Filename: zasm.l
**
** Project: Zip CPU -- a small, lightweight, RISC CPU core
**
** Purpose: The lexical analyzer for the assembler. This converts assembler
** input into tokens, to feed the parser.
**
**
** Creator: Dan Gisselquist, Ph.D.
** Gisselquist Tecnology, LLC
**
********************************************************************************
**
** Copyright (C) 2015, Gisselquist Technology, LLC
**
** This program is free software (firmware): you can redistribute it and/or
** modify it under the terms of the GNU General Public License as published
** by the Free Software Foundation, either version 3 of the License, or (at
** your option) any later version.
**
** This program is distributed in the hope that it will be useful, but WITHOUT
** ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
** for more details.
**
** You should have received a copy of the GNU General Public License along
** with this program. (It's in the $(ROOT)/doc directory, run make with no
** target there if the PDF file isn't present.) If not, see
** <http://www.gnu.org/licenses/> for a copy.
**
** License: GPL, v3, as defined and found on www.gnu.org,
** http://www.gnu.org/licenses/gpl.html
**
**
*******************************************************************************/
%{
#include <stdio.h>
#include "asmdata.h"
#include "zasm.tab.h"
extern "C" int yylex();
extern "C" int yywrap() { return 1;}
extern char *master_input_filename;
%}
%option yylineno
%option warn
%%
^"#line"[ \t]+[0-9]+[ \t]+["][^"]*["][ \t]*$ {
yylineno = atoi(&yytext[6]);
char *bg, *en;
bg = strchr(yytext, '\"')+1;
en = strchr(bg, '\"'); *en = '\0';
if ((master_input_filename == NULL)||(strcmp(master_input_filename, bg)!=0)) {
if (!master_input_filename) delete[] master_input_filename;
master_input_filename = new char[en-bg+2];
strcpy(master_input_filename, bg);
}
}
^"#line"[ \t]+[0-9]+[ \t]+$ { yylineno = atoi(&yytext[6]); }
[uU][rR]1[0-5] { yylval.u_reg=(ZPARSER::ZIPREG)(26+yytext[3]-'0');return REG; }
[sS][rR]1[0-5] { yylval.u_reg=(ZPARSER::ZIPREG)(10+yytext[3]-'0');return REG; }
[rR]1[0-5] { yylval.u_reg=(ZPARSER::ZIPREG)(10+yytext[2]-'0');return REG; }
[uU][rR][0-9] { yylval.u_reg=(ZPARSER::ZIPREG)(16+yytext[2]-'0');return REG; }
[sS][rR][0-9] { yylval.u_reg=(ZPARSER::ZIPREG)( yytext[2]-'0');return REG; }
[rR][0-9] { yylval.u_reg=(ZPARSER::ZIPREG)( yytext[1]-'0');return REG; }
[uU][pP][cC] { yylval.u_reg = ZPARSER::ZIP_uPC; return REG; }
[sS][pP][cC] { yylval.u_reg = ZPARSER::ZIP_PC; return REG; }
[pP][cC] { yylval.u_reg = ZPARSER::ZIP_PC; return REG; }
[uU][cC][cC] { yylval.u_reg = ZPARSER::ZIP_uCC; return REG; }
[sS][cC][cC] { yylval.u_reg = ZPARSER::ZIP_CC; return REG; }
[cC][cC] { yylval.u_reg = ZPARSER::ZIP_CC; return REG; }
[uU][sS][pP] { yylval.u_reg = ZPARSER::ZIP_uSP; return REG; }
[sS][sS][pP] { yylval.u_reg = ZPARSER::ZIP_SP; return REG; }
[sS][pP] { yylval.u_reg = ZPARSER::ZIP_SP; return REG; }
[bB][rR][aA] { yylval.u_op = OP_BRA; return BRANCHOP; }
[bB][rR][zZ] { yylval.u_op = OP_BZ; return BRANCHOP; }
[bB][zZ] { yylval.u_op = OP_BZ; return BRANCHOP; }
[bB][nN][zZ] { yylval.u_op = OP_BNZ; return BRANCHOP; }
[bB][nN][eE] { yylval.u_op = OP_BNZ; return BRANCHOP; }
[bB][gG][eE] { yylval.u_op = OP_BGE; return BRANCHOP; }
[bB][gG][tT] { yylval.u_op = OP_BGT; return BRANCHOP; }
[bB][gG] { yylval.u_op = OP_BGT; return BRANCHOP; }
[bB][lL][tT] { yylval.u_op = OP_BLT; return BRANCHOP; }
[bB][nN] { yylval.u_op = OP_BLT; return BRANCHOP; }
[bB][rR][cC] { yylval.u_op = OP_BRC; return BRANCHOP; }
[bB][cC] { yylval.u_op = OP_BRC; return BRANCHOP; }
[bB][rR][vV] { yylval.u_op = OP_BRV; return BRANCHOP; }
[bB][vV] { yylval.u_op = OP_BRV; return BRANCHOP; }
[cC][lL][rR] { yylval.u_op = OP_CLR; return SINGLOP; }
[cC][lL][rR][fF] {yylval.u_op = OP_CLRF;return SINGLOP; }
[iI][nN][tT] { yylval.u_op = OP_TRAP;return SINGLOP; }
[tT][rR][aA][pP] {yylval.u_op = OP_TRAP;return SINGLOP; }
[jJ][mM][pP] { yylval.u_op = OP_JMP; return SINGLOP; }
[lL][jJ][mM][pP] {yylval.u_op = OP_LJMP;return SINGLOP; }
[nN][oO][tT] { yylval.u_op = OP_NOT; return SINGLOP; }
[cC][mM][pP] { yylval.u_op = OP_CMP; return DUALOP; }
[tT][sS][tT] { yylval.u_op = OP_TST; return DUALOP; }
[mM][oO][vV] { yylval.u_op = OP_MOV; return DUALOP; }
[lL][dD][iI] { yylval.u_op = OP_LDI; return LDIOP; }
[lL][dD][iI][hH][iI] { yylval.u_op =OP_LDIHI; return LDHLOP; }
[lL][dD][iI][lL][oO] { yylval.u_op =OP_LDILO; return LDHLOP; }
[mM][pP][yY] { yylval.u_op = OP_MPY; return DUALOP; }
[rR][oO][lL] { yylval.u_op = OP_ROL; return DUALOP; }
[sS][uU][bB] { yylval.u_op = OP_SUB; return DUALOP; }
[aA][nN][dD] { yylval.u_op = OP_AND; return DUALOP; }
[aA][dD][dD] { yylval.u_op = OP_ADD; return DUALOP; }
[oO][rR] { yylval.u_op = OP_OR; return DUALOP;; }
[xX][oO][rR] { yylval.u_op = OP_XOR; return DUALOP; }
[lL][sS][lL] { yylval.u_op = OP_LSL; return DUALOP; }
[aA][sS][rR] { yylval.u_op = OP_ASR; return DUALOP; }
[lL][sS][rR] { yylval.u_op = OP_LSR; return DUALOP; }
[lL][oO][dD] { yylval.u_op = OP_LOD; return LOADOP; }
[sS][tT][oO] { yylval.u_op = OP_STO; return STOROP; }
[hH][aA][lL][tT] { yylval.u_op = OP_HALT; return BAREOP; }
[wW][aA][iI][tT] { yylval.u_op = OP_HALT; return BAREOP; }
[rR][tT][uU] { yylval.u_op = OP_RTU; return BAREOP; }
[nN][oO][pP] { yylval.u_op = OP_NOOP; return BAREOP; }
[nN][oO][oO][pP] { yylval.u_op = OP_NOOP; return BAREOP; }
[bB][rR][eE][aA][kK] { yylval.u_op = OP_BREAK; return BAREOP; }
[bB][rR][kK] { yylval.u_op = OP_BREAK; return BAREOP; }
[bB][uU][sS][yY] { yylval.u_op = OP_BUSY; return BAREOP; }
[eE][qQ][uU] { return EQU; }
[fF][iI][lL][lL] { return FILL; }
[wW][oO][rR][dD] { return WORD; }
"__"[hH][eE][rR][eE]"__" { return HERE; }
[\.][dD][aA][tT] { return WORD; }
[\.][zZ]/[ \t\n] { yylval.u_cond = ZPARSER::ZIPC_Z; return COND; }
[\.][nN][eE]/[ \t\n] { yylval.u_cond = ZPARSER::ZIPC_NZ; return COND; }
[\.][nN][zZ]/[ \t\n] { yylval.u_cond = ZPARSER::ZIPC_NZ; return COND; }
[\.][gG][eE]/[ \t\n] { yylval.u_cond = ZPARSER::ZIPC_GE; return COND; }
[\.][gG][tT]/[ \t\n] { yylval.u_cond = ZPARSER::ZIPC_GT; return COND; }
[\.][lL][tT]/[ \t\n] { yylval.u_cond = ZPARSER::ZIPC_LT; return COND; }
[\.][nN]/[ \t\n] { yylval.u_cond = ZPARSER::ZIPC_LT; return COND; }
[\.][cC]/[ \t\n] { yylval.u_cond = ZPARSER::ZIPC_C; return COND; }
[\.][vV]/[ \t\n] { yylval.u_cond = ZPARSER::ZIPC_V; return COND; }
[_A-Za-z][_a-zA-Z0-9]* { yylval.u_id = strdup(yytext); return IDENTIFIER; }
"$"?[-]?0[xX][0-9A-Fa-f]+ { yylval.u_ival = strtoul(yytext+(((*yytext)=='$')?1:0),NULL,16);return INT;}
"$"?[-]?0[0-7]+ { yylval.u_ival = strtoul(yytext+(((*yytext)=='$')?1:0),NULL, 8);return INT;}
"$"?[-]?[1-9][0-9]* { yylval.u_ival = strtoul(yytext+(((*yytext)=='$')?1:0),NULL,10);return INT;}
"$"?[-]?[1-9A-Fa-f][0-9A-Fa-f]*h {yylval.u_ival=strtoul(yytext+(((*yytext)=='$')?1:0),NULL,16); return INT;}
"$"?[-]?[0-7]+o { yylval.u_ival = strtoul(yytext+(((*yytext)=='$')?1:0),NULL, 8);return INT;}
"$"?"0" { yylval.u_ival = 0;return INT;}
"$" { return DOLLAR; }
"," { return COMMA; }
"+" { return PLUS; }
"-" { return MINUS; }
"*" { return TIMES; }
"||" { return BOOLEANOR; }
"|" { return BITWISEOR; }
"&&" { return BOOLEANAND; }
"&" { return BITWISEAND; }
"^" { return BITWISEXOR; }
":" { return COLON; }
"." { return DOT; }
[ \t]+ { }
[(] { return '('; }
[)] { return ')'; }
\n.* { if (linecp) free(linecp); linecp = strdup(&yytext[1]); yyless(1); return '\n'; }
%%
Go to most recent revision | Compare with Previous | Blame | View Log