Skip to content

Commit

Permalink
Compiler finished
Browse files Browse the repository at this point in the history
  • Loading branch information
garciafdezpatricia committed Jun 10, 2023
0 parents commit 52a2a86
Show file tree
Hide file tree
Showing 186 changed files with 11,001 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/libraries/antlr_4_11_1_complete.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/libraries/introspector_1_2.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/libraries/lib.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions AG type-checking.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
AG: type-checking

// expressions
(1) IntLiteral: expression -> INT_CONSTANT
(2) CharLiteral: expression -> CHAR_CONSTANT
(3) DoubleLiteral: expression -> REAL_CONSTANT
(4) Variable: expression -> ID
(5) FuncInvocation: expression1 -> Variable expression2*
(6) Arithmetic: expression1 -> expression2 expression3
(7) ArithComparison: expression1 -> expression2 expression3
(8) LogComparison: expression1 -> expression2 expression3
(9) Minus: expression1 -> expression2
(10) Negation: expression1 -> expression2
(11) FieldAccess: expression1 -> expression2 ID
(12) ArrayIndex: expression1 -> expression2 expression3

// definitions
(13) FuncDefinition: funcdefinition -> ID vardefinition* statement* type
(14) VarDefinition: vardefinition -> ID type

// statements
(15) Assignment: statement -> expression1 expression2
(16) IfStatement: statement -> expression statement1* statement2*
(17) Input: statement -> expression*
(18) Print: statement -> expression*
(19) Return: statement -> expression
(20) WhileStatement: statement -> expression statement*

// Attributes
expression.type, statement.return

// Semantic rules
(1) expression.type = new Int(expression.line, expression.column) // int
(2) expression.type = new Char(expression.line, expression.column) // char
(3) expression.type = new Real(expression.line, expression.column) // real
(4) expression.type = expresion.definition.type // variable
(5) expression1.type = variable.definition.type.returnType // function invocation
(6) expression1.type = expression2.type.arithmetic(expression3.type) // arithmetic
(7) expression1.type = expression2.type.arithComparison(expression3.type) // arith comparison
(8) expression1.type = expression2.type.logicComparison(expression3.type) // logic comparison
(9) expression1.type = expression2.type.unaryMinus() // minus
(10) expression1.type = expression2.type.unaryNegation() // negation
(11) expression1.type = expression2.type.access(ID) //fieldaccess
(12) expression1.type = expression2.type.squareBrackets(expression3) // array indexer

(13) funcdefinition.type = new FunctionType(ID.line, ID.column, vardefinition*, type)
(14) vardefinition.type = type

// statements
(15) expression2.type = expression2.type.assignment(expression1.type) // assignment
(16) expression.type = expression.type.isLogical() // if
(17) expression*.type = expression*.type.isBuiltin() // input
(18) expression*.type = expression*.type.isBuiltIn() // print
(19) Return: statement -> expression // not finished
(20) expression.type = expression.type.isLogical() // while


Binary file added AST.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions DLP.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="lib" level="project" />
<orderEntry type="library" name="antlr-4.11.1-complete" level="project" />
<orderEntry type="library" name="introspector-1.2" level="project" />
</component>
</module>
Binary file added Lexer-with-IntelliJ-and-ANTLR.pdf
Binary file not shown.
3 changes: 3 additions & 0 deletions MAPL.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cls
cd %~dp0
start .\mapl\GVM.exe output.txt
91 changes: 91 additions & 0 deletions big.input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
pair:struct {
integer:int;
character:char;
};

acme:[2]struct {
employees: [2]struct { age:int; };
};

fibonacci:[8][3]int;

#-------------------------------

def p(): {}

def f(r:double, e:int):int {
real:double;
c:char;
result:int;
real = r * 10.0;
c='0';
if e < 256: {
c = (char)e;
result = (int)c;
}
else:
result = (int)real;
return result;
}

def initialize(): {
i:int;
fibonacci[0][0] = 0;
fibonacci[0][1] = 1;
fibonacci[0][2] = 1;
i = 1;
while i < 8: {
fibonacci[i][0] = fibonacci[i - 1][1];
fibonacci[i][1] = fibonacci[i - 1][2];
fibonacci[i][2] = fibonacci[i][0] + fibonacci[i][1];
i = i + 1;
}
}

#-------------------------------

def main(): {
i, j:int;
p();
i=0;
pair.character='0';
pair.integer=(int)'0';

# Shows 48 (decimal value of '0')
print f((double)i, (int)(pair.character)), '\n';
f(1.3, 2);

initialize();
i = 0;
while i < 8: {
# Shows the Fib sequence, from 1 to 8 (34)
print '(', i + 1, ')', fibonacci[i][0],
'+', fibonacci[i][1] , '=' ,
fibonacci[i][2] , '\n';
i = i + 1;
}

acme[1].employees[1].age = 56;
# Shows 56
print acme[1].employees[1].age, '\n';
i = 0;
while i<2: {
j = 0;
while j<2: {
acme[i].employees[j].age = i + j;
j = j+ 1;
}
i= i + 1;
}

i = 0;
while i<2: {
j = 0;
while j<2: {
# Shows 0 1 1 2
print acme[i].employees[j].age, ' ';
j = j+ 1;
}
i= i + 1;
}
}
Loading

0 comments on commit 52a2a86

Please sign in to comment.