31
def.yy
31
def.yy
@@ -1,17 +1,14 @@
|
||||
%{
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <FlexLexer.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#define INFILE_ERROR 1
|
||||
#define OUTFILE_ERROR 2
|
||||
|
||||
extern yyFlexLexer lexer;
|
||||
|
||||
void yyerror(const char *s);
|
||||
int yylex();
|
||||
|
||||
extern int yylex(void);
|
||||
extern void yyerror(const char *s);
|
||||
extern int yylineno;
|
||||
extern FILE *yyin;
|
||||
%}
|
||||
|
||||
%union {
|
||||
@@ -48,7 +45,7 @@ statement
|
||||
|
||||
variable_declaration
|
||||
: LET ID COLON INT_TYPE '=' expression SEMICOLON
|
||||
{ printf("Deklaracja zmiennej: %s\n", $2); free($2); }
|
||||
{ printf("Deklaracja zmiennej: %s\n", $2); }
|
||||
;
|
||||
|
||||
expression
|
||||
@@ -58,21 +55,11 @@ expression
|
||||
| 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); free($1); }
|
||||
| ID { printf("Identyfikator: %s\n", $1); }
|
||||
;
|
||||
|
||||
%%
|
||||
|
||||
yyFlexLexer lexer;
|
||||
|
||||
int yylex() {
|
||||
return lexer.yylex();
|
||||
}
|
||||
|
||||
void yyerror(const char *s) {
|
||||
fprintf(stderr, "Blad: %s w linii %d\n", s, lexer.lineno());
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
yyparse();
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user