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

Subversion Repositories zipcpu

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /zipcpu/trunk
    from Rev 52 to Rev 53
    Reverse comparison

Rev 52 → Rev 53

/sw/zasm/zpp.l
71,7 → 71,7
const char *stb_getdefn(const char *str);
%}
%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 stack
ID [_:A-Za-z][_:A-Za-z0-9]*
79,9 → 79,9
 
%%
<COMMENT>"*/" { yy_pop_state(); }
<COMMENT>[^*]+ { /* Ignore comments */ }
<COMMENT>[^*\n]+ { /* Ignore comments */ }
<COMMENT>"*"+[^/] { /* Ignore comments */ }
<INITIAL,INDEF>^"#include"[ \t]+\"[^\"]+\" {
<INITIAL,INDEF>^"#include"[ \t]+\"[^\n\"]+\" {
char *ptr = &yytext[9], *start, *end, *str;
while(isspace(*ptr))
ptr++;
102,7 → 102,7
BEGIN DFV;
}
<DEF>{IDDOT}/[(] { stb_define(yytext); BEGIN DFA; }
<DFA>"("[^)]+")" {
<DFA>"("[^)\n]+")" {
/* Process macro arguments */
stb_args(yytext);
BEGIN DFV;
154,11 → 154,11
// fprintf(stderr, "C: Adding to macro %s\n", yytext);
stb_macro(yytext);
}
<DFV>[0-7]+[oO] {/* Get any hexadecimal constants */
<DFV>[0-7]+[oO] {/* Get any octal constants */
// fprintf(stderr, "D: Adding to macro %s\n", yytext);
stb_macro(yytext);
}
<DFV>[0-9]+ {/* Get any hexadecimal constants */
<DFV>[0-9]+ {/* Get any decimal constants */
// fprintf(stderr, "E: Adding to macro %s\n", yytext);
stb_macro(yytext);
}
169,13 → 169,30
fprintf(yyout, "\n"); mark_line(); yylineno++;
stb_macro("\n");
}
<INNOTDEF,NODEF,NVRDEF>^"#define".*$ { yy_push_state(DONTDEF); }
<DONTDEF>"\\"[ \t]*((;"//").*)?\n {/* Continue onto next line */
fprintf(yyout, "\n"); mark_line(); yylineno++; }
<DONTDEF>[a-zA-Z0-9_,.()]* { }
<DONTDEF>[ \t]* { }
<DONTDEF>((;|"//").*)?$ { yy_pop_state(); }
<DONTDEF>"\\"[ \t]*((;|"//").*)?\n {/* Continue onto next line */
fprintf(yyout, "\n"); mark_line(); yylineno++; }
<INITIAL,INDEF>^[ \t]+.[dD][aA][tT][aA]? { fprintf(yyout, "\tWORD"); }
<INITIAL,INDEF>^"#defcont"[ \t]+ { yy_push_state(DFV); }
<INITIAL,INDEF>^"#ifdef"[ \t]* { ndef = 0; yy_push_state(IFDEFV); }
<INITIAL,INDEF>^"#ifndef"[ \t]* { ndef = 1; yy_push_state(IFDEFV); }
<INITIAL,INDEF>^"#defcont"[ \t]+ {
yy_push_state(DFV); }
<INITIAL,INDEF>^"#ifdef"[ \t]* { ndef = 0;
yy_push_state(IFDEFV); }
<INITIAL,INDEF>^"#ifndef"[ \t]* { ndef = 1;
yy_push_state(IFDEFV); }
<INNOTDEF,NODEF,NVRDEF>^"#ifdef"[ \t]* { ndef = 2;
yy_push_state(IFDEFV); }
<INNOTDEF,NODEF,NVRDEF>^"#ifndef"[ \t]* { ndef = 2;
yy_push_state(IFDEFV); }
<IFDEFV>{IDDOT} {
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;
} else {
BEGIN INNOTDEF_EOL;
189,18 → 206,26
<INDEF_EOL>(;|"//").*$ { BEGIN INDEF; }
<INNOTDEF_EOL>[ \t]*$ { BEGIN INNOTDEF; }
<INNOTDEF_EOL>(;|"//").*$ { BEGIN INNOTDEF; }
<INDEF_EOL>[^ \t\n].*$ { BEGIN INDEF; fprintf(stderr, "WARNING! Unexpected characters on IFDEF line, \'%s\'\n", yytext); mark_line(); }
<INNOTDEF_EOL>[^ \t\n].*$ { BEGIN INNOTDEF; fprintf(stderr, "WARNING! Unexpected characters on IFNDEF line, %s\n", yytext); mark_line(); }
<NVRDEF_EOL>[ \t]*$ { BEGIN NVRDEF; }
<NVRDEF_EOL>(;|"//").*$ { BEGIN NVRDEF; }
<NVRDEF_EOL>[^ \t\n].*$ { BEGIN INDEF; mark_line(); }
<INNOTDEF_EOL>[^ \t\n].*$ { BEGIN INNOTDEF; mark_line(); }
<INDEF,NVRDEF>^"#else"[ \t]*((;|"//").*)?$ { BEGIN NODEF; }
<INNOTDEF>^"#else"[ \t]*((;|"//").*)?$ { BEGIN INDEF; }
<INNOTDEF>(.*) { }
<INNOTDEF,NVRDEF,NODEF>^[^#\n]([^\n]*)$ { /* Skip text */ }
<INDEF>^"#elsif"[ \t]* { BEGIN NVRDEF; }
<NVRDEF,NODEF,INDEF,INNOTDEF>^"#endif"[ \t]*((;|"//").*)?$ { yy_pop_state(); }
<NVRDEF,NODEF,INDEF,INNOTDEF>^"#endif"[ \t]*((;|"//").*)?$ {
yy_pop_state(); }
<NVRDEF,NODEF,INDEF,INNOTDEF>^"#endif"[ \t]*"/*" { BEGIN COMMENT; }
<*>^"#endif"[ \t]* { fprintf(stderr, "ERR: Unknown endif!!\n");}
<INITIAL,INDEF>^"#struct"[ \t]* {
yy_push_state(GETSTRUCTID); structno = 0; }
<*>^"#"{ID}[ \t]* { fprintf(stderr, "ERR: Unrecognized preprocessor instruction, %s\n", yytext);}
<NVRDEF,NODEF,INDEF,INNOTDEF>^"#endif" { yy_pop_state(); }
<*>^"#ifdef"[ \t]* { fprintf(stderr, "ERR: Line %d, Unknown ifdef!! (state = %d)\n", yylineno, YYSTATE);}
<*>^"#else"[ \t]* { fprintf(stderr, "ERR: Line %d, Unknown else!! (state = %d)\n", yylineno, YYSTATE);}
<*>^"#endif"[ \t]* { fprintf(stderr, "ERR: Line %d, Unknown endif!! (state = %d)\n", yylineno, YYSTATE);}
<INITIAL,INDEF>^"#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);
}
<GETSTRUCTID>{ID}/[ \t\n;/] { BEGIN INSTRUCT;
structid = strdup(yytext);
}
210,7 → 235,6
/* Not yet: ^"#struct"[ \t]* {} */
/* Not yet: ^"#endstruct"[ \t]* {} */
/* Not yet: ^"#seg"[ \t]* {} */
<NODEF,NVRDEF>.* { /* Ignore everything in these states*/ }
<INITIAL,INDEF>{ID}/[^(] {
if (stb_isdefined(yytext))
fprintf(yyout, "%s", stb_getdefn(yytext));
245,13 → 269,13
<*>[ \t]+ { ECHO; }
<*>\n { ECHO; yylineno++; mark_line(); }
/* <*>. { printf("Unmatched \'%c\'\n", yytext[0]); } */
<NVRDEF,NODEF,INDEF,INNOTDEF><<EOF>> { fprintf(stderr, "Unexpected EOF! Expecting #endif\n"); }
<IFDEFV><<EOF>> { fprintf(stderr, "Unexpected EOF! Expecting #endif\n"); }
<COMMENT><<EOF>> { fprintf(stderr, "Unexpected EOF! Expecting */\n"); }
<INSTRUCT><<EOF>> { fprintf(stderr, "Unexpected EOF! Expecting #endstruct\n"); }
<GETSTRUCTID><<EOF>> { fprintf(stderr, "Unexpected EOF! Expecting #struct ID, then #endstruct\n"); }
<DFA,DFV,DFV_EOL><<EOF>> { fprintf(stderr, "Unexpected EOF! Expecting end of line\n"); }
<INDEF_EOL,INNOTDEF_EOL><<EOF> { fprintf(stderr, "Unexpected EOF Expecting end of line, then #endif\n"); }
<NVRDEF,NODEF,INDEF,INNOTDEF><<EOF>> { fprintf(stderr, "Unexpected EOF! Expecting #endif\n"); yyterminate(); }
<IFDEFV><<EOF>> { fprintf(stderr, "Unexpected EOF! Expecting #endif\n"); yyterminate(); }
<COMMENT><<EOF>> { fprintf(stderr, "Unexpected EOF! Expecting */\n"); yyterminate(); }
<INSTRUCT><<EOF>> { fprintf(stderr, "Unexpected EOF! Expecting #endstruct\n"); yyterminate(); }
<GETSTRUCTID><<EOF>> { fprintf(stderr, "Unexpected EOF! Expecting #struct ID, then #endstruct\n"); yyterminate(); }
<DFA,DFV,DFV_EOL><<EOF>> { fprintf(stderr, "Unexpected EOF! Expecting end of line\n"); yyterminate(); }
<INDEF_EOL,INNOTDEF_EOL><<EOF> { fprintf(stderr, "Unexpected EOF Expecting end of line, then #endif\n"); yyterminate(); }
<INITIAL><<EOF>> { if (end_of_file()) yyterminate(); }
 
%%
676,13 → 700,13
char *pathcpy = new char[strlen(pathptr)+8192];
strcpy(pathcpy, pathptr);
 
fprintf(stderr, "ZIPINC := %s\n", pathptr);
// fprintf(stderr, "ZIPINC := %s\n", pathptr);
dptr = pathptr;
while((!m_fp)&&(NULL != (colonp = strchr(dptr, ':')))) {
strncpy(pathcpy, dptr, colonp-pathptr);
strcat(pathcpy, "/");
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)
m_fp = fopen(pathcpy, "r");
dptr = colonp+1;
690,7 → 714,7
strcpy(pathcpy, dptr);
strcat(pathcpy, "/");
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");
} if (!m_fp) {
fprintf(stderr, "Cannot open %s\n", fname);
789,4 → 813,5
 
return 0;
}
// <NODEF,NVRDEF>.* { 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.