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