Initial version of donated sources by Avertec, 3.4p5.
[tas-yagle.git] / distrib / sources / tas / stb / stb.lex
1 %{
2 #include STB_H
3 #include "stb_parse.h"
4 #include "stb.tab.h"
5
6 #define ECHO
7 //fprintf(stderr,"\n-=<{oo}>=- %s\n",yytext)
8 #define YY_NO_UNPUT
9 /* ###--------------------------------------------------------------### */
10 /* function : search */
11 /* description : check that an identifier is a reserved word or not */
12 /* called func. : addht, addhtitem, gethtitem, namealloc */
13 /* ###--------------------------------------------------------------### */
14
15 extern int yylineno;
16
17 static char *stripquotes();
18
19 static int search (key)
20 char *key;
21 {
22 static ht *pt_hash = NULL;
23
24 if (pt_hash == NULL) {
25 pt_hash = addht (100);
26 addhtitem (pt_hash, namealloc("begin"), _BEGIN);
27 addhtitem (pt_hash, namealloc("clock"), _CLOCK);
28 addhtitem (pt_hash, namealloc("connectors"), _CONNECTORS);
29 addhtitem (pt_hash, namealloc("groups"), _GROUPS);
30 addhtitem (pt_hash, namealloc("asynchronous"), _ASYNCHRONOUS);
31 addhtitem (pt_hash, namealloc("equivalent"), _EQUIVALENT);
32 addhtitem (pt_hash, namealloc("disable"), _DISABLE);
33 addhtitem (pt_hash, namealloc("stable"), _STABLE);
34 addhtitem (pt_hash, namealloc("down"), _DOWN);
35 addhtitem (pt_hash, namealloc("default"), _DEFAULT);
36 addhtitem (pt_hash, namealloc("end"), _END);
37 addhtitem (pt_hash, namealloc("holdtime"), _HOLDTIME);
38 addhtitem (pt_hash, namealloc("input"), _INPUT);
39 addhtitem (pt_hash, namealloc("name"), _NAME);
40 addhtitem (pt_hash, namealloc("stability"), _STABILITY);
41 addhtitem (pt_hash, namealloc("output"), _OUTPUT);
42 addhtitem (pt_hash, namealloc("period"), _PERIOD);
43 addhtitem (pt_hash, namealloc("setuptime"), _SETUPTIME);
44 addhtitem (pt_hash, namealloc("version"), _VERSION);
45 addhtitem (pt_hash, namealloc("unstable"), _UNSTABLE);
46 addhtitem (pt_hash, namealloc("verify"), _VERIFY);
47 addhtitem (pt_hash, namealloc("specify"), _SPECIFY);
48 addhtitem (pt_hash, namealloc("up"), _UP);
49 addhtitem (pt_hash, namealloc("down"), _DOWN);
50 addhtitem (pt_hash, namealloc("noverif"), _NOVERIF);
51 addhtitem (pt_hash, namealloc("rising"), _RISING);
52 addhtitem (pt_hash, namealloc("falling"), _FALLING);
53 addhtitem (pt_hash, namealloc("from"), _FROM);
54 addhtitem (pt_hash, namealloc("for"), _FOR);
55 addhtitem (pt_hash, namealloc("to"), _TO);
56 addhtitem (pt_hash, namealloc("internal"), _INTERNAL);
57 addhtitem (pt_hash, namealloc("nodes"), _NODES);
58 addhtitem (pt_hash, namealloc("after"), _AFTER);
59 addhtitem (pt_hash, namealloc("before"), _BEFORE);
60 addhtitem (pt_hash, namealloc("conditioned"), _CONDITIONED);
61 addhtitem (pt_hash, namealloc("command"), _COMMAND);
62 addhtitem (pt_hash, namealloc("states"), _STATES);
63 addhtitem (pt_hash, namealloc("without"), _WITHOUT);
64 addhtitem (pt_hash, namealloc("precharge"), _PRECHARGE);
65 addhtitem (pt_hash, namealloc("evaluate"), _EVALUATE);
66 addhtitem (pt_hash, namealloc("multiple"), _MULTIPLE);
67 addhtitem (pt_hash, namealloc("priority"), _PRIORITY);
68 addhtitem (pt_hash, namealloc("memory"), _MEMORY);
69 }
70 return (gethtitem (pt_hash, namealloc(key)));
71 }
72
73 %}
74
75 upper_case_letter [A-Z]
76 digit [0-9]
77 wildcard [*]
78 allowed [/]
79 space_character [ \t]
80 format_effector [\t\v\r\l\f]
81 end_of_line \n
82 lower_case_letter [a-z]
83 wildcard_letter ({upper_case_letter}|{lower_case_letter}|{wildcard})
84 wildcard_letter_or_digit ({wildcard_letter}|{digit}|{allowed})
85 decimal_literal {integer}(\.{integer})?
86 integer [\-]?{digit}(_?{digit})*
87 comment ^[ \t]*[#]+.*
88
89 %%
90 {end_of_line} {ECHO;yylineno++;}
91 {space_character} {ECHO;}
92 {comment} {ECHO;}
93 \( {ECHO;return(LeftParen);}
94 \) {ECHO;return(RightParen);}
95 \: {ECHO;return(Colon);}
96 \; {ECHO;return(Semicolon);}
97 \, {ECHO;return(Comma);}
98 \! {ECHO;return(Not);}
99
100
101 \"[^ \t\n]*\" {
102 ECHO;
103 stblval.text = stripquotes(yytext);
104 return (Identifier);
105 }
106
107 {wildcard_letter}((([.]?)|(_*)){wildcard_letter_or_digit})*(\[{integer}\])? {
108 int itoken;
109
110 ECHO;
111 itoken = search (yytext);
112 if (itoken == EMPTYHT) {
113 stblval.text = namealloc(yytext);
114 return (Identifier);
115 }
116 else {
117 return (itoken);
118 }
119 }
120
121 {integer} {
122 ECHO;
123 stblval.valu = (int) strtol(yytext,(char**)NULL,10);
124 return (Integer);
125 }
126
127 {decimal_literal} {
128 ECHO;
129 stblval.valu = (int) strtod(yytext,(char**)NULL);
130 return (decimal_literal);
131 }
132
133 %%
134
135 static char *stripquotes(source)
136 char *source;
137 {
138 char dest[1024];
139 int i = 0, j = 0;
140
141 while (*source != 0 && i < 1023) {
142 if ((dest[i] = source[j++]) != '"') i++;
143 }
144 dest[i] = 0;
145
146 return namealloc(dest);
147 }
148
149 int stbclosefile()
150 {
151 return(fclose(stbin)) ;
152 }
153
154 int yywrap() {return 1;}