Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding the operation of unary minus #27

Open
wants to merge 1 commit into
base: atividade1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions eplan.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/target/generated-sources/cup" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/target/generated-sources/jflex" isTestSource="false" generated="true" />
<excludeFolder url="file://$MODULE_DIR$/target/classes" />
<excludeFolder url="file://$MODULE_DIR$/target/maven-archiver" />
<excludeFolder url="file://$MODULE_DIR$/target/surefire" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: com.beust:jcommander:1.58" level="project" />
<orderEntry type="library" name="Maven: com.github.vbmacher:java-cup-runtime:11b-20160615" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.4" level="project" />
<orderEntry type="library" name="Maven: io.javaslang:javaslang:2.0.4" level="project" />
<orderEntry type="library" name="Maven: io.javaslang:javaslang-match:2.0.4" level="project" />
<orderEntry type="library" name="Maven: io.javaslang:javaslang-render:2.0.0" level="project" />
<orderEntry type="library" name="Maven: org.bytedeco.javacpp-presets:llvm:3.8.0-1.2" level="project" />
<orderEntry type="library" name="Maven: org.bytedeco:javacpp:1.2" level="project" />
<orderEntry type="library" name="Maven: org.bytedeco.javacpp-presets:llvm:linux-x86_64:3.8.0-1.2" level="project" />
</component>
</module>
7 changes: 4 additions & 3 deletions src/main/cup/parser.cup
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ term ::=
;

factor ::=
LITNUM:x {: RESULT = new ExpNum(x); :}
| LPAREN exp:x RPAREN {: RESULT = x; :}
;
LITNUM:x {: RESULT = new ExpNum(x); :}
| MINUS factor:x {: RESULT = new ExpNegate(x); :}
| LPAREN exp:x RPAREN {: RESULT = x; :}
;
30 changes: 30 additions & 0 deletions src/main/java/absyn/ExpNegate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package absyn;


import javaslang.collection.Tree;
import static org.bytedeco.javacpp.LLVM.*;

/**
* Created by christian on 10/20/16.
*/

public class ExpNegate extends Exp{

public final Exp arg;

public ExpNegate(Exp arg) {
this.arg = arg;
}

@Override
public LLVMValueRef codegen(LLVMModuleRef module, LLVMBuilderRef builder) {
final LLVMValueRef v_arg = arg.codegen(module,builder);
final LLVMValueRef zero = LLVMConstReal(LLVMDoubleType(), 0);
return LLVMBuildFSub(builder, zero, v_arg, "subtmp");
}

@Override
public Tree.Node<String> toTree() {
return Tree.of("ExpNegate", arg.toTree());
}
}