diff options
Diffstat (limited to 'tp2-files')
-rw-r--r-- | tp2-files/Calculatrice-final.jj | 34 |
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; } } |