Merge pull request #3 from UB-CSE443/Sprint1-TokenizeOperators-FE-t#08
Sprint1 tokenize operators fe t#08
This commit is contained in:
30
Makefile
30
Makefile
@ -1,14 +1,16 @@
|
||||
# Basic Makefile example from flex documentation -- provides explicit rules
|
||||
# Creates "myprogram" from "scan.l" and "myprogram.c"
|
||||
#
|
||||
#LEX=flex
|
||||
#myprogram: scan.o myprogram.o
|
||||
#$(CC) -o $@ $(LDFLAGS) $^
|
||||
#myprogram.o: myprogram.c
|
||||
#$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $^
|
||||
#scan.o: scan.c
|
||||
#$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $^
|
||||
#scan.c: scan.l
|
||||
#$(LEX) $(LFLAGS) -o $@ $^
|
||||
#clean:
|
||||
#$(RM) *.o scan.c
|
||||
CC := gcc
|
||||
FLEX := flex
|
||||
LEX := lexicalStructure.lex
|
||||
EXE := lexicalStructure
|
||||
|
||||
lexicalStructure:
|
||||
$(FLEX) $(LEX)
|
||||
$(CC) lex.yy.c -o $(EXE)
|
||||
|
||||
test_operators:
|
||||
./$(EXE) ./tests/test_operators.alpha
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
rm -f lex.yy.c
|
||||
rm -f $(EXE)
|
||||
|
@ -1,5 +1,7 @@
|
||||
/* so we placed the citation here. */
|
||||
/* definitions */
|
||||
/* Lexical Analysis with Flex (1.6.0) We used some of the code from this manual */
|
||||
/* so we placed the citation here. */
|
||||
/* definitions */
|
||||
|
||||
%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 */
|
||||
%%
|
||||
|
||||
|
||||
/* rules */
|
||||
{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 ) );}
|
||||
|
||||
/* 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 ) );}
|
||||
|
||||
{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();
|
||||
|
||||
}
|
||||
%%
|
23
tests/test_operators.alpha
Normal file
23
tests/test_operators.alpha
Normal file
@ -0,0 +1,23 @@
|
||||
+
|
||||
-
|
||||
*
|
||||
/
|
||||
\
|
||||
%
|
||||
<
|
||||
>
|
||||
=
|
||||
:=
|
||||
=:
|
||||
:
|
||||
=
|
||||
!
|
||||
&
|
||||
|
|
||||
.
|
||||
relEASE
|
||||
release
|
||||
RELEASE
|
||||
reserve
|
||||
RESERVE
|
||||
reSERVe
|
Reference in New Issue
Block a user