From: khamidou Date: Wed, 2 Mar 2011 10:44:41 +0000 (+0100) Subject: added a byte string feature X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;ds=sidebyside;p=miniforth.git added a byte string feature --- diff --git a/as.c b/as.c index ae17885..e57d63c 100644 --- a/as.c +++ b/as.c @@ -87,8 +87,8 @@ int first_pass() { t = yylex(); if (t != T_TIMES) - fail("Expected a times keyword after db directive"); - + fail("Expected a times keyword or a string after db directive"); + t = yylex(); if (t != NUMBER) @@ -97,6 +97,10 @@ int first_pass() { current_offset += atoi(yytext); break; + case STRING: + current_offset += strlen(yytext); + break; + default: current_offset++; @@ -218,8 +222,15 @@ int parse() { for(i = 1; i <= max_iter; i++) writeint(val, outfp); + break; + + case STRING: + /* output the string in raw form to the file */ + for(i = 0; i < strlen(yytext); i++) + writeint(yytext[i], outfp); + break; default: fail("unexpected %s in input at line %d", yytext, yylineno); break; diff --git a/aslexer.l b/aslexer.l index 75c60ca..ac50eb1 100644 --- a/aslexer.l +++ b/aslexer.l @@ -31,5 +31,6 @@ [0-9]+ { return NUMBER; } [a-zA-Z][a-zA-Z0-9]*: { return T_LABEL; } [a-zA-Z][a-zA-Z0-9]* { return WORD; } +\".+\" { return STRING; } <> { return -1; } diff --git a/tokens.h b/tokens.h index 94826e4..daa39f7 100644 --- a/tokens.h +++ b/tokens.h @@ -3,6 +3,7 @@ enum tokens { NUMBER, WORD, + STRING, T_LABEL, T_PUSH, T_POP,