Česky
Kamil Dudka

Flex/Bison based compiler and interpreter written in C++ (using Boost)

File detail

Name:Downloadscanner.lex [Download]
Location: vyp08 > vyp08-1.0pre1 > src
Size:2.4 KB
Last modification:2009-07-04 19:51

File content

/*
 * Copyright (C) 2008 Kamil Dudka <xdudka00@stud.fit.vutbr.cz>
 *
 * This file is part of vyp08 (compiler and interpreter of VYP08 language).
 *
 * vyp08 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
 * any later version.
 *
 * vyp08 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 vyp08.  If not, see <http://www.gnu.org/licenses/>.
 */

/* use C++ instead of C */
%option c++

/* count line numbers automatically */
%option yylineno

/* do not use yywrap function/method */
%option noyywrap

%{
#include "scanner.h"
%}

space               [ \t\n\r\v\f]+
id                  [A-Za-z][A-Za-z0-9_]*
int                 [0-9]+
double              [0-9]+\.([0-9]+(e[+-]?[0-9]+)?)?
esc_quot            (\\\\)*\\\"
string              \"{esc_quot}?([^\\]{esc_quot}|[^\"])*\"

%%
{space}             /* skip blanks and tabs */
{id}                return ETOKEN_ID;
{int}               return ETOKEN_NUMBER_INT;
{double}            return ETOKEN_NUMBER_DOUBLE;
{string}            return ETOKEN_STRING;
"{"                 return ETOKEN_OP_LCBR;
"}"                 return ETOKEN_OP_RCBR;
"("                 return ETOKEN_OP_LPAR;
")"                 return ETOKEN_OP_RPAR;
"*"                 return ETOKEN_OP_STAR;
"/"                 return ETOKEN_OP_SLASH;
"+"                 return ETOKEN_OP_PLUS;
"-"                 return ETOKEN_OP_MINUS;
"<"                 return ETOKEN_OP_LESS;
"<="                return ETOKEN_OP_LESS_EQ;
">"                 return ETOKEN_OP_GREATER;
">="                return ETOKEN_OP_GREATER_EQ;
":="                return ETOKEN_OP_ASSIGN;
","                 return ETOKEN_OP_COMMA;
";"                 return ETOKEN_OP_SEMICOLON;
"/*"    {
    int c;
    while((c = yyinput()) != 0) {
        if(c == '*') {
            if((c = yyinput()) == '/')
                break;
            else
                unput(c);
        }
    }
}
"//"    {
    int c;
    while ((c = yyinput()) != 0) {
        if (c == '\n' || c == EOF)
            break;
    }
}

%%