From ed9dcfac0bd24c21333f25cca9231ce00f42aee8 Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Tue, 24 Jan 2017 14:46:13 +0100 Subject: Systematically use English names for nonterminals; also replace "unary" by "factor". (Akim's suggestion.) --- tp2-files/Calculatrice-final.jj | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'tp2-files') 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; } } -- cgit v1.2.3