2019-01-03 16:59:28 +01:00
|
|
|
|
#include <locale.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
|
#include "util.h"
|
2019-01-06 12:30:07 +01:00
|
|
|
|
#include "lexer.h"
|
2019-01-03 16:59:28 +01:00
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
|
{
|
2019-01-06 12:30:07 +01:00
|
|
|
|
/* Омогућава библиотекама коришћеним у интерпретеру да протумаче српску ћирилицу */
|
|
|
|
|
if (setlocale(LC_ALL, "sr_RS.utf8") == NULL)
|
|
|
|
|
{
|
2019-01-06 15:27:54 +01:00
|
|
|
|
fprintf(stderr, "locale couldn't be set to \"sr_RS.utf8\",\
|
|
|
|
|
check if you've enabled it on your system\n");
|
2019-01-06 12:30:07 +01:00
|
|
|
|
exit(0);
|
|
|
|
|
}
|
2019-01-03 16:59:28 +01:00
|
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
|
{
|
2019-01-06 12:30:07 +01:00
|
|
|
|
char *input = readline("Л> ");
|
2019-01-03 16:59:28 +01:00
|
|
|
|
if (input == NULL)
|
|
|
|
|
{
|
|
|
|
|
putchar('\n');
|
2019-01-06 12:30:07 +01:00
|
|
|
|
printf("Крај улазног тока.\n");
|
|
|
|
|
// Превод
|
2019-01-03 16:59:28 +01:00
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-06 12:30:07 +01:00
|
|
|
|
token *tokenList, *current;
|
2019-01-06 15:27:54 +01:00
|
|
|
|
|
2019-01-06 12:30:07 +01:00
|
|
|
|
current = tokenList = lexLine(input);
|
|
|
|
|
int i = 0;
|
|
|
|
|
while (current != NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("Токен бр. %d: \"%s\", тип:%s\n", i,
|
|
|
|
|
current->lexeme, current->type == number ? "number" : (current->type == symbol
|
|
|
|
|
? "symbol" : "parenthesis"));
|
2019-01-06 15:27:54 +01:00
|
|
|
|
current = current->next;
|
|
|
|
|
++i;
|
2019-01-06 12:30:07 +01:00
|
|
|
|
}
|
2019-01-03 16:59:28 +01:00
|
|
|
|
|
|
|
|
|
free(input);
|
|
|
|
|
}
|
|
|
|
|
}
|