old-trainOS/trainscript/trainscript.l

67 lines
1.9 KiB
Text
Raw Normal View History

%{
#include <stdlib.h>
#include "common.h"
2015-08-13 12:56:50 +00:00
#include "trainscript.tab.hpp"
%}
%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!
\; { 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; }
VAR { return KW_VAR; }
PUB { return KW_PUB; }
PRI { return KW_PRI; }
PTR { return KW_PTR; }
2015-08-10 14:37:16 +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; }
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; }
[0-9]+\.[0-9]* { yylval->fval = atof(yytext); return REAL; }
[0-9]+ { yylval->ival = atoi(yytext); return INT; }
[a-zA-Z0-9'_]+ { yylval->text = yyextra->strdup(yytext); return IDENTIFIER; }
. { yyerror(NULL, "illegal token"); }
%%
2015-08-10 14:37:16 +00:00
/*
\t { return TAB; }
*/