Add integer parsing
Signed-off-by: Username404 <w.iron.zombie@gmail.com>
This commit is contained in:
		
							parent
							
								
									adbe98ec00
								
							
						
					
					
						commit
						8a97def6b2
					
				| @ -105,6 +105,10 @@ namespace StandardComponents { | ||||
|         using NamedIdentifier::NamedIdentifier; | ||||
|     }; | ||||
|     namespace types { | ||||
|         struct Integer: ParseComponent { | ||||
|             long double value; | ||||
|             Integer(const string& value): value(stold(value)) {} | ||||
|         }; | ||||
|         struct String: ParseComponent { | ||||
|             const string content; | ||||
|             explicit String(const char* string): content(string) {} | ||||
|  | ||||
| @ -42,6 +42,16 @@ namespace Parser { | ||||
|             const tok& current = lexed[i], next = hasNext ? lexed[i + 1] : tok(UNEXPECTED, current.line); | ||||
| 
 | ||||
|             switch (current.toktype) { | ||||
|                 case NUMBER: { | ||||
|                     types::Integer Int = current.toktext; | ||||
|                     if (nextAre({DOT, NUMBER})) { | ||||
|                         i += 2; | ||||
|                         const string& right = lexed[i].toktext; | ||||
|                         Int.value += stold(right) / pow(10, right.size()); | ||||
|                     } | ||||
|                     parseTree << Int; | ||||
|                     break; | ||||
|                 } | ||||
|                 case STRING: parseTree << types::String(current.toktext.data()); break; | ||||
|                 case IDENTIFIER: { | ||||
|                     if (current.toktext == "class" || current.toktext == "structure") { | ||||
|  | ||||
| @ -132,7 +132,8 @@ public: | ||||
|                 output << ((parseComponent.name == "print") ? print_functions.first : (parseComponent.name == "print_line") ? print_functions.second : parseComponent.name) << '('; | ||||
|                 separate_transpileTree(parseComponent, ", "); | ||||
|                 output << ')'; | ||||
|             ) | ||||
|             ), | ||||
|             make_task(StandardComponents::types::Integer, output << parseComponent.value;) | ||||
|         })); | ||||
|         return staticMap; | ||||
|     }; | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user