printing ReturnStatementNode nodes
git-svn-id: svn://anubis/jtlc/trunk@25 f5bc74b8-7b62-4e90-9214-7121d538519f
This commit is contained in:
parent
922c1bc4b4
commit
b23442a2f4
@ -6,6 +6,8 @@ using namespace std;
|
|||||||
Compiler::Compiler(FILE * output_file)
|
Compiler::Compiler(FILE * output_file)
|
||||||
{
|
{
|
||||||
m_outfile = output_file;
|
m_outfile = output_file;
|
||||||
|
write("#include <stdint.h>\n");
|
||||||
|
write("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Compiler::write(const string & str)
|
void Compiler::write(const string & str)
|
||||||
|
13
nodes/DoubleNode.cc
Normal file
13
nodes/DoubleNode.cc
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include "Node.h"
|
||||||
|
#include "parser/parser.h"
|
||||||
|
#include "main/Compiler.h"
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void DoubleNode::process(refptr<Compiler> compiler)
|
||||||
|
{
|
||||||
|
char buff[50];
|
||||||
|
sprintf(buff, "%lf", m_double);
|
||||||
|
compiler->write(buff);
|
||||||
|
}
|
13
nodes/IntegerNode.cc
Normal file
13
nodes/IntegerNode.cc
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include "Node.h"
|
||||||
|
#include "parser/parser.h"
|
||||||
|
#include "main/Compiler.h"
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void IntegerNode::process(refptr<Compiler> compiler)
|
||||||
|
{
|
||||||
|
char buff[30];
|
||||||
|
sprintf(buff, "%llu", (long long unsigned int) m_integer);
|
||||||
|
compiler->write(buff);
|
||||||
|
}
|
@ -49,6 +49,11 @@ class DoubleNode : public Node
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DoubleNode(double val) { m_double = val; }
|
DoubleNode(double val) { m_double = val; }
|
||||||
|
void process(refptr<Compiler> compiler);
|
||||||
|
};
|
||||||
|
|
||||||
|
class ExpressionNode : public Node
|
||||||
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
class FunctionNode : public Node
|
class FunctionNode : public Node
|
||||||
@ -67,6 +72,7 @@ class IntegerNode : public Node
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
IntegerNode(uint64_t integer) { m_integer = integer; }
|
IntegerNode(uint64_t integer) { m_integer = integer; }
|
||||||
|
void process(refptr<Compiler> compiler);
|
||||||
};
|
};
|
||||||
|
|
||||||
class ItemsNode : public Node
|
class ItemsNode : public Node
|
||||||
@ -90,12 +96,15 @@ class ProgramNode : public Node
|
|||||||
|
|
||||||
class ReturnStatementNode : public Node
|
class ReturnStatementNode : public Node
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
void process(refptr<Compiler> compiler);
|
||||||
};
|
};
|
||||||
|
|
||||||
class StringNode : public Node
|
class StringNode : public Node
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
StringNode(const std::string & str) { m_string = str; }
|
StringNode(const std::string & str) { m_string = str; }
|
||||||
|
void process(refptr<Compiler> compiler);
|
||||||
};
|
};
|
||||||
|
|
||||||
class StructTypeNode : public Node
|
class StructTypeNode : public Node
|
||||||
|
13
nodes/ReturnStatementNode.cc
Normal file
13
nodes/ReturnStatementNode.cc
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include "Node.h"
|
||||||
|
#include "parser/parser.h"
|
||||||
|
#include "main/Compiler.h"
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void ReturnStatementNode::process(refptr<Compiler> compiler)
|
||||||
|
{
|
||||||
|
compiler->write("return (");
|
||||||
|
m_children[0]->process(compiler);
|
||||||
|
compiler->write(");\n");
|
||||||
|
}
|
11
nodes/StringNode.cc
Normal file
11
nodes/StringNode.cc
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include "Node.h"
|
||||||
|
#include "parser/parser.h"
|
||||||
|
#include "main/Compiler.h"
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void StringNode::process(refptr<Compiler> compiler)
|
||||||
|
{
|
||||||
|
compiler->write(m_string);
|
||||||
|
}
|
@ -273,7 +273,12 @@ return_statement: RETURN expression SEMICOLON {
|
|||||||
;
|
;
|
||||||
|
|
||||||
expression: assign_expr {
|
expression: assign_expr {
|
||||||
$$ = $1;
|
$$ = new ExpressionNode();
|
||||||
|
$$->addChild($1);
|
||||||
|
}
|
||||||
|
| literal {
|
||||||
|
$$ = new ExpressionNode();
|
||||||
|
$$->addChild($1);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -284,6 +289,17 @@ assign_expr: lvalue ASSIGN expression {
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
literal: INT_LITERAL {
|
||||||
|
$$ = $1;
|
||||||
|
}
|
||||||
|
| REAL_LITERAL {
|
||||||
|
$$ = $1;
|
||||||
|
}
|
||||||
|
| STRING_LITERAL {
|
||||||
|
$$ = $1;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
lvalue: IDENTIFIER {
|
lvalue: IDENTIFIER {
|
||||||
$$ = new LValueNode();
|
$$ = new LValueNode();
|
||||||
$$->addChild($1);
|
$$->addChild($1);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
main() : int
|
main() : int
|
||||||
{
|
{
|
||||||
c("return 42;");
|
return 42;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user