finished my assignment and added the line number and column number functionality to my file. t#07

This commit is contained in:
Meyer Simon
2025-02-11 16:26:30 -05:00
parent 78c743736c
commit bfa79fe7be
4 changed files with 18 additions and 1894 deletions

1870
lex.yy.c

File diff suppressed because it is too large Load Diff

BIN
lexer

Binary file not shown.

Binary file not shown.

View File

@ -5,37 +5,31 @@
%{
#include "typedefs.h"
%}
int line_number = 1, column_number = 1;
%%
.|\n
"integer" {printf("T_INTEGER %s, Token %d\n",yytext, T_INTEGER);} //{return T_INTEGER}
"address" {printf("T_ADDRESS %s, Token %d\n",yytext, T_ADDRESS);} //{return T_ADDRESS}
"Boolean" {printf("T_BOOLEAN %s, Token %d\n",yytext, T_BOOLEAN);} //{return T_BOOLEAN}
"character" {printf("T_CHARACTER %s, Token %d\n",yytext, T_CHARACTER);} //{return T_CHARACTER}
"string" {printf("T_STRING %s, Token %d\n",yytext, T_STRING);} //{return T_STRING}
\n line_number++ column_number = 1;
. column_number++;
"integer" {return T_INTEGER}
"address" {return T_ADDRESS}
"Boolean" {return T_BOOLEAN}
"character" {return T_CHARACTER}
"string" {return T_STRING}
/* KEYWARDS */
"while" {printf("WHILE %s, Token %d\n",yytext, WHILE);} //{return WHILE}
"if" {printf("IF %s, Token %d\n",yytext, IF);} //{return IF}
"then" {printf("THEN %s, Token %d\n",yytext, THEN);} //{return THEN}
"else" {printf("ELSE %s, Token %d\n",yytext, ELSE);} //{return ELSE}
"type" {printf("TYPE %s, Token %d\n",yytext, TYPE);} //{return TYPE}
"function" {printf("FUNCTION %s, Token %d\n",yytext, FUNCTION);} //{return FUNCTION}
"return" {printf("RETURN %s, Token %d\n",yytext, RETURN);} //{return RETURN}
"external" {printf("EXTERNAL %s, Token %d\n",yytext, EXTERNAL);} //{return EXTERNAL}
"as" {printf("AS %s, Token %d\n",yytext, AS);} //{return AS}
"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}
%%
int main(int argc, char *argv[]){
argc--, argv++;
if ( argc > 0 )
yyin = fopen( argv[0], "r" );
else
yyin = stdin;
yylex();
}