init
This commit is contained in:
66
def.yy
Normal file
66
def.yy
Normal file
@@ -0,0 +1,66 @@
|
||||
%{
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#define INFILE_ERROR 1
|
||||
#define OUTFILE_ERROR 2
|
||||
|
||||
extern int yylex(void);
|
||||
extern void yyerror(const char *s);
|
||||
extern int yylineno;
|
||||
extern FILE *yyin;
|
||||
%}
|
||||
|
||||
%union {
|
||||
char *text;
|
||||
int ival;
|
||||
}
|
||||
|
||||
%token <text> ID
|
||||
%token <ival> INT_LIT
|
||||
%token LET
|
||||
%token INT_TYPE
|
||||
%token SEMICOLON COLON
|
||||
|
||||
%left '+' '-'
|
||||
%left '*' '/'
|
||||
|
||||
%start program
|
||||
|
||||
%%
|
||||
|
||||
program
|
||||
: statement_list { printf("koniec\n"); }
|
||||
;
|
||||
|
||||
statement_list
|
||||
: statement
|
||||
| statement_list statement
|
||||
;
|
||||
|
||||
statement
|
||||
: variable_declaration { printf("Deklaracja zmiennej\n"); }
|
||||
| expression SEMICOLON { printf("instrukcja\n"); }
|
||||
;
|
||||
|
||||
variable_declaration
|
||||
: LET ID COLON INT_TYPE '=' expression SEMICOLON
|
||||
{ printf("Deklaracja zmiennej: %s\n", $2); }
|
||||
;
|
||||
|
||||
expression
|
||||
: expression '+' expression { printf("Wyrazenie z +\n"); }
|
||||
| expression '-' expression { printf("Wyrazenie z -\n"); }
|
||||
| expression '*' expression { printf("Wyrazenie z *\n"); }
|
||||
| expression '/' expression { printf("Wyrazenie z /\n"); }
|
||||
| '(' expression ')' { printf("Wyrazenie w nawiasach\n"); }
|
||||
| INT_LIT { printf("Literal calkowity: %d\n", $1); }
|
||||
| ID { printf("Identyfikator: %s\n", $1); }
|
||||
;
|
||||
|
||||
%%
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
yyparse();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user