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

212 lines
3.7 KiB
Plaintext
Raw Normal View History

%{
2014-11-29 00:47:50 +01:00
/*
* Monicelli: as esoteric language compiler
*
* 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>
#include <cstdlib>
2014-11-28 19:01:15 +01:00
static void meta(const char *);
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);
%}
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
2014-11-23 23:14:12 +01:00
"#"[^\n]* {
2014-11-28 19:01:15 +01:00
meta(yytext + 1);
2014-11-23 23:14:12 +01:00
}
2014-11-23 22:42:59 +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ù" {
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 brematura anche, se" {
2014-11-28 19:01:15 +01:00
return token::LOOP_CONDITION;
}
"che cos'è" {
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à 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 supercazzola" {
2014-11-28 19:01:15 +01:00
return token::FUNDECL;
}
"con" {
2014-11-28 19:01:15 +01:00
return token::PARAMS;
}
"," {
2014-11-28 19:01:15 +01:00
return token::COMMA;
}
"brematurata la supercazzola" {
2014-11-28 19:01:15 +01:00
return token::FUNCALL;
}
"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;
}
{DIGIT}+ {
2014-11-28 19:01:15 +01:00
lval->intval = strtol(yytext, NULL, 10);
return token::NUMBER;
}
<INITIAL,shift>. {
return -1;
2014-11-27 21:30:49 +01:00
}
%%
2014-11-28 19:01:15 +01:00
void meta(const char *text) {
while (*text != '\0' && *text == ' ') {
text += 1;
}
std::cerr << "META: " << text << std::endl;
}