Branch Initialize

This commit is contained in:
Scarlett
2025-02-10 12:26:23 -05:00
parent 200307291c
commit 232ad5c9ae
4 changed files with 67 additions and 31 deletions

View File

@ -1,14 +1,19 @@
# Basic Makefile example from flex documentation -- provides explicit rules CC := gcc
# Creates "myprogram" from "scan.l" and "myprogram.c" FLEX := flex
# LEX := lexicalStructure.lex
#LEX=flex EXE := lexicalStructure
#myprogram: scan.o myprogram.o
#$(CC) -o $@ $(LDFLAGS) $^ lexicalStructure:
#myprogram.o: myprogram.c $(FLEX) $(LEX)
#$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $^ $(CC) lex.yy.c -o $(EXE)
#scan.o: scan.c
#$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $^ test:
#scan.c: scan.l ./$(EXE) ./tests/test_constants_literals.txt
#$(LEX) $(LFLAGS) -o $@ $^ ./$(EXE) ./tests/test_keywards.alpha
#clean: ./$(EXE) ./tests/test_types.alpha
#$(RM) *.o scan.c ./$(EXE) ./tests/test_variables.txt
clean:
rm -f *.o
rm -f lex.yy.c
rm -f $(EXE)

View File

@ -6,31 +6,39 @@
#include "typedefs.h" #include "typedefs.h"
%} %}
DIGIT [0-9]
CHAR \\\\n|\\\\t|\\\'|[^'\\\n\t]
STRINGVAL CHAR | " "
%% %%
{DIGIT}+ {printf( "C_INTEGER: %s (%d)\n", yytext, atoi( yytext ) );}
"null" {printf( "C_NULL: %s (%d)\n", yytext, atoi( yytext ) );}
'{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 ) );}
"{STRINGVAL}+" {printf( "C_STRING: %s (%d)\n", yytext, atoi( yytext ) );}
.|\n .|\n
"integer" {printf("T_INTEGER %s, Token %d\n",yytext, T_INTEGER);} //{return T_INTEGER} "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} "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} "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} "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} "string" {printf("T_STRING %s, Token %d\n",yytext, T_STRING);} // {return T_STRING}
/* KEYWARDS */ /* KEYWARDS */
"while" {printf("WHILE %s, Token %d\n",yytext, WHILE);} // {return WHILE}
"if" {printf("IF %s, Token %d\n",yytext, IF);} // {return IF}
"while" {printf("WHILE %s, Token %d\n",yytext, WHILE);} //{return WHILE} "then" {printf("THEN %s, Token %d\n",yytext, THEN);} // {return THEN}
"if" {printf("IF %s, Token %d\n",yytext, IF);} //{return IF} "else" {printf("ELSE %s, Token %d\n",yytext, ELSE);} // {return ELSE}
"then" {printf("THEN %s, Token %d\n",yytext, THEN);} //{return THEN} "type" {printf("TYPE %s, Token %d\n",yytext, TYPE);} // {return TYPE}
"else" {printf("ELSE %s, Token %d\n",yytext, ELSE);} //{return ELSE} "function" {printf("FUNCTION %s, Token %d\n",yytext, FUNCTION);} // {return FUNCTION}
"type" {printf("TYPE %s, Token %d\n",yytext, TYPE);} //{return TYPE} "return" {printf("RETURN %s, Token %d\n",yytext, RETURN);} // {return RETURN}
"function" {printf("FUNCTION %s, Token %d\n",yytext, FUNCTION);} //{return FUNCTION} "external" {printf("EXTERNAL %s, Token %d\n",yytext, EXTERNAL);} // {return EXTERNAL}
"return" {printf("RETURN %s, Token %d\n",yytext, RETURN);} //{return RETURN} "as" {printf("AS %s, Token %d\n",yytext, AS);} // {return AS}
"external" {printf("EXTERNAL %s, Token %d\n",yytext, EXTERNAL);} //{return EXTERNAL}
"as" {printf("AS %s, Token %d\n",yytext, AS);} //{return AS}
%% %%
int main(int argc, char *argv[]){ int main(int argc, char *argv[]){
argc--, argv++; argc--, argv++;
if ( argc > 0 ) if ( argc > 0 )

View File

@ -0,0 +1,23 @@
This is a test
9combined 7okens
12345
893247892
combined'DueToUnknownChar _validtoken __validtoken1 _valid_token2 validToken3_
true false
null while !wrong if when
else type function
return external as
string _NOte_that_was_not_reserved
([)]{}:;,->"\
+-*/%
<=
:=
"This is not a valid
String"
"This is a valid String"
!|
..
(* this is a comment *)
(*Not a comment
$^&
>

0
tests/test_variables.txt Normal file
View File