Homework 1
This commit is contained in:
parent
49bca7f856
commit
12f678a924
43 changed files with 3703 additions and 0 deletions
11
.classpath
Normal file
11
.classpath
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="test"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="lib" path="lib/antlr-4.4-complete.jar"/>
|
||||
<classpathentry kind="lib" path="lib/junit-4.12.jar"/>
|
||||
<classpathentry kind="lib" path="lib/hamcrest-core-1.3.jar"/>
|
||||
<classpathentry kind="lib" path="lib/javaliParserObf.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
245
.gitignore
vendored
Normal file
245
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,245 @@
|
|||
|
||||
# Created by https://www.gitignore.io/api/java,linux,macos,windows,intellij,intellij+all
|
||||
# Edit at https://www.gitignore.io/?templates=java,linux,macos,windows,intellij,intellij+all
|
||||
|
||||
### Intellij ###
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
|
||||
# Generated files
|
||||
.idea/**/contentModel.xml
|
||||
|
||||
# Sensitive or high-churn files
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
|
||||
# Gradle
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Gradle and Maven with auto-import
|
||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||
# since they will be recreated, and may cause churn. Uncomment if using
|
||||
# auto-import.
|
||||
# .idea/modules.xml
|
||||
# .idea/*.iml
|
||||
# .idea/modules
|
||||
# *.iml
|
||||
# *.ipr
|
||||
|
||||
# CMake
|
||||
cmake-build-*/
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
# File-based project format
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
# Editor-based Rest Client
|
||||
.idea/httpRequests
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
### Intellij Patch ###
|
||||
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
|
||||
|
||||
# *.iml
|
||||
# modules.xml
|
||||
# .idea/misc.xml
|
||||
# *.ipr
|
||||
|
||||
# Sonarlint plugin
|
||||
.idea/**/sonarlint/
|
||||
|
||||
# SonarQube Plugin
|
||||
.idea/**/sonarIssues.xml
|
||||
|
||||
# Markdown Navigator plugin
|
||||
.idea/**/markdown-navigator.xml
|
||||
.idea/**/markdown-navigator/
|
||||
|
||||
### Intellij+all ###
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff
|
||||
|
||||
# Generated files
|
||||
|
||||
# Sensitive or high-churn files
|
||||
|
||||
# Gradle
|
||||
|
||||
# Gradle and Maven with auto-import
|
||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||
# since they will be recreated, and may cause churn. Uncomment if using
|
||||
# auto-import.
|
||||
# .idea/modules.xml
|
||||
# .idea/*.iml
|
||||
# .idea/modules
|
||||
# *.iml
|
||||
# *.ipr
|
||||
|
||||
# CMake
|
||||
|
||||
# Mongo Explorer plugin
|
||||
|
||||
# File-based project format
|
||||
|
||||
# IntelliJ
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
|
||||
# JIRA plugin
|
||||
|
||||
# Cursive Clojure plugin
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
|
||||
# Editor-based Rest Client
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
|
||||
### Intellij+all Patch ###
|
||||
# Ignores the whole .idea folder and all .iml files
|
||||
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
|
||||
#
|
||||
#.idea/
|
||||
#
|
||||
## Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
|
||||
#
|
||||
#*.iml
|
||||
#modules.xml
|
||||
#.idea/misc.xml
|
||||
#*.ipr
|
||||
#
|
||||
## Sonarlint plugin
|
||||
#.idea/sonarlint
|
||||
#
|
||||
### Java ###
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
|
||||
### Linux ###
|
||||
*~
|
||||
|
||||
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||
.fuse_hidden*
|
||||
|
||||
# KDE directory preferences
|
||||
.directory
|
||||
|
||||
# Linux trash folder which might appear on any partition or disk
|
||||
.Trash-*
|
||||
|
||||
# .nfs files are created when an open file is removed but is still being accessed
|
||||
.nfs*
|
||||
|
||||
### macOS ###
|
||||
# General
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
### Windows ###
|
||||
# Windows thumbnail cache files
|
||||
Thumbs.db
|
||||
Thumbs.db:encryptable
|
||||
ehthumbs.db
|
||||
ehthumbs_vista.db
|
||||
|
||||
# Dump file
|
||||
*.stackdump
|
||||
|
||||
# Folder config file
|
||||
[Dd]esktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msix
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
# End of https://www.gitignore.io/api/java,linux,macos,windows,intellij,intellij+all
|
||||
23
.project
Normal file
23
.project
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Javali-HW1</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
2
.settings/org.eclipse.core.resources.prefs
Normal file
2
.settings/org.eclipse.core.resources.prefs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
||||
12
.settings/org.eclipse.jdt.core.prefs
Normal file
12
.settings/org.eclipse.jdt.core.prefs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
5
Grade.txt
Normal file
5
Grade.txt
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
Grade: 24/25
|
||||
|
||||
31/31 tests passed [20/20]
|
||||
|
||||
Submitted test cases [4/5]
|
||||
87
build.xml
Normal file
87
build.xml
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
<project name="compiler-design" default="compile" basedir="." xmlns:jacoco="antlib:org.jacoco.ant">
|
||||
|
||||
<!-- A very simple ant file that primarily exists to run cup and lex;
|
||||
it also includes targets to build the compiler and run tests for those
|
||||
who would rather not use Eclipse -->
|
||||
|
||||
<!-- Set project properties. -->
|
||||
<property name="src.dir" value="${basedir}/src"/>
|
||||
<property name="test.dir" value="${basedir}/test"/>
|
||||
<property name="javali_tests.dir" value="${basedir}/javali_tests"/>
|
||||
<property name="parser.dir" value="${src.dir}/cd/frontend/parser"/>
|
||||
<property name="parser.jar" value="${basedir}/lib/javaliParserObf.jar"/>
|
||||
<property name="build.dir" value="${basedir}/bin"/>
|
||||
<property name="junit.jar" value="${basedir}/lib/junit-4.12.jar"/>
|
||||
<property name="hamcrest.jar" value="${basedir}/lib/hamcrest-core-1.3.jar"/>
|
||||
<property name="antlr.jar" value="${basedir}/lib/antlr-4.4-complete.jar"/>
|
||||
<property name="antlr.profile" value="false"/>
|
||||
<property name="antlr.report" value="false"/>
|
||||
<property name="jacocoant.jar" value="${basedir}/lib/jacocoant.jar"/>
|
||||
<property name="coverage.file" location="${build.dir}/jacoco.exec"/>
|
||||
<property name="min.coverage" value="0.5"/>
|
||||
<property name="coverage.check" value="cd.frontend.*:cd.backend.*"/>
|
||||
|
||||
|
||||
|
||||
<!-- Cleans generated code, but NOT the parser source! -->
|
||||
<target name="clean">
|
||||
<delete dir="${build.dir}"/>
|
||||
</target>
|
||||
|
||||
|
||||
<!-- Builds the compiler framework for HW1. -->
|
||||
<target name="compile">
|
||||
<mkdir dir="${build.dir}"/>
|
||||
|
||||
<javac debug="true" destdir="${build.dir}" includeantruntime="false">
|
||||
<src path="${src.dir}"/>
|
||||
<src path="${test.dir}"/>
|
||||
<classpath>
|
||||
<pathelement location="${antlr.jar}"/>
|
||||
<pathelement location="${junit.jar}"/>
|
||||
<pathelement location="${hamcrest.jar}"/>
|
||||
<pathelement location="${parser.jar}"/>
|
||||
</classpath>
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<!-- Deletes all byproducts of running the tests -->
|
||||
<target name="clean-test">
|
||||
<delete>
|
||||
<fileset dir="${javali_tests.dir}" includes="**/*.err"/>
|
||||
<fileset dir="${javali_tests.dir}" includes="**/*.s"/>
|
||||
<fileset dir="${javali_tests.dir}" includes="**/*.bin"/>
|
||||
<fileset dir="${javali_tests.dir}" includes="**/*.dot"/>
|
||||
<fileset dir="${javali_tests.dir}" includes="**/*.exe"/>
|
||||
<fileset dir="${javali_tests.dir}" includes="**/*.ref"/>
|
||||
</delete>
|
||||
</target>
|
||||
|
||||
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
|
||||
<classpath path="${jacocoant.jar}"/>
|
||||
</taskdef>
|
||||
|
||||
<!-- Runs the tests. Use the compile target first! -->
|
||||
<target name="test" depends="compile">
|
||||
<jacoco:coverage destfile="${coverage.file}">
|
||||
<junit fork="true" forkmode="once" failureproperty="tests-failed" outputtoformatters="false">
|
||||
<formatter type="brief" usefile="false"/>
|
||||
<batchtest skipNonTests="true">
|
||||
<fileset dir="bin" includes="**/*.class" />
|
||||
</batchtest>
|
||||
<assertions enablesystemassertions="true" />
|
||||
<sysproperty key="cd.meta_hidden.Version" value="REFERENCE" />
|
||||
<classpath>
|
||||
<pathelement location="${build.dir}"/>
|
||||
<pathelement location="${junit.jar}"/>
|
||||
<pathelement location="${hamcrest.jar}"/>
|
||||
<pathelement location="${antlr.jar}"/>
|
||||
<pathelement location="${parser.jar}"/>
|
||||
</classpath>
|
||||
</junit>
|
||||
</jacoco:coverage>
|
||||
<fail if="tests-failed" />
|
||||
</target>
|
||||
|
||||
|
||||
</project>
|
||||
24
javali_tests/HW1/EightVariables.javali
Normal file
24
javali_tests/HW1/EightVariables.javali
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/* Test expression evaluation with 8 variables */
|
||||
class Main {
|
||||
void main() {
|
||||
int r1, r2, r3;
|
||||
int i0, i1, i2, i3, i4, i5, i6, i7;
|
||||
|
||||
i0 = 0;
|
||||
i1 = 1;
|
||||
i2 = 2;
|
||||
i3 = 3;
|
||||
i4 = 4;
|
||||
i5 = 5;
|
||||
i6 = 6;
|
||||
i7 = 7;
|
||||
|
||||
r1 = i0 + (i1 + ( i2 + ( i3 + ( i4 + (i5 + (i6 + i7))))));
|
||||
r2 = ((((((i0 + i1) + i2) + i3) + i4) + i5) + i6) + i7;
|
||||
r3 = ((i0 + i1) + (i2 + i3)) + ((i4 + i5) + (i6 + i7));
|
||||
|
||||
write(r1); writeln();
|
||||
write(r2); writeln();
|
||||
write(r3); writeln();
|
||||
}
|
||||
}
|
||||
7
javali_tests/HW1/HelloWorld.javali
Normal file
7
javali_tests/HW1/HelloWorld.javali
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
/* Kind of like hello world */
|
||||
class Main {
|
||||
void main() {
|
||||
write(53110);
|
||||
writeln();
|
||||
}
|
||||
}
|
||||
19
javali_tests/HW1/ImmediateOperands.javali
Normal file
19
javali_tests/HW1/ImmediateOperands.javali
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/* Check if code selection for immediate operands works */
|
||||
class Main {
|
||||
void main() {
|
||||
int i0;
|
||||
i0 = 0;
|
||||
|
||||
i0 = 5 + i0;
|
||||
write(i0);
|
||||
writeln();
|
||||
|
||||
i0 = i0 + 5;
|
||||
write(i0);
|
||||
writeln();
|
||||
|
||||
i0 = i0 + 5 + 3;
|
||||
write(i0);
|
||||
writeln();
|
||||
}
|
||||
}
|
||||
18
javali_tests/HW1/Negation.javali
Normal file
18
javali_tests/HW1/Negation.javali
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
class Main {
|
||||
void main() {
|
||||
int A,B,a,b,c,d;
|
||||
|
||||
A = 1;
|
||||
B = 1;
|
||||
|
||||
a = A * (-B);
|
||||
b = -A * B;
|
||||
c = -(A + B);
|
||||
d = -(A * B);
|
||||
|
||||
write(a); writeln();
|
||||
write(b); writeln();
|
||||
write(c); writeln();
|
||||
write(d); writeln();
|
||||
}
|
||||
}
|
||||
21
javali_tests/HW1_nop90/Division.javali
Executable file
21
javali_tests/HW1_nop90/Division.javali
Executable file
|
|
@ -0,0 +1,21 @@
|
|||
class Main {
|
||||
void main() {
|
||||
int a, b, c, d, e;
|
||||
|
||||
a = 10;
|
||||
b = -1;
|
||||
c = 0;
|
||||
d = 100;
|
||||
e = 2;
|
||||
|
||||
write(a / b); writeln();
|
||||
write(d / e); writeln();
|
||||
write(c / d); writeln();
|
||||
write(b / a + c); writeln();
|
||||
write(d / e * a / b * c); writeln();
|
||||
write(d / e * a / b); writeln();
|
||||
write(d / e + a / b); writeln();
|
||||
write(d / e * a * b * c); writeln();
|
||||
write(d / e * a - b + c); writeln();
|
||||
}
|
||||
}
|
||||
20
javali_tests/HW1_nop90/EightVariablesWrite.javali
Normal file
20
javali_tests/HW1_nop90/EightVariablesWrite.javali
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* Test expression evaluation with 8 variables */
|
||||
class Main {
|
||||
void main() {
|
||||
int r1, r2, r3;
|
||||
int i0, i1, i2, i3, i4, i5, i6, i7;
|
||||
|
||||
i0 = 0;
|
||||
i1 = 1;
|
||||
i2 = 2;
|
||||
i3 = 3;
|
||||
i4 = 4;
|
||||
i5 = 5;
|
||||
i6 = 6;
|
||||
i7 = 7;
|
||||
|
||||
write(i0 + (i1 + ( i2 + ( i3 + ( i4 + (i5 + (i6 + i7))))))); writeln();
|
||||
write(((((((i0 + i1) + i2) + i3) + i4) + i5) + i6) + i7); writeln();
|
||||
write(((i0 + i1) + (i2 + i3)) + ((i4 + i5) + (i6 + i7))); writeln();
|
||||
}
|
||||
}
|
||||
31
javali_tests/HW1_nop90/Multiplication.javali
Executable file
31
javali_tests/HW1_nop90/Multiplication.javali
Executable file
|
|
@ -0,0 +1,31 @@
|
|||
class Main {
|
||||
void main() {
|
||||
int r1;
|
||||
int i0, i1;
|
||||
int x,y,z;
|
||||
|
||||
i0 = 5;
|
||||
i1 = 2;
|
||||
|
||||
r1 = i1 * 3;
|
||||
write(r1); writeln();
|
||||
|
||||
r1 = i0 * i1;
|
||||
write(r1); writeln();
|
||||
|
||||
r1 = r1 * i0 * i1 * 3;
|
||||
write(r1); writeln();
|
||||
|
||||
y = 5;
|
||||
z = 10;
|
||||
x = (-y * z);
|
||||
write(x); writeln();
|
||||
|
||||
y = 0;
|
||||
z = - 10;
|
||||
x = (y * z);
|
||||
write(x); writeln();
|
||||
write(y * z); writeln();
|
||||
write(0 * -10); writeln();
|
||||
}
|
||||
}
|
||||
25
javali_tests/HW1_nop90/Overflow.javali
Executable file
25
javali_tests/HW1_nop90/Overflow.javali
Executable file
|
|
@ -0,0 +1,25 @@
|
|||
/* Test what happens for Integers that are to big for 32bits
|
||||
2147483647 (=0x7FFFFFFF) is the biggest integer in 32bits (IntMAX)
|
||||
*/
|
||||
class Main {
|
||||
void main() {
|
||||
int x,y,z;
|
||||
x = 2147483647;
|
||||
write( x ); writeln();
|
||||
/* add 1 to IntMax and output it */
|
||||
write( x + 1); writeln();
|
||||
|
||||
/* read an int bigger than IntMAX */
|
||||
x = read();
|
||||
write(x); writeln();
|
||||
|
||||
/* performe some operation that should generate an int overflow */
|
||||
x = 2147483640;
|
||||
y = 60000;
|
||||
write( x + y); writeln();
|
||||
z = 20000000;
|
||||
write( y * z); writeln();
|
||||
write( (y * z) ); writeln();
|
||||
|
||||
}
|
||||
}
|
||||
1
javali_tests/HW1_nop90/Overflow.javali.in
Executable file
1
javali_tests/HW1_nop90/Overflow.javali.in
Executable file
|
|
@ -0,0 +1 @@
|
|||
2147483647
|
||||
26
javali_tests/HW1_nop90/ReadWrite.javali
Executable file
26
javali_tests/HW1_nop90/ReadWrite.javali
Executable file
|
|
@ -0,0 +1,26 @@
|
|||
/* Test read/write native functions */
|
||||
class Main {
|
||||
void main() {
|
||||
int r1, r2, readvar, a1;
|
||||
|
||||
r1 = 6;
|
||||
/* r2 = 22 */
|
||||
r2 = read();
|
||||
|
||||
write(r1); writeln(); // 6
|
||||
|
||||
/* test expressions inside write() */
|
||||
write(r1 - 3); writeln(); // 3
|
||||
write(r1 - 6); writeln(); // 0
|
||||
write(r1 - 7); writeln(); // -1
|
||||
/* should output 111 */
|
||||
readvar = read(); // 1
|
||||
write( (r1 + (r2 * 5)) + readvar); // 117
|
||||
write(- r1); // -6
|
||||
writeln();
|
||||
/* should output 15 */
|
||||
a1 = read(); // -15
|
||||
write(- a1); // 15
|
||||
|
||||
}
|
||||
}
|
||||
6
javali_tests/HW1_nop90/ReadWrite.javali.in
Executable file
6
javali_tests/HW1_nop90/ReadWrite.javali.in
Executable file
|
|
@ -0,0 +1,6 @@
|
|||
22
|
||||
|
||||
|
||||
1
|
||||
|
||||
-15
|
||||
15
javali_tests/HW1_nop90/UnaryOperators.javali
Executable file
15
javali_tests/HW1_nop90/UnaryOperators.javali
Executable file
|
|
@ -0,0 +1,15 @@
|
|||
class Main {
|
||||
void main() {
|
||||
int a, b;
|
||||
|
||||
a = 1;
|
||||
b = 2;
|
||||
|
||||
write(+a); writeln();
|
||||
write(-a); writeln();
|
||||
write(+a --b); writeln();
|
||||
write(-a--b); writeln();
|
||||
write(-----a-----5--b); writeln();
|
||||
write(-----a*---------b);writeln();
|
||||
}
|
||||
}
|
||||
24
javali_tests/HW1_nop90/noParentheses.javali
Executable file
24
javali_tests/HW1_nop90/noParentheses.javali
Executable file
|
|
@ -0,0 +1,24 @@
|
|||
/* test what happens if there are no parentheses */
|
||||
|
||||
class Main {
|
||||
void main() {
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
|
||||
x = 5;
|
||||
y = 10;
|
||||
z = 100;
|
||||
|
||||
write( x + y + z); writeln();
|
||||
/* */
|
||||
write( - x + y - z); writeln();
|
||||
|
||||
/* should output 205 */
|
||||
write( x + 2 * z); writeln();
|
||||
|
||||
write( x + 2 * z / x + 1); writeln();
|
||||
write(+x); writeln();
|
||||
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue