2014-11-23 19:04:25 +01:00
|
|
|
%{
|
|
|
|
#include "Type.h"
|
|
|
|
#include "Monicelli.tab.h"
|
|
|
|
#include <stdlib.h>
|
2014-11-23 23:14:12 +01:00
|
|
|
#include <stdio.h>
|
2014-11-23 19:04:25 +01:00
|
|
|
|
|
|
|
extern int lineNumber;
|
|
|
|
extern void yyerror(const char *);
|
2014-11-23 23:22:44 +01:00
|
|
|
extern void meta(const char *);
|
2014-11-23 19:04:25 +01:00
|
|
|
%}
|
|
|
|
|
|
|
|
%option noyywrap
|
|
|
|
|
|
|
|
DIGIT [0-9]
|
|
|
|
HEXDIGIT [0-9a-zA-Z]
|
|
|
|
CHAR [a-zA-Z_]
|
|
|
|
|
2014-11-23 22:06:37 +01:00
|
|
|
%x shift
|
|
|
|
|
2014-11-23 19:04:25 +01:00
|
|
|
%%
|
2014-11-23 23:14:43 +01:00
|
|
|
<INITIAL,shift>("\r\n"|"\n") {
|
2014-11-23 19:04:25 +01:00
|
|
|
lineNumber += 1;
|
|
|
|
}
|
|
|
|
|
2014-11-23 23:14:12 +01:00
|
|
|
"#"[^\n]* {
|
2014-11-23 23:22:44 +01:00
|
|
|
meta(yytext + 1);
|
2014-11-23 23:14:12 +01:00
|
|
|
}
|
2014-11-23 22:42:59 +01:00
|
|
|
|
2014-11-23 20:43:28 +01:00
|
|
|
"bituma"[^\n]* {}
|
|
|
|
|
2014-11-23 19:04:25 +01:00
|
|
|
"Lei ha clacsonato" {
|
|
|
|
return MAIN;
|
|
|
|
}
|
|
|
|
"vaffanzum" {
|
|
|
|
return RETURN;
|
|
|
|
}
|
|
|
|
"Necchi" {
|
|
|
|
yylval.typeval = TYPENAME_INT;
|
|
|
|
return TYPENAME;
|
|
|
|
}
|
|
|
|
"Mascetti" {
|
|
|
|
yylval.typeval = TYPENAME_CHAR;
|
|
|
|
return TYPENAME;
|
|
|
|
}
|
|
|
|
"Perozzi" {
|
|
|
|
yylval.typeval = TYPENAME_FLOAT;
|
|
|
|
return TYPENAME;
|
|
|
|
}
|
|
|
|
"Melandri" {
|
|
|
|
yylval.typeval = TYPENAME_BOOL;
|
|
|
|
return TYPENAME;
|
|
|
|
}
|
|
|
|
"Sassaroli" {
|
|
|
|
yylval.typeval = TYPENAME_DOUBLE;
|
|
|
|
return TYPENAME;
|
|
|
|
}
|
|
|
|
"conte" {
|
|
|
|
return STAR;
|
|
|
|
}
|
2014-11-23 20:43:42 +01:00
|
|
|
"voglio" {
|
2014-11-23 19:04:25 +01:00
|
|
|
return VARDECL;
|
|
|
|
}
|
2014-11-23 22:18:03 +01:00
|
|
|
"come "("se ")?"fosse" {
|
2014-11-23 19:04:25 +01:00
|
|
|
return ASSIGN;
|
|
|
|
}
|
2014-11-23 23:46:32 +01:00
|
|
|
("il"|"lo"|"la"|"l'"|"i"|"gli"|"le"|"un"|"un'"|"una"|"dei") {
|
2014-11-23 19:04:25 +01:00
|
|
|
return ARTICLE;
|
|
|
|
}
|
|
|
|
"più" {
|
|
|
|
return OP_PLUS;
|
|
|
|
}
|
|
|
|
"meno" {
|
|
|
|
return OP_MINUS;
|
|
|
|
}
|
|
|
|
"per" {
|
|
|
|
return OP_TIMES;
|
|
|
|
}
|
|
|
|
"diviso" {
|
|
|
|
return OP_DIV;
|
|
|
|
}
|
2014-11-23 22:06:37 +01:00
|
|
|
"con scappellamento a" {
|
|
|
|
BEGIN(shift);
|
|
|
|
}
|
|
|
|
<shift>"per" {
|
|
|
|
BEGIN(INITIAL);
|
|
|
|
}
|
|
|
|
<shift>"sinistra" {
|
2014-11-23 19:04:25 +01:00
|
|
|
return OP_SHL;
|
|
|
|
}
|
2014-11-23 22:06:37 +01:00
|
|
|
<shift>"destra" {
|
2014-11-23 19:04:25 +01:00
|
|
|
return OP_SHR;
|
|
|
|
}
|
|
|
|
"minore di" {
|
|
|
|
return OP_LT;
|
|
|
|
}
|
|
|
|
"maggiore di" {
|
|
|
|
return OP_GT;
|
|
|
|
}
|
|
|
|
"minore o uguale a" {
|
|
|
|
return OP_LTE;
|
|
|
|
}
|
|
|
|
"maggiore o uguale a" {
|
|
|
|
return OP_GTE;
|
|
|
|
}
|
|
|
|
"a posterdati" {
|
|
|
|
return PRINT;
|
|
|
|
}
|
|
|
|
"mi porga" {
|
|
|
|
return INPUT;
|
|
|
|
}
|
2014-11-23 22:06:11 +01:00
|
|
|
"ho visto" {
|
2014-11-23 19:04:25 +01:00
|
|
|
return ASSERT_BEGIN;
|
|
|
|
}
|
|
|
|
"!" {
|
|
|
|
return ASSERT_END;
|
|
|
|
}
|
|
|
|
"stuzzica" {
|
|
|
|
return LOOP_BEGIN;
|
|
|
|
}
|
|
|
|
"e brematura anche, se" {
|
|
|
|
return LOOP_CONDITION;
|
|
|
|
}
|
|
|
|
"che cos'è" {
|
|
|
|
return BRANCH_CONDITION;
|
|
|
|
}
|
|
|
|
"?" {
|
|
|
|
return BRANCH_BEGIN;
|
|
|
|
}
|
2014-11-24 10:54:25 +01:00
|
|
|
"o tarapia tapioco" {
|
2014-11-23 19:04:25 +01:00
|
|
|
return BRANCH_ELSE;
|
|
|
|
}
|
|
|
|
"e velocità di esecuzione" {
|
|
|
|
return BRANCH_END;
|
|
|
|
}
|
|
|
|
":" {
|
|
|
|
return COLON;
|
|
|
|
}
|
|
|
|
"blinda la supercazzola" {
|
|
|
|
return FUNDECL;
|
|
|
|
}
|
|
|
|
"con" {
|
|
|
|
return PARAMS;
|
|
|
|
}
|
|
|
|
"," {
|
|
|
|
return COMMA;
|
|
|
|
}
|
|
|
|
"brematurata la supercazzola" {
|
|
|
|
return FUNCALL;
|
|
|
|
}
|
|
|
|
"avvertite don ulrico" {
|
|
|
|
return ABORT;
|
|
|
|
}
|
2014-11-23 23:22:55 +01:00
|
|
|
"o magari" {
|
2014-11-23 19:24:10 +01:00
|
|
|
return CASE_END;
|
|
|
|
}
|
2014-11-23 19:04:25 +01:00
|
|
|
|
2014-11-23 23:14:43 +01:00
|
|
|
<INITIAL,shift>[ \t\f\v] {}
|
2014-11-23 19:04:25 +01:00
|
|
|
|
|
|
|
{CHAR}({DIGIT}|{CHAR})* {
|
|
|
|
yylval.strval = strdup(yytext);
|
|
|
|
return ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
{DIGIT}+ {
|
|
|
|
yylval.intval = strtol(yytext, NULL, 10);
|
|
|
|
return NUMBER;
|
|
|
|
}
|
|
|
|
|
2014-11-23 23:14:43 +01:00
|
|
|
<INITIAL,shift>. {
|
2014-11-23 22:19:10 +01:00
|
|
|
yyerror("Unexpected token");
|
2014-11-23 19:04:25 +01:00
|
|
|
return -1;
|
|
|
|
};
|
|
|
|
|
|
|
|
%%
|
|
|
|
|