parser/calc/lexer.l
author Markus Bröker <mbroeker@largo.dyndns.tv>
Fri, 19 Nov 2010 16:32:43 +0100
changeset 160 26414889dded
parent 39 46d7ec9d63bd
permissions -rw-r--r--
removed unneeded includes and code cleanups 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
%{
39
46d7ec9d63bd Project Parser
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 38
diff changeset
     7
    #include <stdio.h>
46d7ec9d63bd Project Parser
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 38
diff changeset
     8
    #include "parser.h"
37
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
39
46d7ec9d63bd Project Parser
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 38
diff changeset
    13
[0-9]+         { yylval = atoi(yytext); return DIGIT; }
46d7ec9d63bd Project Parser
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 38
diff changeset
    14
[a-zA-Z]       { yylval = yytext[0]; return LETTER; }
46d7ec9d63bd Project Parser
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 38
diff changeset
    15
"+"            { return PLUS; }
46d7ec9d63bd Project Parser
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 38
diff changeset
    16
"-"            { return MINUS; }
46d7ec9d63bd Project Parser
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 38
diff changeset
    17
"*"            { return MUL; }
46d7ec9d63bd Project Parser
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 38
diff changeset
    18
"/"            { return DIV; }
46d7ec9d63bd Project Parser
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 38
diff changeset
    19
"("|")"|"="    { return yytext[0]; }
46d7ec9d63bd Project Parser
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 38
diff changeset
    20
[ \t]+         {}
46d7ec9d63bd Project Parser
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 38
diff changeset
    21
\n             { return yytext[0]; }
46d7ec9d63bd Project Parser
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 38
diff changeset
    22
.              { printf("FEHLER: %s\n", yytext); }
37
0fbbe329c3a2 demos/parser
Markus Bröker <mbroeker@largo.localnet>
parents:
diff changeset
    23
%%