From 7bc67b95161a34f8eca635d4000d9602508a9243 Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Mon, 23 Dec 2019 01:32:39 +0000 Subject: checkpoint --- lex.l | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'lex.l') diff --git a/lex.l b/lex.l index ce84278..5319430 100644 --- a/lex.l +++ b/lex.l @@ -1,18 +1,35 @@ +%option noinput nounput %option noyywrap %option nodefault -%option yylineno -%option noinput nounput +/* %option reentrant bison-bridge bison-locations */ %{ #include -#include "basic.h" +#include "sexpr.h" +#include "sinter.h" #include "parse.h" void yyerror(const char *s, ...); char *str_value(char *s); +void update_yylloc() { + yylloc.first_line = yylloc.last_line; + yylloc.first_column = yylloc.last_column; + + for (int i = 0; yytext[i]; i++) { + if (yytext[i] == '\n') { + yylloc.last_line++; + yylloc.last_column = 0; + } else { + yylloc.last_column++; + } + } +} + +#define YY_USER_ACTION update_yylloc(); + char *str_value(char *s) { s++; /* FIXME: strdup allocates memory! */ @@ -24,7 +41,9 @@ char *str_value(char *s) { %} -ID [-A-Za-z_+*!/.=<>][-A-Za-z0-9_+*!.=<>]* +%option yylineno + +ID [-A-Za-z_+*^!:/%.=<>][-A-Za-z0-9_+*^!:/%.=<>]* STRING ["][^"]*["]|['][^']*['] FLOAT [+-]?([0-9]+[.][0-9]*([Ee][+-]?[0-9]+)?|[.][0-9]+([Ee][+-]?[0-9]+)?) INT [+-]?[0-9]+ -- cgit v1.2.1