83 |
%let idchar = {letter}|{dig}|"_"|"'"; |
%let idchar = {letter}|{dig}|"_"|"'"; |
84 |
%let id = {letter}{idchar}*; |
%let id = {letter}{idchar}*; |
85 |
%let ws = " "|[\t\n\v\f\r]; |
%let ws = " "|[\t\n\v\f\r]; |
86 |
|
%let esc = "\\"[abfnrtv\\\"]|"\\"{dig}{dig}{dig}; |
87 |
|
%let sgood = [\032-\126]&[^\"\\]; (* sgood means "characters good inside strings" *) |
88 |
|
%let eol = "\n"; |
89 |
|
|
90 |
(***** Keywords and operators *****) |
(***** Keywords and operators *****) |
91 |
|
|
|
<INITIAL> "(" => (T.LP); |
|
|
<INITIAL> ")" => (T.RP); |
|
|
<INITIAL> "[" => (T.LB); |
|
|
<INITIAL> "]" => (T.RB); |
|
|
<INITIAL> "{" => (T.LCB); |
|
|
<INITIAL> "}" => (T.RCB); |
|
92 |
<INITIAL> "||" => (T.OP_orelse); |
<INITIAL> "||" => (T.OP_orelse); |
93 |
<INITIAL> "&&" => (T.OP_andalso); |
<INITIAL> "&&" => (T.OP_andalso); |
94 |
<INITIAL> "<" => (T.OP_lt); |
<INITIAL> "<" => (T.OP_lt); |
100 |
<INITIAL> "+" => (T.OP_plus); |
<INITIAL> "+" => (T.OP_plus); |
101 |
<INITIAL> "-" => (T.OP_minus); |
<INITIAL> "-" => (T.OP_minus); |
102 |
<INITIAL> "*" => (T.OP_star); |
<INITIAL> "*" => (T.OP_star); |
103 |
|
<INITIAL> "/" => (T.OP_slash); |
104 |
<INITIAL> "@" => (T.OP_at); |
<INITIAL> "@" => (T.OP_at); |
105 |
|
<INITIAL> "(" => (T.LP); |
106 |
|
<INITIAL> ")" => (T.RP); |
107 |
|
<INITIAL> "[" => (T.LB); |
108 |
|
<INITIAL> "]" => (T.RB); |
109 |
|
<INITIAL> "{" => (T.LCB); |
110 |
|
<INITIAL> "}" => (T.RCB); |
111 |
<INITIAL> "," => (T.COMMA); |
<INITIAL> "," => (T.COMMA); |
112 |
<INITIAL> ";" => (T.SEMI); |
<INITIAL> ";" => (T.SEMI); |
113 |
<INITIAL> "#" => (T.HASH); |
<INITIAL> "#" => (T.HASH); |
114 |
<INITIAL> "!" => (T.BANG); |
<INITIAL> "!" => (T.BANG); |
115 |
|
<INITIAL> "=" => (T.OP_eq); |
116 |
|
|
117 |
<INITIAL> {id} => (Keywords.idToken yytext); |
<INITIAL> {id} => (Keywords.idToken yytext); |
118 |
|
|
122 |
=> (mkFloat yysubstr); |
=> (mkFloat yysubstr); |
123 |
<INITIAL> {ws} => (skip ()); |
<INITIAL> {ws} => (skip ()); |
124 |
|
|
125 |
|
<INITIAL> . => (lexErr(yypos, ["bad character `", String.toString yytext]); |
126 |
|
continue()); |
127 |
|
|
128 |
|
(***** Strings *****) |
129 |
|
|
130 |
|
<INITIAL> "\"" => (YYBEGIN STRING; continue()); |
131 |
|
<STRING>{esc} => (addStr(valOf(String.fromString yytext)); continue()); |
132 |
|
<STRING>{sgood}+ => (addStr yytext; continue()); |
133 |
|
<STRING> "\"" => (YYBEGIN INITIAL; mkString()); |
134 |
|
|
135 |
|
<STRING> . => (lexErr(yypos, [ |
136 |
|
"bad character `", String.toString yytext, |
137 |
|
"' in string literal" |
138 |
|
]); |
139 |
|
continue()); |
140 |
|
|
141 |
(***** Comments *****) |
(***** Comments *****) |
142 |
<INITIAL> "//" |
<INITIAL> "//" => (YYBEGIN COM1; skip()); |
143 |
=> (YYBEGIN COM1; skip()); |
<COM1> {eol} => (YYBEGIN INITIAL; skip()); |
144 |
<COM1> {eol} |
<COM1> . => (skip()); |
|
=> (YYBEGIN INITIAL; skip()); |
|
145 |
|
|
146 |
<INITIAL> "/*" |
<INITIAL> "/*" |
147 |
=> (YYBEGIN COM2; skip()); |
=> (YYBEGIN COM2; skip()); |