SHARE
TWEET

Untitled

a guest Jul 11th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %{
  2. /* C++ string header, for string ops below */
  3. #include <string>
  4.  
  5. /* Implementation of yyFlexScanner */
  6. #include "mc_scanner.hpp"
  7. #undef  YY_DECL
  8. #define YY_DECL int MC::MC_Scanner::yylex( MC::MC_Parser::semantic_type *
  9. const lval, MC::MC_Parser::location_type *loc )
  10.  
  11. /* typedef to make the returns for the tokens shorter */
  12. using token = MC::MC_Parser::token;
  13.  
  14. /* define yyterminate as this instead of NULL */
  15. #define yyterminate() return( token::END )
  16.  
  17. /* msvc2010 requires that we exclude this header file. */
  18. #define YY_NO_UNISTD_H
  19.  
  20. /* update location on matching */
  21. #define YY_USER_ACTION loc->step(); loc->columns(yyleng);
  22.  
  23. %}
  24.  
  25. %option debug
  26. %option nodefault
  27. %option yyclass="MC::MC_Scanner"
  28. %option noyywrap
  29. %option c++
  30.  
  31. %%
  32. %{          /** Code executed at the beginning of yylex **/
  33.             yylval = lval;
  34. %}
  35.  
  36. [a-z]       {
  37.                return( token::LOWER );
  38.             }
  39.  
  40. [A-Z]       {
  41.                return( token::UPPER );
  42.             }
  43.  
  44. [a-zA-Z]+   {
  45.                yylval->build< std::string >( yytext );
  46.                return( token::WORD );
  47.             }
  48.  
  49.  %%
  50.      
  51. %skeleton "lalr1.cc"
  52. %require  "3.0"
  53. %debug
  54. %defines
  55. %define api.namespace {MC}
  56. %define parser_class_name {MC_Parser}
  57.  
  58. %code requires{
  59.    namespace MC {
  60.       class MC_Driver;
  61.       class MC_Scanner;
  62.  }
  63.  
  64.  %parse-param { MC_Scanner  &scanner  }
  65.  %parse-param { MC_Driver  &driver  }
  66.  
  67.  %code{
  68.  #include <iostream>
  69.  #include <cstdlib>
  70.  #include <fstream>
  71.  
  72.  /* include for all driver functions */
  73.  #include "mc_driver.hpp"
  74.  
  75.  #undef yylex
  76.  #define yylex scanner.yylex
  77.  }
  78.      
  79. #if ! defined(yyFlexLexerOnce)
  80. #include <FlexLexer.h>
  81. #endif
  82.  
  83. #include "mc_parser.tab.hh"
  84. #include "location.hh"
  85.  
  86. namespace MC{
  87.  
  88.     class MC_Scanner : public yyFlexLexer{
  89.     public:
  90.  
  91.       MC_Scanner(std::istream *in) : yyFlexLexer(in)
  92.       {};
  93.       virtual ~MC_Scanner() {};
  94.  
  95.       //get rid of override virtual function warning
  96.       using FlexLexer::yylex;
  97.  
  98.       virtual
  99.       int yylex( MC::MC_Parser::semantic_type * const lval,
  100.                  MC::MC_Parser::location_type *location );
  101.       // YY_DECL defined in mc_lexer.l
  102.       // Method body created by flex in mc_lexer.yy.cc
  103.  
  104.  
  105.      private:
  106.        /* yyval ptr */
  107.       MC::MC_Parser::semantic_type *yylval = nullptr;
  108.    };
  109.  
  110. } /* end namespace MC */
  111.      
  112. #undef yylex
  113. #define yylex scanner.yylex
  114.      
  115. %code requires{
  116.    namespace MC {
  117.       class MC_Driver;
  118.       class MC_Scanner;
  119.  }
  120.  
  121.  %parse-param { MC_Scanner  &scanner  }
  122.  %parse-param { MC_Driver  &driver  }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top