summaryrefslogtreecommitdiff
path: root/glcpp-lex.l
diff options
context:
space:
mode:
authorCarl Worth <cworth@cworth.org>2010-05-20 22:27:07 -0700
committerCarl Worth <cworth@cworth.org>2010-05-20 22:27:07 -0700
commitb20d33c5c6fea8e392c26e9ab060efd14034f1f9 (patch)
tree0285aa21a9c693a155d02a1b1f715137b49f494c /glcpp-lex.l
parentd8327e575dd20fe696f3a44ada4bd4001b15db27 (diff)
Implement #if, #else, #elif, and #endif with tests.
So far the only expression implemented is a single integer literal, but obviously that's easy to extend. Various things including nesting are tested here.
Diffstat (limited to 'glcpp-lex.l')
-rw-r--r--glcpp-lex.l32
1 files changed, 32 insertions, 0 deletions
diff --git a/glcpp-lex.l b/glcpp-lex.l
index 6138a9de12..825ce3d370 100644
--- a/glcpp-lex.l
+++ b/glcpp-lex.l
@@ -36,6 +36,7 @@
%x ST_DEFINE_OBJ_OR_FUNC
%x ST_DEFINE_PARAMETER
%x ST_DEFINE_VALUE
+%x ST_IF
%x ST_UNDEF
%x ST_UNDEF_END
@@ -44,11 +45,42 @@ NONSPACE [^[:space:]]
NEWLINE [\n]
HSPACE [ \t]
HASH ^{HSPACE}*#{HSPACE}*
+INTEGER [0-9]+
IDENTIFIER [_a-zA-Z][_a-zA-Z0-9]*
TOKEN [^[:space:](),]+
%%
+{HASH}if{HSPACE}* {
+ BEGIN ST_IF;
+ return IF;
+}
+
+{HASH}elif{HSPACE}* {
+ BEGIN ST_IF;
+ return ELIF;
+}
+
+<ST_IF>{INTEGER} {
+ yylval.ival = atoi (yytext);
+ return INTEGER;
+}
+
+<ST_IF>{HSPACE}+
+
+<ST_IF>\n {
+ BEGIN INITIAL;
+ return NEWLINE;
+}
+
+{HASH}endif{HSPACE}* {
+ return ENDIF;
+}
+
+{HASH}else{HSPACE}* {
+ return ELSE;
+}
+
{HASH}undef{HSPACE}* {
BEGIN ST_UNDEF;
return UNDEF;