2015-08-09 19:43:47 +00:00
|
|
|
%{
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "common.h"
|
2015-08-13 12:56:50 +00:00
|
|
|
#include "trainscript.tab.hpp"
|
2015-08-09 19:43:47 +00:00
|
|
|
|
|
|
|
%}
|
|
|
|
%option noyywrap
|
|
|
|
%option never-interactive
|
|
|
|
%option reentrant
|
|
|
|
%option bison-bridge
|
|
|
|
%option yylineno
|
|
|
|
%%
|
|
|
|
\#[^\n]* ; // Eat all the comments!
|
2015-08-10 14:37:16 +00:00
|
|
|
[ \t]+ ; // Eat all the whitespace!
|
2015-08-09 19:43:47 +00:00
|
|
|
\; { return SEMICOLON; }
|
|
|
|
\: { return COLON; }
|
|
|
|
\, { return COMMA; }
|
|
|
|
\| { return PIPE; }
|
|
|
|
\( { return LBRACKET; }
|
|
|
|
\) { return RBRACKET; }
|
|
|
|
\+ { return PLUS; }
|
|
|
|
\- { return MINUS; }
|
|
|
|
\* { return MULTIPLY; }
|
|
|
|
\/ { return DIVIDE; }
|
|
|
|
\% { return MODULO; }
|
|
|
|
\-\>|→ { return RARROW; }
|
|
|
|
\<\-|← { return LARROW; }
|
2015-08-10 14:37:16 +00:00
|
|
|
|
|
|
|
\< { return OP_LT; }
|
|
|
|
\<\= { return OP_LE; }
|
|
|
|
\> { return OP_GT; }
|
|
|
|
\>\= { return OP_GE; }
|
|
|
|
\= { return OP_EQ; }
|
|
|
|
\≠|\=\/\= { return OP_NEQ; }
|
|
|
|
|
2015-08-09 19:43:47 +00:00
|
|
|
VAR { return KW_VAR; }
|
|
|
|
PUB { return KW_PUB; }
|
|
|
|
PRI { return KW_PRI; }
|
|
|
|
PTR { return KW_PTR; }
|
2015-08-10 14:37:16 +00:00
|
|
|
|
2015-08-09 19:43:47 +00:00
|
|
|
VOID { return KW_VOID; }
|
|
|
|
INT { return KW_INT; }
|
|
|
|
REAL { return KW_REAL; }
|
|
|
|
TEXT { return KW_TEXT; }
|
2015-08-10 14:37:16 +00:00
|
|
|
BOOL { return KW_BOOL; }
|
|
|
|
|
|
|
|
BEGIN { return KW_BEGIN; }
|
|
|
|
END { return KW_END; }
|
|
|
|
IF { return KW_IF; }
|
2015-08-10 15:05:58 +00:00
|
|
|
THEN { return KW_THEN; }
|
2015-08-10 14:37:16 +00:00
|
|
|
ELSE { return KW_ELSE; }
|
2015-08-12 10:15:47 +00:00
|
|
|
ELSEIF { return KW_ELSEIF; }
|
2015-08-10 14:37:16 +00:00
|
|
|
REPEAT { return KW_REPEAT; }
|
|
|
|
FROM { return KW_FROM; }
|
|
|
|
TO { return KW_TO; }
|
|
|
|
UNTIL { return KW_UNTIL; }
|
|
|
|
WHILE { return KW_WHILE; }
|
2015-08-12 12:13:49 +00:00
|
|
|
DO { return KW_DO; }
|
2015-08-10 10:10:05 +00:00
|
|
|
[0-9]+\.[0-9]* { yylval->fval = atof(yytext); return REAL; }
|
2015-08-09 19:43:47 +00:00
|
|
|
[0-9]+ { yylval->ival = atoi(yytext); return INT; }
|
2015-08-16 21:40:34 +00:00
|
|
|
[a-zA-Z0-9'_]+ { yylval->text = yyextra->strdup(yytext); return IDENTIFIER; }
|
2015-08-09 19:43:47 +00:00
|
|
|
. { yyerror(NULL, "illegal token"); }
|
|
|
|
%%
|
2015-08-10 14:37:16 +00:00
|
|
|
/*
|
|
|
|
\t { return TAB; }
|
|
|
|
*/
|