diff lwcc/lex.c @ 298:6112c67728ba ccdev

Add stringification and token concatenation Add support for # and ## in macro expansion by the preprocessor (stringification and token concatenation). Totally untested.
author William Astle <lost@l-w.ca>
date Sat, 14 Sep 2013 22:42:53 -0600
parents 83fcc1ed6ad6
children 856caf91ffaa
line wrap: on
line diff
--- a/lwcc/lex.c	Sat Sep 14 21:27:03 2013 -0600
+++ b/lwcc/lex.c	Sat Sep 14 22:42:53 2013 -0600
@@ -209,6 +209,14 @@
 {
 	int c;
 
+	if (pp -> lexstr)
+	{
+		if (pp -> lexstr[pp -> lexstrloc])
+			return pp -> lexstr[pp -> lexstrloc++];
+		else
+			return CPP_EOL;
+	}
+
 	if (pp -> ungetbufl > 0)
 	{
 		pp -> ungetbufl--;
@@ -586,7 +594,8 @@
 				c = preproc_lex_fetch_byte(pp);
 				if (c == CPP_EOF || c == CPP_EOL)
 				{
-					preproc_throw_error(pp, "Invalid character constant");
+					if (!pp -> lexstr)
+						preproc_throw_error(pp, "Invalid character constant");
 					break;
 				}
 				cl++;
@@ -595,7 +604,7 @@
 			}
 			strbuf_add(strbuf, c);
 		}
-		if (cl == 0)
+		if (cl == 0 && !pp -> lexstr)
 			preproc_throw_error(pp, "Invalid character constant");
 		strval = strbuf_end(strbuf);
 		ttype = TOK_CHR_LIT;
@@ -616,7 +625,8 @@
 				c = preproc_lex_fetch_byte(pp);
 				if (c == CPP_EOF || c == CPP_EOL)
 				{
-					preproc_throw_error(pp, "Invalid string constant");
+					if (!pp -> lexstr)
+						preproc_throw_error(pp, "Invalid string constant");
 					break;
 				}
 				cl++;