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

Subversion Repositories zipcpu

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

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

Rev 46 Rev 53
Line 69... Line 69...
void    stb_addmacro(const char *value);
void    stb_addmacro(const char *value);
bool    stb_isdefined(const char *str);
bool    stb_isdefined(const char *str);
const char      *stb_getdefn(const char *str);
const char      *stb_getdefn(const char *str);
%}
%}
%x DEF DFA DFV DFV_EOL INDEF IFDEFV INNOTDEF NODEF NVRDEF COMMENT INSTRUCT
%x DEF DFA DFV DFV_EOL INDEF IFDEFV INNOTDEF NODEF NVRDEF COMMENT INSTRUCT
%x INDEF_EOL INNOTDEF_EOL GETSTRUCTID
%x INDEF_EOL INNOTDEF_EOL GETSTRUCTID NVRDEF_EOL DONTDEF
%option noyywrap
%option noyywrap
%option stack
%option stack
ID [_:A-Za-z][_:A-Za-z0-9]*
ID [_:A-Za-z][_:A-Za-z0-9]*
IDDOT {ID}("."{ID})*
IDDOT {ID}("."{ID})*
 
 
%%
%%
"*/"            { yy_pop_state(); }
"*/"            { yy_pop_state(); }
[^*]+           { /* Ignore comments */ }
[^*\n]+ { /* Ignore comments */ }
"*"+[^/]        { /* Ignore comments */ }
"*"+[^/]        { /* Ignore comments */ }
^"#include"[ \t]+\"[^\"]+\"     {
^"#include"[ \t]+\"[^\n\"]+\"   {
                char *ptr = &yytext[9], *start, *end, *str;
                char *ptr = &yytext[9], *start, *end, *str;
                while(isspace(*ptr))
                while(isspace(*ptr))
                        ptr++;
                        ptr++;
                start = ++ptr;
                start = ++ptr;
                ptr++;
                ptr++;
Line 100... Line 100...
                // fprintf(stderr, "Defining \'%s\'\n", yytext);
                // fprintf(stderr, "Defining \'%s\'\n", yytext);
                stb_define(yytext);
                stb_define(yytext);
                BEGIN DFV;
                BEGIN DFV;
        }
        }
{IDDOT}/[(]     { stb_define(yytext); BEGIN DFA; }
{IDDOT}/[(]     { stb_define(yytext); BEGIN DFA; }
"("[^)]+")"                             {
"("[^)\n]+")"                           {
                /* Process macro arguments */
                /* Process macro arguments */
                stb_args(yytext);
                stb_args(yytext);
                BEGIN DFV;
                BEGIN DFV;
        }
        }
^[ \t]+ { stb_macro(yytext); /* Replicate initial spaces */ }
^[ \t]+ { stb_macro(yytext); /* Replicate initial spaces */ }
Line 152... Line 152...
        }
        }
[0-9A-Fa-f]+[hH]        {/* Get any hexadecimal constants */
[0-9A-Fa-f]+[hH]        {/* Get any hexadecimal constants */
                // fprintf(stderr, "C: Adding to macro %s\n", yytext);
                // fprintf(stderr, "C: Adding to macro %s\n", yytext);
                stb_macro(yytext);
                stb_macro(yytext);
        }
        }
[0-7]+[oO]      {/* Get any hexadecimal constants */
[0-7]+[oO]      {/* Get any octal constants */
                // fprintf(stderr, "D: Adding to macro %s\n", yytext);
                // fprintf(stderr, "D: Adding to macro %s\n", yytext);
                stb_macro(yytext);
                stb_macro(yytext);
        }
        }
[0-9]+  {/* Get any hexadecimal constants */
[0-9]+  {/* Get any decimal constants */
                // fprintf(stderr, "E: Adding to macro %s\n", yytext);
                // fprintf(stderr, "E: Adding to macro %s\n", yytext);
                stb_macro(yytext);
                stb_macro(yytext);
        }
        }
[ \t]*((;|"//").*)?$    {/* Parse to end of line, get value for our define */
[ \t]*((;|"//").*)?$    {/* Parse to end of line, get value for our define */
                yy_pop_state();
                yy_pop_state();
        }
        }
[ \t]*"\\"[ \t]*((;|"//").*)?\n {/* Continue onto next line */
[ \t]*"\\"[ \t]*((;|"//").*)?\n {/* Continue onto next line */
                fprintf(yyout, "\n"); mark_line(); yylineno++;
                fprintf(yyout, "\n"); mark_line(); yylineno++;
                stb_macro("\n");
                stb_macro("\n");
        }
        }
 
^"#define".*$   { yy_push_state(DONTDEF); }
 
"\\"[ \t]*((;"//").*)?\n        {/* Continue onto next line */
 
                fprintf(yyout, "\n"); mark_line(); yylineno++; }
 
[a-zA-Z0-9_,.()]*       { }
 
[ \t]*                  { }
 
((;|"//").*)?$          { yy_pop_state(); }
 
"\\"[ \t]*((;|"//").*)?\n       {/* Continue onto next line */
 
                fprintf(yyout, "\n"); mark_line(); yylineno++; }
^[ \t]+.[dD][aA][tT][aA]?       { fprintf(yyout, "\tWORD"); }
^[ \t]+.[dD][aA][tT][aA]?       { fprintf(yyout, "\tWORD"); }
^"#defcont"[ \t]+       { yy_push_state(DFV); }
^"#defcont"[ \t]+       {
^"#ifdef"[ \t]* { ndef = 0; yy_push_state(IFDEFV); }
                yy_push_state(DFV); }
^"#ifndef"[ \t]*        { ndef = 1; yy_push_state(IFDEFV); }
^"#ifdef"[ \t]* { ndef = 0;
 
                yy_push_state(IFDEFV); }
 
^"#ifndef"[ \t]*        { ndef = 1;
 
                yy_push_state(IFDEFV); }
 
^"#ifdef"[ \t]* { ndef = 2;
 
                yy_push_state(IFDEFV); }
 
^"#ifndef"[ \t]*        { ndef = 2;
 
                yy_push_state(IFDEFV); }
{IDDOT} {
{IDDOT} {
                bool    known = stb_isdefined(yytext);
                bool    known = stb_isdefined(yytext);
                if ( ((known)&&(ndef==0)) || ((!known)&&(ndef!=0)) ) {
                if (ndef == 2) {
 
                        BEGIN NVRDEF_EOL;
 
                } else if ( ((known)&&(ndef==0)) || ((!known)&&(ndef!=0)) ) {
                        BEGIN INDEF_EOL;
                        BEGIN INDEF_EOL;
                } else {
                } else {
                        BEGIN INNOTDEF_EOL;
                        BEGIN INNOTDEF_EOL;
                }
                }
        }
        }
Line 187... Line 204...
        /* ^"#elsif"[ \t]*      { yy_pop_state(); yy_push_state(IFDEFE); } */
        /* ^"#elsif"[ \t]*      { yy_pop_state(); yy_push_state(IFDEFE); } */
[ \t]*$         { BEGIN INDEF; }
[ \t]*$         { BEGIN INDEF; }
(;|"//").*$             { BEGIN INDEF; }
(;|"//").*$             { BEGIN INDEF; }
[ \t]*$         { BEGIN INNOTDEF; }
[ \t]*$         { BEGIN INNOTDEF; }
(;|"//").*$     { BEGIN INNOTDEF; }
(;|"//").*$     { BEGIN INNOTDEF; }
[^ \t\n].*$             { BEGIN INDEF; fprintf(stderr, "WARNING! Unexpected characters on IFDEF line, \'%s\'\n", yytext); mark_line(); }
[ \t]*$         { BEGIN NVRDEF; }
[^ \t\n].*$     { BEGIN INNOTDEF; fprintf(stderr, "WARNING! Unexpected characters on IFNDEF line, %s\n", yytext); mark_line(); }
(;|"//").*$             { BEGIN NVRDEF; }
 
[^ \t\n].*$             { BEGIN INDEF; mark_line(); }
 
[^ \t\n].*$     { BEGIN INNOTDEF; mark_line(); }
^"#else"[ \t]*((;|"//").*)?$    { BEGIN NODEF; }
^"#else"[ \t]*((;|"//").*)?$    { BEGIN NODEF; }
^"#else"[ \t]*((;|"//").*)?$            { BEGIN INDEF; }
^"#else"[ \t]*((;|"//").*)?$            { BEGIN INDEF; }
(.*)                    { }
^[^#\n]([^\n]*)$                { /* Skip text */ }
^"#elsif"[ \t]*         { BEGIN NVRDEF; }
^"#elsif"[ \t]*         { BEGIN NVRDEF; }
^"#endif"[ \t]*((;|"//").*)?$   { yy_pop_state(); }
^"#endif"[ \t]*((;|"//").*)?$   {
 
                                yy_pop_state(); }
^"#endif"[ \t]*"/*"     { BEGIN COMMENT; }
^"#endif"[ \t]*"/*"     { BEGIN COMMENT; }
<*>^"#endif"[ \t]*         { fprintf(stderr, "ERR: Unknown endif!!\n");}
^"#endif"       { yy_pop_state(); }
^"#struct"[ \t]*        {
<*>^"#ifdef"[ \t]*         { fprintf(stderr, "ERR: Line %d, Unknown ifdef!! (state = %d)\n", yylineno, YYSTATE);}
                yy_push_state(GETSTRUCTID); structno  = 0; }
<*>^"#else"[ \t]*          { fprintf(stderr, "ERR: Line %d, Unknown else!! (state = %d)\n", yylineno, YYSTATE);}
<*>^"#"{ID}[ \t]*          { fprintf(stderr, "ERR: Unrecognized preprocessor instruction, %s\n", yytext);}
<*>^"#endif"[ \t]*         { fprintf(stderr, "ERR: Line %d, Unknown endif!! (state = %d)\n", yylineno, YYSTATE);}
 
^"#struct"[ \t]*        { yy_push_state(GETSTRUCTID); structno  = 0; }
 
<*>^"#"{ID}[ \t]*          {
 
        fprintf(stderr, "ERR: Line %d, unrecognized preprocessor instruction, \'%s\' (state = %d)\n",
 
                        yylineno, yytext, YYSTATE);
 
        }
{ID}/[ \t\n;/]  { BEGIN INSTRUCT;
{ID}/[ \t\n;/]  { BEGIN INSTRUCT;
                structid = strdup(yytext);
                structid = strdup(yytext);
                }
                }
{ID}("."{ID})*  {
{ID}("."{ID})*  {
                fprintf(yyout, "\t%s.%s\tequ\t%d", structid, yytext, structno++); }
                fprintf(yyout, "\t%s.%s\tequ\t%d", structid, yytext, structno++); }
^"#endstruct".*$        { yy_pop_state(); }
^"#endstruct".*$        { yy_pop_state(); }
        /* Not yet: ^"#struct"[ \t]*    {}      */
        /* Not yet: ^"#struct"[ \t]*    {}      */
        /* Not yet: ^"#endstruct"[ \t]* {}      */
        /* Not yet: ^"#endstruct"[ \t]* {}      */
        /* Not yet: ^"#seg"[ \t]*       {}      */
        /* Not yet: ^"#seg"[ \t]*       {}      */
.*              { /* Ignore everything in these states*/ }
 
{ID}/[^(]       {
{ID}/[^(]       {
                if (stb_isdefined(yytext))
                if (stb_isdefined(yytext))
                        fprintf(yyout, "%s", stb_getdefn(yytext));
                        fprintf(yyout, "%s", stb_getdefn(yytext));
                else
                else
                        fprintf(yyout, "%s", yytext);
                        fprintf(yyout, "%s", yytext);
Line 243... Line 267...
<*>"#error".*$             { fprintf(stderr, "ERROR: %s\n", &yytext[8]); exit(-1); }
<*>"#error".*$             { fprintf(stderr, "ERROR: %s\n", &yytext[8]); exit(-1); }
<*>"/*"                    { yy_push_state(COMMENT); }
<*>"/*"                    { yy_push_state(COMMENT); }
<*>[ \t]+          { ECHO; }
<*>[ \t]+          { ECHO; }
<*>\n                      { ECHO; yylineno++; mark_line(); }
<*>\n                      { ECHO; yylineno++; mark_line(); }
        /* <*>.                    { printf("Unmatched \'%c\'\n", yytext[0]); } */
        /* <*>.                    { printf("Unmatched \'%c\'\n", yytext[0]); } */
<>       { fprintf(stderr, "Unexpected EOF!  Expecting #endif\n"); }
<>       { fprintf(stderr, "Unexpected EOF!  Expecting #endif\n"); yyterminate(); }
<>               { fprintf(stderr, "Unexpected EOF!  Expecting #endif\n"); }
<>               { fprintf(stderr, "Unexpected EOF!  Expecting #endif\n"); yyterminate(); }
<>       { fprintf(stderr, "Unexpected EOF!  Expecting */\n"); }
<>       { fprintf(stderr, "Unexpected EOF!  Expecting */\n"); yyterminate(); }
<>       { fprintf(stderr, "Unexpected EOF!  Expecting #endstruct\n"); }
<>       { fprintf(stderr, "Unexpected EOF!  Expecting #endstruct\n"); yyterminate(); }
<>       { fprintf(stderr, "Unexpected EOF!  Expecting #struct ID, then #endstruct\n"); }
<>       { fprintf(stderr, "Unexpected EOF!  Expecting #struct ID, then #endstruct\n"); yyterminate(); }
<> { fprintf(stderr, "Unexpected EOF!  Expecting end of line\n"); }
<> { fprintf(stderr, "Unexpected EOF!  Expecting end of line\n"); yyterminate(); }
 
 
<>       { if (end_of_file()) yyterminate(); }
<>       { if (end_of_file()) yyterminate(); }
 
 
%%
%%
 
 
class   SYMTABLE_ACTION {
class   SYMTABLE_ACTION {
Line 674... Line 698...
                        } else {
                        } else {
                                char    *dptr, *colonp;
                                char    *dptr, *colonp;
                                char *pathcpy = new char[strlen(pathptr)+8192];
                                char *pathcpy = new char[strlen(pathptr)+8192];
                                strcpy(pathcpy, pathptr);
                                strcpy(pathcpy, pathptr);
 
 
                                fprintf(stderr, "ZIPINC := %s\n", pathptr);
                                // fprintf(stderr, "ZIPINC := %s\n", pathptr);
                                dptr = pathptr;
                                dptr = pathptr;
                                while((!m_fp)&&(NULL != (colonp = strchr(dptr, ':')))) {
                                while((!m_fp)&&(NULL != (colonp = strchr(dptr, ':')))) {
                                        strncpy(pathcpy, dptr, colonp-pathptr);
                                        strncpy(pathcpy, dptr, colonp-pathptr);
                                        strcat(pathcpy, "/");
                                        strcat(pathcpy, "/");
                                        strcat(pathcpy, fname);
                                        strcat(pathcpy, fname);
                                        fprintf(stderr, "Looking for include file, %s\n", pathcpy);
                                        // fprintf(stderr, "Looking for include file, %s\n", pathcpy);
                                        if (access(fname, R_OK)==0)
                                        if (access(fname, R_OK)==0)
                                                m_fp = fopen(pathcpy, "r");
                                                m_fp = fopen(pathcpy, "r");
                                        dptr = colonp+1;
                                        dptr = colonp+1;
                                } if ((!m_fp)&&(*dptr)) {
                                } if ((!m_fp)&&(*dptr)) {
                                        strcpy(pathcpy, dptr);
                                        strcpy(pathcpy, dptr);
                                        strcat(pathcpy, "/");
                                        strcat(pathcpy, "/");
                                        strcat(pathcpy, fname);
                                        strcat(pathcpy, fname);
                                        fprintf(stderr, "Looking for include file, %s\n", pathcpy);
                                        // fprintf(stderr, "Looking for include file, %s\n", pathcpy);
                                        m_fp = fopen(pathcpy, "r");
                                        m_fp = fopen(pathcpy, "r");
                                } if (!m_fp) {
                                } if (!m_fp) {
                                        fprintf(stderr, "Cannot open %s\n", fname);
                                        fprintf(stderr, "Cannot open %s\n", fname);
                                        perror("O/S Err:");
                                        perror("O/S Err:");
                                        exit(-1);
                                        exit(-1);
Line 787... Line 811...
                }
                }
        }
        }
 
 
        return 0;
        return 0;
}
}
 
// .*           { fprintf(stderr, "Ignoring everything, line %d, \'%s\'\n", yylineno, yytext); /* Ignore everything in these states*/ }
 
 

powered by: WebSVN 2.1.0

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