summaryrefslogtreecommitdiff
path: root/libcpu/i386_lex.l
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2008-01-02 17:44:39 +0000
committerUlrich Drepper <drepper@redhat.com>2008-01-02 17:44:39 +0000
commit3cbdd387c752999255aea91600b5cfdefbeac7d0 (patch)
tree50c18bd26f8cd31f4c1aa3ce1d78bb98548659ba /libcpu/i386_lex.l
parentad024afc93dcd0f4797b3e80bfb6b80c34da5c12 (diff)
downloadelfutils-3cbdd387c752999255aea91600b5cfdefbeac7d0.tar.gz
propagate from branch 'com.redhat.elfutils.disasm' (head d15b4eb794e81e477f9896fe82a74cb5ecf4514c)
to branch 'com.redhat.elfutils' (head eaacbf01f8cc89d043ec6eca9b5e35cb5c4cde06)
Diffstat (limited to 'libcpu/i386_lex.l')
-rw-r--r--libcpu/i386_lex.l115
1 files changed, 115 insertions, 0 deletions
diff --git a/libcpu/i386_lex.l b/libcpu/i386_lex.l
new file mode 100644
index 00000000..ea121909
--- /dev/null
+++ b/libcpu/i386_lex.l
@@ -0,0 +1,115 @@
+%{
+/* Copyright (C) 2004, 2005, 2007 Red Hat, Inc.
+ Written by Ulrich Drepper <drepper@redhat.com>, 2004.
+
+ This program is Open Source software; you can redistribute it and/or
+ modify it under the terms of the Open Software License version 1.0 as
+ published by the Open Source Initiative.
+
+ You should have received a copy of the Open Software License along
+ with this program; if not, you may obtain a copy of the Open Software
+ License version 1.0 from http://www.opensource.org/licenses/osl.php or
+ by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
+ 3001 King Ranch Road, Ukiah, CA 95482. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <ctype.h>
+#include <error.h>
+#include <libintl.h>
+
+#include <system.h>
+#include "i386_parse.h"
+
+
+static void eat_to_eol (void);
+static void invalid_char (int ch);
+%}
+
+ID [a-zA-Z_][a-zA-Z0-9_/]*
+ID2 [a-zA-Z0-9_:/]*
+NUMBER [0-9]+
+WHITE [[:space:]]+
+
+%option yylineno
+%option never-interactive
+%option noyywrap
+
+
+%x MAIN
+
+%%
+
+"%mask" { return kMASK; }
+
+"%prefix" { return kPREFIX; }
+"%suffix" { return kSUFFIX; }
+
+"%synonym" { return kSYNONYM; }
+
+{NUMBER} { i386_lval.num = strtoul (yytext, NULL, 10);
+ return kNUMBER; }
+
+"%%" { BEGIN (MAIN); return kPERCPERC; }
+
+
+<MAIN>"0" { return '0'; }
+<MAIN>"1" { return '1'; }
+
+<INITIAL,MAIN>"{"{ID2}"}" { i386_lval.str = xstrndup (yytext + 1,
+ yyleng - 2);
+ return kBITFIELD; }
+
+<MAIN>"INVALID" { i386_lval.str = (void *) -1l;
+ return kID; }
+
+<MAIN>{ID} { i386_lval.str = xstrndup (yytext, yyleng);
+ return kID; }
+
+<MAIN>"," { return ','; }
+
+<MAIN>":" { return ':'; }
+
+<INITIAL,MAIN>^"\n" { /* IGNORE */ }
+
+<INITIAL,MAIN>"\n" { return '\n'; }
+
+<INITIAL,MAIN>^"#" { eat_to_eol (); }
+
+{WHITE} { /* IGNORE */ }
+
+<MAIN>{WHITE} { return kSPACE; }
+
+<MAIN>. { i386_lval.ch = *yytext; return kCHAR; }
+
+. { invalid_char (*yytext); }
+
+
+%%
+
+static void
+eat_to_eol (void)
+{
+ while (1)
+ {
+ int c = input ();
+
+ if (c == EOF || c == '\n')
+ break;
+ }
+}
+
+static void
+invalid_char (int ch)
+{
+ error (0, 0, (isascii (ch)
+ ? gettext ("invalid character '%c' at line %d; ignored")
+ : gettext ("invalid character '\\%o' at line %d; ignored")),
+ ch, yylineno);
+}
+
+// Local Variables:
+// mode: C
+// End: