This repository has been archived on 2024-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
pacciani/Monicelli.lpp

211 lines
3.9 KiB
Plaintext
Raw Normal View History

%{
2014-11-29 00:47:50 +01:00
/*
2014-11-29 21:38:52 +01:00
* Monicelli: an esoteric language compiler
2014-11-29 00:47:50 +01:00
*
* Copyright (C) 2014 Stefano Sanfilippo
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2014-11-28 19:01:15 +01:00
#include "Scanner.hpp"
#include "Parser.hpp"
2014-11-28 00:01:24 +01:00
#include <string>
2014-11-27 20:02:15 +01:00
using namespace monicelli;
2014-11-28 19:01:15 +01:00
typedef Parser::token token;
#define YY_USER_ACTION location->begin.columns(yyleng);
static inline
bool in(const char *sub, const std::string &str) {
return str.find(sub) != std::string::npos;
}
%}
2014-11-28 19:01:15 +01:00
%option ecs stack warn c++
%option nodefault noyywrap nounput yylineno
%option yyclass="Scanner"
DIGIT [0-9]
HEXDIGIT [0-9a-zA-Z]
CHAR [a-zA-Z_]
%x shift
%%
2014-11-28 19:07:34 +01:00
("#"|"bituma")[^\n]* {}
"Lei ha clacsonato" {
2014-11-28 19:01:15 +01:00
return token::MAIN;
}
"vaffanzum" {
2014-11-28 19:01:15 +01:00
return token::RETURN;
}
"Necchi" {
2014-11-28 19:01:15 +01:00
lval->typeval = Type::INT;
return token::TYPENAME;
}
"Mascetti" {
2014-11-28 19:01:15 +01:00
lval->typeval = Type::CHAR;
return token::TYPENAME;
}
"Perozzi" {
2014-11-28 19:01:15 +01:00
lval->typeval = Type::FLOAT;
return token::TYPENAME;
}
"Melandri" {
2014-11-28 19:01:15 +01:00
lval->typeval = Type::BOOL;
return token::TYPENAME;
}
"Sassaroli" {
2014-11-28 19:01:15 +01:00
lval->typeval = Type::DOUBLE;
return token::TYPENAME;
}
"conte" {
2014-11-28 19:01:15 +01:00
return token::STAR;
}
2014-11-23 20:43:42 +01:00
"voglio" {
2014-11-28 19:01:15 +01:00
return token::VARDECL;
}
2014-11-23 22:18:03 +01:00
"come "("se ")?"fosse" {
2014-11-28 19:01:15 +01:00
return token::ASSIGN;
}
2014-11-29 18:26:25 +01:00
("il"|"lo"|"la"|"l'"|"i"|"gli"|"le"|"un"|"un'"|"una"|"dei"|"delle") {
2014-11-28 19:01:15 +01:00
return token::ARTICLE;
}
"pi"("ù"|"u`") {
2014-11-28 19:01:15 +01:00
return token::OP_PLUS;
}
"meno" {
2014-11-28 19:01:15 +01:00
return token::OP_MINUS;
}
"per" {
2014-11-28 19:01:15 +01:00
return token::OP_TIMES;
}
"diviso" {
2014-11-28 19:01:15 +01:00
return token::OP_DIV;
}
"con scappellamento a" {
BEGIN(shift);
}
<shift>"per" {
BEGIN(INITIAL);
}
<shift>"sinistra" {
2014-11-28 19:01:15 +01:00
return token::OP_SHL;
}
<shift>"destra" {
2014-11-28 19:01:15 +01:00
return token::OP_SHR;
}
"minore "("di"|"del") {
2014-11-28 19:01:15 +01:00
return token::OP_LT;
}
"maggiore "("di"|"del") {
2014-11-28 19:01:15 +01:00
return token::OP_GT;
}
"minore o uguale "("a"|"di") {
2014-11-28 19:01:15 +01:00
return token::OP_LTE;
}
"maggiore o uguale "("a"|"di") {
2014-11-28 19:01:15 +01:00
return token::OP_GTE;
}
"a posterdati" {
2014-11-28 19:01:15 +01:00
return token::PRINT;
}
"mi porga" {
2014-11-28 19:01:15 +01:00
return token::INPUT;
}
2014-11-23 22:06:11 +01:00
"ho visto" {
2014-11-28 19:01:15 +01:00
return token::ASSERT;
}
"!" {
2014-11-28 19:01:15 +01:00
return token::BANG;
}
"stuzzica" {
2014-11-28 19:01:15 +01:00
return token::LOOP_BEGIN;
}
"e "("b"|"p")"rematura anche, se" {
2014-11-28 19:01:15 +01:00
return token::LOOP_CONDITION;
}
"che cos'"("è"|"e`") {
2014-11-28 19:01:15 +01:00
return token::BRANCH_CONDITION;
}
"?" {
2014-11-28 19:01:15 +01:00
return token::BRANCH_BEGIN;
}
2014-11-24 10:54:25 +01:00
"o tarapia tapioco" {
2014-11-28 19:01:15 +01:00
return token::BRANCH_ELSE;
}
"e velocit"("à"|"a`")" di esecuzione" {
2014-11-28 19:01:15 +01:00
return token::BRANCH_END;
}
":" {
2014-11-28 19:01:15 +01:00
return token::COLON;
}
"blinda la supercazzo"("r"|"l")"a" {
2014-12-02 14:14:58 +01:00
return token::FUN_DECL;
}
"con" {
2014-11-28 19:01:15 +01:00
return token::PARAMS;
}
"," {
2014-11-28 19:01:15 +01:00
return token::COMMA;
}
("b"|"p")"rematurata la supercazzo"("r"|"l")"a" {
2014-12-02 14:14:58 +01:00
return token::FUN_CALL;
}
"o scherziamo"("?")? {
2014-11-28 19:01:15 +01:00
return token::FUN_END;
}
"avvertite don ulrico" {
2014-11-28 19:01:15 +01:00
return token::ABORT;
}
2014-11-23 23:22:55 +01:00
"o magari" {
2014-11-28 19:01:15 +01:00
return token::CASE_END;
}
<INITIAL,shift>"\n" {
location->begin.lines();
}
<INITIAL,shift>[ \t\f\v\r] {
2014-11-28 19:07:34 +01:00
}
{CHAR}({DIGIT}|{CHAR})* {
2014-11-28 19:01:15 +01:00
lval->strval = new std::string(yytext);
return token::ID;
}
2014-11-29 22:37:57 +01:00
[-+]?(({DIGIT}*".")?{DIGIT}+|{DIGIT}+".")([eE][-+]?{DIGIT}+)? {
std::string value(yytext);
if (in(".", value) || in("e", value) || in("E", value)) {
2014-11-29 22:37:57 +01:00
lval->floatval = std::stod(value);
return token::FLOAT;
} else {
lval->intval = std::stol(value);
return token::NUMBER;
}
}
<INITIAL,shift>. {
return token::ERROR;
2014-11-27 21:30:49 +01:00
}
%%