diff --git a/Makefile b/Makefile index a9544ee..3a7cffc 100644 --- a/Makefile +++ b/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) diff --git a/lexicalStructure.lex b/lexicalStructure.lex index 22632ba..dd5b71e 100644 --- a/lexicalStructure.lex +++ b/lexicalStructure.lex @@ -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(); - -} +%% \ No newline at end of file diff --git a/tests/test_operators.alpha b/tests/test_operators.alpha new file mode 100644 index 0000000..b985387 --- /dev/null +++ b/tests/test_operators.alpha @@ -0,0 +1,23 @@ ++ +- +* +/ +\ +% +< +> += +:= +=: +: += +! +& +| +. +relEASE +release +RELEASE +reserve +RESERVE +reSERVe \ No newline at end of file