lexer_lex now returns the number of tokens it pushed
authorjordan@hack_attack <jordanlavatai@gmail.com>
Fri, 7 Oct 2016 20:48:22 +0000 (13:48 -0700)
committerjordan@hack_attack <jordanlavatai@gmail.com>
Fri, 7 Oct 2016 20:48:22 +0000 (13:48 -0700)
src/apc/lexer_lex.rl

index d27c40b..d87f47d 100644 (file)
@@ -24,15 +24,18 @@ char* ttos(const char* str, int);
   action set_ref {
                    tok_t = REF;                      \
                    yylval.ref = ttor(ts, p-ts);      \
-                   lexer_pushtok(tok_t, yylval); }
+                   lexer_pushtok(tok_t, yylval);     \
+                   num_tokens++; }
 
   action set_val { tok_t = NUM;                      \
                    yylval.val = ttov(ts, p-ts);      \
-                   lexer_pushtok(tok_t, yylval); }
+                   lexer_pushtok(tok_t, yylval);     \
+                   num_tokens++; }
 
   action set_name { tok_t = NAME;                    \
                     yylval.str = ttos(ts, p-ts);     \
-                    lexer_pushtok(tok_t, yylval); }
+                    lexer_pushtok(tok_t, yylval);    \
+                    num_tokens++; }
 
   action set_ts   { ts = p; }
 
@@ -54,17 +57,18 @@ char* ttos(const char* str, int);
 int lexer_lex (const char* str)
 {
   const char *p, *pe, *ts, *eof;
-  int  cs, tok_t ; //tok_t == token type
+  int  cs, tok_t, num_tokens; //tok_t == token type
+
+  num_tokens = 0;
 
   p = ts = str;
   pe = p + strlen(str) + 1;
   %%write init;
   %%write exec;
 
-  lexer_pushtok(tok_t, yylval);
 
   printf (str);
-  return 1;
+  return num_tokens;
 }
 
 int ipow(int base, int exp)