Test cases added
This commit is contained in:
8
Makefile
8
Makefile
@ -7,8 +7,14 @@ lexicalStructure:
|
|||||||
$(FLEX) $(LEX)
|
$(FLEX) $(LEX)
|
||||||
$(CC) lex.yy.c -o $(EXE)
|
$(CC) lex.yy.c -o $(EXE)
|
||||||
|
|
||||||
test_operators:
|
test:
|
||||||
|
./$(EXE) ./tests/test_comments.alpha
|
||||||
|
./$(EXE) ./tests/test_generalTokenTest.alpha
|
||||||
|
./$(EXE) ./tests/test_keywords.alpha
|
||||||
./$(EXE) ./tests/test_operators.alpha
|
./$(EXE) ./tests/test_operators.alpha
|
||||||
|
./$(EXE) ./tests/test_otherpunc.alpha
|
||||||
|
./$(EXE) ./tests/test_simpleIntTest.alpha
|
||||||
|
./$(EXE) ./tests/test_simpleLiteral.alpha
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.o
|
rm -f *.o
|
||||||
|
@ -4,8 +4,10 @@
|
|||||||
|
|
||||||
%option noyywrap
|
%option noyywrap
|
||||||
%{
|
%{
|
||||||
#include "typedefs.h"
|
#include <stdbool.h>
|
||||||
int line_number = 1, column_number = 1;
|
#include "typedefs.h"
|
||||||
|
int line_number = 1, column_number = 1;
|
||||||
|
bool DEBUG = true;
|
||||||
%}
|
%}
|
||||||
|
|
||||||
COM ([^*]|\*+[^)*])*
|
COM ([^*]|\*+[^)*])*
|
||||||
@ -18,55 +20,63 @@ SCHAR \\n|\\t|\\\"|[^\"\n\\]
|
|||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
"integer" {return T_INTEGER;}
|
"integer" {if(DEBUG) {printf( "T_INTEGER: %s (%d)\n", yytext, T_INTEGER);} else {return T_INTEGER;}}
|
||||||
"address" {return T_ADDRESS;}
|
"address" {if(DEBUG) {printf( "T_ADDRESS: %s (%d)\n", yytext, T_ADDRESS);} else {return T_ADDRESS;}}
|
||||||
"Boolean" {return T_BOOLEAN;}
|
"Boolean" {if(DEBUG) {printf( "T_BOOLEAN: %s (%d)\n", yytext, T_BOOLEAN);} else {return T_BOOLEAN;}}
|
||||||
"character" {return T_CHARACTER;}
|
"character" {if(DEBUG) {printf( "T_CHARACTER: %s (%d)\n", yytext, T_CHARACTER);} else {return T_CHARACTER;}}
|
||||||
|
|
||||||
{DIGIT}+ {return C_INTEGER;}
|
"while" {if(DEBUG) {printf( "WHILE: %s (%d)\n", yytext, WHILE);} else {return WHILE;}}
|
||||||
"null" {return C_NULL;}
|
"if" {if(DEBUG) {printf( "IF: %s (%d)\n", yytext, IF);} else {return IF;}}
|
||||||
|
"then" {if(DEBUG) {printf( "THEN: %s (%d)\n", yytext, THEN);} else {return THEN;}}
|
||||||
|
"else" {if(DEBUG) {printf( "ELSE: %s (%d)\n", yytext, ELSE);} else {return ELSE;}}
|
||||||
|
"type" {if(DEBUG) {printf( "TYPE: %s (%d)\n", yytext, TYPE);} else {return TYPE;}}
|
||||||
|
"function" {if(DEBUG) {printf( "FUNCTION: %s (%d)\n", yytext, FUNCTION);} else {return FUNCTION;}}
|
||||||
|
"return" {if(DEBUG) {printf( "RETURN: %s (%d)\n", yytext, RETURN);} else {return RETURN;}}
|
||||||
|
"external" {if(DEBUG) {printf( "EXTERNAL: %s (%d)\n", yytext, EXTERNAL);} else {return EXTERNAL;}}
|
||||||
|
"as" {if(DEBUG) {printf( "AS: %s (%d)\n", yytext, AS);} else {return AS;}}
|
||||||
|
|
||||||
"while" {return WHILE;}
|
"release" {if(DEBUG) {printf( "RELEASE: %s (%d)\n", yytext, RELEASE);} else {return RELEASE;}}
|
||||||
"if" {return IF;}
|
"reserve" {if(DEBUG) {printf( "RESERVE: %s (%d)\n", yytext, RESERVE);} else {return RESERVE;}}
|
||||||
"then" {return THEN;}
|
|
||||||
"else" {return ELSE;}
|
|
||||||
"type" {return TYPE;}
|
|
||||||
"function" {return FUNCTION;}
|
|
||||||
"return" {return RETURN;}
|
|
||||||
"external" {return EXTERNAL;}
|
|
||||||
"as" {return AS;}
|
|
||||||
|
|
||||||
'{CHAR}' {return C_CHARACTER;}
|
"+" {if(DEBUG) {printf( "ADD: %s (%d)\n", yytext, ADD);} else {return ADD;}}
|
||||||
"true" {return C_TRUE;}
|
"-" {if(DEBUG) {printf( "SUB_OR_NEG: %s (%d)\n", yytext, SUB_OR_NEG);} else {return SUB_OR_NEG;}}
|
||||||
"false" {return C_FALSE;}
|
"*" {if(DEBUG) {printf( "MUL: %s (%d)\n", yytext, MUL);} else {return MUL;}}
|
||||||
|
"/" {if(DEBUG) {printf( "DIV: %s (%d)\n", yytext, DIV);} else {return DIV;}}
|
||||||
|
"%" {if(DEBUG) {printf( "REM: %s (%d)\n", yytext, REM);} else {return REM;}}
|
||||||
|
"<" {if(DEBUG) {printf( "LESS_THAN: %s (%d)\n", yytext, LESS_THAN);} else {return LESS_THAN;}}
|
||||||
|
"=" {if(DEBUG) {printf( "EQUAL_TO: %s (%d)\n", yytext, EQUAL_TO);} else {return EQUAL_TO;}}
|
||||||
|
":=" {if(DEBUG) {printf( "ASSIGN: %s (%d)\n", yytext, ASSIGN);} else {return ASSIGN;}}
|
||||||
|
"!" {if(DEBUG) {printf( "NOT: %s (%d)\n", yytext, NOT);} else {return NOT;}}
|
||||||
|
"&" {if(DEBUG) {printf( "AND: %s (%d)\n", yytext, AND);} else {return AND;}}
|
||||||
|
"|" {if(DEBUG) {printf( "OR: %s (%d)\n", yytext, OR);} else {return OR;}}
|
||||||
|
"." {if(DEBUG) {printf( "DOT: %s (%d)\n", yytext, DOT);} else {return DOT;}}
|
||||||
|
|
||||||
"+" {return ADD;}
|
";" {if(DEBUG) {printf( "SEMI_COLON: %s (%d)\n", yytext, SEMI_COLON);} else {return SEMI_COLON;}}
|
||||||
"-" {return SUB_OR_NEG;}
|
":" {if(DEBUG) {printf( "COLON: %s (%d)\n", yytext, COLON);} else {return COLON;}}
|
||||||
"*" {return MUL;}
|
"," {if(DEBUG) {printf( "COMMA: %s (%d)\n", yytext, COMMA);} else {return COMMA;}}
|
||||||
"/" {return DIV;}
|
"->" {if(DEBUG) {printf( "ARROW: %s (%d)\n", yytext, ARROW);} else {return ARROW;}}
|
||||||
"%" {return REM;}
|
|
||||||
"<" {return LESS_THAN;}
|
|
||||||
"=" {return EQUAL_TO;}
|
|
||||||
":=" {return ASSIGN;}
|
|
||||||
"!" {return NOT;}
|
|
||||||
"&" {return AND;}
|
|
||||||
"|" {return OR;}
|
|
||||||
"." {return DOT;}
|
|
||||||
|
|
||||||
";" {return SEMI_COLON;}
|
{DIGIT}+ {if(DEBUG) {printf( "C_INTEGER: %s (%d)\n", yytext, C_INTEGER);} else {return C_INTEGER;}}
|
||||||
":" {return COLON;}
|
'{CHAR}' {if(DEBUG) {printf( "C_CHARACTER: %s (%d)\n", yytext, C_CHARACTER);} else {return C_CHARACTER;}}
|
||||||
"," {return COMMA;}
|
\"{SCHAR}*\" {if(DEBUG) {printf( "C_STRING: %s (%d)\n", yytext, C_STRING);} else {return C_STRING;}}
|
||||||
"->" {return ARROW;}
|
"(*"{COM}"*)" {if(DEBUG) {printf( "COMMENT: %s (%d)\n", yytext, COMMENT);} else {return COMMENT;}}
|
||||||
|
"true" {if(DEBUG) {printf( "C_TRUE: %s (%d)\n", yytext, C_TRUE);} else {return C_TRUE;}}
|
||||||
|
"false" {if(DEBUG) {printf( "C_FALSE: %s (%d)\n", yytext, C_FALSE);} else {return C_FALSE;}}
|
||||||
|
"null" {if(DEBUG) {printf( "C_NULL: %s (%d)\n", yytext, C_NULL);} else {return C_NULL;}}
|
||||||
|
|
||||||
"reserve" {return RESERVE;}
|
{ID} {if(DEBUG) {printf( "ID: %s (%d)\n", yytext, ID);} else {return ID;}}
|
||||||
"release" {return RELEASE;}
|
|
||||||
|
|
||||||
\"{SCHAR}*\" {return C_STRING;}
|
|
||||||
"(*"{COM}"*)" {return COMMENT;}
|
|
||||||
|
|
||||||
{ID} {return ID;}
|
|
||||||
|
|
||||||
\n {line_number++; column_number = 1;}
|
\n {line_number++; column_number = 1;}
|
||||||
. {column_number++;}
|
. {column_number++;}
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
|
int main( int argc, char **argv )
|
||||||
|
{
|
||||||
|
argc--, argv++;
|
||||||
|
if ( argc > 0 )
|
||||||
|
yyin = fopen( argv[0], "r" );
|
||||||
|
else
|
||||||
|
yyin = stdin;
|
||||||
|
yylex();
|
||||||
|
}
|
3
runner.c
3
runner.c
@ -1,7 +1,6 @@
|
|||||||
#include "runner.h"
|
#include "runner.h"
|
||||||
|
|
||||||
|
int main(int argc, char ** argv) {
|
||||||
int main(int argc, char *argv[]) {
|
|
||||||
char *check_input;
|
char *check_input;
|
||||||
int token;
|
int token;
|
||||||
//check_input can be compared to INVALID_ARG and DIFF_ARG to determine if -tok and holds the generated file name if it is
|
//check_input can be compared to INVALID_ARG and DIFF_ARG to determine if -tok and holds the generated file name if it is
|
||||||
|
7
runner.h
7
runner.h
@ -3,11 +3,12 @@
|
|||||||
#define INVALID_ARG "invalid"
|
#define INVALID_ARG "invalid"
|
||||||
#define DIFF_ARG "diff"
|
#define DIFF_ARG "diff"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <std.io>
|
#include <stdio.h>
|
||||||
#include "lex.yy.c"
|
#include "lex.yy.c"
|
||||||
|
|
||||||
extern int line_number, column_number;
|
extern int line_number, column_number;
|
||||||
extern char *yytext;
|
extern char *yytext;
|
||||||
|
|
||||||
int main(int argc, char* argv);
|
int main(int argc, char *argv[]);
|
||||||
char *is_tok(int argc, char* argv);#define ALPHA_OFFSET 5
|
char *is_tok(int argc, char *argv[]);
|
||||||
|
#define ALPHA_OFFSET 5
|
||||||
|
Reference in New Issue
Block a user