• Non ci sono risultati.

Appendice B : Definizione Lexer Jflex

N/A
N/A
Protected

Academic year: 2021

Condividi "Appendice B : Definizione Lexer Jflex"

Copied!
4
0
0

Testo completo

(1)

94

Appendice B : Definizione Lexer Jflex

import java_cup.runtime.*; %% %class prova %unicode %cup %line %column %{

StringBuffer string = new StringBuffer();

private Symbol symbol(int type) {

return new Symbol(type, yyline, yycolumn); }

private Symbol symbol(int type, Object value) {

return new Symbol(type, yyline, yycolumn, value); } %} Terminatori = \r|\n|\r\n InputC = [^\r\n] Spazio = {Terminatori} | [ \t\f]* /*Commenti*/

Commenti = {Tradizionali} | {FineLinea} | {Documentazione} Tradizionali = "/*" [^*] ~"*/" | "/*" "*"+ "/"

FineLinea = "//" {InputC}* {Terminatori} Documentazione = "/**" {Contenuti} "*"+ "/"

(2)

95

Contenuti = ( [^*] | \*+ [^/*] )*

Identificatori = [a-zA-Z] [a-zA-Z0-9]*

Digits = [0-9]+ Char = '.' bool = true|false InteriDec = 0 | [1-9][0-9]* Razionali = {Digits}"."{Digits} %state TKSTRING %% <YYINITIAL> { /*Booleani*/

{bool} { return symbol(sym.TKBOOL, new Boolean(yytext())); }

/*Interi decimali*/

{InteriDec} { return symbol(sym.TKINT, new Integer(yytext())); }

/*Stringhe*/

\" { string.setLength(0); yybegin(TKSTRING); }

/*Singoli caratteri*/

{Char} { return symbol(sym.TKCHAR,new Character(yycharat(1))); }

/*Razionali*/

{Razionali} { return symbol(sym.TKREAL,

(3)

96 /*Simboli*/ ":=" { return symbol(sym.UPDATE); } "[" { return symbol(sym.LBRACK); } "]" { return symbol(sym.RBRACK); } "(" { return symbol(sym.LPAREN); } ")" { return symbol(sym.RPAREN); } "." { return symbol(sym.DOT); } "," { return symbol(sym.COMMA); } "=" { return symbol(sym.EQ); } "^" { return symbol(sym.EXT); } "let" { return symbol(sym.LET); } "in" { return symbol(sym.IN); } ":" { return symbol(sym.COLON); } "->" { return symbol(sym.ARROW); } ";" { return symbol(sym.SEMI); }

"INT" { return symbol(sym.INT); } "REAL" { return symbol(sym.REAL); } "STRING" { return symbol(sym.STRING); } "CHAR" { return symbol(sym.CHAR); } "BOOL" { return symbol(sym.BOOL); } "Type" { return symbol(sym.Type); } "epyT" { return symbol(sym.epyT); }

/*Identificatori*/

{Identificatori} { return symbol(sym.IDE, new String(yytext())); }

/*Commenti*/ {Commenti} { /* ignore */ } /*Spazio*/ {Spazio} { /* ignore */ } } <TKSTRING> {

(4)

97 \" { yybegin(YYINITIAL); return symbol(sym.TKSTRING, string.toString()); } [^\n\r\"\\]+ { string.append( yytext() ); } \\t { string.append( '\t' ); } \\n { string.append( '\n' ); } \\r { string.append( '\r' ); } \\\" { string.append( '\"' ); } \\ { string.append( '\\' ); } } /* Errore */ .|\n {

throw new RuntimeException("Carattere illegale \"" +yytext()+ "\" at line "+yyline+", column "+yycolumn); }

/*Fine file*/

Riferimenti

Documenti correlati

eines Druckkessels bewegt sich auf den roten Bereich zu. Ein Felsen am Moselsteilhang oberhalb von Krôv gérât ins Rutschen. European University Institute. Available Open

All the platforms have already committed to providing high-quality sports media content inside their sports section: Youku broadcasts live Chinese University

Inizialmente si sono analizzate le varie voci di costo delle famiglie di fondi, ed in particolare si è notato che le commissioni di switch sono in quasi tutti i casi pari a

First, both the Bagwell-Staiger model and the Grossman-Helpman model say that even when governments have political-support motives and engage in protectionism, a trade

First, after the &#34;Governmentality&#34; lecture, Foucault several times shifted the meaning of the term and the respective periodisation. To give only a few

Smentendo l’idea dell’inesistenza della nozione di individualità nel pensiero cinese diffusasi in Occidente, la prima parte della trattazione mette in luce la centralità

In the different parts of my analysis, I believe I showed how much this is true in Freedom: how Joey was influenced by his mother’s and Connie’s devotion, but also by his

From an institutional perspective the European Community may be coherently interpreted both as an institution that has been established by the member states within the