/
evo
/
Gtk4-tutorial
Обзор
Документация
Войти
/
evo
/
Gtk4-tutorial
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/turtle/turtle.lex
78 строк
3 KB
Toshio Sekiya
Add DND section (section 28).
29 июл 2023, 15:41
29 июл 2023, 15:41
bda0f28
Код
Авторство
О чём код?
%top{ #include <string.h> #include <stdlib.h> #include <glib.h> #include "turtle_parser.h" static int nline = 1; static int ncolumn = 1; static void get_location (char *text); /* Dinamically allocated memories are added to the single list. They will be freed in the finalize function. */ extern GSList *list; } %option noyywrap REAL_NUMBER (0|[1-9][0-9]*)(\.[0-9]+)? IDENTIFIER [a-zA-Z][a-zA-Z0-9]* %% /* rules */ #.* ; /* comment. Be careful. Dot symbol (.) matches any character but new line. */ [ ] ncolumn++; /* white space. [ and ] is a "character class". */ \t ncolumn += 8; /* assume that tab is 8 spaces. */ \n nline++; ncolumn = 1; /* reserved keywords */ pu get_location (yytext); return PU; /* pen up */ pd get_location (yytext); return PD; /* pen down */ pw get_location (yytext); return PW; /* pen width = line width */ fd get_location (yytext); return FD; /* forward */ tr get_location (yytext); return TR; /* turn right */ tl get_location (yytext); return TL; /* turn left, since ver 0.5 */ bc get_location (yytext); return BC; /* background color */ fc get_location (yytext); return FC; /* foreground color */ dp get_location (yytext); return DP; /* define procedure */ if get_location (yytext); return IF; /* if statement */ rt get_location (yytext); return RT; /* return statement */ rs get_location (yytext); return RS; /* reset the status */ rp get_location (yytext); return RP; /* repeat, since ver 0.5 */ /* constant */ {REAL_NUMBER} get_location (yytext); yylval.NUM = atof (yytext); return NUM; /* identifier */ {IDENTIFIER} { get_location (yytext); yylval.ID = g_strdup(yytext); list = g_slist_prepend (list, yylval.ID); return ID; } "=" get_location (yytext); return '='; ">" get_location (yytext); return '>'; "<" get_location (yytext); return '<'; "+" get_location (yytext); return '+'; "-" get_location (yytext); return '-'; "*" get_location (yytext); return '*'; "/" get_location (yytext); return '/'; "(" get_location (yytext); return '('; ")" get_location (yytext); return ')'; "{" get_location (yytext); return '{'; "}" get_location (yytext); return '}'; "," get_location (yytext); return ','; . ncolumn++; return YYUNDEF; %% static void get_location (char *text) { yylloc.first_line = yylloc.last_line = nline; yylloc.first_column = ncolumn; yylloc.last_column = (ncolumn += strlen(text)) - 1; } static YY_BUFFER_STATE state; void init_flex (const char *text) { state = yy_scan_string (text); } void finalize_flex (void) { yy_delete_buffer (state); }