Merge branch 'Dev' into Sprint1-TokenizeConstantsAndLiterals-FE-t#03

This commit is contained in:
Moroseui
2025-02-12 12:45:55 -05:00
committed by GitHub
5 changed files with 135 additions and 29 deletions

View File

@ -1,11 +1,13 @@
/* so we placed the citation here. */
/* definitions */
/* Lexical Analysis with Flex (1.6.0) We used some of the code from this manual */
/* so we placed the citation here. */
/* definitions */
%option noyywrap
%{
#include "typedefs.h"
%}
int line_number = 1, column_number = 1;
DIGIT [0-9]
CHAR \\n|\\t|\\'|[^'\n\t\\]
@ -18,33 +20,61 @@ 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 */
%%
\n line_number++ column_number = 1;
. column_number++;
"integer" {return T_INTEGER}
"address" {return T_ADDRESS}
"Boolean" {return T_BOOLEAN}
"character" {return T_CHARACTER}
/* rules */
{DIGIT}+ {printf( "C_INTEGER: %s (%d)\n", yytext, atoi( yytext ) );}
"null" {printf( "C_NULL: %s (%d)\n", yytext, atoi( yytext ) );}
"while" {return WHILE}
"if" {return IF}
"then" {return THEN}
"else" {return ELSE}
"type" {return TYPE}
"function" {return FUNCTION}
"return" {return RETURN}
"external" {return EXTERNAL}
"as" {return AS}
'{CHAR}' {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 ) );}
/* OPERATORS */
"+" {return ADD;}
"-" {return SUB_OR_NEG;}
"*" {return MUL;}
"/" {return DIV;}
"%" {return REM;}
"<" {return LESS_THAN;}
"=" {return EQUAL_TO;}
":=" {return ASSIGN;}
"!" {return NOT;}
"&" {return AND;}
"|" {return OR;}
"." {return DOT;}
"reserve" {return RESERVE;}
"release" {return RELEASE;}
\"{SCHAR}*\" {printf( "C_STRING: %s (%d)\n", yytext, atoi( yytext ) );}
\(\*{COMMENTCHAR}*\*\) {printf( "COMMENT: %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();
}