From b7ed17742e576b378e7ce0f872fb7987f9c43331 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Sat, 11 May 2019 21:19:15 -0700 Subject: [PATCH] Add initial parser --- Makefile | 3 +++ parser.y | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 parser.y diff --git a/Makefile b/Makefile index 2bbf4a9..6403429 100644 --- a/Makefile +++ b/Makefile @@ -6,5 +6,8 @@ scan: main.cpp scanner.cpp scanner.cpp: scanner.l flex -o scanner.cpp scanner.l +parser.tab.cpp: parser.y + bison -d parser.y + clean: rm -f scan scanner.cpp diff --git a/parser.y b/parser.y new file mode 100644 index 0000000..4f7dbc0 --- /dev/null +++ b/parser.y @@ -0,0 +1,58 @@ +%{ + +#include + +%} + +%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 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 { std::string } +%define api.pure full +%define api.push-pull push + +%% + +program + : statements {} + ; + +statements + : statement statements {} + | statement {} + ; + +statement + : PLUS {} + ; + +%%