Added return statements t#04

This commit is contained in:
Scarlett
2025-02-11 17:15:54 -05:00
parent 9c67da0348
commit 466f111c87
10 changed files with 1809 additions and 128 deletions

View File

@ -8,7 +8,7 @@ lexicalStructure:
$(CC) lex.yy.c -o $(EXE)
test1:
./$(EXE) ./tests/test_constants_literals.txt
./$(EXE) ./tests/test_constants_literals.alpha
test2:
./$(EXE) ./tests/test_keywards.alpha
@ -17,10 +17,13 @@ test3:
./$(EXE) ./tests/test_types.alpha
test4:
./$(EXE) ./tests/test_variables.txt
./$(EXE) ./tests/test_variables.alpha
test5:
./$(EXE) ./tests/test_otherpunc.txt
./$(EXE) ./tests/test_otherpunc.alpha
test6:
./$(EXE) ./tests/test_comments.alpha
clean:
rm -f *.o

1787
lex.yy.c Normal file

File diff suppressed because it is too large Load Diff

BIN
lexicalStructure Executable file

Binary file not shown.

View File

@ -6,47 +6,19 @@
#include "typedefs.h"
%}
DIGIT [0-9]
CHAR \\n|\\t|\\'|[^'\n\t\\]
SCHAR \\n|\\t|\\\"|[^\"\n\\]
COM ([^*]|\*+[^)*])*
ID [A-Za-z_][0-9A-Za-z_]*
%%
"(*"{COM}"*)" {printf("COMMENT: %s, Token: %d\n", yytext, COMMENT );} // {return COMMENT}
"(*"{COM}"*)" {return COMMENT;}
"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}
";" {return SEMI_COLON;}
":" {return COLON;}
"," {return COMMA;}
"->" {return ARROW;}
"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}
";" {printf("SEMI_COLON %s, Token: %d\n", yytext, SEMI_COLON);}
":" {printf("COLON %s, Token: %d\n", yytext, COLON);}
"," {printf("COMMA %s, Token: %d\n", yytext, COMMA);}
"->" {printf("ARROW %s, Token: %d\n", yytext, ARROW);}
{DIGIT}+ {printf("C_INTEGER: %s, Token: %d\n", yytext, atoi( yytext ) );}
"null" {printf("C_NULL: %s, Token: %d\n", yytext, atoi( yytext ) );}
'{CHAR}' {printf("C_CHARACTER: %s, Token: %d\n", yytext, atoi( yytext ) );}
"true" {printf("C_TRUE: %s, Token: %d\n", yytext, atoi( yytext ) );}
"false" {printf("C_FALSE: %s, Token: %d\n", yytext, atoi( yytext ) );}
\"{SCHAR}*\" {printf("C_STRING: %s, Token: %d\n", yytext, atoi( yytext ) );}
{ID} {printf("ID: %s, Token: %d\n", yytext, ID);}
.|\n
{ID} {return ID;}
%%
@ -57,4 +29,4 @@ int main(int argc, char *argv[]){
else
yyin = stdin;
yylex();
}
}

View File

@ -0,0 +1,9 @@
(* hello *)
(* hello *)
(* I'd think this is a legal "string" that contains several \n \t
escaped characters, isn't it? *)
(* \ *)
(* *)
(*{COMMENT}+ *)
(* * *)
(* (hello) *)

View File

@ -1,50 +0,0 @@
'''
'\'
false
'''
nullfalse
"nulltrue
null
'7'
true
'189
'\t'
'"'
'/'
'\n'
'\''
'\t'
'\\'
'n'
'\'
'fdsf'
'
'
' '
'''
"STRINGwithnotSPaces"
' '
'\ '
"J"
""
" "
\"\"
"this is a string" 721398 'g' '/n'
12893 "this is not a string
"{SCHAR}"
"SCHAR"
"[SCHAR]"
"I'd think this is a legal \"string\" that contains \n \t several escaped characters, isn't it?"
"I'd think this is a legal \"string\" that contains several \\n \\t escaped characters, isn't it?"
(* hello *)
(* hello *)
(* I'd think this is a legal "string" that contains several \n \t
escaped characters, isn't it? *)
(* \ *)
(* *)
(*{COMMENT}+ *)
(* * *)
(* (hello) *)

View File

@ -1,30 +0,0 @@
while
While
whiLe
if
IF
If
iF
then
Then
theN
else
eLse
elSe
Else
type
Type
tyPe
function
Function
functioN
return
Return
returN
external
External
exteRnal
as
As
aS
functionaly

View File

@ -1,10 +0,0 @@
integer
Integer
address
Address
Boolean
boolean
character
Character
string
String