summaryrefslogtreecommitdiff
path: root/support/rail/lex.l
blob: 7b61c0eb30d0c9bac76a08268aac6a0c5186ca52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* lex.l - lexical analyzer for rail program */

%{

#include <string.h>

#include "rail.h"
#include "gram.h"

unsigned line;	/* current input line */
int copy;	/* copy to output flag */

#define	COPY	(copy && fputs(yytext,outf))

extern YYSTYPE yylval;

%}

%%

[a-zA-Z_][0-9a-zA-Z_.]* {
		COPY;
		yylval.id=lookup(yytext);
		return(IDENTIFIER);
}

[0-9][0-9]* {
		COPY;
		yylval.num=atoi(yytext);
		return(NUMBER);
}

\\rail@i {
		COPY;
		return(RAILI);
}

\\rail@p {
		COPY;
		return(RAILP);
}

\\rail@t {
		COPY;
		return(RAILT);
}

\\par {
		COPY;
}

\\\\ {		COPY;
		return(RAILCR);
}

\\[a-zA-Z@]+ {
		COPY;
		return(CS);
}

\\[^ \n\t] {
		COPY;
		return(CS);
}

'[^\n\t']*' {
		COPY;
		yytext[yyleng-1]='\0';
		yylval.text=mcheck(strdup(yytext+1));
		return(STRING);
}

\[[^\n\t\]]*\] {
		COPY;
		yytext[yyleng-1]='\0';
		yylval.text=mcheck(strdup(yytext+1));
		return(ANNOT);
}

\"[^\n\t\"]*\" {
		COPY;
		yytext[yyleng-1]='\0';
		yylval.text=mcheck(strdup(yytext+1));
		return(STRING);
}

[ \t]+ {
		COPY;
}

\n {
		COPY;
		line++;
}

. {
		COPY;
		return(yytext[0]);
}