You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
3.9 KiB

%{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "types.h"
#include "y.tab.h"
void yyerror(char *);
extern YYSTYPE yylval;
extern FILE *yyin;
int yylineno;
%}
%%
\/\*.*?\*\/ { ; // comment }
-?[0-9]+ { yylval.int_num = atoi(yytext); return INTEGER; }
\'[ -~]\' { yylval.byte_num = yytext[1]; return CHAR; }
[-()<>=+*/:;,%{}\[\]] { return *yytext; }
"if" { return IF; }
"else" { return ELSE; }
"print" { return PRINT_TOKEN; }
"string" { return KEYWORD_S; }
"while" { return WHILE; }
"int" { return KEYWORD_I; }
"def" { return DEF;}
"call" { return CALL; }
"char" { return KEYWORD_C; }
"++" { return INCREASE; }
"--" { return DECREASE; }
"<=" { return LESS_THAN_OR_EQUAL; }
">=" { return GREATER_THAN_OR_EQUAL; }
\"(\\.|[^"\\])*\" { yytext++; yytext[strlen(yytext)-1] = 0; yylval.str_ptr = strdup(yytext); return STRING; }
[a-zA-Z0-9_]+ { yylval.str_ptr = strdup(yytext); return VARNAME; }
-?[0-9]*\.[0-9]+ { yylval.double_num = atof(yytext); return DOUBLEVAR; }
"\n" { yylineno++; }
[ ?\t\n\r]
. printf("invalid character on line %d, '%s'\n", yylineno, yytext);
<<EOF>> { exit(0); }
%%
int yywrap(void) {
return 1;
}
int main(int argc, char* argv[])
{
_var_map = malloc(sizeof(map_void_t));
map_init(_var_map);
_temp_statement_head = NULL;
_function_list = NULL;
FILE *fh;
if (argc > 1)
{
if (strcmp(argv[1],"help") == 0 || strcmp(argv[1],"-help") == 0
|| strcmp(argv[1],"--help") == 0 || strcmp(argv[1],"h") == 0
|| strcmp(argv[1],"-h") == 0)
{
printf("[ HELP ] put a file/path as the first flag.\n");
printf("[ HELP ] -h, -help, --help, help, h: Prints this.\n");
printf("[ HELP ] -d, d, -debug, debug: Enter REPL mode.\n");
}
else if (strcmp(argv[1],"-debug") == 0 || strcmp(argv[1],"-d") == 0
|| strcmp(argv[1],"d") == 0 || strcmp(argv[1],"debug") == 0)
{
_DEON_DEBUG = 1;
yyparse();
}
else if (fh = fopen(argv[1], "r"))
{
yyin = fh;
yyparse();
fclose(fh);
}
else
{
printf("[ ERROR ] please enter a correct command. try --help\n");
fclose(fh);
}
} else
printf("[ ERROR ] missing input file. Try --help?\n");
return 0;
}