Skip to content

Commit 3134286

Browse files
committed
Handle lowercase variable names
M100 BASIC barfs with a syntax error if presented with a lowercase variable name in a tokenized file. Fortunately, the fix was easy: since the lexer is already matching all BASIC keywords plus strings, remarks, and data statements, the only thing left was variables. So, all we have to do is use yyput(toupper()) instead of the default ECHO.
1 parent 3fe7b7c commit 3134286

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

m100-tokenize.lex

+15
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
* gcc lex.tokenize.c
77
*/
88

9+
#include <ctype.h> /* For toupper() */
10+
911
%option prefix="tokenize"
12+
%option case-insensitive
1013

1114
/* Define states that simply copy text instead of lexing */
1215
%x string
@@ -51,6 +54,7 @@
5154
yyterminate();
5255
}
5356

57+
/* Table of tokens, case-insensitive due to %option above. */
5458
END yyput(128);
5559
FOR yyput(129);
5660
NEXT yyput(130);
@@ -181,6 +185,17 @@ ASC yyput(249);
181185
"MID$" yyput(254);
182186
"'" yyput(':'); yyput(0x8E); yyput(0xFF); BEGIN(remark);
183187

188+
189+
/* Anything not yet matched is a variable name, so capitalize it. */
190+
<INITIAL>. {
191+
char *yptr = yytext;
192+
while ( *yptr )
193+
yyput( toupper( *yptr++ ) );
194+
}
195+
196+
197+
198+
184199
%%
185200

186201
/* The main() routine, yyput(), fixup_ptrs() */

0 commit comments

Comments
 (0)