Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %{
- /* C++ string header, for string ops below */
- #include <string>
- /* Implementation of yyFlexScanner */
- #include "mc_scanner.hpp"
- #undef YY_DECL
- #define YY_DECL int MC::MC_Scanner::yylex( MC::MC_Parser::semantic_type *
- const lval, MC::MC_Parser::location_type *loc )
- /* typedef to make the returns for the tokens shorter */
- using token = MC::MC_Parser::token;
- /* define yyterminate as this instead of NULL */
- #define yyterminate() return( token::END )
- /* msvc2010 requires that we exclude this header file. */
- #define YY_NO_UNISTD_H
- /* update location on matching */
- #define YY_USER_ACTION loc->step(); loc->columns(yyleng);
- %}
- %option debug
- %option nodefault
- %option yyclass="MC::MC_Scanner"
- %option noyywrap
- %option c++
- %%
- %{ /** Code executed at the beginning of yylex **/
- yylval = lval;
- %}
- [a-z] {
- return( token::LOWER );
- }
- [A-Z] {
- return( token::UPPER );
- }
- [a-zA-Z]+ {
- yylval->build< std::string >( yytext );
- return( token::WORD );
- }
- %%
- %skeleton "lalr1.cc"
- %require "3.0"
- %debug
- %defines
- %define api.namespace {MC}
- %define parser_class_name {MC_Parser}
- %code requires{
- namespace MC {
- class MC_Driver;
- class MC_Scanner;
- }
- %parse-param { MC_Scanner &scanner }
- %parse-param { MC_Driver &driver }
- %code{
- #include <iostream>
- #include <cstdlib>
- #include <fstream>
- /* include for all driver functions */
- #include "mc_driver.hpp"
- #undef yylex
- #define yylex scanner.yylex
- }
- #if ! defined(yyFlexLexerOnce)
- #include <FlexLexer.h>
- #endif
- #include "mc_parser.tab.hh"
- #include "location.hh"
- namespace MC{
- class MC_Scanner : public yyFlexLexer{
- public:
- MC_Scanner(std::istream *in) : yyFlexLexer(in)
- {};
- virtual ~MC_Scanner() {};
- //get rid of override virtual function warning
- using FlexLexer::yylex;
- virtual
- int yylex( MC::MC_Parser::semantic_type * const lval,
- MC::MC_Parser::location_type *location );
- // YY_DECL defined in mc_lexer.l
- // Method body created by flex in mc_lexer.yy.cc
- private:
- /* yyval ptr */
- MC::MC_Parser::semantic_type *yylval = nullptr;
- };
- } /* end namespace MC */
- #undef yylex
- #define yylex scanner.yylex
- %code requires{
- namespace MC {
- class MC_Driver;
- class MC_Scanner;
- }
- %parse-param { MC_Scanner &scanner }
- %parse-param { MC_Driver &driver }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement