Blang/src/lib/src/lexer.l

50 lines
1.3 KiB
Plaintext

%{
#include <iostream>
#include <string>
#include "Token.hpp"
#include "parser_gen.h"
using namespace std;
%}
%option noyywrap
integer [0-9]+
real [0-9]+\.[0-9]*|\.[0-9]+
operator "+"|"-"|"/"|"*"|">"|"<"|"<="|">="|"="|"!="
ident [a-zA-Z_][0-9a-zA-Z_]*
string \"[^\n"]+\"
%%
{integer} { return(INTEGER); }
{real} { return(FLOAT); }
{string} { return(STRING); }
{operator} { return(DO) }
"->" { return(ASSIGN); }
"=>" { return(IMPLIES); }
"Do" { return(DO); }
"LpWhile" { return(LPWHILE); }
"While" { return(WHILE); }
"WhileEnd" { return(WHILEEND); }
"If" { return(IF); }
"Then" { return(THEN); }
"Else" { return(ELSE); }
"IfEnd" { return(IFEND); }
"For" { return(FOR); }
"To" { return(TO); }
"Step" { return(STEP); }
"Next" { return(NEXT); }
"Goto" { return(GOTO); }
"Lbl" { return(LABEL); }
"Break" { return(BREAK); }
"Return" { return(RETURN); }
"Stop" { return(STOP); }
{ident} { return(IDENTIFIER); }
"\n" { return(EOL); }
[ \t]+
. { cerr << "Invalid character: " << yytext << endl; }
%%