More stuff! Tons of stuff!
This commit is contained in:
@@ -60,6 +60,9 @@ SET(SCULLY_SOURCE
|
|||||||
|
|
||||||
src/AST/ASTElement.cpp
|
src/AST/ASTElement.cpp
|
||||||
src/AST/ASTVisitor.cpp
|
src/AST/ASTVisitor.cpp
|
||||||
|
src/AST/Statement.cpp
|
||||||
|
src/AST/VariableDefinition.cpp
|
||||||
|
src/AST/Type.cpp
|
||||||
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/grammar.cpp
|
${CMAKE_CURRENT_BINARY_DIR}/grammar.cpp
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -8,6 +8,9 @@
|
|||||||
#include "Token.h"
|
#include "Token.h"
|
||||||
|
|
||||||
#include "AST/ASTElement.h"
|
#include "AST/ASTElement.h"
|
||||||
|
#include "AST/Statement.h"
|
||||||
|
#include "AST/VariableDefinition.h"
|
||||||
|
#include "AST/Type.h"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,18 +44,18 @@ fundefs(A) ::= . { A = 0; }
|
|||||||
fundefs(A) ::= fundefs fundef(B). { A = A + B; }
|
fundefs(A) ::= fundefs fundef(B). { A = A + B; }
|
||||||
|
|
||||||
%type fundef {int}
|
%type fundef {int}
|
||||||
fundef(A) ::= type(T) T_IDENTIFIER(ID) params(P) T_BEGIN statements(S) T_END. { A = T + 1 + P + S; /* ID */ }
|
fundef(A) ::= type(T) T_IDENTIFIER(ID) params(P) T_BEGIN statements(S) T_END. { A = 1 + 1 + P + S; /* T ID */ }
|
||||||
|
|
||||||
%type type {int}
|
%type type {Type*}
|
||||||
type(A) ::= T_BOOL. { A = 1; }
|
type(A) ::= T_BOOL. { A = new Type("bool"); }
|
||||||
type(A) ::= T_INT. { A = 1; }
|
type(A) ::= T_INT. { A = new Type("int"); }
|
||||||
type(A) ::= T_STRING. { A = 1; }
|
type(A) ::= T_STRING. { A = new Type("string"); }
|
||||||
type(A) ::= T_VOID. { A = 1; }
|
type(A) ::= T_VOID. { A = new Type("void"); }
|
||||||
|
|
||||||
%type params {int}
|
%type params {int}
|
||||||
params(A) ::= . { A = 0; }
|
params(A) ::= . { A = 0; }
|
||||||
params(A) ::= type(T) T_IDENTIFIER(ID). { A = T + 1; /* ID */ }
|
params(A) ::= type(T) T_IDENTIFIER(ID). { A = 1 + 1; /* T ID */ }
|
||||||
params(A) ::= params(B) T_COMMA type(T) T_IDENTIFIER(ID). { A = B + T + 1; /* ID */ }
|
params(A) ::= params(B) T_COMMA type(T) T_IDENTIFIER(ID). { A = B + 1 + 1; /* T ID */ }
|
||||||
|
|
||||||
%type statement {int}
|
%type statement {int}
|
||||||
statement(A) ::= T_IF T_LPAREN expr(E) T_RPAREN statement(S). { A = E + S; }
|
statement(A) ::= T_IF T_LPAREN expr(E) T_RPAREN statement(S). { A = E + S; }
|
||||||
@@ -84,7 +87,7 @@ expr(A) ::= T_FALSE. { A = 1; }
|
|||||||
expr(A) ::= T_IDENTIFIER(ID) T_LPAREN values(V) T_RPAREN. { A = 1 + V; /* ID */ }
|
expr(A) ::= T_IDENTIFIER(ID) T_LPAREN values(V) T_RPAREN. { A = 1 + V; /* ID */ }
|
||||||
|
|
||||||
%type vardef {int}
|
%type vardef {int}
|
||||||
vardef(A) ::= type(T) T_IDENTIFIER(ID). { A = T + 1; /* ID */ }
|
vardef(A) ::= type(T) T_IDENTIFIER(ID). { A = 1 + 1; /* T ID */ }
|
||||||
|
|
||||||
%type values {int}
|
%type values {int}
|
||||||
values(A) ::= . { A = 0; }
|
values(A) ::= . { A = 0; }
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#ifndef ASTELEMENT_H
|
#ifndef ASTELEMENT_H
|
||||||
#define ASTELEMENT_H
|
#define ASTELEMENT_H
|
||||||
|
|
||||||
#include "AST/ASTVisitor.h"
|
class ASTVisitor;
|
||||||
|
|
||||||
class ASTElement {
|
class ASTElement {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
#ifndef ASTVISITOR_H
|
#ifndef ASTVISITOR_H
|
||||||
#define ASTVISITOR_H
|
#define ASTVISITOR_H
|
||||||
|
|
||||||
|
#include "VariableDefinition.h"
|
||||||
|
|
||||||
class ASTVisitor {
|
class ASTVisitor {
|
||||||
public:
|
public:
|
||||||
ASTVisitor();
|
ASTVisitor();
|
||||||
virtual ~ASTVisitor();
|
virtual ~ASTVisitor();
|
||||||
|
|
||||||
|
virtual void visit(VariableDefinition* e) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ASTVISITOR_H
|
#endif // ASTVISITOR_H
|
||||||
|
|||||||
14
inc/AST/Statement.h
Normal file
14
inc/AST/Statement.h
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#ifndef STATEMENT_H
|
||||||
|
#define STATEMENT_H
|
||||||
|
|
||||||
|
#include "AST/ASTElement.h"
|
||||||
|
|
||||||
|
class Statement : public ASTElement {
|
||||||
|
public:
|
||||||
|
Statement();
|
||||||
|
virtual ~Statement();
|
||||||
|
|
||||||
|
virtual void accept(ASTVisitor* visitor) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // STATEMENT_H
|
||||||
16
inc/AST/Type.h
Normal file
16
inc/AST/Type.h
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#ifndef TYPE_H
|
||||||
|
#define TYPE_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class Type {
|
||||||
|
public:
|
||||||
|
Type(std::string name);
|
||||||
|
~Type();
|
||||||
|
|
||||||
|
std::string getName();
|
||||||
|
private:
|
||||||
|
std::string name_;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TYPE_H
|
||||||
25
inc/AST/VariableDefinition.h
Normal file
25
inc/AST/VariableDefinition.h
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#ifndef VARIABLEDEFINITION_H
|
||||||
|
#define VARIABLEDEFINITION_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "AST/Statement.h"
|
||||||
|
|
||||||
|
class VariableDefinition : public Statement
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
VariableDefinition(int type, std::string name);
|
||||||
|
virtual ~VariableDefinition();
|
||||||
|
|
||||||
|
virtual void accept(ASTVisitor* visitor);
|
||||||
|
|
||||||
|
// Type* getType();
|
||||||
|
int getType();
|
||||||
|
std::string getName();
|
||||||
|
private:
|
||||||
|
// Type* type_
|
||||||
|
int type_;
|
||||||
|
std::string name_;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // VARIABLEDEFINITION_H
|
||||||
@@ -7,4 +7,3 @@ ASTVisitor::ASTVisitor() {
|
|||||||
ASTVisitor::~ASTVisitor() {
|
ASTVisitor::~ASTVisitor() {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
9
src/AST/Statement.cpp
Normal file
9
src/AST/Statement.cpp
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#include "AST/Statement.h"
|
||||||
|
|
||||||
|
Statement::Statement() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
Statement::~Statement() {
|
||||||
|
//
|
||||||
|
}
|
||||||
5
src/AST/Type.cpp
Normal file
5
src/AST/Type.cpp
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#include "AST/Type.h"
|
||||||
|
|
||||||
|
Type::Type(std::string name) : name_(name) {
|
||||||
|
//
|
||||||
|
}
|
||||||
22
src/AST/VariableDefinition.cpp
Normal file
22
src/AST/VariableDefinition.cpp
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#include "AST/VariableDefinition.h"
|
||||||
|
#include "AST/ASTVisitor.h"
|
||||||
|
|
||||||
|
VariableDefinition::VariableDefinition(int type, std::string name) : type_(type), name_(name) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
VariableDefinition::~VariableDefinition() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void VariableDefinition::accept(ASTVisitor* visitor) {
|
||||||
|
visitor->visit(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
int VariableDefinition::getType() {
|
||||||
|
return type_;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string VariableDefinition::getName() {
|
||||||
|
return name_;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user