~alexandre-hardy/linuxjoymap/linuxjoymap

« back to all changes in this revision

Viewing changes to oldparser/program.lex

  • Committer: Alexandre Hardy
  • Date: 2009-07-17 09:20:57 UTC
  • Revision ID: ah@zenwalk-20090717092057-oxa4o16isawqa7ue
Initial creation of project

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%{
 
2
#include <string.h>
 
3
#include <math.h>
 
4
#include <stdio.h>
 
5
 
 
6
static int lineno=1;
 
7
%}
 
8
 
 
9
digit   [0-9]
 
10
id      [a-zA-Z_][A-Za-z0-9_]*
 
11
comment [#].*[\n]
 
12
white   [ \r\t]
 
13
newline [\n]
 
14
int     {digit}+
 
15
float   {int}"."{int}
 
16
num     [\+\-]?({float}|{int})
 
17
value   {int}
 
18
string  \"[^\"]*\"
 
19
%%
 
20
if              { return IF;}
 
21
else            { return ELSE;}
 
22
while           { return WHILE;}
 
23
delay           { return DELAY;}
 
24
wait            { return WAIT;}
 
25
var             { return VAR;}
 
26
signal          { return PSIGNAL;}
 
27
press           { return PRESS;}
 
28
release         { return RELEASE;}
 
29
halt            { return PHALT;}
 
30
thread          { return PTHREAD;}
 
31
{comment}       { lineno++;}
 
32
{white}         {}
 
33
{newline}       { lineno++;}
 
34
{id}            { 
 
35
                        yytext[strlen(yytext)-1]='\0';
 
36
                        strcpy(yylval.string,yytext);
 
37
                        return ID;
 
38
                }
 
39
{string}        {        
 
40
                        yytext[strlen(yytext)-1]='\0';
 
41
                        strcpy(yylval.string,yytext+1);
 
42
                        return STRING; 
 
43
                }
 
44
{value}         { 
 
45
                        strcpy(yylval.string,yytext);
 
46
                        return INT;
 
47
                }
 
48
.               { return yytext[0];}
 
49
%%
 
50
 
 
51
int yywrap(void) {
 
52
        return 1;
 
53
}
 
54
 
 
55
void yyerror(char *s) {
 
56
        printf("Parse error(line %d):" , lineno);
 
57
        printf("%s\n", s);
 
58
}