Browse Source

Add tolower function for strings.

ObjPtr
Michael Uleysky 9 years ago
parent
commit
3ef04a9ba0
  1. 6
      include/common.h
  2. 5
      src/parser/grammatical.y
  3. 3
      src/parser/lexical.l

6
include/common.h

@ -1,5 +1,7 @@
#ifndef COMMON_H #ifndef COMMON_H
#define COMMON_H #define COMMON_H
//#include <algorithm>
#include <cctype>
#include <iostream> #include <iostream>
#include <memory> #include <memory>
#include <set> #include <set>
@ -314,4 +316,8 @@ inline bool str2uint(const char* str, uint64_t* res)
inline bool str2double(const std::string& str, double* res) {return str2double(str.c_str(),res);} inline bool str2double(const std::string& str, double* res) {return str2double(str.c_str(),res);}
inline bool str2int(const std::string& str, int64_t* res) {return str2int(str.c_str(),res);} inline bool str2int(const std::string& str, int64_t* res) {return str2int(str.c_str(),res);}
inline bool str2uint(const std::string& str, int64_t* res) {return str2uint(str.c_str(),res);} inline bool str2uint(const std::string& str, int64_t* res) {return str2uint(str.c_str(),res);}
inline void tolower(std::string& str) {for(auto& p: str) p=tolower(p);}
inline void tolower(std::string* str) {for(auto& p:*str) p=tolower(p);}
inline void tolower(char* str) {for(*str=tolower(*str);'\0'!=*str++;*str=tolower(*str));}
#endif #endif

5
src/parser/grammatical.y

@ -14,7 +14,6 @@
%{ %{
#include <inttypes.h> #include <inttypes.h>
#include <algorithm>
#include "parser.h" #include "parser.h"
#include "object.h" #include "object.h"
#include "globals.h" #include "globals.h"
@ -104,7 +103,7 @@ line:
NAME ASSIGN object ENDL {COUT(DEBUG)<<" NAME ASSIGN object ENDL\n"; if(G_vars.count(*$1)!=0) delete G_vars[*$1]; G_vars[*$1]=$3; delete $1;} NAME ASSIGN object ENDL {COUT(DEBUG)<<" NAME ASSIGN object ENDL\n"; if(G_vars.count(*$1)!=0) delete G_vars[*$1]; G_vars[*$1]=$3; delete $1;}
| NAME ASSIGN list ENDL {COUT(DEBUG)<<" NAME ASSIGN list ENDL\n"; if(G_vars.count(*$1)!=0) delete G_vars[*$1]; G_vars[*$1]=$3; delete $1;} | NAME ASSIGN list ENDL {COUT(DEBUG)<<" NAME ASSIGN list ENDL\n"; if(G_vars.count(*$1)!=0) delete G_vars[*$1]; G_vars[*$1]=$3; delete $1;}
| NAME OBRACE list CBRACE ENDL {COUT(DEBUG)<<" NAME OBRACE list CBRACE ENDL\n"; | NAME OBRACE list CBRACE ENDL {COUT(DEBUG)<<" NAME OBRACE list CBRACE ENDL\n";
transform($1->begin(),$1->end(),$1->begin(),::tolower); tolower($1);
ObjectList* ol=dynamic_cast<ObjectList*>($3); ObjectList* ol=dynamic_cast<ObjectList*>($3);
if(*$1=="save") G_tosave.push_back(ol); if(*$1=="save") G_tosave.push_back(ol);
else if(*$1=="print") G_toprint.push_back(ol); else if(*$1=="print") G_toprint.push_back(ol);
@ -117,7 +116,7 @@ line:
} }
delete $1;} delete $1;}
| NAME OBRACE object CBRACE ENDL {COUT(DEBUG)<<" NAME OBRACE object CBRACE ENDL\n"; | NAME OBRACE object CBRACE ENDL {COUT(DEBUG)<<" NAME OBRACE object CBRACE ENDL\n";
transform($1->begin(),$1->end(),$1->begin(),::tolower); tolower($1);
ObjectList* ol=new ObjectList($3); ObjectList* ol=new ObjectList($3);
if(*$1=="save") G_tosave.push_back(ol); if(*$1=="save") G_tosave.push_back(ol);
else if(*$1=="print") G_toprint.push_back(ol); else if(*$1=="print") G_toprint.push_back(ol);

3
src/parser/lexical.l

@ -14,7 +14,6 @@
%x PREPROC %x PREPROC
%{ %{
#include <algorithm>
#include "common.h" #include "common.h"
#include "parser.h" #include "parser.h"
// flex use register keyword, but it deprecated in C++11. // flex use register keyword, but it deprecated in C++11.
@ -44,7 +43,7 @@ std::string str;
<PARSE,INITIAL>@[Ii][Nn][Cc][Ll][Uu][Dd][Ee][ \t]*\" yy_push_state(INCLUDE,yyscanner); str.erase(); yynextsym; <PARSE,INITIAL>@[Ii][Nn][Cc][Ll][Uu][Dd][Ee][ \t]*\" yy_push_state(INCLUDE,yyscanner); str.erase(); yynextsym;
@ BEGIN(PREPROC); yynextsym; @ BEGIN(PREPROC); yynextsym;
<PREPROC>[a-zA-Z]* { <PREPROC>[a-zA-Z]* {
yynextsym; str=yytext; transform(str.begin(),str.end(),str.begin(),::tolower); yynextsym; str=yytext; tolower(str);
if("use"==str) return DIR_USE; if("use"==str) return DIR_USE;
if("includepath"==str) return DIR_INCLUDEPATH; if("includepath"==str) return DIR_INCLUDEPATH;
if("modulepath"==str) return DIR_MODULEPATH; if("modulepath"==str) return DIR_MODULEPATH;

Loading…
Cancel
Save