-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 | ||
|
||
|
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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
cls | ||
cd %~dp0 | ||
start .\mapl\GVM.exe output.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; | ||
} | ||
} |