-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3d.l
150 lines (130 loc) · 4.46 KB
/
3d.l
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
%{
enum
{
LOOKUP = 0,
INT,
FLOAT,
TEXT,
CHAR,
KEYWORD,
ARGUMENT,
DATATYPE,
CONDITIONAL_KEY,
ITERATIVE_KEY,
ARITHEMATIC_OPERATOR,
LOGICAL_OPERATOR,
RELATIONAL_OPERATOR,
IDENTIFIER,
UNARY_OPERATOR,
FORMAT_PROCESSOR,
FUNCTION,
ACCESS_MODIFIER,
DELIMITER,
COMMA,
INVERTED_COMMAS,
PARANTHESIS,
BLOCK,
BRACKET,
ASSIGNMENT_OPERATOR
};
int state;
int addWord(int type, char *word);
int lookupWord(char *word);
%}
%%
\n { state = LOOKUP; }
^INT { state = INT; }
^FLOAT { state = FLOAT; }
^text { state = TEXT; }
^CHAR { state = CHAR; }
^keyword { state = KEYWORD; }
^argument { state = ARGUMENT; }
^datatype { state = DATATYPE; }
^conditional { state = CONDITIONAL_KEY; }
^iterative { state = ITERATIVE_KEY; }
^arithematic { state = ARITHEMATIC_OPERATOR; }
^logical { state = LOGICAL_OPERATOR; }
^relational { state = RELATIONAL_OPERATOR; }
^identifier { state = IDENTIFIER; }
^unary { state = UNARY_OPERATOR; }
^format { state = FORMAT_PROCESSOR; }
^function { state = FUNCTION; }
^access { state = ACCESS_MODIFIER; }
^delimiter { state = DELIMITER; }
^comma { state = COMMA; }
^inverted_commas { state = INVERTED_COMMAS; }
^paranthesis { state = PARANTHESIS; }
^block { state = BLOCK; }
^bracket { state = BRACKET; }
^assignment { state = ASSIGNMENT_OPERATOR; }
[a-zA-Z1-9]+ {
if(state != LOOKUP) {
addWord(state, yytext);
} else {
switch(lookupWord(yytext))
{
case INT: printf("%s: int\n", yytext); break;
case FLOAT: printf("%s: float\n", yytext); break;
case TEXT: printf("%s: text\n", yytext); break;
case CHAR: printf("%s: char\n", yytext); break;
case KEYWORD: printf("%s: keyword\n", yytext); break;
case ARGUMENT: printf("%s: argument\n", yytext); break;
case DATATYPE: printf("%s: datatype\n", yytext); break;
case CONDITIONAL_KEY: printf("%s: conditional keyword\n", yytext); break;
case ITERATIVE_KEY: printf("%s: iterative keyword\n", yytext); break;
case ARITHEMATIC_OPERATOR: printf("%s: arithematic operator\n", yytext); break;
case LOGICAL_OPERATOR: printf("%s: logical operator\n", yytext); break;
case RELATIONAL_OPERATOR: printf("%s: relational operator\n", yytext); break;
case IDENTIFIER: printf("%s: identifier\n", yytext); break;
case UNARY_OPERATOR: printf("%s: unary operator\n", yytext); break;
case FORMAT_PROCESSOR: printf("%s: format processor\n", yytext); break;
case FUNCTION: printf("%s: function\n", yytext); break;
case ACCESS_MODIFIER: printf("%s: access modifier\n", yytext); break;
case DELIMITER: printf("%s: delimiter\n", yytext); break;
case COMMA: printf("%s: comma\n", yytext); break;
case INVERTED_COMMAS: printf("%s: inverted commas\n", yytext); break;
case PARANTHESIS: printf("%s: parathesis\n", yytext); break;
case BLOCK: printf("%s: block\n", yytext); break;
case BRACKET: printf("%s: bracket\n", yytext); break;
case ASSIGNMENT_OPERATOR: printf("%s: assignment operator\n", yytext); break;
default: printf("%s: don't recognize\n", yytext); break;
}
}
}
. /* ignore anything else */ ;
%%
void main()
{
yylex();
}
struct word {
char *wordName;
int wordType;
struct word *next;
};
struct word *wordList;
extern void *malloc() ;
int addWord(int type, char *word)
{
struct word *wp;
if(lookupWord(word) != LOOKUP) {
printf("!!! warning: word %s already defined \n", word);
return 0;
}
wp = (struct word *) malloc(sizeof(struct word));
wp->next = wordList;
wp->wordName = (char *) malloc(strlen(word)+1);
strcpy(wp->wordName, word);
wp->wordType = type;
wordList = wp;
return 1;
}
int lookupWord(char *word)
{
struct word *wp = wordList;
for(; wp; wp = wp->next) {
if(strcmp(wp->wordName, word) == 0)
return wp->wordType;
}
return LOOKUP;
}