From 145d3eeb85d874364198fe6af8c01bac2d646ff4 Mon Sep 17 00:00:00 2001 From: Partho Bhattacharya Date: Fri, 7 Feb 2025 14:31:10 -0500 Subject: [PATCH] updated lex file to have working code for all except for chars and strings. Also added the test files for just Int Testing and for testing for all literals (that is still failing for char and strings) --- lexicalStructure.lex | 36 +++++++++++++++++++++++++----------- simpleIntTest.txt | 4 ++++ simpleLiteralTest.a | 11 +++++++++++ 3 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 simpleIntTest.txt create mode 100644 simpleLiteralTest.a diff --git a/lexicalStructure.lex b/lexicalStructure.lex index 706baca..de6d394 100644 --- a/lexicalStructure.lex +++ b/lexicalStructure.lex @@ -1,23 +1,37 @@ -/* Lexical Analysis with Flex (2.6.0) We used some of the code from this manual */ -/* so we placed the citation here. */ -/* definitions */ + /* Lexical Analysis with Flex (2.6.0) We used some of the code from this manual */ + /* so we placed the citation here. */ + /* definitions */ %option noyywrap - %{ - #include - %} +%{ +#include "typedefs.h" +%} +DIGIT [0-9] %% -/* rules */ -[0-9]+ {printf( "C_INTEGER: %s (%d)\n", yytext, atoi( yytext ) );} + /* rules */ +{DIGIT}+ {printf( "C_INTEGER: %s (%d)\n", yytext, atoi( yytext ) );} "null" {printf( "C_NULL: %s (%d)\n", yytext, atoi( yytext ) );} -['][.]['] | [']\\[nt'\\]['] {printf( "C_CHARACTER: %s (%d)\n", yytext, atoi( yytext ) );} /*using double \ per documentation to show escaped chars*/ +"'"[.|\n]"'" {printf( "C_CHARACTER: %s (%d)\n", yytext, atoi( yytext ) );} /*using double \ per documentation to show escaped chars*/ "true" {printf( "C_TRUE: %s (%d)\n", yytext, atoi( yytext ) );} "false" {printf( "C_FALSE: %s (%d)\n", yytext, atoi( yytext ) );} -["][.]+["] {printf( "C_STRING: %s (%d)\n", yytext, atoi( yytext ) );} +"\""[\^{}}\n]*"\"" {printf( "C_STRING: %s (%d)\n", yytext, atoi( yytext ) );} + +.|\n + %% -/* user code */ + /* user code */ + +int main( int argc, char **argv ) +{ + argc--, argv++; /* skip over program name */ + if ( argc > 0 ) + yyin = fopen( argv[0], "r" ); + else + yyin = stdin; + yylex(); +} diff --git a/simpleIntTest.txt b/simpleIntTest.txt new file mode 100644 index 0000000..507ec22 --- /dev/null +++ b/simpleIntTest.txt @@ -0,0 +1,4 @@ +45 +123 +8392 + diff --git a/simpleLiteralTest.a b/simpleLiteralTest.a new file mode 100644 index 0000000..d93c06a --- /dev/null +++ b/simpleLiteralTest.a @@ -0,0 +1,11 @@ +"this is a string" 721398 'g' '/n' +12893 "this is not a string +" +false +nullfalse +"nulltrue +null +'7' +true +'189 +