diff options
author | clifford <clifford@b57f626f-c46c-0410-a088-ec61d464b74c> | 2009-06-30 18:05:10 (GMT) |
---|---|---|
committer | clifford <clifford@b57f626f-c46c-0410-a088-ec61d464b74c> | 2009-06-30 18:05:10 (GMT) |
commit | 78244d328918b149b86d9b925010e934244d0137 (patch) | |
tree | 54228d6e3480fc309143a4ed3d9deb0d51994f56 /parser.y | |
parent | a70715ab8c31160f1be2a74d208681c2ad422bbb (diff) |
Clifford Wolf:
Improved value handling
Fixed math functions
Improved control statements
git-svn-id: http://svn.clifford.at/openscad/trunk@39 b57f626f-c46c-0410-a088-ec61d464b74c
Diffstat (limited to 'parser.y')
-rw-r--r-- | parser.y | 86 |
1 files changed, 38 insertions, 48 deletions
@@ -48,6 +48,7 @@ public: %union { char *text; double number; + class Value *value; class Expression *expr; class ModuleInstanciation *inst; class ArgContainer *arg; @@ -70,6 +71,8 @@ public: %left '.' %type <expr> expr +%type <value> vector_const +%type <expr> vector_expr %type <inst> module_instantciation %type <inst> module_instantciation_list @@ -171,17 +174,17 @@ expr: TOK_TRUE { $$ = new Expression(); $$->type = 'C'; - $$->const_value = Value(true); + $$->const_value = new Value(true); } | TOK_FALSE { $$ = new Expression(); $$->type = 'C'; - $$->const_value = Value(false); + $$->const_value = new Value(false); } | TOK_UNDEF { $$ = new Expression(); $$->type = 'C'; - $$->const_value = Value(); + $$->const_value = new Value(); } | TOK_ID { $$ = new Expression(); @@ -199,18 +202,18 @@ expr: TOK_STRING { $$ = new Expression(); $$->type = 'C'; - $$->const_value = Value(QString($1)); + $$->const_value = new Value(QString($1)); free($1); } | TOK_NUMBER { $$ = new Expression(); $$->type = 'C'; - $$->const_value = Value($1); + $$->const_value = new Value($1); } | '[' expr ':' expr ']' { Expression *e_one = new Expression(); e_one->type = 'C'; - e_one->const_value = Value(1.0); + e_one->const_value = new Value(1.0); $$ = new Expression(); $$->type = 'R'; $$->children.append($2); @@ -224,54 +227,19 @@ expr: $$->children.append($4); $$->children.append($6); } | - '[' TOK_NUMBER TOK_NUMBER TOK_NUMBER ']' { + '[' ']' { $$ = new Expression(); $$->type = 'C'; - $$->const_value = Value($2, $3, $4); + $$->const_value = new Value(); + $$->const_value->type = Value::VECTOR; } | - '[' TOK_NUMBER TOK_NUMBER TOK_NUMBER TOK_NUMBER ';' - TOK_NUMBER TOK_NUMBER TOK_NUMBER TOK_NUMBER ';' - TOK_NUMBER TOK_NUMBER TOK_NUMBER TOK_NUMBER ';' - TOK_NUMBER TOK_NUMBER TOK_NUMBER TOK_NUMBER ']' { + '[' vector_const ']' { $$ = new Expression(); $$->type = 'C'; - double m[16] = { - $2, $3, $4, $5, - $7, $8, $9, $10, - $12, $13, $14, $15, - $17, $18, $19, $20, - }; - $$->const_value = Value(m); - } | - '[' expr ',' expr ',' expr ']' { - $$ = new Expression(); - $$->type = 'V'; - $$->children.append($2); - $$->children.append($4); - $$->children.append($6); + $$->const_value = $2; } | - '[' expr ',' expr ',' expr ',' expr ';' - expr ',' expr ',' expr ',' expr ';' - expr ',' expr ',' expr ',' expr ';' - expr ',' expr ',' expr ',' expr ']' { - $$ = new Expression(); - $$->type = 'M'; - $$->children.append($2); - $$->children.append($4); - $$->children.append($6); - $$->children.append($8); - $$->children.append($10); - $$->children.append($12); - $$->children.append($14); - $$->children.append($16); - $$->children.append($18); - $$->children.append($20); - $$->children.append($22); - $$->children.append($24); - $$->children.append($26); - $$->children.append($28); - $$->children.append($30); - $$->children.append($32); + '[' vector_expr ']' { + $$ = $2; } | expr '*' expr { $$ = new Expression(); @@ -331,6 +299,28 @@ expr: delete $3; } ; +vector_const: + TOK_NUMBER { + $$ = new Value(); + $$->type = Value::VECTOR; + $$->vec.append(new Value($1)); + } | + vector_const TOK_NUMBER { + $$ = $1; + $$->vec.append(new Value($2)); + } ; + +vector_expr: + expr { + $$ = new Expression(); + $$->type = 'V'; + $$->children.append($1); + } | + vector_expr ',' expr { + $$ = $1; + $$->children.append($3); + } ; + arguments_decl: /* empty */ { $$ = new ArgsContainer(); |