summaryrefslogtreecommitdiffstats
path: root/tp2-files
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2017-01-24 16:10:40 +0100
committerDavid A. Madore <david+git@madore.org>2017-01-24 16:10:40 +0100
commitc0144ee707a03caffae6963c429f17078c6dc89e (patch)
tree227102a94e90e26772d0ac5cc902a79a0db9955c /tp2-files
parent06043c0f14dc6ddb1be75ff1247834cd23cb64f7 (diff)
parent228342757a709fddffc3c08209b7376680e1b2ba (diff)
downloadinf105-c0144ee707a03caffae6963c429f17078c6dc89e.tar.gz
inf105-c0144ee707a03caffae6963c429f17078c6dc89e.tar.bz2
inf105-c0144ee707a03caffae6963c429f17078c6dc89e.zip
Merge branch 'master' of git.madore.org:teach/inf105
Diffstat (limited to 'tp2-files')
-rw-r--r--tp2-files/Calculatrice-final.jj34
1 files changed, 17 insertions, 17 deletions
diff --git a/tp2-files/Calculatrice-final.jj b/tp2-files/Calculatrice-final.jj
index 9a03f39..889659c 100644
--- a/tp2-files/Calculatrice-final.jj
+++ b/tp2-files/Calculatrice-final.jj
@@ -37,47 +37,47 @@ void boucle():
}
// Expression (axiome de la grammaire de la calculatrice)
-// expression → terme ( "+" terme | "-" terme )*
+// expression → term ( "+" term | "-" term )*
double expression():
{ double a,b; }
{
- a=terme()
+ a=term()
(
- "+" b=terme() { a += b; }
- | "-" b=terme() { a -= b; }
+ "+" b=term() { a += b; }
+ | "-" b=term() { a -= b; }
)* { return a; }
}
// Terme d'une somme ou différence
-// terme → unaire ( "*" unaire | "/" unaire )*
-double terme():
+// term → factor ( "*" factor | "/" factor )*
+double term():
{ double a,b; }
{
- a=unaire()
+ a=factor()
(
- "*" b=unaire() { a *= b; }
- | "/" b=unaire() { a /= b; }
+ "*" b=factor() { a *= b; }
+ | "/" b=factor() { a /= b; }
)* { return a; }
}
// Gestion du "+" et "−" unaires
-// unaire → puissance | "+" puissance | "-" puissance
-double unaire():
+// factor → power | "+" power | "-" power
+double factor():
{ double a; }
{
- a=puissance() { return a; }
-| "+" a=puissance() { return a; }
-| "-" a=puissance() { return -a; }
+ a=power() { return a; }
+| "+" a=power() { return a; }
+| "-" a=power() { return -a; }
}
// Opération puissance (associative à droite)
-// puissance → element ( "^" unaire )?
-double puissance():
+// power → element ( "^" factor )?
+double power():
{ double a,b; }
{
a=element()
(
- "^" b=unaire() { a = Math.pow(a,b); }
+ "^" b=factor() { a = Math.pow(a,b); }
)? { return a; }
}