Sprint1 tokenize operators fe t#08
This commit is contained in:
Annie Slenker
2025-02-11 16:48:59 -05:00
committed by GitHub
3 changed files with 64 additions and 31 deletions

View File

@ -1,14 +1,16 @@
# 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_operators:
#scan.c: scan.l ./$(EXE) ./tests/test_operators.alpha
#$(LEX) $(LFLAGS) -o $@ $^
#clean: clean:
#$(RM) *.o scan.c rm -f *.o
rm -f lex.yy.c
rm -f $(EXE)

View File

@ -1,5 +1,7 @@
/* so we placed the citation here. */ /* Lexical Analysis with Flex (1.6.0) We used some of the code from this manual */
/* definitions */ /* so we placed the citation here. */
/* definitions */
%option noyywrap %option noyywrap
%{ %{
@ -18,6 +20,7 @@ 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 */ /*Making the contents of a comment anything that is either not a * or not a * followed by ) to terminate comments at the first ENDCOM */
%% %%
/* rules */ /* rules */
{DIGIT}+ {printf( "C_INTEGER: %s (%d)\n", yytext, atoi( yytext ) );} {DIGIT}+ {printf( "C_INTEGER: %s (%d)\n", yytext, atoi( yytext ) );}
@ -29,22 +32,27 @@ COMMENTCHAR [^\*]|\*[^\)]
"false" {printf( "C_FALSE: %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 ) );} \"{SCHAR}*\" {printf( "C_STRING: %s (%d)\n", yytext, atoi( yytext ) );}
{STARTCOM}{COMMENTCHAR}*{ENDCOM} {printf( "COMMENT: %s (%d)\n", yytext, atoi( yytext ) );} {STARTCOM}{COMMENTCHAR}*{ENDCOM} {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();
}

View File

@ -0,0 +1,23 @@
+
-
*
/
\
%
<
>
=
:=
=:
:
=
!
&
|
.
relEASE
release
RELEASE
reserve
RESERVE
reSERVe