/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Copyright (C) 2006 Silvano Rivoira * * All rights reserved. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License. See the file * * COPYRIGHT for more information. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* regular languages scanner specification */ import java_cup.runtime.*; %% %public %class Scanner %implements sym %unicode %line %column %cup %cupdebug %{ StringBuffer string = new StringBuffer(); private Symbol symbol(int type) { return new JavaSymbol(type, yyline+1, yycolumn+1, yytext()); } private Symbol symbol(int type, Object value) { return new JavaSymbol(type, yyline+1, yycolumn+1, yytext(), value); } %} /* main character classes */ LineTerminator = \r|\n|\r\n InputCharacter = [^\r\n] WhiteSpace = {LineTerminator} | [ \t\f] /* comments */ Comment = {TraditionalComment} | {EndOfLineComment} | {DocumentationComment} TraditionalComment = "/*" [^*] ~"*/" | "/*" "*"+ "/" EndOfLineComment = "//" {InputCharacter}* {LineTerminator}? DocumentationComment = "/*" "*"+ [^/*] ~"*/" /* identifiers */ Identifier = "$"[:jletterdigit:][:jletterdigit:]* /* input symbols */ InputSymbol = [:jletterdigit:][:jletterdigit:]* %% { /* keywords */ "&" { return symbol(EMPTY); } /* separators */ "(" { return symbol(LPAREN); } ")" { return symbol(RPAREN); } "[" { return symbol(LBRACK); } "]" { return symbol(RBRACK); } "%[" { return symbol(LDEF); } "%]" { return symbol(RDEF); } "%{" { return symbol(LALPHA); } "%}" { return symbol(RALPHA); } "," { return symbol(COMMA); } /* operators */ "=" { return symbol(EQ); } "=?" { return symbol(EQUESTION); } "in?" { return symbol(INQUESTION); } "#" { return symbol(PROD); } "+" { return symbol(PLUS); } "-" { return symbol(MINUS); } "!" { return symbol(NOT); } "|" { return symbol(UNION); } "*" { return symbol(STAR); } /* comments */ {Comment} { /* ignore */ } /* whitespace */ {WhiteSpace} { /* ignore */ } /* identifiers */ {Identifier} { return symbol(IDENTIFIER, yytext()); } /* input symbols */ {InputSymbol} { return symbol(INPUTSYMBOL, yytext()); } } /* error fallback */ .|\n { return symbol(ILLEGAL_CHARACTER, yytext());} <> { return symbol(EOF); }