Skip to content
Snippets Groups Projects
Commit 830204a4 authored by christia.agodomou's avatar christia.agodomou
Browse files

division

parent 5095f63a
Branches
No related tags found
No related merge requests found
/*
* Represent an addition expression node inside the AST.
*/
public class Division extends Arithmetique {
/**
* Constructor
*/
public Division(Expression operandeGauche, Expression operandeDroite, String fl, int line, int col) {
super(operandeGauche, operandeDroite, fl, line, col);
}
/**
* Get the binary operator
*/
public String operateur() {
return "/";
}
/**
* Accepts a AST visitor
*/
Object accept(ASTVisitor visitor){
return visitor.visit(this);
}
}
......@@ -2,5 +2,5 @@ programme Program
debutprg
b = 3;
c = c - 2;
c = c / 2;
finprg
......@@ -19,7 +19,7 @@ public interface ASTVisitor {
Object visit(DeclarationProgramme node);
// Object visit(DeclarationVariable node);
// Object visit(Diff node);
// Object visit(Division node);
Object visit(Division node);
// Object visit(Ecrire node);
Object visit(Egal node);
// Object visit(Et node);
......
......@@ -26,7 +26,7 @@ public class ByteCodeGenerator implements ASTVisitor{
// public Object visit(Diff node) { return null; }
// public Object visit(Division node) { return null; }
public Object visit(Division node) { return null; }
// public Object visit(Ecrire node) { return null; }
......
......@@ -28,7 +28,7 @@ public class SemanticAnalyzer implements ASTVisitor {
// public Object visit(Diff node) { return null; }
// public Object visit(Division node) { return null; }
public Object visit(Division node) { return null; }
// public Object visit(Ecrire node) { return null; }
......
......@@ -123,12 +123,12 @@ public class SourceCodeGenerator implements ASTVisitor{
// return null;
// }
//
// public Object visit(Division node){
// node.getGauche().accept(this);
// code += " / ";
// node.getDroite().accept(this);
// return null;
// }
public Object visit(Division node){
node.getGauche().accept(this);
code += " / ";
node.getDroite().accept(this);
return null;
}
//
// public Object visit(Ecrire node){
// code += "ecrire ";
......
......@@ -78,7 +78,7 @@ declar_const ::= CONSTANT type IDENT EQUAL expr SEMICOLON {: :};
op_bin ::= expr:a PLUS expr:b {: RESULT = new Addition(a, b, "", aleft, aright); :}
| expr:a MINUS expr:b {: RESULT = new Soustraction(a, b, "", aleft, aright); :}
| expr TIMES expr {: :}
| expr DIVIDE expr {: :}
| expr:a DIVIDE expr:b {: RESULT = new Division(a, b, "", aleft, aright);:}
| expr AND expr {: :}
| expr OR expr {: :};
......
//----------------------------------------------------
// The following code was generated by CUP v0.11a beta 20060608
// Wed Nov 23 18:32:15 CET 2022
// Wed Nov 23 18:56:00 CET 2022
//----------------------------------------------------
import java_cup.runtime.*;
......@@ -10,7 +10,7 @@ import java.io.*;
import java.util.*;
/** CUP v0.11a beta 20060608 generated parser.
* @version Wed Nov 23 18:32:15 CET 2022
* @version Wed Nov 23 18:56:00 CET 2022
*/
public class parser extends java_cup.runtime.lr_parser {
......@@ -747,7 +747,13 @@ class CUP$parser$actions {
case 17: // op_bin ::= expr DIVIDE expr
{
Binaire RESULT =null;
int aleft = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).left;
int aright = ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)).right;
Expression a = (Expression)((java_cup.runtime.Symbol) CUP$parser$stack.elementAt(CUP$parser$top-2)).value;
int bleft = ((java_cup.runtime.Symbol)CUP$parser$stack.peek()).left;
int bright = ((java_cup.runtime.Symbol)CUP$parser$stack.peek()).right;
Expression b = (Expression)((java_cup.runtime.Symbol) CUP$parser$stack.peek()).value;
RESULT = new Division(a, b, "", aleft, aright);
CUP$parser$result = parser.getSymbolFactory().newSymbol("op_bin",20, ((java_cup.runtime.Symbol)CUP$parser$stack.elementAt(CUP$parser$top-2)), ((java_cup.runtime.Symbol)CUP$parser$stack.peek()), RESULT);
}
return CUP$parser$result;
......
//----------------------------------------------------
// The following code was generated by CUP v0.11a beta 20060608
// Wed Nov 23 18:32:15 CET 2022
// Wed Nov 23 18:56:00 CET 2022
//----------------------------------------------------
/** CUP generated class containing symbol constants. */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment