2019-05-11 21:19:15 -07:00
|
|
|
%{
|
|
|
|
|
|
|
|
#include <string>
|
2019-05-11 22:34:26 -07:00
|
|
|
#include <iostream>
|
|
|
|
#include "parser.hpp"
|
2019-05-11 21:19:15 -07:00
|
|
|
|
|
|
|
%}
|
|
|
|
|
|
|
|
%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
|
2019-05-11 22:34:26 -07:00
|
|
|
%token FLOAT
|
|
|
|
%token INTEGER
|
2019-05-11 21:19:15 -07:00
|
|
|
%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
|
|
|
|
|
2019-05-11 22:34:26 -07:00
|
|
|
%define api.value.type { const char* }
|
2019-05-11 21:19:15 -07:00
|
|
|
%define api.pure full
|
|
|
|
%define api.push-pull push
|
2019-05-11 22:34:26 -07:00
|
|
|
%start program
|
|
|
|
|
|
|
|
%{
|
|
|
|
|
|
|
|
void yyerror(const char* s) {
|
|
|
|
std::cout << s << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
%}
|
2019-05-11 21:19:15 -07:00
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
program
|
2019-05-11 22:34:26 -07:00
|
|
|
: program stmt
|
|
|
|
| stmt
|
2019-05-11 21:19:15 -07:00
|
|
|
;
|
|
|
|
|
2019-05-11 22:34:26 -07:00
|
|
|
stmt
|
|
|
|
: expr NEWLINE;
|
|
|
|
|
|
|
|
expr
|
|
|
|
: assign
|
|
|
|
| INTEGER
|
2019-05-11 21:19:15 -07:00
|
|
|
;
|
|
|
|
|
2019-05-11 22:34:26 -07:00
|
|
|
assign
|
|
|
|
: IDENTIFIER ASSIGN expr
|
2019-05-11 21:19:15 -07:00
|
|
|
;
|
|
|
|
|
|
|
|
%%
|