[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
C++ variants
From: |
Hans Aberg |
Subject: |
C++ variants |
Date: |
Sun, 18 Jan 2015 23:10:38 +0100 |
Bison C++ variants do not save the type, however, if one wants to put data in a
lookup table or a return type, it may be needed. In the calc++ example .yy
file, one might have types say bool b, integer z, and rational r (using GMP):
assignment:
"identifier" ":=“ b-exp { driver.variables[$1] = $3; };
"identifier" ":=“ z-exp { driver.variables[$1] = $3; };
"identifier" ":=“ q-exp { driver.variables[$1] = $3; };
and similarly for
unit: assignments exp { driver.result = $2; };
Do you have an example of that? - Before, I used a polymorphic type storing a
pointer, but the idea is to avoid that in the case the parser is statically
typed.
- C++ variants,
Hans Aberg <=