diff --git a/.idea/misc.xml b/.idea/misc.xml index 432b6463321993752b6a5bdf57f389f0f99993b6..c0afcc3621d040185d14ee0a9e86252e14044728 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,4 +3,10 @@ <component name="ProjectRootManager" version="2" project-jdk-name="19" project-jdk-type="JavaSDK"> <output url="file://$PROJECT_DIR$/out" /> </component> + <component name="RMI Configuration"> + <Server /> + <Port>0</Port> + <ProjectOutput>false</ProjectOutput> + <CODEBASE /> + </component> </project> \ No newline at end of file diff --git a/AST/AST.class b/AST/AST.class index cb53cf1a804db82ad71625b141a6c40fb98e7837..a5f8b3cf1cc68dee6e127499ee1054b32ce167f7 100644 Binary files a/AST/AST.class and b/AST/AST.class differ diff --git a/AST/AST.java b/AST/AST.java index 0957fb3728c886386fc5449340415b0932ba0007..f30471767ef46d5ffe5a3c806085c21d51fe8166 100644 --- a/AST/AST.java +++ b/AST/AST.java @@ -2,7 +2,7 @@ package AST; import java.util.Deque; import java.util.ArrayDeque; -public abstract class AST { +public abstract class AST{ // vous pouvez ajouter ici les méthodes disponible sur tous les noeuds de vos ASTs diff --git a/AST/Bloc.class b/AST/Bloc.class new file mode 100644 index 0000000000000000000000000000000000000000..b227596fe64c4eb0b7da1e5397741afbcd9c7f93 Binary files /dev/null and b/AST/Bloc.class differ diff --git a/AST/Bloc.java b/AST/Bloc.java new file mode 100644 index 0000000000000000000000000000000000000000..34d16faca0f9abe0c03df2ce5da2b09e442e3db4 --- /dev/null +++ b/AST/Bloc.java @@ -0,0 +1,13 @@ +package AST; +public class Bloc extends Commande { + Programme prg; + public Bloc(Programme prg) { + this.prg = prg; + } + public String toAssembly(){ + return this.prg.toAssembly(); + } + public String toString() { + return String.format("Programme(%1$s)", prg.toString()); + } +} \ No newline at end of file diff --git a/AST/Bool.class b/AST/Bool.class new file mode 100644 index 0000000000000000000000000000000000000000..621e9bc2892fe7eecb09f92e1016991809694d1b Binary files /dev/null and b/AST/Bool.class differ diff --git a/AST/Bool.java b/AST/Bool.java new file mode 100644 index 0000000000000000000000000000000000000000..27652641fcb9e8f9cd7a1fc34951adede4dffee4 --- /dev/null +++ b/AST/Bool.java @@ -0,0 +1,16 @@ +package AST; + +public class Bool extends ExpressionA { + public boolean num; + + public Bool(boolean num) { + this.num = num; + } + + public String toString() { + return Boolean.toString(num); + } + public String toAssembly() { + return "CsteBo " + num+"\n"; + } +} diff --git a/AST/Cmnt.java b/AST/Cmnt.java new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/AST/Commande.class b/AST/Commande.class new file mode 100644 index 0000000000000000000000000000000000000000..d10848c631b230bbd409739a28239c2946ef0131 Binary files /dev/null and b/AST/Commande.class differ diff --git a/AST/Commande.java b/AST/Commande.java new file mode 100644 index 0000000000000000000000000000000000000000..6c6ea437c6e153b80f55132c31b03a363d38b4f9 --- /dev/null +++ b/AST/Commande.java @@ -0,0 +1,4 @@ +package AST; +public abstract class Commande extends AST{ + public abstract String toAssembly(); +} \ No newline at end of file diff --git a/AST/Div.class b/AST/Div.class index 28a2d5238d24ff9f140bfc225c3fc81cfbed0e16..d99ff356440d3373a8c94a92208ae2e9ea497341 100644 Binary files a/AST/Div.class and b/AST/Div.class differ diff --git a/AST/Egal.class b/AST/Egal.class new file mode 100644 index 0000000000000000000000000000000000000000..0501a44581b17e6f68b4e0083abe044441ac57bd Binary files /dev/null and b/AST/Egal.class differ diff --git a/AST/Egal.java b/AST/Egal.java new file mode 100644 index 0000000000000000000000000000000000000000..4a61e077a231a3496b8ba643340674e487e1a645 --- /dev/null +++ b/AST/Egal.java @@ -0,0 +1,15 @@ +package AST; + +public class Egal extends ExpressionA_Binaire { + + public Egal(ExpressionA gauche, ExpressionA droite) { + super(gauche, droite); + } + + public String symbole() { + return "Equals"; + } + public String toAssembly() { + return gauche.toAssembly() + droite.toAssembly() + "Equals\n"; + } +} diff --git a/AST/Et.class b/AST/Et.class new file mode 100644 index 0000000000000000000000000000000000000000..f9c175ccaaef4c305da2eeb0c2cf339d9c9ec593 Binary files /dev/null and b/AST/Et.class differ diff --git a/AST/Et.java b/AST/Et.java new file mode 100644 index 0000000000000000000000000000000000000000..f0ff6e286338510a7c9a4e30536358eb286e2818 --- /dev/null +++ b/AST/Et.java @@ -0,0 +1,15 @@ +package AST; + +public class Et extends ExpressionA_Binaire { + + public Et(ExpressionA gauche, ExpressionA droite) { + super(gauche, droite); + } + + public String symbole() { + return "Et"; + } + public String toAssembly() { + return gauche.toAssembly() +"ConJmp "+Tools.countNewLines(droite.toAssembly())+"\n"+ droite.toAssembly() + "Jump 2\n"+"CstBo False\n"; + } +} diff --git a/AST/ExpressionA.class b/AST/ExpressionA.class index afb7c6c77ed45410d1992fe6577007d186441a6c..b03c3632a9d570725f3a16dc146a38c6cf350185 100644 Binary files a/AST/ExpressionA.class and b/AST/ExpressionA.class differ diff --git a/AST/ExpressionA.java b/AST/ExpressionA.java index f3a9ba1c9f99e91b40953fa96b05c6518d1f819e..f453d8084c6b6275cb1efa29adee1cb2a79f737e 100644 --- a/AST/ExpressionA.java +++ b/AST/ExpressionA.java @@ -1,6 +1,6 @@ package AST; -public abstract class ExpressionA extends AST { +public abstract class ExpressionA extends Commande { // un jour il y aura d'autres choses ici - public abstract String toAssembly(); + //public abstract String toAssembly(); } diff --git a/AST/ExpressionA_Binaire.class b/AST/ExpressionA_Binaire.class index 30abb9ba7d764eca7e7f57c5047adc0f7c4ee247..3b498003f9097114a86a0eec598038063bb9fae4 100644 Binary files a/AST/ExpressionA_Binaire.class and b/AST/ExpressionA_Binaire.class differ diff --git a/AST/FloatT.class b/AST/FloatT.class new file mode 100644 index 0000000000000000000000000000000000000000..ec1eaeca8924c22faf4ef8ae4d6451577a28ccf7 Binary files /dev/null and b/AST/FloatT.class differ diff --git a/AST/FloatT.java b/AST/FloatT.java new file mode 100644 index 0000000000000000000000000000000000000000..ae7215bd75ccf218a0a036cbac32e597d2e60e4a --- /dev/null +++ b/AST/FloatT.java @@ -0,0 +1,22 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package AST; + +public class FloatT extends ExpressionA { + public float arg; + + public FloatT(float var1) { + this.arg = var1; + } + + public String toString() { + return Float.toString(this.arg); + } + + public String toAssembly() { + return "CsteNb " + this.arg + "\n"; + } +} diff --git a/AST/GrEgNb.class b/AST/GrEgNb.class new file mode 100644 index 0000000000000000000000000000000000000000..14f6ae5fa8994d423c1c5bb7b08b9fb1e4efefe5 Binary files /dev/null and b/AST/GrEgNb.class differ diff --git a/AST/GrEgNb.java b/AST/GrEgNb.java new file mode 100644 index 0000000000000000000000000000000000000000..03c2aab41852088fb0ee091131cb72cdf6f280db --- /dev/null +++ b/AST/GrEgNb.java @@ -0,0 +1,15 @@ +package AST; + +public class GrEgNb extends ExpressionA_Binaire { + + public GrEgNb(ExpressionA gauche, ExpressionA droite) { + super(gauche, droite); + } + + public String symbole() { + return "GrEqNb"; + } + public String toAssembly() { + return gauche.toAssembly() + droite.toAssembly() + "GrEqNb\n"; + } +} diff --git a/AST/GrStNb.class b/AST/GrStNb.class new file mode 100644 index 0000000000000000000000000000000000000000..ae2abe3a192d0fb06ef279a26806a29092cff131 Binary files /dev/null and b/AST/GrStNb.class differ diff --git a/AST/GrStNb.java b/AST/GrStNb.java new file mode 100644 index 0000000000000000000000000000000000000000..4db76e1b9428f07fab22b899a3b90dc0a540e6f4 --- /dev/null +++ b/AST/GrStNb.java @@ -0,0 +1,15 @@ +package AST; + +public class GrStNb extends ExpressionA_Binaire { + + public GrStNb(ExpressionA gauche, ExpressionA droite) { + super(gauche, droite); + } + + public String symbole() { + return "GrStNb"; + } + public String toAssembly() { + return gauche.toAssembly() + droite.toAssembly() + "GrStNb\n"; + } +} diff --git a/AST/Ident.class b/AST/Ident.class new file mode 100644 index 0000000000000000000000000000000000000000..f89b7136cbc0450d1a6413810692246f0a527ac4 Binary files /dev/null and b/AST/Ident.class differ diff --git a/AST/Ident.java b/AST/Ident.java new file mode 100644 index 0000000000000000000000000000000000000000..204efa21bfbc766cd21aa5a5a887cc97169158a5 --- /dev/null +++ b/AST/Ident.java @@ -0,0 +1,14 @@ +package AST; +public class Ident extends ExpressionA{ + private String arg; + public Ident(String t){ + this.arg = t; + } + public String toString() { + return arg; + } + + public String toAssembly() { + return "" ; + } +} \ No newline at end of file diff --git a/AST/Import.class b/AST/Import.class new file mode 100644 index 0000000000000000000000000000000000000000..1fda0d5b5fdb31a9087ba072a1ffa4d1ec81538c Binary files /dev/null and b/AST/Import.class differ diff --git a/AST/Import.java b/AST/Import.java new file mode 100644 index 0000000000000000000000000000000000000000..3c6dccf5577148d0552e18b6d076bf39b41d286d --- /dev/null +++ b/AST/Import.java @@ -0,0 +1,31 @@ +package AST; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.io.IOException; +import java.util.List; + +public class Import extends Commande { + + public Commande arg; + + public Import(Commande arg) { + this.arg = arg; + } + + public String toString() { + return String.format("Import(%1$s)", arg.toString()); + } + @Override + public String toAssembly() { + String content=""; + try { + List<String> lines = Files.readAllLines(Paths.get(String.format("%1$s", arg.toString()))); + for (String line : lines) { + content+=("\n"+line); + } + }catch (IOException e) { + System.out.println("Error reading file: " + e.getMessage()); + } + return (arg.toAssembly())+content; + } +} diff --git a/AST/LoEqNb.class b/AST/LoEqNb.class new file mode 100644 index 0000000000000000000000000000000000000000..9a4059474a6401873dfddb453ee4e728c0101b9a Binary files /dev/null and b/AST/LoEqNb.class differ diff --git a/AST/LoEqNb.java b/AST/LoEqNb.java new file mode 100644 index 0000000000000000000000000000000000000000..fd6a521a0f13da6554de3c4de888a8e8e6ba6664 --- /dev/null +++ b/AST/LoEqNb.java @@ -0,0 +1,15 @@ +package AST; + +public class LoEqNb extends ExpressionA_Binaire { + + public LoEqNb(ExpressionA gauche, ExpressionA droite) { + super(gauche, droite); + } + + public String symbole() { + return "LoEqNb"; + } + public String toAssembly() { + return gauche.toAssembly() + droite.toAssembly() + "LoEqNb\n"; + } +} diff --git a/AST/LoStNb.class b/AST/LoStNb.class new file mode 100644 index 0000000000000000000000000000000000000000..e5657fa5bacd37d8603168d058c68e7dbac2c80b Binary files /dev/null and b/AST/LoStNb.class differ diff --git a/AST/LoStNb.java b/AST/LoStNb.java new file mode 100644 index 0000000000000000000000000000000000000000..953f9624d946c854bc166e9cc9ba787dd42eb740 --- /dev/null +++ b/AST/LoStNb.java @@ -0,0 +1,15 @@ +package AST; + +public class LoStNb extends ExpressionA_Binaire { + + public LoStNb(ExpressionA gauche, ExpressionA droite) { + super(gauche, droite); + } + + public String symbole() { + return "LoStNb"; + } + public String toAssembly() { + return gauche.toAssembly() + droite.toAssembly() + "LoStNb\n"; + } +} diff --git a/AST/Modulo.class b/AST/Modulo.class new file mode 100644 index 0000000000000000000000000000000000000000..b864946b1f7702590d855a8a4edc115fd943ead6 Binary files /dev/null and b/AST/Modulo.class differ diff --git a/AST/Modulo.java b/AST/Modulo.java new file mode 100644 index 0000000000000000000000000000000000000000..b02615f3782638f78ebcd67c4f2b9c116a1c3ad1 --- /dev/null +++ b/AST/Modulo.java @@ -0,0 +1,11 @@ +package AST; + +public class Modulo extends ExpressionA_Binaire { + + public Modulo(ExpressionA gauche,ExpressionA droite) {super(gauche, droite);} + + public String symbole() {return "Modulo";}; + public String toAssembly() { + return gauche.toAssembly() + droite.toAssembly() + "ModuNb\n"; + } +} diff --git a/AST/Moins.class b/AST/Moins.class index 09b7db74821e5580e0d1f0c3762342bb10532b96..927dba8650a29ae1c1b4482a2aebc62485466422 100644 Binary files a/AST/Moins.class and b/AST/Moins.class differ diff --git a/AST/Mult.class b/AST/Mult.class index f6230546d8631f3ccd470d1b98967e74ee8ea7e2..a6c0f5da77cf06c49d568a321f6819468c778d23 100644 Binary files a/AST/Mult.class and b/AST/Mult.class differ diff --git a/AST/Neg.class b/AST/Neg.class index becf0d8ed78719a4c9dcb0b3fee726b0daa2ef23..e2fd20a2d94f1c4a727bde6380bf174e06a27537 100644 Binary files a/AST/Neg.class and b/AST/Neg.class differ diff --git a/AST/Not.class b/AST/Not.class new file mode 100644 index 0000000000000000000000000000000000000000..a034875f8e07101cd714431486992ecebd589630 Binary files /dev/null and b/AST/Not.class differ diff --git a/AST/Not.java b/AST/Not.java new file mode 100644 index 0000000000000000000000000000000000000000..8cdde2e820e275752a3de321017d3efc2eabec9c --- /dev/null +++ b/AST/Not.java @@ -0,0 +1,17 @@ +package AST; + +public class Not extends ExpressionA { + + public ExpressionA arg; + + public Not(ExpressionA arg) { + this.arg = arg; + } + + public String toString() { + return String.format("Not(%1$s)", arg.toString()); + } + public String toAssembly() { + return (arg.toAssembly())+"Not\n"; + } +} diff --git a/AST/NotEql.class b/AST/NotEql.class new file mode 100644 index 0000000000000000000000000000000000000000..edd14ea0bc406fac0ff7bd5d688673058527b670 Binary files /dev/null and b/AST/NotEql.class differ diff --git a/AST/NotEql.java b/AST/NotEql.java new file mode 100644 index 0000000000000000000000000000000000000000..33e5304dc634e2fa93d2faa7ba1b7ce158dde9eb --- /dev/null +++ b/AST/NotEql.java @@ -0,0 +1,15 @@ +package AST; + +public class NotEql extends ExpressionA_Binaire { + + public NotEql(ExpressionA gauche, ExpressionA droite) { + super(gauche, droite); + } + + public String symbole() { + return "NotEqual"; + } + public String toAssembly() { + return gauche.toAssembly() + droite.toAssembly() + "NotEql\n"; + } +} diff --git a/AST/Num.class b/AST/Num.class index bce82d1ab9ce5e014e9c95a84de02e8946045055..b1fe25f2ed155a198f4aa38a1d1771b3c6082f93 100644 Binary files a/AST/Num.class and b/AST/Num.class differ diff --git a/AST/Plus.class b/AST/Plus.class index d0d6755c7957cbb093f0794617d5b11c2a599af3..4d1011a7d3196c4eb8f78dfa7778b9924d423683 100644 Binary files a/AST/Plus.class and b/AST/Plus.class differ diff --git a/AST/Programme.class b/AST/Programme.class new file mode 100644 index 0000000000000000000000000000000000000000..77eddfa134b7c2e8ed4df95157deeac88d4c2944 Binary files /dev/null and b/AST/Programme.class differ diff --git a/AST/Programme.java b/AST/Programme.java new file mode 100644 index 0000000000000000000000000000000000000000..d75d30a8c6a0bc1263667448286b200a28b6ffe7 --- /dev/null +++ b/AST/Programme.java @@ -0,0 +1,23 @@ +package AST; +import java.util.List; +import java.util.ArrayList; +public class Programme extends AST { + public List<Commande> commandes; + + public Programme(List<Commande> commandes) { + this.commandes = commandes; + //System.out.println("prg cree"); + } + public Programme(Programme a){ + this.commandes = a.commandes; + } + + public String toAssembly() { + String assembly = ""; + for (Commande commande : commandes) { + assembly = assembly+commande.toAssembly()+"Drop\n"; + + } + return assembly; + } +} diff --git a/AST/Tools.class b/AST/Tools.class new file mode 100644 index 0000000000000000000000000000000000000000..8d8f0a15685faa2f70f2692752fb2b6f5213098a Binary files /dev/null and b/AST/Tools.class differ diff --git a/AST/Tools.java b/AST/Tools.java new file mode 100644 index 0000000000000000000000000000000000000000..98b3dff297fe3e1401fc5469216883e1f6b5d267 --- /dev/null +++ b/AST/Tools.java @@ -0,0 +1,8 @@ +package AST; + +public class Tools { + public static int countNewLines(String input) { + String[] lines = input.split("\n", -1); // Utilisez "\r\n" si nécessaire + return lines.length; + } +} \ No newline at end of file diff --git a/AST/script b/AST/script new file mode 100755 index 0000000000000000000000000000000000000000..1d70f285ff6b8a8118b20697a675df98ac34f3ad --- /dev/null +++ b/AST/script @@ -0,0 +1,17 @@ +#!/bin/bash + +# Specify the output file name +output_file="operation.java" + +# Remove the output file if it already exists +rm -f "$output_file" + +# Loop through all .java files in the current directory +for file in *.java; do + # Append the content of each .java file to the output file + cat "$file" >> "$output_file" + echo "" >> "$output_file" # Add a newline after each file +done + +echo "All .java files combined into $output_file" + diff --git a/Compilateur.class b/Compilateur.class index 1c4d79fddc79d98aae8417efccb5f86bdcc49bdf..a3c147856b91f2607cabef807e917b87c71e6b83 100644 Binary files a/Compilateur.class and b/Compilateur.class differ diff --git a/Compilateur.java b/Compilateur.java index 71b240187d29be803900ffdf744dc7007a5589f3..c593cd9efdd22f6514f29e3547d2b81e30a3c8a5 100644 --- a/Compilateur.java +++ b/Compilateur.java @@ -1,36 +1,50 @@ /* Compilateur.java */ /* Generated By:JavaCC: Do not edit this line. Compilateur.java */ import AST.*; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.List; import java.io.InputStream; public class Compilateur implements CompilateurConstants { public static void main(String args[]) { try { - System.out.print("Tapez une Expression : "); - Compilateur parseur = new Compilateur(System.in); - ExpressionA ast = parseur.mainNT(); - System.out.println("AST calcul\u00e9 : \n" + ast.toAssembly()+"Halt"); + //System.out.print("Tapez une Expression : "); + FileInputStream fis = new FileInputStream("test.js"); + Compilateur parseur = new Compilateur(fis); + Programme programme = parseur.mainNT(); // Changer pour Programme + System.out.println("Assembly code : \n" + programme.toAssembly()+"Halt"); // Modifier pour générer l'assembleur System.out.println("C'est bien une expression arithm\u00e9tique !!"); - } catch (TokenMgrError e) { - System.out.println("Ceci n'est pas une expression arithm\u00e9tique :"+e); - } catch (ParseException e){ - System.out.println("Ceci n'est pas une expression arithm\u00e9tique :"+e); - } } + }catch (FileNotFoundException e) { + System.out.println("Le fichier sp\u00e9cifi\u00e9 n'a pas \u00e9t\u00e9 trouv\u00e9."); + }catch (TokenMgrError e) { + System.out.println("Ceci n'est pas une expression arithm\u00e9tique :"+e.toString()); + }catch (ParseException e){ + System.out.println("Ceci n'est pas une expression arithm\u00e9tique :"+e); + } } - static final public ExpressionA mainNT() throws ParseException {ExpressionA expression; - expression = expression(); - jj_consume_token(EOL); -{if ("" != null) return expression;} + static final public Programme mainNT() throws ParseException {Programme prg; + prg = programme(); + jj_consume_token(0); +{if ("" != null) return prg;} throw new Error("Missing return statement in function"); } - static final public ExpressionA expression() throws ParseException {ExpressionA gauche, droite; - gauche = terme(); + static final public Programme programme() throws ParseException {List<Commande> programme = new ArrayList<>(); + Commande commande; label_1: while (true) { switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { - case 5: - case 6:{ + case FLOAT: + case NOMBRE: + case BOOLEAN: + case IMPORT: + case IDENT: + case 13: + case 23: + case 27: + case 29:{ ; break; } @@ -38,21 +52,151 @@ public class Compilateur implements CompilateurConstants { jj_la1[0] = jj_gen; break label_1; } + commande = commande(); +programme.add(commande); + } +{if ("" != null) return new Programme(programme);} + throw new Error("Missing return statement in function"); +} + + static final public Commande commande() throws ParseException {Commande expr; + Programme prg; + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case FLOAT: + case NOMBRE: + case BOOLEAN: + case IDENT: + case 23: + case 27: + case 29:{ + expr = expression(); + jj_consume_token(EOL); +{if ("" != null) return expr;} + break; + } + case IMPORT:{ + jj_consume_token(IMPORT); + expr = facteur(); + jj_consume_token(EOL); +{if ("" != null) return new Import(expr);} + break; + } + case 13:{ + jj_consume_token(13); + prg = programme(); + jj_consume_token(14); +{if ("" != null) return new Bloc(prg);} + break; + } + default: + jj_la1[1] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + throw new Error("Missing return statement in function"); +} + + static final public ExpressionA expression() throws ParseException {ExpressionA gauche, droite; + gauche = comp(); + label_2: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case 15: + case 16: + case 17: + case 18: + case 19: + case 20: + case 21:{ + ; + break; + } + default: + jj_la1[2] = jj_gen; + break label_2; + } switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { - case 5:{ - jj_consume_token(5); + case 15:{ + jj_consume_token(15); + droite = comp(); +gauche = new Egal(gauche, droite); + break; + } + case 16:{ + jj_consume_token(16); + droite = comp(); +gauche = new GrEgNb(gauche, droite); + break; + } + case 17:{ + jj_consume_token(17); + droite = comp(); +gauche = new GrStNb(gauche, droite); + break; + } + case 18:{ + jj_consume_token(18); + droite = comp(); +gauche = new LoStNb(gauche, droite); + break; + } + case 19:{ + jj_consume_token(19); + droite = comp(); +gauche = new LoEqNb(gauche, droite); + break; + } + case 20:{ + jj_consume_token(20); + droite = comp(); +gauche = new NotEql(gauche, droite); + break; + } + case 21:{ + jj_consume_token(21); + droite = comp(); +gauche = new Et(gauche, droite); + break; + } + default: + jj_la1[3] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } +{if ("" != null) return gauche;} + throw new Error("Missing return statement in function"); +} + + static final public ExpressionA comp() throws ParseException {ExpressionA gauche, droite; + gauche = terme(); + label_3: + while (true) { + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case 22: + case 23:{ + ; + break; + } + default: + jj_la1[4] = jj_gen; + break label_3; + } + switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { + case 22:{ + jj_consume_token(22); droite = terme(); gauche = new Plus(gauche, droite); break; } - case 6:{ - jj_consume_token(6); + case 23:{ + jj_consume_token(23); droite = terme(); gauche = new Moins(gauche, droite); break; } default: - jj_la1[1] = jj_gen; + jj_la1[5] = jj_gen; jj_consume_token(-1); throw new ParseException(); } @@ -63,33 +207,40 @@ gauche = new Moins(gauche, droite); static final public ExpressionA terme() throws ParseException {ExpressionA gauche, droite; gauche = facteur(); - label_2: + label_4: while (true) { switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { - case 7: - case 8:{ + case 24: + case 25: + case 26:{ ; break; } default: - jj_la1[2] = jj_gen; - break label_2; + jj_la1[6] = jj_gen; + break label_4; } switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { - case 7:{ - jj_consume_token(7); + case 24:{ + jj_consume_token(24); droite = facteur(); gauche = new Mult(gauche, droite); break; } - case 8:{ - jj_consume_token(8); + case 25:{ + jj_consume_token(25); droite = facteur(); gauche = new Div(gauche, droite); break; } + case 26:{ + jj_consume_token(26); + droite = facteur(); +gauche = new Modulo(gauche, droite); + break; + } default: - jj_la1[3] = jj_gen; + jj_la1[7] = jj_gen; jj_consume_token(-1); throw new ParseException(); } @@ -100,26 +251,47 @@ gauche = new Div(gauche, droite); static final public ExpressionA facteur() throws ParseException {ExpressionA expr; switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) { - case 9:{ - jj_consume_token(9); + case 27:{ + jj_consume_token(27); expr = expression(); - jj_consume_token(10); + jj_consume_token(28); {if ("" != null) return expr;} break; } - case 6:{ - jj_consume_token(6); + case 23:{ + jj_consume_token(23); expr = facteur(); {if ("" != null) return new Neg(expr);} break; } + case 29:{ + jj_consume_token(29); + expr = facteur(); +{if ("" != null) return new Not(expr);} + break; + } case NOMBRE:{ jj_consume_token(NOMBRE); {if ("" != null) return new Num(Integer.parseInt(token.image));} break; } + case FLOAT:{ + jj_consume_token(FLOAT); +{if ("" != null) return new FloatT(Float.parseFloat(token.image));} + break; + } + case BOOLEAN:{ + jj_consume_token(BOOLEAN); +{if ("" != null) return new Bool(Boolean.parseBoolean(token.image));} + break; + } + case IDENT:{ + jj_consume_token(IDENT); +{if ("" != null) return new Ident(token.image);} + break; + } default: - jj_la1[4] = jj_gen; + jj_la1[8] = jj_gen; jj_consume_token(-1); throw new ParseException(); } @@ -136,13 +308,13 @@ gauche = new Div(gauche, droite); static public Token jj_nt; static private int jj_ntk; static private int jj_gen; - static final private int[] jj_la1 = new int[5]; + static final private int[] jj_la1 = new int[9]; static private int[] jj_la1_0; static { jj_la1_init_0(); } private static void jj_la1_init_0() { - jj_la1_0 = new int[] {0x60,0x60,0x180,0x180,0x248,}; + jj_la1_0 = new int[] {0x288020ce,0x288020ce,0x3f8000,0x3f8000,0xc00000,0xc00000,0x7000000,0x7000000,0x2880008e,}; } /** Constructor with InputStream. */ @@ -163,7 +335,7 @@ gauche = new Div(gauche, droite); token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 5; i++) jj_la1[i] = -1; + for (int i = 0; i < 9; i++) jj_la1[i] = -1; } /** Reinitialise. */ @@ -177,7 +349,7 @@ gauche = new Div(gauche, droite); token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 5; i++) jj_la1[i] = -1; + for (int i = 0; i < 9; i++) jj_la1[i] = -1; } /** Constructor. */ @@ -194,7 +366,7 @@ gauche = new Div(gauche, droite); token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 5; i++) jj_la1[i] = -1; + for (int i = 0; i < 9; i++) jj_la1[i] = -1; } /** Reinitialise. */ @@ -212,7 +384,7 @@ gauche = new Div(gauche, droite); token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 5; i++) jj_la1[i] = -1; + for (int i = 0; i < 9; i++) jj_la1[i] = -1; } /** Constructor with generated Token Manager. */ @@ -228,7 +400,7 @@ gauche = new Div(gauche, droite); token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 5; i++) jj_la1[i] = -1; + for (int i = 0; i < 9; i++) jj_la1[i] = -1; } /** Reinitialise. */ @@ -237,7 +409,7 @@ gauche = new Div(gauche, droite); token = new Token(); jj_ntk = -1; jj_gen = 0; - for (int i = 0; i < 5; i++) jj_la1[i] = -1; + for (int i = 0; i < 9; i++) jj_la1[i] = -1; } static private Token jj_consume_token(int kind) throws ParseException { @@ -288,12 +460,12 @@ gauche = new Div(gauche, droite); /** Generate ParseException. */ static public ParseException generateParseException() { jj_expentries.clear(); - boolean[] la1tokens = new boolean[11]; + boolean[] la1tokens = new boolean[30]; if (jj_kind >= 0) { la1tokens[jj_kind] = true; jj_kind = -1; } - for (int i = 0; i < 5; i++) { + for (int i = 0; i < 9; i++) { if (jj_la1[i] == jj_gen) { for (int j = 0; j < 32; j++) { if ((jj_la1_0[i] & (1<<j)) != 0) { @@ -302,7 +474,7 @@ gauche = new Div(gauche, droite); } } } - for (int i = 0; i < 11; i++) { + for (int i = 0; i < 30; i++) { if (la1tokens[i]) { jj_expentry = new int[1]; jj_expentry[0] = i; diff --git a/Compilateur.jj b/Compilateur.jj index aa74977342a7d08629fc4bb7d476902c5eb17bdd..5bed1612e55c4ecdbee2a6b1c1eb9e9936454761 100644 --- a/Compilateur.jj +++ b/Compilateur.jj @@ -1,47 +1,111 @@ PARSER_BEGIN(Compilateur) import AST.*; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.List; import java.io.InputStream; public class Compilateur { public static void main(String args[]) { try { - System.out.print("Tapez une Expression : "); - Compilateur parseur = new Compilateur(System.in); - ExpressionA ast = parseur.mainNT(); - System.out.println("AST calculé : \n" + ast.toAssembly()+"Halt"); + //System.out.print("Tapez une Expression : "); + FileInputStream fis = new FileInputStream("test.js"); + Compilateur parseur = new Compilateur(fis); + Programme programme = parseur.mainNT(); // Changer pour Programme + System.out.println("Assembly code : \n" + programme.toAssembly()+"Halt"); // Modifier pour générer l'assembleur System.out.println("C'est bien une expression arithmétique !!"); - } catch (TokenMgrError e) { - System.out.println("Ceci n'est pas une expression arithm\u00e9tique :"+e); - } catch (ParseException e){ - System.out.println("Ceci n'est pas une expression arithm\u00e9tique :"+e); - } } + }catch (FileNotFoundException e) { + System.out.println("Le fichier spécifié n'a pas été trouvé."); + }catch (TokenMgrError e) { + System.out.println("Ceci n'est pas une expression arithm\u00e9tique :"+e.toString()); + }catch (ParseException e){ + System.out.println("Ceci n'est pas une expression arithm\u00e9tique :"+e); + } } } PARSER_END(Compilateur) -SKIP : -{ " " | "\t" } TOKEN : -{ < NOMBRE: ["1"-"9"] (["0"-"9"])* > -| < EOL: "\n" > +{ + < FLOAT: (("0" | ["1"-"9"] (["0"-"9"])* )? "." (["0"-"9"])+ (("E" | "e") ("+" | "-")? (["0"-"9"])+)? ) | (["0"-"9"])+ (("E" | "e") ("+" | "-")? (["0"-"9"])+)> + | < NOMBRE: (["1"-"9"] (["0"-"9"])* | "0") (("E" | "e") ("+" | "-")? (["0"-"9"])+)?> + | < BOOLEAN: "True" | "False"> + | < EOL: ";\n" | ";" > + | < NAN: "NaN"> + | < IMPORT: "import"> + | < IDENT : (["a"-"z", "A"-"Z", "0"-"9", "/"])+ > +} +SKIP : +{ " " | "\t" | "\n" | < "//" (~["\n", "\r"])* ("\n" | "\r" | "\r\n") > | < "/*" (~["*"])* "*" (~["/", "*"] (~["*"])* "*" )* "/" >} + + +Programme mainNT () : +{ + Programme prg; } +{ + prg=programme() <EOF> { return prg; } -ExpressionA mainNT () : + +} +Programme programme() : +{ + List<Commande> programme = new ArrayList<>(); + Commande commande; +} { - ExpressionA expression; + ( + commande=commande() { + + programme.add(commande); + + } + )* + { + return new Programme(programme);} + } +Commande commande() : { - expression=expression() <EOL> { return expression; } + Commande expr; + Programme prg; } -ExpressionA expression () : +{ + expr=expression() <EOL> { return expr; } + | <IMPORT> expr=facteur() <EOL> { return new Import(expr); } + | "{" prg=programme() "}" {return new Bloc(prg);} + +} + + + +ExpressionA expression() : +{ + ExpressionA gauche, droite; +} +{ + gauche=comp() ( + "==" droite=comp() { gauche = new Egal(gauche, droite); } + | ">=" droite=comp() { gauche = new GrEgNb(gauche, droite); } + | ">" droite=comp() { gauche = new GrStNb(gauche, droite);} + | "<" droite=comp() { gauche = new LoStNb(gauche, droite);} + | "<=" droite=comp() { gauche = new LoEqNb(gauche, droite); } + | "!=" droite=comp() { gauche = new NotEql(gauche, droite); } + | "&&" droite=comp() { gauche = new Et(gauche, droite); } + )* + { return gauche; } +} + +ExpressionA comp() : { ExpressionA gauche, droite; } { gauche=terme() ( - "+" droite=terme() { gauche = new Plus(gauche, droite); } + "+" droite=terme() { gauche = new Plus(gauche, droite); } | "-" droite=terme() { gauche = new Moins(gauche, droite); } - )* + )* { return gauche; } } ExpressionA terme () : @@ -50,8 +114,9 @@ ExpressionA terme () : } { gauche=facteur() ( - "*" droite=facteur() { gauche = new Mult(gauche, droite); } - | "/" droite=facteur() { gauche = new Div(gauche, droite); } + "*" droite=facteur() { gauche = new Mult(gauche, droite); } + | "/" droite=facteur() { gauche = new Div(gauche, droite);} + | "%" droite=facteur() { gauche = new Modulo(gauche, droite); } )* { return gauche; } } @@ -61,7 +126,11 @@ ExpressionA facteur() : ExpressionA expr; } { - "(" expr=expression() ")" { return expr; } - | "-" expr=facteur() { return new Neg(expr); } // Construit un nœud Neg - | <NOMBRE> { return new Num(Integer.parseInt(token.image)); } // Construit un nœud Num + "(" expr=expression() ")" { return expr; } + | "-" expr=facteur() { return new Neg(expr); } + | "!" expr=facteur() { return new Not(expr); } + | <NOMBRE> { return new Num(Integer.parseInt(token.image));} + | <FLOAT> { return new FloatT(Float.parseFloat(token.image));} + | <BOOLEAN> { return new Bool(Boolean.parseBoolean(token.image));}// Construit un nœud Num + | <IDENT> { return new Ident(token.image);}// Construit un nœud Num } diff --git a/CompilateurConstants.class b/CompilateurConstants.class index a58ead425930158a1078c1587deed3c426639012..6744d538acbf54bed39e5040317a6c0d8dc7d5f3 100644 Binary files a/CompilateurConstants.class and b/CompilateurConstants.class differ diff --git a/CompilateurConstants.java b/CompilateurConstants.java index 62e0b982c719887f0b41fece6ccfa5586bff97ad..e13a9828cf4c1962e6c81c35886574757b166a15 100644 --- a/CompilateurConstants.java +++ b/CompilateurConstants.java @@ -9,9 +9,19 @@ public interface CompilateurConstants { /** End of File. */ int EOF = 0; /** RegularExpression Id. */ - int NOMBRE = 3; + int FLOAT = 1; + /** RegularExpression Id. */ + int NOMBRE = 2; + /** RegularExpression Id. */ + int BOOLEAN = 3; /** RegularExpression Id. */ int EOL = 4; + /** RegularExpression Id. */ + int NAN = 5; + /** RegularExpression Id. */ + int IMPORT = 6; + /** RegularExpression Id. */ + int IDENT = 7; /** Lexical state. */ int DEFAULT = 0; @@ -19,16 +29,35 @@ public interface CompilateurConstants { /** Literal token values. */ String[] tokenImage = { "<EOF>", + "<FLOAT>", + "<NOMBRE>", + "<BOOLEAN>", + "<EOL>", + "\"NaN\"", + "\"import\"", + "<IDENT>", "\" \"", "\"\\t\"", - "<NOMBRE>", "\"\\n\"", + "<token of kind 11>", + "<token of kind 12>", + "\"{\"", + "\"}\"", + "\"==\"", + "\">=\"", + "\">\"", + "\"<\"", + "\"<=\"", + "\"!=\"", + "\"&&\"", "\"+\"", "\"-\"", "\"*\"", "\"/\"", + "\"%\"", "\"(\"", "\")\"", + "\"!\"", }; } diff --git a/CompilateurTokenManager.class b/CompilateurTokenManager.class index 07b173fc224be35b1a4ff6b8c2fe2cb6a464732b..f890cd2b152ee280b60e5c74a48d3c0df69cc516 100644 Binary files a/CompilateurTokenManager.class and b/CompilateurTokenManager.class differ diff --git a/CompilateurTokenManager.java b/CompilateurTokenManager.java index 9a0b305705c5e977cf616a5f280907a8a51b321a..b55ab2d104d4529b7aa107bcb8684437a4e58013 100644 --- a/CompilateurTokenManager.java +++ b/CompilateurTokenManager.java @@ -1,6 +1,10 @@ /* CompilateurTokenManager.java */ /* Generated By:JavaCC: Do not edit this line. CompilateurTokenManager.java */ import AST.*; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.List; import java.io.InputStream; /** Token Manager. */ @@ -14,6 +18,52 @@ public class CompilateurTokenManager implements CompilateurConstants { private static final int jjStopStringLiteralDfa_0(int pos, long active0){ switch (pos) { + case 0: + if ((active0 & 0x2000000L) != 0L) + { + jjmatchedKind = 7; + return 29; + } + if ((active0 & 0x60L) != 0L) + { + jjmatchedKind = 7; + return 20; + } + return -1; + case 1: + if ((active0 & 0x60L) != 0L) + { + jjmatchedKind = 7; + jjmatchedPos = 1; + return 20; + } + return -1; + case 2: + if ((active0 & 0x40L) != 0L) + { + jjmatchedKind = 7; + jjmatchedPos = 2; + return 20; + } + if ((active0 & 0x20L) != 0L) + return 20; + return -1; + case 3: + if ((active0 & 0x40L) != 0L) + { + jjmatchedKind = 7; + jjmatchedPos = 3; + return 20; + } + return -1; + case 4: + if ((active0 & 0x40L) != 0L) + { + jjmatchedKind = 7; + jjmatchedPos = 4; + return 20; + } + return -1; default : return -1; } @@ -30,28 +80,165 @@ static private int jjStopAtPos(int pos, int kind) static private int jjMoveStringLiteralDfa0_0(){ switch(curChar) { - case 10: - return jjStopAtPos(0, 4); + case 33: + jjmatchedKind = 29; + return jjMoveStringLiteralDfa1_0(0x100000L); + case 37: + return jjStopAtPos(0, 26); + case 38: + return jjMoveStringLiteralDfa1_0(0x200000L); case 40: - return jjStopAtPos(0, 9); + return jjStopAtPos(0, 27); case 41: - return jjStopAtPos(0, 10); + return jjStopAtPos(0, 28); case 42: - return jjStopAtPos(0, 7); + return jjStopAtPos(0, 24); case 43: - return jjStopAtPos(0, 5); + return jjStopAtPos(0, 22); case 45: - return jjStopAtPos(0, 6); + return jjStopAtPos(0, 23); case 47: - return jjStopAtPos(0, 8); + return jjStartNfaWithStates_0(0, 7, 29); + case 60: + jjmatchedKind = 18; + return jjMoveStringLiteralDfa1_0(0x80000L); + case 61: + return jjMoveStringLiteralDfa1_0(0x8000L); + case 62: + jjmatchedKind = 17; + return jjMoveStringLiteralDfa1_0(0x10000L); + case 78: + return jjMoveStringLiteralDfa1_0(0x20L); + case 105: + return jjMoveStringLiteralDfa1_0(0x40L); + case 123: + return jjStopAtPos(0, 13); + case 125: + return jjStopAtPos(0, 14); default : - return jjMoveNfa_0(0, 0); + return jjMoveNfa_0(12, 0); } } +static private int jjMoveStringLiteralDfa1_0(long active0){ + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(0, active0); + return 1; + } + switch(curChar) + { + case 38: + if ((active0 & 0x200000L) != 0L) + return jjStopAtPos(1, 21); + break; + case 61: + if ((active0 & 0x8000L) != 0L) + return jjStopAtPos(1, 15); + else if ((active0 & 0x10000L) != 0L) + return jjStopAtPos(1, 16); + else if ((active0 & 0x80000L) != 0L) + return jjStopAtPos(1, 19); + else if ((active0 & 0x100000L) != 0L) + return jjStopAtPos(1, 20); + break; + case 97: + return jjMoveStringLiteralDfa2_0(active0, 0x20L); + case 109: + return jjMoveStringLiteralDfa2_0(active0, 0x40L); + default : + break; + } + return jjStartNfa_0(0, active0); +} +static private int jjMoveStringLiteralDfa2_0(long old0, long active0){ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(0, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(1, active0); + return 2; + } + switch(curChar) + { + case 78: + if ((active0 & 0x20L) != 0L) + return jjStartNfaWithStates_0(2, 5, 20); + break; + case 112: + return jjMoveStringLiteralDfa3_0(active0, 0x40L); + default : + break; + } + return jjStartNfa_0(1, active0); +} +static private int jjMoveStringLiteralDfa3_0(long old0, long active0){ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(1, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(2, active0); + return 3; + } + switch(curChar) + { + case 111: + return jjMoveStringLiteralDfa4_0(active0, 0x40L); + default : + break; + } + return jjStartNfa_0(2, active0); +} +static private int jjMoveStringLiteralDfa4_0(long old0, long active0){ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(2, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(3, active0); + return 4; + } + switch(curChar) + { + case 114: + return jjMoveStringLiteralDfa5_0(active0, 0x40L); + default : + break; + } + return jjStartNfa_0(3, active0); +} +static private int jjMoveStringLiteralDfa5_0(long old0, long active0){ + if (((active0 &= old0)) == 0L) + return jjStartNfa_0(3, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_0(4, active0); + return 5; + } + switch(curChar) + { + case 116: + if ((active0 & 0x40L) != 0L) + return jjStartNfaWithStates_0(5, 6, 20); + break; + default : + break; + } + return jjStartNfa_0(4, active0); +} +static private int jjStartNfaWithStates_0(int pos, int kind, int state) +{ + jjmatchedKind = kind; + jjmatchedPos = pos; + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { return pos + 1; } + return jjMoveNfa_0(state, pos + 1); +} +static final long[] jjbitVec0 = { + 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL +}; static private int jjMoveNfa_0(int startState, int curPos) { int startsAt = 0; - jjnewStateCnt = 2; + jjnewStateCnt = 40; int i = 1; jjstateSet[0] = startState; int kind = 0x7fffffff; @@ -66,19 +253,186 @@ static private int jjMoveNfa_0(int startState, int curPos) { switch(jjstateSet[--i]) { + case 12: + if ((0x3ff800000000000L & l) != 0L) + { + if (kind > 7) + kind = 7; + { jjCheckNAdd(20); } + } + else if (curChar == 59) + { + if (kind > 4) + kind = 4; + } + else if (curChar == 46) + { jjCheckNAdd(1); } + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAddTwoStates(5, 6); } + else if (curChar == 47) + { jjAddStates(0, 1); } + else if (curChar == 59) + jjstateSet[jjnewStateCnt++] = 17; + if ((0x3fe000000000000L & l) != 0L) + { + if (kind > 2) + kind = 2; + { jjCheckNAddStates(2, 5); } + } + else if (curChar == 48) + { + if (kind > 2) + kind = 2; + { jjCheckNAddTwoStates(0, 22); } + } + break; + case 29: + if ((0x3ff800000000000L & l) != 0L) + { + if (kind > 7) + kind = 7; + { jjCheckNAdd(20); } + } + else if (curChar == 42) + { jjCheckNAddTwoStates(35, 36); } + if (curChar == 47) + { jjCheckNAddStates(6, 8); } + break; case 0: + if (curChar == 46) + { jjCheckNAdd(1); } + break; + case 1: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 1) + kind = 1; + { jjCheckNAddTwoStates(1, 2); } + break; + case 3: + if ((0x280000000000L & l) != 0L) + { jjCheckNAdd(4); } + break; + case 4: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 1) + kind = 1; + { jjCheckNAdd(4); } + break; + case 5: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAddTwoStates(5, 6); } + break; + case 7: + if ((0x280000000000L & l) != 0L) + { jjCheckNAdd(8); } + break; + case 8: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 1) + kind = 1; + { jjCheckNAdd(8); } + break; + case 17: + if (curChar == 10 && kind > 4) + kind = 4; + break; + case 18: + if (curChar == 59) + jjstateSet[jjnewStateCnt++] = 17; + break; + case 19: + if (curChar == 59 && kind > 4) + kind = 4; + break; + case 20: + if ((0x3ff800000000000L & l) == 0L) + break; + if (kind > 7) + kind = 7; + { jjCheckNAdd(20); } + break; + case 21: + if (curChar != 48) + break; + if (kind > 2) + kind = 2; + { jjCheckNAddTwoStates(0, 22); } + break; + case 23: + if ((0x280000000000L & l) != 0L) + { jjCheckNAdd(24); } + break; + case 24: + if ((0x3ff000000000000L & l) == 0L) + break; + if (kind > 2) + kind = 2; + { jjCheckNAdd(24); } + break; + case 25: if ((0x3fe000000000000L & l) == 0L) break; - if (kind > 3) - kind = 3; - { jjCheckNAdd(1); } + if (kind > 2) + kind = 2; + { jjCheckNAddStates(2, 5); } break; - case 1: + case 26: + if ((0x3ff000000000000L & l) != 0L) + { jjCheckNAddTwoStates(26, 0); } + break; + case 27: if ((0x3ff000000000000L & l) == 0L) break; - if (kind > 3) - kind = 3; - { jjCheckNAdd(1); } + if (kind > 2) + kind = 2; + { jjCheckNAddTwoStates(27, 22); } + break; + case 28: + if (curChar == 47) + { jjAddStates(0, 1); } + break; + case 30: + if ((0xffffffffffffdbffL & l) != 0L) + { jjCheckNAddStates(6, 8); } + break; + case 31: + if ((0x2400L & l) != 0L && kind > 11) + kind = 11; + break; + case 32: + if (curChar == 10 && kind > 11) + kind = 11; + break; + case 33: + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 32; + break; + case 34: + if (curChar == 42) + { jjCheckNAddTwoStates(35, 36); } + break; + case 35: + if ((0xfffffbffffffffffL & l) != 0L) + { jjCheckNAddTwoStates(35, 36); } + break; + case 36: + if (curChar == 42) + { jjAddStates(9, 10); } + break; + case 37: + if ((0xffff7bffffffffffL & l) != 0L) + { jjCheckNAddTwoStates(38, 36); } + break; + case 38: + if ((0xfffffbffffffffffL & l) != 0L) + { jjCheckNAddTwoStates(38, 36); } + break; + case 39: + if (curChar == 47 && kind > 12) + kind = 12; break; default : break; } @@ -91,6 +445,76 @@ static private int jjMoveNfa_0(int startState, int curPos) { switch(jjstateSet[--i]) { + case 12: + if ((0x7fffffe07fffffeL & l) != 0L) + { + if (kind > 7) + kind = 7; + { jjCheckNAdd(20); } + } + if (curChar == 70) + jjstateSet[jjnewStateCnt++] = 15; + else if (curChar == 84) + jjstateSet[jjnewStateCnt++] = 11; + break; + case 29: + case 20: + if ((0x7fffffe07fffffeL & l) == 0L) + break; + if (kind > 7) + kind = 7; + { jjCheckNAdd(20); } + break; + case 2: + if ((0x2000000020L & l) != 0L) + { jjAddStates(11, 12); } + break; + case 6: + if ((0x2000000020L & l) != 0L) + { jjAddStates(13, 14); } + break; + case 9: + if (curChar == 101 && kind > 3) + kind = 3; + break; + case 10: + if (curChar == 117) + { jjCheckNAdd(9); } + break; + case 11: + if (curChar == 114) + jjstateSet[jjnewStateCnt++] = 10; + break; + case 13: + if (curChar == 115) + { jjCheckNAdd(9); } + break; + case 14: + if (curChar == 108) + jjstateSet[jjnewStateCnt++] = 13; + break; + case 15: + if (curChar == 97) + jjstateSet[jjnewStateCnt++] = 14; + break; + case 16: + if (curChar == 70) + jjstateSet[jjnewStateCnt++] = 15; + break; + case 22: + if ((0x2000000020L & l) != 0L) + { jjAddStates(15, 16); } + break; + case 30: + { jjAddStates(6, 8); } + break; + case 35: + { jjCheckNAddTwoStates(35, 36); } + break; + case 37: + case 38: + { jjCheckNAddTwoStates(38, 36); } + break; default : break; } } while(i != startsAt); @@ -103,6 +527,19 @@ static private int jjMoveNfa_0(int startState, int curPos) { switch(jjstateSet[--i]) { + case 30: + if ((jjbitVec0[i2] & l2) != 0L) + { jjAddStates(6, 8); } + break; + case 35: + if ((jjbitVec0[i2] & l2) != 0L) + { jjCheckNAddTwoStates(35, 36); } + break; + case 37: + case 38: + if ((jjbitVec0[i2] & l2) != 0L) + { jjCheckNAddTwoStates(38, 36); } + break; default : break; } } while(i != startsAt); @@ -114,7 +551,7 @@ static private int jjMoveNfa_0(int startState, int curPos) kind = 0x7fffffff; } ++curPos; - if ((i = jjnewStateCnt) == (startsAt = 2 - (jjnewStateCnt = startsAt))) + if ((i = jjnewStateCnt) == (startsAt = 40 - (jjnewStateCnt = startsAt))) return curPos; try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { return curPos; } @@ -123,7 +560,9 @@ static private int jjMoveNfa_0(int startState, int curPos) /** Token literal values. */ public static final String[] jjstrLiteralImages = { -"", null, null, null, "\12", "\53", "\55", "\52", "\57", "\50", "\51", }; +"", null, null, null, null, "\116\141\116", "\151\155\160\157\162\164", null, +null, null, null, null, null, "\173", "\175", "\75\75", "\76\75", "\76", "\74", +"\74\75", "\41\75", "\46\46", "\53", "\55", "\52", "\57", "\45", "\50", "\51", "\41", }; static protected Token jjFillToken() { final Token t; @@ -147,7 +586,9 @@ static protected Token jjFillToken() return t; } -static final int[] jjnextStates = {0 +static final int[] jjnextStates = { + 29, 34, 26, 0, 27, 22, 30, 31, 33, 37, 39, 3, 4, 7, 8, 23, + 24, }; static int curLexState = 0; @@ -179,7 +620,7 @@ public static Token getNextToken() } try { input_stream.backup(0); - while (curChar <= 32 && (0x100000200L & (1L << curChar)) != 0L) + while (curChar <= 32 && (0x100000600L & (1L << curChar)) != 0L) curChar = input_stream.BeginToken(); } catch (java.io.IOException e1) { continue EOFLoop; } @@ -268,6 +709,13 @@ static private void jjCheckNAddTwoStates(int state1, int state2) jjCheckNAdd(state2); } +static private void jjCheckNAddStates(int start, int end) +{ + do { + jjCheckNAdd(jjnextStates[start]); + } while (start++ != end); +} + /** Constructor. */ public CompilateurTokenManager(SimpleCharStream stream){ @@ -301,7 +749,7 @@ static private void jjCheckNAddTwoStates(int state1, int state2) { int i; jjround = 0x80000001; - for (i = 2; i-- > 0;) + for (i = 40; i-- > 0;) jjrounds[i] = 0x80000000; } @@ -330,13 +778,14 @@ public static final String[] lexStateNames = { /** Lex State array. */ public static final int[] jjnewLexState = { - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, }; static final long[] jjtoToken = { - 0x7f9L, + 0x3fffe0ffL, }; static final long[] jjtoSkip = { - 0x6L, + 0x1f00L, }; static final long[] jjtoSpecial = { 0x0L, @@ -346,8 +795,8 @@ static final long[] jjtoMore = { }; static protected SimpleCharStream input_stream; - static private final int[] jjrounds = new int[2]; - static private final int[] jjstateSet = new int[2 * 2]; + static private final int[] jjrounds = new int[40]; + static private final int[] jjstateSet = new int[2 * 40]; private static final StringBuilder jjimage = new StringBuilder(); private static StringBuilder image = jjimage; private static int jjimageLen; diff --git a/ParseException.class b/ParseException.class index 29184c2cd6f645b83b49b2ef98ba500fa10b9476..fbfcd52dc4678e31125d3765cf5f984ae2318b9c 100644 Binary files a/ParseException.class and b/ParseException.class differ diff --git a/SimpleCharStream.class b/SimpleCharStream.class index 254e09b6f6901caf5575cbd7de42b45338c2c622..5e58d5b98c7130d4c549fe8236a6fc5ca790c2a9 100644 Binary files a/SimpleCharStream.class and b/SimpleCharStream.class differ diff --git a/Token.class b/Token.class index c95e81ca1441e72eed0f164afce31bfd64ea7a00..3fd4d89f913973f5a02133375ab3f8aad812b78e 100644 Binary files a/Token.class and b/Token.class differ diff --git a/TokenMgrError.class b/TokenMgrError.class index a009d022fb150c24e8cc1918dd5d7fc8c6423cf2..0b8021ce2be08b6c1082055483f72ae92c6ea65b 100644 Binary files a/TokenMgrError.class and b/TokenMgrError.class differ diff --git a/malib b/malib new file mode 100644 index 0000000000000000000000000000000000000000..36efd574f6d9e0b6b3942d64bc0f105c78388f26 --- /dev/null +++ b/malib @@ -0,0 +1,4 @@ +CsteNb 2 +CsteNb 1 +AddiNb + diff --git a/mi-makefile.sh b/mi-makefile.sh index 70a28f2f2f6b21cf451fcb0cf5ba7e90e5b9aea5..7708b8ce272e3476fc6de3b7c272d249d216a5c1 100755 --- a/mi-makefile.sh +++ b/mi-makefile.sh @@ -41,6 +41,7 @@ done if [ $# -eq 1 ]; then exit 1 fi +javac AST/*.java # program launching javacc Compilateur.jj javac *.java diff --git a/test.js b/test.js new file mode 100644 index 0000000000000000000000000000000000000000..042cd46c3f432ec7d501460ed387a2177cdaf385 --- /dev/null +++ b/test.js @@ -0,0 +1,8 @@ +import malib; +/// True + False +/* cgvhjbkn +1 */ +{ + 9-1; + +} +5*5;