Česky
Kamil Dudka

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

File detail

Name:Downloadparser.h [Download]
Location: vyp08 > vyp08-1.0pre1 > src
Size:3.9 KB
Last modification:2009-07-04 19:51

Source code

/*
 * 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/>.
 */
 
#ifndef PARSER_H
#define PARSER_H
 
#include "config.h"
#include "scanner.h"
 
#ifndef BUILDING_DOX
#   include <string>
#endif
 
/**
 * builder interface
 * set of callback methods called by parser
 */
class IBuilder: public IErrorSensitive {
    public:
        virtual ~IBuilder() { }
        virtual void errorDetected()                    = 0; ///< called if error is detected
        virtual void glVar(EToken type, Token id)       = 0; ///< define global variable
        virtual void fncDeclInit(EToken type, Token id) = 0; ///< fnc decl detected
        virtual void fncDeclArg(EToken type)            = 0; ///< fnc decl arg
        virtual void fncDecl()                          = 0; ///< fnc decl complete
        virtual void fncDefInit(EToken type, Token id)  = 0; ///< fnc def detected
        virtual void fncDefArg(EToken type, Token id)   = 0; ///< fnc def arg
        virtual void fncDefVar(EToken type, Token id)   = 0; ///< fnc local variable
        virtual void fncDefBody()                       = 0; ///< fnc body
        virtual void fncDef()                           = 0; ///< fnc def complete
        virtual void assign(Token token)                = 0; ///< assign command
        virtual void ifEnter(Token token)               = 0; ///< if statement, if part
        virtual void ifElse()                           = 0; ///< if statement, else part
        virtual void ifLeave()                          = 0; ///< if statement complete
        virtual void whileInit(Token token)             = 0; ///< while, B_EXPR follows
        virtual void whileEnter()                       = 0; ///< while, CMD_LIST follows
        virtual void whileLeave()                       = 0; ///< while statement complete
        virtual void pushToken(Token token)             = 0; ///< push token
        virtual void evalUnOp(Token token)              = 0; ///< eval unary operator
        virtual void evalBinOp(Token token)             = 0; ///< eval binary operator
 
        /**
         * function call
         * @param id token initiating function call
         * @param argsToPop count of arguments to pop from stack and give them to function
         * @param pushResult true if function return value is going to be used
         */
        virtual void fncCall(Token id, int argsToPop, bool pushResult) = 0;
 
        /**
         * print function call
         * @param id token initiating function call
         * @param valType type of expression expected by print function
         */
        virtual void fncCallPrint(Token id, EToken valType) = 0;
};
 
/**
 * parser (static only) interface
 */
class Parser {
    public:
        /**
         * @param scanner IScanner object used to read input
         * @param builder IBuilder object used to build output
         * @param fileName Name (or alias) of input file name used in error/warning messages.
         * @return Return zero value on success, error code otherwise.
         */
        static int parse(IScanner *scanner, IBuilder *builder, std::string fileName);
#ifdef BUILDING_DOX
        // pull this in only for Doxygne to know these classes are being used
        IScanner *scanner;
        Builder *builder;
#endif
    private:
        Parser();
};
 
#endif /* PARSER_H */