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 +