|
a/c99.y |
|
b/c99.y |
|
... |
|
... |
22 |
// get tail of a string |
22 |
// get tail of a string |
23 |
#define TAIL(str) (&str[strlen(str)-1]) |
23 |
#define TAIL(str) (&str[strlen(str)-1]) |
24 |
|
24 |
|
25 |
|
25 |
|
26 |
/* fifo to store expression strings */ |
26 |
/* fifo to store expression strings */ |
27 |
#define NULL 0 |
|
|
28 |
|
|
|
29 |
#define STMT_SIZE 128 |
27 |
#define STMT_SIZE 128 |
30 |
#define FIFO_SIZE 20 |
28 |
#define FIFO_SIZE 20 |
31 |
|
29 |
|
32 |
typedef enum |
30 |
typedef enum |
33 |
{ |
31 |
{ |
|
... |
|
... |
61 |
void fifo_tag(fifo_entry_t type); |
59 |
void fifo_tag(fifo_entry_t type); |
62 |
|
60 |
|
63 |
// map c datatype to iec (standard and userdefined) |
61 |
// map c datatype to iec (standard and userdefined) |
64 |
char *maptype(char *ctype); |
62 |
char *maptype(char *ctype); |
65 |
|
63 |
|
66 |
|
64 |
// lex/yacc functions |
|
|
65 |
extern int yylex (void); |
67 |
%} |
66 |
%} |
68 |
|
67 |
|
69 |
%% |
68 |
%% |
70 |
|
69 |
|
71 |
primary_expression |
70 |
primary_expression |
|
... |
|
... |
104 |
; |
103 |
; |
105 |
|
104 |
|
106 |
unary_expression |
105 |
unary_expression |
107 |
: postfix_expression |
106 |
: postfix_expression |
108 |
| INC_OP unary_expression |
107 |
| INC_OP unary_expression |
109 |
{ sprintf($<str>$, "%s %s",$<str>1, $<str>2); } |
108 |
{ sprintf($<str>$, "(%s:=%s+1)",$<str>2, $<str>2); } |
110 |
| DEC_OP unary_expression |
109 |
| DEC_OP unary_expression |
111 |
{ sprintf($<str>$, "%s %s",$<str>1, $<str>2); } |
110 |
{ sprintf($<str>$, "(%s:=%s-1)",$<str>2, $<str>2); } |
112 |
| unary_operator cast_expression |
111 |
| unary_operator cast_expression |
113 |
{ sprintf($<str>$, "%s^",$<str>2); } |
112 |
{ sprintf($<str>$, "%s^",$<str>2); } |
114 |
| SIZEOF unary_expression |
113 |
| SIZEOF unary_expression |
115 |
{ sprintf($<str>$, "%s %s",$<str>1, $<str>2); } |
114 |
{ sprintf($<str>$, "%s %s",$<str>1, $<str>2); } |
116 |
| SIZEOF '(' type_name ')' |
115 |
| SIZEOF '(' type_name ')' |
|
... |
|
... |
137 |
| multiplicative_expression '*' cast_expression |
136 |
| multiplicative_expression '*' cast_expression |
138 |
{ sprintf($<str>$, "%s * %s",$<str>1, $<str>3); } |
137 |
{ sprintf($<str>$, "%s * %s",$<str>1, $<str>3); } |
139 |
| multiplicative_expression '/' cast_expression |
138 |
| multiplicative_expression '/' cast_expression |
140 |
{ sprintf($<str>$, "%s / %s",$<str>1, $<str>3); } |
139 |
{ sprintf($<str>$, "%s / %s",$<str>1, $<str>3); } |
141 |
| multiplicative_expression '%' cast_expression |
140 |
| multiplicative_expression '%' cast_expression |
142 |
{ sprintf($<str>$, "%s % %s",$<str>1, $<str>3); } |
141 |
{ sprintf($<str>$, "%s %s",$<str>1, $<str>3); } |
143 |
; |
142 |
; |
144 |
|
143 |
|
145 |
additive_expression |
144 |
additive_expression |
146 |
: multiplicative_expression |
145 |
: multiplicative_expression |
147 |
| additive_expression '+' multiplicative_expression |
146 |
| additive_expression '+' multiplicative_expression |
|
... |
|
... |
586 |
: WHILE '(' expression ')' statement |
585 |
: WHILE '(' expression ')' statement |
587 |
{ sprintf($<str>$, "WHILE %s DO\n%s\nEND_WHILE\n",$<str>3, $<str>5); } |
586 |
{ sprintf($<str>$, "WHILE %s DO\n%s\nEND_WHILE\n",$<str>3, $<str>5); } |
588 |
| DO statement WHILE '(' expression ')' ';' |
587 |
| DO statement WHILE '(' expression ')' ';' |
589 |
| FOR '(' expression_statement expression_statement ')' statement |
588 |
| FOR '(' expression_statement expression_statement ')' statement |
590 |
| FOR '(' expression_statement expression_statement expression ')' statement |
589 |
| FOR '(' expression_statement expression_statement expression ')' statement |
|
|
590 |
{ sprintf($<str>$, "%s\nWHILE %s DO\n%s\n%s;\nEND_WHILE\n",$<str>3, $<str>4, $<str>7, $<str>5); } |
591 |
| FOR '(' declaration expression_statement ')' statement |
591 |
| FOR '(' declaration expression_statement ')' statement |
592 |
| FOR '(' declaration expression_statement expression ')' statement |
592 |
| FOR '(' declaration expression_statement expression ')' statement |
593 |
; |
593 |
; |
594 |
|
594 |
|
595 |
jump_statement |
595 |
jump_statement |
|
... |
|
... |
618 |
| declaration_specifiers declarator compound_statement |
618 |
| declaration_specifiers declarator compound_statement |
619 |
{ |
619 |
{ |
620 |
char *p; |
620 |
char *p; |
621 |
while( (p=fifo_pop(decl_all)) != NULL) |
621 |
while( (p=fifo_pop(decl_all)) != NULL) |
622 |
{ |
622 |
{ |
623 |
printf(p); |
623 |
printf("%s", p); |
624 |
printf("%s;\n", $<str>1); |
624 |
printf("%s;\n", $<str>1); |
625 |
} |
625 |
} |
626 |
printf($<str>3); |
626 |
printf("%s", $<str>3); |
627 |
strcpy($<str>$, ""); |
627 |
strcpy($<str>$, ""); |
628 |
} |
628 |
} |
629 |
; |
629 |
; |
630 |
|
630 |
|
631 |
declaration_list |
631 |
declaration_list |