Commit 5f2862d7 authored by LucasDANIELE's avatar LucasDANIELE
Browse files

Initial commit

parents
SRC=src
TEST=test
CLASSES_DEST=build/classes
TESTS_DEST=build/test
LIB=lib
PACKAGE_RACINE=fr/insarouen/asi/compilation/basic
PACKAGE_MOTEUR=$(PACKAGE_RACINE)/moteur
PACKAGE_EXPRESSION=$(PACKAGE_MOTEUR)/expression
PACKAGE_AST=$(PACKAGE_MOTEUR)/arbreSyntaxiqueAbstrait
PACKAGE_INTER=$(PACKAGE_RACINE)/analyseurs
all: javacc javac tests
javacc: $(SRC)/$(PACKAGE_INTER)/AnalyseurSyntaxique.java
javac: main moteur expression ast analyseurSyntaxique
main: $(CLASSES_DEST)/$(PACKAGE_RACINE)/Main.class
moteur: $(CLASSES_DEST)/$(PACKAGE_MOTEUR)/IdentifiantException.class $(CLASSES_DEST)/$(PACKAGE_MOTEUR)/IdentifiantInconnuException.class $(CLASSES_DEST)/$(PACKAGE_MOTEUR)/Identifiant.class $(CLASSES_DEST)/$(PACKAGE_MOTEUR)/LabelInconnuException.class $(CLASSES_DEST)/$(PACKAGE_MOTEUR)/Memoire.class $(CLASSES_DEST)/$(PACKAGE_MOTEUR)/MoteurException.class $(CLASSES_DEST)/$(PACKAGE_MOTEUR)/OperationInterditeException.class $(CLASSES_DEST)/$(PACKAGE_MOTEUR)/Programme.class $(CLASSES_DEST)/$(PACKAGE_MOTEUR)/TypeIncompatibleException.class $(CLASSES_DEST)/$(PACKAGE_MOTEUR)/TypeValeur.class $(CLASSES_DEST)/$(PACKAGE_MOTEUR)/Valeur.class $(CLASSES_DEST)/$(PACKAGE_MOTEUR)/VariableInconnueException.class $(CLASSES_DEST)/$(PACKAGE_MOTEUR)/Variable.class
expression: $(CLASSES_DEST)/$(PACKAGE_EXPRESSION)/Addition.class $(CLASSES_DEST)/$(PACKAGE_EXPRESSION)/Constante.class $(CLASSES_DEST)/$(PACKAGE_EXPRESSION)/Difference.class $(CLASSES_DEST)/$(PACKAGE_EXPRESSION)/Division.class $(CLASSES_DEST)/$(PACKAGE_EXPRESSION)/Egalite.class $(CLASSES_DEST)/$(PACKAGE_EXPRESSION)/Et.class $(CLASSES_DEST)/$(PACKAGE_EXPRESSION)/ExpressionBinaire.class $(CLASSES_DEST)/$(PACKAGE_EXPRESSION)/Expression.class $(CLASSES_DEST)/$(PACKAGE_EXPRESSION)/ExpressionUnaire.class $(CLASSES_DEST)/$(PACKAGE_EXPRESSION)/IdentifiantDeVariable.class $(CLASSES_DEST)/$(PACKAGE_EXPRESSION)/Moins.class $(CLASSES_DEST)/$(PACKAGE_EXPRESSION)/Multiplication.class $(CLASSES_DEST)/$(PACKAGE_EXPRESSION)/Non.class $(CLASSES_DEST)/$(PACKAGE_EXPRESSION)/Ou.class $(CLASSES_DEST)/$(PACKAGE_EXPRESSION)/PlusGrand.class $(CLASSES_DEST)/$(PACKAGE_EXPRESSION)/PlusGrandOuEgale.class $(CLASSES_DEST)/$(PACKAGE_EXPRESSION)/PlusPetit.class $(CLASSES_DEST)/$(PACKAGE_EXPRESSION)/PlusPetitOuEgale.class $(CLASSES_DEST)/$(PACKAGE_EXPRESSION)/Soustraction.class
ast: $(CLASSES_DEST)/$(PACKAGE_AST)/Affectation.class $(CLASSES_DEST)/$(PACKAGE_AST)/AllerA.class $(CLASSES_DEST)/$(PACKAGE_AST)/Ecrire.class $(CLASSES_DEST)/$(PACKAGE_AST)/Instruction.class $(CLASSES_DEST)/$(PACKAGE_AST)/Lire.class $(CLASSES_DEST)/$(PACKAGE_AST)/Rien.class $(CLASSES_DEST)/$(PACKAGE_AST)/SiAlors.class
analyseurSyntaxique: $(CLASSES_DEST)/$(PACKAGE_INTER)/AnalyseurSyntaxiqueConstants.class $(CLASSES_DEST)/$(PACKAGE_INTER)/AnalyseurSyntaxique.class $(CLASSES_DEST)/$(PACKAGE_INTER)/AnalyseurSyntaxiqueTokenManager.class $(CLASSES_DEST)/$(PACKAGE_INTER)/ParseException.class $(CLASSES_DEST)/$(PACKAGE_INTER)/SimpleCharStream.class $(CLASSES_DEST)/$(PACKAGE_INTER)/Token.class $(CLASSES_DEST)/$(PACKAGE_INTER)/TokenMgrError.class
tests: $(TESTS_DEST)/$(PACKAGE_MOTEUR)/ValeurTest.class
$(SRC)/$(PACKAGE_INTER)/AnalyseurSyntaxique.java: $(SRC)/$(PACKAGE_INTER)/AnalyseurSyntaxique.jj
javacc -OUTPUT_DIRECTORY=$(SRC)/$(PACKAGE_INTER)/ $<
$(CLASSES_DEST)/%.class: $(SRC)/%.java
javac -d $(CLASSES_DEST) -cp $(CLASSES_DEST) -sourcepath src $<
$(TESTS_DEST)/%.class: $(TEST)/%.java
javac -d $(TESTS_DEST) -cp $(LIB)/junit-4.10.jar:$(CLASSES_DEST) -sourcepath src $<
clean:
rm $(SRC)/$(PACKAGE_INTER)/*.java
rm -rf $(CLASSES_DEST)/*
rm -rf $(TESTS_DEST)/*
#!/bin/bash
java -cp build/classes fr.insarouen.asi.compilation.basic.Main $*
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="bASIcACompleter" default="default" basedir=".">
<description>Builds, tests, and runs the project bASIcACompleter.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar: JAR building
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="bASIcACompleter-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->
</project>
debut : lire n
si n<2 alors allera debut
i=1
boucle: s=0
j=1
somme: si j>i/2 alors allera finsomme
si j*(i/j)==i alors s=s+j
j=j+1
allera somme
finsomme: si s==i alors ecrire i
i=i+1
si i<=n alors allera boucle
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build
This diff is collapsed.
build.xml.data.CRC32=f2145198
build.xml.script.CRC32=e9aa164d
build.xml.stylesheet.CRC32=8064a381@1.75.2.48
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=f2145198
nbproject/build-impl.xml.script.CRC32=e7625947
nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.75.2.48
application.args=exemple.bas
compile.on.save=true
user.properties.file=/home/delestre/.netbeans/8.0.1/build.properties
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/home/delestre/Documents/Cours/ASI/Compilation/Projets/java/bASIcACompleter/src/fr/insarouen/asi/compilation/basic/analyseurs/AnalyseurSyntaxique.jj</file>
</group>
</open-files>
</project-private>
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
application.title=bASIcACompleter
application.vendor=delestre
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned:
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
# Only compile against the classpath explicitly listed here:
build.sysclasspath=ignore
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
# Uncomment to specify the preferred debugger connection transport:
#debug.transport=dt_socket
debug.classpath=\
${run.classpath}
debug.test.classpath=\
${run.test.classpath}
# Files in build.classes.dir which should be excluded from distribution jar
dist.archive.excludes=
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/bASIcACompleter.jar
dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
includes=**
jar.compress=false
javac.classpath=
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.processorpath=\
${javac.classpath}
javac.source=1.8
javac.target=1.8
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}:\
${libs.junit_4.classpath}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=${source.encoding}
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
main.class=fr.insarouen.asi.compilation.basic.Main
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
platform.active=default_platform
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
# Space-separated list of JVM arguments used when running the project.
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
# To set system properties for unit tests define test-sys-prop.name=value:
run.jvmargs=
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
source.encoding=UTF-8
src.dir=src
test.src.dir=test
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>bASIcACompleter</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package fr.insarouen.asi.compilation.basic;
import fr.insarouen.asi.compilation.basic.analyseurs.AnalyseurSyntaxique;
import fr.insarouen.asi.compilation.basic.analyseurs.ParseException;
import fr.insarouen.asi.compilation.basic.moteur.arbreSyntaxiqueAbstrait.Affectation;
import fr.insarouen.asi.compilation.basic.moteur.Identifiant;
import fr.insarouen.asi.compilation.basic.moteur.IdentifiantException;
import fr.insarouen.asi.compilation.basic.moteur.Memoire;
import fr.insarouen.asi.compilation.basic.moteur.Programme;
import fr.insarouen.asi.compilation.basic.moteur.Valeur;
import fr.insarouen.asi.compilation.basic.moteur.VariableInconnueException;
import fr.insarouen.asi.compilation.basic.moteur.expression.Addition;
import fr.insarouen.asi.compilation.basic.moteur.expression.Constante;
import fr.insarouen.asi.compilation.basic.moteur.expression.IdentifiantDeVariable;
import fr.insarouen.asi.compilation.basic.moteur.expression.Multiplication;
import fr.insarouen.asi.compilation.basic.moteur.expression.Soustraction;
import fr.insarouen.asi.compilation.basic.moteur.TypeIncompatibleException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
/**
*
* @author delestre
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws TypeIncompatibleException, IdentifiantException, VariableInconnueException {
AnalyseurSyntaxique analyseurSyntaxique;
Programme prg;
if (args.length == 1) {
try {
analyseurSyntaxique = new AnalyseurSyntaxique(new FileInputStream(args[0]));
prg = analyseurSyntaxique.programme();
prg.executer();
} catch (FileNotFoundException e) {
System.err.println("Fichier " + args[0] + "inexistant");
} catch (ParseException | IdentifiantException e) {
System.err.println(e.getMessage());
}
} else {
System.out.println("Utilisation : java fr.insarouen.asi.compilation.basic.Main nomDuFichierBasic");
}
}
}
options {
LOOKAHEAD = 1;
STATIC = false;
IGNORE_CASE = false;
}
PARSER_BEGIN(AnalyseurSyntaxique)
public class AnalyseurSyntaxique {}
PARSER_END(AnalyseurSyntaxique)
SKIP : {}
TOKEN : {}
package fr.insarouen.asi.compilation.basic.moteur;
import java.util.Objects;
import java.util.regex.Pattern;
public class Identifiant {
private String id;
public Identifiant(String str) throws IdentifiantException {
if (!Pattern.matches("[_a-zA-Z][_a-zA-Z0-9]*",str))
throw new IdentifiantException("la chaine de caractères "+str+" n'est pas un identifiant valide");
else
id = str.toLowerCase();
}
@Override
public int hashCode() {
int hash = 7;
hash = 29 * hash + Objects.hashCode(this.id);
return hash;
}
@Override
public boolean equals(Object o) {
if (o==this) {
return true;
} else if (o instanceof Identifiant) {
return ((Identifiant)o).toString().equals(toString());
}
return false;
}
@Override
public String toString() {
return id;
}
}
package fr.insarouen.asi.compilation.basic.moteur;
public class IdentifiantException extends MoteurException {
public IdentifiantException(String s) {
super(s);
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package fr.insarouen.asi.compilation.basic.moteur;
/**
*
* @author delestre
*/
public class IdentifiantInconnuException extends MoteurException {
private Identifiant idAyantProvoqueException;
public IdentifiantInconnuException(Identifiant id) {
super("");
idAyantProvoqueException = id;
}
public Identifiant identifiantAyantProvoqueException() {
return idAyantProvoqueException;
}
public String toString() {
return "l'indentifiant "+identifiantAyantProvoqueException()+" est inconnu";
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package fr.insarouen.asi.compilation.basic.moteur;
/**
*
* @author delestre
*/
public class LabelInconnuException extends IdentifiantInconnuException {
public LabelInconnuException(Identifiant id) {
super(id);
}
public String toString() {
return "le label "+identifiantAyantProvoqueException()+" est inconnu";
}
}
package fr.insarouen.asi.compilation.basic.moteur;
import java.util.Map;
import java.util.HashMap;
public class Memoire {
private final Map<Identifiant,Valeur> lesVariables;
public Memoire() {
lesVariables = new HashMap<>();
}
public void setValeur(Identifiant id, Valeur val) {
lesVariables.put(id, val);
}
public Valeur getValeur(Identifiant id) throws VariableInconnueException {
if (!lesVariables.containsKey(id)) {
throw new VariableInconnueException(id);
}
return lesVariables.get(id);
}
@Override
public String toString() {
StringBuilder res = new StringBuilder("");
for (Identifiant id : lesVariables.keySet()) {
res.append(id.toString());
res.append("=");
res.append(lesVariables.get(id).toString());
res.append(" ");
}
return res.toString();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment