-
-
Save cabelotaina/ee89a89088030d8d7037ef82961b315b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace ast | |
{ | |
enum { | |
PROGRAM, | |
SUBROUTINE, | |
FUNCTION, | |
STOP, | |
RETURN, | |
END, | |
PARAMETER, | |
INTEGER, | |
REAL, | |
CYCLE, | |
EXIT, | |
IF, | |
ELSE, | |
ELSEIF, | |
ENDIF, | |
WHILE, | |
DO, | |
ENDDO, | |
PRINT, | |
READ, | |
CALL | |
}; | |
enum { | |
SIGN_SUM, | |
SIGN_SUB, | |
SIGN_TIMES, | |
SIGN_DIV | |
}; | |
enum { | |
REL_EQ, | |
REL_NE, | |
REL_GT, | |
REL_GE, | |
REL_LT, | |
REL_LE | |
}; | |
enum { | |
BOOL_TRUE, | |
BOOL_FALSE | |
}; | |
enum { | |
ASSIGN, | |
COMMA, | |
LP, | |
RP | |
}; | |
typedef std::vector<std::string> VarList; | |
typedef std::vector<VarList> VarCore; | |
struct Quantity | |
{ | |
VarCore parts; | |
VarList cond; | |
}; | |
struct Term | |
{ | |
double coefficient; | |
Quantity quantity; | |
inline Term& flip_sign(int s) | |
{ | |
if (s == SIGN_TIMES) { | |
coefficient = -coefficient; | |
} | |
return *this; | |
} | |
}; | |
typedef std::vector<Term> Expression; | |
struct Relation { | |
Expression left; | |
int relation; | |
Expression right; | |
}; | |
struct FunctionOf { | |
VarList function, of; | |
}; | |
// our very begining AST | |
typedef std::vector<std::string> ParameterList; | |
struct ExecutableProgram { | |
MainProgram left; | |
ExecutableProgram program; | |
Subprogram right; | |
}; | |
struct Subprogram { | |
Subroutine sub; | |
Function func; | |
}; | |
struct MainProgram { | |
MainProgramPrefix left; | |
Body content; | |
MainProgramSuffix right; | |
}; | |
; | |
struct Subroutine { | |
SubroutinePrefix pre; | |
ParameterList params; | |
Body content; | |
SubroutineSuffix suf; | |
}; | |
struct Function { | |
FunctionPrefix pre; | |
VarList ParameterList; | |
Body content; | |
FunctionSuffix suf; | |
} | |
struct MainProgramPrefix { | |
std::string ReservedWord = "PROGRAM"; | |
std::string Name; | |
} | |
//typedef std::string MainProgramSuffix = "END" | |
struct MainProgramSuffix { | |
std::string stop = "STOP"; | |
std::string end = "END"; | |
} | |
struct SubroutinePrefix { | |
std::string "SUBROUTINE"; | |
Name id; | |
}; | |
struct SubroutineSuffix{ | |
std::string ret = "RETURN", end = "END"; | |
}; | |
struct FunctionPrefix { | |
Type type; | |
std::string func = "FUNCTION"; | |
Name id; | |
}; | |
struct FunctionSuffix { | |
std::string ret = "RETURN", end = "END"; | |
}; | |
typedef std::vector<char> Name; | |
struct Body{ | |
BodyConstruct contruct; | |
Body content; | |
}; | |
struct BodyConstruct { | |
SpecificationConstruct specification; | |
ExecutableConstruct executable; | |
}; | |
struct SpecificationConstruct{ | |
DeclarationConstruct dec; | |
ParameterStatement param; | |
}; | |
struct DeclarationConstruct { | |
Declaration dec; | |
DeclarationConstruct decConst; | |
}; | |
struct Declaration{ | |
Type; | |
IdentifierDeclarationList; | |
}; | |
typedef int INTEGER; | |
typedef float REAL; | |
typedef char CHARACTER; | |
typedef bool LOGICAL; | |
// O que vai ser esses cara? | |
// enum Type : "INTEGER" | |
// | "REAL" | |
// | "CHARACTER" | |
// | "LOGICAL" | |
// ; | |
// struct Type { | |
// int type; | |
// } | |
// enum Type { | |
// INTEGER i; | |
// REAL r; | |
// CHARACTER c; | |
// LOGICAL l; | |
// }; | |
// struct Type { | |
// INTEGER i; | |
// REAL r; | |
// CHARACTER c; | |
// LOGICAL l; | |
// }; | |
typedef std::string Identifier; | |
struct IdentifierDeclaration { | |
Identifier id; | |
std::string lp = "(", rp = ")"; | |
int integer; | |
}; | |
typedef std::std::vector<string> IdentifierDeclarationList; | |
struct ParameterStatement{ | |
std::string id = "PARAMETER"; | |
std::string lp = "(", rp = ")"; | |
ConstantList l; | |
}; | |
struct ConstantExpression { | |
Number n; | |
StringLiteral sl; | |
}; | |
struct ConstantDefinition { | |
Identifier id; | |
std::string equal = "="; // ver se isso declara uma definicao de constante | |
ConstantExpression ce; | |
}; | |
typedef std::vector<ConstantDefinition> ConstantList; | |
struct ExecutableConstruct{ | |
Statement stm; | |
ExecutableConstruct ec; | |
}; | |
struct Statement{ | |
AssignmentStatement as; | |
ReadStatement rs; | |
IfConstruct ic; | |
DoConstruct dc; | |
WhileConstruct wc; | |
CallStatement cs; | |
CycleStatement cys; | |
ExitStatement es; | |
}; | |
struct AssignmentStatement { | |
Identifier id; | |
std::string eq = "=", lp = "(", rp = ")"; | |
Expression exp; | |
Integer value; | |
}; | |
struct Expression { | |
Factor f; | |
int relation; | |
Expression ex; | |
}; | |
struct Factor { | |
Factor f; | |
int relation; | |
Term t; | |
}; | |
typedef std::verctor<Expression> ExpressionList; | |
struct Term { | |
int lp; | |
Expression ex | |
int rp; | |
Identifier id; | |
ExpressionList el; | |
Number n; | |
Term t; // como fica "-" Term | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment