Initial test bootstrap.
This commit is contained in:
parent
6c618749f1
commit
4b308f6c32
94 changed files with 2543 additions and 681 deletions
78
src/base/compiler/KScope.cpp
Normal file
78
src/base/compiler/KScope.cpp
Normal file
|
@ -0,0 +1,78 @@
|
|||
#include "KScope.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
void KScopeLexer::run(const FileSystemPath& path)
|
||||
{
|
||||
printf("Before read");
|
||||
File f(path);
|
||||
|
||||
const auto content = f<.readText();
|
||||
printf("Content is: %s\n", content);
|
||||
fflush(stdout);
|
||||
|
||||
Vector<Token> tokens;
|
||||
for(const auto c : content.data())
|
||||
{
|
||||
printf("Char is: %c\n", c);
|
||||
if (CharUtils::is_space(c))
|
||||
{
|
||||
if (m_working_token.is_identifier() || m_working_token.is_number())
|
||||
{
|
||||
on_token_finished(tokens);
|
||||
}
|
||||
}
|
||||
else if (CharUtils::is_alpha(c))
|
||||
{
|
||||
if (m_working_token.is_number())
|
||||
{
|
||||
on_token_finished(tokens);
|
||||
m_working_token = Token();
|
||||
m_working_token.set_is_identifier();
|
||||
}
|
||||
else if (!m_working_token.is_identifier())
|
||||
{
|
||||
m_working_token = Token();
|
||||
m_working_token.set_is_identifier();
|
||||
}
|
||||
m_working_token.m_value += c;
|
||||
}
|
||||
else if (CharUtils::is_digit(c))
|
||||
{
|
||||
if (m_working_token.is_number() || m_working_token.is_identifier())
|
||||
{
|
||||
m_working_token.m_value += c;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_working_token = Token();
|
||||
m_working_token.set_is_number();
|
||||
m_working_token.m_value += c;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_working_token.is_identifier() || m_working_token.is_number())
|
||||
{
|
||||
on_token_finished(tokens);
|
||||
}
|
||||
|
||||
m_working_token.set_is_literal();
|
||||
m_working_token.m_value += c;
|
||||
on_token_finished(tokens);
|
||||
}
|
||||
}
|
||||
on_token_finished(tokens);
|
||||
}
|
||||
|
||||
void KScopeLexer::on_token_finished(Vector<Token>& tokens)
|
||||
{
|
||||
if (m_working_token.m_type == TokenT::NONE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_working_token.on_finished();
|
||||
tokens.push_back(m_working_token);
|
||||
m_working_token = Token();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue