Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %{
- #include <stdio.h>
- #include <string.h>
- void yyerror(const char *str) {
- fprintf(stderr,"ошибка: %s\n",str);
- fflush(stdout);
- }
- int yywrap() {
- return 1;
- }
- int indent_level;
- void indent() {
- fprintf(stdout, "IL:%d\n", indent_level);
- int i;
- for (i = 0; i < indent_level*4; i++) {
- fprintf(stdout, " ");
- }
- }
- int main() {
- indent_level = 0;
- yyparse();
- }
- %}
- %token ASSIGMENT EOL OBRACKET CBRACKET
- %union {
- double _double;
- int _int;
- char * _string;
- int _block;
- }
- %token <_double> FLOAT
- %token <_string> IDENT
- %token <_string> STRING
- %token <_int> INTEGER
- %token <_block> block
- %%
- statements
- :
- | statements statement
- ;
- oblock
- :
- OBRACKET {
- fprintf(stdout, "block:open\n");
- fflush(stdout);
- $<_block>$ = 1;
- }
- ;
- cblock
- :
- CBRACKET {
- fprintf(stdout, "block:close\n");
- fflush(stdout);
- $<_block>$ = 0;
- }
- ;
- BLOCK
- :
- oblock statements cblock
- ;
- value
- :
- STRING {
- fprintf(stdout, "value:%s\n", $1);
- fflush(stdout);
- $<_string>$ = $1;
- }
- |
- INTEGER {
- fprintf(stdout, "value:%d\n", $1);
- fflush(stdout);
- $<_int>$ = $1;
- }
- |
- FLOAT {
- fprintf(stdout, "value:%lf\n", $1);
- fflush(stdout);
- $<_double>$ = $1;
- }
- |
- BLOCK {
- fprintf(stdout, "value:block\n");
- fflush(stdout);
- }
- ;
- statement
- :
- IDENT ASSIGMENT value EOL {
- fprintf(stdout, "ident:%s\n", $1);
- fflush(stdout);
- }
- |
- EOL {
- ;
- }
- ;
- %%
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement