76 lines
826 B
Plaintext
76 lines
826 B
Plaintext
%{
|
|
|
|
#include <string>
|
|
#include <iostream>
|
|
#include "parser.hpp"
|
|
|
|
%}
|
|
|
|
%token INDENT
|
|
%token DEDENT
|
|
%token NEWLINE
|
|
%token AND
|
|
%token BREAK
|
|
%token DEF
|
|
%token ELIF
|
|
%token ELSE
|
|
%token FOR
|
|
%token IF
|
|
%token NOT
|
|
%token OR
|
|
%token RETURN
|
|
%token WHILE
|
|
%token BOOLEAN
|
|
%token FLOAT
|
|
%token INTEGER
|
|
%token IDENTIFIER
|
|
%token ASSIGN
|
|
%token PLUS
|
|
%token MINUS
|
|
%token TIMES
|
|
%token DIVIDEDBY
|
|
%token EQ
|
|
%token NEQ
|
|
%token GT
|
|
%token GTE
|
|
%token LT
|
|
%token LTE
|
|
%token LPAREN
|
|
%token RPAREN
|
|
%token COMMA
|
|
%token COLON
|
|
|
|
%define api.value.type { const char* }
|
|
%define api.pure full
|
|
%define api.push-pull push
|
|
%start program
|
|
|
|
%{
|
|
|
|
void yyerror(const char* s) {
|
|
std::cout << s << std::endl;
|
|
}
|
|
|
|
%}
|
|
|
|
%%
|
|
|
|
program
|
|
: program stmt
|
|
| stmt
|
|
;
|
|
|
|
stmt
|
|
: expr NEWLINE;
|
|
|
|
expr
|
|
: assign
|
|
| INTEGER
|
|
;
|
|
|
|
assign
|
|
: IDENTIFIER ASSIGN expr
|
|
;
|
|
|
|
%%
|