diff options
author | David A. Madore <david+git@madore.org> | 2017-01-24 14:46:13 +0100 |
---|---|---|
committer | David A. Madore <david+git@madore.org> | 2017-01-24 14:46:13 +0100 |
commit | ed9dcfac0bd24c21333f25cca9231ce00f42aee8 (patch) | |
tree | 35191cb3917467f07c5abd5d6e6b69b0d85b72b3 /tp2-files | |
parent | b3ef7af199ccebe7bccfe8d18b80022a23e7fcf3 (diff) | |
download | inf105-ed9dcfac0bd24c21333f25cca9231ce00f42aee8.tar.gz inf105-ed9dcfac0bd24c21333f25cca9231ce00f42aee8.tar.bz2 inf105-ed9dcfac0bd24c21333f25cca9231ce00f42aee8.zip |
Systematically use English names for nonterminals; also replace "unary" by "factor". (Akim's suggestion.)
Diffstat (limited to 'tp2-files')
-rw-r--r-- | tp2-files/Calculatrice-final.jj | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/tp2-files/Calculatrice-final.jj b/tp2-files/Calculatrice-final.jj index 9a03f39..a7ea9f0 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 d'une somme ou différence +// 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(): +// Gestion du "+" et "−" factors +// 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(): +// Opération power (associative à droite) +// 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; } } |