blob: ea104aae4c7e2e7f39617fafa1d1b27c5ada31ad (
plain)
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
33
34
35
36
|
# $Id: simple_calculator.tac,v 1.1 2004/08/18 23:53:43 tang Exp $
# This example demonstrates symbol and synthesized values.
%{
#!/usr/bin/tclsh
%}
%token ID NEWLINE
%start start
%%
start: E NEWLINE { puts "Result is $1" }
| E { puts "Result is $1" }
;
E: E '+' T { set _ [expr {$1 + $3}] }
| E '-' T { set _ [expr {$1 - $3}] }
| T
;
T: T '*' F { set _ [expr {$1 * $3}] }
| T '/' F { set _ [expr {$1 / $3}] }
| F
;
F: '(' E ')' { set _ $2 }
| ID { set _ $::yylval }
;
%%
source simple_scanner.tcl
yyparse
|