types and locations
[ccc.git] / scan.l
diff --git a/scan.l b/scan.l
index 048d104..b1fb5be 100644 (file)
--- a/scan.l
+++ b/scan.l
@@ -3,9 +3,21 @@
 %{
 
 #include <stdio.h>
+#define YY_USER_ACTION \
+    yylloc.first_line = yylloc.last_line; \
+    yylloc.first_column = yylloc.last_column; \
+    for(int i = 0; yytext[i] != '\0'; i++) { \
+        if(yytext[i] == '\n') { \
+            yylloc.last_line++; \
+            yylloc.last_column = 0; \
+        } \
+        else { \
+            yylloc.last_column++; \
+        } \
+    }
+
 #include "ast.h"
 #include "y.tab.h"
-extern YYSTYPE yylval;
 
 %}
 
@@ -18,6 +30,7 @@ var         return VAR;
 true        { yylval.expr = expr_bool(true); return BOOL; }
 false       { yylval.expr = expr_bool(false); return BOOL; }
 return      return RETURN;
+->          return ARROW;
 =           return ASSIGN;
 !           return INVERSE;
 \|\|        return BINOR;
@@ -40,6 +53,8 @@ return      return RETURN;
 \{          return COPEN;
 \}          return CCLOSE;
 \;          return SEMICOLON;
+\[          return SOPEN;
+\]          return SCLOSE;
 \[\]        return NIL;
 \.          return DOT;
 ,           return COMMA;