summaryrefslogtreecommitdiff
path: root/other/gramble/compiler.l
blob: 1dbb21b43a0ef045ee7133028efac95b4c9e9296 (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
/* fornax - distributed packet network
 *
 * by team teso
 *
 * lex command lexical analyzer
 */


%{
#undef	yywrap

#include <string.h>
#include "../../shared/common.h"
#include "branch.h"
#include "call.h"
#include "compiler.h"
#include "condition.h"
#include "element.h"
#include "symbol.h"
#include "y.tab.h"

#undef	ECHO
#undef	YY_INPUT
#define	YY_INPUT(b, r, ms) (r = cp_yyinput (b, ms))

%}

%%

[\n\t ]+	;	 /* strip any whitespaces */

\{	{
		return (EXPR_BLOCK_BEGIN);
	}

\}	{
		return (EXPR_BLOCK_END);
	}

\"[^\"]*\"	{
			yylval.str = xstrdup (yytext + 1);
			yylval.str[strlen (yylval.str) - 1] = '\x00';

			return (ASTRING);
		}

[iI][fF]	{
			return (IF);
		}

[eE][lL][sS][eE]	{
				return (ELSE);
			}

\$[a-zA-Z\_]+[a-zA-Z0-9\_]*	{
					yylval.str = xstrdup (yytext);

					return (VARIABLE);
				}

(\&\&)|(\|\|)	{
			if (strcmp (yytext, "&&") == 0)
				yylval.logoper = LO_AND;
			else if (strcmp (yytext, "||") == 0)
				yylval.logoper = LO_OR;

			return (LOG_OPER);
		}

(\=\=)|(\>\=)|(\<\=)|(\!\=)	{
					if (strcmp (yytext, "==") == 0)
						yylval.eq = EQ_EQUAL;
					else if (strcmp (yytext, ">=") == 0)
						yylval.eq = EQ_GREATEQ;
					else if (strcmp (yytext, "<=") == 0)
						yylval.eq = EQ_LOWEREQ;
					else if (strcmp (yytext, "!=") == 0)
						yylval.eq = EQ_NOTEQ;

					return (EQ_OP);
				}

[a-zA-Z0-9\.\_]+	{
				yylval.str = xstrdup (yytext);

				return (STRING);
			}

[=]		{
			return (EQ);
		}

.	return (yytext[0]);