more nodes
git-svn-id: svn://anubis/jtlc/trunk@15 f5bc74b8-7b62-4e90-9214-7121d538519f
This commit is contained in:
parent
7b1893c1e5
commit
9c26b9593c
@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
#include <stdio.h> /* tmpfile() */
|
#include <stdio.h> /* tmpfile() */
|
||||||
#include <stdlib.h> /* exit() */
|
#include <stdlib.h> /* exit() */
|
||||||
|
#include <unistd.h> /* unlink() */
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "util/refptr.h"
|
#include "util/refptr.h"
|
||||||
#include "parser/parser.h"
|
#include "parser/parser.h"
|
||||||
@ -42,8 +43,10 @@ int main(int argc, char * argv[])
|
|||||||
|
|
||||||
void compile(const char * filename)
|
void compile(const char * filename)
|
||||||
{
|
{
|
||||||
FILE * out = tmpfile();
|
string out_filename = string(filename) + ".c";
|
||||||
|
FILE * out = fopen(out_filename.c_str(), "w");
|
||||||
refptr<Node> tree = parse(filename);
|
refptr<Node> tree = parse(filename);
|
||||||
tree->process(out);
|
tree->process(out);
|
||||||
fclose(out);
|
fclose(out);
|
||||||
|
// unlink(out_filename.c_str());
|
||||||
}
|
}
|
||||||
|
12
nodes/Node.h
12
nodes/Node.h
@ -33,6 +33,10 @@ class ArrayTypeNode : public Node
|
|||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class AssignExprNode : public Node
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
class CStatementNode : public Node
|
class CStatementNode : public Node
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -66,6 +70,10 @@ class ItemsNode : public Node
|
|||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class LValueNode : public Node
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
class PrimitiveTypeNode : public Node
|
class PrimitiveTypeNode : public Node
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -76,6 +84,10 @@ class ProgramNode : public Node
|
|||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ReturnStatementNode : public Node
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
class StringNode : public Node
|
class StringNode : public Node
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -93,6 +93,7 @@ static YYSTYPE parse_result;
|
|||||||
program: program_items {
|
program: program_items {
|
||||||
$$ = new ProgramNode();
|
$$ = new ProgramNode();
|
||||||
$$->addChildren($1);
|
$$->addChildren($1);
|
||||||
|
parse_result = $$;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -241,24 +242,39 @@ type: primitive_type {
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
statement: expression SEMICOLON
|
statement: expression SEMICOLON {
|
||||||
| return_statement
|
$$ = $1;
|
||||||
|
}
|
||||||
|
| return_statement {
|
||||||
|
$$ = $1;
|
||||||
|
}
|
||||||
| c_statement {
|
| c_statement {
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
return_statement: RETURN expression SEMICOLON
|
return_statement: RETURN expression SEMICOLON {
|
||||||
|
$$ = new ReturnStatementNode();
|
||||||
|
$$->addChild($2);
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
expression: assign_expr
|
expression: assign_expr {
|
||||||
|
$$ = $1;
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
assign_expr: lvalue ASSIGN expression
|
assign_expr: lvalue ASSIGN expression {
|
||||||
| lvalue DASSIGN expression
|
$$ = new AssignExprNode();
|
||||||
|
$$->addChild($1);
|
||||||
|
$$->addChild($3);
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
lvalue: IDENTIFIER
|
lvalue: IDENTIFIER {
|
||||||
|
$$ = new LValueNode();
|
||||||
|
$$->addChild($1);
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
c_statement: C LPAREN STRING_LITERAL RPAREN SEMICOLON {
|
c_statement: C LPAREN STRING_LITERAL RPAREN SEMICOLON {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user