diff --git a/lexicalStructure.lex b/lexicalStructure.lex index f5315a1..1e2b52c 100644 --- a/lexicalStructure.lex +++ b/lexicalStructure.lex @@ -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 diff --git a/simpleLiteralTest.a b/simpleLiteralTest.a index e85644b..f97cf52 100644 --- a/simpleLiteralTest.a +++ b/simpleLiteralTest.a @@ -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 '") *) ' ' ' '