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:
@ -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 <typedefs.h>
|
||||
%}
|
||||
%{
|
||||
#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();
|
||||
}
|
||||
|
4
simpleIntTest.txt
Normal file
4
simpleIntTest.txt
Normal file
@ -0,0 +1,4 @@
|
||||
45
|
||||
123
|
||||
8392
|
||||
|
11
simpleLiteralTest.a
Normal file
11
simpleLiteralTest.a
Normal 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
|
||||
|
Reference in New Issue
Block a user