parser/calc/lexer.l
author Markus Bröker <mbroeker@largo.localnet>
Thu, 16 Apr 2009 12:49:11 +0200
changeset 38 48f6f3918b82
parent 37 0fbbe329c3a2
child 39 46d7ec9d63bd
permissions -rw-r--r--
Project Split finished committer: Markus Bröker <mbroeker@largo.homelinux.org>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37
0fbbe329c3a2 demos/parser
Markus Bröker <mbroeker@largo.localnet>
parents:
diff changeset
     1
/**
0fbbe329c3a2 demos/parser
Markus Bröker <mbroeker@largo.localnet>
parents:
diff changeset
     2
 * test/demos/parser/lexer.ll
0fbbe329c3a2 demos/parser
Markus Bröker <mbroeker@largo.localnet>
parents:
diff changeset
     3
 * Copyright (C) 2008 Markus Broeker
0fbbe329c3a2 demos/parser
Markus Bröker <mbroeker@largo.localnet>
parents:
diff changeset
     4
 */
0fbbe329c3a2 demos/parser
Markus Bröker <mbroeker@largo.localnet>
parents:
diff changeset
     5
0fbbe329c3a2 demos/parser
Markus Bröker <mbroeker@largo.localnet>
parents:
diff changeset
     6
%{
0fbbe329c3a2 demos/parser
Markus Bröker <mbroeker@largo.localnet>
parents:
diff changeset
     7
	#include <stdio.h>
0fbbe329c3a2 demos/parser
Markus Bröker <mbroeker@largo.localnet>
parents:
diff changeset
     8
	#include "parser.h"
0fbbe329c3a2 demos/parser
Markus Bröker <mbroeker@largo.localnet>
parents:
diff changeset
     9
%}
0fbbe329c3a2 demos/parser
Markus Bröker <mbroeker@largo.localnet>
parents:
diff changeset
    10
0fbbe329c3a2 demos/parser
Markus Bröker <mbroeker@largo.localnet>
parents:
diff changeset
    11
%%
0fbbe329c3a2 demos/parser
Markus Bröker <mbroeker@largo.localnet>
parents:
diff changeset
    12
38
48f6f3918b82 Project Split finished
Markus Bröker <mbroeker@largo.localnet>
parents: 37
diff changeset
    13
[0-9]+		{ yylval = atoi(yytext); return DIGIT; }
48f6f3918b82 Project Split finished
Markus Bröker <mbroeker@largo.localnet>
parents: 37
diff changeset
    14
[a-zA-Z]	{ yylval = yytext[0]; return LETTER; }
48f6f3918b82 Project Split finished
Markus Bröker <mbroeker@largo.localnet>
parents: 37
diff changeset
    15
"+"		{ return PLUS; }
48f6f3918b82 Project Split finished
Markus Bröker <mbroeker@largo.localnet>
parents: 37
diff changeset
    16
"-"		{ return MINUS; }
48f6f3918b82 Project Split finished
Markus Bröker <mbroeker@largo.localnet>
parents: 37
diff changeset
    17
"*"		{ return MUL; }
48f6f3918b82 Project Split finished
Markus Bröker <mbroeker@largo.localnet>
parents: 37
diff changeset
    18
"/"		{ return DIV; }
48f6f3918b82 Project Split finished
Markus Bröker <mbroeker@largo.localnet>
parents: 37
diff changeset
    19
"("|")"|"="	{ return yytext[0]; }
48f6f3918b82 Project Split finished
Markus Bröker <mbroeker@largo.localnet>
parents: 37
diff changeset
    20
[ \t]+		{}
48f6f3918b82 Project Split finished
Markus Bröker <mbroeker@largo.localnet>
parents: 37
diff changeset
    21
\n		{ return yytext[0]; }
48f6f3918b82 Project Split finished
Markus Bröker <mbroeker@largo.localnet>
parents: 37
diff changeset
    22
.		{ printf("FEHLER: %s\n", yytext); }
37
0fbbe329c3a2 demos/parser
Markus Bröker <mbroeker@largo.localnet>
parents:
diff changeset
    23
%%