From 4b4cda91cb41ca8da96193fe8da442a77523cfc1 Mon Sep 17 00:00:00 2001 From: mrexodia Date: Wed, 21 Sep 2016 21:46:11 +0200 Subject: [PATCH] changed AST --- btparser/ast.h | 23 ++++++++++++++++------- btparser/parser.cpp | 15 ++++++++++----- btparser/parser.h | 3 ++- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/btparser/ast.h b/btparser/ast.h index 5d35d12..6d83a8a 100644 --- a/btparser/ast.h +++ b/btparser/ast.h @@ -55,21 +55,30 @@ namespace AST { }; - class Builtin : public Decl //built-in declaration (int x) + class BuiltinVar : public Decl //built-in variable declaration (int x) { Type mType; - string mId; + string mName; public: - explicit Builtin(Type type, const string & id) - : mType(type), mId(id) {} + explicit BuiltinVar(Type type, const string & id) + : mType(type), mName(id) {} }; - class Struct : public Decl //struct (can contain code, not just declarations) + class Struct : public Decl //struct declaration (can contain code, not just declarations) { - string mId; + string mName; uptr mBlock; public: explicit Struct(const string & id, uptr block) - : mId(id), mBlock(move(block)) {} + : mName(id), mBlock(move(block)) {} + }; + + class StructVar : public Decl //struct variable declaration: (struct {...} x;) + { + string mVarName; //name of the variable + string mStructName; //name of the struct + public: + explicit StructVar(const string & varName, const string & structName) + : mVarName(varName), mStructName(structName) {} }; }; \ No newline at end of file diff --git a/btparser/parser.cpp b/btparser/parser.cpp index 6b1ef2a..167fec3 100644 --- a/btparser/parser.cpp +++ b/btparser/parser.cpp @@ -128,7 +128,7 @@ uptr Parser::ParseReturn() uptr Parser::ParseDecl() { - auto builtin = ParseBuiltin(); + auto builtin = ParseBuiltinVar(); if (builtin) return move(builtin); auto stru = ParseStruct(); @@ -137,7 +137,7 @@ uptr Parser::ParseDecl() return nullptr; } -uptr Parser::ParseBuiltin() +uptr Parser::ParseBuiltinVar() { if (CurToken.Token == Lexer::tok_uint) //TODO: properly handle types { @@ -145,18 +145,18 @@ uptr Parser::ParseBuiltin() NextToken(); if (CurToken.Token != Lexer::tok_identifier) { - ReportError("failed to parse Builtin (no identifier)"); + ReportError("failed to parse BuiltinVar (no identifier)"); return nullptr; } auto id = CurToken.IdentifierStr; NextToken(); if (CurToken.Token != Lexer::tok_semic) { - ReportError("failed to parse Builtin (no semicolon)"); + ReportError("failed to parse BuiltinVar (no semicolon)"); return nullptr; } NextToken(); - return make_uptr(type, id); + return make_uptr(type, id); } return nullptr; } @@ -182,3 +182,8 @@ uptr Parser::ParseStruct() } return nullptr; } + +AST::uptr Parser::ParseStructVar() +{ + return nullptr; +} diff --git a/btparser/parser.h b/btparser/parser.h index 90271a9..288084c 100644 --- a/btparser/parser.h +++ b/btparser/parser.h @@ -37,6 +37,7 @@ private: AST::uptr ParseReturn(); AST::uptr ParseDecl(); - AST::uptr ParseBuiltin(); + AST::uptr ParseBuiltinVar(); AST::uptr ParseStruct(); + AST::uptr ParseStructVar(); }; \ No newline at end of file