diff options
author | Justyna Ilczuk <justyna.ilczuk@gmail.com> | 2012-12-16 09:24:16 +0100 |
---|---|---|
committer | Justyna Ilczuk <justyna.ilczuk@gmail.com> | 2012-12-16 09:24:16 +0100 |
commit | 9e1b5fa9110c633f0765cb0cc518b24b97525519 (patch) | |
tree | bc54b374fb90dd57471c32b06b2bb00b2d49203c | |
parent | bc04b973776d1f78343862698e5450372360140f (diff) | |
download | sencha-lang-9e1b5fa9110c633f0765cb0cc518b24b97525519.tar.gz sencha-lang-9e1b5fa9110c633f0765cb0cc518b24b97525519.tar.bz2 sencha-lang-9e1b5fa9110c633f0765cb0cc518b24b97525519.tar.xz sencha-lang-9e1b5fa9110c633f0765cb0cc518b24b97525519.zip |
I added simple float usage.
-rw-r--r-- | Sencha-lang/Lexer.cpp | 42 | ||||
-rw-r--r-- | Sencha-lang/Parser.cpp | 7 | ||||
-rw-r--r-- | Sencha-lang/main.cpp | 1 |
3 files changed, 44 insertions, 6 deletions
diff --git a/Sencha-lang/Lexer.cpp b/Sencha-lang/Lexer.cpp index 6ab2e8a..d77a61d 100644 --- a/Sencha-lang/Lexer.cpp +++ b/Sencha-lang/Lexer.cpp @@ -62,11 +62,28 @@ pair<string, Token> Lexer::parse_token(string line) { string token_value = ""; unsigned int i; +
for(i=0; i< line.size(); i++) { if(token_value == "" && isspace(line[i])) continue; + if(isdigit(line[i]))
+ {
+ token_value += line[i++];
+ for(; i < line.size(); i++)
+ {
+ if(isdigit(line[i]) || line[i] == '.')
+ {
+ token_value += line[i];
+ }
+ else
+ {
+ break;
+ }
+ }
+ }
+
if(line[i] == '\"')
{
token_value += line[i++];
@@ -154,13 +171,28 @@ type_of_token Lexer::guess_type(string value) if(value == "") return t_invalid_token; if(isdigit(value[0])) { - bool is_integer = true; - for(unsigned int i=1; i<value.size(); i++) - { - if(!isdigit(value[i])) is_integer = false; + bool is_number = true;
+ bool dot_used = false; + for(unsigned int i=0; i<value.size(); i++) + {
+ if(value[i] == '.')
+ {
+ if(dot_used) return t_invalid_token;
+ dot_used = true;
+ continue;
+ } + if(!isdigit(value[i])) is_number = false; } - if(is_integer) return t_integer; + if(is_number)
+ {
+ if(dot_used)
+ {
+ return t_float;
+ }
+ else return t_integer;
+ }
+ else return t_invalid_token; } if(isalpha(value[0])) diff --git a/Sencha-lang/Parser.cpp b/Sencha-lang/Parser.cpp index 70b775c..5721beb 100644 --- a/Sencha-lang/Parser.cpp +++ b/Sencha-lang/Parser.cpp @@ -282,6 +282,13 @@ ASTExpression * Parser::prim_expr(ASTNode * expression) ce = new ConstantExpression(expression, std::atoi(tok_value.c_str()));
read_next(); + }
+ else if(current_token.get_type() == t_float)
+ {
+ report("Number: " + tok_value + "\n");
+
+ ce = new ConstantExpression(expression, std::atof(tok_value.c_str()));
+ read_next();
} else if(current_token.get_type() == t_literal) { diff --git a/Sencha-lang/main.cpp b/Sencha-lang/main.cpp index 805af2d..fe7160a 100644 --- a/Sencha-lang/main.cpp +++ b/Sencha-lang/main.cpp @@ -179,7 +179,6 @@ void interactive() if(level_of_depth == 0) { parser.interpret(); parser.program->execute_last(); - //cout << parser.report_message << endl; //cout << parser.error_message << endl; //cout << parser.show_tokens() << endl; |