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)

This commit is contained in:
Partho Bhattacharya
2025-02-07 14:31:10 -05:00
parent cfd64648d9
commit 145d3eeb85
3 changed files with 40 additions and 11 deletions
+18 -4
View File
@@ -3,21 +3,35 @@
/* definitions */
%option noyywrap
%{
#include <typedefs.h>
#include "typedefs.h"
%}
DIGIT [0-9]
%%
/* rules */
[0-9]+ {printf( "C_INTEGER: %s (%d)\n", yytext, atoi( yytext ) );}
{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 */
int main( int argc, char **argv )
{
argc--, argv++; /* skip over program name */
if ( argc > 0 )
yyin = fopen( argv[0], "r" );
else
yyin = stdin;
yylex();
}
+4
View File
@@ -0,0 +1,4 @@
45
123
8392
+11
View File
@@ -0,0 +1,11 @@
"this is a string" 721398 'g' '/n'
12893 "this is not a string
"
false
nullfalse
"nulltrue
null
'7'
true
'189