1 %skeleton "lalr1.cc" /* -*- C++ -*- */
2 %define "parser_class_name" "calcxx_parser"
6 # include "calc++-driver.hh"
11 // The parsing context.
12 %parse-param { calcxx_driver& driver }
13 %lex-param { calcxx_driver& driver }
18 // Initialize the initial location.
19 @$.begin.filename = @$.end.filename = &driver.file;
29 /// Value of a numeric literal.
31 /// Name of a variable.
35 %token YYEOF 0 "end of file"
36 %token TOKEN_ASSIGN ":="
37 %token <sval> TOKEN_IDENTIFIER "identifier"
38 %token <ival> TOKEN_NUMBER "number"
39 %type <ival> exp "expression"
41 %printer { debug_stream () << *$$; } "identifier"
42 %destructor { delete $$; } "identifier"
44 %printer { debug_stream () << $$; } "number" "expression"
48 unit: assignments exp { driver.result = $2; };
50 assignments: assignments assignment {}
53 assignment: TOKEN_IDENTIFIER ":=" exp { driver.variables[*$1] = $3; };
57 exp: exp '+' exp { $$ = $1 + $3; }
58 | exp '-' exp { $$ = $1 - $3; }
59 | exp '*' exp { $$ = $1 * $3; }
60 | exp '/' exp { $$ = $1 / $3; }
61 | TOKEN_IDENTIFIER { $$ = driver.variables[*$1]; }
62 | TOKEN_NUMBER { $$ = $1; };
65 yy::calcxx_parser::error (const location& l, const std::string& m)