summaryrefslogtreecommitdiff
path: root/compiler/ex-spec.lex
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/ex-spec.lex')
-rw-r--r--compiler/ex-spec.lex216
1 files changed, 216 insertions, 0 deletions
diff --git a/compiler/ex-spec.lex b/compiler/ex-spec.lex
new file mode 100644
index 0000000..c7dd03c
--- /dev/null
+++ b/compiler/ex-spec.lex
@@ -0,0 +1,216 @@
+/* Copyright (C) 2003 Søren Sandmann (sandmann@daimi.au.dk)
+ *
+ * Author: Søren Sandmann
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+%{
+#include <string.h>
+#include "ex-compiler.h"
+#include "ex-parser.h"
+
+ static int line;
+ static int pos;
+ static void set_position (void); /* update yylval.token */
+%}
+
+%option never-interactive nounput
+
+LETTER [A-Za-z_]
+DIGIT [0-9]
+HEX_DIGIT {DIGIT}|[A-Fa-f]
+OCTAL_DIGIT [0-7]
+BINARY_DIGIT [0-1]
+ID {LETTER}({LETTER}|{DIGIT})*
+WS [ \t\r\n]
+CCOMMENT "/*"([^*]|"*"[^/])*"*/"
+CPPCOMMENT \/\/[^\n]*\n
+EAT ({WS}|{CCOMMENT}|{CPPCOMMENT})+
+
+%%
+
+{EAT} {
+ set_position ();
+}
+"namespace" {
+ set_position ();
+ return TOK_NAMESPACE;
+}
+"extension" {
+ set_position ();
+ return TOK_EXTENSION;
+}
+"type" {
+ set_position ();
+ return TOK_TYPE;
+}
+"bits" {
+ set_position ();
+ return TOK_BITS;
+}
+"xid" {
+ set_position ();
+ return TOK_XID;
+}
+"enum" {
+ set_position ();
+ return TOK_ENUM;
+}
+"struct" {
+ set_position ();
+ return TOK_STRUCT;
+}
+"list" {
+ set_position ();
+ return TOK_LIST;
+}
+"request" {
+ set_position ();
+ return TOK_REQUEST;
+}
+"event" {
+ set_position ();
+ return TOK_EVENT;
+}
+"error" {
+ set_position ();
+ return TOK_ERROR;
+}
+"union" {
+ set_position ();
+ return TOK_UNION;
+}
+"masked_list" {
+ set_position ();
+ return TOK_MASKED_LIST;
+}
+"errors" {
+ set_position ();
+ return TOK_ERRORS;
+}
+"reply" {
+ set_position ();
+ return TOK_REPLY;
+}
+"uses" {
+ set_position ();
+ return TOK_USES;
+}
+"int8" {
+ set_position ();
+ return TOK_INT8;
+}
+"int16" {
+ set_position ();
+ return TOK_INT16;
+}
+"int32" {
+ set_position ();
+ return TOK_INT32;
+}
+"int64" {
+ set_position ();
+ return TOK_INT64;
+}
+"card8" {
+ set_position ();
+ return TOK_CARD8;
+}
+"card16" {
+ set_position ();
+ return TOK_CARD16;
+}
+"card32" {
+ set_position ();
+ return TOK_CARD32;
+}
+"card64" {
+ set_position ();
+ return TOK_CARD64;
+}
+"boolean" {
+ set_position ();
+ return TOK_BOOLEAN;
+}
+"::" {
+ set_position ();
+ return TOK_COLON_COLON;
+}
+0(x|X)([a-fA-F0-9][a-fA-F0-9]*) {
+ yylval.token.int_const = strtol (yytext, NULL, 16);
+ set_position ();
+ return TOK_INT_CONST;
+}
+[1-9][0-9]* {
+ yylval.token.int_const = strtol (yytext, NULL, 10);
+ set_position ();
+ return TOK_INT_CONST;
+}
+{ID} {
+ yylval.token.string_const = ex_strdup (yytext);
+ set_position ();
+ return TOK_IDENTIFIER;
+}
+\"([^\"]|\\\")*\" {
+ char *stripped;
+
+ stripped = ex_strdup (yytext + 1);
+ stripped [strlen (stripped) - 1] = '\0';
+
+ yylval.token.string_const = stripped;
+
+ set_position ();
+ return TOK_STRING_CONST;
+}
+. {
+ set_position ();
+ return *yytext;
+}
+
+%%
+
+static void
+set_position (void)
+{
+ const char *s;
+
+ yylval.token.first_line = line;
+ yylval.token.first_char = pos;
+
+ for (s = yytext; *s != '\0'; ++s)
+ {
+ if (*s == '\n')
+ {
+ line++;
+ pos = 1;
+ }
+ else
+ {
+ pos++;
+ }
+ }
+
+ yylval.token.last_line = line;
+ yylval.token.last_char = pos;
+}
+
+void
+ex_init_scanner (void)
+{
+ line = 1;
+ pos = 1;
+}