From 80d6c4f64ad4d293cc23e845f7013d6d45c309c5 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 30 Sep 2006 19:56:06 +0000 Subject: [PATCH] Support ignoring statements Allow numbers to begin with a plus sign Support exponents in floating point numbers --- source/loader.h | 6 +++++- source/parser.cpp | 37 +++++++++++++++++++++++++++++++++---- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/source/loader.h b/source/loader.h index 2fe0292..6e9c4f8 100644 --- a/source/loader.h +++ b/source/loader.h @@ -172,6 +172,9 @@ protected: void add(const std::string &k, T L::*p) { actions.insert(typename ActionMap::value_type(k, new LoadValue(p))); } + void add(const std::string &k) + { actions.insert(ActionMap::value_type(k, 0)); } + template void load_sub(S &s) { load_sub(s); } @@ -196,7 +199,8 @@ private: ActionMap::iterator j=actions.find(st.keyword); if(j==actions.end()) throw Exception(st.get_location()+": Unknown keyword '"+st.keyword+"'"); - j->second->execute(*this, st); + if(j->second) + j->second->execute(*this, st); cur_st=0; } }; diff --git a/source/parser.cpp b/source/parser.cpp index 7b9af11..f74be86 100644 --- a/source/parser.cpp +++ b/source/parser.cpp @@ -143,7 +143,9 @@ Token Parser::parse_token() enum ParseState { INIT, - NEGATIVE, + SIGN, + FLOATEXPINIT, + FLOATEXPSIGN, STRING, ACCEPT, ZERO, @@ -151,11 +153,14 @@ Token Parser::parse_token() HEXADECIMAL, OCTAL, FLOAT, + FLOATEXP, IDENTIFIER }; static Token::Type token_type[]= { + Token::SPECIAL, + Token::SPECIAL, Token::SPECIAL, Token::SPECIAL, Token::STRING, @@ -165,6 +170,7 @@ Token Parser::parse_token() Token::INTEGER, Token::INTEGER, Token::FLOAT, + Token::FLOAT, Token::IDENTIFIER }; @@ -185,8 +191,8 @@ Token Parser::parse_token() case INIT: if(c=='0') state=ZERO; - else if(c=='-') - state=NEGATIVE; + else if(c=='-' || c=='+') + state=SIGN; else if(c=='.') state=FLOAT; else if(c=='"') @@ -201,7 +207,7 @@ Token Parser::parse_token() parse_error(c, state); break; - case NEGATIVE: + case SIGN: if(c=='0') state=ZERO; else if(isdigit(c)) @@ -241,6 +247,29 @@ Token Parser::parse_token() break; case FLOAT: + if(c=='e' || c=='E') + state=FLOATEXPINIT; + else if(!isdigit(c)) + parse_error(c, state); + break; + + case FLOATEXPINIT: + if(c=='+' || c=='-') + state=FLOATEXPSIGN; + else if(isdigit(c)) + state=FLOATEXP; + else + parse_error(c, state); + break; + + case FLOATEXPSIGN: + if(isdigit(c)) + state=FLOATEXP; + else + parse_error(c, state); + break; + + case FLOATEXP: if(!isdigit(c)) parse_error(c, state); break; -- 2.45.2