Compare commits
	
		
			2 Commits
		
	
	
		
			f93b2deda2
			...
			acc9b94c1f
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					acc9b94c1f | ||
| 
						 | 
					8d3cc2181e | 
@@ -20,6 +20,7 @@ struct Token {
 | 
			
		||||
    enum TokenType type;
 | 
			
		||||
    std::variant<int64_t, double, std::string> value;
 | 
			
		||||
};
 | 
			
		||||
bool operator==(Token const& one, Token const& other);
 | 
			
		||||
std::ostream &operator<<(std::ostream &os, Token const &t);
 | 
			
		||||
 | 
			
		||||
class Lexer {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										15
									
								
								src/lex.cpp
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								src/lex.cpp
									
									
									
									
									
								
							@@ -23,6 +23,10 @@ std::ostream &operator<<(std::ostream &os, Token const &t) {
 | 
			
		||||
    return os;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool operator==(Token const& one, Token const& other) {
 | 
			
		||||
    return one.type == other.type && one.value == other.value; 
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool ispunct(char c) {
 | 
			
		||||
    for (char i : "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~") {
 | 
			
		||||
        if (i == c) return true;
 | 
			
		||||
@@ -61,9 +65,10 @@ Token Lexer::lexNumOrSym() {
 | 
			
		||||
    // ... this will almost certainly change, won't it?
 | 
			
		||||
    string s = acc.str();
 | 
			
		||||
    string iterate_over = (s.at(0) == '-') ? s.substr(1) : s;
 | 
			
		||||
    bool is_number = true;
 | 
			
		||||
    bool is_number = false;
 | 
			
		||||
    bool dot_seen = false;
 | 
			
		||||
    for (char c : s) {
 | 
			
		||||
    for (char c : iterate_over) {
 | 
			
		||||
        
 | 
			
		||||
        if (c == '.') {
 | 
			
		||||
            if (dot_seen) {
 | 
			
		||||
                is_number = false;
 | 
			
		||||
@@ -72,14 +77,16 @@ Token Lexer::lexNumOrSym() {
 | 
			
		||||
            dot_seen = true;
 | 
			
		||||
            continue;
 | 
			
		||||
        }
 | 
			
		||||
        if (!isdigit(c)) {
 | 
			
		||||
        if (isdigit(c)) {
 | 
			
		||||
            is_number = true;
 | 
			
		||||
        } else {
 | 
			
		||||
            is_number = false;
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (is_number && dot_seen) {
 | 
			
		||||
        if (s == ".")
 | 
			
		||||
        if (iterate_over == ".")
 | 
			
		||||
            return {TokenType::Symbol, s};
 | 
			
		||||
        return {TokenType::Double, stod(s)};
 | 
			
		||||
    } else if (is_number) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user