-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathexpr.cpp.par
32 lines (26 loc) · 914 Bytes
/
expr.cpp.par
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
%!language "C++";
%whitespaces ' \t';
%lexeme int;
%default action [* @@ = @1 *];
%left '+' '-';
%left '*' '/';
%prologue [*
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <locale.h>
#include <iostream>
*];
calc$ : expr [* std::cout << "= " <<
@expr << std::endl *]
;
expr : expr:a '+' expr:b [* @@ = @a + @b *]
| expr:a '-' expr:b [* @@ = @a - @b *]
| expr:a '*' expr:b [* @@ = @a * @b *]
| expr:a '/' expr:b [* @@ = @a / @b *]
| '(' expr ')' [* @@ = @expr *]
| int
;
int : '0-9' [* @@ = @1 - '0' *]
| int '0-9' [* @@ = @int * 10 + @2 - '0' *]
;