diff --git a/DragonLisp.y b/DragonLisp.y index e5fd7f0..dd94a94 100644 --- a/DragonLisp.y +++ b/DragonLisp.y @@ -58,7 +58,9 @@ namespace DragonLisp { %token END 0 "EOF" %token NUMBER "number" -%type operator +%type basic_operator +%type arithmetic_operator +%type comparsion_operator %define parse.error verbose @@ -72,19 +74,37 @@ R | R S-Expr S-Expr - : LPAREN operator NUMBER NUMBER RPAREN { + : LPAREN basic_operator NUMBER NUMBER RPAREN { std::printf("Operator -> %d, LHS -> %lld, RHS -> %lld\n", int($2), $3, $4); std::printf("This is S-Expr!\n"); } ; -operator +basic_operator + : arithmetic_operator { $$ = $1; } + | boolean_operator { $$ = $1; } + | comparsion_operator { $$ = $1; } +; + +arithmetic_operator : PLUS { $$ = Token::PLUS; std::printf("I am plus +\n"); } | MINUS { $$ = Token::MINUS; std::printf("I am minus -\n"); } | STAR { $$ = Token::MULTIPLY; std::printf("I am star *\n"); } | SLASH { $$ = Token::DIVIDE; std::printf("I am slash /\n"); } ; +boolean_operator + : +; + +comparsion_operator + : LE { $$ = Token::LE; } + | LT { $$ = Token::LT; } + | GE { $$ = Token::GE; } + | GT { $$ = Token::GT; } + | EQUAL { $$ = Token::EQUAL; } + | NE { $$ = Token::NE; } + %% void DragonLisp::DLParser::error(const location_type& l, const std::string& msg) {