OpenCores
URL https://opencores.org/ocsvn/zipcpu/zipcpu/trunk

Subversion Repositories zipcpu

[/] [zipcpu/] [trunk/] [sw/] [zasm/] [zasm.l] - Diff between revs 46 and 54

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 46 Rev 54
Line 42... Line 42...
#include "zasm.tab.h"
#include "zasm.tab.h"
 
 
extern "C" int yylex();
extern "C" int yylex();
extern "C" int  yywrap() { return 1;}
extern "C" int  yywrap() { return 1;}
extern  char *master_input_filename;
extern  char *master_input_filename;
 
extern  int     decode_char_int(const char *str);
%}
%}
 
 
%option yylineno
%option yylineno
%option warn
%option warn
 
 
Line 158... Line 159...
"$"?[-]?0[xX][0-9A-Fa-f]+ { yylval.u_ival = strtoul(yytext+(((*yytext)=='$')?1:0),NULL,16);return INT;}
"$"?[-]?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;}
"$"?[-]?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-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;}
"$"?[-]?[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-7]+o         { yylval.u_ival = strtoul(yytext+(((*yytext)=='$')?1:0),NULL, 8);return INT;}
"\'"[^\\\']"\'"         { yylval.u_ival = yytext[1]&0x0ff; return INT; }
"\'"(("\\\'")|([^'\\])|("\\"[0abfnrtv])|("\\\\")|("\\\"")){1,4}"\'" {
"\'\\"[abnr\\\'\"]"\'"          {
                yylval.u_ival = decode_char_int(&yytext[1]); return INT; }
                yylval.u_ival = yytext[2];
 
                if (yytext[2] == 'a') yylval.u_ival = '\a';
 
                else if (yytext[2] == 'b') yylval.u_ival = '\b';
 
                else if (yytext[2] == 'f') yylval.u_ival = '\f';
 
                else if (yytext[2] == 'n') yylval.u_ival = '\n';
 
                else if (yytext[2] == 'r') yylval.u_ival = '\r';
 
                else if (yytext[2] == 't') yylval.u_ival = '\t';
 
                else if (yytext[2] == 'v') yylval.u_ival = '\v';
 
                else if (yytext[2] == '0') yylval.u_ival = '\0';
 
                else if (yytext[2] == '\\') yylval.u_ival = '\\';
 
                else if (yytext[2] == '\'') yylval.u_ival = '\'';
 
                else if (yytext[2] == '\"') yylval.u_ival = '\"';
 
                return INT; }
 
"\'"[^\\\'][^\\\']"\'"          { yylval.u_ival = ((yytext[1]&0x0ff)<<8)+(yytext[2]&0x0ff); return INT; }
 
"\'"[^\\\'][^\\\'][^\\\']"\'"           { yylval.u_ival = ((yytext[1]&0x0ff)<<16)
 
                                        +((yytext[2]&0x0ff)<<8)
 
                                        +(yytext[3]&0x0ff); return INT; }
 
"\'"[^\\\'][^\\\'][^\\\'][^\\\']"\'"    { yylval.u_ival = ((yytext[1]&0x0ff)<<24)
 
                                        +((yytext[2]&0x0ff)<<16)
 
                                        +((yytext[3]&0x0ff)<<8)
 
                                        +(yytext[4]&0x0ff); return INT; }
 
"$"?"0"           { yylval.u_ival = 0;return INT;}
"$"?"0"           { yylval.u_ival = 0;return INT;}
"$"             { return DOLLAR; }
"$"             { return DOLLAR; }
","             { return COMMA; }
","             { return COMMA; }
"+"             { return PLUS; }
"+"             { return PLUS; }
"-"             { return MINUS; }
"-"             { return MINUS; }
Line 202... Line 182...
[)]             { return ')'; }
[)]             { return ')'; }
\n.*            { if (linecp) free(linecp); linecp = strdup(&yytext[1]); yyless(1); return '\n'; }
\n.*            { if (linecp) free(linecp); linecp = strdup(&yytext[1]); yyless(1); return '\n'; }
 
 
%%
%%
 
 
 
int     decode_char_int(const char *str) {
 
        unsigned r = 0;
 
        // fprintf(stderr, "Decoding character string: \'%s\n", str);
 
        while((*str)&&('\'' != (*str))) {
 
                if ('\\' == (*str)) {
 
                        // Process escape characters
 
                        str++;
 
                        if ('\0' != (*str)) {
 
                                r<<=8;
 
                                switch(*str) {
 
                                case '0': break;
 
                                case  'a': r |= '\a'; break;
 
                                case  'b': r |= '\b'; break;
 
                                case  'n': r |= '\n'; break;
 
                                case  'f': r |= '\f'; break;
 
                                case  'r': r |= '\r'; break;
 
                                case  't': r |= '\t'; break;
 
                                case  'v': r |= '\v'; break;
 
                                case '\'': r |= '\''; break;
 
                                case '\"': r |= '\"'; break;
 
                                case '\\': r |= '\\'; break;
 
                                } str++;
 
                        }
 
                } else {
 
                        r = (r<<8)|(*str);
 
                        str++;
 
                }
 
        } return r;
 
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.