many more nodes

git-svn-id: svn://anubis/jtlc/trunk@14 f5bc74b8-7b62-4e90-9214-7121d538519f
This commit is contained in:
josh 2010-01-13 21:02:33 +00:00
parent 55b80e8f09
commit 7b1893c1e5
2 changed files with 124 additions and 44 deletions

View File

@ -29,6 +29,10 @@ class Node
}; };
class ArrayTypeNode : public Node
{
};
class CStatementNode : public Node class CStatementNode : public Node
{ {
public: public:
@ -42,6 +46,10 @@ class DoubleNode : public Node
DoubleNode(double val) { m_double = val; } DoubleNode(double val) { m_double = val; }
}; };
class FunctionNode : public Node
{
};
class IdentifierNode : public Node class IdentifierNode : public Node
{ {
public: public:
@ -54,6 +62,16 @@ class IntegerNode : public Node
IntegerNode(uint64_t integer) { m_integer = integer; } IntegerNode(uint64_t integer) { m_integer = integer; }
}; };
class ItemsNode : public Node
{
};
class PrimitiveTypeNode : public Node
{
public:
PrimitiveTypeNode(uint64_t type) { m_integer = type; }
};
class ProgramNode : public Node class ProgramNode : public Node
{ {
}; };
@ -64,4 +82,12 @@ class StringNode : public Node
StringNode(const std::string & str) { m_string = str; } StringNode(const std::string & str) { m_string = str; }
}; };
class StructTypeNode : public Node
{
};
class VariableSpecNode : public Node
{
};
#endif #endif

View File

@ -97,26 +97,21 @@ program: program_items {
; ;
program_items: /* empty */ program_items: /* empty */
| program_item program_items | program_item program_items {
$$ = new ItemsNode();
$$->addChild($1);
$$->addChildren($2);
}
; ;
program_item: module_declaration program_item: function {
| import $$ = $1;
| variable_declaration }
| function | c_statement {
| c_statement $$ = $1;
}
; ;
module_declaration: MODULE module_name SEMICOLON
;
module_name: IDENTIFIER module_name_more
;
module_name_more: /* empty */
| DOT IDENTIFIER module_name_more
;
import: IMPORT import_name SEMICOLON import: IMPORT import_name SEMICOLON
; ;
@ -131,60 +126,119 @@ import_name_more_more: IDENTIFIER import_name_more
| STAR | STAR
; ;
function: IDENTIFIER LPAREN parameter_list RPAREN COLON type LCURLY function_items RCURLY function: IDENTIFIER LPAREN parameter_list RPAREN COLON type LCURLY function_items RCURLY {
$$ = new FunctionNode();
$$->addChild($3);
$$->addChild($6);
$$->addChildren($8);
}
; ;
function_items: /* empty */ function_items: /* empty */
| statement function_items | statement function_items {
$$ = new ItemsNode();
$$->addChild($1);
$$->addChildren($2);
}
; ;
parameter_list: /* empty */ parameter_list: /* empty */
| variable_spec parameter_list_more | variable_spec parameter_list_more {
$$ = new ItemsNode();
$$->addChild($1);
$$->addChildren($2);
}
; ;
parameter_list_more: /* empty */ parameter_list_more: /* empty */
| COMMA variable_spec parameter_list_more | COMMA variable_spec parameter_list_more {
$$ = new ItemsNode();
$$->addChild($2);
$$->addChildren($3);
}
; ;
primitive_type: BYTE primitive_type: BYTE {
| UBYTE $$ = new PrimitiveTypeNode(BYTE);
| CHAR }
| WCHAR | UBYTE {
| SHORT $$ = new PrimitiveTypeNode(UBYTE);
| USHORT }
| INT | CHAR {
| UINT $$ = new PrimitiveTypeNode(CHAR);
| LONG }
| ULONG | WCHAR {
$$ = new PrimitiveTypeNode(WCHAR);
}
| SHORT {
$$ = new PrimitiveTypeNode(SHORT);
}
| USHORT {
$$ = new PrimitiveTypeNode(USHORT);
}
| INT {
$$ = new PrimitiveTypeNode(INT);
}
| UINT {
$$ = new PrimitiveTypeNode(UINT);
}
| LONG {
$$ = new PrimitiveTypeNode(LONG);
}
| ULONG {
$$ = new PrimitiveTypeNode(ULONG);
}
; ;
struct_type: STRUCT LCURLY struct_items RCURLY struct_type: STRUCT LCURLY struct_items RCURLY {
$$ = new StructTypeNode();
$$->addChildren($3);
}
; ;
struct_items: /* empty */ struct_items: /* empty */
| struct_item struct_items | struct_item struct_items {
$$ = new ItemsNode();
$$->addChild($1);
$$->addChildren($2);
}
; ;
struct_item: variable_declaration struct_item: variable_declaration {
$$ = $1;
}
; ;
variable_declaration: variable_spec SEMICOLON; variable_declaration: variable_spec SEMICOLON {
$$ = $1;
}
; ;
variable_spec: IDENTIFIER COLON type variable_spec: IDENTIFIER COLON type {
$$ = new VariableSpecNode();
$$->addChild($1);
$$->addChild($3);
}
; ;
ptr_type: type STAR array_type: type LBRACKET RBRACKET {
; $$ = new ArrayTypeNode();
$$->addChild($1);
array_type: type LBRACKET RBRACKET }
; ;
type: primitive_type type: primitive_type {
| ptr_type $$ = $1;
| struct_type }
| array_type | struct_type {
| IDENTIFIER $$ = $1;
}
| array_type {
$$ = $1;
}
| IDENTIFIER {
$$ = $1;
}
; ;
statement: expression SEMICOLON statement: expression SEMICOLON