From eca93250bdb1209cd489f167534ab6f5a3346794 Mon Sep 17 00:00:00 2001 From: khamidou Date: Wed, 2 Mar 2011 11:44:41 +0100 Subject: [PATCH] added a byte string feature --- as.c | 15 +++++++++++++-- aslexer.l | 1 + tokens.h | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) 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, -- 2.43.0