arm: init from ppc
[uebersetzerbau-ss10.git] / gesamt_arm / scanner.lex
diff --git a/gesamt_arm/scanner.lex b/gesamt_arm/scanner.lex
new file mode 100644 (file)
index 0000000..92f6df7
--- /dev/null
@@ -0,0 +1,67 @@
+       #include <stdio.h>
+       #include <stdlib.h>
+       #include <string.h>
+       #include "parser.h"
+
+KEYWORD struct|end|method|var|if|then|else|while|do|return|not|or|this
+IDENTIFIER [a-zA-Z_][0-9a-zA-Z_]*
+NUMBER_HEX 0x[0-9A-Fa-f]+
+NUMBER_DEC [0-9]+
+WHITESPACE [\t\n\r ]
+COMMENT_START \/\*
+COMMENT_END    \*\/
+
+%x COMMENT
+%option yylineno
+%%
+
+{COMMENT_START} BEGIN(COMMENT);
+
+<COMMENT>{COMMENT_END} BEGIN(INITIAL);
+
+<COMMENT><<EOF>> {
+       fprintf(stderr, "Kommentar nicht geschlossen\n");
+       exit(1);
+}
+
+<COMMENT>(.|\n) /* alles im kommentar wird ignoriert */
+
+struct return(STRUCT);
+end return(END);
+method return(METHOD);
+var return(VAR);
+if return(IF);
+then return(THEN);
+else return(ELSE);
+while return(WHILE);
+do return(DO);
+return return(RETURN);
+not return(NOT);
+or return(OR);
+this return(THIS);
+
+{IDENTIFIER} return(IDENT); @{ @IDENT.name@ = strdup(yytext); @}
+
+{NUMBER_DEC} return(NUM); @{ @NUM.val@ = strtol(yytext, (char **)NULL, 10); @}
+{NUMBER_HEX} return(NUM); @{ @NUM.val@ = strtol(yytext, (char **)NULL, 16); @}
+
+\:= return(ASSIGN);
+\; return(';');
+\( return('(');
+\) return(')');
+\. return('.');
+\- return('-');
+\* return('*');
+\< return('<');
+\= return('=');
+\, return(',');
+
+{WHITESPACE} /* ignore */
+
+. {
+               fprintf(stderr, "Lexical error on line %i\n", yylineno);
+               exit(1);
+}
+
+%%
+