diff options
Diffstat (limited to 'c_compiler')
102 files changed, 1477 insertions, 0 deletions
diff --git a/c_compiler/include/ast.hpp b/c_compiler/include/ast.hpp new file mode 100644 index 0000000..9d51816 --- /dev/null +++ b/c_compiler/include/ast.hpp @@ -0,0 +1,14 @@ +#ifndef AST_HPP +#define AST_HPP + +#include "base.hpp" +#include "statement.hpp" +#include "function.hpp" +#include "declaration.hpp" +#include "expression.hpp" +#include "primitives.hpp" +#include "ast_top.hpp" + +ast_Top *parseAST(); + +#endif diff --git a/c_compiler/include/ast_top.hpp b/c_compiler/include/ast_top.hpp new file mode 100644 index 0000000..737ff58 --- /dev/null +++ b/c_compiler/include/ast_top.hpp @@ -0,0 +1,24 @@ +#ifndef TOP_AST_HPP +#define TOP_AST_HPP + +#include "ast.hpp" + +#include <vector> + +class ast_Top { +public: + void print() { + for(size_t i = 0; i < vec.size(); ++i) { + vec[i]->print(); + } + } + + void push(const Base *stmnt) { + vec.push_back(stmnt); + } + +private: + std::vector<const Base *> vec; +}; + +#endif diff --git a/c_compiler/include/base.hpp b/c_compiler/include/base.hpp new file mode 100644 index 0000000..9451609 --- /dev/null +++ b/c_compiler/include/base.hpp @@ -0,0 +1,16 @@ +#ifndef AST_BASE_HPP +#define AST_BASE_HPP + +#include <string> +#include <iostream> +#include <vector> + +class Base { +public: + virtual ~Base() {} + + virtual void print() const = 0; + virtual void push(const Base* _var) const = 0; +}; + +#endif diff --git a/c_compiler/include/declaration.hpp b/c_compiler/include/declaration.hpp new file mode 100644 index 0000000..bfd3070 --- /dev/null +++ b/c_compiler/include/declaration.hpp @@ -0,0 +1,50 @@ +#ifndef AST_DECLARATION_HPP +#define AST_DECLARATION_HPP + +#include "ast.hpp" + +#include <vector> + +// Declaration that holds a list of declarations + +class DeclarationList : public Base { +private: + mutable std::vector<const Base*> dec_list; + +public: + DeclarationList(const Base* _dec) { + dec_list.push_back(_dec); + } + + virtual void print() const { + for(size_t i = 0; i < dec_list.size(); ++i) { + dec_list[i]->print(); + } + } + + virtual void push(const Base* _dec) const { + dec_list.push_back(_dec); + } +}; + +class VariableDeclaration : public Base { +private: + mutable std::vector<const Base*> var_list; + +public: + VariableDeclaration(const Base* _var) { + var_list.push_back(_var); + } + + virtual void print() const { + for(size_t i = 0; i < var_list.size(); ++i) { + var_list[i]->print(); + } + } + + virtual void push(const Base* _var) const { + var_list.push_back(_var); + } +}; + +#endif diff --git a/c_compiler/include/expression.hpp b/c_compiler/include/expression.hpp new file mode 100644 index 0000000..f67d2d7 --- /dev/null +++ b/c_compiler/include/expression.hpp @@ -0,0 +1,24 @@ +#ifndef AST_EXPRESSION_HPP +#define AST_EXPRESSION_HPP + +#include "ast.hpp" + +#include <string> +#include <iostream> + +class Expression : public Base { +private: +public: + Expression() {} + + virtual void print() const { + + } + + virtual void push(const Base* _base) const { + std::cerr << "Can't call this function for this type" << std::endl; + (void)_base; + } +}; + +#endif diff --git a/c_compiler/include/function.hpp b/c_compiler/include/function.hpp new file mode 100644 index 0000000..6fbcdee --- /dev/null +++ b/c_compiler/include/function.hpp @@ -0,0 +1,53 @@ +#ifndef AST_FUNCTION_HPP +#define AST_FUNCTION_HPP + +#include "ast.hpp" + +#include <string> +#include <iostream> + +class Function : public Base { +private: + std::string id; + const Base* param; + const Base* comp_statement; +public: + Function(const std::string& _id, const Base* _param, const Base* _comp_statement) : + id(_id), param(_param), comp_statement(_comp_statement) {} + + virtual void print() const { + std::cout << "<Function id=\"" << id << "\">" << std::endl; + param->print(); + comp_statement->print(); + std::cout << "</Function>" << std::endl; + } + + virtual void push(const Base* var) const { + std::cerr << "Error: Can't call this function on this class" << std::endl; + (void)var; + } +}; + +class ParamList : public Base { +private: + mutable std::vector<const Base*> param_list; + +public: + ParamList() {} + + ParamList(const Base* param) { + param_list.push_back(param); + } + + virtual void print() const { + for(size_t i = 0; i < param_list.size(); ++i) { + param_list[i]->print(); + } + } + + virtual void push(const Base* _var) const { + param_list.push_back(_var); + } +}; + +#endif diff --git a/c_compiler/include/primitives.hpp b/c_compiler/include/primitives.hpp new file mode 100644 index 0000000..2eeaa19 --- /dev/null +++ b/c_compiler/include/primitives.hpp @@ -0,0 +1,40 @@ +#ifndef AST_PRIMITIVES_HPP +#define AST_PRIMITIVES_HPP + +#include "ast.hpp" + +#include <string> + +class Variable : public Base { +private: + std::string id; +public: + Variable(const std::string& _id) : id(_id) {} + + virtual void print() const { + std::cout << "<Variable id=\"" << id << "\" />" << std::endl; + } + + virtual void push(const Base* var) const { + std::cerr << "Error: Can't call this function on this class" << std::endl; + (void)var; + } +}; + +class Parameter : public Base { +private: + std::string id; +public: + Parameter(const std::string& _id) : id(_id) {} + + virtual void print() const { + std::cout << "<Parameter id=\"" << id << "\" />" << std::endl; + } + + virtual void push(const Base* var) const { + std::cerr << "Error: Can't call this function on this class" << std::endl; + (void)var; + } +}; + +#endif diff --git a/c_compiler/include/statement.hpp b/c_compiler/include/statement.hpp new file mode 100644 index 0000000..4761efb --- /dev/null +++ b/c_compiler/include/statement.hpp @@ -0,0 +1,81 @@ +#ifndef AST_STATEMENT_HPP +#define AST_STATEMENT_HPP + +#include "ast.hpp" + +class Statement : public Base { +protected: + mutable std::vector<const Base*> list; + +public: + Statement() {} + + Statement(const Base* _el) { + list.push_back(_el); + } + + Statement(const Base* _dec, const Base* _statement) { + list.push_back(_dec); + list.push_back(_statement); + } + virtual void print() const { + for(size_t i = 0; i < list.size(); ++i) { + list[i]->print(); + } + } + + virtual void push(const Base* _var) const { + list.push_back(_var); + } +}; + +class StatementList : public Statement { +public: + StatementList(const Base* _statement) : Statement(_statement) {} +}; + +class CompoundStatement : public Statement { +public: + CompoundStatement() : Statement() {} + CompoundStatement(const Base* _el) : Statement(_el) {} + CompoundStatement(const Base* _dec, const Base* _statement) : + Statement(_dec, _statement) {} + + virtual void print() const override { + std::cout << "<Scope>" << std::endl; + for(size_t i = 0; i < list.size(); ++i) { + list[i]->print(); + } + std::cout << "</Scope>" << std::endl; + } +}; + +class SelectionStatement : public Statement { +public: + SelectionStatement() : Statement() {} + SelectionStatement(const Base* _el) : Statement(_el) {} + SelectionStatement(const Base* _if, const Base* _else) : + Statement(_if, _else) {} +}; + +class ExpressionStatement : public Statement { +public: + ExpressionStatement() : Statement() {} + ExpressionStatement(const Base* _el) : Statement(_el) {} +}; + +class JumpStatement : public Statement { +public: + JumpStatement() : Statement() {} + JumpStatement(const Base* _el) : Statement(_el) {} +}; + +class IterationStatement : public Statement { +public: + IterationStatement() : Statement() {} + IterationStatement(const Base* _el) : Statement(_el) {} + IterationStatement(const Base* _if, const Base* _else) : + Statement(_if, _else) {} +}; + +#endif diff --git a/c_compiler/src/c_lexer.flex b/c_compiler/src/c_lexer.flex new file mode 100644 index 0000000..c8ca90a --- /dev/null +++ b/c_compiler/src/c_lexer.flex @@ -0,0 +1,98 @@ +%option noyywrap + +%{ +// Avoid error "error: fileno was not declared in this scope" +extern "C" int fileno(FILE *stream); + +#include "c_parser.tab.hpp" + +%} + +KEYWORD auto|double|int|struct|break|else|long|switch|case|enum|register|typedef|char|extern|return|union|const|float|short|unsigned|continue|for|signed|void|default|goto|sizeof|volatile|do|if|static|while + +IDENTIFIER [_a-zA-Z][_a-zA-Z0-9]* + +OPERATOR [.][.][.]|[<>][<>][=]|[-][-]|[+][+]|[|][|]|[#][#]|[&][&]|[+\-*\/<>=!%^|&][=]|[<][<]|[->][>]|[<>&=+\/\-*(){}\[\]\.,%~!?:|^;] + +ASSIGNMENT_OPERATOR (([<>][<>]|[*\/%+\-&^|])[=]|[=]) + +FRACTIONALCONSTANT (([0-9]*\.[0-9]+)|([0-9]+\.)) +EXPONENTPART ([eE][+-]?[0-9]+) + +FLOATINGSUFFI X ([flFL]) +INTEGERSUFFIX ([uU][lL]|[lL][uU]|[uUlL]) + +DECIMALCONSTANT ([1-9][0-9]*) +OCTALCONSTANT ([0][0-7]*) +HEXCONSTANT ([0][xX][0-9A-Fa-f]+) + +CHARCONSTANT ('(([\\]['])|([^']))+') + +STRINGLITERAL ["](([\\]["])|([^"]))*["] + +WHITESPACE [ \t\r\n]+ + +PREPROC [#][ ][0-9]+[ ]{STRINGLITERAL}[ 0-9]* + +ALL . + +%% + +typedef|extern|static|auto|register { return T_STRG_SPEC; } +void|char|short|int|long|float|double|signed|unsigned { return T_TYPE_SPEC; } +const|volatile { return T_TYPE_QUAL; } + +[;] { return T_SC; } +[,] { return T_CMA; } +[(] { return T_LRB; } +[)] { return T_RRB; } +[{] { return T_LCB; } +[}] { return T_RCB; } +[[] { return T_LSB; } +[]] { return T_RSB; } +[?] { return T_QU; } +[:] { return T_COL; } +[|][|] { return T_LOG_OR; } +[&][&] { return T_LOG_AND; } +[|] { return T_OR; } +[\^] { return T_XOR; } +[&] { return T_AND; } +[=][=] { return T_EQUALITY_OP; } +[!][=] { return T_EQUALITY_OP; } +([<>][=])|[<>] { return T_REL_OP; } +[<>][<>] { return T_SHIFT_OP; } +[*] { return T_MULT; } +[\/] { return T_DIV; } +[%] { return T_REM; } +[~] { return T_TILDE; } +[!] { return T_NOT; } +[.] { return T_DOT; } +[-][>] { return T_ARROW; } +[+-][+-] { return T_INCDEC; } +[+-] { return T_ADDSUB_OP; } +[=] { yylval.string = new std::string(yytext); return T_EQ; } + +{ASSIGNMENT_OPERATOR} { yylval.string = new std::string(yytext); return T_ASSIGN_OPER; } + +if { return T_IF; } +else { return T_ELSE; } +return { return T_RETURN; } +while { return T_WHILE; } +do { return T_DO; } +for { return T_FOR; } +sizeof { return T_SIZEOF; } + +{IDENTIFIER} { yylval.string = new std::string(yytext); return T_IDENTIFIER; } + +({HEXCONSTANT}|{OCTALCONSTANT}|{DECIMALCONSTANT}){INTEGERSUFFIX}? { yylval.number = strtol(yytext, NULL, 0); return T_INT_CONST; } + +{WHITESPACE} { ; } + +. { fprintf(stderr, "Invalid token\n"); exit(1); } + +%% + +void yyerror(char const *s) { + fprintf (stderr, "Parse error : %s\n", s); + exit(1); +} diff --git a/c_compiler/src/c_parser.y b/c_compiler/src/c_parser.y new file mode 100644 index 0000000..1fc4d4a --- /dev/null +++ b/c_compiler/src/c_parser.y @@ -0,0 +1,303 @@ +%code requires{ + +#include "ast.hpp" +extern ast_Top *g_root; // A way of getting the AST out + +//! This is to fix problems when generating C++ +// We are declaring the functions provided by Flex, so +// that Bison generated code can call them. +int yylex(void); +void yyerror(const char *); + +} + +// Represents the value associated with any kind of +// AST node. +%union{ + const Base *stmnt; + double number; + std::string *string; +} + +%token T_TYPE_SPEC T_TYPE_QUAL T_STRG_SPEC T_IDENTIFIER +%token T_SC T_CMA T_LRB T_LCB T_RCB T_LSB T_RSB T_QU T_COL T_LOG_OR T_LOG_AND T_OR T_XOR T_AND T_EQUALITY_OP T_REL_OP T_SHIFT_OP T_MULT T_DIV T_REM T_TILDE T_NOT T_DOT T_ARROW T_INCDEC T_ADDSUB_OP T_ASSIGN_OPER T_EQ T_SIZEOF +%token T_INT_CONST +%token T_IF T_WHILE T_DO T_FOR T_RETURN +%nonassoc T_RRB +%nonassoc T_ELSE + + +%type <stmnt> ExtDef ExtDeclaration + +%type <stmnt> FuncDef ParameterList Parameter ParamDeclarator + +%type <stmnt> DeclarationList Declaration DeclarationSpec DeclarationSpec_T InitDeclarator InitDeclaratorList Declarator + +%type <stmnt> StatementList Statement CompoundStatement CompoundStatement_2 SelectionStatement ExpressionStatement JumpStatement IterationStatement + +%type <stmnt> Expression AssignmentExpression ConditionalExpression LogicalOrExpression LogicalAndExpression InclusiveOrExpression ExclusiveOrExpression AndExpression EqualityExpression RelationalExpression ShiftExpression AdditiveExpression MultiplicativeExpression CastExpression UnaryExpression PostfixExpression PostfixExpression2 ArgumentExpressionList PrimaryExpression + + +%type <number> Constant T_INT_CONST + + +%type <string> T_IDENTIFIER MultDivRemOP UnaryOperator ASSIGN_OPER T_ASSIGN_OPER T_EQ T_AND T_ADDSUB_OP T_TILDE T_NOT T_MULT T_DIV T_REM //T_Operator + +%start ROOT + +%% + +ROOT: + ExtDef { ; } + ; + +// EXTERNAL DEFINITION + +ExtDef: + ExtDeclaration { g_root->push($1); } + | ExtDef ExtDeclaration { g_root->push($2); } + ; + +ExtDeclaration: + Declaration { $$ = $1; } + | FuncDef { $$ = $1; } + ; + +// FUNCTION DEFINITION + +FuncDef: + DeclarationSpec T_IDENTIFIER T_LRB ParameterList T_RRB CompoundStatement { $$ = new Function(*$2, $4, $6); } + ; + +ParameterList: + %empty { $$ = new ParamList(); } + | Parameter { $$ = new ParamList($1); } + | ParameterList T_CMA Parameter { $$->push($3); } + ; + +Parameter: + DeclarationSpec ParamDeclarator { $$ = $2; } + ; + +ParamDeclarator: + T_IDENTIFIER { $$ = new Parameter(*$1);} + ; + +// Declaration + +DeclarationList: + Declaration { $$ = new DeclarationList($1); } + | DeclarationList Declaration { $$->push($2); } + ; + +Declaration: + DeclarationSpec InitDeclaratorList T_SC { $$ = $2; } + ; + +DeclarationSpec: + DeclarationSpec_T { ; } + | DeclarationSpec_T DeclarationSpec { ; } + ; + +DeclarationSpec_T: + T_TYPE_SPEC { ; } + | T_TYPE_QUAL { ; } + | T_STRG_SPEC { ; } + ; + +InitDeclaratorList: + InitDeclarator { $$ = new VariableDeclaration($1); } + | InitDeclaratorList T_CMA InitDeclarator { $$->push($3); } + ; + +InitDeclarator: + Declarator { ; } + | Declarator T_EQ AssignmentExpression { ; } + ; + +Declarator: + T_IDENTIFIER {$$ = new Variable(*$1); } + ; + +// Statement + +StatementList: + Statement { $$ = new StatementList($1); } + | StatementList Statement { $$->push($2); } + ; + +Statement: + CompoundStatement { $$ = $1; } + | SelectionStatement { $$ = $1; } + | ExpressionStatement { $$ = $1; } + | JumpStatement { $$ = $1; } + | IterationStatement { $$ = $1; } + ; + +CompoundStatement: + T_LCB CompoundStatement_2 { $$ = $2; } + ; + +CompoundStatement_2: + T_RCB { $$ = new CompoundStatement; } + | DeclarationList T_RCB { $$ = new CompoundStatement($1); } + | DeclarationList StatementList T_RCB { $$ = new CompoundStatement($1, $2); } + | StatementList T_RCB { $$ = new CompoundStatement($1); } + ; + +SelectionStatement: + T_IF T_LRB Expression T_RRB Statement { $$ = new SelectionStatement($5); } +| T_IF T_LRB Expression T_RRB Statement T_ELSE Statement { $$ = new SelectionStatement($5, $7); } + ; + +ExpressionStatement: + T_SC { $$ = new ExpressionStatement(); } + | Expression T_SC { $$ = $1; } + ; + +JumpStatement: + T_RETURN ExpressionStatement { $$ = $2; } + ; + +IterationStatement: + T_WHILE T_LRB Expression T_RRB Statement { $$ = $5; } + | T_DO Statement T_WHILE T_LRB Expression T_RRB T_SC { $$ = $2; } + | T_FOR T_LRB Expression T_SC Expression T_SC Expression T_RRB Statement { $$ = $9; } + ; + +// Expressions + +Expression: + AssignmentExpression { $$ = $1; } + ; + +AssignmentExpression: + ConditionalExpression { $$ = $1; } + | UnaryExpression ASSIGN_OPER AssignmentExpression { $$ = $1; } + ; + +ASSIGN_OPER: + T_ASSIGN_OPER { ; } + | T_EQ { ; } + ; + +ConditionalExpression: + LogicalOrExpression { $$ = $1; } + | LogicalOrExpression T_QU Expression T_COL ConditionalExpression { $$ = $1; } + ; + +LogicalOrExpression: + LogicalAndExpression { $$ = $1; } + | LogicalOrExpression T_LOG_OR LogicalAndExpression { $$ = $3; } + ; + +LogicalAndExpression: + InclusiveOrExpression { $$ = $1; } + | LogicalAndExpression T_LOG_AND InclusiveOrExpression { $$ = $3; } + ; + +InclusiveOrExpression: + ExclusiveOrExpression { $$ = $1; } + | InclusiveOrExpression T_OR ExclusiveOrExpression { $$ = $3; } + ; + +ExclusiveOrExpression: + AndExpression { $$ = $1; } + | ExclusiveOrExpression T_XOR AndExpression { $$ = $3; } + ; + +AndExpression: + EqualityExpression { $$ = $1; } + | AndExpression T_AND EqualityExpression { $$ = $3; } + ; + +EqualityExpression: + RelationalExpression { $$ = $1; } + | EqualityExpression T_EQUALITY_OP RelationalExpression { $$ = $3; } + ; + +RelationalExpression: + ShiftExpression { $$ = $1; } + | RelationalExpression T_REL_OP ShiftExpression { $$ = $3; } + ; + +ShiftExpression: + AdditiveExpression { $$ = $1; } + | ShiftExpression T_SHIFT_OP AdditiveExpression { $$ = $3; } + ; + +AdditiveExpression: + MultiplicativeExpression { $$ = $1; } + | AdditiveExpression T_ADDSUB_OP MultiplicativeExpression { $$ = $3; } + ; + +MultiplicativeExpression: + CastExpression { $$ = $1; } + | MultiplicativeExpression MultDivRemOP CastExpression { $$ = $3; } + ; + +MultDivRemOP: + T_MULT { $$ = $1; } + | T_DIV { $$ = $1; } + | T_REM { $$ = $1; } + ; + +CastExpression: + UnaryExpression { $$ = $1; } + | T_LRB T_TYPE_SPEC T_RRB CastExpression { $$ = $4; } + ; + +UnaryExpression: + PostfixExpression { $$ = $1; } + | T_INCDEC UnaryExpression { $$ = $2; } + | UnaryOperator CastExpression { $$ = $2; } + | T_SIZEOF UnaryExpression { $$ = $2; } + | T_SIZEOF T_LRB T_TYPE_SPEC T_RRB { $$ = new Expression(); } + ; + +UnaryOperator: + T_AND { $$ = $1; } + | T_ADDSUB_OP { $$ = $1; } + | T_MULT { $$ = $1; } + | T_TILDE { $$ = $1; } + | T_NOT { $$ = $1; } + ; + +PostfixExpression: + PrimaryExpression { $$ = $1; } + | PostfixExpression T_LSB Expression T_RSB { $$ = $3; } + | PostfixExpression T_LRB PostfixExpression2 { $$ = $3; } + | PostfixExpression T_DOT T_IDENTIFIER { $$ = new Expression(); } + | PostfixExpression T_ARROW T_IDENTIFIER { $$ = new Expression(); } + | PostfixExpression T_INCDEC { $$ = new Expression(); } + ; + +PostfixExpression2: + T_RRB { $$ = new Expression(); } + | ArgumentExpressionList T_RRB { $$ = $1; } + ; + +ArgumentExpressionList: + AssignmentExpression { $$ = $1; } + | ArgumentExpressionList T_CMA AssignmentExpression { $$ = $3; } + ; + +PrimaryExpression: + T_IDENTIFIER { $$ = new Expression(); } + | Constant { $$ = new Expression(); } + | T_LRB Expression T_RRB { $$ = $2; } + ; + +Constant: + T_INT_CONST { $$ = $1; } + ; + +%% + +ast_Top *g_root; // Definition of variable (to match declaration earlier) + +ast_Top *parseAST() { + g_root = new ast_Top; + yyparse(); + return g_root; +} diff --git a/c_compiler/src/parser_main.cpp b/c_compiler/src/parser_main.cpp new file mode 100644 index 0000000..9626334 --- /dev/null +++ b/c_compiler/src/parser_main.cpp @@ -0,0 +1,15 @@ +#include "ast.hpp" + +#include <iostream> + +int main(int argc, char *argv[]) { + ast_Top *ast = parseAST(); + + std::cout << "<?xml version=\"1.0\"?>" << std::endl << "<Program>" << std::endl; + + ast->print(); + + std::cout << "</Program>" << std::endl; + + return 0; +} diff --git a/c_compiler/test/in/01.c b/c_compiler/test/in/01.c new file mode 100644 index 0000000..76425b5 --- /dev/null +++ b/c_compiler/test/in/01.c @@ -0,0 +1,6 @@ +int a; +int b = 0; +int c, d; + +int e, + f; diff --git a/c_compiler/test/in/02.c b/c_compiler/test/in/02.c new file mode 100644 index 0000000..45b1467 --- /dev/null +++ b/c_compiler/test/in/02.c @@ -0,0 +1 @@ +int f() {} diff --git a/c_compiler/test/in/03.c b/c_compiler/test/in/03.c new file mode 100644 index 0000000..e57aaa9 --- /dev/null +++ b/c_compiler/test/in/03.c @@ -0,0 +1 @@ +int foo(int bar) {} diff --git a/c_compiler/test/in/04.c b/c_compiler/test/in/04.c new file mode 100644 index 0000000..2e3aa5d --- /dev/null +++ b/c_compiler/test/in/04.c @@ -0,0 +1,4 @@ +int foo(int bar1, int bar2) { + int x; + int y, z; +} diff --git a/c_compiler/test/in/05.c b/c_compiler/test/in/05.c new file mode 100644 index 0000000..2317163 --- /dev/null +++ b/c_compiler/test/in/05.c @@ -0,0 +1,3 @@ +int foo(int x, int y) { + {} +} diff --git a/c_compiler/test/in/06.c b/c_compiler/test/in/06.c new file mode 100644 index 0000000..2dcdc2b --- /dev/null +++ b/c_compiler/test/in/06.c @@ -0,0 +1,6 @@ +int f(int a, int b, int c) { + int d; + { + int e; + } +} diff --git a/c_compiler/test/in/07.c b/c_compiler/test/in/07.c new file mode 100644 index 0000000..80d8051 --- /dev/null +++ b/c_compiler/test/in/07.c @@ -0,0 +1,5 @@ +int foo(int a) { + if(x == y) { + int z; + } +} diff --git a/c_compiler/test/in/08.c b/c_compiler/test/in/08.c new file mode 100644 index 0000000..c57a6ab --- /dev/null +++ b/c_compiler/test/in/08.c @@ -0,0 +1,10 @@ +int func(int a, int b) { + int c = 0; + if(a == b) { + int d; + } else if(a == d) { + int e; + return d; + } + return c; +} diff --git a/c_compiler/test/in/09.c b/c_compiler/test/in/09.c new file mode 100644 index 0000000..ae86bb1 --- /dev/null +++ b/c_compiler/test/in/09.c @@ -0,0 +1,15 @@ +int x() +{} + +int g; + +int zz(int a, int b, int c) +{ + if(a==b){ + int a; + return a; + }else{ + int fsdfsdfs; + return c; + } +} diff --git a/c_compiler/test/in/10.c b/c_compiler/test/in/10.c new file mode 100644 index 0000000..37a6ecc --- /dev/null +++ b/c_compiler/test/in/10.c @@ -0,0 +1,18 @@ +int f() +{} + +int g = 2; + +int x(int y) { + int z = 3; + + if(y < z || g < z) { + int r; + ++y; + } else if(y == z) { + int f; + --y; + } else return y; + + return g; +} diff --git a/c_compiler/test/in/11.c b/c_compiler/test/in/11.c new file mode 100644 index 0000000..2d8cac6 --- /dev/null +++ b/c_compiler/test/in/11.c @@ -0,0 +1,10 @@ +int f() { + int x = 0; + + while(x < 5) { + int y = 0; + x++; + } + + return x; +} diff --git a/c_compiler/test/in/12.c b/c_compiler/test/in/12.c new file mode 100644 index 0000000..37b8b7e --- /dev/null +++ b/c_compiler/test/in/12.c @@ -0,0 +1,4 @@ +int f(int b, int c) { + int a = b+c; + return a; +} diff --git a/c_compiler/test/in/13.c b/c_compiler/test/in/13.c new file mode 100644 index 0000000..d912d70 --- /dev/null +++ b/c_compiler/test/in/13.c @@ -0,0 +1,8 @@ +int func(int x, int y) { + int i; + for(i = 0; i < 5; ++i) { + int z = 0; + z = x + y + i; + return x + y; + } +} diff --git a/c_compiler/test/in/14.c b/c_compiler/test/in/14.c new file mode 100644 index 0000000..94506d7 --- /dev/null +++ b/c_compiler/test/in/14.c @@ -0,0 +1,12 @@ +int function_1(int a, int b) { + int x = 0; + + do { + int c = a + b; + x += a; + x = x * b; + x -= c; + } while(x < 500); + + return x; +} diff --git a/c_compiler/test/in/15.c b/c_compiler/test/in/15.c new file mode 100644 index 0000000..3189b56 --- /dev/null +++ b/c_compiler/test/in/15.c @@ -0,0 +1,28 @@ +int add(int a, int b) +{ + int c = a + b; + return c; +} + +int sub(int a, int b) +{ + int c = a - b; + return c; +} + +int mult_by_5(int a) +{ + int b = 5; + return a * b; +} + +int add_5(int a) +{ + int i; + for(i = 0; i < 5; ++i) + { + int b = ++a; + } + + return a; +} diff --git a/c_compiler/test/out/01.diff.txt b/c_compiler/test/out/01.diff.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/c_compiler/test/out/01.diff.txt diff --git a/c_compiler/test/out/01.pretty.xml b/c_compiler/test/out/01.pretty.xml new file mode 100644 index 0000000..e0545e4 --- /dev/null +++ b/c_compiler/test/out/01.pretty.xml @@ -0,0 +1,9 @@ +<?xml version="1.0"?> +<Program> + <Variable id="a" /> + <Variable id="b" /> + <Variable id="c" /> + <Variable id="d" /> + <Variable id="e" /> + <Variable id="f" /> +</Program> diff --git a/c_compiler/test/out/01.stderr.txt b/c_compiler/test/out/01.stderr.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/c_compiler/test/out/01.stderr.txt diff --git a/c_compiler/test/out/01.stdout.txt b/c_compiler/test/out/01.stdout.txt new file mode 100644 index 0000000..bd7cd1f --- /dev/null +++ b/c_compiler/test/out/01.stdout.txt @@ -0,0 +1,9 @@ +<?xml version="1.0"?> +<Program> +<Variable id="a" /> +<Variable id="b" /> +<Variable id="c" /> +<Variable id="d" /> +<Variable id="e" /> +<Variable id="f" /> +</Program> diff --git a/c_compiler/test/out/01.stdout.xml b/c_compiler/test/out/01.stdout.xml new file mode 100644 index 0000000..bd7cd1f --- /dev/null +++ b/c_compiler/test/out/01.stdout.xml @@ -0,0 +1,9 @@ +<?xml version="1.0"?> +<Program> +<Variable id="a" /> +<Variable id="b" /> +<Variable id="c" /> +<Variable id="d" /> +<Variable id="e" /> +<Variable id="f" /> +</Program> diff --git a/c_compiler/test/out/02.diff.txt b/c_compiler/test/out/02.diff.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/c_compiler/test/out/02.diff.txt diff --git a/c_compiler/test/out/02.pretty.xml b/c_compiler/test/out/02.pretty.xml new file mode 100644 index 0000000..1f73bca --- /dev/null +++ b/c_compiler/test/out/02.pretty.xml @@ -0,0 +1,6 @@ +<?xml version="1.0"?> +<Program> + <Function id="f"> + <Scope></Scope> + </Function> +</Program> diff --git a/c_compiler/test/out/02.stderr.txt b/c_compiler/test/out/02.stderr.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/c_compiler/test/out/02.stderr.txt diff --git a/c_compiler/test/out/02.stdout.xml b/c_compiler/test/out/02.stdout.xml new file mode 100644 index 0000000..bc37d7a --- /dev/null +++ b/c_compiler/test/out/02.stdout.xml @@ -0,0 +1,7 @@ +<?xml version="1.0"?> +<Program> +<Function id="f"> +<Scope> +</Scope> +</Function> +</Program> diff --git a/c_compiler/test/out/03.diff.txt b/c_compiler/test/out/03.diff.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/c_compiler/test/out/03.diff.txt diff --git a/c_compiler/test/out/03.pretty.xml b/c_compiler/test/out/03.pretty.xml new file mode 100644 index 0000000..6ab6ab3 --- /dev/null +++ b/c_compiler/test/out/03.pretty.xml @@ -0,0 +1,7 @@ +<?xml version="1.0"?> +<Program> + <Function id="foo"> + <Parameter id="bar" /> + <Scope></Scope> + </Function> +</Program> diff --git a/c_compiler/test/out/03.stderr.txt b/c_compiler/test/out/03.stderr.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/c_compiler/test/out/03.stderr.txt diff --git a/c_compiler/test/out/03.stdout.xml b/c_compiler/test/out/03.stdout.xml new file mode 100644 index 0000000..6ca0ab2 --- /dev/null +++ b/c_compiler/test/out/03.stdout.xml @@ -0,0 +1,8 @@ +<?xml version="1.0"?> +<Program> +<Function id="foo"> +<Parameter id="bar" /> +<Scope> +</Scope> +</Function> +</Program> diff --git a/c_compiler/test/out/04.diff.txt b/c_compiler/test/out/04.diff.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/c_compiler/test/out/04.diff.txt diff --git a/c_compiler/test/out/04.pretty.xml b/c_compiler/test/out/04.pretty.xml new file mode 100644 index 0000000..caae53b --- /dev/null +++ b/c_compiler/test/out/04.pretty.xml @@ -0,0 +1,12 @@ +<?xml version="1.0"?> +<Program> + <Function id="foo"> + <Parameter id="bar1" /> + <Parameter id="bar2" /> + <Scope> + <Variable id="x" /> + <Variable id="y" /> + <Variable id="z" /> + </Scope> + </Function> +</Program> diff --git a/c_compiler/test/out/04.stderr.txt b/c_compiler/test/out/04.stderr.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/c_compiler/test/out/04.stderr.txt diff --git a/c_compiler/test/out/04.stdout.xml b/c_compiler/test/out/04.stdout.xml new file mode 100644 index 0000000..9257eac --- /dev/null +++ b/c_compiler/test/out/04.stdout.xml @@ -0,0 +1,12 @@ +<?xml version="1.0"?> +<Program> +<Function id="foo"> +<Parameter id="bar1" /> +<Parameter id="bar2" /> +<Scope> +<Variable id="x" /> +<Variable id="y" /> +<Variable id="z" /> +</Scope> +</Function> +</Program> diff --git a/c_compiler/test/out/05.diff.txt b/c_compiler/test/out/05.diff.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/c_compiler/test/out/05.diff.txt diff --git a/c_compiler/test/out/05.pretty.xml b/c_compiler/test/out/05.pretty.xml new file mode 100644 index 0000000..944d950 --- /dev/null +++ b/c_compiler/test/out/05.pretty.xml @@ -0,0 +1,10 @@ +<?xml version="1.0"?> +<Program> + <Function id="foo"> + <Parameter id="x" /> + <Parameter id="y" /> + <Scope> + <Scope></Scope> + </Scope> + </Function> +</Program> diff --git a/c_compiler/test/out/05.stderr.txt b/c_compiler/test/out/05.stderr.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/c_compiler/test/out/05.stderr.txt diff --git a/c_compiler/test/out/05.stdout.xml b/c_compiler/test/out/05.stdout.xml new file mode 100644 index 0000000..7381e51 --- /dev/null +++ b/c_compiler/test/out/05.stdout.xml @@ -0,0 +1,11 @@ +<?xml version="1.0"?> +<Program> +<Function id="foo"> +<Parameter id="x" /> +<Parameter id="y" /> +<Scope> +<Scope> +</Scope> +</Scope> +</Function> +</Program> diff --git a/c_compiler/test/out/06.diff.txt b/c_compiler/test/out/06.diff.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/c_compiler/test/out/06.diff.txt diff --git a/c_compiler/test/out/06.pretty.xml b/c_compiler/test/out/06.pretty.xml new file mode 100644 index 0000000..6422001 --- /dev/null +++ b/c_compiler/test/out/06.pretty.xml @@ -0,0 +1,14 @@ +<?xml version="1.0"?> +<Program> + <Function id="f"> + <Parameter id="a" /> + <Parameter id="b" /> + <Parameter id="c" /> + <Scope> + <Variable id="d" /> + <Scope> + <Variable id="e" /> + </Scope> + </Scope> + </Function> +</Program> diff --git a/c_compiler/test/out/06.stderr.txt b/c_compiler/test/out/06.stderr.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/c_compiler/test/out/06.stderr.txt diff --git a/c_compiler/test/out/06.stdout.xml b/c_compiler/test/out/06.stdout.xml new file mode 100644 index 0000000..fbcbebd --- /dev/null +++ b/c_compiler/test/out/06.stdout.xml @@ -0,0 +1,14 @@ +<?xml version="1.0"?> +<Program> +<Function id="f"> +<Parameter id="a" /> +<Parameter id="b" /> +<Parameter id="c" /> +<Scope> +<Variable id="d" /> +<Scope> +<Variable id="e" /> +</Scope> +</Scope> +</Function> +</Program> diff --git a/c_compiler/test/out/07.diff.txt b/c_compiler/test/out/07.diff.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/c_compiler/test/out/07.diff.txt diff --git a/c_compiler/test/out/07.pretty.xml b/c_compiler/test/out/07.pretty.xml new file mode 100644 index 0000000..11c3b77 --- /dev/null +++ b/c_compiler/test/out/07.pretty.xml @@ -0,0 +1,11 @@ +<?xml version="1.0"?> +<Program> + <Function id="foo"> + <Parameter id="a" /> + <Scope> + <Scope> + <Variable id="z" /> + </Scope> + </Scope> + </Function> +</Program> diff --git a/c_compiler/test/out/07.stderr.txt b/c_compiler/test/out/07.stderr.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/c_compiler/test/out/07.stderr.txt diff --git a/c_compiler/test/out/07.stdout.xml b/c_compiler/test/out/07.stdout.xml new file mode 100644 index 0000000..ff0efb2 --- /dev/null +++ b/c_compiler/test/out/07.stdout.xml @@ -0,0 +1,11 @@ +<?xml version="1.0"?> +<Program> +<Function id="foo"> +<Parameter id="a" /> +<Scope> +<Scope> +<Variable id="z" /> +</Scope> +</Scope> +</Function> +</Program> diff --git a/c_compiler/test/out/08.diff.txt b/c_compiler/test/out/08.diff.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/c_compiler/test/out/08.diff.txt diff --git a/c_compiler/test/out/08.pretty.xml b/c_compiler/test/out/08.pretty.xml new file mode 100644 index 0000000..6cf0f8e --- /dev/null +++ b/c_compiler/test/out/08.pretty.xml @@ -0,0 +1,16 @@ +<?xml version="1.0"?> +<Program> + <Function id="func"> + <Parameter id="a" /> + <Parameter id="b" /> + <Scope> + <Variable id="c" /> + <Scope> + <Variable id="d" /> + </Scope> + <Scope> + <Variable id="e" /> + </Scope> + </Scope> + </Function> +</Program> diff --git a/c_compiler/test/out/08.stderr.txt b/c_compiler/test/out/08.stderr.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/c_compiler/test/out/08.stderr.txt diff --git a/c_compiler/test/out/08.stdout.xml b/c_compiler/test/out/08.stdout.xml new file mode 100644 index 0000000..7929e75 --- /dev/null +++ b/c_compiler/test/out/08.stdout.xml @@ -0,0 +1,16 @@ +<?xml version="1.0"?> +<Program> +<Function id="func"> +<Parameter id="a" /> +<Parameter id="b" /> +<Scope> +<Variable id="c" /> +<Scope> +<Variable id="d" /> +</Scope> +<Scope> +<Variable id="e" /> +</Scope> +</Scope> +</Function> +</Program> diff --git a/c_compiler/test/out/09.diff.txt b/c_compiler/test/out/09.diff.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/c_compiler/test/out/09.diff.txt diff --git a/c_compiler/test/out/09.pretty.xml b/c_compiler/test/out/09.pretty.xml new file mode 100644 index 0000000..6c137df --- /dev/null +++ b/c_compiler/test/out/09.pretty.xml @@ -0,0 +1,20 @@ +<?xml version="1.0"?> +<Program> + <Function id="x"> + <Scope></Scope> + </Function> + <Variable id="g" /> + <Function id="zz"> + <Parameter id="a" /> + <Parameter id="b" /> + <Parameter id="c" /> + <Scope> + <Scope> + <Variable id="a" /> + </Scope> + <Scope> + <Variable id="fsdfsdfs" /> + </Scope> + </Scope> + </Function> +</Program> diff --git a/c_compiler/test/out/09.stderr.txt b/c_compiler/test/out/09.stderr.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/c_compiler/test/out/09.stderr.txt diff --git a/c_compiler/test/out/09.stdout.xml b/c_compiler/test/out/09.stdout.xml new file mode 100644 index 0000000..7a7a770 --- /dev/null +++ b/c_compiler/test/out/09.stdout.xml @@ -0,0 +1,21 @@ +<?xml version="1.0"?> +<Program> +<Function id="x"> +<Scope> +</Scope> +</Function> +<Variable id="g" /> +<Function id="zz"> +<Parameter id="a" /> +<Parameter id="b" /> +<Parameter id="c" /> +<Scope> +<Scope> +<Variable id="a" /> +</Scope> +<Scope> +<Variable id="fsdfsdfs" /> +</Scope> +</Scope> +</Function> +</Program> diff --git a/c_compiler/test/out/10.diff.txt b/c_compiler/test/out/10.diff.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/c_compiler/test/out/10.diff.txt diff --git a/c_compiler/test/out/10.pretty.xml b/c_compiler/test/out/10.pretty.xml new file mode 100644 index 0000000..89a6292 --- /dev/null +++ b/c_compiler/test/out/10.pretty.xml @@ -0,0 +1,19 @@ +<?xml version="1.0"?> +<Program> + <Function id="f"> + <Scope></Scope> + </Function> + <Variable id="g" /> + <Function id="x"> + <Parameter id="y" /> + <Scope> + <Variable id="z" /> + <Scope> + <Variable id="r" /> + </Scope> + <Scope> + <Variable id="f" /> + </Scope> + </Scope> + </Function> +</Program> diff --git a/c_compiler/test/out/10.stderr.txt b/c_compiler/test/out/10.stderr.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/c_compiler/test/out/10.stderr.txt diff --git a/c_compiler/test/out/10.stdout.xml b/c_compiler/test/out/10.stdout.xml new file mode 100644 index 0000000..b07997e --- /dev/null +++ b/c_compiler/test/out/10.stdout.xml @@ -0,0 +1,20 @@ +<?xml version="1.0"?> +<Program> +<Function id="f"> +<Scope> +</Scope> +</Function> +<Variable id="g" /> +<Function id="x"> +<Parameter id="y" /> +<Scope> +<Variable id="z" /> +<Scope> +<Variable id="r" /> +</Scope> +<Scope> +<Variable id="f" /> +</Scope> +</Scope> +</Function> +</Program> diff --git a/c_compiler/test/out/11.diff.txt b/c_compiler/test/out/11.diff.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/c_compiler/test/out/11.diff.txt diff --git a/c_compiler/test/out/11.pretty.xml b/c_compiler/test/out/11.pretty.xml new file mode 100644 index 0000000..b9779d7 --- /dev/null +++ b/c_compiler/test/out/11.pretty.xml @@ -0,0 +1,11 @@ +<?xml version="1.0"?> +<Program> + <Function id="f"> + <Scope> + <Variable id="x" /> + <Scope> + <Variable id="y" /> + </Scope> + </Scope> + </Function> +</Program> diff --git a/c_compiler/test/out/11.stderr.txt b/c_compiler/test/out/11.stderr.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/c_compiler/test/out/11.stderr.txt diff --git a/c_compiler/test/out/11.stdout.xml b/c_compiler/test/out/11.stdout.xml new file mode 100644 index 0000000..0822742 --- /dev/null +++ b/c_compiler/test/out/11.stdout.xml @@ -0,0 +1,11 @@ +<?xml version="1.0"?> +<Program> +<Function id="f"> +<Scope> +<Variable id="x" /> +<Scope> +<Variable id="y" /> +</Scope> +</Scope> +</Function> +</Program> diff --git a/c_compiler/test/out/12.diff.txt b/c_compiler/test/out/12.diff.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/c_compiler/test/out/12.diff.txt diff --git a/c_compiler/test/out/12.pretty.xml b/c_compiler/test/out/12.pretty.xml new file mode 100644 index 0000000..9f49265 --- /dev/null +++ b/c_compiler/test/out/12.pretty.xml @@ -0,0 +1,10 @@ +<?xml version="1.0"?> +<Program> + <Function id="f"> + <Parameter id="b" /> + <Parameter id="c" /> + <Scope> + <Variable id="a" /> + </Scope> + </Function> +</Program> diff --git a/c_compiler/test/out/12.stderr.txt b/c_compiler/test/out/12.stderr.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/c_compiler/test/out/12.stderr.txt diff --git a/c_compiler/test/out/12.stdout.xml b/c_compiler/test/out/12.stdout.xml new file mode 100644 index 0000000..471f225 --- /dev/null +++ b/c_compiler/test/out/12.stdout.xml @@ -0,0 +1,10 @@ +<?xml version="1.0"?> +<Program> +<Function id="f"> +<Parameter id="b" /> +<Parameter id="c" /> +<Scope> +<Variable id="a" /> +</Scope> +</Function> +</Program> diff --git a/c_compiler/test/out/13.diff.txt b/c_compiler/test/out/13.diff.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/c_compiler/test/out/13.diff.txt diff --git a/c_compiler/test/out/13.pretty.xml b/c_compiler/test/out/13.pretty.xml new file mode 100644 index 0000000..a604ecd --- /dev/null +++ b/c_compiler/test/out/13.pretty.xml @@ -0,0 +1,13 @@ +<?xml version="1.0"?> +<Program> + <Function id="func"> + <Parameter id="x" /> + <Parameter id="y" /> + <Scope> + <Variable id="i" /> + <Scope> + <Variable id="z" /> + </Scope> + </Scope> + </Function> +</Program> diff --git a/c_compiler/test/out/13.stderr.txt b/c_compiler/test/out/13.stderr.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/c_compiler/test/out/13.stderr.txt diff --git a/c_compiler/test/out/13.stdout.xml b/c_compiler/test/out/13.stdout.xml new file mode 100644 index 0000000..511d93b --- /dev/null +++ b/c_compiler/test/out/13.stdout.xml @@ -0,0 +1,13 @@ +<?xml version="1.0"?> +<Program> +<Function id="func"> +<Parameter id="x" /> +<Parameter id="y" /> +<Scope> +<Variable id="i" /> +<Scope> +<Variable id="z" /> +</Scope> +</Scope> +</Function> +</Program> diff --git a/c_compiler/test/out/14.diff.txt b/c_compiler/test/out/14.diff.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/c_compiler/test/out/14.diff.txt diff --git a/c_compiler/test/out/14.pretty.xml b/c_compiler/test/out/14.pretty.xml new file mode 100644 index 0000000..866d44e --- /dev/null +++ b/c_compiler/test/out/14.pretty.xml @@ -0,0 +1,13 @@ +<?xml version="1.0"?> +<Program> + <Function id="function_1"> + <Parameter id="a" /> + <Parameter id="b" /> + <Scope> + <Variable id="x" /> + <Scope> + <Variable id="c" /> + </Scope> + </Scope> + </Function> +</Program> diff --git a/c_compiler/test/out/14.stderr.txt b/c_compiler/test/out/14.stderr.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/c_compiler/test/out/14.stderr.txt diff --git a/c_compiler/test/out/14.stdout.xml b/c_compiler/test/out/14.stdout.xml new file mode 100644 index 0000000..1b412d3 --- /dev/null +++ b/c_compiler/test/out/14.stdout.xml @@ -0,0 +1,13 @@ +<?xml version="1.0"?> +<Program> +<Function id="function_1"> +<Parameter id="a" /> +<Parameter id="b" /> +<Scope> +<Variable id="x" /> +<Scope> +<Variable id="c" /> +</Scope> +</Scope> +</Function> +</Program> diff --git a/c_compiler/test/out/15.diff.txt b/c_compiler/test/out/15.diff.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/c_compiler/test/out/15.diff.txt diff --git a/c_compiler/test/out/15.pretty.xml b/c_compiler/test/out/15.pretty.xml new file mode 100644 index 0000000..b06dde0 --- /dev/null +++ b/c_compiler/test/out/15.pretty.xml @@ -0,0 +1,32 @@ +<?xml version="1.0"?> +<Program> + <Function id="add"> + <Parameter id="a" /> + <Parameter id="b" /> + <Scope> + <Variable id="c" /> + </Scope> + </Function> + <Function id="sub"> + <Parameter id="a" /> + <Parameter id="b" /> + <Scope> + <Variable id="c" /> + </Scope> + </Function> + <Function id="mult_by_5"> + <Parameter id="a" /> + <Scope> + <Variable id="b" /> + </Scope> + </Function> + <Function id="add_5"> + <Parameter id="a" /> + <Scope> + <Variable id="i" /> + <Scope> + <Variable id="b" /> + </Scope> + </Scope> + </Function> +</Program> diff --git a/c_compiler/test/out/15.stderr.txt b/c_compiler/test/out/15.stderr.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/c_compiler/test/out/15.stderr.txt diff --git a/c_compiler/test/out/15.stdout.xml b/c_compiler/test/out/15.stdout.xml new file mode 100644 index 0000000..d4c29b2 --- /dev/null +++ b/c_compiler/test/out/15.stdout.xml @@ -0,0 +1,32 @@ +<?xml version="1.0"?> +<Program> +<Function id="add"> +<Parameter id="a" /> +<Parameter id="b" /> +<Scope> +<Variable id="c" /> +</Scope> +</Function> +<Function id="sub"> +<Parameter id="a" /> +<Parameter id="b" /> +<Scope> +<Variable id="c" /> +</Scope> +</Function> +<Function id="mult_by_5"> +<Parameter id="a" /> +<Scope> +<Variable id="b" /> +</Scope> +</Function> +<Function id="add_5"> +<Parameter id="a" /> +<Scope> +<Variable id="i" /> +<Scope> +<Variable id="b" /> +</Scope> +</Scope> +</Function> +</Program> diff --git a/c_compiler/test/ref/01.stdout.xml b/c_compiler/test/ref/01.stdout.xml new file mode 100644 index 0000000..e0545e4 --- /dev/null +++ b/c_compiler/test/ref/01.stdout.xml @@ -0,0 +1,9 @@ +<?xml version="1.0"?> +<Program> + <Variable id="a" /> + <Variable id="b" /> + <Variable id="c" /> + <Variable id="d" /> + <Variable id="e" /> + <Variable id="f" /> +</Program> diff --git a/c_compiler/test/ref/02.stdout.xml b/c_compiler/test/ref/02.stdout.xml new file mode 100644 index 0000000..6caf2fc --- /dev/null +++ b/c_compiler/test/ref/02.stdout.xml @@ -0,0 +1,7 @@ +<?xml version="1.0"?> +<Program> + <Function id="f"> + <Scope> + </Scope> + </Function> +</Program> diff --git a/c_compiler/test/ref/03.stdout.xml b/c_compiler/test/ref/03.stdout.xml new file mode 100644 index 0000000..2c29a50 --- /dev/null +++ b/c_compiler/test/ref/03.stdout.xml @@ -0,0 +1,8 @@ +<?xml version="1.0"?> +<Program> + <Function id="foo"> + <Parameter id="bar" /> + <Scope> + </Scope> + </Function> +</Program> diff --git a/c_compiler/test/ref/04.stdout.xml b/c_compiler/test/ref/04.stdout.xml new file mode 100644 index 0000000..caae53b --- /dev/null +++ b/c_compiler/test/ref/04.stdout.xml @@ -0,0 +1,12 @@ +<?xml version="1.0"?> +<Program> + <Function id="foo"> + <Parameter id="bar1" /> + <Parameter id="bar2" /> + <Scope> + <Variable id="x" /> + <Variable id="y" /> + <Variable id="z" /> + </Scope> + </Function> +</Program> diff --git a/c_compiler/test/ref/05.stdout.xml b/c_compiler/test/ref/05.stdout.xml new file mode 100644 index 0000000..f4b306f --- /dev/null +++ b/c_compiler/test/ref/05.stdout.xml @@ -0,0 +1,11 @@ +<?xml version="1.0"?> +<Program> + <Function id="foo"> + <Parameter id="x" /> + <Parameter id="y" /> + <Scope> + <Scope> + </Scope> + </Scope> + </Function> +</Program> diff --git a/c_compiler/test/ref/06.stdout.xml b/c_compiler/test/ref/06.stdout.xml new file mode 100644 index 0000000..3526139 --- /dev/null +++ b/c_compiler/test/ref/06.stdout.xml @@ -0,0 +1,14 @@ +<?xml version="1.0"?> +<Program> + <Function id="f"> + <Parameter id="a" /> + <Parameter id="b" /> + <Parameter id="c" /> + <Scope> + <Variable id="d" /> + <Scope> + <Variable id="e" /> + </Scope> + </Scope> + </Function> +</Program> diff --git a/c_compiler/test/ref/07.stdout.xml b/c_compiler/test/ref/07.stdout.xml new file mode 100644 index 0000000..17c7c1b --- /dev/null +++ b/c_compiler/test/ref/07.stdout.xml @@ -0,0 +1,11 @@ +<?xml version="1.0"?> +<Program> + <Function id="foo"> + <Parameter id="a" /> + <Scope> + <Scope> + <Variable id="z" /> + </Scope> + </Scope> + </Function> +</Program> diff --git a/c_compiler/test/ref/08.stdout.xml b/c_compiler/test/ref/08.stdout.xml new file mode 100644 index 0000000..0838fe5 --- /dev/null +++ b/c_compiler/test/ref/08.stdout.xml @@ -0,0 +1,16 @@ +<?xml version="1.0"?> +<Program> + <Function id="func"> + <Parameter id="a" /> + <Parameter id="b" /> + <Scope> + <Variable id="c" /> + <Scope> + <Variable id="d" /> + </Scope> + <Scope> + <Variable id="e" /> + </Scope> + </Scope> + </Function> +</Program> diff --git a/c_compiler/test/ref/09.stdout.xml b/c_compiler/test/ref/09.stdout.xml new file mode 100644 index 0000000..646cd98 --- /dev/null +++ b/c_compiler/test/ref/09.stdout.xml @@ -0,0 +1,21 @@ +<?xml version="1.0"?> +<Program> + <Function id="x"> + <Scope> + </Scope> + </Function> + <Variable id="g" /> + <Function id="zz"> + <Parameter id="a" /> + <Parameter id="b" /> + <Parameter id="c" /> + <Scope> + <Scope> + <Variable id="a" /> + </Scope> + <Scope> + <Variable id="fsdfsdfs" /> + </Scope> + </Scope> + </Function> +</Program> diff --git a/c_compiler/test/ref/10.stdout.xml b/c_compiler/test/ref/10.stdout.xml new file mode 100644 index 0000000..21cadeb --- /dev/null +++ b/c_compiler/test/ref/10.stdout.xml @@ -0,0 +1,20 @@ +<?xml version="1.0"?> +<Program> + <Function id="f"> + <Scope> + </Scope> + </Function> + <Variable id="g" /> + <Function id="x"> + <Parameter id="y" /> + <Scope> + <Variable id="z" /> + <Scope> + <Variable id="r" /> + </Scope> + <Scope> + <Variable id="f" /> + </Scope> + </Scope> + </Function> +</Program> diff --git a/c_compiler/test/ref/11.stdout.xml b/c_compiler/test/ref/11.stdout.xml new file mode 100644 index 0000000..ad96d6c --- /dev/null +++ b/c_compiler/test/ref/11.stdout.xml @@ -0,0 +1,11 @@ +<?xml version="1.0"?> +<Program> + <Function id="f"> + <Scope> + <Variable id="x" /> + <Scope> + <Variable id="y" /> + </Scope> + </Scope> + </Function> +</Program> diff --git a/c_compiler/test/ref/12.stdout.xml b/c_compiler/test/ref/12.stdout.xml new file mode 100644 index 0000000..9f49265 --- /dev/null +++ b/c_compiler/test/ref/12.stdout.xml @@ -0,0 +1,10 @@ +<?xml version="1.0"?> +<Program> + <Function id="f"> + <Parameter id="b" /> + <Parameter id="c" /> + <Scope> + <Variable id="a" /> + </Scope> + </Function> +</Program> diff --git a/c_compiler/test/ref/13.stdout.xml b/c_compiler/test/ref/13.stdout.xml new file mode 100644 index 0000000..f0385cb --- /dev/null +++ b/c_compiler/test/ref/13.stdout.xml @@ -0,0 +1,13 @@ +<?xml version="1.0"?> +<Program> + <Function id="func"> + <Parameter id="x" /> + <Parameter id="y" /> + <Scope> + <Variable id="i" /> + <Scope> + <Variable id="z" /> + </Scope> + </Scope> + </Function> +</Program> diff --git a/c_compiler/test/ref/14.stdout.xml b/c_compiler/test/ref/14.stdout.xml new file mode 100644 index 0000000..63aec85 --- /dev/null +++ b/c_compiler/test/ref/14.stdout.xml @@ -0,0 +1,13 @@ +<?xml version="1.0"?> +<Program> + <Function id="function_1"> + <Parameter id="a" /> + <Parameter id="b" /> + <Scope> + <Variable id="x" /> + <Scope> + <Variable id="c" /> + </Scope> + </Scope> + </Function> +</Program> diff --git a/c_compiler/test/ref/15.stdout.xml b/c_compiler/test/ref/15.stdout.xml new file mode 100644 index 0000000..029ccb8 --- /dev/null +++ b/c_compiler/test/ref/15.stdout.xml @@ -0,0 +1,32 @@ +<?xml version="1.0"?> +<Program> + <Function id="add"> + <Parameter id="a" /> + <Parameter id="b" /> + <Scope> + <Variable id="c" /> + </Scope> + </Function> + <Function id="sub"> + <Parameter id="a" /> + <Parameter id="b" /> + <Scope> + <Variable id="c" /> + </Scope> + </Function> + <Function id="mult_by_5"> + <Parameter id="a" /> + <Scope> + <Variable id="b" /> + </Scope> + </Function> + <Function id="add_5"> + <Parameter id="a" /> + <Scope> + <Variable id="i" /> + <Scope> + <Variable id="b" /> + </Scope> + </Scope> + </Function> +</Program> |