added comment functionality for lexer, expanded tests, and updated to identify empty strings
This commit is contained in:
@ -7,8 +7,13 @@
|
||||
|
||||
DIGIT [0-9]
|
||||
CHAR \\n|\\t|\\'|[^'\n\t\\]
|
||||
SCHAR \\n|\\t|\\\"|[^\"\n\\]
|
||||
|
||||
/* char can be a newline, tab, an escaped quote, or anything but a single quote, an actual line break, an actual tab, or a backslash by itself (to prevent confusion from escaped quote */
|
||||
SCHAR \\n|\\t|\\\"|[^\"\n\\]
|
||||
/*similar to above, a string Char (SCHAR) is the same as a CHAR except we cannot have double quotes instead of single quotes. Double quotes need to be escaped in Flex unlike single quotes based on documentation */
|
||||
STARTCOM \(\*
|
||||
ENDCOM \*\)
|
||||
COMMENTCHAR [^\*]|\*[^\)]
|
||||
/*Making the contents of a comment anything that is either not a * or not a * followed by ) to terminate comments at the first ENDCOM */
|
||||
%%
|
||||
/* rules */
|
||||
{DIGIT}+ {printf( "C_INTEGER: %s (%d)\n", yytext, atoi( yytext ) );}
|
||||
@ -21,7 +26,9 @@ SCHAR \\n|\\t|\\\"|[^\"\n\\]
|
||||
|
||||
"false" {printf( "C_FALSE: %s (%d)\n", yytext, atoi( yytext ) );}
|
||||
|
||||
\"{SCHAR}+\" {printf( "C_STRING: %s (%d)\n", yytext, atoi( yytext ) );}
|
||||
\"{SCHAR}*\" {printf( "C_STRING: %s (%d)\n", yytext, atoi( yytext ) );}
|
||||
|
||||
{STARTCOM}{COMMENTCHAR}*{ENDCOM} {printf( "COMMENT: %s (%d)\n", yytext, atoi( yytext ) );}
|
||||
|
||||
.|\n
|
||||
|
||||
|
@ -1,9 +1,15 @@
|
||||
"this is a string" 721398 'g' '/n'
|
||||
12893 "this is not a string
|
||||
"this is a string" 721398 'g' '/n' (* should print 3 tokens before this *)
|
||||
'
|
||||
'
|
||||
12893 "this is not a string (*one valid token before this*)
|
||||
(* spacey comment here
|
||||
over multiple lines
|
||||
will it work? *)
|
||||
"
|
||||
'''
|
||||
'\'
|
||||
false
|
||||
(**)
|
||||
'''
|
||||
nullfalse
|
||||
"nulltrue
|
||||
@ -21,6 +27,7 @@ true
|
||||
'n'
|
||||
'\'
|
||||
'fdsf'
|
||||
(*/jnewjno2893u86^ Lots of random characters /n /t '") *)
|
||||
'
|
||||
'
|
||||
' '
|
||||
|
Reference in New Issue
Block a user