cirilisp/cirilisp.c

44 lines
1,019 B
C
Raw Normal View History

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