From aaf658cf37f7c508457601ac4412990a4980545d Mon Sep 17 00:00:00 2001 From: cwjki Date: Mon, 1 Mar 2021 15:17:33 -0500 Subject: [PATCH 001/194] agregando mi nombre y usuario jki --- doc/team.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/doc/team.yml b/doc/team.yml index c16162532..da01a6382 100644 --- a/doc/team.yml +++ b/doc/team.yml @@ -2,9 +2,6 @@ members: - name: Nombre Apellido1 Apellido2 github: github_id group: CXXX - - name: Nombre Apellido1 Apellido2 - github: github_id - group: CXXX - - name: Nombre Apellido1 Apellido2 - github: github_id - group: CXXX + - name: Juan Carlos Casteleiro Wong + github: cwjki + group: C411 From b98c481dd54454db4704ac2f012b13b251d5b81e Mon Sep 17 00:00:00 2001 From: livi98 Date: Mon, 1 Mar 2021 15:24:25 -0500 Subject: [PATCH 002/194] Datos de Pin --- doc/team.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/team.yml b/doc/team.yml index da01a6382..e6b508515 100644 --- a/doc/team.yml +++ b/doc/team.yml @@ -1,7 +1,7 @@ members: - - name: Nombre Apellido1 Apellido2 - github: github_id - group: CXXX + - name: Olivia Gonzalez Pena + github: livi98 + group: C411 - name: Juan Carlos Casteleiro Wong github: cwjki group: C411 From dec819f6ae1d55be92b71448bd9fb33bb6ffd643 Mon Sep 17 00:00:00 2001 From: cwjki Date: Mon, 1 Mar 2021 15:37:09 -0500 Subject: [PATCH 003/194] =?UTF-8?q?Pe=C3=B1a?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/team.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/team.yml b/doc/team.yml index e6b508515..6ceff4a4f 100644 --- a/doc/team.yml +++ b/doc/team.yml @@ -1,5 +1,5 @@ members: - - name: Olivia Gonzalez Pena + - name: Olivia Gonzalez Peña github: livi98 group: C411 - name: Juan Carlos Casteleiro Wong From a61d547a50e126cbdf4d1ac679295b84ecc7348f Mon Sep 17 00:00:00 2001 From: livi98 Date: Mon, 1 Mar 2021 15:43:58 -0500 Subject: [PATCH 004/194] test --- doc/team.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/team.yml b/doc/team.yml index 6ceff4a4f..bc6a301de 100644 --- a/doc/team.yml +++ b/doc/team.yml @@ -4,4 +4,4 @@ members: group: C411 - name: Juan Carlos Casteleiro Wong github: cwjki - group: C411 + group: C411 \ No newline at end of file From a10d4bb55f75cfd2790fd0846fbbf175120cdecc Mon Sep 17 00:00:00 2001 From: livi98 Date: Mon, 1 Mar 2021 15:46:53 -0500 Subject: [PATCH 005/194] esto es una prueba --- doc/team.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/team.yml b/doc/team.yml index bc6a301de..4c34871af 100644 --- a/doc/team.yml +++ b/doc/team.yml @@ -4,4 +4,5 @@ members: group: C411 - name: Juan Carlos Casteleiro Wong github: cwjki - group: C411 \ No newline at end of file + group: C411 + esto es una prueba \ No newline at end of file From 57b45a5c60f8b95ed8cc8e47be1b9883391053d7 Mon Sep 17 00:00:00 2001 From: cwjki Date: Mon, 1 Mar 2021 15:47:57 -0500 Subject: [PATCH 006/194] otra prueba --- doc/team.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/team.yml b/doc/team.yml index 6ceff4a4f..14e112abe 100644 --- a/doc/team.yml +++ b/doc/team.yml @@ -5,3 +5,7 @@ members: - name: Juan Carlos Casteleiro Wong github: cwjki group: C411 + + + +esto es otra prueba \ No newline at end of file From 0a70bd25663607aef73fd419fe69b0eb0409aea4 Mon Sep 17 00:00:00 2001 From: cwjki Date: Mon, 1 Mar 2021 16:01:36 -0500 Subject: [PATCH 007/194] test --- doc/team.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/team.yml b/doc/team.yml index 6ceff4a4f..ea3c54143 100644 --- a/doc/team.yml +++ b/doc/team.yml @@ -5,3 +5,5 @@ members: - name: Juan Carlos Casteleiro Wong github: cwjki group: C411 + +test \ No newline at end of file From dda94c3d87075ed917b623b73635363979ee104d Mon Sep 17 00:00:00 2001 From: cwjki Date: Mon, 1 Mar 2021 16:08:10 -0500 Subject: [PATCH 008/194] no funciono lo que queriamos probar --- doc/team.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/doc/team.yml b/doc/team.yml index ea3c54143..bc6a301de 100644 --- a/doc/team.yml +++ b/doc/team.yml @@ -4,6 +4,4 @@ members: group: C411 - name: Juan Carlos Casteleiro Wong github: cwjki - group: C411 - -test \ No newline at end of file + group: C411 \ No newline at end of file From f507eaaa3c1be2dfa36c365ed3de07dbc300ac1c Mon Sep 17 00:00:00 2001 From: cwjki Date: Sun, 5 Sep 2021 17:51:58 -0400 Subject: [PATCH 009/194] lexer.py init --- doc/team.yml | 1 - requirements.txt | 1 + src/1_sintactic/lexer.py | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 src/1_sintactic/lexer.py diff --git a/doc/team.yml b/doc/team.yml index ea3c54143..b96f2e877 100644 --- a/doc/team.yml +++ b/doc/team.yml @@ -6,4 +6,3 @@ members: github: cwjki group: C411 -test \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 9eb0cad1a..5a914fd88 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ pytest pytest-ordering +ply \ No newline at end of file diff --git a/src/1_sintactic/lexer.py b/src/1_sintactic/lexer.py new file mode 100644 index 000000000..d9c72cda2 --- /dev/null +++ b/src/1_sintactic/lexer.py @@ -0,0 +1 @@ +import ply.lex as lex \ No newline at end of file From a9af1fa3be6e64eafce42f0c01a784a8fe59913c Mon Sep 17 00:00:00 2001 From: cwjki Date: Mon, 6 Sep 2021 12:53:26 -0400 Subject: [PATCH 010/194] tokens and reserved lexer --- src/1_sintactic/lexer.py | 60 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/src/1_sintactic/lexer.py b/src/1_sintactic/lexer.py index d9c72cda2..70fc4743a 100644 --- a/src/1_sintactic/lexer.py +++ b/src/1_sintactic/lexer.py @@ -1 +1,59 @@ -import ply.lex as lex \ No newline at end of file +import ply.lex as lex + + +def find_column(input, lexpos): + line_start = input.rfind('\n', 0, lexpos) + 1 + return (lexpos - line_start) + 1 + + +class CoolLexer: + + +reserved = { + 'class': 'CLASS', + 'else': 'ELSE', + 'false': 'FALSE', + 'fi': 'FI', + 'if': 'IF', + 'in': 'IN', + 'inherits': 'INHERITS', + 'isvoid': 'ISVOID', + 'let': 'LET', + 'loop': 'LOOP', + 'pool': 'POOL', + 'then': 'THEN', + 'while': 'WHILE', + 'case': 'CASE', + 'esac': 'ESAC', + 'new': 'NEW', + 'of': 'OF', + 'not': 'NOT' + 'true': 'TRUE' +} + +tokens = [ + 'ID', + 'TYPE', + 'LPAREN', + 'RPAREN', + 'LBRACE', + 'RBRACE', + 'COLON', + 'SEMICOLON', + 'COMMA', + 'DOT', + 'AT', + 'ASSIGN', + 'PLUS', + 'MINUS', + 'STAR', + 'DIV', + 'EQUAL', + 'LESS', + 'LESSEQ', + 'ARROW', + 'INT', + 'STRING', + 'BOOLEAN', + 'NOT' +] From 530b10e5c0a1aa86a4af7eb66a6b777687f946a4 Mon Sep 17 00:00:00 2001 From: cwjki Date: Mon, 6 Sep 2021 16:00:05 -0400 Subject: [PATCH 011/194] working on lexer.py --- src/1_sintactic/lexer.py | 153 ++++++++++++++++++++++++++------------- 1 file changed, 102 insertions(+), 51 deletions(-) diff --git a/src/1_sintactic/lexer.py b/src/1_sintactic/lexer.py index 70fc4743a..4873eb453 100644 --- a/src/1_sintactic/lexer.py +++ b/src/1_sintactic/lexer.py @@ -1,59 +1,110 @@ import ply.lex as lex -def find_column(input, lexpos): - line_start = input.rfind('\n', 0, lexpos) + 1 - return (lexpos - line_start) + 1 class CoolLexer: + reserved = { + 'class': 'CLASS', + 'else': 'ELSE', + 'false': 'FALSE', + 'fi': 'FI', + 'if': 'IF', + 'in': 'IN', + 'inherits': 'INHERITS', + 'isvoid': 'ISVOID', + 'let': 'LET', + 'loop': 'LOOP', + 'pool': 'POOL', + 'then': 'THEN', + 'while': 'WHILE', + 'case': 'CASE', + 'esac': 'ESAC', + 'new': 'NEW', + 'of': 'OF', + 'not': 'NOT' + 'true': 'TRUE' + } + + tokens = [ + 'ID', + 'TYPE', + 'LPAREN', + 'RPAREN', + 'LBRACE', + 'RBRACE', + 'COLON', + 'SEMICOLON', + 'COMMA', + 'DOT', + 'AT', + 'ASSIGN', + 'PLUS', + 'MINUS', + 'STAR', + 'DIV', + 'EQUAL', + 'LESS', + 'LESSEQ', + 'ARROW', + 'INT', + 'STRING', + 'BOOLEAN', + 'NOT' + ] + list(reserved.values()) + + + + def find_column(self, t): + line_start = self.text.rfind('\n', 0, t.lexpos) + 1 + return (t.lexpos - line_start) + 1 + + def add_row_column(self, t): + t.row = t.lexer.lineno + t.column = self.find_column(t) + + + + + + + def t_LPAREN(self, t): + r'\(' + self.add_row_column(t) + return t + + def t_RPAREN(self, t): + r'\)' + self.add_row_column(t) + return t + + def t_LBRACE(self, t): + r'\{' + self.add_row_column(t) + return t + + def t_RPAREN(self, t): + r'\}' + self.add_row_column(t) + return t + + def t_COLON(self, t): + r':' + self.add_row_column(t) + return t + + def t_SEMICOLON(self, t): + r';' + self.add_row_column(t) + return t + + def t_DOT(self, t): + r'\.' + self.add_row_column(t) + return t + + + + -reserved = { - 'class': 'CLASS', - 'else': 'ELSE', - 'false': 'FALSE', - 'fi': 'FI', - 'if': 'IF', - 'in': 'IN', - 'inherits': 'INHERITS', - 'isvoid': 'ISVOID', - 'let': 'LET', - 'loop': 'LOOP', - 'pool': 'POOL', - 'then': 'THEN', - 'while': 'WHILE', - 'case': 'CASE', - 'esac': 'ESAC', - 'new': 'NEW', - 'of': 'OF', - 'not': 'NOT' - 'true': 'TRUE' -} - -tokens = [ - 'ID', - 'TYPE', - 'LPAREN', - 'RPAREN', - 'LBRACE', - 'RBRACE', - 'COLON', - 'SEMICOLON', - 'COMMA', - 'DOT', - 'AT', - 'ASSIGN', - 'PLUS', - 'MINUS', - 'STAR', - 'DIV', - 'EQUAL', - 'LESS', - 'LESSEQ', - 'ARROW', - 'INT', - 'STRING', - 'BOOLEAN', - 'NOT' -] From 90a4923bacbffe980b76ec9cee5b8b78927e028c Mon Sep 17 00:00:00 2001 From: cwjki Date: Tue, 14 Sep 2021 18:53:17 -0400 Subject: [PATCH 012/194] workin on lexer.py --- src/1_sintactic/lexer.py | 78 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 76 insertions(+), 2 deletions(-) diff --git a/src/1_sintactic/lexer.py b/src/1_sintactic/lexer.py index 4873eb453..6d6b6960e 100644 --- a/src/1_sintactic/lexer.py +++ b/src/1_sintactic/lexer.py @@ -50,7 +50,6 @@ class CoolLexer: 'ARROW', 'INT', 'STRING', - 'BOOLEAN', 'NOT' ] + list(reserved.values()) @@ -68,7 +67,6 @@ def add_row_column(self, t): - def t_LPAREN(self, t): r'\(' self.add_row_column(t) @@ -99,12 +97,88 @@ def t_SEMICOLON(self, t): self.add_row_column(t) return t + def t_COMMA(self, t): + r',' + self.add_line_column(t) + return t + def t_DOT(self, t): r'\.' self.add_row_column(t) return t + def t_AT(self, t): + r'@' + self.add_row_column(t) + return t + + def t_ASSIGN(self, t): + r'<-' + self.add_row_column(t) + return t + + def t_PLUS(self, t): + r'\+' + self.add_row_column(t) + return t + + def t_MINUS(self, t): + r'-' + self.add_row_column(t) + return t + + def t_STAR(self, t): + r'\*' + self.add_row_column(t) + return t + def t_DIV(self, t): + r'/' + self.add_row_column(t) + return t + + def t_EQUAL(self, t): + r'=' + self.add_row_column(t) + return t + + def t_LESS(self, t): + r'<' + self.add_row_column(t) + return t + + def t_LESSEQ(self, t): + r'<=' + self.add_row_column(t) + return t + + def t_ARROW(self, t): + r'=>' + self.add_row_column(t) + return t + + def t_NOT(self, t): + r'~' + self.add_row_column(t) + return t + + def t_INT(self, t): + r'\d+' + t.value = int(t.value) + self.add_row_column(t) + return t + + def t_ID(self, t): + r'[a-z][a-zA-Z_0-9]*' + t.type = self.reserved.get(t.value.lower(), 'ID') + self.add_row_column(t) + return t + + def t_TYPE(self, t): + r'[A-Z][a-zA-Z_0-9]*' + t.type = self.reserved.get(t.value.lower(), 'TYPE') + self.add_row_column(t) + return t From 88865ff70e8e635927e23d47b7b8eb7e57876d19 Mon Sep 17 00:00:00 2001 From: cwjki Date: Sat, 9 Oct 2021 18:28:38 -0400 Subject: [PATCH 013/194] comments and strings in lexer --- src/1_sintactic/lexer.py | 131 ++++++++++++++++++++++++++++++++++++--- src/utils/errors.py | 15 +++++ 2 files changed, 138 insertions(+), 8 deletions(-) create mode 100644 src/utils/errors.py diff --git a/src/1_sintactic/lexer.py b/src/1_sintactic/lexer.py index 6d6b6960e..e1bdeb5a8 100644 --- a/src/1_sintactic/lexer.py +++ b/src/1_sintactic/lexer.py @@ -1,9 +1,18 @@ import ply.lex as lex +from utils.errors import * +class CoolLexer: + def __init__(self, **kwargs): + self.errors = [] + self.lexer = lex.lex(modele=self, **kwargs) + self.lexer.lineno = 1 + self.lexer.linestart = 0 - -class CoolLexer: + states = ( + ('comments', 'exclusive'), + ('strings', 'exclusive') + ) reserved = { 'class': 'CLASS', @@ -23,7 +32,7 @@ class CoolLexer: 'esac': 'ESAC', 'new': 'NEW', 'of': 'OF', - 'not': 'NOT' + 'not': 'NOT', 'true': 'TRUE' } @@ -53,7 +62,108 @@ class CoolLexer: 'NOT' ] + list(reserved.values()) + # Comments + def t_comment(self, t): + r'--.*($|\n)' + t.lexer.lineno += 1 + t.lexer.linestart = t.lexer.lexpos + + def t_comments(self, t): + r'\(\*' + t.lexer.level = 1 + t.lexer.begin('comments') + + def t_comments_open(self, t): + r'\(\*' + t.lexer.level += 1 + + def t_comments_close(self, t): + r'\*\)' + t.lexer.level -= 1 + if t.lexer.level == 0: + t.lexer.begin('INITIAL') + + def t_comments_newline(self, t): + r'\n+' + t.lexer.lineno += len(t.value) + t.lexer.linestart = t.lexer.lexpos + + def t_comments_error(self, t): + t.lexer.skip(1) + + def t_comments_eof(self, t): + line = t.lexer.lineno + column = self.find_column(t) + add_lexer_error(line, column, "EOF in comment") + + t_comments_ignore = ' \t\f\r\v' + + # Strings + t_strings_ignore = '' + + def t_strings(self, t): + r'\"' + t.lexer.string_start = t.lexer.lexpos + t.lexer.string = '' + t.lexer.backslash = False + t.lexer.begin('string') + + def t_strings_end(self, t): + r'\"' + self.add_row_column(t) + + if t.lexer.backslash: + t.lexer.string += '"' + t.lexer.backslash = False + else: + t.value = t.lexer.string + t.type = 'string' + t.lexer.begin('INITIAL') + return t + + def t_strings_newline(self, t): + r'\n' + t.lexer.lineno += 1 + self.add_row_column(t) + t.lexer.linestart = t.lexer.lexpos + + if not t.lexer.backslash: + add_lexer_error(t.row, t.column, 'Undeterminated string constant') + t.lexer.begin('INITIAL') + + def t_strings_nill(self, t): + r'\0' + self.add_row_column(t) + add_lexer_error(t.row, t.column, 'Null caracter in string') + + def t_strings_consume(self, t): + r'[^\n]' + + if t.lexer.backslash: + if t.value == 'b': + t.lexer.string += '\b' + elif t.value == 't': + t.lexer.string += '\t' + if t.value == 'f': + t.lexer.string += '\f' + elif t.value == 'n': + t.lexer.string += '\n' + elif t.value == '\\': + t.lexer.string += '\\' + else: + t.lexer.string += t.value + + t.backslash = FALSE + else: + if t.value != '\\': + t.lexer.string += t.value + else: + t.lexer.backslash = True + + def t_strings_eof(self, t): + self.add_row_column(t) + add_lexer_error(t.row, r.column, 'EOF in string constant') def find_column(self, t): line_start = self.text.rfind('\n', 0, t.lexpos) + 1 @@ -63,15 +173,13 @@ def add_row_column(self, t): t.row = t.lexer.lineno t.column = self.find_column(t) - - - + t_ignore = ' \t\f\r\t\v' def t_LPAREN(self, t): r'\(' self.add_row_column(t) return t - + def t_RPAREN(self, t): r'\)' self.add_row_column(t) @@ -81,7 +189,7 @@ def t_LBRACE(self, t): r'\{' self.add_row_column(t) return t - + def t_RPAREN(self, t): r'\}' self.add_row_column(t) @@ -180,5 +288,12 @@ def t_TYPE(self, t): self.add_row_column(t) return t + def t_newline(self, t): + + + + + + diff --git a/src/utils/errors.py b/src/utils/errors.py new file mode 100644 index 000000000..05c303e9b --- /dev/null +++ b/src/utils/errors.py @@ -0,0 +1,15 @@ +LEXER_ERRORS = [] +PARSER_ERRORS = [] +SEMANTIC_ERRORS = [] + + +def add_lexer_error(line, column, message): + LEXER_ERRORS.append(f'({line}, {column}) - LexicographicError: {message}') + + +def add_parser_error(line, column, message): + PARSER_ERRORS.append(f'({line}, {column}) - SyntacticError: {message}') + + +def add_semantic_error(line, column, message): + SEMANTIC_ERRORS.append(f'({line}, {column}) - SemanticError: {message}') \ No newline at end of file From b02c9852f011bb2cf5af7a7ac149b8427f2aa5fa Mon Sep 17 00:00:00 2001 From: cwjki Date: Sun, 10 Oct 2021 16:53:08 -0400 Subject: [PATCH 014/194] lexer finished, i hope :) --- src/1_sintactic/lexer.py | 122 +++++++++++++++++++++++++-------------- src/utils/errors.py | 24 ++++---- 2 files changed, 93 insertions(+), 53 deletions(-) diff --git a/src/1_sintactic/lexer.py b/src/1_sintactic/lexer.py index e1bdeb5a8..4def179ff 100644 --- a/src/1_sintactic/lexer.py +++ b/src/1_sintactic/lexer.py @@ -1,13 +1,14 @@ import ply.lex as lex from utils.errors import * -class CoolLexer: +class CoolLexer: def __init__(self, **kwargs): self.errors = [] self.lexer = lex.lex(modele=self, **kwargs) self.lexer.lineno = 1 - self.lexer.linestart = 0 + self.lexer.linestart = 0 + self.errors = [] states = ( ('comments', 'exclusive'), @@ -76,13 +77,13 @@ def t_comments(self, t): def t_comments_open(self, t): r'\(\*' t.lexer.level += 1 - + def t_comments_close(self, t): r'\*\)' t.lexer.level -= 1 if t.lexer.level == 0: t.lexer.begin('INITIAL') - + def t_comments_newline(self, t): r'\n+' t.lexer.lineno += len(t.value) @@ -90,15 +91,15 @@ def t_comments_newline(self, t): def t_comments_error(self, t): t.lexer.skip(1) - + def t_comments_eof(self, t): line = t.lexer.lineno column = self.find_column(t) - add_lexer_error(line, column, "EOF in comment") + self.errors.append(LexicographicError("EOF in comment", line, column)) t_comments_ignore = ' \t\f\r\v' - - # Strings + + # Strings t_strings_ignore = '' def t_strings(self, t): @@ -110,9 +111,9 @@ def t_strings(self, t): def t_strings_end(self, t): r'\"' - self.add_row_column(t) + self.add_line_column(t) - if t.lexer.backslash: + if t.lexer.backslash: t.lexer.string += '"' t.lexer.backslash = False else: @@ -120,22 +121,24 @@ def t_strings_end(self, t): t.type = 'string' t.lexer.begin('INITIAL') return t - + def t_strings_newline(self, t): r'\n' t.lexer.lineno += 1 - self.add_row_column(t) + self.add_line_column(t) t.lexer.linestart = t.lexer.lexpos if not t.lexer.backslash: - add_lexer_error(t.row, t.column, 'Undeterminated string constant') + self.errors.append(LexicographicError( + 'Undeterminated string constant'), t.line, t.column) t.lexer.begin('INITIAL') def t_strings_nill(self, t): r'\0' - self.add_row_column(t) - add_lexer_error(t.row, t.column, 'Null caracter in string') + self.add_line_column(t) + self.errors.append(LexicographicErroricError( + 'Null caracter in string', t.line, t.column)) def t_strings_consume(self, t): r'[^\n]' @@ -162,47 +165,48 @@ def t_strings_consume(self, t): t.lexer.backslash = True def t_strings_eof(self, t): - self.add_row_column(t) - add_lexer_error(t.row, r.column, 'EOF in string constant') + self.add_line_column(t) + self.errors.append(LexicographicErroricError( + 'EOF in string constant', t.line, t.column)) def find_column(self, t): line_start = self.text.rfind('\n', 0, t.lexpos) + 1 return (t.lexpos - line_start) + 1 - def add_row_column(self, t): - t.row = t.lexer.lineno + def add_line_column(self, t): + t.line = t.lexer.lineno t.column = self.find_column(t) t_ignore = ' \t\f\r\t\v' def t_LPAREN(self, t): r'\(' - self.add_row_column(t) + self.add_line_column(t) return t def t_RPAREN(self, t): r'\)' - self.add_row_column(t) + self.add_line_column(t) return t def t_LBRACE(self, t): r'\{' - self.add_row_column(t) + self.add_line_column(t) return t def t_RPAREN(self, t): r'\}' - self.add_row_column(t) + self.add_line_column(t) return t def t_COLON(self, t): r':' - self.add_row_column(t) + self.add_line_column(t) return t def t_SEMICOLON(self, t): r';' - self.add_row_column(t) + self.add_line_column(t) return t def t_COMMA(self, t): @@ -212,88 +216,122 @@ def t_COMMA(self, t): def t_DOT(self, t): r'\.' - self.add_row_column(t) + self.add_line_column(t) return t def t_AT(self, t): r'@' - self.add_row_column(t) + self.add_line_column(t) return t def t_ASSIGN(self, t): r'<-' - self.add_row_column(t) + self.add_line_column(t) return t def t_PLUS(self, t): r'\+' - self.add_row_column(t) + self.add_line_column(t) return t def t_MINUS(self, t): r'-' - self.add_row_column(t) + self.add_line_column(t) return t def t_STAR(self, t): r'\*' - self.add_row_column(t) + self.add_line_column(t) return t def t_DIV(self, t): r'/' - self.add_row_column(t) + self.add_line_column(t) return t def t_EQUAL(self, t): r'=' - self.add_row_column(t) + self.add_line_column(t) return t def t_LESS(self, t): r'<' - self.add_row_column(t) + self.add_line_column(t) return t def t_LESSEQ(self, t): r'<=' - self.add_row_column(t) + self.add_line_column(t) return t def t_ARROW(self, t): r'=>' - self.add_row_column(t) + self.add_line_column(t) return t def t_NOT(self, t): r'~' - self.add_row_column(t) + self.add_line_column(t) return t def t_INT(self, t): r'\d+' t.value = int(t.value) - self.add_row_column(t) + self.add_line_column(t) return t def t_ID(self, t): r'[a-z][a-zA-Z_0-9]*' t.type = self.reserved.get(t.value.lower(), 'ID') - self.add_row_column(t) + self.add_line_column(t) return t def t_TYPE(self, t): r'[A-Z][a-zA-Z_0-9]*' t.type = self.reserved.get(t.value.lower(), 'TYPE') - self.add_row_column(t) + self.add_line_column(t) return t def t_newline(self, t): - + r'\n+' + t.lexer.lineno += len(t.value) + t.lexer.linestart = t.lexer.lexpos + + def t_error(self, t): + self.add_line_column(t) + self.errors.append(LexicographicError( + f'ERROR \"{t.value[0]}\"', line, column)) + t.lexer.skip(1) + + def tokenize(self, text): + self.lexer.input(text) + tokens = [] + for token in self.lexer: + tokens.append(Token(token.value, token.type, + token.row, token.column)) + self.lexer.lineno = 1 + self.linestart = 0 + return tokens - + def run(self, text): + tokens = self.tokenize(text) + if self.errors: + for error in self.errors: + print(error) + raise Exception() + return tokens +class Token: + def __init__(self, lex, token_type, row, column): + self.lex = lex + self.type = token_type + self.line = line + self.column = column + def __str__(self): + return f'{self.type}: {self.lex} ({self.line}, {self.column})' + def __repr__(self): + return str(self) diff --git a/src/utils/errors.py b/src/utils/errors.py index 05c303e9b..f38c4dc68 100644 --- a/src/utils/errors.py +++ b/src/utils/errors.py @@ -1,15 +1,17 @@ -LEXER_ERRORS = [] -PARSER_ERRORS = [] -SEMANTIC_ERRORS = [] +class CoolError(): + def __init__(self, error_type, text, line, column): + self.type = type + self.text = text + self.line = line + self.column = column + def __str__(self): + return f'({self.line, self.column}) - {self.error_type}: {self.text}' -def add_lexer_error(line, column, message): - LEXER_ERRORS.append(f'({line}, {column}) - LexicographicError: {message}') + def __repr__(self): + return str(self) -def add_parser_error(line, column, message): - PARSER_ERRORS.append(f'({line}, {column}) - SyntacticError: {message}') - - -def add_semantic_error(line, column, message): - SEMANTIC_ERRORS.append(f'({line}, {column}) - SemanticError: {message}') \ No newline at end of file +class LexicographicError(CoolError): + def __init__(self, text, line, column): + super().__init__('LexicograficError', text, line, column) From 24d2143e7bc9dc70ad7721de4b56d796e1b57c82 Mon Sep 17 00:00:00 2001 From: cwjki Date: Mon, 11 Oct 2021 00:54:57 -0400 Subject: [PATCH 015/194] starting ast.py --- src/1_sintactic/ast.py | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/1_sintactic/ast.py diff --git a/src/1_sintactic/ast.py b/src/1_sintactic/ast.py new file mode 100644 index 000000000..9e523d622 --- /dev/null +++ b/src/1_sintactic/ast.py @@ -0,0 +1,47 @@ +class Node(): + def __init__(self): + pass + + +class ProgramNode(Node): + def __init__(self, classes): + super().__init__() + self.classes = classes + + +class ClassDeclarationNode(Node): + def __init__(self, name, features, parent=None): + super().__init__() + self.name = name + self.features = features + self.parent = parent + + +class FuncDeclarationNode(Node): + def __init__(self, name, params, return_type, expr=None): + super().__init__() + self.name = name + self.params = params + self.return_type = return_type + self.exp = exp + + +class AttrDeclarationNode(Node): + def __init__(self, name, type, expr=None): + super().__init__() + self.name = name + self.type = type + self.exp = exp + + +class ExpressionNode(Node): + def __init__(self): + super().__init__() + self.computed_type = None + + +class AssignNode(ExpressionNode): + def __init__(self, name, expr): + super().__init__() + self.name = name + self.expr = expr From 9db81e500e8faa8d0cbf5b9912ed9c4a9507764c Mon Sep 17 00:00:00 2001 From: cwjki Date: Mon, 11 Oct 2021 15:33:15 -0400 Subject: [PATCH 016/194] adding some nodes to ast.py --- src/1_sintactic/ast.py | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/1_sintactic/ast.py b/src/1_sintactic/ast.py index 9e523d622..28dadcbd1 100644 --- a/src/1_sintactic/ast.py +++ b/src/1_sintactic/ast.py @@ -45,3 +45,50 @@ def __init__(self, name, expr): super().__init__() self.name = name self.expr = expr + + +# FUNC CALLS NODES MISSING + + +class IfNode(ExpressionNode): + def __init__(self, condition, then_expr, else_expr): + super().__init__() + self.condition = condition + self.then_expr = then_expr + self.else_expr = else_expr + + +class WhileNode(ExpressionNode): + def __init__(self, condition, body): + super().__init__() + self.condition = condition + self.body = body + + +class BlockNode(ExpressionNode): + def __init__(self, exprs): + super().__init__() + self.exprs = exprs + + +class LetNode(ExpressionNode): + def __init__(self, let_attrs, expr): + super().__init__() + self.let_attrs = let_attrs + self.expr = expr + + +class CaseNode(ExpressionNode): + def __init__(self, expr, case_list): + super().__init__() + self.expr = expr + self.case_list = case_list: + + +class CaseOptionNode(ExpressionNode): + def __init__(self, id, expr, type): + super().__init__() + self.id = id + self.expr = expr + self.type = type + From c897722194004710b787e9e0dee1bd5e1b59d74c Mon Sep 17 00:00:00 2001 From: cwjki Date: Mon, 11 Oct 2021 16:07:21 -0400 Subject: [PATCH 017/194] almost finish the ast --- src/1_sintactic/ast.py | 94 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) diff --git a/src/1_sintactic/ast.py b/src/1_sintactic/ast.py index 28dadcbd1..07cec9be2 100644 --- a/src/1_sintactic/ast.py +++ b/src/1_sintactic/ast.py @@ -91,4 +91,96 @@ def __init__(self, id, expr, type): self.id = id self.expr = expr self.type = type - + + +class VarNode(ExpressionNode): + def __init__(self, id): + super().__init__() + self.id = id + + +class NewNode(ExpressionNode): + def __init__(self, type): + super().__init__() + self.type = type + + +# ---------------- Binary Nodes ------------------ + +class BinaryNode(ExpressionNode): + def __init__(self, lvalue, rvalue): + super().__init__() + self.lvalue = lvalue + self.rvalue = rvalue + + +class PlusNode(BinaryNode): + pass + + +class MinusNode(BinaryNode): + pass + + +class StarNode(BinaryNode): + pass + + +class DivNode(BinaryNode): + pass + + +class LessThanNode(BinaryNode): + pass + + +class LessEqNode(BinaryNode): + pass + + +class EqNode(BinaryNode): + pass + + +# ---------------- Unary Nodes ------------------ + +class UnaryNode(ExpressionNode): + def __init__(self, value): + super().__init__() + self.value = value + + +class NotNode(UnaryNode): + pass + + +class LogicNotNode(UnaryNode): + pass + + +class AtomicNode(UnaryNode): + pass + + +class IsVoidNode(UnaryNode): + pass + + +# ---------------- Constant Nodes ------------------ + +class ConstantNode(ExpressionNode): + def __init__(self, value): + super().__init__() + self.value = value + + +class IntNode(ConstantNode): + pass + + +class BoolNode(ConstantNode): + pass + + +class StringNode(ConstantNode): + pass From 9a8e4303ec2b8c09635beb803e1a3583aa4c5e8a Mon Sep 17 00:00:00 2001 From: cwjki Date: Fri, 15 Oct 2021 17:31:22 -0400 Subject: [PATCH 018/194] ast nodes done --- src/1_sintactic/ast.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/1_sintactic/ast.py b/src/1_sintactic/ast.py index 07cec9be2..d00e10678 100644 --- a/src/1_sintactic/ast.py +++ b/src/1_sintactic/ast.py @@ -47,7 +47,13 @@ def __init__(self, name, expr): self.expr = expr -# FUNC CALLS NODES MISSING +class FuncCallNode(ExpressionNode): + def __init__(self, id, args, object=None, type=None): + super().__init__() + self.id = id + self.args = args + self.object = object + self.type = type class IfNode(ExpressionNode): From 6a60ca28c5339e9282e0f2cdc7a053da8f7db7d1 Mon Sep 17 00:00:00 2001 From: cwjki Date: Fri, 15 Oct 2021 18:31:45 -0400 Subject: [PATCH 019/194] starting the parser --- src/1_sintactic/parser.py | 46 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/1_sintactic/parser.py diff --git a/src/1_sintactic/parser.py b/src/1_sintactic/parser.py new file mode 100644 index 000000000..34966a7a8 --- /dev/null +++ b/src/1_sintactic/parser.py @@ -0,0 +1,46 @@ +from ast import * +import ply.yacc as yacc + + +class CoolParser: + def __init__(self, lexer): + self.lexer = lexer + self.parser = yacc.yacc(start='program', module=self) + + def parse(self, program): + pass + + def p_program(self, p): + 'program : class_list' + p[0] = ProgramNode(p[1]) + + def p_epsilon(self, p): + 'epsilon :' + pass + + def p_class_list(self, p): + '''class_list : def_class SEMICOLON class_list + | def_class SEMICOLON ''' + p[0] = [p[1]] if len(p) == 3 else [p[1]] + p[3] + + def p_def_class(self, p): + '''def_class : CLASS TYPE LPAREN feature_list RPAREN + | CLASS TYPE INHERITS TYPE LPAREN feature_list RPAREN''' + if len(p) == 8: + p[0] = ClassDeclarationNode(p[2], p[6], p[4]) + else: + p[0] = ClassDeclarationNode(p[2], p[4]) + + def p_feature_list(self, p): + '''feature_list : def_attr SEMICOLON feature_list + | def_func SEMICOLON feature_list + | epsilon''' + p[0] = [p[1]] + p[3] if len(p) == 4 else [] + + def p_def_attr(self, p): + '''def_attr : ID COLON TYPE + | ID COLON TYPE ASSIGN expr''' + if len(p) == 4: + p[0] = AttrDeclarationNode(p[1], p[3]) + else: + p[0] = AttrDeclarationNode(p[1], p[3], p[5]) From 4ee8e3b511ad9e4a77bf8e3b71450ee3e3704db0 Mon Sep 17 00:00:00 2001 From: cwjki Date: Fri, 15 Oct 2021 21:55:56 -0400 Subject: [PATCH 020/194] working on the parser --- src/1_sintactic/parser.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/1_sintactic/parser.py b/src/1_sintactic/parser.py index 34966a7a8..c7acaf0f8 100644 --- a/src/1_sintactic/parser.py +++ b/src/1_sintactic/parser.py @@ -44,3 +44,30 @@ def p_def_attr(self, p): p[0] = AttrDeclarationNode(p[1], p[3]) else: p[0] = AttrDeclarationNode(p[1], p[3], p[5]) + + def p_def_func(self, p): + '''def_func : ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACE''' + p[0] = FuncDeclarationNode(p[1], p[3], p[6], p[8]) + + def p_params(self, p): + '''params : param_list + | param_list_empty''' + p[0] = p[1] + + def p_param_list(self, p): + '''param_list : param + | param COMMA param_list''' + p[0] = [p[1]] if len(p) == 2 else [p[1]] + p[3] + + def p_param_list_empty(self, p): + '''para,_list_empty : epsilon''' + p[0] = [] + + def p_param(self, p): + '''param : ID COLON TYPE''' + p[0] = (p[1], p[3]) + + def p_let_attrs(p): + '''let_attrs : def_attr + | def_attr COMMA let_attrs''' + p[0] = [p[1]] if len(p) == 2 else [p[1]] + p[3] From bd57ebff4e5ae54624b27a6dcd19899cfd51a34f Mon Sep 17 00:00:00 2001 From: cwjki Date: Mon, 18 Oct 2021 18:01:52 -0400 Subject: [PATCH 021/194] working on parser --- src/1_sintactic/ast.py | 2 +- src/1_sintactic/parser.py | 62 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/src/1_sintactic/ast.py b/src/1_sintactic/ast.py index d00e10678..89eedbddc 100644 --- a/src/1_sintactic/ast.py +++ b/src/1_sintactic/ast.py @@ -92,7 +92,7 @@ def __init__(self, expr, case_list): class CaseOptionNode(ExpressionNode): - def __init__(self, id, expr, type): + def __init__(self, id, type, expr): super().__init__() self.id = id self.expr = expr diff --git a/src/1_sintactic/parser.py b/src/1_sintactic/parser.py index c7acaf0f8..73a16eb8c 100644 --- a/src/1_sintactic/parser.py +++ b/src/1_sintactic/parser.py @@ -67,7 +67,67 @@ def p_param(self, p): '''param : ID COLON TYPE''' p[0] = (p[1], p[3]) - def p_let_attrs(p): + def p_let_attrs(self, p): '''let_attrs : def_attr | def_attr COMMA let_attrs''' p[0] = [p[1]] if len(p) == 2 else [p[1]] + p[3] + + def p_case_list(self, p): + '''case_list : case_option SEMICOLON + | case_option SEMICOLON case_list''' + p[0] = [p[1]] if len(p) == 3 else [p[1]] + p[3] + + def p_case_option(self, p): + '''case_option : ID COLON TYPE ARROW expr''' + p[0] = CaseOptionNode(p[1], p[3], p[5]) + + def p_args(self, p): + '''args : arg_list + | arg_list_empty''' + p[0] = p[1] + + def p_arg_list(self, p): + '''arg_list : expr + | expr COMMA arg_list''' + p[0] = [p[1]] if len(p) == 2 else [p[1]] + p[3] + + def p_arg_list_empty(p): + '''arg_list_empty : epsilon''' + p[0] = [] + + def p_atom_int(self, p): + '''atom : INT''' + p[0] = IntNode(int(p[1])) + + def p_atom_id(self, p): + '''atom : ID''' + p[0] = VarNode(p[1]) + + def p_atom_bool(self, p): + '''atom : BOOL''' + p[0] = BoolNode(p[1]) + + def p_atom_string(self, p): + '''atom : STRING''' + p[0] = StringNode(p[1]) + + def p_atom_new(self, p): + '''atom : NEW TYPE''' + p[0] = NewNode(p[2]) + + def p_atom_block(self, p): + '''atom : block''' + p[0] = p[1] + + def p_block(self, p): + '''block : LBRACE block_list RBRACE''' + p[0] = p[2] + + def p_block_list(self, p): + ''' block_list : expr SEMICOLON + | expr SEMICOLON block_list''' + p[0] = BlockNode([p[1]]) if len(p) == 3 else BlockNode([p[1]] + p[3].exprs) + + def p_error(self, p): + pass + From 6d5450ff7d963e9cb356b709d564ad9c19b6a9da Mon Sep 17 00:00:00 2001 From: cwjki Date: Mon, 18 Oct 2021 19:28:39 -0400 Subject: [PATCH 022/194] adding lines and columns in parser --- src/1_sintactic/ast.py | 7 ++++- src/1_sintactic/parser.py | 54 +++++++++++++++++++++++++++++++-------- src/utils/errors.py | 10 ++++++++ src/utils/utils.py | 3 +++ 4 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 src/utils/utils.py diff --git a/src/1_sintactic/ast.py b/src/1_sintactic/ast.py index 89eedbddc..f61c9809b 100644 --- a/src/1_sintactic/ast.py +++ b/src/1_sintactic/ast.py @@ -1,6 +1,11 @@ class Node(): def __init__(self): - pass + self.line = 0 + self.column = 0 + + def add_line_column(self, line, column): + self.line = line + self.column = column class ProgramNode(Node): diff --git a/src/1_sintactic/parser.py b/src/1_sintactic/parser.py index 73a16eb8c..d38ae2f0e 100644 --- a/src/1_sintactic/parser.py +++ b/src/1_sintactic/parser.py @@ -1,11 +1,23 @@ -from ast import * import ply.yacc as yacc +from ast import * +from utils.utils import * class CoolParser: def __init__(self, lexer): self.lexer = lexer self.parser = yacc.yacc(start='program', module=self) + self.errors = [] + + procedence = ( + ('left, AT'), + ('left, NOT'), + ('left, ISVOID'), + ('left, EQUAL, LESS, LESSEQ'), + ('left, PLUS, MINUS'), + ('left, STAR, DIV'), + ('left, DOT') + ) def parse(self, program): pass @@ -24,13 +36,16 @@ def p_class_list(self, p): p[0] = [p[1]] if len(p) == 3 else [p[1]] + p[3] def p_def_class(self, p): - '''def_class : CLASS TYPE LPAREN feature_list RPAREN + '''def_class : CLASS TYPE LPAREN feature_list RPAREN | CLASS TYPE INHERITS TYPE LPAREN feature_list RPAREN''' if len(p) == 8: p[0] = ClassDeclarationNode(p[2], p[6], p[4]) else: p[0] = ClassDeclarationNode(p[2], p[4]) + p[0].add_line_column(p.lineno(2), find_column( + p.lexer.lexdata, p.lexpos(2))) + def p_feature_list(self, p): '''feature_list : def_attr SEMICOLON feature_list | def_func SEMICOLON feature_list @@ -38,13 +53,16 @@ def p_feature_list(self, p): p[0] = [p[1]] + p[3] if len(p) == 4 else [] def p_def_attr(self, p): - '''def_attr : ID COLON TYPE + '''def_attr : ID COLON TYPE | ID COLON TYPE ASSIGN expr''' if len(p) == 4: p[0] = AttrDeclarationNode(p[1], p[3]) else: p[0] = AttrDeclarationNode(p[1], p[3], p[5]) + p[0].add_line_column(p.lineno(3), find_column( + p.lexer.lexdata, p.lexpos(3))) + def p_def_func(self, p): '''def_func : ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACE''' p[0] = FuncDeclarationNode(p[1], p[3], p[6], p[8]) @@ -80,9 +98,11 @@ def p_case_list(self, p): def p_case_option(self, p): '''case_option : ID COLON TYPE ARROW expr''' p[0] = CaseOptionNode(p[1], p[3], p[5]) + p[0].add_line_column(p.lineno(3), find_column( + p.lexer.lexdata, p.lexpos(3))) def p_args(self, p): - '''args : arg_list + '''args : arg_list | arg_list_empty''' p[0] = p[1] @@ -98,36 +118,50 @@ def p_arg_list_empty(p): def p_atom_int(self, p): '''atom : INT''' p[0] = IntNode(int(p[1])) + p[0].add_line_column(p.lineno(1), find_column( + p.lexer.lexdata, p.lexpos(1))) def p_atom_id(self, p): '''atom : ID''' p[0] = VarNode(p[1]) + p[0].add_line_column(p.lineno(1), find_column( + p.lexer.lexdata, p.lexpos(1))) def p_atom_bool(self, p): '''atom : BOOL''' p[0] = BoolNode(p[1]) + p[0].add_line_column(p.lineno(1), find_column( + p.lexer.lexdata, p.lexpos(1))) def p_atom_string(self, p): '''atom : STRING''' p[0] = StringNode(p[1]) + p[0].add_line_column(p.lineno(1), find_column( + p.lexer.lexdata, p.lexpos(1))) def p_atom_new(self, p): '''atom : NEW TYPE''' p[0] = NewNode(p[2]) - + p[0].add_line_column(p.lineno(2), find_column( + p.lexer.lexdata, p.lexpos(2))) + def p_atom_block(self, p): '''atom : block''' p[0] = p[1] - + def p_block(self, p): '''block : LBRACE block_list RBRACE''' p[0] = p[2] - + def p_block_list(self, p): ''' block_list : expr SEMICOLON | expr SEMICOLON block_list''' - p[0] = BlockNode([p[1]]) if len(p) == 3 else BlockNode([p[1]] + p[3].exprs) + p[0] = BlockNode([p[1]]) if len( + p) == 3 else BlockNode([p[1]] + p[3].exprs) def p_error(self, p): - pass - + if p: + self.lexer.add_line_column(p) + self.errors.append(SyntacticError(f'ERROR at or near {p.value}', p.line, p.column) + else: + self.errors.append(SyntacticError(f'ERROR at or near EOF', 0, 0) diff --git a/src/utils/errors.py b/src/utils/errors.py index f38c4dc68..45d5855b6 100644 --- a/src/utils/errors.py +++ b/src/utils/errors.py @@ -15,3 +15,13 @@ def __repr__(self): class LexicographicError(CoolError): def __init__(self, text, line, column): super().__init__('LexicograficError', text, line, column) + + +class SyntacticError(CoolError): + def __init__(self, text, line, column): + super().__init__('SyntacticError', text, line, column) + + +class SemanticError(CoolError): + def __init__(self, text, line, column): + super().__init__('SemanticError', text, line, column) diff --git a/src/utils/utils.py b/src/utils/utils.py new file mode 100644 index 000000000..743031b0d --- /dev/null +++ b/src/utils/utils.py @@ -0,0 +1,3 @@ +def find_column(text, pos): + line_start = text.rfind('\n', 0, pos) + 1 + return (pos - line_start) + 1 From c1f6b8b82e5885f336378580e0f2ef15a7b5259d Mon Sep 17 00:00:00 2001 From: cwjki Date: Mon, 18 Oct 2021 19:44:01 -0400 Subject: [PATCH 023/194] not finished expr parser --- src/1_sintactic/parser.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/1_sintactic/parser.py b/src/1_sintactic/parser.py index d38ae2f0e..96364d341 100644 --- a/src/1_sintactic/parser.py +++ b/src/1_sintactic/parser.py @@ -66,6 +66,8 @@ def p_def_attr(self, p): def p_def_func(self, p): '''def_func : ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACE''' p[0] = FuncDeclarationNode(p[1], p[3], p[6], p[8]) + p[0].add_line_column(p.lineno(6), find_column( + p.lexer.lexdata, p.lexpos(6))) def p_params(self, p): '''params : param_list @@ -85,6 +87,36 @@ def p_param(self, p): '''param : ID COLON TYPE''' p[0] = (p[1], p[3]) + def p_expr_flow(self, p): + '''expr : LET let_attrs IN expr + | CASE expr OF case_list ESAC + | IF expr THEN expr ELSE expr FI + | WHILE expr LOOP expr POOL''' + + if p[1].lower() == 'let': + p[0] = LetNode(p[2], p[4]) + elif p[1].lower() == 'case': + p[0] = CaseNode(p[2], p[4]) + elif p[1].lower() == 'if': + p[0] = IfNode(p[2], p[4], p[6]) + elif p[1].lower() == 'while': + p[0] = WhileNode(p[2], p[4]) + + p[0].add_line_column(p.lineno(2), find_column( + p.lexer.lexdata, p.lexpos(2))) + + def p_expr_assign(self, p): + '''expr : ID ASSIGN expr''' + p[0] = AssignNode(p[1], p[3]) + p[0].add_line_column(p.lineno(1), find_column( + p.lexer.lexdata, p.lexpos(1))) + + def p_expr_func_call(self, p): + '''expr : expr AT TYPE DOT ID LPAREN args RPAREN + | expr DOT ID LPAREN args RPAREN + | ID LPAREN args RPAREN''' + pass + def p_let_attrs(self, p): '''let_attrs : def_attr | def_attr COMMA let_attrs''' From 4a2131f981fa70e104d8274d218a3ee86e6a7e31 Mon Sep 17 00:00:00 2001 From: cwjki Date: Tue, 19 Oct 2021 17:47:05 -0400 Subject: [PATCH 024/194] parser finished, hope :) --- src/1_sintactic/ast.py | 8 ++--- src/1_sintactic/parser.py | 66 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 67 insertions(+), 7 deletions(-) diff --git a/src/1_sintactic/ast.py b/src/1_sintactic/ast.py index f61c9809b..46bbffaf8 100644 --- a/src/1_sintactic/ast.py +++ b/src/1_sintactic/ast.py @@ -141,7 +141,7 @@ class DivNode(BinaryNode): pass -class LessThanNode(BinaryNode): +class LessNode(BinaryNode): pass @@ -149,7 +149,7 @@ class LessEqNode(BinaryNode): pass -class EqNode(BinaryNode): +class EqualNode(BinaryNode): pass @@ -165,10 +165,6 @@ class NotNode(UnaryNode): pass -class LogicNotNode(UnaryNode): - pass - - class AtomicNode(UnaryNode): pass diff --git a/src/1_sintactic/parser.py b/src/1_sintactic/parser.py index 96364d341..651bc63b6 100644 --- a/src/1_sintactic/parser.py +++ b/src/1_sintactic/parser.py @@ -115,7 +115,71 @@ def p_expr_func_call(self, p): '''expr : expr AT TYPE DOT ID LPAREN args RPAREN | expr DOT ID LPAREN args RPAREN | ID LPAREN args RPAREN''' - pass + if len(p) == 9: + if p[7] is None: + p[7] = [] + p[0] = FuncCallNode(p[5], p[7], p[1], p[3]) + p[0].add_line_column(p.lineno(5), find_column( + p.lexer.lexdata, p.lexpos(5))) + elif len(p) == 7: + if p[5] is None: + p[5] = [] + p[0] = FuncCallNode(p[3], p[5], p[1]) + p[0].add_line_column(p.lineno(3), find_column( + p.lexer.lexdata, p.lexpos(3))) + else: + if p[3] is None: + p[3] = [] + p[0] = FuncCallNode(p[1], p[3]) + p[0].add_line_column(p.lineno(1), find_column( + p.lexer.lexdata, p.lexpos(1))) + + p[0].lineno = p.lineno(0) + + def p_expr_operators_binary(self, p): + '''expr : expr PLUS expr + | expr MINUS expr + | expr STAR expr + | expr DIV expr + | expr LESS expr + | expr LESSEQ expr + | expr EQUAL expr''' + if p[2] == '+': + p[0] = PlusNode(p[1], p[3]) + elif p[2] == '-': + p[0] = MinusNode(p[1], p[3]) + elif p[2] == '*': + p[0] = StarNode(p[1], p[3]) + elif p[2] == '/': + p[0] = DivNode(p[1], p[3]) + elif p[2] == '<': + p[0] = LessNode(p[1], p[3]) + elif p[2] == '<=': + p[0] = LessEqNode(p[1], p[3]) + elif p[2] == '<=': + p[0] = EqualNode(p[1], p[3]) + + p[0].add_line_column(p.lineno(0), find_column( + p.lexer.lexdata, p.lexpos(0))) + + def p_expr_operators_unary(self, p): + '''expr : NOT expr + | ISVOID expr''' + if p[1] == '~': + p[0] = NegationNode(p[2]) + elif p[1].lower() == 'isvoid': + p[0] = IsVoidNode(p[2]): + + p[0].add_line_column(p.lineno(2), find_column( + p.lexer.lexdata, p.lexpos(2))) + + def p_expr_group(self, p): + '''expr : LPAREN expr RPAREN''' + p[0] = p[2] + + def p_expr_atom(self, p): + '''expr : atom''' + p[0] = p[1] def p_let_attrs(self, p): '''let_attrs : def_attr From 039de67b2ee52b32c92736083db95b055bde170c Mon Sep 17 00:00:00 2001 From: cwjki Date: Tue, 19 Oct 2021 18:45:26 -0400 Subject: [PATCH 025/194] before testing lexer and parser --- src/1_sintactic/lexer.py | 14 -------------- src/main.py | 25 +++++++++++++++++++++++++ src/utils/utils.py | 14 ++++++++++++++ 3 files changed, 39 insertions(+), 14 deletions(-) create mode 100644 src/main.py diff --git a/src/1_sintactic/lexer.py b/src/1_sintactic/lexer.py index 4def179ff..ee9421dfd 100644 --- a/src/1_sintactic/lexer.py +++ b/src/1_sintactic/lexer.py @@ -321,17 +321,3 @@ def run(self, text): raise Exception() return tokens - - -class Token: - def __init__(self, lex, token_type, row, column): - self.lex = lex - self.type = token_type - self.line = line - self.column = column - - def __str__(self): - return f'{self.type}: {self.lex} ({self.line}, {self.column})' - - def __repr__(self): - return str(self) diff --git a/src/main.py b/src/main.py new file mode 100644 index 000000000..f3bc476f7 --- /dev/null +++ b/src/main.py @@ -0,0 +1,25 @@ +import sys +from lexer import CoolLexer +from parser import CoolParser + + +def main(input, output): + try: + with open(input) as f: + text = f.read() + + lexer = CoolLexer() + tokens = lexer.run(text) + + parser = CoolParser(lexer) + ast = parser.parse(text, debug=True) + + except FileNotFoundError: + pass + + +if __name__ == "__main__": + input = sys.argv[1] + output = sys.argv[2] + + main(input, output) diff --git a/src/utils/utils.py b/src/utils/utils.py index 743031b0d..0bbabdaa9 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -1,3 +1,17 @@ def find_column(text, pos): line_start = text.rfind('\n', 0, pos) + 1 return (pos - line_start) + 1 + + +class Token: + def __init__(self, lex, token_type, row, column): + self.lex = lex + self.type = token_type + self.line = line + self.column = column + + def __str__(self): + return f'{self.type}: {self.lex} ({self.line}, {self.column})' + + def __repr__(self): + return str(self) From 6fb5b21e0a5f0d478b1e3a1614778b7e9421a0ba Mon Sep 17 00:00:00 2001 From: cwjki Date: Tue, 19 Oct 2021 19:29:03 -0400 Subject: [PATCH 026/194] fixing some names and imports --- src/lexer/__init__.py | 1 + src/{1_sintactic => lexer}/lexer.py | 0 src/main.py | 1 - src/parser/__init__.py | 1 + src/{1_sintactic => parser}/ast.py | 0 src/{1_sintactic => parser}/parser.py | 0 src/test.cl | 10 ++++++++++ src/utils/__init__.py | 1 + 8 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 src/lexer/__init__.py rename src/{1_sintactic => lexer}/lexer.py (100%) create mode 100644 src/parser/__init__.py rename src/{1_sintactic => parser}/ast.py (100%) rename src/{1_sintactic => parser}/parser.py (100%) create mode 100644 src/test.cl create mode 100644 src/utils/__init__.py diff --git a/src/lexer/__init__.py b/src/lexer/__init__.py new file mode 100644 index 000000000..355693011 --- /dev/null +++ b/src/lexer/__init__.py @@ -0,0 +1 @@ +from lexer.lexer import CoolLexer diff --git a/src/1_sintactic/lexer.py b/src/lexer/lexer.py similarity index 100% rename from src/1_sintactic/lexer.py rename to src/lexer/lexer.py diff --git a/src/main.py b/src/main.py index f3bc476f7..593de752e 100644 --- a/src/main.py +++ b/src/main.py @@ -1,6 +1,5 @@ import sys from lexer import CoolLexer -from parser import CoolParser def main(input, output): diff --git a/src/parser/__init__.py b/src/parser/__init__.py new file mode 100644 index 000000000..d5cd44fbb --- /dev/null +++ b/src/parser/__init__.py @@ -0,0 +1 @@ +from parser.parser import CoolParser diff --git a/src/1_sintactic/ast.py b/src/parser/ast.py similarity index 100% rename from src/1_sintactic/ast.py rename to src/parser/ast.py diff --git a/src/1_sintactic/parser.py b/src/parser/parser.py similarity index 100% rename from src/1_sintactic/parser.py rename to src/parser/parser.py diff --git a/src/test.cl b/src/test.cl new file mode 100644 index 000000000..2cbd6819c --- /dev/null +++ b/src/test.cl @@ -0,0 +1,10 @@ +class Main inherits IO { + a : String <- case 1 of + n : Main => n.type_name(); + a : Int => a.type_name(); + esac; + + main(): IO { + out_string(a) + }; +}; \ No newline at end of file diff --git a/src/utils/__init__.py b/src/utils/__init__.py new file mode 100644 index 000000000..59fff5689 --- /dev/null +++ b/src/utils/__init__.py @@ -0,0 +1 @@ +from utils.utils import find_column, Token From 70169967c3ba3a0d73fac1ef978f4f06f96ec092 Mon Sep 17 00:00:00 2001 From: cwjki Date: Tue, 26 Oct 2021 17:10:34 -0400 Subject: [PATCH 027/194] fixing some typos in parser.py --- src/__init__.py | 0 src/main.py | 1 + src/parser/parser.py | 7 ++++--- 3 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 src/__init__.py diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/main.py b/src/main.py index 593de752e..623ede777 100644 --- a/src/main.py +++ b/src/main.py @@ -1,4 +1,5 @@ import sys +from parser import CoolParser from lexer import CoolLexer diff --git a/src/parser/parser.py b/src/parser/parser.py index 651bc63b6..a98c2b79a 100644 --- a/src/parser/parser.py +++ b/src/parser/parser.py @@ -168,7 +168,7 @@ def p_expr_operators_unary(self, p): if p[1] == '~': p[0] = NegationNode(p[2]) elif p[1].lower() == 'isvoid': - p[0] = IsVoidNode(p[2]): + p[0] = IsVoidNode(p[2]) p[0].add_line_column(p.lineno(2), find_column( p.lexer.lexdata, p.lexpos(2))) @@ -258,6 +258,7 @@ def p_block_list(self, p): def p_error(self, p): if p: self.lexer.add_line_column(p) - self.errors.append(SyntacticError(f'ERROR at or near {p.value}', p.line, p.column) + self.errors.append(SyntacticError( + f'ERROR at or near {p.value}', p.line, p.column)) else: - self.errors.append(SyntacticError(f'ERROR at or near EOF', 0, 0) + self.errors.append(SyntacticError(f'ERROR at or near EOF', 0, 0)) From 1695462e1e7854948d2912f2dd3c50ec7ba49b3f Mon Sep 17 00:00:00 2001 From: cwjki Date: Tue, 26 Oct 2021 17:24:06 -0400 Subject: [PATCH 028/194] adding visitor .py --- src/utils/visitor.py | 82 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/utils/visitor.py diff --git a/src/utils/visitor.py b/src/utils/visitor.py new file mode 100644 index 000000000..d4f2e4d7c --- /dev/null +++ b/src/utils/visitor.py @@ -0,0 +1,82 @@ +# The MIT License (MIT) +# +# Copyright (c) 2013 Curtis Schlak +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +import inspect + +__all__ = ['on', 'when'] + + +def on(param_name): + def f(fn): + dispatcher = Dispatcher(param_name, fn) + return dispatcher + return f + + +def when(param_type): + def f(fn): + frame = inspect.currentframe().f_back + func_name = fn.func_name if 'func_name' in dir(fn) else fn.__name__ + dispatcher = frame.f_locals[func_name] + if not isinstance(dispatcher, Dispatcher): + dispatcher = dispatcher.dispatcher + dispatcher.add_target(param_type, fn) + + def ff(*args, **kw): + return dispatcher(*args, **kw) + ff.dispatcher = dispatcher + return ff + return f + + +class Dispatcher(object): + def __init__(self, param_name, fn): + frame = inspect.currentframe().f_back.f_back + top_level = frame.f_locals == frame.f_globals + self.param_index = self.__argspec(fn).args.index(param_name) + self.param_name = param_name + self.targets = {} + + def __call__(self, *args, **kw): + typ = args[self.param_index].__class__ + d = self.targets.get(typ) + if d is not None: + return d(*args, **kw) + else: + issub = issubclass + t = self.targets + ks = t.keys() + ans = [t[k](*args, **kw) for k in ks if issub(typ, k)] + if len(ans) == 1: + return ans.pop() + return ans + + def add_target(self, typ, target): + self.targets[typ] = target + + @staticmethod + def __argspec(fn): + # Support for Python 3 type hints requires inspect.getfullargspec + if hasattr(inspect, 'getfullargspec'): + return inspect.getfullargspec(fn) + else: + return inspect.getargspec(fn) From 3b336510bcf085d1bf58333cc1711747de053d68 Mon Sep 17 00:00:00 2001 From: cwjki Date: Wed, 27 Oct 2021 14:34:40 -0400 Subject: [PATCH 029/194] starting the semantic analyser --- src/semantic/semantic.py | 9 +++++++++ src/semantic/visitors/type_collector.py | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/semantic/semantic.py create mode 100644 src/semantic/visitors/type_collector.py diff --git a/src/semantic/semantic.py b/src/semantic/semantic.py new file mode 100644 index 000000000..8f1f8f5cf --- /dev/null +++ b/src/semantic/semantic.py @@ -0,0 +1,9 @@ + + +class SemanticAnalyser: + def __init__(self, ast): + self.ast = ast + self.errors = [] + + def analyse(self): + pass diff --git a/src/semantic/visitors/type_collector.py b/src/semantic/visitors/type_collector.py new file mode 100644 index 000000000..72f8b0800 --- /dev/null +++ b/src/semantic/visitors/type_collector.py @@ -0,0 +1,23 @@ +from utils import visitor + + + + + +class TypeCollector(object): + def __init__(self, errors = []): + self.context = None + self.errors = errors + + @visitor.on('node') + def visit(self, node): + pass + + + @visitor.when(ProgramNode) + def visit(self, node): + pass + + @visitor.when(ClassDeclarationNode) + def visit(self, node): + pass From 72acd2460ca2ac152d4b556c10bbe3e7ad94b4a7 Mon Sep 17 00:00:00 2001 From: cwjki Date: Wed, 27 Oct 2021 18:19:32 -0400 Subject: [PATCH 030/194] creating semantic types --- .vscode/settings.json | 4 ++ src/semantic/types.py | 111 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 src/semantic/types.py diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..cc67606f3 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "python.linting.pylintEnabled": true, + "python.linting.enabled": true +} \ No newline at end of file diff --git a/src/semantic/types.py b/src/semantic/types.py new file mode 100644 index 000000000..2eead1bb2 --- /dev/null +++ b/src/semantic/types.py @@ -0,0 +1,111 @@ +from utils.errors import SemanticError + + +class Attribute: + def __init__(self, name, typex, index): + self.name = name + self.type = typex + self.index = index + self.expr = None + + def __str__(self): + return f'[attr] {self.name} : {self.type.name}' + + def __repr__(self): + return str(self) + + +class Method: + def __init__(self, name, param_names, param_types, return_type): + self.name = name + self.param_names = param_names + self.param_types = param_types + self.return_type = return_type + + +class Type: + def __init__(self, name, position, parent=True): + if name == 'ObjectType': + return ObjectType(position) + self.name = name + self.attributes = {} + self.methods = {} + self.position = position + if parent: + self.parent = ObjectType(position) + else: + self.parent = None + + def set_parent(self, parent): + if type(self.parent) != ObjectType and self.parent is not None: + line, column = self.position + raise SemanticError( + f'Parent already defined for {self.name}', line, column) + self.parent = parent + + def get_attribute(self, name, position): + try: + return self.attributes[name] + except KeyError: + if self.parent is None: + line, column = self.position + raise SemanticError( + f'Attribute {name} is not defined in {self.name}', line, column) + try: + return self.parent.get_attribute(name, position) + except: + line, column = self.position + raise SemanticError( + f'Attribute {name} is not defined in {self.name}', line, column) + + def define_attribute(self, name, typex, position): + try: + self.attributes[name] + except KeyError: + try: + self.get_attribute(name, position) + except SemanticError: + attribute = Attribute(name, typex, len(self.attributes)) + self.attributes[name] = attribute + return attribute + else: + line, column = self.position + raise SemanticError( + f'Attribute {name} is an attribute of an inherited class', line, column) + else: + line, column = self.position + raise SemanticError( + f'Attribute {name} is already defined', line, column) + + def get_method(self, name, position): + try: + return self.methods[name] + except KeyError: + if self.parent is None: + line, column = self.position + raise SemanticError( + f'Method {name} is not defined in {self.name}', line, column) + try: + return self.parent.get_method(name, position) + except: + line, column = self.position + raise SemanticError( + f'Method {name} is not defined in {self.name}', line, column) + + def define_method(self, name, param_names, param_types, return_type, position=(0, 0)): + if name in self.methods: + line, column = self.position + raise SemanticError( + f'Method {name} is already defined', line, column) + + method = self.methods[name] = Method(name, param_names, param_types, return_type) + return method + + +class ObjectType(Type): + def __init__(self, position=(0, 0)): + self.name = 'Object' + self.attributes = {} + self.methods = {} + self.parent = None + self.position = position From 32ce1da1bc4939dbbade2394b92bb52ac123ce42 Mon Sep 17 00:00:00 2001 From: Juan Carlos Casteleiro Wong Date: Tue, 4 Jan 2022 13:11:49 -0500 Subject: [PATCH 031/194] test develop branch --- src/main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.py b/src/main.py index 623ede777..177591f32 100644 --- a/src/main.py +++ b/src/main.py @@ -2,6 +2,8 @@ from parser import CoolParser from lexer import CoolLexer +#develop branch + def main(input, output): try: From e3d2432477a34a702d40933ffad629555e3bca0d Mon Sep 17 00:00:00 2001 From: Juan Carlos Casteleiro Wong Date: Tue, 4 Jan 2022 13:20:41 -0500 Subject: [PATCH 032/194] jki test --- src/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.py b/src/main.py index 177591f32..7acd332ee 100644 --- a/src/main.py +++ b/src/main.py @@ -3,6 +3,7 @@ from lexer import CoolLexer #develop branch +#jki branch def main(input, output): From 47c4dbb05cc57d421a8724a81ea3c8a7b30d69fb Mon Sep 17 00:00:00 2001 From: liviton Date: Tue, 4 Jan 2022 19:32:41 +0100 Subject: [PATCH 033/194] a --- src/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.py b/src/main.py index 177591f32..728f2a58a 100644 --- a/src/main.py +++ b/src/main.py @@ -3,7 +3,7 @@ from lexer import CoolLexer #develop branch - +#livi test def main(input, output): try: From 6494d0beedacc81290e6306651e415a37ec943c3 Mon Sep 17 00:00:00 2001 From: Juan Carlos Casteleiro Wong Date: Tue, 4 Jan 2022 13:46:39 -0500 Subject: [PATCH 034/194] final test git --- src/main.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main.py b/src/main.py index 27ccc7616..623ede777 100644 --- a/src/main.py +++ b/src/main.py @@ -2,10 +2,6 @@ from parser import CoolParser from lexer import CoolLexer -#develop branch -#jki branch - -#livi test def main(input, output): try: From 7a559e7b42bc3b3fce8da4ad728fba4e2b680fc8 Mon Sep 17 00:00:00 2001 From: Juan Carlos Casteleiro Wong Date: Tue, 4 Jan 2022 18:09:05 -0500 Subject: [PATCH 035/194] fixing typos in lexer.py --- src/lexer/lexer.py | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/lexer/lexer.py b/src/lexer/lexer.py index ee9421dfd..3fbcabcaf 100644 --- a/src/lexer/lexer.py +++ b/src/lexer/lexer.py @@ -1,14 +1,9 @@ -import ply.lex as lex -from utils.errors import * +from ply import lex +from src.utils.errors import LexicographicError +from src.utils.utils import Token class CoolLexer: - def __init__(self, **kwargs): - self.errors = [] - self.lexer = lex.lex(modele=self, **kwargs) - self.lexer.lineno = 1 - self.lexer.linestart = 0 - self.errors = [] states = ( ('comments', 'exclusive'), @@ -63,11 +58,15 @@ def __init__(self, **kwargs): 'NOT' ] + list(reserved.values()) + def __init__(self, **kwargs): + self.errors = [] + self.lexer = lex.lex(module=self, **kwargs) + self.lexer.lineno = 1 + self.lexer.linestart = 0 + self.errors = [] + self.text = None + # Comments - def t_comment(self, t): - r'--.*($|\n)' - t.lexer.lineno += 1 - t.lexer.linestart = t.lexer.lexpos def t_comments(self, t): r'\(\*' @@ -131,13 +130,13 @@ def t_strings_newline(self, t): if not t.lexer.backslash: self.errors.append(LexicographicError( - 'Undeterminated string constant'), t.line, t.column) + 'Undeterminated string constant', t.line, t.column)) t.lexer.begin('INITIAL') def t_strings_nill(self, t): r'\0' self.add_line_column(t) - self.errors.append(LexicographicErroricError( + self.errors.append(LexicographicError( 'Null caracter in string', t.line, t.column)) def t_strings_consume(self, t): @@ -157,7 +156,7 @@ def t_strings_consume(self, t): else: t.lexer.string += t.value - t.backslash = FALSE + t.backslash = False else: if t.value != '\\': t.lexer.string += t.value @@ -166,7 +165,7 @@ def t_strings_consume(self, t): def t_strings_eof(self, t): self.add_line_column(t) - self.errors.append(LexicographicErroricError( + self.errors.append(LexicographicError( 'EOF in string constant', t.line, t.column)) def find_column(self, t): @@ -194,7 +193,7 @@ def t_LBRACE(self, t): self.add_line_column(t) return t - def t_RPAREN(self, t): + def t_RBRACE(self, t): r'\}' self.add_line_column(t) return t @@ -300,17 +299,18 @@ def t_newline(self, t): def t_error(self, t): self.add_line_column(t) self.errors.append(LexicographicError( - f'ERROR \"{t.value[0]}\"', line, column)) + f'ERROR \"{t.value[0]}\"', t.line, t.column)) t.lexer.skip(1) def tokenize(self, text): + self.text = text self.lexer.input(text) tokens = [] for token in self.lexer: tokens.append(Token(token.value, token.type, token.row, token.column)) self.lexer.lineno = 1 - self.linestart = 0 + self.lexer.linestart = 0 return tokens def run(self, text): From 8f5f8cfb87003dcdb1f46e1be8c1822b9c172e76 Mon Sep 17 00:00:00 2001 From: Juan Carlos Casteleiro Wong Date: Tue, 4 Jan 2022 18:42:37 -0500 Subject: [PATCH 036/194] fixing warnings in ast.py --- src/lexer/__init__.py | 2 +- src/lexer/lexer.py | 1 + src/parser/__init__.py | 2 +- src/parser/ast.py | 32 ++++++++++++++++---------------- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/lexer/__init__.py b/src/lexer/__init__.py index 355693011..45457d048 100644 --- a/src/lexer/__init__.py +++ b/src/lexer/__init__.py @@ -1 +1 @@ -from lexer.lexer import CoolLexer +from src.lexer.lexer import CoolLexer diff --git a/src/lexer/lexer.py b/src/lexer/lexer.py index 3fbcabcaf..ee5d1af30 100644 --- a/src/lexer/lexer.py +++ b/src/lexer/lexer.py @@ -1,4 +1,5 @@ from ply import lex + from src.utils.errors import LexicographicError from src.utils.utils import Token diff --git a/src/parser/__init__.py b/src/parser/__init__.py index d5cd44fbb..e52103032 100644 --- a/src/parser/__init__.py +++ b/src/parser/__init__.py @@ -1 +1 @@ -from parser.parser import CoolParser +from src.parser.parser import CoolParser diff --git a/src/parser/ast.py b/src/parser/ast.py index 46bbffaf8..835ffc441 100644 --- a/src/parser/ast.py +++ b/src/parser/ast.py @@ -28,15 +28,15 @@ def __init__(self, name, params, return_type, expr=None): self.name = name self.params = params self.return_type = return_type - self.exp = exp + self.expr = expr class AttrDeclarationNode(Node): - def __init__(self, name, type, expr=None): + def __init__(self, name, typex, expr=None): super().__init__() self.name = name - self.type = type - self.exp = exp + self.type = typex + self.expr = expr class ExpressionNode(Node): @@ -53,12 +53,12 @@ def __init__(self, name, expr): class FuncCallNode(ExpressionNode): - def __init__(self, id, args, object=None, type=None): + def __init__(self, idx, args, obj=None, typex=None): super().__init__() - self.id = id + self.id = idx self.args = args - self.object = object - self.type = type + self.object = obj + self.type = typex class IfNode(ExpressionNode): @@ -93,27 +93,27 @@ class CaseNode(ExpressionNode): def __init__(self, expr, case_list): super().__init__() self.expr = expr - self.case_list = case_list: + self.case_list = case_list class CaseOptionNode(ExpressionNode): - def __init__(self, id, type, expr): + def __init__(self, idx, typex, expr): super().__init__() - self.id = id + self.id = idx self.expr = expr - self.type = type + self.type = typex class VarNode(ExpressionNode): - def __init__(self, id): + def __init__(self, idx): super().__init__() - self.id = id + self.id = idx class NewNode(ExpressionNode): - def __init__(self, type): + def __init__(self, typex): super().__init__() - self.type = type + self.type = typex # ---------------- Binary Nodes ------------------ From 307370f822409a9ea96113abd5560add40b551b9 Mon Sep 17 00:00:00 2001 From: Juan Carlos Casteleiro Wong Date: Tue, 4 Jan 2022 19:15:54 -0500 Subject: [PATCH 037/194] fixing warnings in parser.py --- src/parser/parser.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/parser/parser.py b/src/parser/parser.py index a98c2b79a..fd61f139c 100644 --- a/src/parser/parser.py +++ b/src/parser/parser.py @@ -1,6 +1,7 @@ -import ply.yacc as yacc -from ast import * -from utils.utils import * +from ply import yacc +from src.parser.ast import * +from src.utils.errors import SyntacticError +from src.utils.utils import find_column class CoolParser: @@ -28,7 +29,6 @@ def p_program(self, p): def p_epsilon(self, p): 'epsilon :' - pass def p_class_list(self, p): '''class_list : def_class SEMICOLON class_list @@ -166,7 +166,7 @@ def p_expr_operators_unary(self, p): '''expr : NOT expr | ISVOID expr''' if p[1] == '~': - p[0] = NegationNode(p[2]) + p[0] = NotNode(p[2]) elif p[1].lower() == 'isvoid': p[0] = IsVoidNode(p[2]) @@ -207,7 +207,7 @@ def p_arg_list(self, p): | expr COMMA arg_list''' p[0] = [p[1]] if len(p) == 2 else [p[1]] + p[3] - def p_arg_list_empty(p): + def p_arg_list_empty(self, p): '''arg_list_empty : epsilon''' p[0] = [] @@ -261,4 +261,4 @@ def p_error(self, p): self.errors.append(SyntacticError( f'ERROR at or near {p.value}', p.line, p.column)) else: - self.errors.append(SyntacticError(f'ERROR at or near EOF', 0, 0)) + self.errors.append(SyntacticError('ERROR at or near EOF', 0, 0)) From 74f5d0fcbc9e309f4afec6d5505121222b595c63 Mon Sep 17 00:00:00 2001 From: Juan Carlos Casteleiro Wong Date: Wed, 5 Jan 2022 17:00:43 -0500 Subject: [PATCH 038/194] fixed all warning from lexer and parser --- src/main.py | 18 ++++++++++++------ src/parser/parser.py | 2 +- src/utils/__init__.py | 2 +- src/utils/errors.py | 4 ++-- src/utils/utils.py | 2 +- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/main.py b/src/main.py index 623ede777..19ea5dad5 100644 --- a/src/main.py +++ b/src/main.py @@ -1,6 +1,7 @@ import sys -from parser import CoolParser -from lexer import CoolLexer + +from src.lexer import CoolLexer +from src.parser import CoolParser def main(input, output): @@ -10,16 +11,21 @@ def main(input, output): lexer = CoolLexer() tokens = lexer.run(text) + print(tokens) parser = CoolParser(lexer) - ast = parser.parse(text, debug=True) + + ast = parser.parse(text) + print(ast) + if parser.errors: + raise Exception() except FileNotFoundError: pass if __name__ == "__main__": - input = sys.argv[1] - output = sys.argv[2] + input_ = sys.argv[1] + output_ = sys.argv[2] - main(input, output) + main(input_, output_) diff --git a/src/parser/parser.py b/src/parser/parser.py index fd61f139c..10378d2a2 100644 --- a/src/parser/parser.py +++ b/src/parser/parser.py @@ -21,7 +21,7 @@ def __init__(self, lexer): ) def parse(self, program): - pass + return self.parser.parse(program, self.lexer.lexer) def p_program(self, p): 'program : class_list' diff --git a/src/utils/__init__.py b/src/utils/__init__.py index 59fff5689..46e01819d 100644 --- a/src/utils/__init__.py +++ b/src/utils/__init__.py @@ -1 +1 @@ -from utils.utils import find_column, Token +from src.utils.utils import find_column, Token diff --git a/src/utils/errors.py b/src/utils/errors.py index 45d5855b6..789bc67b7 100644 --- a/src/utils/errors.py +++ b/src/utils/errors.py @@ -1,12 +1,12 @@ class CoolError(): def __init__(self, error_type, text, line, column): - self.type = type + self.type = error_type self.text = text self.line = line self.column = column def __str__(self): - return f'({self.line, self.column}) - {self.error_type}: {self.text}' + return f'({self.line, self.column}) - {self.type}: {self.text}' def __repr__(self): return str(self) diff --git a/src/utils/utils.py b/src/utils/utils.py index 0bbabdaa9..c5ca8c808 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -7,7 +7,7 @@ class Token: def __init__(self, lex, token_type, row, column): self.lex = lex self.type = token_type - self.line = line + self.line = row self.column = column def __str__(self): From 2d23c6ec33a1705710292f984198bfae5d46ac20 Mon Sep 17 00:00:00 2001 From: cwjki Date: Wed, 5 Jan 2022 18:28:15 -0500 Subject: [PATCH 039/194] trying wsl on windows --- src/main.py | 62 ++++++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/main.py b/src/main.py index 19ea5dad5..879798d6d 100644 --- a/src/main.py +++ b/src/main.py @@ -1,31 +1,31 @@ -import sys - -from src.lexer import CoolLexer -from src.parser import CoolParser - - -def main(input, output): - try: - with open(input) as f: - text = f.read() - - lexer = CoolLexer() - tokens = lexer.run(text) - print(tokens) - - parser = CoolParser(lexer) - - ast = parser.parse(text) - print(ast) - if parser.errors: - raise Exception() - - except FileNotFoundError: - pass - - -if __name__ == "__main__": - input_ = sys.argv[1] - output_ = sys.argv[2] - - main(input_, output_) +import sys + +from src.lexer import CoolLexer +from src.parser import CoolParser + + +def main(input, output): + try: + with open(input) as f: + text = f.read() + + lexer = CoolLexer() + tokens = lexer.run(text) + print(tokens) + + parser = CoolParser(lexer) + + ast = parser.parse(text) + print(ast) + if parser.errors: + raise Exception() + + except FileNotFoundError: + pass + + +if __name__ == "__main__": + input_ = sys.argv[1] + output_ = sys.argv[2] + + main(input_, output_) From e84b084021118232fb67f546433504dfae68fdb4 Mon Sep 17 00:00:00 2001 From: liviton Date: Thu, 6 Jan 2022 00:49:05 +0100 Subject: [PATCH 040/194] cil_ast pag 7 conf hasta arith --- src/code_generator/cil_ast.py | 78 +++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/code_generator/cil_ast.py diff --git a/src/code_generator/cil_ast.py b/src/code_generator/cil_ast.py new file mode 100644 index 000000000..56fc30b46 --- /dev/null +++ b/src/code_generator/cil_ast.py @@ -0,0 +1,78 @@ +class ASTNode: + def __init__(self): + pass + def __repr__(self): + return str(self) + +class ProgramNode(ASTNode): + def __init__(self, dottypes, dotdata, dotcode): + self.dottypes = dottypes + self.dotdata = dotdata + self.dotcode = dotcode + +#.TYPE +class TypeNode(ASTNode): + def __init__(self, name): + self.name = name + self.attributes = [] + self.methods = {} + +#.DATA +class DataNode(ASTNode): + def __init__(self, vname, value): + self.name = vname + self.value = value + +#.CODE +class FunctionNode(ASTNode): + def __init__(self, name, params=[], localvars=[], instructions =[]): + self.name = name + self.params = params + self.localvars = localvars + self.instructions = instructions + +class ExpressionNode(ASTNode): + def __init__(self): + pass + +#sin type expression +class ParamNode(ExpressionNode): + def __init__(self, name): + self.name = name + +class LocalNode(ExpressionNode): + def __init__(self, name): + self.name = name + +class AssignNode(ExpressionNode): + def __init__(self, dest, expr): + self.dest = dest + self.expr = expr + +class ArithExpressionNode(ExpressionNode): + def __init__(self, dest, left, right): + self.dest = dest + self.left = left + self.right = right + +class PlusNode(ArithExpressionNode): + pass + +class MinusNode(ArithExpressionNode): + pass + +class StarNode(ArithExpressionNode): + pass + +class DivNode(ArithExpressionNode): + pass + +class LessNode(ArithExpressionNode): + pass + +class LessEqualNode(ArithExpressionNode): + pass + +class EqualNode(ArithExpressionNode): + pass + From 1c0b7f41bc9bd3e1db66c8449a15a50127e67542 Mon Sep 17 00:00:00 2001 From: liviton Date: Thu, 6 Jan 2022 02:01:05 +0100 Subject: [PATCH 041/194] cil_ast pag 11 conf hasta vcall --- src/code_generator/cil_ast.py | 73 +++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/src/code_generator/cil_ast.py b/src/code_generator/cil_ast.py index 56fc30b46..abc95cf81 100644 --- a/src/code_generator/cil_ast.py +++ b/src/code_generator/cil_ast.py @@ -55,6 +55,7 @@ def __init__(self, dest, left, right): self.left = left self.right = right +#Arith class PlusNode(ArithExpressionNode): pass @@ -76,3 +77,75 @@ class LessEqualNode(ArithExpressionNode): class EqualNode(ArithExpressionNode): pass +#Attr +class GetAttrNode(ExpressionNode): + def __init__(self, dest, instance, attr, static_type): + self.local_dest = dest + self.instance = instance + self.attr = attr + self.static_type = static_type + +class SetAttrNode(ExpressionNode): + def __init__(self, instance, attr, value, static_type): + self.instance = instance + self.attr = attr + self.value = value + self.static_type = static_type + + +#Arrays and Strings +class GetIndexNode(ExpressionNode): + pass +class SetIndexNode(ExpressionNode): + pass + +#Memory +class AllocateNode(ExpressionNode): + def __init__(self, t, dest): + self.type = t + self.local_dest = dest + +class ArrayNode(ExpressionNode): + pass + +class TypeOfNode(ExpressionNode): + def __init__(self, t, dest): + self.var = t + self.local_dest = dest + +#Jumps +class LabelNode(ExpressionNode): + def __init__(self, label): + self.label = label + +class GoToNode(ExpressionNode): + def __init__(self, label): + self.label = label + +class IfGoTo(ExpressionNode): + def __init__(self, condition, label): + self.condition = condition + self.label = label + +#Static Invocation +class CallNode(ExpressionNode): + def __init__(self, dest, func, args, static_type, ret_type): + self.local_dest = dest + self.function = func + self.args = args + self.static_type = static_type + self.ret_type = ret_type + +#Dynamic Invocation +class VCallNode(ExpressionNode): + def __init__(self, instance, dest, func, args, dynamic_type, ret_type): + self.instance = instance + self.local_dest = dest + self.function = func + self.args = args + self.dynamic_type = dynamic_type + self.ret_type = ret_type + + + + From edeae3f14fd86b69103c0c3622e6fef09e34828e Mon Sep 17 00:00:00 2001 From: Juan Carlos Casteleiro Wong Date: Thu, 6 Jan 2022 13:14:08 -0500 Subject: [PATCH 042/194] figthing with the imports pylint --- src/lexer/__init__.py | 2 +- src/lexer/lexer.py | 4 +-- src/main.py | 18 ++++++++------ src/mytest.cl | 55 ++++++++++++++++++++++++++++++++++++++++++ src/parser/__init__.py | 2 +- src/parser/parser.py | 6 ++--- src/utils/__init__.py | 3 ++- 7 files changed, 75 insertions(+), 15 deletions(-) create mode 100644 src/mytest.cl diff --git a/src/lexer/__init__.py b/src/lexer/__init__.py index 45457d048..fef7cff14 100644 --- a/src/lexer/__init__.py +++ b/src/lexer/__init__.py @@ -1 +1 @@ -from src.lexer.lexer import CoolLexer +from .lexer import CoolLexer diff --git a/src/lexer/lexer.py b/src/lexer/lexer.py index ee5d1af30..6b8a1b85a 100644 --- a/src/lexer/lexer.py +++ b/src/lexer/lexer.py @@ -1,7 +1,7 @@ from ply import lex -from src.utils.errors import LexicographicError -from src.utils.utils import Token +from utils.errors import LexicographicError +from utils.utils import Token class CoolLexer: diff --git a/src/main.py b/src/main.py index 879798d6d..61b2e7256 100644 --- a/src/main.py +++ b/src/main.py @@ -1,14 +1,16 @@ import sys -from src.lexer import CoolLexer -from src.parser import CoolParser +from lexer import CoolLexer +from parser import CoolParser -def main(input, output): +def main(input_): try: - with open(input) as f: + with open(input_) as f: text = f.read() + print(text) + lexer = CoolLexer() tokens = lexer.run(text) print(tokens) @@ -25,7 +27,9 @@ def main(input, output): if __name__ == "__main__": - input_ = sys.argv[1] - output_ = sys.argv[2] + # input_ = sys.argv[1] + # output_ = sys.argv[2] + # main(input_, output_) - main(input_, output_) + input_ = 'mytest.cl' + main(input_) diff --git a/src/mytest.cl b/src/mytest.cl new file mode 100644 index 000000000..69533f23c --- /dev/null +++ b/src/mytest.cl @@ -0,0 +1,55 @@ +--Any characters between two dashes “--” and the next newline +--(or EOF, if there is no next newline) are treated as comments + +(*(*(* +Comments may also be written by enclosing +text in (∗ . . . ∗). The latter form of comment may be nested. +Comments cannot cross file boundaries. +*)*)*) + +class Error() { + + (* There was once a comment, + that was quite long. + But, the reader soon discovered that + the comment was indeed longer than + previously assumed. Now, the reader + was in a real dilemma; is the comment + ever gonna end? If I stop reading, will + it end? + He started imagining all sorts of things. + He thought about heisenberg's cat and how + how that relates to the end of the sentence. + He thought to himself "I'm gonna stop reading". + "If I keep reading this comment, I'm gonna know + the fate of this sentence; That will be disastorous." + He knew that such a comment was gonna extend to + another file. It was too awesome to be contained in + a single file. And he would have kept reading too... + if only... + cool wasn't a super-duper-fab-awesomest language; + but cool is that language; + "This comment shall go not cross this file" said cool. + Alas! The reader could read no more. + There was once a comment, + that was quite long. + But, the reader soon discovered that + the comment was indeed longer than + previously assumed. Now, the reader + was in a real dilemma; is the comment + ever gonna end? If I stop reading, will + it end? + He started imagining all sorts of things. + He thought about heisenberg's cat and how + how that relates to the end of the sentence. + He thought to himself "I'm gonna stop reading". + "If I keep reading this comment, I'm gonna know + the fate of this sentence; That will be disastorous." + He knew that such a comment was gonna extend to + another file. It was too awesome to be contained in + a single file. And he would have kept reading too... + if only... + cool wasn't a super-duper-fab-awesomest language; + but cool is that language; + "This comment shall go not cross this file" said cool. + Alas! The reader could read no more. \ No newline at end of file diff --git a/src/parser/__init__.py b/src/parser/__init__.py index e52103032..aab02ac7f 100644 --- a/src/parser/__init__.py +++ b/src/parser/__init__.py @@ -1 +1 @@ -from src.parser.parser import CoolParser +from .parser import CoolParser \ No newline at end of file diff --git a/src/parser/parser.py b/src/parser/parser.py index 10378d2a2..3d7572c46 100644 --- a/src/parser/parser.py +++ b/src/parser/parser.py @@ -1,7 +1,7 @@ from ply import yacc -from src.parser.ast import * -from src.utils.errors import SyntacticError -from src.utils.utils import find_column +from ast import * +from utils.errors import SyntacticError +from utils.utils import find_column class CoolParser: diff --git a/src/utils/__init__.py b/src/utils/__init__.py index 46e01819d..1a7eeac05 100644 --- a/src/utils/__init__.py +++ b/src/utils/__init__.py @@ -1 +1,2 @@ -from src.utils.utils import find_column, Token +from .utils import find_column, Token +from .errors import LexicographicError, SemanticError, SyntacticError \ No newline at end of file From 81abcafe4881ffafecd936c288971b5cca944251 Mon Sep 17 00:00:00 2001 From: liviton Date: Thu, 6 Jan 2022 19:44:22 +0100 Subject: [PATCH 043/194] cil_ast complete --- src/code_generator/cil_ast.py | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/code_generator/cil_ast.py b/src/code_generator/cil_ast.py index abc95cf81..24da63f55 100644 --- a/src/code_generator/cil_ast.py +++ b/src/code_generator/cil_ast.py @@ -147,5 +147,56 @@ def __init__(self, instance, dest, func, args, dynamic_type, ret_type): self.ret_type = ret_type +#Args +class ArgNode(ExpressionNode): + def __init__(self, name): + self.name = name + + +#Return +class ReturnNode(ExpressionNode): + def __init__(self, value): + self.value = value +#IO +class LoadNode(ExpressionNode): + def __init__(self, dest, msg): + self.local_dest = dest + self.msg = msg + +class LengthNode(ExpressionNode): + def __init__(self, dest, arg): + self.local_dest = dest + self.arg = arg + +class ConcatNode(ExpressionNode): + def __init__(self, dest, head, tail): + self.local_dest = dest + self.head = head + self.tail = tail + +class PrefixNode(ExpressionNode): + def __init__(self, dest, string, n): + self.local_dest = dest + self.string = string + self.n = n + +class SubstringNode(ExpressionNode): + def __init__(self, dest, string, begin, final): + self.local_dest = dest + self.begin = begin + self.string = string + self.final = final + +class StrNode(ExpressionNode): + def __init__(self, dest, value): + self.local_dest = dest + self.value = value + +class ReadNode(ExpressionNode): + def __init__(self, dest): + self.local_dest = dest +class PrintNode(ExpressionNode): + def __init__(self, value): + self.value = value \ No newline at end of file From 7e256dd53de0a9471faebb612c92ce7073f7346f Mon Sep 17 00:00:00 2001 From: Juan Carlos Casteleiro Wong Date: Thu, 6 Jan 2022 13:50:57 -0500 Subject: [PATCH 044/194] error in parser uknown location --- src/lexer/__init__.py | 2 +- src/lexer/lexer.py | 2 +- src/mytest.cl | 2 +- src/parser/parser.py | 2 +- src/{parser => utils}/ast.py | 0 5 files changed, 4 insertions(+), 4 deletions(-) rename src/{parser => utils}/ast.py (100%) diff --git a/src/lexer/__init__.py b/src/lexer/__init__.py index fef7cff14..4cc27177f 100644 --- a/src/lexer/__init__.py +++ b/src/lexer/__init__.py @@ -1 +1 @@ -from .lexer import CoolLexer +from .lexer import CoolLexer \ No newline at end of file diff --git a/src/lexer/lexer.py b/src/lexer/lexer.py index 6b8a1b85a..a6a5b4fbc 100644 --- a/src/lexer/lexer.py +++ b/src/lexer/lexer.py @@ -309,7 +309,7 @@ def tokenize(self, text): tokens = [] for token in self.lexer: tokens.append(Token(token.value, token.type, - token.row, token.column)) + token.line, token.column)) self.lexer.lineno = 1 self.lexer.linestart = 0 return tokens diff --git a/src/mytest.cl b/src/mytest.cl index 69533f23c..044a44b3b 100644 --- a/src/mytest.cl +++ b/src/mytest.cl @@ -1,4 +1,4 @@ ---Any characters between two dashes “--” and the next newline +--Any characters between two dashes "-- and the next newline --(or EOF, if there is no next newline) are treated as comments (*(*(* diff --git a/src/parser/parser.py b/src/parser/parser.py index 3d7572c46..0de644747 100644 --- a/src/parser/parser.py +++ b/src/parser/parser.py @@ -1,5 +1,5 @@ from ply import yacc -from ast import * +from utils.ast import * from utils.errors import SyntacticError from utils.utils import find_column diff --git a/src/parser/ast.py b/src/utils/ast.py similarity index 100% rename from src/parser/ast.py rename to src/utils/ast.py From 205338e8562e854c1a7b570db0bd35db07e84eaa Mon Sep 17 00:00:00 2001 From: Juan Carlos Casteleiro Wong Date: Thu, 6 Jan 2022 13:55:17 -0500 Subject: [PATCH 045/194] parser folder changed to cparser :( --- src/{parser => cparser}/__init__.py | 0 src/{parser => cparser}/parser.py | 0 src/main.py | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) rename src/{parser => cparser}/__init__.py (100%) rename src/{parser => cparser}/parser.py (100%) diff --git a/src/parser/__init__.py b/src/cparser/__init__.py similarity index 100% rename from src/parser/__init__.py rename to src/cparser/__init__.py diff --git a/src/parser/parser.py b/src/cparser/parser.py similarity index 100% rename from src/parser/parser.py rename to src/cparser/parser.py diff --git a/src/main.py b/src/main.py index 61b2e7256..a97ff9cec 100644 --- a/src/main.py +++ b/src/main.py @@ -1,7 +1,7 @@ import sys from lexer import CoolLexer -from parser import CoolParser +from cparser import CoolParser def main(input_): From 38c440cafa847318b7005a33b25501f28951901e Mon Sep 17 00:00:00 2001 From: liviton Date: Thu, 6 Jan 2022 22:21:11 +0100 Subject: [PATCH 046/194] cil_ast complete 2.0 --- src/code_generator/BaseCoolToCilVisitor.py | 62 +++++++++++++++ src/code_generator/cil_ast.py | 88 +++++++++++----------- 2 files changed, 107 insertions(+), 43 deletions(-) create mode 100644 src/code_generator/BaseCoolToCilVisitor.py diff --git a/src/code_generator/BaseCoolToCilVisitor.py b/src/code_generator/BaseCoolToCilVisitor.py new file mode 100644 index 000000000..98fa5153a --- /dev/null +++ b/src/code_generator/BaseCoolToCilVisitor.py @@ -0,0 +1,62 @@ +class BaseCOOLToCILVisitor: + def __init__(self, context): + self.dottypes = [] + self.dotdata = [] + self.dotcode = [] + self.current_type = None + self.current_method = None + self.current_function = None + self.context = context + + @property + def params(self): + return self.current_function.params + + @property + def localvars(self): + return self.current_function.localvars + + @property + def instructions(self): + return self.current_function.instructions + + def register_param(self, vinfo): + #'param_{self.current_function.name[9:]}_{vinfo.name}_{len(self.params)}' + vinfo.name = vinfo.name + param_node = cil.ParamNode(vinfo.name) + self.params.append(param_node) + return vinfo.name + + def register_local(self, vinfo): + vinfo.name = f'local_{self.current_function.name[9:]}_{vinfo.name}_{len(self.localvars)}' + local_node = cil.LocalNode(vinfo.name) + self.localvars.append(local_node) + return vinfo.name + + def define_internal_local(self): + vinfo = VariableInfo('internal', None) + return self.register_local(vinfo) + + def register_instruction(self, instruction): + self.instructions.append(instruction) + return instruction + ############################### + + def to_function_name(self, method_name, type_name): + return f'function_{method_name}_at_{type_name}' + + def register_function(self, function_name): + function_node = cil.FunctionNode(function_name, [], [], []) + self.dotcode.append(function_node) + return function_node + + def register_type(self, name): + type_node = cil.TypeNode(name) + self.dottypes.append(type_node) + return type_node + + def register_data(self, value): + vname = f'data_{len(self.dotdata)}' + data_node = cil.DataNode(vname, value) + self.dotdata.append(data_node) + return data_node \ No newline at end of file diff --git a/src/code_generator/cil_ast.py b/src/code_generator/cil_ast.py index 24da63f55..08c158ed5 100644 --- a/src/code_generator/cil_ast.py +++ b/src/code_generator/cil_ast.py @@ -1,55 +1,51 @@ -class ASTNode: - def __init__(self): - pass - def __repr__(self): - return str(self) +class Node: + pass -class ProgramNode(ASTNode): +class ProgramNode(Node): def __init__(self, dottypes, dotdata, dotcode): self.dottypes = dottypes self.dotdata = dotdata self.dotcode = dotcode #.TYPE -class TypeNode(ASTNode): +class TypeNode(Node): def __init__(self, name): self.name = name self.attributes = [] - self.methods = {} + self.methods = [] #.DATA -class DataNode(ASTNode): +class DataNode(Node): def __init__(self, vname, value): self.name = vname self.value = value #.CODE -class FunctionNode(ASTNode): +class FunctionNode(Node): def __init__(self, name, params=[], localvars=[], instructions =[]): self.name = name self.params = params self.localvars = localvars self.instructions = instructions -class ExpressionNode(ASTNode): +class InstructionNode(Node): def __init__(self): pass -#sin type expression -class ParamNode(ExpressionNode): +class ParamNode(InstructionNode): def __init__(self, name): self.name = name -class LocalNode(ExpressionNode): +class LocalNode(InstructionNode): def __init__(self, name): self.name = name -class AssignNode(ExpressionNode): - def __init__(self, dest, expr): +class AssignNode(InstructionNode): + def __init__(self, dest, source): self.dest = dest - self.expr = expr + self.source = source -class ArithExpressionNode(ExpressionNode): +class ArithExpressionNode(InstructionNode): def __init__(self, dest, left, right): self.dest = dest self.left = left @@ -78,14 +74,14 @@ class EqualNode(ArithExpressionNode): pass #Attr -class GetAttrNode(ExpressionNode): +class GetAttrNode(InstructionNode): def __init__(self, dest, instance, attr, static_type): self.local_dest = dest self.instance = instance self.attr = attr self.static_type = static_type -class SetAttrNode(ExpressionNode): +class SetAttrNode(InstructionNode): def __init__(self, instance, attr, value, static_type): self.instance = instance self.attr = attr @@ -94,41 +90,41 @@ def __init__(self, instance, attr, value, static_type): #Arrays and Strings -class GetIndexNode(ExpressionNode): +class GetIndexNode(InstructionNode): pass -class SetIndexNode(ExpressionNode): +class SetIndexNode(InstructionNode): pass #Memory -class AllocateNode(ExpressionNode): +class AllocateNode(InstructionNode): def __init__(self, t, dest): self.type = t self.local_dest = dest -class ArrayNode(ExpressionNode): +class ArrayNode(InstructionNode): pass -class TypeOfNode(ExpressionNode): - def __init__(self, t, dest): - self.var = t +class TypeOfNode(InstructionNode): + def __init__(self, obj, dest): + self.obj = obj self.local_dest = dest #Jumps -class LabelNode(ExpressionNode): +class LabelNode(InstructionNode): def __init__(self, label): self.label = label -class GoToNode(ExpressionNode): +class GoToNode(InstructionNode): def __init__(self, label): self.label = label -class IfGoTo(ExpressionNode): +class IfGoTo(InstructionNode): def __init__(self, condition, label): self.condition = condition self.label = label #Static Invocation -class CallNode(ExpressionNode): +class CallNode(InstructionNode): def __init__(self, dest, func, args, static_type, ret_type): self.local_dest = dest self.function = func @@ -137,7 +133,7 @@ def __init__(self, dest, func, args, static_type, ret_type): self.ret_type = ret_type #Dynamic Invocation -class VCallNode(ExpressionNode): +class VCallNode(InstructionNode): def __init__(self, instance, dest, func, args, dynamic_type, ret_type): self.instance = instance self.local_dest = dest @@ -148,55 +144,61 @@ def __init__(self, instance, dest, func, args, dynamic_type, ret_type): #Args -class ArgNode(ExpressionNode): +class ArgNode(InstructionNode): def __init__(self, name): self.name = name #Return -class ReturnNode(ExpressionNode): +class ReturnNode(InstructionNode): def __init__(self, value): self.value = value #IO -class LoadNode(ExpressionNode): +class LoadNode(InstructionNode): def __init__(self, dest, msg): self.local_dest = dest self.msg = msg -class LengthNode(ExpressionNode): +class LengthNode(InstructionNode): def __init__(self, dest, arg): self.local_dest = dest self.arg = arg -class ConcatNode(ExpressionNode): +class ConcatNode(InstructionNode): def __init__(self, dest, head, tail): self.local_dest = dest self.head = head self.tail = tail -class PrefixNode(ExpressionNode): +class PrefixNode(InstructionNode): def __init__(self, dest, string, n): self.local_dest = dest self.string = string self.n = n -class SubstringNode(ExpressionNode): +class SubstringNode(InstructionNode): def __init__(self, dest, string, begin, final): self.local_dest = dest self.begin = begin self.string = string self.final = final -class StrNode(ExpressionNode): +class StrNode(InstructionNode): def __init__(self, dest, value): self.local_dest = dest self.value = value -class ReadNode(ExpressionNode): +class ToStrNode(InstructionNode): + def __init__(self, dest, ivalue): + self.dest = dest + self.ivalue = ivalue + +class ReadNode(InstructionNode): def __init__(self, dest): self.local_dest = dest -class PrintNode(ExpressionNode): +class PrintNode(InstructionNode): def __init__(self, value): - self.value = value \ No newline at end of file + self.value = value + From cdbc12b7d275fac125af2ece552df28d9a44bef2 Mon Sep 17 00:00:00 2001 From: liviton Date: Thu, 6 Jan 2022 22:22:38 +0100 Subject: [PATCH 047/194] adding BaseCOOLToCILVisitor --- src/code_generator/BaseCoolToCilVisitor.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/code_generator/BaseCoolToCilVisitor.py b/src/code_generator/BaseCoolToCilVisitor.py index 98fa5153a..c54cc1347 100644 --- a/src/code_generator/BaseCoolToCilVisitor.py +++ b/src/code_generator/BaseCoolToCilVisitor.py @@ -1,3 +1,4 @@ +import cil_ast as cil class BaseCOOLToCILVisitor: def __init__(self, context): self.dottypes = [] From 660ec91d6b4b2a20cc512e02d94cb5bfb69244ad Mon Sep 17 00:00:00 2001 From: cwjki Date: Thu, 6 Jan 2022 17:05:47 -0500 Subject: [PATCH 048/194] first test pass manually --- src/cparser/parser.py | 12 ++++-- src/cparser/parsetab.py | 87 +++++++++++++++++++++++++++++++++++++++++ src/lexer/lexer.py | 61 ++++------------------------- src/main.py | 10 +++-- src/mytest.cl | 2 +- src/utils/ast.py | 6 ++- src/utils/utils.py | 48 +++++++++++++++++++++++ 7 files changed, 163 insertions(+), 63 deletions(-) create mode 100644 src/cparser/parsetab.py diff --git a/src/cparser/parser.py b/src/cparser/parser.py index 0de644747..4c7966abf 100644 --- a/src/cparser/parser.py +++ b/src/cparser/parser.py @@ -1,12 +1,13 @@ from ply import yacc from utils.ast import * from utils.errors import SyntacticError -from utils.utils import find_column +from utils.utils import find_column, tokens class CoolParser: def __init__(self, lexer): self.lexer = lexer + self.tokens = tokens self.parser = yacc.yacc(start='program', module=self) self.errors = [] @@ -80,7 +81,7 @@ def p_param_list(self, p): p[0] = [p[1]] if len(p) == 2 else [p[1]] + p[3] def p_param_list_empty(self, p): - '''para,_list_empty : epsilon''' + '''param_list_empty : epsilon''' p[0] = [] def p_param(self, p): @@ -164,11 +165,14 @@ def p_expr_operators_binary(self, p): def p_expr_operators_unary(self, p): '''expr : NOT expr - | ISVOID expr''' + | ISVOID expr + | LNOT expr''' if p[1] == '~': - p[0] = NotNode(p[2]) + p[0] = NegationNode(p[2]) elif p[1].lower() == 'isvoid': p[0] = IsVoidNode(p[2]) + elif p[1].lower() == 'not': + p[0] = LogicNegationNode(p[2]) p[0].add_line_column(p.lineno(2), find_column( p.lexer.lexdata, p.lexpos(2))) diff --git a/src/cparser/parsetab.py b/src/cparser/parsetab.py new file mode 100644 index 000000000..3658bd136 --- /dev/null +++ b/src/cparser/parsetab.py @@ -0,0 +1,87 @@ + +# parsetab.py +# This file is automatically generated. Do not edit. +# pylint: disable=W,C,R +_tabversion = '3.10' + +_lr_method = 'LALR' + +_lr_signature = 'programARROW ASSIGN AT BOOL CASE CLASS COLON COMMA DIV DOT ELSE EQUAL ESAC FI ID IF IN INHERITS INT ISVOID LBRACE LESS LESSEQ LET LNOT LOOP LPAREN MINUS NEW NOT OF PLUS POOL RBRACE RPAREN SEMICOLON STAR STRING THEN TYPE WHILEprogram : class_listepsilon :class_list : def_class SEMICOLON class_list\n | def_class SEMICOLON def_class : CLASS TYPE LPAREN feature_list RPAREN\n | CLASS TYPE INHERITS TYPE LPAREN feature_list RPARENfeature_list : def_attr SEMICOLON feature_list\n | def_func SEMICOLON feature_list\n | epsilondef_attr : ID COLON TYPE\n | ID COLON TYPE ASSIGN exprdef_func : ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACEparams : param_list\n | param_list_emptyparam_list : param\n | param COMMA param_listparam_list_empty : epsilonparam : ID COLON TYPEexpr : LET let_attrs IN expr\n | CASE expr OF case_list ESAC\n | IF expr THEN expr ELSE expr FI\n | WHILE expr LOOP expr POOLexpr : ID ASSIGN exprexpr : expr AT TYPE DOT ID LPAREN args RPAREN\n | expr DOT ID LPAREN args RPAREN\n | ID LPAREN args RPARENexpr : expr PLUS expr\n | expr MINUS expr\n | expr STAR expr\n | expr DIV expr\n | expr LESS expr\n | expr LESSEQ expr\n | expr EQUAL exprexpr : NOT expr\n | ISVOID expr\n | LNOT exprexpr : LPAREN expr RPARENexpr : atomlet_attrs : def_attr\n | def_attr COMMA let_attrscase_list : case_option SEMICOLON\n | case_option SEMICOLON case_listcase_option : ID COLON TYPE ARROW exprargs : arg_list\n | arg_list_emptyarg_list : expr\n | expr COMMA arg_listarg_list_empty : epsilonatom : INTatom : IDatom : BOOLatom : STRINGatom : NEW TYPEatom : blockblock : LBRACE block_list RBRACE block_list : expr SEMICOLON\n | expr SEMICOLON block_list' + +_lr_action_items = {'CLASS':([0,5,],[4,4,]),'$end':([1,2,5,7,],[0,-1,-4,-3,]),'SEMICOLON':([3,11,12,16,24,36,37,38,47,48,49,50,52,75,76,77,78,80,82,90,91,92,93,94,95,96,102,103,106,110,113,122,126,127,129,135,136,137,],[5,17,18,-5,-10,-6,-50,-11,-38,-49,-51,-52,-54,-34,-35,-36,-53,104,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,123,-20,-22,-12,-25,-21,-24,-43,]),'TYPE':([4,9,19,33,51,55,59,124,],[6,15,24,54,78,81,88,131,]),'LPAREN':([6,14,15,32,37,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,89,97,100,101,104,105,107,109,120,125,128,134,],[8,20,21,43,58,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,109,43,43,43,43,43,43,43,128,43,43,43,]),'INHERITS':([6,],[9,]),'ID':([8,17,18,20,21,32,35,39,40,41,42,43,44,45,46,53,57,58,60,61,62,63,64,65,66,67,97,98,99,100,101,104,105,107,108,109,123,125,128,134,],[14,14,14,25,14,37,25,70,37,37,37,37,37,37,37,37,37,37,89,37,37,37,37,37,37,37,37,70,114,37,37,37,37,37,120,37,114,37,37,37,]),'RPAREN':([8,10,13,17,18,20,21,22,23,26,27,28,29,30,31,37,47,48,49,50,52,54,56,58,74,75,76,77,78,82,83,84,85,86,87,90,91,92,93,94,95,96,102,103,106,109,110,119,121,122,126,128,129,133,135,136,],[-2,16,-9,-2,-2,-2,-2,-7,-8,34,-13,-14,-15,-17,36,-50,-38,-49,-51,-52,-54,-18,-16,-2,102,-34,-35,-36,-53,-23,106,-44,-45,-46,-48,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-2,-19,-47,129,-20,-22,-2,-25,136,-21,-24,]),'COLON':([14,25,34,70,114,],[19,33,55,19,124,]),'COMMA':([24,29,37,38,47,48,49,50,52,54,69,75,76,77,78,82,86,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-10,35,-50,-11,-38,-49,-51,-52,-54,-18,98,-34,-35,-36,-53,-23,107,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'IN':([24,37,38,47,48,49,50,52,68,69,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,111,122,126,129,135,136,],[-10,-50,-11,-38,-49,-51,-52,-54,97,-39,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-40,-20,-22,-25,-21,-24,]),'ASSIGN':([24,37,],[32,57,]),'LET':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,]),'CASE':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,]),'IF':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,]),'WHILE':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,]),'NOT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,]),'ISVOID':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,]),'LNOT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,]),'INT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,]),'BOOL':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,]),'STRING':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,]),'NEW':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,]),'LBRACE':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,81,97,100,101,104,105,107,109,125,128,134,],[53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,105,53,53,53,53,53,53,53,53,53,53,]),'AT':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,59,-38,-49,-51,-52,-54,59,59,59,59,59,59,59,-53,59,59,59,59,59,59,59,59,59,59,-37,-55,-26,59,59,59,59,-20,-22,-25,59,-21,-24,59,]),'DOT':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,88,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,60,-38,-49,-51,-52,-54,60,60,60,60,60,60,60,-53,60,60,60,108,60,60,60,60,60,60,60,-37,-55,-26,60,60,60,60,-20,-22,-25,60,-21,-24,60,]),'PLUS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,61,-38,-49,-51,-52,-54,61,61,61,61,61,61,61,-53,61,61,61,61,61,61,61,61,61,61,-37,-55,-26,61,61,61,61,-20,-22,-25,61,-21,-24,61,]),'MINUS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,62,-38,-49,-51,-52,-54,62,62,62,62,62,62,62,-53,62,62,62,62,62,62,62,62,62,62,-37,-55,-26,62,62,62,62,-20,-22,-25,62,-21,-24,62,]),'STAR':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,63,-38,-49,-51,-52,-54,63,63,63,63,63,63,63,-53,63,63,63,63,63,63,63,63,63,63,-37,-55,-26,63,63,63,63,-20,-22,-25,63,-21,-24,63,]),'DIV':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,64,-38,-49,-51,-52,-54,64,64,64,64,64,64,64,-53,64,64,64,64,64,64,64,64,64,64,-37,-55,-26,64,64,64,64,-20,-22,-25,64,-21,-24,64,]),'LESS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,65,-38,-49,-51,-52,-54,65,65,65,65,65,65,65,-53,65,65,65,65,65,65,65,65,65,65,-37,-55,-26,65,65,65,65,-20,-22,-25,65,-21,-24,65,]),'LESSEQ':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,66,-38,-49,-51,-52,-54,66,66,66,66,66,66,66,-53,66,66,66,66,66,66,66,66,66,66,-37,-55,-26,66,66,66,66,-20,-22,-25,66,-21,-24,66,]),'EQUAL':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,67,-38,-49,-51,-52,-54,67,67,67,67,67,67,67,-53,67,67,67,67,67,67,67,67,67,67,-37,-55,-26,67,67,67,67,-20,-22,-25,67,-21,-24,67,]),'OF':([37,47,48,49,50,52,71,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,99,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'THEN':([37,47,48,49,50,52,72,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,100,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'LOOP':([37,47,48,49,50,52,73,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,101,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'ELSE':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,115,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,125,-20,-22,-25,-21,-24,]),'POOL':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,116,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,126,-20,-22,-25,-21,-24,]),'RBRACE':([37,47,48,49,50,52,75,76,77,78,79,82,90,91,92,93,94,95,96,102,103,104,106,110,117,118,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,103,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-56,-26,-19,-57,127,-20,-22,-25,-21,-24,]),'FI':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,132,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,135,-21,-24,]),'ESAC':([112,123,130,],[122,-41,-42,]),'ARROW':([131,],[134,]),} + +_lr_action = {} +for _k, _v in _lr_action_items.items(): + for _x,_y in zip(_v[0],_v[1]): + if not _x in _lr_action: _lr_action[_x] = {} + _lr_action[_x][_k] = _y +del _lr_action_items + +_lr_goto_items = {'program':([0,],[1,]),'class_list':([0,5,],[2,7,]),'def_class':([0,5,],[3,3,]),'feature_list':([8,17,18,21,],[10,22,23,31,]),'def_attr':([8,17,18,21,39,98,],[11,11,11,11,69,69,]),'def_func':([8,17,18,21,],[12,12,12,12,]),'epsilon':([8,17,18,20,21,58,109,128,],[13,13,13,30,13,87,87,87,]),'params':([20,],[26,]),'param_list':([20,35,],[27,56,]),'param_list_empty':([20,],[28,]),'param':([20,35,],[29,29,]),'expr':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[38,71,72,73,74,75,76,77,80,82,86,90,91,92,93,94,95,96,110,115,116,80,118,86,86,132,86,137,]),'atom':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,]),'block':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,]),'let_attrs':([39,98,],[68,111,]),'block_list':([53,104,],[79,117,]),'args':([58,109,128,],[83,121,133,]),'arg_list':([58,107,109,128,],[84,119,84,84,]),'arg_list_empty':([58,109,128,],[85,85,85,]),'case_list':([99,123,],[112,130,]),'case_option':([99,123,],[113,113,]),} + +_lr_goto = {} +for _k, _v in _lr_goto_items.items(): + for _x, _y in zip(_v[0], _v[1]): + if not _x in _lr_goto: _lr_goto[_x] = {} + _lr_goto[_x][_k] = _y +del _lr_goto_items +_lr_productions = [ + ("S' -> program","S'",1,None,None,None), + ('program -> class_list','program',1,'p_program','parser.py',28), + ('epsilon -> ','epsilon',0,'p_epsilon','parser.py',32), + ('class_list -> def_class SEMICOLON class_list','class_list',3,'p_class_list','parser.py',35), + ('class_list -> def_class SEMICOLON','class_list',2,'p_class_list','parser.py',36), + ('def_class -> CLASS TYPE LPAREN feature_list RPAREN','def_class',5,'p_def_class','parser.py',40), + ('def_class -> CLASS TYPE INHERITS TYPE LPAREN feature_list RPAREN','def_class',7,'p_def_class','parser.py',41), + ('feature_list -> def_attr SEMICOLON feature_list','feature_list',3,'p_feature_list','parser.py',51), + ('feature_list -> def_func SEMICOLON feature_list','feature_list',3,'p_feature_list','parser.py',52), + ('feature_list -> epsilon','feature_list',1,'p_feature_list','parser.py',53), + ('def_attr -> ID COLON TYPE','def_attr',3,'p_def_attr','parser.py',57), + ('def_attr -> ID COLON TYPE ASSIGN expr','def_attr',5,'p_def_attr','parser.py',58), + ('def_func -> ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACE','def_func',9,'p_def_func','parser.py',68), + ('params -> param_list','params',1,'p_params','parser.py',74), + ('params -> param_list_empty','params',1,'p_params','parser.py',75), + ('param_list -> param','param_list',1,'p_param_list','parser.py',79), + ('param_list -> param COMMA param_list','param_list',3,'p_param_list','parser.py',80), + ('param_list_empty -> epsilon','param_list_empty',1,'p_param_list_empty','parser.py',84), + ('param -> ID COLON TYPE','param',3,'p_param','parser.py',88), + ('expr -> LET let_attrs IN expr','expr',4,'p_expr_flow','parser.py',92), + ('expr -> CASE expr OF case_list ESAC','expr',5,'p_expr_flow','parser.py',93), + ('expr -> IF expr THEN expr ELSE expr FI','expr',7,'p_expr_flow','parser.py',94), + ('expr -> WHILE expr LOOP expr POOL','expr',5,'p_expr_flow','parser.py',95), + ('expr -> ID ASSIGN expr','expr',3,'p_expr_assign','parser.py',110), + ('expr -> expr AT TYPE DOT ID LPAREN args RPAREN','expr',8,'p_expr_func_call','parser.py',116), + ('expr -> expr DOT ID LPAREN args RPAREN','expr',6,'p_expr_func_call','parser.py',117), + ('expr -> ID LPAREN args RPAREN','expr',4,'p_expr_func_call','parser.py',118), + ('expr -> expr PLUS expr','expr',3,'p_expr_operators_binary','parser.py',141), + ('expr -> expr MINUS expr','expr',3,'p_expr_operators_binary','parser.py',142), + ('expr -> expr STAR expr','expr',3,'p_expr_operators_binary','parser.py',143), + ('expr -> expr DIV expr','expr',3,'p_expr_operators_binary','parser.py',144), + ('expr -> expr LESS expr','expr',3,'p_expr_operators_binary','parser.py',145), + ('expr -> expr LESSEQ expr','expr',3,'p_expr_operators_binary','parser.py',146), + ('expr -> expr EQUAL expr','expr',3,'p_expr_operators_binary','parser.py',147), + ('expr -> NOT expr','expr',2,'p_expr_operators_unary','parser.py',167), + ('expr -> ISVOID expr','expr',2,'p_expr_operators_unary','parser.py',168), + ('expr -> LNOT expr','expr',2,'p_expr_operators_unary','parser.py',169), + ('expr -> LPAREN expr RPAREN','expr',3,'p_expr_group','parser.py',181), + ('expr -> atom','expr',1,'p_expr_atom','parser.py',185), + ('let_attrs -> def_attr','let_attrs',1,'p_let_attrs','parser.py',189), + ('let_attrs -> def_attr COMMA let_attrs','let_attrs',3,'p_let_attrs','parser.py',190), + ('case_list -> case_option SEMICOLON','case_list',2,'p_case_list','parser.py',194), + ('case_list -> case_option SEMICOLON case_list','case_list',3,'p_case_list','parser.py',195), + ('case_option -> ID COLON TYPE ARROW expr','case_option',5,'p_case_option','parser.py',199), + ('args -> arg_list','args',1,'p_args','parser.py',205), + ('args -> arg_list_empty','args',1,'p_args','parser.py',206), + ('arg_list -> expr','arg_list',1,'p_arg_list','parser.py',210), + ('arg_list -> expr COMMA arg_list','arg_list',3,'p_arg_list','parser.py',211), + ('arg_list_empty -> epsilon','arg_list_empty',1,'p_arg_list_empty','parser.py',215), + ('atom -> INT','atom',1,'p_atom_int','parser.py',219), + ('atom -> ID','atom',1,'p_atom_id','parser.py',225), + ('atom -> BOOL','atom',1,'p_atom_bool','parser.py',231), + ('atom -> STRING','atom',1,'p_atom_string','parser.py',237), + ('atom -> NEW TYPE','atom',2,'p_atom_new','parser.py',243), + ('atom -> block','atom',1,'p_atom_block','parser.py',249), + ('block -> LBRACE block_list RBRACE','block',3,'p_block','parser.py',253), + ('block_list -> expr SEMICOLON','block_list',2,'p_block_list','parser.py',257), + ('block_list -> expr SEMICOLON block_list','block_list',3,'p_block_list','parser.py',258), +] diff --git a/src/lexer/lexer.py b/src/lexer/lexer.py index a6a5b4fbc..e1f22e09a 100644 --- a/src/lexer/lexer.py +++ b/src/lexer/lexer.py @@ -1,7 +1,7 @@ from ply import lex from utils.errors import LexicographicError -from utils.utils import Token +from utils.utils import Token, tokens, reserved class CoolLexer: @@ -11,60 +11,13 @@ class CoolLexer: ('strings', 'exclusive') ) - reserved = { - 'class': 'CLASS', - 'else': 'ELSE', - 'false': 'FALSE', - 'fi': 'FI', - 'if': 'IF', - 'in': 'IN', - 'inherits': 'INHERITS', - 'isvoid': 'ISVOID', - 'let': 'LET', - 'loop': 'LOOP', - 'pool': 'POOL', - 'then': 'THEN', - 'while': 'WHILE', - 'case': 'CASE', - 'esac': 'ESAC', - 'new': 'NEW', - 'of': 'OF', - 'not': 'NOT', - 'true': 'TRUE' - } - - tokens = [ - 'ID', - 'TYPE', - 'LPAREN', - 'RPAREN', - 'LBRACE', - 'RBRACE', - 'COLON', - 'SEMICOLON', - 'COMMA', - 'DOT', - 'AT', - 'ASSIGN', - 'PLUS', - 'MINUS', - 'STAR', - 'DIV', - 'EQUAL', - 'LESS', - 'LESSEQ', - 'ARROW', - 'INT', - 'STRING', - 'NOT' - ] + list(reserved.values()) - def __init__(self, **kwargs): self.errors = [] + self.reserved = reserved + self.tokens = tokens self.lexer = lex.lex(module=self, **kwargs) self.lexer.lineno = 1 self.lexer.linestart = 0 - self.errors = [] self.text = None # Comments @@ -107,7 +60,7 @@ def t_strings(self, t): t.lexer.string_start = t.lexer.lexpos t.lexer.string = '' t.lexer.backslash = False - t.lexer.begin('string') + t.lexer.begin('strings') def t_strings_end(self, t): r'\"' @@ -118,7 +71,7 @@ def t_strings_end(self, t): t.lexer.backslash = False else: t.value = t.lexer.string - t.type = 'string' + t.type = 'STRING' t.lexer.begin('INITIAL') return t @@ -164,6 +117,9 @@ def t_strings_consume(self, t): else: t.lexer.backslash = True + def t_strings_error(self, t): + pass + def t_strings_eof(self, t): self.add_line_column(t) self.errors.append(LexicographicError( @@ -319,6 +275,5 @@ def run(self, text): if self.errors: for error in self.errors: print(error) - raise Exception() return tokens diff --git a/src/main.py b/src/main.py index a97ff9cec..b439552d8 100644 --- a/src/main.py +++ b/src/main.py @@ -9,18 +9,20 @@ def main(input_): with open(input_) as f: text = f.read() - print(text) - + print("****LEXER****") lexer = CoolLexer() tokens = lexer.run(text) + + print("TOKENS") print(tokens) + print("****PARSER****") parser = CoolParser(lexer) ast = parser.parse(text) print(ast) if parser.errors: - raise Exception() + print("HUBO ERRORES") except FileNotFoundError: pass @@ -31,5 +33,5 @@ def main(input_): # output_ = sys.argv[2] # main(input_, output_) - input_ = 'mytest.cl' + input_ = '/mnt/d/UH/4to Año/EVEA/Complementos de Compilacion/cool-compiler/cool-compiler-2021/src/mytest.cl' main(input_) diff --git a/src/mytest.cl b/src/mytest.cl index 044a44b3b..c2bb9938c 100644 --- a/src/mytest.cl +++ b/src/mytest.cl @@ -1,4 +1,4 @@ ---Any characters between two dashes "-- and the next newline +--Any characters between two dashes "--" and the next newline --(or EOF, if there is no next newline) are treated as comments (*(*(* diff --git a/src/utils/ast.py b/src/utils/ast.py index 835ffc441..c69a682f4 100644 --- a/src/utils/ast.py +++ b/src/utils/ast.py @@ -161,7 +161,11 @@ def __init__(self, value): self.value = value -class NotNode(UnaryNode): +class NegationNode(UnaryNode): + pass + + +class LogicNegationNode(UnaryNode): pass diff --git a/src/utils/utils.py b/src/utils/utils.py index c5ca8c808..af9b2d8ad 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -15,3 +15,51 @@ def __str__(self): def __repr__(self): return str(self) + + +reserved = { + 'class': 'CLASS', + 'else': 'ELSE', + 'fi': 'FI', + 'if': 'IF', + 'in': 'IN', + 'inherits': 'INHERITS', + 'isvoid': 'ISVOID', + 'let': 'LET', + 'loop': 'LOOP', + 'pool': 'POOL', + 'then': 'THEN', + 'while': 'WHILE', + 'case': 'CASE', + 'esac': 'ESAC', + 'new': 'NEW', + 'of': 'OF', + 'not': 'LNOT' +} + +tokens = [ + 'ID', + 'TYPE', + 'LPAREN', + 'RPAREN', + 'LBRACE', + 'RBRACE', + 'COLON', + 'SEMICOLON', + 'COMMA', + 'DOT', + 'AT', + 'ASSIGN', + 'PLUS', + 'MINUS', + 'STAR', + 'DIV', + 'EQUAL', + 'LESS', + 'LESSEQ', + 'ARROW', + 'INT', + 'STRING', + 'NOT', + 'BOOL' +] + list(reserved.values()) From 535baecb709ad2880f79b84a7f38ef70952dfa64 Mon Sep 17 00:00:00 2001 From: liviton Date: Fri, 7 Jan 2022 00:43:33 +0100 Subject: [PATCH 049/194] COOLToCLIVisitor ProgramNode sin build_in --- src/code_generator/BaseCoolToCilVisitor.py | 18 ++++++++-------- src/code_generator/COOLToCILVisitor.py | 24 ++++++++++++++++++++++ src/code_generator/cil_ast.py | 3 ++- 3 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 src/code_generator/COOLToCILVisitor.py diff --git a/src/code_generator/BaseCoolToCilVisitor.py b/src/code_generator/BaseCoolToCilVisitor.py index c54cc1347..5386a0785 100644 --- a/src/code_generator/BaseCoolToCilVisitor.py +++ b/src/code_generator/BaseCoolToCilVisitor.py @@ -21,22 +21,20 @@ def localvars(self): def instructions(self): return self.current_function.instructions - def register_param(self, vinfo): + def register_param(self, type, name): #'param_{self.current_function.name[9:]}_{vinfo.name}_{len(self.params)}' - vinfo.name = vinfo.name - param_node = cil.ParamNode(vinfo.name) + param_node = cil.ParamNode(type, name) self.params.append(param_node) - return vinfo.name + return name - def register_local(self, vinfo): - vinfo.name = f'local_{self.current_function.name[9:]}_{vinfo.name}_{len(self.localvars)}' - local_node = cil.LocalNode(vinfo.name) + def register_local(self, name): + #vinfo.name = f'local_{self.current_function.name[9:]}_{vinfo.name}_{len(self.localvars)}' + local_node = cil.LocalNode(name) self.localvars.append(local_node) - return vinfo.name + return name def define_internal_local(self): - vinfo = VariableInfo('internal', None) - return self.register_local(vinfo) + return self.register_local('internal') def register_instruction(self, instruction): self.instructions.append(instruction) diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py new file mode 100644 index 000000000..b3e2edc06 --- /dev/null +++ b/src/code_generator/COOLToCILVisitor.py @@ -0,0 +1,24 @@ +from cil_ast import * +import BaseCOOLToCILVisitor +from utils import visitor + +class COOLToCILVisitor(BaseCOOLToCILVisitor): + @visitor.on('node') + def visit(self, node): + pass + + @visitor.when(ProgramNode) + def visit(self, node, scope): + self.current_function = self.register_function('entry') + instance = self.define_internal_local() + result = self.define_internal_local() + self.register_instruction(AllocateNode('Main', instance)) + self.register_instruction(ArgNode(instance)) + self.register_instruction(CallNode(self.to_function_name('main', 'Main'), result)) + self.register_instruction(ReturnNode(0)) + self.current_function = None + # self.create_built_in() + for declaration, child_scope in zip(node.declarations, scope.children): + self.visit(declaration, child_scope) + + return ProgramNode(self.dottypes, self.dotdata, self.dotcode) \ No newline at end of file diff --git a/src/code_generator/cil_ast.py b/src/code_generator/cil_ast.py index 08c158ed5..f188ce98e 100644 --- a/src/code_generator/cil_ast.py +++ b/src/code_generator/cil_ast.py @@ -33,7 +33,8 @@ def __init__(self): pass class ParamNode(InstructionNode): - def __init__(self, name): + def __init__(self, type, name): + self.type = type self.name = name class LocalNode(InstructionNode): From 9ffc0a03bb9534fad97fbf15f843a249748c6c2c Mon Sep 17 00:00:00 2001 From: cwjki Date: Thu, 6 Jan 2022 18:51:16 -0500 Subject: [PATCH 050/194] adding Atribute and Method class --- src/lexer/lexer.py | 10 +-- src/main.py | 2 +- src/semantic/__init__.py | 0 src/semantic/semantic.py | 41 +++++++-- src/semantic/types.py | 111 ------------------------ src/semantic/visitors/__init__.py | 0 src/semantic/visitors/type_collector.py | 4 +- 7 files changed, 44 insertions(+), 124 deletions(-) create mode 100644 src/semantic/__init__.py delete mode 100644 src/semantic/types.py create mode 100644 src/semantic/visitors/__init__.py diff --git a/src/lexer/lexer.py b/src/lexer/lexer.py index e1f22e09a..01d0aa0e4 100644 --- a/src/lexer/lexer.py +++ b/src/lexer/lexer.py @@ -205,6 +205,11 @@ def t_DIV(self, t): self.add_line_column(t) return t + def t_ARROW(self, t): + r'=>' + self.add_line_column(t) + return t + def t_EQUAL(self, t): r'=' self.add_line_column(t) @@ -220,11 +225,6 @@ def t_LESSEQ(self, t): self.add_line_column(t) return t - def t_ARROW(self, t): - r'=>' - self.add_line_column(t) - return t - def t_NOT(self, t): r'~' self.add_line_column(t) diff --git a/src/main.py b/src/main.py index b439552d8..ee184fca4 100644 --- a/src/main.py +++ b/src/main.py @@ -33,5 +33,5 @@ def main(input_): # output_ = sys.argv[2] # main(input_, output_) - input_ = '/mnt/d/UH/4to Año/EVEA/Complementos de Compilacion/cool-compiler/cool-compiler-2021/src/mytest.cl' + input_ = '/mnt/d/UH/4to Año/EVEA/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/lexer/iis2.cl' main(input_) diff --git a/src/semantic/__init__.py b/src/semantic/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/semantic/semantic.py b/src/semantic/semantic.py index 8f1f8f5cf..7e73d9804 100644 --- a/src/semantic/semantic.py +++ b/src/semantic/semantic.py @@ -1,9 +1,38 @@ +import itertools as itt +from collections import OrderedDict +from utils.errors import SemanticError +import itertools as itt +from collections import OrderedDict -class SemanticAnalyser: - def __init__(self, ast): - self.ast = ast - self.errors = [] - def analyse(self): - pass +class Attribute: + def __init__(self, name, typex, index): + self.name = name + self.type = typex + self.index = index + + def __str__(self): + return f'[attrib] {self.name} : {self.type.name};' + + def __repr__(self): + return str(self) + + +class Method: + def __init__(self, name, param_names, params_types, return_type): + self.name = name + self.param_names = param_names + self.param_types = params_types + self.return_type = return_type + + def __str__(self): + params = ', '.join(f'{n}:{t.name}' for n, t in zip( + self.param_names, self.param_types)) + return f'[method] {self.name}({params}): {self.return_type.name};' + + def __eq__(self, other): + return other.name == self.name and \ + other.return_type == self.return_type and \ + other.param_types == self.param_types + diff --git a/src/semantic/types.py b/src/semantic/types.py deleted file mode 100644 index 2eead1bb2..000000000 --- a/src/semantic/types.py +++ /dev/null @@ -1,111 +0,0 @@ -from utils.errors import SemanticError - - -class Attribute: - def __init__(self, name, typex, index): - self.name = name - self.type = typex - self.index = index - self.expr = None - - def __str__(self): - return f'[attr] {self.name} : {self.type.name}' - - def __repr__(self): - return str(self) - - -class Method: - def __init__(self, name, param_names, param_types, return_type): - self.name = name - self.param_names = param_names - self.param_types = param_types - self.return_type = return_type - - -class Type: - def __init__(self, name, position, parent=True): - if name == 'ObjectType': - return ObjectType(position) - self.name = name - self.attributes = {} - self.methods = {} - self.position = position - if parent: - self.parent = ObjectType(position) - else: - self.parent = None - - def set_parent(self, parent): - if type(self.parent) != ObjectType and self.parent is not None: - line, column = self.position - raise SemanticError( - f'Parent already defined for {self.name}', line, column) - self.parent = parent - - def get_attribute(self, name, position): - try: - return self.attributes[name] - except KeyError: - if self.parent is None: - line, column = self.position - raise SemanticError( - f'Attribute {name} is not defined in {self.name}', line, column) - try: - return self.parent.get_attribute(name, position) - except: - line, column = self.position - raise SemanticError( - f'Attribute {name} is not defined in {self.name}', line, column) - - def define_attribute(self, name, typex, position): - try: - self.attributes[name] - except KeyError: - try: - self.get_attribute(name, position) - except SemanticError: - attribute = Attribute(name, typex, len(self.attributes)) - self.attributes[name] = attribute - return attribute - else: - line, column = self.position - raise SemanticError( - f'Attribute {name} is an attribute of an inherited class', line, column) - else: - line, column = self.position - raise SemanticError( - f'Attribute {name} is already defined', line, column) - - def get_method(self, name, position): - try: - return self.methods[name] - except KeyError: - if self.parent is None: - line, column = self.position - raise SemanticError( - f'Method {name} is not defined in {self.name}', line, column) - try: - return self.parent.get_method(name, position) - except: - line, column = self.position - raise SemanticError( - f'Method {name} is not defined in {self.name}', line, column) - - def define_method(self, name, param_names, param_types, return_type, position=(0, 0)): - if name in self.methods: - line, column = self.position - raise SemanticError( - f'Method {name} is already defined', line, column) - - method = self.methods[name] = Method(name, param_names, param_types, return_type) - return method - - -class ObjectType(Type): - def __init__(self, position=(0, 0)): - self.name = 'Object' - self.attributes = {} - self.methods = {} - self.parent = None - self.position = position diff --git a/src/semantic/visitors/__init__.py b/src/semantic/visitors/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/semantic/visitors/type_collector.py b/src/semantic/visitors/type_collector.py index 72f8b0800..90e806da6 100644 --- a/src/semantic/visitors/type_collector.py +++ b/src/semantic/visitors/type_collector.py @@ -1,4 +1,6 @@ from utils import visitor +from utils.ast import ProgramNode, ClassDeclarationNode +from semantic. @@ -16,7 +18,7 @@ def visit(self, node): @visitor.when(ProgramNode) def visit(self, node): - pass + self.context = Context() @visitor.when(ClassDeclarationNode) def visit(self, node): From efdbdf04b20831fe0a255620fd7e94925c95531c Mon Sep 17 00:00:00 2001 From: liviton Date: Fri, 7 Jan 2022 00:52:32 +0100 Subject: [PATCH 051/194] COOLToCLIVisitor ProgramNode sin build_in 2.0 --- src/code_generator/COOLToCILVisitor.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index b3e2edc06..1e5fdbd5a 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -1,6 +1,7 @@ -from cil_ast import * -import BaseCOOLToCILVisitor +import cil_ast as cil +from BaseCOOLToCILVisitor import * from utils import visitor +from parser.ast import * class COOLToCILVisitor(BaseCOOLToCILVisitor): @visitor.on('node') @@ -12,13 +13,24 @@ def visit(self, node, scope): self.current_function = self.register_function('entry') instance = self.define_internal_local() result = self.define_internal_local() - self.register_instruction(AllocateNode('Main', instance)) - self.register_instruction(ArgNode(instance)) - self.register_instruction(CallNode(self.to_function_name('main', 'Main'), result)) - self.register_instruction(ReturnNode(0)) + self.register_instruction(cil.AllocateNode('Main', instance)) + self.register_instruction(cil.ArgNode(instance)) + self.register_instruction(cil.CallNode(self.to_function_name('main', 'Main'), result)) + self.register_instruction(cil.ReturnNode(0)) self.current_function = None + # self.create_built_in() + for declaration, child_scope in zip(node.declarations, scope.children): self.visit(declaration, child_scope) - return ProgramNode(self.dottypes, self.dotdata, self.dotcode) \ No newline at end of file + return cil.ProgramNode(self.dottypes, self.dotdata, self.dotcode) + + + + + + + + + From 5e768ac909dee8b80ba2217c084519974b864cd5 Mon Sep 17 00:00:00 2001 From: cwjki Date: Thu, 6 Jan 2022 20:36:57 -0500 Subject: [PATCH 052/194] working on the Type class in semantic --- src/semantic/semantic.py | 298 ++++++++++++++++++++++++++++++++++++++- src/utils/errors.py | 1 + 2 files changed, 294 insertions(+), 5 deletions(-) diff --git a/src/semantic/semantic.py b/src/semantic/semantic.py index 7e73d9804..dad224b9a 100644 --- a/src/semantic/semantic.py +++ b/src/semantic/semantic.py @@ -1,16 +1,13 @@ -import itertools as itt -from collections import OrderedDict from utils.errors import SemanticError - -import itertools as itt from collections import OrderedDict class Attribute: - def __init__(self, name, typex, index): + def __init__(self, name, typex, index, tok=None): self.name = name self.type = typex self.index = index + self.expr = None def __str__(self): return f'[attrib] {self.name} : {self.type.name};' @@ -36,3 +33,294 @@ def __eq__(self, other): other.return_type == self.return_type and \ other.param_types == self.param_types + +# class MethodError(Method): +# def __init__(self, name, param_names, param_types, return_types): +# super().__init__(name, param_names, param_types, return_types) + +# def __str__(self): +# return f'[method] {self.name} ERROR' + + +class Type: + def __init__(self, name: str, pos, parent=True): + if name == 'ObjectType': + return ObjectType(pos) + self.name = name + self.attributes = {} + self.methods = {} + if parent: + self.parent = ObjectType(pos) + else: + self.parent = None + self.pos = pos + + def set_parent(self, parent): + if type(self.parent) != ObjectType and self.parent is not None: + error_msg = f'Parent type is already set for {self.name}.' + raise SemanticError(error_msg, *self.pos) + self.parent = parent + + def get_attribute(self, name: str, pos) -> Attribute: + try: + return self.attributes[name] + except KeyError: + if self.parent is None: + error_msg = f'Attribute {name} is not defined in {self.name}.' + raise SemanticError(error_msg, *pos) + try: + return self.parent.get_attribute(name, pos) + except: + error_msg = f'Attribute {name} is not defined in {self.name}.' + raise SemanticError(error_msg, *pos) + + def define_attribute(self, name: str, typex, pos): + try: + self.attributes[name] + except KeyError: + try: + self.get_attribute(name, pos) + except: + self.attributes[name] = attribute = Attribute( + name, typex, len(self.attributes)) + return attribute + else: + error_msg = f'Attribute {name} is an attribute of an inherit class.' + raise SemanticError(error_msg, *pos) + else: + error_msg = f'Attribute {name} is multiply defined in class.' + raise SemanticError(error_msg, *pos) + + def get_method(self, name: str, pos) -> Method: + try: + return self.methods[name] + except KeyError: + error_msg = f'Method {name} is not defined in {self.name}.' + if self.parent is None: + raise SemanticError(error_msg, *pos) + try: + return self.parent.get_method(name, pos) + except: + raise SemanticError(error_msg, *pos) + + def define_method(self, name: str, param_names: list, param_types: list, return_type, pos=(0, 0)): + if name in self.methods: + error_msg = f'Method {name} is multiply defined' + raise SemanticError(error_msg, *pos) + + method = self.methods[name] = Method( + name, param_names, param_types, return_type) + return method + + def change_type(self, method, nparm, newtype): + idx = method.param_names.index(nparm) + method.param_types[idx] = newtype + + def all_attributes(self, clean=True): + plain = OrderedDict() if self.parent is None else self.parent.all_attributes(False) + for attr in self.attributes.values(): + plain[attr.name] = (attr, self) + return plain.values() if clean else plain + + def all_methods(self, clean=True): + plain = OrderedDict() if self.parent is None else self.parent.all_methods(False) + for method in self.methods.values(): + plain[method.name] = (method, self) + return plain.values() if clean else plain + + def conforms_to(self, other): + return other.bypass() or self == other or self.parent is not None and self.parent.conforms_to(other) + + def bypass(self): + return False + + def __str__(self): + output = f'type {self.name}' + parent = '' if self.parent is None else f' : {self.parent.name}' + output += parent + output += ' {' + output += '\n\t' if self.attributes or self.methods else '' + output += '\n\t'.join(str(x) for x in self.attributes.values()) + output += '\n\t' if self.attributes else '' + output += '\n\t'.join(str(x) for x in self.methods.values()) + output += '\n' if self.methods else '' + output += '}\n' + return output + + def __repr__(self): + return str(self) + + +class ErrorType(Type): + def __init__(self, pos=(0, 0)): + Type.__init__(self, '', pos) + + def conforms_to(self, other): + return True + + def bypass(self): + return True + + def __eq__(self, other): + return isinstance(other, ErrorType) + + def __ne__(self, other): + return not isinstance(other, ErrorType) + + +class VoidType(Type): + def __init__(self, pos=(0, 0)): + Type.__init__(self, 'Void', pos) + + def conforms_to(self, other): + return True + + def bypass(self): + return True + + def __eq__(self, other): + return isinstance(other, VoidType) + + +class BoolType(Type): + def __init__(self, pos=(0, 0)): + self.name = 'Bool' + self.attributes = {} + self.methods = {} + self.parent = None + self.pos = pos + self.init_methods() + + def init_methods(self): + self.define_method('abort', [], [], self) + self.define_method('type_name', [], [], StringType()) + self.define_method('copy', [], [], SelfType()) + + def conforms_to(self, other): + return other.name == 'Object' or other.name == self.name + + def __eq__(self, other): + return other.name == self.name or isinstance(other, BoolType) + + def __ne__(self, other): + return other.name != self.name and not isinstance(other, BoolType) + + +class SelfType(Type): + def __init__(self, pos=(0, 0)): + self.name = 'Self' + self.attributes = {} + self.methods = {} + self.parent = None + self.pos = pos + + def __eq__(self, other): + return other.name == self.name or isinstance(other, SelfType) + + def __ne__(self, other): + return other.name != self.name and not isinstance(other, SelfType) + + +class IntType(Type): + def __init__(self, pos=(0, 0)): + self.name = 'Int' + self.attributes = {} + self.methods = {} + self.parent = None + self.pos = pos + self.init_methods() + + def init_methods(self): + self.define_method('abort', [], [], self) + self.define_method('type_name', [], [], Type('String', (0, 0), False)) + self.define_method('copy', [], [], SelfType()) + + def conforms_to(self, other): + return other.name == 'Object' or other.name == self.name + + def __eq__(self, other): + return other.name == self.name or isinstance(other, IntType) + + def __ne__(self, other): + return other.name != self.name and not isinstance(other, IntType) + + +class StringType(Type): + def __init__(self, pos=(0, 0)): + self.name = 'String' + self.attributes = {} + self.methods = {} + self.parent = None + self.pos = pos + self.init_methods() + + def init_methods(self): + self.define_method('abort', [], [], self) + self.define_method('type_name', [], [], self) + self.define_method('copy', [], [], SelfType()) + self.define_method('length', [], [], IntType()) + self.define_method('concat', ['s'], [self], self) + self.define_method('substr', ['i', 'l'], [IntType(), IntType()], self) + + def conforms_to(self, other): + return other.name == 'Object' or other.name == self.name + + def __eq__(self, other): + return other.name == self.name or isinstance(other, StringType) + + def __ne__(self, other): + return other.name != self.name and not isinstance(other, StringType) + + +class ObjectType(Type): + def __init__(self, pos=(0, 0)): + self.name = 'Object' + self.attributes = {} + self.methods = {} + self.parent = None + self.pos = pos + self.init_methods() + + def init_methods(self): + self.define_method('abort', [], [], self) + self.define_method('type_name', [], [], StringType()) + self.define_method('copy', [], [], SelfType()) + + def __eq__(self, other): + return other.name == self.name or isinstance(other, ObjectType) + + def __ne__(self, other): + return other.name != self.name and not isinstance(other, ObjectType) + + +# class AutoType(Type): +# def __init__(self): +# Type.__init__(self, 'AUTO_TYPE') + +# def __eq__(self, other): +# return other.name == self.name or isinstance(other, AutoType) + +# def __ne__(self, other): +# return other.name != self.name and not isinstance(other, AutoType) + + +class IOType(Type): + def __init__(self, pos=(0, 0)): + self.name = 'IO' + self.attributes = {} + self.methods = {} + self.parent = ObjectType(pos) + self.pos = pos + self.init_methods() + + def init_methods(self): + self.define_method('out_string', ['x'], [StringType()], SelfType()) + self.define_method('out_int', ['x'], [IntType()], SelfType()) + self.define_method('in_string', [], [], StringType()) + self.define_method('in_int', [], [], IntType()) + + def __eq__(self, other): + return other.name == self.name or isinstance(other, IOType) + + def __ne__(self, other): + return other.name != self.name and not isinstance(other, IOType) diff --git a/src/utils/errors.py b/src/utils/errors.py index 789bc67b7..3d8bb449a 100644 --- a/src/utils/errors.py +++ b/src/utils/errors.py @@ -25,3 +25,4 @@ def __init__(self, text, line, column): class SemanticError(CoolError): def __init__(self, text, line, column): super().__init__('SemanticError', text, line, column) + From f072c449d6e858bc7fa745725c2ef309a05579d0 Mon Sep 17 00:00:00 2001 From: cwjki Date: Thu, 6 Jan 2022 21:07:00 -0500 Subject: [PATCH 053/194] probar los test --- src/coolc.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/coolc.sh b/src/coolc.sh index 3088de4f9..a934b0590 100755 --- a/src/coolc.sh +++ b/src/coolc.sh @@ -7,5 +7,10 @@ OUTPUT_FILE=${INPUT_FILE:0: -2}mips echo "LINEA_CON_NOMBRE_Y_VERSION_DEL_COMPILADOR" # TODO: Recuerde cambiar estas echo "Copyright (c) 2019: Nombre1, Nombre2, Nombre3" # TODO: líneas a los valores correctos +FILE="__main__.py" + +# Llamar al compilador +python ${FILE} $INPUT_FILE $OUTPUT_FILE + # Llamar al compilador -echo "Compiling $INPUT_FILE into $OUTPUT_FILE" +# echo "Compiling $INPUT_FILE into $OUTPUT_FILE" From 08aaf0147ca715a57cef8daa3d4df1bebc3ecd18 Mon Sep 17 00:00:00 2001 From: cwjki Date: Thu, 6 Jan 2022 21:22:37 -0500 Subject: [PATCH 054/194] test2 --- src/main.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/main.py b/src/main.py index ee184fca4..e638a488a 100644 --- a/src/main.py +++ b/src/main.py @@ -9,20 +9,12 @@ def main(input_): with open(input_) as f: text = f.read() - print("****LEXER****") lexer = CoolLexer() tokens = lexer.run(text) - print("TOKENS") - print(tokens) - - print("****PARSER****") parser = CoolParser(lexer) ast = parser.parse(text) - print(ast) - if parser.errors: - print("HUBO ERRORES") except FileNotFoundError: pass From 838639c346d24a9e20bc3f25cc637fc6cd112fca Mon Sep 17 00:00:00 2001 From: cwjki Date: Fri, 7 Jan 2022 12:03:08 -0500 Subject: [PATCH 055/194] checking the testing, removing '()' from the error print --- src/utils/errors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/errors.py b/src/utils/errors.py index 3d8bb449a..483908e8d 100644 --- a/src/utils/errors.py +++ b/src/utils/errors.py @@ -6,7 +6,7 @@ def __init__(self, error_type, text, line, column): self.column = column def __str__(self): - return f'({self.line, self.column}) - {self.type}: {self.text}' + return f'{self.line, self.column} - {self.type}: {self.text}' def __repr__(self): return str(self) From 2f52adda30798dbf221f663a88605646b4e58cb7 Mon Sep 17 00:00:00 2001 From: cwjki Date: Fri, 7 Jan 2022 12:15:32 -0500 Subject: [PATCH 056/194] trying to fix the testing --- src/lexer/lexer.py | 1 + src/main.py | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lexer/lexer.py b/src/lexer/lexer.py index 01d0aa0e4..efe819a5f 100644 --- a/src/lexer/lexer.py +++ b/src/lexer/lexer.py @@ -275,5 +275,6 @@ def run(self, text): if self.errors: for error in self.errors: print(error) + raise Exception() return tokens diff --git a/src/main.py b/src/main.py index e638a488a..b2298c08e 100644 --- a/src/main.py +++ b/src/main.py @@ -12,9 +12,9 @@ def main(input_): lexer = CoolLexer() tokens = lexer.run(text) - parser = CoolParser(lexer) + # parser = CoolParser(lexer) - ast = parser.parse(text) + # ast = parser.parse(text) except FileNotFoundError: pass @@ -25,5 +25,5 @@ def main(input_): # output_ = sys.argv[2] # main(input_, output_) - input_ = '/mnt/d/UH/4to Año/EVEA/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/lexer/iis2.cl' + input_ = '/mnt/d/UH/4to Año/EVEA/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/lexer/iis4.cl' main(input_) From 9441d45cad4d456d11fcf054bfb3ea728c70d904 Mon Sep 17 00:00:00 2001 From: cwjki Date: Fri, 7 Jan 2022 12:53:56 -0500 Subject: [PATCH 057/194] testing 2 --- src/coolc.sh | 2 +- src/main.py | 2 +- src/mytest.cl | 55 --------------------------------------------------- 3 files changed, 2 insertions(+), 57 deletions(-) delete mode 100644 src/mytest.cl diff --git a/src/coolc.sh b/src/coolc.sh index a934b0590..3c4dc0960 100755 --- a/src/coolc.sh +++ b/src/coolc.sh @@ -5,7 +5,7 @@ OUTPUT_FILE=${INPUT_FILE:0: -2}mips # Si su compilador no lo hace ya, aquí puede imprimir la información de contacto echo "LINEA_CON_NOMBRE_Y_VERSION_DEL_COMPILADOR" # TODO: Recuerde cambiar estas -echo "Copyright (c) 2019: Nombre1, Nombre2, Nombre3" # TODO: líneas a los valores correctos +echo "Copyright (c) 2021: Juan Carlos Casteleiro Wong, Olivia González Peña" # TODO: líneas a los valores correctos FILE="__main__.py" diff --git a/src/main.py b/src/main.py index b2298c08e..a4096057d 100644 --- a/src/main.py +++ b/src/main.py @@ -17,7 +17,7 @@ def main(input_): # ast = parser.parse(text) except FileNotFoundError: - pass + raise Exception() if __name__ == "__main__": diff --git a/src/mytest.cl b/src/mytest.cl deleted file mode 100644 index c2bb9938c..000000000 --- a/src/mytest.cl +++ /dev/null @@ -1,55 +0,0 @@ ---Any characters between two dashes "--" and the next newline ---(or EOF, if there is no next newline) are treated as comments - -(*(*(* -Comments may also be written by enclosing -text in (∗ . . . ∗). The latter form of comment may be nested. -Comments cannot cross file boundaries. -*)*)*) - -class Error() { - - (* There was once a comment, - that was quite long. - But, the reader soon discovered that - the comment was indeed longer than - previously assumed. Now, the reader - was in a real dilemma; is the comment - ever gonna end? If I stop reading, will - it end? - He started imagining all sorts of things. - He thought about heisenberg's cat and how - how that relates to the end of the sentence. - He thought to himself "I'm gonna stop reading". - "If I keep reading this comment, I'm gonna know - the fate of this sentence; That will be disastorous." - He knew that such a comment was gonna extend to - another file. It was too awesome to be contained in - a single file. And he would have kept reading too... - if only... - cool wasn't a super-duper-fab-awesomest language; - but cool is that language; - "This comment shall go not cross this file" said cool. - Alas! The reader could read no more. - There was once a comment, - that was quite long. - But, the reader soon discovered that - the comment was indeed longer than - previously assumed. Now, the reader - was in a real dilemma; is the comment - ever gonna end? If I stop reading, will - it end? - He started imagining all sorts of things. - He thought about heisenberg's cat and how - how that relates to the end of the sentence. - He thought to himself "I'm gonna stop reading". - "If I keep reading this comment, I'm gonna know - the fate of this sentence; That will be disastorous." - He knew that such a comment was gonna extend to - another file. It was too awesome to be contained in - a single file. And he would have kept reading too... - if only... - cool wasn't a super-duper-fab-awesomest language; - but cool is that language; - "This comment shall go not cross this file" said cool. - Alas! The reader could read no more. \ No newline at end of file From dd40b0a8709520ff7bd5eb35c6c831f4517ae610 Mon Sep 17 00:00:00 2001 From: cwjki Date: Fri, 7 Jan 2022 13:01:56 -0500 Subject: [PATCH 058/194] i was passing a single test :( --- src/main.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main.py b/src/main.py index a4096057d..3717d8a57 100644 --- a/src/main.py +++ b/src/main.py @@ -4,7 +4,7 @@ from cparser import CoolParser -def main(input_): +def main(input_, output_): try: with open(input_) as f: text = f.read() @@ -21,9 +21,9 @@ def main(input_): if __name__ == "__main__": - # input_ = sys.argv[1] - # output_ = sys.argv[2] - # main(input_, output_) + input_ = sys.argv[1] + output_ = sys.argv[2] + main(input_, output_) - input_ = '/mnt/d/UH/4to Año/EVEA/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/lexer/iis4.cl' - main(input_) + # input_ = '/mnt/d/UH/4to Año/EVEA/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/lexer/iis4.cl' + # main(input_) From bb51c74f66dcfd518a52d35564cd453f3386ef86 Mon Sep 17 00:00:00 2001 From: liviton Date: Sat, 8 Jan 2022 00:49:07 +0100 Subject: [PATCH 059/194] COOLToCLIVisitor fixing ProgramNode 2.0 sin buitl_in --- src/code_generator/COOLToCILVisitor.py | 43 +++++++++++++++++++++++++- src/parser/ast.py | 6 ++-- src/semantic/types.py | 2 +- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index 1e5fdbd5a..52a23ceae 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -15,7 +15,10 @@ def visit(self, node, scope): result = self.define_internal_local() self.register_instruction(cil.AllocateNode('Main', instance)) self.register_instruction(cil.ArgNode(instance)) - self.register_instruction(cil.CallNode(self.to_function_name('main', 'Main'), result)) + + #self.register_instruction(cil.CallNode(self.to_function_name('main', 'Main'), result)) + self.register_instruction(cil.CallNode(result, self.to_function_name('main', 'Main'), [cil.ArgNode(instance)], 'Main')) + self.register_instruction(cil.ReturnNode(0)) self.current_function = None @@ -26,7 +29,45 @@ def visit(self, node, scope): return cil.ProgramNode(self.dottypes, self.dotdata, self.dotcode) + @visitor.when(ClassDeclarationNode) + def visit(self, node, scope): + self.current_type = self.context.get_type(node.id) + type_node = self.register_type(node.id) + type_node.attributes = [attr.name for attr, _ in self.current_type.all_attributes()] + type_node.methods = [(method.name, self.to_function_name(method.name, xtype.name)) for method, xtype in self.current_type.all_methods()] + + func_declarations = (f for f in node.features if isinstance(f, FuncDeclarationNode)) + for feature, child_scope in zip(func_declarations, scope.children): + self.visit(feature, child_scope) + + + #init + self.current_function = self.register_function(self.init_name(node.id)) + #allocate + instance = self.register_local('instance') + self.register_instruction(cil.AllocateNode(node.id, instance)) + + func = self.current_function + vtemp = self.define_internal_local() + + #init_attr + self.current_function = self.register_function(self.init_name(node.id, attr=True)) + self.register_param(self.vself) + if node.parent != 'Object' and node.parent != 'IO': + self.register_instruction(cil.ArgNode(self.vself.name)) + self.register_instruction(cil.CallNode(self.init_name(node.parent, attr=True), vtemp)) + attr_declarations = (f for f in node.features if isinstance(f, AttrDeclarationNode)) + for feature in attr_declarations: + self.visit(feature, scope) + + self.current_function = func + self.register_instruction(cil.ArgNode(instance)) + self.register_instruction(cil.StaticCallNode(self.init_name(node.id, attr=True), vtemp)) + self.register_instruction(cil.ReturnNode(instance)) + self.current_function = None + + self.current_type = None diff --git a/src/parser/ast.py b/src/parser/ast.py index 46bbffaf8..dff9ad274 100644 --- a/src/parser/ast.py +++ b/src/parser/ast.py @@ -28,7 +28,7 @@ def __init__(self, name, params, return_type, expr=None): self.name = name self.params = params self.return_type = return_type - self.exp = exp + self.exp = expr class AttrDeclarationNode(Node): @@ -36,7 +36,7 @@ def __init__(self, name, type, expr=None): super().__init__() self.name = name self.type = type - self.exp = exp + self.exp = expr class ExpressionNode(Node): @@ -93,7 +93,7 @@ class CaseNode(ExpressionNode): def __init__(self, expr, case_list): super().__init__() self.expr = expr - self.case_list = case_list: + self.case_list = case_list class CaseOptionNode(ExpressionNode): diff --git a/src/semantic/types.py b/src/semantic/types.py index 2eead1bb2..b455aa253 100644 --- a/src/semantic/types.py +++ b/src/semantic/types.py @@ -64,7 +64,7 @@ def define_attribute(self, name, typex, position): except KeyError: try: self.get_attribute(name, position) - except SemanticError: + except SemanticError(): attribute = Attribute(name, typex, len(self.attributes)) self.attributes[name] = attribute return attribute From e412d4f6390925bf73d44870bf52815184e03cce Mon Sep 17 00:00:00 2001 From: root Date: Mon, 10 Jan 2022 13:27:35 -0500 Subject: [PATCH 060/194] trying to fix the test --- src/coolc.sh | 2 +- src/main.py | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/coolc.sh b/src/coolc.sh index 3c4dc0960..1521cd252 100755 --- a/src/coolc.sh +++ b/src/coolc.sh @@ -7,7 +7,7 @@ OUTPUT_FILE=${INPUT_FILE:0: -2}mips echo "LINEA_CON_NOMBRE_Y_VERSION_DEL_COMPILADOR" # TODO: Recuerde cambiar estas echo "Copyright (c) 2021: Juan Carlos Casteleiro Wong, Olivia González Peña" # TODO: líneas a los valores correctos -FILE="__main__.py" +FILE="main.py" # Llamar al compilador python ${FILE} $INPUT_FILE $OUTPUT_FILE diff --git a/src/main.py b/src/main.py index 3717d8a57..609594dab 100644 --- a/src/main.py +++ b/src/main.py @@ -4,26 +4,26 @@ from cparser import CoolParser -def main(input_, output_): - try: - with open(input_) as f: - text = f.read() +def main(_input, _output): - lexer = CoolLexer() - tokens = lexer.run(text) + with open(_input) as file: + text = file.read() - # parser = CoolParser(lexer) + lexer = CoolLexer() + tokens = lexer.run(text) - # ast = parser.parse(text) + # parser = CoolParser(lexer) - except FileNotFoundError: - raise Exception() + # ast = parser.parse(text) if __name__ == "__main__": - input_ = sys.argv[1] - output_ = sys.argv[2] - main(input_, output_) + + path = '/mnt/d/UH/4to Año/EVEA/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/lexer/iis1.cl' + _input = sys.argv[1] if len(sys.argv) > 1 else path + _output = sys.argv[2] if len(sys.argv) > 2 else None + + main(_input, _output) # input_ = '/mnt/d/UH/4to Año/EVEA/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/lexer/iis4.cl' # main(input_) From 298f0ba0b2aafc7a2e8e240e1e05f93d3a2f732d Mon Sep 17 00:00:00 2001 From: cwjki Date: Mon, 10 Jan 2022 13:43:52 -0500 Subject: [PATCH 061/194] fixing the tester 2 --- src/utils/errors.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/utils/errors.py b/src/utils/errors.py index 483908e8d..c3691bd83 100644 --- a/src/utils/errors.py +++ b/src/utils/errors.py @@ -14,7 +14,7 @@ def __repr__(self): class LexicographicError(CoolError): def __init__(self, text, line, column): - super().__init__('LexicograficError', text, line, column) + super().__init__('LexicographicError', text, line, column) class SyntacticError(CoolError): @@ -25,4 +25,3 @@ def __init__(self, text, line, column): class SemanticError(CoolError): def __init__(self, text, line, column): super().__init__('SemanticError', text, line, column) - From 858e6ccb53c104ddbd768a57af6b33676471cace Mon Sep 17 00:00:00 2001 From: root Date: Tue, 11 Jan 2022 17:11:46 -0500 Subject: [PATCH 062/194] testing 3 --- src/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.py b/src/main.py index 609594dab..bd3e6e21a 100644 --- a/src/main.py +++ b/src/main.py @@ -19,7 +19,7 @@ def main(_input, _output): if __name__ == "__main__": - path = '/mnt/d/UH/4to Año/EVEA/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/lexer/iis1.cl' + path = '/mnt/d/UH/4to Año/EVEA/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/lexer/string4_error.txt' _input = sys.argv[1] if len(sys.argv) > 1 else path _output = sys.argv[2] if len(sys.argv) > 2 else None From 07d0aca40a0cc704636eb7987404a9eb6799d64f Mon Sep 17 00:00:00 2001 From: liviton Date: Tue, 11 Jan 2022 23:17:30 +0100 Subject: [PATCH 063/194] COOLToCLIVisitor ClassDeclarationNode --- src/code_generator/COOLToCILVisitor.py | 62 ++++++++++---------------- 1 file changed, 24 insertions(+), 38 deletions(-) diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index 52a23ceae..51e273a6a 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -32,46 +32,32 @@ def visit(self, node, scope): @visitor.when(ClassDeclarationNode) def visit(self, node, scope): self.current_type = self.context.get_type(node.id) - type_node = self.register_type(node.id) - type_node.attributes = [attr.name for attr, _ in self.current_type.all_attributes()] - type_node.methods = [(method.name, self.to_function_name(method.name, xtype.name)) for method, xtype in self.current_type.all_methods()] - - func_declarations = (f for f in node.features if isinstance(f, FuncDeclarationNode)) - for feature, child_scope in zip(func_declarations, scope.children): - self.visit(feature, child_scope) - - - #init - self.current_function = self.register_function(self.init_name(node.id)) - #allocate - instance = self.register_local('instance') - self.register_instruction(cil.AllocateNode(node.id, instance)) - func = self.current_function - vtemp = self.define_internal_local() - - #init_attr - self.current_function = self.register_function(self.init_name(node.id, attr=True)) - self.register_param(self.vself) - if node.parent != 'Object' and node.parent != 'IO': - self.register_instruction(cil.ArgNode(self.vself.name)) - self.register_instruction(cil.CallNode(self.init_name(node.parent, attr=True), vtemp)) - attr_declarations = (f for f in node.features if isinstance(f, AttrDeclarationNode)) - for feature in attr_declarations: - self.visit(feature, scope) + cil_type_node = self.register_type(self.current_type) + cil_type_node.attributes = self.current_type.get_all_attributes() - self.current_function = func - self.register_instruction(cil.ArgNode(instance)) - self.register_instruction(cil.StaticCallNode(self.init_name(node.id, attr=True), vtemp)) - - self.register_instruction(cil.ReturnNode(instance)) - self.current_function = None - - self.current_type = None - - - - + if len(cil_type_node.attributes) != 0: + constructor = FuncDeclarationNode(node.token, [], node.token, BlockNode([], node.token)) + func_declarations = [constructor] + self.constructors.append(node.id) + self.current_type.define_method(self.current_type.name, [], [], self.current_type, node.pos) + scopes = [scope] + list(scope.functions.values()) + else: + func_declarations = [] + scopes = list(scope.functions.values()) + + for attr, a_type in cil_type_node.attributes: + cil_type_node.attributes.append((attr.name, self.to_attr_name(attr.name, a_type.name))) + self.initialize_attr(constructor, attr, scope) ## add the initialization code in the constructor + if cil_type_node.attributes: + constructor.body.expr_list.append(SelfNode()) + + for method, mtype in self.current_type.all_methods(): + cil_type_node.methods.append((method.name, self.to_function_name(method.name, mtype.name))) + + func_declarations += [f for f in node.features if isinstance(f, FuncDeclarationNode)] + for feature, child_scope in zip(func_declarations, scopes): + self.visit(feature, child_scope) From 1573a44e7e6ed13fa7f24e0c94d96c612ffec7bd Mon Sep 17 00:00:00 2001 From: cwjki Date: Tue, 11 Jan 2022 17:28:05 -0500 Subject: [PATCH 064/194] fixing the merge --- src/utils/ast.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/utils/ast.py b/src/utils/ast.py index 3e3defef5..c69a682f4 100644 --- a/src/utils/ast.py +++ b/src/utils/ast.py @@ -28,24 +28,15 @@ def __init__(self, name, params, return_type, expr=None): self.name = name self.params = params self.return_type = return_type -<<<<<<< HEAD:src/utils/ast.py self.expr = expr -======= - self.exp = expr ->>>>>>> livi:src/parser/ast.py class AttrDeclarationNode(Node): def __init__(self, name, typex, expr=None): super().__init__() self.name = name -<<<<<<< HEAD:src/utils/ast.py self.type = typex self.expr = expr -======= - self.type = type - self.exp = expr ->>>>>>> livi:src/parser/ast.py class ExpressionNode(Node): From 20ac7e9e863cbd8d1b435b6834bcd7297aa1d075 Mon Sep 17 00:00:00 2001 From: cwjki Date: Tue, 11 Jan 2022 17:38:36 -0500 Subject: [PATCH 065/194] changing the dashes --- tests/lexer/comment1.cl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/lexer/comment1.cl b/tests/lexer/comment1.cl index 69533f23c..c2bb9938c 100644 --- a/tests/lexer/comment1.cl +++ b/tests/lexer/comment1.cl @@ -1,4 +1,4 @@ ---Any characters between two dashes “--” and the next newline +--Any characters between two dashes "--" and the next newline --(or EOF, if there is no next newline) are treated as comments (*(*(* From 53499ff2087ccfd73007230085f0fefad3be3623 Mon Sep 17 00:00:00 2001 From: cwjki Date: Tue, 11 Jan 2022 18:13:34 -0500 Subject: [PATCH 066/194] fixing the lineno in lexer --- src/lexer/lexer.py | 89 ++++++++++++++++++++++++---------------------- src/main.py | 2 +- src/utils/utils.py | 4 +-- 3 files changed, 49 insertions(+), 46 deletions(-) diff --git a/src/lexer/lexer.py b/src/lexer/lexer.py index efe819a5f..570fb2d91 100644 --- a/src/lexer/lexer.py +++ b/src/lexer/lexer.py @@ -20,8 +20,15 @@ def __init__(self, **kwargs): self.lexer.linestart = 0 self.text = None + + # Comments + def t_comment(self, t): + r'--.*($|\n)' + t.lexer.lineno += 1 + t.lexer.linestart = t.lexer.lexpos + def t_comments(self, t): r'\(\*' t.lexer.level = 1 @@ -46,9 +53,10 @@ def t_comments_error(self, t): t.lexer.skip(1) def t_comments_eof(self, t): - line = t.lexer.lineno - column = self.find_column(t) - self.errors.append(LexicographicError("EOF in comment", line, column)) + self.compute_column(t) + if t.lexer.level > 0: + self.errors.append(LexicographicError( + "EOF in comment", t.lineno, t.column)) t_comments_ignore = ' \t\f\r\v' @@ -64,7 +72,7 @@ def t_strings(self, t): def t_strings_end(self, t): r'\"' - self.add_line_column(t) + self.compute_column(t) if t.lexer.backslash: t.lexer.string += '"' @@ -78,20 +86,20 @@ def t_strings_end(self, t): def t_strings_newline(self, t): r'\n' t.lexer.lineno += 1 - self.add_line_column(t) + self.compute_column(t) t.lexer.linestart = t.lexer.lexpos if not t.lexer.backslash: self.errors.append(LexicographicError( - 'Undeterminated string constant', t.line, t.column)) + 'Undeterminated string constant', t.lineno, t.column)) t.lexer.begin('INITIAL') def t_strings_nill(self, t): r'\0' - self.add_line_column(t) + self.compute_column(t) self.errors.append(LexicographicError( - 'Null caracter in string', t.line, t.column)) + 'Null caracter in string', t.lineno, t.column)) def t_strings_consume(self, t): r'[^\n]' @@ -121,131 +129,126 @@ def t_strings_error(self, t): pass def t_strings_eof(self, t): - self.add_line_column(t) + self.compute_column(t) self.errors.append(LexicographicError( - 'EOF in string constant', t.line, t.column)) - - def find_column(self, t): - line_start = self.text.rfind('\n', 0, t.lexpos) + 1 - return (t.lexpos - line_start) + 1 - - def add_line_column(self, t): - t.line = t.lexer.lineno - t.column = self.find_column(t) + 'EOF in string constant', t.lineno, t.column)) t_ignore = ' \t\f\r\t\v' + def compute_column(self, t): + t.column = t.lexpos - t.lexer.linestart + 1 + def t_LPAREN(self, t): r'\(' - self.add_line_column(t) + self.compute_column(t) return t def t_RPAREN(self, t): r'\)' - self.add_line_column(t) + self.compute_column(t) return t def t_LBRACE(self, t): r'\{' - self.add_line_column(t) + self.compute_column(t) return t def t_RBRACE(self, t): r'\}' - self.add_line_column(t) + self.compute_column(t) return t def t_COLON(self, t): r':' - self.add_line_column(t) + self.compute_column(t) return t def t_SEMICOLON(self, t): r';' - self.add_line_column(t) + self.compute_column(t) return t def t_COMMA(self, t): r',' - self.add_line_column(t) + self.compute_column(t) return t def t_DOT(self, t): r'\.' - self.add_line_column(t) + self.compute_column(t) return t def t_AT(self, t): r'@' - self.add_line_column(t) + self.compute_column(t) return t def t_ASSIGN(self, t): r'<-' - self.add_line_column(t) + self.compute_column(t) return t def t_PLUS(self, t): r'\+' - self.add_line_column(t) + self.compute_column(t) return t def t_MINUS(self, t): r'-' - self.add_line_column(t) + self.compute_column(t) return t def t_STAR(self, t): r'\*' - self.add_line_column(t) + self.compute_column(t) return t def t_DIV(self, t): r'/' - self.add_line_column(t) + self.compute_column(t) return t def t_ARROW(self, t): r'=>' - self.add_line_column(t) + self.compute_column(t) return t def t_EQUAL(self, t): r'=' - self.add_line_column(t) + self.compute_column(t) return t def t_LESS(self, t): r'<' - self.add_line_column(t) + self.compute_column(t) return t def t_LESSEQ(self, t): r'<=' - self.add_line_column(t) + self.compute_column(t) return t def t_NOT(self, t): r'~' - self.add_line_column(t) + self.compute_column(t) return t def t_INT(self, t): r'\d+' t.value = int(t.value) - self.add_line_column(t) + self.compute_column(t) return t def t_ID(self, t): r'[a-z][a-zA-Z_0-9]*' t.type = self.reserved.get(t.value.lower(), 'ID') - self.add_line_column(t) + self.compute_column(t) return t def t_TYPE(self, t): r'[A-Z][a-zA-Z_0-9]*' t.type = self.reserved.get(t.value.lower(), 'TYPE') - self.add_line_column(t) + self.compute_column(t) return t def t_newline(self, t): @@ -254,9 +257,9 @@ def t_newline(self, t): t.lexer.linestart = t.lexer.lexpos def t_error(self, t): - self.add_line_column(t) + self.compute_column(t) self.errors.append(LexicographicError( - f'ERROR \"{t.value[0]}\"', t.line, t.column)) + f'ERROR \"{t.value[0]}\"', t.lineno, t.column)) t.lexer.skip(1) def tokenize(self, text): @@ -265,7 +268,7 @@ def tokenize(self, text): tokens = [] for token in self.lexer: tokens.append(Token(token.value, token.type, - token.line, token.column)) + token.lineno, token.column)) self.lexer.lineno = 1 self.lexer.linestart = 0 return tokens diff --git a/src/main.py b/src/main.py index bd3e6e21a..e984c6bb2 100644 --- a/src/main.py +++ b/src/main.py @@ -19,7 +19,7 @@ def main(_input, _output): if __name__ == "__main__": - path = '/mnt/d/UH/4to Año/EVEA/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/lexer/string4_error.txt' + path = '/mnt/d/UH/4to Año/EVEA/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/lexer/string4.cl' _input = sys.argv[1] if len(sys.argv) > 1 else path _output = sys.argv[2] if len(sys.argv) > 2 else None diff --git a/src/utils/utils.py b/src/utils/utils.py index af9b2d8ad..8d02720b0 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -7,11 +7,11 @@ class Token: def __init__(self, lex, token_type, row, column): self.lex = lex self.type = token_type - self.line = row + self.lineno = row self.column = column def __str__(self): - return f'{self.type}: {self.lex} ({self.line}, {self.column})' + return f'{self.type}: {self.lex} ({self.lineno}, {self.column})' def __repr__(self): return str(self) From 1fd5ca873346da8f7f9a501ac99c71177a005213 Mon Sep 17 00:00:00 2001 From: liviton Date: Wed, 12 Jan 2022 01:55:04 +0100 Subject: [PATCH 067/194] COOLToCLIVisitor FuncDeclarationNode --- src/code_generator/BaseCoolToCilVisitor.py | 3 +++ src/code_generator/COOLToCILVisitor.py | 26 +++++++++++++++++++--- src/utils/ast.py | 12 +++------- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/code_generator/BaseCoolToCilVisitor.py b/src/code_generator/BaseCoolToCilVisitor.py index 5386a0785..c02a535c8 100644 --- a/src/code_generator/BaseCoolToCilVisitor.py +++ b/src/code_generator/BaseCoolToCilVisitor.py @@ -43,6 +43,9 @@ def register_instruction(self, instruction): def to_function_name(self, method_name, type_name): return f'function_{method_name}_at_{type_name}' + + def to_attribute_name(self, attr_name, type_name): + return f'function_{attr_name}_at_{type_name}' def register_function(self, function_name): function_node = cil.FunctionNode(function_name, [], [], []) diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index 51e273a6a..fc82d95f6 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -1,7 +1,7 @@ import cil_ast as cil from BaseCOOLToCILVisitor import * from utils import visitor -from parser.ast import * +from utils.ast import * class COOLToCILVisitor(BaseCOOLToCILVisitor): @visitor.on('node') @@ -47,8 +47,8 @@ def visit(self, node, scope): scopes = list(scope.functions.values()) for attr, a_type in cil_type_node.attributes: - cil_type_node.attributes.append((attr.name, self.to_attr_name(attr.name, a_type.name))) - self.initialize_attr(constructor, attr, scope) ## add the initialization code in the constructor + cil_type_node.attributes.append((attr.name, self.to_attribute_name(attr.name, a_type.name))) + self.initialize_attr(constructor, attr, scope) if cil_type_node.attributes: constructor.body.expr_list.append(SelfNode()) @@ -59,5 +59,25 @@ def visit(self, node, scope): for feature, child_scope in zip(func_declarations, scopes): self.visit(feature, child_scope) + @visitor.when(FuncDeclarationNode) + def visit(self, node, scope): + self.current_method = self.current_type.get_method(node.id) + cil_name = self.to_function_name(node.id, self.current_type.name) + self.current_function = self.register_function(cil_name) + + self.register_param('self', self.current_type.name) + for param_name, param_type in node.params: + self.register_param(param_name, param_type.value) + + ret_value = self.visit(node.body, scope) + if not isinstance(ret_value, str): + result = self.define_internal_local() + self.register_instruction(cil.AssignNode(result, ret_value)) + self.register_instruction(cil.ReturnNode(result)) + else: + self.register_instruction(cil.ReturnNode(ret_value)) + + self.current_method = None + diff --git a/src/utils/ast.py b/src/utils/ast.py index 3e3defef5..41d19f021 100644 --- a/src/utils/ast.py +++ b/src/utils/ast.py @@ -28,24 +28,15 @@ def __init__(self, name, params, return_type, expr=None): self.name = name self.params = params self.return_type = return_type -<<<<<<< HEAD:src/utils/ast.py self.expr = expr -======= - self.exp = expr ->>>>>>> livi:src/parser/ast.py class AttrDeclarationNode(Node): def __init__(self, name, typex, expr=None): super().__init__() self.name = name -<<<<<<< HEAD:src/utils/ast.py self.type = typex self.expr = expr -======= - self.type = type - self.exp = expr ->>>>>>> livi:src/parser/ast.py class ExpressionNode(Node): @@ -185,6 +176,9 @@ class AtomicNode(UnaryNode): class IsVoidNode(UnaryNode): pass +class SelfNode(UnaryNode): + pass + # ---------------- Constant Nodes ------------------ From c8e25d4560aa0e2833f8f0d273a180621410f22e Mon Sep 17 00:00:00 2001 From: liviton Date: Wed, 12 Jan 2022 04:39:31 +0100 Subject: [PATCH 068/194] COOLToCLIVisitor AttrDeclarationNode --- src/code_generator/COOLToCILVisitor.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index fc82d95f6..d51095670 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -59,6 +59,8 @@ def visit(self, node, scope): for feature, child_scope in zip(func_declarations, scopes): self.visit(feature, child_scope) + self.current_type = None + @visitor.when(FuncDeclarationNode) def visit(self, node, scope): self.current_method = self.current_type.get_method(node.id) @@ -79,5 +81,14 @@ def visit(self, node, scope): self.current_method = None + @visitor.when(AttrDeclarationNode) + def visit(self, node, scope): + if node.expr: + self.visit(node.expr, scope) + self.register_instruction(cil.SetAttrNode(self.vself.name, node.id, scope.ret_expr, self.current_type)) + elif node.type in self.value_types: + local_value = self.define_internal_local() + self.register_instruction(cil.AllocateNode(node.type, local_value)) + self.register_instruction(cil.SetAttrNode(self.vself.name, node.id, local_value, self.current_type)) From c032cb2f14517e9a6e0add70506d8134e2e48a6d Mon Sep 17 00:00:00 2001 From: liviton Date: Wed, 12 Jan 2022 05:31:40 +0100 Subject: [PATCH 069/194] COOLToCLIVisitor AssignNode --- src/code_generator/BaseCoolToCilVisitor.py | 3 +++ src/code_generator/COOLToCILVisitor.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/code_generator/BaseCoolToCilVisitor.py b/src/code_generator/BaseCoolToCilVisitor.py index c02a535c8..e68aae9b3 100644 --- a/src/code_generator/BaseCoolToCilVisitor.py +++ b/src/code_generator/BaseCoolToCilVisitor.py @@ -46,6 +46,9 @@ def to_function_name(self, method_name, type_name): def to_attribute_name(self, attr_name, type_name): return f'function_{attr_name}_at_{type_name}' + + def to_variable_name(self, var_name): + return f'function_{var_name}' def register_function(self, function_name): function_node = cil.FunctionNode(function_name, [], [], []) diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index d51095670..ae9da8c25 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -91,4 +91,19 @@ def visit(self, node, scope): self.register_instruction(cil.AllocateNode(node.type, local_value)) self.register_instruction(cil.SetAttrNode(self.vself.name, node.id, local_value, self.current_type)) + @visitor.when(AssignNode) + def visit(self, node, scope): + var_info = scope.find_local(node.id) + value, typex = self.visit(node.expr, scope) + if var_info is None: + var_info = scope.find_attribute(node.id) + attributes_names = [attr.name for attr, attr_type in self.current_type.get_all_attributes()] + self.register_instruction(cil.SetAttrNode('self', var_info.name, self.current_type.name, value)) + else: + local_name = self.to_variable_name(var_info.name) + self.register_instruction(cil.AssignNode(local_name, value)) + return value, typex + @visitor.when(FuncCallNode) + def visit(self, node, scope): + pass From 34faa2ad0da42b905f025425e401e17080cbe934 Mon Sep 17 00:00:00 2001 From: cwjki Date: Wed, 12 Jan 2022 13:36:01 -0500 Subject: [PATCH 070/194] fixing the mixed2.cl test --- src/lexer/lexer.py | 2 +- src/main.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lexer/lexer.py b/src/lexer/lexer.py index 570fb2d91..0b34b4553 100644 --- a/src/lexer/lexer.py +++ b/src/lexer/lexer.py @@ -118,7 +118,7 @@ def t_strings_consume(self, t): else: t.lexer.string += t.value - t.backslash = False + t.lexer.backslash = False else: if t.value != '\\': t.lexer.string += t.value diff --git a/src/main.py b/src/main.py index e984c6bb2..92764e455 100644 --- a/src/main.py +++ b/src/main.py @@ -19,7 +19,7 @@ def main(_input, _output): if __name__ == "__main__": - path = '/mnt/d/UH/4to Año/EVEA/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/lexer/string4.cl' + path = '/mnt/d/UH/4to Año/EVEA/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/lexer/mixed2.cl' _input = sys.argv[1] if len(sys.argv) > 1 else path _output = sys.argv[2] if len(sys.argv) > 2 else None From 6b189139c501d7b86c918c1312a528473a11bd7a Mon Sep 17 00:00:00 2001 From: cwjki Date: Wed, 12 Jan 2022 13:39:30 -0500 Subject: [PATCH 071/194] all the lexer test pass :) --- src/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.py b/src/main.py index 92764e455..b37e1bacc 100644 --- a/src/main.py +++ b/src/main.py @@ -19,7 +19,7 @@ def main(_input, _output): if __name__ == "__main__": - path = '/mnt/d/UH/4to Año/EVEA/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/lexer/mixed2.cl' + path = '/mnt/d/UH/4to Año/EVEA/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/lexer/comment1.cl' _input = sys.argv[1] if len(sys.argv) > 1 else path _output = sys.argv[2] if len(sys.argv) > 2 else None From 8911632ea1aa32ff6d5027830834723d7549fc33 Mon Sep 17 00:00:00 2001 From: cwjki Date: Wed, 12 Jan 2022 13:41:58 -0500 Subject: [PATCH 072/194] starting the parser testing --- tests/lexer/comment1.cl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/lexer/comment1.cl b/tests/lexer/comment1.cl index c2bb9938c..69533f23c 100644 --- a/tests/lexer/comment1.cl +++ b/tests/lexer/comment1.cl @@ -1,4 +1,4 @@ ---Any characters between two dashes "--" and the next newline +--Any characters between two dashes “--” and the next newline --(or EOF, if there is no next newline) are treated as comments (*(*(* From 32f7baf1f4778732c4c10e051b968ec700da78fc Mon Sep 17 00:00:00 2001 From: cwjki Date: Wed, 12 Jan 2022 13:45:33 -0500 Subject: [PATCH 073/194] parser test 1 --- src/main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main.py b/src/main.py index b37e1bacc..41fcb6c76 100644 --- a/src/main.py +++ b/src/main.py @@ -12,9 +12,10 @@ def main(_input, _output): lexer = CoolLexer() tokens = lexer.run(text) - # parser = CoolParser(lexer) - - # ast = parser.parse(text) + parser = CoolParser(lexer) + ast = parser.parse(text) + if parser.errors: + raise Exception() if __name__ == "__main__": From 4fe8de667da2cc220f99e06862070be1f22399cf Mon Sep 17 00:00:00 2001 From: cwjki Date: Wed, 12 Jan 2022 19:40:25 -0500 Subject: [PATCH 074/194] testing parser 2 --- src/cparser/parser.py | 17 +++++++++++++---- src/main.py | 4 +++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/cparser/parser.py b/src/cparser/parser.py index 4c7966abf..d4ce23c42 100644 --- a/src/cparser/parser.py +++ b/src/cparser/parser.py @@ -261,8 +261,17 @@ def p_block_list(self, p): def p_error(self, p): if p: - self.lexer.add_line_column(p) - self.errors.append(SyntacticError( - f'ERROR at or near {p.value}', p.line, p.column)) + self.add_error(p) else: - self.errors.append(SyntacticError('ERROR at or near EOF', 0, 0)) + column = find_column(self.lexer.lexer, self.lexer.lexer) + line = self.lexer.lexer.lineno + self.errors.append(SyntacticError( + 'ERROR at or near EOF', line, column - 1)) + + def add_error(self, p): + self.errors.append(SyntacticError( + f'ERROR at or near {p.value}', p.lineno, p.column)) + + def print_error(self): + for error in self.errors: + print(error) diff --git a/src/main.py b/src/main.py index 41fcb6c76..0b50ee611 100644 --- a/src/main.py +++ b/src/main.py @@ -1,3 +1,4 @@ +from ast import parse import sys from lexer import CoolLexer @@ -15,12 +16,13 @@ def main(_input, _output): parser = CoolParser(lexer) ast = parser.parse(text) if parser.errors: + parser.print_error() raise Exception() if __name__ == "__main__": - path = '/mnt/d/UH/4to Año/EVEA/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/lexer/comment1.cl' + path = '/mnt/d/UH/4to Año/EVEA/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/parser/assignment1.cl' _input = sys.argv[1] if len(sys.argv) > 1 else path _output = sys.argv[2] if len(sys.argv) > 2 else None From 0c2550b342eed4e45fd5b7f936c89955c28e79e5 Mon Sep 17 00:00:00 2001 From: cwjki Date: Wed, 12 Jan 2022 19:56:31 -0500 Subject: [PATCH 075/194] LBRACE LPAREN --- src/cparser/parser.py | 4 ++-- src/cparser/parsetab.py | 8 ++++---- src/main.py | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cparser/parser.py b/src/cparser/parser.py index d4ce23c42..c9fcb7504 100644 --- a/src/cparser/parser.py +++ b/src/cparser/parser.py @@ -37,8 +37,8 @@ def p_class_list(self, p): p[0] = [p[1]] if len(p) == 3 else [p[1]] + p[3] def p_def_class(self, p): - '''def_class : CLASS TYPE LPAREN feature_list RPAREN - | CLASS TYPE INHERITS TYPE LPAREN feature_list RPAREN''' + '''def_class : CLASS TYPE LBRACE feature_list RBRACE + | CLASS TYPE INHERITS TYPE LBRACE feature_list RBRACE''' if len(p) == 8: p[0] = ClassDeclarationNode(p[2], p[6], p[4]) else: diff --git a/src/cparser/parsetab.py b/src/cparser/parsetab.py index 3658bd136..2098fe1a9 100644 --- a/src/cparser/parsetab.py +++ b/src/cparser/parsetab.py @@ -6,9 +6,9 @@ _lr_method = 'LALR' -_lr_signature = 'programARROW ASSIGN AT BOOL CASE CLASS COLON COMMA DIV DOT ELSE EQUAL ESAC FI ID IF IN INHERITS INT ISVOID LBRACE LESS LESSEQ LET LNOT LOOP LPAREN MINUS NEW NOT OF PLUS POOL RBRACE RPAREN SEMICOLON STAR STRING THEN TYPE WHILEprogram : class_listepsilon :class_list : def_class SEMICOLON class_list\n | def_class SEMICOLON def_class : CLASS TYPE LPAREN feature_list RPAREN\n | CLASS TYPE INHERITS TYPE LPAREN feature_list RPARENfeature_list : def_attr SEMICOLON feature_list\n | def_func SEMICOLON feature_list\n | epsilondef_attr : ID COLON TYPE\n | ID COLON TYPE ASSIGN exprdef_func : ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACEparams : param_list\n | param_list_emptyparam_list : param\n | param COMMA param_listparam_list_empty : epsilonparam : ID COLON TYPEexpr : LET let_attrs IN expr\n | CASE expr OF case_list ESAC\n | IF expr THEN expr ELSE expr FI\n | WHILE expr LOOP expr POOLexpr : ID ASSIGN exprexpr : expr AT TYPE DOT ID LPAREN args RPAREN\n | expr DOT ID LPAREN args RPAREN\n | ID LPAREN args RPARENexpr : expr PLUS expr\n | expr MINUS expr\n | expr STAR expr\n | expr DIV expr\n | expr LESS expr\n | expr LESSEQ expr\n | expr EQUAL exprexpr : NOT expr\n | ISVOID expr\n | LNOT exprexpr : LPAREN expr RPARENexpr : atomlet_attrs : def_attr\n | def_attr COMMA let_attrscase_list : case_option SEMICOLON\n | case_option SEMICOLON case_listcase_option : ID COLON TYPE ARROW exprargs : arg_list\n | arg_list_emptyarg_list : expr\n | expr COMMA arg_listarg_list_empty : epsilonatom : INTatom : IDatom : BOOLatom : STRINGatom : NEW TYPEatom : blockblock : LBRACE block_list RBRACE block_list : expr SEMICOLON\n | expr SEMICOLON block_list' +_lr_signature = 'programARROW ASSIGN AT BOOL CASE CLASS COLON COMMA DIV DOT ELSE EQUAL ESAC FI ID IF IN INHERITS INT ISVOID LBRACE LESS LESSEQ LET LNOT LOOP LPAREN MINUS NEW NOT OF PLUS POOL RBRACE RPAREN SEMICOLON STAR STRING THEN TYPE WHILEprogram : class_listepsilon :class_list : def_class SEMICOLON class_list\n | def_class SEMICOLON def_class : CLASS TYPE LBRACE feature_list RBRACE\n | CLASS TYPE INHERITS TYPE LBRACE feature_list RBRACEfeature_list : def_attr SEMICOLON feature_list\n | def_func SEMICOLON feature_list\n | epsilondef_attr : ID COLON TYPE\n | ID COLON TYPE ASSIGN exprdef_func : ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACEparams : param_list\n | param_list_emptyparam_list : param\n | param COMMA param_listparam_list_empty : epsilonparam : ID COLON TYPEexpr : LET let_attrs IN expr\n | CASE expr OF case_list ESAC\n | IF expr THEN expr ELSE expr FI\n | WHILE expr LOOP expr POOLexpr : ID ASSIGN exprexpr : expr AT TYPE DOT ID LPAREN args RPAREN\n | expr DOT ID LPAREN args RPAREN\n | ID LPAREN args RPARENexpr : expr PLUS expr\n | expr MINUS expr\n | expr STAR expr\n | expr DIV expr\n | expr LESS expr\n | expr LESSEQ expr\n | expr EQUAL exprexpr : NOT expr\n | ISVOID expr\n | LNOT exprexpr : LPAREN expr RPARENexpr : atomlet_attrs : def_attr\n | def_attr COMMA let_attrscase_list : case_option SEMICOLON\n | case_option SEMICOLON case_listcase_option : ID COLON TYPE ARROW exprargs : arg_list\n | arg_list_emptyarg_list : expr\n | expr COMMA arg_listarg_list_empty : epsilonatom : INTatom : IDatom : BOOLatom : STRINGatom : NEW TYPEatom : blockblock : LBRACE block_list RBRACE block_list : expr SEMICOLON\n | expr SEMICOLON block_list' -_lr_action_items = {'CLASS':([0,5,],[4,4,]),'$end':([1,2,5,7,],[0,-1,-4,-3,]),'SEMICOLON':([3,11,12,16,24,36,37,38,47,48,49,50,52,75,76,77,78,80,82,90,91,92,93,94,95,96,102,103,106,110,113,122,126,127,129,135,136,137,],[5,17,18,-5,-10,-6,-50,-11,-38,-49,-51,-52,-54,-34,-35,-36,-53,104,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,123,-20,-22,-12,-25,-21,-24,-43,]),'TYPE':([4,9,19,33,51,55,59,124,],[6,15,24,54,78,81,88,131,]),'LPAREN':([6,14,15,32,37,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,89,97,100,101,104,105,107,109,120,125,128,134,],[8,20,21,43,58,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,109,43,43,43,43,43,43,43,128,43,43,43,]),'INHERITS':([6,],[9,]),'ID':([8,17,18,20,21,32,35,39,40,41,42,43,44,45,46,53,57,58,60,61,62,63,64,65,66,67,97,98,99,100,101,104,105,107,108,109,123,125,128,134,],[14,14,14,25,14,37,25,70,37,37,37,37,37,37,37,37,37,37,89,37,37,37,37,37,37,37,37,70,114,37,37,37,37,37,120,37,114,37,37,37,]),'RPAREN':([8,10,13,17,18,20,21,22,23,26,27,28,29,30,31,37,47,48,49,50,52,54,56,58,74,75,76,77,78,82,83,84,85,86,87,90,91,92,93,94,95,96,102,103,106,109,110,119,121,122,126,128,129,133,135,136,],[-2,16,-9,-2,-2,-2,-2,-7,-8,34,-13,-14,-15,-17,36,-50,-38,-49,-51,-52,-54,-18,-16,-2,102,-34,-35,-36,-53,-23,106,-44,-45,-46,-48,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-2,-19,-47,129,-20,-22,-2,-25,136,-21,-24,]),'COLON':([14,25,34,70,114,],[19,33,55,19,124,]),'COMMA':([24,29,37,38,47,48,49,50,52,54,69,75,76,77,78,82,86,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-10,35,-50,-11,-38,-49,-51,-52,-54,-18,98,-34,-35,-36,-53,-23,107,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'IN':([24,37,38,47,48,49,50,52,68,69,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,111,122,126,129,135,136,],[-10,-50,-11,-38,-49,-51,-52,-54,97,-39,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-40,-20,-22,-25,-21,-24,]),'ASSIGN':([24,37,],[32,57,]),'LET':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,]),'CASE':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,]),'IF':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,]),'WHILE':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,]),'NOT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,]),'ISVOID':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,]),'LNOT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,]),'INT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,]),'BOOL':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,]),'STRING':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,]),'NEW':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,]),'LBRACE':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,81,97,100,101,104,105,107,109,125,128,134,],[53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,105,53,53,53,53,53,53,53,53,53,53,]),'AT':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,59,-38,-49,-51,-52,-54,59,59,59,59,59,59,59,-53,59,59,59,59,59,59,59,59,59,59,-37,-55,-26,59,59,59,59,-20,-22,-25,59,-21,-24,59,]),'DOT':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,88,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,60,-38,-49,-51,-52,-54,60,60,60,60,60,60,60,-53,60,60,60,108,60,60,60,60,60,60,60,-37,-55,-26,60,60,60,60,-20,-22,-25,60,-21,-24,60,]),'PLUS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,61,-38,-49,-51,-52,-54,61,61,61,61,61,61,61,-53,61,61,61,61,61,61,61,61,61,61,-37,-55,-26,61,61,61,61,-20,-22,-25,61,-21,-24,61,]),'MINUS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,62,-38,-49,-51,-52,-54,62,62,62,62,62,62,62,-53,62,62,62,62,62,62,62,62,62,62,-37,-55,-26,62,62,62,62,-20,-22,-25,62,-21,-24,62,]),'STAR':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,63,-38,-49,-51,-52,-54,63,63,63,63,63,63,63,-53,63,63,63,63,63,63,63,63,63,63,-37,-55,-26,63,63,63,63,-20,-22,-25,63,-21,-24,63,]),'DIV':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,64,-38,-49,-51,-52,-54,64,64,64,64,64,64,64,-53,64,64,64,64,64,64,64,64,64,64,-37,-55,-26,64,64,64,64,-20,-22,-25,64,-21,-24,64,]),'LESS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,65,-38,-49,-51,-52,-54,65,65,65,65,65,65,65,-53,65,65,65,65,65,65,65,65,65,65,-37,-55,-26,65,65,65,65,-20,-22,-25,65,-21,-24,65,]),'LESSEQ':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,66,-38,-49,-51,-52,-54,66,66,66,66,66,66,66,-53,66,66,66,66,66,66,66,66,66,66,-37,-55,-26,66,66,66,66,-20,-22,-25,66,-21,-24,66,]),'EQUAL':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,67,-38,-49,-51,-52,-54,67,67,67,67,67,67,67,-53,67,67,67,67,67,67,67,67,67,67,-37,-55,-26,67,67,67,67,-20,-22,-25,67,-21,-24,67,]),'OF':([37,47,48,49,50,52,71,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,99,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'THEN':([37,47,48,49,50,52,72,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,100,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'LOOP':([37,47,48,49,50,52,73,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,101,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'ELSE':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,115,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,125,-20,-22,-25,-21,-24,]),'POOL':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,116,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,126,-20,-22,-25,-21,-24,]),'RBRACE':([37,47,48,49,50,52,75,76,77,78,79,82,90,91,92,93,94,95,96,102,103,104,106,110,117,118,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,103,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-56,-26,-19,-57,127,-20,-22,-25,-21,-24,]),'FI':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,132,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,135,-21,-24,]),'ESAC':([112,123,130,],[122,-41,-42,]),'ARROW':([131,],[134,]),} +_lr_action_items = {'CLASS':([0,5,],[4,4,]),'$end':([1,2,5,7,],[0,-1,-4,-3,]),'SEMICOLON':([3,11,12,16,24,36,37,38,47,48,49,50,52,75,76,77,78,80,82,90,91,92,93,94,95,96,102,103,106,110,113,122,126,127,129,135,136,137,],[5,17,18,-5,-10,-6,-50,-11,-38,-49,-51,-52,-54,-34,-35,-36,-53,104,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,123,-20,-22,-12,-25,-21,-24,-43,]),'TYPE':([4,9,19,33,51,55,59,124,],[6,15,24,54,78,81,88,131,]),'LBRACE':([6,15,32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,81,97,100,101,104,105,107,109,125,128,134,],[8,21,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,105,53,53,53,53,53,53,53,53,53,53,]),'INHERITS':([6,],[9,]),'ID':([8,17,18,20,21,32,35,39,40,41,42,43,44,45,46,53,57,58,60,61,62,63,64,65,66,67,97,98,99,100,101,104,105,107,108,109,123,125,128,134,],[14,14,14,25,14,37,25,70,37,37,37,37,37,37,37,37,37,37,89,37,37,37,37,37,37,37,37,70,114,37,37,37,37,37,120,37,114,37,37,37,]),'RBRACE':([8,10,13,17,18,21,22,23,31,37,47,48,49,50,52,75,76,77,78,79,82,90,91,92,93,94,95,96,102,103,104,106,110,117,118,122,126,129,135,136,],[-2,16,-9,-2,-2,-2,-7,-8,36,-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,103,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-56,-26,-19,-57,127,-20,-22,-25,-21,-24,]),'COLON':([14,25,34,70,114,],[19,33,55,19,124,]),'LPAREN':([14,32,37,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,89,97,100,101,104,105,107,109,120,125,128,134,],[20,43,58,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,109,43,43,43,43,43,43,43,128,43,43,43,]),'RPAREN':([20,26,27,28,29,30,37,47,48,49,50,52,54,56,58,74,75,76,77,78,82,83,84,85,86,87,90,91,92,93,94,95,96,102,103,106,109,110,119,121,122,126,128,129,133,135,136,],[-2,34,-13,-14,-15,-17,-50,-38,-49,-51,-52,-54,-18,-16,-2,102,-34,-35,-36,-53,-23,106,-44,-45,-46,-48,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-2,-19,-47,129,-20,-22,-2,-25,136,-21,-24,]),'COMMA':([24,29,37,38,47,48,49,50,52,54,69,75,76,77,78,82,86,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-10,35,-50,-11,-38,-49,-51,-52,-54,-18,98,-34,-35,-36,-53,-23,107,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'IN':([24,37,38,47,48,49,50,52,68,69,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,111,122,126,129,135,136,],[-10,-50,-11,-38,-49,-51,-52,-54,97,-39,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-40,-20,-22,-25,-21,-24,]),'ASSIGN':([24,37,],[32,57,]),'LET':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,]),'CASE':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,]),'IF':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,]),'WHILE':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,]),'NOT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,]),'ISVOID':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,]),'LNOT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,]),'INT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,]),'BOOL':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,]),'STRING':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,]),'NEW':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,]),'AT':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,59,-38,-49,-51,-52,-54,59,59,59,59,59,59,59,-53,59,59,59,59,59,59,59,59,59,59,-37,-55,-26,59,59,59,59,-20,-22,-25,59,-21,-24,59,]),'DOT':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,88,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,60,-38,-49,-51,-52,-54,60,60,60,60,60,60,60,-53,60,60,60,108,60,60,60,60,60,60,60,-37,-55,-26,60,60,60,60,-20,-22,-25,60,-21,-24,60,]),'PLUS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,61,-38,-49,-51,-52,-54,61,61,61,61,61,61,61,-53,61,61,61,61,61,61,61,61,61,61,-37,-55,-26,61,61,61,61,-20,-22,-25,61,-21,-24,61,]),'MINUS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,62,-38,-49,-51,-52,-54,62,62,62,62,62,62,62,-53,62,62,62,62,62,62,62,62,62,62,-37,-55,-26,62,62,62,62,-20,-22,-25,62,-21,-24,62,]),'STAR':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,63,-38,-49,-51,-52,-54,63,63,63,63,63,63,63,-53,63,63,63,63,63,63,63,63,63,63,-37,-55,-26,63,63,63,63,-20,-22,-25,63,-21,-24,63,]),'DIV':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,64,-38,-49,-51,-52,-54,64,64,64,64,64,64,64,-53,64,64,64,64,64,64,64,64,64,64,-37,-55,-26,64,64,64,64,-20,-22,-25,64,-21,-24,64,]),'LESS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,65,-38,-49,-51,-52,-54,65,65,65,65,65,65,65,-53,65,65,65,65,65,65,65,65,65,65,-37,-55,-26,65,65,65,65,-20,-22,-25,65,-21,-24,65,]),'LESSEQ':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,66,-38,-49,-51,-52,-54,66,66,66,66,66,66,66,-53,66,66,66,66,66,66,66,66,66,66,-37,-55,-26,66,66,66,66,-20,-22,-25,66,-21,-24,66,]),'EQUAL':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,67,-38,-49,-51,-52,-54,67,67,67,67,67,67,67,-53,67,67,67,67,67,67,67,67,67,67,-37,-55,-26,67,67,67,67,-20,-22,-25,67,-21,-24,67,]),'OF':([37,47,48,49,50,52,71,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,99,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'THEN':([37,47,48,49,50,52,72,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,100,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'LOOP':([37,47,48,49,50,52,73,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,101,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'ELSE':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,115,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,125,-20,-22,-25,-21,-24,]),'POOL':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,116,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,126,-20,-22,-25,-21,-24,]),'FI':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,132,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,135,-21,-24,]),'ESAC':([112,123,130,],[122,-41,-42,]),'ARROW':([131,],[134,]),} _lr_action = {} for _k, _v in _lr_action_items.items(): @@ -31,8 +31,8 @@ ('epsilon -> ','epsilon',0,'p_epsilon','parser.py',32), ('class_list -> def_class SEMICOLON class_list','class_list',3,'p_class_list','parser.py',35), ('class_list -> def_class SEMICOLON','class_list',2,'p_class_list','parser.py',36), - ('def_class -> CLASS TYPE LPAREN feature_list RPAREN','def_class',5,'p_def_class','parser.py',40), - ('def_class -> CLASS TYPE INHERITS TYPE LPAREN feature_list RPAREN','def_class',7,'p_def_class','parser.py',41), + ('def_class -> CLASS TYPE LBRACE feature_list RBRACE','def_class',5,'p_def_class','parser.py',40), + ('def_class -> CLASS TYPE INHERITS TYPE LBRACE feature_list RBRACE','def_class',7,'p_def_class','parser.py',41), ('feature_list -> def_attr SEMICOLON feature_list','feature_list',3,'p_feature_list','parser.py',51), ('feature_list -> def_func SEMICOLON feature_list','feature_list',3,'p_feature_list','parser.py',52), ('feature_list -> epsilon','feature_list',1,'p_feature_list','parser.py',53), diff --git a/src/main.py b/src/main.py index 0b50ee611..b56da4d47 100644 --- a/src/main.py +++ b/src/main.py @@ -22,7 +22,7 @@ def main(_input, _output): if __name__ == "__main__": - path = '/mnt/d/UH/4to Año/EVEA/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/parser/assignment1.cl' + path = '/mnt/d/UH/4to Año/EVEA/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/parser/class1.cl' _input = sys.argv[1] if len(sys.argv) > 1 else path _output = sys.argv[2] if len(sys.argv) > 2 else None From bf197f86d30876f99b9857b4ede3c5e3e0190ed9 Mon Sep 17 00:00:00 2001 From: cwjki Date: Wed, 12 Jan 2022 20:02:22 -0500 Subject: [PATCH 076/194] fixing a typo in parser --- src/cparser/parser.py | 2 +- src/main.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cparser/parser.py b/src/cparser/parser.py index c9fcb7504..25e4c4315 100644 --- a/src/cparser/parser.py +++ b/src/cparser/parser.py @@ -157,7 +157,7 @@ def p_expr_operators_binary(self, p): p[0] = LessNode(p[1], p[3]) elif p[2] == '<=': p[0] = LessEqNode(p[1], p[3]) - elif p[2] == '<=': + elif p[2] == '=': p[0] = EqualNode(p[1], p[3]) p[0].add_line_column(p.lineno(0), find_column( diff --git a/src/main.py b/src/main.py index b56da4d47..506c548a3 100644 --- a/src/main.py +++ b/src/main.py @@ -22,7 +22,7 @@ def main(_input, _output): if __name__ == "__main__": - path = '/mnt/d/UH/4to Año/EVEA/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/parser/class1.cl' + path = '/mnt/d/UH/4to Año/EVEA/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/parser/conditional4.cl' _input = sys.argv[1] if len(sys.argv) > 1 else path _output = sys.argv[2] if len(sys.argv) > 2 else None From 8f3027264a39badebcb82e8797d6311a6de2b405 Mon Sep 17 00:00:00 2001 From: liviton Date: Thu, 13 Jan 2022 02:05:02 +0100 Subject: [PATCH 077/194] COOLToCLIVisitor Nodes FuncCall If While Block --- src/code_generator/COOLToCILVisitor.py | 81 +++++++++++++++++++++++++- src/code_generator/cil_ast.py | 2 +- 2 files changed, 81 insertions(+), 2 deletions(-) diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index ae9da8c25..d2bd8a912 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -106,4 +106,83 @@ def visit(self, node, scope): @visitor.when(FuncCallNode) def visit(self, node, scope): - pass + obj, otype = self.visit(node.obj, scope) + + meth = otype.get_method(node.id) + args_node = [cil.ArgNode(obj)] + self.handle_arguments(node.args, scope, meth.param_types) + + rtype = meth.return_type + result = None if isinstance(rtype, VoidType) else self.define_internal_local() + + continue_label = cil.LabelNode(f'continue__{self.index}') + isvoid = self.check_void(obj) + self.register_instruction(cil.IfGoToNode(isvoid, continue_label.label)) + self.register_instruction(cil.ErrorNode('dispatch_error')) + self.register_instruction(continue_label) + + #desambiguar segun sea el llamado, dinamico o estatico + # self.register_instruction(cil.StaticCallNode(node.type, node.id, result, args_node, rtype.name)) + # return result, self._return_type(otype, node) + + # self.register_instruction(cil.DynamicCallNode(self.current_type.name, 'self', node.id, result, args_node, rtype.name)) + # return result, self._return_type(self.current_type, node) + + # if otype in [StringType(), IntType(), BoolType()]: + # self.register_instruction(cil.StaticCallNode(otype.name, node.id, result, args_node, rtype.name)) + # else: + # self.register_instruction(cil.DynamicCallNode(otype.name, obj, node.id, result, args_node, rtype.name)) + # return result, self._return_type(otype, node) + + return + + @visitor.when(IfNode) + def visit(self, node, scope): + vcondition = self.define_internal_local() + value = self.visit(node.condition, scope) + + then_label_node = self.register_label('then_label') + else_label_node = self.register_label('else_label') + continue_label_node = self.register_label('continue_label') + + #If condition GOTO then_label + self.visit(node.condition) + self.register_instruction(cil.GetAttrNode(vcondition, scope.ret_expr, 'value', 'Bool')) + self.register_instruction(cil.IfGoToNode(vcondition, then_label_node.label)) + #GOTO else_label + self.register_instruction(cil.GoToNode(else_label_node.label)) + #Label then_label + self.register_instruction(then_label_node) + self.visit(node.then_expr, scope) + self.register_instruction(cil.AssignNode(vcondition, scope.ret_expr)) + self.register_instruction(cil.GoToNode(continue_label_node.label)) + #Label else_label + self.register_instruction(else_label_node) + self.visit(node.else_expr, scope) + self.register_instruction(cil.AssignNode(vcondition, scope.ret_expr)) + + self.register_instruction(continue_label_node) + scope.ret_expr = vcondition + + @visitor.when(WhileNode) + def visit(self, node, scope): + start_label = cil.LabelNode(f'start__{self.idx}') + end_label = cil.LabelNode(f'end__{self.idx}') + + result = self.define_internal_local() + self.register_instruction(cil.VoidConstantNode(result)) + self.register_instruction(start_label) + + cond, _ = self.visit(node.cond, scope) + self.register_instruction(cil.IfGoToNode(cond, end_label.label)) + expr, typex = self.visit(node.expr, scope) + self.register_instruction(cil.AssignNode(result, expr)) + self.register_instruction(cil.GoToNode(start_label.label)) + self.register_instruction(end_label) + + @visitor.when(BlockNode) + def visit(self, node, scope): + for expr in node.exprs: + value, typex = self.visit(expr, scope) + result = self.define_internal_local() + self.register_instruction(cil.AssignNode(result, value)) + return result, typex \ No newline at end of file diff --git a/src/code_generator/cil_ast.py b/src/code_generator/cil_ast.py index f188ce98e..1b93b545a 100644 --- a/src/code_generator/cil_ast.py +++ b/src/code_generator/cil_ast.py @@ -119,7 +119,7 @@ class GoToNode(InstructionNode): def __init__(self, label): self.label = label -class IfGoTo(InstructionNode): +class IfGoToNode(InstructionNode): def __init__(self, condition, label): self.condition = condition self.label = label From 42c9d77ef114dd4f4435e22a07c02ca64b3d83d9 Mon Sep 17 00:00:00 2001 From: liviton Date: Sun, 16 Jan 2022 00:59:47 +0100 Subject: [PATCH 078/194] COOLToCLIVisitor Nodes Let Case Var New AllBinary --- src/code_generator/COOLToCILVisitor.py | 88 +++++++++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-) diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index d2bd8a912..2e1416a66 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -185,4 +185,90 @@ def visit(self, node, scope): value, typex = self.visit(expr, scope) result = self.define_internal_local() self.register_instruction(cil.AssignNode(result, value)) - return result, typex \ No newline at end of file + return result, typex + + visitor.when(LetNode) + def visit(self, node, scope): + child_scope = scope.expr_dict[node] + for init in node.let_attrs: + self.visit(init, child_scope) + + expr, typex = self.visit(node.expr, child_scope) + return expr, typex + + visitor.when(CaseNode) + def visit(self, node, scope): + expr, typex = self.visit(node.expr, scope) + + result = self.define_internal_local() + end_label = cil.LabelNode(f'end__{self.idx}') + error_label = cil.LabelNode(f'error__{self.idx}') + + isvoid = self.check_void(expr) + self.register_instruction(cil.IfGoToNode(isvoid, error_label.label)) + try: + new_scope = scope.expr_dict[node] + except: + new_scope = scope + sorted_case_list = self.sort_option_nodes_by_type(node.case_list) + for i, case in enumerate(sorted_case_list): + next_label = cil.LabelNode(f'next__{self.idx}_{i}') + expr_i = self.visit(case, new_scope.create_child(), expr, next_label, typex) + self.register_instruction(cil.AssignNode(result, expr_i)) + self.register_instruction(cil.GoToNode(end_label.label)) + self.register_instruction(next_label) + self.register_instruction(end_label) + return result, typex + + visitor.when(VarNode) + def visit(self, node, scope): + try: + typex = scope.find_local(node.lex).type + name = self.to_var_name(node.lex) + return name, get_type(typex, self.current_type) + except: + var_info = scope.find_attribute(node.lex) + local_var = self.register_local(var_info.name) + self.register_instruction(cil.GetAttrNode('self', var_info.name, self.current_type.name, local_var, var_info.type.name)) + return local_var, get_type(var_info.type, self.current_type) + + visitor.when(NewNode) + def visit(self, node, scope): + instance = self.define_internal_local() + typex = self.context.get_type(node.lex) + typex = get_type(typex, self.current_type) + self.register_instruction(cil.AllocateNode(typex.name, instance)) + + if typex.get_all_attributes(): + self.register_instruction(cil.CallNode(typex.name, typex.name, instance, [cil.ArgNode(instance)], typex.name)) + + return instance, typex + + @visitor.when(PlusNode) + def visit(self, node, scope): + return self._define_binary_node(node, scope, cil.PlusNode) + + @visitor.when(MinusNode) + def visit(self, node, scope): + return self._define_binary_node(node, scope, cil.MinusNode) + + @visitor.when(StarNode) + def visit(self, node, scope): + return self._define_binary_node(node, scope, cil.StarNode) + + @visitor.when(DivNode) + def visit(self, node, scope): + return self._define_binary_node(node, scope, cil.DivNode) + + @visitor.when(LessNode) + def visit(self, node, scope): + return self._define_binary_node(node, scope, cil.LessNode) + + @visitor.when(LessEqNode) + def visit(self, node, scope): + return self._define_binary_node(node, scope, cil.LessEqualNode) + + @visitor.when(EqualNode) + def visit(self, node, scope): + return self._define_binary_node(node, scope, cil.EqualNode) + From f9822f72af31ee86377a81579a378210009bda6d Mon Sep 17 00:00:00 2001 From: livi98 Date: Tue, 8 Feb 2022 00:27:30 +0100 Subject: [PATCH 079/194] sync ubuntu --- .github/workflows/tests.yml | 166 +-- .gitignore | 820 +++++------ .vscode/settings.json | 6 +- LICENSE | 42 +- Readme.md | 344 ++--- doc/Readme.md | 66 +- doc/team.yml | 16 +- requirements.txt | 4 +- src/Readme.md | 156 +- src/code_generator/BaseCoolToCilVisitor.py | 132 +- src/code_generator/COOLToCILVisitor.py | 548 +++---- src/code_generator/cil_ast.py | 410 +++--- src/coolc.sh | 32 +- src/cparser/parser.py | 536 +++---- src/cparser/parsetab.py | 174 +-- src/lexer/lexer.py | 560 +++---- src/makefile | 24 +- src/semantic/semantic.py | 652 ++++---- src/semantic/types.py | 222 +-- src/semantic/visitors/type_collector.py | 50 +- src/test.cl | 18 +- src/utils/__init__.py | 2 +- src/utils/ast.py | 400 ++--- src/utils/utils.py | 130 +- src/utils/visitor.py | 164 +-- tests/codegen/arith.cl | 860 +++++------ tests/codegen/arith_input.txt | 26 +- tests/codegen/arith_output.txt | 316 ++-- tests/codegen/atoi_output.txt | 2 +- tests/codegen/book_list.cl | 264 ++-- tests/codegen/book_list_output.txt | 14 +- tests/codegen/cells.cl | 194 +-- tests/codegen/cells_output.txt | 42 +- tests/codegen/complex.cl | 104 +- tests/codegen/complex_output.txt | 2 +- tests/codegen/fib.cl | 58 +- tests/codegen/fib_input.txt | 2 +- tests/codegen/fib_output.txt | 4 +- tests/codegen/graph.cl | 762 +++++----- tests/codegen/graph_input.txt | 10 +- tests/codegen/graph_output.txt | 14 +- tests/codegen/hairyscary.cl | 134 +- tests/codegen/hello_world.cl | 10 +- tests/codegen/hello_world_output.txt | 2 +- tests/codegen/io.cl | 206 +-- tests/codegen/io_output.txt | 10 +- tests/codegen/life.cl | 872 +++++------ tests/codegen/life_input.txt | 130 +- tests/codegen/life_output.txt | 1554 ++++++++++---------- tests/codegen/list_output.txt | 10 +- tests/codegen/new_complex.cl | 158 +- tests/codegen/new_complex_output.txt | 4 +- tests/codegen/palindrome.cl | 50 +- tests/codegen/palindrome_input.txt | 2 +- tests/codegen/palindrome_output.txt | 4 +- tests/codegen/primes_output.txt | 192 +-- tests/codegen/print-cool_output.txt | 2 +- tests/codegen/sort-list_input.txt | 2 +- tests/codegen/sort-list_output.txt | 20 +- tests/codegen_test.py | 32 +- tests/conftest.py | 10 +- tests/lexer/comment1.cl | 108 +- tests/lexer/comment1_error.txt | 2 +- tests/lexer/iis1.cl | 220 +-- tests/lexer/iis1_error.txt | 2 +- tests/lexer/iis2.cl | 238 +-- tests/lexer/iis2_error.txt | 2 +- tests/lexer/iis3.cl | 240 +-- tests/lexer/iis3_error.txt | 2 +- tests/lexer/iis4.cl | 238 +-- tests/lexer/iis4_error.txt | 2 +- tests/lexer/iis5.cl | 242 +-- tests/lexer/iis5_error.txt | 4 +- tests/lexer/iis6.cl | 248 ++-- tests/lexer/iis6_error.txt | 2 +- tests/lexer/mixed1.cl | 26 +- tests/lexer/mixed1_error.txt | 2 +- tests/lexer/mixed2.cl | 38 +- tests/lexer/mixed2_error.txt | 6 +- tests/lexer/string1.cl | 10 +- tests/lexer/string1_error.txt | 2 +- tests/lexer/string2.cl | 36 +- tests/lexer/string4.cl | 74 +- tests/lexer/string4_error.txt | 4 +- tests/lexer_test.py | 24 +- tests/parser/assignment1.cl | 72 +- tests/parser/assignment2.cl | 72 +- tests/parser/assignment3.cl | 72 +- tests/parser/attribute1.cl | 66 +- tests/parser/attribute2.cl | 66 +- tests/parser/attribute3.cl | 66 +- tests/parser/block1.cl | 172 +-- tests/parser/block2.cl | 172 +-- tests/parser/block3.cl | 172 +-- tests/parser/block4.cl | 174 +-- tests/parser/case1.cl | 180 +-- tests/parser/case2.cl | 184 +-- tests/parser/case3.cl | 184 +-- tests/parser/case4.cl | 184 +-- tests/parser/case5.cl | 184 +-- tests/parser/case6.cl | 184 +-- tests/parser/class1.cl | 40 +- tests/parser/class2.cl | 40 +- tests/parser/class3.cl | 68 +- tests/parser/class4.cl | 72 +- tests/parser/class5.cl | 68 +- tests/parser/class6.cl | 68 +- tests/parser/conditional1.cl | 136 +- tests/parser/conditional2.cl | 136 +- tests/parser/conditional3.cl | 136 +- tests/parser/conditional4.cl | 144 +- tests/parser/conditional5.cl | 144 +- tests/parser/conditional6.cl | 144 +- tests/parser/dispatch1.cl | 88 +- tests/parser/dispatch2.cl | 88 +- tests/parser/dispatch3.cl | 88 +- tests/parser/dispatch4.cl | 104 +- tests/parser/dispatch5.cl | 104 +- tests/parser/dispatch6.cl | 112 +- tests/parser/dispatch7.cl | 112 +- tests/parser/dispatch8.cl | 112 +- tests/parser/dispatch9.cl | 120 +- tests/parser/let1.cl | 168 +-- tests/parser/let2.cl | 168 +-- tests/parser/let3.cl | 168 +-- tests/parser/let4.cl | 168 +-- tests/parser/let5.cl | 168 +-- tests/parser/let6.cl | 146 +- tests/parser/let7.cl | 168 +-- tests/parser/loop1.cl | 154 +- tests/parser/loop2.cl | 154 +- tests/parser/loop3.cl | 154 +- tests/parser/loop4.cl | 154 +- tests/parser/method1.cl | 66 +- tests/parser/method2.cl | 66 +- tests/parser/method3.cl | 66 +- tests/parser/method4.cl | 66 +- tests/parser/method5.cl | 66 +- tests/parser/method6.cl | 64 +- tests/parser/mixed1.cl | 198 +-- tests/parser/mixed2.cl | 28 +- tests/parser/mixed3.cl | 80 +- tests/parser/mixed4.cl | 42 +- tests/parser/mixed5.cl | 40 +- tests/parser/mixed6.cl | 10 +- tests/parser/operation1.cl | 200 +-- tests/parser/operation2.cl | 200 +-- tests/parser/operation3.cl | 200 +-- tests/parser/operation4.cl | 200 +-- tests/parser/program2.cl | 40 +- tests/parser/program3.cl | 48 +- tests/parser_test.py | 24 +- tests/semantic/arithmetic1.cl | 20 +- tests/semantic/arithmetic10.cl | 28 +- tests/semantic/arithmetic11.cl | 26 +- tests/semantic/arithmetic12.cl | 26 +- tests/semantic/arithmetic1_error.txt | 2 +- tests/semantic/arithmetic2.cl | 20 +- tests/semantic/arithmetic2_error.txt | 2 +- tests/semantic/arithmetic3.cl | 20 +- tests/semantic/arithmetic3_error.txt | 2 +- tests/semantic/arithmetic4.cl | 20 +- tests/semantic/arithmetic5.cl | 20 +- tests/semantic/arithmetic5_error.txt | 2 +- tests/semantic/arithmetic6.cl | 22 +- tests/semantic/arithmetic6_error.txt | 2 +- tests/semantic/arithmetic7.cl | 24 +- tests/semantic/arithmetic7_error.txt | 2 +- tests/semantic/arithmetic8.cl | 26 +- tests/semantic/arithmetic8_error.txt | 2 +- tests/semantic/arithmetic9.cl | 28 +- tests/semantic/assignment1.cl | 14 +- tests/semantic/assignment1_error.txt | 2 +- tests/semantic/assignment2.cl | 26 +- tests/semantic/assignment2_error.txt | 2 +- tests/semantic/assignment3.cl | 28 +- tests/semantic/attributes1.cl | 24 +- tests/semantic/attributes1_error.txt | 2 +- tests/semantic/attributes2.cl | 24 +- tests/semantic/attributes2_error.txt | 2 +- tests/semantic/attributes3.cl | 48 +- tests/semantic/attributes3_error.txt | 2 +- tests/semantic/attributes4.cl | 76 +- tests/semantic/basics1.cl | 18 +- tests/semantic/basics1_error.txt | 2 +- tests/semantic/basics2.cl | 18 +- tests/semantic/basics2_error.txt | 2 +- tests/semantic/basics3.cl | 16 +- tests/semantic/basics3_error.txt | 2 +- tests/semantic/basics4.cl | 16 +- tests/semantic/basics4_error.txt | 2 +- tests/semantic/basics5.cl | 16 +- tests/semantic/basics5_error.txt | 2 +- tests/semantic/basics6.cl | 16 +- tests/semantic/basics6_error.txt | 2 +- tests/semantic/basics7.cl | 16 +- tests/semantic/basics7_error.txt | 2 +- tests/semantic/basics8.cl | 16 +- tests/semantic/basics8_error.txt | 2 +- tests/semantic/blocks1.cl | 60 +- tests/semantic/blocks1_error.txt | 2 +- tests/semantic/case1.cl | 46 +- tests/semantic/case1_error.txt | 2 +- tests/semantic/case2.cl | 44 +- tests/semantic/case3.cl | 44 +- tests/semantic/class1.cl | 16 +- tests/semantic/class1_error.txt | 4 +- tests/semantic/conditionals1.cl | 26 +- tests/semantic/conditionals1_error.txt | 2 +- tests/semantic/conditionals2.cl | 48 +- tests/semantic/conditionals2_error.txt | 4 +- tests/semantic/dispatch1.cl | 64 +- tests/semantic/dispatch1_error.txt | 2 +- tests/semantic/dispatch2.cl | 66 +- tests/semantic/dispatch2_error.txt | 2 +- tests/semantic/dispatch3.cl | 70 +- tests/semantic/dispatch3_error.txt | 2 +- tests/semantic/dispatch4.cl | 70 +- tests/semantic/dispatch5.cl | 60 +- tests/semantic/dispatch5_error.txt | 2 +- tests/semantic/dispatch6.cl | 64 +- tests/semantic/dispatch6_error.txt | 2 +- tests/semantic/eq1.cl | 32 +- tests/semantic/eq1_error.txt | 2 +- tests/semantic/eq2.cl | 34 +- tests/semantic/eq2_error.txt | 2 +- tests/semantic/eq3.cl | 34 +- tests/semantic/eq3_error.txt | 2 +- tests/semantic/eq4.cl | 34 +- tests/semantic/eq4_error.txt | 2 +- tests/semantic/isvoid1.cl | 50 +- tests/semantic/isvoid1_error.txt | 2 +- tests/semantic/let1.cl | 28 +- tests/semantic/let1_error.txt | 2 +- tests/semantic/let2.cl | 28 +- tests/semantic/let2_error.txt | 2 +- tests/semantic/let3.cl | 28 +- tests/semantic/loops1.cl | 14 +- tests/semantic/loops2.cl | 18 +- tests/semantic/loops2_error.txt | 2 +- tests/semantic/methods1.cl | 22 +- tests/semantic/methods1_error.txt | 2 +- tests/semantic/methods2.cl | 22 +- tests/semantic/methods2_error.txt | 2 +- tests/semantic/methods3.cl | 26 +- tests/semantic/methods3_error.txt | 2 +- tests/semantic/methods4.cl | 36 +- tests/semantic/methods4_error.txt | 2 +- tests/semantic/methods5.cl | 40 +- tests/semantic/methods5_error.txt | 2 +- tests/semantic/methods6.cl | 52 +- tests/semantic/methods6_error.txt | 2 +- tests/semantic/methods7.cl | 22 +- tests/semantic/methods8.cl | 22 +- tests/semantic/new1.cl | 60 +- tests/semantic/self1.cl | 22 +- tests/semantic/self1_error.txt | 2 +- tests/semantic/self2.cl | 20 +- tests/semantic/self2_error.txt | 2 +- tests/semantic/self3.cl | 20 +- tests/semantic/self3_error.txt | 2 +- tests/semantic/self4.cl | 18 +- tests/semantic/self4_error.txt | 2 +- tests/semantic_test.py | 26 +- tests/utils/utils.py | 182 +-- 265 files changed, 11823 insertions(+), 11823 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 62ff3680b..9fb3b7bf2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,83 +1,83 @@ -name: Tests - -on: [push, pull_request] - -jobs: - lexer: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Setup Python - uses: actions/setup-python@v2 - - - name: Install requirements - run: pip install -r requirements.txt - - - name: Run tests - run: | - cd src - make clean - make - make test TAG=lexer - - parser: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Setup Python - uses: actions/setup-python@v2 - - - name: Install requirements - run: pip install -r requirements.txt - - - name: Run tests - run: | - cd src - make clean - make - make test TAG=parser - - semantic: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Setup Python - uses: actions/setup-python@v2 - - - name: Install requirements - run: pip install -r requirements.txt - - - name: Run tests - run: | - cd src - make clean - make - make test TAG=semantic - - codegen: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Setup Python - uses: actions/setup-python@v2 - - - name: Install requirements - run: pip install -r requirements.txt - - - name: Install spim - run: sudo apt-get install spim - - - name: Run tests - run: | - cd src - make clean - make - make test TAG=codegen +name: Tests + +on: [push, pull_request] + +jobs: + lexer: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v2 + + - name: Install requirements + run: pip install -r requirements.txt + + - name: Run tests + run: | + cd src + make clean + make + make test TAG=lexer + + parser: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v2 + + - name: Install requirements + run: pip install -r requirements.txt + + - name: Run tests + run: | + cd src + make clean + make + make test TAG=parser + + semantic: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v2 + + - name: Install requirements + run: pip install -r requirements.txt + + - name: Run tests + run: | + cd src + make clean + make + make test TAG=semantic + + codegen: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v2 + + - name: Install requirements + run: pip install -r requirements.txt + + - name: Install spim + run: sudo apt-get install spim + + - name: Run tests + run: | + cd src + make clean + make + make test TAG=codegen diff --git a/.gitignore b/.gitignore index 4acafde18..0b07f7b23 100644 --- a/.gitignore +++ b/.gitignore @@ -1,410 +1,410 @@ -# File created using '.gitignore Generator' for Visual Studio Code: https://bit.ly/vscode-gig - -# Created by https://www.gitignore.io/api/visualstudiocode,linux,latex,python -# Edit at https://www.gitignore.io/?templates=visualstudiocode,linux,latex,python - -### LaTeX ### -## Core latex/pdflatex auxiliary files: -*.aux -*.lof -*.log -*.lot -*.fls -*.out -*.toc -*.fmt -*.fot -*.cb -*.cb2 -.*.lb - -## Intermediate documents: -*.dvi -*.xdv -*-converted-to.* -# these rules might exclude image files for figures etc. -# *.ps -# *.eps -# *.pdf - -## Generated if empty string is given at "Please type another file name for output:" -.pdf - -## Bibliography auxiliary files (bibtex/biblatex/biber): -*.bbl -*.bcf -*.blg -*-blx.aux -*-blx.bib -*.run.xml - -## Build tool auxiliary files: -*.fdb_latexmk -*.synctex -*.synctex(busy) -*.synctex.gz -*.synctex.gz(busy) -*.pdfsync - -## Build tool directories for auxiliary files -# latexrun -latex.out/ - -## Auxiliary and intermediate files from other packages: -# algorithms -*.alg -*.loa - -# achemso -acs-*.bib - -# amsthm -*.thm - -# beamer -*.nav -*.pre -*.snm -*.vrb - -# changes -*.soc - -# comment -*.cut - -# cprotect -*.cpt - -# elsarticle (documentclass of Elsevier journals) -*.spl - -# endnotes -*.ent - -# fixme -*.lox - -# feynmf/feynmp -*.mf -*.mp -*.t[1-9] -*.t[1-9][0-9] -*.tfm - -#(r)(e)ledmac/(r)(e)ledpar -*.end -*.?end -*.[1-9] -*.[1-9][0-9] -*.[1-9][0-9][0-9] -*.[1-9]R -*.[1-9][0-9]R -*.[1-9][0-9][0-9]R -*.eledsec[1-9] -*.eledsec[1-9]R -*.eledsec[1-9][0-9] -*.eledsec[1-9][0-9]R -*.eledsec[1-9][0-9][0-9] -*.eledsec[1-9][0-9][0-9]R - -# glossaries -*.acn -*.acr -*.glg -*.glo -*.gls -*.glsdefs - -# uncomment this for glossaries-extra (will ignore makeindex's style files!) -# *.ist - -# gnuplottex -*-gnuplottex-* - -# gregoriotex -*.gaux -*.gtex - -# htlatex -*.4ct -*.4tc -*.idv -*.lg -*.trc -*.xref - -# hyperref -*.brf - -# knitr -*-concordance.tex -# TODO Comment the next line if you want to keep your tikz graphics files -*.tikz -*-tikzDictionary - -# listings -*.lol - -# luatexja-ruby -*.ltjruby - -# makeidx -*.idx -*.ilg -*.ind - -# minitoc -*.maf -*.mlf -*.mlt -*.mtc[0-9]* -*.slf[0-9]* -*.slt[0-9]* -*.stc[0-9]* - -# minted -_minted* -*.pyg - -# morewrites -*.mw - -# nomencl -*.nlg -*.nlo -*.nls - -# pax -*.pax - -# pdfpcnotes -*.pdfpc - -# sagetex -*.sagetex.sage -*.sagetex.py -*.sagetex.scmd - -# scrwfile -*.wrt - -# sympy -*.sout -*.sympy -sympy-plots-for-*.tex/ - -# pdfcomment -*.upa -*.upb - -# pythontex -*.pytxcode -pythontex-files-*/ - -# tcolorbox -*.listing - -# thmtools -*.loe - -# TikZ & PGF -*.dpth -*.md5 -*.auxlock - -# todonotes -*.tdo - -# vhistory -*.hst -*.ver - -# easy-todo -*.lod - -# xcolor -*.xcp - -# xmpincl -*.xmpi - -# xindy -*.xdy - -# xypic precompiled matrices -*.xyc - -# endfloat -*.ttt -*.fff - -# Latexian -TSWLatexianTemp* - -## Editors: -# WinEdt -*.bak -*.sav - -# Texpad -.texpadtmp - -# LyX -*.lyx~ - -# Kile -*.backup - -# KBibTeX -*~[0-9]* - -# auto folder when using emacs and auctex -./auto/* -*.el - -# expex forward references with \gathertags -*-tags.tex - -# standalone packages -*.sta - -### LaTeX Patch ### -# glossaries -*.glstex - -### 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* - -### Python ### -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -pip-wheel-metadata/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -.hypothesis/ -.pytest_cache/ - -# Translations -*.mo -*.pot - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -target/ - -# pyenv -.python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# celery beat schedule file -celerybeat-schedule - -# SageMath parsed files -*.sage.py - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# Mr Developer -.mr.developer.cfg -.project -.pydevproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -### VisualStudioCode ### -.vscode/* -!.vscode/settings.json -!.vscode/tasks.json -!.vscode/launch.json -!.vscode/extensions.json - -### VisualStudioCode Patch ### -# Ignore all local history of files -.history - -# End of https://www.gitignore.io/api/visualstudiocode,linux,latex,python - -# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option) - +# File created using '.gitignore Generator' for Visual Studio Code: https://bit.ly/vscode-gig + +# Created by https://www.gitignore.io/api/visualstudiocode,linux,latex,python +# Edit at https://www.gitignore.io/?templates=visualstudiocode,linux,latex,python + +### LaTeX ### +## Core latex/pdflatex auxiliary files: +*.aux +*.lof +*.log +*.lot +*.fls +*.out +*.toc +*.fmt +*.fot +*.cb +*.cb2 +.*.lb + +## Intermediate documents: +*.dvi +*.xdv +*-converted-to.* +# these rules might exclude image files for figures etc. +# *.ps +# *.eps +# *.pdf + +## Generated if empty string is given at "Please type another file name for output:" +.pdf + +## Bibliography auxiliary files (bibtex/biblatex/biber): +*.bbl +*.bcf +*.blg +*-blx.aux +*-blx.bib +*.run.xml + +## Build tool auxiliary files: +*.fdb_latexmk +*.synctex +*.synctex(busy) +*.synctex.gz +*.synctex.gz(busy) +*.pdfsync + +## Build tool directories for auxiliary files +# latexrun +latex.out/ + +## Auxiliary and intermediate files from other packages: +# algorithms +*.alg +*.loa + +# achemso +acs-*.bib + +# amsthm +*.thm + +# beamer +*.nav +*.pre +*.snm +*.vrb + +# changes +*.soc + +# comment +*.cut + +# cprotect +*.cpt + +# elsarticle (documentclass of Elsevier journals) +*.spl + +# endnotes +*.ent + +# fixme +*.lox + +# feynmf/feynmp +*.mf +*.mp +*.t[1-9] +*.t[1-9][0-9] +*.tfm + +#(r)(e)ledmac/(r)(e)ledpar +*.end +*.?end +*.[1-9] +*.[1-9][0-9] +*.[1-9][0-9][0-9] +*.[1-9]R +*.[1-9][0-9]R +*.[1-9][0-9][0-9]R +*.eledsec[1-9] +*.eledsec[1-9]R +*.eledsec[1-9][0-9] +*.eledsec[1-9][0-9]R +*.eledsec[1-9][0-9][0-9] +*.eledsec[1-9][0-9][0-9]R + +# glossaries +*.acn +*.acr +*.glg +*.glo +*.gls +*.glsdefs + +# uncomment this for glossaries-extra (will ignore makeindex's style files!) +# *.ist + +# gnuplottex +*-gnuplottex-* + +# gregoriotex +*.gaux +*.gtex + +# htlatex +*.4ct +*.4tc +*.idv +*.lg +*.trc +*.xref + +# hyperref +*.brf + +# knitr +*-concordance.tex +# TODO Comment the next line if you want to keep your tikz graphics files +*.tikz +*-tikzDictionary + +# listings +*.lol + +# luatexja-ruby +*.ltjruby + +# makeidx +*.idx +*.ilg +*.ind + +# minitoc +*.maf +*.mlf +*.mlt +*.mtc[0-9]* +*.slf[0-9]* +*.slt[0-9]* +*.stc[0-9]* + +# minted +_minted* +*.pyg + +# morewrites +*.mw + +# nomencl +*.nlg +*.nlo +*.nls + +# pax +*.pax + +# pdfpcnotes +*.pdfpc + +# sagetex +*.sagetex.sage +*.sagetex.py +*.sagetex.scmd + +# scrwfile +*.wrt + +# sympy +*.sout +*.sympy +sympy-plots-for-*.tex/ + +# pdfcomment +*.upa +*.upb + +# pythontex +*.pytxcode +pythontex-files-*/ + +# tcolorbox +*.listing + +# thmtools +*.loe + +# TikZ & PGF +*.dpth +*.md5 +*.auxlock + +# todonotes +*.tdo + +# vhistory +*.hst +*.ver + +# easy-todo +*.lod + +# xcolor +*.xcp + +# xmpincl +*.xmpi + +# xindy +*.xdy + +# xypic precompiled matrices +*.xyc + +# endfloat +*.ttt +*.fff + +# Latexian +TSWLatexianTemp* + +## Editors: +# WinEdt +*.bak +*.sav + +# Texpad +.texpadtmp + +# LyX +*.lyx~ + +# Kile +*.backup + +# KBibTeX +*~[0-9]* + +# auto folder when using emacs and auctex +./auto/* +*.el + +# expex forward references with \gathertags +*-tags.tex + +# standalone packages +*.sta + +### LaTeX Patch ### +# glossaries +*.glstex + +### 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* + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# Mr Developer +.mr.developer.cfg +.project +.pydevproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history + +# End of https://www.gitignore.io/api/visualstudiocode,linux,latex,python + +# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option) + diff --git a/.vscode/settings.json b/.vscode/settings.json index cc67606f3..82a851134 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,4 @@ -{ - "python.linting.pylintEnabled": true, - "python.linting.enabled": true +{ + "python.linting.pylintEnabled": true, + "python.linting.enabled": true } \ No newline at end of file diff --git a/LICENSE b/LICENSE index 718bd210a..7f19c2d8c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,21 +1,21 @@ -MIT License - -Copyright (c) 2021 School of Math and Computer Science, University of Havana - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +MIT License + +Copyright (c) 2021 School of Math and Computer Science, University of Havana + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Readme.md b/Readme.md index a47d48b9e..0e33ddb08 100644 --- a/Readme.md +++ b/Readme.md @@ -1,172 +1,172 @@ -# COOL: Proyecto de Compilación - -> Proyecto base para el compilador de 4to año en Ciencia de la Computación. - -## Generalidades - -La evaluación de la asignatura Complementos de Compilación, inscrita en el programa del 4to año de la Licenciatura en Ciencia de la Computación de la Facultad de Matemática y Computación de la -Universidad de La Habana, consiste este curso en la implementación de un compilador completamente -funcional para el lenguaje _COOL_. - -_COOL (Classroom Object-Oriented Language)_ es un pequeño lenguaje que puede ser implementado con un esfuerzo razonable en un semestre del curso. Aun así, _COOL_ mantiene muchas de las características de los lenguajes de programación modernos, incluyendo orientación a objetos, tipado estático y manejo automático de memoria. - -## Cómo comenzar (o terminar) - -El proyecto de Compilación será recogido y evaluado **únicamente** a través de Github. Es imprescindible tener una cuenta de Github para cada participante, y que su proyecto esté correctamente hosteado en esta plataforma. A continuación le damos las instrucciones mínimas necesarias para ello: - -### 1. Si no lo han hecho ya, regístrense en [Github](https://github.com) todos los miembros del equipo (es gratis). - -![](img/img1.png) - -### 2. Haga click en el botón **Fork** para hacer una copia del proyecto en el perfil de Github de uno de los miembros. - -Opcionalmente pueden [crear una organización](https://github.com/organizations/new) y copiar el proyecto en el perfil de la misma. - -![](img/img2.png) - -### 3. Una vez hecho esto, tendrá un nuevo repositorio en `github/`. - -Revise que el repositorio de su equipo está en su perfil. -En este ejemplo se ha copiado a la cuenta de `github.com/apiad`. - -Debe indicar bajo el nombre del repositorio: `"forked from matcom/cool-compiler-2021"`. - -![](img/img3.png) - -### 4. Clone este proyecto en un repositorio local. - -Busque la URL de su proyecto en la interfaz web de Github. - -Asegúrese de clonar **su copia** y no el proyecto original en `matcom/cool-compiler-2021`. - -![](img/img4.png) - -```bash -$ git clone git@github.com:/cool-compiler-2021.git -``` - -> Donde `` es posiblemente el nombre de su equipo o del miembro donde se hizo el _fork_. - -A partir de este punto debe tener un proyecto `cool-compiler-2021` local. -El siguiente paso depende de si usted ya tiene su código versionado con `git` o no. - -### 5.A. Si tiene su proyecto en git (y no quiere perder la historia): - -#### 5.1. Mezcle hacia el nuevo respositorio su repositorio anterior: - -```bash -$ cd cool-compiler-2021 -$ git pull --allow-unrelated-histories master -``` - -#### 5.2. Organice su proyecto, código fuente y documentación, de acuerdo a las instrucciones de este documento, y vuelva a hacer `commit`. - -```bash -$ mv src/ -$ git add . -$ git commit -a -m "Mezclado con el proyecto base" -``` - -#### 5.3. A partir de este punto puede hacer `push` cada vez que tenga cambios que subir. - -```bash -$ git push origin master -``` - -### 5.B Si aún no tiene su proyecto en git (o no le importa la historia): - -#### 5.1. Simplemente copie el código de su proyecto en la carpeta correspondiente `src` y haga su primer commit. - -```bash -$ mv src/ -$ git commit -a -m "Hello Git!" -``` - -#### 5.2. A partir de este punto asegúrese de hacer `commit` de forma regular para mantener su repositorio actualizado. - -Si necesita saber más sobre `git`, todo lo imprescindible está en [esta guía](doc/github-git-cheat-sheet.pdf). - -#### 5.3. A partir de este punto puede hacer `push` cada vez que tenga cambios que subir. - -```bash -$ git push origin master -``` - -## Entregas - -En este proyecto se realizarán entregas parciales a lo largo del curso. Para realizar una entrega, siga los siguientes pasos. - -### 1. Cree un pull request al proyecto original desde su copia. - -![](img/img5.png) - -### 2. Asegúrese de tener la siguiente configuración antes de hacer click en **Create pull request**. - -- **base repository**: `matcom/cool-compiler-2021` (repositorio original) - - **branch**: `master` -- **head repository**: `/cool-compiler-2021` (repositorio propio) - - **branch**: `master` (o la que corresponda) - -> Asegúrese que se indica **Able to merge**. De lo contrario, existen cambios en el repositorio original que usted no tiene, y debe actualizarlos. - -> **NOTA**: Asegúrese que el _pull request_ se hace a la rama `master`. - -![](img/img6.png) - -### 3. Introduzca un título y descripción adecuados, y haga click en **Create pull request**. - -![](img/img7.png) - -### 4. Espere mientras se ejecutan las pruebas. - -Verá la indicación **Some checks haven't completed yet**. - -![](img/img8.png) - -Es posible que tenga que actualizar los cambios que se hayan hecho en el repositorio original, por ejemplo, si se han agregado nuevos tests. En este caso obtendrá el siguiente mensaje: - -> **This branch is out-of-date with base branch** - -Haga click en **Update branch** y siga las instrucciones. -### 5. Verifique que no hubo errores en las pruebas. - -Si ve el mensaje **(All | Some) checks have failed**, significa que su código no pasó las pruebas. - -![](img/img9.png) - -Para ver los resultados de las pruebas haga click en el link **Details**. - -![](img/img10.png) - - -### 6. Arregle los errores y repita el paso 5 hasta que todas las pruebas pasen. - -Para cualquier modificación que haga a su proyecto, haga _commit_ y _push_ para **su repositorio personal** y automáticamente se actualizará el estado del _pull request_ y se volverán a ejecutar las pruebas. **No es necesario** abrir un _pull request_ nuevo por cada entrega, sino actualizar el anterior. - -> **Por favor asegúrese de mantener un solo _pull request_ activo por equipo**. En caso de abrir uno nuevo, cerrar el anterior. - -## Sobre la implementación - -Ponga todo su código e instrucciones necesarias en la carpeta `src`. Más información en [`src/Readme.md`](src/Readme.md). - -## Sobre la documentación - -Usted debe presentar un reporte escrito documentando el proceso de construcción de su compilador y los detalles más importantes de su funcionamiento. Más información en [`doc/Readme.md`](doc/Readme.md). - -## Sobre los equipos de desarrollo - -Para desarrollar el compilador del lenguaje COOL se trabajará en equipos de 2 o 3 integrantes. - -## Sobre los casos de prueba - -La carpeta `tests` contiene todos los casos de prueba que son obligatorios de pasar para que su proyecto tenga derecho a ser evaluado. - -Estos tests se ejecutan automáticamente cada vez que hace un _pull request_ al repositorio `matcom/cool-compiler-2021`. Solo aquellos proyectos que pasen todas las pruebas con éxito serán evaluados. - -Para ejecutar las pruebas localmente, debe tener instalado `Python 3.7`, `pip` y `make` (normalmente viene con Linux). Ejecute: - -```bash -$ pip install -r requirements.txt -$ cd src -$ make test -``` +# COOL: Proyecto de Compilación + +> Proyecto base para el compilador de 4to año en Ciencia de la Computación. + +## Generalidades + +La evaluación de la asignatura Complementos de Compilación, inscrita en el programa del 4to año de la Licenciatura en Ciencia de la Computación de la Facultad de Matemática y Computación de la +Universidad de La Habana, consiste este curso en la implementación de un compilador completamente +funcional para el lenguaje _COOL_. + +_COOL (Classroom Object-Oriented Language)_ es un pequeño lenguaje que puede ser implementado con un esfuerzo razonable en un semestre del curso. Aun así, _COOL_ mantiene muchas de las características de los lenguajes de programación modernos, incluyendo orientación a objetos, tipado estático y manejo automático de memoria. + +## Cómo comenzar (o terminar) + +El proyecto de Compilación será recogido y evaluado **únicamente** a través de Github. Es imprescindible tener una cuenta de Github para cada participante, y que su proyecto esté correctamente hosteado en esta plataforma. A continuación le damos las instrucciones mínimas necesarias para ello: + +### 1. Si no lo han hecho ya, regístrense en [Github](https://github.com) todos los miembros del equipo (es gratis). + +![](img/img1.png) + +### 2. Haga click en el botón **Fork** para hacer una copia del proyecto en el perfil de Github de uno de los miembros. + +Opcionalmente pueden [crear una organización](https://github.com/organizations/new) y copiar el proyecto en el perfil de la misma. + +![](img/img2.png) + +### 3. Una vez hecho esto, tendrá un nuevo repositorio en `github/`. + +Revise que el repositorio de su equipo está en su perfil. +En este ejemplo se ha copiado a la cuenta de `github.com/apiad`. + +Debe indicar bajo el nombre del repositorio: `"forked from matcom/cool-compiler-2021"`. + +![](img/img3.png) + +### 4. Clone este proyecto en un repositorio local. + +Busque la URL de su proyecto en la interfaz web de Github. + +Asegúrese de clonar **su copia** y no el proyecto original en `matcom/cool-compiler-2021`. + +![](img/img4.png) + +```bash +$ git clone git@github.com:/cool-compiler-2021.git +``` + +> Donde `` es posiblemente el nombre de su equipo o del miembro donde se hizo el _fork_. + +A partir de este punto debe tener un proyecto `cool-compiler-2021` local. +El siguiente paso depende de si usted ya tiene su código versionado con `git` o no. + +### 5.A. Si tiene su proyecto en git (y no quiere perder la historia): + +#### 5.1. Mezcle hacia el nuevo respositorio su repositorio anterior: + +```bash +$ cd cool-compiler-2021 +$ git pull --allow-unrelated-histories master +``` + +#### 5.2. Organice su proyecto, código fuente y documentación, de acuerdo a las instrucciones de este documento, y vuelva a hacer `commit`. + +```bash +$ mv src/ +$ git add . +$ git commit -a -m "Mezclado con el proyecto base" +``` + +#### 5.3. A partir de este punto puede hacer `push` cada vez que tenga cambios que subir. + +```bash +$ git push origin master +``` + +### 5.B Si aún no tiene su proyecto en git (o no le importa la historia): + +#### 5.1. Simplemente copie el código de su proyecto en la carpeta correspondiente `src` y haga su primer commit. + +```bash +$ mv src/ +$ git commit -a -m "Hello Git!" +``` + +#### 5.2. A partir de este punto asegúrese de hacer `commit` de forma regular para mantener su repositorio actualizado. + +Si necesita saber más sobre `git`, todo lo imprescindible está en [esta guía](doc/github-git-cheat-sheet.pdf). + +#### 5.3. A partir de este punto puede hacer `push` cada vez que tenga cambios que subir. + +```bash +$ git push origin master +``` + +## Entregas + +En este proyecto se realizarán entregas parciales a lo largo del curso. Para realizar una entrega, siga los siguientes pasos. + +### 1. Cree un pull request al proyecto original desde su copia. + +![](img/img5.png) + +### 2. Asegúrese de tener la siguiente configuración antes de hacer click en **Create pull request**. + +- **base repository**: `matcom/cool-compiler-2021` (repositorio original) + - **branch**: `master` +- **head repository**: `/cool-compiler-2021` (repositorio propio) + - **branch**: `master` (o la que corresponda) + +> Asegúrese que se indica **Able to merge**. De lo contrario, existen cambios en el repositorio original que usted no tiene, y debe actualizarlos. + +> **NOTA**: Asegúrese que el _pull request_ se hace a la rama `master`. + +![](img/img6.png) + +### 3. Introduzca un título y descripción adecuados, y haga click en **Create pull request**. + +![](img/img7.png) + +### 4. Espere mientras se ejecutan las pruebas. + +Verá la indicación **Some checks haven't completed yet**. + +![](img/img8.png) + +Es posible que tenga que actualizar los cambios que se hayan hecho en el repositorio original, por ejemplo, si se han agregado nuevos tests. En este caso obtendrá el siguiente mensaje: + +> **This branch is out-of-date with base branch** + +Haga click en **Update branch** y siga las instrucciones. +### 5. Verifique que no hubo errores en las pruebas. + +Si ve el mensaje **(All | Some) checks have failed**, significa que su código no pasó las pruebas. + +![](img/img9.png) + +Para ver los resultados de las pruebas haga click en el link **Details**. + +![](img/img10.png) + + +### 6. Arregle los errores y repita el paso 5 hasta que todas las pruebas pasen. + +Para cualquier modificación que haga a su proyecto, haga _commit_ y _push_ para **su repositorio personal** y automáticamente se actualizará el estado del _pull request_ y se volverán a ejecutar las pruebas. **No es necesario** abrir un _pull request_ nuevo por cada entrega, sino actualizar el anterior. + +> **Por favor asegúrese de mantener un solo _pull request_ activo por equipo**. En caso de abrir uno nuevo, cerrar el anterior. + +## Sobre la implementación + +Ponga todo su código e instrucciones necesarias en la carpeta `src`. Más información en [`src/Readme.md`](src/Readme.md). + +## Sobre la documentación + +Usted debe presentar un reporte escrito documentando el proceso de construcción de su compilador y los detalles más importantes de su funcionamiento. Más información en [`doc/Readme.md`](doc/Readme.md). + +## Sobre los equipos de desarrollo + +Para desarrollar el compilador del lenguaje COOL se trabajará en equipos de 2 o 3 integrantes. + +## Sobre los casos de prueba + +La carpeta `tests` contiene todos los casos de prueba que son obligatorios de pasar para que su proyecto tenga derecho a ser evaluado. + +Estos tests se ejecutan automáticamente cada vez que hace un _pull request_ al repositorio `matcom/cool-compiler-2021`. Solo aquellos proyectos que pasen todas las pruebas con éxito serán evaluados. + +Para ejecutar las pruebas localmente, debe tener instalado `Python 3.7`, `pip` y `make` (normalmente viene con Linux). Ejecute: + +```bash +$ pip install -r requirements.txt +$ cd src +$ make test +``` diff --git a/doc/Readme.md b/doc/Readme.md index 3b2569f5c..a7ed0e32d 100644 --- a/doc/Readme.md +++ b/doc/Readme.md @@ -1,33 +1,33 @@ -# Documentación - -## Readme - -Modifique el contenido de este documento para documentar de forma clara y concisa los siguientes aspectos: - -- Cómo ejecutar (y compilar si es necesario) su compilador. -- Requisitos adicionales, dependencias, configuración, etc. -- Opciones adicionales que tenga su compilador. - -## Sobre los Equipos de Desarrollo - -Para desarrollar el compilador del lenguaje COOL se trabajará en equipos de 2 o 3 integrantes. El proyecto de Compilación será recogido y evaluado únicamente a través de Github. Es imprescindible tener una cuenta de Github para cada participante, y que su proyecto esté correctamente hosteado en esta plataforma. - -**⚠️ NOTA**: Debe completar el archivo `team.yml` con los datos correctos de cada miembro de su equipo. - -## Sobre los Materiales a Entregar - -Para la evaluación del proyecto Ud. debe entregar un informe en formato PDF (`report.pdf`) en esta carpeta, que resuma de manera organizada y comprensible la arquitectura e implementación de su compilador. -El documento no tiene límite de extensión. -En él explicará en más detalle su solución a los problemas que, durante la implementación de cada una de las fases del proceso de compilación, hayan requerido de Ud. especial atención. - -## Estructura del reporte - -Usted es libre de estructurar su reporte escrito como más conveniente le parezca. A continuación le sugerimos algunas secciones que no deberían faltar, aunque puede mezclar, renombrar y organizarlas de la manera que mejor le parezca: - -- **Uso del compilador**: detalles sobre las opciones de líneas de comando, si tiene opciones adicionales (e.j., `--ast` genera un AST en JSON, etc.). Básicamente lo mismo que pondrá en este Readme. -- **Arquitectura del compilador**: una explicación general de la arquitectura, en cuántos módulos se divide el proyecto, cuantas fases tiene, qué tipo de gramática se utiliza, y en general, como se organiza el proyecto. Una buena imagen siempre ayuda. -- **Problemas técnicos**: detalles sobre cualquier problema teórico o técnico interesante que haya necesitado resolver de forma particular. - -## Sobre la Fecha de Entrega - -Se realizarán recogidas parciales del proyecto a lo largo del curso. En el Canal de Telegram se anunciará la fecha y requisitos de cada entrega. +# Documentación + +## Readme + +Modifique el contenido de este documento para documentar de forma clara y concisa los siguientes aspectos: + +- Cómo ejecutar (y compilar si es necesario) su compilador. +- Requisitos adicionales, dependencias, configuración, etc. +- Opciones adicionales que tenga su compilador. + +## Sobre los Equipos de Desarrollo + +Para desarrollar el compilador del lenguaje COOL se trabajará en equipos de 2 o 3 integrantes. El proyecto de Compilación será recogido y evaluado únicamente a través de Github. Es imprescindible tener una cuenta de Github para cada participante, y que su proyecto esté correctamente hosteado en esta plataforma. + +**⚠️ NOTA**: Debe completar el archivo `team.yml` con los datos correctos de cada miembro de su equipo. + +## Sobre los Materiales a Entregar + +Para la evaluación del proyecto Ud. debe entregar un informe en formato PDF (`report.pdf`) en esta carpeta, que resuma de manera organizada y comprensible la arquitectura e implementación de su compilador. +El documento no tiene límite de extensión. +En él explicará en más detalle su solución a los problemas que, durante la implementación de cada una de las fases del proceso de compilación, hayan requerido de Ud. especial atención. + +## Estructura del reporte + +Usted es libre de estructurar su reporte escrito como más conveniente le parezca. A continuación le sugerimos algunas secciones que no deberían faltar, aunque puede mezclar, renombrar y organizarlas de la manera que mejor le parezca: + +- **Uso del compilador**: detalles sobre las opciones de líneas de comando, si tiene opciones adicionales (e.j., `--ast` genera un AST en JSON, etc.). Básicamente lo mismo que pondrá en este Readme. +- **Arquitectura del compilador**: una explicación general de la arquitectura, en cuántos módulos se divide el proyecto, cuantas fases tiene, qué tipo de gramática se utiliza, y en general, como se organiza el proyecto. Una buena imagen siempre ayuda. +- **Problemas técnicos**: detalles sobre cualquier problema teórico o técnico interesante que haya necesitado resolver de forma particular. + +## Sobre la Fecha de Entrega + +Se realizarán recogidas parciales del proyecto a lo largo del curso. En el Canal de Telegram se anunciará la fecha y requisitos de cada entrega. diff --git a/doc/team.yml b/doc/team.yml index b96f2e877..a42d65e6a 100644 --- a/doc/team.yml +++ b/doc/team.yml @@ -1,8 +1,8 @@ -members: - - name: Olivia Gonzalez Peña - github: livi98 - group: C411 - - name: Juan Carlos Casteleiro Wong - github: cwjki - group: C411 - +members: + - name: Olivia Gonzalez Peña + github: livi98 + group: C411 + - name: Juan Carlos Casteleiro Wong + github: cwjki + group: C411 + diff --git a/requirements.txt b/requirements.txt index 5a914fd88..194b049fa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -pytest -pytest-ordering +pytest +pytest-ordering ply \ No newline at end of file diff --git a/src/Readme.md b/src/Readme.md index 1200371b5..cdca282ec 100644 --- a/src/Readme.md +++ b/src/Readme.md @@ -1,78 +1,78 @@ -# COOL: Proyecto de Compilación - -La evaluación de la asignatura Complementos de Compilación, inscrita en el programa del 4to año de la Licenciatura en Ciencia de la Computación de la Facultad de Matemática y Computación de la -Universidad de La Habana, consiste este curso en la implementación de un compilador completamente -funcional para el lenguaje _COOL_. - -_COOL (Classroom Object-Oriented Language)_ es un pequeño lenguaje que puede ser implementado con un esfuerzo razonable en un semestre del curso. Aun así, _COOL_ mantiene muchas de las características de los lenguajes de programación modernos, incluyendo orientación a objetos, tipado estático y manejo automático de memoria. - -### Sobre el Lenguaje COOL - -Ud. podrá encontrar la especificación formal del lenguaje COOL en el documento _"COOL Language Reference Manual"_, que se distribuye junto con el presente texto. - -## Código Fuente - -### Compilando su proyecto - -Si es necesario compilar su proyecto, incluya todas las instrucciones necesarias en un archivo [`/src/makefile`](/src/makefile). -Durante la evaluación su proyecto se compilará ejecutando la siguiente secuencia: - -```bash -$ cd source -$ make clean -$ make -``` - -### Ejecutando su proyecto - -Incluya en un archivo [`/src/coolc.sh`](/src/coolc.sh) todas las instrucciones que hacen falta para lanzar su compilador. Recibirá como entrada un archivo con extensión `.cl` y debe generar como salida un archivo `.mips` cuyo nombre será el mismo que la entrada. - -Para lanzar el compilador, se ejecutará la siguiente instrucción: - -```bash -$ cd source -$ ./coolc.sh -``` - -### Sobre el Compilador de COOL - -El compilador de COOL se ejecutará como se ha definido anteriormente. -En caso de que no ocurran errores durante la operación del compilador, **coolc.sh** deberá terminar con código de salida 0, generar (o sobrescribir si ya existe) en la misma carpeta del archivo **.cl** procesado, y con el mismo nombre que éste, un archivo con extension **.mips** que pueda ser ejecutado con **spim**. Además, reportar a la salida estándar solamente lo siguiente: - - - - -En caso de que ocurran errores durante la operación del compilador, **coolc.sh** deberá terminar con código -de salida (exit code) 1 y reportar a la salida estándar (standard output stream) lo que sigue... - - - - _1 - ... - _n - -... donde `_i` tiene el siguiente formato: - - (,) - : - -Los campos `` y `` indican la ubicación del error en el fichero **.cl** procesado. En caso -de que la naturaleza del error sea tal que no pueda asociárselo a una línea y columna en el archivo de -código fuente, el valor de dichos campos debe ser 0. - -El campo `` será alguno entre: - -- `CompilerError`: se reporta al detectar alguna anomalía con la entrada del compilador. Por ejemplo, si el fichero a compilar no existe. -- `LexicographicError`: errores detectados por el lexer. -- `SyntacticError`: errores detectados por el parser. -- `NameError`: se reporta al referenciar un `identificador` en un ámbito en el que no es visible. -- `TypeError`: se reporta al detectar un problema de tipos. Incluye: - - incompatibilidad de tipos entre `rvalue` y `lvalue`, - - operación no definida entre objetos de ciertos tipos, y - - tipo referenciado pero no definido. -- `AttributeError`: se reporta cuando un atributo o método se referencia pero no está definido. -- `SemanticError`: cualquier otro error semántico. - -### Sobre la Implementación del Compilador de COOL - -El compilador debe estar implementado en `python`. Usted debe utilizar una herramienta generadora de analizadores -lexicográficos y sintácticos. Puede utilizar la que sea de su preferencia. +# COOL: Proyecto de Compilación + +La evaluación de la asignatura Complementos de Compilación, inscrita en el programa del 4to año de la Licenciatura en Ciencia de la Computación de la Facultad de Matemática y Computación de la +Universidad de La Habana, consiste este curso en la implementación de un compilador completamente +funcional para el lenguaje _COOL_. + +_COOL (Classroom Object-Oriented Language)_ es un pequeño lenguaje que puede ser implementado con un esfuerzo razonable en un semestre del curso. Aun así, _COOL_ mantiene muchas de las características de los lenguajes de programación modernos, incluyendo orientación a objetos, tipado estático y manejo automático de memoria. + +### Sobre el Lenguaje COOL + +Ud. podrá encontrar la especificación formal del lenguaje COOL en el documento _"COOL Language Reference Manual"_, que se distribuye junto con el presente texto. + +## Código Fuente + +### Compilando su proyecto + +Si es necesario compilar su proyecto, incluya todas las instrucciones necesarias en un archivo [`/src/makefile`](/src/makefile). +Durante la evaluación su proyecto se compilará ejecutando la siguiente secuencia: + +```bash +$ cd source +$ make clean +$ make +``` + +### Ejecutando su proyecto + +Incluya en un archivo [`/src/coolc.sh`](/src/coolc.sh) todas las instrucciones que hacen falta para lanzar su compilador. Recibirá como entrada un archivo con extensión `.cl` y debe generar como salida un archivo `.mips` cuyo nombre será el mismo que la entrada. + +Para lanzar el compilador, se ejecutará la siguiente instrucción: + +```bash +$ cd source +$ ./coolc.sh +``` + +### Sobre el Compilador de COOL + +El compilador de COOL se ejecutará como se ha definido anteriormente. +En caso de que no ocurran errores durante la operación del compilador, **coolc.sh** deberá terminar con código de salida 0, generar (o sobrescribir si ya existe) en la misma carpeta del archivo **.cl** procesado, y con el mismo nombre que éste, un archivo con extension **.mips** que pueda ser ejecutado con **spim**. Además, reportar a la salida estándar solamente lo siguiente: + + + + +En caso de que ocurran errores durante la operación del compilador, **coolc.sh** deberá terminar con código +de salida (exit code) 1 y reportar a la salida estándar (standard output stream) lo que sigue... + + + + _1 + ... + _n + +... donde `_i` tiene el siguiente formato: + + (,) - : + +Los campos `` y `` indican la ubicación del error en el fichero **.cl** procesado. En caso +de que la naturaleza del error sea tal que no pueda asociárselo a una línea y columna en el archivo de +código fuente, el valor de dichos campos debe ser 0. + +El campo `` será alguno entre: + +- `CompilerError`: se reporta al detectar alguna anomalía con la entrada del compilador. Por ejemplo, si el fichero a compilar no existe. +- `LexicographicError`: errores detectados por el lexer. +- `SyntacticError`: errores detectados por el parser. +- `NameError`: se reporta al referenciar un `identificador` en un ámbito en el que no es visible. +- `TypeError`: se reporta al detectar un problema de tipos. Incluye: + - incompatibilidad de tipos entre `rvalue` y `lvalue`, + - operación no definida entre objetos de ciertos tipos, y + - tipo referenciado pero no definido. +- `AttributeError`: se reporta cuando un atributo o método se referencia pero no está definido. +- `SemanticError`: cualquier otro error semántico. + +### Sobre la Implementación del Compilador de COOL + +El compilador debe estar implementado en `python`. Usted debe utilizar una herramienta generadora de analizadores +lexicográficos y sintácticos. Puede utilizar la que sea de su preferencia. diff --git a/src/code_generator/BaseCoolToCilVisitor.py b/src/code_generator/BaseCoolToCilVisitor.py index e68aae9b3..2501fbd4b 100644 --- a/src/code_generator/BaseCoolToCilVisitor.py +++ b/src/code_generator/BaseCoolToCilVisitor.py @@ -1,67 +1,67 @@ -import cil_ast as cil -class BaseCOOLToCILVisitor: - def __init__(self, context): - self.dottypes = [] - self.dotdata = [] - self.dotcode = [] - self.current_type = None - self.current_method = None - self.current_function = None - self.context = context - - @property - def params(self): - return self.current_function.params - - @property - def localvars(self): - return self.current_function.localvars - - @property - def instructions(self): - return self.current_function.instructions - - def register_param(self, type, name): - #'param_{self.current_function.name[9:]}_{vinfo.name}_{len(self.params)}' - param_node = cil.ParamNode(type, name) - self.params.append(param_node) - return name - - def register_local(self, name): - #vinfo.name = f'local_{self.current_function.name[9:]}_{vinfo.name}_{len(self.localvars)}' - local_node = cil.LocalNode(name) - self.localvars.append(local_node) - return name - - def define_internal_local(self): - return self.register_local('internal') - - def register_instruction(self, instruction): - self.instructions.append(instruction) - return instruction - ############################### - - def to_function_name(self, method_name, type_name): - return f'function_{method_name}_at_{type_name}' - - def to_attribute_name(self, attr_name, type_name): - return f'function_{attr_name}_at_{type_name}' - - def to_variable_name(self, var_name): - return f'function_{var_name}' - - def register_function(self, function_name): - function_node = cil.FunctionNode(function_name, [], [], []) - self.dotcode.append(function_node) - return function_node - - def register_type(self, name): - type_node = cil.TypeNode(name) - self.dottypes.append(type_node) - return type_node - - def register_data(self, value): - vname = f'data_{len(self.dotdata)}' - data_node = cil.DataNode(vname, value) - self.dotdata.append(data_node) +import cil_ast as cil +class BaseCOOLToCILVisitor: + def __init__(self, context): + self.dottypes = [] + self.dotdata = [] + self.dotcode = [] + self.current_type = None + self.current_method = None + self.current_function = None + self.context = context + + @property + def params(self): + return self.current_function.params + + @property + def localvars(self): + return self.current_function.localvars + + @property + def instructions(self): + return self.current_function.instructions + + def register_param(self, type, name): + #'param_{self.current_function.name[9:]}_{vinfo.name}_{len(self.params)}' + param_node = cil.ParamNode(type, name) + self.params.append(param_node) + return name + + def register_local(self, name): + #vinfo.name = f'local_{self.current_function.name[9:]}_{vinfo.name}_{len(self.localvars)}' + local_node = cil.LocalNode(name) + self.localvars.append(local_node) + return name + + def define_internal_local(self): + return self.register_local('internal') + + def register_instruction(self, instruction): + self.instructions.append(instruction) + return instruction + ############################### + + def to_function_name(self, method_name, type_name): + return f'function_{method_name}_at_{type_name}' + + def to_attribute_name(self, attr_name, type_name): + return f'function_{attr_name}_at_{type_name}' + + def to_variable_name(self, var_name): + return f'function_{var_name}' + + def register_function(self, function_name): + function_node = cil.FunctionNode(function_name, [], [], []) + self.dotcode.append(function_node) + return function_node + + def register_type(self, name): + type_node = cil.TypeNode(name) + self.dottypes.append(type_node) + return type_node + + def register_data(self, value): + vname = f'data_{len(self.dotdata)}' + data_node = cil.DataNode(vname, value) + self.dotdata.append(data_node) return data_node \ No newline at end of file diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index 2e1416a66..68fc61494 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -1,274 +1,274 @@ -import cil_ast as cil -from BaseCOOLToCILVisitor import * -from utils import visitor -from utils.ast import * - -class COOLToCILVisitor(BaseCOOLToCILVisitor): - @visitor.on('node') - def visit(self, node): - pass - - @visitor.when(ProgramNode) - def visit(self, node, scope): - self.current_function = self.register_function('entry') - instance = self.define_internal_local() - result = self.define_internal_local() - self.register_instruction(cil.AllocateNode('Main', instance)) - self.register_instruction(cil.ArgNode(instance)) - - #self.register_instruction(cil.CallNode(self.to_function_name('main', 'Main'), result)) - self.register_instruction(cil.CallNode(result, self.to_function_name('main', 'Main'), [cil.ArgNode(instance)], 'Main')) - - self.register_instruction(cil.ReturnNode(0)) - self.current_function = None - - # self.create_built_in() - - for declaration, child_scope in zip(node.declarations, scope.children): - self.visit(declaration, child_scope) - - return cil.ProgramNode(self.dottypes, self.dotdata, self.dotcode) - - @visitor.when(ClassDeclarationNode) - def visit(self, node, scope): - self.current_type = self.context.get_type(node.id) - - cil_type_node = self.register_type(self.current_type) - cil_type_node.attributes = self.current_type.get_all_attributes() - - if len(cil_type_node.attributes) != 0: - constructor = FuncDeclarationNode(node.token, [], node.token, BlockNode([], node.token)) - func_declarations = [constructor] - self.constructors.append(node.id) - self.current_type.define_method(self.current_type.name, [], [], self.current_type, node.pos) - scopes = [scope] + list(scope.functions.values()) - else: - func_declarations = [] - scopes = list(scope.functions.values()) - - for attr, a_type in cil_type_node.attributes: - cil_type_node.attributes.append((attr.name, self.to_attribute_name(attr.name, a_type.name))) - self.initialize_attr(constructor, attr, scope) - if cil_type_node.attributes: - constructor.body.expr_list.append(SelfNode()) - - for method, mtype in self.current_type.all_methods(): - cil_type_node.methods.append((method.name, self.to_function_name(method.name, mtype.name))) - - func_declarations += [f for f in node.features if isinstance(f, FuncDeclarationNode)] - for feature, child_scope in zip(func_declarations, scopes): - self.visit(feature, child_scope) - - self.current_type = None - - @visitor.when(FuncDeclarationNode) - def visit(self, node, scope): - self.current_method = self.current_type.get_method(node.id) - cil_name = self.to_function_name(node.id, self.current_type.name) - self.current_function = self.register_function(cil_name) - - self.register_param('self', self.current_type.name) - for param_name, param_type in node.params: - self.register_param(param_name, param_type.value) - - ret_value = self.visit(node.body, scope) - if not isinstance(ret_value, str): - result = self.define_internal_local() - self.register_instruction(cil.AssignNode(result, ret_value)) - self.register_instruction(cil.ReturnNode(result)) - else: - self.register_instruction(cil.ReturnNode(ret_value)) - - self.current_method = None - - @visitor.when(AttrDeclarationNode) - def visit(self, node, scope): - if node.expr: - self.visit(node.expr, scope) - self.register_instruction(cil.SetAttrNode(self.vself.name, node.id, scope.ret_expr, self.current_type)) - elif node.type in self.value_types: - local_value = self.define_internal_local() - self.register_instruction(cil.AllocateNode(node.type, local_value)) - self.register_instruction(cil.SetAttrNode(self.vself.name, node.id, local_value, self.current_type)) - - @visitor.when(AssignNode) - def visit(self, node, scope): - var_info = scope.find_local(node.id) - value, typex = self.visit(node.expr, scope) - if var_info is None: - var_info = scope.find_attribute(node.id) - attributes_names = [attr.name for attr, attr_type in self.current_type.get_all_attributes()] - self.register_instruction(cil.SetAttrNode('self', var_info.name, self.current_type.name, value)) - else: - local_name = self.to_variable_name(var_info.name) - self.register_instruction(cil.AssignNode(local_name, value)) - return value, typex - - @visitor.when(FuncCallNode) - def visit(self, node, scope): - obj, otype = self.visit(node.obj, scope) - - meth = otype.get_method(node.id) - args_node = [cil.ArgNode(obj)] + self.handle_arguments(node.args, scope, meth.param_types) - - rtype = meth.return_type - result = None if isinstance(rtype, VoidType) else self.define_internal_local() - - continue_label = cil.LabelNode(f'continue__{self.index}') - isvoid = self.check_void(obj) - self.register_instruction(cil.IfGoToNode(isvoid, continue_label.label)) - self.register_instruction(cil.ErrorNode('dispatch_error')) - self.register_instruction(continue_label) - - #desambiguar segun sea el llamado, dinamico o estatico - # self.register_instruction(cil.StaticCallNode(node.type, node.id, result, args_node, rtype.name)) - # return result, self._return_type(otype, node) - - # self.register_instruction(cil.DynamicCallNode(self.current_type.name, 'self', node.id, result, args_node, rtype.name)) - # return result, self._return_type(self.current_type, node) - - # if otype in [StringType(), IntType(), BoolType()]: - # self.register_instruction(cil.StaticCallNode(otype.name, node.id, result, args_node, rtype.name)) - # else: - # self.register_instruction(cil.DynamicCallNode(otype.name, obj, node.id, result, args_node, rtype.name)) - # return result, self._return_type(otype, node) - - return - - @visitor.when(IfNode) - def visit(self, node, scope): - vcondition = self.define_internal_local() - value = self.visit(node.condition, scope) - - then_label_node = self.register_label('then_label') - else_label_node = self.register_label('else_label') - continue_label_node = self.register_label('continue_label') - - #If condition GOTO then_label - self.visit(node.condition) - self.register_instruction(cil.GetAttrNode(vcondition, scope.ret_expr, 'value', 'Bool')) - self.register_instruction(cil.IfGoToNode(vcondition, then_label_node.label)) - #GOTO else_label - self.register_instruction(cil.GoToNode(else_label_node.label)) - #Label then_label - self.register_instruction(then_label_node) - self.visit(node.then_expr, scope) - self.register_instruction(cil.AssignNode(vcondition, scope.ret_expr)) - self.register_instruction(cil.GoToNode(continue_label_node.label)) - #Label else_label - self.register_instruction(else_label_node) - self.visit(node.else_expr, scope) - self.register_instruction(cil.AssignNode(vcondition, scope.ret_expr)) - - self.register_instruction(continue_label_node) - scope.ret_expr = vcondition - - @visitor.when(WhileNode) - def visit(self, node, scope): - start_label = cil.LabelNode(f'start__{self.idx}') - end_label = cil.LabelNode(f'end__{self.idx}') - - result = self.define_internal_local() - self.register_instruction(cil.VoidConstantNode(result)) - self.register_instruction(start_label) - - cond, _ = self.visit(node.cond, scope) - self.register_instruction(cil.IfGoToNode(cond, end_label.label)) - expr, typex = self.visit(node.expr, scope) - self.register_instruction(cil.AssignNode(result, expr)) - self.register_instruction(cil.GoToNode(start_label.label)) - self.register_instruction(end_label) - - @visitor.when(BlockNode) - def visit(self, node, scope): - for expr in node.exprs: - value, typex = self.visit(expr, scope) - result = self.define_internal_local() - self.register_instruction(cil.AssignNode(result, value)) - return result, typex - - visitor.when(LetNode) - def visit(self, node, scope): - child_scope = scope.expr_dict[node] - for init in node.let_attrs: - self.visit(init, child_scope) - - expr, typex = self.visit(node.expr, child_scope) - return expr, typex - - visitor.when(CaseNode) - def visit(self, node, scope): - expr, typex = self.visit(node.expr, scope) - - result = self.define_internal_local() - end_label = cil.LabelNode(f'end__{self.idx}') - error_label = cil.LabelNode(f'error__{self.idx}') - - isvoid = self.check_void(expr) - self.register_instruction(cil.IfGoToNode(isvoid, error_label.label)) - try: - new_scope = scope.expr_dict[node] - except: - new_scope = scope - sorted_case_list = self.sort_option_nodes_by_type(node.case_list) - for i, case in enumerate(sorted_case_list): - next_label = cil.LabelNode(f'next__{self.idx}_{i}') - expr_i = self.visit(case, new_scope.create_child(), expr, next_label, typex) - self.register_instruction(cil.AssignNode(result, expr_i)) - self.register_instruction(cil.GoToNode(end_label.label)) - self.register_instruction(next_label) - self.register_instruction(end_label) - return result, typex - - visitor.when(VarNode) - def visit(self, node, scope): - try: - typex = scope.find_local(node.lex).type - name = self.to_var_name(node.lex) - return name, get_type(typex, self.current_type) - except: - var_info = scope.find_attribute(node.lex) - local_var = self.register_local(var_info.name) - self.register_instruction(cil.GetAttrNode('self', var_info.name, self.current_type.name, local_var, var_info.type.name)) - return local_var, get_type(var_info.type, self.current_type) - - visitor.when(NewNode) - def visit(self, node, scope): - instance = self.define_internal_local() - typex = self.context.get_type(node.lex) - typex = get_type(typex, self.current_type) - self.register_instruction(cil.AllocateNode(typex.name, instance)) - - if typex.get_all_attributes(): - self.register_instruction(cil.CallNode(typex.name, typex.name, instance, [cil.ArgNode(instance)], typex.name)) - - return instance, typex - - @visitor.when(PlusNode) - def visit(self, node, scope): - return self._define_binary_node(node, scope, cil.PlusNode) - - @visitor.when(MinusNode) - def visit(self, node, scope): - return self._define_binary_node(node, scope, cil.MinusNode) - - @visitor.when(StarNode) - def visit(self, node, scope): - return self._define_binary_node(node, scope, cil.StarNode) - - @visitor.when(DivNode) - def visit(self, node, scope): - return self._define_binary_node(node, scope, cil.DivNode) - - @visitor.when(LessNode) - def visit(self, node, scope): - return self._define_binary_node(node, scope, cil.LessNode) - - @visitor.when(LessEqNode) - def visit(self, node, scope): - return self._define_binary_node(node, scope, cil.LessEqualNode) - - @visitor.when(EqualNode) - def visit(self, node, scope): - return self._define_binary_node(node, scope, cil.EqualNode) - +import cil_ast as cil +from BaseCOOLToCILVisitor import * +from utils import visitor +from utils.ast import * + +class COOLToCILVisitor(BaseCOOLToCILVisitor): + @visitor.on('node') + def visit(self, node): + pass + + @visitor.when(ProgramNode) + def visit(self, node, scope): + self.current_function = self.register_function('entry') + instance = self.define_internal_local() + result = self.define_internal_local() + self.register_instruction(cil.AllocateNode('Main', instance)) + self.register_instruction(cil.ArgNode(instance)) + + #self.register_instruction(cil.CallNode(self.to_function_name('main', 'Main'), result)) + self.register_instruction(cil.CallNode(result, self.to_function_name('main', 'Main'), [cil.ArgNode(instance)], 'Main')) + + self.register_instruction(cil.ReturnNode(0)) + self.current_function = None + + # self.create_built_in() + + for declaration, child_scope in zip(node.declarations, scope.children): + self.visit(declaration, child_scope) + + return cil.ProgramNode(self.dottypes, self.dotdata, self.dotcode) + + @visitor.when(ClassDeclarationNode) + def visit(self, node, scope): + self.current_type = self.context.get_type(node.id) + + cil_type_node = self.register_type(self.current_type) + cil_type_node.attributes = self.current_type.get_all_attributes() + + if len(cil_type_node.attributes) != 0: + constructor = FuncDeclarationNode(node.token, [], node.token, BlockNode([], node.token)) + func_declarations = [constructor] + self.constructors.append(node.id) + self.current_type.define_method(self.current_type.name, [], [], self.current_type, node.pos) + scopes = [scope] + list(scope.functions.values()) + else: + func_declarations = [] + scopes = list(scope.functions.values()) + + for attr, a_type in cil_type_node.attributes: + cil_type_node.attributes.append((attr.name, self.to_attribute_name(attr.name, a_type.name))) + self.initialize_attr(constructor, attr, scope) + if cil_type_node.attributes: + constructor.body.expr_list.append(SelfNode()) + + for method, mtype in self.current_type.all_methods(): + cil_type_node.methods.append((method.name, self.to_function_name(method.name, mtype.name))) + + func_declarations += [f for f in node.features if isinstance(f, FuncDeclarationNode)] + for feature, child_scope in zip(func_declarations, scopes): + self.visit(feature, child_scope) + + self.current_type = None + + @visitor.when(FuncDeclarationNode) + def visit(self, node, scope): + self.current_method = self.current_type.get_method(node.id) + cil_name = self.to_function_name(node.id, self.current_type.name) + self.current_function = self.register_function(cil_name) + + self.register_param('self', self.current_type.name) + for param_name, param_type in node.params: + self.register_param(param_name, param_type.value) + + ret_value = self.visit(node.body, scope) + if not isinstance(ret_value, str): + result = self.define_internal_local() + self.register_instruction(cil.AssignNode(result, ret_value)) + self.register_instruction(cil.ReturnNode(result)) + else: + self.register_instruction(cil.ReturnNode(ret_value)) + + self.current_method = None + + @visitor.when(AttrDeclarationNode) + def visit(self, node, scope): + if node.expr: + self.visit(node.expr, scope) + self.register_instruction(cil.SetAttrNode(self.vself.name, node.id, scope.ret_expr, self.current_type)) + elif node.type in self.value_types: + local_value = self.define_internal_local() + self.register_instruction(cil.AllocateNode(node.type, local_value)) + self.register_instruction(cil.SetAttrNode(self.vself.name, node.id, local_value, self.current_type)) + + @visitor.when(AssignNode) + def visit(self, node, scope): + var_info = scope.find_local(node.id) + value, typex = self.visit(node.expr, scope) + if var_info is None: + var_info = scope.find_attribute(node.id) + attributes_names = [attr.name for attr, attr_type in self.current_type.get_all_attributes()] + self.register_instruction(cil.SetAttrNode('self', var_info.name, self.current_type.name, value)) + else: + local_name = self.to_variable_name(var_info.name) + self.register_instruction(cil.AssignNode(local_name, value)) + return value, typex + + @visitor.when(FuncCallNode) + def visit(self, node, scope): + obj, otype = self.visit(node.obj, scope) + + meth = otype.get_method(node.id) + args_node = [cil.ArgNode(obj)] + self.handle_arguments(node.args, scope, meth.param_types) + + rtype = meth.return_type + result = None if isinstance(rtype, VoidType) else self.define_internal_local() + + continue_label = cil.LabelNode(f'continue__{self.index}') + isvoid = self.check_void(obj) + self.register_instruction(cil.IfGoToNode(isvoid, continue_label.label)) + self.register_instruction(cil.ErrorNode('dispatch_error')) + self.register_instruction(continue_label) + + #desambiguar segun sea el llamado, dinamico o estatico + # self.register_instruction(cil.StaticCallNode(node.type, node.id, result, args_node, rtype.name)) + # return result, self._return_type(otype, node) + + # self.register_instruction(cil.DynamicCallNode(self.current_type.name, 'self', node.id, result, args_node, rtype.name)) + # return result, self._return_type(self.current_type, node) + + # if otype in [StringType(), IntType(), BoolType()]: + # self.register_instruction(cil.StaticCallNode(otype.name, node.id, result, args_node, rtype.name)) + # else: + # self.register_instruction(cil.DynamicCallNode(otype.name, obj, node.id, result, args_node, rtype.name)) + # return result, self._return_type(otype, node) + + return + + @visitor.when(IfNode) + def visit(self, node, scope): + vcondition = self.define_internal_local() + value = self.visit(node.condition, scope) + + then_label_node = self.register_label('then_label') + else_label_node = self.register_label('else_label') + continue_label_node = self.register_label('continue_label') + + #If condition GOTO then_label + self.visit(node.condition) + self.register_instruction(cil.GetAttrNode(vcondition, scope.ret_expr, 'value', 'Bool')) + self.register_instruction(cil.IfGoToNode(vcondition, then_label_node.label)) + #GOTO else_label + self.register_instruction(cil.GoToNode(else_label_node.label)) + #Label then_label + self.register_instruction(then_label_node) + self.visit(node.then_expr, scope) + self.register_instruction(cil.AssignNode(vcondition, scope.ret_expr)) + self.register_instruction(cil.GoToNode(continue_label_node.label)) + #Label else_label + self.register_instruction(else_label_node) + self.visit(node.else_expr, scope) + self.register_instruction(cil.AssignNode(vcondition, scope.ret_expr)) + + self.register_instruction(continue_label_node) + scope.ret_expr = vcondition + + @visitor.when(WhileNode) + def visit(self, node, scope): + start_label = cil.LabelNode(f'start__{self.idx}') + end_label = cil.LabelNode(f'end__{self.idx}') + + result = self.define_internal_local() + self.register_instruction(cil.VoidConstantNode(result)) + self.register_instruction(start_label) + + cond, _ = self.visit(node.cond, scope) + self.register_instruction(cil.IfGoToNode(cond, end_label.label)) + expr, typex = self.visit(node.expr, scope) + self.register_instruction(cil.AssignNode(result, expr)) + self.register_instruction(cil.GoToNode(start_label.label)) + self.register_instruction(end_label) + + @visitor.when(BlockNode) + def visit(self, node, scope): + for expr in node.exprs: + value, typex = self.visit(expr, scope) + result = self.define_internal_local() + self.register_instruction(cil.AssignNode(result, value)) + return result, typex + + visitor.when(LetNode) + def visit(self, node, scope): + child_scope = scope.expr_dict[node] + for init in node.let_attrs: + self.visit(init, child_scope) + + expr, typex = self.visit(node.expr, child_scope) + return expr, typex + + visitor.when(CaseNode) + def visit(self, node, scope): + expr, typex = self.visit(node.expr, scope) + + result = self.define_internal_local() + end_label = cil.LabelNode(f'end__{self.idx}') + error_label = cil.LabelNode(f'error__{self.idx}') + + isvoid = self.check_void(expr) + self.register_instruction(cil.IfGoToNode(isvoid, error_label.label)) + try: + new_scope = scope.expr_dict[node] + except: + new_scope = scope + sorted_case_list = self.sort_option_nodes_by_type(node.case_list) + for i, case in enumerate(sorted_case_list): + next_label = cil.LabelNode(f'next__{self.idx}_{i}') + expr_i = self.visit(case, new_scope.create_child(), expr, next_label, typex) + self.register_instruction(cil.AssignNode(result, expr_i)) + self.register_instruction(cil.GoToNode(end_label.label)) + self.register_instruction(next_label) + self.register_instruction(end_label) + return result, typex + + visitor.when(VarNode) + def visit(self, node, scope): + try: + typex = scope.find_local(node.lex).type + name = self.to_var_name(node.lex) + return name, get_type(typex, self.current_type) + except: + var_info = scope.find_attribute(node.lex) + local_var = self.register_local(var_info.name) + self.register_instruction(cil.GetAttrNode('self', var_info.name, self.current_type.name, local_var, var_info.type.name)) + return local_var, get_type(var_info.type, self.current_type) + + visitor.when(NewNode) + def visit(self, node, scope): + instance = self.define_internal_local() + typex = self.context.get_type(node.lex) + typex = get_type(typex, self.current_type) + self.register_instruction(cil.AllocateNode(typex.name, instance)) + + if typex.get_all_attributes(): + self.register_instruction(cil.CallNode(typex.name, typex.name, instance, [cil.ArgNode(instance)], typex.name)) + + return instance, typex + + @visitor.when(PlusNode) + def visit(self, node, scope): + return self._define_binary_node(node, scope, cil.PlusNode) + + @visitor.when(MinusNode) + def visit(self, node, scope): + return self._define_binary_node(node, scope, cil.MinusNode) + + @visitor.when(StarNode) + def visit(self, node, scope): + return self._define_binary_node(node, scope, cil.StarNode) + + @visitor.when(DivNode) + def visit(self, node, scope): + return self._define_binary_node(node, scope, cil.DivNode) + + @visitor.when(LessNode) + def visit(self, node, scope): + return self._define_binary_node(node, scope, cil.LessNode) + + @visitor.when(LessEqNode) + def visit(self, node, scope): + return self._define_binary_node(node, scope, cil.LessEqualNode) + + @visitor.when(EqualNode) + def visit(self, node, scope): + return self._define_binary_node(node, scope, cil.EqualNode) + diff --git a/src/code_generator/cil_ast.py b/src/code_generator/cil_ast.py index 1b93b545a..25fa5ac3c 100644 --- a/src/code_generator/cil_ast.py +++ b/src/code_generator/cil_ast.py @@ -1,205 +1,205 @@ -class Node: - pass - -class ProgramNode(Node): - def __init__(self, dottypes, dotdata, dotcode): - self.dottypes = dottypes - self.dotdata = dotdata - self.dotcode = dotcode - -#.TYPE -class TypeNode(Node): - def __init__(self, name): - self.name = name - self.attributes = [] - self.methods = [] - -#.DATA -class DataNode(Node): - def __init__(self, vname, value): - self.name = vname - self.value = value - -#.CODE -class FunctionNode(Node): - def __init__(self, name, params=[], localvars=[], instructions =[]): - self.name = name - self.params = params - self.localvars = localvars - self.instructions = instructions - -class InstructionNode(Node): - def __init__(self): - pass - -class ParamNode(InstructionNode): - def __init__(self, type, name): - self.type = type - self.name = name - -class LocalNode(InstructionNode): - def __init__(self, name): - self.name = name - -class AssignNode(InstructionNode): - def __init__(self, dest, source): - self.dest = dest - self.source = source - -class ArithExpressionNode(InstructionNode): - def __init__(self, dest, left, right): - self.dest = dest - self.left = left - self.right = right - -#Arith -class PlusNode(ArithExpressionNode): - pass - -class MinusNode(ArithExpressionNode): - pass - -class StarNode(ArithExpressionNode): - pass - -class DivNode(ArithExpressionNode): - pass - -class LessNode(ArithExpressionNode): - pass - -class LessEqualNode(ArithExpressionNode): - pass - -class EqualNode(ArithExpressionNode): - pass - -#Attr -class GetAttrNode(InstructionNode): - def __init__(self, dest, instance, attr, static_type): - self.local_dest = dest - self.instance = instance - self.attr = attr - self.static_type = static_type - -class SetAttrNode(InstructionNode): - def __init__(self, instance, attr, value, static_type): - self.instance = instance - self.attr = attr - self.value = value - self.static_type = static_type - - -#Arrays and Strings -class GetIndexNode(InstructionNode): - pass -class SetIndexNode(InstructionNode): - pass - -#Memory -class AllocateNode(InstructionNode): - def __init__(self, t, dest): - self.type = t - self.local_dest = dest - -class ArrayNode(InstructionNode): - pass - -class TypeOfNode(InstructionNode): - def __init__(self, obj, dest): - self.obj = obj - self.local_dest = dest - -#Jumps -class LabelNode(InstructionNode): - def __init__(self, label): - self.label = label - -class GoToNode(InstructionNode): - def __init__(self, label): - self.label = label - -class IfGoToNode(InstructionNode): - def __init__(self, condition, label): - self.condition = condition - self.label = label - -#Static Invocation -class CallNode(InstructionNode): - def __init__(self, dest, func, args, static_type, ret_type): - self.local_dest = dest - self.function = func - self.args = args - self.static_type = static_type - self.ret_type = ret_type - -#Dynamic Invocation -class VCallNode(InstructionNode): - def __init__(self, instance, dest, func, args, dynamic_type, ret_type): - self.instance = instance - self.local_dest = dest - self.function = func - self.args = args - self.dynamic_type = dynamic_type - self.ret_type = ret_type - - -#Args -class ArgNode(InstructionNode): - def __init__(self, name): - self.name = name - - -#Return -class ReturnNode(InstructionNode): - def __init__(self, value): - self.value = value - -#IO -class LoadNode(InstructionNode): - def __init__(self, dest, msg): - self.local_dest = dest - self.msg = msg - -class LengthNode(InstructionNode): - def __init__(self, dest, arg): - self.local_dest = dest - self.arg = arg - -class ConcatNode(InstructionNode): - def __init__(self, dest, head, tail): - self.local_dest = dest - self.head = head - self.tail = tail - -class PrefixNode(InstructionNode): - def __init__(self, dest, string, n): - self.local_dest = dest - self.string = string - self.n = n - -class SubstringNode(InstructionNode): - def __init__(self, dest, string, begin, final): - self.local_dest = dest - self.begin = begin - self.string = string - self.final = final - -class StrNode(InstructionNode): - def __init__(self, dest, value): - self.local_dest = dest - self.value = value - -class ToStrNode(InstructionNode): - def __init__(self, dest, ivalue): - self.dest = dest - self.ivalue = ivalue - -class ReadNode(InstructionNode): - def __init__(self, dest): - self.local_dest = dest - -class PrintNode(InstructionNode): - def __init__(self, value): - self.value = value - +class Node: + pass + +class ProgramNode(Node): + def __init__(self, dottypes, dotdata, dotcode): + self.dottypes = dottypes + self.dotdata = dotdata + self.dotcode = dotcode + +#.TYPE +class TypeNode(Node): + def __init__(self, name): + self.name = name + self.attributes = [] + self.methods = [] + +#.DATA +class DataNode(Node): + def __init__(self, vname, value): + self.name = vname + self.value = value + +#.CODE +class FunctionNode(Node): + def __init__(self, name, params=[], localvars=[], instructions =[]): + self.name = name + self.params = params + self.localvars = localvars + self.instructions = instructions + +class InstructionNode(Node): + def __init__(self): + pass + +class ParamNode(InstructionNode): + def __init__(self, type, name): + self.type = type + self.name = name + +class LocalNode(InstructionNode): + def __init__(self, name): + self.name = name + +class AssignNode(InstructionNode): + def __init__(self, dest, source): + self.dest = dest + self.source = source + +class ArithExpressionNode(InstructionNode): + def __init__(self, dest, left, right): + self.dest = dest + self.left = left + self.right = right + +#Arith +class PlusNode(ArithExpressionNode): + pass + +class MinusNode(ArithExpressionNode): + pass + +class StarNode(ArithExpressionNode): + pass + +class DivNode(ArithExpressionNode): + pass + +class LessNode(ArithExpressionNode): + pass + +class LessEqualNode(ArithExpressionNode): + pass + +class EqualNode(ArithExpressionNode): + pass + +#Attr +class GetAttrNode(InstructionNode): + def __init__(self, dest, instance, attr, static_type): + self.local_dest = dest + self.instance = instance + self.attr = attr + self.static_type = static_type + +class SetAttrNode(InstructionNode): + def __init__(self, instance, attr, value, static_type): + self.instance = instance + self.attr = attr + self.value = value + self.static_type = static_type + + +#Arrays and Strings +class GetIndexNode(InstructionNode): + pass +class SetIndexNode(InstructionNode): + pass + +#Memory +class AllocateNode(InstructionNode): + def __init__(self, t, dest): + self.type = t + self.local_dest = dest + +class ArrayNode(InstructionNode): + pass + +class TypeOfNode(InstructionNode): + def __init__(self, obj, dest): + self.obj = obj + self.local_dest = dest + +#Jumps +class LabelNode(InstructionNode): + def __init__(self, label): + self.label = label + +class GoToNode(InstructionNode): + def __init__(self, label): + self.label = label + +class IfGoToNode(InstructionNode): + def __init__(self, condition, label): + self.condition = condition + self.label = label + +#Static Invocation +class CallNode(InstructionNode): + def __init__(self, dest, func, args, static_type, ret_type): + self.local_dest = dest + self.function = func + self.args = args + self.static_type = static_type + self.ret_type = ret_type + +#Dynamic Invocation +class VCallNode(InstructionNode): + def __init__(self, instance, dest, func, args, dynamic_type, ret_type): + self.instance = instance + self.local_dest = dest + self.function = func + self.args = args + self.dynamic_type = dynamic_type + self.ret_type = ret_type + + +#Args +class ArgNode(InstructionNode): + def __init__(self, name): + self.name = name + + +#Return +class ReturnNode(InstructionNode): + def __init__(self, value): + self.value = value + +#IO +class LoadNode(InstructionNode): + def __init__(self, dest, msg): + self.local_dest = dest + self.msg = msg + +class LengthNode(InstructionNode): + def __init__(self, dest, arg): + self.local_dest = dest + self.arg = arg + +class ConcatNode(InstructionNode): + def __init__(self, dest, head, tail): + self.local_dest = dest + self.head = head + self.tail = tail + +class PrefixNode(InstructionNode): + def __init__(self, dest, string, n): + self.local_dest = dest + self.string = string + self.n = n + +class SubstringNode(InstructionNode): + def __init__(self, dest, string, begin, final): + self.local_dest = dest + self.begin = begin + self.string = string + self.final = final + +class StrNode(InstructionNode): + def __init__(self, dest, value): + self.local_dest = dest + self.value = value + +class ToStrNode(InstructionNode): + def __init__(self, dest, ivalue): + self.dest = dest + self.ivalue = ivalue + +class ReadNode(InstructionNode): + def __init__(self, dest): + self.local_dest = dest + +class PrintNode(InstructionNode): + def __init__(self, value): + self.value = value + diff --git a/src/coolc.sh b/src/coolc.sh index 1521cd252..861584cad 100755 --- a/src/coolc.sh +++ b/src/coolc.sh @@ -1,16 +1,16 @@ -# Incluya aquí las instrucciones necesarias para ejecutar su compilador - -INPUT_FILE=$1 -OUTPUT_FILE=${INPUT_FILE:0: -2}mips - -# Si su compilador no lo hace ya, aquí puede imprimir la información de contacto -echo "LINEA_CON_NOMBRE_Y_VERSION_DEL_COMPILADOR" # TODO: Recuerde cambiar estas -echo "Copyright (c) 2021: Juan Carlos Casteleiro Wong, Olivia González Peña" # TODO: líneas a los valores correctos - -FILE="main.py" - -# Llamar al compilador -python ${FILE} $INPUT_FILE $OUTPUT_FILE - -# Llamar al compilador -# echo "Compiling $INPUT_FILE into $OUTPUT_FILE" +# Incluya aquí las instrucciones necesarias para ejecutar su compilador + +INPUT_FILE=$1 +OUTPUT_FILE=${INPUT_FILE:0: -2}mips + +# Si su compilador no lo hace ya, aquí puede imprimir la información de contacto +echo "LINEA_CON_NOMBRE_Y_VERSION_DEL_COMPILADOR" # TODO: Recuerde cambiar estas +echo "Copyright (c) 2021: Juan Carlos Casteleiro Wong, Olivia González Peña" # TODO: líneas a los valores correctos + +FILE="main.py" + +# Llamar al compilador +python ${FILE} $INPUT_FILE $OUTPUT_FILE + +# Llamar al compilador +# echo "Compiling $INPUT_FILE into $OUTPUT_FILE" diff --git a/src/cparser/parser.py b/src/cparser/parser.py index 4c7966abf..279504589 100644 --- a/src/cparser/parser.py +++ b/src/cparser/parser.py @@ -1,268 +1,268 @@ -from ply import yacc -from utils.ast import * -from utils.errors import SyntacticError -from utils.utils import find_column, tokens - - -class CoolParser: - def __init__(self, lexer): - self.lexer = lexer - self.tokens = tokens - self.parser = yacc.yacc(start='program', module=self) - self.errors = [] - - procedence = ( - ('left, AT'), - ('left, NOT'), - ('left, ISVOID'), - ('left, EQUAL, LESS, LESSEQ'), - ('left, PLUS, MINUS'), - ('left, STAR, DIV'), - ('left, DOT') - ) - - def parse(self, program): - return self.parser.parse(program, self.lexer.lexer) - - def p_program(self, p): - 'program : class_list' - p[0] = ProgramNode(p[1]) - - def p_epsilon(self, p): - 'epsilon :' - - def p_class_list(self, p): - '''class_list : def_class SEMICOLON class_list - | def_class SEMICOLON ''' - p[0] = [p[1]] if len(p) == 3 else [p[1]] + p[3] - - def p_def_class(self, p): - '''def_class : CLASS TYPE LPAREN feature_list RPAREN - | CLASS TYPE INHERITS TYPE LPAREN feature_list RPAREN''' - if len(p) == 8: - p[0] = ClassDeclarationNode(p[2], p[6], p[4]) - else: - p[0] = ClassDeclarationNode(p[2], p[4]) - - p[0].add_line_column(p.lineno(2), find_column( - p.lexer.lexdata, p.lexpos(2))) - - def p_feature_list(self, p): - '''feature_list : def_attr SEMICOLON feature_list - | def_func SEMICOLON feature_list - | epsilon''' - p[0] = [p[1]] + p[3] if len(p) == 4 else [] - - def p_def_attr(self, p): - '''def_attr : ID COLON TYPE - | ID COLON TYPE ASSIGN expr''' - if len(p) == 4: - p[0] = AttrDeclarationNode(p[1], p[3]) - else: - p[0] = AttrDeclarationNode(p[1], p[3], p[5]) - - p[0].add_line_column(p.lineno(3), find_column( - p.lexer.lexdata, p.lexpos(3))) - - def p_def_func(self, p): - '''def_func : ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACE''' - p[0] = FuncDeclarationNode(p[1], p[3], p[6], p[8]) - p[0].add_line_column(p.lineno(6), find_column( - p.lexer.lexdata, p.lexpos(6))) - - def p_params(self, p): - '''params : param_list - | param_list_empty''' - p[0] = p[1] - - def p_param_list(self, p): - '''param_list : param - | param COMMA param_list''' - p[0] = [p[1]] if len(p) == 2 else [p[1]] + p[3] - - def p_param_list_empty(self, p): - '''param_list_empty : epsilon''' - p[0] = [] - - def p_param(self, p): - '''param : ID COLON TYPE''' - p[0] = (p[1], p[3]) - - def p_expr_flow(self, p): - '''expr : LET let_attrs IN expr - | CASE expr OF case_list ESAC - | IF expr THEN expr ELSE expr FI - | WHILE expr LOOP expr POOL''' - - if p[1].lower() == 'let': - p[0] = LetNode(p[2], p[4]) - elif p[1].lower() == 'case': - p[0] = CaseNode(p[2], p[4]) - elif p[1].lower() == 'if': - p[0] = IfNode(p[2], p[4], p[6]) - elif p[1].lower() == 'while': - p[0] = WhileNode(p[2], p[4]) - - p[0].add_line_column(p.lineno(2), find_column( - p.lexer.lexdata, p.lexpos(2))) - - def p_expr_assign(self, p): - '''expr : ID ASSIGN expr''' - p[0] = AssignNode(p[1], p[3]) - p[0].add_line_column(p.lineno(1), find_column( - p.lexer.lexdata, p.lexpos(1))) - - def p_expr_func_call(self, p): - '''expr : expr AT TYPE DOT ID LPAREN args RPAREN - | expr DOT ID LPAREN args RPAREN - | ID LPAREN args RPAREN''' - if len(p) == 9: - if p[7] is None: - p[7] = [] - p[0] = FuncCallNode(p[5], p[7], p[1], p[3]) - p[0].add_line_column(p.lineno(5), find_column( - p.lexer.lexdata, p.lexpos(5))) - elif len(p) == 7: - if p[5] is None: - p[5] = [] - p[0] = FuncCallNode(p[3], p[5], p[1]) - p[0].add_line_column(p.lineno(3), find_column( - p.lexer.lexdata, p.lexpos(3))) - else: - if p[3] is None: - p[3] = [] - p[0] = FuncCallNode(p[1], p[3]) - p[0].add_line_column(p.lineno(1), find_column( - p.lexer.lexdata, p.lexpos(1))) - - p[0].lineno = p.lineno(0) - - def p_expr_operators_binary(self, p): - '''expr : expr PLUS expr - | expr MINUS expr - | expr STAR expr - | expr DIV expr - | expr LESS expr - | expr LESSEQ expr - | expr EQUAL expr''' - if p[2] == '+': - p[0] = PlusNode(p[1], p[3]) - elif p[2] == '-': - p[0] = MinusNode(p[1], p[3]) - elif p[2] == '*': - p[0] = StarNode(p[1], p[3]) - elif p[2] == '/': - p[0] = DivNode(p[1], p[3]) - elif p[2] == '<': - p[0] = LessNode(p[1], p[3]) - elif p[2] == '<=': - p[0] = LessEqNode(p[1], p[3]) - elif p[2] == '<=': - p[0] = EqualNode(p[1], p[3]) - - p[0].add_line_column(p.lineno(0), find_column( - p.lexer.lexdata, p.lexpos(0))) - - def p_expr_operators_unary(self, p): - '''expr : NOT expr - | ISVOID expr - | LNOT expr''' - if p[1] == '~': - p[0] = NegationNode(p[2]) - elif p[1].lower() == 'isvoid': - p[0] = IsVoidNode(p[2]) - elif p[1].lower() == 'not': - p[0] = LogicNegationNode(p[2]) - - p[0].add_line_column(p.lineno(2), find_column( - p.lexer.lexdata, p.lexpos(2))) - - def p_expr_group(self, p): - '''expr : LPAREN expr RPAREN''' - p[0] = p[2] - - def p_expr_atom(self, p): - '''expr : atom''' - p[0] = p[1] - - def p_let_attrs(self, p): - '''let_attrs : def_attr - | def_attr COMMA let_attrs''' - p[0] = [p[1]] if len(p) == 2 else [p[1]] + p[3] - - def p_case_list(self, p): - '''case_list : case_option SEMICOLON - | case_option SEMICOLON case_list''' - p[0] = [p[1]] if len(p) == 3 else [p[1]] + p[3] - - def p_case_option(self, p): - '''case_option : ID COLON TYPE ARROW expr''' - p[0] = CaseOptionNode(p[1], p[3], p[5]) - p[0].add_line_column(p.lineno(3), find_column( - p.lexer.lexdata, p.lexpos(3))) - - def p_args(self, p): - '''args : arg_list - | arg_list_empty''' - p[0] = p[1] - - def p_arg_list(self, p): - '''arg_list : expr - | expr COMMA arg_list''' - p[0] = [p[1]] if len(p) == 2 else [p[1]] + p[3] - - def p_arg_list_empty(self, p): - '''arg_list_empty : epsilon''' - p[0] = [] - - def p_atom_int(self, p): - '''atom : INT''' - p[0] = IntNode(int(p[1])) - p[0].add_line_column(p.lineno(1), find_column( - p.lexer.lexdata, p.lexpos(1))) - - def p_atom_id(self, p): - '''atom : ID''' - p[0] = VarNode(p[1]) - p[0].add_line_column(p.lineno(1), find_column( - p.lexer.lexdata, p.lexpos(1))) - - def p_atom_bool(self, p): - '''atom : BOOL''' - p[0] = BoolNode(p[1]) - p[0].add_line_column(p.lineno(1), find_column( - p.lexer.lexdata, p.lexpos(1))) - - def p_atom_string(self, p): - '''atom : STRING''' - p[0] = StringNode(p[1]) - p[0].add_line_column(p.lineno(1), find_column( - p.lexer.lexdata, p.lexpos(1))) - - def p_atom_new(self, p): - '''atom : NEW TYPE''' - p[0] = NewNode(p[2]) - p[0].add_line_column(p.lineno(2), find_column( - p.lexer.lexdata, p.lexpos(2))) - - def p_atom_block(self, p): - '''atom : block''' - p[0] = p[1] - - def p_block(self, p): - '''block : LBRACE block_list RBRACE''' - p[0] = p[2] - - def p_block_list(self, p): - ''' block_list : expr SEMICOLON - | expr SEMICOLON block_list''' - p[0] = BlockNode([p[1]]) if len( - p) == 3 else BlockNode([p[1]] + p[3].exprs) - - def p_error(self, p): - if p: - self.lexer.add_line_column(p) - self.errors.append(SyntacticError( - f'ERROR at or near {p.value}', p.line, p.column)) - else: - self.errors.append(SyntacticError('ERROR at or near EOF', 0, 0)) +from ply import yacc +from utils.ast import * +from utils.errors import SyntacticError +from utils.utils import find_column, tokens + + +class CoolParser: + def __init__(self, lexer): + self.lexer = lexer + self.tokens = tokens + self.parser = yacc.yacc(start='program', module=self) + self.errors = [] + + procedence = ( + ('left, AT'), + ('left, NOT'), + ('left, ISVOID'), + ('left, EQUAL, LESS, LESSEQ'), + ('left, PLUS, MINUS'), + ('left, STAR, DIV'), + ('left, DOT') + ) + + def parse(self, program): + return self.parser.parse(program, self.lexer.lexer) + + def p_program(self, p): + 'program : class_list' + p[0] = ProgramNode(p[1]) + + def p_epsilon(self, p): + 'epsilon :' + + def p_class_list(self, p): + '''class_list : def_class SEMICOLON class_list + | def_class SEMICOLON ''' + p[0] = [p[1]] if len(p) == 3 else [p[1]] + p[3] + + def p_def_class(self, p): + '''def_class : CLASS TYPE LPAREN feature_list RPAREN + | CLASS TYPE INHERITS TYPE LPAREN feature_list RPAREN''' + if len(p) == 8: + p[0] = ClassDeclarationNode(p[2], p[6], p[4]) + else: + p[0] = ClassDeclarationNode(p[2], p[4]) + + p[0].add_line_column(p.lineno(2), find_column( + p.lexer.lexdata, p.lexpos(2))) + + def p_feature_list(self, p): + '''feature_list : def_attr SEMICOLON feature_list + | def_func SEMICOLON feature_list + | epsilon''' + p[0] = [p[1]] + p[3] if len(p) == 4 else [] + + def p_def_attr(self, p): + '''def_attr : ID COLON TYPE + | ID COLON TYPE ASSIGN expr''' + if len(p) == 4: + p[0] = AttrDeclarationNode(p[1], p[3]) + else: + p[0] = AttrDeclarationNode(p[1], p[3], p[5]) + + p[0].add_line_column(p.lineno(3), find_column( + p.lexer.lexdata, p.lexpos(3))) + + def p_def_func(self, p): + '''def_func : ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACE''' + p[0] = FuncDeclarationNode(p[1], p[3], p[6], p[8]) + p[0].add_line_column(p.lineno(6), find_column( + p.lexer.lexdata, p.lexpos(6))) + + def p_params(self, p): + '''params : param_list + | param_list_empty''' + p[0] = p[1] + + def p_param_list(self, p): + '''param_list : param + | param COMMA param_list''' + p[0] = [p[1]] if len(p) == 2 else [p[1]] + p[3] + + def p_param_list_empty(self, p): + '''param_list_empty : epsilon''' + p[0] = [] + + def p_param(self, p): + '''param : ID COLON TYPE''' + p[0] = (p[1], p[3]) + + def p_expr_flow(self, p): + '''expr : LET let_attrs IN expr + | CASE expr OF case_list ESAC + | IF expr THEN expr ELSE expr FI + | WHILE expr LOOP expr POOL''' + + if p[1].lower() == 'let': + p[0] = LetNode(p[2], p[4]) + elif p[1].lower() == 'case': + p[0] = CaseNode(p[2], p[4]) + elif p[1].lower() == 'if': + p[0] = IfNode(p[2], p[4], p[6]) + elif p[1].lower() == 'while': + p[0] = WhileNode(p[2], p[4]) + + p[0].add_line_column(p.lineno(2), find_column( + p.lexer.lexdata, p.lexpos(2))) + + def p_expr_assign(self, p): + '''expr : ID ASSIGN expr''' + p[0] = AssignNode(p[1], p[3]) + p[0].add_line_column(p.lineno(1), find_column( + p.lexer.lexdata, p.lexpos(1))) + + def p_expr_func_call(self, p): + '''expr : expr AT TYPE DOT ID LPAREN args RPAREN + | expr DOT ID LPAREN args RPAREN + | ID LPAREN args RPAREN''' + if len(p) == 9: + if p[7] is None: + p[7] = [] + p[0] = FuncCallNode(p[5], p[7], p[1], p[3]) + p[0].add_line_column(p.lineno(5), find_column( + p.lexer.lexdata, p.lexpos(5))) + elif len(p) == 7: + if p[5] is None: + p[5] = [] + p[0] = FuncCallNode(p[3], p[5], p[1]) + p[0].add_line_column(p.lineno(3), find_column( + p.lexer.lexdata, p.lexpos(3))) + else: + if p[3] is None: + p[3] = [] + p[0] = FuncCallNode(p[1], p[3]) + p[0].add_line_column(p.lineno(1), find_column( + p.lexer.lexdata, p.lexpos(1))) + + p[0].lineno = p.lineno(0) + + def p_expr_operators_binary(self, p): + '''expr : expr PLUS expr + | expr MINUS expr + | expr STAR expr + | expr DIV expr + | expr LESS expr + | expr LESSEQ expr + | expr EQUAL expr''' + if p[2] == '+': + p[0] = PlusNode(p[1], p[3]) + elif p[2] == '-': + p[0] = MinusNode(p[1], p[3]) + elif p[2] == '*': + p[0] = StarNode(p[1], p[3]) + elif p[2] == '/': + p[0] = DivNode(p[1], p[3]) + elif p[2] == '<': + p[0] = LessNode(p[1], p[3]) + elif p[2] == '<=': + p[0] = LessEqNode(p[1], p[3]) + elif p[2] == '<=': + p[0] = EqualNode(p[1], p[3]) + + p[0].add_line_column(p.lineno(0), find_column( + p.lexer.lexdata, p.lexpos(0))) + + def p_expr_operators_unary(self, p): + '''expr : NOT expr + | ISVOID expr + | LNOT expr''' + if p[1] == '~': + p[0] = NegationNode(p[2]) + elif p[1].lower() == 'isvoid': + p[0] = IsVoidNode(p[2]) + elif p[1].lower() == 'not': + p[0] = LogicNegationNode(p[2]) + + p[0].add_line_column(p.lineno(2), find_column( + p.lexer.lexdata, p.lexpos(2))) + + def p_expr_group(self, p): + '''expr : LPAREN expr RPAREN''' + p[0] = p[2] + + def p_expr_atom(self, p): + '''expr : atom''' + p[0] = p[1] + + def p_let_attrs(self, p): + '''let_attrs : def_attr + | def_attr COMMA let_attrs''' + p[0] = [p[1]] if len(p) == 2 else [p[1]] + p[3] + + def p_case_list(self, p): + '''case_list : case_option SEMICOLON + | case_option SEMICOLON case_list''' + p[0] = [p[1]] if len(p) == 3 else [p[1]] + p[3] + + def p_case_option(self, p): + '''case_option : ID COLON TYPE ARROW expr''' + p[0] = CaseOptionNode(p[1], p[3], p[5]) + p[0].add_line_column(p.lineno(3), find_column( + p.lexer.lexdata, p.lexpos(3))) + + def p_args(self, p): + '''args : arg_list + | arg_list_empty''' + p[0] = p[1] + + def p_arg_list(self, p): + '''arg_list : expr + | expr COMMA arg_list''' + p[0] = [p[1]] if len(p) == 2 else [p[1]] + p[3] + + def p_arg_list_empty(self, p): + '''arg_list_empty : epsilon''' + p[0] = [] + + def p_atom_int(self, p): + '''atom : INT''' + p[0] = IntNode(int(p[1])) + p[0].add_line_column(p.lineno(1), find_column( + p.lexer.lexdata, p.lexpos(1))) + + def p_atom_id(self, p): + '''atom : ID''' + p[0] = VarNode(p[1]) + p[0].add_line_column(p.lineno(1), find_column( + p.lexer.lexdata, p.lexpos(1))) + + def p_atom_bool(self, p): + '''atom : BOOL''' + p[0] = BoolNode(p[1]) + p[0].add_line_column(p.lineno(1), find_column( + p.lexer.lexdata, p.lexpos(1))) + + def p_atom_string(self, p): + '''atom : STRING''' + p[0] = StringNode(p[1]) + p[0].add_line_column(p.lineno(1), find_column( + p.lexer.lexdata, p.lexpos(1))) + + def p_atom_new(self, p): + '''atom : NEW TYPE''' + p[0] = NewNode(p[2]) + p[0].add_line_column(p.lineno(2), find_column( + p.lexer.lexdata, p.lexpos(2))) + + def p_atom_block(self, p): + '''atom : block''' + p[0] = p[1] + + def p_block(self, p): + '''block : LBRACE block_list RBRACE''' + p[0] = p[2] + + def p_block_list(self, p): + ''' block_list : expr SEMICOLON + | expr SEMICOLON block_list''' + p[0] = BlockNode([p[1]]) if len( + p) == 3 else BlockNode([p[1]] + p[3].exprs) + + def p_error(self, p): + if p: + self.lexer.add_line_column(p) + self.errors.append(SyntacticError( + f'ERROR at or near {p.value}', p.line, p.column)) + else: + self.errors.append(SyntacticError('ERROR at or near EOF', 0, 0)) diff --git a/src/cparser/parsetab.py b/src/cparser/parsetab.py index 3658bd136..6c2955ec9 100644 --- a/src/cparser/parsetab.py +++ b/src/cparser/parsetab.py @@ -1,87 +1,87 @@ - -# parsetab.py -# This file is automatically generated. Do not edit. -# pylint: disable=W,C,R -_tabversion = '3.10' - -_lr_method = 'LALR' - -_lr_signature = 'programARROW ASSIGN AT BOOL CASE CLASS COLON COMMA DIV DOT ELSE EQUAL ESAC FI ID IF IN INHERITS INT ISVOID LBRACE LESS LESSEQ LET LNOT LOOP LPAREN MINUS NEW NOT OF PLUS POOL RBRACE RPAREN SEMICOLON STAR STRING THEN TYPE WHILEprogram : class_listepsilon :class_list : def_class SEMICOLON class_list\n | def_class SEMICOLON def_class : CLASS TYPE LPAREN feature_list RPAREN\n | CLASS TYPE INHERITS TYPE LPAREN feature_list RPARENfeature_list : def_attr SEMICOLON feature_list\n | def_func SEMICOLON feature_list\n | epsilondef_attr : ID COLON TYPE\n | ID COLON TYPE ASSIGN exprdef_func : ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACEparams : param_list\n | param_list_emptyparam_list : param\n | param COMMA param_listparam_list_empty : epsilonparam : ID COLON TYPEexpr : LET let_attrs IN expr\n | CASE expr OF case_list ESAC\n | IF expr THEN expr ELSE expr FI\n | WHILE expr LOOP expr POOLexpr : ID ASSIGN exprexpr : expr AT TYPE DOT ID LPAREN args RPAREN\n | expr DOT ID LPAREN args RPAREN\n | ID LPAREN args RPARENexpr : expr PLUS expr\n | expr MINUS expr\n | expr STAR expr\n | expr DIV expr\n | expr LESS expr\n | expr LESSEQ expr\n | expr EQUAL exprexpr : NOT expr\n | ISVOID expr\n | LNOT exprexpr : LPAREN expr RPARENexpr : atomlet_attrs : def_attr\n | def_attr COMMA let_attrscase_list : case_option SEMICOLON\n | case_option SEMICOLON case_listcase_option : ID COLON TYPE ARROW exprargs : arg_list\n | arg_list_emptyarg_list : expr\n | expr COMMA arg_listarg_list_empty : epsilonatom : INTatom : IDatom : BOOLatom : STRINGatom : NEW TYPEatom : blockblock : LBRACE block_list RBRACE block_list : expr SEMICOLON\n | expr SEMICOLON block_list' - -_lr_action_items = {'CLASS':([0,5,],[4,4,]),'$end':([1,2,5,7,],[0,-1,-4,-3,]),'SEMICOLON':([3,11,12,16,24,36,37,38,47,48,49,50,52,75,76,77,78,80,82,90,91,92,93,94,95,96,102,103,106,110,113,122,126,127,129,135,136,137,],[5,17,18,-5,-10,-6,-50,-11,-38,-49,-51,-52,-54,-34,-35,-36,-53,104,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,123,-20,-22,-12,-25,-21,-24,-43,]),'TYPE':([4,9,19,33,51,55,59,124,],[6,15,24,54,78,81,88,131,]),'LPAREN':([6,14,15,32,37,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,89,97,100,101,104,105,107,109,120,125,128,134,],[8,20,21,43,58,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,109,43,43,43,43,43,43,43,128,43,43,43,]),'INHERITS':([6,],[9,]),'ID':([8,17,18,20,21,32,35,39,40,41,42,43,44,45,46,53,57,58,60,61,62,63,64,65,66,67,97,98,99,100,101,104,105,107,108,109,123,125,128,134,],[14,14,14,25,14,37,25,70,37,37,37,37,37,37,37,37,37,37,89,37,37,37,37,37,37,37,37,70,114,37,37,37,37,37,120,37,114,37,37,37,]),'RPAREN':([8,10,13,17,18,20,21,22,23,26,27,28,29,30,31,37,47,48,49,50,52,54,56,58,74,75,76,77,78,82,83,84,85,86,87,90,91,92,93,94,95,96,102,103,106,109,110,119,121,122,126,128,129,133,135,136,],[-2,16,-9,-2,-2,-2,-2,-7,-8,34,-13,-14,-15,-17,36,-50,-38,-49,-51,-52,-54,-18,-16,-2,102,-34,-35,-36,-53,-23,106,-44,-45,-46,-48,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-2,-19,-47,129,-20,-22,-2,-25,136,-21,-24,]),'COLON':([14,25,34,70,114,],[19,33,55,19,124,]),'COMMA':([24,29,37,38,47,48,49,50,52,54,69,75,76,77,78,82,86,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-10,35,-50,-11,-38,-49,-51,-52,-54,-18,98,-34,-35,-36,-53,-23,107,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'IN':([24,37,38,47,48,49,50,52,68,69,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,111,122,126,129,135,136,],[-10,-50,-11,-38,-49,-51,-52,-54,97,-39,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-40,-20,-22,-25,-21,-24,]),'ASSIGN':([24,37,],[32,57,]),'LET':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,]),'CASE':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,]),'IF':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,]),'WHILE':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,]),'NOT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,]),'ISVOID':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,]),'LNOT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,]),'INT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,]),'BOOL':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,]),'STRING':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,]),'NEW':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,]),'LBRACE':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,81,97,100,101,104,105,107,109,125,128,134,],[53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,105,53,53,53,53,53,53,53,53,53,53,]),'AT':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,59,-38,-49,-51,-52,-54,59,59,59,59,59,59,59,-53,59,59,59,59,59,59,59,59,59,59,-37,-55,-26,59,59,59,59,-20,-22,-25,59,-21,-24,59,]),'DOT':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,88,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,60,-38,-49,-51,-52,-54,60,60,60,60,60,60,60,-53,60,60,60,108,60,60,60,60,60,60,60,-37,-55,-26,60,60,60,60,-20,-22,-25,60,-21,-24,60,]),'PLUS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,61,-38,-49,-51,-52,-54,61,61,61,61,61,61,61,-53,61,61,61,61,61,61,61,61,61,61,-37,-55,-26,61,61,61,61,-20,-22,-25,61,-21,-24,61,]),'MINUS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,62,-38,-49,-51,-52,-54,62,62,62,62,62,62,62,-53,62,62,62,62,62,62,62,62,62,62,-37,-55,-26,62,62,62,62,-20,-22,-25,62,-21,-24,62,]),'STAR':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,63,-38,-49,-51,-52,-54,63,63,63,63,63,63,63,-53,63,63,63,63,63,63,63,63,63,63,-37,-55,-26,63,63,63,63,-20,-22,-25,63,-21,-24,63,]),'DIV':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,64,-38,-49,-51,-52,-54,64,64,64,64,64,64,64,-53,64,64,64,64,64,64,64,64,64,64,-37,-55,-26,64,64,64,64,-20,-22,-25,64,-21,-24,64,]),'LESS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,65,-38,-49,-51,-52,-54,65,65,65,65,65,65,65,-53,65,65,65,65,65,65,65,65,65,65,-37,-55,-26,65,65,65,65,-20,-22,-25,65,-21,-24,65,]),'LESSEQ':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,66,-38,-49,-51,-52,-54,66,66,66,66,66,66,66,-53,66,66,66,66,66,66,66,66,66,66,-37,-55,-26,66,66,66,66,-20,-22,-25,66,-21,-24,66,]),'EQUAL':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,67,-38,-49,-51,-52,-54,67,67,67,67,67,67,67,-53,67,67,67,67,67,67,67,67,67,67,-37,-55,-26,67,67,67,67,-20,-22,-25,67,-21,-24,67,]),'OF':([37,47,48,49,50,52,71,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,99,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'THEN':([37,47,48,49,50,52,72,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,100,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'LOOP':([37,47,48,49,50,52,73,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,101,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'ELSE':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,115,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,125,-20,-22,-25,-21,-24,]),'POOL':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,116,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,126,-20,-22,-25,-21,-24,]),'RBRACE':([37,47,48,49,50,52,75,76,77,78,79,82,90,91,92,93,94,95,96,102,103,104,106,110,117,118,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,103,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-56,-26,-19,-57,127,-20,-22,-25,-21,-24,]),'FI':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,132,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,135,-21,-24,]),'ESAC':([112,123,130,],[122,-41,-42,]),'ARROW':([131,],[134,]),} - -_lr_action = {} -for _k, _v in _lr_action_items.items(): - for _x,_y in zip(_v[0],_v[1]): - if not _x in _lr_action: _lr_action[_x] = {} - _lr_action[_x][_k] = _y -del _lr_action_items - -_lr_goto_items = {'program':([0,],[1,]),'class_list':([0,5,],[2,7,]),'def_class':([0,5,],[3,3,]),'feature_list':([8,17,18,21,],[10,22,23,31,]),'def_attr':([8,17,18,21,39,98,],[11,11,11,11,69,69,]),'def_func':([8,17,18,21,],[12,12,12,12,]),'epsilon':([8,17,18,20,21,58,109,128,],[13,13,13,30,13,87,87,87,]),'params':([20,],[26,]),'param_list':([20,35,],[27,56,]),'param_list_empty':([20,],[28,]),'param':([20,35,],[29,29,]),'expr':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[38,71,72,73,74,75,76,77,80,82,86,90,91,92,93,94,95,96,110,115,116,80,118,86,86,132,86,137,]),'atom':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,]),'block':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,]),'let_attrs':([39,98,],[68,111,]),'block_list':([53,104,],[79,117,]),'args':([58,109,128,],[83,121,133,]),'arg_list':([58,107,109,128,],[84,119,84,84,]),'arg_list_empty':([58,109,128,],[85,85,85,]),'case_list':([99,123,],[112,130,]),'case_option':([99,123,],[113,113,]),} - -_lr_goto = {} -for _k, _v in _lr_goto_items.items(): - for _x, _y in zip(_v[0], _v[1]): - if not _x in _lr_goto: _lr_goto[_x] = {} - _lr_goto[_x][_k] = _y -del _lr_goto_items -_lr_productions = [ - ("S' -> program","S'",1,None,None,None), - ('program -> class_list','program',1,'p_program','parser.py',28), - ('epsilon -> ','epsilon',0,'p_epsilon','parser.py',32), - ('class_list -> def_class SEMICOLON class_list','class_list',3,'p_class_list','parser.py',35), - ('class_list -> def_class SEMICOLON','class_list',2,'p_class_list','parser.py',36), - ('def_class -> CLASS TYPE LPAREN feature_list RPAREN','def_class',5,'p_def_class','parser.py',40), - ('def_class -> CLASS TYPE INHERITS TYPE LPAREN feature_list RPAREN','def_class',7,'p_def_class','parser.py',41), - ('feature_list -> def_attr SEMICOLON feature_list','feature_list',3,'p_feature_list','parser.py',51), - ('feature_list -> def_func SEMICOLON feature_list','feature_list',3,'p_feature_list','parser.py',52), - ('feature_list -> epsilon','feature_list',1,'p_feature_list','parser.py',53), - ('def_attr -> ID COLON TYPE','def_attr',3,'p_def_attr','parser.py',57), - ('def_attr -> ID COLON TYPE ASSIGN expr','def_attr',5,'p_def_attr','parser.py',58), - ('def_func -> ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACE','def_func',9,'p_def_func','parser.py',68), - ('params -> param_list','params',1,'p_params','parser.py',74), - ('params -> param_list_empty','params',1,'p_params','parser.py',75), - ('param_list -> param','param_list',1,'p_param_list','parser.py',79), - ('param_list -> param COMMA param_list','param_list',3,'p_param_list','parser.py',80), - ('param_list_empty -> epsilon','param_list_empty',1,'p_param_list_empty','parser.py',84), - ('param -> ID COLON TYPE','param',3,'p_param','parser.py',88), - ('expr -> LET let_attrs IN expr','expr',4,'p_expr_flow','parser.py',92), - ('expr -> CASE expr OF case_list ESAC','expr',5,'p_expr_flow','parser.py',93), - ('expr -> IF expr THEN expr ELSE expr FI','expr',7,'p_expr_flow','parser.py',94), - ('expr -> WHILE expr LOOP expr POOL','expr',5,'p_expr_flow','parser.py',95), - ('expr -> ID ASSIGN expr','expr',3,'p_expr_assign','parser.py',110), - ('expr -> expr AT TYPE DOT ID LPAREN args RPAREN','expr',8,'p_expr_func_call','parser.py',116), - ('expr -> expr DOT ID LPAREN args RPAREN','expr',6,'p_expr_func_call','parser.py',117), - ('expr -> ID LPAREN args RPAREN','expr',4,'p_expr_func_call','parser.py',118), - ('expr -> expr PLUS expr','expr',3,'p_expr_operators_binary','parser.py',141), - ('expr -> expr MINUS expr','expr',3,'p_expr_operators_binary','parser.py',142), - ('expr -> expr STAR expr','expr',3,'p_expr_operators_binary','parser.py',143), - ('expr -> expr DIV expr','expr',3,'p_expr_operators_binary','parser.py',144), - ('expr -> expr LESS expr','expr',3,'p_expr_operators_binary','parser.py',145), - ('expr -> expr LESSEQ expr','expr',3,'p_expr_operators_binary','parser.py',146), - ('expr -> expr EQUAL expr','expr',3,'p_expr_operators_binary','parser.py',147), - ('expr -> NOT expr','expr',2,'p_expr_operators_unary','parser.py',167), - ('expr -> ISVOID expr','expr',2,'p_expr_operators_unary','parser.py',168), - ('expr -> LNOT expr','expr',2,'p_expr_operators_unary','parser.py',169), - ('expr -> LPAREN expr RPAREN','expr',3,'p_expr_group','parser.py',181), - ('expr -> atom','expr',1,'p_expr_atom','parser.py',185), - ('let_attrs -> def_attr','let_attrs',1,'p_let_attrs','parser.py',189), - ('let_attrs -> def_attr COMMA let_attrs','let_attrs',3,'p_let_attrs','parser.py',190), - ('case_list -> case_option SEMICOLON','case_list',2,'p_case_list','parser.py',194), - ('case_list -> case_option SEMICOLON case_list','case_list',3,'p_case_list','parser.py',195), - ('case_option -> ID COLON TYPE ARROW expr','case_option',5,'p_case_option','parser.py',199), - ('args -> arg_list','args',1,'p_args','parser.py',205), - ('args -> arg_list_empty','args',1,'p_args','parser.py',206), - ('arg_list -> expr','arg_list',1,'p_arg_list','parser.py',210), - ('arg_list -> expr COMMA arg_list','arg_list',3,'p_arg_list','parser.py',211), - ('arg_list_empty -> epsilon','arg_list_empty',1,'p_arg_list_empty','parser.py',215), - ('atom -> INT','atom',1,'p_atom_int','parser.py',219), - ('atom -> ID','atom',1,'p_atom_id','parser.py',225), - ('atom -> BOOL','atom',1,'p_atom_bool','parser.py',231), - ('atom -> STRING','atom',1,'p_atom_string','parser.py',237), - ('atom -> NEW TYPE','atom',2,'p_atom_new','parser.py',243), - ('atom -> block','atom',1,'p_atom_block','parser.py',249), - ('block -> LBRACE block_list RBRACE','block',3,'p_block','parser.py',253), - ('block_list -> expr SEMICOLON','block_list',2,'p_block_list','parser.py',257), - ('block_list -> expr SEMICOLON block_list','block_list',3,'p_block_list','parser.py',258), -] + +# parsetab.py +# This file is automatically generated. Do not edit. +# pylint: disable=W,C,R +_tabversion = '3.10' + +_lr_method = 'LALR' + +_lr_signature = 'programARROW ASSIGN AT BOOL CASE CLASS COLON COMMA DIV DOT ELSE EQUAL ESAC FI ID IF IN INHERITS INT ISVOID LBRACE LESS LESSEQ LET LNOT LOOP LPAREN MINUS NEW NOT OF PLUS POOL RBRACE RPAREN SEMICOLON STAR STRING THEN TYPE WHILEprogram : class_listepsilon :class_list : def_class SEMICOLON class_list\n | def_class SEMICOLON def_class : CLASS TYPE LPAREN feature_list RPAREN\n | CLASS TYPE INHERITS TYPE LPAREN feature_list RPARENfeature_list : def_attr SEMICOLON feature_list\n | def_func SEMICOLON feature_list\n | epsilondef_attr : ID COLON TYPE\n | ID COLON TYPE ASSIGN exprdef_func : ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACEparams : param_list\n | param_list_emptyparam_list : param\n | param COMMA param_listparam_list_empty : epsilonparam : ID COLON TYPEexpr : LET let_attrs IN expr\n | CASE expr OF case_list ESAC\n | IF expr THEN expr ELSE expr FI\n | WHILE expr LOOP expr POOLexpr : ID ASSIGN exprexpr : expr AT TYPE DOT ID LPAREN args RPAREN\n | expr DOT ID LPAREN args RPAREN\n | ID LPAREN args RPARENexpr : expr PLUS expr\n | expr MINUS expr\n | expr STAR expr\n | expr DIV expr\n | expr LESS expr\n | expr LESSEQ expr\n | expr EQUAL exprexpr : NOT expr\n | ISVOID expr\n | LNOT exprexpr : LPAREN expr RPARENexpr : atomlet_attrs : def_attr\n | def_attr COMMA let_attrscase_list : case_option SEMICOLON\n | case_option SEMICOLON case_listcase_option : ID COLON TYPE ARROW exprargs : arg_list\n | arg_list_emptyarg_list : expr\n | expr COMMA arg_listarg_list_empty : epsilonatom : INTatom : IDatom : BOOLatom : STRINGatom : NEW TYPEatom : blockblock : LBRACE block_list RBRACE block_list : expr SEMICOLON\n | expr SEMICOLON block_list' + +_lr_action_items = {'CLASS':([0,5,],[4,4,]),'$end':([1,2,5,7,],[0,-1,-4,-3,]),'SEMICOLON':([3,11,12,16,24,36,37,38,47,48,49,50,52,75,76,77,78,80,82,90,91,92,93,94,95,96,102,103,106,110,113,122,126,127,129,135,136,137,],[5,17,18,-5,-10,-6,-50,-11,-38,-49,-51,-52,-54,-34,-35,-36,-53,104,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,123,-20,-22,-12,-25,-21,-24,-43,]),'TYPE':([4,9,19,33,51,55,59,124,],[6,15,24,54,78,81,88,131,]),'LPAREN':([6,14,15,32,37,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,89,97,100,101,104,105,107,109,120,125,128,134,],[8,20,21,43,58,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,109,43,43,43,43,43,43,43,128,43,43,43,]),'INHERITS':([6,],[9,]),'ID':([8,17,18,20,21,32,35,39,40,41,42,43,44,45,46,53,57,58,60,61,62,63,64,65,66,67,97,98,99,100,101,104,105,107,108,109,123,125,128,134,],[14,14,14,25,14,37,25,70,37,37,37,37,37,37,37,37,37,37,89,37,37,37,37,37,37,37,37,70,114,37,37,37,37,37,120,37,114,37,37,37,]),'RPAREN':([8,10,13,17,18,20,21,22,23,26,27,28,29,30,31,37,47,48,49,50,52,54,56,58,74,75,76,77,78,82,83,84,85,86,87,90,91,92,93,94,95,96,102,103,106,109,110,119,121,122,126,128,129,133,135,136,],[-2,16,-9,-2,-2,-2,-2,-7,-8,34,-13,-14,-15,-17,36,-50,-38,-49,-51,-52,-54,-18,-16,-2,102,-34,-35,-36,-53,-23,106,-44,-45,-46,-48,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-2,-19,-47,129,-20,-22,-2,-25,136,-21,-24,]),'COLON':([14,25,34,70,114,],[19,33,55,19,124,]),'COMMA':([24,29,37,38,47,48,49,50,52,54,69,75,76,77,78,82,86,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-10,35,-50,-11,-38,-49,-51,-52,-54,-18,98,-34,-35,-36,-53,-23,107,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'IN':([24,37,38,47,48,49,50,52,68,69,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,111,122,126,129,135,136,],[-10,-50,-11,-38,-49,-51,-52,-54,97,-39,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-40,-20,-22,-25,-21,-24,]),'ASSIGN':([24,37,],[32,57,]),'LET':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,]),'CASE':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,]),'IF':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,]),'WHILE':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,]),'NOT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,]),'ISVOID':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,]),'LNOT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,]),'INT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,]),'BOOL':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,]),'STRING':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,]),'NEW':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,]),'LBRACE':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,81,97,100,101,104,105,107,109,125,128,134,],[53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,105,53,53,53,53,53,53,53,53,53,53,]),'AT':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,59,-38,-49,-51,-52,-54,59,59,59,59,59,59,59,-53,59,59,59,59,59,59,59,59,59,59,-37,-55,-26,59,59,59,59,-20,-22,-25,59,-21,-24,59,]),'DOT':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,88,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,60,-38,-49,-51,-52,-54,60,60,60,60,60,60,60,-53,60,60,60,108,60,60,60,60,60,60,60,-37,-55,-26,60,60,60,60,-20,-22,-25,60,-21,-24,60,]),'PLUS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,61,-38,-49,-51,-52,-54,61,61,61,61,61,61,61,-53,61,61,61,61,61,61,61,61,61,61,-37,-55,-26,61,61,61,61,-20,-22,-25,61,-21,-24,61,]),'MINUS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,62,-38,-49,-51,-52,-54,62,62,62,62,62,62,62,-53,62,62,62,62,62,62,62,62,62,62,-37,-55,-26,62,62,62,62,-20,-22,-25,62,-21,-24,62,]),'STAR':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,63,-38,-49,-51,-52,-54,63,63,63,63,63,63,63,-53,63,63,63,63,63,63,63,63,63,63,-37,-55,-26,63,63,63,63,-20,-22,-25,63,-21,-24,63,]),'DIV':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,64,-38,-49,-51,-52,-54,64,64,64,64,64,64,64,-53,64,64,64,64,64,64,64,64,64,64,-37,-55,-26,64,64,64,64,-20,-22,-25,64,-21,-24,64,]),'LESS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,65,-38,-49,-51,-52,-54,65,65,65,65,65,65,65,-53,65,65,65,65,65,65,65,65,65,65,-37,-55,-26,65,65,65,65,-20,-22,-25,65,-21,-24,65,]),'LESSEQ':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,66,-38,-49,-51,-52,-54,66,66,66,66,66,66,66,-53,66,66,66,66,66,66,66,66,66,66,-37,-55,-26,66,66,66,66,-20,-22,-25,66,-21,-24,66,]),'EQUAL':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,67,-38,-49,-51,-52,-54,67,67,67,67,67,67,67,-53,67,67,67,67,67,67,67,67,67,67,-37,-55,-26,67,67,67,67,-20,-22,-25,67,-21,-24,67,]),'OF':([37,47,48,49,50,52,71,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,99,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'THEN':([37,47,48,49,50,52,72,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,100,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'LOOP':([37,47,48,49,50,52,73,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,101,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'ELSE':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,115,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,125,-20,-22,-25,-21,-24,]),'POOL':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,116,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,126,-20,-22,-25,-21,-24,]),'RBRACE':([37,47,48,49,50,52,75,76,77,78,79,82,90,91,92,93,94,95,96,102,103,104,106,110,117,118,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,103,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-56,-26,-19,-57,127,-20,-22,-25,-21,-24,]),'FI':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,132,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,135,-21,-24,]),'ESAC':([112,123,130,],[122,-41,-42,]),'ARROW':([131,],[134,]),} + +_lr_action = {} +for _k, _v in _lr_action_items.items(): + for _x,_y in zip(_v[0],_v[1]): + if not _x in _lr_action: _lr_action[_x] = {} + _lr_action[_x][_k] = _y +del _lr_action_items + +_lr_goto_items = {'program':([0,],[1,]),'class_list':([0,5,],[2,7,]),'def_class':([0,5,],[3,3,]),'feature_list':([8,17,18,21,],[10,22,23,31,]),'def_attr':([8,17,18,21,39,98,],[11,11,11,11,69,69,]),'def_func':([8,17,18,21,],[12,12,12,12,]),'epsilon':([8,17,18,20,21,58,109,128,],[13,13,13,30,13,87,87,87,]),'params':([20,],[26,]),'param_list':([20,35,],[27,56,]),'param_list_empty':([20,],[28,]),'param':([20,35,],[29,29,]),'expr':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[38,71,72,73,74,75,76,77,80,82,86,90,91,92,93,94,95,96,110,115,116,80,118,86,86,132,86,137,]),'atom':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,]),'block':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,]),'let_attrs':([39,98,],[68,111,]),'block_list':([53,104,],[79,117,]),'args':([58,109,128,],[83,121,133,]),'arg_list':([58,107,109,128,],[84,119,84,84,]),'arg_list_empty':([58,109,128,],[85,85,85,]),'case_list':([99,123,],[112,130,]),'case_option':([99,123,],[113,113,]),} + +_lr_goto = {} +for _k, _v in _lr_goto_items.items(): + for _x, _y in zip(_v[0], _v[1]): + if not _x in _lr_goto: _lr_goto[_x] = {} + _lr_goto[_x][_k] = _y +del _lr_goto_items +_lr_productions = [ + ("S' -> program","S'",1,None,None,None), + ('program -> class_list','program',1,'p_program','parser.py',28), + ('epsilon -> ','epsilon',0,'p_epsilon','parser.py',32), + ('class_list -> def_class SEMICOLON class_list','class_list',3,'p_class_list','parser.py',35), + ('class_list -> def_class SEMICOLON','class_list',2,'p_class_list','parser.py',36), + ('def_class -> CLASS TYPE LPAREN feature_list RPAREN','def_class',5,'p_def_class','parser.py',40), + ('def_class -> CLASS TYPE INHERITS TYPE LPAREN feature_list RPAREN','def_class',7,'p_def_class','parser.py',41), + ('feature_list -> def_attr SEMICOLON feature_list','feature_list',3,'p_feature_list','parser.py',51), + ('feature_list -> def_func SEMICOLON feature_list','feature_list',3,'p_feature_list','parser.py',52), + ('feature_list -> epsilon','feature_list',1,'p_feature_list','parser.py',53), + ('def_attr -> ID COLON TYPE','def_attr',3,'p_def_attr','parser.py',57), + ('def_attr -> ID COLON TYPE ASSIGN expr','def_attr',5,'p_def_attr','parser.py',58), + ('def_func -> ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACE','def_func',9,'p_def_func','parser.py',68), + ('params -> param_list','params',1,'p_params','parser.py',74), + ('params -> param_list_empty','params',1,'p_params','parser.py',75), + ('param_list -> param','param_list',1,'p_param_list','parser.py',79), + ('param_list -> param COMMA param_list','param_list',3,'p_param_list','parser.py',80), + ('param_list_empty -> epsilon','param_list_empty',1,'p_param_list_empty','parser.py',84), + ('param -> ID COLON TYPE','param',3,'p_param','parser.py',88), + ('expr -> LET let_attrs IN expr','expr',4,'p_expr_flow','parser.py',92), + ('expr -> CASE expr OF case_list ESAC','expr',5,'p_expr_flow','parser.py',93), + ('expr -> IF expr THEN expr ELSE expr FI','expr',7,'p_expr_flow','parser.py',94), + ('expr -> WHILE expr LOOP expr POOL','expr',5,'p_expr_flow','parser.py',95), + ('expr -> ID ASSIGN expr','expr',3,'p_expr_assign','parser.py',110), + ('expr -> expr AT TYPE DOT ID LPAREN args RPAREN','expr',8,'p_expr_func_call','parser.py',116), + ('expr -> expr DOT ID LPAREN args RPAREN','expr',6,'p_expr_func_call','parser.py',117), + ('expr -> ID LPAREN args RPAREN','expr',4,'p_expr_func_call','parser.py',118), + ('expr -> expr PLUS expr','expr',3,'p_expr_operators_binary','parser.py',141), + ('expr -> expr MINUS expr','expr',3,'p_expr_operators_binary','parser.py',142), + ('expr -> expr STAR expr','expr',3,'p_expr_operators_binary','parser.py',143), + ('expr -> expr DIV expr','expr',3,'p_expr_operators_binary','parser.py',144), + ('expr -> expr LESS expr','expr',3,'p_expr_operators_binary','parser.py',145), + ('expr -> expr LESSEQ expr','expr',3,'p_expr_operators_binary','parser.py',146), + ('expr -> expr EQUAL expr','expr',3,'p_expr_operators_binary','parser.py',147), + ('expr -> NOT expr','expr',2,'p_expr_operators_unary','parser.py',167), + ('expr -> ISVOID expr','expr',2,'p_expr_operators_unary','parser.py',168), + ('expr -> LNOT expr','expr',2,'p_expr_operators_unary','parser.py',169), + ('expr -> LPAREN expr RPAREN','expr',3,'p_expr_group','parser.py',181), + ('expr -> atom','expr',1,'p_expr_atom','parser.py',185), + ('let_attrs -> def_attr','let_attrs',1,'p_let_attrs','parser.py',189), + ('let_attrs -> def_attr COMMA let_attrs','let_attrs',3,'p_let_attrs','parser.py',190), + ('case_list -> case_option SEMICOLON','case_list',2,'p_case_list','parser.py',194), + ('case_list -> case_option SEMICOLON case_list','case_list',3,'p_case_list','parser.py',195), + ('case_option -> ID COLON TYPE ARROW expr','case_option',5,'p_case_option','parser.py',199), + ('args -> arg_list','args',1,'p_args','parser.py',205), + ('args -> arg_list_empty','args',1,'p_args','parser.py',206), + ('arg_list -> expr','arg_list',1,'p_arg_list','parser.py',210), + ('arg_list -> expr COMMA arg_list','arg_list',3,'p_arg_list','parser.py',211), + ('arg_list_empty -> epsilon','arg_list_empty',1,'p_arg_list_empty','parser.py',215), + ('atom -> INT','atom',1,'p_atom_int','parser.py',219), + ('atom -> ID','atom',1,'p_atom_id','parser.py',225), + ('atom -> BOOL','atom',1,'p_atom_bool','parser.py',231), + ('atom -> STRING','atom',1,'p_atom_string','parser.py',237), + ('atom -> NEW TYPE','atom',2,'p_atom_new','parser.py',243), + ('atom -> block','atom',1,'p_atom_block','parser.py',249), + ('block -> LBRACE block_list RBRACE','block',3,'p_block','parser.py',253), + ('block_list -> expr SEMICOLON','block_list',2,'p_block_list','parser.py',257), + ('block_list -> expr SEMICOLON block_list','block_list',3,'p_block_list','parser.py',258), +] diff --git a/src/lexer/lexer.py b/src/lexer/lexer.py index efe819a5f..7cfbe64ea 100644 --- a/src/lexer/lexer.py +++ b/src/lexer/lexer.py @@ -1,280 +1,280 @@ -from ply import lex - -from utils.errors import LexicographicError -from utils.utils import Token, tokens, reserved - - -class CoolLexer: - - states = ( - ('comments', 'exclusive'), - ('strings', 'exclusive') - ) - - def __init__(self, **kwargs): - self.errors = [] - self.reserved = reserved - self.tokens = tokens - self.lexer = lex.lex(module=self, **kwargs) - self.lexer.lineno = 1 - self.lexer.linestart = 0 - self.text = None - - # Comments - - def t_comments(self, t): - r'\(\*' - t.lexer.level = 1 - t.lexer.begin('comments') - - def t_comments_open(self, t): - r'\(\*' - t.lexer.level += 1 - - def t_comments_close(self, t): - r'\*\)' - t.lexer.level -= 1 - if t.lexer.level == 0: - t.lexer.begin('INITIAL') - - def t_comments_newline(self, t): - r'\n+' - t.lexer.lineno += len(t.value) - t.lexer.linestart = t.lexer.lexpos - - def t_comments_error(self, t): - t.lexer.skip(1) - - def t_comments_eof(self, t): - line = t.lexer.lineno - column = self.find_column(t) - self.errors.append(LexicographicError("EOF in comment", line, column)) - - t_comments_ignore = ' \t\f\r\v' - - # Strings - t_strings_ignore = '' - - def t_strings(self, t): - r'\"' - t.lexer.string_start = t.lexer.lexpos - t.lexer.string = '' - t.lexer.backslash = False - t.lexer.begin('strings') - - def t_strings_end(self, t): - r'\"' - self.add_line_column(t) - - if t.lexer.backslash: - t.lexer.string += '"' - t.lexer.backslash = False - else: - t.value = t.lexer.string - t.type = 'STRING' - t.lexer.begin('INITIAL') - return t - - def t_strings_newline(self, t): - r'\n' - t.lexer.lineno += 1 - self.add_line_column(t) - - t.lexer.linestart = t.lexer.lexpos - - if not t.lexer.backslash: - self.errors.append(LexicographicError( - 'Undeterminated string constant', t.line, t.column)) - t.lexer.begin('INITIAL') - - def t_strings_nill(self, t): - r'\0' - self.add_line_column(t) - self.errors.append(LexicographicError( - 'Null caracter in string', t.line, t.column)) - - def t_strings_consume(self, t): - r'[^\n]' - - if t.lexer.backslash: - if t.value == 'b': - t.lexer.string += '\b' - elif t.value == 't': - t.lexer.string += '\t' - if t.value == 'f': - t.lexer.string += '\f' - elif t.value == 'n': - t.lexer.string += '\n' - elif t.value == '\\': - t.lexer.string += '\\' - else: - t.lexer.string += t.value - - t.backslash = False - else: - if t.value != '\\': - t.lexer.string += t.value - else: - t.lexer.backslash = True - - def t_strings_error(self, t): - pass - - def t_strings_eof(self, t): - self.add_line_column(t) - self.errors.append(LexicographicError( - 'EOF in string constant', t.line, t.column)) - - def find_column(self, t): - line_start = self.text.rfind('\n', 0, t.lexpos) + 1 - return (t.lexpos - line_start) + 1 - - def add_line_column(self, t): - t.line = t.lexer.lineno - t.column = self.find_column(t) - - t_ignore = ' \t\f\r\t\v' - - def t_LPAREN(self, t): - r'\(' - self.add_line_column(t) - return t - - def t_RPAREN(self, t): - r'\)' - self.add_line_column(t) - return t - - def t_LBRACE(self, t): - r'\{' - self.add_line_column(t) - return t - - def t_RBRACE(self, t): - r'\}' - self.add_line_column(t) - return t - - def t_COLON(self, t): - r':' - self.add_line_column(t) - return t - - def t_SEMICOLON(self, t): - r';' - self.add_line_column(t) - return t - - def t_COMMA(self, t): - r',' - self.add_line_column(t) - return t - - def t_DOT(self, t): - r'\.' - self.add_line_column(t) - return t - - def t_AT(self, t): - r'@' - self.add_line_column(t) - return t - - def t_ASSIGN(self, t): - r'<-' - self.add_line_column(t) - return t - - def t_PLUS(self, t): - r'\+' - self.add_line_column(t) - return t - - def t_MINUS(self, t): - r'-' - self.add_line_column(t) - return t - - def t_STAR(self, t): - r'\*' - self.add_line_column(t) - return t - - def t_DIV(self, t): - r'/' - self.add_line_column(t) - return t - - def t_ARROW(self, t): - r'=>' - self.add_line_column(t) - return t - - def t_EQUAL(self, t): - r'=' - self.add_line_column(t) - return t - - def t_LESS(self, t): - r'<' - self.add_line_column(t) - return t - - def t_LESSEQ(self, t): - r'<=' - self.add_line_column(t) - return t - - def t_NOT(self, t): - r'~' - self.add_line_column(t) - return t - - def t_INT(self, t): - r'\d+' - t.value = int(t.value) - self.add_line_column(t) - return t - - def t_ID(self, t): - r'[a-z][a-zA-Z_0-9]*' - t.type = self.reserved.get(t.value.lower(), 'ID') - self.add_line_column(t) - return t - - def t_TYPE(self, t): - r'[A-Z][a-zA-Z_0-9]*' - t.type = self.reserved.get(t.value.lower(), 'TYPE') - self.add_line_column(t) - return t - - def t_newline(self, t): - r'\n+' - t.lexer.lineno += len(t.value) - t.lexer.linestart = t.lexer.lexpos - - def t_error(self, t): - self.add_line_column(t) - self.errors.append(LexicographicError( - f'ERROR \"{t.value[0]}\"', t.line, t.column)) - t.lexer.skip(1) - - def tokenize(self, text): - self.text = text - self.lexer.input(text) - tokens = [] - for token in self.lexer: - tokens.append(Token(token.value, token.type, - token.line, token.column)) - self.lexer.lineno = 1 - self.lexer.linestart = 0 - return tokens - - def run(self, text): - tokens = self.tokenize(text) - if self.errors: - for error in self.errors: - print(error) - raise Exception() - - return tokens +from ply import lex + +from utils.errors import LexicographicError +from utils.utils import Token, tokens, reserved + + +class CoolLexer: + + states = ( + ('comments', 'exclusive'), + ('strings', 'exclusive') + ) + + def __init__(self, **kwargs): + self.errors = [] + self.reserved = reserved + self.tokens = tokens + self.lexer = lex.lex(module=self, **kwargs) + self.lexer.lineno = 1 + self.lexer.linestart = 0 + self.text = None + + # Comments + + def t_comments(self, t): + r'\(\*' + t.lexer.level = 1 + t.lexer.begin('comments') + + def t_comments_open(self, t): + r'\(\*' + t.lexer.level += 1 + + def t_comments_close(self, t): + r'\*\)' + t.lexer.level -= 1 + if t.lexer.level == 0: + t.lexer.begin('INITIAL') + + def t_comments_newline(self, t): + r'\n+' + t.lexer.lineno += len(t.value) + t.lexer.linestart = t.lexer.lexpos + + def t_comments_error(self, t): + t.lexer.skip(1) + + def t_comments_eof(self, t): + line = t.lexer.lineno + column = self.find_column(t) + self.errors.append(LexicographicError("EOF in comment", line, column)) + + t_comments_ignore = ' \t\f\r\v' + + # Strings + t_strings_ignore = '' + + def t_strings(self, t): + r'\"' + t.lexer.string_start = t.lexer.lexpos + t.lexer.string = '' + t.lexer.backslash = False + t.lexer.begin('strings') + + def t_strings_end(self, t): + r'\"' + self.add_line_column(t) + + if t.lexer.backslash: + t.lexer.string += '"' + t.lexer.backslash = False + else: + t.value = t.lexer.string + t.type = 'STRING' + t.lexer.begin('INITIAL') + return t + + def t_strings_newline(self, t): + r'\n' + t.lexer.lineno += 1 + self.add_line_column(t) + + t.lexer.linestart = t.lexer.lexpos + + if not t.lexer.backslash: + self.errors.append(LexicographicError( + 'Undeterminated string constant', t.line, t.column)) + t.lexer.begin('INITIAL') + + def t_strings_nill(self, t): + r'\0' + self.add_line_column(t) + self.errors.append(LexicographicError( + 'Null caracter in string', t.line, t.column)) + + def t_strings_consume(self, t): + r'[^\n]' + + if t.lexer.backslash: + if t.value == 'b': + t.lexer.string += '\b' + elif t.value == 't': + t.lexer.string += '\t' + if t.value == 'f': + t.lexer.string += '\f' + elif t.value == 'n': + t.lexer.string += '\n' + elif t.value == '\\': + t.lexer.string += '\\' + else: + t.lexer.string += t.value + + t.backslash = False + else: + if t.value != '\\': + t.lexer.string += t.value + else: + t.lexer.backslash = True + + def t_strings_error(self, t): + pass + + def t_strings_eof(self, t): + self.add_line_column(t) + self.errors.append(LexicographicError( + 'EOF in string constant', t.line, t.column)) + + def find_column(self, t): + line_start = self.text.rfind('\n', 0, t.lexpos) + 1 + return (t.lexpos - line_start) + 1 + + def add_line_column(self, t): + t.line = t.lexer.lineno + t.column = self.find_column(t) + + t_ignore = ' \t\f\r\t\v' + + def t_LPAREN(self, t): + r'\(' + self.add_line_column(t) + return t + + def t_RPAREN(self, t): + r'\)' + self.add_line_column(t) + return t + + def t_LBRACE(self, t): + r'\{' + self.add_line_column(t) + return t + + def t_RBRACE(self, t): + r'\}' + self.add_line_column(t) + return t + + def t_COLON(self, t): + r':' + self.add_line_column(t) + return t + + def t_SEMICOLON(self, t): + r';' + self.add_line_column(t) + return t + + def t_COMMA(self, t): + r',' + self.add_line_column(t) + return t + + def t_DOT(self, t): + r'\.' + self.add_line_column(t) + return t + + def t_AT(self, t): + r'@' + self.add_line_column(t) + return t + + def t_ASSIGN(self, t): + r'<-' + self.add_line_column(t) + return t + + def t_PLUS(self, t): + r'\+' + self.add_line_column(t) + return t + + def t_MINUS(self, t): + r'-' + self.add_line_column(t) + return t + + def t_STAR(self, t): + r'\*' + self.add_line_column(t) + return t + + def t_DIV(self, t): + r'/' + self.add_line_column(t) + return t + + def t_ARROW(self, t): + r'=>' + self.add_line_column(t) + return t + + def t_EQUAL(self, t): + r'=' + self.add_line_column(t) + return t + + def t_LESS(self, t): + r'<' + self.add_line_column(t) + return t + + def t_LESSEQ(self, t): + r'<=' + self.add_line_column(t) + return t + + def t_NOT(self, t): + r'~' + self.add_line_column(t) + return t + + def t_INT(self, t): + r'\d+' + t.value = int(t.value) + self.add_line_column(t) + return t + + def t_ID(self, t): + r'[a-z][a-zA-Z_0-9]*' + t.type = self.reserved.get(t.value.lower(), 'ID') + self.add_line_column(t) + return t + + def t_TYPE(self, t): + r'[A-Z][a-zA-Z_0-9]*' + t.type = self.reserved.get(t.value.lower(), 'TYPE') + self.add_line_column(t) + return t + + def t_newline(self, t): + r'\n+' + t.lexer.lineno += len(t.value) + t.lexer.linestart = t.lexer.lexpos + + def t_error(self, t): + self.add_line_column(t) + self.errors.append(LexicographicError( + f'ERROR \"{t.value[0]}\"', t.line, t.column)) + t.lexer.skip(1) + + def tokenize(self, text): + self.text = text + self.lexer.input(text) + tokens = [] + for token in self.lexer: + tokens.append(Token(token.value, token.type, + token.line, token.column)) + self.lexer.lineno = 1 + self.lexer.linestart = 0 + return tokens + + def run(self, text): + tokens = self.tokenize(text) + if self.errors: + for error in self.errors: + print(error) + raise Exception() + + return tokens diff --git a/src/makefile b/src/makefile index 30df993f5..cd83fb352 100644 --- a/src/makefile +++ b/src/makefile @@ -1,12 +1,12 @@ -.PHONY: clean - -main: - # Compiling the compiler :) - -clean: - rm -rf build/* - rm -rf ../tests/*/*.mips - -test: - pytest ../tests -v --tb=short -m=${TAG} - +.PHONY: clean + +main: + # Compiling the compiler :) + +clean: + rm -rf build/* + rm -rf ../tests/*/*.mips + +test: + pytest ../tests -v --tb=short -m=${TAG} + diff --git a/src/semantic/semantic.py b/src/semantic/semantic.py index dad224b9a..b66abab7f 100644 --- a/src/semantic/semantic.py +++ b/src/semantic/semantic.py @@ -1,326 +1,326 @@ -from utils.errors import SemanticError -from collections import OrderedDict - - -class Attribute: - def __init__(self, name, typex, index, tok=None): - self.name = name - self.type = typex - self.index = index - self.expr = None - - def __str__(self): - return f'[attrib] {self.name} : {self.type.name};' - - def __repr__(self): - return str(self) - - -class Method: - def __init__(self, name, param_names, params_types, return_type): - self.name = name - self.param_names = param_names - self.param_types = params_types - self.return_type = return_type - - def __str__(self): - params = ', '.join(f'{n}:{t.name}' for n, t in zip( - self.param_names, self.param_types)) - return f'[method] {self.name}({params}): {self.return_type.name};' - - def __eq__(self, other): - return other.name == self.name and \ - other.return_type == self.return_type and \ - other.param_types == self.param_types - - -# class MethodError(Method): -# def __init__(self, name, param_names, param_types, return_types): -# super().__init__(name, param_names, param_types, return_types) - -# def __str__(self): -# return f'[method] {self.name} ERROR' - - -class Type: - def __init__(self, name: str, pos, parent=True): - if name == 'ObjectType': - return ObjectType(pos) - self.name = name - self.attributes = {} - self.methods = {} - if parent: - self.parent = ObjectType(pos) - else: - self.parent = None - self.pos = pos - - def set_parent(self, parent): - if type(self.parent) != ObjectType and self.parent is not None: - error_msg = f'Parent type is already set for {self.name}.' - raise SemanticError(error_msg, *self.pos) - self.parent = parent - - def get_attribute(self, name: str, pos) -> Attribute: - try: - return self.attributes[name] - except KeyError: - if self.parent is None: - error_msg = f'Attribute {name} is not defined in {self.name}.' - raise SemanticError(error_msg, *pos) - try: - return self.parent.get_attribute(name, pos) - except: - error_msg = f'Attribute {name} is not defined in {self.name}.' - raise SemanticError(error_msg, *pos) - - def define_attribute(self, name: str, typex, pos): - try: - self.attributes[name] - except KeyError: - try: - self.get_attribute(name, pos) - except: - self.attributes[name] = attribute = Attribute( - name, typex, len(self.attributes)) - return attribute - else: - error_msg = f'Attribute {name} is an attribute of an inherit class.' - raise SemanticError(error_msg, *pos) - else: - error_msg = f'Attribute {name} is multiply defined in class.' - raise SemanticError(error_msg, *pos) - - def get_method(self, name: str, pos) -> Method: - try: - return self.methods[name] - except KeyError: - error_msg = f'Method {name} is not defined in {self.name}.' - if self.parent is None: - raise SemanticError(error_msg, *pos) - try: - return self.parent.get_method(name, pos) - except: - raise SemanticError(error_msg, *pos) - - def define_method(self, name: str, param_names: list, param_types: list, return_type, pos=(0, 0)): - if name in self.methods: - error_msg = f'Method {name} is multiply defined' - raise SemanticError(error_msg, *pos) - - method = self.methods[name] = Method( - name, param_names, param_types, return_type) - return method - - def change_type(self, method, nparm, newtype): - idx = method.param_names.index(nparm) - method.param_types[idx] = newtype - - def all_attributes(self, clean=True): - plain = OrderedDict() if self.parent is None else self.parent.all_attributes(False) - for attr in self.attributes.values(): - plain[attr.name] = (attr, self) - return plain.values() if clean else plain - - def all_methods(self, clean=True): - plain = OrderedDict() if self.parent is None else self.parent.all_methods(False) - for method in self.methods.values(): - plain[method.name] = (method, self) - return plain.values() if clean else plain - - def conforms_to(self, other): - return other.bypass() or self == other or self.parent is not None and self.parent.conforms_to(other) - - def bypass(self): - return False - - def __str__(self): - output = f'type {self.name}' - parent = '' if self.parent is None else f' : {self.parent.name}' - output += parent - output += ' {' - output += '\n\t' if self.attributes or self.methods else '' - output += '\n\t'.join(str(x) for x in self.attributes.values()) - output += '\n\t' if self.attributes else '' - output += '\n\t'.join(str(x) for x in self.methods.values()) - output += '\n' if self.methods else '' - output += '}\n' - return output - - def __repr__(self): - return str(self) - - -class ErrorType(Type): - def __init__(self, pos=(0, 0)): - Type.__init__(self, '', pos) - - def conforms_to(self, other): - return True - - def bypass(self): - return True - - def __eq__(self, other): - return isinstance(other, ErrorType) - - def __ne__(self, other): - return not isinstance(other, ErrorType) - - -class VoidType(Type): - def __init__(self, pos=(0, 0)): - Type.__init__(self, 'Void', pos) - - def conforms_to(self, other): - return True - - def bypass(self): - return True - - def __eq__(self, other): - return isinstance(other, VoidType) - - -class BoolType(Type): - def __init__(self, pos=(0, 0)): - self.name = 'Bool' - self.attributes = {} - self.methods = {} - self.parent = None - self.pos = pos - self.init_methods() - - def init_methods(self): - self.define_method('abort', [], [], self) - self.define_method('type_name', [], [], StringType()) - self.define_method('copy', [], [], SelfType()) - - def conforms_to(self, other): - return other.name == 'Object' or other.name == self.name - - def __eq__(self, other): - return other.name == self.name or isinstance(other, BoolType) - - def __ne__(self, other): - return other.name != self.name and not isinstance(other, BoolType) - - -class SelfType(Type): - def __init__(self, pos=(0, 0)): - self.name = 'Self' - self.attributes = {} - self.methods = {} - self.parent = None - self.pos = pos - - def __eq__(self, other): - return other.name == self.name or isinstance(other, SelfType) - - def __ne__(self, other): - return other.name != self.name and not isinstance(other, SelfType) - - -class IntType(Type): - def __init__(self, pos=(0, 0)): - self.name = 'Int' - self.attributes = {} - self.methods = {} - self.parent = None - self.pos = pos - self.init_methods() - - def init_methods(self): - self.define_method('abort', [], [], self) - self.define_method('type_name', [], [], Type('String', (0, 0), False)) - self.define_method('copy', [], [], SelfType()) - - def conforms_to(self, other): - return other.name == 'Object' or other.name == self.name - - def __eq__(self, other): - return other.name == self.name or isinstance(other, IntType) - - def __ne__(self, other): - return other.name != self.name and not isinstance(other, IntType) - - -class StringType(Type): - def __init__(self, pos=(0, 0)): - self.name = 'String' - self.attributes = {} - self.methods = {} - self.parent = None - self.pos = pos - self.init_methods() - - def init_methods(self): - self.define_method('abort', [], [], self) - self.define_method('type_name', [], [], self) - self.define_method('copy', [], [], SelfType()) - self.define_method('length', [], [], IntType()) - self.define_method('concat', ['s'], [self], self) - self.define_method('substr', ['i', 'l'], [IntType(), IntType()], self) - - def conforms_to(self, other): - return other.name == 'Object' or other.name == self.name - - def __eq__(self, other): - return other.name == self.name or isinstance(other, StringType) - - def __ne__(self, other): - return other.name != self.name and not isinstance(other, StringType) - - -class ObjectType(Type): - def __init__(self, pos=(0, 0)): - self.name = 'Object' - self.attributes = {} - self.methods = {} - self.parent = None - self.pos = pos - self.init_methods() - - def init_methods(self): - self.define_method('abort', [], [], self) - self.define_method('type_name', [], [], StringType()) - self.define_method('copy', [], [], SelfType()) - - def __eq__(self, other): - return other.name == self.name or isinstance(other, ObjectType) - - def __ne__(self, other): - return other.name != self.name and not isinstance(other, ObjectType) - - -# class AutoType(Type): -# def __init__(self): -# Type.__init__(self, 'AUTO_TYPE') - -# def __eq__(self, other): -# return other.name == self.name or isinstance(other, AutoType) - -# def __ne__(self, other): -# return other.name != self.name and not isinstance(other, AutoType) - - -class IOType(Type): - def __init__(self, pos=(0, 0)): - self.name = 'IO' - self.attributes = {} - self.methods = {} - self.parent = ObjectType(pos) - self.pos = pos - self.init_methods() - - def init_methods(self): - self.define_method('out_string', ['x'], [StringType()], SelfType()) - self.define_method('out_int', ['x'], [IntType()], SelfType()) - self.define_method('in_string', [], [], StringType()) - self.define_method('in_int', [], [], IntType()) - - def __eq__(self, other): - return other.name == self.name or isinstance(other, IOType) - - def __ne__(self, other): - return other.name != self.name and not isinstance(other, IOType) +from utils.errors import SemanticError +from collections import OrderedDict + + +class Attribute: + def __init__(self, name, typex, index, tok=None): + self.name = name + self.type = typex + self.index = index + self.expr = None + + def __str__(self): + return f'[attrib] {self.name} : {self.type.name};' + + def __repr__(self): + return str(self) + + +class Method: + def __init__(self, name, param_names, params_types, return_type): + self.name = name + self.param_names = param_names + self.param_types = params_types + self.return_type = return_type + + def __str__(self): + params = ', '.join(f'{n}:{t.name}' for n, t in zip( + self.param_names, self.param_types)) + return f'[method] {self.name}({params}): {self.return_type.name};' + + def __eq__(self, other): + return other.name == self.name and \ + other.return_type == self.return_type and \ + other.param_types == self.param_types + + +# class MethodError(Method): +# def __init__(self, name, param_names, param_types, return_types): +# super().__init__(name, param_names, param_types, return_types) + +# def __str__(self): +# return f'[method] {self.name} ERROR' + + +class Type: + def __init__(self, name: str, pos, parent=True): + if name == 'ObjectType': + return ObjectType(pos) + self.name = name + self.attributes = {} + self.methods = {} + if parent: + self.parent = ObjectType(pos) + else: + self.parent = None + self.pos = pos + + def set_parent(self, parent): + if type(self.parent) != ObjectType and self.parent is not None: + error_msg = f'Parent type is already set for {self.name}.' + raise SemanticError(error_msg, *self.pos) + self.parent = parent + + def get_attribute(self, name: str, pos) -> Attribute: + try: + return self.attributes[name] + except KeyError: + if self.parent is None: + error_msg = f'Attribute {name} is not defined in {self.name}.' + raise SemanticError(error_msg, *pos) + try: + return self.parent.get_attribute(name, pos) + except: + error_msg = f'Attribute {name} is not defined in {self.name}.' + raise SemanticError(error_msg, *pos) + + def define_attribute(self, name: str, typex, pos): + try: + self.attributes[name] + except KeyError: + try: + self.get_attribute(name, pos) + except: + self.attributes[name] = attribute = Attribute( + name, typex, len(self.attributes)) + return attribute + else: + error_msg = f'Attribute {name} is an attribute of an inherit class.' + raise SemanticError(error_msg, *pos) + else: + error_msg = f'Attribute {name} is multiply defined in class.' + raise SemanticError(error_msg, *pos) + + def get_method(self, name: str, pos) -> Method: + try: + return self.methods[name] + except KeyError: + error_msg = f'Method {name} is not defined in {self.name}.' + if self.parent is None: + raise SemanticError(error_msg, *pos) + try: + return self.parent.get_method(name, pos) + except: + raise SemanticError(error_msg, *pos) + + def define_method(self, name: str, param_names: list, param_types: list, return_type, pos=(0, 0)): + if name in self.methods: + error_msg = f'Method {name} is multiply defined' + raise SemanticError(error_msg, *pos) + + method = self.methods[name] = Method( + name, param_names, param_types, return_type) + return method + + def change_type(self, method, nparm, newtype): + idx = method.param_names.index(nparm) + method.param_types[idx] = newtype + + def all_attributes(self, clean=True): + plain = OrderedDict() if self.parent is None else self.parent.all_attributes(False) + for attr in self.attributes.values(): + plain[attr.name] = (attr, self) + return plain.values() if clean else plain + + def all_methods(self, clean=True): + plain = OrderedDict() if self.parent is None else self.parent.all_methods(False) + for method in self.methods.values(): + plain[method.name] = (method, self) + return plain.values() if clean else plain + + def conforms_to(self, other): + return other.bypass() or self == other or self.parent is not None and self.parent.conforms_to(other) + + def bypass(self): + return False + + def __str__(self): + output = f'type {self.name}' + parent = '' if self.parent is None else f' : {self.parent.name}' + output += parent + output += ' {' + output += '\n\t' if self.attributes or self.methods else '' + output += '\n\t'.join(str(x) for x in self.attributes.values()) + output += '\n\t' if self.attributes else '' + output += '\n\t'.join(str(x) for x in self.methods.values()) + output += '\n' if self.methods else '' + output += '}\n' + return output + + def __repr__(self): + return str(self) + + +class ErrorType(Type): + def __init__(self, pos=(0, 0)): + Type.__init__(self, '', pos) + + def conforms_to(self, other): + return True + + def bypass(self): + return True + + def __eq__(self, other): + return isinstance(other, ErrorType) + + def __ne__(self, other): + return not isinstance(other, ErrorType) + + +class VoidType(Type): + def __init__(self, pos=(0, 0)): + Type.__init__(self, 'Void', pos) + + def conforms_to(self, other): + return True + + def bypass(self): + return True + + def __eq__(self, other): + return isinstance(other, VoidType) + + +class BoolType(Type): + def __init__(self, pos=(0, 0)): + self.name = 'Bool' + self.attributes = {} + self.methods = {} + self.parent = None + self.pos = pos + self.init_methods() + + def init_methods(self): + self.define_method('abort', [], [], self) + self.define_method('type_name', [], [], StringType()) + self.define_method('copy', [], [], SelfType()) + + def conforms_to(self, other): + return other.name == 'Object' or other.name == self.name + + def __eq__(self, other): + return other.name == self.name or isinstance(other, BoolType) + + def __ne__(self, other): + return other.name != self.name and not isinstance(other, BoolType) + + +class SelfType(Type): + def __init__(self, pos=(0, 0)): + self.name = 'Self' + self.attributes = {} + self.methods = {} + self.parent = None + self.pos = pos + + def __eq__(self, other): + return other.name == self.name or isinstance(other, SelfType) + + def __ne__(self, other): + return other.name != self.name and not isinstance(other, SelfType) + + +class IntType(Type): + def __init__(self, pos=(0, 0)): + self.name = 'Int' + self.attributes = {} + self.methods = {} + self.parent = None + self.pos = pos + self.init_methods() + + def init_methods(self): + self.define_method('abort', [], [], self) + self.define_method('type_name', [], [], Type('String', (0, 0), False)) + self.define_method('copy', [], [], SelfType()) + + def conforms_to(self, other): + return other.name == 'Object' or other.name == self.name + + def __eq__(self, other): + return other.name == self.name or isinstance(other, IntType) + + def __ne__(self, other): + return other.name != self.name and not isinstance(other, IntType) + + +class StringType(Type): + def __init__(self, pos=(0, 0)): + self.name = 'String' + self.attributes = {} + self.methods = {} + self.parent = None + self.pos = pos + self.init_methods() + + def init_methods(self): + self.define_method('abort', [], [], self) + self.define_method('type_name', [], [], self) + self.define_method('copy', [], [], SelfType()) + self.define_method('length', [], [], IntType()) + self.define_method('concat', ['s'], [self], self) + self.define_method('substr', ['i', 'l'], [IntType(), IntType()], self) + + def conforms_to(self, other): + return other.name == 'Object' or other.name == self.name + + def __eq__(self, other): + return other.name == self.name or isinstance(other, StringType) + + def __ne__(self, other): + return other.name != self.name and not isinstance(other, StringType) + + +class ObjectType(Type): + def __init__(self, pos=(0, 0)): + self.name = 'Object' + self.attributes = {} + self.methods = {} + self.parent = None + self.pos = pos + self.init_methods() + + def init_methods(self): + self.define_method('abort', [], [], self) + self.define_method('type_name', [], [], StringType()) + self.define_method('copy', [], [], SelfType()) + + def __eq__(self, other): + return other.name == self.name or isinstance(other, ObjectType) + + def __ne__(self, other): + return other.name != self.name and not isinstance(other, ObjectType) + + +# class AutoType(Type): +# def __init__(self): +# Type.__init__(self, 'AUTO_TYPE') + +# def __eq__(self, other): +# return other.name == self.name or isinstance(other, AutoType) + +# def __ne__(self, other): +# return other.name != self.name and not isinstance(other, AutoType) + + +class IOType(Type): + def __init__(self, pos=(0, 0)): + self.name = 'IO' + self.attributes = {} + self.methods = {} + self.parent = ObjectType(pos) + self.pos = pos + self.init_methods() + + def init_methods(self): + self.define_method('out_string', ['x'], [StringType()], SelfType()) + self.define_method('out_int', ['x'], [IntType()], SelfType()) + self.define_method('in_string', [], [], StringType()) + self.define_method('in_int', [], [], IntType()) + + def __eq__(self, other): + return other.name == self.name or isinstance(other, IOType) + + def __ne__(self, other): + return other.name != self.name and not isinstance(other, IOType) diff --git a/src/semantic/types.py b/src/semantic/types.py index b455aa253..4970d29ab 100644 --- a/src/semantic/types.py +++ b/src/semantic/types.py @@ -1,111 +1,111 @@ -from utils.errors import SemanticError - - -class Attribute: - def __init__(self, name, typex, index): - self.name = name - self.type = typex - self.index = index - self.expr = None - - def __str__(self): - return f'[attr] {self.name} : {self.type.name}' - - def __repr__(self): - return str(self) - - -class Method: - def __init__(self, name, param_names, param_types, return_type): - self.name = name - self.param_names = param_names - self.param_types = param_types - self.return_type = return_type - - -class Type: - def __init__(self, name, position, parent=True): - if name == 'ObjectType': - return ObjectType(position) - self.name = name - self.attributes = {} - self.methods = {} - self.position = position - if parent: - self.parent = ObjectType(position) - else: - self.parent = None - - def set_parent(self, parent): - if type(self.parent) != ObjectType and self.parent is not None: - line, column = self.position - raise SemanticError( - f'Parent already defined for {self.name}', line, column) - self.parent = parent - - def get_attribute(self, name, position): - try: - return self.attributes[name] - except KeyError: - if self.parent is None: - line, column = self.position - raise SemanticError( - f'Attribute {name} is not defined in {self.name}', line, column) - try: - return self.parent.get_attribute(name, position) - except: - line, column = self.position - raise SemanticError( - f'Attribute {name} is not defined in {self.name}', line, column) - - def define_attribute(self, name, typex, position): - try: - self.attributes[name] - except KeyError: - try: - self.get_attribute(name, position) - except SemanticError(): - attribute = Attribute(name, typex, len(self.attributes)) - self.attributes[name] = attribute - return attribute - else: - line, column = self.position - raise SemanticError( - f'Attribute {name} is an attribute of an inherited class', line, column) - else: - line, column = self.position - raise SemanticError( - f'Attribute {name} is already defined', line, column) - - def get_method(self, name, position): - try: - return self.methods[name] - except KeyError: - if self.parent is None: - line, column = self.position - raise SemanticError( - f'Method {name} is not defined in {self.name}', line, column) - try: - return self.parent.get_method(name, position) - except: - line, column = self.position - raise SemanticError( - f'Method {name} is not defined in {self.name}', line, column) - - def define_method(self, name, param_names, param_types, return_type, position=(0, 0)): - if name in self.methods: - line, column = self.position - raise SemanticError( - f'Method {name} is already defined', line, column) - - method = self.methods[name] = Method(name, param_names, param_types, return_type) - return method - - -class ObjectType(Type): - def __init__(self, position=(0, 0)): - self.name = 'Object' - self.attributes = {} - self.methods = {} - self.parent = None - self.position = position +from utils.errors import SemanticError + + +class Attribute: + def __init__(self, name, typex, index): + self.name = name + self.type = typex + self.index = index + self.expr = None + + def __str__(self): + return f'[attr] {self.name} : {self.type.name}' + + def __repr__(self): + return str(self) + + +class Method: + def __init__(self, name, param_names, param_types, return_type): + self.name = name + self.param_names = param_names + self.param_types = param_types + self.return_type = return_type + + +class Type: + def __init__(self, name, position, parent=True): + if name == 'ObjectType': + return ObjectType(position) + self.name = name + self.attributes = {} + self.methods = {} + self.position = position + if parent: + self.parent = ObjectType(position) + else: + self.parent = None + + def set_parent(self, parent): + if type(self.parent) != ObjectType and self.parent is not None: + line, column = self.position + raise SemanticError( + f'Parent already defined for {self.name}', line, column) + self.parent = parent + + def get_attribute(self, name, position): + try: + return self.attributes[name] + except KeyError: + if self.parent is None: + line, column = self.position + raise SemanticError( + f'Attribute {name} is not defined in {self.name}', line, column) + try: + return self.parent.get_attribute(name, position) + except: + line, column = self.position + raise SemanticError( + f'Attribute {name} is not defined in {self.name}', line, column) + + def define_attribute(self, name, typex, position): + try: + self.attributes[name] + except KeyError: + try: + self.get_attribute(name, position) + except SemanticError(): + attribute = Attribute(name, typex, len(self.attributes)) + self.attributes[name] = attribute + return attribute + else: + line, column = self.position + raise SemanticError( + f'Attribute {name} is an attribute of an inherited class', line, column) + else: + line, column = self.position + raise SemanticError( + f'Attribute {name} is already defined', line, column) + + def get_method(self, name, position): + try: + return self.methods[name] + except KeyError: + if self.parent is None: + line, column = self.position + raise SemanticError( + f'Method {name} is not defined in {self.name}', line, column) + try: + return self.parent.get_method(name, position) + except: + line, column = self.position + raise SemanticError( + f'Method {name} is not defined in {self.name}', line, column) + + def define_method(self, name, param_names, param_types, return_type, position=(0, 0)): + if name in self.methods: + line, column = self.position + raise SemanticError( + f'Method {name} is already defined', line, column) + + method = self.methods[name] = Method(name, param_names, param_types, return_type) + return method + + +class ObjectType(Type): + def __init__(self, position=(0, 0)): + self.name = 'Object' + self.attributes = {} + self.methods = {} + self.parent = None + self.position = position diff --git a/src/semantic/visitors/type_collector.py b/src/semantic/visitors/type_collector.py index 90e806da6..795e94dd6 100644 --- a/src/semantic/visitors/type_collector.py +++ b/src/semantic/visitors/type_collector.py @@ -1,25 +1,25 @@ -from utils import visitor -from utils.ast import ProgramNode, ClassDeclarationNode -from semantic. - - - - - -class TypeCollector(object): - def __init__(self, errors = []): - self.context = None - self.errors = errors - - @visitor.on('node') - def visit(self, node): - pass - - - @visitor.when(ProgramNode) - def visit(self, node): - self.context = Context() - - @visitor.when(ClassDeclarationNode) - def visit(self, node): - pass +from utils import visitor +from utils.ast import ProgramNode, ClassDeclarationNode +from semantic. + + + + + +class TypeCollector(object): + def __init__(self, errors = []): + self.context = None + self.errors = errors + + @visitor.on('node') + def visit(self, node): + pass + + + @visitor.when(ProgramNode) + def visit(self, node): + self.context = Context() + + @visitor.when(ClassDeclarationNode) + def visit(self, node): + pass diff --git a/src/test.cl b/src/test.cl index 2cbd6819c..d01d577f2 100644 --- a/src/test.cl +++ b/src/test.cl @@ -1,10 +1,10 @@ -class Main inherits IO { - a : String <- case 1 of - n : Main => n.type_name(); - a : Int => a.type_name(); - esac; - - main(): IO { - out_string(a) - }; +class Main inherits IO { + a : String <- case 1 of + n : Main => n.type_name(); + a : Int => a.type_name(); + esac; + + main(): IO { + out_string(a) + }; }; \ No newline at end of file diff --git a/src/utils/__init__.py b/src/utils/__init__.py index 1a7eeac05..3676a62d6 100644 --- a/src/utils/__init__.py +++ b/src/utils/__init__.py @@ -1,2 +1,2 @@ -from .utils import find_column, Token +from .utils import find_column, Token from .errors import LexicographicError, SemanticError, SyntacticError \ No newline at end of file diff --git a/src/utils/ast.py b/src/utils/ast.py index 41d19f021..916613d54 100644 --- a/src/utils/ast.py +++ b/src/utils/ast.py @@ -1,200 +1,200 @@ -class Node(): - def __init__(self): - self.line = 0 - self.column = 0 - - def add_line_column(self, line, column): - self.line = line - self.column = column - - -class ProgramNode(Node): - def __init__(self, classes): - super().__init__() - self.classes = classes - - -class ClassDeclarationNode(Node): - def __init__(self, name, features, parent=None): - super().__init__() - self.name = name - self.features = features - self.parent = parent - - -class FuncDeclarationNode(Node): - def __init__(self, name, params, return_type, expr=None): - super().__init__() - self.name = name - self.params = params - self.return_type = return_type - self.expr = expr - - -class AttrDeclarationNode(Node): - def __init__(self, name, typex, expr=None): - super().__init__() - self.name = name - self.type = typex - self.expr = expr - - -class ExpressionNode(Node): - def __init__(self): - super().__init__() - self.computed_type = None - - -class AssignNode(ExpressionNode): - def __init__(self, name, expr): - super().__init__() - self.name = name - self.expr = expr - - -class FuncCallNode(ExpressionNode): - def __init__(self, idx, args, obj=None, typex=None): - super().__init__() - self.id = idx - self.args = args - self.object = obj - self.type = typex - - -class IfNode(ExpressionNode): - def __init__(self, condition, then_expr, else_expr): - super().__init__() - self.condition = condition - self.then_expr = then_expr - self.else_expr = else_expr - - -class WhileNode(ExpressionNode): - def __init__(self, condition, body): - super().__init__() - self.condition = condition - self.body = body - - -class BlockNode(ExpressionNode): - def __init__(self, exprs): - super().__init__() - self.exprs = exprs - - -class LetNode(ExpressionNode): - def __init__(self, let_attrs, expr): - super().__init__() - self.let_attrs = let_attrs - self.expr = expr - - -class CaseNode(ExpressionNode): - def __init__(self, expr, case_list): - super().__init__() - self.expr = expr - self.case_list = case_list - - -class CaseOptionNode(ExpressionNode): - def __init__(self, idx, typex, expr): - super().__init__() - self.id = idx - self.expr = expr - self.type = typex - - -class VarNode(ExpressionNode): - def __init__(self, idx): - super().__init__() - self.id = idx - - -class NewNode(ExpressionNode): - def __init__(self, typex): - super().__init__() - self.type = typex - - -# ---------------- Binary Nodes ------------------ - -class BinaryNode(ExpressionNode): - def __init__(self, lvalue, rvalue): - super().__init__() - self.lvalue = lvalue - self.rvalue = rvalue - - -class PlusNode(BinaryNode): - pass - - -class MinusNode(BinaryNode): - pass - - -class StarNode(BinaryNode): - pass - - -class DivNode(BinaryNode): - pass - - -class LessNode(BinaryNode): - pass - - -class LessEqNode(BinaryNode): - pass - - -class EqualNode(BinaryNode): - pass - - -# ---------------- Unary Nodes ------------------ - -class UnaryNode(ExpressionNode): - def __init__(self, value): - super().__init__() - self.value = value - - -class NegationNode(UnaryNode): - pass - - -class LogicNegationNode(UnaryNode): - pass - - -class AtomicNode(UnaryNode): - pass - - -class IsVoidNode(UnaryNode): - pass - -class SelfNode(UnaryNode): - pass - - -# ---------------- Constant Nodes ------------------ - -class ConstantNode(ExpressionNode): - def __init__(self, value): - super().__init__() - self.value = value - - -class IntNode(ConstantNode): - pass - - -class BoolNode(ConstantNode): - pass - - -class StringNode(ConstantNode): - pass +class Node(): + def __init__(self): + self.line = 0 + self.column = 0 + + def add_line_column(self, line, column): + self.line = line + self.column = column + + +class ProgramNode(Node): + def __init__(self, classes): + super().__init__() + self.classes = classes + + +class ClassDeclarationNode(Node): + def __init__(self, name, features, parent=None): + super().__init__() + self.name = name + self.features = features + self.parent = parent + + +class FuncDeclarationNode(Node): + def __init__(self, name, params, return_type, expr=None): + super().__init__() + self.name = name + self.params = params + self.return_type = return_type + self.expr = expr + + +class AttrDeclarationNode(Node): + def __init__(self, name, typex, expr=None): + super().__init__() + self.name = name + self.type = typex + self.expr = expr + + +class ExpressionNode(Node): + def __init__(self): + super().__init__() + self.computed_type = None + + +class AssignNode(ExpressionNode): + def __init__(self, name, expr): + super().__init__() + self.name = name + self.expr = expr + + +class FuncCallNode(ExpressionNode): + def __init__(self, idx, args, obj=None, typex=None): + super().__init__() + self.id = idx + self.args = args + self.object = obj + self.type = typex + + +class IfNode(ExpressionNode): + def __init__(self, condition, then_expr, else_expr): + super().__init__() + self.condition = condition + self.then_expr = then_expr + self.else_expr = else_expr + + +class WhileNode(ExpressionNode): + def __init__(self, condition, body): + super().__init__() + self.condition = condition + self.body = body + + +class BlockNode(ExpressionNode): + def __init__(self, exprs): + super().__init__() + self.exprs = exprs + + +class LetNode(ExpressionNode): + def __init__(self, let_attrs, expr): + super().__init__() + self.let_attrs = let_attrs + self.expr = expr + + +class CaseNode(ExpressionNode): + def __init__(self, expr, case_list): + super().__init__() + self.expr = expr + self.case_list = case_list + + +class CaseOptionNode(ExpressionNode): + def __init__(self, idx, typex, expr): + super().__init__() + self.id = idx + self.expr = expr + self.type = typex + + +class VarNode(ExpressionNode): + def __init__(self, idx): + super().__init__() + self.id = idx + + +class NewNode(ExpressionNode): + def __init__(self, typex): + super().__init__() + self.type = typex + + +# ---------------- Binary Nodes ------------------ + +class BinaryNode(ExpressionNode): + def __init__(self, lvalue, rvalue): + super().__init__() + self.lvalue = lvalue + self.rvalue = rvalue + + +class PlusNode(BinaryNode): + pass + + +class MinusNode(BinaryNode): + pass + + +class StarNode(BinaryNode): + pass + + +class DivNode(BinaryNode): + pass + + +class LessNode(BinaryNode): + pass + + +class LessEqNode(BinaryNode): + pass + + +class EqualNode(BinaryNode): + pass + + +# ---------------- Unary Nodes ------------------ + +class UnaryNode(ExpressionNode): + def __init__(self, value): + super().__init__() + self.value = value + + +class NegationNode(UnaryNode): + pass + + +class LogicNegationNode(UnaryNode): + pass + + +class AtomicNode(UnaryNode): + pass + + +class IsVoidNode(UnaryNode): + pass + +class SelfNode(UnaryNode): + pass + + +# ---------------- Constant Nodes ------------------ + +class ConstantNode(ExpressionNode): + def __init__(self, value): + super().__init__() + self.value = value + + +class IntNode(ConstantNode): + pass + + +class BoolNode(ConstantNode): + pass + + +class StringNode(ConstantNode): + pass diff --git a/src/utils/utils.py b/src/utils/utils.py index af9b2d8ad..d28665c52 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -1,65 +1,65 @@ -def find_column(text, pos): - line_start = text.rfind('\n', 0, pos) + 1 - return (pos - line_start) + 1 - - -class Token: - def __init__(self, lex, token_type, row, column): - self.lex = lex - self.type = token_type - self.line = row - self.column = column - - def __str__(self): - return f'{self.type}: {self.lex} ({self.line}, {self.column})' - - def __repr__(self): - return str(self) - - -reserved = { - 'class': 'CLASS', - 'else': 'ELSE', - 'fi': 'FI', - 'if': 'IF', - 'in': 'IN', - 'inherits': 'INHERITS', - 'isvoid': 'ISVOID', - 'let': 'LET', - 'loop': 'LOOP', - 'pool': 'POOL', - 'then': 'THEN', - 'while': 'WHILE', - 'case': 'CASE', - 'esac': 'ESAC', - 'new': 'NEW', - 'of': 'OF', - 'not': 'LNOT' -} - -tokens = [ - 'ID', - 'TYPE', - 'LPAREN', - 'RPAREN', - 'LBRACE', - 'RBRACE', - 'COLON', - 'SEMICOLON', - 'COMMA', - 'DOT', - 'AT', - 'ASSIGN', - 'PLUS', - 'MINUS', - 'STAR', - 'DIV', - 'EQUAL', - 'LESS', - 'LESSEQ', - 'ARROW', - 'INT', - 'STRING', - 'NOT', - 'BOOL' -] + list(reserved.values()) +def find_column(text, pos): + line_start = text.rfind('\n', 0, pos) + 1 + return (pos - line_start) + 1 + + +class Token: + def __init__(self, lex, token_type, row, column): + self.lex = lex + self.type = token_type + self.line = row + self.column = column + + def __str__(self): + return f'{self.type}: {self.lex} ({self.line}, {self.column})' + + def __repr__(self): + return str(self) + + +reserved = { + 'class': 'CLASS', + 'else': 'ELSE', + 'fi': 'FI', + 'if': 'IF', + 'in': 'IN', + 'inherits': 'INHERITS', + 'isvoid': 'ISVOID', + 'let': 'LET', + 'loop': 'LOOP', + 'pool': 'POOL', + 'then': 'THEN', + 'while': 'WHILE', + 'case': 'CASE', + 'esac': 'ESAC', + 'new': 'NEW', + 'of': 'OF', + 'not': 'LNOT' +} + +tokens = [ + 'ID', + 'TYPE', + 'LPAREN', + 'RPAREN', + 'LBRACE', + 'RBRACE', + 'COLON', + 'SEMICOLON', + 'COMMA', + 'DOT', + 'AT', + 'ASSIGN', + 'PLUS', + 'MINUS', + 'STAR', + 'DIV', + 'EQUAL', + 'LESS', + 'LESSEQ', + 'ARROW', + 'INT', + 'STRING', + 'NOT', + 'BOOL' +] + list(reserved.values()) diff --git a/src/utils/visitor.py b/src/utils/visitor.py index d4f2e4d7c..aece92ec4 100644 --- a/src/utils/visitor.py +++ b/src/utils/visitor.py @@ -1,82 +1,82 @@ -# The MIT License (MIT) -# -# Copyright (c) 2013 Curtis Schlak -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - -import inspect - -__all__ = ['on', 'when'] - - -def on(param_name): - def f(fn): - dispatcher = Dispatcher(param_name, fn) - return dispatcher - return f - - -def when(param_type): - def f(fn): - frame = inspect.currentframe().f_back - func_name = fn.func_name if 'func_name' in dir(fn) else fn.__name__ - dispatcher = frame.f_locals[func_name] - if not isinstance(dispatcher, Dispatcher): - dispatcher = dispatcher.dispatcher - dispatcher.add_target(param_type, fn) - - def ff(*args, **kw): - return dispatcher(*args, **kw) - ff.dispatcher = dispatcher - return ff - return f - - -class Dispatcher(object): - def __init__(self, param_name, fn): - frame = inspect.currentframe().f_back.f_back - top_level = frame.f_locals == frame.f_globals - self.param_index = self.__argspec(fn).args.index(param_name) - self.param_name = param_name - self.targets = {} - - def __call__(self, *args, **kw): - typ = args[self.param_index].__class__ - d = self.targets.get(typ) - if d is not None: - return d(*args, **kw) - else: - issub = issubclass - t = self.targets - ks = t.keys() - ans = [t[k](*args, **kw) for k in ks if issub(typ, k)] - if len(ans) == 1: - return ans.pop() - return ans - - def add_target(self, typ, target): - self.targets[typ] = target - - @staticmethod - def __argspec(fn): - # Support for Python 3 type hints requires inspect.getfullargspec - if hasattr(inspect, 'getfullargspec'): - return inspect.getfullargspec(fn) - else: - return inspect.getargspec(fn) +# The MIT License (MIT) +# +# Copyright (c) 2013 Curtis Schlak +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +import inspect + +__all__ = ['on', 'when'] + + +def on(param_name): + def f(fn): + dispatcher = Dispatcher(param_name, fn) + return dispatcher + return f + + +def when(param_type): + def f(fn): + frame = inspect.currentframe().f_back + func_name = fn.func_name if 'func_name' in dir(fn) else fn.__name__ + dispatcher = frame.f_locals[func_name] + if not isinstance(dispatcher, Dispatcher): + dispatcher = dispatcher.dispatcher + dispatcher.add_target(param_type, fn) + + def ff(*args, **kw): + return dispatcher(*args, **kw) + ff.dispatcher = dispatcher + return ff + return f + + +class Dispatcher(object): + def __init__(self, param_name, fn): + frame = inspect.currentframe().f_back.f_back + top_level = frame.f_locals == frame.f_globals + self.param_index = self.__argspec(fn).args.index(param_name) + self.param_name = param_name + self.targets = {} + + def __call__(self, *args, **kw): + typ = args[self.param_index].__class__ + d = self.targets.get(typ) + if d is not None: + return d(*args, **kw) + else: + issub = issubclass + t = self.targets + ks = t.keys() + ans = [t[k](*args, **kw) for k in ks if issub(typ, k)] + if len(ans) == 1: + return ans.pop() + return ans + + def add_target(self, typ, target): + self.targets[typ] = target + + @staticmethod + def __argspec(fn): + # Support for Python 3 type hints requires inspect.getfullargspec + if hasattr(inspect, 'getfullargspec'): + return inspect.getfullargspec(fn) + else: + return inspect.getargspec(fn) diff --git a/tests/codegen/arith.cl b/tests/codegen/arith.cl index af5951cf7..0d9f5dd33 100755 --- a/tests/codegen/arith.cl +++ b/tests/codegen/arith.cl @@ -1,430 +1,430 @@ -(* - * A contribution from Anne Sheets (sheets@cory) - * - * Tests the arithmetic operations and various other things - *) - -class A { - - var : Int <- 0; - - value() : Int { var }; - - set_var(num : Int) : A{ - { - var <- num; - self; - } - }; - - method1(num : Int) : A { -- same - self - }; - - method2(num1 : Int, num2 : Int) : A { -- plus - (let x : Int in - { - x <- num1 + num2; - (new B).set_var(x); - } - ) - }; - - method3(num : Int) : A { -- negate - (let x : Int in - { - x <- ~num; - (new C).set_var(x); - } - ) - }; - - method4(num1 : Int, num2 : Int) : A { -- diff - if num2 < num1 then - (let x : Int in - { - x <- num1 - num2; - (new D).set_var(x); - } - ) - else - (let x : Int in - { - x <- num2 - num1; - (new D).set_var(x); - } - ) - fi - }; - - method5(num : Int) : A { -- factorial - (let x : Int <- 1 in - { - (let y : Int <- 1 in - while y <= num loop - { - x <- x * y; - y <- y + 1; - } - pool - ); - (new E).set_var(x); - } - ) - }; - -}; - -class B inherits A { -- B is a number squared - - method5(num : Int) : A { -- square - (let x : Int in - { - x <- num * num; - (new E).set_var(x); - } - ) - }; - -}; - -class C inherits B { - - method6(num : Int) : A { -- negate - (let x : Int in - { - x <- ~num; - (new A).set_var(x); - } - ) - }; - - method5(num : Int) : A { -- cube - (let x : Int in - { - x <- num * num * num; - (new E).set_var(x); - } - ) - }; - -}; - -class D inherits B { - - method7(num : Int) : Bool { -- divisible by 3 - (let x : Int <- num in - if x < 0 then method7(~x) else - if 0 = x then true else - if 1 = x then false else - if 2 = x then false else - method7(x - 3) - fi fi fi fi - ) - }; - -}; - -class E inherits D { - - method6(num : Int) : A { -- division - (let x : Int in - { - x <- num / 8; - (new A).set_var(x); - } - ) - }; - -}; - -(* The following code is from atoi.cl in ~cs164/examples *) - -(* - The class A2I provides integer-to-string and string-to-integer -conversion routines. To use these routines, either inherit them -in the class where needed, have a dummy variable bound to -something of type A2I, or simpl write (new A2I).method(argument). -*) - - -(* - c2i Converts a 1-character string to an integer. Aborts - if the string is not "0" through "9" -*) -class A2I { - - c2i(char : String) : Int { - if char = "0" then 0 else - if char = "1" then 1 else - if char = "2" then 2 else - if char = "3" then 3 else - if char = "4" then 4 else - if char = "5" then 5 else - if char = "6" then 6 else - if char = "7" then 7 else - if char = "8" then 8 else - if char = "9" then 9 else - { abort(); 0; } (* the 0 is needed to satisfy the - typchecker *) - fi fi fi fi fi fi fi fi fi fi - }; - -(* - i2c is the inverse of c2i. -*) - i2c(i : Int) : String { - if i = 0 then "0" else - if i = 1 then "1" else - if i = 2 then "2" else - if i = 3 then "3" else - if i = 4 then "4" else - if i = 5 then "5" else - if i = 6 then "6" else - if i = 7 then "7" else - if i = 8 then "8" else - if i = 9 then "9" else - { abort(); ""; } -- the "" is needed to satisfy the typchecker - fi fi fi fi fi fi fi fi fi fi - }; - -(* - a2i converts an ASCII string into an integer. The empty string -is converted to 0. Signed and unsigned strings are handled. The -method aborts if the string does not represent an integer. Very -long strings of digits produce strange answers because of arithmetic -overflow. - -*) - a2i(s : String) : Int { - if s.length() = 0 then 0 else - if s.substr(0,1) = "-" then ~a2i_aux(s.substr(1,s.length()-1)) else - if s.substr(0,1) = "+" then a2i_aux(s.substr(1,s.length()-1)) else - a2i_aux(s) - fi fi fi - }; - -(* a2i_aux converts the usigned portion of the string. As a - programming example, this method is written iteratively. *) - - - a2i_aux(s : String) : Int { - (let int : Int <- 0 in - { - (let j : Int <- s.length() in - (let i : Int <- 0 in - while i < j loop - { - int <- int * 10 + c2i(s.substr(i,1)); - i <- i + 1; - } - pool - ) - ); - int; - } - ) - }; - -(* i2a converts an integer to a string. Positive and negative - numbers are handled correctly. *) - - i2a(i : Int) : String { - if i = 0 then "0" else - if 0 < i then i2a_aux(i) else - "-".concat(i2a_aux(i * ~1)) - fi fi - }; - -(* i2a_aux is an example using recursion. *) - - i2a_aux(i : Int) : String { - if i = 0 then "" else - (let next : Int <- i / 10 in - i2a_aux(next).concat(i2c(i - next * 10)) - ) - fi - }; - -}; - -class Main inherits IO { - - char : String; - avar : A; - a_var : A; - flag : Bool <- true; - - - menu() : String { - { - out_string("\n\tTo add a number to "); - print(avar); - out_string("...enter a:\n"); - out_string("\tTo negate "); - print(avar); - out_string("...enter b:\n"); - out_string("\tTo find the difference between "); - print(avar); - out_string("and another number...enter c:\n"); - out_string("\tTo find the factorial of "); - print(avar); - out_string("...enter d:\n"); - out_string("\tTo square "); - print(avar); - out_string("...enter e:\n"); - out_string("\tTo cube "); - print(avar); - out_string("...enter f:\n"); - out_string("\tTo find out if "); - print(avar); - out_string("is a multiple of 3...enter g:\n"); - out_string("\tTo divide "); - print(avar); - out_string("by 8...enter h:\n"); - out_string("\tTo get a new number...enter j:\n"); - out_string("\tTo quit...enter q:\n\n"); - in_string(); - } - }; - - prompt() : String { - { - out_string("\n"); - out_string("Please enter a number... "); - in_string(); - } - }; - - get_int() : Int { - { - (let z : A2I <- new A2I in - (let s : String <- prompt() in - z.a2i(s) - ) - ); - } - }; - - is_even(num : Int) : Bool { - (let x : Int <- num in - if x < 0 then is_even(~x) else - if 0 = x then true else - if 1 = x then false else - is_even(x - 2) - fi fi fi - ) - }; - - class_type(var : A) : IO { - case var of - a : A => out_string("Class type is now A\n"); - b : B => out_string("Class type is now B\n"); - c : C => out_string("Class type is now C\n"); - d : D => out_string("Class type is now D\n"); - e : E => out_string("Class type is now E\n"); - o : Object => out_string("Oooops\n"); - esac - }; - - print(var : A) : IO { - (let z : A2I <- new A2I in - { - out_string(z.i2a(var.value())); - out_string(" "); - } - ) - }; - - main() : Object { - { - avar <- (new A); - while flag loop - { - -- avar <- (new A).set_var(get_int()); - out_string("number "); - print(avar); - if is_even(avar.value()) then - out_string("is even!\n") - else - out_string("is odd!\n") - fi; - -- print(avar); -- prints out answer - class_type(avar); - char <- menu(); - if char = "a" then -- add - { - a_var <- (new A).set_var(get_int()); - avar <- (new B).method2(avar.value(), a_var.value()); - } else - if char = "b" then -- negate - case avar of - c : C => avar <- c.method6(c.value()); - a : A => avar <- a.method3(a.value()); - o : Object => { - out_string("Oooops\n"); - abort(); 0; - }; - esac else - if char = "c" then -- diff - { - a_var <- (new A).set_var(get_int()); - avar <- (new D).method4(avar.value(), a_var.value()); - } else - if char = "d" then avar <- (new C)@A.method5(avar.value()) else - -- factorial - if char = "e" then avar <- (new C)@B.method5(avar.value()) else - -- square - if char = "f" then avar <- (new C)@C.method5(avar.value()) else - -- cube - if char = "g" then -- multiple of 3? - if ((new D).method7(avar.value())) - then -- avar <- (new A).method1(avar.value()) - { - out_string("number "); - print(avar); - out_string("is divisible by 3.\n"); - } - else -- avar <- (new A).set_var(0) - { - out_string("number "); - print(avar); - out_string("is not divisible by 3.\n"); - } - fi else - if char = "h" then - (let x : A in - { - x <- (new E).method6(avar.value()); - (let r : Int <- (avar.value() - (x.value() * 8)) in - { - out_string("number "); - print(avar); - out_string("is equal to "); - print(x); - out_string("times 8 with a remainder of "); - (let a : A2I <- new A2I in - { - out_string(a.i2a(r)); - out_string("\n"); - } - ); -- end let a: - } - ); -- end let r: - avar <- x; - } - ) -- end let x: - else - if char = "j" then avar <- (new A) - else - if char = "q" then flag <- false - else - avar <- (new A).method1(avar.value()) -- divide/8 - fi fi fi fi fi fi fi fi fi fi; - } - pool; - } - }; - -}; - +(* + * A contribution from Anne Sheets (sheets@cory) + * + * Tests the arithmetic operations and various other things + *) + +class A { + + var : Int <- 0; + + value() : Int { var }; + + set_var(num : Int) : A{ + { + var <- num; + self; + } + }; + + method1(num : Int) : A { -- same + self + }; + + method2(num1 : Int, num2 : Int) : A { -- plus + (let x : Int in + { + x <- num1 + num2; + (new B).set_var(x); + } + ) + }; + + method3(num : Int) : A { -- negate + (let x : Int in + { + x <- ~num; + (new C).set_var(x); + } + ) + }; + + method4(num1 : Int, num2 : Int) : A { -- diff + if num2 < num1 then + (let x : Int in + { + x <- num1 - num2; + (new D).set_var(x); + } + ) + else + (let x : Int in + { + x <- num2 - num1; + (new D).set_var(x); + } + ) + fi + }; + + method5(num : Int) : A { -- factorial + (let x : Int <- 1 in + { + (let y : Int <- 1 in + while y <= num loop + { + x <- x * y; + y <- y + 1; + } + pool + ); + (new E).set_var(x); + } + ) + }; + +}; + +class B inherits A { -- B is a number squared + + method5(num : Int) : A { -- square + (let x : Int in + { + x <- num * num; + (new E).set_var(x); + } + ) + }; + +}; + +class C inherits B { + + method6(num : Int) : A { -- negate + (let x : Int in + { + x <- ~num; + (new A).set_var(x); + } + ) + }; + + method5(num : Int) : A { -- cube + (let x : Int in + { + x <- num * num * num; + (new E).set_var(x); + } + ) + }; + +}; + +class D inherits B { + + method7(num : Int) : Bool { -- divisible by 3 + (let x : Int <- num in + if x < 0 then method7(~x) else + if 0 = x then true else + if 1 = x then false else + if 2 = x then false else + method7(x - 3) + fi fi fi fi + ) + }; + +}; + +class E inherits D { + + method6(num : Int) : A { -- division + (let x : Int in + { + x <- num / 8; + (new A).set_var(x); + } + ) + }; + +}; + +(* The following code is from atoi.cl in ~cs164/examples *) + +(* + The class A2I provides integer-to-string and string-to-integer +conversion routines. To use these routines, either inherit them +in the class where needed, have a dummy variable bound to +something of type A2I, or simpl write (new A2I).method(argument). +*) + + +(* + c2i Converts a 1-character string to an integer. Aborts + if the string is not "0" through "9" +*) +class A2I { + + c2i(char : String) : Int { + if char = "0" then 0 else + if char = "1" then 1 else + if char = "2" then 2 else + if char = "3" then 3 else + if char = "4" then 4 else + if char = "5" then 5 else + if char = "6" then 6 else + if char = "7" then 7 else + if char = "8" then 8 else + if char = "9" then 9 else + { abort(); 0; } (* the 0 is needed to satisfy the + typchecker *) + fi fi fi fi fi fi fi fi fi fi + }; + +(* + i2c is the inverse of c2i. +*) + i2c(i : Int) : String { + if i = 0 then "0" else + if i = 1 then "1" else + if i = 2 then "2" else + if i = 3 then "3" else + if i = 4 then "4" else + if i = 5 then "5" else + if i = 6 then "6" else + if i = 7 then "7" else + if i = 8 then "8" else + if i = 9 then "9" else + { abort(); ""; } -- the "" is needed to satisfy the typchecker + fi fi fi fi fi fi fi fi fi fi + }; + +(* + a2i converts an ASCII string into an integer. The empty string +is converted to 0. Signed and unsigned strings are handled. The +method aborts if the string does not represent an integer. Very +long strings of digits produce strange answers because of arithmetic +overflow. + +*) + a2i(s : String) : Int { + if s.length() = 0 then 0 else + if s.substr(0,1) = "-" then ~a2i_aux(s.substr(1,s.length()-1)) else + if s.substr(0,1) = "+" then a2i_aux(s.substr(1,s.length()-1)) else + a2i_aux(s) + fi fi fi + }; + +(* a2i_aux converts the usigned portion of the string. As a + programming example, this method is written iteratively. *) + + + a2i_aux(s : String) : Int { + (let int : Int <- 0 in + { + (let j : Int <- s.length() in + (let i : Int <- 0 in + while i < j loop + { + int <- int * 10 + c2i(s.substr(i,1)); + i <- i + 1; + } + pool + ) + ); + int; + } + ) + }; + +(* i2a converts an integer to a string. Positive and negative + numbers are handled correctly. *) + + i2a(i : Int) : String { + if i = 0 then "0" else + if 0 < i then i2a_aux(i) else + "-".concat(i2a_aux(i * ~1)) + fi fi + }; + +(* i2a_aux is an example using recursion. *) + + i2a_aux(i : Int) : String { + if i = 0 then "" else + (let next : Int <- i / 10 in + i2a_aux(next).concat(i2c(i - next * 10)) + ) + fi + }; + +}; + +class Main inherits IO { + + char : String; + avar : A; + a_var : A; + flag : Bool <- true; + + + menu() : String { + { + out_string("\n\tTo add a number to "); + print(avar); + out_string("...enter a:\n"); + out_string("\tTo negate "); + print(avar); + out_string("...enter b:\n"); + out_string("\tTo find the difference between "); + print(avar); + out_string("and another number...enter c:\n"); + out_string("\tTo find the factorial of "); + print(avar); + out_string("...enter d:\n"); + out_string("\tTo square "); + print(avar); + out_string("...enter e:\n"); + out_string("\tTo cube "); + print(avar); + out_string("...enter f:\n"); + out_string("\tTo find out if "); + print(avar); + out_string("is a multiple of 3...enter g:\n"); + out_string("\tTo divide "); + print(avar); + out_string("by 8...enter h:\n"); + out_string("\tTo get a new number...enter j:\n"); + out_string("\tTo quit...enter q:\n\n"); + in_string(); + } + }; + + prompt() : String { + { + out_string("\n"); + out_string("Please enter a number... "); + in_string(); + } + }; + + get_int() : Int { + { + (let z : A2I <- new A2I in + (let s : String <- prompt() in + z.a2i(s) + ) + ); + } + }; + + is_even(num : Int) : Bool { + (let x : Int <- num in + if x < 0 then is_even(~x) else + if 0 = x then true else + if 1 = x then false else + is_even(x - 2) + fi fi fi + ) + }; + + class_type(var : A) : IO { + case var of + a : A => out_string("Class type is now A\n"); + b : B => out_string("Class type is now B\n"); + c : C => out_string("Class type is now C\n"); + d : D => out_string("Class type is now D\n"); + e : E => out_string("Class type is now E\n"); + o : Object => out_string("Oooops\n"); + esac + }; + + print(var : A) : IO { + (let z : A2I <- new A2I in + { + out_string(z.i2a(var.value())); + out_string(" "); + } + ) + }; + + main() : Object { + { + avar <- (new A); + while flag loop + { + -- avar <- (new A).set_var(get_int()); + out_string("number "); + print(avar); + if is_even(avar.value()) then + out_string("is even!\n") + else + out_string("is odd!\n") + fi; + -- print(avar); -- prints out answer + class_type(avar); + char <- menu(); + if char = "a" then -- add + { + a_var <- (new A).set_var(get_int()); + avar <- (new B).method2(avar.value(), a_var.value()); + } else + if char = "b" then -- negate + case avar of + c : C => avar <- c.method6(c.value()); + a : A => avar <- a.method3(a.value()); + o : Object => { + out_string("Oooops\n"); + abort(); 0; + }; + esac else + if char = "c" then -- diff + { + a_var <- (new A).set_var(get_int()); + avar <- (new D).method4(avar.value(), a_var.value()); + } else + if char = "d" then avar <- (new C)@A.method5(avar.value()) else + -- factorial + if char = "e" then avar <- (new C)@B.method5(avar.value()) else + -- square + if char = "f" then avar <- (new C)@C.method5(avar.value()) else + -- cube + if char = "g" then -- multiple of 3? + if ((new D).method7(avar.value())) + then -- avar <- (new A).method1(avar.value()) + { + out_string("number "); + print(avar); + out_string("is divisible by 3.\n"); + } + else -- avar <- (new A).set_var(0) + { + out_string("number "); + print(avar); + out_string("is not divisible by 3.\n"); + } + fi else + if char = "h" then + (let x : A in + { + x <- (new E).method6(avar.value()); + (let r : Int <- (avar.value() - (x.value() * 8)) in + { + out_string("number "); + print(avar); + out_string("is equal to "); + print(x); + out_string("times 8 with a remainder of "); + (let a : A2I <- new A2I in + { + out_string(a.i2a(r)); + out_string("\n"); + } + ); -- end let a: + } + ); -- end let r: + avar <- x; + } + ) -- end let x: + else + if char = "j" then avar <- (new A) + else + if char = "q" then flag <- false + else + avar <- (new A).method1(avar.value()) -- divide/8 + fi fi fi fi fi fi fi fi fi fi; + } + pool; + } + }; + +}; + diff --git a/tests/codegen/arith_input.txt b/tests/codegen/arith_input.txt index 83e05b1ea..c431a225b 100644 --- a/tests/codegen/arith_input.txt +++ b/tests/codegen/arith_input.txt @@ -1,13 +1,13 @@ -a -1 -b -c -0 -d -e -f -g -h -j -5 -q +a +1 +b +c +0 +d +e +f +g +h +j +5 +q diff --git a/tests/codegen/arith_output.txt b/tests/codegen/arith_output.txt index 44b4ce73e..476cb3bad 100644 --- a/tests/codegen/arith_output.txt +++ b/tests/codegen/arith_output.txt @@ -1,158 +1,158 @@ -number 0 is even! -Class type is now A - - To add a number to 0 ...enter a: - To negate 0 ...enter b: - To find the difference between 0 and another number...enter c: - To find the factorial of 0 ...enter d: - To square 0 ...enter e: - To cube 0 ...enter f: - To find out if 0 is a multiple of 3...enter g: - To divide 0 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - - -Please enter a number... number 1 is odd! -Class type is now B - - To add a number to 1 ...enter a: - To negate 1 ...enter b: - To find the difference between 1 and another number...enter c: - To find the factorial of 1 ...enter d: - To square 1 ...enter e: - To cube 1 ...enter f: - To find out if 1 is a multiple of 3...enter g: - To divide 1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number -1 is odd! -Class type is now C - - To add a number to -1 ...enter a: - To negate -1 ...enter b: - To find the difference between -1 and another number...enter c: - To find the factorial of -1 ...enter d: - To square -1 ...enter e: - To cube -1 ...enter f: - To find out if -1 is a multiple of 3...enter g: - To divide -1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - - -Please enter a number... number 1 is odd! -Class type is now D - - To add a number to 1 ...enter a: - To negate 1 ...enter b: - To find the difference between 1 and another number...enter c: - To find the factorial of 1 ...enter d: - To square 1 ...enter e: - To cube 1 ...enter f: - To find out if 1 is a multiple of 3...enter g: - To divide 1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 1 is odd! -Class type is now E - - To add a number to 1 ...enter a: - To negate 1 ...enter b: - To find the difference between 1 and another number...enter c: - To find the factorial of 1 ...enter d: - To square 1 ...enter e: - To cube 1 ...enter f: - To find out if 1 is a multiple of 3...enter g: - To divide 1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 1 is odd! -Class type is now E - - To add a number to 1 ...enter a: - To negate 1 ...enter b: - To find the difference between 1 and another number...enter c: - To find the factorial of 1 ...enter d: - To square 1 ...enter e: - To cube 1 ...enter f: - To find out if 1 is a multiple of 3...enter g: - To divide 1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 1 is odd! -Class type is now E - - To add a number to 1 ...enter a: - To negate 1 ...enter b: - To find the difference between 1 and another number...enter c: - To find the factorial of 1 ...enter d: - To square 1 ...enter e: - To cube 1 ...enter f: - To find out if 1 is a multiple of 3...enter g: - To divide 1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 1 is not divisible by 3. -number 1 is odd! -Class type is now E - - To add a number to 1 ...enter a: - To negate 1 ...enter b: - To find the difference between 1 and another number...enter c: - To find the factorial of 1 ...enter d: - To square 1 ...enter e: - To cube 1 ...enter f: - To find out if 1 is a multiple of 3...enter g: - To divide 1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 1 is equal to 0 times 8 with a remainder of 1 -number 0 is even! -Class type is now A - - To add a number to 0 ...enter a: - To negate 0 ...enter b: - To find the difference between 0 and another number...enter c: - To find the factorial of 0 ...enter d: - To square 0 ...enter e: - To cube 0 ...enter f: - To find out if 0 is a multiple of 3...enter g: - To divide 0 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 0 is even! -Class type is now A - - To add a number to 0 ...enter a: - To negate 0 ...enter b: - To find the difference between 0 and another number...enter c: - To find the factorial of 0 ...enter d: - To square 0 ...enter e: - To cube 0 ...enter f: - To find out if 0 is a multiple of 3...enter g: - To divide 0 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 0 is even! -Class type is now A - - To add a number to 0 ...enter a: - To negate 0 ...enter b: - To find the difference between 0 and another number...enter c: - To find the factorial of 0 ...enter d: - To square 0 ...enter e: - To cube 0 ...enter f: - To find out if 0 is a multiple of 3...enter g: - To divide 0 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - +number 0 is even! +Class type is now A + + To add a number to 0 ...enter a: + To negate 0 ...enter b: + To find the difference between 0 and another number...enter c: + To find the factorial of 0 ...enter d: + To square 0 ...enter e: + To cube 0 ...enter f: + To find out if 0 is a multiple of 3...enter g: + To divide 0 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + + +Please enter a number... number 1 is odd! +Class type is now B + + To add a number to 1 ...enter a: + To negate 1 ...enter b: + To find the difference between 1 and another number...enter c: + To find the factorial of 1 ...enter d: + To square 1 ...enter e: + To cube 1 ...enter f: + To find out if 1 is a multiple of 3...enter g: + To divide 1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number -1 is odd! +Class type is now C + + To add a number to -1 ...enter a: + To negate -1 ...enter b: + To find the difference between -1 and another number...enter c: + To find the factorial of -1 ...enter d: + To square -1 ...enter e: + To cube -1 ...enter f: + To find out if -1 is a multiple of 3...enter g: + To divide -1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + + +Please enter a number... number 1 is odd! +Class type is now D + + To add a number to 1 ...enter a: + To negate 1 ...enter b: + To find the difference between 1 and another number...enter c: + To find the factorial of 1 ...enter d: + To square 1 ...enter e: + To cube 1 ...enter f: + To find out if 1 is a multiple of 3...enter g: + To divide 1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 1 is odd! +Class type is now E + + To add a number to 1 ...enter a: + To negate 1 ...enter b: + To find the difference between 1 and another number...enter c: + To find the factorial of 1 ...enter d: + To square 1 ...enter e: + To cube 1 ...enter f: + To find out if 1 is a multiple of 3...enter g: + To divide 1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 1 is odd! +Class type is now E + + To add a number to 1 ...enter a: + To negate 1 ...enter b: + To find the difference between 1 and another number...enter c: + To find the factorial of 1 ...enter d: + To square 1 ...enter e: + To cube 1 ...enter f: + To find out if 1 is a multiple of 3...enter g: + To divide 1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 1 is odd! +Class type is now E + + To add a number to 1 ...enter a: + To negate 1 ...enter b: + To find the difference between 1 and another number...enter c: + To find the factorial of 1 ...enter d: + To square 1 ...enter e: + To cube 1 ...enter f: + To find out if 1 is a multiple of 3...enter g: + To divide 1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 1 is not divisible by 3. +number 1 is odd! +Class type is now E + + To add a number to 1 ...enter a: + To negate 1 ...enter b: + To find the difference between 1 and another number...enter c: + To find the factorial of 1 ...enter d: + To square 1 ...enter e: + To cube 1 ...enter f: + To find out if 1 is a multiple of 3...enter g: + To divide 1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 1 is equal to 0 times 8 with a remainder of 1 +number 0 is even! +Class type is now A + + To add a number to 0 ...enter a: + To negate 0 ...enter b: + To find the difference between 0 and another number...enter c: + To find the factorial of 0 ...enter d: + To square 0 ...enter e: + To cube 0 ...enter f: + To find out if 0 is a multiple of 3...enter g: + To divide 0 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 0 is even! +Class type is now A + + To add a number to 0 ...enter a: + To negate 0 ...enter b: + To find the difference between 0 and another number...enter c: + To find the factorial of 0 ...enter d: + To square 0 ...enter e: + To cube 0 ...enter f: + To find out if 0 is a multiple of 3...enter g: + To divide 0 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 0 is even! +Class type is now A + + To add a number to 0 ...enter a: + To negate 0 ...enter b: + To find the difference between 0 and another number...enter c: + To find the factorial of 0 ...enter d: + To square 0 ...enter e: + To cube 0 ...enter f: + To find out if 0 is a multiple of 3...enter g: + To divide 0 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + diff --git a/tests/codegen/atoi_output.txt b/tests/codegen/atoi_output.txt index 51b815a48..c51d7bad6 100644 --- a/tests/codegen/atoi_output.txt +++ b/tests/codegen/atoi_output.txt @@ -1 +1 @@ -678987 == 678987 +678987 == 678987 diff --git a/tests/codegen/book_list.cl b/tests/codegen/book_list.cl index 025ea1695..d39f86bbe 100755 --- a/tests/codegen/book_list.cl +++ b/tests/codegen/book_list.cl @@ -1,132 +1,132 @@ --- example of static and dynamic type differing for a dispatch - -Class Book inherits IO { - title : String; - author : String; - - initBook(title_p : String, author_p : String) : Book { - { - title <- title_p; - author <- author_p; - self; - } - }; - - print() : Book { - { - out_string("title: ").out_string(title).out_string("\n"); - out_string("author: ").out_string(author).out_string("\n"); - self; - } - }; -}; - -Class Article inherits Book { - per_title : String; - - initArticle(title_p : String, author_p : String, - per_title_p : String) : Article { - { - initBook(title_p, author_p); - per_title <- per_title_p; - self; - } - }; - - print() : Book { - { - self@Book.print(); - out_string("periodical: ").out_string(per_title).out_string("\n"); - self; - } - }; -}; - -Class BookList inherits IO { - (* Since abort "returns" type Object, we have to add - an expression of type Bool here to satisfy the typechecker. - This code is unreachable, since abort() halts the program. - *) - isNil() : Bool { { abort(); true; } }; - - cons(hd : Book) : Cons { - (let new_cell : Cons <- new Cons in - new_cell.init(hd,self) - ) - }; - - (* Since abort "returns" type Object, we have to add - an expression of type Book here to satisfy the typechecker. - This code is unreachable, since abort() halts the program. - *) - car() : Book { { abort(); new Book; } }; - - (* Since abort "returns" type Object, we have to add - an expression of type BookList here to satisfy the typechecker. - This code is unreachable, since abort() halts the program. - *) - cdr() : BookList { { abort(); new BookList; } }; - - print_list() : Object { abort() }; -}; - -Class Cons inherits BookList { - xcar : Book; -- We keep the car and cdr in attributes. - xcdr : BookList; -- Because methods and features must have different names, - -- we use xcar and xcdr for the attributes and reserve - -- car and cdr for the features. - - isNil() : Bool { false }; - - init(hd : Book, tl : BookList) : Cons { - { - xcar <- hd; - xcdr <- tl; - self; - } - }; - - car() : Book { xcar }; - - cdr() : BookList { xcdr }; - - print_list() : Object { - { - case xcar.print() of - dummy : Book => out_string("- dynamic type was Book -\n"); - dummy : Article => out_string("- dynamic type was Article -\n"); - esac; - xcdr.print_list(); - } - }; -}; - -Class Nil inherits BookList { - isNil() : Bool { true }; - - print_list() : Object { true }; -}; - - -Class Main { - - books : BookList; - - main() : Object { - (let a_book : Book <- - (new Book).initBook("Compilers, Principles, Techniques, and Tools", - "Aho, Sethi, and Ullman") - in - (let an_article : Article <- - (new Article).initArticle("The Top 100 CD_ROMs", - "Ulanoff", - "PC Magazine") - in - { - books <- (new Nil).cons(a_book).cons(an_article); - books.print_list(); - } - ) -- end let an_article - ) -- end let a_book - }; -}; +-- example of static and dynamic type differing for a dispatch + +Class Book inherits IO { + title : String; + author : String; + + initBook(title_p : String, author_p : String) : Book { + { + title <- title_p; + author <- author_p; + self; + } + }; + + print() : Book { + { + out_string("title: ").out_string(title).out_string("\n"); + out_string("author: ").out_string(author).out_string("\n"); + self; + } + }; +}; + +Class Article inherits Book { + per_title : String; + + initArticle(title_p : String, author_p : String, + per_title_p : String) : Article { + { + initBook(title_p, author_p); + per_title <- per_title_p; + self; + } + }; + + print() : Book { + { + self@Book.print(); + out_string("periodical: ").out_string(per_title).out_string("\n"); + self; + } + }; +}; + +Class BookList inherits IO { + (* Since abort "returns" type Object, we have to add + an expression of type Bool here to satisfy the typechecker. + This code is unreachable, since abort() halts the program. + *) + isNil() : Bool { { abort(); true; } }; + + cons(hd : Book) : Cons { + (let new_cell : Cons <- new Cons in + new_cell.init(hd,self) + ) + }; + + (* Since abort "returns" type Object, we have to add + an expression of type Book here to satisfy the typechecker. + This code is unreachable, since abort() halts the program. + *) + car() : Book { { abort(); new Book; } }; + + (* Since abort "returns" type Object, we have to add + an expression of type BookList here to satisfy the typechecker. + This code is unreachable, since abort() halts the program. + *) + cdr() : BookList { { abort(); new BookList; } }; + + print_list() : Object { abort() }; +}; + +Class Cons inherits BookList { + xcar : Book; -- We keep the car and cdr in attributes. + xcdr : BookList; -- Because methods and features must have different names, + -- we use xcar and xcdr for the attributes and reserve + -- car and cdr for the features. + + isNil() : Bool { false }; + + init(hd : Book, tl : BookList) : Cons { + { + xcar <- hd; + xcdr <- tl; + self; + } + }; + + car() : Book { xcar }; + + cdr() : BookList { xcdr }; + + print_list() : Object { + { + case xcar.print() of + dummy : Book => out_string("- dynamic type was Book -\n"); + dummy : Article => out_string("- dynamic type was Article -\n"); + esac; + xcdr.print_list(); + } + }; +}; + +Class Nil inherits BookList { + isNil() : Bool { true }; + + print_list() : Object { true }; +}; + + +Class Main { + + books : BookList; + + main() : Object { + (let a_book : Book <- + (new Book).initBook("Compilers, Principles, Techniques, and Tools", + "Aho, Sethi, and Ullman") + in + (let an_article : Article <- + (new Article).initArticle("The Top 100 CD_ROMs", + "Ulanoff", + "PC Magazine") + in + { + books <- (new Nil).cons(a_book).cons(an_article); + books.print_list(); + } + ) -- end let an_article + ) -- end let a_book + }; +}; diff --git a/tests/codegen/book_list_output.txt b/tests/codegen/book_list_output.txt index 3408320b2..ced587a4f 100644 --- a/tests/codegen/book_list_output.txt +++ b/tests/codegen/book_list_output.txt @@ -1,7 +1,7 @@ -title: The Top 100 CD_ROMs -author: Ulanoff -periodical: PC Magazine -- dynamic type was Article - -title: Compilers, Principles, Techniques, and Tools -author: Aho, Sethi, and Ullman -- dynamic type was Book - +title: The Top 100 CD_ROMs +author: Ulanoff +periodical: PC Magazine +- dynamic type was Article - +title: Compilers, Principles, Techniques, and Tools +author: Aho, Sethi, and Ullman +- dynamic type was Book - diff --git a/tests/codegen/cells.cl b/tests/codegen/cells.cl index 9fd6741bb..bcd891498 100755 --- a/tests/codegen/cells.cl +++ b/tests/codegen/cells.cl @@ -1,97 +1,97 @@ -(* models one-dimensional cellular automaton on a circle of finite radius - arrays are faked as Strings, - X's respresent live cells, dots represent dead cells, - no error checking is done *) -class CellularAutomaton inherits IO { - population_map : String; - - init(map : String) : CellularAutomaton { - { - population_map <- map; - self; - } - }; - - print() : CellularAutomaton { - { - out_string(population_map.concat("\n")); - self; - } - }; - - num_cells() : Int { - population_map.length() - }; - - cell(position : Int) : String { - population_map.substr(position, 1) - }; - - cell_left_neighbor(position : Int) : String { - if position = 0 then - cell(num_cells() - 1) - else - cell(position - 1) - fi - }; - - cell_right_neighbor(position : Int) : String { - if position = num_cells() - 1 then - cell(0) - else - cell(position + 1) - fi - }; - - (* a cell will live if exactly 1 of itself and it's immediate - neighbors are alive *) - cell_at_next_evolution(position : Int) : String { - if (if cell(position) = "X" then 1 else 0 fi - + if cell_left_neighbor(position) = "X" then 1 else 0 fi - + if cell_right_neighbor(position) = "X" then 1 else 0 fi - = 1) - then - "X" - else - "." - fi - }; - - evolve() : CellularAutomaton { - (let position : Int in - (let num : Int <- num_cells() in - (let temp : String in - { - while position < num loop - { - temp <- temp.concat(cell_at_next_evolution(position)); - position <- position + 1; - } - pool; - population_map <- temp; - self; - } - ) ) ) - }; -}; - -class Main { - cells : CellularAutomaton; - - main() : Main { - { - cells <- (new CellularAutomaton).init(" X "); - cells.print(); - (let countdown : Int <- 20 in - while 0 < countdown loop - { - cells.evolve(); - cells.print(); - countdown <- countdown - 1; - } - pool - ); - self; - } - }; -}; +(* models one-dimensional cellular automaton on a circle of finite radius + arrays are faked as Strings, + X's respresent live cells, dots represent dead cells, + no error checking is done *) +class CellularAutomaton inherits IO { + population_map : String; + + init(map : String) : CellularAutomaton { + { + population_map <- map; + self; + } + }; + + print() : CellularAutomaton { + { + out_string(population_map.concat("\n")); + self; + } + }; + + num_cells() : Int { + population_map.length() + }; + + cell(position : Int) : String { + population_map.substr(position, 1) + }; + + cell_left_neighbor(position : Int) : String { + if position = 0 then + cell(num_cells() - 1) + else + cell(position - 1) + fi + }; + + cell_right_neighbor(position : Int) : String { + if position = num_cells() - 1 then + cell(0) + else + cell(position + 1) + fi + }; + + (* a cell will live if exactly 1 of itself and it's immediate + neighbors are alive *) + cell_at_next_evolution(position : Int) : String { + if (if cell(position) = "X" then 1 else 0 fi + + if cell_left_neighbor(position) = "X" then 1 else 0 fi + + if cell_right_neighbor(position) = "X" then 1 else 0 fi + = 1) + then + "X" + else + "." + fi + }; + + evolve() : CellularAutomaton { + (let position : Int in + (let num : Int <- num_cells() in + (let temp : String in + { + while position < num loop + { + temp <- temp.concat(cell_at_next_evolution(position)); + position <- position + 1; + } + pool; + population_map <- temp; + self; + } + ) ) ) + }; +}; + +class Main { + cells : CellularAutomaton; + + main() : Main { + { + cells <- (new CellularAutomaton).init(" X "); + cells.print(); + (let countdown : Int <- 20 in + while 0 < countdown loop + { + cells.evolve(); + cells.print(); + countdown <- countdown - 1; + } + pool + ); + self; + } + }; +}; diff --git a/tests/codegen/cells_output.txt b/tests/codegen/cells_output.txt index 6304902cc..9d06c27bc 100644 --- a/tests/codegen/cells_output.txt +++ b/tests/codegen/cells_output.txt @@ -1,21 +1,21 @@ - X -........XXX........ -.......X...X....... -......XXX.XXX...... -.....X.......X..... -....XXX.....XXX.... -...X...X...X...X... -..XXX.XXX.XXX.XXX.. -.X...............X. -XXX.............XXX -...X...........X... -..XXX.........XXX.. -.X...X.......X...X. -XXX.XXX.....XXX.XXX -.......X...X....... -......XXX.XXX...... -.....X.......X..... -....XXX.....XXX.... -...X...X...X...X... -..XXX.XXX.XXX.XXX.. -.X...............X. + X +........XXX........ +.......X...X....... +......XXX.XXX...... +.....X.......X..... +....XXX.....XXX.... +...X...X...X...X... +..XXX.XXX.XXX.XXX.. +.X...............X. +XXX.............XXX +...X...........X... +..XXX.........XXX.. +.X...X.......X...X. +XXX.XXX.....XXX.XXX +.......X...X....... +......XXX.XXX...... +.....X.......X..... +....XXX.....XXX.... +...X...X...X...X... +..XXX.XXX.XXX.XXX.. +.X...............X. diff --git a/tests/codegen/complex.cl b/tests/codegen/complex.cl index 0b7aa44e9..9edb6151d 100755 --- a/tests/codegen/complex.cl +++ b/tests/codegen/complex.cl @@ -1,52 +1,52 @@ -class Main inherits IO { - main() : IO { - (let c : Complex <- (new Complex).init(1, 1) in - if c.reflect_X().reflect_Y() = c.reflect_0() - then out_string("=)\n") - else out_string("=(\n") - fi - ) - }; -}; - -class Complex inherits IO { - x : Int; - y : Int; - - init(a : Int, b : Int) : Complex { - { - x = a; - y = b; - self; - } - }; - - print() : Object { - if y = 0 - then out_int(x) - else out_int(x).out_string("+").out_int(y).out_string("I") - fi - }; - - reflect_0() : Complex { - { - x = ~x; - y = ~y; - self; - } - }; - - reflect_X() : Complex { - { - y = ~y; - self; - } - }; - - reflect_Y() : Complex { - { - x = ~x; - self; - } - }; -}; +class Main inherits IO { + main() : IO { + (let c : Complex <- (new Complex).init(1, 1) in + if c.reflect_X().reflect_Y() = c.reflect_0() + then out_string("=)\n") + else out_string("=(\n") + fi + ) + }; +}; + +class Complex inherits IO { + x : Int; + y : Int; + + init(a : Int, b : Int) : Complex { + { + x = a; + y = b; + self; + } + }; + + print() : Object { + if y = 0 + then out_int(x) + else out_int(x).out_string("+").out_int(y).out_string("I") + fi + }; + + reflect_0() : Complex { + { + x = ~x; + y = ~y; + self; + } + }; + + reflect_X() : Complex { + { + y = ~y; + self; + } + }; + + reflect_Y() : Complex { + { + x = ~x; + self; + } + }; +}; diff --git a/tests/codegen/complex_output.txt b/tests/codegen/complex_output.txt index 18b77c1fc..7d6173685 100644 --- a/tests/codegen/complex_output.txt +++ b/tests/codegen/complex_output.txt @@ -1 +1 @@ -=) +=) diff --git a/tests/codegen/fib.cl b/tests/codegen/fib.cl index 08ceaede8..ced8cee48 100644 --- a/tests/codegen/fib.cl +++ b/tests/codegen/fib.cl @@ -1,29 +1,29 @@ -class Main inherits IO { - -- the class has features. Only methods in this case. - main(): Object { - { - out_string("Enter n to find nth fibonacci number!\n"); - out_int(fib(in_int())); - out_string("\n"); - } - }; - - fib(i : Int) : Int { -- list of formals. And the return type of the method. - let a : Int <- 1, - b : Int <- 0, - c : Int <- 0 - in - { - while (not (i = 0)) loop -- expressions are nested. - { - c <- a + b; - i <- i - 1; - b <- a; - a <- c; - } - pool; - c; - } - }; - -}; +class Main inherits IO { + -- the class has features. Only methods in this case. + main(): Object { + { + out_string("Enter n to find nth fibonacci number!\n"); + out_int(fib(in_int())); + out_string("\n"); + } + }; + + fib(i : Int) : Int { -- list of formals. And the return type of the method. + let a : Int <- 1, + b : Int <- 0, + c : Int <- 0 + in + { + while (not (i = 0)) loop -- expressions are nested. + { + c <- a + b; + i <- i - 1; + b <- a; + a <- c; + } + pool; + c; + } + }; + +}; diff --git a/tests/codegen/fib_input.txt b/tests/codegen/fib_input.txt index f599e28b8..d43401489 100644 --- a/tests/codegen/fib_input.txt +++ b/tests/codegen/fib_input.txt @@ -1 +1 @@ -10 +10 diff --git a/tests/codegen/fib_output.txt b/tests/codegen/fib_output.txt index d402da6af..2552f4479 100644 --- a/tests/codegen/fib_output.txt +++ b/tests/codegen/fib_output.txt @@ -1,2 +1,2 @@ -Enter n to find nth fibonacci number! -89 +Enter n to find nth fibonacci number! +89 diff --git a/tests/codegen/graph.cl b/tests/codegen/graph.cl index 8e511358c..59e29bbf4 100755 --- a/tests/codegen/graph.cl +++ b/tests/codegen/graph.cl @@ -1,381 +1,381 @@ -(* - * Cool program reading descriptions of weighted directed graphs - * from stdin. It builds up a graph objects with a list of vertices - * and a list of edges. Every vertice has a list of outgoing edges. - * - * INPUT FORMAT - * Every line has the form vertice successor* - * Where vertice is an int, and successor is vertice,weight - * - * An empty line or EOF terminates the input. - * - * The list of vertices and the edge list is printed out by the Main - * class. - * - * TEST - * Once compiled, the file g1.graph can be fed to the program. - * The output should look like this: - -nautilus.CS.Berkeley.EDU 53# spim -file graph.s (new Bar); - n : Foo => (new Razz); - n : Bar => n; - esac; - - b : Int <- a.doh() + g.doh() + doh() + printh(); - - doh() : Int { (let i : Int <- h in { h <- h + 2; i; } ) }; - -}; - -class Bar inherits Razz { - - c : Int <- doh(); - - d : Object <- printh(); -}; - - -class Razz inherits Foo { - - e : Bar <- case self of - n : Razz => (new Bar); - n : Bar => n; - esac; - - f : Int <- a@Bazz.doh() + g.doh() + e.doh() + doh() + printh(); - -}; - -class Bazz inherits IO { - - h : Int <- 1; - - g : Foo <- case self of - n : Bazz => (new Foo); - n : Razz => (new Bar); - n : Foo => (new Razz); - n : Bar => n; - esac; - - i : Object <- printh(); - - printh() : Int { { out_int(h); 0; } }; - - doh() : Int { (let i: Int <- h in { h <- h + 1; i; } ) }; -}; - -(* scary . . . *) -class Main { - a : Bazz <- new Bazz; - b : Foo <- new Foo; - c : Razz <- new Razz; - d : Bar <- new Bar; - - main(): String { "do nothing" }; - -}; - - - - - +(* hairy . . .*) + +class Foo inherits Bazz { + a : Razz <- case self of + n : Razz => (new Bar); + n : Foo => (new Razz); + n : Bar => n; + esac; + + b : Int <- a.doh() + g.doh() + doh() + printh(); + + doh() : Int { (let i : Int <- h in { h <- h + 2; i; } ) }; + +}; + +class Bar inherits Razz { + + c : Int <- doh(); + + d : Object <- printh(); +}; + + +class Razz inherits Foo { + + e : Bar <- case self of + n : Razz => (new Bar); + n : Bar => n; + esac; + + f : Int <- a@Bazz.doh() + g.doh() + e.doh() + doh() + printh(); + +}; + +class Bazz inherits IO { + + h : Int <- 1; + + g : Foo <- case self of + n : Bazz => (new Foo); + n : Razz => (new Bar); + n : Foo => (new Razz); + n : Bar => n; + esac; + + i : Object <- printh(); + + printh() : Int { { out_int(h); 0; } }; + + doh() : Int { (let i: Int <- h in { h <- h + 1; i; } ) }; +}; + +(* scary . . . *) +class Main { + a : Bazz <- new Bazz; + b : Foo <- new Foo; + c : Razz <- new Razz; + d : Bar <- new Bar; + + main(): String { "do nothing" }; + +}; + + + + + diff --git a/tests/codegen/hello_world.cl b/tests/codegen/hello_world.cl index 0c818f908..b0a180a2e 100755 --- a/tests/codegen/hello_world.cl +++ b/tests/codegen/hello_world.cl @@ -1,5 +1,5 @@ -class Main inherits IO { - main(): IO { - out_string("Hello, World.\n") - }; -}; +class Main inherits IO { + main(): IO { + out_string("Hello, World.\n") + }; +}; diff --git a/tests/codegen/hello_world_output.txt b/tests/codegen/hello_world_output.txt index 349db2bfe..9c1c7a002 100644 --- a/tests/codegen/hello_world_output.txt +++ b/tests/codegen/hello_world_output.txt @@ -1 +1 @@ -Hello, World. +Hello, World. diff --git a/tests/codegen/io.cl b/tests/codegen/io.cl index 7f0de869e..42ee6854e 100755 --- a/tests/codegen/io.cl +++ b/tests/codegen/io.cl @@ -1,103 +1,103 @@ -(* - * The IO class is predefined and has 4 methods: - * - * out_string(s : String) : SELF_TYPE - * out_int(i : Int) : SELF_TYPE - * in_string() : String - * in_int() : Int - * - * The out operations print their argument to the terminal. The - * in_string method reads an entire line from the terminal and returns a - * string not containing the new line. The in_int method also reads - * an entire line from the terminal and returns the integer - * corresponding to the first non blank word on the line. If that - * word is not an integer, it returns 0. - * - * - * Because our language is object oriented, we need an object of type - * IO in order to call any of these methods. - * - * There are basically two ways of getting access to IO in a class C. - * - * 1) Define C to Inherit from IO. This way the IO methods become - * methods of C, and they can be called using the abbreviated - * dispatch, i.e. - * - * class C inherits IO is - * ... - * out_string("Hello world\n") - * ... - * end; - * - * 2) If your class C does not directly or indirectly inherit from - * IO, the best way to access IO is through an initialized - * attribute of type IO. - * - * class C inherits Foo is - * io : IO <- new IO; - * ... - * io.out_string("Hello world\n"); - * ... - * end; - * - * Approach 1) is most often used, in particular when you need IO - * functions in the Main class. - * - *) - - -class A { - - -- Let's assume that we don't want A to not inherit from IO. - - io : IO <- new IO; - - out_a() : Object { io.out_string("A: Hello world\n") }; - -}; - - -class B inherits A { - - -- B does not have to an extra attribute, since it inherits io from A. - - out_b() : Object { io.out_string("B: Hello world\n") }; - -}; - - -class C inherits IO { - - -- Now the IO methods are part of C. - - out_c() : Object { out_string("C: Hello world\n") }; - - -- Note that out_string(...) is just a shorthand for self.out_string(...) - -}; - - -class D inherits C { - - -- Inherits IO methods from C. - - out_d() : Object { out_string("D: Hello world\n") }; - -}; - - -class Main inherits IO { - - -- Same case as class C. - - main() : Object { - { - (new A).out_a(); - (new B).out_b(); - (new C).out_c(); - (new D).out_d(); - out_string("Done.\n"); - } - }; - -}; +(* + * The IO class is predefined and has 4 methods: + * + * out_string(s : String) : SELF_TYPE + * out_int(i : Int) : SELF_TYPE + * in_string() : String + * in_int() : Int + * + * The out operations print their argument to the terminal. The + * in_string method reads an entire line from the terminal and returns a + * string not containing the new line. The in_int method also reads + * an entire line from the terminal and returns the integer + * corresponding to the first non blank word on the line. If that + * word is not an integer, it returns 0. + * + * + * Because our language is object oriented, we need an object of type + * IO in order to call any of these methods. + * + * There are basically two ways of getting access to IO in a class C. + * + * 1) Define C to Inherit from IO. This way the IO methods become + * methods of C, and they can be called using the abbreviated + * dispatch, i.e. + * + * class C inherits IO is + * ... + * out_string("Hello world\n") + * ... + * end; + * + * 2) If your class C does not directly or indirectly inherit from + * IO, the best way to access IO is through an initialized + * attribute of type IO. + * + * class C inherits Foo is + * io : IO <- new IO; + * ... + * io.out_string("Hello world\n"); + * ... + * end; + * + * Approach 1) is most often used, in particular when you need IO + * functions in the Main class. + * + *) + + +class A { + + -- Let's assume that we don't want A to not inherit from IO. + + io : IO <- new IO; + + out_a() : Object { io.out_string("A: Hello world\n") }; + +}; + + +class B inherits A { + + -- B does not have to an extra attribute, since it inherits io from A. + + out_b() : Object { io.out_string("B: Hello world\n") }; + +}; + + +class C inherits IO { + + -- Now the IO methods are part of C. + + out_c() : Object { out_string("C: Hello world\n") }; + + -- Note that out_string(...) is just a shorthand for self.out_string(...) + +}; + + +class D inherits C { + + -- Inherits IO methods from C. + + out_d() : Object { out_string("D: Hello world\n") }; + +}; + + +class Main inherits IO { + + -- Same case as class C. + + main() : Object { + { + (new A).out_a(); + (new B).out_b(); + (new C).out_c(); + (new D).out_d(); + out_string("Done.\n"); + } + }; + +}; diff --git a/tests/codegen/io_output.txt b/tests/codegen/io_output.txt index f846f596d..870cffce6 100644 --- a/tests/codegen/io_output.txt +++ b/tests/codegen/io_output.txt @@ -1,5 +1,5 @@ -A: Hello world -B: Hello world -C: Hello world -D: Hello world -Done. +A: Hello world +B: Hello world +C: Hello world +D: Hello world +Done. diff --git a/tests/codegen/life.cl b/tests/codegen/life.cl index b83d97957..7d7a41fdb 100755 --- a/tests/codegen/life.cl +++ b/tests/codegen/life.cl @@ -1,436 +1,436 @@ -(* The Game of Life - Tendo Kayiira, Summer '95 - With code taken from /private/cool/class/examples/cells.cl - - This introduction was taken off the internet. It gives a brief - description of the Game Of Life. It also gives the rules by which - this particular game follows. - - Introduction - - John Conway's Game of Life is a mathematical amusement, but it - is also much more: an insight into how a system of simple - cellualar automata can create complex, odd, and often aesthetically - pleasing patterns. It is played on a cartesian grid of cells - which are either 'on' or 'off' The game gets it's name from the - similarity between the behaviour of these cells and the behaviour - of living organisms. - - The Rules - - The playfield is a cartesian grid of arbitrary size. Each cell in - this grid can be in an 'on' state or an 'off' state. On each 'turn' - (called a generation,) the state of each cell changes simultaneously - depending on it's state and the state of all cells adjacent to it. - - For 'on' cells, - If the cell has 0 or 1 neighbours which are 'on', the cell turns - 'off'. ('dies of loneliness') - If the cell has 2 or 3 neighbours which are 'on', the cell stays - 'on'. (nothing happens to that cell) - If the cell has 4, 5, 6, 7, 8, or 9 neighbours which are 'on', - the cell turns 'off'. ('dies of overcrowding') - - For 'off' cells, - If the cell has 0, 1, 2, 4, 5, 6, 7, 8, or 9 neighbours which - are 'on', the cell stays 'off'. (nothing happens to that cell) - If the cell has 3 neighbours which are 'on', the cell turns - 'on'. (3 neighbouring 'alive' cells 'give birth' to a fourth.) - - Repeat for as many generations as desired. - - *) - - -class Board inherits IO { - - rows : Int; - columns : Int; - board_size : Int; - - size_of_board(initial : String) : Int { - initial.length() - }; - - board_init(start : String) : Board { - (let size :Int <- size_of_board(start) in - { - if size = 15 then - { - rows <- 3; - columns <- 5; - board_size <- size; - } - else if size = 16 then - { - rows <- 4; - columns <- 4; - board_size <- size; - } - else if size = 20 then - { - rows <- 4; - columns <- 5; - board_size <- size; - } - else if size = 21 then - { - rows <- 3; - columns <- 7; - board_size <- size; - } - else if size = 25 then - { - rows <- 5; - columns <- 5; - board_size <- size; - } - else if size = 28 then - { - rows <- 7; - columns <- 4; - board_size <- size; - } - else -- If none of the above fit, then just give - { -- the configuration of the most common board - rows <- 5; - columns <- 5; - board_size <- size; - } - fi fi fi fi fi fi; - self; - } - ) - }; - -}; - - - -class CellularAutomaton inherits Board { - population_map : String; - - init(map : String) : CellularAutomaton { - { - population_map <- map; - board_init(map); - self; - } - }; - - - - - print() : CellularAutomaton { - - (let i : Int <- 0 in - (let num : Int <- board_size in - { - out_string("\n"); - while i < num loop - { - out_string(population_map.substr(i,columns)); - out_string("\n"); - i <- i + columns; - } - pool; - out_string("\n"); - self; - } - ) ) - }; - - num_cells() : Int { - population_map.length() - }; - - cell(position : Int) : String { - if board_size - 1 < position then - " " - else - population_map.substr(position, 1) - fi - }; - - north(position : Int): String { - if (position - columns) < 0 then - " " - else - cell(position - columns) - fi - }; - - south(position : Int): String { - if board_size < (position + columns) then - " " - else - cell(position + columns) - fi - }; - - east(position : Int): String { - if (((position + 1) /columns ) * columns) = (position + 1) then - " " - else - cell(position + 1) - fi - }; - - west(position : Int): String { - if position = 0 then - " " - else - if ((position / columns) * columns) = position then - " " - else - cell(position - 1) - fi fi - }; - - northwest(position : Int): String { - if (position - columns) < 0 then - " " - else if ((position / columns) * columns) = position then - " " - else - north(position - 1) - fi fi - }; - - northeast(position : Int): String { - if (position - columns) < 0 then - " " - else if (((position + 1) /columns ) * columns) = (position + 1) then - " " - else - north(position + 1) - fi fi - }; - - southeast(position : Int): String { - if board_size < (position + columns) then - " " - else if (((position + 1) /columns ) * columns) = (position + 1) then - " " - else - south(position + 1) - fi fi - }; - - southwest(position : Int): String { - if board_size < (position + columns) then - " " - else if ((position / columns) * columns) = position then - " " - else - south(position - 1) - fi fi - }; - - neighbors(position: Int): Int { - { - if north(position) = "X" then 1 else 0 fi - + if south(position) = "X" then 1 else 0 fi - + if east(position) = "X" then 1 else 0 fi - + if west(position) = "X" then 1 else 0 fi - + if northeast(position) = "X" then 1 else 0 fi - + if northwest(position) = "X" then 1 else 0 fi - + if southeast(position) = "X" then 1 else 0 fi - + if southwest(position) = "X" then 1 else 0 fi; - } - }; - - -(* A cell will live if 2 or 3 of it's neighbors are alive. It dies - otherwise. A cell is born if only 3 of it's neighbors are alive. *) - - cell_at_next_evolution(position : Int) : String { - - if neighbors(position) = 3 then - "X" - else - if neighbors(position) = 2 then - if cell(position) = "X" then - "X" - else - "-" - fi - else - "-" - fi fi - }; - - - evolve() : CellularAutomaton { - (let position : Int <- 0 in - (let num : Int <- num_cells() in - (let temp : String in - { - while position < num loop - { - temp <- temp.concat(cell_at_next_evolution(position)); - position <- position + 1; - } - pool; - population_map <- temp; - self; - } - ) ) ) - }; - -(* This is where the background pattern is detremined by the user. More - patterns can be added as long as whoever adds keeps the board either - 3x5, 4x5, 5x5, 3x7, 7x4, 4x4 with the row first then column. *) - option(): String { - { - (let num : Int in - { - out_string("\nPlease chose a number:\n"); - out_string("\t1: A cross\n"); - out_string("\t2: A slash from the upper left to lower right\n"); - out_string("\t3: A slash from the upper right to lower left\n"); - out_string("\t4: An X\n"); - out_string("\t5: A greater than sign \n"); - out_string("\t6: A less than sign\n"); - out_string("\t7: Two greater than signs\n"); - out_string("\t8: Two less than signs\n"); - out_string("\t9: A 'V'\n"); - out_string("\t10: An inverse 'V'\n"); - out_string("\t11: Numbers 9 and 10 combined\n"); - out_string("\t12: A full grid\n"); - out_string("\t13: A 'T'\n"); - out_string("\t14: A plus '+'\n"); - out_string("\t15: A 'W'\n"); - out_string("\t16: An 'M'\n"); - out_string("\t17: An 'E'\n"); - out_string("\t18: A '3'\n"); - out_string("\t19: An 'O'\n"); - out_string("\t20: An '8'\n"); - out_string("\t21: An 'S'\n"); - out_string("Your choice => "); - num <- in_int(); - out_string("\n"); - if num = 1 then - " XX XXXX XXXX XX " - else if num = 2 then - " X X X X X " - else if num = 3 then - "X X X X X" - else if num = 4 then - "X X X X X X X X X" - else if num = 5 then - "X X X X X " - else if num = 6 then - " X X X X X" - else if num = 7 then - "X X X XX X " - else if num = 8 then - " X XX X X X " - else if num = 9 then - "X X X X X " - else if num = 10 then - " X X X X X" - else if num = 11 then - "X X X X X X X X" - else if num = 12 then - "XXXXXXXXXXXXXXXXXXXXXXXXX" - else if num = 13 then - "XXXXX X X X X " - else if num = 14 then - " X X XXXXX X X " - else if num = 15 then - "X X X X X X X " - else if num = 16 then - " X X X X X X X" - else if num = 17 then - "XXXXX X XXXXX X XXXX" - else if num = 18 then - "XXX X X X X XXXX " - else if num = 19 then - " XX X XX X XX " - else if num = 20 then - " XX X XX X XX X XX X XX " - else if num = 21 then - " XXXX X XX X XXXX " - else - " " - fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi; - } - ); - } - }; - - - - - prompt() : Bool { - { - (let ans : String in - { - out_string("Would you like to continue with the next generation? \n"); - out_string("Please use lowercase y or n for your answer [y]: "); - ans <- in_string(); - out_string("\n"); - if ans = "n" then - false - else - true - fi; - } - ); - } - }; - - - prompt2() : Bool { - (let ans : String in - { - out_string("\n\n"); - out_string("Would you like to choose a background pattern? \n"); - out_string("Please use lowercase y or n for your answer [n]: "); - ans <- in_string(); - if ans = "y" then - true - else - false - fi; - } - ) - }; - - -}; - -class Main inherits CellularAutomaton { - cells : CellularAutomaton; - - main() : Main { - { - (let continue : Bool in - (let choice : String in - { - out_string("Welcome to the Game of Life.\n"); - out_string("There are many initial states to choose from. \n"); - while prompt2() loop - { - continue <- true; - choice <- option(); - cells <- (new CellularAutomaton).init(choice); - cells.print(); - while continue loop - if prompt() then - { - cells.evolve(); - cells.print(); - } - else - continue <- false - fi - pool; - } - pool; - self; - } ) ); } - }; -}; - +(* The Game of Life + Tendo Kayiira, Summer '95 + With code taken from /private/cool/class/examples/cells.cl + + This introduction was taken off the internet. It gives a brief + description of the Game Of Life. It also gives the rules by which + this particular game follows. + + Introduction + + John Conway's Game of Life is a mathematical amusement, but it + is also much more: an insight into how a system of simple + cellualar automata can create complex, odd, and often aesthetically + pleasing patterns. It is played on a cartesian grid of cells + which are either 'on' or 'off' The game gets it's name from the + similarity between the behaviour of these cells and the behaviour + of living organisms. + + The Rules + + The playfield is a cartesian grid of arbitrary size. Each cell in + this grid can be in an 'on' state or an 'off' state. On each 'turn' + (called a generation,) the state of each cell changes simultaneously + depending on it's state and the state of all cells adjacent to it. + + For 'on' cells, + If the cell has 0 or 1 neighbours which are 'on', the cell turns + 'off'. ('dies of loneliness') + If the cell has 2 or 3 neighbours which are 'on', the cell stays + 'on'. (nothing happens to that cell) + If the cell has 4, 5, 6, 7, 8, or 9 neighbours which are 'on', + the cell turns 'off'. ('dies of overcrowding') + + For 'off' cells, + If the cell has 0, 1, 2, 4, 5, 6, 7, 8, or 9 neighbours which + are 'on', the cell stays 'off'. (nothing happens to that cell) + If the cell has 3 neighbours which are 'on', the cell turns + 'on'. (3 neighbouring 'alive' cells 'give birth' to a fourth.) + + Repeat for as many generations as desired. + + *) + + +class Board inherits IO { + + rows : Int; + columns : Int; + board_size : Int; + + size_of_board(initial : String) : Int { + initial.length() + }; + + board_init(start : String) : Board { + (let size :Int <- size_of_board(start) in + { + if size = 15 then + { + rows <- 3; + columns <- 5; + board_size <- size; + } + else if size = 16 then + { + rows <- 4; + columns <- 4; + board_size <- size; + } + else if size = 20 then + { + rows <- 4; + columns <- 5; + board_size <- size; + } + else if size = 21 then + { + rows <- 3; + columns <- 7; + board_size <- size; + } + else if size = 25 then + { + rows <- 5; + columns <- 5; + board_size <- size; + } + else if size = 28 then + { + rows <- 7; + columns <- 4; + board_size <- size; + } + else -- If none of the above fit, then just give + { -- the configuration of the most common board + rows <- 5; + columns <- 5; + board_size <- size; + } + fi fi fi fi fi fi; + self; + } + ) + }; + +}; + + + +class CellularAutomaton inherits Board { + population_map : String; + + init(map : String) : CellularAutomaton { + { + population_map <- map; + board_init(map); + self; + } + }; + + + + + print() : CellularAutomaton { + + (let i : Int <- 0 in + (let num : Int <- board_size in + { + out_string("\n"); + while i < num loop + { + out_string(population_map.substr(i,columns)); + out_string("\n"); + i <- i + columns; + } + pool; + out_string("\n"); + self; + } + ) ) + }; + + num_cells() : Int { + population_map.length() + }; + + cell(position : Int) : String { + if board_size - 1 < position then + " " + else + population_map.substr(position, 1) + fi + }; + + north(position : Int): String { + if (position - columns) < 0 then + " " + else + cell(position - columns) + fi + }; + + south(position : Int): String { + if board_size < (position + columns) then + " " + else + cell(position + columns) + fi + }; + + east(position : Int): String { + if (((position + 1) /columns ) * columns) = (position + 1) then + " " + else + cell(position + 1) + fi + }; + + west(position : Int): String { + if position = 0 then + " " + else + if ((position / columns) * columns) = position then + " " + else + cell(position - 1) + fi fi + }; + + northwest(position : Int): String { + if (position - columns) < 0 then + " " + else if ((position / columns) * columns) = position then + " " + else + north(position - 1) + fi fi + }; + + northeast(position : Int): String { + if (position - columns) < 0 then + " " + else if (((position + 1) /columns ) * columns) = (position + 1) then + " " + else + north(position + 1) + fi fi + }; + + southeast(position : Int): String { + if board_size < (position + columns) then + " " + else if (((position + 1) /columns ) * columns) = (position + 1) then + " " + else + south(position + 1) + fi fi + }; + + southwest(position : Int): String { + if board_size < (position + columns) then + " " + else if ((position / columns) * columns) = position then + " " + else + south(position - 1) + fi fi + }; + + neighbors(position: Int): Int { + { + if north(position) = "X" then 1 else 0 fi + + if south(position) = "X" then 1 else 0 fi + + if east(position) = "X" then 1 else 0 fi + + if west(position) = "X" then 1 else 0 fi + + if northeast(position) = "X" then 1 else 0 fi + + if northwest(position) = "X" then 1 else 0 fi + + if southeast(position) = "X" then 1 else 0 fi + + if southwest(position) = "X" then 1 else 0 fi; + } + }; + + +(* A cell will live if 2 or 3 of it's neighbors are alive. It dies + otherwise. A cell is born if only 3 of it's neighbors are alive. *) + + cell_at_next_evolution(position : Int) : String { + + if neighbors(position) = 3 then + "X" + else + if neighbors(position) = 2 then + if cell(position) = "X" then + "X" + else + "-" + fi + else + "-" + fi fi + }; + + + evolve() : CellularAutomaton { + (let position : Int <- 0 in + (let num : Int <- num_cells() in + (let temp : String in + { + while position < num loop + { + temp <- temp.concat(cell_at_next_evolution(position)); + position <- position + 1; + } + pool; + population_map <- temp; + self; + } + ) ) ) + }; + +(* This is where the background pattern is detremined by the user. More + patterns can be added as long as whoever adds keeps the board either + 3x5, 4x5, 5x5, 3x7, 7x4, 4x4 with the row first then column. *) + option(): String { + { + (let num : Int in + { + out_string("\nPlease chose a number:\n"); + out_string("\t1: A cross\n"); + out_string("\t2: A slash from the upper left to lower right\n"); + out_string("\t3: A slash from the upper right to lower left\n"); + out_string("\t4: An X\n"); + out_string("\t5: A greater than sign \n"); + out_string("\t6: A less than sign\n"); + out_string("\t7: Two greater than signs\n"); + out_string("\t8: Two less than signs\n"); + out_string("\t9: A 'V'\n"); + out_string("\t10: An inverse 'V'\n"); + out_string("\t11: Numbers 9 and 10 combined\n"); + out_string("\t12: A full grid\n"); + out_string("\t13: A 'T'\n"); + out_string("\t14: A plus '+'\n"); + out_string("\t15: A 'W'\n"); + out_string("\t16: An 'M'\n"); + out_string("\t17: An 'E'\n"); + out_string("\t18: A '3'\n"); + out_string("\t19: An 'O'\n"); + out_string("\t20: An '8'\n"); + out_string("\t21: An 'S'\n"); + out_string("Your choice => "); + num <- in_int(); + out_string("\n"); + if num = 1 then + " XX XXXX XXXX XX " + else if num = 2 then + " X X X X X " + else if num = 3 then + "X X X X X" + else if num = 4 then + "X X X X X X X X X" + else if num = 5 then + "X X X X X " + else if num = 6 then + " X X X X X" + else if num = 7 then + "X X X XX X " + else if num = 8 then + " X XX X X X " + else if num = 9 then + "X X X X X " + else if num = 10 then + " X X X X X" + else if num = 11 then + "X X X X X X X X" + else if num = 12 then + "XXXXXXXXXXXXXXXXXXXXXXXXX" + else if num = 13 then + "XXXXX X X X X " + else if num = 14 then + " X X XXXXX X X " + else if num = 15 then + "X X X X X X X " + else if num = 16 then + " X X X X X X X" + else if num = 17 then + "XXXXX X XXXXX X XXXX" + else if num = 18 then + "XXX X X X X XXXX " + else if num = 19 then + " XX X XX X XX " + else if num = 20 then + " XX X XX X XX X XX X XX " + else if num = 21 then + " XXXX X XX X XXXX " + else + " " + fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi; + } + ); + } + }; + + + + + prompt() : Bool { + { + (let ans : String in + { + out_string("Would you like to continue with the next generation? \n"); + out_string("Please use lowercase y or n for your answer [y]: "); + ans <- in_string(); + out_string("\n"); + if ans = "n" then + false + else + true + fi; + } + ); + } + }; + + + prompt2() : Bool { + (let ans : String in + { + out_string("\n\n"); + out_string("Would you like to choose a background pattern? \n"); + out_string("Please use lowercase y or n for your answer [n]: "); + ans <- in_string(); + if ans = "y" then + true + else + false + fi; + } + ) + }; + + +}; + +class Main inherits CellularAutomaton { + cells : CellularAutomaton; + + main() : Main { + { + (let continue : Bool in + (let choice : String in + { + out_string("Welcome to the Game of Life.\n"); + out_string("There are many initial states to choose from. \n"); + while prompt2() loop + { + continue <- true; + choice <- option(); + cells <- (new CellularAutomaton).init(choice); + cells.print(); + while continue loop + if prompt() then + { + cells.evolve(); + cells.print(); + } + else + continue <- false + fi + pool; + } + pool; + self; + } ) ); } + }; +}; + diff --git a/tests/codegen/life_input.txt b/tests/codegen/life_input.txt index 07e016726..1dfbde620 100644 --- a/tests/codegen/life_input.txt +++ b/tests/codegen/life_input.txt @@ -1,66 +1,66 @@ -y -1 -n -y -2 -n -y -3 -n -y -4 -n -y -5 -n -y -6 -n -y -7 -n -y -8 -n -y -9 -n -y -10 -n -y -11 -n -y -12 -n -y -13 -n -y -14 -n -y -15 -n -y -16 -n -y -17 -n -y -18 -n -y -19 -n -y -20 -n -y -21 -y -y -n +y +1 +n +y +2 +n +y +3 +n +y +4 +n +y +5 +n +y +6 +n +y +7 +n +y +8 +n +y +9 +n +y +10 +n +y +11 +n +y +12 +n +y +13 +n +y +14 +n +y +15 +n +y +16 +n +y +17 +n +y +18 +n +y +19 +n +y +20 +n +y +21 +y +y +n n \ No newline at end of file diff --git a/tests/codegen/life_output.txt b/tests/codegen/life_output.txt index 5a9b9f73d..e804b2382 100644 --- a/tests/codegen/life_output.txt +++ b/tests/codegen/life_output.txt @@ -1,778 +1,778 @@ -Welcome to the Game of Life. -There are many initial states to choose from. - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - XX -XXXX -XXXX - XX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - X - X - X - X -X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X - X - X - X - X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X X - X X - X - X X -X X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X - X - X - X -X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - X - X - X - X - X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X X - X X -X X - - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - X X -X X - X X - - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X X - X X - X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - X - X X -X X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X X X - X X -X X X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -XXXXX -XXXXX -XXXXX -XXXXX -XXXXX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -XXXXX - X - X - X - X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - X - X -XXXXX - X - X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X X - X X X - X X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - X X - X X X -X X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -XXXX -X -X -XXXX -X -X -XXXX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -XXX - X - X - X - X - X -XXX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - XX -X X -X X - XX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - XX -X X -X X - XX -X X -X X - XX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - XXX -X -X - XX - X - X -XXX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - --XX- -X-X- -X--- --XX- ----X --X-X --XX- - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - --XX- -X-X- -X-X- --XX- --X-X --X-X --XX- - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? +Welcome to the Game of Life. +There are many initial states to choose from. + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + XX +XXXX +XXXX + XX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + X + X + X + X +X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X + X + X + X + X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X X + X X + X + X X +X X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X + X + X + X +X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + X + X + X + X + X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X X + X X +X X + + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + X X +X X + X X + + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X X + X X + X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + X + X X +X X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X X X + X X +X X X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +XXXXX +XXXXX +XXXXX +XXXXX +XXXXX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +XXXXX + X + X + X + X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + X + X +XXXXX + X + X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X X + X X X + X X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + X X + X X X +X X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +XXXX +X +X +XXXX +X +X +XXXX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +XXX + X + X + X + X + X +XXX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + XX +X X +X X + XX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + XX +X X +X X + XX +X X +X X + XX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + XXX +X +X + XX + X + X +XXX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + +-XX- +X-X- +X--- +-XX- +---X +-X-X +-XX- + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + +-XX- +X-X- +X-X- +-XX- +-X-X +-X-X +-XX- + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? Please use lowercase y or n for your answer [n]: \ No newline at end of file diff --git a/tests/codegen/list_output.txt b/tests/codegen/list_output.txt index fca724903..00d68ed23 100644 --- a/tests/codegen/list_output.txt +++ b/tests/codegen/list_output.txt @@ -1,5 +1,5 @@ -5 4 3 2 1 -4 3 2 1 -3 2 1 -2 1 -1 +5 4 3 2 1 +4 3 2 1 +3 2 1 +2 1 +1 diff --git a/tests/codegen/new_complex.cl b/tests/codegen/new_complex.cl index a4fe714ce..ad7035b56 100755 --- a/tests/codegen/new_complex.cl +++ b/tests/codegen/new_complex.cl @@ -1,79 +1,79 @@ -class Main inherits IO { - main() : IO { - (let c : Complex <- (new Complex).init(1, 1) in - { - -- trivially equal (see CoolAid) - if c.reflect_X() = c.reflect_0() - then out_string("=)\n") - else out_string("=(\n") - fi; - -- equal - if c.reflect_X().reflect_Y().equal(c.reflect_0()) - then out_string("=)\n") - else out_string("=(\n") - fi; - } - ) - }; -}; - -class Complex inherits IO { - x : Int; - y : Int; - - init(a : Int, b : Int) : Complex { - { - x = a; - y = b; - self; - } - }; - - print() : Object { - if y = 0 - then out_int(x) - else out_int(x).out_string("+").out_int(y).out_string("I") - fi - }; - - reflect_0() : Complex { - { - x = ~x; - y = ~y; - self; - } - }; - - reflect_X() : Complex { - { - y = ~y; - self; - } - }; - - reflect_Y() : Complex { - { - x = ~x; - self; - } - }; - - equal(d : Complex) : Bool { - if x = d.x_value() - then - if y = d.y_value() - then true - else false - fi - else false - fi - }; - - x_value() : Int { - x - }; - - y_value() : Int { - y - }; -}; +class Main inherits IO { + main() : IO { + (let c : Complex <- (new Complex).init(1, 1) in + { + -- trivially equal (see CoolAid) + if c.reflect_X() = c.reflect_0() + then out_string("=)\n") + else out_string("=(\n") + fi; + -- equal + if c.reflect_X().reflect_Y().equal(c.reflect_0()) + then out_string("=)\n") + else out_string("=(\n") + fi; + } + ) + }; +}; + +class Complex inherits IO { + x : Int; + y : Int; + + init(a : Int, b : Int) : Complex { + { + x = a; + y = b; + self; + } + }; + + print() : Object { + if y = 0 + then out_int(x) + else out_int(x).out_string("+").out_int(y).out_string("I") + fi + }; + + reflect_0() : Complex { + { + x = ~x; + y = ~y; + self; + } + }; + + reflect_X() : Complex { + { + y = ~y; + self; + } + }; + + reflect_Y() : Complex { + { + x = ~x; + self; + } + }; + + equal(d : Complex) : Bool { + if x = d.x_value() + then + if y = d.y_value() + then true + else false + fi + else false + fi + }; + + x_value() : Int { + x + }; + + y_value() : Int { + y + }; +}; diff --git a/tests/codegen/new_complex_output.txt b/tests/codegen/new_complex_output.txt index 0e8da112c..831c23af4 100644 --- a/tests/codegen/new_complex_output.txt +++ b/tests/codegen/new_complex_output.txt @@ -1,2 +1,2 @@ -=) -=) +=) +=) diff --git a/tests/codegen/palindrome.cl b/tests/codegen/palindrome.cl index 7f24789f9..6acbeb731 100755 --- a/tests/codegen/palindrome.cl +++ b/tests/codegen/palindrome.cl @@ -1,25 +1,25 @@ -class Main inherits IO { - pal(s : String) : Bool { - if s.length() = 0 - then true - else if s.length() = 1 - then true - else if s.substr(0, 1) = s.substr(s.length() - 1, 1) - then pal(s.substr(1, s.length() -2)) - else false - fi fi fi - }; - - i : Int; - - main() : IO { - { - i <- ~1; - out_string("enter a string\n"); - if pal(in_string()) - then out_string("that was a palindrome\n") - else out_string("that was not a palindrome\n") - fi; - } - }; -}; +class Main inherits IO { + pal(s : String) : Bool { + if s.length() = 0 + then true + else if s.length() = 1 + then true + else if s.substr(0, 1) = s.substr(s.length() - 1, 1) + then pal(s.substr(1, s.length() -2)) + else false + fi fi fi + }; + + i : Int; + + main() : IO { + { + i <- ~1; + out_string("enter a string\n"); + if pal(in_string()) + then out_string("that was a palindrome\n") + else out_string("that was not a palindrome\n") + fi; + } + }; +}; diff --git a/tests/codegen/palindrome_input.txt b/tests/codegen/palindrome_input.txt index 8e1b64142..c49a0114c 100644 --- a/tests/codegen/palindrome_input.txt +++ b/tests/codegen/palindrome_input.txt @@ -1 +1 @@ -anitalabalatina +anitalabalatina diff --git a/tests/codegen/palindrome_output.txt b/tests/codegen/palindrome_output.txt index 7a0095959..e93d36585 100644 --- a/tests/codegen/palindrome_output.txt +++ b/tests/codegen/palindrome_output.txt @@ -1,2 +1,2 @@ -enter a string -that was a palindrome +enter a string +that was a palindrome diff --git a/tests/codegen/primes_output.txt b/tests/codegen/primes_output.txt index a4d0fcb3f..cf5d78d49 100644 --- a/tests/codegen/primes_output.txt +++ b/tests/codegen/primes_output.txt @@ -1,96 +1,96 @@ -2 is trivially prime. -3 is prime. -5 is prime. -7 is prime. -11 is prime. -13 is prime. -17 is prime. -19 is prime. -23 is prime. -29 is prime. -31 is prime. -37 is prime. -41 is prime. -43 is prime. -47 is prime. -53 is prime. -59 is prime. -61 is prime. -67 is prime. -71 is prime. -73 is prime. -79 is prime. -83 is prime. -89 is prime. -97 is prime. -101 is prime. -103 is prime. -107 is prime. -109 is prime. -113 is prime. -127 is prime. -131 is prime. -137 is prime. -139 is prime. -149 is prime. -151 is prime. -157 is prime. -163 is prime. -167 is prime. -173 is prime. -179 is prime. -181 is prime. -191 is prime. -193 is prime. -197 is prime. -199 is prime. -211 is prime. -223 is prime. -227 is prime. -229 is prime. -233 is prime. -239 is prime. -241 is prime. -251 is prime. -257 is prime. -263 is prime. -269 is prime. -271 is prime. -277 is prime. -281 is prime. -283 is prime. -293 is prime. -307 is prime. -311 is prime. -313 is prime. -317 is prime. -331 is prime. -337 is prime. -347 is prime. -349 is prime. -353 is prime. -359 is prime. -367 is prime. -373 is prime. -379 is prime. -383 is prime. -389 is prime. -397 is prime. -401 is prime. -409 is prime. -419 is prime. -421 is prime. -431 is prime. -433 is prime. -439 is prime. -443 is prime. -449 is prime. -457 is prime. -461 is prime. -463 is prime. -467 is prime. -479 is prime. -487 is prime. -491 is prime. -499 is prime. -Abort called from class String +2 is trivially prime. +3 is prime. +5 is prime. +7 is prime. +11 is prime. +13 is prime. +17 is prime. +19 is prime. +23 is prime. +29 is prime. +31 is prime. +37 is prime. +41 is prime. +43 is prime. +47 is prime. +53 is prime. +59 is prime. +61 is prime. +67 is prime. +71 is prime. +73 is prime. +79 is prime. +83 is prime. +89 is prime. +97 is prime. +101 is prime. +103 is prime. +107 is prime. +109 is prime. +113 is prime. +127 is prime. +131 is prime. +137 is prime. +139 is prime. +149 is prime. +151 is prime. +157 is prime. +163 is prime. +167 is prime. +173 is prime. +179 is prime. +181 is prime. +191 is prime. +193 is prime. +197 is prime. +199 is prime. +211 is prime. +223 is prime. +227 is prime. +229 is prime. +233 is prime. +239 is prime. +241 is prime. +251 is prime. +257 is prime. +263 is prime. +269 is prime. +271 is prime. +277 is prime. +281 is prime. +283 is prime. +293 is prime. +307 is prime. +311 is prime. +313 is prime. +317 is prime. +331 is prime. +337 is prime. +347 is prime. +349 is prime. +353 is prime. +359 is prime. +367 is prime. +373 is prime. +379 is prime. +383 is prime. +389 is prime. +397 is prime. +401 is prime. +409 is prime. +419 is prime. +421 is prime. +431 is prime. +433 is prime. +439 is prime. +443 is prime. +449 is prime. +457 is prime. +461 is prime. +463 is prime. +467 is prime. +479 is prime. +487 is prime. +491 is prime. +499 is prime. +Abort called from class String diff --git a/tests/codegen/print-cool_output.txt b/tests/codegen/print-cool_output.txt index 2b58f8985..3c8cd620c 100644 --- a/tests/codegen/print-cool_output.txt +++ b/tests/codegen/print-cool_output.txt @@ -1 +1 @@ -cool +cool diff --git a/tests/codegen/sort-list_input.txt b/tests/codegen/sort-list_input.txt index f599e28b8..d43401489 100644 --- a/tests/codegen/sort-list_input.txt +++ b/tests/codegen/sort-list_input.txt @@ -1 +1 @@ -10 +10 diff --git a/tests/codegen/sort-list_output.txt b/tests/codegen/sort-list_output.txt index 9878d57ea..7b1d40452 100644 --- a/tests/codegen/sort-list_output.txt +++ b/tests/codegen/sort-list_output.txt @@ -1,10 +1,10 @@ -How many numbers to sort? 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 +How many numbers to sort? 0 +1 +2 +3 +4 +5 +6 +7 +8 +9 diff --git a/tests/codegen_test.py b/tests/codegen_test.py index 48df768ff..e748bd2d1 100644 --- a/tests/codegen_test.py +++ b/tests/codegen_test.py @@ -1,17 +1,17 @@ -import pytest -import os -from utils import compare_outputs - -tests_dir = __file__.rpartition('/')[0] + '/codegen/' -tests = [(file) for file in os.listdir(tests_dir) if file.endswith('.cl')] - -# @pytest.mark.lexer -# @pytest.mark.parser -# @pytest.mark.semantic -@pytest.mark.codegen -@pytest.mark.ok -@pytest.mark.run(order=4) -@pytest.mark.parametrize("cool_file", tests) -def test_codegen(compiler_path, cool_file): - compare_outputs(compiler_path, tests_dir + cool_file, tests_dir + cool_file[:-3] + '_input.txt',\ +import pytest +import os +from utils import compare_outputs + +tests_dir = __file__.rpartition('/')[0] + '/codegen/' +tests = [(file) for file in os.listdir(tests_dir) if file.endswith('.cl')] + +# @pytest.mark.lexer +# @pytest.mark.parser +# @pytest.mark.semantic +@pytest.mark.codegen +@pytest.mark.ok +@pytest.mark.run(order=4) +@pytest.mark.parametrize("cool_file", tests) +def test_codegen(compiler_path, cool_file): + compare_outputs(compiler_path, tests_dir + cool_file, tests_dir + cool_file[:-3] + '_input.txt',\ tests_dir + cool_file[:-3] + '_output.txt') \ No newline at end of file diff --git a/tests/conftest.py b/tests/conftest.py index 1f44eeb72..561d8bafc 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,6 @@ -import pytest -import os - -@pytest.fixture -def compiler_path(): +import pytest +import os + +@pytest.fixture +def compiler_path(): return os.path.abspath('./coolc.sh') \ No newline at end of file diff --git a/tests/lexer/comment1.cl b/tests/lexer/comment1.cl index 69533f23c..1b63af3c7 100644 --- a/tests/lexer/comment1.cl +++ b/tests/lexer/comment1.cl @@ -1,55 +1,55 @@ ---Any characters between two dashes “--” and the next newline ---(or EOF, if there is no next newline) are treated as comments - -(*(*(* -Comments may also be written by enclosing -text in (∗ . . . ∗). The latter form of comment may be nested. -Comments cannot cross file boundaries. -*)*)*) - -class Error() { - - (* There was once a comment, - that was quite long. - But, the reader soon discovered that - the comment was indeed longer than - previously assumed. Now, the reader - was in a real dilemma; is the comment - ever gonna end? If I stop reading, will - it end? - He started imagining all sorts of things. - He thought about heisenberg's cat and how - how that relates to the end of the sentence. - He thought to himself "I'm gonna stop reading". - "If I keep reading this comment, I'm gonna know - the fate of this sentence; That will be disastorous." - He knew that such a comment was gonna extend to - another file. It was too awesome to be contained in - a single file. And he would have kept reading too... - if only... - cool wasn't a super-duper-fab-awesomest language; - but cool is that language; - "This comment shall go not cross this file" said cool. - Alas! The reader could read no more. - There was once a comment, - that was quite long. - But, the reader soon discovered that - the comment was indeed longer than - previously assumed. Now, the reader - was in a real dilemma; is the comment - ever gonna end? If I stop reading, will - it end? - He started imagining all sorts of things. - He thought about heisenberg's cat and how - how that relates to the end of the sentence. - He thought to himself "I'm gonna stop reading". - "If I keep reading this comment, I'm gonna know - the fate of this sentence; That will be disastorous." - He knew that such a comment was gonna extend to - another file. It was too awesome to be contained in - a single file. And he would have kept reading too... - if only... - cool wasn't a super-duper-fab-awesomest language; - but cool is that language; - "This comment shall go not cross this file" said cool. +--Any characters between two dashes “--” and the next newline +--(or EOF, if there is no next newline) are treated as comments + +(*(*(* +Comments may also be written by enclosing +text in (∗ . . . ∗). The latter form of comment may be nested. +Comments cannot cross file boundaries. +*)*)*) + +class Error() { + + (* There was once a comment, + that was quite long. + But, the reader soon discovered that + the comment was indeed longer than + previously assumed. Now, the reader + was in a real dilemma; is the comment + ever gonna end? If I stop reading, will + it end? + He started imagining all sorts of things. + He thought about heisenberg's cat and how + how that relates to the end of the sentence. + He thought to himself "I'm gonna stop reading". + "If I keep reading this comment, I'm gonna know + the fate of this sentence; That will be disastorous." + He knew that such a comment was gonna extend to + another file. It was too awesome to be contained in + a single file. And he would have kept reading too... + if only... + cool wasn't a super-duper-fab-awesomest language; + but cool is that language; + "This comment shall go not cross this file" said cool. + Alas! The reader could read no more. + There was once a comment, + that was quite long. + But, the reader soon discovered that + the comment was indeed longer than + previously assumed. Now, the reader + was in a real dilemma; is the comment + ever gonna end? If I stop reading, will + it end? + He started imagining all sorts of things. + He thought about heisenberg's cat and how + how that relates to the end of the sentence. + He thought to himself "I'm gonna stop reading". + "If I keep reading this comment, I'm gonna know + the fate of this sentence; That will be disastorous." + He knew that such a comment was gonna extend to + another file. It was too awesome to be contained in + a single file. And he would have kept reading too... + if only... + cool wasn't a super-duper-fab-awesomest language; + but cool is that language; + "This comment shall go not cross this file" said cool. Alas! The reader could read no more. \ No newline at end of file diff --git a/tests/lexer/comment1_error.txt b/tests/lexer/comment1_error.txt index 9fd7b8d67..710483ee9 100644 --- a/tests/lexer/comment1_error.txt +++ b/tests/lexer/comment1_error.txt @@ -1 +1 @@ -(55, 46) - LexicographicError: EOF in comment +(55, 46) - LexicographicError: EOF in comment diff --git a/tests/lexer/iis1.cl b/tests/lexer/iis1.cl index 12cb52beb..ca6b68ac3 100644 --- a/tests/lexer/iis1.cl +++ b/tests/lexer/iis1.cl @@ -1,111 +1,111 @@ -(* Integers, Identifiers, and Special Notation *) - -0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ -5! = 120, 2 + 2 = 5 or E = mc2; p + 1 @ p = 1: for x in range(len(b)) -new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) -class Class if then else fi testing Testing ~007agent_bond james_007B0N3SS___ -loop pool while tRuE or noT faLsE let in case of ESAC - -(* -#3 INT_CONST 0007 -#3 INT_CONST 123 -#3 '+' -#3 INT_CONST 1 -#3 '-' -#3 INT_CONST 1 -#3 '+' -#3 INT_CONST 90 -#3 '-' -#3 INT_CONST 09 -#3 '+' -#3 INT_CONST 11113 -#3 '-' -#3 INT_CONST 4 -#3 OBJECTID r -#3 '*' -#3 OBJECTID a -#3 '*' -#3 OBJECTID self -#3 '*' -#3 OBJECTID c -#3 '+' -#3 '+' -#4 INT_CONST 5 -#4 ERROR "!" -#4 '=' -#4 INT_CONST 120 -#4 ',' -#4 INT_CONST 2 -#4 '+' -#4 INT_CONST 2 -#4 '=' -#4 INT_CONST 5 -#4 OBJECTID or -#4 TYPEID E -#4 '=' -#4 OBJECTID mc2 -#4 ';' -#4 OBJECTID p -#4 '+' -#4 INT_CONST 1 -#4 '@' -#4 OBJECTID p -#4 '=' -#4 INT_CONST 1 -#4 ':' -#4 OBJECTID for -#4 OBJECTID x -#4 IN -#4 OBJECTID range -#4 '(' -#4 OBJECTID len -#4 '(' -#4 OBJECTID b -#4 ')' -#4 ')' -#5 NEW -#5 '/' -#5 ASSIGN -#5 '<' -#5 LE -#5 DARROW -#5 '{' -#5 '(' -#5 TYPEID Int -#5 ':' -#5 TYPEID Objet -#5 ',' -#5 TYPEID Bool -#5 ';' -#5 TYPEID String -#5 '.' -#5 OBJECTID string -#5 TYPEID SELF_TYPE -#5 ISVOID -#5 '}' -#5 ')' -#6 CLASS -#6 CLASS -#6 IF -#6 THEN -#6 ELSE -#6 FI -#6 OBJECTID testing -#6 TYPEID Testing -#6 '~' -#6 INT_CONST 007 -#6 OBJECTID agent_bond -#6 OBJECTID james_007B0N3SS___ -#7 LOOP -#7 POOL -#7 WHILE -#7 BOOL_CONST true -#7 OBJECTID or -#7 NOT -#7 BOOL_CONST false -#7 LET -#7 IN -#7 CASE -#7 OF -#7 ESAC +(* Integers, Identifiers, and Special Notation *) + +0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ +5! = 120, 2 + 2 = 5 or E = mc2; p + 1 @ p = 1: for x in range(len(b)) +new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) +class Class if then else fi testing Testing ~007agent_bond james_007B0N3SS___ +loop pool while tRuE or noT faLsE let in case of ESAC + +(* +#3 INT_CONST 0007 +#3 INT_CONST 123 +#3 '+' +#3 INT_CONST 1 +#3 '-' +#3 INT_CONST 1 +#3 '+' +#3 INT_CONST 90 +#3 '-' +#3 INT_CONST 09 +#3 '+' +#3 INT_CONST 11113 +#3 '-' +#3 INT_CONST 4 +#3 OBJECTID r +#3 '*' +#3 OBJECTID a +#3 '*' +#3 OBJECTID self +#3 '*' +#3 OBJECTID c +#3 '+' +#3 '+' +#4 INT_CONST 5 +#4 ERROR "!" +#4 '=' +#4 INT_CONST 120 +#4 ',' +#4 INT_CONST 2 +#4 '+' +#4 INT_CONST 2 +#4 '=' +#4 INT_CONST 5 +#4 OBJECTID or +#4 TYPEID E +#4 '=' +#4 OBJECTID mc2 +#4 ';' +#4 OBJECTID p +#4 '+' +#4 INT_CONST 1 +#4 '@' +#4 OBJECTID p +#4 '=' +#4 INT_CONST 1 +#4 ':' +#4 OBJECTID for +#4 OBJECTID x +#4 IN +#4 OBJECTID range +#4 '(' +#4 OBJECTID len +#4 '(' +#4 OBJECTID b +#4 ')' +#4 ')' +#5 NEW +#5 '/' +#5 ASSIGN +#5 '<' +#5 LE +#5 DARROW +#5 '{' +#5 '(' +#5 TYPEID Int +#5 ':' +#5 TYPEID Objet +#5 ',' +#5 TYPEID Bool +#5 ';' +#5 TYPEID String +#5 '.' +#5 OBJECTID string +#5 TYPEID SELF_TYPE +#5 ISVOID +#5 '}' +#5 ')' +#6 CLASS +#6 CLASS +#6 IF +#6 THEN +#6 ELSE +#6 FI +#6 OBJECTID testing +#6 TYPEID Testing +#6 '~' +#6 INT_CONST 007 +#6 OBJECTID agent_bond +#6 OBJECTID james_007B0N3SS___ +#7 LOOP +#7 POOL +#7 WHILE +#7 BOOL_CONST true +#7 OBJECTID or +#7 NOT +#7 BOOL_CONST false +#7 LET +#7 IN +#7 CASE +#7 OF +#7 ESAC *) \ No newline at end of file diff --git a/tests/lexer/iis1_error.txt b/tests/lexer/iis1_error.txt index 9e6d66cac..12f62f1ba 100644 --- a/tests/lexer/iis1_error.txt +++ b/tests/lexer/iis1_error.txt @@ -1 +1 @@ -(4, 2) - LexicographicError: ERROR "!" +(4, 2) - LexicographicError: ERROR "!" diff --git a/tests/lexer/iis2.cl b/tests/lexer/iis2.cl index 9b25715d4..d42552494 100644 --- a/tests/lexer/iis2.cl +++ b/tests/lexer/iis2.cl @@ -1,120 +1,120 @@ -(* Integers, Identifiers, and Special Notation *) - -0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ -class Class if then else fi testing Testing ~007agent_bond james_007bones___ - - -new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) -loop pool while tRuE or noT faLsE let in case of ESAC - -factorial(5) = 120, 2 + 2 = 5? or E = mc2; p + 1 resto p = 1: (@ for x in range(len(b))) - -(* -#3 INT_CONST 0007 -#3 INT_CONST 123 -#3 '+' -#3 INT_CONST 1 -#3 '-' -#3 INT_CONST 1 -#3 '+' -#3 INT_CONST 90 -#3 '-' -#3 INT_CONST 09 -#3 '+' -#3 INT_CONST 11113 -#3 '-' -#3 INT_CONST 4 -#3 OBJECTID r -#3 '*' -#3 OBJECTID a -#3 '*' -#3 OBJECTID self -#3 '*' -#3 OBJECTID c -#3 '+' -#3 '+' -#4 CLASS -#4 CLASS -#4 IF -#4 THEN -#4 ELSE -#4 FI -#4 OBJECTID testing -#4 TYPEID Testing -#4 '~' -#4 INT_CONST 007 -#4 OBJECTID agent_bond -#4 OBJECTID james_007bones___ -#7 NEW -#7 '/' -#7 ASSIGN -#7 '<' -#7 LE -#7 DARROW -#7 '{' -#7 '(' -#7 TYPEID Int -#7 ':' -#7 TYPEID Objet -#7 ',' -#7 TYPEID Bool -#7 ';' -#7 TYPEID String -#7 '.' -#7 OBJECTID string -#7 TYPEID SELF_TYPE -#7 ISVOID -#7 '}' -#7 ')' -#8 LOOP -#8 POOL -#8 WHILE -#8 BOOL_CONST true -#8 OBJECTID or -#8 NOT -#8 BOOL_CONST false -#8 LET -#8 IN -#8 CASE -#8 OF -#8 ESAC -#10 OBJECTID factorial -#10 '(' -#10 INT_CONST 5 -#10 ')' -#10 '=' -#10 INT_CONST 120 -#10 ',' -#10 INT_CONST 2 -#10 '+' -#10 INT_CONST 2 -#10 '=' -#10 INT_CONST 5 -#10 ERROR "?" -#10 OBJECTID or -#10 TYPEID E -#10 '=' -#10 OBJECTID mc2 -#10 ';' -#10 OBJECTID p -#10 '+' -#10 INT_CONST 1 -#10 OBJECTID resto -#10 OBJECTID p -#10 '=' -#10 INT_CONST 1 -#10 ':' -#10 '(' -#10 '@' -#10 OBJECTID for -#10 OBJECTID x -#10 IN -#10 OBJECTID range -#10 '(' -#10 OBJECTID len -#10 '(' -#10 OBJECTID b -#10 ')' -#10 ')' -#10 ')' +(* Integers, Identifiers, and Special Notation *) + +0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ +class Class if then else fi testing Testing ~007agent_bond james_007bones___ + + +new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) +loop pool while tRuE or noT faLsE let in case of ESAC + +factorial(5) = 120, 2 + 2 = 5? or E = mc2; p + 1 resto p = 1: (@ for x in range(len(b))) + +(* +#3 INT_CONST 0007 +#3 INT_CONST 123 +#3 '+' +#3 INT_CONST 1 +#3 '-' +#3 INT_CONST 1 +#3 '+' +#3 INT_CONST 90 +#3 '-' +#3 INT_CONST 09 +#3 '+' +#3 INT_CONST 11113 +#3 '-' +#3 INT_CONST 4 +#3 OBJECTID r +#3 '*' +#3 OBJECTID a +#3 '*' +#3 OBJECTID self +#3 '*' +#3 OBJECTID c +#3 '+' +#3 '+' +#4 CLASS +#4 CLASS +#4 IF +#4 THEN +#4 ELSE +#4 FI +#4 OBJECTID testing +#4 TYPEID Testing +#4 '~' +#4 INT_CONST 007 +#4 OBJECTID agent_bond +#4 OBJECTID james_007bones___ +#7 NEW +#7 '/' +#7 ASSIGN +#7 '<' +#7 LE +#7 DARROW +#7 '{' +#7 '(' +#7 TYPEID Int +#7 ':' +#7 TYPEID Objet +#7 ',' +#7 TYPEID Bool +#7 ';' +#7 TYPEID String +#7 '.' +#7 OBJECTID string +#7 TYPEID SELF_TYPE +#7 ISVOID +#7 '}' +#7 ')' +#8 LOOP +#8 POOL +#8 WHILE +#8 BOOL_CONST true +#8 OBJECTID or +#8 NOT +#8 BOOL_CONST false +#8 LET +#8 IN +#8 CASE +#8 OF +#8 ESAC +#10 OBJECTID factorial +#10 '(' +#10 INT_CONST 5 +#10 ')' +#10 '=' +#10 INT_CONST 120 +#10 ',' +#10 INT_CONST 2 +#10 '+' +#10 INT_CONST 2 +#10 '=' +#10 INT_CONST 5 +#10 ERROR "?" +#10 OBJECTID or +#10 TYPEID E +#10 '=' +#10 OBJECTID mc2 +#10 ';' +#10 OBJECTID p +#10 '+' +#10 INT_CONST 1 +#10 OBJECTID resto +#10 OBJECTID p +#10 '=' +#10 INT_CONST 1 +#10 ':' +#10 '(' +#10 '@' +#10 OBJECTID for +#10 OBJECTID x +#10 IN +#10 OBJECTID range +#10 '(' +#10 OBJECTID len +#10 '(' +#10 OBJECTID b +#10 ')' +#10 ')' +#10 ')' *) \ No newline at end of file diff --git a/tests/lexer/iis2_error.txt b/tests/lexer/iis2_error.txt index 922391a9d..988d0286e 100644 --- a/tests/lexer/iis2_error.txt +++ b/tests/lexer/iis2_error.txt @@ -1 +1 @@ -(10, 30) - LexicographicError: ERROR "?" +(10, 30) - LexicographicError: ERROR "?" diff --git a/tests/lexer/iis3.cl b/tests/lexer/iis3.cl index 0b965ddea..dcd85f960 100644 --- a/tests/lexer/iis3.cl +++ b/tests/lexer/iis3.cl @@ -1,121 +1,121 @@ -(* Integers, Identifiers, and Special Notation *) - -factorial(5) = 120, 2 + 2 = 5 or E = mc^2; p + 1 @ p = 1: z for x in range(len(b))) - -loop pool while tRuE or noT faLsE let in case of ESAC - -new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) - - -0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ -class Class if then else fi testing Testing ~007agent_bond james_007bones___ - -(* -#3 OBJECTID factorial -#3 '(' -#3 INT_CONST 5 -#3 ')' -#3 '=' -#3 INT_CONST 120 -#3 ',' -#3 INT_CONST 2 -#3 '+' -#3 INT_CONST 2 -#3 '=' -#3 INT_CONST 5 -#3 OBJECTID or -#3 TYPEID E -#3 '=' -#3 OBJECTID mc -#3 ERROR "^" -#3 INT_CONST 2 -#3 ';' -#3 OBJECTID p -#3 '+' -#3 INT_CONST 1 -#3 '@' -#3 OBJECTID p -#3 '=' -#3 INT_CONST 1 -#3 ':' -#3 OBJECTID z -#3 OBJECTID for -#3 OBJECTID x -#3 IN -#3 OBJECTID range -#3 '(' -#3 OBJECTID len -#3 '(' -#3 OBJECTID b -#3 ')' -#3 ')' -#3 ')' -#5 LOOP -#5 POOL -#5 WHILE -#5 BOOL_CONST true -#5 OBJECTID or -#5 NOT -#5 BOOL_CONST false -#5 LET -#5 IN -#5 CASE -#5 OF -#5 ESAC -#7 NEW -#7 '/' -#7 ASSIGN -#7 '<' -#7 LE -#7 DARROW -#7 '{' -#7 '(' -#7 TYPEID Int -#7 ':' -#7 TYPEID Objet -#7 ',' -#7 TYPEID Bool -#7 ';' -#7 TYPEID String -#7 '.' -#7 OBJECTID string -#7 TYPEID SELF_TYPE -#7 ISVOID -#7 '}' -#7 ')' -#10 INT_CONST 0007 -#10 INT_CONST 123 -#10 '+' -#10 INT_CONST 1 -#10 '-' -#10 INT_CONST 1 -#10 '+' -#10 INT_CONST 90 -#10 '-' -#10 INT_CONST 09 -#10 '+' -#10 INT_CONST 11113 -#10 '-' -#10 INT_CONST 4 -#10 OBJECTID r -#10 '*' -#10 OBJECTID a -#10 '*' -#10 OBJECTID self -#10 '*' -#10 OBJECTID c -#10 '+' -#10 '+' -#11 CLASS -#11 CLASS -#11 IF -#11 THEN -#11 ELSE -#11 FI -#11 OBJECTID testing -#11 TYPEID Testing -#11 '~' -#11 INT_CONST 007 -#11 OBJECTID agent_bond -#11 OBJECTID james_007bones___ +(* Integers, Identifiers, and Special Notation *) + +factorial(5) = 120, 2 + 2 = 5 or E = mc^2; p + 1 @ p = 1: z for x in range(len(b))) + +loop pool while tRuE or noT faLsE let in case of ESAC + +new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) + + +0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ +class Class if then else fi testing Testing ~007agent_bond james_007bones___ + +(* +#3 OBJECTID factorial +#3 '(' +#3 INT_CONST 5 +#3 ')' +#3 '=' +#3 INT_CONST 120 +#3 ',' +#3 INT_CONST 2 +#3 '+' +#3 INT_CONST 2 +#3 '=' +#3 INT_CONST 5 +#3 OBJECTID or +#3 TYPEID E +#3 '=' +#3 OBJECTID mc +#3 ERROR "^" +#3 INT_CONST 2 +#3 ';' +#3 OBJECTID p +#3 '+' +#3 INT_CONST 1 +#3 '@' +#3 OBJECTID p +#3 '=' +#3 INT_CONST 1 +#3 ':' +#3 OBJECTID z +#3 OBJECTID for +#3 OBJECTID x +#3 IN +#3 OBJECTID range +#3 '(' +#3 OBJECTID len +#3 '(' +#3 OBJECTID b +#3 ')' +#3 ')' +#3 ')' +#5 LOOP +#5 POOL +#5 WHILE +#5 BOOL_CONST true +#5 OBJECTID or +#5 NOT +#5 BOOL_CONST false +#5 LET +#5 IN +#5 CASE +#5 OF +#5 ESAC +#7 NEW +#7 '/' +#7 ASSIGN +#7 '<' +#7 LE +#7 DARROW +#7 '{' +#7 '(' +#7 TYPEID Int +#7 ':' +#7 TYPEID Objet +#7 ',' +#7 TYPEID Bool +#7 ';' +#7 TYPEID String +#7 '.' +#7 OBJECTID string +#7 TYPEID SELF_TYPE +#7 ISVOID +#7 '}' +#7 ')' +#10 INT_CONST 0007 +#10 INT_CONST 123 +#10 '+' +#10 INT_CONST 1 +#10 '-' +#10 INT_CONST 1 +#10 '+' +#10 INT_CONST 90 +#10 '-' +#10 INT_CONST 09 +#10 '+' +#10 INT_CONST 11113 +#10 '-' +#10 INT_CONST 4 +#10 OBJECTID r +#10 '*' +#10 OBJECTID a +#10 '*' +#10 OBJECTID self +#10 '*' +#10 OBJECTID c +#10 '+' +#10 '+' +#11 CLASS +#11 CLASS +#11 IF +#11 THEN +#11 ELSE +#11 FI +#11 OBJECTID testing +#11 TYPEID Testing +#11 '~' +#11 INT_CONST 007 +#11 OBJECTID agent_bond +#11 OBJECTID james_007bones___ *) \ No newline at end of file diff --git a/tests/lexer/iis3_error.txt b/tests/lexer/iis3_error.txt index b001b6a71..3abc2b556 100644 --- a/tests/lexer/iis3_error.txt +++ b/tests/lexer/iis3_error.txt @@ -1 +1 @@ -(3, 40) - LexicographicError: ERROR "^" +(3, 40) - LexicographicError: ERROR "^" diff --git a/tests/lexer/iis4.cl b/tests/lexer/iis4.cl index 9e7a9cb62..5357ab734 100644 --- a/tests/lexer/iis4.cl +++ b/tests/lexer/iis4.cl @@ -1,120 +1,120 @@ -(* Integers, Identifiers, and Special Notation *) - -new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) -0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ - -factorial(5) = 120, 2 + 2 = 5 or E = mc2; p + 1 % p = 1: @.@ for x in range(len(b))~ - - -loop pool while tRuE or noT faLsE let in case of ESAC -class Class if then else fi testing Testing ~007agent_bond james_007bones___ - -(* -#3 NEW -#3 '/' -#3 ASSIGN -#3 '<' -#3 LE -#3 DARROW -#3 '{' -#3 '(' -#3 TYPEID Int -#3 ':' -#3 TYPEID Objet -#3 ',' -#3 TYPEID Bool -#3 ';' -#3 TYPEID String -#3 '.' -#3 OBJECTID string -#3 TYPEID SELF_TYPE -#3 ISVOID -#3 '}' -#3 ')' -#4 INT_CONST 0007 -#4 INT_CONST 123 -#4 '+' -#4 INT_CONST 1 -#4 '-' -#4 INT_CONST 1 -#4 '+' -#4 INT_CONST 90 -#4 '-' -#4 INT_CONST 09 -#4 '+' -#4 INT_CONST 11113 -#4 '-' -#4 INT_CONST 4 -#4 OBJECTID r -#4 '*' -#4 OBJECTID a -#4 '*' -#4 OBJECTID self -#4 '*' -#4 OBJECTID c -#4 '+' -#4 '+' -#6 OBJECTID factorial -#6 '(' -#6 INT_CONST 5 -#6 ')' -#6 '=' -#6 INT_CONST 120 -#6 ',' -#6 INT_CONST 2 -#6 '+' -#6 INT_CONST 2 -#6 '=' -#6 INT_CONST 5 -#6 OBJECTID or -#6 TYPEID E -#6 '=' -#6 OBJECTID mc2 -#6 ';' -#6 OBJECTID p -#6 '+' -#6 INT_CONST 1 -#6 ERROR "%" -#6 OBJECTID p -#6 '=' -#6 INT_CONST 1 -#6 ':' -#6 '@' -#6 '.' -#6 '@' -#6 OBJECTID for -#6 OBJECTID x -#6 IN -#6 OBJECTID range -#6 '(' -#6 OBJECTID len -#6 '(' -#6 OBJECTID b -#6 ')' -#6 ')' -#6 '~' -#9 LOOP -#9 POOL -#9 WHILE -#9 BOOL_CONST true -#9 OBJECTID or -#9 NOT -#9 BOOL_CONST false -#9 LET -#9 IN -#9 CASE -#9 OF -#9 ESAC -#10 CLASS -#10 CLASS -#10 IF -#10 THEN -#10 ELSE -#10 FI -#10 OBJECTID testing -#10 TYPEID Testing -#10 '~' -#10 INT_CONST 007 -#10 OBJECTID agent_bond -#10 OBJECTID james_007bones___ +(* Integers, Identifiers, and Special Notation *) + +new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) +0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ + +factorial(5) = 120, 2 + 2 = 5 or E = mc2; p + 1 % p = 1: @.@ for x in range(len(b))~ + + +loop pool while tRuE or noT faLsE let in case of ESAC +class Class if then else fi testing Testing ~007agent_bond james_007bones___ + +(* +#3 NEW +#3 '/' +#3 ASSIGN +#3 '<' +#3 LE +#3 DARROW +#3 '{' +#3 '(' +#3 TYPEID Int +#3 ':' +#3 TYPEID Objet +#3 ',' +#3 TYPEID Bool +#3 ';' +#3 TYPEID String +#3 '.' +#3 OBJECTID string +#3 TYPEID SELF_TYPE +#3 ISVOID +#3 '}' +#3 ')' +#4 INT_CONST 0007 +#4 INT_CONST 123 +#4 '+' +#4 INT_CONST 1 +#4 '-' +#4 INT_CONST 1 +#4 '+' +#4 INT_CONST 90 +#4 '-' +#4 INT_CONST 09 +#4 '+' +#4 INT_CONST 11113 +#4 '-' +#4 INT_CONST 4 +#4 OBJECTID r +#4 '*' +#4 OBJECTID a +#4 '*' +#4 OBJECTID self +#4 '*' +#4 OBJECTID c +#4 '+' +#4 '+' +#6 OBJECTID factorial +#6 '(' +#6 INT_CONST 5 +#6 ')' +#6 '=' +#6 INT_CONST 120 +#6 ',' +#6 INT_CONST 2 +#6 '+' +#6 INT_CONST 2 +#6 '=' +#6 INT_CONST 5 +#6 OBJECTID or +#6 TYPEID E +#6 '=' +#6 OBJECTID mc2 +#6 ';' +#6 OBJECTID p +#6 '+' +#6 INT_CONST 1 +#6 ERROR "%" +#6 OBJECTID p +#6 '=' +#6 INT_CONST 1 +#6 ':' +#6 '@' +#6 '.' +#6 '@' +#6 OBJECTID for +#6 OBJECTID x +#6 IN +#6 OBJECTID range +#6 '(' +#6 OBJECTID len +#6 '(' +#6 OBJECTID b +#6 ')' +#6 ')' +#6 '~' +#9 LOOP +#9 POOL +#9 WHILE +#9 BOOL_CONST true +#9 OBJECTID or +#9 NOT +#9 BOOL_CONST false +#9 LET +#9 IN +#9 CASE +#9 OF +#9 ESAC +#10 CLASS +#10 CLASS +#10 IF +#10 THEN +#10 ELSE +#10 FI +#10 OBJECTID testing +#10 TYPEID Testing +#10 '~' +#10 INT_CONST 007 +#10 OBJECTID agent_bond +#10 OBJECTID james_007bones___ *) \ No newline at end of file diff --git a/tests/lexer/iis4_error.txt b/tests/lexer/iis4_error.txt index f24076a8c..aab8f39c1 100644 --- a/tests/lexer/iis4_error.txt +++ b/tests/lexer/iis4_error.txt @@ -1 +1 @@ -(6, 49) - LexicographicError: ERROR "!" +(6, 49) - LexicographicError: ERROR "!" diff --git a/tests/lexer/iis5.cl b/tests/lexer/iis5.cl index d146c0547..f602488b9 100644 --- a/tests/lexer/iis5.cl +++ b/tests/lexer/iis5.cl @@ -1,121 +1,121 @@ -(* Integers, Identifiers, and Special Notation *) - - -loop pool while tRuE or noT faLsE let in case of ESAC -new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) -class Class if then else fi testing Testing ~007agent_bond james_007bones___ - -factorial(5) = 120, 2 + 2 = 5 or E = mc2; p + 1 resto p = 1: [@.@ for x in range(len(b))] - -0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ - -(* -#4 LOOP -#4 POOL -#4 WHILE -#4 BOOL_CONST true -#4 OBJECTID or -#4 NOT -#4 BOOL_CONST false -#4 LET -#4 IN -#4 CASE -#4 OF -#4 ESAC -#5 NEW -#5 '/' -#5 ASSIGN -#5 '<' -#5 LE -#5 DARROW -#5 '{' -#5 '(' -#5 TYPEID Int -#5 ':' -#5 TYPEID Objet -#5 ',' -#5 TYPEID Bool -#5 ';' -#5 TYPEID String -#5 '.' -#5 OBJECTID string -#5 TYPEID SELF_TYPE -#5 ISVOID -#5 '}' -#5 ')' -#6 CLASS -#6 CLASS -#6 IF -#6 THEN -#6 ELSE -#6 FI -#6 OBJECTID testing -#6 TYPEID Testing -#6 '~' -#6 INT_CONST 007 -#6 OBJECTID agent_bond -#6 OBJECTID james_007bones___ -#8 OBJECTID factorial -#8 '(' -#8 INT_CONST 5 -#8 ')' -#8 '=' -#8 INT_CONST 120 -#8 ',' -#8 INT_CONST 2 -#8 '+' -#8 INT_CONST 2 -#8 '=' -#8 INT_CONST 5 -#8 OBJECTID or -#8 TYPEID E -#8 '=' -#8 OBJECTID mc2 -#8 ';' -#8 OBJECTID p -#8 '+' -#8 INT_CONST 1 -#8 OBJECTID resto -#8 OBJECTID p -#8 '=' -#8 INT_CONST 1 -#8 ':' -#8 ERROR "[" -#8 '@' -#8 '.' -#8 '@' -#8 OBJECTID for -#8 OBJECTID x -#8 IN -#8 OBJECTID range -#8 '(' -#8 OBJECTID len -#8 '(' -#8 OBJECTID b -#8 ')' -#8 ')' -#8 ERROR "]" -#10 INT_CONST 0007 -#10 INT_CONST 123 -#10 '+' -#10 INT_CONST 1 -#10 '-' -#10 INT_CONST 1 -#10 '+' -#10 INT_CONST 90 -#10 '-' -#10 INT_CONST 09 -#10 '+' -#10 INT_CONST 11113 -#10 '-' -#10 INT_CONST 4 -#10 OBJECTID r -#10 '*' -#10 OBJECTID a -#10 '*' -#10 OBJECTID self -#10 '*' -#10 OBJECTID c -#10 '+' -#10 '+' -*) +(* Integers, Identifiers, and Special Notation *) + + +loop pool while tRuE or noT faLsE let in case of ESAC +new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) +class Class if then else fi testing Testing ~007agent_bond james_007bones___ + +factorial(5) = 120, 2 + 2 = 5 or E = mc2; p + 1 resto p = 1: [@.@ for x in range(len(b))] + +0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ + +(* +#4 LOOP +#4 POOL +#4 WHILE +#4 BOOL_CONST true +#4 OBJECTID or +#4 NOT +#4 BOOL_CONST false +#4 LET +#4 IN +#4 CASE +#4 OF +#4 ESAC +#5 NEW +#5 '/' +#5 ASSIGN +#5 '<' +#5 LE +#5 DARROW +#5 '{' +#5 '(' +#5 TYPEID Int +#5 ':' +#5 TYPEID Objet +#5 ',' +#5 TYPEID Bool +#5 ';' +#5 TYPEID String +#5 '.' +#5 OBJECTID string +#5 TYPEID SELF_TYPE +#5 ISVOID +#5 '}' +#5 ')' +#6 CLASS +#6 CLASS +#6 IF +#6 THEN +#6 ELSE +#6 FI +#6 OBJECTID testing +#6 TYPEID Testing +#6 '~' +#6 INT_CONST 007 +#6 OBJECTID agent_bond +#6 OBJECTID james_007bones___ +#8 OBJECTID factorial +#8 '(' +#8 INT_CONST 5 +#8 ')' +#8 '=' +#8 INT_CONST 120 +#8 ',' +#8 INT_CONST 2 +#8 '+' +#8 INT_CONST 2 +#8 '=' +#8 INT_CONST 5 +#8 OBJECTID or +#8 TYPEID E +#8 '=' +#8 OBJECTID mc2 +#8 ';' +#8 OBJECTID p +#8 '+' +#8 INT_CONST 1 +#8 OBJECTID resto +#8 OBJECTID p +#8 '=' +#8 INT_CONST 1 +#8 ':' +#8 ERROR "[" +#8 '@' +#8 '.' +#8 '@' +#8 OBJECTID for +#8 OBJECTID x +#8 IN +#8 OBJECTID range +#8 '(' +#8 OBJECTID len +#8 '(' +#8 OBJECTID b +#8 ')' +#8 ')' +#8 ERROR "]" +#10 INT_CONST 0007 +#10 INT_CONST 123 +#10 '+' +#10 INT_CONST 1 +#10 '-' +#10 INT_CONST 1 +#10 '+' +#10 INT_CONST 90 +#10 '-' +#10 INT_CONST 09 +#10 '+' +#10 INT_CONST 11113 +#10 '-' +#10 INT_CONST 4 +#10 OBJECTID r +#10 '*' +#10 OBJECTID a +#10 '*' +#10 OBJECTID self +#10 '*' +#10 OBJECTID c +#10 '+' +#10 '+' +*) diff --git a/tests/lexer/iis5_error.txt b/tests/lexer/iis5_error.txt index b3dbadcb6..9d6e1a738 100644 --- a/tests/lexer/iis5_error.txt +++ b/tests/lexer/iis5_error.txt @@ -1,2 +1,2 @@ -(8, 62) - LexicographicError: ERROR "[" -(8, 89) - LexicographicError: ERROR "]" +(8, 62) - LexicographicError: ERROR "[" +(8, 89) - LexicographicError: ERROR "]" diff --git a/tests/lexer/iis6.cl b/tests/lexer/iis6.cl index 1042f132b..ba93b19d9 100644 --- a/tests/lexer/iis6.cl +++ b/tests/lexer/iis6.cl @@ -1,125 +1,125 @@ -(* Integers, Identifiers, and Special Notation *) - -factorial(5) = 120, 2 + 2 = 5 or E = mc2; p + 1 resto p = 1: {@.@ for x in range(len(b))} - -new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) - - -class Class if then else fi testing Testing ~007agent_bond _james_007bones___ - - - -0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ -loop pool while tRuE or noT faLsE let in case of ESAC - -(* -#3 OBJECTID factorial -#3 '(' -#3 INT_CONST 5 -#3 ')' -#3 '=' -#3 INT_CONST 120 -#3 ',' -#3 INT_CONST 2 -#3 '+' -#3 INT_CONST 2 -#3 '=' -#3 INT_CONST 5 -#3 OBJECTID or -#3 TYPEID E -#3 '=' -#3 OBJECTID mc2 -#3 ';' -#3 OBJECTID p -#3 '+' -#3 INT_CONST 1 -#3 OBJECTID resto -#3 OBJECTID p -#3 '=' -#3 INT_CONST 1 -#3 ':' -#3 '{' -#3 '@' -#3 '.' -#3 '@' -#3 OBJECTID for -#3 OBJECTID x -#3 IN -#3 OBJECTID range -#3 '(' -#3 OBJECTID len -#3 '(' -#3 OBJECTID b -#3 ')' -#3 ')' -#3 '}' -#5 NEW -#5 '/' -#5 ASSIGN -#5 '<' -#5 LE -#5 DARROW -#5 '{' -#5 '(' -#5 TYPEID Int -#5 ':' -#5 TYPEID Objet -#5 ',' -#5 TYPEID Bool -#5 ';' -#5 TYPEID String -#5 '.' -#5 OBJECTID string -#5 TYPEID SELF_TYPE -#5 ISVOID -#5 '}' -#5 ')' -#8 CLASS -#8 CLASS -#8 IF -#8 THEN -#8 ELSE -#8 FI -#8 OBJECTID testing -#8 TYPEID Testing -#8 '~' -#8 INT_CONST 007 -#8 OBJECTID agent_bond -#8 ERROR "_" -#8 OBJECTID james_007bones___ -#12 INT_CONST 0007 -#12 INT_CONST 123 -#12 '+' -#12 INT_CONST 1 -#12 '-' -#12 INT_CONST 1 -#12 '+' -#12 INT_CONST 90 -#12 '-' -#12 INT_CONST 09 -#12 '+' -#12 INT_CONST 11113 -#12 '-' -#12 INT_CONST 4 -#12 OBJECTID r -#12 '*' -#12 OBJECTID a -#12 '*' -#12 OBJECTID self -#12 '*' -#12 OBJECTID c -#12 '+' -#12 '+' -#13 LOOP -#13 POOL -#13 WHILE -#13 BOOL_CONST true -#13 OBJECTID or -#13 NOT -#13 BOOL_CONST false -#13 LET -#13 IN -#13 CASE -#13 OF -#13 ESAC +(* Integers, Identifiers, and Special Notation *) + +factorial(5) = 120, 2 + 2 = 5 or E = mc2; p + 1 resto p = 1: {@.@ for x in range(len(b))} + +new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) + + +class Class if then else fi testing Testing ~007agent_bond _james_007bones___ + + + +0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ +loop pool while tRuE or noT faLsE let in case of ESAC + +(* +#3 OBJECTID factorial +#3 '(' +#3 INT_CONST 5 +#3 ')' +#3 '=' +#3 INT_CONST 120 +#3 ',' +#3 INT_CONST 2 +#3 '+' +#3 INT_CONST 2 +#3 '=' +#3 INT_CONST 5 +#3 OBJECTID or +#3 TYPEID E +#3 '=' +#3 OBJECTID mc2 +#3 ';' +#3 OBJECTID p +#3 '+' +#3 INT_CONST 1 +#3 OBJECTID resto +#3 OBJECTID p +#3 '=' +#3 INT_CONST 1 +#3 ':' +#3 '{' +#3 '@' +#3 '.' +#3 '@' +#3 OBJECTID for +#3 OBJECTID x +#3 IN +#3 OBJECTID range +#3 '(' +#3 OBJECTID len +#3 '(' +#3 OBJECTID b +#3 ')' +#3 ')' +#3 '}' +#5 NEW +#5 '/' +#5 ASSIGN +#5 '<' +#5 LE +#5 DARROW +#5 '{' +#5 '(' +#5 TYPEID Int +#5 ':' +#5 TYPEID Objet +#5 ',' +#5 TYPEID Bool +#5 ';' +#5 TYPEID String +#5 '.' +#5 OBJECTID string +#5 TYPEID SELF_TYPE +#5 ISVOID +#5 '}' +#5 ')' +#8 CLASS +#8 CLASS +#8 IF +#8 THEN +#8 ELSE +#8 FI +#8 OBJECTID testing +#8 TYPEID Testing +#8 '~' +#8 INT_CONST 007 +#8 OBJECTID agent_bond +#8 ERROR "_" +#8 OBJECTID james_007bones___ +#12 INT_CONST 0007 +#12 INT_CONST 123 +#12 '+' +#12 INT_CONST 1 +#12 '-' +#12 INT_CONST 1 +#12 '+' +#12 INT_CONST 90 +#12 '-' +#12 INT_CONST 09 +#12 '+' +#12 INT_CONST 11113 +#12 '-' +#12 INT_CONST 4 +#12 OBJECTID r +#12 '*' +#12 OBJECTID a +#12 '*' +#12 OBJECTID self +#12 '*' +#12 OBJECTID c +#12 '+' +#12 '+' +#13 LOOP +#13 POOL +#13 WHILE +#13 BOOL_CONST true +#13 OBJECTID or +#13 NOT +#13 BOOL_CONST false +#13 LET +#13 IN +#13 CASE +#13 OF +#13 ESAC *) \ No newline at end of file diff --git a/tests/lexer/iis6_error.txt b/tests/lexer/iis6_error.txt index d7fad9c79..79a9d5aee 100644 --- a/tests/lexer/iis6_error.txt +++ b/tests/lexer/iis6_error.txt @@ -1 +1 @@ -(8, 60) - LexicographicError: ERROR "_" +(8, 60) - LexicographicError: ERROR "_" diff --git a/tests/lexer/mixed1.cl b/tests/lexer/mixed1.cl index 803d58ef5..d3e520a10 100644 --- a/tests/lexer/mixed1.cl +++ b/tests/lexer/mixed1.cl @@ -1,14 +1,14 @@ -"lkjdsafkljdsalfj\u0000dsafdsaf\u0000djafslkjdsalf\nsdajf\" lkjfdsasdkjfl"123 -adsfasklj# -LKldsajf iNhERITS -"lkdsajf" - -(* -#1 STR_CONST "lkjdsafkljdsalfju0000dsafdsafu0000djafslkjdsalf\nsdajf\" lkjfdsasdkjfl" -#1 INT_CONST 123 -#2 OBJECTID adsfasklj -#2 ERROR "#" -#3 TYPEID LKldsajf -#3 INHERITS -#4 STR_CONST "lkdsajf" +"lkjdsafkljdsalfj\u0000dsafdsaf\u0000djafslkjdsalf\nsdajf\" lkjfdsasdkjfl"123 +adsfasklj# +LKldsajf iNhERITS +"lkdsajf" + +(* +#1 STR_CONST "lkjdsafkljdsalfju0000dsafdsafu0000djafslkjdsalf\nsdajf\" lkjfdsasdkjfl" +#1 INT_CONST 123 +#2 OBJECTID adsfasklj +#2 ERROR "#" +#3 TYPEID LKldsajf +#3 INHERITS +#4 STR_CONST "lkdsajf" *) \ No newline at end of file diff --git a/tests/lexer/mixed1_error.txt b/tests/lexer/mixed1_error.txt index 99af5fbdc..a142c2edd 100644 --- a/tests/lexer/mixed1_error.txt +++ b/tests/lexer/mixed1_error.txt @@ -1 +1 @@ -(2, 10) - LexicographicError: ERROR "#" +(2, 10) - LexicographicError: ERROR "#" diff --git a/tests/lexer/mixed2.cl b/tests/lexer/mixed2.cl index 12039e123..759bf9523 100644 --- a/tests/lexer/mixed2.cl +++ b/tests/lexer/mixed2.cl @@ -1,20 +1,20 @@ -"kjas\"lnnsdj\nfljrdsaf" -@.$.@ -@*%*@ -"alkjfldajf""dasfadsf - -(* -#1 STR_CONST "kjas\"lnnsdj\nfljrdsaf" -#2 '@' -#2 '.' -#2 ERROR "$" -#2 '.' -#2 '@' -#3 '@' -#3 '*' -#3 ERROR "%" -#3 '*' -#3 '@' -#4 STR_CONST "alkjfldajf" -#4 ERROR "Unterminated string constant" +"kjas\"lnnsdj\nfljrdsaf" +@.$.@ +@*%*@ +"alkjfldajf""dasfadsf + +(* +#1 STR_CONST "kjas\"lnnsdj\nfljrdsaf" +#2 '@' +#2 '.' +#2 ERROR "$" +#2 '.' +#2 '@' +#3 '@' +#3 '*' +#3 ERROR "%" +#3 '*' +#3 '@' +#4 STR_CONST "alkjfldajf" +#4 ERROR "Unterminated string constant" *) \ No newline at end of file diff --git a/tests/lexer/mixed2_error.txt b/tests/lexer/mixed2_error.txt index 097dc2a07..37cb73ac2 100644 --- a/tests/lexer/mixed2_error.txt +++ b/tests/lexer/mixed2_error.txt @@ -1,3 +1,3 @@ -(2, 3) - LexicographicError: ERROR "$" -(3, 3) - LexicographicError: ERROR "%" -(4, 22) - LexicographicError: Unterminated string constant +(2, 3) - LexicographicError: ERROR "$" +(3, 3) - LexicographicError: ERROR "%" +(4, 22) - LexicographicError: Unterminated string constant diff --git a/tests/lexer/string1.cl b/tests/lexer/string1.cl index 6c3c00833..f0a5bd873 100644 --- a/tests/lexer/string1.cl +++ b/tests/lexer/string1.cl @@ -1,6 +1,6 @@ -(* A non-escaped newline character may not appear in a string *) - -"This \ -is OK" -"This is not +(* A non-escaped newline character may not appear in a string *) + +"This \ +is OK" +"This is not OK" \ No newline at end of file diff --git a/tests/lexer/string1_error.txt b/tests/lexer/string1_error.txt index 078c12bbb..1dd4d70d9 100644 --- a/tests/lexer/string1_error.txt +++ b/tests/lexer/string1_error.txt @@ -1,2 +1,2 @@ -(5, 13) - LexicographicError: Unterminated string constant +(5, 13) - LexicographicError: Unterminated string constant (6, 4) - LexicographicError: EOF in string constant \ No newline at end of file diff --git a/tests/lexer/string2.cl b/tests/lexer/string2.cl index 3704b6ae7..cb3024180 100644 --- a/tests/lexer/string2.cl +++ b/tests/lexer/string2.cl @@ -1,19 +1,19 @@ -(* A string may not contain EOF *) - -" May the Triforce \ - 0 \ - 0v0 \ - 0vvv0 \ - 0vvvvv0 \ - 0vvvvvvv0 \ - 0vvvvvvvvv0 \ - 0vvvvvvvvvvv0 \ - 000000000000000 \ - 0v0 0v0 \ - 0vvv0 0vvv0 \ - 0vvvvv0 0vvvvv0 \ - 0vvvvvvv0 0vvvvvvv0 \ - 0vvvvvvvvv0 0vvvvvvvvv0 \ - 0vvvvvvvvvvv0 0vvvvvvvvvvv0 \ - 00000000000000000000000000000 \ +(* A string may not contain EOF *) + +" May the Triforce \ + 0 \ + 0v0 \ + 0vvv0 \ + 0vvvvv0 \ + 0vvvvvvv0 \ + 0vvvvvvvvv0 \ + 0vvvvvvvvvvv0 \ + 000000000000000 \ + 0v0 0v0 \ + 0vvv0 0vvv0 \ + 0vvvvv0 0vvvvv0 \ + 0vvvvvvv0 0vvvvvvv0 \ + 0vvvvvvvvv0 0vvvvvvvvv0 \ + 0vvvvvvvvvvv0 0vvvvvvvvvvv0 \ + 00000000000000000000000000000 \ be with you! \ No newline at end of file diff --git a/tests/lexer/string4.cl b/tests/lexer/string4.cl index f4d39c027..7ca4eb42b 100644 --- a/tests/lexer/string4.cl +++ b/tests/lexer/string4.cl @@ -1,38 +1,38 @@ -class Main { - str <- "The big brown fox - jumped over the fence"; - main() : Object { - { - out_string("Yay! This is the newest shites ); - } - }; -}; - -(* -#1 CLASS -#1 TYPEID Main -#1 '{' -#2 OBJECTID str -#2 ASSIGN -#3 ERROR "Unterminated string constant" -#3 OBJECTID jumped -#3 OBJECTID over -#3 OBJECTID the -#3 OBJECTID fence -#4 ERROR "Unterminated string constant" -#4 OBJECTID main -#4 '(' -#4 ')' -#4 ':' -#4 TYPEID Object -#4 '{' -#5 '{' -#6 OBJECTID out_string -#6 '(' -#7 ERROR "Unterminated string constant" -#7 '}' -#8 '}' -#8 ';' -#9 '}' -#9 ';' +class Main { + str <- "The big brown fox + jumped over the fence"; + main() : Object { + { + out_string("Yay! This is the newest shites ); + } + }; +}; + +(* +#1 CLASS +#1 TYPEID Main +#1 '{' +#2 OBJECTID str +#2 ASSIGN +#3 ERROR "Unterminated string constant" +#3 OBJECTID jumped +#3 OBJECTID over +#3 OBJECTID the +#3 OBJECTID fence +#4 ERROR "Unterminated string constant" +#4 OBJECTID main +#4 '(' +#4 ')' +#4 ':' +#4 TYPEID Object +#4 '{' +#5 '{' +#6 OBJECTID out_string +#6 '(' +#7 ERROR "Unterminated string constant" +#7 '}' +#8 '}' +#8 ';' +#9 '}' +#9 ';' *) \ No newline at end of file diff --git a/tests/lexer/string4_error.txt b/tests/lexer/string4_error.txt index 5ab0ea847..bf420217c 100644 --- a/tests/lexer/string4_error.txt +++ b/tests/lexer/string4_error.txt @@ -1,3 +1,3 @@ -(2, 30) - LexicographicError: Unterminated string constant -(3, 36) - LexicographicError: Unterminated string constant +(2, 30) - LexicographicError: Unterminated string constant +(3, 36) - LexicographicError: Unterminated string constant (6, 58) - LexicographicError: Unterminated string constant \ No newline at end of file diff --git a/tests/lexer_test.py b/tests/lexer_test.py index 2a27223d3..a21fd880a 100644 --- a/tests/lexer_test.py +++ b/tests/lexer_test.py @@ -1,13 +1,13 @@ -import pytest -import os -from utils import compare_errors - -tests_dir = __file__.rpartition('/')[0] + '/lexer/' -tests = [(file) for file in os.listdir(tests_dir) if file.endswith('.cl')] - -@pytest.mark.lexer -@pytest.mark.error -@pytest.mark.run(order=1) -@pytest.mark.parametrize("cool_file", tests) -def test_lexer_errors(compiler_path, cool_file): +import pytest +import os +from utils import compare_errors + +tests_dir = __file__.rpartition('/')[0] + '/lexer/' +tests = [(file) for file in os.listdir(tests_dir) if file.endswith('.cl')] + +@pytest.mark.lexer +@pytest.mark.error +@pytest.mark.run(order=1) +@pytest.mark.parametrize("cool_file", tests) +def test_lexer_errors(compiler_path, cool_file): compare_errors(compiler_path, tests_dir + cool_file, tests_dir + cool_file[:-3] + '_error.txt') \ No newline at end of file diff --git a/tests/parser/assignment1.cl b/tests/parser/assignment1.cl index 75b4c5bbd..e89ade368 100644 --- a/tests/parser/assignment1.cl +++ b/tests/parser/assignment1.cl @@ -1,37 +1,37 @@ -(* An assignment has the form <- *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(): String { - Test1 <- "Hello World" -- Identifiers begin with a lower case letter - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* An assignment has the form <- *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(): String { + Test1 <- "Hello World" -- Identifiers begin with a lower case letter + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/assignment2.cl b/tests/parser/assignment2.cl index 4efb96487..7b8ed54ba 100644 --- a/tests/parser/assignment2.cl +++ b/tests/parser/assignment2.cl @@ -1,37 +1,37 @@ -(* An assignment has the form <- *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 - 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(): Int { - test1 <-- ~(1 + 2 + 3 + 4 + 5) -- The left side must be an expression - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* An assignment has the form <- *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 - 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(): Int { + test1 <-- ~(1 + 2 + 3 + 4 + 5) -- The left side must be an expression + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/assignment3.cl b/tests/parser/assignment3.cl index ff633f331..f54305e27 100644 --- a/tests/parser/assignment3.cl +++ b/tests/parser/assignment3.cl @@ -1,37 +1,37 @@ -(* An assignment has the form <- *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(): Bool { - test1 <- true++ -- The left side must be an expression - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* An assignment has the form <- *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(): Bool { + test1 <- true++ -- The left side must be an expression + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/attribute1.cl b/tests/parser/attribute1.cl index 063a02c02..59740336d 100644 --- a/tests/parser/attribute1.cl +++ b/tests/parser/attribute1.cl @@ -1,34 +1,34 @@ -(* An attribute of class A specifies a variable that is part of the state of objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - -- Attributes names must begin with lowercase letters - Test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* An attribute of class A specifies a variable that is part of the state of objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + -- Attributes names must begin with lowercase letters + Test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/attribute2.cl b/tests/parser/attribute2.cl index c05211483..337696859 100644 --- a/tests/parser/attribute2.cl +++ b/tests/parser/attribute2.cl @@ -1,34 +1,34 @@ -(* An attribute of class A specifies a variable that is part of the state of objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - -- Type names must begin with uppercase letters - test3: string <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* An attribute of class A specifies a variable that is part of the state of objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + -- Type names must begin with uppercase letters + test3: string <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/attribute3.cl b/tests/parser/attribute3.cl index d858ae47c..b29b4b26d 100644 --- a/tests/parser/attribute3.cl +++ b/tests/parser/attribute3.cl @@ -1,34 +1,34 @@ -(* An attribute of class A specifies a variable that is part of the state of objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - -- Expected '<-' not '<=' - test3: String <= "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* An attribute of class A specifies a variable that is part of the state of objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + -- Expected '<-' not '<=' + test3: String <= "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/block1.cl b/tests/parser/block1.cl index 3613d9268..f15872812 100644 --- a/tests/parser/block1.cl +++ b/tests/parser/block1.cl @@ -1,87 +1,87 @@ -(* A block has the form { ; ... ; } *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - pow: Int <- 1; - count: Int <- 0; - - testing6(a: Int): IO { - { - count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2 -- Missing ";" - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A block has the form { ; ... ; } *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + pow: Int <- 1; + count: Int <- 0; + + testing6(a: Int): IO { + { + count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2 -- Missing ";" + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/block2.cl b/tests/parser/block2.cl index f485dd0b1..1f45fca4c 100644 --- a/tests/parser/block2.cl +++ b/tests/parser/block2.cl @@ -1,87 +1,87 @@ -(* A block has the form { ; ... ; } *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - pow: Int <- 1; - count: Int <- 0; - - testing6(a: Int): IO { - -- Missing "{" - count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A block has the form { ; ... ; } *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + pow: Int <- 1; + count: Int <- 0; + + testing6(a: Int): IO { + -- Missing "{" + count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/block3.cl b/tests/parser/block3.cl index ae1598c3b..9b63b0015 100644 --- a/tests/parser/block3.cl +++ b/tests/parser/block3.cl @@ -1,87 +1,87 @@ -(* A block has the form { ; ... ; } *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - pow: Int <- 1; - count: Int <- 0; - - testing6(a: Int): IO { - { - count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - -- Missing "}" - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A block has the form { ; ... ; } *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + pow: Int <- 1; + count: Int <- 0; + + testing6(a: Int): IO { + { + count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + -- Missing "}" + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/block4.cl b/tests/parser/block4.cl index 8fd883d02..c144dae48 100644 --- a/tests/parser/block4.cl +++ b/tests/parser/block4.cl @@ -1,88 +1,88 @@ -(* A block has the form { ; ... ; } *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - pow: Int <- 1; - count: Int <- 0; - - testing6(a: Int): IO { - { - count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - true++; -- Only expressions - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A block has the form { ; ... ; } *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + pow: Int <- 1; + count: Int <- 0; + + testing6(a: Int): IO { + { + count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + true++; -- Only expressions + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/case1.cl b/tests/parser/case1.cl index c2f508809..35fe5af53 100644 --- a/tests/parser/case1.cl +++ b/tests/parser/case1.cl @@ -1,91 +1,91 @@ -(* Case expressions provide runtime type tests on objects *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case 2 + 2 of - -- Every case expression must have at least one branch - esac - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Case expressions provide runtime type tests on objects *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case 2 + 2 of + -- Every case expression must have at least one branch + esac + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/case2.cl b/tests/parser/case2.cl index f9162e49f..12cbb87b5 100644 --- a/tests/parser/case2.cl +++ b/tests/parser/case2.cl @@ -1,93 +1,93 @@ -(* Case expressions provide runtime type tests on objects *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case "2 + 2" of - x: Int => new IO.out_string("Es un entero!") -- Missing ";" - y: String => new IO.out_string("Es una cadena!"); - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Case expressions provide runtime type tests on objects *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case "2 + 2" of + x: Int => new IO.out_string("Es un entero!") -- Missing ";" + y: String => new IO.out_string("Es una cadena!"); + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/case3.cl b/tests/parser/case3.cl index a7eedc18b..8fd851836 100644 --- a/tests/parser/case3.cl +++ b/tests/parser/case3.cl @@ -1,93 +1,93 @@ -(* Case expressions provide runtime type tests on objects *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case 2 + false of - x: Int => new IO.out_string("Es un entero!"); - y: string => new IO.out_string("Es una cadena!"); -- Type identifiers starts with a uppercase letter - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Case expressions provide runtime type tests on objects *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case 2 + false of + x: Int => new IO.out_string("Es un entero!"); + y: string => new IO.out_string("Es una cadena!"); -- Type identifiers starts with a uppercase letter + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/case4.cl b/tests/parser/case4.cl index 25ca3858f..eb8a3d3a2 100644 --- a/tests/parser/case4.cl +++ b/tests/parser/case4.cl @@ -1,93 +1,93 @@ -(* Case expressions provide runtime type tests on objects *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case true of - x: Int => new IO.out_string("Es un entero!"); - y: String => new IO.out_string("Es una cadena!"); - Mazinger_Z: Bool => new IO.out_string("Es un booleano!"); -- Identifiers starts with a lowercase letter - esac - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Case expressions provide runtime type tests on objects *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case true of + x: Int => new IO.out_string("Es un entero!"); + y: String => new IO.out_string("Es una cadena!"); + Mazinger_Z: Bool => new IO.out_string("Es un booleano!"); -- Identifiers starts with a lowercase letter + esac + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/case5.cl b/tests/parser/case5.cl index b36c663e1..f0483f1f5 100644 --- a/tests/parser/case5.cl +++ b/tests/parser/case5.cl @@ -1,93 +1,93 @@ -(* Case expressions provide runtime type tests on objects *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case test2 of - x: Int <- new IO.out_string("Es un entero!"); -- Must be '=>' not '<-'; - y: String => new IO.out_string("Es una cadena!"); - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Case expressions provide runtime type tests on objects *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case test2 of + x: Int <- new IO.out_string("Es un entero!"); -- Must be '=>' not '<-'; + y: String => new IO.out_string("Es una cadena!"); + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/case6.cl b/tests/parser/case6.cl index 66e7df2ab..c49467a89 100644 --- a/tests/parser/case6.cl +++ b/tests/parser/case6.cl @@ -1,93 +1,93 @@ -(* Case expressions provide runtime type tests on objects *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case 2 + 2 -- Missing "of" - x: Int => new IO.out_string("Es un entero!"); - y: String => new IO.out_string("Es una cadena!"); - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Case expressions provide runtime type tests on objects *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case 2 + 2 -- Missing "of" + x: Int => new IO.out_string("Es un entero!"); + y: String => new IO.out_string("Es una cadena!"); + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/class1.cl b/tests/parser/class1.cl index f4815e3f4..1c0641a94 100644 --- a/tests/parser/class1.cl +++ b/tests/parser/class1.cl @@ -1,20 +1,20 @@ -(* A class is a list of features *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - testing(): Int { - 2 + 2 - }; -}; - --- Class names must begin with uppercase letters -class alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; -}; +(* A class is a list of features *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + testing(): Int { + 2 + 2 + }; +}; + +-- Class names must begin with uppercase letters +class alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; +}; diff --git a/tests/parser/class2.cl b/tests/parser/class2.cl index f363b032a..baf290822 100644 --- a/tests/parser/class2.cl +++ b/tests/parser/class2.cl @@ -1,20 +1,20 @@ -(* A class is a list of features *) - -CLaSS Main { - main(): Object { - (new Alpha).print() - }; -}; - -CLaSS Test { - testing(): Int { - 2 + 2 - }; -}; - --- Type names must begin with uppercase letters -CLaSS Alpha iNHeRiTS iO { - print() : Object { - out_string("reached!!\n") - }; -}; +(* A class is a list of features *) + +CLaSS Main { + main(): Object { + (new Alpha).print() + }; +}; + +CLaSS Test { + testing(): Int { + 2 + 2 + }; +}; + +-- Type names must begin with uppercase letters +CLaSS Alpha iNHeRiTS iO { + print() : Object { + out_string("reached!!\n") + }; +}; diff --git a/tests/parser/class3.cl b/tests/parser/class3.cl index 0c801372a..5c89c5eb8 100644 --- a/tests/parser/class3.cl +++ b/tests/parser/class3.cl @@ -1,34 +1,34 @@ -(* A class is a list of features *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - -- Missing semicolon - testing2(a: Alpha, b: Int): Int { - 2 + 2 - } - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; -}; +(* A class is a list of features *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + -- Missing semicolon + testing2(a: Alpha, b: Int): Int { + 2 + 2 + } + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; +}; diff --git a/tests/parser/class4.cl b/tests/parser/class4.cl index 5c286b5e6..cdfbc313c 100644 --- a/tests/parser/class4.cl +++ b/tests/parser/class4.cl @@ -1,36 +1,36 @@ -(* A class is a list of features *) - -CLaSS Main { - main(): Object { - (new Alpha).print() - }; -}; - -CLaSS Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - -- Only features - 2 + 2; - - testing3(): String { - "2 + 2" - }; -}; - -CLaSS Alpha iNHeRiTS IO { - print() : Object { - out_string("reached!!\n") - }; -}; +(* A class is a list of features *) + +CLaSS Main { + main(): Object { + (new Alpha).print() + }; +}; + +CLaSS Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + -- Only features + 2 + 2; + + testing3(): String { + "2 + 2" + }; +}; + +CLaSS Alpha iNHeRiTS IO { + print() : Object { + out_string("reached!!\n") + }; +}; diff --git a/tests/parser/class5.cl b/tests/parser/class5.cl index 3f40c36eb..d6b5c5fda 100644 --- a/tests/parser/class5.cl +++ b/tests/parser/class5.cl @@ -1,34 +1,34 @@ -(* A class is a list of features *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - --- Missing '{' -class Test - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; -}; +(* A class is a list of features *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +-- Missing '{' +class Test + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; +}; diff --git a/tests/parser/class6.cl b/tests/parser/class6.cl index 8501d2593..af9ecbf15 100644 --- a/tests/parser/class6.cl +++ b/tests/parser/class6.cl @@ -1,34 +1,34 @@ -(* A class is a list of features *) - -CLaSS Main { - main(): Object { - (new Alpha).print() - }; -}; - --- Missing '}' -CLaSS Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; -; - -CLaSS Alpha iNHeRiTS IO { - print() : Object { - out_string("reached!!\n") - }; -}; +(* A class is a list of features *) + +CLaSS Main { + main(): Object { + (new Alpha).print() + }; +}; + +-- Missing '}' +CLaSS Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; +; + +CLaSS Alpha iNHeRiTS IO { + print() : Object { + out_string("reached!!\n") + }; +}; diff --git a/tests/parser/conditional1.cl b/tests/parser/conditional1.cl index 4d546fc44..f03b9c4e6 100644 --- a/tests/parser/conditional1.cl +++ b/tests/parser/conditional1.cl @@ -1,69 +1,69 @@ -(* A conditional has the form if then else fi *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - if a.length() < b.length() -- Mising "then" - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - else - if a.length() = b.length() then - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - else - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fi - fi - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A conditional has the form if then else fi *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + if a.length() < b.length() -- Mising "then" + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + else + if a.length() = b.length() then + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + else + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fi + fi + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/conditional2.cl b/tests/parser/conditional2.cl index 4f10c2957..9ebd7fe84 100644 --- a/tests/parser/conditional2.cl +++ b/tests/parser/conditional2.cl @@ -1,69 +1,69 @@ -(* A conditional has the form if then else fi *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - if a.length() < b.length() then - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - else - if a.length() = b.length() then - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - else - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - -- Missing "fi" - fi - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A conditional has the form if then else fi *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + if a.length() < b.length() then + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + else + if a.length() = b.length() then + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + else + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + -- Missing "fi" + fi + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/conditional3.cl b/tests/parser/conditional3.cl index 67e991ade..ac143ad42 100644 --- a/tests/parser/conditional3.cl +++ b/tests/parser/conditional3.cl @@ -1,69 +1,69 @@ -(* A conditional has the form if then else fi *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - iF a.length() < b.length() tHen - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - elsE - if a.length() = b.length() then - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - eLseif -- elseif isn't a keyword - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A conditional has the form if then else fi *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + iF a.length() < b.length() tHen + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + elsE + if a.length() = b.length() then + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + eLseif -- elseif isn't a keyword + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/conditional4.cl b/tests/parser/conditional4.cl index 0792fdc85..51337f874 100644 --- a/tests/parser/conditional4.cl +++ b/tests/parser/conditional4.cl @@ -1,73 +1,73 @@ -(* A conditional has the form if then else fi *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(): Int { - if true++ then 1 else 0 -- Condition must be an expression - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A conditional has the form if then else fi *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(): Int { + if true++ then 1 else 0 -- Condition must be an expression + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/conditional5.cl b/tests/parser/conditional5.cl index 0c1e1aad0..399515701 100644 --- a/tests/parser/conditional5.cl +++ b/tests/parser/conditional5.cl @@ -1,73 +1,73 @@ -(* A conditional has the form if then else fi *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(): Int { - if true then true++ else 0 -- If branch must be an expression - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A conditional has the form if then else fi *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(): Int { + if true then true++ else 0 -- If branch must be an expression + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/conditional6.cl b/tests/parser/conditional6.cl index 02310404a..8daa35d7f 100644 --- a/tests/parser/conditional6.cl +++ b/tests/parser/conditional6.cl @@ -1,73 +1,73 @@ -(* A conditional has the form if then else fi *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(): Int { - if true then 1 else false++ -- Else branch must be an expression - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A conditional has the form if then else fi *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(): Int { + if true then 1 else false++ -- Else branch must be an expression + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch1.cl b/tests/parser/dispatch1.cl index 2ca394716..2eba9db03 100644 --- a/tests/parser/dispatch1.cl +++ b/tests/parser/dispatch1.cl @@ -1,45 +1,45 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - Test1.testing4(1, 2).testing4(3, 4).testing4(5, 6) -- Objet identifiers begin with a lower case letter - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + Test1.testing4(1, 2).testing4(3, 4).testing4(5, 6) -- Objet identifiers begin with a lower case letter + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch2.cl b/tests/parser/dispatch2.cl index 0b57467a1..139eba918 100644 --- a/tests/parser/dispatch2.cl +++ b/tests/parser/dispatch2.cl @@ -1,45 +1,45 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13,) -- Extra comma - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13,) -- Extra comma + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch3.cl b/tests/parser/dispatch3.cl index 9f1a5afff..0d88f5c23 100644 --- a/tests/parser/dispatch3.cl +++ b/tests/parser/dispatch3.cl @@ -1,45 +1,45 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).Testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) -- Identifiers begin with a lower case letter - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).Testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) -- Identifiers begin with a lower case letter + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch4.cl b/tests/parser/dispatch4.cl index d1efc469d..dc13fd762 100644 --- a/tests/parser/dispatch4.cl +++ b/tests/parser/dispatch4.cl @@ -1,53 +1,53 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - self.testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true++) -- Arguments must be expressions - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + self.testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true++) -- Arguments must be expressions + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch5.cl b/tests/parser/dispatch5.cl index 63a5afa79..b7bae25e1 100644 --- a/tests/parser/dispatch5.cl +++ b/tests/parser/dispatch5.cl @@ -1,53 +1,53 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, ,true + fALSE) -- Extra comma - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, ,true + fALSE) -- Extra comma + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch6.cl b/tests/parser/dispatch6.cl index 0a953e2e6..6887c60cd 100644 --- a/tests/parser/dispatch6.cl +++ b/tests/parser/dispatch6.cl @@ -1,57 +1,57 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@object.copy() -- Type identifiers begin with a upper case letter - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@object.copy() -- Type identifiers begin with a upper case letter + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch7.cl b/tests/parser/dispatch7.cl index 3ecac4d0f..a9ff1b67a 100644 --- a/tests/parser/dispatch7.cl +++ b/tests/parser/dispatch7.cl @@ -1,57 +1,57 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.Copy() -- Identifiers begin with a lower case letter - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.Copy() -- Identifiers begin with a lower case letter + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch8.cl b/tests/parser/dispatch8.cl index eef0455ef..c1bb2abba 100644 --- a/tests/parser/dispatch8.cl +++ b/tests/parser/dispatch8.cl @@ -1,57 +1,57 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy(,) -- Extra comma - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy(,) -- Extra comma + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch9.cl b/tests/parser/dispatch9.cl index 5fdef22d6..8914a18c2 100644 --- a/tests/parser/dispatch9.cl +++ b/tests/parser/dispatch9.cl @@ -1,61 +1,61 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; - - testing5(): Object { - test1:Object.copy() -- Must be '@' not ':' - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; + + testing5(): Object { + test1:Object.copy() -- Must be '@' not ':' + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/let1.cl b/tests/parser/let1.cl index 576ae383c..0e5fc6d17 100644 --- a/tests/parser/let1.cl +++ b/tests/parser/let1.cl @@ -1,85 +1,85 @@ -(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let Count: Int <- 0, pow: Int <- 1 -- Object identifiers starts with a lowercase letter - in { - -- count <- 0; - -- pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let Count: Int <- 0, pow: Int <- 1 -- Object identifiers starts with a lowercase letter + in { + -- count <- 0; + -- pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/let2.cl b/tests/parser/let2.cl index 4cfaef0f8..01d055dac 100644 --- a/tests/parser/let2.cl +++ b/tests/parser/let2.cl @@ -1,85 +1,85 @@ -(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int, pow: int <- 1 -- Type identifiers starts with a uppercase letter - in { - count <- 0; - -- pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int, pow: int <- 1 -- Type identifiers starts with a uppercase letter + in { + count <- 0; + -- pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/let3.cl b/tests/parser/let3.cl index 91e567fd8..b2b2fb005 100644 --- a/tests/parser/let3.cl +++ b/tests/parser/let3.cl @@ -1,85 +1,85 @@ -(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int, pow: Int, -- Extra comma - in { - count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int, pow: Int, -- Extra comma + in { + count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/let4.cl b/tests/parser/let4.cl index a716c332d..c7d0ea8e3 100644 --- a/tests/parser/let4.cl +++ b/tests/parser/let4.cl @@ -1,85 +1,85 @@ -(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- true++, pow: Int <- 1 -- Initialization must be an expression - in { - count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- true++, pow: Int <- 1 -- Initialization must be an expression + in { + count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/let5.cl b/tests/parser/let5.cl index d974cc138..cc4ed7a99 100644 --- a/tests/parser/let5.cl +++ b/tests/parser/let5.cl @@ -1,85 +1,85 @@ -(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int = 0, pow: Int -- Must be '<-' not '=' - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int = 0, pow: Int -- Must be '<-' not '=' + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/let6.cl b/tests/parser/let6.cl index b6e51d7e1..8bc8c4883 100644 --- a/tests/parser/let6.cl +++ b/tests/parser/let6.cl @@ -1,74 +1,74 @@ -(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int <- 1 - in false++ -- Let body must be an expression - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int <- 1 + in false++ -- Let body must be an expression + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/let7.cl b/tests/parser/let7.cl index 6fd63e6a7..816c59845 100644 --- a/tests/parser/let7.cl +++ b/tests/parser/let7.cl @@ -1,85 +1,85 @@ -(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - (* Missing "in" *) { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + (* Missing "in" *) { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/loop1.cl b/tests/parser/loop1.cl index 7d0d7688f..2065de506 100644 --- a/tests/parser/loop1.cl +++ b/tests/parser/loop1.cl @@ -1,78 +1,78 @@ -(* A loop has the form while loop pool *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - count: Int <- 1; - - testing6(): Object { - while count < 1024*1024 - -- Missing "loop" - count <- count * 2 - pool - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A loop has the form while loop pool *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + count: Int <- 1; + + testing6(): Object { + while count < 1024*1024 + -- Missing "loop" + count <- count * 2 + pool + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/loop2.cl b/tests/parser/loop2.cl index a9613c487..70f8cd910 100644 --- a/tests/parser/loop2.cl +++ b/tests/parser/loop2.cl @@ -1,78 +1,78 @@ -(* A loop has the form while loop pool *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - count: Int <- 1; - - testing6(): Object { - while count < 1024*1024 - loop - count <- count * 2 - -- Missing "pool" - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A loop has the form while loop pool *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + count: Int <- 1; + + testing6(): Object { + while count < 1024*1024 + loop + count <- count * 2 + -- Missing "pool" + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/loop3.cl b/tests/parser/loop3.cl index 860adb4d1..fbb3a56b4 100644 --- a/tests/parser/loop3.cl +++ b/tests/parser/loop3.cl @@ -1,78 +1,78 @@ -(* A loop has the form while loop pool *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - count: Int <- 1; - - testing6(): Object { - while count => 1024*1024 -- Condition must be an expression - loop - count <- count * 2 - pool - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A loop has the form while loop pool *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + count: Int <- 1; + + testing6(): Object { + while count => 1024*1024 -- Condition must be an expression + loop + count <- count * 2 + pool + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/loop4.cl b/tests/parser/loop4.cl index 0a1194e82..47b0e5f4a 100644 --- a/tests/parser/loop4.cl +++ b/tests/parser/loop4.cl @@ -1,78 +1,78 @@ -(* A loop has the form while loop pool *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - count: Int <- 1; - - testing6(): Object { - while count < 1024*1024 - loop - count <- true++ -- While body must be an expression - pool - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A loop has the form while loop pool *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + count: Int <- 1; + + testing6(): Object { + while count < 1024*1024 + loop + count <- true++ -- While body must be an expression + pool + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/method1.cl b/tests/parser/method1.cl index fcfbbcd30..d86661430 100644 --- a/tests/parser/method1.cl +++ b/tests/parser/method1.cl @@ -1,34 +1,34 @@ -(* A method of class A is a procedure that may manipulate the variables and objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - -- Method names must begin with lowercase letters - Testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A method of class A is a procedure that may manipulate the variables and objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + -- Method names must begin with lowercase letters + Testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/method2.cl b/tests/parser/method2.cl index d5bdfd85c..83648f50d 100644 --- a/tests/parser/method2.cl +++ b/tests/parser/method2.cl @@ -1,34 +1,34 @@ -(* A method of class A is a procedure that may manipulate the variables and objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - -- Parameter names must begin with lowercase letters - testing2(a: Alpha, B: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A method of class A is a procedure that may manipulate the variables and objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + -- Parameter names must begin with lowercase letters + testing2(a: Alpha, B: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/method3.cl b/tests/parser/method3.cl index 1e5c9eb53..428b25fec 100644 --- a/tests/parser/method3.cl +++ b/tests/parser/method3.cl @@ -1,34 +1,34 @@ -(* A method of class A is a procedure that may manipulate the variables and objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - -- Type names must begin with uppercase letters - testing2(a: Alpha, b: int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A method of class A is a procedure that may manipulate the variables and objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + -- Type names must begin with uppercase letters + testing2(a: Alpha, b: int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/method4.cl b/tests/parser/method4.cl index 019ada276..52ec07bce 100644 --- a/tests/parser/method4.cl +++ b/tests/parser/method4.cl @@ -1,34 +1,34 @@ -(* A method of class A is a procedure that may manipulate the variables and objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - -- Missing paremeter - testing3(x: Int,): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A method of class A is a procedure that may manipulate the variables and objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + -- Missing paremeter + testing3(x: Int,): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/method5.cl b/tests/parser/method5.cl index 13127f664..706a3145c 100644 --- a/tests/parser/method5.cl +++ b/tests/parser/method5.cl @@ -1,34 +1,34 @@ -(* A method of class A is a procedure that may manipulate the variables and objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - -- Type names must begin with uppercase letters - testing3(): string { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A method of class A is a procedure that may manipulate the variables and objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + -- Type names must begin with uppercase letters + testing3(): string { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/method6.cl b/tests/parser/method6.cl index d48cd1293..26ce7f19f 100644 --- a/tests/parser/method6.cl +++ b/tests/parser/method6.cl @@ -1,33 +1,33 @@ -(* A method of class A is a procedure that may manipulate the variables and objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - -- Body can't be empty - testing2(a: Alpha, b: Int): Int { - }; - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A method of class A is a procedure that may manipulate the variables and objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + -- Body can't be empty + testing2(a: Alpha, b: Int): Int { + }; + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/mixed1.cl b/tests/parser/mixed1.cl index a27879513..b13e679da 100644 --- a/tests/parser/mixed1.cl +++ b/tests/parser/mixed1.cl @@ -1,100 +1,100 @@ -(* Cool has four binary arithmetic operations: +, -, *, /. *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case 2 + 2 of - x: Int => new IO.out_string("Es un entero!"); - y: String => new IO.out_string("Es una cadena!"); - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; - - a: Int <- 1; - - testing8(x: Int, y: Int): Bool { - let z: Int <- 3, w: Int <- 4 - in isvoid (3 + a * (x / w + new Int) - y - (((if tRue = not faLSe then ~z else 3 <= 4 + "hey".length() fi + a))/(0)*(((4 * 4))))) - }; -}-- Mising ";" - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Cool has four binary arithmetic operations: +, -, *, /. *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case 2 + 2 of + x: Int => new IO.out_string("Es un entero!"); + y: String => new IO.out_string("Es una cadena!"); + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; + + a: Int <- 1; + + testing8(x: Int, y: Int): Bool { + let z: Int <- 3, w: Int <- 4 + in isvoid (3 + a * (x / w + new Int) - y - (((if tRue = not faLSe then ~z else 3 <= 4 + "hey".length() fi + a))/(0)*(((4 * 4))))) + }; +}-- Mising ";" + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/mixed2.cl b/tests/parser/mixed2.cl index f5477e0bb..6776fcc12 100644 --- a/tests/parser/mixed2.cl +++ b/tests/parser/mixed2.cl @@ -1,14 +1,14 @@ -class Main { - main(): Object { - (new Alpha).print() - }; - -}; - -(* Class names must begin with uppercase letters *) -class alpha inherits IO { - print() : Object { - out_string("reached!!\n"); - }; -}; - +class Main { + main(): Object { + (new Alpha).print() + }; + +}; + +(* Class names must begin with uppercase letters *) +class alpha inherits IO { + print() : Object { + out_string("reached!!\n"); + }; +}; + diff --git a/tests/parser/mixed3.cl b/tests/parser/mixed3.cl index 1bdcad743..f5271eb3e 100644 --- a/tests/parser/mixed3.cl +++ b/tests/parser/mixed3.cl @@ -1,40 +1,40 @@ -class Main inherits IO { - main() : Object { - { - out_string("Enter a number to check if number is prime\n"); - let i : Int <- in_int() in { - if(i <= 1) then { - out_string("Invalid Input\n"); - abort(); - } else { - if (isPrime(i) = 1) then - out_string("Number is prime\n") - else - out_string("Number is composite\n") - fi; - } - fi; - }; - } - }; - - mod(i : Int, ) : Int { -- Formal list must be comma separated. A comma does not terminate a list of formals. - i - (i/k)*k - }; - - isPrime(i : Int) : Int { - { - let x : Int <- 2, - c : Int <- 1 in - { - while (not (x = i)) loop - if (mod(i, x) = 0) then { - c <- 0; - x <- i; - } else x <- x + 1 fi - pool; - c; - }; - } - }; -}; +class Main inherits IO { + main() : Object { + { + out_string("Enter a number to check if number is prime\n"); + let i : Int <- in_int() in { + if(i <= 1) then { + out_string("Invalid Input\n"); + abort(); + } else { + if (isPrime(i) = 1) then + out_string("Number is prime\n") + else + out_string("Number is composite\n") + fi; + } + fi; + }; + } + }; + + mod(i : Int, ) : Int { -- Formal list must be comma separated. A comma does not terminate a list of formals. + i - (i/k)*k + }; + + isPrime(i : Int) : Int { + { + let x : Int <- 2, + c : Int <- 1 in + { + while (not (x = i)) loop + if (mod(i, x) = 0) then { + c <- 0; + x <- i; + } else x <- x + 1 fi + pool; + c; + }; + } + }; +}; diff --git a/tests/parser/mixed4.cl b/tests/parser/mixed4.cl index e752253be..47e6ea5e9 100644 --- a/tests/parser/mixed4.cl +++ b/tests/parser/mixed4.cl @@ -1,21 +1,21 @@ -class Main inherits IO { - main() : Object { - { - out_string("Enter number of numbers to multiply\n"); - out_int(prod(in_int())); - out_string("\n"); - } - }; - - prod(i : Int) : Int { - let y : Int <- 1 in { - while (not (i = 0) ) loop { - out_string("Enter Number: "); - y <- y * in_int(Main : Int); -- the parser correctly catches the error here - i <- i - 1; - } - pool; - y; - } - }; -}; +class Main inherits IO { + main() : Object { + { + out_string("Enter number of numbers to multiply\n"); + out_int(prod(in_int())); + out_string("\n"); + } + }; + + prod(i : Int) : Int { + let y : Int <- 1 in { + while (not (i = 0) ) loop { + out_string("Enter Number: "); + y <- y * in_int(Main : Int); -- the parser correctly catches the error here + i <- i - 1; + } + pool; + y; + } + }; +}; diff --git a/tests/parser/mixed5.cl b/tests/parser/mixed5.cl index c9176a890..d4ca68f44 100644 --- a/tests/parser/mixed5.cl +++ b/tests/parser/mixed5.cl @@ -1,20 +1,20 @@ -class Main inherits IO { - str <- "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; - main() : Object { - { - out_string("Enter number of numbers to multiply\n"); - out_int(prod(in_int())); - out_string("\n"); - } - }; - prod(i : Int) : Int { - let y : Int <- 1 in { - while (not (i = 0) ) loop { - out_string("Enter Number: "); - y <- y * in_int(); - i <- i - 1; - } - y; - } - }; -} +class Main inherits IO { + str <- "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; + main() : Object { + { + out_string("Enter number of numbers to multiply\n"); + out_int(prod(in_int())); + out_string("\n"); + } + }; + prod(i : Int) : Int { + let y : Int <- 1 in { + while (not (i = 0) ) loop { + out_string("Enter Number: "); + y <- y * in_int(); + i <- i - 1; + } + y; + } + }; +} diff --git a/tests/parser/mixed6.cl b/tests/parser/mixed6.cl index 5da80da31..0a51656c9 100644 --- a/tests/parser/mixed6.cl +++ b/tests/parser/mixed6.cl @@ -1,5 +1,5 @@ -classs Doom { - i : Int <- 0; - main() : Object { - if i = 0 then out_string("This is da real *h*t") - +classs Doom { + i : Int <- 0; + main() : Object { + if i = 0 then out_string("This is da real *h*t") + diff --git a/tests/parser/operation1.cl b/tests/parser/operation1.cl index d38eb72d0..d892ec8a6 100644 --- a/tests/parser/operation1.cl +++ b/tests/parser/operation1.cl @@ -1,101 +1,101 @@ -(* Cool has four binary arithmetic operations: +, -, *, /. *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case 2 + 2 of - x: Int => new IO.out_string("Es un entero!"); - y: String => new IO.out_string("Es una cadena!"); - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; - - a: Int <- 1; - - testing8(x: Int, y: Int): Bool { - let z: Int <- 3, w: Int <- 4 - -- Missing ')' - in isvoid (3 + a * (x / w + new Int) - y - (((if tRue = not faLSe then ~z else 3 <= 4 + "hey".length() fi + a)/(0)*(((4 * 4))))) - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Cool has four binary arithmetic operations: +, -, *, /. *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case 2 + 2 of + x: Int => new IO.out_string("Es un entero!"); + y: String => new IO.out_string("Es una cadena!"); + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; + + a: Int <- 1; + + testing8(x: Int, y: Int): Bool { + let z: Int <- 3, w: Int <- 4 + -- Missing ')' + in isvoid (3 + a * (x / w + new Int) - y - (((if tRue = not faLSe then ~z else 3 <= 4 + "hey".length() fi + a)/(0)*(((4 * 4))))) + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/operation2.cl b/tests/parser/operation2.cl index 2dc628359..1f167409a 100644 --- a/tests/parser/operation2.cl +++ b/tests/parser/operation2.cl @@ -1,101 +1,101 @@ -(* Cool has four binary arithmetic operations: +, -, *, /. *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case 2 + 2 of - x: Int => new IO.out_string("Es un entero!"); - y: String => new IO.out_string("Es una cadena!"); - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; - - a: Int <- 1; - - testing8(x: Int, y: Int): Bool { - let z: Int <- 3, w: Int <- 4 - -- Type identifiers starts with a uppercase letter - in isvoid (3 + a * (x / w + new int) - y - (((if tRue = not faLSe then ~z else 3 <= 4 + "hey".length() fi + a))/(0)*(((4 * 4))))) - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Cool has four binary arithmetic operations: +, -, *, /. *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case 2 + 2 of + x: Int => new IO.out_string("Es un entero!"); + y: String => new IO.out_string("Es una cadena!"); + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; + + a: Int <- 1; + + testing8(x: Int, y: Int): Bool { + let z: Int <- 3, w: Int <- 4 + -- Type identifiers starts with a uppercase letter + in isvoid (3 + a * (x / w + new int) - y - (((if tRue = not faLSe then ~z else 3 <= 4 + "hey".length() fi + a))/(0)*(((4 * 4))))) + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/operation3.cl b/tests/parser/operation3.cl index 61d6cbfa8..ef125927a 100644 --- a/tests/parser/operation3.cl +++ b/tests/parser/operation3.cl @@ -1,101 +1,101 @@ -(* Cool has four binary arithmetic operations: +, -, *, /. *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case 2 + 2 of - x: Int => new IO.out_string("Es un entero!"); - y: String => new IO.out_string("Es una cadena!"); - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; - - a: Int <- 1; - - testing8(x: Int, y: Int): Bool { - let z: Int <- 3, w: Int <- 4 - -- Object identifiers starts with a lowercase letter - in isvoid (3 + a * (x / w + new Int) - y - (((if tRue = not faLSe then ~Mazinger_Z else 3 <= 4 + "hey".length() fi + a))/(0)*(((4 * 4))))) - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Cool has four binary arithmetic operations: +, -, *, /. *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case 2 + 2 of + x: Int => new IO.out_string("Es un entero!"); + y: String => new IO.out_string("Es una cadena!"); + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; + + a: Int <- 1; + + testing8(x: Int, y: Int): Bool { + let z: Int <- 3, w: Int <- 4 + -- Object identifiers starts with a lowercase letter + in isvoid (3 + a * (x / w + new Int) - y - (((if tRue = not faLSe then ~Mazinger_Z else 3 <= 4 + "hey".length() fi + a))/(0)*(((4 * 4))))) + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/operation4.cl b/tests/parser/operation4.cl index bae7de5b5..2212740e7 100644 --- a/tests/parser/operation4.cl +++ b/tests/parser/operation4.cl @@ -1,101 +1,101 @@ -(* Cool has four binary arithmetic operations: +, -, *, /. *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case 2 + 2 of - x: Int => new IO.out_string("Es un entero!"); - y: String => new IO.out_string("Es una cadena!"); - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; - - a: Int <- 1; - - testing8(x: Int, y: Int): Bool { - let z: Int <- 3, w: Int <- 4 - -- Double "+" - in isvoid (3 + a * (x / w++ new Int) - y - (((if tRue = not faLSe then ~z else 3 <= 4 + "hey".length() fi + a))/(0)*(((4 * 4))))) - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Cool has four binary arithmetic operations: +, -, *, /. *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case 2 + 2 of + x: Int => new IO.out_string("Es un entero!"); + y: String => new IO.out_string("Es una cadena!"); + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; + + a: Int <- 1; + + testing8(x: Int, y: Int): Bool { + let z: Int <- 3, w: Int <- 4 + -- Double "+" + in isvoid (3 + a * (x / w++ new Int) - y - (((if tRue = not faLSe then ~z else 3 <= 4 + "hey".length() fi + a))/(0)*(((4 * 4))))) + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/program2.cl b/tests/parser/program2.cl index f8b16779c..a281c6c14 100644 --- a/tests/parser/program2.cl +++ b/tests/parser/program2.cl @@ -1,20 +1,20 @@ -(* Cool programs are sets of classes *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - --- Missing semicolon -class Test { - testing(): Int { - 2 + 2 - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; -}; +(* Cool programs are sets of classes *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +-- Missing semicolon +class Test { + testing(): Int { + 2 + 2 + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; +}; diff --git a/tests/parser/program3.cl b/tests/parser/program3.cl index e27889c57..10d2dc71e 100644 --- a/tests/parser/program3.cl +++ b/tests/parser/program3.cl @@ -1,24 +1,24 @@ -(* Cool programs are sets of classes *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - testing(): Int { - 2 + 2 - }; -}; - --- Only classes -suma(a: Int, b: Int) int { - a + b -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; -}; +(* Cool programs are sets of classes *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + testing(): Int { + 2 + 2 + }; +}; + +-- Only classes +suma(a: Int, b: Int) int { + a + b +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; +}; diff --git a/tests/parser_test.py b/tests/parser_test.py index 129c0f20a..166de45de 100644 --- a/tests/parser_test.py +++ b/tests/parser_test.py @@ -1,13 +1,13 @@ -import pytest -import os -from utils import compare_errors - -tests_dir = __file__.rpartition('/')[0] + '/parser/' -tests = [(file) for file in os.listdir(tests_dir) if file.endswith('.cl')] - -@pytest.mark.parser -@pytest.mark.error -@pytest.mark.run(order=2) -@pytest.mark.parametrize("cool_file", tests) -def test_parser_errors(compiler_path, cool_file): +import pytest +import os +from utils import compare_errors + +tests_dir = __file__.rpartition('/')[0] + '/parser/' +tests = [(file) for file in os.listdir(tests_dir) if file.endswith('.cl')] + +@pytest.mark.parser +@pytest.mark.error +@pytest.mark.run(order=2) +@pytest.mark.parametrize("cool_file", tests) +def test_parser_errors(compiler_path, cool_file): compare_errors(compiler_path, tests_dir + cool_file, tests_dir + cool_file[:-3] + '_error.txt') \ No newline at end of file diff --git a/tests/semantic/arithmetic1.cl b/tests/semantic/arithmetic1.cl index bf94eb194..65719c064 100644 --- a/tests/semantic/arithmetic1.cl +++ b/tests/semantic/arithmetic1.cl @@ -1,11 +1,11 @@ ---The static types of the two sub-expressions must be Int. - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Int <- let x: Int <- 1 * 2 / 3 - 4 + new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in x <- x + new A.type_name().concat(new B.type_name().concat(new C.type_name())); +--The static types of the two sub-expressions must be Int. + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Int <- let x: Int <- 1 * 2 / 3 - 4 + new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in x <- x + new A.type_name().concat(new B.type_name().concat(new C.type_name())); }; \ No newline at end of file diff --git a/tests/semantic/arithmetic10.cl b/tests/semantic/arithmetic10.cl index bbfe6cdb3..b2488ad7f 100644 --- a/tests/semantic/arithmetic10.cl +++ b/tests/semantic/arithmetic10.cl @@ -1,15 +1,15 @@ -(* -The expression ~ is the integer -complement of . The expression must have static type Int and the entire expression -has static type Int. -*) - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Bool <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in ~new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); +(* +The expression ~ is the integer +complement of . The expression must have static type Int and the entire expression +has static type Int. +*) + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Bool <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in ~new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); }; \ No newline at end of file diff --git a/tests/semantic/arithmetic11.cl b/tests/semantic/arithmetic11.cl index fc067dc1a..05cec0465 100644 --- a/tests/semantic/arithmetic11.cl +++ b/tests/semantic/arithmetic11.cl @@ -1,14 +1,14 @@ -(* -The expression not is the boolean complement of . The expression - must have static type Bool and the entire expression has static type Bool. -*) - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Bool <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in not 1 + new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); +(* +The expression not is the boolean complement of . The expression + must have static type Bool and the entire expression has static type Bool. +*) + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Bool <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in not 1 + new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); }; \ No newline at end of file diff --git a/tests/semantic/arithmetic12.cl b/tests/semantic/arithmetic12.cl index 2e012fc41..05a2da918 100644 --- a/tests/semantic/arithmetic12.cl +++ b/tests/semantic/arithmetic12.cl @@ -1,14 +1,14 @@ -(* -The expression not is the boolean complement of . The expression - must have static type Bool and the entire expression has static type Bool. -*) - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Int <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in not 1 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); +(* +The expression not is the boolean complement of . The expression + must have static type Bool and the entire expression has static type Bool. +*) + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Int <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in not 1 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); }; \ No newline at end of file diff --git a/tests/semantic/arithmetic1_error.txt b/tests/semantic/arithmetic1_error.txt index a74ebf3da..59213724d 100644 --- a/tests/semantic/arithmetic1_error.txt +++ b/tests/semantic/arithmetic1_error.txt @@ -1 +1 @@ -(10, 27) - TypeError: non-Int arguments: Int + String +(10, 27) - TypeError: non-Int arguments: Int + String diff --git a/tests/semantic/arithmetic2.cl b/tests/semantic/arithmetic2.cl index 59532573d..f1f0935e2 100644 --- a/tests/semantic/arithmetic2.cl +++ b/tests/semantic/arithmetic2.cl @@ -1,11 +1,11 @@ ---The static types of the two sub-expressions must be Int. - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Int <- let x: Int <- 1 + 2 * 3 / 4 - new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in x <- x - new A.type_name().concat(new B.type_name().concat(new C.type_name())); +--The static types of the two sub-expressions must be Int. + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Int <- let x: Int <- 1 + 2 * 3 / 4 - new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in x <- x - new A.type_name().concat(new B.type_name().concat(new C.type_name())); }; \ No newline at end of file diff --git a/tests/semantic/arithmetic2_error.txt b/tests/semantic/arithmetic2_error.txt index 2c7952af8..aebc7aab9 100644 --- a/tests/semantic/arithmetic2_error.txt +++ b/tests/semantic/arithmetic2_error.txt @@ -1 +1 @@ -(10, 27) - TypeError: non-Int arguments: Int - String +(10, 27) - TypeError: non-Int arguments: Int - String diff --git a/tests/semantic/arithmetic3.cl b/tests/semantic/arithmetic3.cl index b208957f5..df64d8000 100644 --- a/tests/semantic/arithmetic3.cl +++ b/tests/semantic/arithmetic3.cl @@ -1,11 +1,11 @@ ---The static types of the two sub-expressions must be Int. - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Int <- let x: Int <- 1 - 2 + 3 * 4 / new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in x <- x / new A.type_name().concat(new B.type_name().concat(new C.type_name())); +--The static types of the two sub-expressions must be Int. + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Int <- let x: Int <- 1 - 2 + 3 * 4 / new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in x <- x / new A.type_name().concat(new B.type_name().concat(new C.type_name())); }; \ No newline at end of file diff --git a/tests/semantic/arithmetic3_error.txt b/tests/semantic/arithmetic3_error.txt index 81d88331a..d0af01bb5 100644 --- a/tests/semantic/arithmetic3_error.txt +++ b/tests/semantic/arithmetic3_error.txt @@ -1 +1 @@ -(10, 27) - TypeError: non-Int arguments: Int / String +(10, 27) - TypeError: non-Int arguments: Int / String diff --git a/tests/semantic/arithmetic4.cl b/tests/semantic/arithmetic4.cl index 2c7dd4fc9..68512ca44 100644 --- a/tests/semantic/arithmetic4.cl +++ b/tests/semantic/arithmetic4.cl @@ -1,11 +1,11 @@ ---The static types of the two sub-expressions must be Int. - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Int <- let x: Int <- 1 / 2 - 3 + 4 * new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in x <- x * new A.type_name().concat(new B.type_name().concat(new C.type_name())); +--The static types of the two sub-expressions must be Int. + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Int <- let x: Int <- 1 / 2 - 3 + 4 * new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in x <- x * new A.type_name().concat(new B.type_name().concat(new C.type_name())); }; \ No newline at end of file diff --git a/tests/semantic/arithmetic5.cl b/tests/semantic/arithmetic5.cl index bc08c6e82..fd77c7971 100644 --- a/tests/semantic/arithmetic5.cl +++ b/tests/semantic/arithmetic5.cl @@ -1,11 +1,11 @@ ---The static type of the expression is Int. - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Bool <- let x: Int <- 1 / 2 - 3 + 4 * new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in x <- x * new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); +--The static type of the expression is Int. + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Bool <- let x: Int <- 1 / 2 - 3 + 4 * new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in x <- x * new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); }; \ No newline at end of file diff --git a/tests/semantic/arithmetic5_error.txt b/tests/semantic/arithmetic5_error.txt index dd5346844..8c67c2f53 100644 --- a/tests/semantic/arithmetic5_error.txt +++ b/tests/semantic/arithmetic5_error.txt @@ -1 +1 @@ -(9, 19) - TypeError: Inferred type Int of initialization of attribute test does not conform to declared type Bool. +(9, 19) - TypeError: Inferred type Int of initialization of attribute test does not conform to declared type Bool. diff --git a/tests/semantic/arithmetic6.cl b/tests/semantic/arithmetic6.cl index a0c3d03ff..d4da66a73 100644 --- a/tests/semantic/arithmetic6.cl +++ b/tests/semantic/arithmetic6.cl @@ -1,11 +1,11 @@ - --The static types of the two sub-expressions must be Int. - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Bool <- let x: Bool <- 1 / 2 - 3 + 4 <= new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in 1 <= new A.type_name().concat(new B.type_name().concat(new C.type_name())); -}; + --The static types of the two sub-expressions must be Int. + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Bool <- let x: Bool <- 1 / 2 - 3 + 4 <= new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in 1 <= new A.type_name().concat(new B.type_name().concat(new C.type_name())); +}; diff --git a/tests/semantic/arithmetic6_error.txt b/tests/semantic/arithmetic6_error.txt index 2e43dfc17..a0d67cb48 100644 --- a/tests/semantic/arithmetic6_error.txt +++ b/tests/semantic/arithmetic6_error.txt @@ -1 +1 @@ -(10, 22) - TypeError: non-Int arguments: Int <= String +(10, 22) - TypeError: non-Int arguments: Int <= String diff --git a/tests/semantic/arithmetic7.cl b/tests/semantic/arithmetic7.cl index c00c75cde..b98a4b0e2 100644 --- a/tests/semantic/arithmetic7.cl +++ b/tests/semantic/arithmetic7.cl @@ -1,12 +1,12 @@ - --The static types of the two sub-expressions must be Int. - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Bool <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in 1 < new A.type_name().concat(new B.type_name().concat(new C.type_name())); -}; - + --The static types of the two sub-expressions must be Int. + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Bool <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in 1 < new A.type_name().concat(new B.type_name().concat(new C.type_name())); +}; + diff --git a/tests/semantic/arithmetic7_error.txt b/tests/semantic/arithmetic7_error.txt index 6f3537117..166bcc8ef 100644 --- a/tests/semantic/arithmetic7_error.txt +++ b/tests/semantic/arithmetic7_error.txt @@ -1 +1 @@ -(10, 22) - TypeError: non-Int arguments: Int < String +(10, 22) - TypeError: non-Int arguments: Int < String diff --git a/tests/semantic/arithmetic8.cl b/tests/semantic/arithmetic8.cl index 3210bdb8a..f3ad37ec4 100644 --- a/tests/semantic/arithmetic8.cl +++ b/tests/semantic/arithmetic8.cl @@ -1,13 +1,13 @@ - --The rules are exactly the same as for the binary arithmetic operations, except that the result is a Bool. - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Int <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in 1 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); -}; - - + --The rules are exactly the same as for the binary arithmetic operations, except that the result is a Bool. + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Int <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in 1 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); +}; + + diff --git a/tests/semantic/arithmetic8_error.txt b/tests/semantic/arithmetic8_error.txt index ebcaa3797..5a8814e1a 100644 --- a/tests/semantic/arithmetic8_error.txt +++ b/tests/semantic/arithmetic8_error.txt @@ -1 +1 @@ -(9, 18) - TypeError: Inferred type Bool of initialization of attribute test does not conform to declared type Int. +(9, 18) - TypeError: Inferred type Bool of initialization of attribute test does not conform to declared type Int. diff --git a/tests/semantic/arithmetic9.cl b/tests/semantic/arithmetic9.cl index 95579e134..b7b4d3645 100644 --- a/tests/semantic/arithmetic9.cl +++ b/tests/semantic/arithmetic9.cl @@ -1,15 +1,15 @@ -(* -The expression ~ is the integer -complement of . The expression must have static type Int and the entire expression -has static type Int. -*) - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Int <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in 1 + ~new A.type_name().concat(new B.type_name().concat(new C.type_name())); +(* +The expression ~ is the integer +complement of . The expression must have static type Int and the entire expression +has static type Int. +*) + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Int <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in 1 + ~new A.type_name().concat(new B.type_name().concat(new C.type_name())); }; \ No newline at end of file diff --git a/tests/semantic/assignment1.cl b/tests/semantic/assignment1.cl index 19ab70219..174f93e2b 100644 --- a/tests/semantic/assignment1.cl +++ b/tests/semantic/assignment1.cl @@ -1,7 +1,7 @@ ---The static type of the expression must conform to the declared type of the identifier - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test: Int <- "String"; -}; +--The static type of the expression must conform to the declared type of the identifier + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test: Int <- "String"; +}; diff --git a/tests/semantic/assignment1_error.txt b/tests/semantic/assignment1_error.txt index 6eb883012..9d05707aa 100644 --- a/tests/semantic/assignment1_error.txt +++ b/tests/semantic/assignment1_error.txt @@ -1 +1 @@ -(6, 18) - TypeError: Inferred type String of initialization of attribute test does not conform to declared type Int. +(6, 18) - TypeError: Inferred type String of initialization of attribute test does not conform to declared type Int. diff --git a/tests/semantic/assignment2.cl b/tests/semantic/assignment2.cl index cace221ae..c7f3d7873 100644 --- a/tests/semantic/assignment2.cl +++ b/tests/semantic/assignment2.cl @@ -1,13 +1,13 @@ ---The static type of an assignment is the static type of . - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test(a: A): B { a <- new C }; - test2(a: A): D { a <- new C }; -}; +--The static type of an assignment is the static type of . + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test(a: A): B { a <- new C }; + test2(a: A): D { a <- new C }; +}; diff --git a/tests/semantic/assignment2_error.txt b/tests/semantic/assignment2_error.txt index ed10b7f38..55f5aa214 100644 --- a/tests/semantic/assignment2_error.txt +++ b/tests/semantic/assignment2_error.txt @@ -1 +1 @@ -(12, 22) - TypeError: Inferred return type C of method test2 does not conform to declared return type D. +(12, 22) - TypeError: Inferred return type C of method test2 does not conform to declared return type D. diff --git a/tests/semantic/assignment3.cl b/tests/semantic/assignment3.cl index eba0d69e2..9d60a4b6c 100644 --- a/tests/semantic/assignment3.cl +++ b/tests/semantic/assignment3.cl @@ -1,14 +1,14 @@ ---The static type of an assignment is the static type of . - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - a: A; - b: B <- a <- new C; - d: D <- a <- new C; -}; +--The static type of an assignment is the static type of . + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + a: A; + b: B <- a <- new C; + d: D <- a <- new C; +}; diff --git a/tests/semantic/attributes1.cl b/tests/semantic/attributes1.cl index 3fa0440e4..d11ea7cdb 100644 --- a/tests/semantic/attributes1.cl +++ b/tests/semantic/attributes1.cl @@ -1,13 +1,13 @@ ---The static type of the expression must conform to the declared type of the attribute. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - test1: IO <- new Main; - test2: B <- new A; - - main(): IO { out_string("Hello World!")}; +--The static type of the expression must conform to the declared type of the attribute. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + test1: IO <- new Main; + test2: B <- new A; + + main(): IO { out_string("Hello World!")}; }; \ No newline at end of file diff --git a/tests/semantic/attributes1_error.txt b/tests/semantic/attributes1_error.txt index 9cb8460c9..22e45b837 100644 --- a/tests/semantic/attributes1_error.txt +++ b/tests/semantic/attributes1_error.txt @@ -1 +1 @@ -(10, 17) - TypeError: Inferred type A of initialization of attribute test2 does not conform to declared type B. +(10, 17) - TypeError: Inferred type A of initialization of attribute test2 does not conform to declared type B. diff --git a/tests/semantic/attributes2.cl b/tests/semantic/attributes2.cl index 7937c2cc8..85c791b5e 100644 --- a/tests/semantic/attributes2.cl +++ b/tests/semantic/attributes2.cl @@ -1,13 +1,13 @@ ---The static type of the expression must conform to the declared type of the attribute. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - test1: IO <- new Main; - test2: C <- new D; - - main(): IO { out_string("Hello World!")}; +--The static type of the expression must conform to the declared type of the attribute. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + test1: IO <- new Main; + test2: C <- new D; + + main(): IO { out_string("Hello World!")}; }; \ No newline at end of file diff --git a/tests/semantic/attributes2_error.txt b/tests/semantic/attributes2_error.txt index 6d601b7cd..d7694b0ad 100644 --- a/tests/semantic/attributes2_error.txt +++ b/tests/semantic/attributes2_error.txt @@ -1 +1 @@ -(10, 17) - TypeError: Inferred type D of initialization of attribute test2 does not conform to declared type C. +(10, 17) - TypeError: Inferred type D of initialization of attribute test2 does not conform to declared type C. diff --git a/tests/semantic/attributes3.cl b/tests/semantic/attributes3.cl index 8a67decd1..0c8294fa2 100644 --- a/tests/semantic/attributes3.cl +++ b/tests/semantic/attributes3.cl @@ -1,25 +1,25 @@ ---Attributes are local to the class in which they are defined or inherited. - -class A { - a: Int <- 5; - test(x1: Int, y1: Int): Int { - let x: Int <- x1, y: Int <-y1 in { - x <- x + a; - y <- y + a; - if b then x + y else x - y fi; - } - }; -}; -class B inherits A { - b: Bool <- true; -}; -class C inherits B { - c: String <- "C"; -}; -class D inherits B { - d: IO <- new Main.main(); -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!") }; +--Attributes are local to the class in which they are defined or inherited. + +class A { + a: Int <- 5; + test(x1: Int, y1: Int): Int { + let x: Int <- x1, y: Int <-y1 in { + x <- x + a; + y <- y + a; + if b then x + y else x - y fi; + } + }; +}; +class B inherits A { + b: Bool <- true; +}; +class C inherits B { + c: String <- "C"; +}; +class D inherits B { + d: IO <- new Main.main(); +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!") }; }; \ No newline at end of file diff --git a/tests/semantic/attributes3_error.txt b/tests/semantic/attributes3_error.txt index 6195c816c..68a2ba571 100644 --- a/tests/semantic/attributes3_error.txt +++ b/tests/semantic/attributes3_error.txt @@ -1 +1 @@ -(9, 16) - NameError: Undeclared identifier b. +(9, 16) - NameError: Undeclared identifier b. diff --git a/tests/semantic/attributes4.cl b/tests/semantic/attributes4.cl index a7f63adbd..307b185fd 100644 --- a/tests/semantic/attributes4.cl +++ b/tests/semantic/attributes4.cl @@ -1,39 +1,39 @@ ---Attributes are local to the class in which they are defined or inherited. - -class A { - a: Int <- 5; -}; -class B inherits A { - b: Bool <- true; - test(x1: Int, y1: Int): Int { - let x: Int <- x1, y: Int <-y1 in { - x <- x + a; - y <- y + a; - if b then x + y else x - y fi; - } - }; -}; -class D inherits B { - d: IO <- new Main.main(); - test3(x1: Int, y1: Int): IO { - let x: Int <- x1, y: Int <-y1, c: String <- "C" in { - x <- x + a; - y <- y + a; - if b then new IO.out_string(c) else d fi; - } - }; -}; -class C inherits B { - c: String <- "C"; - test2(x1: Int, y1: Int): IO { - let x: Int <- x1, y: Int <-y1 in { - x <- x + a; - y <- y + a; - if b then new IO.out_string(c) else d fi; - } - }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!") }; +--Attributes are local to the class in which they are defined or inherited. + +class A { + a: Int <- 5; +}; +class B inherits A { + b: Bool <- true; + test(x1: Int, y1: Int): Int { + let x: Int <- x1, y: Int <-y1 in { + x <- x + a; + y <- y + a; + if b then x + y else x - y fi; + } + }; +}; +class D inherits B { + d: IO <- new Main.main(); + test3(x1: Int, y1: Int): IO { + let x: Int <- x1, y: Int <-y1, c: String <- "C" in { + x <- x + a; + y <- y + a; + if b then new IO.out_string(c) else d fi; + } + }; +}; +class C inherits B { + c: String <- "C"; + test2(x1: Int, y1: Int): IO { + let x: Int <- x1, y: Int <-y1 in { + x <- x + a; + y <- y + a; + if b then new IO.out_string(c) else d fi; + } + }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!") }; }; \ No newline at end of file diff --git a/tests/semantic/basics1.cl b/tests/semantic/basics1.cl index 32ae16564..af84ca0c9 100644 --- a/tests/semantic/basics1.cl +++ b/tests/semantic/basics1.cl @@ -1,10 +1,10 @@ --- It is an error to redefine the IO class. - -class IO { - scan(): String { ":)" }; - print(s: String): IO { new IO }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; +-- It is an error to redefine the IO class. + +class IO { + scan(): String { ":)" }; + print(s: String): IO { new IO }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; }; \ No newline at end of file diff --git a/tests/semantic/basics1_error.txt b/tests/semantic/basics1_error.txt index 676f5049c..0db23a051 100644 --- a/tests/semantic/basics1_error.txt +++ b/tests/semantic/basics1_error.txt @@ -1 +1 @@ -(3, 7) - SemanticError: Redefinition of basic class IO. +(3, 7) - SemanticError: Redefinition of basic class IO. diff --git a/tests/semantic/basics2.cl b/tests/semantic/basics2.cl index cf2b1cd2f..61399a989 100644 --- a/tests/semantic/basics2.cl +++ b/tests/semantic/basics2.cl @@ -1,9 +1,9 @@ --- It is an error to inherit from or redefine Int. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; -}; - -class A inherits Int { - is_prime(): Bool { false }; -}; +-- It is an error to inherit from or redefine Int. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; +}; + +class A inherits Int { + is_prime(): Bool { false }; +}; diff --git a/tests/semantic/basics2_error.txt b/tests/semantic/basics2_error.txt index 69a3b6814..e2810833a 100644 --- a/tests/semantic/basics2_error.txt +++ b/tests/semantic/basics2_error.txt @@ -1 +1 @@ -(7, 18) - SemanticError: Class A cannot inherit class Int. +(7, 18) - SemanticError: Class A cannot inherit class Int. diff --git a/tests/semantic/basics3.cl b/tests/semantic/basics3.cl index fef017a8d..8c28b31e1 100644 --- a/tests/semantic/basics3.cl +++ b/tests/semantic/basics3.cl @@ -1,9 +1,9 @@ --- It is an error to inherit from or redefine Int. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; -}; - -class Int { - is_prime(): Bool { false }; +-- It is an error to inherit from or redefine Int. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; +}; + +class Int { + is_prime(): Bool { false }; }; \ No newline at end of file diff --git a/tests/semantic/basics3_error.txt b/tests/semantic/basics3_error.txt index d8f80cb12..ed382c8eb 100644 --- a/tests/semantic/basics3_error.txt +++ b/tests/semantic/basics3_error.txt @@ -1 +1 @@ -(7, 7) - SemanticError: Redefinition of basic class Int. +(7, 7) - SemanticError: Redefinition of basic class Int. diff --git a/tests/semantic/basics4.cl b/tests/semantic/basics4.cl index 9266ec79b..4475bc08f 100644 --- a/tests/semantic/basics4.cl +++ b/tests/semantic/basics4.cl @@ -1,9 +1,9 @@ --- It is an error to inherit from or redefine String. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; -}; - -class A inherits String { - is_palindrome(): Bool { false }; +-- It is an error to inherit from or redefine String. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; +}; + +class A inherits String { + is_palindrome(): Bool { false }; }; \ No newline at end of file diff --git a/tests/semantic/basics4_error.txt b/tests/semantic/basics4_error.txt index d5cd4c3db..bfe08a9a6 100644 --- a/tests/semantic/basics4_error.txt +++ b/tests/semantic/basics4_error.txt @@ -1 +1 @@ -(7, 18) - SemanticError: Class A cannot inherit class String. +(7, 18) - SemanticError: Class A cannot inherit class String. diff --git a/tests/semantic/basics5.cl b/tests/semantic/basics5.cl index bad5eff13..f0d4dafb3 100644 --- a/tests/semantic/basics5.cl +++ b/tests/semantic/basics5.cl @@ -1,9 +1,9 @@ --- It is an error to inherit from or redefine String. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; -}; - -class String { - is_palindrome(): Bool { false }; +-- It is an error to inherit from or redefine String. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; +}; + +class String { + is_palindrome(): Bool { false }; }; \ No newline at end of file diff --git a/tests/semantic/basics5_error.txt b/tests/semantic/basics5_error.txt index 8437accf7..47b247faa 100644 --- a/tests/semantic/basics5_error.txt +++ b/tests/semantic/basics5_error.txt @@ -1 +1 @@ -(7, 7) - SemanticError: Redefinition of basic class String. +(7, 7) - SemanticError: Redefinition of basic class String. diff --git a/tests/semantic/basics6.cl b/tests/semantic/basics6.cl index 47266ebed..c16572a31 100644 --- a/tests/semantic/basics6.cl +++ b/tests/semantic/basics6.cl @@ -1,9 +1,9 @@ --- It is an error to inherit from or redefine Bool. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; -}; - -class A inherits Bool { - xor(b: Bool): Bool { false }; +-- It is an error to inherit from or redefine Bool. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; +}; + +class A inherits Bool { + xor(b: Bool): Bool { false }; }; \ No newline at end of file diff --git a/tests/semantic/basics6_error.txt b/tests/semantic/basics6_error.txt index b4d22da13..9adf1d488 100644 --- a/tests/semantic/basics6_error.txt +++ b/tests/semantic/basics6_error.txt @@ -1 +1 @@ -(7, 18) - SemanticError: Class A cannot inherit class Bool. +(7, 18) - SemanticError: Class A cannot inherit class Bool. diff --git a/tests/semantic/basics7.cl b/tests/semantic/basics7.cl index 0f30aaec3..38f789245 100644 --- a/tests/semantic/basics7.cl +++ b/tests/semantic/basics7.cl @@ -1,9 +1,9 @@ --- It is an error to inherit from or redefine Bool. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; -}; - -class Bool { - xor(b: Bool): Bool { false }; +-- It is an error to inherit from or redefine Bool. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; +}; + +class Bool { + xor(b: Bool): Bool { false }; }; \ No newline at end of file diff --git a/tests/semantic/basics7_error.txt b/tests/semantic/basics7_error.txt index 92660ab9f..9f1347200 100644 --- a/tests/semantic/basics7_error.txt +++ b/tests/semantic/basics7_error.txt @@ -1 +1 @@ -(7, 7) - SemanticError: Redefinition of basic class Bool. +(7, 7) - SemanticError: Redefinition of basic class Bool. diff --git a/tests/semantic/basics8.cl b/tests/semantic/basics8.cl index 3b9697d4f..d45cd941d 100644 --- a/tests/semantic/basics8.cl +++ b/tests/semantic/basics8.cl @@ -1,9 +1,9 @@ --- It is an error redefine Object. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; -}; - -class Object { - xor(b: Bool): Bool { false }; +-- It is an error redefine Object. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; +}; + +class Object { + xor(b: Bool): Bool { false }; }; \ No newline at end of file diff --git a/tests/semantic/basics8_error.txt b/tests/semantic/basics8_error.txt index 652f47b30..45767c9c5 100644 --- a/tests/semantic/basics8_error.txt +++ b/tests/semantic/basics8_error.txt @@ -1 +1 @@ -(7, 7) - SemanticError: Redefinition of basic class Object. +(7, 7) - SemanticError: Redefinition of basic class Object. diff --git a/tests/semantic/blocks1.cl b/tests/semantic/blocks1.cl index 1e928908b..bad9093d7 100644 --- a/tests/semantic/blocks1.cl +++ b/tests/semantic/blocks1.cl @@ -1,31 +1,31 @@ ---The static type of a block is the static type of the last expression. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test: B <- { - new A; - { - new B; - { - new C; - { - new D; - { - new E; - { - new F; - }; - }; - }; - }; - }; - }; +--The static type of a block is the static type of the last expression. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test: B <- { + new A; + { + new B; + { + new C; + { + new D; + { + new E; + { + new F; + }; + }; + }; + }; + }; + }; }; \ No newline at end of file diff --git a/tests/semantic/blocks1_error.txt b/tests/semantic/blocks1_error.txt index 2f0e2caf3..6bd9d6118 100644 --- a/tests/semantic/blocks1_error.txt +++ b/tests/semantic/blocks1_error.txt @@ -1 +1 @@ -(13, 16) - TypeError: Inferred type F of initialization of attribute test does not conform to declared type B. +(13, 16) - TypeError: Inferred type F of initialization of attribute test does not conform to declared type B. diff --git a/tests/semantic/case1.cl b/tests/semantic/case1.cl index 82c6a4d61..af452f11c 100644 --- a/tests/semantic/case1.cl +++ b/tests/semantic/case1.cl @@ -1,23 +1,23 @@ ---For each branch, let Ti be the static type of . The static type of a case expression is Join 1≤i≤n Ti. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - b: B <- case "true" of - i: Int => New C; - b: Bool => New D; - s: String => New E; - esac; - - test: B <- case 0 of - b: Bool => new F; - i: Int => new E; - esac; -}; +--For each branch, let Ti be the static type of . The static type of a case expression is Join 1≤i≤n Ti. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + b: B <- case "true" of + i: Int => New C; + b: Bool => New D; + s: String => New E; + esac; + + test: B <- case 0 of + b: Bool => new F; + i: Int => new E; + esac; +}; diff --git a/tests/semantic/case1_error.txt b/tests/semantic/case1_error.txt index f05ce31b9..70c7d16ca 100644 --- a/tests/semantic/case1_error.txt +++ b/tests/semantic/case1_error.txt @@ -1 +1 @@ -(19, 16) - TypeError: Inferred type A of initialization of attribute test does not conform to declared type B. +(19, 16) - TypeError: Inferred type A of initialization of attribute test does not conform to declared type B. diff --git a/tests/semantic/case2.cl b/tests/semantic/case2.cl index ae97b41da..dbbe4148c 100644 --- a/tests/semantic/case2.cl +++ b/tests/semantic/case2.cl @@ -1,23 +1,23 @@ --- The variables declared on each branch of a case must all have distinct types. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - b: B <- case "true" of - i: Int => New C; - b: Bool => New D; - s: String => New E; - esac; - - test: A <- case 0 of - b: Bool => new F; - i: Bool => new E; - esac; +-- The variables declared on each branch of a case must all have distinct types. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + b: B <- case "true" of + i: Int => New C; + b: Bool => New D; + s: String => New E; + esac; + + test: A <- case 0 of + b: Bool => new F; + i: Bool => new E; + esac; }; \ No newline at end of file diff --git a/tests/semantic/case3.cl b/tests/semantic/case3.cl index da79bbfe6..9ff06336a 100644 --- a/tests/semantic/case3.cl +++ b/tests/semantic/case3.cl @@ -1,23 +1,23 @@ --- Missing type - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - b: B <- case "true" of - i: Int => New C; - b: Bool => New D; - s: String => New E; - esac; - - test: A <- case 0 of - b: Bool => new F; - i: Ball => new E; - esac; +-- Missing type + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + b: B <- case "true" of + i: Int => New C; + b: Bool => New D; + s: String => New E; + esac; + + test: A <- case 0 of + b: Bool => new F; + i: Ball => new E; + esac; }; \ No newline at end of file diff --git a/tests/semantic/class1.cl b/tests/semantic/class1.cl index ed83da9d1..576a3d0eb 100644 --- a/tests/semantic/class1.cl +++ b/tests/semantic/class1.cl @@ -1,9 +1,9 @@ --- Classes may not be redefined. - -class Repeat { - sum(a: Int, b: Int): Int { a + b }; -}; - -class Repeat { - mult(a: Int, b: Int): Int { a * b }; +-- Classes may not be redefined. + +class Repeat { + sum(a: Int, b: Int): Int { a + b }; +}; + +class Repeat { + mult(a: Int, b: Int): Int { a * b }; }; \ No newline at end of file diff --git a/tests/semantic/class1_error.txt b/tests/semantic/class1_error.txt index 19c507672..6337828d0 100644 --- a/tests/semantic/class1_error.txt +++ b/tests/semantic/class1_error.txt @@ -1,2 +1,2 @@ -(7, 5) - SemanticError: Classes may not be redefined - +(7, 5) - SemanticError: Classes may not be redefined + diff --git a/tests/semantic/conditionals1.cl b/tests/semantic/conditionals1.cl index 3446a8b0f..46af8cc73 100644 --- a/tests/semantic/conditionals1.cl +++ b/tests/semantic/conditionals1.cl @@ -1,14 +1,14 @@ ---The predicate must have static type Bool. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - a: A <- if new F then new D else new C fi; +--The predicate must have static type Bool. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + a: A <- if new F then new D else new C fi; }; \ No newline at end of file diff --git a/tests/semantic/conditionals1_error.txt b/tests/semantic/conditionals1_error.txt index b86345359..52db300b9 100644 --- a/tests/semantic/conditionals1_error.txt +++ b/tests/semantic/conditionals1_error.txt @@ -1 +1 @@ -(13, 16) - TypeError: Predicate of 'if' does not have type Bool. +(13, 16) - TypeError: Predicate of 'if' does not have type Bool. diff --git a/tests/semantic/conditionals2.cl b/tests/semantic/conditionals2.cl index 9d6313d75..8814177fc 100644 --- a/tests/semantic/conditionals2.cl +++ b/tests/semantic/conditionals2.cl @@ -1,24 +1,24 @@ -(* -Let T and F be the static types of the branches of the conditional. Then the static type of the -conditional is T t F. (think: Walk towards Object from each of T and F until the paths meet.) -*) - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - b: B <- if true then - new C - else - if false then new D - else new E fi - fi; - - test: B <- if not true then new F else new E fi; -}; +(* +Let T and F be the static types of the branches of the conditional. Then the static type of the +conditional is T t F. (think: Walk towards Object from each of T and F until the paths meet.) +*) + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + b: B <- if true then + new C + else + if false then new D + else new E fi + fi; + + test: B <- if not true then new F else new E fi; +}; diff --git a/tests/semantic/conditionals2_error.txt b/tests/semantic/conditionals2_error.txt index d6f5fc307..8f54d195e 100644 --- a/tests/semantic/conditionals2_error.txt +++ b/tests/semantic/conditionals2_error.txt @@ -1,2 +1,2 @@ -(23, 16) - TypeError: Inferred type A of initialization of attribute test does not conform to declared type B. - +(23, 16) - TypeError: Inferred type A of initialization of attribute test does not conform to declared type B. + diff --git a/tests/semantic/dispatch1.cl b/tests/semantic/dispatch1.cl index 1c0457fa3..bfd90f075 100644 --- a/tests/semantic/dispatch1.cl +++ b/tests/semantic/dispatch1.cl @@ -1,33 +1,33 @@ -(* -e0 .f(e1, . . . , en ) -Assume e0 has static type A. -Class A must have a method f -*) - -class A inherits IO { - f(x: Int, y: Int): Int { x + y }; - g(x: Int): Int { x + x }; -}; -class B inherits A { - f(a: Int, b: Int): Int { a - b }; -}; -class C inherits B { - ident(m: Int): Int { m }; - f(m: Int, n: Int): Int { m * n }; -}; -class D inherits B { - ident(v: String): IO { new IO.out_string(v) }; - f(v: Int, w: Int): Int { v / w }; - g(v: Int): Int { v + v + v }; - - back(s: String): B { { - out_string(s); - self; - } }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test: B <- new D.back("Hello ").back("World!"); +(* +e0 .f(e1, . . . , en ) +Assume e0 has static type A. +Class A must have a method f +*) + +class A inherits IO { + f(x: Int, y: Int): Int { x + y }; + g(x: Int): Int { x + x }; +}; +class B inherits A { + f(a: Int, b: Int): Int { a - b }; +}; +class C inherits B { + ident(m: Int): Int { m }; + f(m: Int, n: Int): Int { m * n }; +}; +class D inherits B { + ident(v: String): IO { new IO.out_string(v) }; + f(v: Int, w: Int): Int { v / w }; + g(v: Int): Int { v + v + v }; + + back(s: String): B { { + out_string(s); + self; + } }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test: B <- new D.back("Hello ").back("World!"); }; \ No newline at end of file diff --git a/tests/semantic/dispatch1_error.txt b/tests/semantic/dispatch1_error.txt index 7fb22edce..89fa22b77 100644 --- a/tests/semantic/dispatch1_error.txt +++ b/tests/semantic/dispatch1_error.txt @@ -1 +1 @@ -(32, 37) - AttributeError: Dispatch to undefined method back. +(32, 37) - AttributeError: Dispatch to undefined method back. diff --git a/tests/semantic/dispatch2.cl b/tests/semantic/dispatch2.cl index 5182912b8..ebca718ac 100644 --- a/tests/semantic/dispatch2.cl +++ b/tests/semantic/dispatch2.cl @@ -1,34 +1,34 @@ -(* -e0 .f(e1, . . . , en ) -Assume e0 has static type A. -Class A must have a method f -the dispatch and the definition of f must have the same number of arguments -*) - -class A inherits IO { - f(x: Int, y: Int): Int { x + y }; - g(x: Int): Int { x + x }; -}; -class B inherits A { - f(a: Int, b: Int): Int { a - b }; -}; -class C inherits B { - ident(m: Int): Int { m }; - f(m: Int, n: Int): Int { m * n }; -}; -class D inherits B { - ident(v: String): IO { new IO.out_string(v) }; - f(v: Int, w: Int): Int { v / w }; - g(v: Int): Int { v + v + v }; - - back(s: String): B { { - out_string(s); - self; - } }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test: Int <- new D.back("Hello ").g(2, 2); +(* +e0 .f(e1, . . . , en ) +Assume e0 has static type A. +Class A must have a method f +the dispatch and the definition of f must have the same number of arguments +*) + +class A inherits IO { + f(x: Int, y: Int): Int { x + y }; + g(x: Int): Int { x + x }; +}; +class B inherits A { + f(a: Int, b: Int): Int { a - b }; +}; +class C inherits B { + ident(m: Int): Int { m }; + f(m: Int, n: Int): Int { m * n }; +}; +class D inherits B { + ident(v: String): IO { new IO.out_string(v) }; + f(v: Int, w: Int): Int { v / w }; + g(v: Int): Int { v + v + v }; + + back(s: String): B { { + out_string(s); + self; + } }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test: Int <- new D.back("Hello ").g(2, 2); }; \ No newline at end of file diff --git a/tests/semantic/dispatch2_error.txt b/tests/semantic/dispatch2_error.txt index a86c35340..1530fb82c 100644 --- a/tests/semantic/dispatch2_error.txt +++ b/tests/semantic/dispatch2_error.txt @@ -1 +1 @@ -(33, 39) - SemanticError: Method g called with wrong number of arguments. +(33, 39) - SemanticError: Method g called with wrong number of arguments. diff --git a/tests/semantic/dispatch3.cl b/tests/semantic/dispatch3.cl index ecb1535db..98c19da77 100644 --- a/tests/semantic/dispatch3.cl +++ b/tests/semantic/dispatch3.cl @@ -1,36 +1,36 @@ -(* -e0 .f(e1, . . . , en ) -Assume e0 has static type A. -Class A must have a method f -the static type of the ith actual parameter must conform to the declared type of the ith formal parameter. -*) - -class A inherits IO { - f(x: Int, y: Int): Int { x + y }; - g(x: Int): Int { x + x }; -}; -class B inherits A { - f(a: Int, b: Int): Int { a - b }; -}; -class C inherits B { - ident(m: Int): Int { m }; - f(m: Int, n: Int): Int { m * n }; -}; -class D inherits B { - ident(v: String): IO { new IO.out_string(v) }; - f(v: Int, w: Int): Int { v / w }; - g(v: Int): Int { v + v + v }; - - back(s: String): B { { - out_string(s); - self; - } }; - - alphabet(a: A, b: B, c: C): D { self }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test: B <- new D.alphabet(new D, new D, new D.back("Hello ")).back("World!"); +(* +e0 .f(e1, . . . , en ) +Assume e0 has static type A. +Class A must have a method f +the static type of the ith actual parameter must conform to the declared type of the ith formal parameter. +*) + +class A inherits IO { + f(x: Int, y: Int): Int { x + y }; + g(x: Int): Int { x + x }; +}; +class B inherits A { + f(a: Int, b: Int): Int { a - b }; +}; +class C inherits B { + ident(m: Int): Int { m }; + f(m: Int, n: Int): Int { m * n }; +}; +class D inherits B { + ident(v: String): IO { new IO.out_string(v) }; + f(v: Int, w: Int): Int { v / w }; + g(v: Int): Int { v + v + v }; + + back(s: String): B { { + out_string(s); + self; + } }; + + alphabet(a: A, b: B, c: C): D { self }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test: B <- new D.alphabet(new D, new D, new D.back("Hello ")).back("World!"); }; \ No newline at end of file diff --git a/tests/semantic/dispatch3_error.txt b/tests/semantic/dispatch3_error.txt index 0def5cf03..77e81db72 100644 --- a/tests/semantic/dispatch3_error.txt +++ b/tests/semantic/dispatch3_error.txt @@ -1 +1 @@ -(35, 45) - TypeError: In call of method alphabet, type B of parameter c does not conform to declared type C. +(35, 45) - TypeError: In call of method alphabet, type B of parameter c does not conform to declared type C. diff --git a/tests/semantic/dispatch4.cl b/tests/semantic/dispatch4.cl index 9cadd8332..604e462a2 100644 --- a/tests/semantic/dispatch4.cl +++ b/tests/semantic/dispatch4.cl @@ -1,36 +1,36 @@ -(* -e0 .f(e1, . . . , en ) -Assume e0 has static type A. -Class A must have a method f -If f has return type B and B is a class name, then the static type of the dispatch is B. -*) - -class A inherits IO { - f(x: Int, y: Int): Int { x + y }; - g(x: Int): Int { x + x }; -}; -class B inherits A { - f(a: Int, b: Int): Int { a - b }; -}; -class C inherits B { - ident(m: Int): Int { m }; - f(m: Int, n: Int): Int { m * n }; -}; -class D inherits B { - ident(v: String): IO { new IO.out_string(v) }; - f(v: Int, w: Int): Int { v / w }; - g(v: Int): Int { v + v + v }; - - back(s: String): B { { - out_string(s); - self; - } }; - - alphabet(a: A, b: B, c: C): D { self }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test: D <- new D.alphabet(new D, new D.back("Hello "), new C).back("World!"); +(* +e0 .f(e1, . . . , en ) +Assume e0 has static type A. +Class A must have a method f +If f has return type B and B is a class name, then the static type of the dispatch is B. +*) + +class A inherits IO { + f(x: Int, y: Int): Int { x + y }; + g(x: Int): Int { x + x }; +}; +class B inherits A { + f(a: Int, b: Int): Int { a - b }; +}; +class C inherits B { + ident(m: Int): Int { m }; + f(m: Int, n: Int): Int { m * n }; +}; +class D inherits B { + ident(v: String): IO { new IO.out_string(v) }; + f(v: Int, w: Int): Int { v / w }; + g(v: Int): Int { v + v + v }; + + back(s: String): B { { + out_string(s); + self; + } }; + + alphabet(a: A, b: B, c: C): D { self }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test: D <- new D.alphabet(new D, new D.back("Hello "), new C).back("World!"); }; \ No newline at end of file diff --git a/tests/semantic/dispatch5.cl b/tests/semantic/dispatch5.cl index b4437b1b4..9820e5ee1 100644 --- a/tests/semantic/dispatch5.cl +++ b/tests/semantic/dispatch5.cl @@ -1,31 +1,31 @@ -(* -(,...,) is shorthand for self.(,...,). -*) - -class A inherits IO { - f(x: Int, y: Int): Int { x + y }; - g(x: Int): Int { x + x }; -}; -class B inherits A { - f(a: Int, b: Int): Int { a - b }; -}; -class C inherits B { - ident(m: Int): Int { m }; - f(m: Int, n: Int): Int { m * n }; - sum(m: Int, n: Int, p: Int): Int { m + n + p }; -}; -class D inherits B { - ident(v: String): IO { new IO.out_string(v) }; - f(v: Int, w: Int): Int { v / w }; - - back(s: String): B { { - out_string(s); - g(2); - sum(1, 2, 3); - self; - } }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; +(* +(,...,) is shorthand for self.(,...,). +*) + +class A inherits IO { + f(x: Int, y: Int): Int { x + y }; + g(x: Int): Int { x + x }; +}; +class B inherits A { + f(a: Int, b: Int): Int { a - b }; +}; +class C inherits B { + ident(m: Int): Int { m }; + f(m: Int, n: Int): Int { m * n }; + sum(m: Int, n: Int, p: Int): Int { m + n + p }; +}; +class D inherits B { + ident(v: String): IO { new IO.out_string(v) }; + f(v: Int, w: Int): Int { v / w }; + + back(s: String): B { { + out_string(s); + g(2); + sum(1, 2, 3); + self; + } }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; }; \ No newline at end of file diff --git a/tests/semantic/dispatch5_error.txt b/tests/semantic/dispatch5_error.txt index d26bf34a1..6a6922f32 100644 --- a/tests/semantic/dispatch5_error.txt +++ b/tests/semantic/dispatch5_error.txt @@ -1 +1 @@ -(24, 9) - AttributeError: Dispatch to undefined method sum. +(24, 9) - AttributeError: Dispatch to undefined method sum. diff --git a/tests/semantic/dispatch6.cl b/tests/semantic/dispatch6.cl index fcc033f2c..bbe58fbb1 100644 --- a/tests/semantic/dispatch6.cl +++ b/tests/semantic/dispatch6.cl @@ -1,32 +1,32 @@ -(* -e@B.f() invokes the method -f in class B on the object that is the value of e. For this form of dispatch, the static type to the left of -“@”must conform to the type specified to the right of “@”. -*) - -class A { - f(x: Int, y: Int): Int { x + y }; - g(x: Int): Int { x + x }; -}; -class B inherits A { - f(a: Int, b: Int): Int { a - b }; - sum(m: Int, n: Int, p: Int): Int { m + n + p }; -}; -class C inherits B { - ident(m: Int): Int { m }; - f(m: Int, n: Int): Int { m * n }; -}; -class D inherits B { - ident(v: String): IO { new IO.out_string(v) }; - f(v: Int, w: Int): Int { v / w }; - g(v: Int): Int { v + v + v }; - sum(v: Int, w: Int, z: Int): Int { v - w - z }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - a: A <- new D; - b: Int <- new D@B.sum(1, 2, 3); - test: Int <- a@B.sum(1, 2, 3); -}; +(* +e@B.f() invokes the method +f in class B on the object that is the value of e. For this form of dispatch, the static type to the left of +“@”must conform to the type specified to the right of “@”. +*) + +class A { + f(x: Int, y: Int): Int { x + y }; + g(x: Int): Int { x + x }; +}; +class B inherits A { + f(a: Int, b: Int): Int { a - b }; + sum(m: Int, n: Int, p: Int): Int { m + n + p }; +}; +class C inherits B { + ident(m: Int): Int { m }; + f(m: Int, n: Int): Int { m * n }; +}; +class D inherits B { + ident(v: String): IO { new IO.out_string(v) }; + f(v: Int, w: Int): Int { v / w }; + g(v: Int): Int { v + v + v }; + sum(v: Int, w: Int, z: Int): Int { v - w - z }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + a: A <- new D; + b: Int <- new D@B.sum(1, 2, 3); + test: Int <- a@B.sum(1, 2, 3); +}; diff --git a/tests/semantic/dispatch6_error.txt b/tests/semantic/dispatch6_error.txt index ae9184b2f..7d5ec3780 100644 --- a/tests/semantic/dispatch6_error.txt +++ b/tests/semantic/dispatch6_error.txt @@ -1 +1 @@ -(31, 18) - TypeError: Expression type A does not conform to declared static dispatch type B. +(31, 18) - TypeError: Expression type A does not conform to declared static dispatch type B. diff --git a/tests/semantic/eq1.cl b/tests/semantic/eq1.cl index 88f2a7ffe..dc8a0cd43 100644 --- a/tests/semantic/eq1.cl +++ b/tests/semantic/eq1.cl @@ -1,17 +1,17 @@ -(* -The comparison = is a special -case. If either or has static type Int, Bool, or String, then the other must have the -same static type. Any other types, including SELF TYPE, may be freely compared. -*) - -class A { }; -class B inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - x: Bool <- 1 = 2; - test: Bool <- 1 = new A; - y: Bool <- "1" = "2"; - z: Bool <- true = not false; +(* +The comparison = is a special +case. If either or has static type Int, Bool, or String, then the other must have the +same static type. Any other types, including SELF TYPE, may be freely compared. +*) + +class A { }; +class B inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + x: Bool <- 1 = 2; + test: Bool <- 1 = new A; + y: Bool <- "1" = "2"; + z: Bool <- true = not false; }; \ No newline at end of file diff --git a/tests/semantic/eq1_error.txt b/tests/semantic/eq1_error.txt index f81425683..0b85d2fa0 100644 --- a/tests/semantic/eq1_error.txt +++ b/tests/semantic/eq1_error.txt @@ -1 +1 @@ -(14, 21) - TypeError: Illegal comparison with a basic type. +(14, 21) - TypeError: Illegal comparison with a basic type. diff --git a/tests/semantic/eq2.cl b/tests/semantic/eq2.cl index d76852780..f4b2ffac7 100644 --- a/tests/semantic/eq2.cl +++ b/tests/semantic/eq2.cl @@ -1,17 +1,17 @@ -(* -The comparison = is a special -case. If either or has static type Int, Bool, or String, then the other must have the -same static type. Any other types, including SELF TYPE, may be freely compared. -*) - -class A { }; -class B inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - x: Bool <- 1 = 2; - y: Bool <- "1" = "2"; - test: Bool <- "1" = new B; - z: Bool <- true = not false; -}; +(* +The comparison = is a special +case. If either or has static type Int, Bool, or String, then the other must have the +same static type. Any other types, including SELF TYPE, may be freely compared. +*) + +class A { }; +class B inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + x: Bool <- 1 = 2; + y: Bool <- "1" = "2"; + test: Bool <- "1" = new B; + z: Bool <- true = not false; +}; diff --git a/tests/semantic/eq2_error.txt b/tests/semantic/eq2_error.txt index a44ab0d51..1bb29ca32 100644 --- a/tests/semantic/eq2_error.txt +++ b/tests/semantic/eq2_error.txt @@ -1 +1 @@ -(15, 23) - TypeError: Illegal comparison with a basic type. +(15, 23) - TypeError: Illegal comparison with a basic type. diff --git a/tests/semantic/eq3.cl b/tests/semantic/eq3.cl index 4dad693ee..b7ee462c5 100644 --- a/tests/semantic/eq3.cl +++ b/tests/semantic/eq3.cl @@ -1,17 +1,17 @@ -(* -The comparison = is a special -case. If either or has static type Int, Bool, or String, then the other must have the -same static type. Any other types, including SELF TYPE, may be freely compared. -*) - -class A { }; -class B inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - x: Bool <- 1 = 2; - y: Bool <- "1" = "2"; - z: Bool <- true = not false; - test: Bool <- "true" = not false; -}; +(* +The comparison = is a special +case. If either or has static type Int, Bool, or String, then the other must have the +same static type. Any other types, including SELF TYPE, may be freely compared. +*) + +class A { }; +class B inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + x: Bool <- 1 = 2; + y: Bool <- "1" = "2"; + z: Bool <- true = not false; + test: Bool <- "true" = not false; +}; diff --git a/tests/semantic/eq3_error.txt b/tests/semantic/eq3_error.txt index c4e27eb8a..d57841b95 100644 --- a/tests/semantic/eq3_error.txt +++ b/tests/semantic/eq3_error.txt @@ -1 +1 @@ -(16, 26) - TypeError: Illegal comparison with a basic type. +(16, 26) - TypeError: Illegal comparison with a basic type. diff --git a/tests/semantic/eq4.cl b/tests/semantic/eq4.cl index 11afc119f..63c1067f0 100644 --- a/tests/semantic/eq4.cl +++ b/tests/semantic/eq4.cl @@ -1,17 +1,17 @@ -(* -The comparison = is a special -case. If either or has static type Int, Bool, or String, then the other must have the -same static type. Any other types, including SELF TYPE, may be freely compared. The result is a Bool. -*) - -class A { }; -class B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - x: Bool <- 1 = 2; - y: Bool <- "1" = "2"; - z: Bool <- new A = new B; - test: Int <- new A = new B; -}; +(* +The comparison = is a special +case. If either or has static type Int, Bool, or String, then the other must have the +same static type. Any other types, including SELF TYPE, may be freely compared. The result is a Bool. +*) + +class A { }; +class B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + x: Bool <- 1 = 2; + y: Bool <- "1" = "2"; + z: Bool <- new A = new B; + test: Int <- new A = new B; +}; diff --git a/tests/semantic/eq4_error.txt b/tests/semantic/eq4_error.txt index 3ead21d0e..f075fecbe 100644 --- a/tests/semantic/eq4_error.txt +++ b/tests/semantic/eq4_error.txt @@ -1 +1 @@ -(16, 18) - TypeError: Inferred type Bool of initialization of attribute test does not conform to declared type Int. +(16, 18) - TypeError: Inferred type Bool of initialization of attribute test does not conform to declared type Int. diff --git a/tests/semantic/isvoid1.cl b/tests/semantic/isvoid1.cl index 072720d85..7c3a83a77 100644 --- a/tests/semantic/isvoid1.cl +++ b/tests/semantic/isvoid1.cl @@ -1,26 +1,26 @@ ---evaluates to true if expr is void and evaluates to false if expr is not void. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - b: B <- if isvoid new F then - new C - else - if false then new D - else new E fi - fi; - - test: B <- isvoid if isvoid new F then - new C - else - if false then new D - else new E fi - fi; +--evaluates to true if expr is void and evaluates to false if expr is not void. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + b: B <- if isvoid new F then + new C + else + if false then new D + else new E fi + fi; + + test: B <- isvoid if isvoid new F then + new C + else + if false then new D + else new E fi + fi; }; \ No newline at end of file diff --git a/tests/semantic/isvoid1_error.txt b/tests/semantic/isvoid1_error.txt index 0922de909..3fd0157b4 100644 --- a/tests/semantic/isvoid1_error.txt +++ b/tests/semantic/isvoid1_error.txt @@ -1 +1 @@ -(20, 16) - TypeError: Inferred type Bool of initialization of attribute test does not conform to declared type B. +(20, 16) - TypeError: Inferred type Bool of initialization of attribute test does not conform to declared type B. diff --git a/tests/semantic/let1.cl b/tests/semantic/let1.cl index 26ef63026..9220d3dbc 100644 --- a/tests/semantic/let1.cl +++ b/tests/semantic/let1.cl @@ -1,15 +1,15 @@ ---The type of an initialization expression must conform to the declared type of the identifier. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - b: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: B <- new E in b; - test: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: C <- new E in b; +--The type of an initialization expression must conform to the declared type of the identifier. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + b: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: B <- new E in b; + test: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: C <- new E in b; }; \ No newline at end of file diff --git a/tests/semantic/let1_error.txt b/tests/semantic/let1_error.txt index 16ecf780c..56547dae5 100644 --- a/tests/semantic/let1_error.txt +++ b/tests/semantic/let1_error.txt @@ -1 +1 @@ -(14, 76) - TypeError: Inferred type E of initialization of b does not conform to identifier's declared type C. +(14, 76) - TypeError: Inferred type E of initialization of b does not conform to identifier's declared type C. diff --git a/tests/semantic/let2.cl b/tests/semantic/let2.cl index c5956ead3..2949fb94d 100644 --- a/tests/semantic/let2.cl +++ b/tests/semantic/let2.cl @@ -1,15 +1,15 @@ ---The type of let is the type of the body. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - b: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: B <- new E in b; - test: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: A <- new E in b; +--The type of let is the type of the body. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + b: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: B <- new E in b; + test: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: A <- new E in b; }; \ No newline at end of file diff --git a/tests/semantic/let2_error.txt b/tests/semantic/let2_error.txt index b1e8a365d..3b7c669a3 100644 --- a/tests/semantic/let2_error.txt +++ b/tests/semantic/let2_error.txt @@ -1 +1 @@ -(14, 16) - TypeError: Inferred type A of initialization of attribute test does not conform to declared type B. +(14, 16) - TypeError: Inferred type A of initialization of attribute test does not conform to declared type B. diff --git a/tests/semantic/let3.cl b/tests/semantic/let3.cl index 8c0670ab8..0a4a9ceaf 100644 --- a/tests/semantic/let3.cl +++ b/tests/semantic/let3.cl @@ -1,15 +1,15 @@ --- Missing type - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - b: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: B <- new E in b; - test: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: Cadena in new B; +-- Missing type + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + b: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: B <- new E in b; + test: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: Cadena in new B; }; \ No newline at end of file diff --git a/tests/semantic/loops1.cl b/tests/semantic/loops1.cl index de3a624d2..6a0a81818 100644 --- a/tests/semantic/loops1.cl +++ b/tests/semantic/loops1.cl @@ -1,8 +1,8 @@ ---The predicate must have static type Bool. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - i: Int <- 1; - test: Object <- while "true" loop i <- i + 1 pool; +--The predicate must have static type Bool. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + i: Int <- 1; + test: Object <- while "true" loop i <- i + 1 pool; }; \ No newline at end of file diff --git a/tests/semantic/loops2.cl b/tests/semantic/loops2.cl index dea69fa14..d52169da7 100644 --- a/tests/semantic/loops2.cl +++ b/tests/semantic/loops2.cl @@ -1,9 +1,9 @@ ---The static type of a loop expression is Object. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - i: Int <- 1; - test: Object <- while not false loop i <- i + 1 pool; - test2: Int <- while not false loop i <- i + 1 pool; -}; +--The static type of a loop expression is Object. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + i: Int <- 1; + test: Object <- while not false loop i <- i + 1 pool; + test2: Int <- while not false loop i <- i + 1 pool; +}; diff --git a/tests/semantic/loops2_error.txt b/tests/semantic/loops2_error.txt index 9711cdf6a..ab79de8da 100644 --- a/tests/semantic/loops2_error.txt +++ b/tests/semantic/loops2_error.txt @@ -1 +1 @@ -(8, 19) - TypeError: Inferred type Object of initialization of attribute test2 does not conform to declared type Int. +(8, 19) - TypeError: Inferred type Object of initialization of attribute test2 does not conform to declared type Int. diff --git a/tests/semantic/methods1.cl b/tests/semantic/methods1.cl index d12031970..f4ff07bb0 100644 --- a/tests/semantic/methods1.cl +++ b/tests/semantic/methods1.cl @@ -1,12 +1,12 @@ ---The identifiers used in the formal parameter list must be distinct - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test(a: A, a: B): Int { 4 }; +--The identifiers used in the formal parameter list must be distinct + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test(a: A, a: B): Int { 4 }; }; \ No newline at end of file diff --git a/tests/semantic/methods1_error.txt b/tests/semantic/methods1_error.txt index 06ab88a92..809036803 100644 --- a/tests/semantic/methods1_error.txt +++ b/tests/semantic/methods1_error.txt @@ -1 +1 @@ -(11, 16) - SemanticError: Formal parameter a is multiply defined. +(11, 16) - SemanticError: Formal parameter a is multiply defined. diff --git a/tests/semantic/methods2.cl b/tests/semantic/methods2.cl index 3865f0e13..c010df01e 100644 --- a/tests/semantic/methods2.cl +++ b/tests/semantic/methods2.cl @@ -1,12 +1,12 @@ ---The type of the method body must conform to the declared return type. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test(a: A, b: B): C { new D }; +--The type of the method body must conform to the declared return type. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test(a: A, b: B): C { new D }; }; \ No newline at end of file diff --git a/tests/semantic/methods2_error.txt b/tests/semantic/methods2_error.txt index f7e4a330d..1a4baea17 100644 --- a/tests/semantic/methods2_error.txt +++ b/tests/semantic/methods2_error.txt @@ -1 +1 @@ -(11, 27) - TypeError: Inferred return type D of method test does not conform to declared return type C. +(11, 27) - TypeError: Inferred return type D of method test does not conform to declared return type C. diff --git a/tests/semantic/methods3.cl b/tests/semantic/methods3.cl index b92faeb97..9aff4d167 100644 --- a/tests/semantic/methods3.cl +++ b/tests/semantic/methods3.cl @@ -1,14 +1,14 @@ ---A formal parameter hides any definition of an attribute of the same name. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - a: C <- new C; - test(a: D): D { a }; - test2(a: B): C { a }; +--A formal parameter hides any definition of an attribute of the same name. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + a: C <- new C; + test(a: D): D { a }; + test2(a: B): C { a }; }; \ No newline at end of file diff --git a/tests/semantic/methods3_error.txt b/tests/semantic/methods3_error.txt index 1165b7595..a0f6d9db2 100644 --- a/tests/semantic/methods3_error.txt +++ b/tests/semantic/methods3_error.txt @@ -1 +1 @@ -(13, 22) - TypeError: Inferred return type B of method test2 does not conform to declared return type C. +(13, 22) - TypeError: Inferred return type B of method test2 does not conform to declared return type C. diff --git a/tests/semantic/methods4.cl b/tests/semantic/methods4.cl index be8fa36ef..e093bac1c 100644 --- a/tests/semantic/methods4.cl +++ b/tests/semantic/methods4.cl @@ -1,19 +1,19 @@ -(* -The rule is -simple: If a class C inherits a method f from an ancestor class P, then C may override the inherited -definition of f provided the number of arguments, the types of the formal parameters, and the return -type are exactly the same in both definitions. -*) - -class A { - f(x: Int, y: Int): Int { x + y }; -}; -class B inherits A { - f(x: Int, y: Object): Int { x }; -}; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; +(* +The rule is +simple: If a class C inherits a method f from an ancestor class P, then C may override the inherited +definition of f provided the number of arguments, the types of the formal parameters, and the return +type are exactly the same in both definitions. +*) + +class A { + f(x: Int, y: Int): Int { x + y }; +}; +class B inherits A { + f(x: Int, y: Object): Int { x }; +}; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; }; \ No newline at end of file diff --git a/tests/semantic/methods4_error.txt b/tests/semantic/methods4_error.txt index 9f1486dec..c9fc2d12a 100644 --- a/tests/semantic/methods4_error.txt +++ b/tests/semantic/methods4_error.txt @@ -1 +1 @@ -(12, 15) - SemanticError: In redefined method f, parameter type Object is different from original type Int. +(12, 15) - SemanticError: In redefined method f, parameter type Object is different from original type Int. diff --git a/tests/semantic/methods5.cl b/tests/semantic/methods5.cl index 3905dfdd6..732e4d408 100644 --- a/tests/semantic/methods5.cl +++ b/tests/semantic/methods5.cl @@ -1,20 +1,20 @@ -(* -The rule is -simple: If a class C inherits a method f from an ancestor class P, then C may override the inherited -definition of f provided the number of arguments, the types of the formal parameters, and the return -type are exactly the same in both definitions. -*) - -class A { - f(x: Int, y: Int): Int { x + y }; -}; -class B inherits A { - f(a: Int, b: Int): Object { a - b }; -}; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; -}; - +(* +The rule is +simple: If a class C inherits a method f from an ancestor class P, then C may override the inherited +definition of f provided the number of arguments, the types of the formal parameters, and the return +type are exactly the same in both definitions. +*) + +class A { + f(x: Int, y: Int): Int { x + y }; +}; +class B inherits A { + f(a: Int, b: Int): Object { a - b }; +}; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; +}; + diff --git a/tests/semantic/methods5_error.txt b/tests/semantic/methods5_error.txt index 8b6bdf36e..073eee8c5 100644 --- a/tests/semantic/methods5_error.txt +++ b/tests/semantic/methods5_error.txt @@ -1 +1 @@ -(12, 24) - SemanticError: In redefined method f, return type Object is different from original return type Int. +(12, 24) - SemanticError: In redefined method f, return type Object is different from original return type Int. diff --git a/tests/semantic/methods6.cl b/tests/semantic/methods6.cl index dd2b73da6..61a62b4b0 100644 --- a/tests/semantic/methods6.cl +++ b/tests/semantic/methods6.cl @@ -1,27 +1,27 @@ -(* -The rule is -simple: If a class C inherits a method f from an ancestor class P, then C may override the inherited -definition of f provided the number of arguments, the types of the formal parameters, and the return -type are exactly the same in both definitions. -*) - -class A { - f(x: Int, y: Int): Int { x + y }; - g(x: Int): Int { x + x }; -}; -class B inherits A { - f(a: Int, b: Int): Int { a - b }; -}; -class C inherits B { - ident(m: Int): Int { m }; - f(m: Int, n: Int): Int { m * n }; -}; -class D inherits B { - ident(v: String): IO { new IO.out_string(v) }; - f(v: Int, w: Int): Int { v / w }; - g(v: Int, w: Int, z: Int): Int { v + w + z }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; +(* +The rule is +simple: If a class C inherits a method f from an ancestor class P, then C may override the inherited +definition of f provided the number of arguments, the types of the formal parameters, and the return +type are exactly the same in both definitions. +*) + +class A { + f(x: Int, y: Int): Int { x + y }; + g(x: Int): Int { x + x }; +}; +class B inherits A { + f(a: Int, b: Int): Int { a - b }; +}; +class C inherits B { + ident(m: Int): Int { m }; + f(m: Int, n: Int): Int { m * n }; +}; +class D inherits B { + ident(v: String): IO { new IO.out_string(v) }; + f(v: Int, w: Int): Int { v / w }; + g(v: Int, w: Int, z: Int): Int { v + w + z }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; }; \ No newline at end of file diff --git a/tests/semantic/methods6_error.txt b/tests/semantic/methods6_error.txt index 8e32663b9..70ad02e32 100644 --- a/tests/semantic/methods6_error.txt +++ b/tests/semantic/methods6_error.txt @@ -1 +1 @@ -(22, 5) - SemanticError: Incompatible number of formal parameters in redefined method g. +(22, 5) - SemanticError: Incompatible number of formal parameters in redefined method g. diff --git a/tests/semantic/methods7.cl b/tests/semantic/methods7.cl index e5a01f682..21e8ca275 100644 --- a/tests/semantic/methods7.cl +++ b/tests/semantic/methods7.cl @@ -1,12 +1,12 @@ --- Missing type - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test(a: A, b: Ball): Int { 4 }; +-- Missing type + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test(a: A, b: Ball): Int { 4 }; }; \ No newline at end of file diff --git a/tests/semantic/methods8.cl b/tests/semantic/methods8.cl index 3fccab54c..121210748 100644 --- a/tests/semantic/methods8.cl +++ b/tests/semantic/methods8.cl @@ -1,12 +1,12 @@ --- Missing type - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test(a: A, b: B): Integrer { 4 }; +-- Missing type + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test(a: A, b: B): Integrer { 4 }; }; \ No newline at end of file diff --git a/tests/semantic/new1.cl b/tests/semantic/new1.cl index d007fc03d..40a8b9e9b 100644 --- a/tests/semantic/new1.cl +++ b/tests/semantic/new1.cl @@ -1,31 +1,31 @@ --- Missing type - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test: F <- { - new A; - { - new Ball; - { - new C; - { - new D; - { - new E; - { - new F; - }; - }; - }; - }; - }; - }; +-- Missing type + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test: F <- { + new A; + { + new Ball; + { + new C; + { + new D; + { + new E; + { + new F; + }; + }; + }; + }; + }; + }; }; \ No newline at end of file diff --git a/tests/semantic/self1.cl b/tests/semantic/self1.cl index 3387fd263..399f6ff06 100644 --- a/tests/semantic/self1.cl +++ b/tests/semantic/self1.cl @@ -1,11 +1,11 @@ -(* -But it is an error to assign to self or to bind self in a let, a -case, or as a formal parameter. It is also illegal to have attributes named self. -*) - - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test(a: Main): IO { self <- a }; -}; +(* +But it is an error to assign to self or to bind self in a let, a +case, or as a formal parameter. It is also illegal to have attributes named self. +*) + + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test(a: Main): IO { self <- a }; +}; diff --git a/tests/semantic/self1_error.txt b/tests/semantic/self1_error.txt index 6beb3cda2..f9f51b9b3 100644 --- a/tests/semantic/self1_error.txt +++ b/tests/semantic/self1_error.txt @@ -1 +1 @@ -(10, 30) - SemanticError: Cannot assign to 'self'. +(10, 30) - SemanticError: Cannot assign to 'self'. diff --git a/tests/semantic/self2.cl b/tests/semantic/self2.cl index 2e6921a92..6ef75e368 100644 --- a/tests/semantic/self2.cl +++ b/tests/semantic/self2.cl @@ -1,10 +1,10 @@ -(* -But it is an error to assign to self or to bind self in a let, a -case, or as a formal parameter. It is also illegal to have attributes named self. -*) - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test(): IO { let self: Main <- new Main in self }; -}; +(* +But it is an error to assign to self or to bind self in a let, a +case, or as a formal parameter. It is also illegal to have attributes named self. +*) + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test(): IO { let self: Main <- new Main in self }; +}; diff --git a/tests/semantic/self2_error.txt b/tests/semantic/self2_error.txt index 20c883c91..2e53bb210 100644 --- a/tests/semantic/self2_error.txt +++ b/tests/semantic/self2_error.txt @@ -1 +1 @@ -(9, 22) - SemanticError: 'self' cannot be bound in a 'let' expression. +(9, 22) - SemanticError: 'self' cannot be bound in a 'let' expression. diff --git a/tests/semantic/self3.cl b/tests/semantic/self3.cl index 81709b4b5..d314798a9 100644 --- a/tests/semantic/self3.cl +++ b/tests/semantic/self3.cl @@ -1,10 +1,10 @@ -(* -But it is an error to assign to self or to bind self in a let, a -case, or as a formal parameter. It is also illegal to have attributes named self. -*) - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test(self: IO): IO { self }; -}; +(* +But it is an error to assign to self or to bind self in a let, a +case, or as a formal parameter. It is also illegal to have attributes named self. +*) + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test(self: IO): IO { self }; +}; diff --git a/tests/semantic/self3_error.txt b/tests/semantic/self3_error.txt index 0ae382007..0015bbe0a 100644 --- a/tests/semantic/self3_error.txt +++ b/tests/semantic/self3_error.txt @@ -1 +1 @@ -(9, 10) - SemanticError: 'self' cannot be the name of a formal parameter. +(9, 10) - SemanticError: 'self' cannot be the name of a formal parameter. diff --git a/tests/semantic/self4.cl b/tests/semantic/self4.cl index 7c2b960cb..9185c8760 100644 --- a/tests/semantic/self4.cl +++ b/tests/semantic/self4.cl @@ -1,10 +1,10 @@ -(* -But it is an error to assign to self or to bind self in a let, a -case, or as a formal parameter. It is also illegal to have attributes named self. -*) - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - self: IO <- self; +(* +But it is an error to assign to self or to bind self in a let, a +case, or as a formal parameter. It is also illegal to have attributes named self. +*) + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + self: IO <- self; }; \ No newline at end of file diff --git a/tests/semantic/self4_error.txt b/tests/semantic/self4_error.txt index c19ca400f..bf8740604 100644 --- a/tests/semantic/self4_error.txt +++ b/tests/semantic/self4_error.txt @@ -1 +1 @@ -(9, 5) - SemanticError: 'self' cannot be the name of an attribute. +(9, 5) - SemanticError: 'self' cannot be the name of an attribute. diff --git a/tests/semantic_test.py b/tests/semantic_test.py index cac9cd78b..46f07439d 100644 --- a/tests/semantic_test.py +++ b/tests/semantic_test.py @@ -1,14 +1,14 @@ -import pytest -import os -from utils import compare_errors, first_error_only_line - -tests_dir = __file__.rpartition('/')[0] + '/semantic/' -tests = [(file) for file in os.listdir(tests_dir) if file.endswith('.cl')] - -@pytest.mark.semantic -@pytest.mark.error -@pytest.mark.run(order=3) -@pytest.mark.parametrize("cool_file", tests) -def test_semantic_errors(compiler_path, cool_file): - compare_errors(compiler_path, tests_dir + cool_file, tests_dir + cool_file[:-3] + '_error.txt', \ +import pytest +import os +from utils import compare_errors, first_error_only_line + +tests_dir = __file__.rpartition('/')[0] + '/semantic/' +tests = [(file) for file in os.listdir(tests_dir) if file.endswith('.cl')] + +@pytest.mark.semantic +@pytest.mark.error +@pytest.mark.run(order=3) +@pytest.mark.parametrize("cool_file", tests) +def test_semantic_errors(compiler_path, cool_file): + compare_errors(compiler_path, tests_dir + cool_file, tests_dir + cool_file[:-3] + '_error.txt', \ cmp=first_error_only_line) \ No newline at end of file diff --git a/tests/utils/utils.py b/tests/utils/utils.py index 961cf7cbc..f98d19dd0 100644 --- a/tests/utils/utils.py +++ b/tests/utils/utils.py @@ -1,91 +1,91 @@ -import subprocess -import re - - -COMPILER_TIMEOUT = 'El compilador tarda mucho en responder.' -SPIM_TIMEOUT = 'El spim tarda mucho en responder.' -TEST_MUST_FAIL = 'El test %s debe fallar al compilar' -TEST_MUST_COMPILE = 'El test %s debe compilar' -BAD_ERROR_FORMAT = '''El error no esta en formato: (,) - : - o no se encuentra en la 3ra linea\n\n%s''' -UNEXPECTED_ERROR = 'Se esperaba un %s en (%d, %d). Su error fue un %s en (%d, %d)' -UNEXPECTED_OUTPUT = 'La salida de %s no es la esperada:\n%s\nEsperada:\n%s' - -ERROR_FORMAT = r'^\s*\(\s*(\d+)\s*,\s*(\d+)\s*\)\s*-\s*(\w+)\s*:(.*)$' - -def parse_error(error: str): - merror = re.fullmatch(ERROR_FORMAT, error) - assert merror, BAD_ERROR_FORMAT % error - - return (t(x) for t, x in zip([int, int, str, str], merror.groups())) - - -def first_error(compiler_output: list, errors: list): - line, column, error_type, _ = parse_error(errors[0]) - - oline, ocolumn, oerror_type, _ = parse_error(compiler_output[0]) - - assert line == oline and column == ocolumn and error_type == oerror_type,\ - UNEXPECTED_ERROR % (error_type, line, column, oerror_type, oline, ocolumn) - -def first_error_only_line(compiler_output: list, errors: list): - line, column, error_type, _ = parse_error(errors[0]) - - oline, ocolumn, oerror_type, _ = parse_error(compiler_output[0]) - - assert line == oline and error_type == oerror_type,\ - UNEXPECTED_ERROR % (error_type, line, column, oerror_type, oline, ocolumn) - - -def get_file_name(path: str): - try: - return path[path.rindex('/') + 1:] - except ValueError: - return path - -def compare_errors(compiler_path: str, cool_file_path: str, error_file_path: str, cmp=first_error, timeout=100): - try: - sp = subprocess.run(['bash', compiler_path, cool_file_path], capture_output=True, timeout=timeout) - return_code, output = sp.returncode, sp.stdout.decode() - except subprocess.TimeoutExpired: - assert False, COMPILER_TIMEOUT - - assert return_code == 1, TEST_MUST_FAIL % get_file_name(cool_file_path) - - fd = open(error_file_path, 'r') - errors = fd.read().split('\n') - fd.close() - - # checking the errors of compiler - compiler_output = output.split('\n') - cmp(compiler_output[2:], errors) - -SPIM_HEADER = r'''^SPIM Version .+ of .+ -Copyright .+\, James R\. Larus\. -All Rights Reserved\. -See the file README for a full copyright notice\. -(?:Loaded: .+\n)*''' -def compare_outputs(compiler_path: str, cool_file_path: str, input_file_path: str, output_file_path: str, timeout=100): - try: - sp = subprocess.run(['bash', compiler_path, cool_file_path], capture_output=True, timeout=timeout) - assert sp.returncode == 0, TEST_MUST_COMPILE % get_file_name(cool_file_path) - except subprocess.TimeoutExpired: - assert False, COMPILER_TIMEOUT - - spim_file = cool_file_path[:-2] + 'mips' - - try: - fd = open(input_file_path, 'rb') - sp = subprocess.run(['spim', '-file', spim_file], input=fd.read(), capture_output=True, timeout=timeout) - fd.close() - mo = re.match(SPIM_HEADER, sp.stdout.decode()) - if mo: - output = mo.string[mo.end():] - except subprocess.TimeoutExpired: - assert False, SPIM_TIMEOUT - - fd = open(output_file_path, 'r') - eoutput = fd.read() - fd.close() - - assert output == eoutput, UNEXPECTED_OUTPUT % (spim_file, repr(output), repr(eoutput)) +import subprocess +import re + + +COMPILER_TIMEOUT = 'El compilador tarda mucho en responder.' +SPIM_TIMEOUT = 'El spim tarda mucho en responder.' +TEST_MUST_FAIL = 'El test %s debe fallar al compilar' +TEST_MUST_COMPILE = 'El test %s debe compilar' +BAD_ERROR_FORMAT = '''El error no esta en formato: (,) - : + o no se encuentra en la 3ra linea\n\n%s''' +UNEXPECTED_ERROR = 'Se esperaba un %s en (%d, %d). Su error fue un %s en (%d, %d)' +UNEXPECTED_OUTPUT = 'La salida de %s no es la esperada:\n%s\nEsperada:\n%s' + +ERROR_FORMAT = r'^\s*\(\s*(\d+)\s*,\s*(\d+)\s*\)\s*-\s*(\w+)\s*:(.*)$' + +def parse_error(error: str): + merror = re.fullmatch(ERROR_FORMAT, error) + assert merror, BAD_ERROR_FORMAT % error + + return (t(x) for t, x in zip([int, int, str, str], merror.groups())) + + +def first_error(compiler_output: list, errors: list): + line, column, error_type, _ = parse_error(errors[0]) + + oline, ocolumn, oerror_type, _ = parse_error(compiler_output[0]) + + assert line == oline and column == ocolumn and error_type == oerror_type,\ + UNEXPECTED_ERROR % (error_type, line, column, oerror_type, oline, ocolumn) + +def first_error_only_line(compiler_output: list, errors: list): + line, column, error_type, _ = parse_error(errors[0]) + + oline, ocolumn, oerror_type, _ = parse_error(compiler_output[0]) + + assert line == oline and error_type == oerror_type,\ + UNEXPECTED_ERROR % (error_type, line, column, oerror_type, oline, ocolumn) + + +def get_file_name(path: str): + try: + return path[path.rindex('/') + 1:] + except ValueError: + return path + +def compare_errors(compiler_path: str, cool_file_path: str, error_file_path: str, cmp=first_error, timeout=100): + try: + sp = subprocess.run(['bash', compiler_path, cool_file_path], capture_output=True, timeout=timeout) + return_code, output = sp.returncode, sp.stdout.decode() + except subprocess.TimeoutExpired: + assert False, COMPILER_TIMEOUT + + assert return_code == 1, TEST_MUST_FAIL % get_file_name(cool_file_path) + + fd = open(error_file_path, 'r') + errors = fd.read().split('\n') + fd.close() + + # checking the errors of compiler + compiler_output = output.split('\n') + cmp(compiler_output[2:], errors) + +SPIM_HEADER = r'''^SPIM Version .+ of .+ +Copyright .+\, James R\. Larus\. +All Rights Reserved\. +See the file README for a full copyright notice\. +(?:Loaded: .+\n)*''' +def compare_outputs(compiler_path: str, cool_file_path: str, input_file_path: str, output_file_path: str, timeout=100): + try: + sp = subprocess.run(['bash', compiler_path, cool_file_path], capture_output=True, timeout=timeout) + assert sp.returncode == 0, TEST_MUST_COMPILE % get_file_name(cool_file_path) + except subprocess.TimeoutExpired: + assert False, COMPILER_TIMEOUT + + spim_file = cool_file_path[:-2] + 'mips' + + try: + fd = open(input_file_path, 'rb') + sp = subprocess.run(['spim', '-file', spim_file], input=fd.read(), capture_output=True, timeout=timeout) + fd.close() + mo = re.match(SPIM_HEADER, sp.stdout.decode()) + if mo: + output = mo.string[mo.end():] + except subprocess.TimeoutExpired: + assert False, SPIM_TIMEOUT + + fd = open(output_file_path, 'r') + eoutput = fd.read() + fd.close() + + assert output == eoutput, UNEXPECTED_OUTPUT % (spim_file, repr(output), repr(eoutput)) From a0841ffc627f5430ff1b47a71227806a4ac1e613 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 7 Feb 2022 18:44:12 -0500 Subject: [PATCH 080/194] lexer test work here --- src/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.py b/src/main.py index 506c548a3..4c1e0e826 100644 --- a/src/main.py +++ b/src/main.py @@ -22,7 +22,7 @@ def main(_input, _output): if __name__ == "__main__": - path = '/mnt/d/UH/4to Año/EVEA/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/parser/conditional4.cl' + path = '/mnt/d/UH/4to Año/EVEA/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/parser/operation1.cl' _input = sys.argv[1] if len(sys.argv) > 1 else path _output = sys.argv[2] if len(sys.argv) > 2 else None From 4b56ceccf9ec56caeee64307832d3838294d9054 Mon Sep 17 00:00:00 2001 From: cwjki Date: Mon, 7 Feb 2022 19:16:55 -0500 Subject: [PATCH 081/194] Reverting to bf197f86d30876f99b9857b4ede3c5e3e0190ed9 --- .github/workflows/tests.yml | 166 +-- .gitignore | 820 +++++------ .vscode/settings.json | 6 +- LICENSE | 42 +- Readme.md | 344 ++--- doc/Readme.md | 66 +- doc/team.yml | 16 +- requirements.txt | 4 +- src/Readme.md | 156 +- src/code_generator/BaseCoolToCilVisitor.py | 126 +- src/code_generator/COOLToCILVisitor.py | 337 +---- src/code_generator/cil_ast.py | 410 +++--- src/coolc.sh | 32 +- src/cparser/parsetab.py | 8 +- src/main.py | 2 +- src/makefile | 24 +- src/semantic/semantic.py | 652 ++++---- src/semantic/types.py | 222 +-- src/semantic/visitors/type_collector.py | 50 +- src/test.cl | 18 +- src/utils/__init__.py | 2 +- src/utils/ast.py | 3 - src/utils/visitor.py | 164 +-- tests/codegen/arith.cl | 860 +++++------ tests/codegen/arith_input.txt | 26 +- tests/codegen/arith_output.txt | 316 ++-- tests/codegen/atoi_output.txt | 2 +- tests/codegen/book_list.cl | 264 ++-- tests/codegen/book_list_output.txt | 14 +- tests/codegen/cells.cl | 194 +-- tests/codegen/cells_output.txt | 42 +- tests/codegen/complex.cl | 104 +- tests/codegen/complex_output.txt | 2 +- tests/codegen/fib.cl | 58 +- tests/codegen/fib_input.txt | 2 +- tests/codegen/fib_output.txt | 4 +- tests/codegen/graph.cl | 762 +++++----- tests/codegen/graph_input.txt | 10 +- tests/codegen/graph_output.txt | 14 +- tests/codegen/hairyscary.cl | 134 +- tests/codegen/hello_world.cl | 10 +- tests/codegen/hello_world_output.txt | 2 +- tests/codegen/io.cl | 206 +-- tests/codegen/io_output.txt | 10 +- tests/codegen/life.cl | 872 +++++------ tests/codegen/life_input.txt | 130 +- tests/codegen/life_output.txt | 1554 ++++++++++---------- tests/codegen/list_output.txt | 10 +- tests/codegen/new_complex.cl | 158 +- tests/codegen/new_complex_output.txt | 4 +- tests/codegen/palindrome.cl | 50 +- tests/codegen/palindrome_input.txt | 2 +- tests/codegen/palindrome_output.txt | 4 +- tests/codegen/primes_output.txt | 192 +-- tests/codegen/print-cool_output.txt | 2 +- tests/codegen/sort-list_input.txt | 2 +- tests/codegen/sort-list_output.txt | 20 +- tests/codegen_test.py | 32 +- tests/conftest.py | 10 +- tests/lexer/comment1.cl | 108 +- tests/lexer/comment1_error.txt | 2 +- tests/lexer/iis1.cl | 220 +-- tests/lexer/iis1_error.txt | 2 +- tests/lexer/iis2.cl | 238 +-- tests/lexer/iis2_error.txt | 2 +- tests/lexer/iis3.cl | 240 +-- tests/lexer/iis3_error.txt | 2 +- tests/lexer/iis4.cl | 238 +-- tests/lexer/iis4_error.txt | 2 +- tests/lexer/iis5.cl | 242 +-- tests/lexer/iis5_error.txt | 4 +- tests/lexer/iis6.cl | 248 ++-- tests/lexer/iis6_error.txt | 2 +- tests/lexer/mixed1.cl | 26 +- tests/lexer/mixed1_error.txt | 2 +- tests/lexer/mixed2.cl | 38 +- tests/lexer/mixed2_error.txt | 6 +- tests/lexer/string1.cl | 10 +- tests/lexer/string1_error.txt | 2 +- tests/lexer/string2.cl | 36 +- tests/lexer/string4.cl | 74 +- tests/lexer/string4_error.txt | 4 +- tests/lexer_test.py | 24 +- tests/parser/assignment1.cl | 72 +- tests/parser/assignment2.cl | 72 +- tests/parser/assignment3.cl | 72 +- tests/parser/attribute1.cl | 66 +- tests/parser/attribute2.cl | 66 +- tests/parser/attribute3.cl | 66 +- tests/parser/block1.cl | 172 +-- tests/parser/block2.cl | 172 +-- tests/parser/block3.cl | 172 +-- tests/parser/block4.cl | 174 +-- tests/parser/case1.cl | 180 +-- tests/parser/case2.cl | 184 +-- tests/parser/case3.cl | 184 +-- tests/parser/case4.cl | 184 +-- tests/parser/case5.cl | 184 +-- tests/parser/case6.cl | 184 +-- tests/parser/class1.cl | 40 +- tests/parser/class2.cl | 40 +- tests/parser/class3.cl | 68 +- tests/parser/class4.cl | 72 +- tests/parser/class5.cl | 68 +- tests/parser/class6.cl | 68 +- tests/parser/conditional1.cl | 136 +- tests/parser/conditional2.cl | 136 +- tests/parser/conditional3.cl | 136 +- tests/parser/conditional4.cl | 144 +- tests/parser/conditional5.cl | 144 +- tests/parser/conditional6.cl | 144 +- tests/parser/dispatch1.cl | 88 +- tests/parser/dispatch2.cl | 88 +- tests/parser/dispatch3.cl | 88 +- tests/parser/dispatch4.cl | 104 +- tests/parser/dispatch5.cl | 104 +- tests/parser/dispatch6.cl | 112 +- tests/parser/dispatch7.cl | 112 +- tests/parser/dispatch8.cl | 112 +- tests/parser/dispatch9.cl | 120 +- tests/parser/let1.cl | 168 +-- tests/parser/let2.cl | 168 +-- tests/parser/let3.cl | 168 +-- tests/parser/let4.cl | 168 +-- tests/parser/let5.cl | 168 +-- tests/parser/let6.cl | 146 +- tests/parser/let7.cl | 168 +-- tests/parser/loop1.cl | 154 +- tests/parser/loop2.cl | 154 +- tests/parser/loop3.cl | 154 +- tests/parser/loop4.cl | 154 +- tests/parser/method1.cl | 66 +- tests/parser/method2.cl | 66 +- tests/parser/method3.cl | 66 +- tests/parser/method4.cl | 66 +- tests/parser/method5.cl | 66 +- tests/parser/method6.cl | 64 +- tests/parser/mixed1.cl | 198 +-- tests/parser/mixed2.cl | 28 +- tests/parser/mixed3.cl | 80 +- tests/parser/mixed4.cl | 42 +- tests/parser/mixed5.cl | 40 +- tests/parser/mixed6.cl | 10 +- tests/parser/operation1.cl | 200 +-- tests/parser/operation2.cl | 200 +-- tests/parser/operation3.cl | 200 +-- tests/parser/operation4.cl | 200 +-- tests/parser/program2.cl | 40 +- tests/parser/program3.cl | 48 +- tests/parser_test.py | 24 +- tests/semantic/arithmetic1.cl | 20 +- tests/semantic/arithmetic10.cl | 28 +- tests/semantic/arithmetic11.cl | 26 +- tests/semantic/arithmetic12.cl | 26 +- tests/semantic/arithmetic1_error.txt | 2 +- tests/semantic/arithmetic2.cl | 20 +- tests/semantic/arithmetic2_error.txt | 2 +- tests/semantic/arithmetic3.cl | 20 +- tests/semantic/arithmetic3_error.txt | 2 +- tests/semantic/arithmetic4.cl | 20 +- tests/semantic/arithmetic5.cl | 20 +- tests/semantic/arithmetic5_error.txt | 2 +- tests/semantic/arithmetic6.cl | 22 +- tests/semantic/arithmetic6_error.txt | 2 +- tests/semantic/arithmetic7.cl | 24 +- tests/semantic/arithmetic7_error.txt | 2 +- tests/semantic/arithmetic8.cl | 26 +- tests/semantic/arithmetic8_error.txt | 2 +- tests/semantic/arithmetic9.cl | 28 +- tests/semantic/assignment1.cl | 14 +- tests/semantic/assignment1_error.txt | 2 +- tests/semantic/assignment2.cl | 26 +- tests/semantic/assignment2_error.txt | 2 +- tests/semantic/assignment3.cl | 28 +- tests/semantic/attributes1.cl | 24 +- tests/semantic/attributes1_error.txt | 2 +- tests/semantic/attributes2.cl | 24 +- tests/semantic/attributes2_error.txt | 2 +- tests/semantic/attributes3.cl | 48 +- tests/semantic/attributes3_error.txt | 2 +- tests/semantic/attributes4.cl | 76 +- tests/semantic/basics1.cl | 18 +- tests/semantic/basics1_error.txt | 2 +- tests/semantic/basics2.cl | 18 +- tests/semantic/basics2_error.txt | 2 +- tests/semantic/basics3.cl | 16 +- tests/semantic/basics3_error.txt | 2 +- tests/semantic/basics4.cl | 16 +- tests/semantic/basics4_error.txt | 2 +- tests/semantic/basics5.cl | 16 +- tests/semantic/basics5_error.txt | 2 +- tests/semantic/basics6.cl | 16 +- tests/semantic/basics6_error.txt | 2 +- tests/semantic/basics7.cl | 16 +- tests/semantic/basics7_error.txt | 2 +- tests/semantic/basics8.cl | 16 +- tests/semantic/basics8_error.txt | 2 +- tests/semantic/blocks1.cl | 60 +- tests/semantic/blocks1_error.txt | 2 +- tests/semantic/case1.cl | 46 +- tests/semantic/case1_error.txt | 2 +- tests/semantic/case2.cl | 44 +- tests/semantic/case3.cl | 44 +- tests/semantic/class1.cl | 16 +- tests/semantic/class1_error.txt | 4 +- tests/semantic/conditionals1.cl | 26 +- tests/semantic/conditionals1_error.txt | 2 +- tests/semantic/conditionals2.cl | 48 +- tests/semantic/conditionals2_error.txt | 4 +- tests/semantic/dispatch1.cl | 64 +- tests/semantic/dispatch1_error.txt | 2 +- tests/semantic/dispatch2.cl | 66 +- tests/semantic/dispatch2_error.txt | 2 +- tests/semantic/dispatch3.cl | 70 +- tests/semantic/dispatch3_error.txt | 2 +- tests/semantic/dispatch4.cl | 70 +- tests/semantic/dispatch5.cl | 60 +- tests/semantic/dispatch5_error.txt | 2 +- tests/semantic/dispatch6.cl | 64 +- tests/semantic/dispatch6_error.txt | 2 +- tests/semantic/eq1.cl | 32 +- tests/semantic/eq1_error.txt | 2 +- tests/semantic/eq2.cl | 34 +- tests/semantic/eq2_error.txt | 2 +- tests/semantic/eq3.cl | 34 +- tests/semantic/eq3_error.txt | 2 +- tests/semantic/eq4.cl | 34 +- tests/semantic/eq4_error.txt | 2 +- tests/semantic/isvoid1.cl | 50 +- tests/semantic/isvoid1_error.txt | 2 +- tests/semantic/let1.cl | 28 +- tests/semantic/let1_error.txt | 2 +- tests/semantic/let2.cl | 28 +- tests/semantic/let2_error.txt | 2 +- tests/semantic/let3.cl | 28 +- tests/semantic/loops1.cl | 14 +- tests/semantic/loops2.cl | 18 +- tests/semantic/loops2_error.txt | 2 +- tests/semantic/methods1.cl | 22 +- tests/semantic/methods1_error.txt | 2 +- tests/semantic/methods2.cl | 22 +- tests/semantic/methods2_error.txt | 2 +- tests/semantic/methods3.cl | 26 +- tests/semantic/methods3_error.txt | 2 +- tests/semantic/methods4.cl | 36 +- tests/semantic/methods4_error.txt | 2 +- tests/semantic/methods5.cl | 40 +- tests/semantic/methods5_error.txt | 2 +- tests/semantic/methods6.cl | 52 +- tests/semantic/methods6_error.txt | 2 +- tests/semantic/methods7.cl | 22 +- tests/semantic/methods8.cl | 22 +- tests/semantic/new1.cl | 60 +- tests/semantic/self1.cl | 22 +- tests/semantic/self1_error.txt | 2 +- tests/semantic/self2.cl | 20 +- tests/semantic/self2_error.txt | 2 +- tests/semantic/self3.cl | 20 +- tests/semantic/self3_error.txt | 2 +- tests/semantic/self4.cl | 18 +- tests/semantic/self4_error.txt | 2 +- tests/semantic_test.py | 26 +- tests/utils/utils.py | 182 +-- 263 files changed, 10711 insertions(+), 10931 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9fb3b7bf2..62ff3680b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,83 +1,83 @@ -name: Tests - -on: [push, pull_request] - -jobs: - lexer: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Setup Python - uses: actions/setup-python@v2 - - - name: Install requirements - run: pip install -r requirements.txt - - - name: Run tests - run: | - cd src - make clean - make - make test TAG=lexer - - parser: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Setup Python - uses: actions/setup-python@v2 - - - name: Install requirements - run: pip install -r requirements.txt - - - name: Run tests - run: | - cd src - make clean - make - make test TAG=parser - - semantic: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Setup Python - uses: actions/setup-python@v2 - - - name: Install requirements - run: pip install -r requirements.txt - - - name: Run tests - run: | - cd src - make clean - make - make test TAG=semantic - - codegen: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Setup Python - uses: actions/setup-python@v2 - - - name: Install requirements - run: pip install -r requirements.txt - - - name: Install spim - run: sudo apt-get install spim - - - name: Run tests - run: | - cd src - make clean - make - make test TAG=codegen +name: Tests + +on: [push, pull_request] + +jobs: + lexer: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v2 + + - name: Install requirements + run: pip install -r requirements.txt + + - name: Run tests + run: | + cd src + make clean + make + make test TAG=lexer + + parser: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v2 + + - name: Install requirements + run: pip install -r requirements.txt + + - name: Run tests + run: | + cd src + make clean + make + make test TAG=parser + + semantic: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v2 + + - name: Install requirements + run: pip install -r requirements.txt + + - name: Run tests + run: | + cd src + make clean + make + make test TAG=semantic + + codegen: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v2 + + - name: Install requirements + run: pip install -r requirements.txt + + - name: Install spim + run: sudo apt-get install spim + + - name: Run tests + run: | + cd src + make clean + make + make test TAG=codegen diff --git a/.gitignore b/.gitignore index 0b07f7b23..4acafde18 100644 --- a/.gitignore +++ b/.gitignore @@ -1,410 +1,410 @@ -# File created using '.gitignore Generator' for Visual Studio Code: https://bit.ly/vscode-gig - -# Created by https://www.gitignore.io/api/visualstudiocode,linux,latex,python -# Edit at https://www.gitignore.io/?templates=visualstudiocode,linux,latex,python - -### LaTeX ### -## Core latex/pdflatex auxiliary files: -*.aux -*.lof -*.log -*.lot -*.fls -*.out -*.toc -*.fmt -*.fot -*.cb -*.cb2 -.*.lb - -## Intermediate documents: -*.dvi -*.xdv -*-converted-to.* -# these rules might exclude image files for figures etc. -# *.ps -# *.eps -# *.pdf - -## Generated if empty string is given at "Please type another file name for output:" -.pdf - -## Bibliography auxiliary files (bibtex/biblatex/biber): -*.bbl -*.bcf -*.blg -*-blx.aux -*-blx.bib -*.run.xml - -## Build tool auxiliary files: -*.fdb_latexmk -*.synctex -*.synctex(busy) -*.synctex.gz -*.synctex.gz(busy) -*.pdfsync - -## Build tool directories for auxiliary files -# latexrun -latex.out/ - -## Auxiliary and intermediate files from other packages: -# algorithms -*.alg -*.loa - -# achemso -acs-*.bib - -# amsthm -*.thm - -# beamer -*.nav -*.pre -*.snm -*.vrb - -# changes -*.soc - -# comment -*.cut - -# cprotect -*.cpt - -# elsarticle (documentclass of Elsevier journals) -*.spl - -# endnotes -*.ent - -# fixme -*.lox - -# feynmf/feynmp -*.mf -*.mp -*.t[1-9] -*.t[1-9][0-9] -*.tfm - -#(r)(e)ledmac/(r)(e)ledpar -*.end -*.?end -*.[1-9] -*.[1-9][0-9] -*.[1-9][0-9][0-9] -*.[1-9]R -*.[1-9][0-9]R -*.[1-9][0-9][0-9]R -*.eledsec[1-9] -*.eledsec[1-9]R -*.eledsec[1-9][0-9] -*.eledsec[1-9][0-9]R -*.eledsec[1-9][0-9][0-9] -*.eledsec[1-9][0-9][0-9]R - -# glossaries -*.acn -*.acr -*.glg -*.glo -*.gls -*.glsdefs - -# uncomment this for glossaries-extra (will ignore makeindex's style files!) -# *.ist - -# gnuplottex -*-gnuplottex-* - -# gregoriotex -*.gaux -*.gtex - -# htlatex -*.4ct -*.4tc -*.idv -*.lg -*.trc -*.xref - -# hyperref -*.brf - -# knitr -*-concordance.tex -# TODO Comment the next line if you want to keep your tikz graphics files -*.tikz -*-tikzDictionary - -# listings -*.lol - -# luatexja-ruby -*.ltjruby - -# makeidx -*.idx -*.ilg -*.ind - -# minitoc -*.maf -*.mlf -*.mlt -*.mtc[0-9]* -*.slf[0-9]* -*.slt[0-9]* -*.stc[0-9]* - -# minted -_minted* -*.pyg - -# morewrites -*.mw - -# nomencl -*.nlg -*.nlo -*.nls - -# pax -*.pax - -# pdfpcnotes -*.pdfpc - -# sagetex -*.sagetex.sage -*.sagetex.py -*.sagetex.scmd - -# scrwfile -*.wrt - -# sympy -*.sout -*.sympy -sympy-plots-for-*.tex/ - -# pdfcomment -*.upa -*.upb - -# pythontex -*.pytxcode -pythontex-files-*/ - -# tcolorbox -*.listing - -# thmtools -*.loe - -# TikZ & PGF -*.dpth -*.md5 -*.auxlock - -# todonotes -*.tdo - -# vhistory -*.hst -*.ver - -# easy-todo -*.lod - -# xcolor -*.xcp - -# xmpincl -*.xmpi - -# xindy -*.xdy - -# xypic precompiled matrices -*.xyc - -# endfloat -*.ttt -*.fff - -# Latexian -TSWLatexianTemp* - -## Editors: -# WinEdt -*.bak -*.sav - -# Texpad -.texpadtmp - -# LyX -*.lyx~ - -# Kile -*.backup - -# KBibTeX -*~[0-9]* - -# auto folder when using emacs and auctex -./auto/* -*.el - -# expex forward references with \gathertags -*-tags.tex - -# standalone packages -*.sta - -### LaTeX Patch ### -# glossaries -*.glstex - -### 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* - -### Python ### -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -pip-wheel-metadata/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -.hypothesis/ -.pytest_cache/ - -# Translations -*.mo -*.pot - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -target/ - -# pyenv -.python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# celery beat schedule file -celerybeat-schedule - -# SageMath parsed files -*.sage.py - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# Mr Developer -.mr.developer.cfg -.project -.pydevproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -### VisualStudioCode ### -.vscode/* -!.vscode/settings.json -!.vscode/tasks.json -!.vscode/launch.json -!.vscode/extensions.json - -### VisualStudioCode Patch ### -# Ignore all local history of files -.history - -# End of https://www.gitignore.io/api/visualstudiocode,linux,latex,python - -# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option) - +# File created using '.gitignore Generator' for Visual Studio Code: https://bit.ly/vscode-gig + +# Created by https://www.gitignore.io/api/visualstudiocode,linux,latex,python +# Edit at https://www.gitignore.io/?templates=visualstudiocode,linux,latex,python + +### LaTeX ### +## Core latex/pdflatex auxiliary files: +*.aux +*.lof +*.log +*.lot +*.fls +*.out +*.toc +*.fmt +*.fot +*.cb +*.cb2 +.*.lb + +## Intermediate documents: +*.dvi +*.xdv +*-converted-to.* +# these rules might exclude image files for figures etc. +# *.ps +# *.eps +# *.pdf + +## Generated if empty string is given at "Please type another file name for output:" +.pdf + +## Bibliography auxiliary files (bibtex/biblatex/biber): +*.bbl +*.bcf +*.blg +*-blx.aux +*-blx.bib +*.run.xml + +## Build tool auxiliary files: +*.fdb_latexmk +*.synctex +*.synctex(busy) +*.synctex.gz +*.synctex.gz(busy) +*.pdfsync + +## Build tool directories for auxiliary files +# latexrun +latex.out/ + +## Auxiliary and intermediate files from other packages: +# algorithms +*.alg +*.loa + +# achemso +acs-*.bib + +# amsthm +*.thm + +# beamer +*.nav +*.pre +*.snm +*.vrb + +# changes +*.soc + +# comment +*.cut + +# cprotect +*.cpt + +# elsarticle (documentclass of Elsevier journals) +*.spl + +# endnotes +*.ent + +# fixme +*.lox + +# feynmf/feynmp +*.mf +*.mp +*.t[1-9] +*.t[1-9][0-9] +*.tfm + +#(r)(e)ledmac/(r)(e)ledpar +*.end +*.?end +*.[1-9] +*.[1-9][0-9] +*.[1-9][0-9][0-9] +*.[1-9]R +*.[1-9][0-9]R +*.[1-9][0-9][0-9]R +*.eledsec[1-9] +*.eledsec[1-9]R +*.eledsec[1-9][0-9] +*.eledsec[1-9][0-9]R +*.eledsec[1-9][0-9][0-9] +*.eledsec[1-9][0-9][0-9]R + +# glossaries +*.acn +*.acr +*.glg +*.glo +*.gls +*.glsdefs + +# uncomment this for glossaries-extra (will ignore makeindex's style files!) +# *.ist + +# gnuplottex +*-gnuplottex-* + +# gregoriotex +*.gaux +*.gtex + +# htlatex +*.4ct +*.4tc +*.idv +*.lg +*.trc +*.xref + +# hyperref +*.brf + +# knitr +*-concordance.tex +# TODO Comment the next line if you want to keep your tikz graphics files +*.tikz +*-tikzDictionary + +# listings +*.lol + +# luatexja-ruby +*.ltjruby + +# makeidx +*.idx +*.ilg +*.ind + +# minitoc +*.maf +*.mlf +*.mlt +*.mtc[0-9]* +*.slf[0-9]* +*.slt[0-9]* +*.stc[0-9]* + +# minted +_minted* +*.pyg + +# morewrites +*.mw + +# nomencl +*.nlg +*.nlo +*.nls + +# pax +*.pax + +# pdfpcnotes +*.pdfpc + +# sagetex +*.sagetex.sage +*.sagetex.py +*.sagetex.scmd + +# scrwfile +*.wrt + +# sympy +*.sout +*.sympy +sympy-plots-for-*.tex/ + +# pdfcomment +*.upa +*.upb + +# pythontex +*.pytxcode +pythontex-files-*/ + +# tcolorbox +*.listing + +# thmtools +*.loe + +# TikZ & PGF +*.dpth +*.md5 +*.auxlock + +# todonotes +*.tdo + +# vhistory +*.hst +*.ver + +# easy-todo +*.lod + +# xcolor +*.xcp + +# xmpincl +*.xmpi + +# xindy +*.xdy + +# xypic precompiled matrices +*.xyc + +# endfloat +*.ttt +*.fff + +# Latexian +TSWLatexianTemp* + +## Editors: +# WinEdt +*.bak +*.sav + +# Texpad +.texpadtmp + +# LyX +*.lyx~ + +# Kile +*.backup + +# KBibTeX +*~[0-9]* + +# auto folder when using emacs and auctex +./auto/* +*.el + +# expex forward references with \gathertags +*-tags.tex + +# standalone packages +*.sta + +### LaTeX Patch ### +# glossaries +*.glstex + +### 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* + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# Mr Developer +.mr.developer.cfg +.project +.pydevproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history + +# End of https://www.gitignore.io/api/visualstudiocode,linux,latex,python + +# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option) + diff --git a/.vscode/settings.json b/.vscode/settings.json index 82a851134..cc67606f3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,4 @@ -{ - "python.linting.pylintEnabled": true, - "python.linting.enabled": true +{ + "python.linting.pylintEnabled": true, + "python.linting.enabled": true } \ No newline at end of file diff --git a/LICENSE b/LICENSE index 7f19c2d8c..718bd210a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,21 +1,21 @@ -MIT License - -Copyright (c) 2021 School of Math and Computer Science, University of Havana - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +MIT License + +Copyright (c) 2021 School of Math and Computer Science, University of Havana + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Readme.md b/Readme.md index 0e33ddb08..a47d48b9e 100644 --- a/Readme.md +++ b/Readme.md @@ -1,172 +1,172 @@ -# COOL: Proyecto de Compilación - -> Proyecto base para el compilador de 4to año en Ciencia de la Computación. - -## Generalidades - -La evaluación de la asignatura Complementos de Compilación, inscrita en el programa del 4to año de la Licenciatura en Ciencia de la Computación de la Facultad de Matemática y Computación de la -Universidad de La Habana, consiste este curso en la implementación de un compilador completamente -funcional para el lenguaje _COOL_. - -_COOL (Classroom Object-Oriented Language)_ es un pequeño lenguaje que puede ser implementado con un esfuerzo razonable en un semestre del curso. Aun así, _COOL_ mantiene muchas de las características de los lenguajes de programación modernos, incluyendo orientación a objetos, tipado estático y manejo automático de memoria. - -## Cómo comenzar (o terminar) - -El proyecto de Compilación será recogido y evaluado **únicamente** a través de Github. Es imprescindible tener una cuenta de Github para cada participante, y que su proyecto esté correctamente hosteado en esta plataforma. A continuación le damos las instrucciones mínimas necesarias para ello: - -### 1. Si no lo han hecho ya, regístrense en [Github](https://github.com) todos los miembros del equipo (es gratis). - -![](img/img1.png) - -### 2. Haga click en el botón **Fork** para hacer una copia del proyecto en el perfil de Github de uno de los miembros. - -Opcionalmente pueden [crear una organización](https://github.com/organizations/new) y copiar el proyecto en el perfil de la misma. - -![](img/img2.png) - -### 3. Una vez hecho esto, tendrá un nuevo repositorio en `github/`. - -Revise que el repositorio de su equipo está en su perfil. -En este ejemplo se ha copiado a la cuenta de `github.com/apiad`. - -Debe indicar bajo el nombre del repositorio: `"forked from matcom/cool-compiler-2021"`. - -![](img/img3.png) - -### 4. Clone este proyecto en un repositorio local. - -Busque la URL de su proyecto en la interfaz web de Github. - -Asegúrese de clonar **su copia** y no el proyecto original en `matcom/cool-compiler-2021`. - -![](img/img4.png) - -```bash -$ git clone git@github.com:/cool-compiler-2021.git -``` - -> Donde `` es posiblemente el nombre de su equipo o del miembro donde se hizo el _fork_. - -A partir de este punto debe tener un proyecto `cool-compiler-2021` local. -El siguiente paso depende de si usted ya tiene su código versionado con `git` o no. - -### 5.A. Si tiene su proyecto en git (y no quiere perder la historia): - -#### 5.1. Mezcle hacia el nuevo respositorio su repositorio anterior: - -```bash -$ cd cool-compiler-2021 -$ git pull --allow-unrelated-histories master -``` - -#### 5.2. Organice su proyecto, código fuente y documentación, de acuerdo a las instrucciones de este documento, y vuelva a hacer `commit`. - -```bash -$ mv src/ -$ git add . -$ git commit -a -m "Mezclado con el proyecto base" -``` - -#### 5.3. A partir de este punto puede hacer `push` cada vez que tenga cambios que subir. - -```bash -$ git push origin master -``` - -### 5.B Si aún no tiene su proyecto en git (o no le importa la historia): - -#### 5.1. Simplemente copie el código de su proyecto en la carpeta correspondiente `src` y haga su primer commit. - -```bash -$ mv src/ -$ git commit -a -m "Hello Git!" -``` - -#### 5.2. A partir de este punto asegúrese de hacer `commit` de forma regular para mantener su repositorio actualizado. - -Si necesita saber más sobre `git`, todo lo imprescindible está en [esta guía](doc/github-git-cheat-sheet.pdf). - -#### 5.3. A partir de este punto puede hacer `push` cada vez que tenga cambios que subir. - -```bash -$ git push origin master -``` - -## Entregas - -En este proyecto se realizarán entregas parciales a lo largo del curso. Para realizar una entrega, siga los siguientes pasos. - -### 1. Cree un pull request al proyecto original desde su copia. - -![](img/img5.png) - -### 2. Asegúrese de tener la siguiente configuración antes de hacer click en **Create pull request**. - -- **base repository**: `matcom/cool-compiler-2021` (repositorio original) - - **branch**: `master` -- **head repository**: `/cool-compiler-2021` (repositorio propio) - - **branch**: `master` (o la que corresponda) - -> Asegúrese que se indica **Able to merge**. De lo contrario, existen cambios en el repositorio original que usted no tiene, y debe actualizarlos. - -> **NOTA**: Asegúrese que el _pull request_ se hace a la rama `master`. - -![](img/img6.png) - -### 3. Introduzca un título y descripción adecuados, y haga click en **Create pull request**. - -![](img/img7.png) - -### 4. Espere mientras se ejecutan las pruebas. - -Verá la indicación **Some checks haven't completed yet**. - -![](img/img8.png) - -Es posible que tenga que actualizar los cambios que se hayan hecho en el repositorio original, por ejemplo, si se han agregado nuevos tests. En este caso obtendrá el siguiente mensaje: - -> **This branch is out-of-date with base branch** - -Haga click en **Update branch** y siga las instrucciones. -### 5. Verifique que no hubo errores en las pruebas. - -Si ve el mensaje **(All | Some) checks have failed**, significa que su código no pasó las pruebas. - -![](img/img9.png) - -Para ver los resultados de las pruebas haga click en el link **Details**. - -![](img/img10.png) - - -### 6. Arregle los errores y repita el paso 5 hasta que todas las pruebas pasen. - -Para cualquier modificación que haga a su proyecto, haga _commit_ y _push_ para **su repositorio personal** y automáticamente se actualizará el estado del _pull request_ y se volverán a ejecutar las pruebas. **No es necesario** abrir un _pull request_ nuevo por cada entrega, sino actualizar el anterior. - -> **Por favor asegúrese de mantener un solo _pull request_ activo por equipo**. En caso de abrir uno nuevo, cerrar el anterior. - -## Sobre la implementación - -Ponga todo su código e instrucciones necesarias en la carpeta `src`. Más información en [`src/Readme.md`](src/Readme.md). - -## Sobre la documentación - -Usted debe presentar un reporte escrito documentando el proceso de construcción de su compilador y los detalles más importantes de su funcionamiento. Más información en [`doc/Readme.md`](doc/Readme.md). - -## Sobre los equipos de desarrollo - -Para desarrollar el compilador del lenguaje COOL se trabajará en equipos de 2 o 3 integrantes. - -## Sobre los casos de prueba - -La carpeta `tests` contiene todos los casos de prueba que son obligatorios de pasar para que su proyecto tenga derecho a ser evaluado. - -Estos tests se ejecutan automáticamente cada vez que hace un _pull request_ al repositorio `matcom/cool-compiler-2021`. Solo aquellos proyectos que pasen todas las pruebas con éxito serán evaluados. - -Para ejecutar las pruebas localmente, debe tener instalado `Python 3.7`, `pip` y `make` (normalmente viene con Linux). Ejecute: - -```bash -$ pip install -r requirements.txt -$ cd src -$ make test -``` +# COOL: Proyecto de Compilación + +> Proyecto base para el compilador de 4to año en Ciencia de la Computación. + +## Generalidades + +La evaluación de la asignatura Complementos de Compilación, inscrita en el programa del 4to año de la Licenciatura en Ciencia de la Computación de la Facultad de Matemática y Computación de la +Universidad de La Habana, consiste este curso en la implementación de un compilador completamente +funcional para el lenguaje _COOL_. + +_COOL (Classroom Object-Oriented Language)_ es un pequeño lenguaje que puede ser implementado con un esfuerzo razonable en un semestre del curso. Aun así, _COOL_ mantiene muchas de las características de los lenguajes de programación modernos, incluyendo orientación a objetos, tipado estático y manejo automático de memoria. + +## Cómo comenzar (o terminar) + +El proyecto de Compilación será recogido y evaluado **únicamente** a través de Github. Es imprescindible tener una cuenta de Github para cada participante, y que su proyecto esté correctamente hosteado en esta plataforma. A continuación le damos las instrucciones mínimas necesarias para ello: + +### 1. Si no lo han hecho ya, regístrense en [Github](https://github.com) todos los miembros del equipo (es gratis). + +![](img/img1.png) + +### 2. Haga click en el botón **Fork** para hacer una copia del proyecto en el perfil de Github de uno de los miembros. + +Opcionalmente pueden [crear una organización](https://github.com/organizations/new) y copiar el proyecto en el perfil de la misma. + +![](img/img2.png) + +### 3. Una vez hecho esto, tendrá un nuevo repositorio en `github/`. + +Revise que el repositorio de su equipo está en su perfil. +En este ejemplo se ha copiado a la cuenta de `github.com/apiad`. + +Debe indicar bajo el nombre del repositorio: `"forked from matcom/cool-compiler-2021"`. + +![](img/img3.png) + +### 4. Clone este proyecto en un repositorio local. + +Busque la URL de su proyecto en la interfaz web de Github. + +Asegúrese de clonar **su copia** y no el proyecto original en `matcom/cool-compiler-2021`. + +![](img/img4.png) + +```bash +$ git clone git@github.com:/cool-compiler-2021.git +``` + +> Donde `` es posiblemente el nombre de su equipo o del miembro donde se hizo el _fork_. + +A partir de este punto debe tener un proyecto `cool-compiler-2021` local. +El siguiente paso depende de si usted ya tiene su código versionado con `git` o no. + +### 5.A. Si tiene su proyecto en git (y no quiere perder la historia): + +#### 5.1. Mezcle hacia el nuevo respositorio su repositorio anterior: + +```bash +$ cd cool-compiler-2021 +$ git pull --allow-unrelated-histories master +``` + +#### 5.2. Organice su proyecto, código fuente y documentación, de acuerdo a las instrucciones de este documento, y vuelva a hacer `commit`. + +```bash +$ mv src/ +$ git add . +$ git commit -a -m "Mezclado con el proyecto base" +``` + +#### 5.3. A partir de este punto puede hacer `push` cada vez que tenga cambios que subir. + +```bash +$ git push origin master +``` + +### 5.B Si aún no tiene su proyecto en git (o no le importa la historia): + +#### 5.1. Simplemente copie el código de su proyecto en la carpeta correspondiente `src` y haga su primer commit. + +```bash +$ mv src/ +$ git commit -a -m "Hello Git!" +``` + +#### 5.2. A partir de este punto asegúrese de hacer `commit` de forma regular para mantener su repositorio actualizado. + +Si necesita saber más sobre `git`, todo lo imprescindible está en [esta guía](doc/github-git-cheat-sheet.pdf). + +#### 5.3. A partir de este punto puede hacer `push` cada vez que tenga cambios que subir. + +```bash +$ git push origin master +``` + +## Entregas + +En este proyecto se realizarán entregas parciales a lo largo del curso. Para realizar una entrega, siga los siguientes pasos. + +### 1. Cree un pull request al proyecto original desde su copia. + +![](img/img5.png) + +### 2. Asegúrese de tener la siguiente configuración antes de hacer click en **Create pull request**. + +- **base repository**: `matcom/cool-compiler-2021` (repositorio original) + - **branch**: `master` +- **head repository**: `/cool-compiler-2021` (repositorio propio) + - **branch**: `master` (o la que corresponda) + +> Asegúrese que se indica **Able to merge**. De lo contrario, existen cambios en el repositorio original que usted no tiene, y debe actualizarlos. + +> **NOTA**: Asegúrese que el _pull request_ se hace a la rama `master`. + +![](img/img6.png) + +### 3. Introduzca un título y descripción adecuados, y haga click en **Create pull request**. + +![](img/img7.png) + +### 4. Espere mientras se ejecutan las pruebas. + +Verá la indicación **Some checks haven't completed yet**. + +![](img/img8.png) + +Es posible que tenga que actualizar los cambios que se hayan hecho en el repositorio original, por ejemplo, si se han agregado nuevos tests. En este caso obtendrá el siguiente mensaje: + +> **This branch is out-of-date with base branch** + +Haga click en **Update branch** y siga las instrucciones. +### 5. Verifique que no hubo errores en las pruebas. + +Si ve el mensaje **(All | Some) checks have failed**, significa que su código no pasó las pruebas. + +![](img/img9.png) + +Para ver los resultados de las pruebas haga click en el link **Details**. + +![](img/img10.png) + + +### 6. Arregle los errores y repita el paso 5 hasta que todas las pruebas pasen. + +Para cualquier modificación que haga a su proyecto, haga _commit_ y _push_ para **su repositorio personal** y automáticamente se actualizará el estado del _pull request_ y se volverán a ejecutar las pruebas. **No es necesario** abrir un _pull request_ nuevo por cada entrega, sino actualizar el anterior. + +> **Por favor asegúrese de mantener un solo _pull request_ activo por equipo**. En caso de abrir uno nuevo, cerrar el anterior. + +## Sobre la implementación + +Ponga todo su código e instrucciones necesarias en la carpeta `src`. Más información en [`src/Readme.md`](src/Readme.md). + +## Sobre la documentación + +Usted debe presentar un reporte escrito documentando el proceso de construcción de su compilador y los detalles más importantes de su funcionamiento. Más información en [`doc/Readme.md`](doc/Readme.md). + +## Sobre los equipos de desarrollo + +Para desarrollar el compilador del lenguaje COOL se trabajará en equipos de 2 o 3 integrantes. + +## Sobre los casos de prueba + +La carpeta `tests` contiene todos los casos de prueba que son obligatorios de pasar para que su proyecto tenga derecho a ser evaluado. + +Estos tests se ejecutan automáticamente cada vez que hace un _pull request_ al repositorio `matcom/cool-compiler-2021`. Solo aquellos proyectos que pasen todas las pruebas con éxito serán evaluados. + +Para ejecutar las pruebas localmente, debe tener instalado `Python 3.7`, `pip` y `make` (normalmente viene con Linux). Ejecute: + +```bash +$ pip install -r requirements.txt +$ cd src +$ make test +``` diff --git a/doc/Readme.md b/doc/Readme.md index a7ed0e32d..3b2569f5c 100644 --- a/doc/Readme.md +++ b/doc/Readme.md @@ -1,33 +1,33 @@ -# Documentación - -## Readme - -Modifique el contenido de este documento para documentar de forma clara y concisa los siguientes aspectos: - -- Cómo ejecutar (y compilar si es necesario) su compilador. -- Requisitos adicionales, dependencias, configuración, etc. -- Opciones adicionales que tenga su compilador. - -## Sobre los Equipos de Desarrollo - -Para desarrollar el compilador del lenguaje COOL se trabajará en equipos de 2 o 3 integrantes. El proyecto de Compilación será recogido y evaluado únicamente a través de Github. Es imprescindible tener una cuenta de Github para cada participante, y que su proyecto esté correctamente hosteado en esta plataforma. - -**⚠️ NOTA**: Debe completar el archivo `team.yml` con los datos correctos de cada miembro de su equipo. - -## Sobre los Materiales a Entregar - -Para la evaluación del proyecto Ud. debe entregar un informe en formato PDF (`report.pdf`) en esta carpeta, que resuma de manera organizada y comprensible la arquitectura e implementación de su compilador. -El documento no tiene límite de extensión. -En él explicará en más detalle su solución a los problemas que, durante la implementación de cada una de las fases del proceso de compilación, hayan requerido de Ud. especial atención. - -## Estructura del reporte - -Usted es libre de estructurar su reporte escrito como más conveniente le parezca. A continuación le sugerimos algunas secciones que no deberían faltar, aunque puede mezclar, renombrar y organizarlas de la manera que mejor le parezca: - -- **Uso del compilador**: detalles sobre las opciones de líneas de comando, si tiene opciones adicionales (e.j., `--ast` genera un AST en JSON, etc.). Básicamente lo mismo que pondrá en este Readme. -- **Arquitectura del compilador**: una explicación general de la arquitectura, en cuántos módulos se divide el proyecto, cuantas fases tiene, qué tipo de gramática se utiliza, y en general, como se organiza el proyecto. Una buena imagen siempre ayuda. -- **Problemas técnicos**: detalles sobre cualquier problema teórico o técnico interesante que haya necesitado resolver de forma particular. - -## Sobre la Fecha de Entrega - -Se realizarán recogidas parciales del proyecto a lo largo del curso. En el Canal de Telegram se anunciará la fecha y requisitos de cada entrega. +# Documentación + +## Readme + +Modifique el contenido de este documento para documentar de forma clara y concisa los siguientes aspectos: + +- Cómo ejecutar (y compilar si es necesario) su compilador. +- Requisitos adicionales, dependencias, configuración, etc. +- Opciones adicionales que tenga su compilador. + +## Sobre los Equipos de Desarrollo + +Para desarrollar el compilador del lenguaje COOL se trabajará en equipos de 2 o 3 integrantes. El proyecto de Compilación será recogido y evaluado únicamente a través de Github. Es imprescindible tener una cuenta de Github para cada participante, y que su proyecto esté correctamente hosteado en esta plataforma. + +**⚠️ NOTA**: Debe completar el archivo `team.yml` con los datos correctos de cada miembro de su equipo. + +## Sobre los Materiales a Entregar + +Para la evaluación del proyecto Ud. debe entregar un informe en formato PDF (`report.pdf`) en esta carpeta, que resuma de manera organizada y comprensible la arquitectura e implementación de su compilador. +El documento no tiene límite de extensión. +En él explicará en más detalle su solución a los problemas que, durante la implementación de cada una de las fases del proceso de compilación, hayan requerido de Ud. especial atención. + +## Estructura del reporte + +Usted es libre de estructurar su reporte escrito como más conveniente le parezca. A continuación le sugerimos algunas secciones que no deberían faltar, aunque puede mezclar, renombrar y organizarlas de la manera que mejor le parezca: + +- **Uso del compilador**: detalles sobre las opciones de líneas de comando, si tiene opciones adicionales (e.j., `--ast` genera un AST en JSON, etc.). Básicamente lo mismo que pondrá en este Readme. +- **Arquitectura del compilador**: una explicación general de la arquitectura, en cuántos módulos se divide el proyecto, cuantas fases tiene, qué tipo de gramática se utiliza, y en general, como se organiza el proyecto. Una buena imagen siempre ayuda. +- **Problemas técnicos**: detalles sobre cualquier problema teórico o técnico interesante que haya necesitado resolver de forma particular. + +## Sobre la Fecha de Entrega + +Se realizarán recogidas parciales del proyecto a lo largo del curso. En el Canal de Telegram se anunciará la fecha y requisitos de cada entrega. diff --git a/doc/team.yml b/doc/team.yml index a42d65e6a..b96f2e877 100644 --- a/doc/team.yml +++ b/doc/team.yml @@ -1,8 +1,8 @@ -members: - - name: Olivia Gonzalez Peña - github: livi98 - group: C411 - - name: Juan Carlos Casteleiro Wong - github: cwjki - group: C411 - +members: + - name: Olivia Gonzalez Peña + github: livi98 + group: C411 + - name: Juan Carlos Casteleiro Wong + github: cwjki + group: C411 + diff --git a/requirements.txt b/requirements.txt index 194b049fa..5a914fd88 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -pytest -pytest-ordering +pytest +pytest-ordering ply \ No newline at end of file diff --git a/src/Readme.md b/src/Readme.md index cdca282ec..1200371b5 100644 --- a/src/Readme.md +++ b/src/Readme.md @@ -1,78 +1,78 @@ -# COOL: Proyecto de Compilación - -La evaluación de la asignatura Complementos de Compilación, inscrita en el programa del 4to año de la Licenciatura en Ciencia de la Computación de la Facultad de Matemática y Computación de la -Universidad de La Habana, consiste este curso en la implementación de un compilador completamente -funcional para el lenguaje _COOL_. - -_COOL (Classroom Object-Oriented Language)_ es un pequeño lenguaje que puede ser implementado con un esfuerzo razonable en un semestre del curso. Aun así, _COOL_ mantiene muchas de las características de los lenguajes de programación modernos, incluyendo orientación a objetos, tipado estático y manejo automático de memoria. - -### Sobre el Lenguaje COOL - -Ud. podrá encontrar la especificación formal del lenguaje COOL en el documento _"COOL Language Reference Manual"_, que se distribuye junto con el presente texto. - -## Código Fuente - -### Compilando su proyecto - -Si es necesario compilar su proyecto, incluya todas las instrucciones necesarias en un archivo [`/src/makefile`](/src/makefile). -Durante la evaluación su proyecto se compilará ejecutando la siguiente secuencia: - -```bash -$ cd source -$ make clean -$ make -``` - -### Ejecutando su proyecto - -Incluya en un archivo [`/src/coolc.sh`](/src/coolc.sh) todas las instrucciones que hacen falta para lanzar su compilador. Recibirá como entrada un archivo con extensión `.cl` y debe generar como salida un archivo `.mips` cuyo nombre será el mismo que la entrada. - -Para lanzar el compilador, se ejecutará la siguiente instrucción: - -```bash -$ cd source -$ ./coolc.sh -``` - -### Sobre el Compilador de COOL - -El compilador de COOL se ejecutará como se ha definido anteriormente. -En caso de que no ocurran errores durante la operación del compilador, **coolc.sh** deberá terminar con código de salida 0, generar (o sobrescribir si ya existe) en la misma carpeta del archivo **.cl** procesado, y con el mismo nombre que éste, un archivo con extension **.mips** que pueda ser ejecutado con **spim**. Además, reportar a la salida estándar solamente lo siguiente: - - - - -En caso de que ocurran errores durante la operación del compilador, **coolc.sh** deberá terminar con código -de salida (exit code) 1 y reportar a la salida estándar (standard output stream) lo que sigue... - - - - _1 - ... - _n - -... donde `_i` tiene el siguiente formato: - - (,) - : - -Los campos `` y `` indican la ubicación del error en el fichero **.cl** procesado. En caso -de que la naturaleza del error sea tal que no pueda asociárselo a una línea y columna en el archivo de -código fuente, el valor de dichos campos debe ser 0. - -El campo `` será alguno entre: - -- `CompilerError`: se reporta al detectar alguna anomalía con la entrada del compilador. Por ejemplo, si el fichero a compilar no existe. -- `LexicographicError`: errores detectados por el lexer. -- `SyntacticError`: errores detectados por el parser. -- `NameError`: se reporta al referenciar un `identificador` en un ámbito en el que no es visible. -- `TypeError`: se reporta al detectar un problema de tipos. Incluye: - - incompatibilidad de tipos entre `rvalue` y `lvalue`, - - operación no definida entre objetos de ciertos tipos, y - - tipo referenciado pero no definido. -- `AttributeError`: se reporta cuando un atributo o método se referencia pero no está definido. -- `SemanticError`: cualquier otro error semántico. - -### Sobre la Implementación del Compilador de COOL - -El compilador debe estar implementado en `python`. Usted debe utilizar una herramienta generadora de analizadores -lexicográficos y sintácticos. Puede utilizar la que sea de su preferencia. +# COOL: Proyecto de Compilación + +La evaluación de la asignatura Complementos de Compilación, inscrita en el programa del 4to año de la Licenciatura en Ciencia de la Computación de la Facultad de Matemática y Computación de la +Universidad de La Habana, consiste este curso en la implementación de un compilador completamente +funcional para el lenguaje _COOL_. + +_COOL (Classroom Object-Oriented Language)_ es un pequeño lenguaje que puede ser implementado con un esfuerzo razonable en un semestre del curso. Aun así, _COOL_ mantiene muchas de las características de los lenguajes de programación modernos, incluyendo orientación a objetos, tipado estático y manejo automático de memoria. + +### Sobre el Lenguaje COOL + +Ud. podrá encontrar la especificación formal del lenguaje COOL en el documento _"COOL Language Reference Manual"_, que se distribuye junto con el presente texto. + +## Código Fuente + +### Compilando su proyecto + +Si es necesario compilar su proyecto, incluya todas las instrucciones necesarias en un archivo [`/src/makefile`](/src/makefile). +Durante la evaluación su proyecto se compilará ejecutando la siguiente secuencia: + +```bash +$ cd source +$ make clean +$ make +``` + +### Ejecutando su proyecto + +Incluya en un archivo [`/src/coolc.sh`](/src/coolc.sh) todas las instrucciones que hacen falta para lanzar su compilador. Recibirá como entrada un archivo con extensión `.cl` y debe generar como salida un archivo `.mips` cuyo nombre será el mismo que la entrada. + +Para lanzar el compilador, se ejecutará la siguiente instrucción: + +```bash +$ cd source +$ ./coolc.sh +``` + +### Sobre el Compilador de COOL + +El compilador de COOL se ejecutará como se ha definido anteriormente. +En caso de que no ocurran errores durante la operación del compilador, **coolc.sh** deberá terminar con código de salida 0, generar (o sobrescribir si ya existe) en la misma carpeta del archivo **.cl** procesado, y con el mismo nombre que éste, un archivo con extension **.mips** que pueda ser ejecutado con **spim**. Además, reportar a la salida estándar solamente lo siguiente: + + + + +En caso de que ocurran errores durante la operación del compilador, **coolc.sh** deberá terminar con código +de salida (exit code) 1 y reportar a la salida estándar (standard output stream) lo que sigue... + + + + _1 + ... + _n + +... donde `_i` tiene el siguiente formato: + + (,) - : + +Los campos `` y `` indican la ubicación del error en el fichero **.cl** procesado. En caso +de que la naturaleza del error sea tal que no pueda asociárselo a una línea y columna en el archivo de +código fuente, el valor de dichos campos debe ser 0. + +El campo `` será alguno entre: + +- `CompilerError`: se reporta al detectar alguna anomalía con la entrada del compilador. Por ejemplo, si el fichero a compilar no existe. +- `LexicographicError`: errores detectados por el lexer. +- `SyntacticError`: errores detectados por el parser. +- `NameError`: se reporta al referenciar un `identificador` en un ámbito en el que no es visible. +- `TypeError`: se reporta al detectar un problema de tipos. Incluye: + - incompatibilidad de tipos entre `rvalue` y `lvalue`, + - operación no definida entre objetos de ciertos tipos, y + - tipo referenciado pero no definido. +- `AttributeError`: se reporta cuando un atributo o método se referencia pero no está definido. +- `SemanticError`: cualquier otro error semántico. + +### Sobre la Implementación del Compilador de COOL + +El compilador debe estar implementado en `python`. Usted debe utilizar una herramienta generadora de analizadores +lexicográficos y sintácticos. Puede utilizar la que sea de su preferencia. diff --git a/src/code_generator/BaseCoolToCilVisitor.py b/src/code_generator/BaseCoolToCilVisitor.py index 2501fbd4b..5386a0785 100644 --- a/src/code_generator/BaseCoolToCilVisitor.py +++ b/src/code_generator/BaseCoolToCilVisitor.py @@ -1,67 +1,61 @@ -import cil_ast as cil -class BaseCOOLToCILVisitor: - def __init__(self, context): - self.dottypes = [] - self.dotdata = [] - self.dotcode = [] - self.current_type = None - self.current_method = None - self.current_function = None - self.context = context - - @property - def params(self): - return self.current_function.params - - @property - def localvars(self): - return self.current_function.localvars - - @property - def instructions(self): - return self.current_function.instructions - - def register_param(self, type, name): - #'param_{self.current_function.name[9:]}_{vinfo.name}_{len(self.params)}' - param_node = cil.ParamNode(type, name) - self.params.append(param_node) - return name - - def register_local(self, name): - #vinfo.name = f'local_{self.current_function.name[9:]}_{vinfo.name}_{len(self.localvars)}' - local_node = cil.LocalNode(name) - self.localvars.append(local_node) - return name - - def define_internal_local(self): - return self.register_local('internal') - - def register_instruction(self, instruction): - self.instructions.append(instruction) - return instruction - ############################### - - def to_function_name(self, method_name, type_name): - return f'function_{method_name}_at_{type_name}' - - def to_attribute_name(self, attr_name, type_name): - return f'function_{attr_name}_at_{type_name}' - - def to_variable_name(self, var_name): - return f'function_{var_name}' - - def register_function(self, function_name): - function_node = cil.FunctionNode(function_name, [], [], []) - self.dotcode.append(function_node) - return function_node - - def register_type(self, name): - type_node = cil.TypeNode(name) - self.dottypes.append(type_node) - return type_node - - def register_data(self, value): - vname = f'data_{len(self.dotdata)}' - data_node = cil.DataNode(vname, value) - self.dotdata.append(data_node) +import cil_ast as cil +class BaseCOOLToCILVisitor: + def __init__(self, context): + self.dottypes = [] + self.dotdata = [] + self.dotcode = [] + self.current_type = None + self.current_method = None + self.current_function = None + self.context = context + + @property + def params(self): + return self.current_function.params + + @property + def localvars(self): + return self.current_function.localvars + + @property + def instructions(self): + return self.current_function.instructions + + def register_param(self, type, name): + #'param_{self.current_function.name[9:]}_{vinfo.name}_{len(self.params)}' + param_node = cil.ParamNode(type, name) + self.params.append(param_node) + return name + + def register_local(self, name): + #vinfo.name = f'local_{self.current_function.name[9:]}_{vinfo.name}_{len(self.localvars)}' + local_node = cil.LocalNode(name) + self.localvars.append(local_node) + return name + + def define_internal_local(self): + return self.register_local('internal') + + def register_instruction(self, instruction): + self.instructions.append(instruction) + return instruction + ############################### + + def to_function_name(self, method_name, type_name): + return f'function_{method_name}_at_{type_name}' + + def register_function(self, function_name): + function_node = cil.FunctionNode(function_name, [], [], []) + self.dotcode.append(function_node) + return function_node + + def register_type(self, name): + type_node = cil.TypeNode(name) + self.dottypes.append(type_node) + return type_node + + def register_data(self, value): + vname = f'data_{len(self.dotdata)}' + data_node = cil.DataNode(vname, value) + self.dotdata.append(data_node) return data_node \ No newline at end of file diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index 68fc61494..51e273a6a 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -1,274 +1,63 @@ -import cil_ast as cil -from BaseCOOLToCILVisitor import * -from utils import visitor -from utils.ast import * - -class COOLToCILVisitor(BaseCOOLToCILVisitor): - @visitor.on('node') - def visit(self, node): - pass - - @visitor.when(ProgramNode) - def visit(self, node, scope): - self.current_function = self.register_function('entry') - instance = self.define_internal_local() - result = self.define_internal_local() - self.register_instruction(cil.AllocateNode('Main', instance)) - self.register_instruction(cil.ArgNode(instance)) - - #self.register_instruction(cil.CallNode(self.to_function_name('main', 'Main'), result)) - self.register_instruction(cil.CallNode(result, self.to_function_name('main', 'Main'), [cil.ArgNode(instance)], 'Main')) - - self.register_instruction(cil.ReturnNode(0)) - self.current_function = None - - # self.create_built_in() - - for declaration, child_scope in zip(node.declarations, scope.children): - self.visit(declaration, child_scope) - - return cil.ProgramNode(self.dottypes, self.dotdata, self.dotcode) - - @visitor.when(ClassDeclarationNode) - def visit(self, node, scope): - self.current_type = self.context.get_type(node.id) - - cil_type_node = self.register_type(self.current_type) - cil_type_node.attributes = self.current_type.get_all_attributes() - - if len(cil_type_node.attributes) != 0: - constructor = FuncDeclarationNode(node.token, [], node.token, BlockNode([], node.token)) - func_declarations = [constructor] - self.constructors.append(node.id) - self.current_type.define_method(self.current_type.name, [], [], self.current_type, node.pos) - scopes = [scope] + list(scope.functions.values()) - else: - func_declarations = [] - scopes = list(scope.functions.values()) - - for attr, a_type in cil_type_node.attributes: - cil_type_node.attributes.append((attr.name, self.to_attribute_name(attr.name, a_type.name))) - self.initialize_attr(constructor, attr, scope) - if cil_type_node.attributes: - constructor.body.expr_list.append(SelfNode()) - - for method, mtype in self.current_type.all_methods(): - cil_type_node.methods.append((method.name, self.to_function_name(method.name, mtype.name))) - - func_declarations += [f for f in node.features if isinstance(f, FuncDeclarationNode)] - for feature, child_scope in zip(func_declarations, scopes): - self.visit(feature, child_scope) - - self.current_type = None - - @visitor.when(FuncDeclarationNode) - def visit(self, node, scope): - self.current_method = self.current_type.get_method(node.id) - cil_name = self.to_function_name(node.id, self.current_type.name) - self.current_function = self.register_function(cil_name) - - self.register_param('self', self.current_type.name) - for param_name, param_type in node.params: - self.register_param(param_name, param_type.value) - - ret_value = self.visit(node.body, scope) - if not isinstance(ret_value, str): - result = self.define_internal_local() - self.register_instruction(cil.AssignNode(result, ret_value)) - self.register_instruction(cil.ReturnNode(result)) - else: - self.register_instruction(cil.ReturnNode(ret_value)) - - self.current_method = None - - @visitor.when(AttrDeclarationNode) - def visit(self, node, scope): - if node.expr: - self.visit(node.expr, scope) - self.register_instruction(cil.SetAttrNode(self.vself.name, node.id, scope.ret_expr, self.current_type)) - elif node.type in self.value_types: - local_value = self.define_internal_local() - self.register_instruction(cil.AllocateNode(node.type, local_value)) - self.register_instruction(cil.SetAttrNode(self.vself.name, node.id, local_value, self.current_type)) - - @visitor.when(AssignNode) - def visit(self, node, scope): - var_info = scope.find_local(node.id) - value, typex = self.visit(node.expr, scope) - if var_info is None: - var_info = scope.find_attribute(node.id) - attributes_names = [attr.name for attr, attr_type in self.current_type.get_all_attributes()] - self.register_instruction(cil.SetAttrNode('self', var_info.name, self.current_type.name, value)) - else: - local_name = self.to_variable_name(var_info.name) - self.register_instruction(cil.AssignNode(local_name, value)) - return value, typex - - @visitor.when(FuncCallNode) - def visit(self, node, scope): - obj, otype = self.visit(node.obj, scope) - - meth = otype.get_method(node.id) - args_node = [cil.ArgNode(obj)] + self.handle_arguments(node.args, scope, meth.param_types) - - rtype = meth.return_type - result = None if isinstance(rtype, VoidType) else self.define_internal_local() - - continue_label = cil.LabelNode(f'continue__{self.index}') - isvoid = self.check_void(obj) - self.register_instruction(cil.IfGoToNode(isvoid, continue_label.label)) - self.register_instruction(cil.ErrorNode('dispatch_error')) - self.register_instruction(continue_label) - - #desambiguar segun sea el llamado, dinamico o estatico - # self.register_instruction(cil.StaticCallNode(node.type, node.id, result, args_node, rtype.name)) - # return result, self._return_type(otype, node) - - # self.register_instruction(cil.DynamicCallNode(self.current_type.name, 'self', node.id, result, args_node, rtype.name)) - # return result, self._return_type(self.current_type, node) - - # if otype in [StringType(), IntType(), BoolType()]: - # self.register_instruction(cil.StaticCallNode(otype.name, node.id, result, args_node, rtype.name)) - # else: - # self.register_instruction(cil.DynamicCallNode(otype.name, obj, node.id, result, args_node, rtype.name)) - # return result, self._return_type(otype, node) - - return - - @visitor.when(IfNode) - def visit(self, node, scope): - vcondition = self.define_internal_local() - value = self.visit(node.condition, scope) - - then_label_node = self.register_label('then_label') - else_label_node = self.register_label('else_label') - continue_label_node = self.register_label('continue_label') - - #If condition GOTO then_label - self.visit(node.condition) - self.register_instruction(cil.GetAttrNode(vcondition, scope.ret_expr, 'value', 'Bool')) - self.register_instruction(cil.IfGoToNode(vcondition, then_label_node.label)) - #GOTO else_label - self.register_instruction(cil.GoToNode(else_label_node.label)) - #Label then_label - self.register_instruction(then_label_node) - self.visit(node.then_expr, scope) - self.register_instruction(cil.AssignNode(vcondition, scope.ret_expr)) - self.register_instruction(cil.GoToNode(continue_label_node.label)) - #Label else_label - self.register_instruction(else_label_node) - self.visit(node.else_expr, scope) - self.register_instruction(cil.AssignNode(vcondition, scope.ret_expr)) - - self.register_instruction(continue_label_node) - scope.ret_expr = vcondition - - @visitor.when(WhileNode) - def visit(self, node, scope): - start_label = cil.LabelNode(f'start__{self.idx}') - end_label = cil.LabelNode(f'end__{self.idx}') - - result = self.define_internal_local() - self.register_instruction(cil.VoidConstantNode(result)) - self.register_instruction(start_label) - - cond, _ = self.visit(node.cond, scope) - self.register_instruction(cil.IfGoToNode(cond, end_label.label)) - expr, typex = self.visit(node.expr, scope) - self.register_instruction(cil.AssignNode(result, expr)) - self.register_instruction(cil.GoToNode(start_label.label)) - self.register_instruction(end_label) - - @visitor.when(BlockNode) - def visit(self, node, scope): - for expr in node.exprs: - value, typex = self.visit(expr, scope) - result = self.define_internal_local() - self.register_instruction(cil.AssignNode(result, value)) - return result, typex - - visitor.when(LetNode) - def visit(self, node, scope): - child_scope = scope.expr_dict[node] - for init in node.let_attrs: - self.visit(init, child_scope) - - expr, typex = self.visit(node.expr, child_scope) - return expr, typex - - visitor.when(CaseNode) - def visit(self, node, scope): - expr, typex = self.visit(node.expr, scope) - - result = self.define_internal_local() - end_label = cil.LabelNode(f'end__{self.idx}') - error_label = cil.LabelNode(f'error__{self.idx}') - - isvoid = self.check_void(expr) - self.register_instruction(cil.IfGoToNode(isvoid, error_label.label)) - try: - new_scope = scope.expr_dict[node] - except: - new_scope = scope - sorted_case_list = self.sort_option_nodes_by_type(node.case_list) - for i, case in enumerate(sorted_case_list): - next_label = cil.LabelNode(f'next__{self.idx}_{i}') - expr_i = self.visit(case, new_scope.create_child(), expr, next_label, typex) - self.register_instruction(cil.AssignNode(result, expr_i)) - self.register_instruction(cil.GoToNode(end_label.label)) - self.register_instruction(next_label) - self.register_instruction(end_label) - return result, typex - - visitor.when(VarNode) - def visit(self, node, scope): - try: - typex = scope.find_local(node.lex).type - name = self.to_var_name(node.lex) - return name, get_type(typex, self.current_type) - except: - var_info = scope.find_attribute(node.lex) - local_var = self.register_local(var_info.name) - self.register_instruction(cil.GetAttrNode('self', var_info.name, self.current_type.name, local_var, var_info.type.name)) - return local_var, get_type(var_info.type, self.current_type) - - visitor.when(NewNode) - def visit(self, node, scope): - instance = self.define_internal_local() - typex = self.context.get_type(node.lex) - typex = get_type(typex, self.current_type) - self.register_instruction(cil.AllocateNode(typex.name, instance)) - - if typex.get_all_attributes(): - self.register_instruction(cil.CallNode(typex.name, typex.name, instance, [cil.ArgNode(instance)], typex.name)) - - return instance, typex - - @visitor.when(PlusNode) - def visit(self, node, scope): - return self._define_binary_node(node, scope, cil.PlusNode) - - @visitor.when(MinusNode) - def visit(self, node, scope): - return self._define_binary_node(node, scope, cil.MinusNode) - - @visitor.when(StarNode) - def visit(self, node, scope): - return self._define_binary_node(node, scope, cil.StarNode) - - @visitor.when(DivNode) - def visit(self, node, scope): - return self._define_binary_node(node, scope, cil.DivNode) - - @visitor.when(LessNode) - def visit(self, node, scope): - return self._define_binary_node(node, scope, cil.LessNode) - - @visitor.when(LessEqNode) - def visit(self, node, scope): - return self._define_binary_node(node, scope, cil.LessEqualNode) - - @visitor.when(EqualNode) - def visit(self, node, scope): - return self._define_binary_node(node, scope, cil.EqualNode) - +import cil_ast as cil +from BaseCOOLToCILVisitor import * +from utils import visitor +from parser.ast import * + +class COOLToCILVisitor(BaseCOOLToCILVisitor): + @visitor.on('node') + def visit(self, node): + pass + + @visitor.when(ProgramNode) + def visit(self, node, scope): + self.current_function = self.register_function('entry') + instance = self.define_internal_local() + result = self.define_internal_local() + self.register_instruction(cil.AllocateNode('Main', instance)) + self.register_instruction(cil.ArgNode(instance)) + + #self.register_instruction(cil.CallNode(self.to_function_name('main', 'Main'), result)) + self.register_instruction(cil.CallNode(result, self.to_function_name('main', 'Main'), [cil.ArgNode(instance)], 'Main')) + + self.register_instruction(cil.ReturnNode(0)) + self.current_function = None + + # self.create_built_in() + + for declaration, child_scope in zip(node.declarations, scope.children): + self.visit(declaration, child_scope) + + return cil.ProgramNode(self.dottypes, self.dotdata, self.dotcode) + + @visitor.when(ClassDeclarationNode) + def visit(self, node, scope): + self.current_type = self.context.get_type(node.id) + + cil_type_node = self.register_type(self.current_type) + cil_type_node.attributes = self.current_type.get_all_attributes() + + if len(cil_type_node.attributes) != 0: + constructor = FuncDeclarationNode(node.token, [], node.token, BlockNode([], node.token)) + func_declarations = [constructor] + self.constructors.append(node.id) + self.current_type.define_method(self.current_type.name, [], [], self.current_type, node.pos) + scopes = [scope] + list(scope.functions.values()) + else: + func_declarations = [] + scopes = list(scope.functions.values()) + + for attr, a_type in cil_type_node.attributes: + cil_type_node.attributes.append((attr.name, self.to_attr_name(attr.name, a_type.name))) + self.initialize_attr(constructor, attr, scope) ## add the initialization code in the constructor + if cil_type_node.attributes: + constructor.body.expr_list.append(SelfNode()) + + for method, mtype in self.current_type.all_methods(): + cil_type_node.methods.append((method.name, self.to_function_name(method.name, mtype.name))) + + func_declarations += [f for f in node.features if isinstance(f, FuncDeclarationNode)] + for feature, child_scope in zip(func_declarations, scopes): + self.visit(feature, child_scope) + + + diff --git a/src/code_generator/cil_ast.py b/src/code_generator/cil_ast.py index 25fa5ac3c..f188ce98e 100644 --- a/src/code_generator/cil_ast.py +++ b/src/code_generator/cil_ast.py @@ -1,205 +1,205 @@ -class Node: - pass - -class ProgramNode(Node): - def __init__(self, dottypes, dotdata, dotcode): - self.dottypes = dottypes - self.dotdata = dotdata - self.dotcode = dotcode - -#.TYPE -class TypeNode(Node): - def __init__(self, name): - self.name = name - self.attributes = [] - self.methods = [] - -#.DATA -class DataNode(Node): - def __init__(self, vname, value): - self.name = vname - self.value = value - -#.CODE -class FunctionNode(Node): - def __init__(self, name, params=[], localvars=[], instructions =[]): - self.name = name - self.params = params - self.localvars = localvars - self.instructions = instructions - -class InstructionNode(Node): - def __init__(self): - pass - -class ParamNode(InstructionNode): - def __init__(self, type, name): - self.type = type - self.name = name - -class LocalNode(InstructionNode): - def __init__(self, name): - self.name = name - -class AssignNode(InstructionNode): - def __init__(self, dest, source): - self.dest = dest - self.source = source - -class ArithExpressionNode(InstructionNode): - def __init__(self, dest, left, right): - self.dest = dest - self.left = left - self.right = right - -#Arith -class PlusNode(ArithExpressionNode): - pass - -class MinusNode(ArithExpressionNode): - pass - -class StarNode(ArithExpressionNode): - pass - -class DivNode(ArithExpressionNode): - pass - -class LessNode(ArithExpressionNode): - pass - -class LessEqualNode(ArithExpressionNode): - pass - -class EqualNode(ArithExpressionNode): - pass - -#Attr -class GetAttrNode(InstructionNode): - def __init__(self, dest, instance, attr, static_type): - self.local_dest = dest - self.instance = instance - self.attr = attr - self.static_type = static_type - -class SetAttrNode(InstructionNode): - def __init__(self, instance, attr, value, static_type): - self.instance = instance - self.attr = attr - self.value = value - self.static_type = static_type - - -#Arrays and Strings -class GetIndexNode(InstructionNode): - pass -class SetIndexNode(InstructionNode): - pass - -#Memory -class AllocateNode(InstructionNode): - def __init__(self, t, dest): - self.type = t - self.local_dest = dest - -class ArrayNode(InstructionNode): - pass - -class TypeOfNode(InstructionNode): - def __init__(self, obj, dest): - self.obj = obj - self.local_dest = dest - -#Jumps -class LabelNode(InstructionNode): - def __init__(self, label): - self.label = label - -class GoToNode(InstructionNode): - def __init__(self, label): - self.label = label - -class IfGoToNode(InstructionNode): - def __init__(self, condition, label): - self.condition = condition - self.label = label - -#Static Invocation -class CallNode(InstructionNode): - def __init__(self, dest, func, args, static_type, ret_type): - self.local_dest = dest - self.function = func - self.args = args - self.static_type = static_type - self.ret_type = ret_type - -#Dynamic Invocation -class VCallNode(InstructionNode): - def __init__(self, instance, dest, func, args, dynamic_type, ret_type): - self.instance = instance - self.local_dest = dest - self.function = func - self.args = args - self.dynamic_type = dynamic_type - self.ret_type = ret_type - - -#Args -class ArgNode(InstructionNode): - def __init__(self, name): - self.name = name - - -#Return -class ReturnNode(InstructionNode): - def __init__(self, value): - self.value = value - -#IO -class LoadNode(InstructionNode): - def __init__(self, dest, msg): - self.local_dest = dest - self.msg = msg - -class LengthNode(InstructionNode): - def __init__(self, dest, arg): - self.local_dest = dest - self.arg = arg - -class ConcatNode(InstructionNode): - def __init__(self, dest, head, tail): - self.local_dest = dest - self.head = head - self.tail = tail - -class PrefixNode(InstructionNode): - def __init__(self, dest, string, n): - self.local_dest = dest - self.string = string - self.n = n - -class SubstringNode(InstructionNode): - def __init__(self, dest, string, begin, final): - self.local_dest = dest - self.begin = begin - self.string = string - self.final = final - -class StrNode(InstructionNode): - def __init__(self, dest, value): - self.local_dest = dest - self.value = value - -class ToStrNode(InstructionNode): - def __init__(self, dest, ivalue): - self.dest = dest - self.ivalue = ivalue - -class ReadNode(InstructionNode): - def __init__(self, dest): - self.local_dest = dest - -class PrintNode(InstructionNode): - def __init__(self, value): - self.value = value - +class Node: + pass + +class ProgramNode(Node): + def __init__(self, dottypes, dotdata, dotcode): + self.dottypes = dottypes + self.dotdata = dotdata + self.dotcode = dotcode + +#.TYPE +class TypeNode(Node): + def __init__(self, name): + self.name = name + self.attributes = [] + self.methods = [] + +#.DATA +class DataNode(Node): + def __init__(self, vname, value): + self.name = vname + self.value = value + +#.CODE +class FunctionNode(Node): + def __init__(self, name, params=[], localvars=[], instructions =[]): + self.name = name + self.params = params + self.localvars = localvars + self.instructions = instructions + +class InstructionNode(Node): + def __init__(self): + pass + +class ParamNode(InstructionNode): + def __init__(self, type, name): + self.type = type + self.name = name + +class LocalNode(InstructionNode): + def __init__(self, name): + self.name = name + +class AssignNode(InstructionNode): + def __init__(self, dest, source): + self.dest = dest + self.source = source + +class ArithExpressionNode(InstructionNode): + def __init__(self, dest, left, right): + self.dest = dest + self.left = left + self.right = right + +#Arith +class PlusNode(ArithExpressionNode): + pass + +class MinusNode(ArithExpressionNode): + pass + +class StarNode(ArithExpressionNode): + pass + +class DivNode(ArithExpressionNode): + pass + +class LessNode(ArithExpressionNode): + pass + +class LessEqualNode(ArithExpressionNode): + pass + +class EqualNode(ArithExpressionNode): + pass + +#Attr +class GetAttrNode(InstructionNode): + def __init__(self, dest, instance, attr, static_type): + self.local_dest = dest + self.instance = instance + self.attr = attr + self.static_type = static_type + +class SetAttrNode(InstructionNode): + def __init__(self, instance, attr, value, static_type): + self.instance = instance + self.attr = attr + self.value = value + self.static_type = static_type + + +#Arrays and Strings +class GetIndexNode(InstructionNode): + pass +class SetIndexNode(InstructionNode): + pass + +#Memory +class AllocateNode(InstructionNode): + def __init__(self, t, dest): + self.type = t + self.local_dest = dest + +class ArrayNode(InstructionNode): + pass + +class TypeOfNode(InstructionNode): + def __init__(self, obj, dest): + self.obj = obj + self.local_dest = dest + +#Jumps +class LabelNode(InstructionNode): + def __init__(self, label): + self.label = label + +class GoToNode(InstructionNode): + def __init__(self, label): + self.label = label + +class IfGoTo(InstructionNode): + def __init__(self, condition, label): + self.condition = condition + self.label = label + +#Static Invocation +class CallNode(InstructionNode): + def __init__(self, dest, func, args, static_type, ret_type): + self.local_dest = dest + self.function = func + self.args = args + self.static_type = static_type + self.ret_type = ret_type + +#Dynamic Invocation +class VCallNode(InstructionNode): + def __init__(self, instance, dest, func, args, dynamic_type, ret_type): + self.instance = instance + self.local_dest = dest + self.function = func + self.args = args + self.dynamic_type = dynamic_type + self.ret_type = ret_type + + +#Args +class ArgNode(InstructionNode): + def __init__(self, name): + self.name = name + + +#Return +class ReturnNode(InstructionNode): + def __init__(self, value): + self.value = value + +#IO +class LoadNode(InstructionNode): + def __init__(self, dest, msg): + self.local_dest = dest + self.msg = msg + +class LengthNode(InstructionNode): + def __init__(self, dest, arg): + self.local_dest = dest + self.arg = arg + +class ConcatNode(InstructionNode): + def __init__(self, dest, head, tail): + self.local_dest = dest + self.head = head + self.tail = tail + +class PrefixNode(InstructionNode): + def __init__(self, dest, string, n): + self.local_dest = dest + self.string = string + self.n = n + +class SubstringNode(InstructionNode): + def __init__(self, dest, string, begin, final): + self.local_dest = dest + self.begin = begin + self.string = string + self.final = final + +class StrNode(InstructionNode): + def __init__(self, dest, value): + self.local_dest = dest + self.value = value + +class ToStrNode(InstructionNode): + def __init__(self, dest, ivalue): + self.dest = dest + self.ivalue = ivalue + +class ReadNode(InstructionNode): + def __init__(self, dest): + self.local_dest = dest + +class PrintNode(InstructionNode): + def __init__(self, value): + self.value = value + diff --git a/src/coolc.sh b/src/coolc.sh index 861584cad..1521cd252 100755 --- a/src/coolc.sh +++ b/src/coolc.sh @@ -1,16 +1,16 @@ -# Incluya aquí las instrucciones necesarias para ejecutar su compilador - -INPUT_FILE=$1 -OUTPUT_FILE=${INPUT_FILE:0: -2}mips - -# Si su compilador no lo hace ya, aquí puede imprimir la información de contacto -echo "LINEA_CON_NOMBRE_Y_VERSION_DEL_COMPILADOR" # TODO: Recuerde cambiar estas -echo "Copyright (c) 2021: Juan Carlos Casteleiro Wong, Olivia González Peña" # TODO: líneas a los valores correctos - -FILE="main.py" - -# Llamar al compilador -python ${FILE} $INPUT_FILE $OUTPUT_FILE - -# Llamar al compilador -# echo "Compiling $INPUT_FILE into $OUTPUT_FILE" +# Incluya aquí las instrucciones necesarias para ejecutar su compilador + +INPUT_FILE=$1 +OUTPUT_FILE=${INPUT_FILE:0: -2}mips + +# Si su compilador no lo hace ya, aquí puede imprimir la información de contacto +echo "LINEA_CON_NOMBRE_Y_VERSION_DEL_COMPILADOR" # TODO: Recuerde cambiar estas +echo "Copyright (c) 2021: Juan Carlos Casteleiro Wong, Olivia González Peña" # TODO: líneas a los valores correctos + +FILE="main.py" + +# Llamar al compilador +python ${FILE} $INPUT_FILE $OUTPUT_FILE + +# Llamar al compilador +# echo "Compiling $INPUT_FILE into $OUTPUT_FILE" diff --git a/src/cparser/parsetab.py b/src/cparser/parsetab.py index 3658bd136..2098fe1a9 100644 --- a/src/cparser/parsetab.py +++ b/src/cparser/parsetab.py @@ -6,9 +6,9 @@ _lr_method = 'LALR' -_lr_signature = 'programARROW ASSIGN AT BOOL CASE CLASS COLON COMMA DIV DOT ELSE EQUAL ESAC FI ID IF IN INHERITS INT ISVOID LBRACE LESS LESSEQ LET LNOT LOOP LPAREN MINUS NEW NOT OF PLUS POOL RBRACE RPAREN SEMICOLON STAR STRING THEN TYPE WHILEprogram : class_listepsilon :class_list : def_class SEMICOLON class_list\n | def_class SEMICOLON def_class : CLASS TYPE LPAREN feature_list RPAREN\n | CLASS TYPE INHERITS TYPE LPAREN feature_list RPARENfeature_list : def_attr SEMICOLON feature_list\n | def_func SEMICOLON feature_list\n | epsilondef_attr : ID COLON TYPE\n | ID COLON TYPE ASSIGN exprdef_func : ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACEparams : param_list\n | param_list_emptyparam_list : param\n | param COMMA param_listparam_list_empty : epsilonparam : ID COLON TYPEexpr : LET let_attrs IN expr\n | CASE expr OF case_list ESAC\n | IF expr THEN expr ELSE expr FI\n | WHILE expr LOOP expr POOLexpr : ID ASSIGN exprexpr : expr AT TYPE DOT ID LPAREN args RPAREN\n | expr DOT ID LPAREN args RPAREN\n | ID LPAREN args RPARENexpr : expr PLUS expr\n | expr MINUS expr\n | expr STAR expr\n | expr DIV expr\n | expr LESS expr\n | expr LESSEQ expr\n | expr EQUAL exprexpr : NOT expr\n | ISVOID expr\n | LNOT exprexpr : LPAREN expr RPARENexpr : atomlet_attrs : def_attr\n | def_attr COMMA let_attrscase_list : case_option SEMICOLON\n | case_option SEMICOLON case_listcase_option : ID COLON TYPE ARROW exprargs : arg_list\n | arg_list_emptyarg_list : expr\n | expr COMMA arg_listarg_list_empty : epsilonatom : INTatom : IDatom : BOOLatom : STRINGatom : NEW TYPEatom : blockblock : LBRACE block_list RBRACE block_list : expr SEMICOLON\n | expr SEMICOLON block_list' +_lr_signature = 'programARROW ASSIGN AT BOOL CASE CLASS COLON COMMA DIV DOT ELSE EQUAL ESAC FI ID IF IN INHERITS INT ISVOID LBRACE LESS LESSEQ LET LNOT LOOP LPAREN MINUS NEW NOT OF PLUS POOL RBRACE RPAREN SEMICOLON STAR STRING THEN TYPE WHILEprogram : class_listepsilon :class_list : def_class SEMICOLON class_list\n | def_class SEMICOLON def_class : CLASS TYPE LBRACE feature_list RBRACE\n | CLASS TYPE INHERITS TYPE LBRACE feature_list RBRACEfeature_list : def_attr SEMICOLON feature_list\n | def_func SEMICOLON feature_list\n | epsilondef_attr : ID COLON TYPE\n | ID COLON TYPE ASSIGN exprdef_func : ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACEparams : param_list\n | param_list_emptyparam_list : param\n | param COMMA param_listparam_list_empty : epsilonparam : ID COLON TYPEexpr : LET let_attrs IN expr\n | CASE expr OF case_list ESAC\n | IF expr THEN expr ELSE expr FI\n | WHILE expr LOOP expr POOLexpr : ID ASSIGN exprexpr : expr AT TYPE DOT ID LPAREN args RPAREN\n | expr DOT ID LPAREN args RPAREN\n | ID LPAREN args RPARENexpr : expr PLUS expr\n | expr MINUS expr\n | expr STAR expr\n | expr DIV expr\n | expr LESS expr\n | expr LESSEQ expr\n | expr EQUAL exprexpr : NOT expr\n | ISVOID expr\n | LNOT exprexpr : LPAREN expr RPARENexpr : atomlet_attrs : def_attr\n | def_attr COMMA let_attrscase_list : case_option SEMICOLON\n | case_option SEMICOLON case_listcase_option : ID COLON TYPE ARROW exprargs : arg_list\n | arg_list_emptyarg_list : expr\n | expr COMMA arg_listarg_list_empty : epsilonatom : INTatom : IDatom : BOOLatom : STRINGatom : NEW TYPEatom : blockblock : LBRACE block_list RBRACE block_list : expr SEMICOLON\n | expr SEMICOLON block_list' -_lr_action_items = {'CLASS':([0,5,],[4,4,]),'$end':([1,2,5,7,],[0,-1,-4,-3,]),'SEMICOLON':([3,11,12,16,24,36,37,38,47,48,49,50,52,75,76,77,78,80,82,90,91,92,93,94,95,96,102,103,106,110,113,122,126,127,129,135,136,137,],[5,17,18,-5,-10,-6,-50,-11,-38,-49,-51,-52,-54,-34,-35,-36,-53,104,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,123,-20,-22,-12,-25,-21,-24,-43,]),'TYPE':([4,9,19,33,51,55,59,124,],[6,15,24,54,78,81,88,131,]),'LPAREN':([6,14,15,32,37,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,89,97,100,101,104,105,107,109,120,125,128,134,],[8,20,21,43,58,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,109,43,43,43,43,43,43,43,128,43,43,43,]),'INHERITS':([6,],[9,]),'ID':([8,17,18,20,21,32,35,39,40,41,42,43,44,45,46,53,57,58,60,61,62,63,64,65,66,67,97,98,99,100,101,104,105,107,108,109,123,125,128,134,],[14,14,14,25,14,37,25,70,37,37,37,37,37,37,37,37,37,37,89,37,37,37,37,37,37,37,37,70,114,37,37,37,37,37,120,37,114,37,37,37,]),'RPAREN':([8,10,13,17,18,20,21,22,23,26,27,28,29,30,31,37,47,48,49,50,52,54,56,58,74,75,76,77,78,82,83,84,85,86,87,90,91,92,93,94,95,96,102,103,106,109,110,119,121,122,126,128,129,133,135,136,],[-2,16,-9,-2,-2,-2,-2,-7,-8,34,-13,-14,-15,-17,36,-50,-38,-49,-51,-52,-54,-18,-16,-2,102,-34,-35,-36,-53,-23,106,-44,-45,-46,-48,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-2,-19,-47,129,-20,-22,-2,-25,136,-21,-24,]),'COLON':([14,25,34,70,114,],[19,33,55,19,124,]),'COMMA':([24,29,37,38,47,48,49,50,52,54,69,75,76,77,78,82,86,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-10,35,-50,-11,-38,-49,-51,-52,-54,-18,98,-34,-35,-36,-53,-23,107,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'IN':([24,37,38,47,48,49,50,52,68,69,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,111,122,126,129,135,136,],[-10,-50,-11,-38,-49,-51,-52,-54,97,-39,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-40,-20,-22,-25,-21,-24,]),'ASSIGN':([24,37,],[32,57,]),'LET':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,]),'CASE':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,]),'IF':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,]),'WHILE':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,]),'NOT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,]),'ISVOID':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,]),'LNOT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,]),'INT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,]),'BOOL':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,]),'STRING':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,]),'NEW':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,]),'LBRACE':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,81,97,100,101,104,105,107,109,125,128,134,],[53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,105,53,53,53,53,53,53,53,53,53,53,]),'AT':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,59,-38,-49,-51,-52,-54,59,59,59,59,59,59,59,-53,59,59,59,59,59,59,59,59,59,59,-37,-55,-26,59,59,59,59,-20,-22,-25,59,-21,-24,59,]),'DOT':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,88,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,60,-38,-49,-51,-52,-54,60,60,60,60,60,60,60,-53,60,60,60,108,60,60,60,60,60,60,60,-37,-55,-26,60,60,60,60,-20,-22,-25,60,-21,-24,60,]),'PLUS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,61,-38,-49,-51,-52,-54,61,61,61,61,61,61,61,-53,61,61,61,61,61,61,61,61,61,61,-37,-55,-26,61,61,61,61,-20,-22,-25,61,-21,-24,61,]),'MINUS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,62,-38,-49,-51,-52,-54,62,62,62,62,62,62,62,-53,62,62,62,62,62,62,62,62,62,62,-37,-55,-26,62,62,62,62,-20,-22,-25,62,-21,-24,62,]),'STAR':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,63,-38,-49,-51,-52,-54,63,63,63,63,63,63,63,-53,63,63,63,63,63,63,63,63,63,63,-37,-55,-26,63,63,63,63,-20,-22,-25,63,-21,-24,63,]),'DIV':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,64,-38,-49,-51,-52,-54,64,64,64,64,64,64,64,-53,64,64,64,64,64,64,64,64,64,64,-37,-55,-26,64,64,64,64,-20,-22,-25,64,-21,-24,64,]),'LESS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,65,-38,-49,-51,-52,-54,65,65,65,65,65,65,65,-53,65,65,65,65,65,65,65,65,65,65,-37,-55,-26,65,65,65,65,-20,-22,-25,65,-21,-24,65,]),'LESSEQ':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,66,-38,-49,-51,-52,-54,66,66,66,66,66,66,66,-53,66,66,66,66,66,66,66,66,66,66,-37,-55,-26,66,66,66,66,-20,-22,-25,66,-21,-24,66,]),'EQUAL':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,67,-38,-49,-51,-52,-54,67,67,67,67,67,67,67,-53,67,67,67,67,67,67,67,67,67,67,-37,-55,-26,67,67,67,67,-20,-22,-25,67,-21,-24,67,]),'OF':([37,47,48,49,50,52,71,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,99,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'THEN':([37,47,48,49,50,52,72,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,100,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'LOOP':([37,47,48,49,50,52,73,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,101,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'ELSE':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,115,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,125,-20,-22,-25,-21,-24,]),'POOL':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,116,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,126,-20,-22,-25,-21,-24,]),'RBRACE':([37,47,48,49,50,52,75,76,77,78,79,82,90,91,92,93,94,95,96,102,103,104,106,110,117,118,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,103,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-56,-26,-19,-57,127,-20,-22,-25,-21,-24,]),'FI':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,132,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,135,-21,-24,]),'ESAC':([112,123,130,],[122,-41,-42,]),'ARROW':([131,],[134,]),} +_lr_action_items = {'CLASS':([0,5,],[4,4,]),'$end':([1,2,5,7,],[0,-1,-4,-3,]),'SEMICOLON':([3,11,12,16,24,36,37,38,47,48,49,50,52,75,76,77,78,80,82,90,91,92,93,94,95,96,102,103,106,110,113,122,126,127,129,135,136,137,],[5,17,18,-5,-10,-6,-50,-11,-38,-49,-51,-52,-54,-34,-35,-36,-53,104,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,123,-20,-22,-12,-25,-21,-24,-43,]),'TYPE':([4,9,19,33,51,55,59,124,],[6,15,24,54,78,81,88,131,]),'LBRACE':([6,15,32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,81,97,100,101,104,105,107,109,125,128,134,],[8,21,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,105,53,53,53,53,53,53,53,53,53,53,]),'INHERITS':([6,],[9,]),'ID':([8,17,18,20,21,32,35,39,40,41,42,43,44,45,46,53,57,58,60,61,62,63,64,65,66,67,97,98,99,100,101,104,105,107,108,109,123,125,128,134,],[14,14,14,25,14,37,25,70,37,37,37,37,37,37,37,37,37,37,89,37,37,37,37,37,37,37,37,70,114,37,37,37,37,37,120,37,114,37,37,37,]),'RBRACE':([8,10,13,17,18,21,22,23,31,37,47,48,49,50,52,75,76,77,78,79,82,90,91,92,93,94,95,96,102,103,104,106,110,117,118,122,126,129,135,136,],[-2,16,-9,-2,-2,-2,-7,-8,36,-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,103,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-56,-26,-19,-57,127,-20,-22,-25,-21,-24,]),'COLON':([14,25,34,70,114,],[19,33,55,19,124,]),'LPAREN':([14,32,37,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,89,97,100,101,104,105,107,109,120,125,128,134,],[20,43,58,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,109,43,43,43,43,43,43,43,128,43,43,43,]),'RPAREN':([20,26,27,28,29,30,37,47,48,49,50,52,54,56,58,74,75,76,77,78,82,83,84,85,86,87,90,91,92,93,94,95,96,102,103,106,109,110,119,121,122,126,128,129,133,135,136,],[-2,34,-13,-14,-15,-17,-50,-38,-49,-51,-52,-54,-18,-16,-2,102,-34,-35,-36,-53,-23,106,-44,-45,-46,-48,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-2,-19,-47,129,-20,-22,-2,-25,136,-21,-24,]),'COMMA':([24,29,37,38,47,48,49,50,52,54,69,75,76,77,78,82,86,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-10,35,-50,-11,-38,-49,-51,-52,-54,-18,98,-34,-35,-36,-53,-23,107,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'IN':([24,37,38,47,48,49,50,52,68,69,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,111,122,126,129,135,136,],[-10,-50,-11,-38,-49,-51,-52,-54,97,-39,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-40,-20,-22,-25,-21,-24,]),'ASSIGN':([24,37,],[32,57,]),'LET':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,]),'CASE':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,]),'IF':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,]),'WHILE':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,]),'NOT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,]),'ISVOID':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,]),'LNOT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,]),'INT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,]),'BOOL':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,]),'STRING':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,]),'NEW':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,]),'AT':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,59,-38,-49,-51,-52,-54,59,59,59,59,59,59,59,-53,59,59,59,59,59,59,59,59,59,59,-37,-55,-26,59,59,59,59,-20,-22,-25,59,-21,-24,59,]),'DOT':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,88,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,60,-38,-49,-51,-52,-54,60,60,60,60,60,60,60,-53,60,60,60,108,60,60,60,60,60,60,60,-37,-55,-26,60,60,60,60,-20,-22,-25,60,-21,-24,60,]),'PLUS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,61,-38,-49,-51,-52,-54,61,61,61,61,61,61,61,-53,61,61,61,61,61,61,61,61,61,61,-37,-55,-26,61,61,61,61,-20,-22,-25,61,-21,-24,61,]),'MINUS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,62,-38,-49,-51,-52,-54,62,62,62,62,62,62,62,-53,62,62,62,62,62,62,62,62,62,62,-37,-55,-26,62,62,62,62,-20,-22,-25,62,-21,-24,62,]),'STAR':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,63,-38,-49,-51,-52,-54,63,63,63,63,63,63,63,-53,63,63,63,63,63,63,63,63,63,63,-37,-55,-26,63,63,63,63,-20,-22,-25,63,-21,-24,63,]),'DIV':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,64,-38,-49,-51,-52,-54,64,64,64,64,64,64,64,-53,64,64,64,64,64,64,64,64,64,64,-37,-55,-26,64,64,64,64,-20,-22,-25,64,-21,-24,64,]),'LESS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,65,-38,-49,-51,-52,-54,65,65,65,65,65,65,65,-53,65,65,65,65,65,65,65,65,65,65,-37,-55,-26,65,65,65,65,-20,-22,-25,65,-21,-24,65,]),'LESSEQ':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,66,-38,-49,-51,-52,-54,66,66,66,66,66,66,66,-53,66,66,66,66,66,66,66,66,66,66,-37,-55,-26,66,66,66,66,-20,-22,-25,66,-21,-24,66,]),'EQUAL':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,67,-38,-49,-51,-52,-54,67,67,67,67,67,67,67,-53,67,67,67,67,67,67,67,67,67,67,-37,-55,-26,67,67,67,67,-20,-22,-25,67,-21,-24,67,]),'OF':([37,47,48,49,50,52,71,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,99,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'THEN':([37,47,48,49,50,52,72,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,100,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'LOOP':([37,47,48,49,50,52,73,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,101,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'ELSE':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,115,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,125,-20,-22,-25,-21,-24,]),'POOL':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,116,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,126,-20,-22,-25,-21,-24,]),'FI':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,132,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,135,-21,-24,]),'ESAC':([112,123,130,],[122,-41,-42,]),'ARROW':([131,],[134,]),} _lr_action = {} for _k, _v in _lr_action_items.items(): @@ -31,8 +31,8 @@ ('epsilon -> ','epsilon',0,'p_epsilon','parser.py',32), ('class_list -> def_class SEMICOLON class_list','class_list',3,'p_class_list','parser.py',35), ('class_list -> def_class SEMICOLON','class_list',2,'p_class_list','parser.py',36), - ('def_class -> CLASS TYPE LPAREN feature_list RPAREN','def_class',5,'p_def_class','parser.py',40), - ('def_class -> CLASS TYPE INHERITS TYPE LPAREN feature_list RPAREN','def_class',7,'p_def_class','parser.py',41), + ('def_class -> CLASS TYPE LBRACE feature_list RBRACE','def_class',5,'p_def_class','parser.py',40), + ('def_class -> CLASS TYPE INHERITS TYPE LBRACE feature_list RBRACE','def_class',7,'p_def_class','parser.py',41), ('feature_list -> def_attr SEMICOLON feature_list','feature_list',3,'p_feature_list','parser.py',51), ('feature_list -> def_func SEMICOLON feature_list','feature_list',3,'p_feature_list','parser.py',52), ('feature_list -> epsilon','feature_list',1,'p_feature_list','parser.py',53), diff --git a/src/main.py b/src/main.py index 4c1e0e826..506c548a3 100644 --- a/src/main.py +++ b/src/main.py @@ -22,7 +22,7 @@ def main(_input, _output): if __name__ == "__main__": - path = '/mnt/d/UH/4to Año/EVEA/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/parser/operation1.cl' + path = '/mnt/d/UH/4to Año/EVEA/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/parser/conditional4.cl' _input = sys.argv[1] if len(sys.argv) > 1 else path _output = sys.argv[2] if len(sys.argv) > 2 else None diff --git a/src/makefile b/src/makefile index cd83fb352..30df993f5 100644 --- a/src/makefile +++ b/src/makefile @@ -1,12 +1,12 @@ -.PHONY: clean - -main: - # Compiling the compiler :) - -clean: - rm -rf build/* - rm -rf ../tests/*/*.mips - -test: - pytest ../tests -v --tb=short -m=${TAG} - +.PHONY: clean + +main: + # Compiling the compiler :) + +clean: + rm -rf build/* + rm -rf ../tests/*/*.mips + +test: + pytest ../tests -v --tb=short -m=${TAG} + diff --git a/src/semantic/semantic.py b/src/semantic/semantic.py index b66abab7f..dad224b9a 100644 --- a/src/semantic/semantic.py +++ b/src/semantic/semantic.py @@ -1,326 +1,326 @@ -from utils.errors import SemanticError -from collections import OrderedDict - - -class Attribute: - def __init__(self, name, typex, index, tok=None): - self.name = name - self.type = typex - self.index = index - self.expr = None - - def __str__(self): - return f'[attrib] {self.name} : {self.type.name};' - - def __repr__(self): - return str(self) - - -class Method: - def __init__(self, name, param_names, params_types, return_type): - self.name = name - self.param_names = param_names - self.param_types = params_types - self.return_type = return_type - - def __str__(self): - params = ', '.join(f'{n}:{t.name}' for n, t in zip( - self.param_names, self.param_types)) - return f'[method] {self.name}({params}): {self.return_type.name};' - - def __eq__(self, other): - return other.name == self.name and \ - other.return_type == self.return_type and \ - other.param_types == self.param_types - - -# class MethodError(Method): -# def __init__(self, name, param_names, param_types, return_types): -# super().__init__(name, param_names, param_types, return_types) - -# def __str__(self): -# return f'[method] {self.name} ERROR' - - -class Type: - def __init__(self, name: str, pos, parent=True): - if name == 'ObjectType': - return ObjectType(pos) - self.name = name - self.attributes = {} - self.methods = {} - if parent: - self.parent = ObjectType(pos) - else: - self.parent = None - self.pos = pos - - def set_parent(self, parent): - if type(self.parent) != ObjectType and self.parent is not None: - error_msg = f'Parent type is already set for {self.name}.' - raise SemanticError(error_msg, *self.pos) - self.parent = parent - - def get_attribute(self, name: str, pos) -> Attribute: - try: - return self.attributes[name] - except KeyError: - if self.parent is None: - error_msg = f'Attribute {name} is not defined in {self.name}.' - raise SemanticError(error_msg, *pos) - try: - return self.parent.get_attribute(name, pos) - except: - error_msg = f'Attribute {name} is not defined in {self.name}.' - raise SemanticError(error_msg, *pos) - - def define_attribute(self, name: str, typex, pos): - try: - self.attributes[name] - except KeyError: - try: - self.get_attribute(name, pos) - except: - self.attributes[name] = attribute = Attribute( - name, typex, len(self.attributes)) - return attribute - else: - error_msg = f'Attribute {name} is an attribute of an inherit class.' - raise SemanticError(error_msg, *pos) - else: - error_msg = f'Attribute {name} is multiply defined in class.' - raise SemanticError(error_msg, *pos) - - def get_method(self, name: str, pos) -> Method: - try: - return self.methods[name] - except KeyError: - error_msg = f'Method {name} is not defined in {self.name}.' - if self.parent is None: - raise SemanticError(error_msg, *pos) - try: - return self.parent.get_method(name, pos) - except: - raise SemanticError(error_msg, *pos) - - def define_method(self, name: str, param_names: list, param_types: list, return_type, pos=(0, 0)): - if name in self.methods: - error_msg = f'Method {name} is multiply defined' - raise SemanticError(error_msg, *pos) - - method = self.methods[name] = Method( - name, param_names, param_types, return_type) - return method - - def change_type(self, method, nparm, newtype): - idx = method.param_names.index(nparm) - method.param_types[idx] = newtype - - def all_attributes(self, clean=True): - plain = OrderedDict() if self.parent is None else self.parent.all_attributes(False) - for attr in self.attributes.values(): - plain[attr.name] = (attr, self) - return plain.values() if clean else plain - - def all_methods(self, clean=True): - plain = OrderedDict() if self.parent is None else self.parent.all_methods(False) - for method in self.methods.values(): - plain[method.name] = (method, self) - return plain.values() if clean else plain - - def conforms_to(self, other): - return other.bypass() or self == other or self.parent is not None and self.parent.conforms_to(other) - - def bypass(self): - return False - - def __str__(self): - output = f'type {self.name}' - parent = '' if self.parent is None else f' : {self.parent.name}' - output += parent - output += ' {' - output += '\n\t' if self.attributes or self.methods else '' - output += '\n\t'.join(str(x) for x in self.attributes.values()) - output += '\n\t' if self.attributes else '' - output += '\n\t'.join(str(x) for x in self.methods.values()) - output += '\n' if self.methods else '' - output += '}\n' - return output - - def __repr__(self): - return str(self) - - -class ErrorType(Type): - def __init__(self, pos=(0, 0)): - Type.__init__(self, '', pos) - - def conforms_to(self, other): - return True - - def bypass(self): - return True - - def __eq__(self, other): - return isinstance(other, ErrorType) - - def __ne__(self, other): - return not isinstance(other, ErrorType) - - -class VoidType(Type): - def __init__(self, pos=(0, 0)): - Type.__init__(self, 'Void', pos) - - def conforms_to(self, other): - return True - - def bypass(self): - return True - - def __eq__(self, other): - return isinstance(other, VoidType) - - -class BoolType(Type): - def __init__(self, pos=(0, 0)): - self.name = 'Bool' - self.attributes = {} - self.methods = {} - self.parent = None - self.pos = pos - self.init_methods() - - def init_methods(self): - self.define_method('abort', [], [], self) - self.define_method('type_name', [], [], StringType()) - self.define_method('copy', [], [], SelfType()) - - def conforms_to(self, other): - return other.name == 'Object' or other.name == self.name - - def __eq__(self, other): - return other.name == self.name or isinstance(other, BoolType) - - def __ne__(self, other): - return other.name != self.name and not isinstance(other, BoolType) - - -class SelfType(Type): - def __init__(self, pos=(0, 0)): - self.name = 'Self' - self.attributes = {} - self.methods = {} - self.parent = None - self.pos = pos - - def __eq__(self, other): - return other.name == self.name or isinstance(other, SelfType) - - def __ne__(self, other): - return other.name != self.name and not isinstance(other, SelfType) - - -class IntType(Type): - def __init__(self, pos=(0, 0)): - self.name = 'Int' - self.attributes = {} - self.methods = {} - self.parent = None - self.pos = pos - self.init_methods() - - def init_methods(self): - self.define_method('abort', [], [], self) - self.define_method('type_name', [], [], Type('String', (0, 0), False)) - self.define_method('copy', [], [], SelfType()) - - def conforms_to(self, other): - return other.name == 'Object' or other.name == self.name - - def __eq__(self, other): - return other.name == self.name or isinstance(other, IntType) - - def __ne__(self, other): - return other.name != self.name and not isinstance(other, IntType) - - -class StringType(Type): - def __init__(self, pos=(0, 0)): - self.name = 'String' - self.attributes = {} - self.methods = {} - self.parent = None - self.pos = pos - self.init_methods() - - def init_methods(self): - self.define_method('abort', [], [], self) - self.define_method('type_name', [], [], self) - self.define_method('copy', [], [], SelfType()) - self.define_method('length', [], [], IntType()) - self.define_method('concat', ['s'], [self], self) - self.define_method('substr', ['i', 'l'], [IntType(), IntType()], self) - - def conforms_to(self, other): - return other.name == 'Object' or other.name == self.name - - def __eq__(self, other): - return other.name == self.name or isinstance(other, StringType) - - def __ne__(self, other): - return other.name != self.name and not isinstance(other, StringType) - - -class ObjectType(Type): - def __init__(self, pos=(0, 0)): - self.name = 'Object' - self.attributes = {} - self.methods = {} - self.parent = None - self.pos = pos - self.init_methods() - - def init_methods(self): - self.define_method('abort', [], [], self) - self.define_method('type_name', [], [], StringType()) - self.define_method('copy', [], [], SelfType()) - - def __eq__(self, other): - return other.name == self.name or isinstance(other, ObjectType) - - def __ne__(self, other): - return other.name != self.name and not isinstance(other, ObjectType) - - -# class AutoType(Type): -# def __init__(self): -# Type.__init__(self, 'AUTO_TYPE') - -# def __eq__(self, other): -# return other.name == self.name or isinstance(other, AutoType) - -# def __ne__(self, other): -# return other.name != self.name and not isinstance(other, AutoType) - - -class IOType(Type): - def __init__(self, pos=(0, 0)): - self.name = 'IO' - self.attributes = {} - self.methods = {} - self.parent = ObjectType(pos) - self.pos = pos - self.init_methods() - - def init_methods(self): - self.define_method('out_string', ['x'], [StringType()], SelfType()) - self.define_method('out_int', ['x'], [IntType()], SelfType()) - self.define_method('in_string', [], [], StringType()) - self.define_method('in_int', [], [], IntType()) - - def __eq__(self, other): - return other.name == self.name or isinstance(other, IOType) - - def __ne__(self, other): - return other.name != self.name and not isinstance(other, IOType) +from utils.errors import SemanticError +from collections import OrderedDict + + +class Attribute: + def __init__(self, name, typex, index, tok=None): + self.name = name + self.type = typex + self.index = index + self.expr = None + + def __str__(self): + return f'[attrib] {self.name} : {self.type.name};' + + def __repr__(self): + return str(self) + + +class Method: + def __init__(self, name, param_names, params_types, return_type): + self.name = name + self.param_names = param_names + self.param_types = params_types + self.return_type = return_type + + def __str__(self): + params = ', '.join(f'{n}:{t.name}' for n, t in zip( + self.param_names, self.param_types)) + return f'[method] {self.name}({params}): {self.return_type.name};' + + def __eq__(self, other): + return other.name == self.name and \ + other.return_type == self.return_type and \ + other.param_types == self.param_types + + +# class MethodError(Method): +# def __init__(self, name, param_names, param_types, return_types): +# super().__init__(name, param_names, param_types, return_types) + +# def __str__(self): +# return f'[method] {self.name} ERROR' + + +class Type: + def __init__(self, name: str, pos, parent=True): + if name == 'ObjectType': + return ObjectType(pos) + self.name = name + self.attributes = {} + self.methods = {} + if parent: + self.parent = ObjectType(pos) + else: + self.parent = None + self.pos = pos + + def set_parent(self, parent): + if type(self.parent) != ObjectType and self.parent is not None: + error_msg = f'Parent type is already set for {self.name}.' + raise SemanticError(error_msg, *self.pos) + self.parent = parent + + def get_attribute(self, name: str, pos) -> Attribute: + try: + return self.attributes[name] + except KeyError: + if self.parent is None: + error_msg = f'Attribute {name} is not defined in {self.name}.' + raise SemanticError(error_msg, *pos) + try: + return self.parent.get_attribute(name, pos) + except: + error_msg = f'Attribute {name} is not defined in {self.name}.' + raise SemanticError(error_msg, *pos) + + def define_attribute(self, name: str, typex, pos): + try: + self.attributes[name] + except KeyError: + try: + self.get_attribute(name, pos) + except: + self.attributes[name] = attribute = Attribute( + name, typex, len(self.attributes)) + return attribute + else: + error_msg = f'Attribute {name} is an attribute of an inherit class.' + raise SemanticError(error_msg, *pos) + else: + error_msg = f'Attribute {name} is multiply defined in class.' + raise SemanticError(error_msg, *pos) + + def get_method(self, name: str, pos) -> Method: + try: + return self.methods[name] + except KeyError: + error_msg = f'Method {name} is not defined in {self.name}.' + if self.parent is None: + raise SemanticError(error_msg, *pos) + try: + return self.parent.get_method(name, pos) + except: + raise SemanticError(error_msg, *pos) + + def define_method(self, name: str, param_names: list, param_types: list, return_type, pos=(0, 0)): + if name in self.methods: + error_msg = f'Method {name} is multiply defined' + raise SemanticError(error_msg, *pos) + + method = self.methods[name] = Method( + name, param_names, param_types, return_type) + return method + + def change_type(self, method, nparm, newtype): + idx = method.param_names.index(nparm) + method.param_types[idx] = newtype + + def all_attributes(self, clean=True): + plain = OrderedDict() if self.parent is None else self.parent.all_attributes(False) + for attr in self.attributes.values(): + plain[attr.name] = (attr, self) + return plain.values() if clean else plain + + def all_methods(self, clean=True): + plain = OrderedDict() if self.parent is None else self.parent.all_methods(False) + for method in self.methods.values(): + plain[method.name] = (method, self) + return plain.values() if clean else plain + + def conforms_to(self, other): + return other.bypass() or self == other or self.parent is not None and self.parent.conforms_to(other) + + def bypass(self): + return False + + def __str__(self): + output = f'type {self.name}' + parent = '' if self.parent is None else f' : {self.parent.name}' + output += parent + output += ' {' + output += '\n\t' if self.attributes or self.methods else '' + output += '\n\t'.join(str(x) for x in self.attributes.values()) + output += '\n\t' if self.attributes else '' + output += '\n\t'.join(str(x) for x in self.methods.values()) + output += '\n' if self.methods else '' + output += '}\n' + return output + + def __repr__(self): + return str(self) + + +class ErrorType(Type): + def __init__(self, pos=(0, 0)): + Type.__init__(self, '', pos) + + def conforms_to(self, other): + return True + + def bypass(self): + return True + + def __eq__(self, other): + return isinstance(other, ErrorType) + + def __ne__(self, other): + return not isinstance(other, ErrorType) + + +class VoidType(Type): + def __init__(self, pos=(0, 0)): + Type.__init__(self, 'Void', pos) + + def conforms_to(self, other): + return True + + def bypass(self): + return True + + def __eq__(self, other): + return isinstance(other, VoidType) + + +class BoolType(Type): + def __init__(self, pos=(0, 0)): + self.name = 'Bool' + self.attributes = {} + self.methods = {} + self.parent = None + self.pos = pos + self.init_methods() + + def init_methods(self): + self.define_method('abort', [], [], self) + self.define_method('type_name', [], [], StringType()) + self.define_method('copy', [], [], SelfType()) + + def conforms_to(self, other): + return other.name == 'Object' or other.name == self.name + + def __eq__(self, other): + return other.name == self.name or isinstance(other, BoolType) + + def __ne__(self, other): + return other.name != self.name and not isinstance(other, BoolType) + + +class SelfType(Type): + def __init__(self, pos=(0, 0)): + self.name = 'Self' + self.attributes = {} + self.methods = {} + self.parent = None + self.pos = pos + + def __eq__(self, other): + return other.name == self.name or isinstance(other, SelfType) + + def __ne__(self, other): + return other.name != self.name and not isinstance(other, SelfType) + + +class IntType(Type): + def __init__(self, pos=(0, 0)): + self.name = 'Int' + self.attributes = {} + self.methods = {} + self.parent = None + self.pos = pos + self.init_methods() + + def init_methods(self): + self.define_method('abort', [], [], self) + self.define_method('type_name', [], [], Type('String', (0, 0), False)) + self.define_method('copy', [], [], SelfType()) + + def conforms_to(self, other): + return other.name == 'Object' or other.name == self.name + + def __eq__(self, other): + return other.name == self.name or isinstance(other, IntType) + + def __ne__(self, other): + return other.name != self.name and not isinstance(other, IntType) + + +class StringType(Type): + def __init__(self, pos=(0, 0)): + self.name = 'String' + self.attributes = {} + self.methods = {} + self.parent = None + self.pos = pos + self.init_methods() + + def init_methods(self): + self.define_method('abort', [], [], self) + self.define_method('type_name', [], [], self) + self.define_method('copy', [], [], SelfType()) + self.define_method('length', [], [], IntType()) + self.define_method('concat', ['s'], [self], self) + self.define_method('substr', ['i', 'l'], [IntType(), IntType()], self) + + def conforms_to(self, other): + return other.name == 'Object' or other.name == self.name + + def __eq__(self, other): + return other.name == self.name or isinstance(other, StringType) + + def __ne__(self, other): + return other.name != self.name and not isinstance(other, StringType) + + +class ObjectType(Type): + def __init__(self, pos=(0, 0)): + self.name = 'Object' + self.attributes = {} + self.methods = {} + self.parent = None + self.pos = pos + self.init_methods() + + def init_methods(self): + self.define_method('abort', [], [], self) + self.define_method('type_name', [], [], StringType()) + self.define_method('copy', [], [], SelfType()) + + def __eq__(self, other): + return other.name == self.name or isinstance(other, ObjectType) + + def __ne__(self, other): + return other.name != self.name and not isinstance(other, ObjectType) + + +# class AutoType(Type): +# def __init__(self): +# Type.__init__(self, 'AUTO_TYPE') + +# def __eq__(self, other): +# return other.name == self.name or isinstance(other, AutoType) + +# def __ne__(self, other): +# return other.name != self.name and not isinstance(other, AutoType) + + +class IOType(Type): + def __init__(self, pos=(0, 0)): + self.name = 'IO' + self.attributes = {} + self.methods = {} + self.parent = ObjectType(pos) + self.pos = pos + self.init_methods() + + def init_methods(self): + self.define_method('out_string', ['x'], [StringType()], SelfType()) + self.define_method('out_int', ['x'], [IntType()], SelfType()) + self.define_method('in_string', [], [], StringType()) + self.define_method('in_int', [], [], IntType()) + + def __eq__(self, other): + return other.name == self.name or isinstance(other, IOType) + + def __ne__(self, other): + return other.name != self.name and not isinstance(other, IOType) diff --git a/src/semantic/types.py b/src/semantic/types.py index 4970d29ab..b455aa253 100644 --- a/src/semantic/types.py +++ b/src/semantic/types.py @@ -1,111 +1,111 @@ -from utils.errors import SemanticError - - -class Attribute: - def __init__(self, name, typex, index): - self.name = name - self.type = typex - self.index = index - self.expr = None - - def __str__(self): - return f'[attr] {self.name} : {self.type.name}' - - def __repr__(self): - return str(self) - - -class Method: - def __init__(self, name, param_names, param_types, return_type): - self.name = name - self.param_names = param_names - self.param_types = param_types - self.return_type = return_type - - -class Type: - def __init__(self, name, position, parent=True): - if name == 'ObjectType': - return ObjectType(position) - self.name = name - self.attributes = {} - self.methods = {} - self.position = position - if parent: - self.parent = ObjectType(position) - else: - self.parent = None - - def set_parent(self, parent): - if type(self.parent) != ObjectType and self.parent is not None: - line, column = self.position - raise SemanticError( - f'Parent already defined for {self.name}', line, column) - self.parent = parent - - def get_attribute(self, name, position): - try: - return self.attributes[name] - except KeyError: - if self.parent is None: - line, column = self.position - raise SemanticError( - f'Attribute {name} is not defined in {self.name}', line, column) - try: - return self.parent.get_attribute(name, position) - except: - line, column = self.position - raise SemanticError( - f'Attribute {name} is not defined in {self.name}', line, column) - - def define_attribute(self, name, typex, position): - try: - self.attributes[name] - except KeyError: - try: - self.get_attribute(name, position) - except SemanticError(): - attribute = Attribute(name, typex, len(self.attributes)) - self.attributes[name] = attribute - return attribute - else: - line, column = self.position - raise SemanticError( - f'Attribute {name} is an attribute of an inherited class', line, column) - else: - line, column = self.position - raise SemanticError( - f'Attribute {name} is already defined', line, column) - - def get_method(self, name, position): - try: - return self.methods[name] - except KeyError: - if self.parent is None: - line, column = self.position - raise SemanticError( - f'Method {name} is not defined in {self.name}', line, column) - try: - return self.parent.get_method(name, position) - except: - line, column = self.position - raise SemanticError( - f'Method {name} is not defined in {self.name}', line, column) - - def define_method(self, name, param_names, param_types, return_type, position=(0, 0)): - if name in self.methods: - line, column = self.position - raise SemanticError( - f'Method {name} is already defined', line, column) - - method = self.methods[name] = Method(name, param_names, param_types, return_type) - return method - - -class ObjectType(Type): - def __init__(self, position=(0, 0)): - self.name = 'Object' - self.attributes = {} - self.methods = {} - self.parent = None - self.position = position +from utils.errors import SemanticError + + +class Attribute: + def __init__(self, name, typex, index): + self.name = name + self.type = typex + self.index = index + self.expr = None + + def __str__(self): + return f'[attr] {self.name} : {self.type.name}' + + def __repr__(self): + return str(self) + + +class Method: + def __init__(self, name, param_names, param_types, return_type): + self.name = name + self.param_names = param_names + self.param_types = param_types + self.return_type = return_type + + +class Type: + def __init__(self, name, position, parent=True): + if name == 'ObjectType': + return ObjectType(position) + self.name = name + self.attributes = {} + self.methods = {} + self.position = position + if parent: + self.parent = ObjectType(position) + else: + self.parent = None + + def set_parent(self, parent): + if type(self.parent) != ObjectType and self.parent is not None: + line, column = self.position + raise SemanticError( + f'Parent already defined for {self.name}', line, column) + self.parent = parent + + def get_attribute(self, name, position): + try: + return self.attributes[name] + except KeyError: + if self.parent is None: + line, column = self.position + raise SemanticError( + f'Attribute {name} is not defined in {self.name}', line, column) + try: + return self.parent.get_attribute(name, position) + except: + line, column = self.position + raise SemanticError( + f'Attribute {name} is not defined in {self.name}', line, column) + + def define_attribute(self, name, typex, position): + try: + self.attributes[name] + except KeyError: + try: + self.get_attribute(name, position) + except SemanticError(): + attribute = Attribute(name, typex, len(self.attributes)) + self.attributes[name] = attribute + return attribute + else: + line, column = self.position + raise SemanticError( + f'Attribute {name} is an attribute of an inherited class', line, column) + else: + line, column = self.position + raise SemanticError( + f'Attribute {name} is already defined', line, column) + + def get_method(self, name, position): + try: + return self.methods[name] + except KeyError: + if self.parent is None: + line, column = self.position + raise SemanticError( + f'Method {name} is not defined in {self.name}', line, column) + try: + return self.parent.get_method(name, position) + except: + line, column = self.position + raise SemanticError( + f'Method {name} is not defined in {self.name}', line, column) + + def define_method(self, name, param_names, param_types, return_type, position=(0, 0)): + if name in self.methods: + line, column = self.position + raise SemanticError( + f'Method {name} is already defined', line, column) + + method = self.methods[name] = Method(name, param_names, param_types, return_type) + return method + + +class ObjectType(Type): + def __init__(self, position=(0, 0)): + self.name = 'Object' + self.attributes = {} + self.methods = {} + self.parent = None + self.position = position diff --git a/src/semantic/visitors/type_collector.py b/src/semantic/visitors/type_collector.py index 795e94dd6..90e806da6 100644 --- a/src/semantic/visitors/type_collector.py +++ b/src/semantic/visitors/type_collector.py @@ -1,25 +1,25 @@ -from utils import visitor -from utils.ast import ProgramNode, ClassDeclarationNode -from semantic. - - - - - -class TypeCollector(object): - def __init__(self, errors = []): - self.context = None - self.errors = errors - - @visitor.on('node') - def visit(self, node): - pass - - - @visitor.when(ProgramNode) - def visit(self, node): - self.context = Context() - - @visitor.when(ClassDeclarationNode) - def visit(self, node): - pass +from utils import visitor +from utils.ast import ProgramNode, ClassDeclarationNode +from semantic. + + + + + +class TypeCollector(object): + def __init__(self, errors = []): + self.context = None + self.errors = errors + + @visitor.on('node') + def visit(self, node): + pass + + + @visitor.when(ProgramNode) + def visit(self, node): + self.context = Context() + + @visitor.when(ClassDeclarationNode) + def visit(self, node): + pass diff --git a/src/test.cl b/src/test.cl index d01d577f2..2cbd6819c 100644 --- a/src/test.cl +++ b/src/test.cl @@ -1,10 +1,10 @@ -class Main inherits IO { - a : String <- case 1 of - n : Main => n.type_name(); - a : Int => a.type_name(); - esac; - - main(): IO { - out_string(a) - }; +class Main inherits IO { + a : String <- case 1 of + n : Main => n.type_name(); + a : Int => a.type_name(); + esac; + + main(): IO { + out_string(a) + }; }; \ No newline at end of file diff --git a/src/utils/__init__.py b/src/utils/__init__.py index 3676a62d6..1a7eeac05 100644 --- a/src/utils/__init__.py +++ b/src/utils/__init__.py @@ -1,2 +1,2 @@ -from .utils import find_column, Token +from .utils import find_column, Token from .errors import LexicographicError, SemanticError, SyntacticError \ No newline at end of file diff --git a/src/utils/ast.py b/src/utils/ast.py index 41d19f021..c69a682f4 100644 --- a/src/utils/ast.py +++ b/src/utils/ast.py @@ -176,9 +176,6 @@ class AtomicNode(UnaryNode): class IsVoidNode(UnaryNode): pass -class SelfNode(UnaryNode): - pass - # ---------------- Constant Nodes ------------------ diff --git a/src/utils/visitor.py b/src/utils/visitor.py index aece92ec4..d4f2e4d7c 100644 --- a/src/utils/visitor.py +++ b/src/utils/visitor.py @@ -1,82 +1,82 @@ -# The MIT License (MIT) -# -# Copyright (c) 2013 Curtis Schlak -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - -import inspect - -__all__ = ['on', 'when'] - - -def on(param_name): - def f(fn): - dispatcher = Dispatcher(param_name, fn) - return dispatcher - return f - - -def when(param_type): - def f(fn): - frame = inspect.currentframe().f_back - func_name = fn.func_name if 'func_name' in dir(fn) else fn.__name__ - dispatcher = frame.f_locals[func_name] - if not isinstance(dispatcher, Dispatcher): - dispatcher = dispatcher.dispatcher - dispatcher.add_target(param_type, fn) - - def ff(*args, **kw): - return dispatcher(*args, **kw) - ff.dispatcher = dispatcher - return ff - return f - - -class Dispatcher(object): - def __init__(self, param_name, fn): - frame = inspect.currentframe().f_back.f_back - top_level = frame.f_locals == frame.f_globals - self.param_index = self.__argspec(fn).args.index(param_name) - self.param_name = param_name - self.targets = {} - - def __call__(self, *args, **kw): - typ = args[self.param_index].__class__ - d = self.targets.get(typ) - if d is not None: - return d(*args, **kw) - else: - issub = issubclass - t = self.targets - ks = t.keys() - ans = [t[k](*args, **kw) for k in ks if issub(typ, k)] - if len(ans) == 1: - return ans.pop() - return ans - - def add_target(self, typ, target): - self.targets[typ] = target - - @staticmethod - def __argspec(fn): - # Support for Python 3 type hints requires inspect.getfullargspec - if hasattr(inspect, 'getfullargspec'): - return inspect.getfullargspec(fn) - else: - return inspect.getargspec(fn) +# The MIT License (MIT) +# +# Copyright (c) 2013 Curtis Schlak +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +import inspect + +__all__ = ['on', 'when'] + + +def on(param_name): + def f(fn): + dispatcher = Dispatcher(param_name, fn) + return dispatcher + return f + + +def when(param_type): + def f(fn): + frame = inspect.currentframe().f_back + func_name = fn.func_name if 'func_name' in dir(fn) else fn.__name__ + dispatcher = frame.f_locals[func_name] + if not isinstance(dispatcher, Dispatcher): + dispatcher = dispatcher.dispatcher + dispatcher.add_target(param_type, fn) + + def ff(*args, **kw): + return dispatcher(*args, **kw) + ff.dispatcher = dispatcher + return ff + return f + + +class Dispatcher(object): + def __init__(self, param_name, fn): + frame = inspect.currentframe().f_back.f_back + top_level = frame.f_locals == frame.f_globals + self.param_index = self.__argspec(fn).args.index(param_name) + self.param_name = param_name + self.targets = {} + + def __call__(self, *args, **kw): + typ = args[self.param_index].__class__ + d = self.targets.get(typ) + if d is not None: + return d(*args, **kw) + else: + issub = issubclass + t = self.targets + ks = t.keys() + ans = [t[k](*args, **kw) for k in ks if issub(typ, k)] + if len(ans) == 1: + return ans.pop() + return ans + + def add_target(self, typ, target): + self.targets[typ] = target + + @staticmethod + def __argspec(fn): + # Support for Python 3 type hints requires inspect.getfullargspec + if hasattr(inspect, 'getfullargspec'): + return inspect.getfullargspec(fn) + else: + return inspect.getargspec(fn) diff --git a/tests/codegen/arith.cl b/tests/codegen/arith.cl index 0d9f5dd33..af5951cf7 100755 --- a/tests/codegen/arith.cl +++ b/tests/codegen/arith.cl @@ -1,430 +1,430 @@ -(* - * A contribution from Anne Sheets (sheets@cory) - * - * Tests the arithmetic operations and various other things - *) - -class A { - - var : Int <- 0; - - value() : Int { var }; - - set_var(num : Int) : A{ - { - var <- num; - self; - } - }; - - method1(num : Int) : A { -- same - self - }; - - method2(num1 : Int, num2 : Int) : A { -- plus - (let x : Int in - { - x <- num1 + num2; - (new B).set_var(x); - } - ) - }; - - method3(num : Int) : A { -- negate - (let x : Int in - { - x <- ~num; - (new C).set_var(x); - } - ) - }; - - method4(num1 : Int, num2 : Int) : A { -- diff - if num2 < num1 then - (let x : Int in - { - x <- num1 - num2; - (new D).set_var(x); - } - ) - else - (let x : Int in - { - x <- num2 - num1; - (new D).set_var(x); - } - ) - fi - }; - - method5(num : Int) : A { -- factorial - (let x : Int <- 1 in - { - (let y : Int <- 1 in - while y <= num loop - { - x <- x * y; - y <- y + 1; - } - pool - ); - (new E).set_var(x); - } - ) - }; - -}; - -class B inherits A { -- B is a number squared - - method5(num : Int) : A { -- square - (let x : Int in - { - x <- num * num; - (new E).set_var(x); - } - ) - }; - -}; - -class C inherits B { - - method6(num : Int) : A { -- negate - (let x : Int in - { - x <- ~num; - (new A).set_var(x); - } - ) - }; - - method5(num : Int) : A { -- cube - (let x : Int in - { - x <- num * num * num; - (new E).set_var(x); - } - ) - }; - -}; - -class D inherits B { - - method7(num : Int) : Bool { -- divisible by 3 - (let x : Int <- num in - if x < 0 then method7(~x) else - if 0 = x then true else - if 1 = x then false else - if 2 = x then false else - method7(x - 3) - fi fi fi fi - ) - }; - -}; - -class E inherits D { - - method6(num : Int) : A { -- division - (let x : Int in - { - x <- num / 8; - (new A).set_var(x); - } - ) - }; - -}; - -(* The following code is from atoi.cl in ~cs164/examples *) - -(* - The class A2I provides integer-to-string and string-to-integer -conversion routines. To use these routines, either inherit them -in the class where needed, have a dummy variable bound to -something of type A2I, or simpl write (new A2I).method(argument). -*) - - -(* - c2i Converts a 1-character string to an integer. Aborts - if the string is not "0" through "9" -*) -class A2I { - - c2i(char : String) : Int { - if char = "0" then 0 else - if char = "1" then 1 else - if char = "2" then 2 else - if char = "3" then 3 else - if char = "4" then 4 else - if char = "5" then 5 else - if char = "6" then 6 else - if char = "7" then 7 else - if char = "8" then 8 else - if char = "9" then 9 else - { abort(); 0; } (* the 0 is needed to satisfy the - typchecker *) - fi fi fi fi fi fi fi fi fi fi - }; - -(* - i2c is the inverse of c2i. -*) - i2c(i : Int) : String { - if i = 0 then "0" else - if i = 1 then "1" else - if i = 2 then "2" else - if i = 3 then "3" else - if i = 4 then "4" else - if i = 5 then "5" else - if i = 6 then "6" else - if i = 7 then "7" else - if i = 8 then "8" else - if i = 9 then "9" else - { abort(); ""; } -- the "" is needed to satisfy the typchecker - fi fi fi fi fi fi fi fi fi fi - }; - -(* - a2i converts an ASCII string into an integer. The empty string -is converted to 0. Signed and unsigned strings are handled. The -method aborts if the string does not represent an integer. Very -long strings of digits produce strange answers because of arithmetic -overflow. - -*) - a2i(s : String) : Int { - if s.length() = 0 then 0 else - if s.substr(0,1) = "-" then ~a2i_aux(s.substr(1,s.length()-1)) else - if s.substr(0,1) = "+" then a2i_aux(s.substr(1,s.length()-1)) else - a2i_aux(s) - fi fi fi - }; - -(* a2i_aux converts the usigned portion of the string. As a - programming example, this method is written iteratively. *) - - - a2i_aux(s : String) : Int { - (let int : Int <- 0 in - { - (let j : Int <- s.length() in - (let i : Int <- 0 in - while i < j loop - { - int <- int * 10 + c2i(s.substr(i,1)); - i <- i + 1; - } - pool - ) - ); - int; - } - ) - }; - -(* i2a converts an integer to a string. Positive and negative - numbers are handled correctly. *) - - i2a(i : Int) : String { - if i = 0 then "0" else - if 0 < i then i2a_aux(i) else - "-".concat(i2a_aux(i * ~1)) - fi fi - }; - -(* i2a_aux is an example using recursion. *) - - i2a_aux(i : Int) : String { - if i = 0 then "" else - (let next : Int <- i / 10 in - i2a_aux(next).concat(i2c(i - next * 10)) - ) - fi - }; - -}; - -class Main inherits IO { - - char : String; - avar : A; - a_var : A; - flag : Bool <- true; - - - menu() : String { - { - out_string("\n\tTo add a number to "); - print(avar); - out_string("...enter a:\n"); - out_string("\tTo negate "); - print(avar); - out_string("...enter b:\n"); - out_string("\tTo find the difference between "); - print(avar); - out_string("and another number...enter c:\n"); - out_string("\tTo find the factorial of "); - print(avar); - out_string("...enter d:\n"); - out_string("\tTo square "); - print(avar); - out_string("...enter e:\n"); - out_string("\tTo cube "); - print(avar); - out_string("...enter f:\n"); - out_string("\tTo find out if "); - print(avar); - out_string("is a multiple of 3...enter g:\n"); - out_string("\tTo divide "); - print(avar); - out_string("by 8...enter h:\n"); - out_string("\tTo get a new number...enter j:\n"); - out_string("\tTo quit...enter q:\n\n"); - in_string(); - } - }; - - prompt() : String { - { - out_string("\n"); - out_string("Please enter a number... "); - in_string(); - } - }; - - get_int() : Int { - { - (let z : A2I <- new A2I in - (let s : String <- prompt() in - z.a2i(s) - ) - ); - } - }; - - is_even(num : Int) : Bool { - (let x : Int <- num in - if x < 0 then is_even(~x) else - if 0 = x then true else - if 1 = x then false else - is_even(x - 2) - fi fi fi - ) - }; - - class_type(var : A) : IO { - case var of - a : A => out_string("Class type is now A\n"); - b : B => out_string("Class type is now B\n"); - c : C => out_string("Class type is now C\n"); - d : D => out_string("Class type is now D\n"); - e : E => out_string("Class type is now E\n"); - o : Object => out_string("Oooops\n"); - esac - }; - - print(var : A) : IO { - (let z : A2I <- new A2I in - { - out_string(z.i2a(var.value())); - out_string(" "); - } - ) - }; - - main() : Object { - { - avar <- (new A); - while flag loop - { - -- avar <- (new A).set_var(get_int()); - out_string("number "); - print(avar); - if is_even(avar.value()) then - out_string("is even!\n") - else - out_string("is odd!\n") - fi; - -- print(avar); -- prints out answer - class_type(avar); - char <- menu(); - if char = "a" then -- add - { - a_var <- (new A).set_var(get_int()); - avar <- (new B).method2(avar.value(), a_var.value()); - } else - if char = "b" then -- negate - case avar of - c : C => avar <- c.method6(c.value()); - a : A => avar <- a.method3(a.value()); - o : Object => { - out_string("Oooops\n"); - abort(); 0; - }; - esac else - if char = "c" then -- diff - { - a_var <- (new A).set_var(get_int()); - avar <- (new D).method4(avar.value(), a_var.value()); - } else - if char = "d" then avar <- (new C)@A.method5(avar.value()) else - -- factorial - if char = "e" then avar <- (new C)@B.method5(avar.value()) else - -- square - if char = "f" then avar <- (new C)@C.method5(avar.value()) else - -- cube - if char = "g" then -- multiple of 3? - if ((new D).method7(avar.value())) - then -- avar <- (new A).method1(avar.value()) - { - out_string("number "); - print(avar); - out_string("is divisible by 3.\n"); - } - else -- avar <- (new A).set_var(0) - { - out_string("number "); - print(avar); - out_string("is not divisible by 3.\n"); - } - fi else - if char = "h" then - (let x : A in - { - x <- (new E).method6(avar.value()); - (let r : Int <- (avar.value() - (x.value() * 8)) in - { - out_string("number "); - print(avar); - out_string("is equal to "); - print(x); - out_string("times 8 with a remainder of "); - (let a : A2I <- new A2I in - { - out_string(a.i2a(r)); - out_string("\n"); - } - ); -- end let a: - } - ); -- end let r: - avar <- x; - } - ) -- end let x: - else - if char = "j" then avar <- (new A) - else - if char = "q" then flag <- false - else - avar <- (new A).method1(avar.value()) -- divide/8 - fi fi fi fi fi fi fi fi fi fi; - } - pool; - } - }; - -}; - +(* + * A contribution from Anne Sheets (sheets@cory) + * + * Tests the arithmetic operations and various other things + *) + +class A { + + var : Int <- 0; + + value() : Int { var }; + + set_var(num : Int) : A{ + { + var <- num; + self; + } + }; + + method1(num : Int) : A { -- same + self + }; + + method2(num1 : Int, num2 : Int) : A { -- plus + (let x : Int in + { + x <- num1 + num2; + (new B).set_var(x); + } + ) + }; + + method3(num : Int) : A { -- negate + (let x : Int in + { + x <- ~num; + (new C).set_var(x); + } + ) + }; + + method4(num1 : Int, num2 : Int) : A { -- diff + if num2 < num1 then + (let x : Int in + { + x <- num1 - num2; + (new D).set_var(x); + } + ) + else + (let x : Int in + { + x <- num2 - num1; + (new D).set_var(x); + } + ) + fi + }; + + method5(num : Int) : A { -- factorial + (let x : Int <- 1 in + { + (let y : Int <- 1 in + while y <= num loop + { + x <- x * y; + y <- y + 1; + } + pool + ); + (new E).set_var(x); + } + ) + }; + +}; + +class B inherits A { -- B is a number squared + + method5(num : Int) : A { -- square + (let x : Int in + { + x <- num * num; + (new E).set_var(x); + } + ) + }; + +}; + +class C inherits B { + + method6(num : Int) : A { -- negate + (let x : Int in + { + x <- ~num; + (new A).set_var(x); + } + ) + }; + + method5(num : Int) : A { -- cube + (let x : Int in + { + x <- num * num * num; + (new E).set_var(x); + } + ) + }; + +}; + +class D inherits B { + + method7(num : Int) : Bool { -- divisible by 3 + (let x : Int <- num in + if x < 0 then method7(~x) else + if 0 = x then true else + if 1 = x then false else + if 2 = x then false else + method7(x - 3) + fi fi fi fi + ) + }; + +}; + +class E inherits D { + + method6(num : Int) : A { -- division + (let x : Int in + { + x <- num / 8; + (new A).set_var(x); + } + ) + }; + +}; + +(* The following code is from atoi.cl in ~cs164/examples *) + +(* + The class A2I provides integer-to-string and string-to-integer +conversion routines. To use these routines, either inherit them +in the class where needed, have a dummy variable bound to +something of type A2I, or simpl write (new A2I).method(argument). +*) + + +(* + c2i Converts a 1-character string to an integer. Aborts + if the string is not "0" through "9" +*) +class A2I { + + c2i(char : String) : Int { + if char = "0" then 0 else + if char = "1" then 1 else + if char = "2" then 2 else + if char = "3" then 3 else + if char = "4" then 4 else + if char = "5" then 5 else + if char = "6" then 6 else + if char = "7" then 7 else + if char = "8" then 8 else + if char = "9" then 9 else + { abort(); 0; } (* the 0 is needed to satisfy the + typchecker *) + fi fi fi fi fi fi fi fi fi fi + }; + +(* + i2c is the inverse of c2i. +*) + i2c(i : Int) : String { + if i = 0 then "0" else + if i = 1 then "1" else + if i = 2 then "2" else + if i = 3 then "3" else + if i = 4 then "4" else + if i = 5 then "5" else + if i = 6 then "6" else + if i = 7 then "7" else + if i = 8 then "8" else + if i = 9 then "9" else + { abort(); ""; } -- the "" is needed to satisfy the typchecker + fi fi fi fi fi fi fi fi fi fi + }; + +(* + a2i converts an ASCII string into an integer. The empty string +is converted to 0. Signed and unsigned strings are handled. The +method aborts if the string does not represent an integer. Very +long strings of digits produce strange answers because of arithmetic +overflow. + +*) + a2i(s : String) : Int { + if s.length() = 0 then 0 else + if s.substr(0,1) = "-" then ~a2i_aux(s.substr(1,s.length()-1)) else + if s.substr(0,1) = "+" then a2i_aux(s.substr(1,s.length()-1)) else + a2i_aux(s) + fi fi fi + }; + +(* a2i_aux converts the usigned portion of the string. As a + programming example, this method is written iteratively. *) + + + a2i_aux(s : String) : Int { + (let int : Int <- 0 in + { + (let j : Int <- s.length() in + (let i : Int <- 0 in + while i < j loop + { + int <- int * 10 + c2i(s.substr(i,1)); + i <- i + 1; + } + pool + ) + ); + int; + } + ) + }; + +(* i2a converts an integer to a string. Positive and negative + numbers are handled correctly. *) + + i2a(i : Int) : String { + if i = 0 then "0" else + if 0 < i then i2a_aux(i) else + "-".concat(i2a_aux(i * ~1)) + fi fi + }; + +(* i2a_aux is an example using recursion. *) + + i2a_aux(i : Int) : String { + if i = 0 then "" else + (let next : Int <- i / 10 in + i2a_aux(next).concat(i2c(i - next * 10)) + ) + fi + }; + +}; + +class Main inherits IO { + + char : String; + avar : A; + a_var : A; + flag : Bool <- true; + + + menu() : String { + { + out_string("\n\tTo add a number to "); + print(avar); + out_string("...enter a:\n"); + out_string("\tTo negate "); + print(avar); + out_string("...enter b:\n"); + out_string("\tTo find the difference between "); + print(avar); + out_string("and another number...enter c:\n"); + out_string("\tTo find the factorial of "); + print(avar); + out_string("...enter d:\n"); + out_string("\tTo square "); + print(avar); + out_string("...enter e:\n"); + out_string("\tTo cube "); + print(avar); + out_string("...enter f:\n"); + out_string("\tTo find out if "); + print(avar); + out_string("is a multiple of 3...enter g:\n"); + out_string("\tTo divide "); + print(avar); + out_string("by 8...enter h:\n"); + out_string("\tTo get a new number...enter j:\n"); + out_string("\tTo quit...enter q:\n\n"); + in_string(); + } + }; + + prompt() : String { + { + out_string("\n"); + out_string("Please enter a number... "); + in_string(); + } + }; + + get_int() : Int { + { + (let z : A2I <- new A2I in + (let s : String <- prompt() in + z.a2i(s) + ) + ); + } + }; + + is_even(num : Int) : Bool { + (let x : Int <- num in + if x < 0 then is_even(~x) else + if 0 = x then true else + if 1 = x then false else + is_even(x - 2) + fi fi fi + ) + }; + + class_type(var : A) : IO { + case var of + a : A => out_string("Class type is now A\n"); + b : B => out_string("Class type is now B\n"); + c : C => out_string("Class type is now C\n"); + d : D => out_string("Class type is now D\n"); + e : E => out_string("Class type is now E\n"); + o : Object => out_string("Oooops\n"); + esac + }; + + print(var : A) : IO { + (let z : A2I <- new A2I in + { + out_string(z.i2a(var.value())); + out_string(" "); + } + ) + }; + + main() : Object { + { + avar <- (new A); + while flag loop + { + -- avar <- (new A).set_var(get_int()); + out_string("number "); + print(avar); + if is_even(avar.value()) then + out_string("is even!\n") + else + out_string("is odd!\n") + fi; + -- print(avar); -- prints out answer + class_type(avar); + char <- menu(); + if char = "a" then -- add + { + a_var <- (new A).set_var(get_int()); + avar <- (new B).method2(avar.value(), a_var.value()); + } else + if char = "b" then -- negate + case avar of + c : C => avar <- c.method6(c.value()); + a : A => avar <- a.method3(a.value()); + o : Object => { + out_string("Oooops\n"); + abort(); 0; + }; + esac else + if char = "c" then -- diff + { + a_var <- (new A).set_var(get_int()); + avar <- (new D).method4(avar.value(), a_var.value()); + } else + if char = "d" then avar <- (new C)@A.method5(avar.value()) else + -- factorial + if char = "e" then avar <- (new C)@B.method5(avar.value()) else + -- square + if char = "f" then avar <- (new C)@C.method5(avar.value()) else + -- cube + if char = "g" then -- multiple of 3? + if ((new D).method7(avar.value())) + then -- avar <- (new A).method1(avar.value()) + { + out_string("number "); + print(avar); + out_string("is divisible by 3.\n"); + } + else -- avar <- (new A).set_var(0) + { + out_string("number "); + print(avar); + out_string("is not divisible by 3.\n"); + } + fi else + if char = "h" then + (let x : A in + { + x <- (new E).method6(avar.value()); + (let r : Int <- (avar.value() - (x.value() * 8)) in + { + out_string("number "); + print(avar); + out_string("is equal to "); + print(x); + out_string("times 8 with a remainder of "); + (let a : A2I <- new A2I in + { + out_string(a.i2a(r)); + out_string("\n"); + } + ); -- end let a: + } + ); -- end let r: + avar <- x; + } + ) -- end let x: + else + if char = "j" then avar <- (new A) + else + if char = "q" then flag <- false + else + avar <- (new A).method1(avar.value()) -- divide/8 + fi fi fi fi fi fi fi fi fi fi; + } + pool; + } + }; + +}; + diff --git a/tests/codegen/arith_input.txt b/tests/codegen/arith_input.txt index c431a225b..83e05b1ea 100644 --- a/tests/codegen/arith_input.txt +++ b/tests/codegen/arith_input.txt @@ -1,13 +1,13 @@ -a -1 -b -c -0 -d -e -f -g -h -j -5 -q +a +1 +b +c +0 +d +e +f +g +h +j +5 +q diff --git a/tests/codegen/arith_output.txt b/tests/codegen/arith_output.txt index 476cb3bad..44b4ce73e 100644 --- a/tests/codegen/arith_output.txt +++ b/tests/codegen/arith_output.txt @@ -1,158 +1,158 @@ -number 0 is even! -Class type is now A - - To add a number to 0 ...enter a: - To negate 0 ...enter b: - To find the difference between 0 and another number...enter c: - To find the factorial of 0 ...enter d: - To square 0 ...enter e: - To cube 0 ...enter f: - To find out if 0 is a multiple of 3...enter g: - To divide 0 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - - -Please enter a number... number 1 is odd! -Class type is now B - - To add a number to 1 ...enter a: - To negate 1 ...enter b: - To find the difference between 1 and another number...enter c: - To find the factorial of 1 ...enter d: - To square 1 ...enter e: - To cube 1 ...enter f: - To find out if 1 is a multiple of 3...enter g: - To divide 1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number -1 is odd! -Class type is now C - - To add a number to -1 ...enter a: - To negate -1 ...enter b: - To find the difference between -1 and another number...enter c: - To find the factorial of -1 ...enter d: - To square -1 ...enter e: - To cube -1 ...enter f: - To find out if -1 is a multiple of 3...enter g: - To divide -1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - - -Please enter a number... number 1 is odd! -Class type is now D - - To add a number to 1 ...enter a: - To negate 1 ...enter b: - To find the difference between 1 and another number...enter c: - To find the factorial of 1 ...enter d: - To square 1 ...enter e: - To cube 1 ...enter f: - To find out if 1 is a multiple of 3...enter g: - To divide 1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 1 is odd! -Class type is now E - - To add a number to 1 ...enter a: - To negate 1 ...enter b: - To find the difference between 1 and another number...enter c: - To find the factorial of 1 ...enter d: - To square 1 ...enter e: - To cube 1 ...enter f: - To find out if 1 is a multiple of 3...enter g: - To divide 1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 1 is odd! -Class type is now E - - To add a number to 1 ...enter a: - To negate 1 ...enter b: - To find the difference between 1 and another number...enter c: - To find the factorial of 1 ...enter d: - To square 1 ...enter e: - To cube 1 ...enter f: - To find out if 1 is a multiple of 3...enter g: - To divide 1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 1 is odd! -Class type is now E - - To add a number to 1 ...enter a: - To negate 1 ...enter b: - To find the difference between 1 and another number...enter c: - To find the factorial of 1 ...enter d: - To square 1 ...enter e: - To cube 1 ...enter f: - To find out if 1 is a multiple of 3...enter g: - To divide 1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 1 is not divisible by 3. -number 1 is odd! -Class type is now E - - To add a number to 1 ...enter a: - To negate 1 ...enter b: - To find the difference between 1 and another number...enter c: - To find the factorial of 1 ...enter d: - To square 1 ...enter e: - To cube 1 ...enter f: - To find out if 1 is a multiple of 3...enter g: - To divide 1 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 1 is equal to 0 times 8 with a remainder of 1 -number 0 is even! -Class type is now A - - To add a number to 0 ...enter a: - To negate 0 ...enter b: - To find the difference between 0 and another number...enter c: - To find the factorial of 0 ...enter d: - To square 0 ...enter e: - To cube 0 ...enter f: - To find out if 0 is a multiple of 3...enter g: - To divide 0 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 0 is even! -Class type is now A - - To add a number to 0 ...enter a: - To negate 0 ...enter b: - To find the difference between 0 and another number...enter c: - To find the factorial of 0 ...enter d: - To square 0 ...enter e: - To cube 0 ...enter f: - To find out if 0 is a multiple of 3...enter g: - To divide 0 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - -number 0 is even! -Class type is now A - - To add a number to 0 ...enter a: - To negate 0 ...enter b: - To find the difference between 0 and another number...enter c: - To find the factorial of 0 ...enter d: - To square 0 ...enter e: - To cube 0 ...enter f: - To find out if 0 is a multiple of 3...enter g: - To divide 0 by 8...enter h: - To get a new number...enter j: - To quit...enter q: - +number 0 is even! +Class type is now A + + To add a number to 0 ...enter a: + To negate 0 ...enter b: + To find the difference between 0 and another number...enter c: + To find the factorial of 0 ...enter d: + To square 0 ...enter e: + To cube 0 ...enter f: + To find out if 0 is a multiple of 3...enter g: + To divide 0 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + + +Please enter a number... number 1 is odd! +Class type is now B + + To add a number to 1 ...enter a: + To negate 1 ...enter b: + To find the difference between 1 and another number...enter c: + To find the factorial of 1 ...enter d: + To square 1 ...enter e: + To cube 1 ...enter f: + To find out if 1 is a multiple of 3...enter g: + To divide 1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number -1 is odd! +Class type is now C + + To add a number to -1 ...enter a: + To negate -1 ...enter b: + To find the difference between -1 and another number...enter c: + To find the factorial of -1 ...enter d: + To square -1 ...enter e: + To cube -1 ...enter f: + To find out if -1 is a multiple of 3...enter g: + To divide -1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + + +Please enter a number... number 1 is odd! +Class type is now D + + To add a number to 1 ...enter a: + To negate 1 ...enter b: + To find the difference between 1 and another number...enter c: + To find the factorial of 1 ...enter d: + To square 1 ...enter e: + To cube 1 ...enter f: + To find out if 1 is a multiple of 3...enter g: + To divide 1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 1 is odd! +Class type is now E + + To add a number to 1 ...enter a: + To negate 1 ...enter b: + To find the difference between 1 and another number...enter c: + To find the factorial of 1 ...enter d: + To square 1 ...enter e: + To cube 1 ...enter f: + To find out if 1 is a multiple of 3...enter g: + To divide 1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 1 is odd! +Class type is now E + + To add a number to 1 ...enter a: + To negate 1 ...enter b: + To find the difference between 1 and another number...enter c: + To find the factorial of 1 ...enter d: + To square 1 ...enter e: + To cube 1 ...enter f: + To find out if 1 is a multiple of 3...enter g: + To divide 1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 1 is odd! +Class type is now E + + To add a number to 1 ...enter a: + To negate 1 ...enter b: + To find the difference between 1 and another number...enter c: + To find the factorial of 1 ...enter d: + To square 1 ...enter e: + To cube 1 ...enter f: + To find out if 1 is a multiple of 3...enter g: + To divide 1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 1 is not divisible by 3. +number 1 is odd! +Class type is now E + + To add a number to 1 ...enter a: + To negate 1 ...enter b: + To find the difference between 1 and another number...enter c: + To find the factorial of 1 ...enter d: + To square 1 ...enter e: + To cube 1 ...enter f: + To find out if 1 is a multiple of 3...enter g: + To divide 1 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 1 is equal to 0 times 8 with a remainder of 1 +number 0 is even! +Class type is now A + + To add a number to 0 ...enter a: + To negate 0 ...enter b: + To find the difference between 0 and another number...enter c: + To find the factorial of 0 ...enter d: + To square 0 ...enter e: + To cube 0 ...enter f: + To find out if 0 is a multiple of 3...enter g: + To divide 0 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 0 is even! +Class type is now A + + To add a number to 0 ...enter a: + To negate 0 ...enter b: + To find the difference between 0 and another number...enter c: + To find the factorial of 0 ...enter d: + To square 0 ...enter e: + To cube 0 ...enter f: + To find out if 0 is a multiple of 3...enter g: + To divide 0 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + +number 0 is even! +Class type is now A + + To add a number to 0 ...enter a: + To negate 0 ...enter b: + To find the difference between 0 and another number...enter c: + To find the factorial of 0 ...enter d: + To square 0 ...enter e: + To cube 0 ...enter f: + To find out if 0 is a multiple of 3...enter g: + To divide 0 by 8...enter h: + To get a new number...enter j: + To quit...enter q: + diff --git a/tests/codegen/atoi_output.txt b/tests/codegen/atoi_output.txt index c51d7bad6..51b815a48 100644 --- a/tests/codegen/atoi_output.txt +++ b/tests/codegen/atoi_output.txt @@ -1 +1 @@ -678987 == 678987 +678987 == 678987 diff --git a/tests/codegen/book_list.cl b/tests/codegen/book_list.cl index d39f86bbe..025ea1695 100755 --- a/tests/codegen/book_list.cl +++ b/tests/codegen/book_list.cl @@ -1,132 +1,132 @@ --- example of static and dynamic type differing for a dispatch - -Class Book inherits IO { - title : String; - author : String; - - initBook(title_p : String, author_p : String) : Book { - { - title <- title_p; - author <- author_p; - self; - } - }; - - print() : Book { - { - out_string("title: ").out_string(title).out_string("\n"); - out_string("author: ").out_string(author).out_string("\n"); - self; - } - }; -}; - -Class Article inherits Book { - per_title : String; - - initArticle(title_p : String, author_p : String, - per_title_p : String) : Article { - { - initBook(title_p, author_p); - per_title <- per_title_p; - self; - } - }; - - print() : Book { - { - self@Book.print(); - out_string("periodical: ").out_string(per_title).out_string("\n"); - self; - } - }; -}; - -Class BookList inherits IO { - (* Since abort "returns" type Object, we have to add - an expression of type Bool here to satisfy the typechecker. - This code is unreachable, since abort() halts the program. - *) - isNil() : Bool { { abort(); true; } }; - - cons(hd : Book) : Cons { - (let new_cell : Cons <- new Cons in - new_cell.init(hd,self) - ) - }; - - (* Since abort "returns" type Object, we have to add - an expression of type Book here to satisfy the typechecker. - This code is unreachable, since abort() halts the program. - *) - car() : Book { { abort(); new Book; } }; - - (* Since abort "returns" type Object, we have to add - an expression of type BookList here to satisfy the typechecker. - This code is unreachable, since abort() halts the program. - *) - cdr() : BookList { { abort(); new BookList; } }; - - print_list() : Object { abort() }; -}; - -Class Cons inherits BookList { - xcar : Book; -- We keep the car and cdr in attributes. - xcdr : BookList; -- Because methods and features must have different names, - -- we use xcar and xcdr for the attributes and reserve - -- car and cdr for the features. - - isNil() : Bool { false }; - - init(hd : Book, tl : BookList) : Cons { - { - xcar <- hd; - xcdr <- tl; - self; - } - }; - - car() : Book { xcar }; - - cdr() : BookList { xcdr }; - - print_list() : Object { - { - case xcar.print() of - dummy : Book => out_string("- dynamic type was Book -\n"); - dummy : Article => out_string("- dynamic type was Article -\n"); - esac; - xcdr.print_list(); - } - }; -}; - -Class Nil inherits BookList { - isNil() : Bool { true }; - - print_list() : Object { true }; -}; - - -Class Main { - - books : BookList; - - main() : Object { - (let a_book : Book <- - (new Book).initBook("Compilers, Principles, Techniques, and Tools", - "Aho, Sethi, and Ullman") - in - (let an_article : Article <- - (new Article).initArticle("The Top 100 CD_ROMs", - "Ulanoff", - "PC Magazine") - in - { - books <- (new Nil).cons(a_book).cons(an_article); - books.print_list(); - } - ) -- end let an_article - ) -- end let a_book - }; -}; +-- example of static and dynamic type differing for a dispatch + +Class Book inherits IO { + title : String; + author : String; + + initBook(title_p : String, author_p : String) : Book { + { + title <- title_p; + author <- author_p; + self; + } + }; + + print() : Book { + { + out_string("title: ").out_string(title).out_string("\n"); + out_string("author: ").out_string(author).out_string("\n"); + self; + } + }; +}; + +Class Article inherits Book { + per_title : String; + + initArticle(title_p : String, author_p : String, + per_title_p : String) : Article { + { + initBook(title_p, author_p); + per_title <- per_title_p; + self; + } + }; + + print() : Book { + { + self@Book.print(); + out_string("periodical: ").out_string(per_title).out_string("\n"); + self; + } + }; +}; + +Class BookList inherits IO { + (* Since abort "returns" type Object, we have to add + an expression of type Bool here to satisfy the typechecker. + This code is unreachable, since abort() halts the program. + *) + isNil() : Bool { { abort(); true; } }; + + cons(hd : Book) : Cons { + (let new_cell : Cons <- new Cons in + new_cell.init(hd,self) + ) + }; + + (* Since abort "returns" type Object, we have to add + an expression of type Book here to satisfy the typechecker. + This code is unreachable, since abort() halts the program. + *) + car() : Book { { abort(); new Book; } }; + + (* Since abort "returns" type Object, we have to add + an expression of type BookList here to satisfy the typechecker. + This code is unreachable, since abort() halts the program. + *) + cdr() : BookList { { abort(); new BookList; } }; + + print_list() : Object { abort() }; +}; + +Class Cons inherits BookList { + xcar : Book; -- We keep the car and cdr in attributes. + xcdr : BookList; -- Because methods and features must have different names, + -- we use xcar and xcdr for the attributes and reserve + -- car and cdr for the features. + + isNil() : Bool { false }; + + init(hd : Book, tl : BookList) : Cons { + { + xcar <- hd; + xcdr <- tl; + self; + } + }; + + car() : Book { xcar }; + + cdr() : BookList { xcdr }; + + print_list() : Object { + { + case xcar.print() of + dummy : Book => out_string("- dynamic type was Book -\n"); + dummy : Article => out_string("- dynamic type was Article -\n"); + esac; + xcdr.print_list(); + } + }; +}; + +Class Nil inherits BookList { + isNil() : Bool { true }; + + print_list() : Object { true }; +}; + + +Class Main { + + books : BookList; + + main() : Object { + (let a_book : Book <- + (new Book).initBook("Compilers, Principles, Techniques, and Tools", + "Aho, Sethi, and Ullman") + in + (let an_article : Article <- + (new Article).initArticle("The Top 100 CD_ROMs", + "Ulanoff", + "PC Magazine") + in + { + books <- (new Nil).cons(a_book).cons(an_article); + books.print_list(); + } + ) -- end let an_article + ) -- end let a_book + }; +}; diff --git a/tests/codegen/book_list_output.txt b/tests/codegen/book_list_output.txt index ced587a4f..3408320b2 100644 --- a/tests/codegen/book_list_output.txt +++ b/tests/codegen/book_list_output.txt @@ -1,7 +1,7 @@ -title: The Top 100 CD_ROMs -author: Ulanoff -periodical: PC Magazine -- dynamic type was Article - -title: Compilers, Principles, Techniques, and Tools -author: Aho, Sethi, and Ullman -- dynamic type was Book - +title: The Top 100 CD_ROMs +author: Ulanoff +periodical: PC Magazine +- dynamic type was Article - +title: Compilers, Principles, Techniques, and Tools +author: Aho, Sethi, and Ullman +- dynamic type was Book - diff --git a/tests/codegen/cells.cl b/tests/codegen/cells.cl index bcd891498..9fd6741bb 100755 --- a/tests/codegen/cells.cl +++ b/tests/codegen/cells.cl @@ -1,97 +1,97 @@ -(* models one-dimensional cellular automaton on a circle of finite radius - arrays are faked as Strings, - X's respresent live cells, dots represent dead cells, - no error checking is done *) -class CellularAutomaton inherits IO { - population_map : String; - - init(map : String) : CellularAutomaton { - { - population_map <- map; - self; - } - }; - - print() : CellularAutomaton { - { - out_string(population_map.concat("\n")); - self; - } - }; - - num_cells() : Int { - population_map.length() - }; - - cell(position : Int) : String { - population_map.substr(position, 1) - }; - - cell_left_neighbor(position : Int) : String { - if position = 0 then - cell(num_cells() - 1) - else - cell(position - 1) - fi - }; - - cell_right_neighbor(position : Int) : String { - if position = num_cells() - 1 then - cell(0) - else - cell(position + 1) - fi - }; - - (* a cell will live if exactly 1 of itself and it's immediate - neighbors are alive *) - cell_at_next_evolution(position : Int) : String { - if (if cell(position) = "X" then 1 else 0 fi - + if cell_left_neighbor(position) = "X" then 1 else 0 fi - + if cell_right_neighbor(position) = "X" then 1 else 0 fi - = 1) - then - "X" - else - "." - fi - }; - - evolve() : CellularAutomaton { - (let position : Int in - (let num : Int <- num_cells() in - (let temp : String in - { - while position < num loop - { - temp <- temp.concat(cell_at_next_evolution(position)); - position <- position + 1; - } - pool; - population_map <- temp; - self; - } - ) ) ) - }; -}; - -class Main { - cells : CellularAutomaton; - - main() : Main { - { - cells <- (new CellularAutomaton).init(" X "); - cells.print(); - (let countdown : Int <- 20 in - while 0 < countdown loop - { - cells.evolve(); - cells.print(); - countdown <- countdown - 1; - } - pool - ); - self; - } - }; -}; +(* models one-dimensional cellular automaton on a circle of finite radius + arrays are faked as Strings, + X's respresent live cells, dots represent dead cells, + no error checking is done *) +class CellularAutomaton inherits IO { + population_map : String; + + init(map : String) : CellularAutomaton { + { + population_map <- map; + self; + } + }; + + print() : CellularAutomaton { + { + out_string(population_map.concat("\n")); + self; + } + }; + + num_cells() : Int { + population_map.length() + }; + + cell(position : Int) : String { + population_map.substr(position, 1) + }; + + cell_left_neighbor(position : Int) : String { + if position = 0 then + cell(num_cells() - 1) + else + cell(position - 1) + fi + }; + + cell_right_neighbor(position : Int) : String { + if position = num_cells() - 1 then + cell(0) + else + cell(position + 1) + fi + }; + + (* a cell will live if exactly 1 of itself and it's immediate + neighbors are alive *) + cell_at_next_evolution(position : Int) : String { + if (if cell(position) = "X" then 1 else 0 fi + + if cell_left_neighbor(position) = "X" then 1 else 0 fi + + if cell_right_neighbor(position) = "X" then 1 else 0 fi + = 1) + then + "X" + else + "." + fi + }; + + evolve() : CellularAutomaton { + (let position : Int in + (let num : Int <- num_cells() in + (let temp : String in + { + while position < num loop + { + temp <- temp.concat(cell_at_next_evolution(position)); + position <- position + 1; + } + pool; + population_map <- temp; + self; + } + ) ) ) + }; +}; + +class Main { + cells : CellularAutomaton; + + main() : Main { + { + cells <- (new CellularAutomaton).init(" X "); + cells.print(); + (let countdown : Int <- 20 in + while 0 < countdown loop + { + cells.evolve(); + cells.print(); + countdown <- countdown - 1; + } + pool + ); + self; + } + }; +}; diff --git a/tests/codegen/cells_output.txt b/tests/codegen/cells_output.txt index 9d06c27bc..6304902cc 100644 --- a/tests/codegen/cells_output.txt +++ b/tests/codegen/cells_output.txt @@ -1,21 +1,21 @@ - X -........XXX........ -.......X...X....... -......XXX.XXX...... -.....X.......X..... -....XXX.....XXX.... -...X...X...X...X... -..XXX.XXX.XXX.XXX.. -.X...............X. -XXX.............XXX -...X...........X... -..XXX.........XXX.. -.X...X.......X...X. -XXX.XXX.....XXX.XXX -.......X...X....... -......XXX.XXX...... -.....X.......X..... -....XXX.....XXX.... -...X...X...X...X... -..XXX.XXX.XXX.XXX.. -.X...............X. + X +........XXX........ +.......X...X....... +......XXX.XXX...... +.....X.......X..... +....XXX.....XXX.... +...X...X...X...X... +..XXX.XXX.XXX.XXX.. +.X...............X. +XXX.............XXX +...X...........X... +..XXX.........XXX.. +.X...X.......X...X. +XXX.XXX.....XXX.XXX +.......X...X....... +......XXX.XXX...... +.....X.......X..... +....XXX.....XXX.... +...X...X...X...X... +..XXX.XXX.XXX.XXX.. +.X...............X. diff --git a/tests/codegen/complex.cl b/tests/codegen/complex.cl index 9edb6151d..0b7aa44e9 100755 --- a/tests/codegen/complex.cl +++ b/tests/codegen/complex.cl @@ -1,52 +1,52 @@ -class Main inherits IO { - main() : IO { - (let c : Complex <- (new Complex).init(1, 1) in - if c.reflect_X().reflect_Y() = c.reflect_0() - then out_string("=)\n") - else out_string("=(\n") - fi - ) - }; -}; - -class Complex inherits IO { - x : Int; - y : Int; - - init(a : Int, b : Int) : Complex { - { - x = a; - y = b; - self; - } - }; - - print() : Object { - if y = 0 - then out_int(x) - else out_int(x).out_string("+").out_int(y).out_string("I") - fi - }; - - reflect_0() : Complex { - { - x = ~x; - y = ~y; - self; - } - }; - - reflect_X() : Complex { - { - y = ~y; - self; - } - }; - - reflect_Y() : Complex { - { - x = ~x; - self; - } - }; -}; +class Main inherits IO { + main() : IO { + (let c : Complex <- (new Complex).init(1, 1) in + if c.reflect_X().reflect_Y() = c.reflect_0() + then out_string("=)\n") + else out_string("=(\n") + fi + ) + }; +}; + +class Complex inherits IO { + x : Int; + y : Int; + + init(a : Int, b : Int) : Complex { + { + x = a; + y = b; + self; + } + }; + + print() : Object { + if y = 0 + then out_int(x) + else out_int(x).out_string("+").out_int(y).out_string("I") + fi + }; + + reflect_0() : Complex { + { + x = ~x; + y = ~y; + self; + } + }; + + reflect_X() : Complex { + { + y = ~y; + self; + } + }; + + reflect_Y() : Complex { + { + x = ~x; + self; + } + }; +}; diff --git a/tests/codegen/complex_output.txt b/tests/codegen/complex_output.txt index 7d6173685..18b77c1fc 100644 --- a/tests/codegen/complex_output.txt +++ b/tests/codegen/complex_output.txt @@ -1 +1 @@ -=) +=) diff --git a/tests/codegen/fib.cl b/tests/codegen/fib.cl index ced8cee48..08ceaede8 100644 --- a/tests/codegen/fib.cl +++ b/tests/codegen/fib.cl @@ -1,29 +1,29 @@ -class Main inherits IO { - -- the class has features. Only methods in this case. - main(): Object { - { - out_string("Enter n to find nth fibonacci number!\n"); - out_int(fib(in_int())); - out_string("\n"); - } - }; - - fib(i : Int) : Int { -- list of formals. And the return type of the method. - let a : Int <- 1, - b : Int <- 0, - c : Int <- 0 - in - { - while (not (i = 0)) loop -- expressions are nested. - { - c <- a + b; - i <- i - 1; - b <- a; - a <- c; - } - pool; - c; - } - }; - -}; +class Main inherits IO { + -- the class has features. Only methods in this case. + main(): Object { + { + out_string("Enter n to find nth fibonacci number!\n"); + out_int(fib(in_int())); + out_string("\n"); + } + }; + + fib(i : Int) : Int { -- list of formals. And the return type of the method. + let a : Int <- 1, + b : Int <- 0, + c : Int <- 0 + in + { + while (not (i = 0)) loop -- expressions are nested. + { + c <- a + b; + i <- i - 1; + b <- a; + a <- c; + } + pool; + c; + } + }; + +}; diff --git a/tests/codegen/fib_input.txt b/tests/codegen/fib_input.txt index d43401489..f599e28b8 100644 --- a/tests/codegen/fib_input.txt +++ b/tests/codegen/fib_input.txt @@ -1 +1 @@ -10 +10 diff --git a/tests/codegen/fib_output.txt b/tests/codegen/fib_output.txt index 2552f4479..d402da6af 100644 --- a/tests/codegen/fib_output.txt +++ b/tests/codegen/fib_output.txt @@ -1,2 +1,2 @@ -Enter n to find nth fibonacci number! -89 +Enter n to find nth fibonacci number! +89 diff --git a/tests/codegen/graph.cl b/tests/codegen/graph.cl index 59e29bbf4..8e511358c 100755 --- a/tests/codegen/graph.cl +++ b/tests/codegen/graph.cl @@ -1,381 +1,381 @@ -(* - * Cool program reading descriptions of weighted directed graphs - * from stdin. It builds up a graph objects with a list of vertices - * and a list of edges. Every vertice has a list of outgoing edges. - * - * INPUT FORMAT - * Every line has the form vertice successor* - * Where vertice is an int, and successor is vertice,weight - * - * An empty line or EOF terminates the input. - * - * The list of vertices and the edge list is printed out by the Main - * class. - * - * TEST - * Once compiled, the file g1.graph can be fed to the program. - * The output should look like this: - -nautilus.CS.Berkeley.EDU 53# spim -file graph.s (new Bar); - n : Foo => (new Razz); - n : Bar => n; - esac; - - b : Int <- a.doh() + g.doh() + doh() + printh(); - - doh() : Int { (let i : Int <- h in { h <- h + 2; i; } ) }; - -}; - -class Bar inherits Razz { - - c : Int <- doh(); - - d : Object <- printh(); -}; - - -class Razz inherits Foo { - - e : Bar <- case self of - n : Razz => (new Bar); - n : Bar => n; - esac; - - f : Int <- a@Bazz.doh() + g.doh() + e.doh() + doh() + printh(); - -}; - -class Bazz inherits IO { - - h : Int <- 1; - - g : Foo <- case self of - n : Bazz => (new Foo); - n : Razz => (new Bar); - n : Foo => (new Razz); - n : Bar => n; - esac; - - i : Object <- printh(); - - printh() : Int { { out_int(h); 0; } }; - - doh() : Int { (let i: Int <- h in { h <- h + 1; i; } ) }; -}; - -(* scary . . . *) -class Main { - a : Bazz <- new Bazz; - b : Foo <- new Foo; - c : Razz <- new Razz; - d : Bar <- new Bar; - - main(): String { "do nothing" }; - -}; - - - - - +(* hairy . . .*) + +class Foo inherits Bazz { + a : Razz <- case self of + n : Razz => (new Bar); + n : Foo => (new Razz); + n : Bar => n; + esac; + + b : Int <- a.doh() + g.doh() + doh() + printh(); + + doh() : Int { (let i : Int <- h in { h <- h + 2; i; } ) }; + +}; + +class Bar inherits Razz { + + c : Int <- doh(); + + d : Object <- printh(); +}; + + +class Razz inherits Foo { + + e : Bar <- case self of + n : Razz => (new Bar); + n : Bar => n; + esac; + + f : Int <- a@Bazz.doh() + g.doh() + e.doh() + doh() + printh(); + +}; + +class Bazz inherits IO { + + h : Int <- 1; + + g : Foo <- case self of + n : Bazz => (new Foo); + n : Razz => (new Bar); + n : Foo => (new Razz); + n : Bar => n; + esac; + + i : Object <- printh(); + + printh() : Int { { out_int(h); 0; } }; + + doh() : Int { (let i: Int <- h in { h <- h + 1; i; } ) }; +}; + +(* scary . . . *) +class Main { + a : Bazz <- new Bazz; + b : Foo <- new Foo; + c : Razz <- new Razz; + d : Bar <- new Bar; + + main(): String { "do nothing" }; + +}; + + + + + diff --git a/tests/codegen/hello_world.cl b/tests/codegen/hello_world.cl index b0a180a2e..0c818f908 100755 --- a/tests/codegen/hello_world.cl +++ b/tests/codegen/hello_world.cl @@ -1,5 +1,5 @@ -class Main inherits IO { - main(): IO { - out_string("Hello, World.\n") - }; -}; +class Main inherits IO { + main(): IO { + out_string("Hello, World.\n") + }; +}; diff --git a/tests/codegen/hello_world_output.txt b/tests/codegen/hello_world_output.txt index 9c1c7a002..349db2bfe 100644 --- a/tests/codegen/hello_world_output.txt +++ b/tests/codegen/hello_world_output.txt @@ -1 +1 @@ -Hello, World. +Hello, World. diff --git a/tests/codegen/io.cl b/tests/codegen/io.cl index 42ee6854e..7f0de869e 100755 --- a/tests/codegen/io.cl +++ b/tests/codegen/io.cl @@ -1,103 +1,103 @@ -(* - * The IO class is predefined and has 4 methods: - * - * out_string(s : String) : SELF_TYPE - * out_int(i : Int) : SELF_TYPE - * in_string() : String - * in_int() : Int - * - * The out operations print their argument to the terminal. The - * in_string method reads an entire line from the terminal and returns a - * string not containing the new line. The in_int method also reads - * an entire line from the terminal and returns the integer - * corresponding to the first non blank word on the line. If that - * word is not an integer, it returns 0. - * - * - * Because our language is object oriented, we need an object of type - * IO in order to call any of these methods. - * - * There are basically two ways of getting access to IO in a class C. - * - * 1) Define C to Inherit from IO. This way the IO methods become - * methods of C, and they can be called using the abbreviated - * dispatch, i.e. - * - * class C inherits IO is - * ... - * out_string("Hello world\n") - * ... - * end; - * - * 2) If your class C does not directly or indirectly inherit from - * IO, the best way to access IO is through an initialized - * attribute of type IO. - * - * class C inherits Foo is - * io : IO <- new IO; - * ... - * io.out_string("Hello world\n"); - * ... - * end; - * - * Approach 1) is most often used, in particular when you need IO - * functions in the Main class. - * - *) - - -class A { - - -- Let's assume that we don't want A to not inherit from IO. - - io : IO <- new IO; - - out_a() : Object { io.out_string("A: Hello world\n") }; - -}; - - -class B inherits A { - - -- B does not have to an extra attribute, since it inherits io from A. - - out_b() : Object { io.out_string("B: Hello world\n") }; - -}; - - -class C inherits IO { - - -- Now the IO methods are part of C. - - out_c() : Object { out_string("C: Hello world\n") }; - - -- Note that out_string(...) is just a shorthand for self.out_string(...) - -}; - - -class D inherits C { - - -- Inherits IO methods from C. - - out_d() : Object { out_string("D: Hello world\n") }; - -}; - - -class Main inherits IO { - - -- Same case as class C. - - main() : Object { - { - (new A).out_a(); - (new B).out_b(); - (new C).out_c(); - (new D).out_d(); - out_string("Done.\n"); - } - }; - -}; +(* + * The IO class is predefined and has 4 methods: + * + * out_string(s : String) : SELF_TYPE + * out_int(i : Int) : SELF_TYPE + * in_string() : String + * in_int() : Int + * + * The out operations print their argument to the terminal. The + * in_string method reads an entire line from the terminal and returns a + * string not containing the new line. The in_int method also reads + * an entire line from the terminal and returns the integer + * corresponding to the first non blank word on the line. If that + * word is not an integer, it returns 0. + * + * + * Because our language is object oriented, we need an object of type + * IO in order to call any of these methods. + * + * There are basically two ways of getting access to IO in a class C. + * + * 1) Define C to Inherit from IO. This way the IO methods become + * methods of C, and they can be called using the abbreviated + * dispatch, i.e. + * + * class C inherits IO is + * ... + * out_string("Hello world\n") + * ... + * end; + * + * 2) If your class C does not directly or indirectly inherit from + * IO, the best way to access IO is through an initialized + * attribute of type IO. + * + * class C inherits Foo is + * io : IO <- new IO; + * ... + * io.out_string("Hello world\n"); + * ... + * end; + * + * Approach 1) is most often used, in particular when you need IO + * functions in the Main class. + * + *) + + +class A { + + -- Let's assume that we don't want A to not inherit from IO. + + io : IO <- new IO; + + out_a() : Object { io.out_string("A: Hello world\n") }; + +}; + + +class B inherits A { + + -- B does not have to an extra attribute, since it inherits io from A. + + out_b() : Object { io.out_string("B: Hello world\n") }; + +}; + + +class C inherits IO { + + -- Now the IO methods are part of C. + + out_c() : Object { out_string("C: Hello world\n") }; + + -- Note that out_string(...) is just a shorthand for self.out_string(...) + +}; + + +class D inherits C { + + -- Inherits IO methods from C. + + out_d() : Object { out_string("D: Hello world\n") }; + +}; + + +class Main inherits IO { + + -- Same case as class C. + + main() : Object { + { + (new A).out_a(); + (new B).out_b(); + (new C).out_c(); + (new D).out_d(); + out_string("Done.\n"); + } + }; + +}; diff --git a/tests/codegen/io_output.txt b/tests/codegen/io_output.txt index 870cffce6..f846f596d 100644 --- a/tests/codegen/io_output.txt +++ b/tests/codegen/io_output.txt @@ -1,5 +1,5 @@ -A: Hello world -B: Hello world -C: Hello world -D: Hello world -Done. +A: Hello world +B: Hello world +C: Hello world +D: Hello world +Done. diff --git a/tests/codegen/life.cl b/tests/codegen/life.cl index 7d7a41fdb..b83d97957 100755 --- a/tests/codegen/life.cl +++ b/tests/codegen/life.cl @@ -1,436 +1,436 @@ -(* The Game of Life - Tendo Kayiira, Summer '95 - With code taken from /private/cool/class/examples/cells.cl - - This introduction was taken off the internet. It gives a brief - description of the Game Of Life. It also gives the rules by which - this particular game follows. - - Introduction - - John Conway's Game of Life is a mathematical amusement, but it - is also much more: an insight into how a system of simple - cellualar automata can create complex, odd, and often aesthetically - pleasing patterns. It is played on a cartesian grid of cells - which are either 'on' or 'off' The game gets it's name from the - similarity between the behaviour of these cells and the behaviour - of living organisms. - - The Rules - - The playfield is a cartesian grid of arbitrary size. Each cell in - this grid can be in an 'on' state or an 'off' state. On each 'turn' - (called a generation,) the state of each cell changes simultaneously - depending on it's state and the state of all cells adjacent to it. - - For 'on' cells, - If the cell has 0 or 1 neighbours which are 'on', the cell turns - 'off'. ('dies of loneliness') - If the cell has 2 or 3 neighbours which are 'on', the cell stays - 'on'. (nothing happens to that cell) - If the cell has 4, 5, 6, 7, 8, or 9 neighbours which are 'on', - the cell turns 'off'. ('dies of overcrowding') - - For 'off' cells, - If the cell has 0, 1, 2, 4, 5, 6, 7, 8, or 9 neighbours which - are 'on', the cell stays 'off'. (nothing happens to that cell) - If the cell has 3 neighbours which are 'on', the cell turns - 'on'. (3 neighbouring 'alive' cells 'give birth' to a fourth.) - - Repeat for as many generations as desired. - - *) - - -class Board inherits IO { - - rows : Int; - columns : Int; - board_size : Int; - - size_of_board(initial : String) : Int { - initial.length() - }; - - board_init(start : String) : Board { - (let size :Int <- size_of_board(start) in - { - if size = 15 then - { - rows <- 3; - columns <- 5; - board_size <- size; - } - else if size = 16 then - { - rows <- 4; - columns <- 4; - board_size <- size; - } - else if size = 20 then - { - rows <- 4; - columns <- 5; - board_size <- size; - } - else if size = 21 then - { - rows <- 3; - columns <- 7; - board_size <- size; - } - else if size = 25 then - { - rows <- 5; - columns <- 5; - board_size <- size; - } - else if size = 28 then - { - rows <- 7; - columns <- 4; - board_size <- size; - } - else -- If none of the above fit, then just give - { -- the configuration of the most common board - rows <- 5; - columns <- 5; - board_size <- size; - } - fi fi fi fi fi fi; - self; - } - ) - }; - -}; - - - -class CellularAutomaton inherits Board { - population_map : String; - - init(map : String) : CellularAutomaton { - { - population_map <- map; - board_init(map); - self; - } - }; - - - - - print() : CellularAutomaton { - - (let i : Int <- 0 in - (let num : Int <- board_size in - { - out_string("\n"); - while i < num loop - { - out_string(population_map.substr(i,columns)); - out_string("\n"); - i <- i + columns; - } - pool; - out_string("\n"); - self; - } - ) ) - }; - - num_cells() : Int { - population_map.length() - }; - - cell(position : Int) : String { - if board_size - 1 < position then - " " - else - population_map.substr(position, 1) - fi - }; - - north(position : Int): String { - if (position - columns) < 0 then - " " - else - cell(position - columns) - fi - }; - - south(position : Int): String { - if board_size < (position + columns) then - " " - else - cell(position + columns) - fi - }; - - east(position : Int): String { - if (((position + 1) /columns ) * columns) = (position + 1) then - " " - else - cell(position + 1) - fi - }; - - west(position : Int): String { - if position = 0 then - " " - else - if ((position / columns) * columns) = position then - " " - else - cell(position - 1) - fi fi - }; - - northwest(position : Int): String { - if (position - columns) < 0 then - " " - else if ((position / columns) * columns) = position then - " " - else - north(position - 1) - fi fi - }; - - northeast(position : Int): String { - if (position - columns) < 0 then - " " - else if (((position + 1) /columns ) * columns) = (position + 1) then - " " - else - north(position + 1) - fi fi - }; - - southeast(position : Int): String { - if board_size < (position + columns) then - " " - else if (((position + 1) /columns ) * columns) = (position + 1) then - " " - else - south(position + 1) - fi fi - }; - - southwest(position : Int): String { - if board_size < (position + columns) then - " " - else if ((position / columns) * columns) = position then - " " - else - south(position - 1) - fi fi - }; - - neighbors(position: Int): Int { - { - if north(position) = "X" then 1 else 0 fi - + if south(position) = "X" then 1 else 0 fi - + if east(position) = "X" then 1 else 0 fi - + if west(position) = "X" then 1 else 0 fi - + if northeast(position) = "X" then 1 else 0 fi - + if northwest(position) = "X" then 1 else 0 fi - + if southeast(position) = "X" then 1 else 0 fi - + if southwest(position) = "X" then 1 else 0 fi; - } - }; - - -(* A cell will live if 2 or 3 of it's neighbors are alive. It dies - otherwise. A cell is born if only 3 of it's neighbors are alive. *) - - cell_at_next_evolution(position : Int) : String { - - if neighbors(position) = 3 then - "X" - else - if neighbors(position) = 2 then - if cell(position) = "X" then - "X" - else - "-" - fi - else - "-" - fi fi - }; - - - evolve() : CellularAutomaton { - (let position : Int <- 0 in - (let num : Int <- num_cells() in - (let temp : String in - { - while position < num loop - { - temp <- temp.concat(cell_at_next_evolution(position)); - position <- position + 1; - } - pool; - population_map <- temp; - self; - } - ) ) ) - }; - -(* This is where the background pattern is detremined by the user. More - patterns can be added as long as whoever adds keeps the board either - 3x5, 4x5, 5x5, 3x7, 7x4, 4x4 with the row first then column. *) - option(): String { - { - (let num : Int in - { - out_string("\nPlease chose a number:\n"); - out_string("\t1: A cross\n"); - out_string("\t2: A slash from the upper left to lower right\n"); - out_string("\t3: A slash from the upper right to lower left\n"); - out_string("\t4: An X\n"); - out_string("\t5: A greater than sign \n"); - out_string("\t6: A less than sign\n"); - out_string("\t7: Two greater than signs\n"); - out_string("\t8: Two less than signs\n"); - out_string("\t9: A 'V'\n"); - out_string("\t10: An inverse 'V'\n"); - out_string("\t11: Numbers 9 and 10 combined\n"); - out_string("\t12: A full grid\n"); - out_string("\t13: A 'T'\n"); - out_string("\t14: A plus '+'\n"); - out_string("\t15: A 'W'\n"); - out_string("\t16: An 'M'\n"); - out_string("\t17: An 'E'\n"); - out_string("\t18: A '3'\n"); - out_string("\t19: An 'O'\n"); - out_string("\t20: An '8'\n"); - out_string("\t21: An 'S'\n"); - out_string("Your choice => "); - num <- in_int(); - out_string("\n"); - if num = 1 then - " XX XXXX XXXX XX " - else if num = 2 then - " X X X X X " - else if num = 3 then - "X X X X X" - else if num = 4 then - "X X X X X X X X X" - else if num = 5 then - "X X X X X " - else if num = 6 then - " X X X X X" - else if num = 7 then - "X X X XX X " - else if num = 8 then - " X XX X X X " - else if num = 9 then - "X X X X X " - else if num = 10 then - " X X X X X" - else if num = 11 then - "X X X X X X X X" - else if num = 12 then - "XXXXXXXXXXXXXXXXXXXXXXXXX" - else if num = 13 then - "XXXXX X X X X " - else if num = 14 then - " X X XXXXX X X " - else if num = 15 then - "X X X X X X X " - else if num = 16 then - " X X X X X X X" - else if num = 17 then - "XXXXX X XXXXX X XXXX" - else if num = 18 then - "XXX X X X X XXXX " - else if num = 19 then - " XX X XX X XX " - else if num = 20 then - " XX X XX X XX X XX X XX " - else if num = 21 then - " XXXX X XX X XXXX " - else - " " - fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi; - } - ); - } - }; - - - - - prompt() : Bool { - { - (let ans : String in - { - out_string("Would you like to continue with the next generation? \n"); - out_string("Please use lowercase y or n for your answer [y]: "); - ans <- in_string(); - out_string("\n"); - if ans = "n" then - false - else - true - fi; - } - ); - } - }; - - - prompt2() : Bool { - (let ans : String in - { - out_string("\n\n"); - out_string("Would you like to choose a background pattern? \n"); - out_string("Please use lowercase y or n for your answer [n]: "); - ans <- in_string(); - if ans = "y" then - true - else - false - fi; - } - ) - }; - - -}; - -class Main inherits CellularAutomaton { - cells : CellularAutomaton; - - main() : Main { - { - (let continue : Bool in - (let choice : String in - { - out_string("Welcome to the Game of Life.\n"); - out_string("There are many initial states to choose from. \n"); - while prompt2() loop - { - continue <- true; - choice <- option(); - cells <- (new CellularAutomaton).init(choice); - cells.print(); - while continue loop - if prompt() then - { - cells.evolve(); - cells.print(); - } - else - continue <- false - fi - pool; - } - pool; - self; - } ) ); } - }; -}; - +(* The Game of Life + Tendo Kayiira, Summer '95 + With code taken from /private/cool/class/examples/cells.cl + + This introduction was taken off the internet. It gives a brief + description of the Game Of Life. It also gives the rules by which + this particular game follows. + + Introduction + + John Conway's Game of Life is a mathematical amusement, but it + is also much more: an insight into how a system of simple + cellualar automata can create complex, odd, and often aesthetically + pleasing patterns. It is played on a cartesian grid of cells + which are either 'on' or 'off' The game gets it's name from the + similarity between the behaviour of these cells and the behaviour + of living organisms. + + The Rules + + The playfield is a cartesian grid of arbitrary size. Each cell in + this grid can be in an 'on' state or an 'off' state. On each 'turn' + (called a generation,) the state of each cell changes simultaneously + depending on it's state and the state of all cells adjacent to it. + + For 'on' cells, + If the cell has 0 or 1 neighbours which are 'on', the cell turns + 'off'. ('dies of loneliness') + If the cell has 2 or 3 neighbours which are 'on', the cell stays + 'on'. (nothing happens to that cell) + If the cell has 4, 5, 6, 7, 8, or 9 neighbours which are 'on', + the cell turns 'off'. ('dies of overcrowding') + + For 'off' cells, + If the cell has 0, 1, 2, 4, 5, 6, 7, 8, or 9 neighbours which + are 'on', the cell stays 'off'. (nothing happens to that cell) + If the cell has 3 neighbours which are 'on', the cell turns + 'on'. (3 neighbouring 'alive' cells 'give birth' to a fourth.) + + Repeat for as many generations as desired. + + *) + + +class Board inherits IO { + + rows : Int; + columns : Int; + board_size : Int; + + size_of_board(initial : String) : Int { + initial.length() + }; + + board_init(start : String) : Board { + (let size :Int <- size_of_board(start) in + { + if size = 15 then + { + rows <- 3; + columns <- 5; + board_size <- size; + } + else if size = 16 then + { + rows <- 4; + columns <- 4; + board_size <- size; + } + else if size = 20 then + { + rows <- 4; + columns <- 5; + board_size <- size; + } + else if size = 21 then + { + rows <- 3; + columns <- 7; + board_size <- size; + } + else if size = 25 then + { + rows <- 5; + columns <- 5; + board_size <- size; + } + else if size = 28 then + { + rows <- 7; + columns <- 4; + board_size <- size; + } + else -- If none of the above fit, then just give + { -- the configuration of the most common board + rows <- 5; + columns <- 5; + board_size <- size; + } + fi fi fi fi fi fi; + self; + } + ) + }; + +}; + + + +class CellularAutomaton inherits Board { + population_map : String; + + init(map : String) : CellularAutomaton { + { + population_map <- map; + board_init(map); + self; + } + }; + + + + + print() : CellularAutomaton { + + (let i : Int <- 0 in + (let num : Int <- board_size in + { + out_string("\n"); + while i < num loop + { + out_string(population_map.substr(i,columns)); + out_string("\n"); + i <- i + columns; + } + pool; + out_string("\n"); + self; + } + ) ) + }; + + num_cells() : Int { + population_map.length() + }; + + cell(position : Int) : String { + if board_size - 1 < position then + " " + else + population_map.substr(position, 1) + fi + }; + + north(position : Int): String { + if (position - columns) < 0 then + " " + else + cell(position - columns) + fi + }; + + south(position : Int): String { + if board_size < (position + columns) then + " " + else + cell(position + columns) + fi + }; + + east(position : Int): String { + if (((position + 1) /columns ) * columns) = (position + 1) then + " " + else + cell(position + 1) + fi + }; + + west(position : Int): String { + if position = 0 then + " " + else + if ((position / columns) * columns) = position then + " " + else + cell(position - 1) + fi fi + }; + + northwest(position : Int): String { + if (position - columns) < 0 then + " " + else if ((position / columns) * columns) = position then + " " + else + north(position - 1) + fi fi + }; + + northeast(position : Int): String { + if (position - columns) < 0 then + " " + else if (((position + 1) /columns ) * columns) = (position + 1) then + " " + else + north(position + 1) + fi fi + }; + + southeast(position : Int): String { + if board_size < (position + columns) then + " " + else if (((position + 1) /columns ) * columns) = (position + 1) then + " " + else + south(position + 1) + fi fi + }; + + southwest(position : Int): String { + if board_size < (position + columns) then + " " + else if ((position / columns) * columns) = position then + " " + else + south(position - 1) + fi fi + }; + + neighbors(position: Int): Int { + { + if north(position) = "X" then 1 else 0 fi + + if south(position) = "X" then 1 else 0 fi + + if east(position) = "X" then 1 else 0 fi + + if west(position) = "X" then 1 else 0 fi + + if northeast(position) = "X" then 1 else 0 fi + + if northwest(position) = "X" then 1 else 0 fi + + if southeast(position) = "X" then 1 else 0 fi + + if southwest(position) = "X" then 1 else 0 fi; + } + }; + + +(* A cell will live if 2 or 3 of it's neighbors are alive. It dies + otherwise. A cell is born if only 3 of it's neighbors are alive. *) + + cell_at_next_evolution(position : Int) : String { + + if neighbors(position) = 3 then + "X" + else + if neighbors(position) = 2 then + if cell(position) = "X" then + "X" + else + "-" + fi + else + "-" + fi fi + }; + + + evolve() : CellularAutomaton { + (let position : Int <- 0 in + (let num : Int <- num_cells() in + (let temp : String in + { + while position < num loop + { + temp <- temp.concat(cell_at_next_evolution(position)); + position <- position + 1; + } + pool; + population_map <- temp; + self; + } + ) ) ) + }; + +(* This is where the background pattern is detremined by the user. More + patterns can be added as long as whoever adds keeps the board either + 3x5, 4x5, 5x5, 3x7, 7x4, 4x4 with the row first then column. *) + option(): String { + { + (let num : Int in + { + out_string("\nPlease chose a number:\n"); + out_string("\t1: A cross\n"); + out_string("\t2: A slash from the upper left to lower right\n"); + out_string("\t3: A slash from the upper right to lower left\n"); + out_string("\t4: An X\n"); + out_string("\t5: A greater than sign \n"); + out_string("\t6: A less than sign\n"); + out_string("\t7: Two greater than signs\n"); + out_string("\t8: Two less than signs\n"); + out_string("\t9: A 'V'\n"); + out_string("\t10: An inverse 'V'\n"); + out_string("\t11: Numbers 9 and 10 combined\n"); + out_string("\t12: A full grid\n"); + out_string("\t13: A 'T'\n"); + out_string("\t14: A plus '+'\n"); + out_string("\t15: A 'W'\n"); + out_string("\t16: An 'M'\n"); + out_string("\t17: An 'E'\n"); + out_string("\t18: A '3'\n"); + out_string("\t19: An 'O'\n"); + out_string("\t20: An '8'\n"); + out_string("\t21: An 'S'\n"); + out_string("Your choice => "); + num <- in_int(); + out_string("\n"); + if num = 1 then + " XX XXXX XXXX XX " + else if num = 2 then + " X X X X X " + else if num = 3 then + "X X X X X" + else if num = 4 then + "X X X X X X X X X" + else if num = 5 then + "X X X X X " + else if num = 6 then + " X X X X X" + else if num = 7 then + "X X X XX X " + else if num = 8 then + " X XX X X X " + else if num = 9 then + "X X X X X " + else if num = 10 then + " X X X X X" + else if num = 11 then + "X X X X X X X X" + else if num = 12 then + "XXXXXXXXXXXXXXXXXXXXXXXXX" + else if num = 13 then + "XXXXX X X X X " + else if num = 14 then + " X X XXXXX X X " + else if num = 15 then + "X X X X X X X " + else if num = 16 then + " X X X X X X X" + else if num = 17 then + "XXXXX X XXXXX X XXXX" + else if num = 18 then + "XXX X X X X XXXX " + else if num = 19 then + " XX X XX X XX " + else if num = 20 then + " XX X XX X XX X XX X XX " + else if num = 21 then + " XXXX X XX X XXXX " + else + " " + fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi fi; + } + ); + } + }; + + + + + prompt() : Bool { + { + (let ans : String in + { + out_string("Would you like to continue with the next generation? \n"); + out_string("Please use lowercase y or n for your answer [y]: "); + ans <- in_string(); + out_string("\n"); + if ans = "n" then + false + else + true + fi; + } + ); + } + }; + + + prompt2() : Bool { + (let ans : String in + { + out_string("\n\n"); + out_string("Would you like to choose a background pattern? \n"); + out_string("Please use lowercase y or n for your answer [n]: "); + ans <- in_string(); + if ans = "y" then + true + else + false + fi; + } + ) + }; + + +}; + +class Main inherits CellularAutomaton { + cells : CellularAutomaton; + + main() : Main { + { + (let continue : Bool in + (let choice : String in + { + out_string("Welcome to the Game of Life.\n"); + out_string("There are many initial states to choose from. \n"); + while prompt2() loop + { + continue <- true; + choice <- option(); + cells <- (new CellularAutomaton).init(choice); + cells.print(); + while continue loop + if prompt() then + { + cells.evolve(); + cells.print(); + } + else + continue <- false + fi + pool; + } + pool; + self; + } ) ); } + }; +}; + diff --git a/tests/codegen/life_input.txt b/tests/codegen/life_input.txt index 1dfbde620..07e016726 100644 --- a/tests/codegen/life_input.txt +++ b/tests/codegen/life_input.txt @@ -1,66 +1,66 @@ -y -1 -n -y -2 -n -y -3 -n -y -4 -n -y -5 -n -y -6 -n -y -7 -n -y -8 -n -y -9 -n -y -10 -n -y -11 -n -y -12 -n -y -13 -n -y -14 -n -y -15 -n -y -16 -n -y -17 -n -y -18 -n -y -19 -n -y -20 -n -y -21 -y -y -n +y +1 +n +y +2 +n +y +3 +n +y +4 +n +y +5 +n +y +6 +n +y +7 +n +y +8 +n +y +9 +n +y +10 +n +y +11 +n +y +12 +n +y +13 +n +y +14 +n +y +15 +n +y +16 +n +y +17 +n +y +18 +n +y +19 +n +y +20 +n +y +21 +y +y +n n \ No newline at end of file diff --git a/tests/codegen/life_output.txt b/tests/codegen/life_output.txt index e804b2382..5a9b9f73d 100644 --- a/tests/codegen/life_output.txt +++ b/tests/codegen/life_output.txt @@ -1,778 +1,778 @@ -Welcome to the Game of Life. -There are many initial states to choose from. - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - XX -XXXX -XXXX - XX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - X - X - X - X -X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X - X - X - X - X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X X - X X - X - X X -X X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X - X - X - X -X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - X - X - X - X - X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X X - X X -X X - - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - X X -X X - X X - - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X X - X X - X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - X - X X -X X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X X X - X X -X X X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -XXXXX -XXXXX -XXXXX -XXXXX -XXXXX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -XXXXX - X - X - X - X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - X - X -XXXXX - X - X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -X X - X X X - X X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - X X - X X X -X X - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -XXXX -X -X -XXXX -X -X -XXXX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - -XXX - X - X - X - X - X -XXX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - XX -X X -X X - XX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - XX -X X -X X - XX -X X -X X - XX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? -Please use lowercase y or n for your answer [n]: -Please chose a number: - 1: A cross - 2: A slash from the upper left to lower right - 3: A slash from the upper right to lower left - 4: An X - 5: A greater than sign - 6: A less than sign - 7: Two greater than signs - 8: Two less than signs - 9: A 'V' - 10: An inverse 'V' - 11: Numbers 9 and 10 combined - 12: A full grid - 13: A 'T' - 14: A plus '+' - 15: A 'W' - 16: An 'M' - 17: An 'E' - 18: A '3' - 19: An 'O' - 20: An '8' - 21: An 'S' -Your choice => - - XXX -X -X - XX - X - X -XXX - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - --XX- -X-X- -X--- --XX- ----X --X-X --XX- - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - --XX- -X-X- -X-X- --XX- --X-X --X-X --XX- - -Would you like to continue with the next generation? -Please use lowercase y or n for your answer [y]: - - -Would you like to choose a background pattern? +Welcome to the Game of Life. +There are many initial states to choose from. + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + XX +XXXX +XXXX + XX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + X + X + X + X +X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X + X + X + X + X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X X + X X + X + X X +X X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X + X + X + X +X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + X + X + X + X + X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X X + X X +X X + + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + X X +X X + X X + + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X X + X X + X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + X + X X +X X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X X X + X X +X X X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +XXXXX +XXXXX +XXXXX +XXXXX +XXXXX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +XXXXX + X + X + X + X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + X + X +XXXXX + X + X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +X X + X X X + X X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + X X + X X X +X X + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +XXXX +X +X +XXXX +X +X +XXXX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + +XXX + X + X + X + X + X +XXX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + XX +X X +X X + XX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + XX +X X +X X + XX +X X +X X + XX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? +Please use lowercase y or n for your answer [n]: +Please chose a number: + 1: A cross + 2: A slash from the upper left to lower right + 3: A slash from the upper right to lower left + 4: An X + 5: A greater than sign + 6: A less than sign + 7: Two greater than signs + 8: Two less than signs + 9: A 'V' + 10: An inverse 'V' + 11: Numbers 9 and 10 combined + 12: A full grid + 13: A 'T' + 14: A plus '+' + 15: A 'W' + 16: An 'M' + 17: An 'E' + 18: A '3' + 19: An 'O' + 20: An '8' + 21: An 'S' +Your choice => + + XXX +X +X + XX + X + X +XXX + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + +-XX- +X-X- +X--- +-XX- +---X +-X-X +-XX- + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + +-XX- +X-X- +X-X- +-XX- +-X-X +-X-X +-XX- + +Would you like to continue with the next generation? +Please use lowercase y or n for your answer [y]: + + +Would you like to choose a background pattern? Please use lowercase y or n for your answer [n]: \ No newline at end of file diff --git a/tests/codegen/list_output.txt b/tests/codegen/list_output.txt index 00d68ed23..fca724903 100644 --- a/tests/codegen/list_output.txt +++ b/tests/codegen/list_output.txt @@ -1,5 +1,5 @@ -5 4 3 2 1 -4 3 2 1 -3 2 1 -2 1 -1 +5 4 3 2 1 +4 3 2 1 +3 2 1 +2 1 +1 diff --git a/tests/codegen/new_complex.cl b/tests/codegen/new_complex.cl index ad7035b56..a4fe714ce 100755 --- a/tests/codegen/new_complex.cl +++ b/tests/codegen/new_complex.cl @@ -1,79 +1,79 @@ -class Main inherits IO { - main() : IO { - (let c : Complex <- (new Complex).init(1, 1) in - { - -- trivially equal (see CoolAid) - if c.reflect_X() = c.reflect_0() - then out_string("=)\n") - else out_string("=(\n") - fi; - -- equal - if c.reflect_X().reflect_Y().equal(c.reflect_0()) - then out_string("=)\n") - else out_string("=(\n") - fi; - } - ) - }; -}; - -class Complex inherits IO { - x : Int; - y : Int; - - init(a : Int, b : Int) : Complex { - { - x = a; - y = b; - self; - } - }; - - print() : Object { - if y = 0 - then out_int(x) - else out_int(x).out_string("+").out_int(y).out_string("I") - fi - }; - - reflect_0() : Complex { - { - x = ~x; - y = ~y; - self; - } - }; - - reflect_X() : Complex { - { - y = ~y; - self; - } - }; - - reflect_Y() : Complex { - { - x = ~x; - self; - } - }; - - equal(d : Complex) : Bool { - if x = d.x_value() - then - if y = d.y_value() - then true - else false - fi - else false - fi - }; - - x_value() : Int { - x - }; - - y_value() : Int { - y - }; -}; +class Main inherits IO { + main() : IO { + (let c : Complex <- (new Complex).init(1, 1) in + { + -- trivially equal (see CoolAid) + if c.reflect_X() = c.reflect_0() + then out_string("=)\n") + else out_string("=(\n") + fi; + -- equal + if c.reflect_X().reflect_Y().equal(c.reflect_0()) + then out_string("=)\n") + else out_string("=(\n") + fi; + } + ) + }; +}; + +class Complex inherits IO { + x : Int; + y : Int; + + init(a : Int, b : Int) : Complex { + { + x = a; + y = b; + self; + } + }; + + print() : Object { + if y = 0 + then out_int(x) + else out_int(x).out_string("+").out_int(y).out_string("I") + fi + }; + + reflect_0() : Complex { + { + x = ~x; + y = ~y; + self; + } + }; + + reflect_X() : Complex { + { + y = ~y; + self; + } + }; + + reflect_Y() : Complex { + { + x = ~x; + self; + } + }; + + equal(d : Complex) : Bool { + if x = d.x_value() + then + if y = d.y_value() + then true + else false + fi + else false + fi + }; + + x_value() : Int { + x + }; + + y_value() : Int { + y + }; +}; diff --git a/tests/codegen/new_complex_output.txt b/tests/codegen/new_complex_output.txt index 831c23af4..0e8da112c 100644 --- a/tests/codegen/new_complex_output.txt +++ b/tests/codegen/new_complex_output.txt @@ -1,2 +1,2 @@ -=) -=) +=) +=) diff --git a/tests/codegen/palindrome.cl b/tests/codegen/palindrome.cl index 6acbeb731..7f24789f9 100755 --- a/tests/codegen/palindrome.cl +++ b/tests/codegen/palindrome.cl @@ -1,25 +1,25 @@ -class Main inherits IO { - pal(s : String) : Bool { - if s.length() = 0 - then true - else if s.length() = 1 - then true - else if s.substr(0, 1) = s.substr(s.length() - 1, 1) - then pal(s.substr(1, s.length() -2)) - else false - fi fi fi - }; - - i : Int; - - main() : IO { - { - i <- ~1; - out_string("enter a string\n"); - if pal(in_string()) - then out_string("that was a palindrome\n") - else out_string("that was not a palindrome\n") - fi; - } - }; -}; +class Main inherits IO { + pal(s : String) : Bool { + if s.length() = 0 + then true + else if s.length() = 1 + then true + else if s.substr(0, 1) = s.substr(s.length() - 1, 1) + then pal(s.substr(1, s.length() -2)) + else false + fi fi fi + }; + + i : Int; + + main() : IO { + { + i <- ~1; + out_string("enter a string\n"); + if pal(in_string()) + then out_string("that was a palindrome\n") + else out_string("that was not a palindrome\n") + fi; + } + }; +}; diff --git a/tests/codegen/palindrome_input.txt b/tests/codegen/palindrome_input.txt index c49a0114c..8e1b64142 100644 --- a/tests/codegen/palindrome_input.txt +++ b/tests/codegen/palindrome_input.txt @@ -1 +1 @@ -anitalabalatina +anitalabalatina diff --git a/tests/codegen/palindrome_output.txt b/tests/codegen/palindrome_output.txt index e93d36585..7a0095959 100644 --- a/tests/codegen/palindrome_output.txt +++ b/tests/codegen/palindrome_output.txt @@ -1,2 +1,2 @@ -enter a string -that was a palindrome +enter a string +that was a palindrome diff --git a/tests/codegen/primes_output.txt b/tests/codegen/primes_output.txt index cf5d78d49..a4d0fcb3f 100644 --- a/tests/codegen/primes_output.txt +++ b/tests/codegen/primes_output.txt @@ -1,96 +1,96 @@ -2 is trivially prime. -3 is prime. -5 is prime. -7 is prime. -11 is prime. -13 is prime. -17 is prime. -19 is prime. -23 is prime. -29 is prime. -31 is prime. -37 is prime. -41 is prime. -43 is prime. -47 is prime. -53 is prime. -59 is prime. -61 is prime. -67 is prime. -71 is prime. -73 is prime. -79 is prime. -83 is prime. -89 is prime. -97 is prime. -101 is prime. -103 is prime. -107 is prime. -109 is prime. -113 is prime. -127 is prime. -131 is prime. -137 is prime. -139 is prime. -149 is prime. -151 is prime. -157 is prime. -163 is prime. -167 is prime. -173 is prime. -179 is prime. -181 is prime. -191 is prime. -193 is prime. -197 is prime. -199 is prime. -211 is prime. -223 is prime. -227 is prime. -229 is prime. -233 is prime. -239 is prime. -241 is prime. -251 is prime. -257 is prime. -263 is prime. -269 is prime. -271 is prime. -277 is prime. -281 is prime. -283 is prime. -293 is prime. -307 is prime. -311 is prime. -313 is prime. -317 is prime. -331 is prime. -337 is prime. -347 is prime. -349 is prime. -353 is prime. -359 is prime. -367 is prime. -373 is prime. -379 is prime. -383 is prime. -389 is prime. -397 is prime. -401 is prime. -409 is prime. -419 is prime. -421 is prime. -431 is prime. -433 is prime. -439 is prime. -443 is prime. -449 is prime. -457 is prime. -461 is prime. -463 is prime. -467 is prime. -479 is prime. -487 is prime. -491 is prime. -499 is prime. -Abort called from class String +2 is trivially prime. +3 is prime. +5 is prime. +7 is prime. +11 is prime. +13 is prime. +17 is prime. +19 is prime. +23 is prime. +29 is prime. +31 is prime. +37 is prime. +41 is prime. +43 is prime. +47 is prime. +53 is prime. +59 is prime. +61 is prime. +67 is prime. +71 is prime. +73 is prime. +79 is prime. +83 is prime. +89 is prime. +97 is prime. +101 is prime. +103 is prime. +107 is prime. +109 is prime. +113 is prime. +127 is prime. +131 is prime. +137 is prime. +139 is prime. +149 is prime. +151 is prime. +157 is prime. +163 is prime. +167 is prime. +173 is prime. +179 is prime. +181 is prime. +191 is prime. +193 is prime. +197 is prime. +199 is prime. +211 is prime. +223 is prime. +227 is prime. +229 is prime. +233 is prime. +239 is prime. +241 is prime. +251 is prime. +257 is prime. +263 is prime. +269 is prime. +271 is prime. +277 is prime. +281 is prime. +283 is prime. +293 is prime. +307 is prime. +311 is prime. +313 is prime. +317 is prime. +331 is prime. +337 is prime. +347 is prime. +349 is prime. +353 is prime. +359 is prime. +367 is prime. +373 is prime. +379 is prime. +383 is prime. +389 is prime. +397 is prime. +401 is prime. +409 is prime. +419 is prime. +421 is prime. +431 is prime. +433 is prime. +439 is prime. +443 is prime. +449 is prime. +457 is prime. +461 is prime. +463 is prime. +467 is prime. +479 is prime. +487 is prime. +491 is prime. +499 is prime. +Abort called from class String diff --git a/tests/codegen/print-cool_output.txt b/tests/codegen/print-cool_output.txt index 3c8cd620c..2b58f8985 100644 --- a/tests/codegen/print-cool_output.txt +++ b/tests/codegen/print-cool_output.txt @@ -1 +1 @@ -cool +cool diff --git a/tests/codegen/sort-list_input.txt b/tests/codegen/sort-list_input.txt index d43401489..f599e28b8 100644 --- a/tests/codegen/sort-list_input.txt +++ b/tests/codegen/sort-list_input.txt @@ -1 +1 @@ -10 +10 diff --git a/tests/codegen/sort-list_output.txt b/tests/codegen/sort-list_output.txt index 7b1d40452..9878d57ea 100644 --- a/tests/codegen/sort-list_output.txt +++ b/tests/codegen/sort-list_output.txt @@ -1,10 +1,10 @@ -How many numbers to sort? 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 +How many numbers to sort? 0 +1 +2 +3 +4 +5 +6 +7 +8 +9 diff --git a/tests/codegen_test.py b/tests/codegen_test.py index e748bd2d1..48df768ff 100644 --- a/tests/codegen_test.py +++ b/tests/codegen_test.py @@ -1,17 +1,17 @@ -import pytest -import os -from utils import compare_outputs - -tests_dir = __file__.rpartition('/')[0] + '/codegen/' -tests = [(file) for file in os.listdir(tests_dir) if file.endswith('.cl')] - -# @pytest.mark.lexer -# @pytest.mark.parser -# @pytest.mark.semantic -@pytest.mark.codegen -@pytest.mark.ok -@pytest.mark.run(order=4) -@pytest.mark.parametrize("cool_file", tests) -def test_codegen(compiler_path, cool_file): - compare_outputs(compiler_path, tests_dir + cool_file, tests_dir + cool_file[:-3] + '_input.txt',\ +import pytest +import os +from utils import compare_outputs + +tests_dir = __file__.rpartition('/')[0] + '/codegen/' +tests = [(file) for file in os.listdir(tests_dir) if file.endswith('.cl')] + +# @pytest.mark.lexer +# @pytest.mark.parser +# @pytest.mark.semantic +@pytest.mark.codegen +@pytest.mark.ok +@pytest.mark.run(order=4) +@pytest.mark.parametrize("cool_file", tests) +def test_codegen(compiler_path, cool_file): + compare_outputs(compiler_path, tests_dir + cool_file, tests_dir + cool_file[:-3] + '_input.txt',\ tests_dir + cool_file[:-3] + '_output.txt') \ No newline at end of file diff --git a/tests/conftest.py b/tests/conftest.py index 561d8bafc..1f44eeb72 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,6 @@ -import pytest -import os - -@pytest.fixture -def compiler_path(): +import pytest +import os + +@pytest.fixture +def compiler_path(): return os.path.abspath('./coolc.sh') \ No newline at end of file diff --git a/tests/lexer/comment1.cl b/tests/lexer/comment1.cl index 1b63af3c7..69533f23c 100644 --- a/tests/lexer/comment1.cl +++ b/tests/lexer/comment1.cl @@ -1,55 +1,55 @@ ---Any characters between two dashes “--” and the next newline ---(or EOF, if there is no next newline) are treated as comments - -(*(*(* -Comments may also be written by enclosing -text in (∗ . . . ∗). The latter form of comment may be nested. -Comments cannot cross file boundaries. -*)*)*) - -class Error() { - - (* There was once a comment, - that was quite long. - But, the reader soon discovered that - the comment was indeed longer than - previously assumed. Now, the reader - was in a real dilemma; is the comment - ever gonna end? If I stop reading, will - it end? - He started imagining all sorts of things. - He thought about heisenberg's cat and how - how that relates to the end of the sentence. - He thought to himself "I'm gonna stop reading". - "If I keep reading this comment, I'm gonna know - the fate of this sentence; That will be disastorous." - He knew that such a comment was gonna extend to - another file. It was too awesome to be contained in - a single file. And he would have kept reading too... - if only... - cool wasn't a super-duper-fab-awesomest language; - but cool is that language; - "This comment shall go not cross this file" said cool. - Alas! The reader could read no more. - There was once a comment, - that was quite long. - But, the reader soon discovered that - the comment was indeed longer than - previously assumed. Now, the reader - was in a real dilemma; is the comment - ever gonna end? If I stop reading, will - it end? - He started imagining all sorts of things. - He thought about heisenberg's cat and how - how that relates to the end of the sentence. - He thought to himself "I'm gonna stop reading". - "If I keep reading this comment, I'm gonna know - the fate of this sentence; That will be disastorous." - He knew that such a comment was gonna extend to - another file. It was too awesome to be contained in - a single file. And he would have kept reading too... - if only... - cool wasn't a super-duper-fab-awesomest language; - but cool is that language; - "This comment shall go not cross this file" said cool. +--Any characters between two dashes “--” and the next newline +--(or EOF, if there is no next newline) are treated as comments + +(*(*(* +Comments may also be written by enclosing +text in (∗ . . . ∗). The latter form of comment may be nested. +Comments cannot cross file boundaries. +*)*)*) + +class Error() { + + (* There was once a comment, + that was quite long. + But, the reader soon discovered that + the comment was indeed longer than + previously assumed. Now, the reader + was in a real dilemma; is the comment + ever gonna end? If I stop reading, will + it end? + He started imagining all sorts of things. + He thought about heisenberg's cat and how + how that relates to the end of the sentence. + He thought to himself "I'm gonna stop reading". + "If I keep reading this comment, I'm gonna know + the fate of this sentence; That will be disastorous." + He knew that such a comment was gonna extend to + another file. It was too awesome to be contained in + a single file. And he would have kept reading too... + if only... + cool wasn't a super-duper-fab-awesomest language; + but cool is that language; + "This comment shall go not cross this file" said cool. + Alas! The reader could read no more. + There was once a comment, + that was quite long. + But, the reader soon discovered that + the comment was indeed longer than + previously assumed. Now, the reader + was in a real dilemma; is the comment + ever gonna end? If I stop reading, will + it end? + He started imagining all sorts of things. + He thought about heisenberg's cat and how + how that relates to the end of the sentence. + He thought to himself "I'm gonna stop reading". + "If I keep reading this comment, I'm gonna know + the fate of this sentence; That will be disastorous." + He knew that such a comment was gonna extend to + another file. It was too awesome to be contained in + a single file. And he would have kept reading too... + if only... + cool wasn't a super-duper-fab-awesomest language; + but cool is that language; + "This comment shall go not cross this file" said cool. Alas! The reader could read no more. \ No newline at end of file diff --git a/tests/lexer/comment1_error.txt b/tests/lexer/comment1_error.txt index 710483ee9..9fd7b8d67 100644 --- a/tests/lexer/comment1_error.txt +++ b/tests/lexer/comment1_error.txt @@ -1 +1 @@ -(55, 46) - LexicographicError: EOF in comment +(55, 46) - LexicographicError: EOF in comment diff --git a/tests/lexer/iis1.cl b/tests/lexer/iis1.cl index ca6b68ac3..12cb52beb 100644 --- a/tests/lexer/iis1.cl +++ b/tests/lexer/iis1.cl @@ -1,111 +1,111 @@ -(* Integers, Identifiers, and Special Notation *) - -0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ -5! = 120, 2 + 2 = 5 or E = mc2; p + 1 @ p = 1: for x in range(len(b)) -new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) -class Class if then else fi testing Testing ~007agent_bond james_007B0N3SS___ -loop pool while tRuE or noT faLsE let in case of ESAC - -(* -#3 INT_CONST 0007 -#3 INT_CONST 123 -#3 '+' -#3 INT_CONST 1 -#3 '-' -#3 INT_CONST 1 -#3 '+' -#3 INT_CONST 90 -#3 '-' -#3 INT_CONST 09 -#3 '+' -#3 INT_CONST 11113 -#3 '-' -#3 INT_CONST 4 -#3 OBJECTID r -#3 '*' -#3 OBJECTID a -#3 '*' -#3 OBJECTID self -#3 '*' -#3 OBJECTID c -#3 '+' -#3 '+' -#4 INT_CONST 5 -#4 ERROR "!" -#4 '=' -#4 INT_CONST 120 -#4 ',' -#4 INT_CONST 2 -#4 '+' -#4 INT_CONST 2 -#4 '=' -#4 INT_CONST 5 -#4 OBJECTID or -#4 TYPEID E -#4 '=' -#4 OBJECTID mc2 -#4 ';' -#4 OBJECTID p -#4 '+' -#4 INT_CONST 1 -#4 '@' -#4 OBJECTID p -#4 '=' -#4 INT_CONST 1 -#4 ':' -#4 OBJECTID for -#4 OBJECTID x -#4 IN -#4 OBJECTID range -#4 '(' -#4 OBJECTID len -#4 '(' -#4 OBJECTID b -#4 ')' -#4 ')' -#5 NEW -#5 '/' -#5 ASSIGN -#5 '<' -#5 LE -#5 DARROW -#5 '{' -#5 '(' -#5 TYPEID Int -#5 ':' -#5 TYPEID Objet -#5 ',' -#5 TYPEID Bool -#5 ';' -#5 TYPEID String -#5 '.' -#5 OBJECTID string -#5 TYPEID SELF_TYPE -#5 ISVOID -#5 '}' -#5 ')' -#6 CLASS -#6 CLASS -#6 IF -#6 THEN -#6 ELSE -#6 FI -#6 OBJECTID testing -#6 TYPEID Testing -#6 '~' -#6 INT_CONST 007 -#6 OBJECTID agent_bond -#6 OBJECTID james_007B0N3SS___ -#7 LOOP -#7 POOL -#7 WHILE -#7 BOOL_CONST true -#7 OBJECTID or -#7 NOT -#7 BOOL_CONST false -#7 LET -#7 IN -#7 CASE -#7 OF -#7 ESAC +(* Integers, Identifiers, and Special Notation *) + +0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ +5! = 120, 2 + 2 = 5 or E = mc2; p + 1 @ p = 1: for x in range(len(b)) +new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) +class Class if then else fi testing Testing ~007agent_bond james_007B0N3SS___ +loop pool while tRuE or noT faLsE let in case of ESAC + +(* +#3 INT_CONST 0007 +#3 INT_CONST 123 +#3 '+' +#3 INT_CONST 1 +#3 '-' +#3 INT_CONST 1 +#3 '+' +#3 INT_CONST 90 +#3 '-' +#3 INT_CONST 09 +#3 '+' +#3 INT_CONST 11113 +#3 '-' +#3 INT_CONST 4 +#3 OBJECTID r +#3 '*' +#3 OBJECTID a +#3 '*' +#3 OBJECTID self +#3 '*' +#3 OBJECTID c +#3 '+' +#3 '+' +#4 INT_CONST 5 +#4 ERROR "!" +#4 '=' +#4 INT_CONST 120 +#4 ',' +#4 INT_CONST 2 +#4 '+' +#4 INT_CONST 2 +#4 '=' +#4 INT_CONST 5 +#4 OBJECTID or +#4 TYPEID E +#4 '=' +#4 OBJECTID mc2 +#4 ';' +#4 OBJECTID p +#4 '+' +#4 INT_CONST 1 +#4 '@' +#4 OBJECTID p +#4 '=' +#4 INT_CONST 1 +#4 ':' +#4 OBJECTID for +#4 OBJECTID x +#4 IN +#4 OBJECTID range +#4 '(' +#4 OBJECTID len +#4 '(' +#4 OBJECTID b +#4 ')' +#4 ')' +#5 NEW +#5 '/' +#5 ASSIGN +#5 '<' +#5 LE +#5 DARROW +#5 '{' +#5 '(' +#5 TYPEID Int +#5 ':' +#5 TYPEID Objet +#5 ',' +#5 TYPEID Bool +#5 ';' +#5 TYPEID String +#5 '.' +#5 OBJECTID string +#5 TYPEID SELF_TYPE +#5 ISVOID +#5 '}' +#5 ')' +#6 CLASS +#6 CLASS +#6 IF +#6 THEN +#6 ELSE +#6 FI +#6 OBJECTID testing +#6 TYPEID Testing +#6 '~' +#6 INT_CONST 007 +#6 OBJECTID agent_bond +#6 OBJECTID james_007B0N3SS___ +#7 LOOP +#7 POOL +#7 WHILE +#7 BOOL_CONST true +#7 OBJECTID or +#7 NOT +#7 BOOL_CONST false +#7 LET +#7 IN +#7 CASE +#7 OF +#7 ESAC *) \ No newline at end of file diff --git a/tests/lexer/iis1_error.txt b/tests/lexer/iis1_error.txt index 12f62f1ba..9e6d66cac 100644 --- a/tests/lexer/iis1_error.txt +++ b/tests/lexer/iis1_error.txt @@ -1 +1 @@ -(4, 2) - LexicographicError: ERROR "!" +(4, 2) - LexicographicError: ERROR "!" diff --git a/tests/lexer/iis2.cl b/tests/lexer/iis2.cl index d42552494..9b25715d4 100644 --- a/tests/lexer/iis2.cl +++ b/tests/lexer/iis2.cl @@ -1,120 +1,120 @@ -(* Integers, Identifiers, and Special Notation *) - -0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ -class Class if then else fi testing Testing ~007agent_bond james_007bones___ - - -new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) -loop pool while tRuE or noT faLsE let in case of ESAC - -factorial(5) = 120, 2 + 2 = 5? or E = mc2; p + 1 resto p = 1: (@ for x in range(len(b))) - -(* -#3 INT_CONST 0007 -#3 INT_CONST 123 -#3 '+' -#3 INT_CONST 1 -#3 '-' -#3 INT_CONST 1 -#3 '+' -#3 INT_CONST 90 -#3 '-' -#3 INT_CONST 09 -#3 '+' -#3 INT_CONST 11113 -#3 '-' -#3 INT_CONST 4 -#3 OBJECTID r -#3 '*' -#3 OBJECTID a -#3 '*' -#3 OBJECTID self -#3 '*' -#3 OBJECTID c -#3 '+' -#3 '+' -#4 CLASS -#4 CLASS -#4 IF -#4 THEN -#4 ELSE -#4 FI -#4 OBJECTID testing -#4 TYPEID Testing -#4 '~' -#4 INT_CONST 007 -#4 OBJECTID agent_bond -#4 OBJECTID james_007bones___ -#7 NEW -#7 '/' -#7 ASSIGN -#7 '<' -#7 LE -#7 DARROW -#7 '{' -#7 '(' -#7 TYPEID Int -#7 ':' -#7 TYPEID Objet -#7 ',' -#7 TYPEID Bool -#7 ';' -#7 TYPEID String -#7 '.' -#7 OBJECTID string -#7 TYPEID SELF_TYPE -#7 ISVOID -#7 '}' -#7 ')' -#8 LOOP -#8 POOL -#8 WHILE -#8 BOOL_CONST true -#8 OBJECTID or -#8 NOT -#8 BOOL_CONST false -#8 LET -#8 IN -#8 CASE -#8 OF -#8 ESAC -#10 OBJECTID factorial -#10 '(' -#10 INT_CONST 5 -#10 ')' -#10 '=' -#10 INT_CONST 120 -#10 ',' -#10 INT_CONST 2 -#10 '+' -#10 INT_CONST 2 -#10 '=' -#10 INT_CONST 5 -#10 ERROR "?" -#10 OBJECTID or -#10 TYPEID E -#10 '=' -#10 OBJECTID mc2 -#10 ';' -#10 OBJECTID p -#10 '+' -#10 INT_CONST 1 -#10 OBJECTID resto -#10 OBJECTID p -#10 '=' -#10 INT_CONST 1 -#10 ':' -#10 '(' -#10 '@' -#10 OBJECTID for -#10 OBJECTID x -#10 IN -#10 OBJECTID range -#10 '(' -#10 OBJECTID len -#10 '(' -#10 OBJECTID b -#10 ')' -#10 ')' -#10 ')' +(* Integers, Identifiers, and Special Notation *) + +0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ +class Class if then else fi testing Testing ~007agent_bond james_007bones___ + + +new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) +loop pool while tRuE or noT faLsE let in case of ESAC + +factorial(5) = 120, 2 + 2 = 5? or E = mc2; p + 1 resto p = 1: (@ for x in range(len(b))) + +(* +#3 INT_CONST 0007 +#3 INT_CONST 123 +#3 '+' +#3 INT_CONST 1 +#3 '-' +#3 INT_CONST 1 +#3 '+' +#3 INT_CONST 90 +#3 '-' +#3 INT_CONST 09 +#3 '+' +#3 INT_CONST 11113 +#3 '-' +#3 INT_CONST 4 +#3 OBJECTID r +#3 '*' +#3 OBJECTID a +#3 '*' +#3 OBJECTID self +#3 '*' +#3 OBJECTID c +#3 '+' +#3 '+' +#4 CLASS +#4 CLASS +#4 IF +#4 THEN +#4 ELSE +#4 FI +#4 OBJECTID testing +#4 TYPEID Testing +#4 '~' +#4 INT_CONST 007 +#4 OBJECTID agent_bond +#4 OBJECTID james_007bones___ +#7 NEW +#7 '/' +#7 ASSIGN +#7 '<' +#7 LE +#7 DARROW +#7 '{' +#7 '(' +#7 TYPEID Int +#7 ':' +#7 TYPEID Objet +#7 ',' +#7 TYPEID Bool +#7 ';' +#7 TYPEID String +#7 '.' +#7 OBJECTID string +#7 TYPEID SELF_TYPE +#7 ISVOID +#7 '}' +#7 ')' +#8 LOOP +#8 POOL +#8 WHILE +#8 BOOL_CONST true +#8 OBJECTID or +#8 NOT +#8 BOOL_CONST false +#8 LET +#8 IN +#8 CASE +#8 OF +#8 ESAC +#10 OBJECTID factorial +#10 '(' +#10 INT_CONST 5 +#10 ')' +#10 '=' +#10 INT_CONST 120 +#10 ',' +#10 INT_CONST 2 +#10 '+' +#10 INT_CONST 2 +#10 '=' +#10 INT_CONST 5 +#10 ERROR "?" +#10 OBJECTID or +#10 TYPEID E +#10 '=' +#10 OBJECTID mc2 +#10 ';' +#10 OBJECTID p +#10 '+' +#10 INT_CONST 1 +#10 OBJECTID resto +#10 OBJECTID p +#10 '=' +#10 INT_CONST 1 +#10 ':' +#10 '(' +#10 '@' +#10 OBJECTID for +#10 OBJECTID x +#10 IN +#10 OBJECTID range +#10 '(' +#10 OBJECTID len +#10 '(' +#10 OBJECTID b +#10 ')' +#10 ')' +#10 ')' *) \ No newline at end of file diff --git a/tests/lexer/iis2_error.txt b/tests/lexer/iis2_error.txt index 988d0286e..922391a9d 100644 --- a/tests/lexer/iis2_error.txt +++ b/tests/lexer/iis2_error.txt @@ -1 +1 @@ -(10, 30) - LexicographicError: ERROR "?" +(10, 30) - LexicographicError: ERROR "?" diff --git a/tests/lexer/iis3.cl b/tests/lexer/iis3.cl index dcd85f960..0b965ddea 100644 --- a/tests/lexer/iis3.cl +++ b/tests/lexer/iis3.cl @@ -1,121 +1,121 @@ -(* Integers, Identifiers, and Special Notation *) - -factorial(5) = 120, 2 + 2 = 5 or E = mc^2; p + 1 @ p = 1: z for x in range(len(b))) - -loop pool while tRuE or noT faLsE let in case of ESAC - -new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) - - -0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ -class Class if then else fi testing Testing ~007agent_bond james_007bones___ - -(* -#3 OBJECTID factorial -#3 '(' -#3 INT_CONST 5 -#3 ')' -#3 '=' -#3 INT_CONST 120 -#3 ',' -#3 INT_CONST 2 -#3 '+' -#3 INT_CONST 2 -#3 '=' -#3 INT_CONST 5 -#3 OBJECTID or -#3 TYPEID E -#3 '=' -#3 OBJECTID mc -#3 ERROR "^" -#3 INT_CONST 2 -#3 ';' -#3 OBJECTID p -#3 '+' -#3 INT_CONST 1 -#3 '@' -#3 OBJECTID p -#3 '=' -#3 INT_CONST 1 -#3 ':' -#3 OBJECTID z -#3 OBJECTID for -#3 OBJECTID x -#3 IN -#3 OBJECTID range -#3 '(' -#3 OBJECTID len -#3 '(' -#3 OBJECTID b -#3 ')' -#3 ')' -#3 ')' -#5 LOOP -#5 POOL -#5 WHILE -#5 BOOL_CONST true -#5 OBJECTID or -#5 NOT -#5 BOOL_CONST false -#5 LET -#5 IN -#5 CASE -#5 OF -#5 ESAC -#7 NEW -#7 '/' -#7 ASSIGN -#7 '<' -#7 LE -#7 DARROW -#7 '{' -#7 '(' -#7 TYPEID Int -#7 ':' -#7 TYPEID Objet -#7 ',' -#7 TYPEID Bool -#7 ';' -#7 TYPEID String -#7 '.' -#7 OBJECTID string -#7 TYPEID SELF_TYPE -#7 ISVOID -#7 '}' -#7 ')' -#10 INT_CONST 0007 -#10 INT_CONST 123 -#10 '+' -#10 INT_CONST 1 -#10 '-' -#10 INT_CONST 1 -#10 '+' -#10 INT_CONST 90 -#10 '-' -#10 INT_CONST 09 -#10 '+' -#10 INT_CONST 11113 -#10 '-' -#10 INT_CONST 4 -#10 OBJECTID r -#10 '*' -#10 OBJECTID a -#10 '*' -#10 OBJECTID self -#10 '*' -#10 OBJECTID c -#10 '+' -#10 '+' -#11 CLASS -#11 CLASS -#11 IF -#11 THEN -#11 ELSE -#11 FI -#11 OBJECTID testing -#11 TYPEID Testing -#11 '~' -#11 INT_CONST 007 -#11 OBJECTID agent_bond -#11 OBJECTID james_007bones___ +(* Integers, Identifiers, and Special Notation *) + +factorial(5) = 120, 2 + 2 = 5 or E = mc^2; p + 1 @ p = 1: z for x in range(len(b))) + +loop pool while tRuE or noT faLsE let in case of ESAC + +new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) + + +0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ +class Class if then else fi testing Testing ~007agent_bond james_007bones___ + +(* +#3 OBJECTID factorial +#3 '(' +#3 INT_CONST 5 +#3 ')' +#3 '=' +#3 INT_CONST 120 +#3 ',' +#3 INT_CONST 2 +#3 '+' +#3 INT_CONST 2 +#3 '=' +#3 INT_CONST 5 +#3 OBJECTID or +#3 TYPEID E +#3 '=' +#3 OBJECTID mc +#3 ERROR "^" +#3 INT_CONST 2 +#3 ';' +#3 OBJECTID p +#3 '+' +#3 INT_CONST 1 +#3 '@' +#3 OBJECTID p +#3 '=' +#3 INT_CONST 1 +#3 ':' +#3 OBJECTID z +#3 OBJECTID for +#3 OBJECTID x +#3 IN +#3 OBJECTID range +#3 '(' +#3 OBJECTID len +#3 '(' +#3 OBJECTID b +#3 ')' +#3 ')' +#3 ')' +#5 LOOP +#5 POOL +#5 WHILE +#5 BOOL_CONST true +#5 OBJECTID or +#5 NOT +#5 BOOL_CONST false +#5 LET +#5 IN +#5 CASE +#5 OF +#5 ESAC +#7 NEW +#7 '/' +#7 ASSIGN +#7 '<' +#7 LE +#7 DARROW +#7 '{' +#7 '(' +#7 TYPEID Int +#7 ':' +#7 TYPEID Objet +#7 ',' +#7 TYPEID Bool +#7 ';' +#7 TYPEID String +#7 '.' +#7 OBJECTID string +#7 TYPEID SELF_TYPE +#7 ISVOID +#7 '}' +#7 ')' +#10 INT_CONST 0007 +#10 INT_CONST 123 +#10 '+' +#10 INT_CONST 1 +#10 '-' +#10 INT_CONST 1 +#10 '+' +#10 INT_CONST 90 +#10 '-' +#10 INT_CONST 09 +#10 '+' +#10 INT_CONST 11113 +#10 '-' +#10 INT_CONST 4 +#10 OBJECTID r +#10 '*' +#10 OBJECTID a +#10 '*' +#10 OBJECTID self +#10 '*' +#10 OBJECTID c +#10 '+' +#10 '+' +#11 CLASS +#11 CLASS +#11 IF +#11 THEN +#11 ELSE +#11 FI +#11 OBJECTID testing +#11 TYPEID Testing +#11 '~' +#11 INT_CONST 007 +#11 OBJECTID agent_bond +#11 OBJECTID james_007bones___ *) \ No newline at end of file diff --git a/tests/lexer/iis3_error.txt b/tests/lexer/iis3_error.txt index 3abc2b556..b001b6a71 100644 --- a/tests/lexer/iis3_error.txt +++ b/tests/lexer/iis3_error.txt @@ -1 +1 @@ -(3, 40) - LexicographicError: ERROR "^" +(3, 40) - LexicographicError: ERROR "^" diff --git a/tests/lexer/iis4.cl b/tests/lexer/iis4.cl index 5357ab734..9e7a9cb62 100644 --- a/tests/lexer/iis4.cl +++ b/tests/lexer/iis4.cl @@ -1,120 +1,120 @@ -(* Integers, Identifiers, and Special Notation *) - -new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) -0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ - -factorial(5) = 120, 2 + 2 = 5 or E = mc2; p + 1 % p = 1: @.@ for x in range(len(b))~ - - -loop pool while tRuE or noT faLsE let in case of ESAC -class Class if then else fi testing Testing ~007agent_bond james_007bones___ - -(* -#3 NEW -#3 '/' -#3 ASSIGN -#3 '<' -#3 LE -#3 DARROW -#3 '{' -#3 '(' -#3 TYPEID Int -#3 ':' -#3 TYPEID Objet -#3 ',' -#3 TYPEID Bool -#3 ';' -#3 TYPEID String -#3 '.' -#3 OBJECTID string -#3 TYPEID SELF_TYPE -#3 ISVOID -#3 '}' -#3 ')' -#4 INT_CONST 0007 -#4 INT_CONST 123 -#4 '+' -#4 INT_CONST 1 -#4 '-' -#4 INT_CONST 1 -#4 '+' -#4 INT_CONST 90 -#4 '-' -#4 INT_CONST 09 -#4 '+' -#4 INT_CONST 11113 -#4 '-' -#4 INT_CONST 4 -#4 OBJECTID r -#4 '*' -#4 OBJECTID a -#4 '*' -#4 OBJECTID self -#4 '*' -#4 OBJECTID c -#4 '+' -#4 '+' -#6 OBJECTID factorial -#6 '(' -#6 INT_CONST 5 -#6 ')' -#6 '=' -#6 INT_CONST 120 -#6 ',' -#6 INT_CONST 2 -#6 '+' -#6 INT_CONST 2 -#6 '=' -#6 INT_CONST 5 -#6 OBJECTID or -#6 TYPEID E -#6 '=' -#6 OBJECTID mc2 -#6 ';' -#6 OBJECTID p -#6 '+' -#6 INT_CONST 1 -#6 ERROR "%" -#6 OBJECTID p -#6 '=' -#6 INT_CONST 1 -#6 ':' -#6 '@' -#6 '.' -#6 '@' -#6 OBJECTID for -#6 OBJECTID x -#6 IN -#6 OBJECTID range -#6 '(' -#6 OBJECTID len -#6 '(' -#6 OBJECTID b -#6 ')' -#6 ')' -#6 '~' -#9 LOOP -#9 POOL -#9 WHILE -#9 BOOL_CONST true -#9 OBJECTID or -#9 NOT -#9 BOOL_CONST false -#9 LET -#9 IN -#9 CASE -#9 OF -#9 ESAC -#10 CLASS -#10 CLASS -#10 IF -#10 THEN -#10 ELSE -#10 FI -#10 OBJECTID testing -#10 TYPEID Testing -#10 '~' -#10 INT_CONST 007 -#10 OBJECTID agent_bond -#10 OBJECTID james_007bones___ +(* Integers, Identifiers, and Special Notation *) + +new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) +0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ + +factorial(5) = 120, 2 + 2 = 5 or E = mc2; p + 1 % p = 1: @.@ for x in range(len(b))~ + + +loop pool while tRuE or noT faLsE let in case of ESAC +class Class if then else fi testing Testing ~007agent_bond james_007bones___ + +(* +#3 NEW +#3 '/' +#3 ASSIGN +#3 '<' +#3 LE +#3 DARROW +#3 '{' +#3 '(' +#3 TYPEID Int +#3 ':' +#3 TYPEID Objet +#3 ',' +#3 TYPEID Bool +#3 ';' +#3 TYPEID String +#3 '.' +#3 OBJECTID string +#3 TYPEID SELF_TYPE +#3 ISVOID +#3 '}' +#3 ')' +#4 INT_CONST 0007 +#4 INT_CONST 123 +#4 '+' +#4 INT_CONST 1 +#4 '-' +#4 INT_CONST 1 +#4 '+' +#4 INT_CONST 90 +#4 '-' +#4 INT_CONST 09 +#4 '+' +#4 INT_CONST 11113 +#4 '-' +#4 INT_CONST 4 +#4 OBJECTID r +#4 '*' +#4 OBJECTID a +#4 '*' +#4 OBJECTID self +#4 '*' +#4 OBJECTID c +#4 '+' +#4 '+' +#6 OBJECTID factorial +#6 '(' +#6 INT_CONST 5 +#6 ')' +#6 '=' +#6 INT_CONST 120 +#6 ',' +#6 INT_CONST 2 +#6 '+' +#6 INT_CONST 2 +#6 '=' +#6 INT_CONST 5 +#6 OBJECTID or +#6 TYPEID E +#6 '=' +#6 OBJECTID mc2 +#6 ';' +#6 OBJECTID p +#6 '+' +#6 INT_CONST 1 +#6 ERROR "%" +#6 OBJECTID p +#6 '=' +#6 INT_CONST 1 +#6 ':' +#6 '@' +#6 '.' +#6 '@' +#6 OBJECTID for +#6 OBJECTID x +#6 IN +#6 OBJECTID range +#6 '(' +#6 OBJECTID len +#6 '(' +#6 OBJECTID b +#6 ')' +#6 ')' +#6 '~' +#9 LOOP +#9 POOL +#9 WHILE +#9 BOOL_CONST true +#9 OBJECTID or +#9 NOT +#9 BOOL_CONST false +#9 LET +#9 IN +#9 CASE +#9 OF +#9 ESAC +#10 CLASS +#10 CLASS +#10 IF +#10 THEN +#10 ELSE +#10 FI +#10 OBJECTID testing +#10 TYPEID Testing +#10 '~' +#10 INT_CONST 007 +#10 OBJECTID agent_bond +#10 OBJECTID james_007bones___ *) \ No newline at end of file diff --git a/tests/lexer/iis4_error.txt b/tests/lexer/iis4_error.txt index aab8f39c1..f24076a8c 100644 --- a/tests/lexer/iis4_error.txt +++ b/tests/lexer/iis4_error.txt @@ -1 +1 @@ -(6, 49) - LexicographicError: ERROR "!" +(6, 49) - LexicographicError: ERROR "!" diff --git a/tests/lexer/iis5.cl b/tests/lexer/iis5.cl index f602488b9..d146c0547 100644 --- a/tests/lexer/iis5.cl +++ b/tests/lexer/iis5.cl @@ -1,121 +1,121 @@ -(* Integers, Identifiers, and Special Notation *) - - -loop pool while tRuE or noT faLsE let in case of ESAC -new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) -class Class if then else fi testing Testing ~007agent_bond james_007bones___ - -factorial(5) = 120, 2 + 2 = 5 or E = mc2; p + 1 resto p = 1: [@.@ for x in range(len(b))] - -0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ - -(* -#4 LOOP -#4 POOL -#4 WHILE -#4 BOOL_CONST true -#4 OBJECTID or -#4 NOT -#4 BOOL_CONST false -#4 LET -#4 IN -#4 CASE -#4 OF -#4 ESAC -#5 NEW -#5 '/' -#5 ASSIGN -#5 '<' -#5 LE -#5 DARROW -#5 '{' -#5 '(' -#5 TYPEID Int -#5 ':' -#5 TYPEID Objet -#5 ',' -#5 TYPEID Bool -#5 ';' -#5 TYPEID String -#5 '.' -#5 OBJECTID string -#5 TYPEID SELF_TYPE -#5 ISVOID -#5 '}' -#5 ')' -#6 CLASS -#6 CLASS -#6 IF -#6 THEN -#6 ELSE -#6 FI -#6 OBJECTID testing -#6 TYPEID Testing -#6 '~' -#6 INT_CONST 007 -#6 OBJECTID agent_bond -#6 OBJECTID james_007bones___ -#8 OBJECTID factorial -#8 '(' -#8 INT_CONST 5 -#8 ')' -#8 '=' -#8 INT_CONST 120 -#8 ',' -#8 INT_CONST 2 -#8 '+' -#8 INT_CONST 2 -#8 '=' -#8 INT_CONST 5 -#8 OBJECTID or -#8 TYPEID E -#8 '=' -#8 OBJECTID mc2 -#8 ';' -#8 OBJECTID p -#8 '+' -#8 INT_CONST 1 -#8 OBJECTID resto -#8 OBJECTID p -#8 '=' -#8 INT_CONST 1 -#8 ':' -#8 ERROR "[" -#8 '@' -#8 '.' -#8 '@' -#8 OBJECTID for -#8 OBJECTID x -#8 IN -#8 OBJECTID range -#8 '(' -#8 OBJECTID len -#8 '(' -#8 OBJECTID b -#8 ')' -#8 ')' -#8 ERROR "]" -#10 INT_CONST 0007 -#10 INT_CONST 123 -#10 '+' -#10 INT_CONST 1 -#10 '-' -#10 INT_CONST 1 -#10 '+' -#10 INT_CONST 90 -#10 '-' -#10 INT_CONST 09 -#10 '+' -#10 INT_CONST 11113 -#10 '-' -#10 INT_CONST 4 -#10 OBJECTID r -#10 '*' -#10 OBJECTID a -#10 '*' -#10 OBJECTID self -#10 '*' -#10 OBJECTID c -#10 '+' -#10 '+' -*) +(* Integers, Identifiers, and Special Notation *) + + +loop pool while tRuE or noT faLsE let in case of ESAC +new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) +class Class if then else fi testing Testing ~007agent_bond james_007bones___ + +factorial(5) = 120, 2 + 2 = 5 or E = mc2; p + 1 resto p = 1: [@.@ for x in range(len(b))] + +0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ + +(* +#4 LOOP +#4 POOL +#4 WHILE +#4 BOOL_CONST true +#4 OBJECTID or +#4 NOT +#4 BOOL_CONST false +#4 LET +#4 IN +#4 CASE +#4 OF +#4 ESAC +#5 NEW +#5 '/' +#5 ASSIGN +#5 '<' +#5 LE +#5 DARROW +#5 '{' +#5 '(' +#5 TYPEID Int +#5 ':' +#5 TYPEID Objet +#5 ',' +#5 TYPEID Bool +#5 ';' +#5 TYPEID String +#5 '.' +#5 OBJECTID string +#5 TYPEID SELF_TYPE +#5 ISVOID +#5 '}' +#5 ')' +#6 CLASS +#6 CLASS +#6 IF +#6 THEN +#6 ELSE +#6 FI +#6 OBJECTID testing +#6 TYPEID Testing +#6 '~' +#6 INT_CONST 007 +#6 OBJECTID agent_bond +#6 OBJECTID james_007bones___ +#8 OBJECTID factorial +#8 '(' +#8 INT_CONST 5 +#8 ')' +#8 '=' +#8 INT_CONST 120 +#8 ',' +#8 INT_CONST 2 +#8 '+' +#8 INT_CONST 2 +#8 '=' +#8 INT_CONST 5 +#8 OBJECTID or +#8 TYPEID E +#8 '=' +#8 OBJECTID mc2 +#8 ';' +#8 OBJECTID p +#8 '+' +#8 INT_CONST 1 +#8 OBJECTID resto +#8 OBJECTID p +#8 '=' +#8 INT_CONST 1 +#8 ':' +#8 ERROR "[" +#8 '@' +#8 '.' +#8 '@' +#8 OBJECTID for +#8 OBJECTID x +#8 IN +#8 OBJECTID range +#8 '(' +#8 OBJECTID len +#8 '(' +#8 OBJECTID b +#8 ')' +#8 ')' +#8 ERROR "]" +#10 INT_CONST 0007 +#10 INT_CONST 123 +#10 '+' +#10 INT_CONST 1 +#10 '-' +#10 INT_CONST 1 +#10 '+' +#10 INT_CONST 90 +#10 '-' +#10 INT_CONST 09 +#10 '+' +#10 INT_CONST 11113 +#10 '-' +#10 INT_CONST 4 +#10 OBJECTID r +#10 '*' +#10 OBJECTID a +#10 '*' +#10 OBJECTID self +#10 '*' +#10 OBJECTID c +#10 '+' +#10 '+' +*) diff --git a/tests/lexer/iis5_error.txt b/tests/lexer/iis5_error.txt index 9d6e1a738..b3dbadcb6 100644 --- a/tests/lexer/iis5_error.txt +++ b/tests/lexer/iis5_error.txt @@ -1,2 +1,2 @@ -(8, 62) - LexicographicError: ERROR "[" -(8, 89) - LexicographicError: ERROR "]" +(8, 62) - LexicographicError: ERROR "[" +(8, 89) - LexicographicError: ERROR "]" diff --git a/tests/lexer/iis6.cl b/tests/lexer/iis6.cl index ba93b19d9..1042f132b 100644 --- a/tests/lexer/iis6.cl +++ b/tests/lexer/iis6.cl @@ -1,125 +1,125 @@ -(* Integers, Identifiers, and Special Notation *) - -factorial(5) = 120, 2 + 2 = 5 or E = mc2; p + 1 resto p = 1: {@.@ for x in range(len(b))} - -new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) - - -class Class if then else fi testing Testing ~007agent_bond _james_007bones___ - - - -0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ -loop pool while tRuE or noT faLsE let in case of ESAC - -(* -#3 OBJECTID factorial -#3 '(' -#3 INT_CONST 5 -#3 ')' -#3 '=' -#3 INT_CONST 120 -#3 ',' -#3 INT_CONST 2 -#3 '+' -#3 INT_CONST 2 -#3 '=' -#3 INT_CONST 5 -#3 OBJECTID or -#3 TYPEID E -#3 '=' -#3 OBJECTID mc2 -#3 ';' -#3 OBJECTID p -#3 '+' -#3 INT_CONST 1 -#3 OBJECTID resto -#3 OBJECTID p -#3 '=' -#3 INT_CONST 1 -#3 ':' -#3 '{' -#3 '@' -#3 '.' -#3 '@' -#3 OBJECTID for -#3 OBJECTID x -#3 IN -#3 OBJECTID range -#3 '(' -#3 OBJECTID len -#3 '(' -#3 OBJECTID b -#3 ')' -#3 ')' -#3 '}' -#5 NEW -#5 '/' -#5 ASSIGN -#5 '<' -#5 LE -#5 DARROW -#5 '{' -#5 '(' -#5 TYPEID Int -#5 ':' -#5 TYPEID Objet -#5 ',' -#5 TYPEID Bool -#5 ';' -#5 TYPEID String -#5 '.' -#5 OBJECTID string -#5 TYPEID SELF_TYPE -#5 ISVOID -#5 '}' -#5 ')' -#8 CLASS -#8 CLASS -#8 IF -#8 THEN -#8 ELSE -#8 FI -#8 OBJECTID testing -#8 TYPEID Testing -#8 '~' -#8 INT_CONST 007 -#8 OBJECTID agent_bond -#8 ERROR "_" -#8 OBJECTID james_007bones___ -#12 INT_CONST 0007 -#12 INT_CONST 123 -#12 '+' -#12 INT_CONST 1 -#12 '-' -#12 INT_CONST 1 -#12 '+' -#12 INT_CONST 90 -#12 '-' -#12 INT_CONST 09 -#12 '+' -#12 INT_CONST 11113 -#12 '-' -#12 INT_CONST 4 -#12 OBJECTID r -#12 '*' -#12 OBJECTID a -#12 '*' -#12 OBJECTID self -#12 '*' -#12 OBJECTID c -#12 '+' -#12 '+' -#13 LOOP -#13 POOL -#13 WHILE -#13 BOOL_CONST true -#13 OBJECTID or -#13 NOT -#13 BOOL_CONST false -#13 LET -#13 IN -#13 CASE -#13 OF -#13 ESAC +(* Integers, Identifiers, and Special Notation *) + +factorial(5) = 120, 2 + 2 = 5 or E = mc2; p + 1 resto p = 1: {@.@ for x in range(len(b))} + +new / <- <<==> {( Int: Objet, Bool; String.string SELF_TYPE isvoid }) + + +class Class if then else fi testing Testing ~007agent_bond _james_007bones___ + + + +0007 123 +1 -1 +90 -09 +11113 -4r *a *self* c++ +loop pool while tRuE or noT faLsE let in case of ESAC + +(* +#3 OBJECTID factorial +#3 '(' +#3 INT_CONST 5 +#3 ')' +#3 '=' +#3 INT_CONST 120 +#3 ',' +#3 INT_CONST 2 +#3 '+' +#3 INT_CONST 2 +#3 '=' +#3 INT_CONST 5 +#3 OBJECTID or +#3 TYPEID E +#3 '=' +#3 OBJECTID mc2 +#3 ';' +#3 OBJECTID p +#3 '+' +#3 INT_CONST 1 +#3 OBJECTID resto +#3 OBJECTID p +#3 '=' +#3 INT_CONST 1 +#3 ':' +#3 '{' +#3 '@' +#3 '.' +#3 '@' +#3 OBJECTID for +#3 OBJECTID x +#3 IN +#3 OBJECTID range +#3 '(' +#3 OBJECTID len +#3 '(' +#3 OBJECTID b +#3 ')' +#3 ')' +#3 '}' +#5 NEW +#5 '/' +#5 ASSIGN +#5 '<' +#5 LE +#5 DARROW +#5 '{' +#5 '(' +#5 TYPEID Int +#5 ':' +#5 TYPEID Objet +#5 ',' +#5 TYPEID Bool +#5 ';' +#5 TYPEID String +#5 '.' +#5 OBJECTID string +#5 TYPEID SELF_TYPE +#5 ISVOID +#5 '}' +#5 ')' +#8 CLASS +#8 CLASS +#8 IF +#8 THEN +#8 ELSE +#8 FI +#8 OBJECTID testing +#8 TYPEID Testing +#8 '~' +#8 INT_CONST 007 +#8 OBJECTID agent_bond +#8 ERROR "_" +#8 OBJECTID james_007bones___ +#12 INT_CONST 0007 +#12 INT_CONST 123 +#12 '+' +#12 INT_CONST 1 +#12 '-' +#12 INT_CONST 1 +#12 '+' +#12 INT_CONST 90 +#12 '-' +#12 INT_CONST 09 +#12 '+' +#12 INT_CONST 11113 +#12 '-' +#12 INT_CONST 4 +#12 OBJECTID r +#12 '*' +#12 OBJECTID a +#12 '*' +#12 OBJECTID self +#12 '*' +#12 OBJECTID c +#12 '+' +#12 '+' +#13 LOOP +#13 POOL +#13 WHILE +#13 BOOL_CONST true +#13 OBJECTID or +#13 NOT +#13 BOOL_CONST false +#13 LET +#13 IN +#13 CASE +#13 OF +#13 ESAC *) \ No newline at end of file diff --git a/tests/lexer/iis6_error.txt b/tests/lexer/iis6_error.txt index 79a9d5aee..d7fad9c79 100644 --- a/tests/lexer/iis6_error.txt +++ b/tests/lexer/iis6_error.txt @@ -1 +1 @@ -(8, 60) - LexicographicError: ERROR "_" +(8, 60) - LexicographicError: ERROR "_" diff --git a/tests/lexer/mixed1.cl b/tests/lexer/mixed1.cl index d3e520a10..803d58ef5 100644 --- a/tests/lexer/mixed1.cl +++ b/tests/lexer/mixed1.cl @@ -1,14 +1,14 @@ -"lkjdsafkljdsalfj\u0000dsafdsaf\u0000djafslkjdsalf\nsdajf\" lkjfdsasdkjfl"123 -adsfasklj# -LKldsajf iNhERITS -"lkdsajf" - -(* -#1 STR_CONST "lkjdsafkljdsalfju0000dsafdsafu0000djafslkjdsalf\nsdajf\" lkjfdsasdkjfl" -#1 INT_CONST 123 -#2 OBJECTID adsfasklj -#2 ERROR "#" -#3 TYPEID LKldsajf -#3 INHERITS -#4 STR_CONST "lkdsajf" +"lkjdsafkljdsalfj\u0000dsafdsaf\u0000djafslkjdsalf\nsdajf\" lkjfdsasdkjfl"123 +adsfasklj# +LKldsajf iNhERITS +"lkdsajf" + +(* +#1 STR_CONST "lkjdsafkljdsalfju0000dsafdsafu0000djafslkjdsalf\nsdajf\" lkjfdsasdkjfl" +#1 INT_CONST 123 +#2 OBJECTID adsfasklj +#2 ERROR "#" +#3 TYPEID LKldsajf +#3 INHERITS +#4 STR_CONST "lkdsajf" *) \ No newline at end of file diff --git a/tests/lexer/mixed1_error.txt b/tests/lexer/mixed1_error.txt index a142c2edd..99af5fbdc 100644 --- a/tests/lexer/mixed1_error.txt +++ b/tests/lexer/mixed1_error.txt @@ -1 +1 @@ -(2, 10) - LexicographicError: ERROR "#" +(2, 10) - LexicographicError: ERROR "#" diff --git a/tests/lexer/mixed2.cl b/tests/lexer/mixed2.cl index 759bf9523..12039e123 100644 --- a/tests/lexer/mixed2.cl +++ b/tests/lexer/mixed2.cl @@ -1,20 +1,20 @@ -"kjas\"lnnsdj\nfljrdsaf" -@.$.@ -@*%*@ -"alkjfldajf""dasfadsf - -(* -#1 STR_CONST "kjas\"lnnsdj\nfljrdsaf" -#2 '@' -#2 '.' -#2 ERROR "$" -#2 '.' -#2 '@' -#3 '@' -#3 '*' -#3 ERROR "%" -#3 '*' -#3 '@' -#4 STR_CONST "alkjfldajf" -#4 ERROR "Unterminated string constant" +"kjas\"lnnsdj\nfljrdsaf" +@.$.@ +@*%*@ +"alkjfldajf""dasfadsf + +(* +#1 STR_CONST "kjas\"lnnsdj\nfljrdsaf" +#2 '@' +#2 '.' +#2 ERROR "$" +#2 '.' +#2 '@' +#3 '@' +#3 '*' +#3 ERROR "%" +#3 '*' +#3 '@' +#4 STR_CONST "alkjfldajf" +#4 ERROR "Unterminated string constant" *) \ No newline at end of file diff --git a/tests/lexer/mixed2_error.txt b/tests/lexer/mixed2_error.txt index 37cb73ac2..097dc2a07 100644 --- a/tests/lexer/mixed2_error.txt +++ b/tests/lexer/mixed2_error.txt @@ -1,3 +1,3 @@ -(2, 3) - LexicographicError: ERROR "$" -(3, 3) - LexicographicError: ERROR "%" -(4, 22) - LexicographicError: Unterminated string constant +(2, 3) - LexicographicError: ERROR "$" +(3, 3) - LexicographicError: ERROR "%" +(4, 22) - LexicographicError: Unterminated string constant diff --git a/tests/lexer/string1.cl b/tests/lexer/string1.cl index f0a5bd873..6c3c00833 100644 --- a/tests/lexer/string1.cl +++ b/tests/lexer/string1.cl @@ -1,6 +1,6 @@ -(* A non-escaped newline character may not appear in a string *) - -"This \ -is OK" -"This is not +(* A non-escaped newline character may not appear in a string *) + +"This \ +is OK" +"This is not OK" \ No newline at end of file diff --git a/tests/lexer/string1_error.txt b/tests/lexer/string1_error.txt index 1dd4d70d9..078c12bbb 100644 --- a/tests/lexer/string1_error.txt +++ b/tests/lexer/string1_error.txt @@ -1,2 +1,2 @@ -(5, 13) - LexicographicError: Unterminated string constant +(5, 13) - LexicographicError: Unterminated string constant (6, 4) - LexicographicError: EOF in string constant \ No newline at end of file diff --git a/tests/lexer/string2.cl b/tests/lexer/string2.cl index cb3024180..3704b6ae7 100644 --- a/tests/lexer/string2.cl +++ b/tests/lexer/string2.cl @@ -1,19 +1,19 @@ -(* A string may not contain EOF *) - -" May the Triforce \ - 0 \ - 0v0 \ - 0vvv0 \ - 0vvvvv0 \ - 0vvvvvvv0 \ - 0vvvvvvvvv0 \ - 0vvvvvvvvvvv0 \ - 000000000000000 \ - 0v0 0v0 \ - 0vvv0 0vvv0 \ - 0vvvvv0 0vvvvv0 \ - 0vvvvvvv0 0vvvvvvv0 \ - 0vvvvvvvvv0 0vvvvvvvvv0 \ - 0vvvvvvvvvvv0 0vvvvvvvvvvv0 \ - 00000000000000000000000000000 \ +(* A string may not contain EOF *) + +" May the Triforce \ + 0 \ + 0v0 \ + 0vvv0 \ + 0vvvvv0 \ + 0vvvvvvv0 \ + 0vvvvvvvvv0 \ + 0vvvvvvvvvvv0 \ + 000000000000000 \ + 0v0 0v0 \ + 0vvv0 0vvv0 \ + 0vvvvv0 0vvvvv0 \ + 0vvvvvvv0 0vvvvvvv0 \ + 0vvvvvvvvv0 0vvvvvvvvv0 \ + 0vvvvvvvvvvv0 0vvvvvvvvvvv0 \ + 00000000000000000000000000000 \ be with you! \ No newline at end of file diff --git a/tests/lexer/string4.cl b/tests/lexer/string4.cl index 7ca4eb42b..f4d39c027 100644 --- a/tests/lexer/string4.cl +++ b/tests/lexer/string4.cl @@ -1,38 +1,38 @@ -class Main { - str <- "The big brown fox - jumped over the fence"; - main() : Object { - { - out_string("Yay! This is the newest shites ); - } - }; -}; - -(* -#1 CLASS -#1 TYPEID Main -#1 '{' -#2 OBJECTID str -#2 ASSIGN -#3 ERROR "Unterminated string constant" -#3 OBJECTID jumped -#3 OBJECTID over -#3 OBJECTID the -#3 OBJECTID fence -#4 ERROR "Unterminated string constant" -#4 OBJECTID main -#4 '(' -#4 ')' -#4 ':' -#4 TYPEID Object -#4 '{' -#5 '{' -#6 OBJECTID out_string -#6 '(' -#7 ERROR "Unterminated string constant" -#7 '}' -#8 '}' -#8 ';' -#9 '}' -#9 ';' +class Main { + str <- "The big brown fox + jumped over the fence"; + main() : Object { + { + out_string("Yay! This is the newest shites ); + } + }; +}; + +(* +#1 CLASS +#1 TYPEID Main +#1 '{' +#2 OBJECTID str +#2 ASSIGN +#3 ERROR "Unterminated string constant" +#3 OBJECTID jumped +#3 OBJECTID over +#3 OBJECTID the +#3 OBJECTID fence +#4 ERROR "Unterminated string constant" +#4 OBJECTID main +#4 '(' +#4 ')' +#4 ':' +#4 TYPEID Object +#4 '{' +#5 '{' +#6 OBJECTID out_string +#6 '(' +#7 ERROR "Unterminated string constant" +#7 '}' +#8 '}' +#8 ';' +#9 '}' +#9 ';' *) \ No newline at end of file diff --git a/tests/lexer/string4_error.txt b/tests/lexer/string4_error.txt index bf420217c..5ab0ea847 100644 --- a/tests/lexer/string4_error.txt +++ b/tests/lexer/string4_error.txt @@ -1,3 +1,3 @@ -(2, 30) - LexicographicError: Unterminated string constant -(3, 36) - LexicographicError: Unterminated string constant +(2, 30) - LexicographicError: Unterminated string constant +(3, 36) - LexicographicError: Unterminated string constant (6, 58) - LexicographicError: Unterminated string constant \ No newline at end of file diff --git a/tests/lexer_test.py b/tests/lexer_test.py index a21fd880a..2a27223d3 100644 --- a/tests/lexer_test.py +++ b/tests/lexer_test.py @@ -1,13 +1,13 @@ -import pytest -import os -from utils import compare_errors - -tests_dir = __file__.rpartition('/')[0] + '/lexer/' -tests = [(file) for file in os.listdir(tests_dir) if file.endswith('.cl')] - -@pytest.mark.lexer -@pytest.mark.error -@pytest.mark.run(order=1) -@pytest.mark.parametrize("cool_file", tests) -def test_lexer_errors(compiler_path, cool_file): +import pytest +import os +from utils import compare_errors + +tests_dir = __file__.rpartition('/')[0] + '/lexer/' +tests = [(file) for file in os.listdir(tests_dir) if file.endswith('.cl')] + +@pytest.mark.lexer +@pytest.mark.error +@pytest.mark.run(order=1) +@pytest.mark.parametrize("cool_file", tests) +def test_lexer_errors(compiler_path, cool_file): compare_errors(compiler_path, tests_dir + cool_file, tests_dir + cool_file[:-3] + '_error.txt') \ No newline at end of file diff --git a/tests/parser/assignment1.cl b/tests/parser/assignment1.cl index e89ade368..75b4c5bbd 100644 --- a/tests/parser/assignment1.cl +++ b/tests/parser/assignment1.cl @@ -1,37 +1,37 @@ -(* An assignment has the form <- *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(): String { - Test1 <- "Hello World" -- Identifiers begin with a lower case letter - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* An assignment has the form <- *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(): String { + Test1 <- "Hello World" -- Identifiers begin with a lower case letter + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/assignment2.cl b/tests/parser/assignment2.cl index 7b8ed54ba..4efb96487 100644 --- a/tests/parser/assignment2.cl +++ b/tests/parser/assignment2.cl @@ -1,37 +1,37 @@ -(* An assignment has the form <- *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 - 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(): Int { - test1 <-- ~(1 + 2 + 3 + 4 + 5) -- The left side must be an expression - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* An assignment has the form <- *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 - 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(): Int { + test1 <-- ~(1 + 2 + 3 + 4 + 5) -- The left side must be an expression + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/assignment3.cl b/tests/parser/assignment3.cl index f54305e27..ff633f331 100644 --- a/tests/parser/assignment3.cl +++ b/tests/parser/assignment3.cl @@ -1,37 +1,37 @@ -(* An assignment has the form <- *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(): Bool { - test1 <- true++ -- The left side must be an expression - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* An assignment has the form <- *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(): Bool { + test1 <- true++ -- The left side must be an expression + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/attribute1.cl b/tests/parser/attribute1.cl index 59740336d..063a02c02 100644 --- a/tests/parser/attribute1.cl +++ b/tests/parser/attribute1.cl @@ -1,34 +1,34 @@ -(* An attribute of class A specifies a variable that is part of the state of objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - -- Attributes names must begin with lowercase letters - Test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* An attribute of class A specifies a variable that is part of the state of objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + -- Attributes names must begin with lowercase letters + Test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/attribute2.cl b/tests/parser/attribute2.cl index 337696859..c05211483 100644 --- a/tests/parser/attribute2.cl +++ b/tests/parser/attribute2.cl @@ -1,34 +1,34 @@ -(* An attribute of class A specifies a variable that is part of the state of objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - -- Type names must begin with uppercase letters - test3: string <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* An attribute of class A specifies a variable that is part of the state of objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + -- Type names must begin with uppercase letters + test3: string <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/attribute3.cl b/tests/parser/attribute3.cl index b29b4b26d..d858ae47c 100644 --- a/tests/parser/attribute3.cl +++ b/tests/parser/attribute3.cl @@ -1,34 +1,34 @@ -(* An attribute of class A specifies a variable that is part of the state of objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - -- Expected '<-' not '<=' - test3: String <= "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* An attribute of class A specifies a variable that is part of the state of objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + -- Expected '<-' not '<=' + test3: String <= "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/block1.cl b/tests/parser/block1.cl index f15872812..3613d9268 100644 --- a/tests/parser/block1.cl +++ b/tests/parser/block1.cl @@ -1,87 +1,87 @@ -(* A block has the form { ; ... ; } *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - pow: Int <- 1; - count: Int <- 0; - - testing6(a: Int): IO { - { - count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2 -- Missing ";" - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A block has the form { ; ... ; } *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + pow: Int <- 1; + count: Int <- 0; + + testing6(a: Int): IO { + { + count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2 -- Missing ";" + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/block2.cl b/tests/parser/block2.cl index 1f45fca4c..f485dd0b1 100644 --- a/tests/parser/block2.cl +++ b/tests/parser/block2.cl @@ -1,87 +1,87 @@ -(* A block has the form { ; ... ; } *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - pow: Int <- 1; - count: Int <- 0; - - testing6(a: Int): IO { - -- Missing "{" - count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A block has the form { ; ... ; } *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + pow: Int <- 1; + count: Int <- 0; + + testing6(a: Int): IO { + -- Missing "{" + count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/block3.cl b/tests/parser/block3.cl index 9b63b0015..ae1598c3b 100644 --- a/tests/parser/block3.cl +++ b/tests/parser/block3.cl @@ -1,87 +1,87 @@ -(* A block has the form { ; ... ; } *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - pow: Int <- 1; - count: Int <- 0; - - testing6(a: Int): IO { - { - count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - -- Missing "}" - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A block has the form { ; ... ; } *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + pow: Int <- 1; + count: Int <- 0; + + testing6(a: Int): IO { + { + count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + -- Missing "}" + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/block4.cl b/tests/parser/block4.cl index c144dae48..8fd883d02 100644 --- a/tests/parser/block4.cl +++ b/tests/parser/block4.cl @@ -1,88 +1,88 @@ -(* A block has the form { ; ... ; } *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - pow: Int <- 1; - count: Int <- 0; - - testing6(a: Int): IO { - { - count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - true++; -- Only expressions - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A block has the form { ; ... ; } *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + pow: Int <- 1; + count: Int <- 0; + + testing6(a: Int): IO { + { + count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + true++; -- Only expressions + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/case1.cl b/tests/parser/case1.cl index 35fe5af53..c2f508809 100644 --- a/tests/parser/case1.cl +++ b/tests/parser/case1.cl @@ -1,91 +1,91 @@ -(* Case expressions provide runtime type tests on objects *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case 2 + 2 of - -- Every case expression must have at least one branch - esac - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Case expressions provide runtime type tests on objects *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case 2 + 2 of + -- Every case expression must have at least one branch + esac + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/case2.cl b/tests/parser/case2.cl index 12cbb87b5..f9162e49f 100644 --- a/tests/parser/case2.cl +++ b/tests/parser/case2.cl @@ -1,93 +1,93 @@ -(* Case expressions provide runtime type tests on objects *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case "2 + 2" of - x: Int => new IO.out_string("Es un entero!") -- Missing ";" - y: String => new IO.out_string("Es una cadena!"); - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Case expressions provide runtime type tests on objects *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case "2 + 2" of + x: Int => new IO.out_string("Es un entero!") -- Missing ";" + y: String => new IO.out_string("Es una cadena!"); + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/case3.cl b/tests/parser/case3.cl index 8fd851836..a7eedc18b 100644 --- a/tests/parser/case3.cl +++ b/tests/parser/case3.cl @@ -1,93 +1,93 @@ -(* Case expressions provide runtime type tests on objects *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case 2 + false of - x: Int => new IO.out_string("Es un entero!"); - y: string => new IO.out_string("Es una cadena!"); -- Type identifiers starts with a uppercase letter - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Case expressions provide runtime type tests on objects *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case 2 + false of + x: Int => new IO.out_string("Es un entero!"); + y: string => new IO.out_string("Es una cadena!"); -- Type identifiers starts with a uppercase letter + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/case4.cl b/tests/parser/case4.cl index eb8a3d3a2..25ca3858f 100644 --- a/tests/parser/case4.cl +++ b/tests/parser/case4.cl @@ -1,93 +1,93 @@ -(* Case expressions provide runtime type tests on objects *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case true of - x: Int => new IO.out_string("Es un entero!"); - y: String => new IO.out_string("Es una cadena!"); - Mazinger_Z: Bool => new IO.out_string("Es un booleano!"); -- Identifiers starts with a lowercase letter - esac - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Case expressions provide runtime type tests on objects *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case true of + x: Int => new IO.out_string("Es un entero!"); + y: String => new IO.out_string("Es una cadena!"); + Mazinger_Z: Bool => new IO.out_string("Es un booleano!"); -- Identifiers starts with a lowercase letter + esac + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/case5.cl b/tests/parser/case5.cl index f0483f1f5..b36c663e1 100644 --- a/tests/parser/case5.cl +++ b/tests/parser/case5.cl @@ -1,93 +1,93 @@ -(* Case expressions provide runtime type tests on objects *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case test2 of - x: Int <- new IO.out_string("Es un entero!"); -- Must be '=>' not '<-'; - y: String => new IO.out_string("Es una cadena!"); - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Case expressions provide runtime type tests on objects *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case test2 of + x: Int <- new IO.out_string("Es un entero!"); -- Must be '=>' not '<-'; + y: String => new IO.out_string("Es una cadena!"); + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/case6.cl b/tests/parser/case6.cl index c49467a89..66e7df2ab 100644 --- a/tests/parser/case6.cl +++ b/tests/parser/case6.cl @@ -1,93 +1,93 @@ -(* Case expressions provide runtime type tests on objects *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case 2 + 2 -- Missing "of" - x: Int => new IO.out_string("Es un entero!"); - y: String => new IO.out_string("Es una cadena!"); - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Case expressions provide runtime type tests on objects *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case 2 + 2 -- Missing "of" + x: Int => new IO.out_string("Es un entero!"); + y: String => new IO.out_string("Es una cadena!"); + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/class1.cl b/tests/parser/class1.cl index 1c0641a94..f4815e3f4 100644 --- a/tests/parser/class1.cl +++ b/tests/parser/class1.cl @@ -1,20 +1,20 @@ -(* A class is a list of features *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - testing(): Int { - 2 + 2 - }; -}; - --- Class names must begin with uppercase letters -class alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; -}; +(* A class is a list of features *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + testing(): Int { + 2 + 2 + }; +}; + +-- Class names must begin with uppercase letters +class alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; +}; diff --git a/tests/parser/class2.cl b/tests/parser/class2.cl index baf290822..f363b032a 100644 --- a/tests/parser/class2.cl +++ b/tests/parser/class2.cl @@ -1,20 +1,20 @@ -(* A class is a list of features *) - -CLaSS Main { - main(): Object { - (new Alpha).print() - }; -}; - -CLaSS Test { - testing(): Int { - 2 + 2 - }; -}; - --- Type names must begin with uppercase letters -CLaSS Alpha iNHeRiTS iO { - print() : Object { - out_string("reached!!\n") - }; -}; +(* A class is a list of features *) + +CLaSS Main { + main(): Object { + (new Alpha).print() + }; +}; + +CLaSS Test { + testing(): Int { + 2 + 2 + }; +}; + +-- Type names must begin with uppercase letters +CLaSS Alpha iNHeRiTS iO { + print() : Object { + out_string("reached!!\n") + }; +}; diff --git a/tests/parser/class3.cl b/tests/parser/class3.cl index 5c89c5eb8..0c801372a 100644 --- a/tests/parser/class3.cl +++ b/tests/parser/class3.cl @@ -1,34 +1,34 @@ -(* A class is a list of features *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - -- Missing semicolon - testing2(a: Alpha, b: Int): Int { - 2 + 2 - } - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; -}; +(* A class is a list of features *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + -- Missing semicolon + testing2(a: Alpha, b: Int): Int { + 2 + 2 + } + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; +}; diff --git a/tests/parser/class4.cl b/tests/parser/class4.cl index cdfbc313c..5c286b5e6 100644 --- a/tests/parser/class4.cl +++ b/tests/parser/class4.cl @@ -1,36 +1,36 @@ -(* A class is a list of features *) - -CLaSS Main { - main(): Object { - (new Alpha).print() - }; -}; - -CLaSS Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - -- Only features - 2 + 2; - - testing3(): String { - "2 + 2" - }; -}; - -CLaSS Alpha iNHeRiTS IO { - print() : Object { - out_string("reached!!\n") - }; -}; +(* A class is a list of features *) + +CLaSS Main { + main(): Object { + (new Alpha).print() + }; +}; + +CLaSS Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + -- Only features + 2 + 2; + + testing3(): String { + "2 + 2" + }; +}; + +CLaSS Alpha iNHeRiTS IO { + print() : Object { + out_string("reached!!\n") + }; +}; diff --git a/tests/parser/class5.cl b/tests/parser/class5.cl index d6b5c5fda..3f40c36eb 100644 --- a/tests/parser/class5.cl +++ b/tests/parser/class5.cl @@ -1,34 +1,34 @@ -(* A class is a list of features *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - --- Missing '{' -class Test - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; -}; +(* A class is a list of features *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +-- Missing '{' +class Test + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; +}; diff --git a/tests/parser/class6.cl b/tests/parser/class6.cl index af9ecbf15..8501d2593 100644 --- a/tests/parser/class6.cl +++ b/tests/parser/class6.cl @@ -1,34 +1,34 @@ -(* A class is a list of features *) - -CLaSS Main { - main(): Object { - (new Alpha).print() - }; -}; - --- Missing '}' -CLaSS Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; -; - -CLaSS Alpha iNHeRiTS IO { - print() : Object { - out_string("reached!!\n") - }; -}; +(* A class is a list of features *) + +CLaSS Main { + main(): Object { + (new Alpha).print() + }; +}; + +-- Missing '}' +CLaSS Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; +; + +CLaSS Alpha iNHeRiTS IO { + print() : Object { + out_string("reached!!\n") + }; +}; diff --git a/tests/parser/conditional1.cl b/tests/parser/conditional1.cl index f03b9c4e6..4d546fc44 100644 --- a/tests/parser/conditional1.cl +++ b/tests/parser/conditional1.cl @@ -1,69 +1,69 @@ -(* A conditional has the form if then else fi *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - if a.length() < b.length() -- Mising "then" - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - else - if a.length() = b.length() then - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - else - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fi - fi - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A conditional has the form if then else fi *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + if a.length() < b.length() -- Mising "then" + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + else + if a.length() = b.length() then + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + else + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fi + fi + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/conditional2.cl b/tests/parser/conditional2.cl index 9ebd7fe84..4f10c2957 100644 --- a/tests/parser/conditional2.cl +++ b/tests/parser/conditional2.cl @@ -1,69 +1,69 @@ -(* A conditional has the form if then else fi *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - if a.length() < b.length() then - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - else - if a.length() = b.length() then - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - else - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - -- Missing "fi" - fi - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A conditional has the form if then else fi *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + if a.length() < b.length() then + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + else + if a.length() = b.length() then + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + else + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + -- Missing "fi" + fi + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/conditional3.cl b/tests/parser/conditional3.cl index ac143ad42..67e991ade 100644 --- a/tests/parser/conditional3.cl +++ b/tests/parser/conditional3.cl @@ -1,69 +1,69 @@ -(* A conditional has the form if then else fi *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - iF a.length() < b.length() tHen - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - elsE - if a.length() = b.length() then - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - eLseif -- elseif isn't a keyword - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A conditional has the form if then else fi *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + iF a.length() < b.length() tHen + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + elsE + if a.length() = b.length() then + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + eLseif -- elseif isn't a keyword + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/conditional4.cl b/tests/parser/conditional4.cl index 51337f874..0792fdc85 100644 --- a/tests/parser/conditional4.cl +++ b/tests/parser/conditional4.cl @@ -1,73 +1,73 @@ -(* A conditional has the form if then else fi *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(): Int { - if true++ then 1 else 0 -- Condition must be an expression - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A conditional has the form if then else fi *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(): Int { + if true++ then 1 else 0 -- Condition must be an expression + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/conditional5.cl b/tests/parser/conditional5.cl index 399515701..0c1e1aad0 100644 --- a/tests/parser/conditional5.cl +++ b/tests/parser/conditional5.cl @@ -1,73 +1,73 @@ -(* A conditional has the form if then else fi *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(): Int { - if true then true++ else 0 -- If branch must be an expression - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A conditional has the form if then else fi *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(): Int { + if true then true++ else 0 -- If branch must be an expression + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/conditional6.cl b/tests/parser/conditional6.cl index 8daa35d7f..02310404a 100644 --- a/tests/parser/conditional6.cl +++ b/tests/parser/conditional6.cl @@ -1,73 +1,73 @@ -(* A conditional has the form if then else fi *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(): Int { - if true then 1 else false++ -- Else branch must be an expression - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A conditional has the form if then else fi *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(): Int { + if true then 1 else false++ -- Else branch must be an expression + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch1.cl b/tests/parser/dispatch1.cl index 2eba9db03..2ca394716 100644 --- a/tests/parser/dispatch1.cl +++ b/tests/parser/dispatch1.cl @@ -1,45 +1,45 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - Test1.testing4(1, 2).testing4(3, 4).testing4(5, 6) -- Objet identifiers begin with a lower case letter - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + Test1.testing4(1, 2).testing4(3, 4).testing4(5, 6) -- Objet identifiers begin with a lower case letter + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch2.cl b/tests/parser/dispatch2.cl index 139eba918..0b57467a1 100644 --- a/tests/parser/dispatch2.cl +++ b/tests/parser/dispatch2.cl @@ -1,45 +1,45 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13,) -- Extra comma - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13,) -- Extra comma + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch3.cl b/tests/parser/dispatch3.cl index 0d88f5c23..9f1a5afff 100644 --- a/tests/parser/dispatch3.cl +++ b/tests/parser/dispatch3.cl @@ -1,45 +1,45 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).Testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) -- Identifiers begin with a lower case letter - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).Testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) -- Identifiers begin with a lower case letter + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch4.cl b/tests/parser/dispatch4.cl index dc13fd762..d1efc469d 100644 --- a/tests/parser/dispatch4.cl +++ b/tests/parser/dispatch4.cl @@ -1,53 +1,53 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - self.testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true++) -- Arguments must be expressions - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + self.testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true++) -- Arguments must be expressions + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch5.cl b/tests/parser/dispatch5.cl index b7bae25e1..63a5afa79 100644 --- a/tests/parser/dispatch5.cl +++ b/tests/parser/dispatch5.cl @@ -1,53 +1,53 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, ,true + fALSE) -- Extra comma - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, ,true + fALSE) -- Extra comma + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch6.cl b/tests/parser/dispatch6.cl index 6887c60cd..0a953e2e6 100644 --- a/tests/parser/dispatch6.cl +++ b/tests/parser/dispatch6.cl @@ -1,57 +1,57 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@object.copy() -- Type identifiers begin with a upper case letter - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@object.copy() -- Type identifiers begin with a upper case letter + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch7.cl b/tests/parser/dispatch7.cl index a9ff1b67a..3ecac4d0f 100644 --- a/tests/parser/dispatch7.cl +++ b/tests/parser/dispatch7.cl @@ -1,57 +1,57 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.Copy() -- Identifiers begin with a lower case letter - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.Copy() -- Identifiers begin with a lower case letter + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch8.cl b/tests/parser/dispatch8.cl index c1bb2abba..eef0455ef 100644 --- a/tests/parser/dispatch8.cl +++ b/tests/parser/dispatch8.cl @@ -1,57 +1,57 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy(,) -- Extra comma - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy(,) -- Extra comma + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/dispatch9.cl b/tests/parser/dispatch9.cl index 8914a18c2..5fdef22d6 100644 --- a/tests/parser/dispatch9.cl +++ b/tests/parser/dispatch9.cl @@ -1,61 +1,61 @@ -(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; - - testing5(): Object { - test1:Object.copy() -- Must be '@' not ':' - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* There are three forms of dispatch (i.e. method call) in Cool. The three forms differ only in how the called method is selected *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; + + testing5(): Object { + test1:Object.copy() -- Must be '@' not ':' + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/let1.cl b/tests/parser/let1.cl index 0e5fc6d17..576ae383c 100644 --- a/tests/parser/let1.cl +++ b/tests/parser/let1.cl @@ -1,85 +1,85 @@ -(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let Count: Int <- 0, pow: Int <- 1 -- Object identifiers starts with a lowercase letter - in { - -- count <- 0; - -- pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let Count: Int <- 0, pow: Int <- 1 -- Object identifiers starts with a lowercase letter + in { + -- count <- 0; + -- pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/let2.cl b/tests/parser/let2.cl index 01d055dac..4cfaef0f8 100644 --- a/tests/parser/let2.cl +++ b/tests/parser/let2.cl @@ -1,85 +1,85 @@ -(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int, pow: int <- 1 -- Type identifiers starts with a uppercase letter - in { - count <- 0; - -- pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int, pow: int <- 1 -- Type identifiers starts with a uppercase letter + in { + count <- 0; + -- pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/let3.cl b/tests/parser/let3.cl index b2b2fb005..91e567fd8 100644 --- a/tests/parser/let3.cl +++ b/tests/parser/let3.cl @@ -1,85 +1,85 @@ -(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int, pow: Int, -- Extra comma - in { - count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int, pow: Int, -- Extra comma + in { + count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/let4.cl b/tests/parser/let4.cl index c7d0ea8e3..a716c332d 100644 --- a/tests/parser/let4.cl +++ b/tests/parser/let4.cl @@ -1,85 +1,85 @@ -(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- true++, pow: Int <- 1 -- Initialization must be an expression - in { - count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- true++, pow: Int <- 1 -- Initialization must be an expression + in { + count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/let5.cl b/tests/parser/let5.cl index cc4ed7a99..d974cc138 100644 --- a/tests/parser/let5.cl +++ b/tests/parser/let5.cl @@ -1,85 +1,85 @@ -(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int = 0, pow: Int -- Must be '<-' not '=' - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int = 0, pow: Int -- Must be '<-' not '=' + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/let6.cl b/tests/parser/let6.cl index 8bc8c4883..b6e51d7e1 100644 --- a/tests/parser/let6.cl +++ b/tests/parser/let6.cl @@ -1,74 +1,74 @@ -(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int <- 1 - in false++ -- Let body must be an expression - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int <- 1 + in false++ -- Let body must be an expression + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/let7.cl b/tests/parser/let7.cl index 816c59845..6fd63e6a7 100644 --- a/tests/parser/let7.cl +++ b/tests/parser/let7.cl @@ -1,85 +1,85 @@ -(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - (* Missing "in" *) { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A let expression has the form let : [ <- ], ..., : [ <- ] in *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + (* Missing "in" *) { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/loop1.cl b/tests/parser/loop1.cl index 2065de506..7d0d7688f 100644 --- a/tests/parser/loop1.cl +++ b/tests/parser/loop1.cl @@ -1,78 +1,78 @@ -(* A loop has the form while loop pool *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - count: Int <- 1; - - testing6(): Object { - while count < 1024*1024 - -- Missing "loop" - count <- count * 2 - pool - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A loop has the form while loop pool *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + count: Int <- 1; + + testing6(): Object { + while count < 1024*1024 + -- Missing "loop" + count <- count * 2 + pool + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/loop2.cl b/tests/parser/loop2.cl index 70f8cd910..a9613c487 100644 --- a/tests/parser/loop2.cl +++ b/tests/parser/loop2.cl @@ -1,78 +1,78 @@ -(* A loop has the form while loop pool *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - count: Int <- 1; - - testing6(): Object { - while count < 1024*1024 - loop - count <- count * 2 - -- Missing "pool" - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A loop has the form while loop pool *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + count: Int <- 1; + + testing6(): Object { + while count < 1024*1024 + loop + count <- count * 2 + -- Missing "pool" + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/loop3.cl b/tests/parser/loop3.cl index fbb3a56b4..860adb4d1 100644 --- a/tests/parser/loop3.cl +++ b/tests/parser/loop3.cl @@ -1,78 +1,78 @@ -(* A loop has the form while loop pool *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - count: Int <- 1; - - testing6(): Object { - while count => 1024*1024 -- Condition must be an expression - loop - count <- count * 2 - pool - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A loop has the form while loop pool *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + count: Int <- 1; + + testing6(): Object { + while count => 1024*1024 -- Condition must be an expression + loop + count <- count * 2 + pool + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/loop4.cl b/tests/parser/loop4.cl index 47b0e5f4a..0a1194e82 100644 --- a/tests/parser/loop4.cl +++ b/tests/parser/loop4.cl @@ -1,78 +1,78 @@ -(* A loop has the form while loop pool *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - count: Int <- 1; - - testing6(): Object { - while count < 1024*1024 - loop - count <- true++ -- While body must be an expression - pool - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A loop has the form while loop pool *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + count: Int <- 1; + + testing6(): Object { + while count < 1024*1024 + loop + count <- true++ -- While body must be an expression + pool + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/method1.cl b/tests/parser/method1.cl index d86661430..fcfbbcd30 100644 --- a/tests/parser/method1.cl +++ b/tests/parser/method1.cl @@ -1,34 +1,34 @@ -(* A method of class A is a procedure that may manipulate the variables and objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - -- Method names must begin with lowercase letters - Testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A method of class A is a procedure that may manipulate the variables and objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + -- Method names must begin with lowercase letters + Testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/method2.cl b/tests/parser/method2.cl index 83648f50d..d5bdfd85c 100644 --- a/tests/parser/method2.cl +++ b/tests/parser/method2.cl @@ -1,34 +1,34 @@ -(* A method of class A is a procedure that may manipulate the variables and objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - -- Parameter names must begin with lowercase letters - testing2(a: Alpha, B: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A method of class A is a procedure that may manipulate the variables and objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + -- Parameter names must begin with lowercase letters + testing2(a: Alpha, B: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/method3.cl b/tests/parser/method3.cl index 428b25fec..1e5c9eb53 100644 --- a/tests/parser/method3.cl +++ b/tests/parser/method3.cl @@ -1,34 +1,34 @@ -(* A method of class A is a procedure that may manipulate the variables and objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - -- Type names must begin with uppercase letters - testing2(a: Alpha, b: int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A method of class A is a procedure that may manipulate the variables and objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + -- Type names must begin with uppercase letters + testing2(a: Alpha, b: int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/method4.cl b/tests/parser/method4.cl index 52ec07bce..019ada276 100644 --- a/tests/parser/method4.cl +++ b/tests/parser/method4.cl @@ -1,34 +1,34 @@ -(* A method of class A is a procedure that may manipulate the variables and objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - -- Missing paremeter - testing3(x: Int,): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A method of class A is a procedure that may manipulate the variables and objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + -- Missing paremeter + testing3(x: Int,): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/method5.cl b/tests/parser/method5.cl index 706a3145c..13127f664 100644 --- a/tests/parser/method5.cl +++ b/tests/parser/method5.cl @@ -1,34 +1,34 @@ -(* A method of class A is a procedure that may manipulate the variables and objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - -- Type names must begin with uppercase letters - testing3(): string { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A method of class A is a procedure that may manipulate the variables and objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + -- Type names must begin with uppercase letters + testing3(): string { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/method6.cl b/tests/parser/method6.cl index 26ce7f19f..d48cd1293 100644 --- a/tests/parser/method6.cl +++ b/tests/parser/method6.cl @@ -1,33 +1,33 @@ -(* A method of class A is a procedure that may manipulate the variables and objects of class A *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - -- Body can't be empty - testing2(a: Alpha, b: Int): Int { - }; - - testing3(): String { - "2 + 2" - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* A method of class A is a procedure that may manipulate the variables and objects of class A *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + -- Body can't be empty + testing2(a: Alpha, b: Int): Int { + }; + + testing3(): String { + "2 + 2" + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/mixed1.cl b/tests/parser/mixed1.cl index b13e679da..a27879513 100644 --- a/tests/parser/mixed1.cl +++ b/tests/parser/mixed1.cl @@ -1,100 +1,100 @@ -(* Cool has four binary arithmetic operations: +, -, *, /. *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case 2 + 2 of - x: Int => new IO.out_string("Es un entero!"); - y: String => new IO.out_string("Es una cadena!"); - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; - - a: Int <- 1; - - testing8(x: Int, y: Int): Bool { - let z: Int <- 3, w: Int <- 4 - in isvoid (3 + a * (x / w + new Int) - y - (((if tRue = not faLSe then ~z else 3 <= 4 + "hey".length() fi + a))/(0)*(((4 * 4))))) - }; -}-- Mising ";" - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Cool has four binary arithmetic operations: +, -, *, /. *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case 2 + 2 of + x: Int => new IO.out_string("Es un entero!"); + y: String => new IO.out_string("Es una cadena!"); + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; + + a: Int <- 1; + + testing8(x: Int, y: Int): Bool { + let z: Int <- 3, w: Int <- 4 + in isvoid (3 + a * (x / w + new Int) - y - (((if tRue = not faLSe then ~z else 3 <= 4 + "hey".length() fi + a))/(0)*(((4 * 4))))) + }; +}-- Mising ";" + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/mixed2.cl b/tests/parser/mixed2.cl index 6776fcc12..f5477e0bb 100644 --- a/tests/parser/mixed2.cl +++ b/tests/parser/mixed2.cl @@ -1,14 +1,14 @@ -class Main { - main(): Object { - (new Alpha).print() - }; - -}; - -(* Class names must begin with uppercase letters *) -class alpha inherits IO { - print() : Object { - out_string("reached!!\n"); - }; -}; - +class Main { + main(): Object { + (new Alpha).print() + }; + +}; + +(* Class names must begin with uppercase letters *) +class alpha inherits IO { + print() : Object { + out_string("reached!!\n"); + }; +}; + diff --git a/tests/parser/mixed3.cl b/tests/parser/mixed3.cl index f5271eb3e..1bdcad743 100644 --- a/tests/parser/mixed3.cl +++ b/tests/parser/mixed3.cl @@ -1,40 +1,40 @@ -class Main inherits IO { - main() : Object { - { - out_string("Enter a number to check if number is prime\n"); - let i : Int <- in_int() in { - if(i <= 1) then { - out_string("Invalid Input\n"); - abort(); - } else { - if (isPrime(i) = 1) then - out_string("Number is prime\n") - else - out_string("Number is composite\n") - fi; - } - fi; - }; - } - }; - - mod(i : Int, ) : Int { -- Formal list must be comma separated. A comma does not terminate a list of formals. - i - (i/k)*k - }; - - isPrime(i : Int) : Int { - { - let x : Int <- 2, - c : Int <- 1 in - { - while (not (x = i)) loop - if (mod(i, x) = 0) then { - c <- 0; - x <- i; - } else x <- x + 1 fi - pool; - c; - }; - } - }; -}; +class Main inherits IO { + main() : Object { + { + out_string("Enter a number to check if number is prime\n"); + let i : Int <- in_int() in { + if(i <= 1) then { + out_string("Invalid Input\n"); + abort(); + } else { + if (isPrime(i) = 1) then + out_string("Number is prime\n") + else + out_string("Number is composite\n") + fi; + } + fi; + }; + } + }; + + mod(i : Int, ) : Int { -- Formal list must be comma separated. A comma does not terminate a list of formals. + i - (i/k)*k + }; + + isPrime(i : Int) : Int { + { + let x : Int <- 2, + c : Int <- 1 in + { + while (not (x = i)) loop + if (mod(i, x) = 0) then { + c <- 0; + x <- i; + } else x <- x + 1 fi + pool; + c; + }; + } + }; +}; diff --git a/tests/parser/mixed4.cl b/tests/parser/mixed4.cl index 47e6ea5e9..e752253be 100644 --- a/tests/parser/mixed4.cl +++ b/tests/parser/mixed4.cl @@ -1,21 +1,21 @@ -class Main inherits IO { - main() : Object { - { - out_string("Enter number of numbers to multiply\n"); - out_int(prod(in_int())); - out_string("\n"); - } - }; - - prod(i : Int) : Int { - let y : Int <- 1 in { - while (not (i = 0) ) loop { - out_string("Enter Number: "); - y <- y * in_int(Main : Int); -- the parser correctly catches the error here - i <- i - 1; - } - pool; - y; - } - }; -}; +class Main inherits IO { + main() : Object { + { + out_string("Enter number of numbers to multiply\n"); + out_int(prod(in_int())); + out_string("\n"); + } + }; + + prod(i : Int) : Int { + let y : Int <- 1 in { + while (not (i = 0) ) loop { + out_string("Enter Number: "); + y <- y * in_int(Main : Int); -- the parser correctly catches the error here + i <- i - 1; + } + pool; + y; + } + }; +}; diff --git a/tests/parser/mixed5.cl b/tests/parser/mixed5.cl index d4ca68f44..c9176a890 100644 --- a/tests/parser/mixed5.cl +++ b/tests/parser/mixed5.cl @@ -1,20 +1,20 @@ -class Main inherits IO { - str <- "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; - main() : Object { - { - out_string("Enter number of numbers to multiply\n"); - out_int(prod(in_int())); - out_string("\n"); - } - }; - prod(i : Int) : Int { - let y : Int <- 1 in { - while (not (i = 0) ) loop { - out_string("Enter Number: "); - y <- y * in_int(); - i <- i - 1; - } - y; - } - }; -} +class Main inherits IO { + str <- "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; + main() : Object { + { + out_string("Enter number of numbers to multiply\n"); + out_int(prod(in_int())); + out_string("\n"); + } + }; + prod(i : Int) : Int { + let y : Int <- 1 in { + while (not (i = 0) ) loop { + out_string("Enter Number: "); + y <- y * in_int(); + i <- i - 1; + } + y; + } + }; +} diff --git a/tests/parser/mixed6.cl b/tests/parser/mixed6.cl index 0a51656c9..5da80da31 100644 --- a/tests/parser/mixed6.cl +++ b/tests/parser/mixed6.cl @@ -1,5 +1,5 @@ -classs Doom { - i : Int <- 0; - main() : Object { - if i = 0 then out_string("This is da real *h*t") - +classs Doom { + i : Int <- 0; + main() : Object { + if i = 0 then out_string("This is da real *h*t") + diff --git a/tests/parser/operation1.cl b/tests/parser/operation1.cl index d892ec8a6..d38eb72d0 100644 --- a/tests/parser/operation1.cl +++ b/tests/parser/operation1.cl @@ -1,101 +1,101 @@ -(* Cool has four binary arithmetic operations: +, -, *, /. *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case 2 + 2 of - x: Int => new IO.out_string("Es un entero!"); - y: String => new IO.out_string("Es una cadena!"); - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; - - a: Int <- 1; - - testing8(x: Int, y: Int): Bool { - let z: Int <- 3, w: Int <- 4 - -- Missing ')' - in isvoid (3 + a * (x / w + new Int) - y - (((if tRue = not faLSe then ~z else 3 <= 4 + "hey".length() fi + a)/(0)*(((4 * 4))))) - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Cool has four binary arithmetic operations: +, -, *, /. *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case 2 + 2 of + x: Int => new IO.out_string("Es un entero!"); + y: String => new IO.out_string("Es una cadena!"); + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; + + a: Int <- 1; + + testing8(x: Int, y: Int): Bool { + let z: Int <- 3, w: Int <- 4 + -- Missing ')' + in isvoid (3 + a * (x / w + new Int) - y - (((if tRue = not faLSe then ~z else 3 <= 4 + "hey".length() fi + a)/(0)*(((4 * 4))))) + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/operation2.cl b/tests/parser/operation2.cl index 1f167409a..2dc628359 100644 --- a/tests/parser/operation2.cl +++ b/tests/parser/operation2.cl @@ -1,101 +1,101 @@ -(* Cool has four binary arithmetic operations: +, -, *, /. *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case 2 + 2 of - x: Int => new IO.out_string("Es un entero!"); - y: String => new IO.out_string("Es una cadena!"); - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; - - a: Int <- 1; - - testing8(x: Int, y: Int): Bool { - let z: Int <- 3, w: Int <- 4 - -- Type identifiers starts with a uppercase letter - in isvoid (3 + a * (x / w + new int) - y - (((if tRue = not faLSe then ~z else 3 <= 4 + "hey".length() fi + a))/(0)*(((4 * 4))))) - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Cool has four binary arithmetic operations: +, -, *, /. *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case 2 + 2 of + x: Int => new IO.out_string("Es un entero!"); + y: String => new IO.out_string("Es una cadena!"); + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; + + a: Int <- 1; + + testing8(x: Int, y: Int): Bool { + let z: Int <- 3, w: Int <- 4 + -- Type identifiers starts with a uppercase letter + in isvoid (3 + a * (x / w + new int) - y - (((if tRue = not faLSe then ~z else 3 <= 4 + "hey".length() fi + a))/(0)*(((4 * 4))))) + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/operation3.cl b/tests/parser/operation3.cl index ef125927a..61d6cbfa8 100644 --- a/tests/parser/operation3.cl +++ b/tests/parser/operation3.cl @@ -1,101 +1,101 @@ -(* Cool has four binary arithmetic operations: +, -, *, /. *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case 2 + 2 of - x: Int => new IO.out_string("Es un entero!"); - y: String => new IO.out_string("Es una cadena!"); - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; - - a: Int <- 1; - - testing8(x: Int, y: Int): Bool { - let z: Int <- 3, w: Int <- 4 - -- Object identifiers starts with a lowercase letter - in isvoid (3 + a * (x / w + new Int) - y - (((if tRue = not faLSe then ~Mazinger_Z else 3 <= 4 + "hey".length() fi + a))/(0)*(((4 * 4))))) - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Cool has four binary arithmetic operations: +, -, *, /. *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case 2 + 2 of + x: Int => new IO.out_string("Es un entero!"); + y: String => new IO.out_string("Es una cadena!"); + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; + + a: Int <- 1; + + testing8(x: Int, y: Int): Bool { + let z: Int <- 3, w: Int <- 4 + -- Object identifiers starts with a lowercase letter + in isvoid (3 + a * (x / w + new Int) - y - (((if tRue = not faLSe then ~Mazinger_Z else 3 <= 4 + "hey".length() fi + a))/(0)*(((4 * 4))))) + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/operation4.cl b/tests/parser/operation4.cl index 2212740e7..bae7de5b5 100644 --- a/tests/parser/operation4.cl +++ b/tests/parser/operation4.cl @@ -1,101 +1,101 @@ -(* Cool has four binary arithmetic operations: +, -, *, /. *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - test1: Object; - - testing1(): Int { - 2 + 2 - }; - - test2: Int <- 1; - - test3: String <- "1"; - - testing2(a: Alpha, b: Int): Int { - 2 + 2 - }; - - testing3(): String { - "2 + 2" - }; - - testing4(x: Int, y: Int): Test { - self - }; - - testing5(a: String, b: String): IO { - If a.length() < b.length() THeN - new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) - eLSe - if a.length() = b.length() THeN - new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) - ElsE - new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) - fI - Fi - }; - - testing6(a: Int): IO { - let count: Int <- 0, pow: Int - in { - -- count <- 0; - pow <- 1; - while pow < a - loop - { - count <- count + 1; - pow <- pow * 2; - } - pool; - new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); - } - }; - - testing7(): Object { - case 2 + 2 of - x: Int => new IO.out_string("Es un entero!"); - y: String => new IO.out_string("Es una cadena!"); - z: Bool => new IO.out_string("Es un booleano!"); - esac - }; - - a: Int <- 1; - - testing8(x: Int, y: Int): Bool { - let z: Int <- 3, w: Int <- 4 - -- Double "+" - in isvoid (3 + a * (x / w++ new Int) - y - (((if tRue = not faLSe then ~z else 3 <= 4 + "hey".length() fi + a))/(0)*(((4 * 4))))) - }; -}; - -class Test2 { - test1: Test <- new Test; - - testing1(): Test { - test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) - }; - - testing2(x: Int, y: Int): Test2 { - self - }; - - testing3(): Test2 { - testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) - }; - - testing4(): Object { - test1@Object.copy() - }; -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; +(* Cool has four binary arithmetic operations: +, -, *, /. *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + test1: Object; + + testing1(): Int { + 2 + 2 + }; + + test2: Int <- 1; + + test3: String <- "1"; + + testing2(a: Alpha, b: Int): Int { + 2 + 2 + }; + + testing3(): String { + "2 + 2" + }; + + testing4(x: Int, y: Int): Test { + self + }; + + testing5(a: String, b: String): IO { + If a.length() < b.length() THeN + new IO.out_string("La cadena \"".concat(b).concat("\" es mas larga que la cadena \"").concat(a).concat("\".")) + eLSe + if a.length() = b.length() THeN + new IO.out_string("La cadena \"".concat(a).concat("\" mide igual que la cadena \"").concat(b).concat("\".")) + ElsE + new IO.out_string("La cadena \"".concat(a).concat("\" es mas larga que la cadena \"").concat(b).concat("\".")) + fI + Fi + }; + + testing6(a: Int): IO { + let count: Int <- 0, pow: Int + in { + -- count <- 0; + pow <- 1; + while pow < a + loop + { + count <- count + 1; + pow <- pow * 2; + } + pool; + new IO.out_string("El logaritmo en base 2 de ").out_int(a).out_string(" es ").out_int(count); + } + }; + + testing7(): Object { + case 2 + 2 of + x: Int => new IO.out_string("Es un entero!"); + y: String => new IO.out_string("Es una cadena!"); + z: Bool => new IO.out_string("Es un booleano!"); + esac + }; + + a: Int <- 1; + + testing8(x: Int, y: Int): Bool { + let z: Int <- 3, w: Int <- 4 + -- Double "+" + in isvoid (3 + a * (x / w++ new Int) - y - (((if tRue = not faLSe then ~z else 3 <= 4 + "hey".length() fi + a))/(0)*(((4 * 4))))) + }; +}; + +class Test2 { + test1: Test <- new Test; + + testing1(): Test { + test1.testing4(1 + 1, 1 + 2).testing4(2 + 3, 3 + 5).testing4(5 + 8, 8 + 13) + }; + + testing2(x: Int, y: Int): Test2 { + self + }; + + testing3(): Test2 { + testing2(1 + 1, 1 + 2).testing2(2 + 3, 3 + 5).testing2(5 + 8, true + fALSE) + }; + + testing4(): Object { + test1@Object.copy() + }; +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; }; \ No newline at end of file diff --git a/tests/parser/program2.cl b/tests/parser/program2.cl index a281c6c14..f8b16779c 100644 --- a/tests/parser/program2.cl +++ b/tests/parser/program2.cl @@ -1,20 +1,20 @@ -(* Cool programs are sets of classes *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - --- Missing semicolon -class Test { - testing(): Int { - 2 + 2 - }; -} - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; -}; +(* Cool programs are sets of classes *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +-- Missing semicolon +class Test { + testing(): Int { + 2 + 2 + }; +} + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; +}; diff --git a/tests/parser/program3.cl b/tests/parser/program3.cl index 10d2dc71e..e27889c57 100644 --- a/tests/parser/program3.cl +++ b/tests/parser/program3.cl @@ -1,24 +1,24 @@ -(* Cool programs are sets of classes *) - -class Main { - main(): Object { - (new Alpha).print() - }; -}; - -class Test { - testing(): Int { - 2 + 2 - }; -}; - --- Only classes -suma(a: Int, b: Int) int { - a + b -}; - -class Alpha inherits IO { - print() : Object { - out_string("reached!!\n") - }; -}; +(* Cool programs are sets of classes *) + +class Main { + main(): Object { + (new Alpha).print() + }; +}; + +class Test { + testing(): Int { + 2 + 2 + }; +}; + +-- Only classes +suma(a: Int, b: Int) int { + a + b +}; + +class Alpha inherits IO { + print() : Object { + out_string("reached!!\n") + }; +}; diff --git a/tests/parser_test.py b/tests/parser_test.py index 166de45de..129c0f20a 100644 --- a/tests/parser_test.py +++ b/tests/parser_test.py @@ -1,13 +1,13 @@ -import pytest -import os -from utils import compare_errors - -tests_dir = __file__.rpartition('/')[0] + '/parser/' -tests = [(file) for file in os.listdir(tests_dir) if file.endswith('.cl')] - -@pytest.mark.parser -@pytest.mark.error -@pytest.mark.run(order=2) -@pytest.mark.parametrize("cool_file", tests) -def test_parser_errors(compiler_path, cool_file): +import pytest +import os +from utils import compare_errors + +tests_dir = __file__.rpartition('/')[0] + '/parser/' +tests = [(file) for file in os.listdir(tests_dir) if file.endswith('.cl')] + +@pytest.mark.parser +@pytest.mark.error +@pytest.mark.run(order=2) +@pytest.mark.parametrize("cool_file", tests) +def test_parser_errors(compiler_path, cool_file): compare_errors(compiler_path, tests_dir + cool_file, tests_dir + cool_file[:-3] + '_error.txt') \ No newline at end of file diff --git a/tests/semantic/arithmetic1.cl b/tests/semantic/arithmetic1.cl index 65719c064..bf94eb194 100644 --- a/tests/semantic/arithmetic1.cl +++ b/tests/semantic/arithmetic1.cl @@ -1,11 +1,11 @@ ---The static types of the two sub-expressions must be Int. - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Int <- let x: Int <- 1 * 2 / 3 - 4 + new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in x <- x + new A.type_name().concat(new B.type_name().concat(new C.type_name())); +--The static types of the two sub-expressions must be Int. + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Int <- let x: Int <- 1 * 2 / 3 - 4 + new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in x <- x + new A.type_name().concat(new B.type_name().concat(new C.type_name())); }; \ No newline at end of file diff --git a/tests/semantic/arithmetic10.cl b/tests/semantic/arithmetic10.cl index b2488ad7f..bbfe6cdb3 100644 --- a/tests/semantic/arithmetic10.cl +++ b/tests/semantic/arithmetic10.cl @@ -1,15 +1,15 @@ -(* -The expression ~ is the integer -complement of . The expression must have static type Int and the entire expression -has static type Int. -*) - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Bool <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in ~new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); +(* +The expression ~ is the integer +complement of . The expression must have static type Int and the entire expression +has static type Int. +*) + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Bool <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in ~new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); }; \ No newline at end of file diff --git a/tests/semantic/arithmetic11.cl b/tests/semantic/arithmetic11.cl index 05cec0465..fc067dc1a 100644 --- a/tests/semantic/arithmetic11.cl +++ b/tests/semantic/arithmetic11.cl @@ -1,14 +1,14 @@ -(* -The expression not is the boolean complement of . The expression - must have static type Bool and the entire expression has static type Bool. -*) - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Bool <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in not 1 + new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); +(* +The expression not is the boolean complement of . The expression + must have static type Bool and the entire expression has static type Bool. +*) + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Bool <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in not 1 + new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); }; \ No newline at end of file diff --git a/tests/semantic/arithmetic12.cl b/tests/semantic/arithmetic12.cl index 05a2da918..2e012fc41 100644 --- a/tests/semantic/arithmetic12.cl +++ b/tests/semantic/arithmetic12.cl @@ -1,14 +1,14 @@ -(* -The expression not is the boolean complement of . The expression - must have static type Bool and the entire expression has static type Bool. -*) - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Int <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in not 1 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); +(* +The expression not is the boolean complement of . The expression + must have static type Bool and the entire expression has static type Bool. +*) + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Int <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in not 1 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); }; \ No newline at end of file diff --git a/tests/semantic/arithmetic1_error.txt b/tests/semantic/arithmetic1_error.txt index 59213724d..a74ebf3da 100644 --- a/tests/semantic/arithmetic1_error.txt +++ b/tests/semantic/arithmetic1_error.txt @@ -1 +1 @@ -(10, 27) - TypeError: non-Int arguments: Int + String +(10, 27) - TypeError: non-Int arguments: Int + String diff --git a/tests/semantic/arithmetic2.cl b/tests/semantic/arithmetic2.cl index f1f0935e2..59532573d 100644 --- a/tests/semantic/arithmetic2.cl +++ b/tests/semantic/arithmetic2.cl @@ -1,11 +1,11 @@ ---The static types of the two sub-expressions must be Int. - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Int <- let x: Int <- 1 + 2 * 3 / 4 - new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in x <- x - new A.type_name().concat(new B.type_name().concat(new C.type_name())); +--The static types of the two sub-expressions must be Int. + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Int <- let x: Int <- 1 + 2 * 3 / 4 - new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in x <- x - new A.type_name().concat(new B.type_name().concat(new C.type_name())); }; \ No newline at end of file diff --git a/tests/semantic/arithmetic2_error.txt b/tests/semantic/arithmetic2_error.txt index aebc7aab9..2c7952af8 100644 --- a/tests/semantic/arithmetic2_error.txt +++ b/tests/semantic/arithmetic2_error.txt @@ -1 +1 @@ -(10, 27) - TypeError: non-Int arguments: Int - String +(10, 27) - TypeError: non-Int arguments: Int - String diff --git a/tests/semantic/arithmetic3.cl b/tests/semantic/arithmetic3.cl index df64d8000..b208957f5 100644 --- a/tests/semantic/arithmetic3.cl +++ b/tests/semantic/arithmetic3.cl @@ -1,11 +1,11 @@ ---The static types of the two sub-expressions must be Int. - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Int <- let x: Int <- 1 - 2 + 3 * 4 / new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in x <- x / new A.type_name().concat(new B.type_name().concat(new C.type_name())); +--The static types of the two sub-expressions must be Int. + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Int <- let x: Int <- 1 - 2 + 3 * 4 / new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in x <- x / new A.type_name().concat(new B.type_name().concat(new C.type_name())); }; \ No newline at end of file diff --git a/tests/semantic/arithmetic3_error.txt b/tests/semantic/arithmetic3_error.txt index d0af01bb5..81d88331a 100644 --- a/tests/semantic/arithmetic3_error.txt +++ b/tests/semantic/arithmetic3_error.txt @@ -1 +1 @@ -(10, 27) - TypeError: non-Int arguments: Int / String +(10, 27) - TypeError: non-Int arguments: Int / String diff --git a/tests/semantic/arithmetic4.cl b/tests/semantic/arithmetic4.cl index 68512ca44..2c7dd4fc9 100644 --- a/tests/semantic/arithmetic4.cl +++ b/tests/semantic/arithmetic4.cl @@ -1,11 +1,11 @@ ---The static types of the two sub-expressions must be Int. - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Int <- let x: Int <- 1 / 2 - 3 + 4 * new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in x <- x * new A.type_name().concat(new B.type_name().concat(new C.type_name())); +--The static types of the two sub-expressions must be Int. + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Int <- let x: Int <- 1 / 2 - 3 + 4 * new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in x <- x * new A.type_name().concat(new B.type_name().concat(new C.type_name())); }; \ No newline at end of file diff --git a/tests/semantic/arithmetic5.cl b/tests/semantic/arithmetic5.cl index fd77c7971..bc08c6e82 100644 --- a/tests/semantic/arithmetic5.cl +++ b/tests/semantic/arithmetic5.cl @@ -1,11 +1,11 @@ ---The static type of the expression is Int. - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Bool <- let x: Int <- 1 / 2 - 3 + 4 * new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in x <- x * new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); +--The static type of the expression is Int. + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Bool <- let x: Int <- 1 / 2 - 3 + 4 * new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in x <- x * new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); }; \ No newline at end of file diff --git a/tests/semantic/arithmetic5_error.txt b/tests/semantic/arithmetic5_error.txt index 8c67c2f53..dd5346844 100644 --- a/tests/semantic/arithmetic5_error.txt +++ b/tests/semantic/arithmetic5_error.txt @@ -1 +1 @@ -(9, 19) - TypeError: Inferred type Int of initialization of attribute test does not conform to declared type Bool. +(9, 19) - TypeError: Inferred type Int of initialization of attribute test does not conform to declared type Bool. diff --git a/tests/semantic/arithmetic6.cl b/tests/semantic/arithmetic6.cl index d4da66a73..a0c3d03ff 100644 --- a/tests/semantic/arithmetic6.cl +++ b/tests/semantic/arithmetic6.cl @@ -1,11 +1,11 @@ - --The static types of the two sub-expressions must be Int. - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Bool <- let x: Bool <- 1 / 2 - 3 + 4 <= new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in 1 <= new A.type_name().concat(new B.type_name().concat(new C.type_name())); -}; + --The static types of the two sub-expressions must be Int. + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Bool <- let x: Bool <- 1 / 2 - 3 + 4 <= new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in 1 <= new A.type_name().concat(new B.type_name().concat(new C.type_name())); +}; diff --git a/tests/semantic/arithmetic6_error.txt b/tests/semantic/arithmetic6_error.txt index a0d67cb48..2e43dfc17 100644 --- a/tests/semantic/arithmetic6_error.txt +++ b/tests/semantic/arithmetic6_error.txt @@ -1 +1 @@ -(10, 22) - TypeError: non-Int arguments: Int <= String +(10, 22) - TypeError: non-Int arguments: Int <= String diff --git a/tests/semantic/arithmetic7.cl b/tests/semantic/arithmetic7.cl index b98a4b0e2..c00c75cde 100644 --- a/tests/semantic/arithmetic7.cl +++ b/tests/semantic/arithmetic7.cl @@ -1,12 +1,12 @@ - --The static types of the two sub-expressions must be Int. - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Bool <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in 1 < new A.type_name().concat(new B.type_name().concat(new C.type_name())); -}; - + --The static types of the two sub-expressions must be Int. + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Bool <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in 1 < new A.type_name().concat(new B.type_name().concat(new C.type_name())); +}; + diff --git a/tests/semantic/arithmetic7_error.txt b/tests/semantic/arithmetic7_error.txt index 166bcc8ef..6f3537117 100644 --- a/tests/semantic/arithmetic7_error.txt +++ b/tests/semantic/arithmetic7_error.txt @@ -1 +1 @@ -(10, 22) - TypeError: non-Int arguments: Int < String +(10, 22) - TypeError: non-Int arguments: Int < String diff --git a/tests/semantic/arithmetic8.cl b/tests/semantic/arithmetic8.cl index f3ad37ec4..3210bdb8a 100644 --- a/tests/semantic/arithmetic8.cl +++ b/tests/semantic/arithmetic8.cl @@ -1,13 +1,13 @@ - --The rules are exactly the same as for the binary arithmetic operations, except that the result is a Bool. - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Int <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in 1 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); -}; - - + --The rules are exactly the same as for the binary arithmetic operations, except that the result is a Bool. + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Int <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in 1 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length(); +}; + + diff --git a/tests/semantic/arithmetic8_error.txt b/tests/semantic/arithmetic8_error.txt index 5a8814e1a..ebcaa3797 100644 --- a/tests/semantic/arithmetic8_error.txt +++ b/tests/semantic/arithmetic8_error.txt @@ -1 +1 @@ -(9, 18) - TypeError: Inferred type Bool of initialization of attribute test does not conform to declared type Int. +(9, 18) - TypeError: Inferred type Bool of initialization of attribute test does not conform to declared type Int. diff --git a/tests/semantic/arithmetic9.cl b/tests/semantic/arithmetic9.cl index b7b4d3645..95579e134 100644 --- a/tests/semantic/arithmetic9.cl +++ b/tests/semantic/arithmetic9.cl @@ -1,15 +1,15 @@ -(* -The expression ~ is the integer -complement of . The expression must have static type Int and the entire expression -has static type Int. -*) - -class A { }; -class B inherits A { }; -class C inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - test: Int <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() - in 1 + ~new A.type_name().concat(new B.type_name().concat(new C.type_name())); +(* +The expression ~ is the integer +complement of . The expression must have static type Int and the entire expression +has static type Int. +*) + +class A { }; +class B inherits A { }; +class C inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + test: Int <- let x: Bool <- 1 / 2 - 3 + 4 < new A.type_name().concat(new B.type_name().concat(new C.type_name())).length() + in 1 + ~new A.type_name().concat(new B.type_name().concat(new C.type_name())); }; \ No newline at end of file diff --git a/tests/semantic/assignment1.cl b/tests/semantic/assignment1.cl index 174f93e2b..19ab70219 100644 --- a/tests/semantic/assignment1.cl +++ b/tests/semantic/assignment1.cl @@ -1,7 +1,7 @@ ---The static type of the expression must conform to the declared type of the identifier - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test: Int <- "String"; -}; +--The static type of the expression must conform to the declared type of the identifier + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test: Int <- "String"; +}; diff --git a/tests/semantic/assignment1_error.txt b/tests/semantic/assignment1_error.txt index 9d05707aa..6eb883012 100644 --- a/tests/semantic/assignment1_error.txt +++ b/tests/semantic/assignment1_error.txt @@ -1 +1 @@ -(6, 18) - TypeError: Inferred type String of initialization of attribute test does not conform to declared type Int. +(6, 18) - TypeError: Inferred type String of initialization of attribute test does not conform to declared type Int. diff --git a/tests/semantic/assignment2.cl b/tests/semantic/assignment2.cl index c7f3d7873..cace221ae 100644 --- a/tests/semantic/assignment2.cl +++ b/tests/semantic/assignment2.cl @@ -1,13 +1,13 @@ ---The static type of an assignment is the static type of . - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test(a: A): B { a <- new C }; - test2(a: A): D { a <- new C }; -}; +--The static type of an assignment is the static type of . + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test(a: A): B { a <- new C }; + test2(a: A): D { a <- new C }; +}; diff --git a/tests/semantic/assignment2_error.txt b/tests/semantic/assignment2_error.txt index 55f5aa214..ed10b7f38 100644 --- a/tests/semantic/assignment2_error.txt +++ b/tests/semantic/assignment2_error.txt @@ -1 +1 @@ -(12, 22) - TypeError: Inferred return type C of method test2 does not conform to declared return type D. +(12, 22) - TypeError: Inferred return type C of method test2 does not conform to declared return type D. diff --git a/tests/semantic/assignment3.cl b/tests/semantic/assignment3.cl index 9d60a4b6c..eba0d69e2 100644 --- a/tests/semantic/assignment3.cl +++ b/tests/semantic/assignment3.cl @@ -1,14 +1,14 @@ ---The static type of an assignment is the static type of . - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - a: A; - b: B <- a <- new C; - d: D <- a <- new C; -}; +--The static type of an assignment is the static type of . + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + a: A; + b: B <- a <- new C; + d: D <- a <- new C; +}; diff --git a/tests/semantic/attributes1.cl b/tests/semantic/attributes1.cl index d11ea7cdb..3fa0440e4 100644 --- a/tests/semantic/attributes1.cl +++ b/tests/semantic/attributes1.cl @@ -1,13 +1,13 @@ ---The static type of the expression must conform to the declared type of the attribute. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - test1: IO <- new Main; - test2: B <- new A; - - main(): IO { out_string("Hello World!")}; +--The static type of the expression must conform to the declared type of the attribute. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + test1: IO <- new Main; + test2: B <- new A; + + main(): IO { out_string("Hello World!")}; }; \ No newline at end of file diff --git a/tests/semantic/attributes1_error.txt b/tests/semantic/attributes1_error.txt index 22e45b837..9cb8460c9 100644 --- a/tests/semantic/attributes1_error.txt +++ b/tests/semantic/attributes1_error.txt @@ -1 +1 @@ -(10, 17) - TypeError: Inferred type A of initialization of attribute test2 does not conform to declared type B. +(10, 17) - TypeError: Inferred type A of initialization of attribute test2 does not conform to declared type B. diff --git a/tests/semantic/attributes2.cl b/tests/semantic/attributes2.cl index 85c791b5e..7937c2cc8 100644 --- a/tests/semantic/attributes2.cl +++ b/tests/semantic/attributes2.cl @@ -1,13 +1,13 @@ ---The static type of the expression must conform to the declared type of the attribute. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - test1: IO <- new Main; - test2: C <- new D; - - main(): IO { out_string("Hello World!")}; +--The static type of the expression must conform to the declared type of the attribute. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + test1: IO <- new Main; + test2: C <- new D; + + main(): IO { out_string("Hello World!")}; }; \ No newline at end of file diff --git a/tests/semantic/attributes2_error.txt b/tests/semantic/attributes2_error.txt index d7694b0ad..6d601b7cd 100644 --- a/tests/semantic/attributes2_error.txt +++ b/tests/semantic/attributes2_error.txt @@ -1 +1 @@ -(10, 17) - TypeError: Inferred type D of initialization of attribute test2 does not conform to declared type C. +(10, 17) - TypeError: Inferred type D of initialization of attribute test2 does not conform to declared type C. diff --git a/tests/semantic/attributes3.cl b/tests/semantic/attributes3.cl index 0c8294fa2..8a67decd1 100644 --- a/tests/semantic/attributes3.cl +++ b/tests/semantic/attributes3.cl @@ -1,25 +1,25 @@ ---Attributes are local to the class in which they are defined or inherited. - -class A { - a: Int <- 5; - test(x1: Int, y1: Int): Int { - let x: Int <- x1, y: Int <-y1 in { - x <- x + a; - y <- y + a; - if b then x + y else x - y fi; - } - }; -}; -class B inherits A { - b: Bool <- true; -}; -class C inherits B { - c: String <- "C"; -}; -class D inherits B { - d: IO <- new Main.main(); -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!") }; +--Attributes are local to the class in which they are defined or inherited. + +class A { + a: Int <- 5; + test(x1: Int, y1: Int): Int { + let x: Int <- x1, y: Int <-y1 in { + x <- x + a; + y <- y + a; + if b then x + y else x - y fi; + } + }; +}; +class B inherits A { + b: Bool <- true; +}; +class C inherits B { + c: String <- "C"; +}; +class D inherits B { + d: IO <- new Main.main(); +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!") }; }; \ No newline at end of file diff --git a/tests/semantic/attributes3_error.txt b/tests/semantic/attributes3_error.txt index 68a2ba571..6195c816c 100644 --- a/tests/semantic/attributes3_error.txt +++ b/tests/semantic/attributes3_error.txt @@ -1 +1 @@ -(9, 16) - NameError: Undeclared identifier b. +(9, 16) - NameError: Undeclared identifier b. diff --git a/tests/semantic/attributes4.cl b/tests/semantic/attributes4.cl index 307b185fd..a7f63adbd 100644 --- a/tests/semantic/attributes4.cl +++ b/tests/semantic/attributes4.cl @@ -1,39 +1,39 @@ ---Attributes are local to the class in which they are defined or inherited. - -class A { - a: Int <- 5; -}; -class B inherits A { - b: Bool <- true; - test(x1: Int, y1: Int): Int { - let x: Int <- x1, y: Int <-y1 in { - x <- x + a; - y <- y + a; - if b then x + y else x - y fi; - } - }; -}; -class D inherits B { - d: IO <- new Main.main(); - test3(x1: Int, y1: Int): IO { - let x: Int <- x1, y: Int <-y1, c: String <- "C" in { - x <- x + a; - y <- y + a; - if b then new IO.out_string(c) else d fi; - } - }; -}; -class C inherits B { - c: String <- "C"; - test2(x1: Int, y1: Int): IO { - let x: Int <- x1, y: Int <-y1 in { - x <- x + a; - y <- y + a; - if b then new IO.out_string(c) else d fi; - } - }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!") }; +--Attributes are local to the class in which they are defined or inherited. + +class A { + a: Int <- 5; +}; +class B inherits A { + b: Bool <- true; + test(x1: Int, y1: Int): Int { + let x: Int <- x1, y: Int <-y1 in { + x <- x + a; + y <- y + a; + if b then x + y else x - y fi; + } + }; +}; +class D inherits B { + d: IO <- new Main.main(); + test3(x1: Int, y1: Int): IO { + let x: Int <- x1, y: Int <-y1, c: String <- "C" in { + x <- x + a; + y <- y + a; + if b then new IO.out_string(c) else d fi; + } + }; +}; +class C inherits B { + c: String <- "C"; + test2(x1: Int, y1: Int): IO { + let x: Int <- x1, y: Int <-y1 in { + x <- x + a; + y <- y + a; + if b then new IO.out_string(c) else d fi; + } + }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!") }; }; \ No newline at end of file diff --git a/tests/semantic/basics1.cl b/tests/semantic/basics1.cl index af84ca0c9..32ae16564 100644 --- a/tests/semantic/basics1.cl +++ b/tests/semantic/basics1.cl @@ -1,10 +1,10 @@ --- It is an error to redefine the IO class. - -class IO { - scan(): String { ":)" }; - print(s: String): IO { new IO }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; +-- It is an error to redefine the IO class. + +class IO { + scan(): String { ":)" }; + print(s: String): IO { new IO }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; }; \ No newline at end of file diff --git a/tests/semantic/basics1_error.txt b/tests/semantic/basics1_error.txt index 0db23a051..676f5049c 100644 --- a/tests/semantic/basics1_error.txt +++ b/tests/semantic/basics1_error.txt @@ -1 +1 @@ -(3, 7) - SemanticError: Redefinition of basic class IO. +(3, 7) - SemanticError: Redefinition of basic class IO. diff --git a/tests/semantic/basics2.cl b/tests/semantic/basics2.cl index 61399a989..cf2b1cd2f 100644 --- a/tests/semantic/basics2.cl +++ b/tests/semantic/basics2.cl @@ -1,9 +1,9 @@ --- It is an error to inherit from or redefine Int. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; -}; - -class A inherits Int { - is_prime(): Bool { false }; -}; +-- It is an error to inherit from or redefine Int. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; +}; + +class A inherits Int { + is_prime(): Bool { false }; +}; diff --git a/tests/semantic/basics2_error.txt b/tests/semantic/basics2_error.txt index e2810833a..69a3b6814 100644 --- a/tests/semantic/basics2_error.txt +++ b/tests/semantic/basics2_error.txt @@ -1 +1 @@ -(7, 18) - SemanticError: Class A cannot inherit class Int. +(7, 18) - SemanticError: Class A cannot inherit class Int. diff --git a/tests/semantic/basics3.cl b/tests/semantic/basics3.cl index 8c28b31e1..fef017a8d 100644 --- a/tests/semantic/basics3.cl +++ b/tests/semantic/basics3.cl @@ -1,9 +1,9 @@ --- It is an error to inherit from or redefine Int. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; -}; - -class Int { - is_prime(): Bool { false }; +-- It is an error to inherit from or redefine Int. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; +}; + +class Int { + is_prime(): Bool { false }; }; \ No newline at end of file diff --git a/tests/semantic/basics3_error.txt b/tests/semantic/basics3_error.txt index ed382c8eb..d8f80cb12 100644 --- a/tests/semantic/basics3_error.txt +++ b/tests/semantic/basics3_error.txt @@ -1 +1 @@ -(7, 7) - SemanticError: Redefinition of basic class Int. +(7, 7) - SemanticError: Redefinition of basic class Int. diff --git a/tests/semantic/basics4.cl b/tests/semantic/basics4.cl index 4475bc08f..9266ec79b 100644 --- a/tests/semantic/basics4.cl +++ b/tests/semantic/basics4.cl @@ -1,9 +1,9 @@ --- It is an error to inherit from or redefine String. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; -}; - -class A inherits String { - is_palindrome(): Bool { false }; +-- It is an error to inherit from or redefine String. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; +}; + +class A inherits String { + is_palindrome(): Bool { false }; }; \ No newline at end of file diff --git a/tests/semantic/basics4_error.txt b/tests/semantic/basics4_error.txt index bfe08a9a6..d5cd4c3db 100644 --- a/tests/semantic/basics4_error.txt +++ b/tests/semantic/basics4_error.txt @@ -1 +1 @@ -(7, 18) - SemanticError: Class A cannot inherit class String. +(7, 18) - SemanticError: Class A cannot inherit class String. diff --git a/tests/semantic/basics5.cl b/tests/semantic/basics5.cl index f0d4dafb3..bad5eff13 100644 --- a/tests/semantic/basics5.cl +++ b/tests/semantic/basics5.cl @@ -1,9 +1,9 @@ --- It is an error to inherit from or redefine String. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; -}; - -class String { - is_palindrome(): Bool { false }; +-- It is an error to inherit from or redefine String. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; +}; + +class String { + is_palindrome(): Bool { false }; }; \ No newline at end of file diff --git a/tests/semantic/basics5_error.txt b/tests/semantic/basics5_error.txt index 47b247faa..8437accf7 100644 --- a/tests/semantic/basics5_error.txt +++ b/tests/semantic/basics5_error.txt @@ -1 +1 @@ -(7, 7) - SemanticError: Redefinition of basic class String. +(7, 7) - SemanticError: Redefinition of basic class String. diff --git a/tests/semantic/basics6.cl b/tests/semantic/basics6.cl index c16572a31..47266ebed 100644 --- a/tests/semantic/basics6.cl +++ b/tests/semantic/basics6.cl @@ -1,9 +1,9 @@ --- It is an error to inherit from or redefine Bool. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; -}; - -class A inherits Bool { - xor(b: Bool): Bool { false }; +-- It is an error to inherit from or redefine Bool. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; +}; + +class A inherits Bool { + xor(b: Bool): Bool { false }; }; \ No newline at end of file diff --git a/tests/semantic/basics6_error.txt b/tests/semantic/basics6_error.txt index 9adf1d488..b4d22da13 100644 --- a/tests/semantic/basics6_error.txt +++ b/tests/semantic/basics6_error.txt @@ -1 +1 @@ -(7, 18) - SemanticError: Class A cannot inherit class Bool. +(7, 18) - SemanticError: Class A cannot inherit class Bool. diff --git a/tests/semantic/basics7.cl b/tests/semantic/basics7.cl index 38f789245..0f30aaec3 100644 --- a/tests/semantic/basics7.cl +++ b/tests/semantic/basics7.cl @@ -1,9 +1,9 @@ --- It is an error to inherit from or redefine Bool. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; -}; - -class Bool { - xor(b: Bool): Bool { false }; +-- It is an error to inherit from or redefine Bool. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; +}; + +class Bool { + xor(b: Bool): Bool { false }; }; \ No newline at end of file diff --git a/tests/semantic/basics7_error.txt b/tests/semantic/basics7_error.txt index 9f1347200..92660ab9f 100644 --- a/tests/semantic/basics7_error.txt +++ b/tests/semantic/basics7_error.txt @@ -1 +1 @@ -(7, 7) - SemanticError: Redefinition of basic class Bool. +(7, 7) - SemanticError: Redefinition of basic class Bool. diff --git a/tests/semantic/basics8.cl b/tests/semantic/basics8.cl index d45cd941d..3b9697d4f 100644 --- a/tests/semantic/basics8.cl +++ b/tests/semantic/basics8.cl @@ -1,9 +1,9 @@ --- It is an error redefine Object. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; -}; - -class Object { - xor(b: Bool): Bool { false }; +-- It is an error redefine Object. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; +}; + +class Object { + xor(b: Bool): Bool { false }; }; \ No newline at end of file diff --git a/tests/semantic/basics8_error.txt b/tests/semantic/basics8_error.txt index 45767c9c5..652f47b30 100644 --- a/tests/semantic/basics8_error.txt +++ b/tests/semantic/basics8_error.txt @@ -1 +1 @@ -(7, 7) - SemanticError: Redefinition of basic class Object. +(7, 7) - SemanticError: Redefinition of basic class Object. diff --git a/tests/semantic/blocks1.cl b/tests/semantic/blocks1.cl index bad9093d7..1e928908b 100644 --- a/tests/semantic/blocks1.cl +++ b/tests/semantic/blocks1.cl @@ -1,31 +1,31 @@ ---The static type of a block is the static type of the last expression. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test: B <- { - new A; - { - new B; - { - new C; - { - new D; - { - new E; - { - new F; - }; - }; - }; - }; - }; - }; +--The static type of a block is the static type of the last expression. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test: B <- { + new A; + { + new B; + { + new C; + { + new D; + { + new E; + { + new F; + }; + }; + }; + }; + }; + }; }; \ No newline at end of file diff --git a/tests/semantic/blocks1_error.txt b/tests/semantic/blocks1_error.txt index 6bd9d6118..2f0e2caf3 100644 --- a/tests/semantic/blocks1_error.txt +++ b/tests/semantic/blocks1_error.txt @@ -1 +1 @@ -(13, 16) - TypeError: Inferred type F of initialization of attribute test does not conform to declared type B. +(13, 16) - TypeError: Inferred type F of initialization of attribute test does not conform to declared type B. diff --git a/tests/semantic/case1.cl b/tests/semantic/case1.cl index af452f11c..82c6a4d61 100644 --- a/tests/semantic/case1.cl +++ b/tests/semantic/case1.cl @@ -1,23 +1,23 @@ ---For each branch, let Ti be the static type of . The static type of a case expression is Join 1≤i≤n Ti. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - b: B <- case "true" of - i: Int => New C; - b: Bool => New D; - s: String => New E; - esac; - - test: B <- case 0 of - b: Bool => new F; - i: Int => new E; - esac; -}; +--For each branch, let Ti be the static type of . The static type of a case expression is Join 1≤i≤n Ti. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + b: B <- case "true" of + i: Int => New C; + b: Bool => New D; + s: String => New E; + esac; + + test: B <- case 0 of + b: Bool => new F; + i: Int => new E; + esac; +}; diff --git a/tests/semantic/case1_error.txt b/tests/semantic/case1_error.txt index 70c7d16ca..f05ce31b9 100644 --- a/tests/semantic/case1_error.txt +++ b/tests/semantic/case1_error.txt @@ -1 +1 @@ -(19, 16) - TypeError: Inferred type A of initialization of attribute test does not conform to declared type B. +(19, 16) - TypeError: Inferred type A of initialization of attribute test does not conform to declared type B. diff --git a/tests/semantic/case2.cl b/tests/semantic/case2.cl index dbbe4148c..ae97b41da 100644 --- a/tests/semantic/case2.cl +++ b/tests/semantic/case2.cl @@ -1,23 +1,23 @@ --- The variables declared on each branch of a case must all have distinct types. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - b: B <- case "true" of - i: Int => New C; - b: Bool => New D; - s: String => New E; - esac; - - test: A <- case 0 of - b: Bool => new F; - i: Bool => new E; - esac; +-- The variables declared on each branch of a case must all have distinct types. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + b: B <- case "true" of + i: Int => New C; + b: Bool => New D; + s: String => New E; + esac; + + test: A <- case 0 of + b: Bool => new F; + i: Bool => new E; + esac; }; \ No newline at end of file diff --git a/tests/semantic/case3.cl b/tests/semantic/case3.cl index 9ff06336a..da79bbfe6 100644 --- a/tests/semantic/case3.cl +++ b/tests/semantic/case3.cl @@ -1,23 +1,23 @@ --- Missing type - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - b: B <- case "true" of - i: Int => New C; - b: Bool => New D; - s: String => New E; - esac; - - test: A <- case 0 of - b: Bool => new F; - i: Ball => new E; - esac; +-- Missing type + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + b: B <- case "true" of + i: Int => New C; + b: Bool => New D; + s: String => New E; + esac; + + test: A <- case 0 of + b: Bool => new F; + i: Ball => new E; + esac; }; \ No newline at end of file diff --git a/tests/semantic/class1.cl b/tests/semantic/class1.cl index 576a3d0eb..ed83da9d1 100644 --- a/tests/semantic/class1.cl +++ b/tests/semantic/class1.cl @@ -1,9 +1,9 @@ --- Classes may not be redefined. - -class Repeat { - sum(a: Int, b: Int): Int { a + b }; -}; - -class Repeat { - mult(a: Int, b: Int): Int { a * b }; +-- Classes may not be redefined. + +class Repeat { + sum(a: Int, b: Int): Int { a + b }; +}; + +class Repeat { + mult(a: Int, b: Int): Int { a * b }; }; \ No newline at end of file diff --git a/tests/semantic/class1_error.txt b/tests/semantic/class1_error.txt index 6337828d0..19c507672 100644 --- a/tests/semantic/class1_error.txt +++ b/tests/semantic/class1_error.txt @@ -1,2 +1,2 @@ -(7, 5) - SemanticError: Classes may not be redefined - +(7, 5) - SemanticError: Classes may not be redefined + diff --git a/tests/semantic/conditionals1.cl b/tests/semantic/conditionals1.cl index 46af8cc73..3446a8b0f 100644 --- a/tests/semantic/conditionals1.cl +++ b/tests/semantic/conditionals1.cl @@ -1,14 +1,14 @@ ---The predicate must have static type Bool. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - a: A <- if new F then new D else new C fi; +--The predicate must have static type Bool. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + a: A <- if new F then new D else new C fi; }; \ No newline at end of file diff --git a/tests/semantic/conditionals1_error.txt b/tests/semantic/conditionals1_error.txt index 52db300b9..b86345359 100644 --- a/tests/semantic/conditionals1_error.txt +++ b/tests/semantic/conditionals1_error.txt @@ -1 +1 @@ -(13, 16) - TypeError: Predicate of 'if' does not have type Bool. +(13, 16) - TypeError: Predicate of 'if' does not have type Bool. diff --git a/tests/semantic/conditionals2.cl b/tests/semantic/conditionals2.cl index 8814177fc..9d6313d75 100644 --- a/tests/semantic/conditionals2.cl +++ b/tests/semantic/conditionals2.cl @@ -1,24 +1,24 @@ -(* -Let T and F be the static types of the branches of the conditional. Then the static type of the -conditional is T t F. (think: Walk towards Object from each of T and F until the paths meet.) -*) - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - b: B <- if true then - new C - else - if false then new D - else new E fi - fi; - - test: B <- if not true then new F else new E fi; -}; +(* +Let T and F be the static types of the branches of the conditional. Then the static type of the +conditional is T t F. (think: Walk towards Object from each of T and F until the paths meet.) +*) + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + b: B <- if true then + new C + else + if false then new D + else new E fi + fi; + + test: B <- if not true then new F else new E fi; +}; diff --git a/tests/semantic/conditionals2_error.txt b/tests/semantic/conditionals2_error.txt index 8f54d195e..d6f5fc307 100644 --- a/tests/semantic/conditionals2_error.txt +++ b/tests/semantic/conditionals2_error.txt @@ -1,2 +1,2 @@ -(23, 16) - TypeError: Inferred type A of initialization of attribute test does not conform to declared type B. - +(23, 16) - TypeError: Inferred type A of initialization of attribute test does not conform to declared type B. + diff --git a/tests/semantic/dispatch1.cl b/tests/semantic/dispatch1.cl index bfd90f075..1c0457fa3 100644 --- a/tests/semantic/dispatch1.cl +++ b/tests/semantic/dispatch1.cl @@ -1,33 +1,33 @@ -(* -e0 .f(e1, . . . , en ) -Assume e0 has static type A. -Class A must have a method f -*) - -class A inherits IO { - f(x: Int, y: Int): Int { x + y }; - g(x: Int): Int { x + x }; -}; -class B inherits A { - f(a: Int, b: Int): Int { a - b }; -}; -class C inherits B { - ident(m: Int): Int { m }; - f(m: Int, n: Int): Int { m * n }; -}; -class D inherits B { - ident(v: String): IO { new IO.out_string(v) }; - f(v: Int, w: Int): Int { v / w }; - g(v: Int): Int { v + v + v }; - - back(s: String): B { { - out_string(s); - self; - } }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test: B <- new D.back("Hello ").back("World!"); +(* +e0 .f(e1, . . . , en ) +Assume e0 has static type A. +Class A must have a method f +*) + +class A inherits IO { + f(x: Int, y: Int): Int { x + y }; + g(x: Int): Int { x + x }; +}; +class B inherits A { + f(a: Int, b: Int): Int { a - b }; +}; +class C inherits B { + ident(m: Int): Int { m }; + f(m: Int, n: Int): Int { m * n }; +}; +class D inherits B { + ident(v: String): IO { new IO.out_string(v) }; + f(v: Int, w: Int): Int { v / w }; + g(v: Int): Int { v + v + v }; + + back(s: String): B { { + out_string(s); + self; + } }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test: B <- new D.back("Hello ").back("World!"); }; \ No newline at end of file diff --git a/tests/semantic/dispatch1_error.txt b/tests/semantic/dispatch1_error.txt index 89fa22b77..7fb22edce 100644 --- a/tests/semantic/dispatch1_error.txt +++ b/tests/semantic/dispatch1_error.txt @@ -1 +1 @@ -(32, 37) - AttributeError: Dispatch to undefined method back. +(32, 37) - AttributeError: Dispatch to undefined method back. diff --git a/tests/semantic/dispatch2.cl b/tests/semantic/dispatch2.cl index ebca718ac..5182912b8 100644 --- a/tests/semantic/dispatch2.cl +++ b/tests/semantic/dispatch2.cl @@ -1,34 +1,34 @@ -(* -e0 .f(e1, . . . , en ) -Assume e0 has static type A. -Class A must have a method f -the dispatch and the definition of f must have the same number of arguments -*) - -class A inherits IO { - f(x: Int, y: Int): Int { x + y }; - g(x: Int): Int { x + x }; -}; -class B inherits A { - f(a: Int, b: Int): Int { a - b }; -}; -class C inherits B { - ident(m: Int): Int { m }; - f(m: Int, n: Int): Int { m * n }; -}; -class D inherits B { - ident(v: String): IO { new IO.out_string(v) }; - f(v: Int, w: Int): Int { v / w }; - g(v: Int): Int { v + v + v }; - - back(s: String): B { { - out_string(s); - self; - } }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test: Int <- new D.back("Hello ").g(2, 2); +(* +e0 .f(e1, . . . , en ) +Assume e0 has static type A. +Class A must have a method f +the dispatch and the definition of f must have the same number of arguments +*) + +class A inherits IO { + f(x: Int, y: Int): Int { x + y }; + g(x: Int): Int { x + x }; +}; +class B inherits A { + f(a: Int, b: Int): Int { a - b }; +}; +class C inherits B { + ident(m: Int): Int { m }; + f(m: Int, n: Int): Int { m * n }; +}; +class D inherits B { + ident(v: String): IO { new IO.out_string(v) }; + f(v: Int, w: Int): Int { v / w }; + g(v: Int): Int { v + v + v }; + + back(s: String): B { { + out_string(s); + self; + } }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test: Int <- new D.back("Hello ").g(2, 2); }; \ No newline at end of file diff --git a/tests/semantic/dispatch2_error.txt b/tests/semantic/dispatch2_error.txt index 1530fb82c..a86c35340 100644 --- a/tests/semantic/dispatch2_error.txt +++ b/tests/semantic/dispatch2_error.txt @@ -1 +1 @@ -(33, 39) - SemanticError: Method g called with wrong number of arguments. +(33, 39) - SemanticError: Method g called with wrong number of arguments. diff --git a/tests/semantic/dispatch3.cl b/tests/semantic/dispatch3.cl index 98c19da77..ecb1535db 100644 --- a/tests/semantic/dispatch3.cl +++ b/tests/semantic/dispatch3.cl @@ -1,36 +1,36 @@ -(* -e0 .f(e1, . . . , en ) -Assume e0 has static type A. -Class A must have a method f -the static type of the ith actual parameter must conform to the declared type of the ith formal parameter. -*) - -class A inherits IO { - f(x: Int, y: Int): Int { x + y }; - g(x: Int): Int { x + x }; -}; -class B inherits A { - f(a: Int, b: Int): Int { a - b }; -}; -class C inherits B { - ident(m: Int): Int { m }; - f(m: Int, n: Int): Int { m * n }; -}; -class D inherits B { - ident(v: String): IO { new IO.out_string(v) }; - f(v: Int, w: Int): Int { v / w }; - g(v: Int): Int { v + v + v }; - - back(s: String): B { { - out_string(s); - self; - } }; - - alphabet(a: A, b: B, c: C): D { self }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test: B <- new D.alphabet(new D, new D, new D.back("Hello ")).back("World!"); +(* +e0 .f(e1, . . . , en ) +Assume e0 has static type A. +Class A must have a method f +the static type of the ith actual parameter must conform to the declared type of the ith formal parameter. +*) + +class A inherits IO { + f(x: Int, y: Int): Int { x + y }; + g(x: Int): Int { x + x }; +}; +class B inherits A { + f(a: Int, b: Int): Int { a - b }; +}; +class C inherits B { + ident(m: Int): Int { m }; + f(m: Int, n: Int): Int { m * n }; +}; +class D inherits B { + ident(v: String): IO { new IO.out_string(v) }; + f(v: Int, w: Int): Int { v / w }; + g(v: Int): Int { v + v + v }; + + back(s: String): B { { + out_string(s); + self; + } }; + + alphabet(a: A, b: B, c: C): D { self }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test: B <- new D.alphabet(new D, new D, new D.back("Hello ")).back("World!"); }; \ No newline at end of file diff --git a/tests/semantic/dispatch3_error.txt b/tests/semantic/dispatch3_error.txt index 77e81db72..0def5cf03 100644 --- a/tests/semantic/dispatch3_error.txt +++ b/tests/semantic/dispatch3_error.txt @@ -1 +1 @@ -(35, 45) - TypeError: In call of method alphabet, type B of parameter c does not conform to declared type C. +(35, 45) - TypeError: In call of method alphabet, type B of parameter c does not conform to declared type C. diff --git a/tests/semantic/dispatch4.cl b/tests/semantic/dispatch4.cl index 604e462a2..9cadd8332 100644 --- a/tests/semantic/dispatch4.cl +++ b/tests/semantic/dispatch4.cl @@ -1,36 +1,36 @@ -(* -e0 .f(e1, . . . , en ) -Assume e0 has static type A. -Class A must have a method f -If f has return type B and B is a class name, then the static type of the dispatch is B. -*) - -class A inherits IO { - f(x: Int, y: Int): Int { x + y }; - g(x: Int): Int { x + x }; -}; -class B inherits A { - f(a: Int, b: Int): Int { a - b }; -}; -class C inherits B { - ident(m: Int): Int { m }; - f(m: Int, n: Int): Int { m * n }; -}; -class D inherits B { - ident(v: String): IO { new IO.out_string(v) }; - f(v: Int, w: Int): Int { v / w }; - g(v: Int): Int { v + v + v }; - - back(s: String): B { { - out_string(s); - self; - } }; - - alphabet(a: A, b: B, c: C): D { self }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test: D <- new D.alphabet(new D, new D.back("Hello "), new C).back("World!"); +(* +e0 .f(e1, . . . , en ) +Assume e0 has static type A. +Class A must have a method f +If f has return type B and B is a class name, then the static type of the dispatch is B. +*) + +class A inherits IO { + f(x: Int, y: Int): Int { x + y }; + g(x: Int): Int { x + x }; +}; +class B inherits A { + f(a: Int, b: Int): Int { a - b }; +}; +class C inherits B { + ident(m: Int): Int { m }; + f(m: Int, n: Int): Int { m * n }; +}; +class D inherits B { + ident(v: String): IO { new IO.out_string(v) }; + f(v: Int, w: Int): Int { v / w }; + g(v: Int): Int { v + v + v }; + + back(s: String): B { { + out_string(s); + self; + } }; + + alphabet(a: A, b: B, c: C): D { self }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test: D <- new D.alphabet(new D, new D.back("Hello "), new C).back("World!"); }; \ No newline at end of file diff --git a/tests/semantic/dispatch5.cl b/tests/semantic/dispatch5.cl index 9820e5ee1..b4437b1b4 100644 --- a/tests/semantic/dispatch5.cl +++ b/tests/semantic/dispatch5.cl @@ -1,31 +1,31 @@ -(* -(,...,) is shorthand for self.(,...,). -*) - -class A inherits IO { - f(x: Int, y: Int): Int { x + y }; - g(x: Int): Int { x + x }; -}; -class B inherits A { - f(a: Int, b: Int): Int { a - b }; -}; -class C inherits B { - ident(m: Int): Int { m }; - f(m: Int, n: Int): Int { m * n }; - sum(m: Int, n: Int, p: Int): Int { m + n + p }; -}; -class D inherits B { - ident(v: String): IO { new IO.out_string(v) }; - f(v: Int, w: Int): Int { v / w }; - - back(s: String): B { { - out_string(s); - g(2); - sum(1, 2, 3); - self; - } }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; +(* +(,...,) is shorthand for self.(,...,). +*) + +class A inherits IO { + f(x: Int, y: Int): Int { x + y }; + g(x: Int): Int { x + x }; +}; +class B inherits A { + f(a: Int, b: Int): Int { a - b }; +}; +class C inherits B { + ident(m: Int): Int { m }; + f(m: Int, n: Int): Int { m * n }; + sum(m: Int, n: Int, p: Int): Int { m + n + p }; +}; +class D inherits B { + ident(v: String): IO { new IO.out_string(v) }; + f(v: Int, w: Int): Int { v / w }; + + back(s: String): B { { + out_string(s); + g(2); + sum(1, 2, 3); + self; + } }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; }; \ No newline at end of file diff --git a/tests/semantic/dispatch5_error.txt b/tests/semantic/dispatch5_error.txt index 6a6922f32..d26bf34a1 100644 --- a/tests/semantic/dispatch5_error.txt +++ b/tests/semantic/dispatch5_error.txt @@ -1 +1 @@ -(24, 9) - AttributeError: Dispatch to undefined method sum. +(24, 9) - AttributeError: Dispatch to undefined method sum. diff --git a/tests/semantic/dispatch6.cl b/tests/semantic/dispatch6.cl index bbe58fbb1..fcc033f2c 100644 --- a/tests/semantic/dispatch6.cl +++ b/tests/semantic/dispatch6.cl @@ -1,32 +1,32 @@ -(* -e@B.f() invokes the method -f in class B on the object that is the value of e. For this form of dispatch, the static type to the left of -“@”must conform to the type specified to the right of “@”. -*) - -class A { - f(x: Int, y: Int): Int { x + y }; - g(x: Int): Int { x + x }; -}; -class B inherits A { - f(a: Int, b: Int): Int { a - b }; - sum(m: Int, n: Int, p: Int): Int { m + n + p }; -}; -class C inherits B { - ident(m: Int): Int { m }; - f(m: Int, n: Int): Int { m * n }; -}; -class D inherits B { - ident(v: String): IO { new IO.out_string(v) }; - f(v: Int, w: Int): Int { v / w }; - g(v: Int): Int { v + v + v }; - sum(v: Int, w: Int, z: Int): Int { v - w - z }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - a: A <- new D; - b: Int <- new D@B.sum(1, 2, 3); - test: Int <- a@B.sum(1, 2, 3); -}; +(* +e@B.f() invokes the method +f in class B on the object that is the value of e. For this form of dispatch, the static type to the left of +“@”must conform to the type specified to the right of “@”. +*) + +class A { + f(x: Int, y: Int): Int { x + y }; + g(x: Int): Int { x + x }; +}; +class B inherits A { + f(a: Int, b: Int): Int { a - b }; + sum(m: Int, n: Int, p: Int): Int { m + n + p }; +}; +class C inherits B { + ident(m: Int): Int { m }; + f(m: Int, n: Int): Int { m * n }; +}; +class D inherits B { + ident(v: String): IO { new IO.out_string(v) }; + f(v: Int, w: Int): Int { v / w }; + g(v: Int): Int { v + v + v }; + sum(v: Int, w: Int, z: Int): Int { v - w - z }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + a: A <- new D; + b: Int <- new D@B.sum(1, 2, 3); + test: Int <- a@B.sum(1, 2, 3); +}; diff --git a/tests/semantic/dispatch6_error.txt b/tests/semantic/dispatch6_error.txt index 7d5ec3780..ae9184b2f 100644 --- a/tests/semantic/dispatch6_error.txt +++ b/tests/semantic/dispatch6_error.txt @@ -1 +1 @@ -(31, 18) - TypeError: Expression type A does not conform to declared static dispatch type B. +(31, 18) - TypeError: Expression type A does not conform to declared static dispatch type B. diff --git a/tests/semantic/eq1.cl b/tests/semantic/eq1.cl index dc8a0cd43..88f2a7ffe 100644 --- a/tests/semantic/eq1.cl +++ b/tests/semantic/eq1.cl @@ -1,17 +1,17 @@ -(* -The comparison = is a special -case. If either or has static type Int, Bool, or String, then the other must have the -same static type. Any other types, including SELF TYPE, may be freely compared. -*) - -class A { }; -class B inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - x: Bool <- 1 = 2; - test: Bool <- 1 = new A; - y: Bool <- "1" = "2"; - z: Bool <- true = not false; +(* +The comparison = is a special +case. If either or has static type Int, Bool, or String, then the other must have the +same static type. Any other types, including SELF TYPE, may be freely compared. +*) + +class A { }; +class B inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + x: Bool <- 1 = 2; + test: Bool <- 1 = new A; + y: Bool <- "1" = "2"; + z: Bool <- true = not false; }; \ No newline at end of file diff --git a/tests/semantic/eq1_error.txt b/tests/semantic/eq1_error.txt index 0b85d2fa0..f81425683 100644 --- a/tests/semantic/eq1_error.txt +++ b/tests/semantic/eq1_error.txt @@ -1 +1 @@ -(14, 21) - TypeError: Illegal comparison with a basic type. +(14, 21) - TypeError: Illegal comparison with a basic type. diff --git a/tests/semantic/eq2.cl b/tests/semantic/eq2.cl index f4b2ffac7..d76852780 100644 --- a/tests/semantic/eq2.cl +++ b/tests/semantic/eq2.cl @@ -1,17 +1,17 @@ -(* -The comparison = is a special -case. If either or has static type Int, Bool, or String, then the other must have the -same static type. Any other types, including SELF TYPE, may be freely compared. -*) - -class A { }; -class B inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - x: Bool <- 1 = 2; - y: Bool <- "1" = "2"; - test: Bool <- "1" = new B; - z: Bool <- true = not false; -}; +(* +The comparison = is a special +case. If either or has static type Int, Bool, or String, then the other must have the +same static type. Any other types, including SELF TYPE, may be freely compared. +*) + +class A { }; +class B inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + x: Bool <- 1 = 2; + y: Bool <- "1" = "2"; + test: Bool <- "1" = new B; + z: Bool <- true = not false; +}; diff --git a/tests/semantic/eq2_error.txt b/tests/semantic/eq2_error.txt index 1bb29ca32..a44ab0d51 100644 --- a/tests/semantic/eq2_error.txt +++ b/tests/semantic/eq2_error.txt @@ -1 +1 @@ -(15, 23) - TypeError: Illegal comparison with a basic type. +(15, 23) - TypeError: Illegal comparison with a basic type. diff --git a/tests/semantic/eq3.cl b/tests/semantic/eq3.cl index b7ee462c5..4dad693ee 100644 --- a/tests/semantic/eq3.cl +++ b/tests/semantic/eq3.cl @@ -1,17 +1,17 @@ -(* -The comparison = is a special -case. If either or has static type Int, Bool, or String, then the other must have the -same static type. Any other types, including SELF TYPE, may be freely compared. -*) - -class A { }; -class B inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - x: Bool <- 1 = 2; - y: Bool <- "1" = "2"; - z: Bool <- true = not false; - test: Bool <- "true" = not false; -}; +(* +The comparison = is a special +case. If either or has static type Int, Bool, or String, then the other must have the +same static type. Any other types, including SELF TYPE, may be freely compared. +*) + +class A { }; +class B inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + x: Bool <- 1 = 2; + y: Bool <- "1" = "2"; + z: Bool <- true = not false; + test: Bool <- "true" = not false; +}; diff --git a/tests/semantic/eq3_error.txt b/tests/semantic/eq3_error.txt index d57841b95..c4e27eb8a 100644 --- a/tests/semantic/eq3_error.txt +++ b/tests/semantic/eq3_error.txt @@ -1 +1 @@ -(16, 26) - TypeError: Illegal comparison with a basic type. +(16, 26) - TypeError: Illegal comparison with a basic type. diff --git a/tests/semantic/eq4.cl b/tests/semantic/eq4.cl index 63c1067f0..11afc119f 100644 --- a/tests/semantic/eq4.cl +++ b/tests/semantic/eq4.cl @@ -1,17 +1,17 @@ -(* -The comparison = is a special -case. If either or has static type Int, Bool, or String, then the other must have the -same static type. Any other types, including SELF TYPE, may be freely compared. The result is a Bool. -*) - -class A { }; -class B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - x: Bool <- 1 = 2; - y: Bool <- "1" = "2"; - z: Bool <- new A = new B; - test: Int <- new A = new B; -}; +(* +The comparison = is a special +case. If either or has static type Int, Bool, or String, then the other must have the +same static type. Any other types, including SELF TYPE, may be freely compared. The result is a Bool. +*) + +class A { }; +class B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + x: Bool <- 1 = 2; + y: Bool <- "1" = "2"; + z: Bool <- new A = new B; + test: Int <- new A = new B; +}; diff --git a/tests/semantic/eq4_error.txt b/tests/semantic/eq4_error.txt index f075fecbe..3ead21d0e 100644 --- a/tests/semantic/eq4_error.txt +++ b/tests/semantic/eq4_error.txt @@ -1 +1 @@ -(16, 18) - TypeError: Inferred type Bool of initialization of attribute test does not conform to declared type Int. +(16, 18) - TypeError: Inferred type Bool of initialization of attribute test does not conform to declared type Int. diff --git a/tests/semantic/isvoid1.cl b/tests/semantic/isvoid1.cl index 7c3a83a77..072720d85 100644 --- a/tests/semantic/isvoid1.cl +++ b/tests/semantic/isvoid1.cl @@ -1,26 +1,26 @@ ---evaluates to true if expr is void and evaluates to false if expr is not void. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - b: B <- if isvoid new F then - new C - else - if false then new D - else new E fi - fi; - - test: B <- isvoid if isvoid new F then - new C - else - if false then new D - else new E fi - fi; +--evaluates to true if expr is void and evaluates to false if expr is not void. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + b: B <- if isvoid new F then + new C + else + if false then new D + else new E fi + fi; + + test: B <- isvoid if isvoid new F then + new C + else + if false then new D + else new E fi + fi; }; \ No newline at end of file diff --git a/tests/semantic/isvoid1_error.txt b/tests/semantic/isvoid1_error.txt index 3fd0157b4..0922de909 100644 --- a/tests/semantic/isvoid1_error.txt +++ b/tests/semantic/isvoid1_error.txt @@ -1 +1 @@ -(20, 16) - TypeError: Inferred type Bool of initialization of attribute test does not conform to declared type B. +(20, 16) - TypeError: Inferred type Bool of initialization of attribute test does not conform to declared type B. diff --git a/tests/semantic/let1.cl b/tests/semantic/let1.cl index 9220d3dbc..26ef63026 100644 --- a/tests/semantic/let1.cl +++ b/tests/semantic/let1.cl @@ -1,15 +1,15 @@ ---The type of an initialization expression must conform to the declared type of the identifier. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - b: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: B <- new E in b; - test: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: C <- new E in b; +--The type of an initialization expression must conform to the declared type of the identifier. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + b: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: B <- new E in b; + test: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: C <- new E in b; }; \ No newline at end of file diff --git a/tests/semantic/let1_error.txt b/tests/semantic/let1_error.txt index 56547dae5..16ecf780c 100644 --- a/tests/semantic/let1_error.txt +++ b/tests/semantic/let1_error.txt @@ -1 +1 @@ -(14, 76) - TypeError: Inferred type E of initialization of b does not conform to identifier's declared type C. +(14, 76) - TypeError: Inferred type E of initialization of b does not conform to identifier's declared type C. diff --git a/tests/semantic/let2.cl b/tests/semantic/let2.cl index 2949fb94d..c5956ead3 100644 --- a/tests/semantic/let2.cl +++ b/tests/semantic/let2.cl @@ -1,15 +1,15 @@ ---The type of let is the type of the body. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - b: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: B <- new E in b; - test: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: A <- new E in b; +--The type of let is the type of the body. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + b: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: B <- new E in b; + test: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: A <- new E in b; }; \ No newline at end of file diff --git a/tests/semantic/let2_error.txt b/tests/semantic/let2_error.txt index 3b7c669a3..b1e8a365d 100644 --- a/tests/semantic/let2_error.txt +++ b/tests/semantic/let2_error.txt @@ -1 +1 @@ -(14, 16) - TypeError: Inferred type A of initialization of attribute test does not conform to declared type B. +(14, 16) - TypeError: Inferred type A of initialization of attribute test does not conform to declared type B. diff --git a/tests/semantic/let3.cl b/tests/semantic/let3.cl index 0a4a9ceaf..8c0670ab8 100644 --- a/tests/semantic/let3.cl +++ b/tests/semantic/let3.cl @@ -1,15 +1,15 @@ --- Missing type - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - b: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: B <- new E in b; - test: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: Cadena in new B; +-- Missing type + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + b: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: B <- new E in b; + test: B <- let a: Bool, a: Int <- 5, a: String, a: A <- new F, b: Cadena in new B; }; \ No newline at end of file diff --git a/tests/semantic/loops1.cl b/tests/semantic/loops1.cl index 6a0a81818..de3a624d2 100644 --- a/tests/semantic/loops1.cl +++ b/tests/semantic/loops1.cl @@ -1,8 +1,8 @@ ---The predicate must have static type Bool. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - i: Int <- 1; - test: Object <- while "true" loop i <- i + 1 pool; +--The predicate must have static type Bool. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + i: Int <- 1; + test: Object <- while "true" loop i <- i + 1 pool; }; \ No newline at end of file diff --git a/tests/semantic/loops2.cl b/tests/semantic/loops2.cl index d52169da7..dea69fa14 100644 --- a/tests/semantic/loops2.cl +++ b/tests/semantic/loops2.cl @@ -1,9 +1,9 @@ ---The static type of a loop expression is Object. - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - i: Int <- 1; - test: Object <- while not false loop i <- i + 1 pool; - test2: Int <- while not false loop i <- i + 1 pool; -}; +--The static type of a loop expression is Object. + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + i: Int <- 1; + test: Object <- while not false loop i <- i + 1 pool; + test2: Int <- while not false loop i <- i + 1 pool; +}; diff --git a/tests/semantic/loops2_error.txt b/tests/semantic/loops2_error.txt index ab79de8da..9711cdf6a 100644 --- a/tests/semantic/loops2_error.txt +++ b/tests/semantic/loops2_error.txt @@ -1 +1 @@ -(8, 19) - TypeError: Inferred type Object of initialization of attribute test2 does not conform to declared type Int. +(8, 19) - TypeError: Inferred type Object of initialization of attribute test2 does not conform to declared type Int. diff --git a/tests/semantic/methods1.cl b/tests/semantic/methods1.cl index f4ff07bb0..d12031970 100644 --- a/tests/semantic/methods1.cl +++ b/tests/semantic/methods1.cl @@ -1,12 +1,12 @@ ---The identifiers used in the formal parameter list must be distinct - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test(a: A, a: B): Int { 4 }; +--The identifiers used in the formal parameter list must be distinct + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test(a: A, a: B): Int { 4 }; }; \ No newline at end of file diff --git a/tests/semantic/methods1_error.txt b/tests/semantic/methods1_error.txt index 809036803..06ab88a92 100644 --- a/tests/semantic/methods1_error.txt +++ b/tests/semantic/methods1_error.txt @@ -1 +1 @@ -(11, 16) - SemanticError: Formal parameter a is multiply defined. +(11, 16) - SemanticError: Formal parameter a is multiply defined. diff --git a/tests/semantic/methods2.cl b/tests/semantic/methods2.cl index c010df01e..3865f0e13 100644 --- a/tests/semantic/methods2.cl +++ b/tests/semantic/methods2.cl @@ -1,12 +1,12 @@ ---The type of the method body must conform to the declared return type. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test(a: A, b: B): C { new D }; +--The type of the method body must conform to the declared return type. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test(a: A, b: B): C { new D }; }; \ No newline at end of file diff --git a/tests/semantic/methods2_error.txt b/tests/semantic/methods2_error.txt index 1a4baea17..f7e4a330d 100644 --- a/tests/semantic/methods2_error.txt +++ b/tests/semantic/methods2_error.txt @@ -1 +1 @@ -(11, 27) - TypeError: Inferred return type D of method test does not conform to declared return type C. +(11, 27) - TypeError: Inferred return type D of method test does not conform to declared return type C. diff --git a/tests/semantic/methods3.cl b/tests/semantic/methods3.cl index 9aff4d167..b92faeb97 100644 --- a/tests/semantic/methods3.cl +++ b/tests/semantic/methods3.cl @@ -1,14 +1,14 @@ ---A formal parameter hides any definition of an attribute of the same name. - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - a: C <- new C; - test(a: D): D { a }; - test2(a: B): C { a }; +--A formal parameter hides any definition of an attribute of the same name. + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + a: C <- new C; + test(a: D): D { a }; + test2(a: B): C { a }; }; \ No newline at end of file diff --git a/tests/semantic/methods3_error.txt b/tests/semantic/methods3_error.txt index a0f6d9db2..1165b7595 100644 --- a/tests/semantic/methods3_error.txt +++ b/tests/semantic/methods3_error.txt @@ -1 +1 @@ -(13, 22) - TypeError: Inferred return type B of method test2 does not conform to declared return type C. +(13, 22) - TypeError: Inferred return type B of method test2 does not conform to declared return type C. diff --git a/tests/semantic/methods4.cl b/tests/semantic/methods4.cl index e093bac1c..be8fa36ef 100644 --- a/tests/semantic/methods4.cl +++ b/tests/semantic/methods4.cl @@ -1,19 +1,19 @@ -(* -The rule is -simple: If a class C inherits a method f from an ancestor class P, then C may override the inherited -definition of f provided the number of arguments, the types of the formal parameters, and the return -type are exactly the same in both definitions. -*) - -class A { - f(x: Int, y: Int): Int { x + y }; -}; -class B inherits A { - f(x: Int, y: Object): Int { x }; -}; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; +(* +The rule is +simple: If a class C inherits a method f from an ancestor class P, then C may override the inherited +definition of f provided the number of arguments, the types of the formal parameters, and the return +type are exactly the same in both definitions. +*) + +class A { + f(x: Int, y: Int): Int { x + y }; +}; +class B inherits A { + f(x: Int, y: Object): Int { x }; +}; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; }; \ No newline at end of file diff --git a/tests/semantic/methods4_error.txt b/tests/semantic/methods4_error.txt index c9fc2d12a..9f1486dec 100644 --- a/tests/semantic/methods4_error.txt +++ b/tests/semantic/methods4_error.txt @@ -1 +1 @@ -(12, 15) - SemanticError: In redefined method f, parameter type Object is different from original type Int. +(12, 15) - SemanticError: In redefined method f, parameter type Object is different from original type Int. diff --git a/tests/semantic/methods5.cl b/tests/semantic/methods5.cl index 732e4d408..3905dfdd6 100644 --- a/tests/semantic/methods5.cl +++ b/tests/semantic/methods5.cl @@ -1,20 +1,20 @@ -(* -The rule is -simple: If a class C inherits a method f from an ancestor class P, then C may override the inherited -definition of f provided the number of arguments, the types of the formal parameters, and the return -type are exactly the same in both definitions. -*) - -class A { - f(x: Int, y: Int): Int { x + y }; -}; -class B inherits A { - f(a: Int, b: Int): Object { a - b }; -}; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; -}; - +(* +The rule is +simple: If a class C inherits a method f from an ancestor class P, then C may override the inherited +definition of f provided the number of arguments, the types of the formal parameters, and the return +type are exactly the same in both definitions. +*) + +class A { + f(x: Int, y: Int): Int { x + y }; +}; +class B inherits A { + f(a: Int, b: Int): Object { a - b }; +}; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; +}; + diff --git a/tests/semantic/methods5_error.txt b/tests/semantic/methods5_error.txt index 073eee8c5..8b6bdf36e 100644 --- a/tests/semantic/methods5_error.txt +++ b/tests/semantic/methods5_error.txt @@ -1 +1 @@ -(12, 24) - SemanticError: In redefined method f, return type Object is different from original return type Int. +(12, 24) - SemanticError: In redefined method f, return type Object is different from original return type Int. diff --git a/tests/semantic/methods6.cl b/tests/semantic/methods6.cl index 61a62b4b0..dd2b73da6 100644 --- a/tests/semantic/methods6.cl +++ b/tests/semantic/methods6.cl @@ -1,27 +1,27 @@ -(* -The rule is -simple: If a class C inherits a method f from an ancestor class P, then C may override the inherited -definition of f provided the number of arguments, the types of the formal parameters, and the return -type are exactly the same in both definitions. -*) - -class A { - f(x: Int, y: Int): Int { x + y }; - g(x: Int): Int { x + x }; -}; -class B inherits A { - f(a: Int, b: Int): Int { a - b }; -}; -class C inherits B { - ident(m: Int): Int { m }; - f(m: Int, n: Int): Int { m * n }; -}; -class D inherits B { - ident(v: String): IO { new IO.out_string(v) }; - f(v: Int, w: Int): Int { v / w }; - g(v: Int, w: Int, z: Int): Int { v + w + z }; -}; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; +(* +The rule is +simple: If a class C inherits a method f from an ancestor class P, then C may override the inherited +definition of f provided the number of arguments, the types of the formal parameters, and the return +type are exactly the same in both definitions. +*) + +class A { + f(x: Int, y: Int): Int { x + y }; + g(x: Int): Int { x + x }; +}; +class B inherits A { + f(a: Int, b: Int): Int { a - b }; +}; +class C inherits B { + ident(m: Int): Int { m }; + f(m: Int, n: Int): Int { m * n }; +}; +class D inherits B { + ident(v: String): IO { new IO.out_string(v) }; + f(v: Int, w: Int): Int { v / w }; + g(v: Int, w: Int, z: Int): Int { v + w + z }; +}; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; }; \ No newline at end of file diff --git a/tests/semantic/methods6_error.txt b/tests/semantic/methods6_error.txt index 70ad02e32..8e32663b9 100644 --- a/tests/semantic/methods6_error.txt +++ b/tests/semantic/methods6_error.txt @@ -1 +1 @@ -(22, 5) - SemanticError: Incompatible number of formal parameters in redefined method g. +(22, 5) - SemanticError: Incompatible number of formal parameters in redefined method g. diff --git a/tests/semantic/methods7.cl b/tests/semantic/methods7.cl index 21e8ca275..e5a01f682 100644 --- a/tests/semantic/methods7.cl +++ b/tests/semantic/methods7.cl @@ -1,12 +1,12 @@ --- Missing type - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test(a: A, b: Ball): Int { 4 }; +-- Missing type + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test(a: A, b: Ball): Int { 4 }; }; \ No newline at end of file diff --git a/tests/semantic/methods8.cl b/tests/semantic/methods8.cl index 121210748..3fccab54c 100644 --- a/tests/semantic/methods8.cl +++ b/tests/semantic/methods8.cl @@ -1,12 +1,12 @@ --- Missing type - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test(a: A, b: B): Integrer { 4 }; +-- Missing type + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test(a: A, b: B): Integrer { 4 }; }; \ No newline at end of file diff --git a/tests/semantic/new1.cl b/tests/semantic/new1.cl index 40a8b9e9b..d007fc03d 100644 --- a/tests/semantic/new1.cl +++ b/tests/semantic/new1.cl @@ -1,31 +1,31 @@ --- Missing type - -class A { }; -class B inherits A { }; -class C inherits B { }; -class D inherits B { }; -class E inherits B { }; -class F inherits A { }; - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test: F <- { - new A; - { - new Ball; - { - new C; - { - new D; - { - new E; - { - new F; - }; - }; - }; - }; - }; - }; +-- Missing type + +class A { }; +class B inherits A { }; +class C inherits B { }; +class D inherits B { }; +class E inherits B { }; +class F inherits A { }; + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test: F <- { + new A; + { + new Ball; + { + new C; + { + new D; + { + new E; + { + new F; + }; + }; + }; + }; + }; + }; }; \ No newline at end of file diff --git a/tests/semantic/self1.cl b/tests/semantic/self1.cl index 399f6ff06..3387fd263 100644 --- a/tests/semantic/self1.cl +++ b/tests/semantic/self1.cl @@ -1,11 +1,11 @@ -(* -But it is an error to assign to self or to bind self in a let, a -case, or as a formal parameter. It is also illegal to have attributes named self. -*) - - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test(a: Main): IO { self <- a }; -}; +(* +But it is an error to assign to self or to bind self in a let, a +case, or as a formal parameter. It is also illegal to have attributes named self. +*) + + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test(a: Main): IO { self <- a }; +}; diff --git a/tests/semantic/self1_error.txt b/tests/semantic/self1_error.txt index f9f51b9b3..6beb3cda2 100644 --- a/tests/semantic/self1_error.txt +++ b/tests/semantic/self1_error.txt @@ -1 +1 @@ -(10, 30) - SemanticError: Cannot assign to 'self'. +(10, 30) - SemanticError: Cannot assign to 'self'. diff --git a/tests/semantic/self2.cl b/tests/semantic/self2.cl index 6ef75e368..2e6921a92 100644 --- a/tests/semantic/self2.cl +++ b/tests/semantic/self2.cl @@ -1,10 +1,10 @@ -(* -But it is an error to assign to self or to bind self in a let, a -case, or as a formal parameter. It is also illegal to have attributes named self. -*) - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test(): IO { let self: Main <- new Main in self }; -}; +(* +But it is an error to assign to self or to bind self in a let, a +case, or as a formal parameter. It is also illegal to have attributes named self. +*) + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test(): IO { let self: Main <- new Main in self }; +}; diff --git a/tests/semantic/self2_error.txt b/tests/semantic/self2_error.txt index 2e53bb210..20c883c91 100644 --- a/tests/semantic/self2_error.txt +++ b/tests/semantic/self2_error.txt @@ -1 +1 @@ -(9, 22) - SemanticError: 'self' cannot be bound in a 'let' expression. +(9, 22) - SemanticError: 'self' cannot be bound in a 'let' expression. diff --git a/tests/semantic/self3.cl b/tests/semantic/self3.cl index d314798a9..81709b4b5 100644 --- a/tests/semantic/self3.cl +++ b/tests/semantic/self3.cl @@ -1,10 +1,10 @@ -(* -But it is an error to assign to self or to bind self in a let, a -case, or as a formal parameter. It is also illegal to have attributes named self. -*) - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - test(self: IO): IO { self }; -}; +(* +But it is an error to assign to self or to bind self in a let, a +case, or as a formal parameter. It is also illegal to have attributes named self. +*) + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + test(self: IO): IO { self }; +}; diff --git a/tests/semantic/self3_error.txt b/tests/semantic/self3_error.txt index 0015bbe0a..0ae382007 100644 --- a/tests/semantic/self3_error.txt +++ b/tests/semantic/self3_error.txt @@ -1 +1 @@ -(9, 10) - SemanticError: 'self' cannot be the name of a formal parameter. +(9, 10) - SemanticError: 'self' cannot be the name of a formal parameter. diff --git a/tests/semantic/self4.cl b/tests/semantic/self4.cl index 9185c8760..7c2b960cb 100644 --- a/tests/semantic/self4.cl +++ b/tests/semantic/self4.cl @@ -1,10 +1,10 @@ -(* -But it is an error to assign to self or to bind self in a let, a -case, or as a formal parameter. It is also illegal to have attributes named self. -*) - -class Main inherits IO { - main(): IO { out_string("Hello World!")}; - - self: IO <- self; +(* +But it is an error to assign to self or to bind self in a let, a +case, or as a formal parameter. It is also illegal to have attributes named self. +*) + +class Main inherits IO { + main(): IO { out_string("Hello World!")}; + + self: IO <- self; }; \ No newline at end of file diff --git a/tests/semantic/self4_error.txt b/tests/semantic/self4_error.txt index bf8740604..c19ca400f 100644 --- a/tests/semantic/self4_error.txt +++ b/tests/semantic/self4_error.txt @@ -1 +1 @@ -(9, 5) - SemanticError: 'self' cannot be the name of an attribute. +(9, 5) - SemanticError: 'self' cannot be the name of an attribute. diff --git a/tests/semantic_test.py b/tests/semantic_test.py index 46f07439d..cac9cd78b 100644 --- a/tests/semantic_test.py +++ b/tests/semantic_test.py @@ -1,14 +1,14 @@ -import pytest -import os -from utils import compare_errors, first_error_only_line - -tests_dir = __file__.rpartition('/')[0] + '/semantic/' -tests = [(file) for file in os.listdir(tests_dir) if file.endswith('.cl')] - -@pytest.mark.semantic -@pytest.mark.error -@pytest.mark.run(order=3) -@pytest.mark.parametrize("cool_file", tests) -def test_semantic_errors(compiler_path, cool_file): - compare_errors(compiler_path, tests_dir + cool_file, tests_dir + cool_file[:-3] + '_error.txt', \ +import pytest +import os +from utils import compare_errors, first_error_only_line + +tests_dir = __file__.rpartition('/')[0] + '/semantic/' +tests = [(file) for file in os.listdir(tests_dir) if file.endswith('.cl')] + +@pytest.mark.semantic +@pytest.mark.error +@pytest.mark.run(order=3) +@pytest.mark.parametrize("cool_file", tests) +def test_semantic_errors(compiler_path, cool_file): + compare_errors(compiler_path, tests_dir + cool_file, tests_dir + cool_file[:-3] + '_error.txt', \ cmp=first_error_only_line) \ No newline at end of file diff --git a/tests/utils/utils.py b/tests/utils/utils.py index f98d19dd0..961cf7cbc 100644 --- a/tests/utils/utils.py +++ b/tests/utils/utils.py @@ -1,91 +1,91 @@ -import subprocess -import re - - -COMPILER_TIMEOUT = 'El compilador tarda mucho en responder.' -SPIM_TIMEOUT = 'El spim tarda mucho en responder.' -TEST_MUST_FAIL = 'El test %s debe fallar al compilar' -TEST_MUST_COMPILE = 'El test %s debe compilar' -BAD_ERROR_FORMAT = '''El error no esta en formato: (,) - : - o no se encuentra en la 3ra linea\n\n%s''' -UNEXPECTED_ERROR = 'Se esperaba un %s en (%d, %d). Su error fue un %s en (%d, %d)' -UNEXPECTED_OUTPUT = 'La salida de %s no es la esperada:\n%s\nEsperada:\n%s' - -ERROR_FORMAT = r'^\s*\(\s*(\d+)\s*,\s*(\d+)\s*\)\s*-\s*(\w+)\s*:(.*)$' - -def parse_error(error: str): - merror = re.fullmatch(ERROR_FORMAT, error) - assert merror, BAD_ERROR_FORMAT % error - - return (t(x) for t, x in zip([int, int, str, str], merror.groups())) - - -def first_error(compiler_output: list, errors: list): - line, column, error_type, _ = parse_error(errors[0]) - - oline, ocolumn, oerror_type, _ = parse_error(compiler_output[0]) - - assert line == oline and column == ocolumn and error_type == oerror_type,\ - UNEXPECTED_ERROR % (error_type, line, column, oerror_type, oline, ocolumn) - -def first_error_only_line(compiler_output: list, errors: list): - line, column, error_type, _ = parse_error(errors[0]) - - oline, ocolumn, oerror_type, _ = parse_error(compiler_output[0]) - - assert line == oline and error_type == oerror_type,\ - UNEXPECTED_ERROR % (error_type, line, column, oerror_type, oline, ocolumn) - - -def get_file_name(path: str): - try: - return path[path.rindex('/') + 1:] - except ValueError: - return path - -def compare_errors(compiler_path: str, cool_file_path: str, error_file_path: str, cmp=first_error, timeout=100): - try: - sp = subprocess.run(['bash', compiler_path, cool_file_path], capture_output=True, timeout=timeout) - return_code, output = sp.returncode, sp.stdout.decode() - except subprocess.TimeoutExpired: - assert False, COMPILER_TIMEOUT - - assert return_code == 1, TEST_MUST_FAIL % get_file_name(cool_file_path) - - fd = open(error_file_path, 'r') - errors = fd.read().split('\n') - fd.close() - - # checking the errors of compiler - compiler_output = output.split('\n') - cmp(compiler_output[2:], errors) - -SPIM_HEADER = r'''^SPIM Version .+ of .+ -Copyright .+\, James R\. Larus\. -All Rights Reserved\. -See the file README for a full copyright notice\. -(?:Loaded: .+\n)*''' -def compare_outputs(compiler_path: str, cool_file_path: str, input_file_path: str, output_file_path: str, timeout=100): - try: - sp = subprocess.run(['bash', compiler_path, cool_file_path], capture_output=True, timeout=timeout) - assert sp.returncode == 0, TEST_MUST_COMPILE % get_file_name(cool_file_path) - except subprocess.TimeoutExpired: - assert False, COMPILER_TIMEOUT - - spim_file = cool_file_path[:-2] + 'mips' - - try: - fd = open(input_file_path, 'rb') - sp = subprocess.run(['spim', '-file', spim_file], input=fd.read(), capture_output=True, timeout=timeout) - fd.close() - mo = re.match(SPIM_HEADER, sp.stdout.decode()) - if mo: - output = mo.string[mo.end():] - except subprocess.TimeoutExpired: - assert False, SPIM_TIMEOUT - - fd = open(output_file_path, 'r') - eoutput = fd.read() - fd.close() - - assert output == eoutput, UNEXPECTED_OUTPUT % (spim_file, repr(output), repr(eoutput)) +import subprocess +import re + + +COMPILER_TIMEOUT = 'El compilador tarda mucho en responder.' +SPIM_TIMEOUT = 'El spim tarda mucho en responder.' +TEST_MUST_FAIL = 'El test %s debe fallar al compilar' +TEST_MUST_COMPILE = 'El test %s debe compilar' +BAD_ERROR_FORMAT = '''El error no esta en formato: (,) - : + o no se encuentra en la 3ra linea\n\n%s''' +UNEXPECTED_ERROR = 'Se esperaba un %s en (%d, %d). Su error fue un %s en (%d, %d)' +UNEXPECTED_OUTPUT = 'La salida de %s no es la esperada:\n%s\nEsperada:\n%s' + +ERROR_FORMAT = r'^\s*\(\s*(\d+)\s*,\s*(\d+)\s*\)\s*-\s*(\w+)\s*:(.*)$' + +def parse_error(error: str): + merror = re.fullmatch(ERROR_FORMAT, error) + assert merror, BAD_ERROR_FORMAT % error + + return (t(x) for t, x in zip([int, int, str, str], merror.groups())) + + +def first_error(compiler_output: list, errors: list): + line, column, error_type, _ = parse_error(errors[0]) + + oline, ocolumn, oerror_type, _ = parse_error(compiler_output[0]) + + assert line == oline and column == ocolumn and error_type == oerror_type,\ + UNEXPECTED_ERROR % (error_type, line, column, oerror_type, oline, ocolumn) + +def first_error_only_line(compiler_output: list, errors: list): + line, column, error_type, _ = parse_error(errors[0]) + + oline, ocolumn, oerror_type, _ = parse_error(compiler_output[0]) + + assert line == oline and error_type == oerror_type,\ + UNEXPECTED_ERROR % (error_type, line, column, oerror_type, oline, ocolumn) + + +def get_file_name(path: str): + try: + return path[path.rindex('/') + 1:] + except ValueError: + return path + +def compare_errors(compiler_path: str, cool_file_path: str, error_file_path: str, cmp=first_error, timeout=100): + try: + sp = subprocess.run(['bash', compiler_path, cool_file_path], capture_output=True, timeout=timeout) + return_code, output = sp.returncode, sp.stdout.decode() + except subprocess.TimeoutExpired: + assert False, COMPILER_TIMEOUT + + assert return_code == 1, TEST_MUST_FAIL % get_file_name(cool_file_path) + + fd = open(error_file_path, 'r') + errors = fd.read().split('\n') + fd.close() + + # checking the errors of compiler + compiler_output = output.split('\n') + cmp(compiler_output[2:], errors) + +SPIM_HEADER = r'''^SPIM Version .+ of .+ +Copyright .+\, James R\. Larus\. +All Rights Reserved\. +See the file README for a full copyright notice\. +(?:Loaded: .+\n)*''' +def compare_outputs(compiler_path: str, cool_file_path: str, input_file_path: str, output_file_path: str, timeout=100): + try: + sp = subprocess.run(['bash', compiler_path, cool_file_path], capture_output=True, timeout=timeout) + assert sp.returncode == 0, TEST_MUST_COMPILE % get_file_name(cool_file_path) + except subprocess.TimeoutExpired: + assert False, COMPILER_TIMEOUT + + spim_file = cool_file_path[:-2] + 'mips' + + try: + fd = open(input_file_path, 'rb') + sp = subprocess.run(['spim', '-file', spim_file], input=fd.read(), capture_output=True, timeout=timeout) + fd.close() + mo = re.match(SPIM_HEADER, sp.stdout.decode()) + if mo: + output = mo.string[mo.end():] + except subprocess.TimeoutExpired: + assert False, SPIM_TIMEOUT + + fd = open(output_file_path, 'r') + eoutput = fd.read() + fd.close() + + assert output == eoutput, UNEXPECTED_OUTPUT % (spim_file, repr(output), repr(eoutput)) From b9386a6ebf6d21533c3437f33747da8cf785d2e1 Mon Sep 17 00:00:00 2001 From: livi98 Date: Tue, 8 Feb 2022 01:52:22 +0100 Subject: [PATCH 082/194] new change --- src/code_generator/COOLToCILVisitor.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index 68fc61494..a8af7b6f6 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -272,3 +272,5 @@ def visit(self, node, scope): def visit(self, node, scope): return self._define_binary_node(node, scope, cil.EqualNode) +#nuevo cambio + From be42513493f54cafc2d58519c16d550b6520f21b Mon Sep 17 00:00:00 2001 From: livi98 Date: Wed, 9 Feb 2022 00:24:29 +0100 Subject: [PATCH 083/194] In BaseCOOLToCILVisitor adding define_biult_in and in COOLToCILVisitor adding NotNode, IsVoid and NewNode --- src/code_generator/BaseCoolToCilVisitor.py | 120 ++++++++++++++++++++- src/code_generator/COOLToCILVisitor.py | 15 ++- 2 files changed, 132 insertions(+), 3 deletions(-) diff --git a/src/code_generator/BaseCoolToCilVisitor.py b/src/code_generator/BaseCoolToCilVisitor.py index 2501fbd4b..5c9ca3f05 100644 --- a/src/code_generator/BaseCoolToCilVisitor.py +++ b/src/code_generator/BaseCoolToCilVisitor.py @@ -64,4 +64,122 @@ def register_data(self, value): vname = f'data_{len(self.dotdata)}' data_node = cil.DataNode(vname, value) self.dotdata.append(data_node) - return data_node \ No newline at end of file + return data_node + + def define_built_in(self): + #regular function + f1_params = [cil.ParamNode("self", 'Object')] + f1_localVars = [cil.LocalNode("local_abort_Object_self_0")] + f1_intructions = [cil.AssignNode(f1_localVars[0].name,f1_params[0].name), + cil.ExitNode(f1_params[0].name)] + f1 = cil.FunctionNode("function_abort_Object",f1_params,f1_localVars,f1_intructions) + + f2_params = [cil.ParamNode("self", 'Object')] + f2_localVars = [cil.LocalNode("local_type_name_Object_result_0")] + f2_intructions = [cil.TypeOfNode(f2_params[0].name,f2_localVars[0].name), + cil.ReturnNode(f2_localVars[0].name)] + f2 = cil.FunctionNode("function_type_name_Object",f2_params,f2_localVars,f2_intructions) + + f3_params = [cil.ParamNode("self", 'Object')] + f3_localVars = [cil.LocalNode("local_copy_Object_result_0")] + f3_intructions = [cil.CopyNode(f3_localVars[0].name,f3_params[0].name), + cil.ReturnNode(f3_localVars[0].name)] + f3 = cil.FunctionNode("function_copy_Object",f3_params,f3_localVars,f3_intructions) + + #IO out + f4_params = [cil.ParamNode("self", 'IO'), cil.ParamNode("word", 'String')] + f4_localVars = [cil.LocalNode("local_out_string_String_self_0")] + f4_intructions = [cil.AssignNode(f4_localVars[0].name, f4_params[0].name), + cil.OutStringNode(f4_params[1].name), + cil.ReturnNode(f4_localVars[0].name)] + f4 = cil.FunctionNode("function_out_string_IO",f4_params,f4_localVars,f4_intructions) + + f5_params = [cil.ParamNode("self", 'IO'), cil.ParamNode("number", 'Int')] + f5_localVars = [cil.LocalNode("local_out_int_IO_self_0")] + f5_intructions = [cil.AssignNode(f5_localVars[0].name,f5_params[0].name), + cil.OutIntNode(f5_params[1].name), + cil.ReturnNode(f5_localVars[0].name)] + f5 = cil.FunctionNode("function_out_int_IO",f5_params,f5_localVars,f5_intructions) + + #IO in + f6_params = [cil.ParamNode("self", 'IO')] + f6_localVars = [cil.LocalNode("local_in_int_IO_result_0")] + f6_intructions = [cil.ReadIntNode(f6_localVars[0].name), + cil.ReturnNode(f6_localVars[0].name)] + f6 = cil.FunctionNode("function_in_int_IO",f6_params,f6_localVars,f6_intructions) + + f7_params = [cil.ParamNode("self", 'IO')] + f7_localVars = [cil.LocalNode("local_in_string_IO_result_0")] + f7_intructions = [cil.ReadStringNode(f7_localVars[0].name), + cil.ReturnNode(f7_localVars[0].name)] + f7 = cil.FunctionNode("function_in_string_IO",f7_params,f7_localVars,f7_intructions) + + #Functions from String type + f8_params = [cil.ParamNode("self", 'String')] + f8_localVars = [cil.LocalNode("local_length_String_result_0")] + f8_intructions = [cil.LengthNode(f8_localVars[0].name,f8_params[0].name), + cil.ReturnNode(f8_localVars[0].name)] + f8 = cil.FunctionNode("function_length_String",f8_params,f8_localVars,f8_intructions) + + f9_params = [cil.ParamNode("self", 'String'), cil.ParamNode("word", 'String')] + f9_localVars = [cil.LocalNode("local_concat_String_result_0")] + f9_intructions = [cil.ConcatNode(f9_localVars[0].name,f9_params[0].name,f9_params[1].name), + cil.ReturnNode(f9_localVars[0].name)] + f9 = cil.FunctionNode("function_concat_String",f9_params,f9_localVars,f9_intructions) + + f10_params = [cil.ParamNode("self", 'String'), cil.ParamNode("begin", 'Int'), cil.ParamNode("end", 'Int')] + f10_localVars = [cil.LocalNode("local_substr_String_result_0")] + f10_intructions = [cil.SubstringNode(f10_localVars[0].name,f10_params[0].name,f10_params[1].name,f10_params[2].name), + cil.ReturnNode(f10_localVars[0].name)] + f10 = cil.FunctionNode("function_substr_String",f10_params,f10_localVars,f10_intructions) + + f11_params = [cil.ParamNode("self", 'String')] + f11_localVars = [cil.LocalNode("local_type_name_String_result_0")] + f11_intructions = [cil.LoadNode(f11_localVars[0].name, 'type_String'), + cil.ReturnNode(f11_localVars[0].name)] + f11 = cil.FunctionNode("function_type_name_String",f11_params,f11_localVars,f11_intructions) + + f12_params = [cil.ParamNode("self", 'String')] + f12_localVars = [cil.LocalNode("local_copy_String_result_0")] + f12_intructions = [cil.ConcatNode(f12_localVars[0].name, f12_params[0].name, None), + cil.ReturnNode(f12_localVars[0].name)] + f12 = cil.FunctionNode("function_copy_String",f12_params,f12_localVars,f12_intructions) + + #Functions from Int type + f13_params = [cil.ParamNode("self", 'Int')] + f13_localVars = [cil.LocalNode("local_type_name_Int_result_0")] + f13_intructions = [cil.LoadNode(f13_localVars[0].name, 'type_Int'), + cil.ReturnNode(f13_localVars[0].name)] + f13 = cil.FunctionNode("function_type_name_Int",f13_params,f13_localVars,f13_intructions) + + f14_params = [cil.ParamNode("self", 'Int')] + f14_localVars = [cil.LocalNode("local_copy_Int_result_0")] + f14_intructions = [cil.AssignNode(f14_localVars[0].name, f14_params[0].name), + cil.ReturnNode(f14_localVars[0].name)] + f14 = cil.FunctionNode("function_copy_Int",f14_params,f14_localVars,f14_intructions) + + #Functions from Bool type + f15_params = [cil.ParamNode("self", 'Bool')] + f15_localVars = [cil.LocalNode("local_type_name_Bool_result_0")] + f15_intructions = [cil.LoadNode(f15_localVars[0].name, 'type_Bool'), + cil.ReturnNode(f15_localVars[0].name)] + f15 = cil.FunctionNode("function_type_name_Bool",f15_params,f15_localVars,f15_intructions) + + f16_params = [cil.ParamNode("self", 'Bool')] + f16_localVars = [cil.LocalNode("local_copy_result_Bool_0")] + f16_intructions = [cil.AssignNode(f16_localVars[0].name, f16_params[0].name), + cil.ReturnNode(f16_localVars[0].name)] + f16 = cil.FunctionNode("function_copy_Bool",f16_params,f16_localVars,f16_intructions) + + self.dotcode += [f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11, f12, f13, f14, f15, f16] + object_methods = [('abort', f1.name), ('type_name', f2.name), ('copy', f3.name)] + string_methods = [('length', f8.name), ('concat', f9.name), ('substr', f10.name), ('type_name', f11.name), ('copy', f12.name)] + io_methods = [('out_string', f4.name), ('out_int', f5.name), ('in_int', f6.name), ('in_string', f7.name)] + int_methods = [('type_name', f13.name), ('copy', f14.name)] + bool_methods = [('type_name', f15.name), ('copy', f16.name)] + + self.dottypes += [cil.TypeNode("Object", [], object_methods), + cil.TypeNode("IO", [], object_methods + io_methods) , + cil.TypeNode("String", [], string_methods), + cil.TypeNode('Int', [], int_methods), + cil.TypeNode('Bool', [], bool_methods)] \ No newline at end of file diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index a8af7b6f6..f3184d79d 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -22,7 +22,7 @@ def visit(self, node, scope): self.register_instruction(cil.ReturnNode(0)) self.current_function = None - # self.create_built_in() + self.define_built_in() for declaration, child_scope in zip(node.declarations, scope.children): self.visit(declaration, child_scope) @@ -178,6 +178,8 @@ def visit(self, node, scope): self.register_instruction(cil.AssignNode(result, expr)) self.register_instruction(cil.GoToNode(start_label.label)) self.register_instruction(end_label) + + return result, ObjectType() @visitor.when(BlockNode) def visit(self, node, scope): @@ -244,6 +246,16 @@ def visit(self, node, scope): return instance, typex + @visitor.when(NegationNode) + def visit(self, node, scope): + return self._define_unary_node(node, scope, cil.LogicalNotNode) + + @visitor.when(IsVoidNode) + def visit(self, node, scope): + expr, _ = self.visit(node.expr, scope) + result = self.check_void(expr) + return result, BoolType() + @visitor.when(PlusNode) def visit(self, node, scope): return self._define_binary_node(node, scope, cil.PlusNode) @@ -272,5 +284,4 @@ def visit(self, node, scope): def visit(self, node, scope): return self._define_binary_node(node, scope, cil.EqualNode) -#nuevo cambio From 2731bfb8aaf1df0ba35a0e30080d2d413b7e230b Mon Sep 17 00:00:00 2001 From: livi98 Date: Wed, 9 Feb 2022 17:22:39 +0100 Subject: [PATCH 084/194] PrintVisitor for cil --- src/code_generator/BaseCoolToCilVisitor.py | 12 +- src/code_generator/COOLToCILVisitor.py | 2 +- src/code_generator/cil_visual_visitor.py | 151 +++++++++++++++++++++ 3 files changed, 163 insertions(+), 2 deletions(-) create mode 100644 src/code_generator/cil_visual_visitor.py diff --git a/src/code_generator/BaseCoolToCilVisitor.py b/src/code_generator/BaseCoolToCilVisitor.py index 5c9ca3f05..7633b1dae 100644 --- a/src/code_generator/BaseCoolToCilVisitor.py +++ b/src/code_generator/BaseCoolToCilVisitor.py @@ -182,4 +182,14 @@ def define_built_in(self): cil.TypeNode("IO", [], object_methods + io_methods) , cil.TypeNode("String", [], string_methods), cil.TypeNode('Int', [], int_methods), - cil.TypeNode('Bool', [], bool_methods)] \ No newline at end of file + cil.TypeNode('Bool', [], bool_methods)] + + #este metodo tiene que ver con los types de la semantica REVISAAAARRRR! + def get_type(self, name) -> Type: + try: + return self.types[name] + except KeyError: + error_text = TypesError.TYPE_NOT_DEFINED % name + raise TypesError(error_text) + + \ No newline at end of file diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index f3184d79d..22004ff00 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -112,7 +112,7 @@ def visit(self, node, scope): args_node = [cil.ArgNode(obj)] + self.handle_arguments(node.args, scope, meth.param_types) rtype = meth.return_type - result = None if isinstance(rtype, VoidType) else self.define_internal_local() + result = None if isinstance(rtype, VoidType()) else self.define_internal_local() continue_label = cil.LabelNode(f'continue__{self.index}') isvoid = self.check_void(obj) diff --git a/src/code_generator/cil_visual_visitor.py b/src/code_generator/cil_visual_visitor.py new file mode 100644 index 000000000..02f43d80a --- /dev/null +++ b/src/code_generator/cil_visual_visitor.py @@ -0,0 +1,151 @@ +from utils import visitor +from cil_ast import * + +def get_formatter(): + class PrintVisitor(object): + @visitor.on('node') + def visit(self, node): + pass + + @visitor.when(ProgramNode) + def visit(self, node): + dottypes = '\n'.join(self.visit(t) for t in node.dottypes) + dotdata = '\n'.join(self.visit(t) for t in node.dotdata) + dotcode = '\n'.join(self.visit(t) for t in node.dotcode) + return f'.TYPES\n{dottypes}\n\n.DATA\n{dotdata}\n\n.CODE\n{dotcode}' + + #.TYPE + @visitor.when(TypeNode) + def visit(self, node): + attributes = '\n\t'.join(f'attribute {x}: {y}' for x, y in node.attributes) + methods = '\n\t'.join(f'method {x}: {y}' for x, y in node.methods) + + return f'type {node.name} {{\n\t{attributes}\n\n\t{methods}\n}}' + + #.DATA + @visitor.when(DataNode) + def visit(self, node): + return f'{node.name} = "{node.value}"' + + #.CODE + @visitor.when(FunctionNode) + def visit(self, node): + params = '\n\t'.join(self.visit(x) for x in node.params) + localvars = '\n\t'.join(self.visit(x) for x in node.localvars) + instructions = '\n\t'.join(self.visit(x) for x in node.instructions) + return f'function {node.name} {{\n\t{params}\n\n\t{localvars}\n\n\t{instructions}\n}}' + #InstructionNode + @visitor.when(ParamNode) + def visit(self, node): + return f'PARAM {node.name}' + + @visitor.when(LocalNode) + def visit(self, node): + return f'LOCAL {node.name}' + + @visitor.when(AssignNode) + def visit(self, node): + return f'{node.dest} = {node.source}' + #ArithNode + @visitor.when(PlusNode) + def visit(self, node): + return f'{node.dest} = {node.left} + {node.right}' + + @visitor.when(MinusNode) + def visit(self, node): + return f'{node.dest} = {node.left} - {node.right}' + + @visitor.when(StarNode) + def visit(self, node): + return f'{node.dest} = {node.left} * {node.right}' + + @visitor.when(DivNode) + def visit(self, node): + return f'{node.dest} = {node.left} / {node.right}' + + @visitor.when(LessNode) + def visit(self, node): + return f'{node.dest} = {node.left} < {node.right}' + + @visitor.when(LessEqualNode) + def visit(self, node): + return f'{node.dest} = {node.left} <= {node.right}' + + @visitor.when(EqualNode) + def visit(self, node): + return f'{node.dest} = {node.left} = {node.right}' + #Attr + @visitor.when(GetAttrNode) + def visit(self, node): + return f'{node.dest} = GETATTR {node.obj} {node.attr}' + + @visitor.when(SetAttrNode) + def visit(self, node): + return f'SETATTR {node.obj} {node.attr} = {node.value}' + #Memory + @visitor.when(AllocateNode) + def visit(self, node): + return f'{node.dest} = ALLOCATE {node.type}' + + @visitor.when(TypeOfNode) + def visit(self, node): + return f'{node.dest} = TYPEOF {node.obj}' + #Jumps + @visitor.when(LabelNode) + def visit(self, node): + return f'LABEL {node.label}' + + @visitor.when(GoToNode) + def visit(self, node): + return f'GOTO {node.label}' + + @visitor.when(IfGoToNode) + def visit(self, node): + return f'IF {node.cond} GOTO {node.label}' + #Static Invocation + @visitor.when(CallNode) + def visit(self, node): + args = '\n\t'.join(self.visit(arg) for arg in node.args) + return f'{args}\n' + f'\t{node.dest} = CALL {node.function}' + #Dynamic Invocation + @visitor.when(VCallNode) + def visit(self, node): + args = '\n\t'.join(self.visit(arg) for arg in node.args) + return f'{args}\n' + f'\t{node.dest} = VCALL {node.type} {node.method}' + #Args + @visitor.when(ArgNode) + def visit(self, node): + return f'ARG {node.dest}' + #Return + @visitor.when(ReturnNode) + def visit(self, node): + return f'RETURN {node.value if node.value is not None else ""}' + #IO + @visitor.when(LoadNode) + def visit(self, node): + return f'{node.dest} = LOAD {node.msg}' + + @visitor.when(LengthNode) + def visit(self, node): + return f'{node.dest} = LENGTH {node.arg}' + + @visitor.when(ConcatNode) + def visit(self, node): + return f'{node.dest} = CONCAT {node.arg1} {node.arg2}' + + @visitor.when(SubstringNode) + def visit(self, node): + return f'{node.dest} = SUBSTRING {node.word} {node.begin} {node.end}' + + @visitor.when(ToStrNode) + def visit(self, node): + return f'{node.dest} = STR {node.ivalue}' + + @visitor.when(ReadNode) + def visit(self, node): + return f'{node.dest} = READ_STR' + + printer = PrintVisitor() + return lambda ast: printer.visit(ast) + + \ No newline at end of file From 7b403b1714a3825954750af4d187e0008e5d6ea6 Mon Sep 17 00:00:00 2001 From: livi98 Date: Wed, 9 Feb 2022 19:24:43 +0100 Subject: [PATCH 085/194] separate func_calls (adding member_call) on COLL AST --- src/code_generator/COOLToCILVisitor.py | 81 ++++++++++++++++-------- src/code_generator/cil_ast.py | 11 ++-- src/code_generator/cil_visual_visitor.py | 6 +- src/utils/ast.py | 8 +++ 4 files changed, 74 insertions(+), 32 deletions(-) diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index 22004ff00..9ff5ffb51 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -1,5 +1,5 @@ import cil_ast as cil -from BaseCOOLToCILVisitor import * +from BaseCoolToCilVisitor import * from utils import visitor from utils.ast import * @@ -106,34 +106,63 @@ def visit(self, node, scope): @visitor.when(FuncCallNode) def visit(self, node, scope): - obj, otype = self.visit(node.obj, scope) + # obj, otype = self.visit(node.obj, scope) - meth = otype.get_method(node.id) - args_node = [cil.ArgNode(obj)] + self.handle_arguments(node.args, scope, meth.param_types) - - rtype = meth.return_type - result = None if isinstance(rtype, VoidType()) else self.define_internal_local() - - continue_label = cil.LabelNode(f'continue__{self.index}') - isvoid = self.check_void(obj) - self.register_instruction(cil.IfGoToNode(isvoid, continue_label.label)) - self.register_instruction(cil.ErrorNode('dispatch_error')) - self.register_instruction(continue_label) - - #desambiguar segun sea el llamado, dinamico o estatico - # self.register_instruction(cil.StaticCallNode(node.type, node.id, result, args_node, rtype.name)) - # return result, self._return_type(otype, node) + # meth = otype.get_method(node.id) + # args_node = [cil.ArgNode(obj)] + self.handle_arguments(node.args, scope, meth.param_types) + + # rtype = meth.return_type + # result = None if isinstance(rtype, VoidType()) else self.define_internal_local() + + # continue_label = cil.LabelNode(f'continue__{self.index}') + # isvoid = self.check_void(obj) + # self.register_instruction(cil.IfGoToNode(isvoid, continue_label.label)) + # self.register_instruction(cil.ErrorNode('dispatch_error')) + # self.register_instruction(continue_label) + + # #desambiguar segun sea el llamado, dinamico o estatico + # # self.register_instruction(cil.StaticCallNode(node.type, node.id, result, args_node, rtype.name)) + # # return result, self._return_type(otype, node) + + # # self.register_instruction(cil.DynamicCallNode(self.current_type.name, 'self', node.id, result, args_node, rtype.name)) + # # return result, self._return_type(self.current_type, node) + + # # if otype in [StringType(), IntType(), BoolType()]: + # # self.register_instruction(cil.StaticCallNode(otype.name, node.id, result, args_node, rtype.name)) + # # else: + # # self.register_instruction(cil.DynamicCallNode(otype.name, obj, node.id, result, args_node, rtype.name)) + # # return result, self._return_type(otype, node) + + result_local = self.define_internal_local(scope = scope, name = "result") + expr_value = self.visit(node.instance, scope) + + func_call_args = [] + for arg in node.args: + param_local = self.visit(arg, scope) + func_call_args.append(cil.ArgNode(param_local)) + func_call_args.append(cil.ArgNode(expr_value)) + + static_instance = self.define_internal_local(scope=scope, name='static_instance') + self.register_instruction(cil.AllocateNode(node.static_type,self.context.get_type(node.static_type).tag ,static_instance)) + + self.register_instruction(cil.VCallNode(result_local, node.method, func_call_args, node.static_type, static_instance)) + return result_local - # self.register_instruction(cil.DynamicCallNode(self.current_type.name, 'self', node.id, result, args_node, rtype.name)) - # return result, self._return_type(self.current_type, node) + @visitor.when(MemberCallNode) + def visit(self, node, scope): + result_local = self.define_internal_local(scope = scope, name = "result") + expr_value = self.visit(node.instance, scope) - # if otype in [StringType(), IntType(), BoolType()]: - # self.register_instruction(cil.StaticCallNode(otype.name, node.id, result, args_node, rtype.name)) - # else: - # self.register_instruction(cil.DynamicCallNode(otype.name, obj, node.id, result, args_node, rtype.name)) - # return result, self._return_type(otype, node) + member_call_args = [] + for arg in node.args: + param_local = self.visit(arg, scope) + member_call_args.append(cil.ArgNode(param_local)) + member_call_args.append(cil.ArgNode(expr_value)) - return + dynamic_type = node.instance.computed_type.name + self.register_instruction(cil.VCallNode(result_local, node.method, member_call_args, dynamic_type, expr_value)) + + return result_local @visitor.when(IfNode) def visit(self, node, scope): @@ -248,7 +277,7 @@ def visit(self, node, scope): @visitor.when(NegationNode) def visit(self, node, scope): - return self._define_unary_node(node, scope, cil.LogicalNotNode) + return self._define_unary_node(node, scope, cil.NotNode) @visitor.when(IsVoidNode) def visit(self, node, scope): diff --git a/src/code_generator/cil_ast.py b/src/code_generator/cil_ast.py index 25fa5ac3c..c425510d9 100644 --- a/src/code_generator/cil_ast.py +++ b/src/code_generator/cil_ast.py @@ -74,6 +74,11 @@ class LessEqualNode(ArithExpressionNode): class EqualNode(ArithExpressionNode): pass +class NotNode(Node): + def __init__(self, dest, expr): + self.dest = dest + self.expr = expr + #Attr class GetAttrNode(InstructionNode): def __init__(self, dest, instance, attr, static_type): @@ -93,6 +98,7 @@ def __init__(self, instance, attr, value, static_type): #Arrays and Strings class GetIndexNode(InstructionNode): pass + class SetIndexNode(InstructionNode): pass @@ -190,11 +196,6 @@ def __init__(self, dest, value): self.local_dest = dest self.value = value -class ToStrNode(InstructionNode): - def __init__(self, dest, ivalue): - self.dest = dest - self.ivalue = ivalue - class ReadNode(InstructionNode): def __init__(self, dest): self.local_dest = dest diff --git a/src/code_generator/cil_visual_visitor.py b/src/code_generator/cil_visual_visitor.py index 02f43d80a..4472efd7b 100644 --- a/src/code_generator/cil_visual_visitor.py +++ b/src/code_generator/cil_visual_visitor.py @@ -74,6 +74,10 @@ def visit(self, node): @visitor.when(EqualNode) def visit(self, node): return f'{node.dest} = {node.left} = {node.right}' + + @visitor.when(NotNode) + def visit(self, node): + return f'{node.dest} = NOT {node.expr}' #Attr @visitor.when(GetAttrNode) def visit(self, node): @@ -137,7 +141,7 @@ def visit(self, node): def visit(self, node): return f'{node.dest} = SUBSTRING {node.word} {node.begin} {node.end}' - @visitor.when(ToStrNode) + @visitor.when(StrNode) def visit(self, node): return f'{node.dest} = STR {node.ivalue}' diff --git a/src/utils/ast.py b/src/utils/ast.py index 916613d54..7242ec412 100644 --- a/src/utils/ast.py +++ b/src/utils/ast.py @@ -1,3 +1,6 @@ +from ast import arg + + class Node(): def __init__(self): self.line = 0 @@ -60,6 +63,11 @@ def __init__(self, idx, args, obj=None, typex=None): self.object = obj self.type = typex +class MemberCallNode(ExpressionNode): + def __init__(self, idx, args): + super().__init__() + self.id = idx + self.args = args class IfNode(ExpressionNode): def __init__(self, condition, then_expr, else_expr): From 2b42c6598021204bb28c3938bac58c9a50d8036e Mon Sep 17 00:00:00 2001 From: livi98 Date: Sat, 12 Feb 2022 22:46:59 +0100 Subject: [PATCH 086/194] BaseCILToMIPSVisitor first ideas --- src/code_generator/BaseCILToMIPSVisitor.py | 243 +++++++++++++++++++++ src/code_generator/BaseCoolToCilVisitor.py | 58 ++++- src/code_generator/COOLToCILVisitor.py | 9 +- 3 files changed, 306 insertions(+), 4 deletions(-) create mode 100644 src/code_generator/BaseCILToMIPSVisitor.py diff --git a/src/code_generator/BaseCILToMIPSVisitor.py b/src/code_generator/BaseCILToMIPSVisitor.py new file mode 100644 index 000000000..2978fec31 --- /dev/null +++ b/src/code_generator/BaseCILToMIPSVisitor.py @@ -0,0 +1,243 @@ +from cil_ast import * + +class BaseCILToMIPSVisitor: + def __init__(self, inherit_graph): + self.code: list = ['.text', '.globl main', 'main:'] + self.initialize_data_code() + self.symbol_table = SymbolTable() + self.reg_desc = RegisterDescriptor() + self.addr_desc = AddressDescriptor() + + self.obj_table: ObjTable = ObjTable(self.dispatch_table) + self.initialize_methods() + self.load_abort_messages() + self.var_address = {'self': AddrType.REF} + + self.loop_idx = 0 + self.first_defined = {'strcopier': True} + self.inherit_graph = inherit_graph + self.space_idx = 0 + + def initialize_methods(self): + self.methods = [] + for entry in self.obj_table: + entry: ObjTabEntry + self.methods.extend(entry.dispatch_table_entry) + + def initialize_data_code(self): + self.data_code = ['.data'] + + def initialize_runtime_errors(self): + self.code.append('# Raise exception method') + self.code.append('.raise:') + self.code.append('li $v0, 4') + self.code.append('syscall') + self.code.append('li $v0, 17') + self.code.append('li $a0, 1') + self.code.append('syscall\n') + self.data_code.append('zero_error: .asciiz \"Division by zero error\n\"') + self.data_code.append('case_void_error: .asciiz \"Case on void error\n\"') + self.data_code.append('dispatch_error: .asciiz \"Dispatch on void error\n\"' ) + self.data_code.append('case_error: .asciiz \"Case statement without a matching branch error\n\"' ) + self.data_code.append('index_error: .asciiz \"Substring out of range error\n\"') + self.data_code.append('heap_error: .asciiz \"Heap overflow error\n\"') + + + def get_basic_blocks(self, instructions): + leaders = self.find_leaders(instructions) + blocks = [instructions[leaders[i-1]:leaders[i]] for i in range(1, len(leaders))] + return blocks + + + def find_leaders(self, instructions): + leaders = {0, len(instructions)} + for i, inst in enumerate(instructions): + if isinstance(inst, GoToNode) or isinstance(inst, IfGoToNode) or isinstance(inst, ReturnNode) \ + or isinstance(inst, CallNode) or isinstance(inst, VCallNode): + leaders.add(i+1) + elif isinstance(inst, LabelNode) or isinstance(inst, FunctionNode): + leaders.add(i) + return sorted(list(leaders)) + + def is_variable(self, expr): + return isinstance(expr, str) + + def is_int(self, expr): + return isinstance(expr, int) + + def get_reg(self, inst): + if self.is_variable(inst.in1): + in1_reg = self.get_reg_var(inst.in1) + if self.is_variable(inst.in2): + in2_reg = self.get_reg_var(inst.in2) + + nu_entry = self.next_use[inst.index] + if nu_entry.in1islive and nu_entry.in1nextuse < inst.index: + self.update_register(inst.out, in1_reg) + return + if nu_entry.in2islive and nu_entry.in2nextuse < inst.index: + self.update_register(inst.out, in2_reg) + return + if self.is_variable(inst.out): + self.get_reg_var(inst.out) + + + def get_reg_var(self, var): + curr_inst = self.inst + register = self.addr_desc.get_var_reg(var) + if register is not None: + return register + + var_st = self.symbol_table.lookup(var) + register = self.reg_desc.find_empty_reg() + if register is not None: + self.update_register(var, register) + self.load_var_code(var) + return register + + next_use = self.next_use[curr_inst.index] + score = self.initialize_score() + for inst in self.block[1:]: + inst: InstructionNode + if self.is_variable(inst.in1) and inst.in1 not in [curr_inst.in1, curr_inst.in2, curr_inst.out] and next_use.in1islive: + self._update_score(score, inst.in1) + if self.is_variable(inst.in2) and inst.in2 not in [curr_inst.in1, curr_inst.in2, curr_inst.out] and next_use.in2islive: + self._update_score(score, inst.in2) + if self.is_variable(inst.out) and inst.out not in [curr_inst.in1, curr_inst.in2, curr_inst.out] and next_use.outislive: + self._update_score(score, inst.out) + + register = min(score, key=lambda x: score[x]) + + self.update_register(var, register) + self.load_var_code(var) + return register + + def initialize_score(self): + score = {} + for reg in self.reg_desc.registers: + score[reg] = 0 + try: + reg = self.addr_desc.get_var_reg(self.inst.in1) + if reg: + score[reg] = 999 + except: pass + try: + reg = self.addr_desc.get_var_reg(self.inst.in2) + if reg: + score[reg] = 999 + except: pass + try: + reg = self.addr_desc.get_var_reg(self.inst.out) + if reg: + score[reg] = 999 + except: pass + return score + + def _update_score(self, score, var): + reg = self.addr_desc.get_var_reg(var) + if reg is None: + return + try: + score[reg] += 1 + except: + score[reg] = 1 + + def update_register(self, var, register): + content = self.reg_desc.get_content(register) + if content is not None: + self.save_var_code(content) + self.addr_desc.set_var_reg(content, None) + self.reg_desc.insert_register(register, var) + self.addr_desc.set_var_reg(var, register) + + def save_var_code(self, var): + memory, register, _= self.addr_desc.get_var_storage(var) + self.code.append(f"sw ${register}, -{memory}($fp)") + + def load_var_code(self, var): + memory, register, _ = self.addr_desc.get_var_storage(var) + self.code.append(f'lw ${register}, -{memory}($fp)') + + def load_used_reg(self, used_reg): + for reg in used_reg: + self.code.append('addiu $sp, $sp, 4') + self.code.append(f'lw ${reg}, ($sp)') + + def empty_registers(self, save=True): + registers = self.reg_desc.used_registers() + for reg, var in registers: + if save: + self.save_var_code(var) + self.addr_desc.set_var_reg(var, None) + self.reg_desc.insert_register(reg, None) + + def push_register(self, register): + self.code.append(f'sw ${register}, ($sp)') + self.code.append('addiu $sp, $sp, -4') + + def pop_register(self, register): + self.code.append('addiu $sp, $sp, 4') + self.code.append(f'lw ${register}, ($sp)') + + def save_to_register(self, expr): + if self.is_int(expr): + self.code.append(f'li $t9, {expr}') + return 't9' + elif self.is_variable(expr): + return self.addr_desc.get_var_reg(expr) + + def get_attr_offset(self, attr_name:str, type_name:str): + return self.obj_table[type_name].attr_offset(attr_name) + + def get_method_offset(self, type_name, method_name): + self.obj_table[type_name].method_offset(method_name) + + def save_meth_addr(self, func_nodes): + self.methods += [funct.name for funct in func_nodes] + words = 'methods: .word ' + ', '.join(map(lambda x: '0', self.methods)) + self.data_code.append(words) + self.code.append('# Save method directions in the methods array') + self.code.append('la $v0, methods') + for i, meth in enumerate(self.methods): + self.code.append(f'la $t9, {meth}') + self.code.append(f'sw $t9, {4*i}($v0)') + + def save_types_addr(self, type_nodes): + words = 'types: .word ' + ', '.join(map(lambda x: '0', self.inherit_graph)) + self.data_code.append(words) + self.code.append('# Save types directions in the types array') + self.code.append('la $t9, types') + self.types = [] + self.code.append('# Save space to locate the type info') + for i, (ntype, nparent) in enumerate(self.inherit_graph.items()): + self.code.append('# Allocating memory') + self.code.append('li $v0, 9') + self.code.append(f'li $a0, 12') + self.code.append('syscall') + self.types.append(ntype) + + self.code.append('# Filling table methods') + self.code.append(f'la $t8, type_{ntype}') + self.code.append(f'sw $t8, 0($v0)') + + self.code.append('# Copying direction to array') + self.code.append(f'sw $v0, {4*i}($t9)') + + self.code.append('# Table addr is now stored in t8') + self.code.append('move $t8, $v0') + self.code.append('# Creating the dispatch table') + self.create_dispatch_table(ntype) + self.code.append('sw $v0, 8($t8)') + + + self.code.append('# Copying parents') + for i, ntype in enumerate(self.types): + self.code.append(f'lw $v0, {4*i}($t9)') + nparent = self.inherit_graph[ntype] + if nparent is not None: + parent_idx = self.types.index(nparent) + + self.code.append(f'lw $t8, {4*parent_idx}($t9)') + else: + self.code.append('li $t8, 0') + self.code.append('sw $t8, 4($v0)') diff --git a/src/code_generator/BaseCoolToCilVisitor.py b/src/code_generator/BaseCoolToCilVisitor.py index 7633b1dae..cafc26d4d 100644 --- a/src/code_generator/BaseCoolToCilVisitor.py +++ b/src/code_generator/BaseCoolToCilVisitor.py @@ -49,6 +49,26 @@ def to_attribute_name(self, attr_name, type_name): def to_variable_name(self, var_name): return f'function_{var_name}' + + def define_method(self, name, param_names, param_types, return_type, pos): + if name in self.methods: + error_text = SemanticError.METHOD_ALREADY_DEFINED % name + raise SemanticError(error_text, *pos) + + method = self.methods[name] = Method(name, param_names, param_types, return_type) + return method + + def initialize_attr(self, constructor, attr, scope): + if attr.expr: + constructor.body.expr_list.append(AssignNode(attr.name, attr.expr)) + elif attr.type == 'Int': + constructor.body.expr_list.append(AssignNode(attr.name, ConstantNumNode(0))) + elif attr.type == 'Bool': + constructor.body.expr_list.append(AssignNode(attr.name, ConstantBoolNode(False))) + elif attr.type == 'String': + constructor.body.expr_list.append(AssignNode(attr.name, ConstantStrNode(""))) + else: + constructor.body.expr_list.append(AssignNode(attr.name, ConstantVoidNode(atrr.name))) def register_function(self, function_name): function_node = cil.FunctionNode(function_name, [], [], []) @@ -66,6 +86,18 @@ def register_data(self, value): self.dotdata.append(data_node) return data_node + def get_all_attributes(self, clean=True): + plain = OrderedDict() if self.parent is None else self.parent.get_all_attributes(False) + for attr in self.attributes.values(): + plain[attr.name] = (attr, self) + return plain.values() if clean else plain + + def get_all_methods(self, clean=True): + plain = OrderedDict() if self.parent is None else self.parent.get_all_methods(False) + for method in self.methods.values(): + plain[method.name] = (method, self) + return plain.values() if clean else plain + def define_built_in(self): #regular function f1_params = [cil.ParamNode("self", 'Object')] @@ -192,4 +224,28 @@ def get_type(self, name) -> Type: error_text = TypesError.TYPE_NOT_DEFINED % name raise TypesError(error_text) - \ No newline at end of file + def check_void(self, expr): + result = self.define_internal_local() + self.register_instruction(cil.TypeOfNode(expr, result)) + + void_expr = self.define_internal_local() + self.register_instruction(cil.LoadNode(void_expr, self.void_data)) + self.register_instruction(cil.EqualNode(result, result, void_expr)) + return result + + def sort_option_nodes_by_type(self, case_list): + return sorted(case_list, reverse=True, + key=lambda x: self.context.get_depth(x.typex)) + + #esto esta asociado al context que define la semantica + def get_depth(self, class_name): + typex = self.types[class_name] + if typex.parent is None: + return 0 + return 1 + self.get_depth(typex.parent.name) + + def _define_unary_node(self, node, scope, cil_node): + result = self.define_internal_local() + expr, typex = self.visit(node.expr, scope) + self.register_instruction(cil_node(result, expr)) + return result, typex \ No newline at end of file diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index 9ff5ffb51..fc5eed136 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -1,5 +1,5 @@ import cil_ast as cil -from BaseCoolToCilVisitor import * +from BaseCoolToCilVisitor import BaseCOOLToCILVisitor from utils import visitor from utils.ast import * @@ -52,7 +52,7 @@ def visit(self, node, scope): if cil_type_node.attributes: constructor.body.expr_list.append(SelfNode()) - for method, mtype in self.current_type.all_methods(): + for method, mtype in self.current_type.get_all_methods(): cil_type_node.methods.append((method.name, self.to_function_name(method.name, mtype.name))) func_declarations += [f for f in node.features if isinstance(f, FuncDeclarationNode)] @@ -61,6 +61,7 @@ def visit(self, node, scope): self.current_type = None +#this get_method is from semantic types @visitor.when(FuncDeclarationNode) def visit(self, node, scope): self.current_method = self.current_type.get_method(node.id) @@ -91,6 +92,7 @@ def visit(self, node, scope): self.register_instruction(cil.AllocateNode(node.type, local_value)) self.register_instruction(cil.SetAttrNode(self.vself.name, node.id, local_value, self.current_type)) +#this find_local, find_attribute is from scope @visitor.when(AssignNode) def visit(self, node, scope): var_info = scope.find_local(node.id) @@ -251,11 +253,12 @@ def visit(self, node, scope): self.register_instruction(end_label) return result, typex +#this find_local, find_attribute is from scope, this get_type is separate, nedd to do it well visitor.when(VarNode) def visit(self, node, scope): try: typex = scope.find_local(node.lex).type - name = self.to_var_name(node.lex) + name = self.to_variable_name(node.lex) return name, get_type(typex, self.current_type) except: var_info = scope.find_attribute(node.lex) From 733e8acd7e1244bf2e3a609fc0396c60dccd7a1d Mon Sep 17 00:00:00 2001 From: livi98 Date: Sun, 13 Feb 2022 02:04:13 +0100 Subject: [PATCH 087/194] BaseCILToMIPSVisitor and MIPSVisitor real first ideas --- src/code_generator/BaseCILToMIPSVisitor.py | 318 +++++++++------------ src/code_generator/BaseCoolToCilVisitor.py | 1 + src/code_generator/CILToMIPSVisitor.py | 99 +++++++ 3 files changed, 237 insertions(+), 181 deletions(-) create mode 100644 src/code_generator/CILToMIPSVisitor.py diff --git a/src/code_generator/BaseCILToMIPSVisitor.py b/src/code_generator/BaseCILToMIPSVisitor.py index 2978fec31..a64f2c352 100644 --- a/src/code_generator/BaseCILToMIPSVisitor.py +++ b/src/code_generator/BaseCILToMIPSVisitor.py @@ -10,7 +10,6 @@ def __init__(self, inherit_graph): self.obj_table: ObjTable = ObjTable(self.dispatch_table) self.initialize_methods() - self.load_abort_messages() self.var_address = {'self': AddrType.REF} self.loop_idx = 0 @@ -27,141 +26,84 @@ def initialize_methods(self): def initialize_data_code(self): self.data_code = ['.data'] - def initialize_runtime_errors(self): - self.code.append('# Raise exception method') - self.code.append('.raise:') - self.code.append('li $v0, 4') - self.code.append('syscall') - self.code.append('li $v0, 17') - self.code.append('li $a0, 1') - self.code.append('syscall\n') - self.data_code.append('zero_error: .asciiz \"Division by zero error\n\"') - self.data_code.append('case_void_error: .asciiz \"Case on void error\n\"') - self.data_code.append('dispatch_error: .asciiz \"Dispatch on void error\n\"' ) - self.data_code.append('case_error: .asciiz \"Case statement without a matching branch error\n\"' ) - self.data_code.append('index_error: .asciiz \"Substring out of range error\n\"') - self.data_code.append('heap_error: .asciiz \"Heap overflow error\n\"') - - def get_basic_blocks(self, instructions): leaders = self.find_leaders(instructions) blocks = [instructions[leaders[i-1]:leaders[i]] for i in range(1, len(leaders))] return blocks - - def find_leaders(self, instructions): - leaders = {0, len(instructions)} - for i, inst in enumerate(instructions): - if isinstance(inst, GoToNode) or isinstance(inst, IfGoToNode) or isinstance(inst, ReturnNode) \ - or isinstance(inst, CallNode) or isinstance(inst, VCallNode): - leaders.add(i+1) - elif isinstance(inst, LabelNode) or isinstance(inst, FunctionNode): - leaders.add(i) - return sorted(list(leaders)) - def is_variable(self, expr): return isinstance(expr, str) - def is_int(self, expr): - return isinstance(expr, int) + def construct_next_use(self, basic_blocks): + next_use = {} + for basic_block in basic_blocks: + for x in self.symbol_table: + self.symbol_table[x].is_live = False + self.symbol_table[x].next_use = None + + for inst in reversed(basic_block): + in1 = inst.in1 if self.is_variable(inst.in1) else None + in2 = inst.in2 if self.is_variable(inst.in2) else None + out = inst.out if self.is_variable(inst.out) else None + + in1nextuse = None + in2nextuse = None + outnextuse = None + in1islive = False + in2islive = False + outislive = False + + entry_in1 = self.symbol_table.lookup(in1) + entry_in2 = self.symbol_table.lookup(in2) + entry_out = self.symbol_table.lookup(out) + if out is not None: + if entry_out is not None: + outnextuse = entry_out.next_use + outislive = entry_out.is_live + else: + entry_out = SymbolTabEntry(out) + entry_out.next_use = None + entry_out.is_live = False + self.symbol_table.insert(entry_out) + if in1 is not None: + if entry_in1 is not None: + in1nextuse = entry_in1.next_use + in1islive = entry_in1.is_live + else: + entry_in1 = SymbolTabEntry(out) + entry_in1.next_use = inst.index + entry_in1.is_live = True + self.symbol_table.insert(entry_in1) + if in2 is not None: + if entry_in2 is not None: + in2nextuse = entry_in2.next_use + in2islive = entry_in2.is_live + else: + entry_in2 = SymbolTabEntry(in2) + entry_in2.next_use = inst.index + entry_in2.is_live = True + self.symbol_table.insert(entry_in2) + + n_entry = NextUseEntry(in1, in2, out, in1nextuse, in2nextuse, outnextuse, in1islive, in2islive, outislive) + next_use[inst.index] = n_entry + return next_use + def get_reg(self, inst): if self.is_variable(inst.in1): in1_reg = self.get_reg_var(inst.in1) if self.is_variable(inst.in2): - in2_reg = self.get_reg_var(inst.in2) - - nu_entry = self.next_use[inst.index] - if nu_entry.in1islive and nu_entry.in1nextuse < inst.index: - self.update_register(inst.out, in1_reg) - return - if nu_entry.in2islive and nu_entry.in2nextuse < inst.index: - self.update_register(inst.out, in2_reg) - return - if self.is_variable(inst.out): - self.get_reg_var(inst.out) - - - def get_reg_var(self, var): - curr_inst = self.inst - register = self.addr_desc.get_var_reg(var) - if register is not None: - return register - - var_st = self.symbol_table.lookup(var) - register = self.reg_desc.find_empty_reg() - if register is not None: - self.update_register(var, register) - self.load_var_code(var) - return register - - next_use = self.next_use[curr_inst.index] - score = self.initialize_score() - for inst in self.block[1:]: - inst: InstructionNode - if self.is_variable(inst.in1) and inst.in1 not in [curr_inst.in1, curr_inst.in2, curr_inst.out] and next_use.in1islive: - self._update_score(score, inst.in1) - if self.is_variable(inst.in2) and inst.in2 not in [curr_inst.in1, curr_inst.in2, curr_inst.out] and next_use.in2islive: - self._update_score(score, inst.in2) - if self.is_variable(inst.out) and inst.out not in [curr_inst.in1, curr_inst.in2, curr_inst.out] and next_use.outislive: - self._update_score(score, inst.out) - - register = min(score, key=lambda x: score[x]) - - self.update_register(var, register) - self.load_var_code(var) - return register - - def initialize_score(self): - score = {} - for reg in self.reg_desc.registers: - score[reg] = 0 - try: - reg = self.addr_desc.get_var_reg(self.inst.in1) - if reg: - score[reg] = 999 - except: pass - try: - reg = self.addr_desc.get_var_reg(self.inst.in2) - if reg: - score[reg] = 999 - except: pass - try: - reg = self.addr_desc.get_var_reg(self.inst.out) - if reg: - score[reg] = 999 - except: pass - return score - - def _update_score(self, score, var): - reg = self.addr_desc.get_var_reg(var) - if reg is None: - return - try: - score[reg] += 1 - except: - score[reg] = 1 - - def update_register(self, var, register): - content = self.reg_desc.get_content(register) - if content is not None: - self.save_var_code(content) - self.addr_desc.set_var_reg(content, None) - self.reg_desc.insert_register(register, var) - self.addr_desc.set_var_reg(var, register) + in2_reg = self.get_reg_var(inst.in2) + + def used_registers(self): + return [(k, v) for k, v in self.registers.items() if v is not None] def save_var_code(self, var): memory, register, _= self.addr_desc.get_var_storage(var) self.code.append(f"sw ${register}, -{memory}($fp)") - def load_var_code(self, var): - memory, register, _ = self.addr_desc.get_var_storage(var) - self.code.append(f'lw ${register}, -{memory}($fp)') - - def load_used_reg(self, used_reg): - for reg in used_reg: - self.code.append('addiu $sp, $sp, 4') - self.code.append(f'lw ${reg}, ($sp)') + def insert_register(self, register, content): + self.registers[register] = content def empty_registers(self, save=True): registers = self.reg_desc.used_registers() @@ -169,15 +111,20 @@ def empty_registers(self, save=True): if save: self.save_var_code(var) self.addr_desc.set_var_reg(var, None) - self.reg_desc.insert_register(reg, None) - - def push_register(self, register): - self.code.append(f'sw ${register}, ($sp)') - self.code.append('addiu $sp, $sp, -4') - - def pop_register(self, register): - self.code.append('addiu $sp, $sp, 4') - self.code.append(f'lw ${register}, ($sp)') + self.reg_desc.insert_register(reg, None) + + def get_type(self, xtype): + if xtype == 'Int': + return AddrType.INT + elif xtype == 'Bool': + return AddrType.BOOL + elif xtype == 'String': + return AddrType.STR + return AddrType.REF + + + def is_int(self, expr): + return isinstance(expr, int) def save_to_register(self, expr): if self.is_int(expr): @@ -186,58 +133,67 @@ def save_to_register(self, expr): elif self.is_variable(expr): return self.addr_desc.get_var_reg(expr) - def get_attr_offset(self, attr_name:str, type_name:str): - return self.obj_table[type_name].attr_offset(attr_name) - - def get_method_offset(self, type_name, method_name): - self.obj_table[type_name].method_offset(method_name) - - def save_meth_addr(self, func_nodes): - self.methods += [funct.name for funct in func_nodes] - words = 'methods: .word ' + ', '.join(map(lambda x: '0', self.methods)) - self.data_code.append(words) - self.code.append('# Save method directions in the methods array') - self.code.append('la $v0, methods') - for i, meth in enumerate(self.methods): - self.code.append(f'la $t9, {meth}') - self.code.append(f'sw $t9, {4*i}($v0)') - - def save_types_addr(self, type_nodes): - words = 'types: .word ' + ', '.join(map(lambda x: '0', self.inherit_graph)) - self.data_code.append(words) - self.code.append('# Save types directions in the types array') - self.code.append('la $t9, types') - self.types = [] - self.code.append('# Save space to locate the type info') - for i, (ntype, nparent) in enumerate(self.inherit_graph.items()): - self.code.append('# Allocating memory') - self.code.append('li $v0, 9') - self.code.append(f'li $a0, 12') - self.code.append('syscall') - self.types.append(ntype) - - self.code.append('# Filling table methods') - self.code.append(f'la $t8, type_{ntype}') - self.code.append(f'sw $t8, 0($v0)') - - self.code.append('# Copying direction to array') - self.code.append(f'sw $v0, {4*i}($t9)') + + + +class AddressDescriptor: + def __init__(self): + self.vars = {} + + def insert_var(self, name, address, register=None, stack=None): + if address is not None: + self.vars[name] = [4*address, register, stack] + else: + self.vars[name] = [address, register, stack] - self.code.append('# Table addr is now stored in t8') - self.code.append('move $t8, $v0') - self.code.append('# Creating the dispatch table') - self.create_dispatch_table(ntype) - self.code.append('sw $v0, 8($t8)') - - - self.code.append('# Copying parents') - for i, ntype in enumerate(self.types): - self.code.append(f'lw $v0, {4*i}($t9)') - nparent = self.inherit_graph[ntype] - if nparent is not None: - parent_idx = self.types.index(nparent) - - self.code.append(f'lw $t8, {4*parent_idx}($t9)') - else: - self.code.append('li $t8, 0') - self.code.append('sw $t8, 4($v0)') + def get_var_addr(self, name): + return self.vars[name][0] + + def set_var_addr(self, name, addr): + self.vars[name][0] = 4*addr + + def get_var_reg(self, var): + return self.vars[var][1] + + def set_var_reg(self, name, reg): + self.vars[name][1] = reg + + def get_var_stack(self, name): + return self.vars[name][2] + + def set_var_stack(self, name, stack_pos): + self.vars[name][1] = stack_pos + + def get_var_storage(self, name): + return self.vars[name] + + + + +class SymbolTabEntry: + def __init__(self, name, is_live=False, next_use=None): + self.name = name + self.is_live = is_live + self.next_use = next_use + +class SymbolTable: + def __init__(self, entries = None): + values = entries if entries is not None else [] + self.entries = {v.name: v for v in values} + + def lookup(self, entry_name: str) -> SymbolTabEntry: + if entry_name != None: + if entry_name in self.entries.keys(): + return self.entries[entry_name] + + def insert(self, entry): + self.entries[entry.name] = entry + + def insert_name(self, name): + self.entries[name] = SymbolTabEntry(name) + + def __getitem__(self, item): + return self.entries[item] + + def __iter__(self): + return iter(self.entries) \ No newline at end of file diff --git a/src/code_generator/BaseCoolToCilVisitor.py b/src/code_generator/BaseCoolToCilVisitor.py index cafc26d4d..ade12a65a 100644 --- a/src/code_generator/BaseCoolToCilVisitor.py +++ b/src/code_generator/BaseCoolToCilVisitor.py @@ -8,6 +8,7 @@ def __init__(self, context): self.current_method = None self.current_function = None self.context = context + self.inherit_graph = {} @property def params(self): diff --git a/src/code_generator/CILToMIPSVisitor.py b/src/code_generator/CILToMIPSVisitor.py new file mode 100644 index 000000000..17bd234af --- /dev/null +++ b/src/code_generator/CILToMIPSVisitor.py @@ -0,0 +1,99 @@ +from codegen.BaseCILToMIPSVisitor import * +from utils import visitor +import cil_ast as cil + +class COOLToCILVisitor(BaseCILToMIPSVisitor): + @visitor.on('node') + def visit(self, node): + pass + + @visitor.when(cil.ProgramNode) + def visit(self, node): + #.TYPE + for type_ in node.dottypes: + self.visit(type_) + self.save_meth_addr(node.dotcode) + self.data_code.append(f"type_Void: .asciiz \"Void\"") + self.save_types_addr(node.dottypes) + #.DATA + for data in node.dotdata: + self.visit(data) + #.CODE + for code in node.dotcode: + self.visit(code) + self.initialize_runtime_errors() + return self.data_code, self.code + + @visitor.when(cil.TypeNode) + def visit(self, node): + self.obj_table.add_entry(node.name, node.methods, node.attributes) + self.data_code.append(f"type_{node.name}: .asciiz \"{node.name}\"") + + @visitor.when(cil.DataNode) + def visit(self, node): + self.data_code.append(f"{node.name}: .asciiz \"{node.value}\"") + + @visitor.when(cil.FunctionNode) + def visit(self, node): + self.code.append('') + self.code.append(f'{node.name}:') + self.locals = 0 + self.code.append('# Gets the params from the stack') + self.code.append(f'move $fp, $sp') + n = len(node.params) + for i, param in enumerate(node.params, 1): + self.visit(param, i, n) + self.code.append('# Gets the frame pointer from the stack') + for i, var in enumerate(node.localvars, len(node.params)): + self.visit(var, i) + self.locals = len(node.params) + len(node.localvars) + blocks = self.get_basic_blocks(node.instructions) + self.next_use = self.construct_next_use(blocks) + for block in blocks: + self.block = block + for inst in block: + self.inst = inst + self.get_reg(inst) + self.visit(inst) + inst = block[-1] + if not (isinstance(inst, cil.GoToNode) or isinstance(inst, cil.IfGoToNode) or isinstance(inst, cil.ReturnNode) \ + or isinstance(inst, cil.CallNode) or isinstance(inst, cil.VCallNode)): + self.empty_registers() + +#this works with a address that I need to do like the Micro + @visitor.when(cil.ParamNode) + def visit(self, node, idx, length): + self.symbol_table.insert_name(node.name) + self.var_address[node.name] = self.get_type(node.type) + self.code.append(f'# Pops the register with the param value {node.name}') + self.code.append('addiu $fp, $fp, 4') + self.addr_desc.insert_var(node.name, length-idx) + + @visitor.when(cil.LocalNode) + def visit(self, node, idx): + self.symbol_table.insert_name(node.name) + self.addr_desc.insert_var(node.name, idx) + self.code.append(f'# Updates stack pointer pushing {node.name} to the stack') + self.code.append(f'addiu $sp, $sp, -4') + + @visitor.when(cil.AssignNode) + def visit(self, node): + rdest = self.addr_desc.get_var_reg(node.dest) + self.code.append(f'# Moving {node.source} to {node.dest}') + if self.is_variable(node.source): + rsrc = self.addr_desc.get_var_reg(node.source) + self.code.append(f'move ${rdest}, ${rsrc}') + self.var_address[node.dest] = self.var_address[node.source] + elif self.is_int(node.source): + self.code.append(f'li ${rdest}, {node.source}') + self.var_address[node.dest] = AddrType.INT + self.save_var_code(node.dest) + + @visitor.when(cil.NotNode) + def visit(self, node): + rdest = self.addr_desc.get_var_reg(node.dest) + rsrc = self.save_to_register(node.expr) + self.code.append(f'# {node.dest} <- ~{node.expr}') + self.code.append(f'not ${rdest}, ${rsrc}') + self.code.append(f'addi ${rdest}, ${rdest}, 1') + self.var_address[node.dest] = AddrType.INT \ No newline at end of file From 57209080a9ed048eacd953ec60320278b90069be Mon Sep 17 00:00:00 2001 From: livi98 Date: Sun, 13 Feb 2022 20:03:40 +0100 Subject: [PATCH 088/194] fixing so many errors on CILToMIPSVisitor and adding ArithNodes --- src/code_generator/CILToMIPSVisitor.py | 126 ++++++++++++++++++++++++- 1 file changed, 122 insertions(+), 4 deletions(-) diff --git a/src/code_generator/CILToMIPSVisitor.py b/src/code_generator/CILToMIPSVisitor.py index 17bd234af..014959d85 100644 --- a/src/code_generator/CILToMIPSVisitor.py +++ b/src/code_generator/CILToMIPSVisitor.py @@ -93,7 +93,125 @@ def visit(self, node): def visit(self, node): rdest = self.addr_desc.get_var_reg(node.dest) rsrc = self.save_to_register(node.expr) - self.code.append(f'# {node.dest} <- ~{node.expr}') - self.code.append(f'not ${rdest}, ${rsrc}') - self.code.append(f'addi ${rdest}, ${rdest}, 1') - self.var_address[node.dest] = AddrType.INT \ No newline at end of file + self.code.append(f'# {node.dest} <- not {node.expr}') + self.code.append(f'beqz ${rsrc}, false_{self.loop_idx}') + self.code.append(f'li ${rdest}, 0') + self.code.append(f'j end_{self.loop_idx}') + self.code.append(f'false_{self.loop_idx}:') + self.code.append(f'li ${rdest}, 1') + self.code.append(f'end_{self.loop_idx}:') + self.loop_idx += 1 + self.var_address[node.dest] = AddrType.BOOL + + @visitor.when(cil.PlusNode) + def visit(self, node): + rdest = self.addr_desc.get_var_reg(node.dest) + self.code.append(f'# {node.dest} <- {node.left} + {node.right}') + if self.is_variable(node.left): + rleft = self.addr_desc.get_var_reg(node.left) + if self.is_variable(node.right): + rright = self.addr_desc.get_var_reg(node.right) + self.code.append(f"add ${rdest}, ${rleft}, ${rright}") + elif self.is_int(node.right): + self.code.append(f"addi ${rdest}, ${rleft}, {node.right}") + elif self.is_int(node.left): + if self.is_int(node.right): + self.code.append(f"li ${rdest}, {node.left + node.right}") + elif self.is_variable(node.right): + rright = self.addr_desc.get_var_reg(node.right) + self.code.append(f"addi ${rdest}, ${rright}, {node.left}") + self.var_address[node.dest] = AddrType.INT + + @visitor.when(cil.MinusNode) + def visit(self, node): + rdest = self.addr_desc.get_var_reg(node.dest) + self.code.append(f'# {node.dest} <- {node.left} - {node.right}') + if self.is_variable(node.left): + rleft = self.addr_desc.get_var_reg(node.left) + if self.is_variable(node.right): + rright = self.addr_desc.get_var_reg(node.right) + self.code.append(f"sub ${rdest}, ${rleft}, ${rright}") + elif self.is_int(node.right): + self.code.append(f"addi ${rdest}, ${rleft}, -{node.right}") + elif self.is_int(node.left): + if self.is_int(node.right): + self.code.append(f"li ${rdest}, {node.left-node.right}") + elif self.is_variable(node.right): + rright = self.addr_desc.get_var_reg(node.right) + self.code.append(f"sub $t9, $zero, {rright}") + self.code.append(f"addi ${rdest}, {node.left}, $t9") + self.var_address[node.dest] = AddrType.INT + + @visitor.when(cil.StarNode) + def visit(self, node): + self.code.append(f'# {node.dest} <- {node.left} * {node.right}') + self._code_to_mult_div(node,'mult', func_op=lambda x, y: x*y) + + @visitor.when(cil.DivNode) + def visit(self, node): + self.code.append(f'# {node.dest} <- {node.left} / {node.right}') + self._code_to_mult_div(node,'div', func_op=lambda x, y: int(x / y)) + + def _code_to_mult_div(self, node, op, func_op): + rdest = self.addr_desc.get_var_reg(node.dest) + if self.is_int(node.left) and self.is_int(node.right): + try: + self.code.append(f"li ${rdest}, {func_op(node.left, node.right)}") + except ZeroDivisionError: + self.code.append('la $a0, zero_error') + self.code.append('j .raise') + else: + if self.is_variable(node.left): + rleft = self.addr_desc.get_var_reg(node.left) + if self.is_variable(node.right): + rright = self.addr_desc.get_var_reg(node.right) + elif self.is_int(node.right): + self.code.append(f"li $t9, {node.right}") + rright = 't9' + elif self.is_int(node.left): + rright = self.addr_desc.get_var_reg(node.right) + self.code.append(f"li $t9, {node.left}") + rleft = 't9' + if op == 'div': + self.code.append('la $a0, zero_error') + self.code.append(f'beqz ${rright}, .raise') + self.code.append(f"{op} ${rleft}, ${rright}") + self.code.append(f"mflo ${rdest}") + self.var_address[node.dest] = AddrType.INT + + @visitor.when(cil.LessNode) + def visit(self, node): + self.code.append(f'# {node.dest} <- {node.left} < {node.right}') + self._code_to_comp(node, 'slt', lambda x, y: x < y) + + @visitor.when(cil.LessEqNode) + def visit(self, node): + self.code.append(f'# {node.dest} <- {node.left} <= {node.right}') + self._code_to_comp(node, 'sle', lambda x, y: x <= y) + + @visitor.when(cil.EqualNode) + def visit(self, node): + self.code.append(f'# {node.dest} <- {node.left} = {node.right}') + if self.is_variable(node.left) and self.is_variable(node.right) and self.var_address[node.left] == AddrType.STR and self.var_address[node.right] == AddrType.STR: + self.compare_strings(node) + else: + self._code_to_comp(node, 'seq', lambda x, y: x == y) + + def _code_to_comp(self, node, op, func_op): + rdest = self.addr_desc.get_var_reg(node.dest) + if self.is_variable(node.left): + rleft = self.addr_desc.get_var_reg(node.left) + if self.is_variable(node.right): + rright = self.addr_desc.get_var_reg(node.right) + self.code.append(f"{op} ${rdest}, ${rleft}, ${rright}") + elif self.is_int(node.right): + self.code.append(f"li $t9, {node.right}") + self.code.append(f"{op} ${rdest}, ${rleft}, $t9") + elif self.is_int(node.left): + if self.is_int(node.right): + self.code.append(f"li ${rdest}, {int(func_op(node.left, node.right))}") + elif self.is_variable(node.right): + rright = self.addr_desc.get_var_reg(node.right) + self.code.append(f"li $t9, {node.left}") + self.code.append(f"{op} ${rdest}, $t9, ${rright}") + self.var_address[node.dest] = AddrType.BOOL \ No newline at end of file From 83b3961a3070edb8ec9f05432eadbb03a70c79a7 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 13 Feb 2022 20:26:07 -0500 Subject: [PATCH 089/194] type collector done --- src/semantic/visitors/typeBuilder.py | 0 src/semantic/visitors/typeChecker.py | 0 src/semantic/visitors/typeCollector.py | 41 +++++++++++++++++++++++++ src/semantic/visitors/type_collector.py | 25 --------------- 4 files changed, 41 insertions(+), 25 deletions(-) create mode 100644 src/semantic/visitors/typeBuilder.py create mode 100644 src/semantic/visitors/typeChecker.py create mode 100644 src/semantic/visitors/typeCollector.py delete mode 100644 src/semantic/visitors/type_collector.py diff --git a/src/semantic/visitors/typeBuilder.py b/src/semantic/visitors/typeBuilder.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/semantic/visitors/typeChecker.py b/src/semantic/visitors/typeChecker.py new file mode 100644 index 000000000..e69de29bb diff --git a/src/semantic/visitors/typeCollector.py b/src/semantic/visitors/typeCollector.py new file mode 100644 index 000000000..578ba5045 --- /dev/null +++ b/src/semantic/visitors/typeCollector.py @@ -0,0 +1,41 @@ +from utils.errors import SemanticError +from semantic.tools import Context +from utils import visitor +from semantic.types import * +from utils.ast import * + + +class TypeCollector(object): + def __init__(self, errors=[]): + self.context = None + self.errors = errors + + @visitor.on('node') + def visit(self, node): + pass + + @visitor.when(ProgramNode) + def visit(self, node: ProgramNode): + self.context = Context() + self.context.types['String'] = StringType() + self.context.types['Int'] = IntType() + self.context.types['Object'] = ObjectType() + self.context.types['Bool'] = BoolType() + self.context.types['SELF_TYPE'] = SelfType() + self.context.types['IO'] = IOType() + # self.context.create_type('SELF_TYPE', (0, 0)) + for dec in node.declarations: + self.visit(dec) + + @visitor.when(ClassDeclarationNode) + def visit(self, node: ClassDeclarationNode): + if node.id in ['String', 'Int', 'Object', 'Bool', 'SELF_TYPE', 'IO']: + error = SemanticError.REDEFINITION_ERROR % node.id + self.errors.append(SemanticError(error, *node.pos)) + try: + self.context.create_type(node.id, node.pos) + except SemanticError as e: + self.errors.append(e) + # añade un como padre Object si este no tiene + if not node.parent: + node.parent = 'Object' diff --git a/src/semantic/visitors/type_collector.py b/src/semantic/visitors/type_collector.py deleted file mode 100644 index 90e806da6..000000000 --- a/src/semantic/visitors/type_collector.py +++ /dev/null @@ -1,25 +0,0 @@ -from utils import visitor -from utils.ast import ProgramNode, ClassDeclarationNode -from semantic. - - - - - -class TypeCollector(object): - def __init__(self, errors = []): - self.context = None - self.errors = errors - - @visitor.on('node') - def visit(self, node): - pass - - - @visitor.when(ProgramNode) - def visit(self, node): - self.context = Context() - - @visitor.when(ClassDeclarationNode) - def visit(self, node): - pass From 4a25f19935066319a45964c3c3be59ac6db05dbf Mon Sep 17 00:00:00 2001 From: root Date: Mon, 14 Feb 2022 13:09:39 -0500 Subject: [PATCH 090/194] typeBuilder done --- src/semantic/visitors/typeBuilder.py | 102 +++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/src/semantic/visitors/typeBuilder.py b/src/semantic/visitors/typeBuilder.py index e69de29bb..c5ecb648b 100644 --- a/src/semantic/visitors/typeBuilder.py +++ b/src/semantic/visitors/typeBuilder.py @@ -0,0 +1,102 @@ +from utils.errors import SemanticError, AttributesError, TypesError, NamesError +from semantic.types import Type, VoidType, ErrorType, Attribute, Method +from semantic.tools import Context +from utils import visitor, is_basic_type +from utils.ast import * + +class TypeBuilder: + def __init__(self, context:Context, errors=[]): + self.context:Context = context + self.current_type:Type = None + self.errors:list = errors + + @visitor.on('node') + def visit(self, node): + pass + + @visitor.when(ProgramNode) + def visit(self, node:ProgramNode): + for dec in node.declarations: + self.visit(dec) + + @visitor.when(ClassDeclarationNode) + def visit(self, node:ClassDeclarationNode): + try: + self.current_type = self.context.get_type(node.id, node.pos) + except SemanticError as e: + self.current_type = ErrorType() + self.errors.append(e) + + + if node.parent is not None: + if node.parent in ['Int', 'Bool', 'String']: + error_text = SemanticError.INHERIT_ERROR % (node.id, node.parent) + self.errors.append(SemanticError(error_text, *node.parent_pos)) + try: + parent = self.context.get_type(node.parent, node.parent_pos) + except SemanticError: + error_text = TypesError.INHERIT_UNDEFINED % (node.id, node.parent) + self.errors.append(TypesError(error_text, *node.parent_pos)) + parent = None + try: + current = parent + while current is not None: + if current.name == self.current_type.name: + error_text = SemanticError.CIRCULAR_DEPENDENCY %(self.current_type.name, self.current_type.name) + raise SemanticError(error_text, *node.pos) + current = current.parent + except SemanticError as e: + parent = ErrorType() + self.errors.append(e) + self.current_type.set_parent(parent) + + for feature in node.features: + self.visit(feature) + + + @visitor.when(FuncDeclarationNode) + def visit(self, node:FuncDeclarationNode): + args_names = [] + args_types = [] + for name, type_ in node.params: + if name in args_names: + error_text = SemanticError.PARAMETER_MULTY_DEFINED % name + self.errors.append(SemanticError(error_text, *type_.pos)) + args_names.append(name) + + try: + arg_type = self.context.get_type(type_.value, type_.pos) + except SemanticError: + error_text = TypesError.PARAMETER_UNDEFINED % (type_.value, type_.value) + self.errors.append(TypesError(error_text, *type_.pos)) + arg_type = ErrorType() + args_types.append(arg_type) + + try: + return_type = self.context.get_type(node.type, node.type_pos) + except SemanticError as e: + error_text = TypesError.RETURN_TYPE_UNDEFINED % (node.type, node.id) + self.errors.append(TypesError(error_text, *node.type_pos)) + return_type = ErrorType(node.type_pos) + + try: + self.current_type.define_method(node.id, args_names, args_types, return_type, node.pos) + except SemanticError as e: + self.errors.append(e) + + @visitor.when(AttrDeclarationNode) + def visit(self, node:AttrDeclarationNode): + try: + attr_type = self.context.get_type(node.type, node.pos) + except SemanticError as e: + error_text = TypesError.ATTR_TYPE_UNDEFINED %(node.type, node.id) + attr_type = ErrorType(node.type_pos) + self.errors.append(TypesError(error_text, *node.type_pos)) + + if node.id == 'self': + self.errors.append(SemanticError(SemanticError.SELF_ATTR, *node.pos)) + + try: + self.current_type.define_attribute(node.id, attr_type, node.pos) + except SemanticError as e: + self.errors.append(e) \ No newline at end of file From 407c848fd757fbc6f6e0ab08831179bfe0b7ce0e Mon Sep 17 00:00:00 2001 From: livi98 Date: Mon, 14 Feb 2022 19:48:30 +0100 Subject: [PATCH 091/194] fixing errors on BaseCILToMIPSVisitor and adding AttrNodes --- src/code_generator/BaseCILToMIPSVisitor.py | 117 +++++++++++++++++++++ src/code_generator/CILToMIPSVisitor.py | 56 +++++++--- 2 files changed, 157 insertions(+), 16 deletions(-) diff --git a/src/code_generator/BaseCILToMIPSVisitor.py b/src/code_generator/BaseCILToMIPSVisitor.py index a64f2c352..e0a674e3e 100644 --- a/src/code_generator/BaseCILToMIPSVisitor.py +++ b/src/code_generator/BaseCILToMIPSVisitor.py @@ -1,4 +1,6 @@ from cil_ast import * +from typing import List, Dict +from enum import Enum class BaseCILToMIPSVisitor: def __init__(self, inherit_graph): @@ -134,6 +136,121 @@ def save_to_register(self, expr): return self.addr_desc.get_var_reg(expr) +class AddrType(Enum): + REF = 1, + STR = 2, + BOOL = 3, + INT = 4, + VOID = 5 + + +class NextUseEntry: + """For each line : for all three variables involved their next use and is live information""" + def __init__(self, in1, in2, out, in1nextuse, in2nextuse, outnextuse, in1islive, in2islive, outislive): + self.in1 = in1 + self.in2 = in2 + self.out = out + self.in1nextuse = in1nextuse + self.in2nextuse = in2nextuse + self.outnextuse = outnextuse + self.in1islive = in1islive + self.in2islive = in2islive + self.outislive = outislive + + +class ObjTabEntry: + def __init__(self, name, methods, attrs): + self.class_tag: str = name + self.size: int = 3 + len(attrs) + self.dispatch_table_size = len(methods) + self.dispatch_table_entry = methods + self.attrs = attrs + + @property + def class_tag_offset(self): + return 0 + + @property + def size_offset(self): + return 1 + + @property + def dispatch_ptr_offset(self): + return 2 + + def attr_offset(self, attr): + return self.attrs.index(attr) + 3 + + def method_offset(self, meth): + "Method offset in dispatch table" + return self.dispatch_table_entry.index(meth) + + +class ObjTable: + def __init__(self, dispatch_table): + self.objects: Dict[str, ObjTabEntry] = {} #self.initialize_built_in() + self.dispatch_table = dispatch_table + + def initialize_built_in(self): + object_methods = [ + 'function_abort_Object', + 'function_type_name_Object', + 'function_copy_Object'] + io_methods = [ + 'function_out_string_IO', + 'function_out_int_IO', + 'function_in_string_IO', + 'function_in_int_IO'] + str_methods = [ + 'function_length_String', + 'function_concat_String', + 'function_substr_String' ] + return { + 'Int': ObjTabEntry('Int', [], []), + 'Bool': ObjTabEntry('Bool', [], []), + 'IO': ObjTabEntry('IO', io_methods, []), + 'String': ObjTabEntry('String', str_methods, []), + 'Object': ObjTabEntry('Object', object_methods, []) + } + + def add_entry(self, name, methods, attrs): + methods = [y for x, y in methods] + attrs = [x for x, y in attrs] + self.objects[name] = ObjTabEntry(name, methods, attrs) + self.dispatch_table.add_class(name, methods) + + def size_of_entry(self, name): + return self.objects[name].size + + def __getitem__(self, item) -> ObjTabEntry: + return self.objects[item] + + def __iter__(self): + return iter(self.objects.values()) + +class RegisterDescriptor: + def __init__(self): + registers = ['t0', 't1', 't2', 't3', 't4', 't5', 't6', 't7', 'a1', 'a2', 'a3', \ + 's0', 's1', 's2', 's3', 's4', 's5', 's6', 's7', 'v1'] + self.registers = {reg: None for reg in registers} + + def insert_register(self, register:str, content:str): + self.registers[register] = content + + def get_content(self, register: str): + return self.registers[register] + + def find_empty_reg(self): + for k, v in self.registers.items(): + if v is None: + return k + + def used_registers(self): + return [(k, v) for k, v in self.registers.items() if v is not None] + + def empty_registers(self): + for k in self.registers: + self.registers[k] = None class AddressDescriptor: diff --git a/src/code_generator/CILToMIPSVisitor.py b/src/code_generator/CILToMIPSVisitor.py index 014959d85..2a9fb87aa 100644 --- a/src/code_generator/CILToMIPSVisitor.py +++ b/src/code_generator/CILToMIPSVisitor.py @@ -89,20 +89,6 @@ def visit(self, node): self.var_address[node.dest] = AddrType.INT self.save_var_code(node.dest) - @visitor.when(cil.NotNode) - def visit(self, node): - rdest = self.addr_desc.get_var_reg(node.dest) - rsrc = self.save_to_register(node.expr) - self.code.append(f'# {node.dest} <- not {node.expr}') - self.code.append(f'beqz ${rsrc}, false_{self.loop_idx}') - self.code.append(f'li ${rdest}, 0') - self.code.append(f'j end_{self.loop_idx}') - self.code.append(f'false_{self.loop_idx}:') - self.code.append(f'li ${rdest}, 1') - self.code.append(f'end_{self.loop_idx}:') - self.loop_idx += 1 - self.var_address[node.dest] = AddrType.BOOL - @visitor.when(cil.PlusNode) def visit(self, node): rdest = self.addr_desc.get_var_reg(node.dest) @@ -184,7 +170,7 @@ def visit(self, node): self.code.append(f'# {node.dest} <- {node.left} < {node.right}') self._code_to_comp(node, 'slt', lambda x, y: x < y) - @visitor.when(cil.LessEqNode) + @visitor.when(cil.LessEqualNode) def visit(self, node): self.code.append(f'# {node.dest} <- {node.left} <= {node.right}') self._code_to_comp(node, 'sle', lambda x, y: x <= y) @@ -214,4 +200,42 @@ def _code_to_comp(self, node, op, func_op): rright = self.addr_desc.get_var_reg(node.right) self.code.append(f"li $t9, {node.left}") self.code.append(f"{op} ${rdest}, $t9, ${rright}") - self.var_address[node.dest] = AddrType.BOOL \ No newline at end of file + self.var_address[node.dest] = AddrType.BOOL + + @visitor.when(cil.NotNode) + def visit(self, node): + rdest = self.addr_desc.get_var_reg(node.dest) + rsrc = self.save_to_register(node.expr) + self.code.append(f'# {node.dest} <- not {node.expr}') + self.code.append(f'beqz ${rsrc}, false_{self.loop_idx}') + self.code.append(f'li ${rdest}, 0') + self.code.append(f'j end_{self.loop_idx}') + self.code.append(f'false_{self.loop_idx}:') + self.code.append(f'li ${rdest}, 1') + self.code.append(f'end_{self.loop_idx}:') + self.loop_idx += 1 + self.var_address[node.dest] = AddrType.BOOL + + @visitor.when(cil.GetAttrNode) + def visit(self, node): + self.code.append(f'# {node.dest} <- GET {node.obj} . {node.attr}') + rdest = self.addr_desc.get_var_reg(node.dest) + self.var_address[node.dest] = self.get_type(node.attr_type) + rsrc = self.addr_desc.get_var_reg(node.obj) + attr_offset = 4*self.get_attr_offset(node.attr, node.type_name) + self.code.append(f'lw ${rdest}, {attr_offset}(${rsrc})') + + @visitor.when(cil.SetAttrNode) + def visit(self, node): + self.code.append(f'# {node.obj} . {node.attr} <- SET {node.value}') + rdest = self.addr_desc.get_var_reg(node.obj) + attr_offset = 4*self.get_attr_offset(node.attr, node.type_name) + if self.is_variable(node.value): + rsrc = self.addr_desc.get_var_reg(node.value) + elif self.is_int(node.value): + self.code.append(f'li $t9, {node.value}') + rsrc = 't9' + elif self.is_void(node.value): + self.code.append(f'la $t9, type_{VOID_NAME}') + rsrc = 't9' + self.code.append(f'sw ${rsrc}, {attr_offset}(${rdest})') \ No newline at end of file From f30fe7aa3821a2b0c70fe6199d3acc411e38886f Mon Sep 17 00:00:00 2001 From: livi98 Date: Mon, 14 Feb 2022 22:50:03 +0100 Subject: [PATCH 092/194] fixing errors on BaseCILToMIPSVisitor 2.0 --- src/code_generator/BaseCILToMIPSVisitor.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/code_generator/BaseCILToMIPSVisitor.py b/src/code_generator/BaseCILToMIPSVisitor.py index e0a674e3e..6c65cb913 100644 --- a/src/code_generator/BaseCILToMIPSVisitor.py +++ b/src/code_generator/BaseCILToMIPSVisitor.py @@ -145,7 +145,6 @@ class AddrType(Enum): class NextUseEntry: - """For each line : for all three variables involved their next use and is live information""" def __init__(self, in1, in2, out, in1nextuse, in2nextuse, outnextuse, in1islive, in2islive, outislive): self.in1 = in1 self.in2 = in2 @@ -182,13 +181,12 @@ def attr_offset(self, attr): return self.attrs.index(attr) + 3 def method_offset(self, meth): - "Method offset in dispatch table" return self.dispatch_table_entry.index(meth) class ObjTable: def __init__(self, dispatch_table): - self.objects: Dict[str, ObjTabEntry] = {} #self.initialize_built_in() + self.objects: Dict[str, ObjTabEntry] = {} self.dispatch_table = dispatch_table def initialize_built_in(self): From d453174fd71ff5107febb4115ea6ced3449a0446 Mon Sep 17 00:00:00 2001 From: livi98 Date: Tue, 15 Feb 2022 02:03:57 +0100 Subject: [PATCH 093/194] fixing errors 3.0 --- .vscode/settings.json | 5 +- src/code_generator/BaseCoolToCilVisitor.py | 1 + src/code_generator/CILToMIPSVisitor.py | 268 ++++++++++++++++++--- 3 files changed, 243 insertions(+), 31 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 82a851134..2e378c23b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,7 @@ { "python.linting.pylintEnabled": true, - "python.linting.enabled": true + "python.linting.enabled": true, + "python.analysis.extraPaths": [ + "./src/code_generator" + ] } \ No newline at end of file diff --git a/src/code_generator/BaseCoolToCilVisitor.py b/src/code_generator/BaseCoolToCilVisitor.py index ade12a65a..813323330 100644 --- a/src/code_generator/BaseCoolToCilVisitor.py +++ b/src/code_generator/BaseCoolToCilVisitor.py @@ -7,6 +7,7 @@ def __init__(self, context): self.current_type = None self.current_method = None self.current_function = None + self.constructors = [] self.context = context self.inherit_graph = {} diff --git a/src/code_generator/CILToMIPSVisitor.py b/src/code_generator/CILToMIPSVisitor.py index 2a9fb87aa..84b4ab473 100644 --- a/src/code_generator/CILToMIPSVisitor.py +++ b/src/code_generator/CILToMIPSVisitor.py @@ -1,8 +1,8 @@ -from codegen.BaseCILToMIPSVisitor import * +from BaseCILToMIPSVisitor import * from utils import visitor import cil_ast as cil -class COOLToCILVisitor(BaseCILToMIPSVisitor): +class CILToMIPSVisitor(BaseCILToMIPSVisitor): @visitor.on('node') def visit(self, node): pass @@ -60,7 +60,6 @@ def visit(self, node): or isinstance(inst, cil.CallNode) or isinstance(inst, cil.VCallNode)): self.empty_registers() -#this works with a address that I need to do like the Micro @visitor.when(cil.ParamNode) def visit(self, node, idx, length): self.symbol_table.insert_name(node.name) @@ -131,18 +130,32 @@ def visit(self, node): @visitor.when(cil.StarNode) def visit(self, node): self.code.append(f'# {node.dest} <- {node.left} * {node.right}') - self._code_to_mult_div(node,'mult', func_op=lambda x, y: x*y) - + rdest = self.addr_desc.get_var_reg(node.dest) + if self.is_int(node.left) and self.is_int(node.right): + self.code.append(f"li ${rdest}, {node.left*node.right}") + else: + if self.is_variable(node.left): + rleft = self.addr_desc.get_var_reg(node.left) + if self.is_variable(node.right): + rright = self.addr_desc.get_var_reg(node.right) + elif self.is_int(node.right): + self.code.append(f"li $t9, {node.right}") + rright = 't9' + elif self.is_int(node.left): + rright = self.addr_desc.get_var_reg(node.right) + self.code.append(f"li $t9, {node.left}") + rleft = 't9' + self.code.append(f"mult ${rleft}, ${rright}") + self.code.append(f"mflo ${rdest}") + self.var_address[node.dest] = AddrType.INT + @visitor.when(cil.DivNode) def visit(self, node): self.code.append(f'# {node.dest} <- {node.left} / {node.right}') - self._code_to_mult_div(node,'div', func_op=lambda x, y: int(x / y)) - - def _code_to_mult_div(self, node, op, func_op): rdest = self.addr_desc.get_var_reg(node.dest) if self.is_int(node.left) and self.is_int(node.right): try: - self.code.append(f"li ${rdest}, {func_op(node.left, node.right)}") + self.code.append(f"li ${rdest}, {node.left/node.right}") except ZeroDivisionError: self.code.append('la $a0, zero_error') self.code.append('j .raise') @@ -158,50 +171,78 @@ def _code_to_mult_div(self, node, op, func_op): rright = self.addr_desc.get_var_reg(node.right) self.code.append(f"li $t9, {node.left}") rleft = 't9' - if op == 'div': - self.code.append('la $a0, zero_error') - self.code.append(f'beqz ${rright}, .raise') - self.code.append(f"{op} ${rleft}, ${rright}") + self.code.append('la $a0, zero_error') + self.code.append(f'beqz ${rright}, .raise') + self.code.append(f"div ${rleft}, ${rright}") self.code.append(f"mflo ${rdest}") self.var_address[node.dest] = AddrType.INT @visitor.when(cil.LessNode) def visit(self, node): self.code.append(f'# {node.dest} <- {node.left} < {node.right}') - self._code_to_comp(node, 'slt', lambda x, y: x < y) + rdest = self.addr_desc.get_var_reg(node.dest) + if self.is_variable(node.left): + rleft = self.addr_desc.get_var_reg(node.left) + if self.is_variable(node.right): + rright = self.addr_desc.get_var_reg(node.right) + self.code.append(f"slt ${rdest}, ${rleft}, ${rright}") + elif self.is_int(node.right): + self.code.append(f"li $t9, {node.right}") + self.code.append(f"slt ${rdest}, ${rleft}, $t9") + elif self.is_int(node.left): + if self.is_int(node.right): + self.code.append(f"li ${rdest}, {int(node.left < node.right)}") + elif self.is_variable(node.right): + rright = self.addr_desc.get_var_reg(node.right) + self.code.append(f"li $t9, {node.left}") + self.code.append(f"slt ${rdest}, $t9, ${rright}") + self.var_address[node.dest] = AddrType.BOOL @visitor.when(cil.LessEqualNode) def visit(self, node): self.code.append(f'# {node.dest} <- {node.left} <= {node.right}') - self._code_to_comp(node, 'sle', lambda x, y: x <= y) - - @visitor.when(cil.EqualNode) - def visit(self, node): - self.code.append(f'# {node.dest} <- {node.left} = {node.right}') - if self.is_variable(node.left) and self.is_variable(node.right) and self.var_address[node.left] == AddrType.STR and self.var_address[node.right] == AddrType.STR: - self.compare_strings(node) - else: - self._code_to_comp(node, 'seq', lambda x, y: x == y) - - def _code_to_comp(self, node, op, func_op): rdest = self.addr_desc.get_var_reg(node.dest) if self.is_variable(node.left): rleft = self.addr_desc.get_var_reg(node.left) if self.is_variable(node.right): rright = self.addr_desc.get_var_reg(node.right) - self.code.append(f"{op} ${rdest}, ${rleft}, ${rright}") + self.code.append(f"sle ${rdest}, ${rleft}, ${rright}") elif self.is_int(node.right): self.code.append(f"li $t9, {node.right}") - self.code.append(f"{op} ${rdest}, ${rleft}, $t9") + self.code.append(f"sle ${rdest}, ${rleft}, $t9") elif self.is_int(node.left): if self.is_int(node.right): - self.code.append(f"li ${rdest}, {int(func_op(node.left, node.right))}") + self.code.append(f"li ${rdest}, {int(node.left <= node.right)}") elif self.is_variable(node.right): rright = self.addr_desc.get_var_reg(node.right) self.code.append(f"li $t9, {node.left}") - self.code.append(f"{op} ${rdest}, $t9, ${rright}") + self.code.append(f"sle ${rdest}, $t9, ${rright}") self.var_address[node.dest] = AddrType.BOOL + @visitor.when(cil.EqualNode) + def visit(self, node): + self.code.append(f'# {node.dest} <- {node.left} = {node.right}') + if self.is_variable(node.left) and self.is_variable(node.right) and self.var_address[node.left] == AddrType.STR and self.var_address[node.right] == AddrType.STR: + self.compare_strings(node) + else: + rdest = self.addr_desc.get_var_reg(node.dest) + if self.is_variable(node.left): + rleft = self.addr_desc.get_var_reg(node.left) + if self.is_variable(node.right): + rright = self.addr_desc.get_var_reg(node.right) + self.code.append(f"seq ${rdest}, ${rleft}, ${rright}") + elif self.is_int(node.right): + self.code.append(f"li $t9, {node.right}") + self.code.append(f"seq ${rdest}, ${rleft}, $t9") + elif self.is_int(node.left): + if self.is_int(node.right): + self.code.append(f"li ${rdest}, {int(node.left == node.right)}") + elif self.is_variable(node.right): + rright = self.addr_desc.get_var_reg(node.right) + self.code.append(f"li $t9, {node.left}") + self.code.append(f"seq ${rdest}, $t9, ${rright}") + self.var_address[node.dest] = AddrType.BOOL + @visitor.when(cil.NotNode) def visit(self, node): rdest = self.addr_desc.get_var_reg(node.dest) @@ -238,4 +279,171 @@ def visit(self, node): elif self.is_void(node.value): self.code.append(f'la $t9, type_{VOID_NAME}') rsrc = 't9' - self.code.append(f'sw ${rsrc}, {attr_offset}(${rdest})') \ No newline at end of file + self.code.append(f'sw ${rsrc}, {attr_offset}(${rdest})') + + @visitor.when(cil.AllocateNode) + def visit(self, node): + rdest = self.addr_desc.get_var_reg(node.dest) + self.var_address[node.dest] = AddrType.REF + self.code.append('# Syscall to allocate memory of the object entry in heap') + self.code.append('li $v0, 9') + size = 4*self.obj_table.size_of_entry(node.type) + self.code.append(f'li $a0, {size}') + self.code.append('syscall') + addrs_stack = self.addr_desc.get_var_addr(node.dest) + self.code.append('# Loads the name of the variable and saves the name like the first field') + self.code.append(f'la $t9, type_{node.type}') + self.code.append(f'sw $t9, 0($v0)') + self.code.append(f'# Saves the size of the node') + self.code.append(f'li $t9, {size}') + self.code.append(f'sw $t9, 4($v0)') + self.code.append(f'move ${rdest}, $v0') + idx = self.types.index(node.type) + self.code.append('# Adding Type Info addr') + self.code.append('la $t8, types') + self.code.append(f'lw $v0, {4*idx}($t8)') + self.code.append(f'sw $v0, 8(${rdest})') + + @visitor.when(cil.TypeOfNode) + def visit(self, node): + rdest = self.addr_desc.get_var_reg(node.dest) + self.code.append(f'# {node.dest} <- Type of {node.obj}') + if self.is_variable(node.obj): + rsrc = self.addr_desc.get_var_reg(node.obj) + if self.var_address[node.obj] == AddrType.REF: + self.code.append(f'lw ${rdest}, 0(${rsrc})') + elif self.var_address[node.obj] == AddrType.STR: + self.code.append(f'la ${rdest}, type_String') + elif self.var_address[node.obj] == AddrType.INT: + self.code.append(f'la ${rdest}, type_Int') + elif self.var_address[node.obj] == AddrType.BOOL: + self.code.append(f'la ${rdest}, type_Bool') + elif self.is_int(node.obj): + self.code.append(f'la ${rdest}, type_Int') + self.var_address[node.dest] = AddrType.STR + + @visitor.when(cil.LabelNode) + def visit(self, node): + self.code.append(f'{node.label}:') + + @visitor.when(cil.GoToNode) + def visit(self, node): + self.empty_registers() + self.code.append(f'j {node.label}') + + @visitor.when(cil.IfGoToNode) + def visit(self, node): + reg = self.save_to_register(node.cond) + self.code.append(f'# If {node.cond} goto {node.label}') + self.empty_registers() + self.code.append(f'bnez ${reg}, {node.label}') + + @visitor.when(cil.CallNode) + def visit(self, node): + function = self.dispatch_table.find_full_name(node.type, node.function) + self.code.append(f'# Static Dispatch of the method {node.function}') + self.push_register('fp') + self.push_register('ra') + self.code.append('# Push the arguments to the stack') + for arg in reversed(node.args): + self.visit(arg) + self.code.append('# Empty all used registers and saves them to memory') + self.empty_registers() + self.code.append('# This function will consume the arguments') + self.code.append(f'jal {function}') + self.code.append('# Pop ra register of return function of the stack') + self.pop_register('ra') + self.code.append('# Pop fp register from the stack') + self.pop_register('fp') + if node.dest is not None: + self.get_reg_var(node.dest) + rdest = self.addr_desc.get_var_reg(node.dest) + self.code.append('# saves the return value') + self.code.append(f'move ${rdest}, $v0') + self.var_address[node.dest] = self.get_type(node.return_type) + + @visitor.when(cil.VCallNode) + def visit(self, node): + self.code.append('# Find the actual name in the dispatch table') + reg = self.addr_desc.get_var_reg(node.obj) + self.code.append('# Gets in a0 the actual direction of the dispatch table') + self.code.append(f'lw $t9, 8(${reg})') + self.code.append('lw $a0, 8($t9)') + function = self.dispatch_table.find_full_name(node.type, node.method) + index = 4*self.dispatch_table.get_offset(node.type, function) + 4 + self.code.append(f'# Saves in t8 the direction of {function}') + self.code.append(f'lw $t8, {index}($a0)') + self.push_register('fp') + self.push_register('ra') + self.code.append('# Push the arguments to the stack') + for arg in reversed(node.args): + self.visit(arg) + self.code.append('# Empty all used registers and saves them to memory') + self.empty_registers() + self.code.append('# This function will consume the arguments') + self.code.append(f'jal $t8') + self.code.append('# Pop ra register of return function of the stack') + self.pop_register('ra') + self.code.append('# Pop fp register from the stack') + self.pop_register('fp') + if node.dest is not None: + self.get_reg_var(node.dest) + rdest = self.addr_desc.get_var_reg(node.dest) + self.code.append('# saves the return value') + self.code.append(f'move ${rdest}, $v0') + self.var_address[node.dest] = self.get_type(node.return_type) + + @visitor.when(cil.ArgNode) + def visit(self, node): + self.code.append('# The rest of the arguments are push into the stack') + if self.is_variable(node.dest): + self.get_reg_var(node.dest) + reg = self.addr_desc.get_var_reg(node.dest) + self.code.append(f'sw ${reg}, ($sp)') + elif self.is_int(node.dest): + self.code.append(f'li $t9, {node.dest}') + self.code.append(f'sw $t9, ($sp)') + self.code.append('addiu $sp, $sp, -4') + + @visitor.when(cil.ReturnNode) + def visit(self, node): + if self.is_variable(node.value): + rdest = self.addr_desc.get_var_reg(node.value) + self.code.append(f'move $v0, ${rdest}') + elif self.is_int(node.value): + self.code.append(f'li $v0, {node.value}') + self.code.append('# Empty all used registers and saves them to memory') + self.empty_registers() + self.code.append('# Removing all locals from stack') + self.code.append(f'addiu $sp, $sp, {self.locals*4}') + self.code.append(f'jr $ra') + self.code.append('') + + @visitor.when(cil.LoadNode) + def visit(self, node): + rdest = self.addr_desc.get_var_reg(node.dest) + self.code.append(f'# Saves in {node.dest} {node.msg}') + self.var_address[node.dest] = AddrType.STR + self.code.append(f'la ${rdest}, {node.msg}') + + @visitor.when(cil.LengthNode) + def visit(self, node): + rdest = self.addr_desc.get_var_reg(node.dest) + reg = self.addr_desc.get_var_reg(node.arg) + loop = f'loop_{self.loop_idx}' + end = f'end_{self.loop_idx}' + self.code.append(f'move $t8, ${reg}') + self.code.append('# Determining the length of a string') + self.code.append(f'{loop}:') + self.code.append(f'lb $t9, 0($t8)') + self.code.append(f'beq $t9, $zero, {end}') + self.code.append(f'addi $t8, $t8, 1') + self.code.append(f'j {loop}') + self.code.append(f'{end}:') + self.code.append(f'sub ${rdest}, $t8, ${reg}') + self.loop_idx += 1 + + + + + From befc5c445bff381554fd24aaf1c4106b5e2150c9 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 15 Feb 2022 00:39:58 -0500 Subject: [PATCH 094/194] finished the typeChecker --- src/semantic/visitors/typeChecker.py | 378 +++++++++++++++++++++++++++ 1 file changed, 378 insertions(+) diff --git a/src/semantic/visitors/typeChecker.py b/src/semantic/visitors/typeChecker.py index e69de29bb..9791780b9 100644 --- a/src/semantic/visitors/typeChecker.py +++ b/src/semantic/visitors/typeChecker.py @@ -0,0 +1,378 @@ +from utils import visitor +from semantic.tools import * +from semantic.types import * +from utils.ast import * +from utils.errors import SemanticError, AttributesError, TypesError, NamesError +from utils import get_type, get_common_basetype + + +class TypeChecker: + def __init__(self, context: Context, errors=[]): + self.context: Context = context + self.current_type: Type = None + self.current_method: Method = None + self.errors = errors + self.current_index = None # Lleva el índice del scope en el que se está + + @visitor.on('node') + def visit(self, node, scope): + pass + + @visitor.when(ProgramNode) + def visit(self, node: ProgramNode, scope: Scope): + for declaration, new_scope in zip(node.declarations, scope.children): + self.visit(declaration, new_scope) + + def _get_type(self, ntype: str, pos): + try: + return self.context.get_type(ntype, pos) + except SemanticError as e: + self.errors.append(e) + return ErrorType() + + def _get_method(self, typex: Type, name: str, pos) -> Method: + try: + return typex.get_method(name, pos) + except SemanticError as e: + if type(typex) != ErrorType and type(typex) != AutoType: + error_text = AttributesError.DISPATCH_UNDEFINED % name + self.errors.append(AttributesError(error_text, *pos)) + return MethodError(name, [], [], ErrorType()) + + @visitor.when(ClassDeclarationNode) + def visit(self, node: ClassDeclarationNode, scope: Scope): + self.current_type = self.context.get_type(node.id, node.pos) + + fd = [feat for feat in node.features if isinstance( + feat, FuncDeclarationNode)] + + for feat in node.features: + if isinstance(feat, AttrDeclarationNode): + self.visit(feat, scope) + + for feat, child_scope in zip(fd, scope.functions.values()): + self.visit(feat, child_scope) + + @visitor.when(AttrDeclarationNode) + def visit(self, node: AttrDeclarationNode, scope: Scope): + attr = self.current_type.get_attribute(node.id, node.pos) + vartype = get_type(attr.type, self.current_type) + + self.current_index = attr.index + typex = self.visit(node.expr, scope) + self.current_index = None + + if not typex.conforms_to(vartype): + error_text = TypesError.ATTR_TYPE_ERROR % ( + typex.name, attr.name, vartype.name) + self.errors.append(TypesError(error_text, *node.pos)) + return ErrorType() + return typex + + @visitor.when(FuncDeclarationNode) + def visit(self, node: FuncDeclarationNode, scope: Scope): + parent = self.current_type.parent + + self.current_method = method = self.current_type.get_method( + node.id, node.pos) + if parent is not None: + try: + old_meth = parent.get_method(node.id, node.pos) + if old_meth.return_type.name != method.return_type.name: + error_text = SemanticError.WRONG_SIGNATURE_RETURN % ( + node.id, method.return_type.name, old_meth.return_type.name) + self.errors.append(SemanticError( + error_text, *node.type_pos)) + if len(method.param_names) != len(old_meth.param_names): + error_text = SemanticError.WRONG_NUMBER_PARAM % node.id + self.errors.append(SemanticError(error_text, *node.pos)) + for (name, param), type1, type2 in zip(node.params, method.param_types, old_meth.param_types): + if type1.name != type2.name: + error_text = SemanticError.WRONG_SIGNATURE_PARAMETER % ( + name, type1.name, type2.name) + self.errors.append( + SemanticError(error_text, *param.pos)) + except SemanticError: + pass + + result = self.visit(node.body, scope) + + return_type = get_type(method.return_type, self.current_type) + + if not result.conforms_to(return_type): + error_text = TypesError.RETURN_TYPE_ERROR % ( + result.name, return_type.name) + self.errors.append(TypesError(error_text, *node.type_pos)) + + @visitor.when(VarDeclarationNode) + def visit(self, node: VarDeclarationNode, scope: Scope): + + vtype = self._get_type(node.type, node.type_pos) + vtype = get_type(vtype, self.current_type) + + if node.expr != None: + typex = self.visit(node.expr, scope) + if not typex.conforms_to(vtype): + error_text = TypesError.UNCONFORMS_TYPE % ( + typex.name, node.id, vtype.name) + self.errors.append(TypesError(error_text, *node.type_pos)) + return typex + return vtype + + @visitor.when(AssignNode) + def visit(self, node: AssignNode, scope: Scope): + vinfo = self.find_variable(scope, node.id) + vtype = get_type(vinfo.type, self.current_type) + + typex = self.visit(node.expr, scope) + + if not typex.conforms_to(vtype): + error_text = TypesError.UNCONFORMS_TYPE % ( + typex.name, node.id, vtype.name) + self.errors.append(TypesError(error_text, *node.pos)) + return typex + + def _check_args(self, meth: Method, scope: Scope, args, pos): + arg_types = [self.visit(arg, scope) for arg in args] + + if len(arg_types) > len(meth.param_types): + error_text = SemanticError.ARGUMENT_ERROR % meth.name + self.errors.append(SemanticError(error_text, *pos)) + elif len(arg_types) < len(meth.param_types): + for arg, arg_info in zip(meth.param_names[len(arg_types):], args[len(arg_types):]): + error_text = SemanticError.ARGUMENT_ERROR % (meth.name) + self.errors.append(SemanticError(error_text, *arg_info.pos)) + + for atype, ptype, param_name in zip(arg_types, meth.param_types, meth.param_names): + if not atype.conforms_to(ptype): + error_text = TypesError.INCOSISTENT_ARG_TYPE % ( + meth.name, atype.name, param_name, ptype.name) + self.errors.append(TypesError(error_text, *pos)) + + @visitor.when(CallNode) + def visit(self, node: CallNode, scope: Scope): + stype = self.visit(node.obj, scope) + + meth = self._get_method(stype, node.id, node.pos) + if not isinstance(meth, MethodError): + self._check_args(meth, scope, node.args, node.pos) + + return get_type(meth.return_type, stype) + + @visitor.when(BaseCallNode) + def visit(self, node: BaseCallNode, scope: Scope): + obj = self.visit(node.obj, scope) + typex = self._get_type(node.type, node.type_pos) + + if not obj.conforms_to(typex): + error_text = TypesError.INCOMPATIBLE_TYPES_DISPATCH % ( + typex.name, obj.name) + self.errors.append(TypesError(error_text, *node.type_pos)) + return ErrorType() + + meth = self._get_method(typex, node.id, node.pos) + if not isinstance(meth, MethodError): + self._check_args(meth, scope, node.args, node.pos) + + return get_type(meth.return_type, typex) + + @visitor.when(StaticCallNode) + def visit(self, node: StaticCallNode, scope: Scope): + typex = self.current_type + + meth = self._get_method(typex, node.id, node.pos) + if not isinstance(meth, MethodError): + self._check_args(meth, scope, node.args, node.pos) + + return get_type(meth.return_type, typex) + + @visitor.when(ConstantNumNode) + def visit(self, node: ConstantNumNode, scope: Scope): + return IntType(node.pos) + + @visitor.when(ConstantBoolNode) + def visit(self, node: ConstantBoolNode, scope: Scope): + return BoolType(node.pos) + + @visitor.when(ConstantStrNode) + def visit(self, node: ConstantStrNode, scope: Scope): + return StringType(node.pos) + + @visitor.when(ConstantVoidNode) + def visit(self, node: ConstantVoidNode, scope: Scope): + return VoidType(node.pos) + + def find_variable(self, scope, lex): + var_info = scope.find_local(lex) + if var_info is None: + var_info = scope.find_attribute(lex) + if lex in self.current_type.attributes and var_info is None: + return VariableInfo(lex, VoidType()) + return var_info + + @visitor.when(VariableNode) + def visit(self, node: VariableNode, scope: Scope): + typex = self.find_variable(scope, node.lex).type + return get_type(typex, self.current_type) + + @visitor.when(InstantiateNode) + def visit(self, node: InstantiateNode, scope: Scope): + try: + type_ = self.context.get_type(node.lex, node.pos) + except SemanticError: + type_ = ErrorType() + error_text = TypesError.NEW_UNDEFINED_CLASS % node.lex + self.errors.append(TypesError(error_text, *node.pos)) + + return get_type(type_, self.current_type) + + @visitor.when(WhileNode) + def visit(self, node: WhileNode, scope: Scope): + cond = self.visit(node.cond, scope) + + if cond.name != 'Bool': + self.errors.append(TypesError( + TypesError.LOOP_CONDITION_ERROR, *node.pos)) + + self.visit(node.expr, scope) + return ObjectType() + + @visitor.when(IsVoidNode) + def visit(self, node: IsVoidNode, scope: Scope): + self.visit(node.expr, scope) + return BoolType() + + @visitor.when(ConditionalNode) + def visit(self, node: ConditionalNode, scope: Scope): + cond = self.visit(node.cond, scope) + + if cond.name != 'Bool': + error_text = TypesError.PREDICATE_ERROR % ('if', 'Bool') + self.errors.append(TypesError(error_text, *node.pos)) + + true_type = self.visit(node.stm, scope) + false_type = self.visit(node.else_stm, scope) + + return get_common_basetype([false_type, true_type]) + # if true_type.conforms_to(false_type): + # return false_type + # elif false_type.conforms_to(true_type): + # return true_type + # else: + # error_text = TypesError.INCOMPATIBLE_TYPES % (false_type.name, true_type.name) + # self.errors.append(TypesError(error_text, *node.pos)) + # return ErrorType() + + @visitor.when(BlockNode) + def visit(self, node: BlockNode, scope: Scope): + value = None + for exp in node.expr_list: + value = self.visit(exp, scope) + return value + + @visitor.when(LetNode) + def visit(self, node: LetNode, scope: Scope): + child_scope = scope.expr_dict[node] + for init in node.init_list: + self.visit(init, child_scope) + return self.visit(node.expr, child_scope) + + @visitor.when(CaseNode) + def visit(self, node: CaseNode, scope: Scope): + type_expr = self.visit(node.expr, scope) + + new_scope = scope.expr_dict[node] + types = [] + var_types = [] + for case, c_scope in zip(node.case_list, new_scope.children): + case: OptionNode + t, vt = self.visit(case, c_scope) + types.append(t) + if case.typex in var_types: + error_text = SemanticError.DUPLICATE_CASE_BRANCH % case.typex + self.errors.append(SemanticError(error_text, *case.type_pos)) + var_types.append(case.typex) + + # for t in var_types: + # if not type_expr.conforms_to(t): + # error_text = TypesError.INCOMPATIBLE_TYPES % (t.name, type_expr.name) + # self.errors.append(TypesError(error_text, *node.pos)) + # return ErrorType() + + return get_common_basetype(types) + + @visitor.when(OptionNode) + def visit(self, node: OptionNode, scope: Scope): + var_info = self.find_variable(scope, node.id) + typex = self.visit(node.expr, scope) + return typex, var_info.type + + def binary_operation(self, node, scope, operator): + ltype = self.visit(node.left, scope) + rtype = self.visit(node.right, scope) + int_type = IntType() + if ltype != int_type or rtype != int_type: + error_text = TypesError.BOPERATION_NOT_DEFINED % ( + ltype.name, operator, rtype.name) + self.errors.append(TypesError(error_text, *node.pos)) + return ErrorType() + if operator == '<' or operator == '<=': + return BoolType() + return int_type + + @visitor.when(PlusNode) + def visit(self, node: PlusNode, scope: Scope): + return self.binary_operation(node, scope, '+') + + @visitor.when(MinusNode) + def visit(self, node: MinusNode, scope: Scope): + return self.binary_operation(node, scope, '-') + + @visitor.when(StarNode) + def visit(self, node: StarNode, scope: Scope): + return self.binary_operation(node, scope, '*') + + @visitor.when(DivNode) + def visit(self, node: DivNode, scope: Scope): + return self.binary_operation(node, scope, '/') + + @visitor.when(LessEqNode) + def visit(self, node: DivNode, scope: Scope): + return self.binary_operation(node, scope, '<=') + + @visitor.when(LessNode) + def visit(self, node: DivNode, scope: Scope): + return self.binary_operation(node, scope, '<') + + @visitor.when(EqualNode) + def visit(self, node: EqualNode, scope: Scope): + ltype = self.visit(node.left, scope) + rtype = self.visit(node.right, scope) + if (ltype == IntType() or rtype == IntType() or ltype == StringType() or rtype == StringType() or ltype == BoolType() or rtype == BoolType()) and ltype != rtype: + error_text = TypesError.COMPARISON_ERROR + self.errors.append(TypesError(error_text, *node.pos)) + return ErrorType() + else: + return BoolType() + + @visitor.when(NotNode) + def visit(self, node: NotNode, scope: Scope): + ltype = self.visit(node.expr, scope) + typex = BoolType() + if ltype != typex: + error_text = TypesError.UOPERATION_NOT_DEFINED % ( + 'not', ltype.name, typex.name) + self.errors.append(TypesError(error_text, *node.pos)) + return ErrorType() + return typex + + @visitor.when(BinaryNotNode) + def visit(self, node: BinaryNotNode, scope: Scope): + ltype = self.visit(node.expr, scope) + int_type = IntType() + if ltype != int_type: + error_text = TypesError.UOPERATION_NOT_DEFINED % ( + '~', ltype.name, int_type.name) + self.errors.append(TypesError(error_text, *node.pos)) + return ErrorType() + return int_type From 197891426b8716ca9eef47e07a6879bb6c6f129c Mon Sep 17 00:00:00 2001 From: livi98 Date: Wed, 16 Feb 2022 02:30:55 +0100 Subject: [PATCH 095/194] fixing errors 4.0 + adding Substring and Concat Nodes on CILToMIPSVisitor --- src/code_generator/BaseCoolToCilVisitor.py | 16 ++- src/code_generator/CILToMIPSVisitor.py | 109 +++++++++++++++++++++ 2 files changed, 123 insertions(+), 2 deletions(-) diff --git a/src/code_generator/BaseCoolToCilVisitor.py b/src/code_generator/BaseCoolToCilVisitor.py index 813323330..a89540faa 100644 --- a/src/code_generator/BaseCoolToCilVisitor.py +++ b/src/code_generator/BaseCoolToCilVisitor.py @@ -239,7 +239,7 @@ def sort_option_nodes_by_type(self, case_list): return sorted(case_list, reverse=True, key=lambda x: self.context.get_depth(x.typex)) - #esto esta asociado al context que define la semantica + #esto esta asociado al context que define la semantica igual que el hierarchy_types def get_depth(self, class_name): typex = self.types[class_name] if typex.parent is None: @@ -250,4 +250,16 @@ def _define_unary_node(self, node, scope, cil_node): result = self.define_internal_local() expr, typex = self.visit(node.expr, scope) self.register_instruction(cil_node(result, expr)) - return result, typex \ No newline at end of file + return result, typex + + def load_var_if_occupied(self, var): + if var is not None: + self.code.append(f'# Restore {var}') + self.load_var_code(var) + + def save_reg_if_occupied(self, reg): + var = self.reg_desc.get_content(reg) + if var is not None: + self.code.append(f'# Saving {reg} to memory') + self.save_var_code(var) + return var \ No newline at end of file diff --git a/src/code_generator/CILToMIPSVisitor.py b/src/code_generator/CILToMIPSVisitor.py index 84b4ab473..c4c63a378 100644 --- a/src/code_generator/CILToMIPSVisitor.py +++ b/src/code_generator/CILToMIPSVisitor.py @@ -443,7 +443,116 @@ def visit(self, node): self.code.append(f'sub ${rdest}, $t8, ${reg}') self.loop_idx += 1 + @visitor.when(cil.ConcatNode) + def visit(self, node): + rdest = self.addr_desc.get_var_reg(node.dest) + self.code.append('# Allocating memory for buffer') + self.code.append('li $a0, 356') + self.code.append('li $v0, 9') + self.code.append('syscall') + self.code.append(f'move ${rdest}, $v0') + rsrc1 = self.addr_desc.get_var_reg(node.arg1) + if node.arg2 is not None: + rsrc2 = self.addr_desc.get_var_reg(node.arg2) + self.code.append('# Copy the first string to dest') + var = self.save_reg_if_occupied('a1') + self.code.append(f'move $a0, ${rsrc1}') + self.code.append(f'move $a1, ${rdest}') + self.push_register('ra') + self.code.append('jal strcopier') + if node.arg2 is not None: + self.code.append('# Concat second string on buffers result') + self.code.append(f'move $a0, ${rsrc2}') + self.code.append(f'move $a1, $v0') + self.code.append('jal strcopier') + self.code.append('sb $0, 0($v0)') + self.pop_register('ra') + self.code.append(f'j finish_{self.loop_idx}') + if self.first_defined['strcopier']: + self.code.append('# Definition of strcopier') + self.code.append('strcopier:') + self.code.append('# In a0 is source and in a1 is dest') + self.code.append(f'loop_{self.loop_idx}:') + self.code.append('lb $t8, ($a0)') + self.code.append(f'beq $t8, $zero, end_{self.loop_idx}') + self.code.append('addiu $a0, $a0, 1') + self.code.append('sb $t8, ($a1)') + self.code.append('addiu $a1, $a1, 1') + self.code.append(f'b loop_{self.loop_idx}') + self.code.append(f'end_{self.loop_idx}:') + self.code.append('move $v0, $a1') + self.code.append('jr $ra') + self.first_defined['strcopier'] = False + self.code.append(f'finish_{self.loop_idx}:') + self.load_var_if_occupied(var) + self.loop_idx += 1 + @visitor.when(cil.SubstringNode) + def visit(self, node): + rdest = self.addr_desc.get_var_reg(node.dest) + self.code.append('# Allocating memory for buffer') + self.code.append('li $a0, 356') + self.code.append('li $v0, 9') + self.code.append('syscall') + self.code.append(f'move ${rdest}, $v0') + if self.is_variable(node.begin): + rstart = self.addr_desc.get_var_reg(node.begin) + elif self.is_int(node.begin): + rstart = 't8' + self.code.append(f'li $t8, {node.begin}') + if self.is_variable(node.end): + rend = self.addr_desc.get_var_reg(node.end) + var = None + elif self.is_int(node.end): + var = self.save_reg_if_occupied('a3') + rend = 'a3' + self.code.append(f'li $a3, {node.end}') + self.get_reg_var(node.word) + rself = self.addr_desc.get_var_reg(node.word) + self.code.append("# Getting substring") + start = f'start_{self.loop_idx}' + error = f'error_{self.loop_idx}' + end_lp = f'end_len_{self.loop_idx}' + self.code.append('# Move to the begining') + self.code.append('li $v0, 0') + self.code.append(f'move $t8, ${rself}') + self.code.append(f'{start}:') + self.code.append('lb $t9, 0($t8)') + self.code.append(f'beqz $t9, {error}') + self.code.append('addi $v0, 1') + self.code.append(f'bgt $v0, ${rstart}, {end_lp}') + self.code.append(f'addi $t8, 1') + self.code.append(f'j {start}') + self.code.append(f'{end_lp}:') + self.code.append('# Saving dest') + self.code.append(f'move $v0, ${rdest}') + loop = f'loop_{self.loop_idx}' + end = f'end_{self.loop_idx}' + self.code.append(f'{loop}:') + self.code.append(f'sub $t9, $v0, ${rdest}') + self.code.append(f'beq $t9, ${rend}, {end}') + self.code.append(f'lb $t9, 0($t8)') + self.code.append(f'beqz $t9, {error}') + self.code.append(f'sb $t9, 0($v0)') + self.code.append('addi $t8, $t8, 1') + self.code.append(f'addi $v0, $v0, 1') + self.code.append(f'j {loop}') + self.code.append(f'{error}:') + self.code.append('la $a0, index_error') + self.code.append('li $v0, 4') + self.code.append(f'move $a0, ${rself}') + self.code.append('syscall') + self.code.append('li $v0, 1') + self.code.append(f'move $a0, ${rstart}') + self.code.append('syscall') + self.code.append('li $v0, 1') + self.code.append(f'move $a0, ${rend}') + self.code.append('syscall') + self.code.append('j .raise') + self.code.append(f'{end}:') + self.code.append('sb $0, 0($v0)') + self.load_var_if_occupied(var) + self.loop_idx += 1 From 214adfd5a9d6c4bc06c3c84be5197a232ff895b0 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 18 Feb 2022 12:47:29 -0500 Subject: [PATCH 096/194] before merge jki --- .pylintrc | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .pylintrc diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 000000000..92721c71d --- /dev/null +++ b/.pylintrc @@ -0,0 +1,3 @@ +[MASTER] +disable=C0114, # missing-module-docstring +disable=C0115, \ No newline at end of file From 9ce0abce3b6a54584b58f7b0cdf33abba6ffcd3d Mon Sep 17 00:00:00 2001 From: cwjki Date: Fri, 18 Feb 2022 13:08:00 -0500 Subject: [PATCH 097/194] trying to fix programcl1 test in parser --- src/lexer/lexer.py | 2 -- src/main.py | 2 +- src/utils/utils.py | 6 +++--- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/lexer/lexer.py b/src/lexer/lexer.py index 0b34b4553..29e1c9fd6 100644 --- a/src/lexer/lexer.py +++ b/src/lexer/lexer.py @@ -20,8 +20,6 @@ def __init__(self, **kwargs): self.lexer.linestart = 0 self.text = None - - # Comments def t_comment(self, t): diff --git a/src/main.py b/src/main.py index 506c548a3..1f60c473f 100644 --- a/src/main.py +++ b/src/main.py @@ -22,7 +22,7 @@ def main(_input, _output): if __name__ == "__main__": - path = '/mnt/d/UH/4to Año/EVEA/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/parser/conditional4.cl' + path = '/home/cwjki/Projects/cool-compiler-2021/tests/parser/program1.cl' _input = sys.argv[1] if len(sys.argv) > 1 else path _output = sys.argv[2] if len(sys.argv) > 2 else None diff --git a/src/utils/utils.py b/src/utils/utils.py index 8d02720b0..b2ddde39c 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -1,6 +1,6 @@ -def find_column(text, pos): - line_start = text.rfind('\n', 0, pos) + 1 - return (pos - line_start) + 1 +def find_column(lexer, token): + line_start = lexer.lexdata.rfind('\n', 0, token.lexpos) + return (token.lexpos - line_start) class Token: From c9824d2329437c886d409cb1655c4dcb47e1f55c Mon Sep 17 00:00:00 2001 From: cwjki Date: Fri, 18 Feb 2022 13:09:47 -0500 Subject: [PATCH 098/194] no funciono --- src/utils/utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/utils.py b/src/utils/utils.py index b2ddde39c..8d02720b0 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -1,6 +1,6 @@ -def find_column(lexer, token): - line_start = lexer.lexdata.rfind('\n', 0, token.lexpos) - return (token.lexpos - line_start) +def find_column(text, pos): + line_start = text.rfind('\n', 0, pos) + 1 + return (pos - line_start) + 1 class Token: From fc834def32bae4e2a35e96256e9029ebaf44e3c6 Mon Sep 17 00:00:00 2001 From: cwjki Date: Fri, 18 Feb 2022 13:23:08 -0500 Subject: [PATCH 099/194] hope this fix the parser errors --- src/cparser/parser.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/cparser/parser.py b/src/cparser/parser.py index 25e4c4315..bfd1554e7 100644 --- a/src/cparser/parser.py +++ b/src/cparser/parser.py @@ -263,10 +263,13 @@ def p_error(self, p): if p: self.add_error(p) else: - column = find_column(self.lexer.lexer, self.lexer.lexer) - line = self.lexer.lexer.lineno - self.errors.append(SyntacticError( - 'ERROR at or near EOF', line, column - 1)) + self.errors.append(SyntacticError('ERROR at or near EOF',0 ,0)) + + # column = find_column(p.lexer.lexdata, p.lexpos) + # line = self.lexer.lexer.lineno + # self.errors.append(SyntacticError( + # 'ERROR at or near EOF', line, column - 1)) + def add_error(self, p): self.errors.append(SyntacticError( From 1e8a8df49e2dbd14eeefd32e267e306ab84059c7 Mon Sep 17 00:00:00 2001 From: cwjki Date: Fri, 18 Feb 2022 13:41:41 -0500 Subject: [PATCH 100/194] fix program1.cl parser test, tryint to test mixed1.cl --- src/cparser/parser.py | 1 + src/lexer/lexer.py | 8 ++++---- src/main.py | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/cparser/parser.py b/src/cparser/parser.py index bfd1554e7..40b92b54a 100644 --- a/src/cparser/parser.py +++ b/src/cparser/parser.py @@ -160,6 +160,7 @@ def p_expr_operators_binary(self, p): elif p[2] == '=': p[0] = EqualNode(p[1], p[3]) + p[0].add_line_column(p.lineno(0), find_column( p.lexer.lexdata, p.lexpos(0))) diff --git a/src/lexer/lexer.py b/src/lexer/lexer.py index 29e1c9fd6..b3635f544 100644 --- a/src/lexer/lexer.py +++ b/src/lexer/lexer.py @@ -216,13 +216,13 @@ def t_EQUAL(self, t): self.compute_column(t) return t - def t_LESS(self, t): - r'<' + def t_LESSEQ(self, t): + r'<=' self.compute_column(t) return t - def t_LESSEQ(self, t): - r'<=' + def t_LESS(self, t): + r'<' self.compute_column(t) return t diff --git a/src/main.py b/src/main.py index 1f60c473f..903108ad0 100644 --- a/src/main.py +++ b/src/main.py @@ -22,7 +22,7 @@ def main(_input, _output): if __name__ == "__main__": - path = '/home/cwjki/Projects/cool-compiler-2021/tests/parser/program1.cl' + path = '/home/cwjki/Projects/cool-compiler-2021/tests/parser/mixed1.cl' _input = sys.argv[1] if len(sys.argv) > 1 else path _output = sys.argv[2] if len(sys.argv) > 2 else None From d4afb533da665b73254b470a4591dcbe4bfe36c3 Mon Sep 17 00:00:00 2001 From: cwjki Date: Fri, 18 Feb 2022 13:48:51 -0500 Subject: [PATCH 101/194] all the parser test are pass, next step fix the semantic tests --- .vscode/settings.json | 5 ++++- src/cparser/parser.py | 6 ++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index cc67606f3..833374fbb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,7 @@ { "python.linting.pylintEnabled": true, - "python.linting.enabled": true + "python.linting.enabled": true, + "editor.tabSize": 2, + "prettier.useTabs": true, + "editor.formatOnSave": true } \ No newline at end of file diff --git a/src/cparser/parser.py b/src/cparser/parser.py index 40b92b54a..068b91749 100644 --- a/src/cparser/parser.py +++ b/src/cparser/parser.py @@ -160,7 +160,6 @@ def p_expr_operators_binary(self, p): elif p[2] == '=': p[0] = EqualNode(p[1], p[3]) - p[0].add_line_column(p.lineno(0), find_column( p.lexer.lexdata, p.lexpos(0))) @@ -264,18 +263,17 @@ def p_error(self, p): if p: self.add_error(p) else: - self.errors.append(SyntacticError('ERROR at or near EOF',0 ,0)) + self.errors.append(SyntacticError('ERROR at or near EOF', 0, 0)) # column = find_column(p.lexer.lexdata, p.lexpos) # line = self.lexer.lexer.lineno # self.errors.append(SyntacticError( # 'ERROR at or near EOF', line, column - 1)) - def add_error(self, p): self.errors.append(SyntacticError( f'ERROR at or near {p.value}', p.lineno, p.column)) - + def print_error(self): for error in self.errors: print(error) From 581e50752dd5fa98312e2a53d9c5230a1e5326b2 Mon Sep 17 00:00:00 2001 From: cwjki Date: Fri, 18 Feb 2022 15:49:41 -0500 Subject: [PATCH 102/194] fixing some bugs in the Context class --- .vscode/settings.json | 1 - src/main.py | 3 ++ src/semantic/semantic.py | 61 ++++++++++++++++++-------- src/semantic/semanticAnalizer.py | 21 +++++++++ src/semantic/visitors/typeCollector.py | 33 +++----------- src/semantic/visitors/typeInferer.py | 0 6 files changed, 71 insertions(+), 48 deletions(-) create mode 100644 src/semantic/semanticAnalizer.py create mode 100644 src/semantic/visitors/typeInferer.py diff --git a/.vscode/settings.json b/.vscode/settings.json index 833374fbb..91bab81f6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,6 @@ { "python.linting.pylintEnabled": true, "python.linting.enabled": true, - "editor.tabSize": 2, "prettier.useTabs": true, "editor.formatOnSave": true } \ No newline at end of file diff --git a/src/main.py b/src/main.py index 903108ad0..c6b4c6858 100644 --- a/src/main.py +++ b/src/main.py @@ -19,6 +19,9 @@ def main(_input, _output): parser.print_error() raise Exception() + + ast, errors, context, scope = SemanticAn + if __name__ == "__main__": diff --git a/src/semantic/semantic.py b/src/semantic/semantic.py index dad224b9a..406b51e6a 100644 --- a/src/semantic/semantic.py +++ b/src/semantic/semantic.py @@ -34,14 +34,6 @@ def __eq__(self, other): other.param_types == self.param_types -# class MethodError(Method): -# def __init__(self, name, param_names, param_types, return_types): -# super().__init__(name, param_names, param_types, return_types) - -# def __str__(self): -# return f'[method] {self.name} ERROR' - - class Type: def __init__(self, name: str, pos, parent=True): if name == 'ObjectType': @@ -293,17 +285,6 @@ def __ne__(self, other): return other.name != self.name and not isinstance(other, ObjectType) -# class AutoType(Type): -# def __init__(self): -# Type.__init__(self, 'AUTO_TYPE') - -# def __eq__(self, other): -# return other.name == self.name or isinstance(other, AutoType) - -# def __ne__(self, other): -# return other.name != self.name and not isinstance(other, AutoType) - - class IOType(Type): def __init__(self, pos=(0, 0)): self.name = 'IO' @@ -324,3 +305,45 @@ def __eq__(self, other): def __ne__(self, other): return other.name != self.name and not isinstance(other, IOType) + + +class Context: + def __init__(self): + self.types = {} + + def get_depth(self, class_name): + typex = self.types[class_name] + if typex.parent is None: + return 0 + return 1 + self.get_depth(typex.parent.name) + + def build_inheritance_graph(self): + graph = {} + for type_name, typex in self.types.items(): + if typex.parent is not None: + graph[type_name] = typex.parent.name + else: + if type_name == 'SELF_TYPE': + continue + graph[type_name] = None + return graph + + def create_type(self, name: str, pos) -> Type: + if name in self.types: + error_text = 'Classes may not be redefined.' + raise SemanticError(error_text, *pos) + typex = self.types[name] = Type(name, pos) + return typex + + def get_type(self, name: str, pos) -> Type: + try: + return self.types[name] + except KeyError: + error_text = f'Type {name} is not defined.' + raise SemanticError(error_text, *pos) + + def __str__(self): + return '{\n\t' + '\n\t'.join(y for x in self.types.values() for y in str(x).split('\n')) + '\n}' + + def __repr__(self): + return str(self) diff --git a/src/semantic/semanticAnalizer.py b/src/semantic/semanticAnalizer.py new file mode 100644 index 000000000..4056232ea --- /dev/null +++ b/src/semantic/semanticAnalizer.py @@ -0,0 +1,21 @@ + + +def semanticAnalizer(ast): + errors = [] + + typeCollector = TypeCollector(errors) + typeCollector.visit(ast) + context = typeCollector.context + + typeBuilder = TypeBuilder(context, errors) + typeBuilder.visit(ast) + + typeInferer = TypeInferer(context, errors) + scope = typeInferer.visit(ast) + + typeChecker = TypeChecker(context, errors) + typeChecker.visit(ast, scope) + + return ast, errors, context, scope + + diff --git a/src/semantic/visitors/typeCollector.py b/src/semantic/visitors/typeCollector.py index 578ba5045..9e4cb3d16 100644 --- a/src/semantic/visitors/typeCollector.py +++ b/src/semantic/visitors/typeCollector.py @@ -1,41 +1,18 @@ -from utils.errors import SemanticError -from semantic.tools import Context from utils import visitor -from semantic.types import * -from utils.ast import * +from utils.ast import * + class TypeCollector(object): def __init__(self, errors=[]): self.context = None self.errors = errors - + @visitor.on('node') def visit(self, node): pass @visitor.when(ProgramNode) - def visit(self, node: ProgramNode): - self.context = Context() - self.context.types['String'] = StringType() - self.context.types['Int'] = IntType() - self.context.types['Object'] = ObjectType() - self.context.types['Bool'] = BoolType() - self.context.types['SELF_TYPE'] = SelfType() - self.context.types['IO'] = IOType() - # self.context.create_type('SELF_TYPE', (0, 0)) - for dec in node.declarations: - self.visit(dec) + def visit(self, programNode): + self.context = - @visitor.when(ClassDeclarationNode) - def visit(self, node: ClassDeclarationNode): - if node.id in ['String', 'Int', 'Object', 'Bool', 'SELF_TYPE', 'IO']: - error = SemanticError.REDEFINITION_ERROR % node.id - self.errors.append(SemanticError(error, *node.pos)) - try: - self.context.create_type(node.id, node.pos) - except SemanticError as e: - self.errors.append(e) - # añade un como padre Object si este no tiene - if not node.parent: - node.parent = 'Object' diff --git a/src/semantic/visitors/typeInferer.py b/src/semantic/visitors/typeInferer.py new file mode 100644 index 000000000..e69de29bb From 5d71a61386655639d64f788bf6ed299750fc2615 Mon Sep 17 00:00:00 2001 From: cwjki Date: Fri, 18 Feb 2022 17:13:46 -0500 Subject: [PATCH 103/194] before modify the ast --- src/semantic/visitors/typeCollector.py | 31 ++++++++++++++++++++++---- src/utils/ast.py | 4 ++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/semantic/visitors/typeCollector.py b/src/semantic/visitors/typeCollector.py index 9e4cb3d16..3019d2856 100644 --- a/src/semantic/visitors/typeCollector.py +++ b/src/semantic/visitors/typeCollector.py @@ -1,18 +1,41 @@ +from src.utils.errors import SemanticError from utils import visitor -from utils.ast import * - +from utils.ast import ProgramNode, ClassDeclarationNode +from semantic.semantic import Context, IntType, StringType, BoolType, ObjectType, SelfType, IOType class TypeCollector(object): def __init__(self, errors=[]): self.context = None self.errors = errors - + @visitor.on('node') def visit(self, node): pass @visitor.when(ProgramNode) def visit(self, programNode): - self.context = + self.context = Context() + self.context.types['Int'] = IntType() + self.context.types['String'] = StringType() + self.context.types['Bool'] = BoolType() + self.context.types['Object'] = ObjectType() + self.context.types['SELF_TYPE'] = SelfType() + self.context.types['IO'] = IOType() + + for classDeclarationNode in programNode.classes: + self.visit(self, classDeclarationNode) + + @visitor.when(ClassDeclarationNode) + def visit(self, classDeclarationNode): + if classDeclarationNode.name in ['Int', 'String', 'Bool', 'Object', 'SELF_TYPE', 'IO']: + errorText = f'Redefinition of basic class {classDeclarationNode.name}' + self.errors.append(SemanticError(errorText, *classDeclarationNode.position)) + try: + self.context.create_type(classDeclarationNode.name, classDeclarationNode.position) + except Exception as error: + self.errors.append(error) + + if not classDeclarationNode.parent: + classDeclarationNode.parent = 'Object' diff --git a/src/utils/ast.py b/src/utils/ast.py index c69a682f4..1c22270cd 100644 --- a/src/utils/ast.py +++ b/src/utils/ast.py @@ -19,6 +19,10 @@ def __init__(self, name, features, parent=None): super().__init__() self.name = name self.features = features + if parent: + self.parent = parent.value + self.parent + self.parent = parent From be19abd78a76afb8dd902f695ab2a7b7de32d9d6 Mon Sep 17 00:00:00 2001 From: cwjki Date: Fri, 18 Feb 2022 18:46:29 -0500 Subject: [PATCH 104/194] fixing some index in parser --- src/cparser/parser.py | 67 +++++++---------- src/utils/ast.py | 167 +++++++++++++++++++++++------------------- 2 files changed, 118 insertions(+), 116 deletions(-) diff --git a/src/cparser/parser.py b/src/cparser/parser.py index 068b91749..962c4b69a 100644 --- a/src/cparser/parser.py +++ b/src/cparser/parser.py @@ -30,6 +30,7 @@ def p_program(self, p): def p_epsilon(self, p): 'epsilon :' + pass def p_class_list(self, p): '''class_list : def_class SEMICOLON class_list @@ -44,8 +45,6 @@ def p_def_class(self, p): else: p[0] = ClassDeclarationNode(p[2], p[4]) - p[0].add_line_column(p.lineno(2), find_column( - p.lexer.lexdata, p.lexpos(2))) def p_feature_list(self, p): '''feature_list : def_attr SEMICOLON feature_list @@ -61,14 +60,10 @@ def p_def_attr(self, p): else: p[0] = AttrDeclarationNode(p[1], p[3], p[5]) - p[0].add_line_column(p.lineno(3), find_column( - p.lexer.lexdata, p.lexpos(3))) def p_def_func(self, p): '''def_func : ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACE''' p[0] = FuncDeclarationNode(p[1], p[3], p[6], p[8]) - p[0].add_line_column(p.lineno(6), find_column( - p.lexer.lexdata, p.lexpos(6))) def p_params(self, p): '''params : param_list @@ -88,6 +83,20 @@ def p_param(self, p): '''param : ID COLON TYPE''' p[0] = (p[1], p[3]) + + def p_let_list(self, p): + '''let_list : let_assign + | let_assign COMMA let_list''' + p[0] = [p[1]] if len(p) == 2 else [p[1]] + p[3] + + def p_let_assign(self, p): + '''let_assign : param ASSIGN expr + | param''' + if len(p) == 2: + p[0] = VarDeclarationNode(p[1][0], p[1][1]) + else: + p[0] = VarDeclarationNode(p[1][0], p[1][1], p[3]) + def p_expr_flow(self, p): '''expr : LET let_attrs IN expr | CASE expr OF case_list ESAC @@ -95,16 +104,14 @@ def p_expr_flow(self, p): | WHILE expr LOOP expr POOL''' if p[1].lower() == 'let': - p[0] = LetNode(p[2], p[4]) + p[0] = LetNode(p[2], p[4], p[1]) elif p[1].lower() == 'case': - p[0] = CaseNode(p[2], p[4]) + p[0] = CaseNode(p[2], p[4], p[1]) elif p[1].lower() == 'if': - p[0] = IfNode(p[2], p[4], p[6]) + p[0] = ConditionalNode(p[2], p[4], p[6], p[1]) elif p[1].lower() == 'while': - p[0] = WhileNode(p[2], p[4]) + p[0] = WhileNode(p[2], p[4], p[1]) - p[0].add_line_column(p.lineno(2), find_column( - p.lexer.lexdata, p.lexpos(2))) def p_expr_assign(self, p): '''expr : ID ASSIGN expr''' @@ -120,22 +127,15 @@ def p_expr_func_call(self, p): if p[7] is None: p[7] = [] p[0] = FuncCallNode(p[5], p[7], p[1], p[3]) - p[0].add_line_column(p.lineno(5), find_column( - p.lexer.lexdata, p.lexpos(5))) elif len(p) == 7: if p[5] is None: p[5] = [] p[0] = FuncCallNode(p[3], p[5], p[1]) - p[0].add_line_column(p.lineno(3), find_column( - p.lexer.lexdata, p.lexpos(3))) else: if p[3] is None: p[3] = [] p[0] = FuncCallNode(p[1], p[3]) - p[0].add_line_column(p.lineno(1), find_column( - p.lexer.lexdata, p.lexpos(1))) - p[0].lineno = p.lineno(0) def p_expr_operators_binary(self, p): '''expr : expr PLUS expr @@ -160,22 +160,18 @@ def p_expr_operators_binary(self, p): elif p[2] == '=': p[0] = EqualNode(p[1], p[3]) - p[0].add_line_column(p.lineno(0), find_column( - p.lexer.lexdata, p.lexpos(0))) def p_expr_operators_unary(self, p): '''expr : NOT expr | ISVOID expr | LNOT expr''' if p[1] == '~': - p[0] = NegationNode(p[2]) + p[0] = NegationNode(p[2], p[1]) elif p[1].lower() == 'isvoid': - p[0] = IsVoidNode(p[2]) + p[0] = IsVoidNode(p[2], p[1]) elif p[1].lower() == 'not': - p[0] = LogicNegationNode(p[2]) + p[0] = LogicNegationNode(p[2], p[1]) - p[0].add_line_column(p.lineno(2), find_column( - p.lexer.lexdata, p.lexpos(2))) def p_expr_group(self, p): '''expr : LPAREN expr RPAREN''' @@ -198,8 +194,6 @@ def p_case_list(self, p): def p_case_option(self, p): '''case_option : ID COLON TYPE ARROW expr''' p[0] = CaseOptionNode(p[1], p[3], p[5]) - p[0].add_line_column(p.lineno(3), find_column( - p.lexer.lexdata, p.lexpos(3))) def p_args(self, p): '''args : arg_list @@ -218,32 +212,25 @@ def p_arg_list_empty(self, p): def p_atom_int(self, p): '''atom : INT''' p[0] = IntNode(int(p[1])) - p[0].add_line_column(p.lineno(1), find_column( - p.lexer.lexdata, p.lexpos(1))) def p_atom_id(self, p): '''atom : ID''' - p[0] = VarNode(p[1]) - p[0].add_line_column(p.lineno(1), find_column( - p.lexer.lexdata, p.lexpos(1))) + p[0] = AtomicNode(p[1]) def p_atom_bool(self, p): '''atom : BOOL''' p[0] = BoolNode(p[1]) - p[0].add_line_column(p.lineno(1), find_column( - p.lexer.lexdata, p.lexpos(1))) + def p_atom_string(self, p): '''atom : STRING''' p[0] = StringNode(p[1]) - p[0].add_line_column(p.lineno(1), find_column( - p.lexer.lexdata, p.lexpos(1))) + def p_atom_new(self, p): '''atom : NEW TYPE''' p[0] = NewNode(p[2]) - p[0].add_line_column(p.lineno(2), find_column( - p.lexer.lexdata, p.lexpos(2))) + def p_atom_block(self, p): '''atom : block''' @@ -257,7 +244,7 @@ def p_block_list(self, p): ''' block_list : expr SEMICOLON | expr SEMICOLON block_list''' p[0] = BlockNode([p[1]]) if len( - p) == 3 else BlockNode([p[1]] + p[3].exprs) + p) == 3 else BlockNode([p[1]] + p[3].exprs, p[2]) def p_error(self, p): if p: diff --git a/src/utils/ast.py b/src/utils/ast.py index 1c22270cd..710610ce1 100644 --- a/src/utils/ast.py +++ b/src/utils/ast.py @@ -1,132 +1,148 @@ -class Node(): - def __init__(self): - self.line = 0 - self.column = 0 +from ply.lex import LexToken + - def add_line_column(self, line, column): - self.line = line - self.column = column +class Node(): + pass class ProgramNode(Node): - def __init__(self, classes): - super().__init__() - self.classes = classes + def __init__(self, declarations): + self.declarations = declarations -class ClassDeclarationNode(Node): - def __init__(self, name, features, parent=None): - super().__init__() - self.name = name +class DeclarationNode(Node): + pass + + +class ClassDeclarationNode(DeclarationNode): + def __init__(self, idx, features, parent=None): + self.id = idx.value + self.token = idx self.features = features + self.position = (idx.lineno, idx.column) if parent: self.parent = parent.value - self.parent - - self.parent = parent + self.parentPos = (parent.lineno, parent.column) + else: + self.parent = None + self.parentPos = (0, 0) -class FuncDeclarationNode(Node): - def __init__(self, name, params, return_type, expr=None): - super().__init__() - self.name = name - self.params = params - self.return_type = return_type +class AttrDeclarationNode(DeclarationNode): + def __init__(self, idx, typex, expr=None): + self.id = idx.value + self.position = (idx.lineno, idx.column) + self.type = typex + self.typePos = (typex.lineno, typex.column) self.expr = expr -class AttrDeclarationNode(Node): - def __init__(self, name, typex, expr=None): - super().__init__() - self.name = name - self.type = typex - self.expr = expr +class FuncDeclarationNode(DeclarationNode): + def __init__(self, idx, params, returnType, body): + self.id = idx.value + self.position = (idx.lineno, idx.column) + self.params = params + self.type = returnType.value + self.typePos = (returnType.lineno, returnType.column) + self.body = body class ExpressionNode(Node): - def __init__(self): - super().__init__() - self.computed_type = None + pass class AssignNode(ExpressionNode): - def __init__(self, name, expr): - super().__init__() - self.name = name + def __init__(self, idx, expr): + self.id = idx.value + self.position = (idx.lineno, idx.column) self.expr = expr class FuncCallNode(ExpressionNode): - def __init__(self, idx, args, obj=None, typex=None): - super().__init__() - self.id = idx + def __init__(self, obj, idx, args, typex): + self.obj = obj + self.id = idx.value + self.position = (idx.lineno, idx.column) + self.args = args + self.type = typex.value + self.typePos = (typex.lineno, typex.column) + + +class MemberCallNode(ExpressionNode): + def __init__(self, obj, idx, args): + self.obj = obj + self.id = idx.value + self.position = (idx.lineno, idx.column) self.args = args - self.object = obj - self.type = typex -class IfNode(ExpressionNode): - def __init__(self, condition, then_expr, else_expr): - super().__init__() +class ConditionalNode(ExpressionNode): + def __init__(self, condition, then_expr, else_expr, token): self.condition = condition self.then_expr = then_expr self.else_expr = else_expr + self.position = (token.lineno, token.column) class WhileNode(ExpressionNode): - def __init__(self, condition, body): - super().__init__() + def __init__(self, condition, body, token): self.condition = condition self.body = body + self.position = (token.lineno, token.column) class BlockNode(ExpressionNode): - def __init__(self, exprs): - super().__init__() + def __init__(self, exprs, token): self.exprs = exprs + self.position = (token.lineno, token.column) class LetNode(ExpressionNode): - def __init__(self, let_attrs, expr): - super().__init__() + def __init__(self, let_attrs, expr, token): self.let_attrs = let_attrs self.expr = expr + self.position = (token.lineno, token.column) class CaseNode(ExpressionNode): - def __init__(self, expr, case_list): - super().__init__() + def __init__(self, expr, case_list, token): self.expr = expr self.case_list = case_list + self.position = (token.lineno, token.column) class CaseOptionNode(ExpressionNode): def __init__(self, idx, typex, expr): - super().__init__() - self.id = idx - self.expr = expr + self.id = idx.value + self.position = (idx.lineno, idx.column) self.type = typex + self.typePos = (typex.lineno, typex.column) + self.expr = expr -class VarNode(ExpressionNode): - def __init__(self, idx): - super().__init__() - self.id = idx +class VarDeclarationNode(ExpressionNode): + def __init__(self, idx, typex, expr=None): + self.id = idx.value + self.position = (idx.lineno, idx.column) + self.type = typex + self.typePos = (typex.lineno, typex.column) + self.expr = expr class NewNode(ExpressionNode): def __init__(self, typex): - super().__init__() self.type = typex + self.typePos = (typex.lineno, typex.column) + # ---------------- Binary Nodes ------------------ class BinaryNode(ExpressionNode): def __init__(self, lvalue, rvalue): - super().__init__() self.lvalue = lvalue self.rvalue = rvalue + self.position = lvalue.position class PlusNode(BinaryNode): @@ -160,9 +176,9 @@ class EqualNode(BinaryNode): # ---------------- Unary Nodes ------------------ class UnaryNode(ExpressionNode): - def __init__(self, value): - super().__init__() - self.value = value + def __init__(self, expr, token): + self.expr = expr + self.position = (token.lineno, token.column) class NegationNode(UnaryNode): @@ -173,29 +189,28 @@ class LogicNegationNode(UnaryNode): pass -class AtomicNode(UnaryNode): - pass - - class IsVoidNode(UnaryNode): pass -# ---------------- Constant Nodes ------------------ - -class ConstantNode(ExpressionNode): - def __init__(self, value): - super().__init__() - self.value = value +# ---------------- Atomic Nodes ------------------ +class AtomicNode(ExpressionNode): + def __init__(self, lex): + try: + self.lex = lex.value + self.position = (lex.lineno, lex.column) + except: + self.lex = lex + self.position = (0, 0) -class IntNode(ConstantNode): +class IntNode(AtomicNode): pass -class BoolNode(ConstantNode): +class BoolNode(AtomicNode): pass -class StringNode(ConstantNode): +class StringNode(AtomicNode): pass From 0899ee51d661ff40123e33687725f54797a78202 Mon Sep 17 00:00:00 2001 From: cwjki Date: Fri, 18 Feb 2022 18:59:23 -0500 Subject: [PATCH 105/194] testing --- src/cparser/parser.py | 67 +++++++++------- src/cparser/parsetab.py | 104 +++++++++++++------------ src/main.py | 2 +- src/utils/ast.py | 169 ++++++++++++++++++---------------------- 4 files changed, 170 insertions(+), 172 deletions(-) diff --git a/src/cparser/parser.py b/src/cparser/parser.py index 962c4b69a..068b91749 100644 --- a/src/cparser/parser.py +++ b/src/cparser/parser.py @@ -30,7 +30,6 @@ def p_program(self, p): def p_epsilon(self, p): 'epsilon :' - pass def p_class_list(self, p): '''class_list : def_class SEMICOLON class_list @@ -45,6 +44,8 @@ def p_def_class(self, p): else: p[0] = ClassDeclarationNode(p[2], p[4]) + p[0].add_line_column(p.lineno(2), find_column( + p.lexer.lexdata, p.lexpos(2))) def p_feature_list(self, p): '''feature_list : def_attr SEMICOLON feature_list @@ -60,10 +61,14 @@ def p_def_attr(self, p): else: p[0] = AttrDeclarationNode(p[1], p[3], p[5]) + p[0].add_line_column(p.lineno(3), find_column( + p.lexer.lexdata, p.lexpos(3))) def p_def_func(self, p): '''def_func : ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACE''' p[0] = FuncDeclarationNode(p[1], p[3], p[6], p[8]) + p[0].add_line_column(p.lineno(6), find_column( + p.lexer.lexdata, p.lexpos(6))) def p_params(self, p): '''params : param_list @@ -83,20 +88,6 @@ def p_param(self, p): '''param : ID COLON TYPE''' p[0] = (p[1], p[3]) - - def p_let_list(self, p): - '''let_list : let_assign - | let_assign COMMA let_list''' - p[0] = [p[1]] if len(p) == 2 else [p[1]] + p[3] - - def p_let_assign(self, p): - '''let_assign : param ASSIGN expr - | param''' - if len(p) == 2: - p[0] = VarDeclarationNode(p[1][0], p[1][1]) - else: - p[0] = VarDeclarationNode(p[1][0], p[1][1], p[3]) - def p_expr_flow(self, p): '''expr : LET let_attrs IN expr | CASE expr OF case_list ESAC @@ -104,14 +95,16 @@ def p_expr_flow(self, p): | WHILE expr LOOP expr POOL''' if p[1].lower() == 'let': - p[0] = LetNode(p[2], p[4], p[1]) + p[0] = LetNode(p[2], p[4]) elif p[1].lower() == 'case': - p[0] = CaseNode(p[2], p[4], p[1]) + p[0] = CaseNode(p[2], p[4]) elif p[1].lower() == 'if': - p[0] = ConditionalNode(p[2], p[4], p[6], p[1]) + p[0] = IfNode(p[2], p[4], p[6]) elif p[1].lower() == 'while': - p[0] = WhileNode(p[2], p[4], p[1]) + p[0] = WhileNode(p[2], p[4]) + p[0].add_line_column(p.lineno(2), find_column( + p.lexer.lexdata, p.lexpos(2))) def p_expr_assign(self, p): '''expr : ID ASSIGN expr''' @@ -127,15 +120,22 @@ def p_expr_func_call(self, p): if p[7] is None: p[7] = [] p[0] = FuncCallNode(p[5], p[7], p[1], p[3]) + p[0].add_line_column(p.lineno(5), find_column( + p.lexer.lexdata, p.lexpos(5))) elif len(p) == 7: if p[5] is None: p[5] = [] p[0] = FuncCallNode(p[3], p[5], p[1]) + p[0].add_line_column(p.lineno(3), find_column( + p.lexer.lexdata, p.lexpos(3))) else: if p[3] is None: p[3] = [] p[0] = FuncCallNode(p[1], p[3]) + p[0].add_line_column(p.lineno(1), find_column( + p.lexer.lexdata, p.lexpos(1))) + p[0].lineno = p.lineno(0) def p_expr_operators_binary(self, p): '''expr : expr PLUS expr @@ -160,18 +160,22 @@ def p_expr_operators_binary(self, p): elif p[2] == '=': p[0] = EqualNode(p[1], p[3]) + p[0].add_line_column(p.lineno(0), find_column( + p.lexer.lexdata, p.lexpos(0))) def p_expr_operators_unary(self, p): '''expr : NOT expr | ISVOID expr | LNOT expr''' if p[1] == '~': - p[0] = NegationNode(p[2], p[1]) + p[0] = NegationNode(p[2]) elif p[1].lower() == 'isvoid': - p[0] = IsVoidNode(p[2], p[1]) + p[0] = IsVoidNode(p[2]) elif p[1].lower() == 'not': - p[0] = LogicNegationNode(p[2], p[1]) + p[0] = LogicNegationNode(p[2]) + p[0].add_line_column(p.lineno(2), find_column( + p.lexer.lexdata, p.lexpos(2))) def p_expr_group(self, p): '''expr : LPAREN expr RPAREN''' @@ -194,6 +198,8 @@ def p_case_list(self, p): def p_case_option(self, p): '''case_option : ID COLON TYPE ARROW expr''' p[0] = CaseOptionNode(p[1], p[3], p[5]) + p[0].add_line_column(p.lineno(3), find_column( + p.lexer.lexdata, p.lexpos(3))) def p_args(self, p): '''args : arg_list @@ -212,25 +218,32 @@ def p_arg_list_empty(self, p): def p_atom_int(self, p): '''atom : INT''' p[0] = IntNode(int(p[1])) + p[0].add_line_column(p.lineno(1), find_column( + p.lexer.lexdata, p.lexpos(1))) def p_atom_id(self, p): '''atom : ID''' - p[0] = AtomicNode(p[1]) + p[0] = VarNode(p[1]) + p[0].add_line_column(p.lineno(1), find_column( + p.lexer.lexdata, p.lexpos(1))) def p_atom_bool(self, p): '''atom : BOOL''' p[0] = BoolNode(p[1]) - + p[0].add_line_column(p.lineno(1), find_column( + p.lexer.lexdata, p.lexpos(1))) def p_atom_string(self, p): '''atom : STRING''' p[0] = StringNode(p[1]) - + p[0].add_line_column(p.lineno(1), find_column( + p.lexer.lexdata, p.lexpos(1))) def p_atom_new(self, p): '''atom : NEW TYPE''' p[0] = NewNode(p[2]) - + p[0].add_line_column(p.lineno(2), find_column( + p.lexer.lexdata, p.lexpos(2))) def p_atom_block(self, p): '''atom : block''' @@ -244,7 +257,7 @@ def p_block_list(self, p): ''' block_list : expr SEMICOLON | expr SEMICOLON block_list''' p[0] = BlockNode([p[1]]) if len( - p) == 3 else BlockNode([p[1]] + p[3].exprs, p[2]) + p) == 3 else BlockNode([p[1]] + p[3].exprs) def p_error(self, p): if p: diff --git a/src/cparser/parsetab.py b/src/cparser/parsetab.py index 2098fe1a9..62804adfa 100644 --- a/src/cparser/parsetab.py +++ b/src/cparser/parsetab.py @@ -6,9 +6,9 @@ _lr_method = 'LALR' -_lr_signature = 'programARROW ASSIGN AT BOOL CASE CLASS COLON COMMA DIV DOT ELSE EQUAL ESAC FI ID IF IN INHERITS INT ISVOID LBRACE LESS LESSEQ LET LNOT LOOP LPAREN MINUS NEW NOT OF PLUS POOL RBRACE RPAREN SEMICOLON STAR STRING THEN TYPE WHILEprogram : class_listepsilon :class_list : def_class SEMICOLON class_list\n | def_class SEMICOLON def_class : CLASS TYPE LBRACE feature_list RBRACE\n | CLASS TYPE INHERITS TYPE LBRACE feature_list RBRACEfeature_list : def_attr SEMICOLON feature_list\n | def_func SEMICOLON feature_list\n | epsilondef_attr : ID COLON TYPE\n | ID COLON TYPE ASSIGN exprdef_func : ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACEparams : param_list\n | param_list_emptyparam_list : param\n | param COMMA param_listparam_list_empty : epsilonparam : ID COLON TYPEexpr : LET let_attrs IN expr\n | CASE expr OF case_list ESAC\n | IF expr THEN expr ELSE expr FI\n | WHILE expr LOOP expr POOLexpr : ID ASSIGN exprexpr : expr AT TYPE DOT ID LPAREN args RPAREN\n | expr DOT ID LPAREN args RPAREN\n | ID LPAREN args RPARENexpr : expr PLUS expr\n | expr MINUS expr\n | expr STAR expr\n | expr DIV expr\n | expr LESS expr\n | expr LESSEQ expr\n | expr EQUAL exprexpr : NOT expr\n | ISVOID expr\n | LNOT exprexpr : LPAREN expr RPARENexpr : atomlet_attrs : def_attr\n | def_attr COMMA let_attrscase_list : case_option SEMICOLON\n | case_option SEMICOLON case_listcase_option : ID COLON TYPE ARROW exprargs : arg_list\n | arg_list_emptyarg_list : expr\n | expr COMMA arg_listarg_list_empty : epsilonatom : INTatom : IDatom : BOOLatom : STRINGatom : NEW TYPEatom : blockblock : LBRACE block_list RBRACE block_list : expr SEMICOLON\n | expr SEMICOLON block_list' +_lr_signature = 'programARROW ASSIGN AT BOOL CASE CLASS COLON COMMA DIV DOT ELSE EQUAL ESAC FI ID IF IN INHERITS INT ISVOID LBRACE LESS LESSEQ LET LNOT LOOP LPAREN MINUS NEW NOT OF PLUS POOL RBRACE RPAREN SEMICOLON STAR STRING THEN TYPE WHILEprogram : class_listepsilon :class_list : def_class SEMICOLON class_list\n | def_class SEMICOLON def_class : CLASS TYPE LBRACE feature_list RBRACE\n | CLASS TYPE INHERITS TYPE LBRACE feature_list RBRACEfeature_list : def_attr SEMICOLON feature_list\n | def_func SEMICOLON feature_list\n | epsilondef_attr : ID COLON TYPE\n | ID COLON TYPE ASSIGN exprdef_func : ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACEparams : param_list\n | param_list_emptyparam_list : param\n | param COMMA param_listparam_list_empty : epsilonparam : ID COLON TYPElet_list : let_assign\n | let_assign COMMA let_listlet_assign : param ASSIGN expr\n | paramexpr : LET let_attrs IN expr\n | CASE expr OF case_list ESAC\n | IF expr THEN expr ELSE expr FI\n | WHILE expr LOOP expr POOLexpr : ID ASSIGN exprexpr : expr AT TYPE DOT ID LPAREN args RPAREN\n | expr DOT ID LPAREN args RPAREN\n | ID LPAREN args RPARENexpr : expr PLUS expr\n | expr MINUS expr\n | expr STAR expr\n | expr DIV expr\n | expr LESS expr\n | expr LESSEQ expr\n | expr EQUAL exprexpr : NOT expr\n | ISVOID expr\n | LNOT exprexpr : LPAREN expr RPARENexpr : atomlet_attrs : def_attr\n | def_attr COMMA let_attrscase_list : case_option SEMICOLON\n | case_option SEMICOLON case_listcase_option : ID COLON TYPE ARROW exprargs : arg_list\n | arg_list_emptyarg_list : expr\n | expr COMMA arg_listarg_list_empty : epsilonatom : INTatom : IDatom : BOOLatom : STRINGatom : NEW TYPEatom : blockblock : LBRACE block_list RBRACE block_list : expr SEMICOLON\n | expr SEMICOLON block_list' -_lr_action_items = {'CLASS':([0,5,],[4,4,]),'$end':([1,2,5,7,],[0,-1,-4,-3,]),'SEMICOLON':([3,11,12,16,24,36,37,38,47,48,49,50,52,75,76,77,78,80,82,90,91,92,93,94,95,96,102,103,106,110,113,122,126,127,129,135,136,137,],[5,17,18,-5,-10,-6,-50,-11,-38,-49,-51,-52,-54,-34,-35,-36,-53,104,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,123,-20,-22,-12,-25,-21,-24,-43,]),'TYPE':([4,9,19,33,51,55,59,124,],[6,15,24,54,78,81,88,131,]),'LBRACE':([6,15,32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,81,97,100,101,104,105,107,109,125,128,134,],[8,21,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,105,53,53,53,53,53,53,53,53,53,53,]),'INHERITS':([6,],[9,]),'ID':([8,17,18,20,21,32,35,39,40,41,42,43,44,45,46,53,57,58,60,61,62,63,64,65,66,67,97,98,99,100,101,104,105,107,108,109,123,125,128,134,],[14,14,14,25,14,37,25,70,37,37,37,37,37,37,37,37,37,37,89,37,37,37,37,37,37,37,37,70,114,37,37,37,37,37,120,37,114,37,37,37,]),'RBRACE':([8,10,13,17,18,21,22,23,31,37,47,48,49,50,52,75,76,77,78,79,82,90,91,92,93,94,95,96,102,103,104,106,110,117,118,122,126,129,135,136,],[-2,16,-9,-2,-2,-2,-7,-8,36,-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,103,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-56,-26,-19,-57,127,-20,-22,-25,-21,-24,]),'COLON':([14,25,34,70,114,],[19,33,55,19,124,]),'LPAREN':([14,32,37,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,89,97,100,101,104,105,107,109,120,125,128,134,],[20,43,58,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,109,43,43,43,43,43,43,43,128,43,43,43,]),'RPAREN':([20,26,27,28,29,30,37,47,48,49,50,52,54,56,58,74,75,76,77,78,82,83,84,85,86,87,90,91,92,93,94,95,96,102,103,106,109,110,119,121,122,126,128,129,133,135,136,],[-2,34,-13,-14,-15,-17,-50,-38,-49,-51,-52,-54,-18,-16,-2,102,-34,-35,-36,-53,-23,106,-44,-45,-46,-48,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-2,-19,-47,129,-20,-22,-2,-25,136,-21,-24,]),'COMMA':([24,29,37,38,47,48,49,50,52,54,69,75,76,77,78,82,86,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-10,35,-50,-11,-38,-49,-51,-52,-54,-18,98,-34,-35,-36,-53,-23,107,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'IN':([24,37,38,47,48,49,50,52,68,69,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,111,122,126,129,135,136,],[-10,-50,-11,-38,-49,-51,-52,-54,97,-39,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-40,-20,-22,-25,-21,-24,]),'ASSIGN':([24,37,],[32,57,]),'LET':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,]),'CASE':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,]),'IF':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,]),'WHILE':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,]),'NOT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,]),'ISVOID':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,]),'LNOT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,]),'INT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,]),'BOOL':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,]),'STRING':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,]),'NEW':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,]),'AT':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,59,-38,-49,-51,-52,-54,59,59,59,59,59,59,59,-53,59,59,59,59,59,59,59,59,59,59,-37,-55,-26,59,59,59,59,-20,-22,-25,59,-21,-24,59,]),'DOT':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,88,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,60,-38,-49,-51,-52,-54,60,60,60,60,60,60,60,-53,60,60,60,108,60,60,60,60,60,60,60,-37,-55,-26,60,60,60,60,-20,-22,-25,60,-21,-24,60,]),'PLUS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,61,-38,-49,-51,-52,-54,61,61,61,61,61,61,61,-53,61,61,61,61,61,61,61,61,61,61,-37,-55,-26,61,61,61,61,-20,-22,-25,61,-21,-24,61,]),'MINUS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,62,-38,-49,-51,-52,-54,62,62,62,62,62,62,62,-53,62,62,62,62,62,62,62,62,62,62,-37,-55,-26,62,62,62,62,-20,-22,-25,62,-21,-24,62,]),'STAR':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,63,-38,-49,-51,-52,-54,63,63,63,63,63,63,63,-53,63,63,63,63,63,63,63,63,63,63,-37,-55,-26,63,63,63,63,-20,-22,-25,63,-21,-24,63,]),'DIV':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,64,-38,-49,-51,-52,-54,64,64,64,64,64,64,64,-53,64,64,64,64,64,64,64,64,64,64,-37,-55,-26,64,64,64,64,-20,-22,-25,64,-21,-24,64,]),'LESS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,65,-38,-49,-51,-52,-54,65,65,65,65,65,65,65,-53,65,65,65,65,65,65,65,65,65,65,-37,-55,-26,65,65,65,65,-20,-22,-25,65,-21,-24,65,]),'LESSEQ':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,66,-38,-49,-51,-52,-54,66,66,66,66,66,66,66,-53,66,66,66,66,66,66,66,66,66,66,-37,-55,-26,66,66,66,66,-20,-22,-25,66,-21,-24,66,]),'EQUAL':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,67,-38,-49,-51,-52,-54,67,67,67,67,67,67,67,-53,67,67,67,67,67,67,67,67,67,67,-37,-55,-26,67,67,67,67,-20,-22,-25,67,-21,-24,67,]),'OF':([37,47,48,49,50,52,71,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,99,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'THEN':([37,47,48,49,50,52,72,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,100,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'LOOP':([37,47,48,49,50,52,73,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,101,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'ELSE':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,115,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,125,-20,-22,-25,-21,-24,]),'POOL':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,116,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,126,-20,-22,-25,-21,-24,]),'FI':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,132,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,135,-21,-24,]),'ESAC':([112,123,130,],[122,-41,-42,]),'ARROW':([131,],[134,]),} +_lr_action_items = {'CLASS':([0,5,],[4,4,]),'$end':([1,2,5,7,],[0,-1,-4,-3,]),'SEMICOLON':([3,11,12,16,24,36,37,38,47,48,49,50,52,75,76,77,78,80,82,90,91,92,93,94,95,96,102,103,106,110,113,122,126,127,129,135,136,137,],[5,17,18,-5,-10,-6,-54,-11,-42,-53,-55,-56,-58,-38,-39,-40,-57,104,-27,-31,-32,-33,-34,-35,-36,-37,-41,-59,-30,-23,123,-24,-26,-12,-29,-25,-28,-47,]),'TYPE':([4,9,19,33,51,55,59,124,],[6,15,24,54,78,81,88,131,]),'LBRACE':([6,15,32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,81,97,100,101,104,105,107,109,125,128,134,],[8,21,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,105,53,53,53,53,53,53,53,53,53,53,]),'INHERITS':([6,],[9,]),'ID':([8,17,18,20,21,32,35,39,40,41,42,43,44,45,46,53,57,58,60,61,62,63,64,65,66,67,97,98,99,100,101,104,105,107,108,109,123,125,128,134,],[14,14,14,25,14,37,25,70,37,37,37,37,37,37,37,37,37,37,89,37,37,37,37,37,37,37,37,70,114,37,37,37,37,37,120,37,114,37,37,37,]),'RBRACE':([8,10,13,17,18,21,22,23,31,37,47,48,49,50,52,75,76,77,78,79,82,90,91,92,93,94,95,96,102,103,104,106,110,117,118,122,126,129,135,136,],[-2,16,-9,-2,-2,-2,-7,-8,36,-54,-42,-53,-55,-56,-58,-38,-39,-40,-57,103,-27,-31,-32,-33,-34,-35,-36,-37,-41,-59,-60,-30,-23,-61,127,-24,-26,-29,-25,-28,]),'COLON':([14,25,34,70,114,],[19,33,55,19,124,]),'LPAREN':([14,32,37,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,89,97,100,101,104,105,107,109,120,125,128,134,],[20,43,58,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,109,43,43,43,43,43,43,43,128,43,43,43,]),'RPAREN':([20,26,27,28,29,30,37,47,48,49,50,52,54,56,58,74,75,76,77,78,82,83,84,85,86,87,90,91,92,93,94,95,96,102,103,106,109,110,119,121,122,126,128,129,133,135,136,],[-2,34,-13,-14,-15,-17,-54,-42,-53,-55,-56,-58,-18,-16,-2,102,-38,-39,-40,-57,-27,106,-48,-49,-50,-52,-31,-32,-33,-34,-35,-36,-37,-41,-59,-30,-2,-23,-51,129,-24,-26,-2,-29,136,-25,-28,]),'COMMA':([24,29,37,38,47,48,49,50,52,54,69,75,76,77,78,82,86,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-10,35,-54,-11,-42,-53,-55,-56,-58,-18,98,-38,-39,-40,-57,-27,107,-31,-32,-33,-34,-35,-36,-37,-41,-59,-30,-23,-24,-26,-29,-25,-28,]),'IN':([24,37,38,47,48,49,50,52,68,69,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,111,122,126,129,135,136,],[-10,-54,-11,-42,-53,-55,-56,-58,97,-43,-38,-39,-40,-57,-27,-31,-32,-33,-34,-35,-36,-37,-41,-59,-30,-23,-44,-24,-26,-29,-25,-28,]),'ASSIGN':([24,37,],[32,57,]),'LET':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,]),'CASE':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,]),'IF':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,]),'WHILE':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,]),'NOT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,]),'ISVOID':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,]),'LNOT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,]),'INT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,]),'BOOL':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,]),'STRING':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,]),'NEW':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,]),'AT':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-54,59,-42,-53,-55,-56,-58,59,59,59,59,59,59,59,-57,59,59,59,59,59,59,59,59,59,59,-41,-59,-30,59,59,59,59,-24,-26,-29,59,-25,-28,59,]),'DOT':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,88,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-54,60,-42,-53,-55,-56,-58,60,60,60,60,60,60,60,-57,60,60,60,108,60,60,60,60,60,60,60,-41,-59,-30,60,60,60,60,-24,-26,-29,60,-25,-28,60,]),'PLUS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-54,61,-42,-53,-55,-56,-58,61,61,61,61,61,61,61,-57,61,61,61,61,61,61,61,61,61,61,-41,-59,-30,61,61,61,61,-24,-26,-29,61,-25,-28,61,]),'MINUS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-54,62,-42,-53,-55,-56,-58,62,62,62,62,62,62,62,-57,62,62,62,62,62,62,62,62,62,62,-41,-59,-30,62,62,62,62,-24,-26,-29,62,-25,-28,62,]),'STAR':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-54,63,-42,-53,-55,-56,-58,63,63,63,63,63,63,63,-57,63,63,63,63,63,63,63,63,63,63,-41,-59,-30,63,63,63,63,-24,-26,-29,63,-25,-28,63,]),'DIV':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-54,64,-42,-53,-55,-56,-58,64,64,64,64,64,64,64,-57,64,64,64,64,64,64,64,64,64,64,-41,-59,-30,64,64,64,64,-24,-26,-29,64,-25,-28,64,]),'LESS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-54,65,-42,-53,-55,-56,-58,65,65,65,65,65,65,65,-57,65,65,65,65,65,65,65,65,65,65,-41,-59,-30,65,65,65,65,-24,-26,-29,65,-25,-28,65,]),'LESSEQ':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-54,66,-42,-53,-55,-56,-58,66,66,66,66,66,66,66,-57,66,66,66,66,66,66,66,66,66,66,-41,-59,-30,66,66,66,66,-24,-26,-29,66,-25,-28,66,]),'EQUAL':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-54,67,-42,-53,-55,-56,-58,67,67,67,67,67,67,67,-57,67,67,67,67,67,67,67,67,67,67,-41,-59,-30,67,67,67,67,-24,-26,-29,67,-25,-28,67,]),'OF':([37,47,48,49,50,52,71,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-54,-42,-53,-55,-56,-58,99,-38,-39,-40,-57,-27,-31,-32,-33,-34,-35,-36,-37,-41,-59,-30,-23,-24,-26,-29,-25,-28,]),'THEN':([37,47,48,49,50,52,72,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-54,-42,-53,-55,-56,-58,100,-38,-39,-40,-57,-27,-31,-32,-33,-34,-35,-36,-37,-41,-59,-30,-23,-24,-26,-29,-25,-28,]),'LOOP':([37,47,48,49,50,52,73,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-54,-42,-53,-55,-56,-58,101,-38,-39,-40,-57,-27,-31,-32,-33,-34,-35,-36,-37,-41,-59,-30,-23,-24,-26,-29,-25,-28,]),'ELSE':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,115,122,126,129,135,136,],[-54,-42,-53,-55,-56,-58,-38,-39,-40,-57,-27,-31,-32,-33,-34,-35,-36,-37,-41,-59,-30,-23,125,-24,-26,-29,-25,-28,]),'POOL':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,116,122,126,129,135,136,],[-54,-42,-53,-55,-56,-58,-38,-39,-40,-57,-27,-31,-32,-33,-34,-35,-36,-37,-41,-59,-30,-23,126,-24,-26,-29,-25,-28,]),'FI':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,132,135,136,],[-54,-42,-53,-55,-56,-58,-38,-39,-40,-57,-27,-31,-32,-33,-34,-35,-36,-37,-41,-59,-30,-23,-24,-26,-29,135,-25,-28,]),'ESAC':([112,123,130,],[122,-45,-46,]),'ARROW':([131,],[134,]),} _lr_action = {} for _k, _v in _lr_action_items.items(): @@ -29,30 +29,34 @@ ("S' -> program","S'",1,None,None,None), ('program -> class_list','program',1,'p_program','parser.py',28), ('epsilon -> ','epsilon',0,'p_epsilon','parser.py',32), - ('class_list -> def_class SEMICOLON class_list','class_list',3,'p_class_list','parser.py',35), - ('class_list -> def_class SEMICOLON','class_list',2,'p_class_list','parser.py',36), - ('def_class -> CLASS TYPE LBRACE feature_list RBRACE','def_class',5,'p_def_class','parser.py',40), - ('def_class -> CLASS TYPE INHERITS TYPE LBRACE feature_list RBRACE','def_class',7,'p_def_class','parser.py',41), - ('feature_list -> def_attr SEMICOLON feature_list','feature_list',3,'p_feature_list','parser.py',51), - ('feature_list -> def_func SEMICOLON feature_list','feature_list',3,'p_feature_list','parser.py',52), - ('feature_list -> epsilon','feature_list',1,'p_feature_list','parser.py',53), - ('def_attr -> ID COLON TYPE','def_attr',3,'p_def_attr','parser.py',57), - ('def_attr -> ID COLON TYPE ASSIGN expr','def_attr',5,'p_def_attr','parser.py',58), - ('def_func -> ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACE','def_func',9,'p_def_func','parser.py',68), - ('params -> param_list','params',1,'p_params','parser.py',74), - ('params -> param_list_empty','params',1,'p_params','parser.py',75), - ('param_list -> param','param_list',1,'p_param_list','parser.py',79), - ('param_list -> param COMMA param_list','param_list',3,'p_param_list','parser.py',80), - ('param_list_empty -> epsilon','param_list_empty',1,'p_param_list_empty','parser.py',84), - ('param -> ID COLON TYPE','param',3,'p_param','parser.py',88), - ('expr -> LET let_attrs IN expr','expr',4,'p_expr_flow','parser.py',92), - ('expr -> CASE expr OF case_list ESAC','expr',5,'p_expr_flow','parser.py',93), - ('expr -> IF expr THEN expr ELSE expr FI','expr',7,'p_expr_flow','parser.py',94), - ('expr -> WHILE expr LOOP expr POOL','expr',5,'p_expr_flow','parser.py',95), - ('expr -> ID ASSIGN expr','expr',3,'p_expr_assign','parser.py',110), - ('expr -> expr AT TYPE DOT ID LPAREN args RPAREN','expr',8,'p_expr_func_call','parser.py',116), - ('expr -> expr DOT ID LPAREN args RPAREN','expr',6,'p_expr_func_call','parser.py',117), - ('expr -> ID LPAREN args RPAREN','expr',4,'p_expr_func_call','parser.py',118), + ('class_list -> def_class SEMICOLON class_list','class_list',3,'p_class_list','parser.py',36), + ('class_list -> def_class SEMICOLON','class_list',2,'p_class_list','parser.py',37), + ('def_class -> CLASS TYPE LBRACE feature_list RBRACE','def_class',5,'p_def_class','parser.py',41), + ('def_class -> CLASS TYPE INHERITS TYPE LBRACE feature_list RBRACE','def_class',7,'p_def_class','parser.py',42), + ('feature_list -> def_attr SEMICOLON feature_list','feature_list',3,'p_feature_list','parser.py',50), + ('feature_list -> def_func SEMICOLON feature_list','feature_list',3,'p_feature_list','parser.py',51), + ('feature_list -> epsilon','feature_list',1,'p_feature_list','parser.py',52), + ('def_attr -> ID COLON TYPE','def_attr',3,'p_def_attr','parser.py',56), + ('def_attr -> ID COLON TYPE ASSIGN expr','def_attr',5,'p_def_attr','parser.py',57), + ('def_func -> ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACE','def_func',9,'p_def_func','parser.py',65), + ('params -> param_list','params',1,'p_params','parser.py',69), + ('params -> param_list_empty','params',1,'p_params','parser.py',70), + ('param_list -> param','param_list',1,'p_param_list','parser.py',74), + ('param_list -> param COMMA param_list','param_list',3,'p_param_list','parser.py',75), + ('param_list_empty -> epsilon','param_list_empty',1,'p_param_list_empty','parser.py',79), + ('param -> ID COLON TYPE','param',3,'p_param','parser.py',83), + ('let_list -> let_assign','let_list',1,'p_let_list','parser.py',88), + ('let_list -> let_assign COMMA let_list','let_list',3,'p_let_list','parser.py',89), + ('let_assign -> param ASSIGN expr','let_assign',3,'p_let_assign','parser.py',93), + ('let_assign -> param','let_assign',1,'p_let_assign','parser.py',94), + ('expr -> LET let_attrs IN expr','expr',4,'p_expr_flow','parser.py',101), + ('expr -> CASE expr OF case_list ESAC','expr',5,'p_expr_flow','parser.py',102), + ('expr -> IF expr THEN expr ELSE expr FI','expr',7,'p_expr_flow','parser.py',103), + ('expr -> WHILE expr LOOP expr POOL','expr',5,'p_expr_flow','parser.py',104), + ('expr -> ID ASSIGN expr','expr',3,'p_expr_assign','parser.py',117), + ('expr -> expr AT TYPE DOT ID LPAREN args RPAREN','expr',8,'p_expr_func_call','parser.py',123), + ('expr -> expr DOT ID LPAREN args RPAREN','expr',6,'p_expr_func_call','parser.py',124), + ('expr -> ID LPAREN args RPAREN','expr',4,'p_expr_func_call','parser.py',125), ('expr -> expr PLUS expr','expr',3,'p_expr_operators_binary','parser.py',141), ('expr -> expr MINUS expr','expr',3,'p_expr_operators_binary','parser.py',142), ('expr -> expr STAR expr','expr',3,'p_expr_operators_binary','parser.py',143), @@ -60,28 +64,28 @@ ('expr -> expr LESS expr','expr',3,'p_expr_operators_binary','parser.py',145), ('expr -> expr LESSEQ expr','expr',3,'p_expr_operators_binary','parser.py',146), ('expr -> expr EQUAL expr','expr',3,'p_expr_operators_binary','parser.py',147), - ('expr -> NOT expr','expr',2,'p_expr_operators_unary','parser.py',167), - ('expr -> ISVOID expr','expr',2,'p_expr_operators_unary','parser.py',168), - ('expr -> LNOT expr','expr',2,'p_expr_operators_unary','parser.py',169), - ('expr -> LPAREN expr RPAREN','expr',3,'p_expr_group','parser.py',181), - ('expr -> atom','expr',1,'p_expr_atom','parser.py',185), - ('let_attrs -> def_attr','let_attrs',1,'p_let_attrs','parser.py',189), - ('let_attrs -> def_attr COMMA let_attrs','let_attrs',3,'p_let_attrs','parser.py',190), - ('case_list -> case_option SEMICOLON','case_list',2,'p_case_list','parser.py',194), - ('case_list -> case_option SEMICOLON case_list','case_list',3,'p_case_list','parser.py',195), - ('case_option -> ID COLON TYPE ARROW expr','case_option',5,'p_case_option','parser.py',199), - ('args -> arg_list','args',1,'p_args','parser.py',205), - ('args -> arg_list_empty','args',1,'p_args','parser.py',206), - ('arg_list -> expr','arg_list',1,'p_arg_list','parser.py',210), - ('arg_list -> expr COMMA arg_list','arg_list',3,'p_arg_list','parser.py',211), - ('arg_list_empty -> epsilon','arg_list_empty',1,'p_arg_list_empty','parser.py',215), - ('atom -> INT','atom',1,'p_atom_int','parser.py',219), - ('atom -> ID','atom',1,'p_atom_id','parser.py',225), - ('atom -> BOOL','atom',1,'p_atom_bool','parser.py',231), - ('atom -> STRING','atom',1,'p_atom_string','parser.py',237), - ('atom -> NEW TYPE','atom',2,'p_atom_new','parser.py',243), - ('atom -> block','atom',1,'p_atom_block','parser.py',249), - ('block -> LBRACE block_list RBRACE','block',3,'p_block','parser.py',253), - ('block_list -> expr SEMICOLON','block_list',2,'p_block_list','parser.py',257), - ('block_list -> expr SEMICOLON block_list','block_list',3,'p_block_list','parser.py',258), + ('expr -> NOT expr','expr',2,'p_expr_operators_unary','parser.py',165), + ('expr -> ISVOID expr','expr',2,'p_expr_operators_unary','parser.py',166), + ('expr -> LNOT expr','expr',2,'p_expr_operators_unary','parser.py',167), + ('expr -> LPAREN expr RPAREN','expr',3,'p_expr_group','parser.py',177), + ('expr -> atom','expr',1,'p_expr_atom','parser.py',181), + ('let_attrs -> def_attr','let_attrs',1,'p_let_attrs','parser.py',185), + ('let_attrs -> def_attr COMMA let_attrs','let_attrs',3,'p_let_attrs','parser.py',186), + ('case_list -> case_option SEMICOLON','case_list',2,'p_case_list','parser.py',190), + ('case_list -> case_option SEMICOLON case_list','case_list',3,'p_case_list','parser.py',191), + ('case_option -> ID COLON TYPE ARROW expr','case_option',5,'p_case_option','parser.py',195), + ('args -> arg_list','args',1,'p_args','parser.py',199), + ('args -> arg_list_empty','args',1,'p_args','parser.py',200), + ('arg_list -> expr','arg_list',1,'p_arg_list','parser.py',204), + ('arg_list -> expr COMMA arg_list','arg_list',3,'p_arg_list','parser.py',205), + ('arg_list_empty -> epsilon','arg_list_empty',1,'p_arg_list_empty','parser.py',209), + ('atom -> INT','atom',1,'p_atom_int','parser.py',213), + ('atom -> ID','atom',1,'p_atom_id','parser.py',217), + ('atom -> BOOL','atom',1,'p_atom_bool','parser.py',221), + ('atom -> STRING','atom',1,'p_atom_string','parser.py',226), + ('atom -> NEW TYPE','atom',2,'p_atom_new','parser.py',231), + ('atom -> block','atom',1,'p_atom_block','parser.py',236), + ('block -> LBRACE block_list RBRACE','block',3,'p_block','parser.py',240), + ('block_list -> expr SEMICOLON','block_list',2,'p_block_list','parser.py',244), + ('block_list -> expr SEMICOLON block_list','block_list',3,'p_block_list','parser.py',245), ] diff --git a/src/main.py b/src/main.py index c6b4c6858..1b2de1d00 100644 --- a/src/main.py +++ b/src/main.py @@ -25,7 +25,7 @@ def main(_input, _output): if __name__ == "__main__": - path = '/home/cwjki/Projects/cool-compiler-2021/tests/parser/mixed1.cl' + path = '/home/cwjki/Projects/cool-compiler-2021/tests/parser/assignment1.cl' _input = sys.argv[1] if len(sys.argv) > 1 else path _output = sys.argv[2] if len(sys.argv) > 2 else None diff --git a/src/utils/ast.py b/src/utils/ast.py index 710610ce1..c69a682f4 100644 --- a/src/utils/ast.py +++ b/src/utils/ast.py @@ -1,148 +1,128 @@ -from ply.lex import LexToken - - class Node(): - pass + def __init__(self): + self.line = 0 + self.column = 0 + + def add_line_column(self, line, column): + self.line = line + self.column = column class ProgramNode(Node): - def __init__(self, declarations): - self.declarations = declarations + def __init__(self, classes): + super().__init__() + self.classes = classes -class DeclarationNode(Node): - pass +class ClassDeclarationNode(Node): + def __init__(self, name, features, parent=None): + super().__init__() + self.name = name + self.features = features + self.parent = parent -class ClassDeclarationNode(DeclarationNode): - def __init__(self, idx, features, parent=None): - self.id = idx.value - self.token = idx - self.features = features - self.position = (idx.lineno, idx.column) - if parent: - self.parent = parent.value - self.parentPos = (parent.lineno, parent.column) - else: - self.parent = None - self.parentPos = (0, 0) - - -class AttrDeclarationNode(DeclarationNode): - def __init__(self, idx, typex, expr=None): - self.id = idx.value - self.position = (idx.lineno, idx.column) - self.type = typex - self.typePos = (typex.lineno, typex.column) +class FuncDeclarationNode(Node): + def __init__(self, name, params, return_type, expr=None): + super().__init__() + self.name = name + self.params = params + self.return_type = return_type self.expr = expr -class FuncDeclarationNode(DeclarationNode): - def __init__(self, idx, params, returnType, body): - self.id = idx.value - self.position = (idx.lineno, idx.column) - self.params = params - self.type = returnType.value - self.typePos = (returnType.lineno, returnType.column) - self.body = body +class AttrDeclarationNode(Node): + def __init__(self, name, typex, expr=None): + super().__init__() + self.name = name + self.type = typex + self.expr = expr class ExpressionNode(Node): - pass + def __init__(self): + super().__init__() + self.computed_type = None class AssignNode(ExpressionNode): - def __init__(self, idx, expr): - self.id = idx.value - self.position = (idx.lineno, idx.column) + def __init__(self, name, expr): + super().__init__() + self.name = name self.expr = expr class FuncCallNode(ExpressionNode): - def __init__(self, obj, idx, args, typex): - self.obj = obj - self.id = idx.value - self.position = (idx.lineno, idx.column) - self.args = args - self.type = typex.value - self.typePos = (typex.lineno, typex.column) - - -class MemberCallNode(ExpressionNode): - def __init__(self, obj, idx, args): - self.obj = obj - self.id = idx.value - self.position = (idx.lineno, idx.column) + def __init__(self, idx, args, obj=None, typex=None): + super().__init__() + self.id = idx self.args = args + self.object = obj + self.type = typex -class ConditionalNode(ExpressionNode): - def __init__(self, condition, then_expr, else_expr, token): +class IfNode(ExpressionNode): + def __init__(self, condition, then_expr, else_expr): + super().__init__() self.condition = condition self.then_expr = then_expr self.else_expr = else_expr - self.position = (token.lineno, token.column) class WhileNode(ExpressionNode): - def __init__(self, condition, body, token): + def __init__(self, condition, body): + super().__init__() self.condition = condition self.body = body - self.position = (token.lineno, token.column) class BlockNode(ExpressionNode): - def __init__(self, exprs, token): + def __init__(self, exprs): + super().__init__() self.exprs = exprs - self.position = (token.lineno, token.column) class LetNode(ExpressionNode): - def __init__(self, let_attrs, expr, token): + def __init__(self, let_attrs, expr): + super().__init__() self.let_attrs = let_attrs self.expr = expr - self.position = (token.lineno, token.column) class CaseNode(ExpressionNode): - def __init__(self, expr, case_list, token): + def __init__(self, expr, case_list): + super().__init__() self.expr = expr self.case_list = case_list - self.position = (token.lineno, token.column) class CaseOptionNode(ExpressionNode): def __init__(self, idx, typex, expr): - self.id = idx.value - self.position = (idx.lineno, idx.column) - self.type = typex - self.typePos = (typex.lineno, typex.column) + super().__init__() + self.id = idx self.expr = expr + self.type = typex -class VarDeclarationNode(ExpressionNode): - def __init__(self, idx, typex, expr=None): - self.id = idx.value - self.position = (idx.lineno, idx.column) - self.type = typex - self.typePos = (typex.lineno, typex.column) - self.expr = expr +class VarNode(ExpressionNode): + def __init__(self, idx): + super().__init__() + self.id = idx class NewNode(ExpressionNode): def __init__(self, typex): + super().__init__() self.type = typex - self.typePos = (typex.lineno, typex.column) - # ---------------- Binary Nodes ------------------ class BinaryNode(ExpressionNode): def __init__(self, lvalue, rvalue): + super().__init__() self.lvalue = lvalue self.rvalue = rvalue - self.position = lvalue.position class PlusNode(BinaryNode): @@ -176,9 +156,9 @@ class EqualNode(BinaryNode): # ---------------- Unary Nodes ------------------ class UnaryNode(ExpressionNode): - def __init__(self, expr, token): - self.expr = expr - self.position = (token.lineno, token.column) + def __init__(self, value): + super().__init__() + self.value = value class NegationNode(UnaryNode): @@ -189,28 +169,29 @@ class LogicNegationNode(UnaryNode): pass +class AtomicNode(UnaryNode): + pass + + class IsVoidNode(UnaryNode): pass -# ---------------- Atomic Nodes ------------------ +# ---------------- Constant Nodes ------------------ + +class ConstantNode(ExpressionNode): + def __init__(self, value): + super().__init__() + self.value = value -class AtomicNode(ExpressionNode): - def __init__(self, lex): - try: - self.lex = lex.value - self.position = (lex.lineno, lex.column) - except: - self.lex = lex - self.position = (0, 0) -class IntNode(AtomicNode): +class IntNode(ConstantNode): pass -class BoolNode(AtomicNode): +class BoolNode(ConstantNode): pass -class StringNode(AtomicNode): +class StringNode(ConstantNode): pass From 9908407bd2714232d1fb740b25d60fbb8cee18ff Mon Sep 17 00:00:00 2001 From: cwjki Date: Fri, 18 Feb 2022 19:03:44 -0500 Subject: [PATCH 106/194] fixing a little typo in typeCollector --- src/semantic/visitors/typeCollector.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/semantic/visitors/typeCollector.py b/src/semantic/visitors/typeCollector.py index 3019d2856..4c9ae722d 100644 --- a/src/semantic/visitors/typeCollector.py +++ b/src/semantic/visitors/typeCollector.py @@ -30,12 +30,13 @@ def visit(self, programNode): def visit(self, classDeclarationNode): if classDeclarationNode.name in ['Int', 'String', 'Bool', 'Object', 'SELF_TYPE', 'IO']: errorText = f'Redefinition of basic class {classDeclarationNode.name}' - self.errors.append(SemanticError(errorText, *classDeclarationNode.position)) + self.errors.append(SemanticError( + errorText, classDeclarationNode.line, classDeclarationNode.column)) try: - self.context.create_type(classDeclarationNode.name, classDeclarationNode.position) + self.context.create_type( + classDeclarationNode.name, classDeclarationNode.line, classDeclarationNode.column) except Exception as error: self.errors.append(error) - + if not classDeclarationNode.parent: classDeclarationNode.parent = 'Object' - From 571e97eaf07221ee8a3eb89baa5f21352173231c Mon Sep 17 00:00:00 2001 From: cwjki Date: Sat, 19 Feb 2022 15:20:04 -0500 Subject: [PATCH 107/194] fixing some typos in TypeBuilder --- src/main.py | 2 +- src/semantic/semanticAnalizer.py | 5 +- src/semantic/visitors/typeBuilder.py | 127 ++++++++----------------- src/semantic/visitors/typeCollector.py | 4 +- src/utils/ast.py | 4 +- src/utils/errors.py | 2 +- 6 files changed, 51 insertions(+), 93 deletions(-) diff --git a/src/main.py b/src/main.py index 1b2de1d00..13c95ca94 100644 --- a/src/main.py +++ b/src/main.py @@ -20,7 +20,7 @@ def main(_input, _output): raise Exception() - ast, errors, context, scope = SemanticAn + # ast, errors, context, scope = SemanticAn if __name__ == "__main__": diff --git a/src/semantic/semanticAnalizer.py b/src/semantic/semanticAnalizer.py index 4056232ea..f72201e85 100644 --- a/src/semantic/semanticAnalizer.py +++ b/src/semantic/semanticAnalizer.py @@ -1,4 +1,4 @@ - +from semantic.visitors.typeCollector import TypeCollector def semanticAnalizer(ast): errors = [] @@ -6,6 +6,7 @@ def semanticAnalizer(ast): typeCollector = TypeCollector(errors) typeCollector.visit(ast) context = typeCollector.context + typeBuilder = TypeBuilder(context, errors) typeBuilder.visit(ast) @@ -17,5 +18,5 @@ def semanticAnalizer(ast): typeChecker.visit(ast, scope) return ast, errors, context, scope - + diff --git a/src/semantic/visitors/typeBuilder.py b/src/semantic/visitors/typeBuilder.py index c5ecb648b..44104d175 100644 --- a/src/semantic/visitors/typeBuilder.py +++ b/src/semantic/visitors/typeBuilder.py @@ -1,102 +1,59 @@ -from utils.errors import SemanticError, AttributesError, TypesError, NamesError -from semantic.types import Type, VoidType, ErrorType, Attribute, Method -from semantic.tools import Context -from utils import visitor, is_basic_type + +from semantic.semantic import ErrorType +from src.utils.errors import SemanticError +from utils import visitor from utils.ast import * + class TypeBuilder: - def __init__(self, context:Context, errors=[]): - self.context:Context = context - self.current_type:Type = None - self.errors:list = errors - + def __init__(self, context, errors=[]): + self.context = context + self.currentType = None + self.errors = errors + @visitor.on('node') def visit(self, node): pass - - @visitor.when(ProgramNode) - def visit(self, node:ProgramNode): - for dec in node.declarations: - self.visit(dec) - @visitor.when(ClassDeclarationNode) - def visit(self, node:ClassDeclarationNode): + @visit.when(ProgramNode) + def visit(self, programNode): + for declaration in programNode.declarations: + self.visit(declaration) + + @visit.when(ClassDeclarationNode) + def visit(self, classDeclarationNode): try: - self.current_type = self.context.get_type(node.id, node.pos) - except SemanticError as e: - self.current_type = ErrorType() - self.errors.append(e) - + self.currentType = self.context.get_type( + classDeclarationNode.name, (classDeclarationNode.line, classDeclarationNode.column)) + except Exception as error: + self.currentType = ErrorType + self.errors.append(error) - if node.parent is not None: - if node.parent in ['Int', 'Bool', 'String']: - error_text = SemanticError.INHERIT_ERROR % (node.id, node.parent) - self.errors.append(SemanticError(error_text, *node.parent_pos)) + if classDeclarationNode.parent is not None: + if classDeclarationNode.parent in ['String', 'Int', 'Bool']: + errorText = f'Class {classDeclarationNode.name} cannot inherit class {classDeclarationNode.parent}.' + self.errors.append(SemanticError( + errorText, classDeclarationNode.line, classDeclarationNode.column)) try: - parent = self.context.get_type(node.parent, node.parent_pos) - except SemanticError: - error_text = TypesError.INHERIT_UNDEFINED % (node.id, node.parent) - self.errors.append(TypesError(error_text, *node.parent_pos)) + parent = self.context.get_type( + classDeclarationNode.parent, (classDeclarationNode.line, classDeclarationNode.column)) + except: + errorText = f'Class {classDeclarationNode.name} inherits from an undefined class {classDeclarationNode.parent}' + self.errors.append(SemanticError( + errorText, classDeclarationNode.line, classDeclarationNode.column)) parent = None try: current = parent - while current is not None: - if current.name == self.current_type.name: - error_text = SemanticError.CIRCULAR_DEPENDENCY %(self.current_type.name, self.current_type.name) - raise SemanticError(error_text, *node.pos) + while current is None: + if current.name == self.currentType.name: + errorText = f'Class {self.currentType.name}, or an ancestor of {self.currentType.name}, is involved in an inheritance cycle.' + raise SemanticError( + errorText, classDeclarationNode.line, classDeclarationNode.column) current = current.parent - except SemanticError as e: + except Exception as error: parent = ErrorType() self.errors.append(e) - self.current_type.set_parent(parent) - - for feature in node.features: - self.visit(feature) - - - @visitor.when(FuncDeclarationNode) - def visit(self, node:FuncDeclarationNode): - args_names = [] - args_types = [] - for name, type_ in node.params: - if name in args_names: - error_text = SemanticError.PARAMETER_MULTY_DEFINED % name - self.errors.append(SemanticError(error_text, *type_.pos)) - args_names.append(name) - - try: - arg_type = self.context.get_type(type_.value, type_.pos) - except SemanticError: - error_text = TypesError.PARAMETER_UNDEFINED % (type_.value, type_.value) - self.errors.append(TypesError(error_text, *type_.pos)) - arg_type = ErrorType() - args_types.append(arg_type) - - try: - return_type = self.context.get_type(node.type, node.type_pos) - except SemanticError as e: - error_text = TypesError.RETURN_TYPE_UNDEFINED % (node.type, node.id) - self.errors.append(TypesError(error_text, *node.type_pos)) - return_type = ErrorType(node.type_pos) - - try: - self.current_type.define_method(node.id, args_names, args_types, return_type, node.pos) - except SemanticError as e: - self.errors.append(e) - - @visitor.when(AttrDeclarationNode) - def visit(self, node:AttrDeclarationNode): - try: - attr_type = self.context.get_type(node.type, node.pos) - except SemanticError as e: - error_text = TypesError.ATTR_TYPE_UNDEFINED %(node.type, node.id) - attr_type = ErrorType(node.type_pos) - self.errors.append(TypesError(error_text, *node.type_pos)) - - if node.id == 'self': - self.errors.append(SemanticError(SemanticError.SELF_ATTR, *node.pos)) + self.currentType.set_parent(parent) - try: - self.current_type.define_attribute(node.id, attr_type, node.pos) - except SemanticError as e: - self.errors.append(e) \ No newline at end of file + for feature in classDeclarationNode.features: + self.visit(feature) diff --git a/src/semantic/visitors/typeCollector.py b/src/semantic/visitors/typeCollector.py index 4c9ae722d..3330e205a 100644 --- a/src/semantic/visitors/typeCollector.py +++ b/src/semantic/visitors/typeCollector.py @@ -23,7 +23,7 @@ def visit(self, programNode): self.context.types['SELF_TYPE'] = SelfType() self.context.types['IO'] = IOType() - for classDeclarationNode in programNode.classes: + for classDeclarationNode in programNode.declarations: self.visit(self, classDeclarationNode) @visitor.when(ClassDeclarationNode) @@ -34,7 +34,7 @@ def visit(self, classDeclarationNode): errorText, classDeclarationNode.line, classDeclarationNode.column)) try: self.context.create_type( - classDeclarationNode.name, classDeclarationNode.line, classDeclarationNode.column) + classDeclarationNode.name, (classDeclarationNode.line, classDeclarationNode.column)) except Exception as error: self.errors.append(error) diff --git a/src/utils/ast.py b/src/utils/ast.py index c69a682f4..9774d9129 100644 --- a/src/utils/ast.py +++ b/src/utils/ast.py @@ -9,9 +9,9 @@ def add_line_column(self, line, column): class ProgramNode(Node): - def __init__(self, classes): + def __init__(self, declarations): super().__init__() - self.classes = classes + self.declarations = declarations class ClassDeclarationNode(Node): diff --git a/src/utils/errors.py b/src/utils/errors.py index c3691bd83..84389f6fe 100644 --- a/src/utils/errors.py +++ b/src/utils/errors.py @@ -1,4 +1,4 @@ -class CoolError(): +class CoolError(Exception): def __init__(self, error_type, text, line, column): self.type = error_type self.text = text From cd49676ba907775b268bd9f5657c3005d0369106 Mon Sep 17 00:00:00 2001 From: cwjki Date: Sat, 19 Feb 2022 16:01:01 -0500 Subject: [PATCH 108/194] adding positions to params --- src/semantic/visitors/typeBuilder.py | 31 +++++++++++++++++++++++--- src/semantic/visitors/typeCollector.py | 2 +- src/utils/ast.py | 2 +- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/semantic/visitors/typeBuilder.py b/src/semantic/visitors/typeBuilder.py index 44104d175..819c509d6 100644 --- a/src/semantic/visitors/typeBuilder.py +++ b/src/semantic/visitors/typeBuilder.py @@ -25,7 +25,7 @@ def visit(self, classDeclarationNode): try: self.currentType = self.context.get_type( classDeclarationNode.name, (classDeclarationNode.line, classDeclarationNode.column)) - except Exception as error: + except SemanticError as error: self.currentType = ErrorType self.errors.append(error) @@ -50,10 +50,35 @@ def visit(self, classDeclarationNode): raise SemanticError( errorText, classDeclarationNode.line, classDeclarationNode.column) current = current.parent - except Exception as error: + except SemanticError as error: parent = ErrorType() - self.errors.append(e) + self.errors.append(error) + self.currentType.set_parent(parent) for feature in classDeclarationNode.features: self.visit(feature) + + + @visit.when(FuncDeclarationNode) + def visit(self, funcDeclarationNode): + argsNames = [] + argsTypes = [] + for name, typex in funcDeclarationNode.params: + if name.value in argsNames: + errorText = f'Formal parameter {name} is multiply defined.' + self.errors.append(SemanticError(errorText, funcDeclarationNode.line, funcDeclarationNode.column)) + + argsNames.append(name) + + try: + argsTypes = self.context.get_type(typex.value, funcDeclarationNode.line, funcDeclarationNode.column) + except SemanticError: + errorText = f'Class {typex.value} of formal parameter {typex.value} is undefined.' + self.errors.append(SemanticError(errorText, funcDeclarationNode.line, funcDeclarationNode.column)) + argType = ErrorType() + + argsTypes.append(argType) + + + diff --git a/src/semantic/visitors/typeCollector.py b/src/semantic/visitors/typeCollector.py index 3330e205a..a106e3bbd 100644 --- a/src/semantic/visitors/typeCollector.py +++ b/src/semantic/visitors/typeCollector.py @@ -35,7 +35,7 @@ def visit(self, classDeclarationNode): try: self.context.create_type( classDeclarationNode.name, (classDeclarationNode.line, classDeclarationNode.column)) - except Exception as error: + except SemanticError as error: self.errors.append(error) if not classDeclarationNode.parent: diff --git a/src/utils/ast.py b/src/utils/ast.py index 9774d9129..25be27181 100644 --- a/src/utils/ast.py +++ b/src/utils/ast.py @@ -26,7 +26,7 @@ class FuncDeclarationNode(Node): def __init__(self, name, params, return_type, expr=None): super().__init__() self.name = name - self.params = params + self.params = [(pname.value, ptype.value, ptype.lineno, ptype.column) for pname, ptype in params] self.return_type = return_type self.expr = expr From 4466c3cdb0fad437cfc9f66fb9cb6eab7e0ea83d Mon Sep 17 00:00:00 2001 From: cwjki Date: Sat, 19 Feb 2022 18:29:07 -0500 Subject: [PATCH 109/194] changing str for lexToken to save the position of params --- src/cparser/parsetab.py | 104 +++++++------- src/main.py | 2 +- src/semantic/visitors/typeBuilder.py | 8 +- src/utils/ast.py | 203 ++++++++++++++++----------- 4 files changed, 176 insertions(+), 141 deletions(-) diff --git a/src/cparser/parsetab.py b/src/cparser/parsetab.py index 62804adfa..2098fe1a9 100644 --- a/src/cparser/parsetab.py +++ b/src/cparser/parsetab.py @@ -6,9 +6,9 @@ _lr_method = 'LALR' -_lr_signature = 'programARROW ASSIGN AT BOOL CASE CLASS COLON COMMA DIV DOT ELSE EQUAL ESAC FI ID IF IN INHERITS INT ISVOID LBRACE LESS LESSEQ LET LNOT LOOP LPAREN MINUS NEW NOT OF PLUS POOL RBRACE RPAREN SEMICOLON STAR STRING THEN TYPE WHILEprogram : class_listepsilon :class_list : def_class SEMICOLON class_list\n | def_class SEMICOLON def_class : CLASS TYPE LBRACE feature_list RBRACE\n | CLASS TYPE INHERITS TYPE LBRACE feature_list RBRACEfeature_list : def_attr SEMICOLON feature_list\n | def_func SEMICOLON feature_list\n | epsilondef_attr : ID COLON TYPE\n | ID COLON TYPE ASSIGN exprdef_func : ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACEparams : param_list\n | param_list_emptyparam_list : param\n | param COMMA param_listparam_list_empty : epsilonparam : ID COLON TYPElet_list : let_assign\n | let_assign COMMA let_listlet_assign : param ASSIGN expr\n | paramexpr : LET let_attrs IN expr\n | CASE expr OF case_list ESAC\n | IF expr THEN expr ELSE expr FI\n | WHILE expr LOOP expr POOLexpr : ID ASSIGN exprexpr : expr AT TYPE DOT ID LPAREN args RPAREN\n | expr DOT ID LPAREN args RPAREN\n | ID LPAREN args RPARENexpr : expr PLUS expr\n | expr MINUS expr\n | expr STAR expr\n | expr DIV expr\n | expr LESS expr\n | expr LESSEQ expr\n | expr EQUAL exprexpr : NOT expr\n | ISVOID expr\n | LNOT exprexpr : LPAREN expr RPARENexpr : atomlet_attrs : def_attr\n | def_attr COMMA let_attrscase_list : case_option SEMICOLON\n | case_option SEMICOLON case_listcase_option : ID COLON TYPE ARROW exprargs : arg_list\n | arg_list_emptyarg_list : expr\n | expr COMMA arg_listarg_list_empty : epsilonatom : INTatom : IDatom : BOOLatom : STRINGatom : NEW TYPEatom : blockblock : LBRACE block_list RBRACE block_list : expr SEMICOLON\n | expr SEMICOLON block_list' +_lr_signature = 'programARROW ASSIGN AT BOOL CASE CLASS COLON COMMA DIV DOT ELSE EQUAL ESAC FI ID IF IN INHERITS INT ISVOID LBRACE LESS LESSEQ LET LNOT LOOP LPAREN MINUS NEW NOT OF PLUS POOL RBRACE RPAREN SEMICOLON STAR STRING THEN TYPE WHILEprogram : class_listepsilon :class_list : def_class SEMICOLON class_list\n | def_class SEMICOLON def_class : CLASS TYPE LBRACE feature_list RBRACE\n | CLASS TYPE INHERITS TYPE LBRACE feature_list RBRACEfeature_list : def_attr SEMICOLON feature_list\n | def_func SEMICOLON feature_list\n | epsilondef_attr : ID COLON TYPE\n | ID COLON TYPE ASSIGN exprdef_func : ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACEparams : param_list\n | param_list_emptyparam_list : param\n | param COMMA param_listparam_list_empty : epsilonparam : ID COLON TYPEexpr : LET let_attrs IN expr\n | CASE expr OF case_list ESAC\n | IF expr THEN expr ELSE expr FI\n | WHILE expr LOOP expr POOLexpr : ID ASSIGN exprexpr : expr AT TYPE DOT ID LPAREN args RPAREN\n | expr DOT ID LPAREN args RPAREN\n | ID LPAREN args RPARENexpr : expr PLUS expr\n | expr MINUS expr\n | expr STAR expr\n | expr DIV expr\n | expr LESS expr\n | expr LESSEQ expr\n | expr EQUAL exprexpr : NOT expr\n | ISVOID expr\n | LNOT exprexpr : LPAREN expr RPARENexpr : atomlet_attrs : def_attr\n | def_attr COMMA let_attrscase_list : case_option SEMICOLON\n | case_option SEMICOLON case_listcase_option : ID COLON TYPE ARROW exprargs : arg_list\n | arg_list_emptyarg_list : expr\n | expr COMMA arg_listarg_list_empty : epsilonatom : INTatom : IDatom : BOOLatom : STRINGatom : NEW TYPEatom : blockblock : LBRACE block_list RBRACE block_list : expr SEMICOLON\n | expr SEMICOLON block_list' -_lr_action_items = {'CLASS':([0,5,],[4,4,]),'$end':([1,2,5,7,],[0,-1,-4,-3,]),'SEMICOLON':([3,11,12,16,24,36,37,38,47,48,49,50,52,75,76,77,78,80,82,90,91,92,93,94,95,96,102,103,106,110,113,122,126,127,129,135,136,137,],[5,17,18,-5,-10,-6,-54,-11,-42,-53,-55,-56,-58,-38,-39,-40,-57,104,-27,-31,-32,-33,-34,-35,-36,-37,-41,-59,-30,-23,123,-24,-26,-12,-29,-25,-28,-47,]),'TYPE':([4,9,19,33,51,55,59,124,],[6,15,24,54,78,81,88,131,]),'LBRACE':([6,15,32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,81,97,100,101,104,105,107,109,125,128,134,],[8,21,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,105,53,53,53,53,53,53,53,53,53,53,]),'INHERITS':([6,],[9,]),'ID':([8,17,18,20,21,32,35,39,40,41,42,43,44,45,46,53,57,58,60,61,62,63,64,65,66,67,97,98,99,100,101,104,105,107,108,109,123,125,128,134,],[14,14,14,25,14,37,25,70,37,37,37,37,37,37,37,37,37,37,89,37,37,37,37,37,37,37,37,70,114,37,37,37,37,37,120,37,114,37,37,37,]),'RBRACE':([8,10,13,17,18,21,22,23,31,37,47,48,49,50,52,75,76,77,78,79,82,90,91,92,93,94,95,96,102,103,104,106,110,117,118,122,126,129,135,136,],[-2,16,-9,-2,-2,-2,-7,-8,36,-54,-42,-53,-55,-56,-58,-38,-39,-40,-57,103,-27,-31,-32,-33,-34,-35,-36,-37,-41,-59,-60,-30,-23,-61,127,-24,-26,-29,-25,-28,]),'COLON':([14,25,34,70,114,],[19,33,55,19,124,]),'LPAREN':([14,32,37,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,89,97,100,101,104,105,107,109,120,125,128,134,],[20,43,58,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,109,43,43,43,43,43,43,43,128,43,43,43,]),'RPAREN':([20,26,27,28,29,30,37,47,48,49,50,52,54,56,58,74,75,76,77,78,82,83,84,85,86,87,90,91,92,93,94,95,96,102,103,106,109,110,119,121,122,126,128,129,133,135,136,],[-2,34,-13,-14,-15,-17,-54,-42,-53,-55,-56,-58,-18,-16,-2,102,-38,-39,-40,-57,-27,106,-48,-49,-50,-52,-31,-32,-33,-34,-35,-36,-37,-41,-59,-30,-2,-23,-51,129,-24,-26,-2,-29,136,-25,-28,]),'COMMA':([24,29,37,38,47,48,49,50,52,54,69,75,76,77,78,82,86,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-10,35,-54,-11,-42,-53,-55,-56,-58,-18,98,-38,-39,-40,-57,-27,107,-31,-32,-33,-34,-35,-36,-37,-41,-59,-30,-23,-24,-26,-29,-25,-28,]),'IN':([24,37,38,47,48,49,50,52,68,69,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,111,122,126,129,135,136,],[-10,-54,-11,-42,-53,-55,-56,-58,97,-43,-38,-39,-40,-57,-27,-31,-32,-33,-34,-35,-36,-37,-41,-59,-30,-23,-44,-24,-26,-29,-25,-28,]),'ASSIGN':([24,37,],[32,57,]),'LET':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,]),'CASE':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,]),'IF':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,]),'WHILE':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,]),'NOT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,]),'ISVOID':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,]),'LNOT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,]),'INT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,]),'BOOL':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,]),'STRING':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,]),'NEW':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,]),'AT':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-54,59,-42,-53,-55,-56,-58,59,59,59,59,59,59,59,-57,59,59,59,59,59,59,59,59,59,59,-41,-59,-30,59,59,59,59,-24,-26,-29,59,-25,-28,59,]),'DOT':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,88,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-54,60,-42,-53,-55,-56,-58,60,60,60,60,60,60,60,-57,60,60,60,108,60,60,60,60,60,60,60,-41,-59,-30,60,60,60,60,-24,-26,-29,60,-25,-28,60,]),'PLUS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-54,61,-42,-53,-55,-56,-58,61,61,61,61,61,61,61,-57,61,61,61,61,61,61,61,61,61,61,-41,-59,-30,61,61,61,61,-24,-26,-29,61,-25,-28,61,]),'MINUS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-54,62,-42,-53,-55,-56,-58,62,62,62,62,62,62,62,-57,62,62,62,62,62,62,62,62,62,62,-41,-59,-30,62,62,62,62,-24,-26,-29,62,-25,-28,62,]),'STAR':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-54,63,-42,-53,-55,-56,-58,63,63,63,63,63,63,63,-57,63,63,63,63,63,63,63,63,63,63,-41,-59,-30,63,63,63,63,-24,-26,-29,63,-25,-28,63,]),'DIV':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-54,64,-42,-53,-55,-56,-58,64,64,64,64,64,64,64,-57,64,64,64,64,64,64,64,64,64,64,-41,-59,-30,64,64,64,64,-24,-26,-29,64,-25,-28,64,]),'LESS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-54,65,-42,-53,-55,-56,-58,65,65,65,65,65,65,65,-57,65,65,65,65,65,65,65,65,65,65,-41,-59,-30,65,65,65,65,-24,-26,-29,65,-25,-28,65,]),'LESSEQ':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-54,66,-42,-53,-55,-56,-58,66,66,66,66,66,66,66,-57,66,66,66,66,66,66,66,66,66,66,-41,-59,-30,66,66,66,66,-24,-26,-29,66,-25,-28,66,]),'EQUAL':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-54,67,-42,-53,-55,-56,-58,67,67,67,67,67,67,67,-57,67,67,67,67,67,67,67,67,67,67,-41,-59,-30,67,67,67,67,-24,-26,-29,67,-25,-28,67,]),'OF':([37,47,48,49,50,52,71,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-54,-42,-53,-55,-56,-58,99,-38,-39,-40,-57,-27,-31,-32,-33,-34,-35,-36,-37,-41,-59,-30,-23,-24,-26,-29,-25,-28,]),'THEN':([37,47,48,49,50,52,72,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-54,-42,-53,-55,-56,-58,100,-38,-39,-40,-57,-27,-31,-32,-33,-34,-35,-36,-37,-41,-59,-30,-23,-24,-26,-29,-25,-28,]),'LOOP':([37,47,48,49,50,52,73,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-54,-42,-53,-55,-56,-58,101,-38,-39,-40,-57,-27,-31,-32,-33,-34,-35,-36,-37,-41,-59,-30,-23,-24,-26,-29,-25,-28,]),'ELSE':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,115,122,126,129,135,136,],[-54,-42,-53,-55,-56,-58,-38,-39,-40,-57,-27,-31,-32,-33,-34,-35,-36,-37,-41,-59,-30,-23,125,-24,-26,-29,-25,-28,]),'POOL':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,116,122,126,129,135,136,],[-54,-42,-53,-55,-56,-58,-38,-39,-40,-57,-27,-31,-32,-33,-34,-35,-36,-37,-41,-59,-30,-23,126,-24,-26,-29,-25,-28,]),'FI':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,132,135,136,],[-54,-42,-53,-55,-56,-58,-38,-39,-40,-57,-27,-31,-32,-33,-34,-35,-36,-37,-41,-59,-30,-23,-24,-26,-29,135,-25,-28,]),'ESAC':([112,123,130,],[122,-45,-46,]),'ARROW':([131,],[134,]),} +_lr_action_items = {'CLASS':([0,5,],[4,4,]),'$end':([1,2,5,7,],[0,-1,-4,-3,]),'SEMICOLON':([3,11,12,16,24,36,37,38,47,48,49,50,52,75,76,77,78,80,82,90,91,92,93,94,95,96,102,103,106,110,113,122,126,127,129,135,136,137,],[5,17,18,-5,-10,-6,-50,-11,-38,-49,-51,-52,-54,-34,-35,-36,-53,104,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,123,-20,-22,-12,-25,-21,-24,-43,]),'TYPE':([4,9,19,33,51,55,59,124,],[6,15,24,54,78,81,88,131,]),'LBRACE':([6,15,32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,81,97,100,101,104,105,107,109,125,128,134,],[8,21,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,105,53,53,53,53,53,53,53,53,53,53,]),'INHERITS':([6,],[9,]),'ID':([8,17,18,20,21,32,35,39,40,41,42,43,44,45,46,53,57,58,60,61,62,63,64,65,66,67,97,98,99,100,101,104,105,107,108,109,123,125,128,134,],[14,14,14,25,14,37,25,70,37,37,37,37,37,37,37,37,37,37,89,37,37,37,37,37,37,37,37,70,114,37,37,37,37,37,120,37,114,37,37,37,]),'RBRACE':([8,10,13,17,18,21,22,23,31,37,47,48,49,50,52,75,76,77,78,79,82,90,91,92,93,94,95,96,102,103,104,106,110,117,118,122,126,129,135,136,],[-2,16,-9,-2,-2,-2,-7,-8,36,-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,103,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-56,-26,-19,-57,127,-20,-22,-25,-21,-24,]),'COLON':([14,25,34,70,114,],[19,33,55,19,124,]),'LPAREN':([14,32,37,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,89,97,100,101,104,105,107,109,120,125,128,134,],[20,43,58,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,109,43,43,43,43,43,43,43,128,43,43,43,]),'RPAREN':([20,26,27,28,29,30,37,47,48,49,50,52,54,56,58,74,75,76,77,78,82,83,84,85,86,87,90,91,92,93,94,95,96,102,103,106,109,110,119,121,122,126,128,129,133,135,136,],[-2,34,-13,-14,-15,-17,-50,-38,-49,-51,-52,-54,-18,-16,-2,102,-34,-35,-36,-53,-23,106,-44,-45,-46,-48,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-2,-19,-47,129,-20,-22,-2,-25,136,-21,-24,]),'COMMA':([24,29,37,38,47,48,49,50,52,54,69,75,76,77,78,82,86,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-10,35,-50,-11,-38,-49,-51,-52,-54,-18,98,-34,-35,-36,-53,-23,107,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'IN':([24,37,38,47,48,49,50,52,68,69,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,111,122,126,129,135,136,],[-10,-50,-11,-38,-49,-51,-52,-54,97,-39,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-40,-20,-22,-25,-21,-24,]),'ASSIGN':([24,37,],[32,57,]),'LET':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,]),'CASE':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,]),'IF':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,]),'WHILE':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,]),'NOT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,]),'ISVOID':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,]),'LNOT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,]),'INT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,]),'BOOL':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,]),'STRING':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,]),'NEW':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,]),'AT':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,59,-38,-49,-51,-52,-54,59,59,59,59,59,59,59,-53,59,59,59,59,59,59,59,59,59,59,-37,-55,-26,59,59,59,59,-20,-22,-25,59,-21,-24,59,]),'DOT':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,88,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,60,-38,-49,-51,-52,-54,60,60,60,60,60,60,60,-53,60,60,60,108,60,60,60,60,60,60,60,-37,-55,-26,60,60,60,60,-20,-22,-25,60,-21,-24,60,]),'PLUS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,61,-38,-49,-51,-52,-54,61,61,61,61,61,61,61,-53,61,61,61,61,61,61,61,61,61,61,-37,-55,-26,61,61,61,61,-20,-22,-25,61,-21,-24,61,]),'MINUS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,62,-38,-49,-51,-52,-54,62,62,62,62,62,62,62,-53,62,62,62,62,62,62,62,62,62,62,-37,-55,-26,62,62,62,62,-20,-22,-25,62,-21,-24,62,]),'STAR':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,63,-38,-49,-51,-52,-54,63,63,63,63,63,63,63,-53,63,63,63,63,63,63,63,63,63,63,-37,-55,-26,63,63,63,63,-20,-22,-25,63,-21,-24,63,]),'DIV':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,64,-38,-49,-51,-52,-54,64,64,64,64,64,64,64,-53,64,64,64,64,64,64,64,64,64,64,-37,-55,-26,64,64,64,64,-20,-22,-25,64,-21,-24,64,]),'LESS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,65,-38,-49,-51,-52,-54,65,65,65,65,65,65,65,-53,65,65,65,65,65,65,65,65,65,65,-37,-55,-26,65,65,65,65,-20,-22,-25,65,-21,-24,65,]),'LESSEQ':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,66,-38,-49,-51,-52,-54,66,66,66,66,66,66,66,-53,66,66,66,66,66,66,66,66,66,66,-37,-55,-26,66,66,66,66,-20,-22,-25,66,-21,-24,66,]),'EQUAL':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,67,-38,-49,-51,-52,-54,67,67,67,67,67,67,67,-53,67,67,67,67,67,67,67,67,67,67,-37,-55,-26,67,67,67,67,-20,-22,-25,67,-21,-24,67,]),'OF':([37,47,48,49,50,52,71,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,99,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'THEN':([37,47,48,49,50,52,72,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,100,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'LOOP':([37,47,48,49,50,52,73,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,101,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'ELSE':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,115,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,125,-20,-22,-25,-21,-24,]),'POOL':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,116,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,126,-20,-22,-25,-21,-24,]),'FI':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,132,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,135,-21,-24,]),'ESAC':([112,123,130,],[122,-41,-42,]),'ARROW':([131,],[134,]),} _lr_action = {} for _k, _v in _lr_action_items.items(): @@ -29,34 +29,30 @@ ("S' -> program","S'",1,None,None,None), ('program -> class_list','program',1,'p_program','parser.py',28), ('epsilon -> ','epsilon',0,'p_epsilon','parser.py',32), - ('class_list -> def_class SEMICOLON class_list','class_list',3,'p_class_list','parser.py',36), - ('class_list -> def_class SEMICOLON','class_list',2,'p_class_list','parser.py',37), - ('def_class -> CLASS TYPE LBRACE feature_list RBRACE','def_class',5,'p_def_class','parser.py',41), - ('def_class -> CLASS TYPE INHERITS TYPE LBRACE feature_list RBRACE','def_class',7,'p_def_class','parser.py',42), - ('feature_list -> def_attr SEMICOLON feature_list','feature_list',3,'p_feature_list','parser.py',50), - ('feature_list -> def_func SEMICOLON feature_list','feature_list',3,'p_feature_list','parser.py',51), - ('feature_list -> epsilon','feature_list',1,'p_feature_list','parser.py',52), - ('def_attr -> ID COLON TYPE','def_attr',3,'p_def_attr','parser.py',56), - ('def_attr -> ID COLON TYPE ASSIGN expr','def_attr',5,'p_def_attr','parser.py',57), - ('def_func -> ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACE','def_func',9,'p_def_func','parser.py',65), - ('params -> param_list','params',1,'p_params','parser.py',69), - ('params -> param_list_empty','params',1,'p_params','parser.py',70), - ('param_list -> param','param_list',1,'p_param_list','parser.py',74), - ('param_list -> param COMMA param_list','param_list',3,'p_param_list','parser.py',75), - ('param_list_empty -> epsilon','param_list_empty',1,'p_param_list_empty','parser.py',79), - ('param -> ID COLON TYPE','param',3,'p_param','parser.py',83), - ('let_list -> let_assign','let_list',1,'p_let_list','parser.py',88), - ('let_list -> let_assign COMMA let_list','let_list',3,'p_let_list','parser.py',89), - ('let_assign -> param ASSIGN expr','let_assign',3,'p_let_assign','parser.py',93), - ('let_assign -> param','let_assign',1,'p_let_assign','parser.py',94), - ('expr -> LET let_attrs IN expr','expr',4,'p_expr_flow','parser.py',101), - ('expr -> CASE expr OF case_list ESAC','expr',5,'p_expr_flow','parser.py',102), - ('expr -> IF expr THEN expr ELSE expr FI','expr',7,'p_expr_flow','parser.py',103), - ('expr -> WHILE expr LOOP expr POOL','expr',5,'p_expr_flow','parser.py',104), - ('expr -> ID ASSIGN expr','expr',3,'p_expr_assign','parser.py',117), - ('expr -> expr AT TYPE DOT ID LPAREN args RPAREN','expr',8,'p_expr_func_call','parser.py',123), - ('expr -> expr DOT ID LPAREN args RPAREN','expr',6,'p_expr_func_call','parser.py',124), - ('expr -> ID LPAREN args RPAREN','expr',4,'p_expr_func_call','parser.py',125), + ('class_list -> def_class SEMICOLON class_list','class_list',3,'p_class_list','parser.py',35), + ('class_list -> def_class SEMICOLON','class_list',2,'p_class_list','parser.py',36), + ('def_class -> CLASS TYPE LBRACE feature_list RBRACE','def_class',5,'p_def_class','parser.py',40), + ('def_class -> CLASS TYPE INHERITS TYPE LBRACE feature_list RBRACE','def_class',7,'p_def_class','parser.py',41), + ('feature_list -> def_attr SEMICOLON feature_list','feature_list',3,'p_feature_list','parser.py',51), + ('feature_list -> def_func SEMICOLON feature_list','feature_list',3,'p_feature_list','parser.py',52), + ('feature_list -> epsilon','feature_list',1,'p_feature_list','parser.py',53), + ('def_attr -> ID COLON TYPE','def_attr',3,'p_def_attr','parser.py',57), + ('def_attr -> ID COLON TYPE ASSIGN expr','def_attr',5,'p_def_attr','parser.py',58), + ('def_func -> ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACE','def_func',9,'p_def_func','parser.py',68), + ('params -> param_list','params',1,'p_params','parser.py',74), + ('params -> param_list_empty','params',1,'p_params','parser.py',75), + ('param_list -> param','param_list',1,'p_param_list','parser.py',79), + ('param_list -> param COMMA param_list','param_list',3,'p_param_list','parser.py',80), + ('param_list_empty -> epsilon','param_list_empty',1,'p_param_list_empty','parser.py',84), + ('param -> ID COLON TYPE','param',3,'p_param','parser.py',88), + ('expr -> LET let_attrs IN expr','expr',4,'p_expr_flow','parser.py',92), + ('expr -> CASE expr OF case_list ESAC','expr',5,'p_expr_flow','parser.py',93), + ('expr -> IF expr THEN expr ELSE expr FI','expr',7,'p_expr_flow','parser.py',94), + ('expr -> WHILE expr LOOP expr POOL','expr',5,'p_expr_flow','parser.py',95), + ('expr -> ID ASSIGN expr','expr',3,'p_expr_assign','parser.py',110), + ('expr -> expr AT TYPE DOT ID LPAREN args RPAREN','expr',8,'p_expr_func_call','parser.py',116), + ('expr -> expr DOT ID LPAREN args RPAREN','expr',6,'p_expr_func_call','parser.py',117), + ('expr -> ID LPAREN args RPAREN','expr',4,'p_expr_func_call','parser.py',118), ('expr -> expr PLUS expr','expr',3,'p_expr_operators_binary','parser.py',141), ('expr -> expr MINUS expr','expr',3,'p_expr_operators_binary','parser.py',142), ('expr -> expr STAR expr','expr',3,'p_expr_operators_binary','parser.py',143), @@ -64,28 +60,28 @@ ('expr -> expr LESS expr','expr',3,'p_expr_operators_binary','parser.py',145), ('expr -> expr LESSEQ expr','expr',3,'p_expr_operators_binary','parser.py',146), ('expr -> expr EQUAL expr','expr',3,'p_expr_operators_binary','parser.py',147), - ('expr -> NOT expr','expr',2,'p_expr_operators_unary','parser.py',165), - ('expr -> ISVOID expr','expr',2,'p_expr_operators_unary','parser.py',166), - ('expr -> LNOT expr','expr',2,'p_expr_operators_unary','parser.py',167), - ('expr -> LPAREN expr RPAREN','expr',3,'p_expr_group','parser.py',177), - ('expr -> atom','expr',1,'p_expr_atom','parser.py',181), - ('let_attrs -> def_attr','let_attrs',1,'p_let_attrs','parser.py',185), - ('let_attrs -> def_attr COMMA let_attrs','let_attrs',3,'p_let_attrs','parser.py',186), - ('case_list -> case_option SEMICOLON','case_list',2,'p_case_list','parser.py',190), - ('case_list -> case_option SEMICOLON case_list','case_list',3,'p_case_list','parser.py',191), - ('case_option -> ID COLON TYPE ARROW expr','case_option',5,'p_case_option','parser.py',195), - ('args -> arg_list','args',1,'p_args','parser.py',199), - ('args -> arg_list_empty','args',1,'p_args','parser.py',200), - ('arg_list -> expr','arg_list',1,'p_arg_list','parser.py',204), - ('arg_list -> expr COMMA arg_list','arg_list',3,'p_arg_list','parser.py',205), - ('arg_list_empty -> epsilon','arg_list_empty',1,'p_arg_list_empty','parser.py',209), - ('atom -> INT','atom',1,'p_atom_int','parser.py',213), - ('atom -> ID','atom',1,'p_atom_id','parser.py',217), - ('atom -> BOOL','atom',1,'p_atom_bool','parser.py',221), - ('atom -> STRING','atom',1,'p_atom_string','parser.py',226), - ('atom -> NEW TYPE','atom',2,'p_atom_new','parser.py',231), - ('atom -> block','atom',1,'p_atom_block','parser.py',236), - ('block -> LBRACE block_list RBRACE','block',3,'p_block','parser.py',240), - ('block_list -> expr SEMICOLON','block_list',2,'p_block_list','parser.py',244), - ('block_list -> expr SEMICOLON block_list','block_list',3,'p_block_list','parser.py',245), + ('expr -> NOT expr','expr',2,'p_expr_operators_unary','parser.py',167), + ('expr -> ISVOID expr','expr',2,'p_expr_operators_unary','parser.py',168), + ('expr -> LNOT expr','expr',2,'p_expr_operators_unary','parser.py',169), + ('expr -> LPAREN expr RPAREN','expr',3,'p_expr_group','parser.py',181), + ('expr -> atom','expr',1,'p_expr_atom','parser.py',185), + ('let_attrs -> def_attr','let_attrs',1,'p_let_attrs','parser.py',189), + ('let_attrs -> def_attr COMMA let_attrs','let_attrs',3,'p_let_attrs','parser.py',190), + ('case_list -> case_option SEMICOLON','case_list',2,'p_case_list','parser.py',194), + ('case_list -> case_option SEMICOLON case_list','case_list',3,'p_case_list','parser.py',195), + ('case_option -> ID COLON TYPE ARROW expr','case_option',5,'p_case_option','parser.py',199), + ('args -> arg_list','args',1,'p_args','parser.py',205), + ('args -> arg_list_empty','args',1,'p_args','parser.py',206), + ('arg_list -> expr','arg_list',1,'p_arg_list','parser.py',210), + ('arg_list -> expr COMMA arg_list','arg_list',3,'p_arg_list','parser.py',211), + ('arg_list_empty -> epsilon','arg_list_empty',1,'p_arg_list_empty','parser.py',215), + ('atom -> INT','atom',1,'p_atom_int','parser.py',219), + ('atom -> ID','atom',1,'p_atom_id','parser.py',225), + ('atom -> BOOL','atom',1,'p_atom_bool','parser.py',231), + ('atom -> STRING','atom',1,'p_atom_string','parser.py',237), + ('atom -> NEW TYPE','atom',2,'p_atom_new','parser.py',243), + ('atom -> block','atom',1,'p_atom_block','parser.py',249), + ('block -> LBRACE block_list RBRACE','block',3,'p_block','parser.py',253), + ('block_list -> expr SEMICOLON','block_list',2,'p_block_list','parser.py',257), + ('block_list -> expr SEMICOLON block_list','block_list',3,'p_block_list','parser.py',258), ] diff --git a/src/main.py b/src/main.py index 13c95ca94..9a35c7f18 100644 --- a/src/main.py +++ b/src/main.py @@ -25,7 +25,7 @@ def main(_input, _output): if __name__ == "__main__": - path = '/home/cwjki/Projects/cool-compiler-2021/tests/parser/assignment1.cl' + path = '/home/cwjki/Projects/cool-compiler-2021/tests/parser/conditional4.cl' _input = sys.argv[1] if len(sys.argv) > 1 else path _output = sys.argv[2] if len(sys.argv) > 2 else None diff --git a/src/semantic/visitors/typeBuilder.py b/src/semantic/visitors/typeBuilder.py index 819c509d6..05a8c5224 100644 --- a/src/semantic/visitors/typeBuilder.py +++ b/src/semantic/visitors/typeBuilder.py @@ -65,7 +65,7 @@ def visit(self, funcDeclarationNode): argsNames = [] argsTypes = [] for name, typex in funcDeclarationNode.params: - if name.value in argsNames: + if name in argsNames: errorText = f'Formal parameter {name} is multiply defined.' self.errors.append(SemanticError(errorText, funcDeclarationNode.line, funcDeclarationNode.column)) @@ -77,8 +77,12 @@ def visit(self, funcDeclarationNode): errorText = f'Class {typex.value} of formal parameter {typex.value} is undefined.' self.errors.append(SemanticError(errorText, funcDeclarationNode.line, funcDeclarationNode.column)) argType = ErrorType() - + argsTypes.append(argType) + + try: + returnType = self.context.get_type(funcDeclarationNode.return_type, ) + except SemanticError as error: diff --git a/src/utils/ast.py b/src/utils/ast.py index 25be27181..32dfb813d 100644 --- a/src/utils/ast.py +++ b/src/utils/ast.py @@ -1,128 +1,157 @@ -class Node(): - def __init__(self): - self.line = 0 - self.column = 0 +from cmath import exp +from select import select + - def add_line_column(self, line, column): - self.line = line - self.column = column +class Node(): + pass class ProgramNode(Node): def __init__(self, declarations): - super().__init__() self.declarations = declarations -class ClassDeclarationNode(Node): - def __init__(self, name, features, parent=None): - super().__init__() - self.name = name - self.features = features - self.parent = parent +class DeclarationNode(Node): + pass -class FuncDeclarationNode(Node): - def __init__(self, name, params, return_type, expr=None): - super().__init__() - self.name = name - self.params = [(pname.value, ptype.value, ptype.lineno, ptype.column) for pname, ptype in params] - self.return_type = return_type - self.expr = expr +class ClassDeclarationNode(DeclarationNode): + def __init__(self, idx, features, parent): + self.id = idx.value + self.line = idx.lineno + self.col = idx.column + self.features = features + if parent: + self.parent = parent.value + self.parentLine = parent.lineno + self.parentCol = parent.column + else: + self.parent = None + self.parentLine = 0 + self.parentCol = 0 + + +class FuncDeclarationNode(DeclarationNode): + def __init__(self, idx, params, return_type, body): + self.id = idx.value + self.line = idx.lineno + self.col = idx.column + self.params = [(pname.value, ptype.value, ptype.lineno, + ptype.column) for pname, ptype in params] + self.type = return_type.value + self.typeLine = return_type.lineno + self.typeCol = return_type.col + self.body = body -class AttrDeclarationNode(Node): - def __init__(self, name, typex, expr=None): - super().__init__() - self.name = name - self.type = typex +class AttrDeclarationNode(DeclarationNode): + def __init__(self, idx, typex, expr=None): + self.id = idx.value + self.line = idx.lineno + self.col = idx.column + self.type = typex.value + self.typeLine = typex.lineno + self.typeCol = typex.col self.expr = expr class ExpressionNode(Node): - def __init__(self): - super().__init__() - self.computed_type = None + pass class AssignNode(ExpressionNode): - def __init__(self, name, expr): - super().__init__() - self.name = name + def __init__(self, idx, expr): + self.id = idx.value + self.line = idx.lineno + self.col = idx.column self.expr = expr class FuncCallNode(ExpressionNode): - def __init__(self, idx, args, obj=None, typex=None): - super().__init__() - self.id = idx + def __init__(self, obj, idx, args, typex): + self.obj = obj + self.id = idx.value + self.line = idx.lineno + self.col = idx.column self.args = args - self.object = obj - self.type = typex + self.type = typex.value + self.typeLine = typex.lineno + self.typeCol = typex.col + +class MemberCallNode(ExpressionNode): + def __init__(self, idx, args): + self.id = idx.value + self.line = idx.lineno + self.col = idx.column + self.args = args -class IfNode(ExpressionNode): - def __init__(self, condition, then_expr, else_expr): - super().__init__() + +class IfThenElseNode(ExpressionNode): + def __init__(self, condition, ifBody, elseBody, token): self.condition = condition - self.then_expr = then_expr - self.else_expr = else_expr + self.ifBody = ifBody + self.elseBody = elseBody + self.line = token.lineno + self.col = token.column class WhileNode(ExpressionNode): - def __init__(self, condition, body): - super().__init__() + def __init__(self, condition, body, token): self.condition = condition self.body = body + self.line = token.lineno + self.col = token.column class BlockNode(ExpressionNode): - def __init__(self, exprs): - super().__init__() - self.exprs = exprs + def __init__(self, exprs, token): + self.expr = exprs + self.line = token.lineno + self.col = token.column -class LetNode(ExpressionNode): - def __init__(self, let_attrs, expr): - super().__init__() - self.let_attrs = let_attrs - self.expr = expr +class LetInNode(ExpressionNode): + def __init__(self, letBody, inBody, token): + self.letBody = letBody + self.inBody = inBody + self.line = token.lineno + self.col = token.column class CaseNode(ExpressionNode): - def __init__(self, expr, case_list): - super().__init__() + def __init__(self, expr, caseList, token): self.expr = expr - self.case_list = case_list + self.caseList = caseList + self.line = token.lineno + self.col = token.column class CaseOptionNode(ExpressionNode): def __init__(self, idx, typex, expr): - super().__init__() - self.id = idx - self.expr = expr - self.type = typex - - -class VarNode(ExpressionNode): - def __init__(self, idx): - super().__init__() - self.id = idx + self.id = idx.value + self.line = idx.lineno + self.col = idx.column + self.type = typex.value + self.typeLine = typex.lineno + self.typeCol = typex.col class NewNode(ExpressionNode): def __init__(self, typex): - super().__init__() - self.type = typex + self.type = typex.value + self.typeLine = typex.lineno + self.typeCol = typex.col + # ---------------- Binary Nodes ------------------ -# ---------------- Binary Nodes ------------------ class BinaryNode(ExpressionNode): def __init__(self, lvalue, rvalue): - super().__init__() self.lvalue = lvalue self.rvalue = rvalue + self.line = lvalue.line + self.col = lvalue.col class PlusNode(BinaryNode): @@ -156,9 +185,10 @@ class EqualNode(BinaryNode): # ---------------- Unary Nodes ------------------ class UnaryNode(ExpressionNode): - def __init__(self, value): - super().__init__() - self.value = value + def __init__(self, expr, token): + self.expr = expr + self.line = token.lineno + self.column = token.column class NegationNode(UnaryNode): @@ -169,29 +199,34 @@ class LogicNegationNode(UnaryNode): pass -class AtomicNode(UnaryNode): - pass - - class IsVoidNode(UnaryNode): pass -# ---------------- Constant Nodes ------------------ +# ---------------- Atomic Nodes ------------------ -class ConstantNode(ExpressionNode): - def __init__(self, value): - super().__init__() - self.value = value +class AtomicNode(ExpressionNode): + def __init__(self, token): + try: + self.id = token.value + self.line = token.lineno + self.col = token.col + except: + self.id = token + self.line = 0 + self.col = 0 -class IntNode(ConstantNode): +class IdNode(AtomicNode): + pass + +class IntNode(AtomicNode): pass -class BoolNode(ConstantNode): +class BoolNode(AtomicNode): pass -class StringNode(ConstantNode): +class StringNode(AtomicNode): pass From a563e665b84547042dbb1aea34b212bcbf742c1c Mon Sep 17 00:00:00 2001 From: cwjki Date: Sat, 19 Feb 2022 19:31:21 -0500 Subject: [PATCH 110/194] separate dotcall and arrobacall --- src/cparser/parser.py | 92 +++++++++++++------------------------------ src/utils/ast.py | 23 +++++++---- 2 files changed, 43 insertions(+), 72 deletions(-) diff --git a/src/cparser/parser.py b/src/cparser/parser.py index 068b91749..3c37de755 100644 --- a/src/cparser/parser.py +++ b/src/cparser/parser.py @@ -30,6 +30,7 @@ def p_program(self, p): def p_epsilon(self, p): 'epsilon :' + pass def p_class_list(self, p): '''class_list : def_class SEMICOLON class_list @@ -40,12 +41,9 @@ def p_def_class(self, p): '''def_class : CLASS TYPE LBRACE feature_list RBRACE | CLASS TYPE INHERITS TYPE LBRACE feature_list RBRACE''' if len(p) == 8: - p[0] = ClassDeclarationNode(p[2], p[6], p[4]) + p[0] = ClassDeclarationNode(p, slice[2], p[6], p.slice[4]) else: - p[0] = ClassDeclarationNode(p[2], p[4]) - - p[0].add_line_column(p.lineno(2), find_column( - p.lexer.lexdata, p.lexpos(2))) + p[0] = ClassDeclarationNode(p.slice[2], p[4]) def p_feature_list(self, p): '''feature_list : def_attr SEMICOLON feature_list @@ -57,18 +55,13 @@ def p_def_attr(self, p): '''def_attr : ID COLON TYPE | ID COLON TYPE ASSIGN expr''' if len(p) == 4: - p[0] = AttrDeclarationNode(p[1], p[3]) + p[0] = AttrDeclarationNode(p.slice[1], p.slice[3]) else: - p[0] = AttrDeclarationNode(p[1], p[3], p[5]) - - p[0].add_line_column(p.lineno(3), find_column( - p.lexer.lexdata, p.lexpos(3))) + p[0] = AttrDeclarationNode(p.slice[1], p.slice[3], p[5]) def p_def_func(self, p): '''def_func : ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACE''' - p[0] = FuncDeclarationNode(p[1], p[3], p[6], p[8]) - p[0].add_line_column(p.lineno(6), find_column( - p.lexer.lexdata, p.lexpos(6))) + p[0] = FuncDeclarationNode(p.slice[1], p[3], p.slice[6], p[8]) def p_params(self, p): '''params : param_list @@ -86,7 +79,7 @@ def p_param_list_empty(self, p): def p_param(self, p): '''param : ID COLON TYPE''' - p[0] = (p[1], p[3]) + p[0] = (p.slice[1], p.slice[3]) def p_expr_flow(self, p): '''expr : LET let_attrs IN expr @@ -95,22 +88,17 @@ def p_expr_flow(self, p): | WHILE expr LOOP expr POOL''' if p[1].lower() == 'let': - p[0] = LetNode(p[2], p[4]) + p[0] = LetInNode(p[2], p[4], p.slice[1]) elif p[1].lower() == 'case': - p[0] = CaseNode(p[2], p[4]) + p[0] = CaseNode(p[2], p[4], p.slice[1]) elif p[1].lower() == 'if': - p[0] = IfNode(p[2], p[4], p[6]) + p[0] = IfThenElseNode(p[2], p[4], p[6], p.slice[1]) elif p[1].lower() == 'while': - p[0] = WhileNode(p[2], p[4]) - - p[0].add_line_column(p.lineno(2), find_column( - p.lexer.lexdata, p.lexpos(2))) + p[0] = WhileNode(p[2], p[4], p.slice[1]) def p_expr_assign(self, p): '''expr : ID ASSIGN expr''' - p[0] = AssignNode(p[1], p[3]) - p[0].add_line_column(p.lineno(1), find_column( - p.lexer.lexdata, p.lexpos(1))) + p[0] = AssignNode(p.slice[1], p[3]) def p_expr_func_call(self, p): '''expr : expr AT TYPE DOT ID LPAREN args RPAREN @@ -119,23 +107,17 @@ def p_expr_func_call(self, p): if len(p) == 9: if p[7] is None: p[7] = [] - p[0] = FuncCallNode(p[5], p[7], p[1], p[3]) - p[0].add_line_column(p.lineno(5), find_column( - p.lexer.lexdata, p.lexpos(5))) + p[0] = ArrobaCallNode(p[1], p.slice[5], p[7], p.slice[3]) + elif len(p) == 7: if p[5] is None: p[5] = [] - p[0] = FuncCallNode(p[3], p[5], p[1]) - p[0].add_line_column(p.lineno(3), find_column( - p.lexer.lexdata, p.lexpos(3))) + p[0] = DotCallNode(p[1], p.slice[3], p[5]) + else: if p[3] is None: p[3] = [] - p[0] = FuncCallNode(p[1], p[3]) - p[0].add_line_column(p.lineno(1), find_column( - p.lexer.lexdata, p.lexpos(1))) - - p[0].lineno = p.lineno(0) + p[0] = MemberCallNode(p.slice[1], p[3]) def p_expr_operators_binary(self, p): '''expr : expr PLUS expr @@ -160,22 +142,16 @@ def p_expr_operators_binary(self, p): elif p[2] == '=': p[0] = EqualNode(p[1], p[3]) - p[0].add_line_column(p.lineno(0), find_column( - p.lexer.lexdata, p.lexpos(0))) - def p_expr_operators_unary(self, p): '''expr : NOT expr | ISVOID expr | LNOT expr''' if p[1] == '~': - p[0] = NegationNode(p[2]) + p[0] = NegationNode(p[2], p.slice[1]) elif p[1].lower() == 'isvoid': - p[0] = IsVoidNode(p[2]) + p[0] = IsVoidNode(p[2], p.slice[1]) elif p[1].lower() == 'not': - p[0] = LogicNegationNode(p[2]) - - p[0].add_line_column(p.lineno(2), find_column( - p.lexer.lexdata, p.lexpos(2))) + p[0] = LogicNegationNode(p[2], p.slice[1]) def p_expr_group(self, p): '''expr : LPAREN expr RPAREN''' @@ -197,9 +173,7 @@ def p_case_list(self, p): def p_case_option(self, p): '''case_option : ID COLON TYPE ARROW expr''' - p[0] = CaseOptionNode(p[1], p[3], p[5]) - p[0].add_line_column(p.lineno(3), find_column( - p.lexer.lexdata, p.lexpos(3))) + p[0] = CaseOptionNode(p.slice[1], p.slice[3], p[5]) def p_args(self, p): '''args : arg_list @@ -217,33 +191,23 @@ def p_arg_list_empty(self, p): def p_atom_int(self, p): '''atom : INT''' - p[0] = IntNode(int(p[1])) - p[0].add_line_column(p.lineno(1), find_column( - p.lexer.lexdata, p.lexpos(1))) + p[0] = IntNode(p.slice[1]) def p_atom_id(self, p): '''atom : ID''' - p[0] = VarNode(p[1]) - p[0].add_line_column(p.lineno(1), find_column( - p.lexer.lexdata, p.lexpos(1))) + p[0] = IdNode(p.slice[1]) def p_atom_bool(self, p): '''atom : BOOL''' - p[0] = BoolNode(p[1]) - p[0].add_line_column(p.lineno(1), find_column( - p.lexer.lexdata, p.lexpos(1))) + p[0] = BoolNode(p.slice[1]) def p_atom_string(self, p): '''atom : STRING''' - p[0] = StringNode(p[1]) - p[0].add_line_column(p.lineno(1), find_column( - p.lexer.lexdata, p.lexpos(1))) + p[0] = StringNode(p.slice[1]) def p_atom_new(self, p): '''atom : NEW TYPE''' - p[0] = NewNode(p[2]) - p[0].add_line_column(p.lineno(2), find_column( - p.lexer.lexdata, p.lexpos(2))) + p[0] = NewNode(p.slice[2]) def p_atom_block(self, p): '''atom : block''' @@ -256,8 +220,8 @@ def p_block(self, p): def p_block_list(self, p): ''' block_list : expr SEMICOLON | expr SEMICOLON block_list''' - p[0] = BlockNode([p[1]]) if len( - p) == 3 else BlockNode([p[1]] + p[3].exprs) + p[0] = BlockNode([p[1]], p.slice[1]) if len( + p) == 3 else BlockNode([p[1]] + p[3].exprs, p.slice[1]) def p_error(self, p): if p: diff --git a/src/utils/ast.py b/src/utils/ast.py index 32dfb813d..953810c22 100644 --- a/src/utils/ast.py +++ b/src/utils/ast.py @@ -67,7 +67,7 @@ def __init__(self, idx, expr): self.expr = expr -class FuncCallNode(ExpressionNode): +class ArrobaCallNode(ExpressionNode): def __init__(self, obj, idx, args, typex): self.obj = obj self.id = idx.value @@ -79,6 +79,15 @@ def __init__(self, obj, idx, args, typex): self.typeCol = typex.col +class DotCallNode(ExpressionNode): + def __init__(self, obj, idx, args): + self.obj = obj + self.id = idx.value + self.line = idx.lineno + self.col = idx.column + self.args = args + + class MemberCallNode(ExpressionNode): def __init__(self, idx, args): self.id = idx.value @@ -136,13 +145,6 @@ def __init__(self, idx, typex, expr): self.typeLine = typex.lineno self.typeCol = typex.col - -class NewNode(ExpressionNode): - def __init__(self, typex): - self.type = typex.value - self.typeLine = typex.lineno - self.typeCol = typex.col - # ---------------- Binary Nodes ------------------ @@ -217,9 +219,14 @@ def __init__(self, token): self.col = 0 +class NewNode(AtomicNode): + pass + + class IdNode(AtomicNode): pass + class IntNode(AtomicNode): pass From 3a63f6834a605b666b0267fbd74c08ccfb0177ed Mon Sep 17 00:00:00 2001 From: cwjki Date: Sat, 19 Feb 2022 19:34:51 -0500 Subject: [PATCH 111/194] retesting parser and lexer --- src/cparser/parser.py | 2 +- src/utils/ast.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cparser/parser.py b/src/cparser/parser.py index 3c37de755..9a97da06b 100644 --- a/src/cparser/parser.py +++ b/src/cparser/parser.py @@ -41,7 +41,7 @@ def p_def_class(self, p): '''def_class : CLASS TYPE LBRACE feature_list RBRACE | CLASS TYPE INHERITS TYPE LBRACE feature_list RBRACE''' if len(p) == 8: - p[0] = ClassDeclarationNode(p, slice[2], p[6], p.slice[4]) + p[0] = ClassDeclarationNode(p.slice[2], p[6], p.slice[4]) else: p[0] = ClassDeclarationNode(p.slice[2], p[4]) diff --git a/src/utils/ast.py b/src/utils/ast.py index 953810c22..198b27ce1 100644 --- a/src/utils/ast.py +++ b/src/utils/ast.py @@ -16,7 +16,7 @@ class DeclarationNode(Node): class ClassDeclarationNode(DeclarationNode): - def __init__(self, idx, features, parent): + def __init__(self, idx, features, parent=None): self.id = idx.value self.line = idx.lineno self.col = idx.column @@ -40,7 +40,7 @@ def __init__(self, idx, params, return_type, body): ptype.column) for pname, ptype in params] self.type = return_type.value self.typeLine = return_type.lineno - self.typeCol = return_type.col + self.typeCol = return_type.column self.body = body @@ -51,7 +51,7 @@ def __init__(self, idx, typex, expr=None): self.col = idx.column self.type = typex.value self.typeLine = typex.lineno - self.typeCol = typex.col + self.typeCol = typex.column self.expr = expr @@ -76,7 +76,7 @@ def __init__(self, obj, idx, args, typex): self.args = args self.type = typex.value self.typeLine = typex.lineno - self.typeCol = typex.col + self.typeCol = typex.column class DotCallNode(ExpressionNode): @@ -143,7 +143,7 @@ def __init__(self, idx, typex, expr): self.col = idx.column self.type = typex.value self.typeLine = typex.lineno - self.typeCol = typex.col + self.typeCol = typex.column # ---------------- Binary Nodes ------------------ @@ -212,7 +212,7 @@ def __init__(self, token): try: self.id = token.value self.line = token.lineno - self.col = token.col + self.col = token.column except: self.id = token self.line = 0 From 74b298887ed64d2447deac77e483c09f56ddb13d Mon Sep 17 00:00:00 2001 From: cwjki Date: Sat, 19 Feb 2022 19:41:38 -0500 Subject: [PATCH 112/194] fixing a typo in BlockNode --- src/cparser/parser.py | 4 ++-- src/main.py | 2 +- src/utils/ast.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cparser/parser.py b/src/cparser/parser.py index 9a97da06b..63a4526db 100644 --- a/src/cparser/parser.py +++ b/src/cparser/parser.py @@ -220,8 +220,8 @@ def p_block(self, p): def p_block_list(self, p): ''' block_list : expr SEMICOLON | expr SEMICOLON block_list''' - p[0] = BlockNode([p[1]], p.slice[1]) if len( - p) == 3 else BlockNode([p[1]] + p[3].exprs, p.slice[1]) + p[0] = BlockNode([p[1]], p.slice[2]) if len( + p) == 3 else BlockNode([p[1]] + p[3].exprs, p.slice[2]) def p_error(self, p): if p: diff --git a/src/main.py b/src/main.py index 9a35c7f18..03b337d3f 100644 --- a/src/main.py +++ b/src/main.py @@ -25,7 +25,7 @@ def main(_input, _output): if __name__ == "__main__": - path = '/home/cwjki/Projects/cool-compiler-2021/tests/parser/conditional4.cl' + path = '/home/cwjki/Projects/cool-compiler-2021/tests/parser/case2.cl' _input = sys.argv[1] if len(sys.argv) > 1 else path _output = sys.argv[2] if len(sys.argv) > 2 else None diff --git a/src/utils/ast.py b/src/utils/ast.py index 198b27ce1..7c19b24de 100644 --- a/src/utils/ast.py +++ b/src/utils/ast.py @@ -115,7 +115,7 @@ def __init__(self, condition, body, token): class BlockNode(ExpressionNode): def __init__(self, exprs, token): - self.expr = exprs + self.exprs = exprs self.line = token.lineno self.col = token.column From 3d6c9ae96dc13d370e2d597e3103a2066e21ebda Mon Sep 17 00:00:00 2001 From: cwjki Date: Sat, 19 Feb 2022 20:27:18 -0500 Subject: [PATCH 113/194] fixing typebuilder in semantics --- src/semantic/visitors/typeBuilder.py | 70 ++++++++++++++++++-------- src/semantic/visitors/typeChecker.py | 2 +- src/semantic/visitors/typeCollector.py | 8 +-- src/utils/errors.py | 5 ++ 4 files changed, 60 insertions(+), 25 deletions(-) diff --git a/src/semantic/visitors/typeBuilder.py b/src/semantic/visitors/typeBuilder.py index 05a8c5224..65ec1a06e 100644 --- a/src/semantic/visitors/typeBuilder.py +++ b/src/semantic/visitors/typeBuilder.py @@ -1,6 +1,5 @@ - from semantic.semantic import ErrorType -from src.utils.errors import SemanticError +from src.utils.errors import SemanticError, TypexError from utils import visitor from utils.ast import * @@ -24,23 +23,23 @@ def visit(self, programNode): def visit(self, classDeclarationNode): try: self.currentType = self.context.get_type( - classDeclarationNode.name, (classDeclarationNode.line, classDeclarationNode.column)) + classDeclarationNode.id, (classDeclarationNode.line, classDeclarationNode.col)) except SemanticError as error: - self.currentType = ErrorType + self.currentType = ErrorType() self.errors.append(error) if classDeclarationNode.parent is not None: if classDeclarationNode.parent in ['String', 'Int', 'Bool']: - errorText = f'Class {classDeclarationNode.name} cannot inherit class {classDeclarationNode.parent}.' + errorText = f'Class {classDeclarationNode.id} cannot inherit class {classDeclarationNode.parent}.' self.errors.append(SemanticError( - errorText, classDeclarationNode.line, classDeclarationNode.column)) + errorText, classDeclarationNode.line, classDeclarationNode.col)) try: parent = self.context.get_type( - classDeclarationNode.parent, (classDeclarationNode.line, classDeclarationNode.column)) + classDeclarationNode.parent, (classDeclarationNode.parentLine, classDeclarationNode.parentCol)) except: - errorText = f'Class {classDeclarationNode.name} inherits from an undefined class {classDeclarationNode.parent}' - self.errors.append(SemanticError( - errorText, classDeclarationNode.line, classDeclarationNode.column)) + errorText = f'Class {classDeclarationNode.id} inherits from an undefined class {classDeclarationNode.parent}' + self.errors.append(TypexError( + errorText, classDeclarationNode.line, classDeclarationNode.col)) parent = None try: current = parent @@ -48,7 +47,7 @@ def visit(self, classDeclarationNode): if current.name == self.currentType.name: errorText = f'Class {self.currentType.name}, or an ancestor of {self.currentType.name}, is involved in an inheritance cycle.' raise SemanticError( - errorText, classDeclarationNode.line, classDeclarationNode.column) + errorText, classDeclarationNode.line, classDeclarationNode.col) current = current.parent except SemanticError as error: parent = ErrorType() @@ -59,30 +58,61 @@ def visit(self, classDeclarationNode): for feature in classDeclarationNode.features: self.visit(feature) - @visit.when(FuncDeclarationNode) def visit(self, funcDeclarationNode): argsNames = [] argsTypes = [] - for name, typex in funcDeclarationNode.params: + for name, typex, line, col in funcDeclarationNode.params: if name in argsNames: errorText = f'Formal parameter {name} is multiply defined.' - self.errors.append(SemanticError(errorText, funcDeclarationNode.line, funcDeclarationNode.column)) + self.errors.append(SemanticError(errorText, line, col)) argsNames.append(name) try: - argsTypes = self.context.get_type(typex.value, funcDeclarationNode.line, funcDeclarationNode.column) + argsTypes = self.context.get_type(typex, line, col) except SemanticError: - errorText = f'Class {typex.value} of formal parameter {typex.value} is undefined.' - self.errors.append(SemanticError(errorText, funcDeclarationNode.line, funcDeclarationNode.column)) + errorText = f'Class {typex} of formal parameter {typex} is undefined.' + self.errors.append(TypexError(errorText, line, col)) argType = ErrorType() argsTypes.append(argType) - + + try: + returnType = self.context.get_type( + funcDeclarationNode.type, funcDeclarationNode.typeLine, funcDeclarationNode.typeCol) + except SemanticError: + errorText = f'Undefined return type {funcDeclarationNode.type} in method {funcDeclarationNode.id}.' + self.errors.append(TypexError( + errorText, funcDeclarationNode.typeLine, funcDeclarationNode.typeCol)) + returnType = ErrorType( + (funcDeclarationNode.typeLine, funcDeclarationNode.typeCol)) + try: - returnType = self.context.get_type(funcDeclarationNode.return_type, ) + self.currentType.define_method(funcDeclarationNode.id, argsNames, argsTypes, + returnType, (funcDeclarationNode.line, funcDeclarationNode.col)) except SemanticError as error: + self.errors.append(error) - + @visit.when(AttrDeclarationNode) + def visit(self, attrDeclarationNode): + try: + attrType = self.context.get_type( + attrDeclarationNode.type, (attrDeclarationNode.line, attrDeclarationNode.col)) + except SemanticError: + errorText = f'Class {attrDeclarationNode.type} of attribute {attrDeclarationNode.id} is undefined.' + self.errors.append(TypexError( + errorText, attrDeclarationNode.typeLine, attrDeclarationNode.typeCol)) + attrType = ErrorType( + (attrDeclarationNode.line, attrDeclarationNode.col)) + + if attrDeclarationNode.id == 'self': + errorText = f"'self' cannot be the name of an attribute." + self.errors.append(SemanticError( + errorText, attrDeclarationNode.line, attrDeclarationNode.col)) + try: + self.currentType.define_attribute( + attrDeclarationNode.id, attrType, (attrDeclarationNode.line, attrDeclarationNode.col)) + except SemanticError as error: + self.errors.append(error) diff --git a/src/semantic/visitors/typeChecker.py b/src/semantic/visitors/typeChecker.py index 9791780b9..eecf9fc93 100644 --- a/src/semantic/visitors/typeChecker.py +++ b/src/semantic/visitors/typeChecker.py @@ -1,5 +1,5 @@ from utils import visitor -from semantic.tools import * +from semantic.semantic import * from semantic.types import * from utils.ast import * from utils.errors import SemanticError, AttributesError, TypesError, NamesError diff --git a/src/semantic/visitors/typeCollector.py b/src/semantic/visitors/typeCollector.py index a106e3bbd..41b95f96b 100644 --- a/src/semantic/visitors/typeCollector.py +++ b/src/semantic/visitors/typeCollector.py @@ -28,13 +28,13 @@ def visit(self, programNode): @visitor.when(ClassDeclarationNode) def visit(self, classDeclarationNode): - if classDeclarationNode.name in ['Int', 'String', 'Bool', 'Object', 'SELF_TYPE', 'IO']: - errorText = f'Redefinition of basic class {classDeclarationNode.name}' + if classDeclarationNode.id in ['Int', 'String', 'Bool', 'Object', 'SELF_TYPE', 'IO']: + errorText = f'Redefinition of basic class {classDeclarationNode.id}' self.errors.append(SemanticError( - errorText, classDeclarationNode.line, classDeclarationNode.column)) + errorText, classDeclarationNode.line, classDeclarationNode.col)) try: self.context.create_type( - classDeclarationNode.name, (classDeclarationNode.line, classDeclarationNode.column)) + classDeclarationNode.id, (classDeclarationNode.line, classDeclarationNode.col)) except SemanticError as error: self.errors.append(error) diff --git a/src/utils/errors.py b/src/utils/errors.py index 84389f6fe..074a8d184 100644 --- a/src/utils/errors.py +++ b/src/utils/errors.py @@ -25,3 +25,8 @@ def __init__(self, text, line, column): class SemanticError(CoolError): def __init__(self, text, line, column): super().__init__('SemanticError', text, line, column) + + +class TypexError(SemanticError): + def __init__(self, text, line, column): + super().__init__('TypeError', text, line, column) From cb0d2d1e2eaecc527db38d7217181e7841418126 Mon Sep 17 00:00:00 2001 From: cwjki Date: Sat, 19 Feb 2022 22:51:16 -0500 Subject: [PATCH 114/194] fixing some typos on Context and Scope classes --- src/semantic/semantic.py | 113 +++++++++++++++++++++++++ src/semantic/visitors/typeBuilder.py | 2 +- src/semantic/visitors/typeCollector.py | 2 +- src/semantic/visitors/typeInferer.py | 75 ++++++++++++++++ 4 files changed, 190 insertions(+), 2 deletions(-) diff --git a/src/semantic/semantic.py b/src/semantic/semantic.py index 406b51e6a..eedd1b2a6 100644 --- a/src/semantic/semantic.py +++ b/src/semantic/semantic.py @@ -1,5 +1,7 @@ +from src.utils.ast import BoolNode, IntNode, IsVoidNode, StringNode from utils.errors import SemanticError from collections import OrderedDict +import itertools as itt class Attribute: @@ -347,3 +349,114 @@ def __str__(self): def __repr__(self): return str(self) + + +class VariableInfo: + def __init__(self, name, vtype, index=None): + self.name = name + self.type = vtype + self.index = index # saves the index in the scope of the variable + + def __str__(self): + return f'{self.name} : {self.type.name}' + + def __repr__(self): + return str(self) + + +class Scope: + def __init__(self, parent=None): + self.locals = [] + self.attributes = [] + self.parent = parent + self.children = [] + self.expr_dict = {} + self.functions = {} + self.index = 0 if parent is None else len(parent) + + def __len__(self): + return len(self.locals) + + def __str__(self): + res = '' + for scope in self.children: + try: + classx = scope.locals[0] + name = classx.type.name + except: + name = '1' + # '\n\t' + ('\n' + '\t').join(str(local) for local in scope.locals) + '\n' + res += name + scope.tab_level(1, '', 1) + return res + + def tab_level(self, tabs, name, num) -> str: + res = ('\t' * tabs) + ('\n' + ('\t' * tabs)).join(str(local) + for local in self.locals) + if self.functions: + children = '\n'.join(v.tab_level( + tabs + 1, '[method] ' + k, num) for k, v in self.functions.items()) + else: + children = '\n'.join(child.tab_level( + tabs + 1, num, num + 1) for child in self.children) + return "\t" * (tabs-1) + f'{name}' + "\t" * tabs + f'\n{res}\n{children}' + + def __repr__(self): + return str(self) + + def create_child(self): + child = Scope(self) + self.children.append(child) + return child + + def define_variable(self, vname, vtype) -> VariableInfo: + info = VariableInfo(vname, vtype) + if info not in self.locals: + self.locals.append(info) + return info + + def find_variable(self, vname, index=None) -> VariableInfo: + locals = self.attributes + self.locals + locals = locals if index is None else itt.islice(locals, index) + try: + return next(x for x in locals if x.name == vname) + except StopIteration: + return self.parent.find_variable(vname, index) if self.parent is not None else None + + def find_local(self, vname, index=None) -> VariableInfo: + locals = self.locals if index is None else itt.islice( + self.locals, index) + try: + return next(x for x in locals if x.name == vname) + except StopIteration: + return self.parent.find_local(vname, self.index) if self.parent is not None else None + + def find_attribute(self, vname, index=None): + locals = self.attributes if index is None else itt.islice( + self.attributes, index) + try: + return next(x for x in locals if x.name == vname) + except StopIteration: + return self.parent.find_attribute(vname, index) if self.parent is not None else None + + def get_class_scope(self): + if self.parent == None or self.parent.parent == None: + return self + return self.parent.get_class_scope() + + def is_defined(self, vname) -> VariableInfo: + return self.find_variable(vname) is not None + + def is_local(self, vname): + return any(True for x in self.locals if x.name == vname) + + def define_attribute(self, attr): + self.attributes.append(attr) + + +def define_default_value(typex, node): + if typex == IntType(): + node.expr = IntNode(0) + elif typex == StringType(): + node.expr = StringNode("") + else: + node.expr = BoolNode('false') diff --git a/src/semantic/visitors/typeBuilder.py b/src/semantic/visitors/typeBuilder.py index 65ec1a06e..312bbe0ba 100644 --- a/src/semantic/visitors/typeBuilder.py +++ b/src/semantic/visitors/typeBuilder.py @@ -5,7 +5,7 @@ class TypeBuilder: - def __init__(self, context, errors=[]): + def __init__(self, context, errors): self.context = context self.currentType = None self.errors = errors diff --git a/src/semantic/visitors/typeCollector.py b/src/semantic/visitors/typeCollector.py index 41b95f96b..e993e788b 100644 --- a/src/semantic/visitors/typeCollector.py +++ b/src/semantic/visitors/typeCollector.py @@ -5,7 +5,7 @@ class TypeCollector(object): - def __init__(self, errors=[]): + def __init__(self, errors): self.context = None self.errors = errors diff --git a/src/semantic/visitors/typeInferer.py b/src/semantic/visitors/typeInferer.py index e69de29bb..423684324 100644 --- a/src/semantic/visitors/typeInferer.py +++ b/src/semantic/visitors/typeInferer.py @@ -0,0 +1,75 @@ +import imp +from src.utils import visitor +from src.utils.ast import AttrDeclarationNode, ClassDeclarationNode, FuncDeclarationNode, IntNode, ProgramNode +from src.semantic.semantic import IntType, Scope, define_default_value +from src.utils.errors import SemanticError + + +class TypeInferer: + def __init__(self, context, errors): + self.context = context + self.errors = errors + self.currentType = None + self.currentMethod = None + self.currentIndex = None + + @visitor.on('node') + def visit(self, node, scope): + pass + + @visitor.when(ProgramNode) + def visit(self, programNode, scope): + scope = Scope() + for declaration in programNode.declarations: + self.visit(declaration, scope.create_child()) + return scope + + @visitor.when(ClassDeclarationNode) + def visit(self, classDeclarationNode, scope): + self.currentType = self._get_type( + classDeclarationNode.id, (classDeclarationNode.line, classDeclarationNode.col)) + scope.define_variable('self', self.currentType) + + for feature in classDeclarationNode.features: + if isinstance(feature, AttrDeclarationNode): + self.visit(feature, scope) + + for attr, _ in self.currentType.all_attributes(): + if scope.find_attribute(attr.name) is None: + scope.define_attribute(attr) + + for feature in classDeclarationNode.features: + if isinstance(feature, FuncDeclarationNode): + self.visit(feature, scope) + + @visitor.when(AttrDeclarationNode) + def visit(self, attrDeclarationNode, scope): + attr = self.currentType.get_attribute( + attrDeclarationNode.id, (attrDeclarationNode.line, attrDeclarationNode.col)) + if attrDeclarationNode.expr is None: + define_default_value(attr.type, attrDeclarationNode) + else: + self.visit(attrDeclarationNode.expr, scope) + attr.expr = attrDeclarationNode.expr + scope.define_attribute(attr) + + + @visitor.when(FuncDeclarationNode) + def visit(self, funcDeclarationNode, scope): + parent = self.currentType.parent + pnames = [param[0] for param in funcDeclarationNode.params] + ptypes = [param[1] for param in funcDeclarationNode.params] + + self.currentMethod = self.currentType.get_method(funcDeclarationNode.id, (funcDeclarationNode.line, funcDeclarationNode.col)) + + newScope = scope.create_child() + scope.functions[funcDeclarationNode.id] = newScope + + for pname, ptype, pline, pcol in funcDeclarationNode.params: + if pname == 'self': + errorText = "'self' cannot be the name of a formal parameter." + self.errors.append(SemanticError(errorText, pline, pcol)) + newScope.define_variable(pname, self._get_type(ptype, (pline,pcol))) + + self.visit(funcDeclarationNode.body, newScope) + From aedea12cc36a7337b562d73516ba012181e437c9 Mon Sep 17 00:00:00 2001 From: cwjki Date: Sun, 20 Feb 2022 14:06:55 -0500 Subject: [PATCH 115/194] adding var declaration to the parser logic --- src/cparser/parser.py | 12 +++++- .../{typeInferer.py => varCollector.py} | 37 +++++++++++++++---- src/utils/ast.py | 11 ++++++ 3 files changed, 51 insertions(+), 9 deletions(-) rename src/semantic/visitors/{typeInferer.py => varCollector.py} (66%) diff --git a/src/cparser/parser.py b/src/cparser/parser.py index 63a4526db..5573e6710 100644 --- a/src/cparser/parser.py +++ b/src/cparser/parser.py @@ -162,10 +162,18 @@ def p_expr_atom(self, p): p[0] = p[1] def p_let_attrs(self, p): - '''let_attrs : def_attr - | def_attr COMMA let_attrs''' + '''let_attrs : def_var + | def_var COMMA let_attrs''' p[0] = [p[1]] if len(p) == 2 else [p[1]] + p[3] + def p_def_var(self, p): + '''def_var : ID COLON TYPE + | ID COLON TYPE ASSIGN expr''' + if len(p) == 4: + p[0] = VarDeclarationNode(p.slice[1], p.slice[3]) + else: + p[0] = VarDeclarationNode(p.slice[1], p.slice[3], p[5]) + def p_case_list(self, p): '''case_list : case_option SEMICOLON | case_option SEMICOLON case_list''' diff --git a/src/semantic/visitors/typeInferer.py b/src/semantic/visitors/varCollector.py similarity index 66% rename from src/semantic/visitors/typeInferer.py rename to src/semantic/visitors/varCollector.py index 423684324..4b65760c8 100644 --- a/src/semantic/visitors/typeInferer.py +++ b/src/semantic/visitors/varCollector.py @@ -1,11 +1,11 @@ import imp from src.utils import visitor -from src.utils.ast import AttrDeclarationNode, ClassDeclarationNode, FuncDeclarationNode, IntNode, ProgramNode -from src.semantic.semantic import IntType, Scope, define_default_value +from src.utils.ast import AssignNode, AttrDeclarationNode, ClassDeclarationNode, FuncDeclarationNode, IntNode, ProgramNode +from src.semantic.semantic import ErrorType, IntType, Scope, define_default_value from src.utils.errors import SemanticError -class TypeInferer: +class VarCollector: def __init__(self, context, errors): self.context = context self.errors = errors @@ -53,14 +53,14 @@ def visit(self, attrDeclarationNode, scope): attr.expr = attrDeclarationNode.expr scope.define_attribute(attr) - @visitor.when(FuncDeclarationNode) def visit(self, funcDeclarationNode, scope): parent = self.currentType.parent pnames = [param[0] for param in funcDeclarationNode.params] ptypes = [param[1] for param in funcDeclarationNode.params] - self.currentMethod = self.currentType.get_method(funcDeclarationNode.id, (funcDeclarationNode.line, funcDeclarationNode.col)) + self.currentMethod = self.currentType.get_method( + funcDeclarationNode.id, (funcDeclarationNode.line, funcDeclarationNode.col)) newScope = scope.create_child() scope.functions[funcDeclarationNode.id] = newScope @@ -69,7 +69,30 @@ def visit(self, funcDeclarationNode, scope): if pname == 'self': errorText = "'self' cannot be the name of a formal parameter." self.errors.append(SemanticError(errorText, pline, pcol)) - newScope.define_variable(pname, self._get_type(ptype, (pline,pcol))) - + newScope.define_variable( + pname, self._get_type(ptype, (pline, pcol))) + self.visit(funcDeclarationNode.body, newScope) + def _get_type(self, ntype, pos): + try: + return self.context.get_type(ntype, pos) + except SemanticError as e: + self.errors.append(e) + return ErrorType() + + @visit.when(AssignNode) + def visit(self, assignNode, scope): + if assignNode.id == 'self': + errorText = '\'self\' cannot be bound in a \'let\' expression.' + self.errors.append(SemanticError( + errorText, assignNode.line, assignNode.col)) + return + + try: + vType = self.context.get_type(assignNode.type, assignNode.line, assignNode.col) + except: + errorText = f'Class {assignNode.type} of let-bound identifier %s is undefined.' + + vInfo = scope.find_variable(assignNode.id) + if vInfo diff --git a/src/utils/ast.py b/src/utils/ast.py index 7c19b24de..ec2234b1a 100644 --- a/src/utils/ast.py +++ b/src/utils/ast.py @@ -55,6 +55,17 @@ def __init__(self, idx, typex, expr=None): self.expr = expr +class VarDeclarationNode(DeclarationNode): + def __init__(self, idx, typex, expr=None): + self.id = idx.value + self.line = idx.lineno + self.col = idx.column + self.type = typex.value + self.typeLine = typex.lineno + self.typeCol = typex.column + self.expr = expr + + class ExpressionNode(Node): pass From b70963a7df908cc66d43d319772566c73f589030 Mon Sep 17 00:00:00 2001 From: cwjki Date: Sun, 20 Feb 2022 14:21:38 -0500 Subject: [PATCH 116/194] adding to the varCollector the varDeclarationNode logic --- src/semantic/visitors/varCollector.py | 34 +++++++++++++++++++-------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/semantic/visitors/varCollector.py b/src/semantic/visitors/varCollector.py index 4b65760c8..172717fc9 100644 --- a/src/semantic/visitors/varCollector.py +++ b/src/semantic/visitors/varCollector.py @@ -1,8 +1,8 @@ import imp from src.utils import visitor -from src.utils.ast import AssignNode, AttrDeclarationNode, ClassDeclarationNode, FuncDeclarationNode, IntNode, ProgramNode +from src.utils.ast import AssignNode, AttrDeclarationNode, ClassDeclarationNode, FuncDeclarationNode, IntNode, ProgramNode, VarDeclarationNode from src.semantic.semantic import ErrorType, IntType, Scope, define_default_value -from src.utils.errors import SemanticError +from src.utils.errors import SemanticError, TypexError class VarCollector: @@ -81,18 +81,32 @@ def _get_type(self, ntype, pos): self.errors.append(e) return ErrorType() - @visit.when(AssignNode) - def visit(self, assignNode, scope): - if assignNode.id == 'self': + @visit.when(VarDeclarationNode) + def visit(self, varDeclarationNode, scope): + if varDeclarationNode.id == 'self': errorText = '\'self\' cannot be bound in a \'let\' expression.' self.errors.append(SemanticError( - errorText, assignNode.line, assignNode.col)) + errorText, varDeclarationNode.line, varDeclarationNode.col)) return try: - vType = self.context.get_type(assignNode.type, assignNode.line, assignNode.col) + vType = self.context.get_type( + varDeclarationNode.type, varDeclarationNode.line, varDeclarationNode.col) except: - errorText = f'Class {assignNode.type} of let-bound identifier %s is undefined.' + errorText = f'Class {varDeclarationNode.type} of let-bound identifier {varDeclarationNode.id} is undefined.' + self.errors.append(TypexError( + errorText, varDeclarationNode.typeLine, varDeclarationNode.typeCol)) + vType = ErrorType() - vInfo = scope.find_variable(assignNode.id) - if vInfo + vType = self._get_type( + varDeclarationNode.type, (varDeclarationNode.typeLine, varDeclarationNode.typeCol)) + varInfo = scope.define_variable(varDeclarationNode.id, vType) + + if varDeclarationNode.expr is not None: + self.visit(varDeclarationNode.expr, scope) + else: + define_default_value(vType, varDeclarationNode) + + @visit.when(AssignNode) + def visit(self, assignNode, scope): + \ No newline at end of file From 9e734934f1f1a3db3512d9cf11158dab5070aa32 Mon Sep 17 00:00:00 2001 From: cwjki Date: Sun, 20 Feb 2022 16:39:37 -0500 Subject: [PATCH 117/194] changing the structure of varCollector hope its work --- src/semantic/visitors/varCollector.py | 98 +++++++++++++++++++++++++-- src/utils/ast.py | 4 +- src/utils/errors.py | 5 ++ 3 files changed, 100 insertions(+), 7 deletions(-) diff --git a/src/semantic/visitors/varCollector.py b/src/semantic/visitors/varCollector.py index 172717fc9..e04c8e44a 100644 --- a/src/semantic/visitors/varCollector.py +++ b/src/semantic/visitors/varCollector.py @@ -1,8 +1,8 @@ import imp from src.utils import visitor -from src.utils.ast import AssignNode, AttrDeclarationNode, ClassDeclarationNode, FuncDeclarationNode, IntNode, ProgramNode, VarDeclarationNode +from src.utils.ast import ArrobaCallNode, AssignNode, AttrDeclarationNode, BlockNode, CaseNode, ClassDeclarationNode, DotCallNode, FuncDeclarationNode, IdNode, IfThenElseNode, IntNode, IsVoidNode, LetInNode, MemberCallNode, ProgramNode, VarDeclarationNode, WhileNode from src.semantic.semantic import ErrorType, IntType, Scope, define_default_value -from src.utils.errors import SemanticError, TypexError +from src.utils.errors import NamexError, SemanticError, TypexError class VarCollector: @@ -81,7 +81,7 @@ def _get_type(self, ntype, pos): self.errors.append(e) return ErrorType() - @visit.when(VarDeclarationNode) + @visitor.when(VarDeclarationNode) def visit(self, varDeclarationNode, scope): if varDeclarationNode.id == 'self': errorText = '\'self\' cannot be bound in a \'let\' expression.' @@ -107,6 +107,94 @@ def visit(self, varDeclarationNode, scope): else: define_default_value(vType, varDeclarationNode) - @visit.when(AssignNode) + @visitor.when(AssignNode) def visit(self, assignNode, scope): - \ No newline at end of file + if assignNode.id == 'self': + errorText = 'Cannot assign to \'self\'.' + self.errors.append(SemanticError( + errorText, assignNode.line, assignNode.col)) + return + + vInfo = scope.find_variable(assignNode.id) + if vInfo is None: + varInfo = scope.find_attribute(assignNode.id) + if varInfo is None: + errorText = f'Undeclared identifier {assignNode.id}.' + self.errors.append(NamexError( + errorText, assignNode.line, assignNode.col)) + vType = ErrorType() + scope.define_variable(assignNode.id, vType) + + self.visit(assignNode.expr, scope) + + @visitor.when(BlockNode) + def visit(self, blockNode, scope): + for expr in blockNode.exprs: + self.visit(expr, scope) + + @visitor.when(LetInNode) + def visit(self, letInNode, scope): + newScope = scope.create_child() + scope.expr_dict[letInNode] = newScope + for letDeclaration in letInNode.letBody: + self.visit(letDeclaration, newScope) + + self.visit(letInNode.inBody, newScope) + + @visitor.when(IdNode) + def visit(self, idNode, scope): + try: + return self.currentType.get_attribute(idNode.id, (idNode.line, idNode.col)).type + except: + if not scope.is_defined(idNode.id): + errorText = f'Undeclared identifier {idNode.id}.' + self.errors.append(NamexError( + errorText, idNode.line, idNode.col)) + vInfo = scope.define_variable( + idNode.id, ErrorType((idNode.line, idNode.col))) + else: + vInfo = scope.find_variable(idNode.id) + + return vInfo.type + + @visitor.when(WhileNode) + def visit(self, whileNode, scope): + self.visit(whileNode.condition, scope) + self.visit(whileNode.body, scope) + + @visitor.when(IfThenElseNode) + def visit(self, ifThenElseNode, scope): + self.visit(ifThenElseNode.condition, scope) + self.visit(ifThenElseNode.ifBody, scope) + self.visit(ifThenElseNode.elseBody, scope) + + @visitor.when(IsVoidNode) + def visit(self, isVoidNode, scope): + self.visit(isVoidNode.expr, scope) + + @visitor.when(ArrobaCallNode) + def visit(self, arrobaCallNode, scope): + self.visit(arrobaCallNode.obj, scope) + for arg in arrobaCallNode.args: + self.visit(arg) + + @visitor.when(DotCallNode) + def visit(self, dotCallNode, scope): + self.visit(dotCallNode.obj, scope) + for arg in dotCallNode.args: + self.visit(arg) + + @visitor.when(MemberCallNode) + def visit(self, memberCallNode, scope): + for arg in memberCallNode.args: + self.visit(arg) + + + @visitor.when(CaseNode) + def visit(self, caseNode, scope): + self.visit(caseNode.expr, scope) + newScope = scope.create_child() + scope.expr_dict[caseNode] = newScope + + for + diff --git a/src/utils/ast.py b/src/utils/ast.py index ec2234b1a..ac9ab2896 100644 --- a/src/utils/ast.py +++ b/src/utils/ast.py @@ -140,9 +140,9 @@ def __init__(self, letBody, inBody, token): class CaseNode(ExpressionNode): - def __init__(self, expr, caseList, token): + def __init__(self, expr, optionList, token): self.expr = expr - self.caseList = caseList + self.optionList = optionList self.line = token.lineno self.col = token.column diff --git a/src/utils/errors.py b/src/utils/errors.py index 074a8d184..79db36883 100644 --- a/src/utils/errors.py +++ b/src/utils/errors.py @@ -30,3 +30,8 @@ def __init__(self, text, line, column): class TypexError(SemanticError): def __init__(self, text, line, column): super().__init__('TypeError', text, line, column) + + +class NamexError(SemanticError): + def __init__(self, text, line, column): + super().__init__('NameError', text, line, column) From 1d8308befde5b6567e892e5bde1da93cc45c2b0b Mon Sep 17 00:00:00 2001 From: cwjki Date: Sun, 20 Feb 2022 17:00:49 -0500 Subject: [PATCH 118/194] trying to pass the semantic tests --- src/main.py | 26 +++++- src/semantic/semanticAnalizer.py | 13 --- src/semantic/types.py | 111 ----------------------- src/semantic/visitors/varCollector.py | 122 ++++++++++++++------------ src/utils/ast.py | 1 + 5 files changed, 92 insertions(+), 181 deletions(-) delete mode 100644 src/semantic/types.py diff --git a/src/main.py b/src/main.py index 03b337d3f..22d65c11c 100644 --- a/src/main.py +++ b/src/main.py @@ -3,6 +3,10 @@ from lexer import CoolLexer from cparser import CoolParser +from src.semantic.visitors.typeBuilder import TypeBuilder +from src.semantic.visitors.typeChecker import TypeChecker +from src.semantic.visitors.typeCollector import TypeCollector +from src.semantic.visitors.varCollector import VarCollector def main(_input, _output): @@ -10,19 +14,37 @@ def main(_input, _output): with open(_input) as file: text = file.read() + # Lexer lexer = CoolLexer() tokens = lexer.run(text) + # Parser parser = CoolParser(lexer) ast = parser.parse(text) if parser.errors: parser.print_error() raise Exception() - - # ast, errors, context, scope = SemanticAn + # Semantic + semanticErrors = [] + typeCollector = TypeCollector(semanticErrors) + typeCollector.visit(ast) + context = typeCollector.context + typeBuilder = TypeBuilder(context, semanticErrors) + typeBuilder.visit(ast) + typeInferer = VarCollector(context, semanticErrors) + scope = typeInferer.visit(ast) + typeChecker = TypeChecker(context, semanticErrors) + typeChecker.visit(ast, scope) + if semanticErrors: + for error in semanticErrors: + print(semanticErrors) + raise Exception() + + # Code Generation + # ast, errors, context, scope = SemanticAn if __name__ == "__main__": path = '/home/cwjki/Projects/cool-compiler-2021/tests/parser/case2.cl' diff --git a/src/semantic/semanticAnalizer.py b/src/semantic/semanticAnalizer.py index f72201e85..64a33c8bf 100644 --- a/src/semantic/semanticAnalizer.py +++ b/src/semantic/semanticAnalizer.py @@ -3,19 +3,6 @@ def semanticAnalizer(ast): errors = [] - typeCollector = TypeCollector(errors) - typeCollector.visit(ast) - context = typeCollector.context - - - typeBuilder = TypeBuilder(context, errors) - typeBuilder.visit(ast) - - typeInferer = TypeInferer(context, errors) - scope = typeInferer.visit(ast) - - typeChecker = TypeChecker(context, errors) - typeChecker.visit(ast, scope) return ast, errors, context, scope diff --git a/src/semantic/types.py b/src/semantic/types.py deleted file mode 100644 index b455aa253..000000000 --- a/src/semantic/types.py +++ /dev/null @@ -1,111 +0,0 @@ -from utils.errors import SemanticError - - -class Attribute: - def __init__(self, name, typex, index): - self.name = name - self.type = typex - self.index = index - self.expr = None - - def __str__(self): - return f'[attr] {self.name} : {self.type.name}' - - def __repr__(self): - return str(self) - - -class Method: - def __init__(self, name, param_names, param_types, return_type): - self.name = name - self.param_names = param_names - self.param_types = param_types - self.return_type = return_type - - -class Type: - def __init__(self, name, position, parent=True): - if name == 'ObjectType': - return ObjectType(position) - self.name = name - self.attributes = {} - self.methods = {} - self.position = position - if parent: - self.parent = ObjectType(position) - else: - self.parent = None - - def set_parent(self, parent): - if type(self.parent) != ObjectType and self.parent is not None: - line, column = self.position - raise SemanticError( - f'Parent already defined for {self.name}', line, column) - self.parent = parent - - def get_attribute(self, name, position): - try: - return self.attributes[name] - except KeyError: - if self.parent is None: - line, column = self.position - raise SemanticError( - f'Attribute {name} is not defined in {self.name}', line, column) - try: - return self.parent.get_attribute(name, position) - except: - line, column = self.position - raise SemanticError( - f'Attribute {name} is not defined in {self.name}', line, column) - - def define_attribute(self, name, typex, position): - try: - self.attributes[name] - except KeyError: - try: - self.get_attribute(name, position) - except SemanticError(): - attribute = Attribute(name, typex, len(self.attributes)) - self.attributes[name] = attribute - return attribute - else: - line, column = self.position - raise SemanticError( - f'Attribute {name} is an attribute of an inherited class', line, column) - else: - line, column = self.position - raise SemanticError( - f'Attribute {name} is already defined', line, column) - - def get_method(self, name, position): - try: - return self.methods[name] - except KeyError: - if self.parent is None: - line, column = self.position - raise SemanticError( - f'Method {name} is not defined in {self.name}', line, column) - try: - return self.parent.get_method(name, position) - except: - line, column = self.position - raise SemanticError( - f'Method {name} is not defined in {self.name}', line, column) - - def define_method(self, name, param_names, param_types, return_type, position=(0, 0)): - if name in self.methods: - line, column = self.position - raise SemanticError( - f'Method {name} is already defined', line, column) - - method = self.methods[name] = Method(name, param_names, param_types, return_type) - return method - - -class ObjectType(Type): - def __init__(self, position=(0, 0)): - self.name = 'Object' - self.attributes = {} - self.methods = {} - self.parent = None - self.position = position diff --git a/src/semantic/visitors/varCollector.py b/src/semantic/visitors/varCollector.py index e04c8e44a..e31682f08 100644 --- a/src/semantic/visitors/varCollector.py +++ b/src/semantic/visitors/varCollector.py @@ -1,6 +1,5 @@ -import imp from src.utils import visitor -from src.utils.ast import ArrobaCallNode, AssignNode, AttrDeclarationNode, BlockNode, CaseNode, ClassDeclarationNode, DotCallNode, FuncDeclarationNode, IdNode, IfThenElseNode, IntNode, IsVoidNode, LetInNode, MemberCallNode, ProgramNode, VarDeclarationNode, WhileNode +from src.utils.ast import ArrobaCallNode, AssignNode, AttrDeclarationNode, BlockNode, CaseNode, CaseOptionNode, ClassDeclarationNode, DotCallNode, FuncDeclarationNode, IdNode, IfThenElseNode, IntNode, IsVoidNode, LetInNode, MemberCallNode, ProgramNode, VarDeclarationNode, WhileNode from src.semantic.semantic import ErrorType, IntType, Scope, define_default_value from src.utils.errors import NamexError, SemanticError, TypexError @@ -42,17 +41,6 @@ def visit(self, classDeclarationNode, scope): if isinstance(feature, FuncDeclarationNode): self.visit(feature, scope) - @visitor.when(AttrDeclarationNode) - def visit(self, attrDeclarationNode, scope): - attr = self.currentType.get_attribute( - attrDeclarationNode.id, (attrDeclarationNode.line, attrDeclarationNode.col)) - if attrDeclarationNode.expr is None: - define_default_value(attr.type, attrDeclarationNode) - else: - self.visit(attrDeclarationNode.expr, scope) - attr.expr = attrDeclarationNode.expr - scope.define_attribute(attr) - @visitor.when(FuncDeclarationNode) def visit(self, funcDeclarationNode, scope): parent = self.currentType.parent @@ -74,6 +62,17 @@ def visit(self, funcDeclarationNode, scope): self.visit(funcDeclarationNode.body, newScope) + @visitor.when(AttrDeclarationNode) + def visit(self, attrDeclarationNode, scope): + attr = self.currentType.get_attribute( + attrDeclarationNode.id, (attrDeclarationNode.line, attrDeclarationNode.col)) + if attrDeclarationNode.expr is None: + define_default_value(attr.type, attrDeclarationNode) + else: + self.visit(attrDeclarationNode.expr, scope) + attr.expr = attrDeclarationNode.expr + scope.define_attribute(attr) + def _get_type(self, ntype, pos): try: return self.context.get_type(ntype, pos) @@ -127,6 +126,34 @@ def visit(self, assignNode, scope): self.visit(assignNode.expr, scope) + @visitor.when(ArrobaCallNode) + def visit(self, arrobaCallNode, scope): + self.visit(arrobaCallNode.obj, scope) + for arg in arrobaCallNode.args: + self.visit(arg) + + @visitor.when(DotCallNode) + def visit(self, dotCallNode, scope): + self.visit(dotCallNode.obj, scope) + for arg in dotCallNode.args: + self.visit(arg) + + @visitor.when(MemberCallNode) + def visit(self, memberCallNode, scope): + for arg in memberCallNode.args: + self.visit(arg) + + @visitor.when(IfThenElseNode) + def visit(self, ifThenElseNode, scope): + self.visit(ifThenElseNode.condition, scope) + self.visit(ifThenElseNode.ifBody, scope) + self.visit(ifThenElseNode.elseBody, scope) + + @visitor.when(WhileNode) + def visit(self, whileNode, scope): + self.visit(whileNode.condition, scope) + self.visit(whileNode.body, scope) + @visitor.when(BlockNode) def visit(self, blockNode, scope): for expr in blockNode.exprs: @@ -141,6 +168,33 @@ def visit(self, letInNode, scope): self.visit(letInNode.inBody, newScope) + @visitor.when(CaseNode) + def visit(self, caseNode, scope): + self.visit(caseNode.expr, scope) + newScope = scope.create_child() + scope.expr_dict[caseNode] = newScope + + for option in caseNode.optionList: + self.visit(option, newScope.create_child()) + + @visitor.when(CaseOptionNode) + def visit(self, caseOptionNode, scope): + try: + typex = self.context.get_type( + caseOptionNode.type, (caseOptionNode.line, caseOptionNode.col)) + except: + errorText = f'Class {caseOptionNode.type} of case branch is undefined.' + self.errors.append(TypexError( + errorText, caseOptionNode.line, caseOptionNode.col)) + typex = ErrorType() + + scope.define_variable(caseOptionNode.id, typex) + self.visit(caseOptionNode.expr, scope) + + @visitor.when(IsVoidNode) + def visit(self, isVoidNode, scope): + self.visit(isVoidNode.expr, scope) + @visitor.when(IdNode) def visit(self, idNode, scope): try: @@ -156,45 +210,3 @@ def visit(self, idNode, scope): vInfo = scope.find_variable(idNode.id) return vInfo.type - - @visitor.when(WhileNode) - def visit(self, whileNode, scope): - self.visit(whileNode.condition, scope) - self.visit(whileNode.body, scope) - - @visitor.when(IfThenElseNode) - def visit(self, ifThenElseNode, scope): - self.visit(ifThenElseNode.condition, scope) - self.visit(ifThenElseNode.ifBody, scope) - self.visit(ifThenElseNode.elseBody, scope) - - @visitor.when(IsVoidNode) - def visit(self, isVoidNode, scope): - self.visit(isVoidNode.expr, scope) - - @visitor.when(ArrobaCallNode) - def visit(self, arrobaCallNode, scope): - self.visit(arrobaCallNode.obj, scope) - for arg in arrobaCallNode.args: - self.visit(arg) - - @visitor.when(DotCallNode) - def visit(self, dotCallNode, scope): - self.visit(dotCallNode.obj, scope) - for arg in dotCallNode.args: - self.visit(arg) - - @visitor.when(MemberCallNode) - def visit(self, memberCallNode, scope): - for arg in memberCallNode.args: - self.visit(arg) - - - @visitor.when(CaseNode) - def visit(self, caseNode, scope): - self.visit(caseNode.expr, scope) - newScope = scope.create_child() - scope.expr_dict[caseNode] = newScope - - for - diff --git a/src/utils/ast.py b/src/utils/ast.py index ac9ab2896..f3f7804c7 100644 --- a/src/utils/ast.py +++ b/src/utils/ast.py @@ -155,6 +155,7 @@ def __init__(self, idx, typex, expr): self.type = typex.value self.typeLine = typex.lineno self.typeCol = typex.column + self.expr = expr # ---------------- Binary Nodes ------------------ From 79aafd17f254a4e2429b21ad4ce96e957a864d52 Mon Sep 17 00:00:00 2001 From: cwjki Date: Sun, 20 Feb 2022 17:01:49 -0500 Subject: [PATCH 119/194] deleting unneccesary files --- src/semantic/semanticAnalizer.py | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 src/semantic/semanticAnalizer.py diff --git a/src/semantic/semanticAnalizer.py b/src/semantic/semanticAnalizer.py deleted file mode 100644 index 64a33c8bf..000000000 --- a/src/semantic/semanticAnalizer.py +++ /dev/null @@ -1,9 +0,0 @@ -from semantic.visitors.typeCollector import TypeCollector - -def semanticAnalizer(ast): - errors = [] - - - return ast, errors, context, scope - - From efe1f452d5707624ab1983347743bb1870d77684 Mon Sep 17 00:00:00 2001 From: livi98 Date: Sun, 20 Feb 2022 23:02:09 +0100 Subject: [PATCH 120/194] fixing func_calls --- src/code_generator/BaseCILToMIPSVisitor.py | 25 ++++++------------ src/code_generator/CILToMIPSVisitor.py | 8 +++--- src/code_generator/COOLToCILVisitor.py | 30 +--------------------- src/code_generator/cil_visual_visitor.py | 3 +-- 4 files changed, 13 insertions(+), 53 deletions(-) diff --git a/src/code_generator/BaseCILToMIPSVisitor.py b/src/code_generator/BaseCILToMIPSVisitor.py index 6c65cb913..6ace43580 100644 --- a/src/code_generator/BaseCILToMIPSVisitor.py +++ b/src/code_generator/BaseCILToMIPSVisitor.py @@ -5,13 +5,16 @@ class BaseCILToMIPSVisitor: def __init__(self, inherit_graph): self.code: list = ['.text', '.globl main', 'main:'] - self.initialize_data_code() + self.data_code = ['.data'] self.symbol_table = SymbolTable() self.reg_desc = RegisterDescriptor() self.addr_desc = AddressDescriptor() self.obj_table: ObjTable = ObjTable(self.dispatch_table) - self.initialize_methods() + self.methods = [] + for entry in self.obj_table: + entry: ObjTabEntry + self.methods.extend(entry.dispatch_table_entry) self.var_address = {'self': AddrType.REF} self.loop_idx = 0 @@ -19,19 +22,6 @@ def __init__(self, inherit_graph): self.inherit_graph = inherit_graph self.space_idx = 0 - def initialize_methods(self): - self.methods = [] - for entry in self.obj_table: - entry: ObjTabEntry - self.methods.extend(entry.dispatch_table_entry) - - def initialize_data_code(self): - self.data_code = ['.data'] - - def get_basic_blocks(self, instructions): - leaders = self.find_leaders(instructions) - blocks = [instructions[leaders[i-1]:leaders[i]] for i in range(1, len(leaders))] - return blocks def is_variable(self, expr): return isinstance(expr, str) @@ -226,6 +216,7 @@ def __getitem__(self, item) -> ObjTabEntry: def __iter__(self): return iter(self.objects.values()) + class RegisterDescriptor: def __init__(self): registers = ['t0', 't1', 't2', 't3', 't4', 't5', 't6', 't7', 'a1', 'a2', 'a3', \ @@ -261,10 +252,10 @@ def insert_var(self, name, address, register=None, stack=None): else: self.vars[name] = [address, register, stack] - def get_var_addr(self, name): + def get_addr(self, name): return self.vars[name][0] - def set_var_addr(self, name, addr): + def set_addr(self, name, addr): self.vars[name][0] = 4*addr def get_var_reg(self, var): diff --git a/src/code_generator/CILToMIPSVisitor.py b/src/code_generator/CILToMIPSVisitor.py index c4c63a378..e98427fb7 100644 --- a/src/code_generator/CILToMIPSVisitor.py +++ b/src/code_generator/CILToMIPSVisitor.py @@ -47,7 +47,8 @@ def visit(self, node): for i, var in enumerate(node.localvars, len(node.params)): self.visit(var, i) self.locals = len(node.params) + len(node.localvars) - blocks = self.get_basic_blocks(node.instructions) + leaders = self.find_leaders(node.instructions) + blocks = [node.instructions[leaders[i-1]:leaders[i]] for i in range(1, len(leaders))] self.next_use = self.construct_next_use(blocks) for block in blocks: self.block = block @@ -290,7 +291,7 @@ def visit(self, node): size = 4*self.obj_table.size_of_entry(node.type) self.code.append(f'li $a0, {size}') self.code.append('syscall') - addrs_stack = self.addr_desc.get_var_addr(node.dest) + addrs_stack = self.addr_desc.get_addr(node.dest) self.code.append('# Loads the name of the variable and saves the name like the first field') self.code.append(f'la $t9, type_{node.type}') self.code.append(f'sw $t9, 0($v0)') @@ -553,6 +554,3 @@ def visit(self, node): self.code.append('sb $0, 0($v0)') self.load_var_if_occupied(var) self.loop_idx += 1 - - - diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index fc5eed136..ea5aff94a 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -108,33 +108,6 @@ def visit(self, node, scope): @visitor.when(FuncCallNode) def visit(self, node, scope): - # obj, otype = self.visit(node.obj, scope) - - # meth = otype.get_method(node.id) - # args_node = [cil.ArgNode(obj)] + self.handle_arguments(node.args, scope, meth.param_types) - - # rtype = meth.return_type - # result = None if isinstance(rtype, VoidType()) else self.define_internal_local() - - # continue_label = cil.LabelNode(f'continue__{self.index}') - # isvoid = self.check_void(obj) - # self.register_instruction(cil.IfGoToNode(isvoid, continue_label.label)) - # self.register_instruction(cil.ErrorNode('dispatch_error')) - # self.register_instruction(continue_label) - - # #desambiguar segun sea el llamado, dinamico o estatico - # # self.register_instruction(cil.StaticCallNode(node.type, node.id, result, args_node, rtype.name)) - # # return result, self._return_type(otype, node) - - # # self.register_instruction(cil.DynamicCallNode(self.current_type.name, 'self', node.id, result, args_node, rtype.name)) - # # return result, self._return_type(self.current_type, node) - - # # if otype in [StringType(), IntType(), BoolType()]: - # # self.register_instruction(cil.StaticCallNode(otype.name, node.id, result, args_node, rtype.name)) - # # else: - # # self.register_instruction(cil.DynamicCallNode(otype.name, obj, node.id, result, args_node, rtype.name)) - # # return result, self._return_type(otype, node) - result_local = self.define_internal_local(scope = scope, name = "result") expr_value = self.visit(node.instance, scope) @@ -253,7 +226,7 @@ def visit(self, node, scope): self.register_instruction(end_label) return result, typex -#this find_local, find_attribute is from scope, this get_type is separate, nedd to do it well +#this find_local, find_attribute is from scope, this get_type is separate, need to do it well visitor.when(VarNode) def visit(self, node, scope): try: @@ -316,4 +289,3 @@ def visit(self, node, scope): def visit(self, node, scope): return self._define_binary_node(node, scope, cil.EqualNode) - diff --git a/src/code_generator/cil_visual_visitor.py b/src/code_generator/cil_visual_visitor.py index 4472efd7b..aa549564a 100644 --- a/src/code_generator/cil_visual_visitor.py +++ b/src/code_generator/cil_visual_visitor.py @@ -151,5 +151,4 @@ def visit(self, node): printer = PrintVisitor() return lambda ast: printer.visit(ast) - - \ No newline at end of file + \ No newline at end of file From 19574affd2b225bc2f2a9ca13a0383d7b5bd01f4 Mon Sep 17 00:00:00 2001 From: cwjki Date: Sun, 20 Feb 2022 17:06:41 -0500 Subject: [PATCH 121/194] fixing the imports --- src/main.py | 8 ++++---- src/semantic/semantic.py | 2 +- src/semantic/visitors/typeBuilder.py | 2 +- src/semantic/visitors/typeChecker.py | 1 - src/semantic/visitors/typeCollector.py | 2 +- src/semantic/visitors/varCollector.py | 8 ++++---- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/main.py b/src/main.py index 22d65c11c..c8038e86d 100644 --- a/src/main.py +++ b/src/main.py @@ -3,10 +3,10 @@ from lexer import CoolLexer from cparser import CoolParser -from src.semantic.visitors.typeBuilder import TypeBuilder -from src.semantic.visitors.typeChecker import TypeChecker -from src.semantic.visitors.typeCollector import TypeCollector -from src.semantic.visitors.varCollector import VarCollector +from semantic.visitors.typeBuilder import TypeBuilder +from semantic.visitors.typeChecker import TypeChecker +from semantic.visitors.typeCollector import TypeCollector +from semantic.visitors.varCollector import VarCollector def main(_input, _output): diff --git a/src/semantic/semantic.py b/src/semantic/semantic.py index eedd1b2a6..f57a67c36 100644 --- a/src/semantic/semantic.py +++ b/src/semantic/semantic.py @@ -1,4 +1,4 @@ -from src.utils.ast import BoolNode, IntNode, IsVoidNode, StringNode +from utils.ast import BoolNode, IntNode, IsVoidNode, StringNode from utils.errors import SemanticError from collections import OrderedDict import itertools as itt diff --git a/src/semantic/visitors/typeBuilder.py b/src/semantic/visitors/typeBuilder.py index 312bbe0ba..a873b94fd 100644 --- a/src/semantic/visitors/typeBuilder.py +++ b/src/semantic/visitors/typeBuilder.py @@ -1,5 +1,5 @@ from semantic.semantic import ErrorType -from src.utils.errors import SemanticError, TypexError +from utils.errors import SemanticError, TypexError from utils import visitor from utils.ast import * diff --git a/src/semantic/visitors/typeChecker.py b/src/semantic/visitors/typeChecker.py index eecf9fc93..70f7e94c5 100644 --- a/src/semantic/visitors/typeChecker.py +++ b/src/semantic/visitors/typeChecker.py @@ -1,6 +1,5 @@ from utils import visitor from semantic.semantic import * -from semantic.types import * from utils.ast import * from utils.errors import SemanticError, AttributesError, TypesError, NamesError from utils import get_type, get_common_basetype diff --git a/src/semantic/visitors/typeCollector.py b/src/semantic/visitors/typeCollector.py index e993e788b..814159bce 100644 --- a/src/semantic/visitors/typeCollector.py +++ b/src/semantic/visitors/typeCollector.py @@ -1,4 +1,4 @@ -from src.utils.errors import SemanticError +from utils.errors import SemanticError from utils import visitor from utils.ast import ProgramNode, ClassDeclarationNode from semantic.semantic import Context, IntType, StringType, BoolType, ObjectType, SelfType, IOType diff --git a/src/semantic/visitors/varCollector.py b/src/semantic/visitors/varCollector.py index e31682f08..c7a27c7c9 100644 --- a/src/semantic/visitors/varCollector.py +++ b/src/semantic/visitors/varCollector.py @@ -1,7 +1,7 @@ -from src.utils import visitor -from src.utils.ast import ArrobaCallNode, AssignNode, AttrDeclarationNode, BlockNode, CaseNode, CaseOptionNode, ClassDeclarationNode, DotCallNode, FuncDeclarationNode, IdNode, IfThenElseNode, IntNode, IsVoidNode, LetInNode, MemberCallNode, ProgramNode, VarDeclarationNode, WhileNode -from src.semantic.semantic import ErrorType, IntType, Scope, define_default_value -from src.utils.errors import NamexError, SemanticError, TypexError +from utils import visitor +from utils.ast import ArrobaCallNode, AssignNode, AttrDeclarationNode, BlockNode, CaseNode, CaseOptionNode, ClassDeclarationNode, DotCallNode, FuncDeclarationNode, IdNode, IfThenElseNode, IntNode, IsVoidNode, LetInNode, MemberCallNode, ProgramNode, VarDeclarationNode, WhileNode +from semantic.semantic import ErrorType, IntType, Scope, define_default_value +from utils.errors import NamexError, SemanticError, TypexError class VarCollector: From 367eba9c3133863c16082a0793a9ce7838cd62d7 Mon Sep 17 00:00:00 2001 From: cwjki Date: Sun, 20 Feb 2022 20:08:31 -0500 Subject: [PATCH 122/194] fixing more imports --- src/cparser/parsetab.py | 118 ++--- src/main.py | 6 +- src/semantic/visitors/typeBuilder.py | 8 +- src/semantic/visitors/typeChecker.py | 754 +++++++++++++-------------- 4 files changed, 444 insertions(+), 442 deletions(-) diff --git a/src/cparser/parsetab.py b/src/cparser/parsetab.py index 2098fe1a9..fc129f583 100644 --- a/src/cparser/parsetab.py +++ b/src/cparser/parsetab.py @@ -6,9 +6,9 @@ _lr_method = 'LALR' -_lr_signature = 'programARROW ASSIGN AT BOOL CASE CLASS COLON COMMA DIV DOT ELSE EQUAL ESAC FI ID IF IN INHERITS INT ISVOID LBRACE LESS LESSEQ LET LNOT LOOP LPAREN MINUS NEW NOT OF PLUS POOL RBRACE RPAREN SEMICOLON STAR STRING THEN TYPE WHILEprogram : class_listepsilon :class_list : def_class SEMICOLON class_list\n | def_class SEMICOLON def_class : CLASS TYPE LBRACE feature_list RBRACE\n | CLASS TYPE INHERITS TYPE LBRACE feature_list RBRACEfeature_list : def_attr SEMICOLON feature_list\n | def_func SEMICOLON feature_list\n | epsilondef_attr : ID COLON TYPE\n | ID COLON TYPE ASSIGN exprdef_func : ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACEparams : param_list\n | param_list_emptyparam_list : param\n | param COMMA param_listparam_list_empty : epsilonparam : ID COLON TYPEexpr : LET let_attrs IN expr\n | CASE expr OF case_list ESAC\n | IF expr THEN expr ELSE expr FI\n | WHILE expr LOOP expr POOLexpr : ID ASSIGN exprexpr : expr AT TYPE DOT ID LPAREN args RPAREN\n | expr DOT ID LPAREN args RPAREN\n | ID LPAREN args RPARENexpr : expr PLUS expr\n | expr MINUS expr\n | expr STAR expr\n | expr DIV expr\n | expr LESS expr\n | expr LESSEQ expr\n | expr EQUAL exprexpr : NOT expr\n | ISVOID expr\n | LNOT exprexpr : LPAREN expr RPARENexpr : atomlet_attrs : def_attr\n | def_attr COMMA let_attrscase_list : case_option SEMICOLON\n | case_option SEMICOLON case_listcase_option : ID COLON TYPE ARROW exprargs : arg_list\n | arg_list_emptyarg_list : expr\n | expr COMMA arg_listarg_list_empty : epsilonatom : INTatom : IDatom : BOOLatom : STRINGatom : NEW TYPEatom : blockblock : LBRACE block_list RBRACE block_list : expr SEMICOLON\n | expr SEMICOLON block_list' +_lr_signature = 'programARROW ASSIGN AT BOOL CASE CLASS COLON COMMA DIV DOT ELSE EQUAL ESAC FI ID IF IN INHERITS INT ISVOID LBRACE LESS LESSEQ LET LNOT LOOP LPAREN MINUS NEW NOT OF PLUS POOL RBRACE RPAREN SEMICOLON STAR STRING THEN TYPE WHILEprogram : class_listepsilon :class_list : def_class SEMICOLON class_list\n | def_class SEMICOLON def_class : CLASS TYPE LBRACE feature_list RBRACE\n | CLASS TYPE INHERITS TYPE LBRACE feature_list RBRACEfeature_list : def_attr SEMICOLON feature_list\n | def_func SEMICOLON feature_list\n | epsilondef_attr : ID COLON TYPE\n | ID COLON TYPE ASSIGN exprdef_func : ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACEparams : param_list\n | param_list_emptyparam_list : param\n | param COMMA param_listparam_list_empty : epsilonparam : ID COLON TYPEexpr : LET let_attrs IN expr\n | CASE expr OF case_list ESAC\n | IF expr THEN expr ELSE expr FI\n | WHILE expr LOOP expr POOLexpr : ID ASSIGN exprexpr : expr AT TYPE DOT ID LPAREN args RPAREN\n | expr DOT ID LPAREN args RPAREN\n | ID LPAREN args RPARENexpr : expr PLUS expr\n | expr MINUS expr\n | expr STAR expr\n | expr DIV expr\n | expr LESS expr\n | expr LESSEQ expr\n | expr EQUAL exprexpr : NOT expr\n | ISVOID expr\n | LNOT exprexpr : LPAREN expr RPARENexpr : atomlet_attrs : def_var\n | def_var COMMA let_attrsdef_var : ID COLON TYPE\n | ID COLON TYPE ASSIGN exprcase_list : case_option SEMICOLON\n | case_option SEMICOLON case_listcase_option : ID COLON TYPE ARROW exprargs : arg_list\n | arg_list_emptyarg_list : expr\n | expr COMMA arg_listarg_list_empty : epsilonatom : INTatom : IDatom : BOOLatom : STRINGatom : NEW TYPEatom : blockblock : LBRACE block_list RBRACE block_list : expr SEMICOLON\n | expr SEMICOLON block_list' -_lr_action_items = {'CLASS':([0,5,],[4,4,]),'$end':([1,2,5,7,],[0,-1,-4,-3,]),'SEMICOLON':([3,11,12,16,24,36,37,38,47,48,49,50,52,75,76,77,78,80,82,90,91,92,93,94,95,96,102,103,106,110,113,122,126,127,129,135,136,137,],[5,17,18,-5,-10,-6,-50,-11,-38,-49,-51,-52,-54,-34,-35,-36,-53,104,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,123,-20,-22,-12,-25,-21,-24,-43,]),'TYPE':([4,9,19,33,51,55,59,124,],[6,15,24,54,78,81,88,131,]),'LBRACE':([6,15,32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,81,97,100,101,104,105,107,109,125,128,134,],[8,21,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,105,53,53,53,53,53,53,53,53,53,53,]),'INHERITS':([6,],[9,]),'ID':([8,17,18,20,21,32,35,39,40,41,42,43,44,45,46,53,57,58,60,61,62,63,64,65,66,67,97,98,99,100,101,104,105,107,108,109,123,125,128,134,],[14,14,14,25,14,37,25,70,37,37,37,37,37,37,37,37,37,37,89,37,37,37,37,37,37,37,37,70,114,37,37,37,37,37,120,37,114,37,37,37,]),'RBRACE':([8,10,13,17,18,21,22,23,31,37,47,48,49,50,52,75,76,77,78,79,82,90,91,92,93,94,95,96,102,103,104,106,110,117,118,122,126,129,135,136,],[-2,16,-9,-2,-2,-2,-7,-8,36,-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,103,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-56,-26,-19,-57,127,-20,-22,-25,-21,-24,]),'COLON':([14,25,34,70,114,],[19,33,55,19,124,]),'LPAREN':([14,32,37,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,89,97,100,101,104,105,107,109,120,125,128,134,],[20,43,58,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,109,43,43,43,43,43,43,43,128,43,43,43,]),'RPAREN':([20,26,27,28,29,30,37,47,48,49,50,52,54,56,58,74,75,76,77,78,82,83,84,85,86,87,90,91,92,93,94,95,96,102,103,106,109,110,119,121,122,126,128,129,133,135,136,],[-2,34,-13,-14,-15,-17,-50,-38,-49,-51,-52,-54,-18,-16,-2,102,-34,-35,-36,-53,-23,106,-44,-45,-46,-48,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-2,-19,-47,129,-20,-22,-2,-25,136,-21,-24,]),'COMMA':([24,29,37,38,47,48,49,50,52,54,69,75,76,77,78,82,86,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-10,35,-50,-11,-38,-49,-51,-52,-54,-18,98,-34,-35,-36,-53,-23,107,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'IN':([24,37,38,47,48,49,50,52,68,69,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,111,122,126,129,135,136,],[-10,-50,-11,-38,-49,-51,-52,-54,97,-39,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-40,-20,-22,-25,-21,-24,]),'ASSIGN':([24,37,],[32,57,]),'LET':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,]),'CASE':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,]),'IF':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,]),'WHILE':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,]),'NOT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,]),'ISVOID':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,]),'LNOT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,]),'INT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,]),'BOOL':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,]),'STRING':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,]),'NEW':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,]),'AT':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,59,-38,-49,-51,-52,-54,59,59,59,59,59,59,59,-53,59,59,59,59,59,59,59,59,59,59,-37,-55,-26,59,59,59,59,-20,-22,-25,59,-21,-24,59,]),'DOT':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,88,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,60,-38,-49,-51,-52,-54,60,60,60,60,60,60,60,-53,60,60,60,108,60,60,60,60,60,60,60,-37,-55,-26,60,60,60,60,-20,-22,-25,60,-21,-24,60,]),'PLUS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,61,-38,-49,-51,-52,-54,61,61,61,61,61,61,61,-53,61,61,61,61,61,61,61,61,61,61,-37,-55,-26,61,61,61,61,-20,-22,-25,61,-21,-24,61,]),'MINUS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,62,-38,-49,-51,-52,-54,62,62,62,62,62,62,62,-53,62,62,62,62,62,62,62,62,62,62,-37,-55,-26,62,62,62,62,-20,-22,-25,62,-21,-24,62,]),'STAR':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,63,-38,-49,-51,-52,-54,63,63,63,63,63,63,63,-53,63,63,63,63,63,63,63,63,63,63,-37,-55,-26,63,63,63,63,-20,-22,-25,63,-21,-24,63,]),'DIV':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,64,-38,-49,-51,-52,-54,64,64,64,64,64,64,64,-53,64,64,64,64,64,64,64,64,64,64,-37,-55,-26,64,64,64,64,-20,-22,-25,64,-21,-24,64,]),'LESS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,65,-38,-49,-51,-52,-54,65,65,65,65,65,65,65,-53,65,65,65,65,65,65,65,65,65,65,-37,-55,-26,65,65,65,65,-20,-22,-25,65,-21,-24,65,]),'LESSEQ':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,66,-38,-49,-51,-52,-54,66,66,66,66,66,66,66,-53,66,66,66,66,66,66,66,66,66,66,-37,-55,-26,66,66,66,66,-20,-22,-25,66,-21,-24,66,]),'EQUAL':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,102,103,106,110,115,116,118,122,126,129,132,135,136,137,],[-50,67,-38,-49,-51,-52,-54,67,67,67,67,67,67,67,-53,67,67,67,67,67,67,67,67,67,67,-37,-55,-26,67,67,67,67,-20,-22,-25,67,-21,-24,67,]),'OF':([37,47,48,49,50,52,71,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,99,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'THEN':([37,47,48,49,50,52,72,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,100,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'LOOP':([37,47,48,49,50,52,73,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,101,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,-21,-24,]),'ELSE':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,115,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,125,-20,-22,-25,-21,-24,]),'POOL':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,116,122,126,129,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,126,-20,-22,-25,-21,-24,]),'FI':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,102,103,106,110,122,126,129,132,135,136,],[-50,-38,-49,-51,-52,-54,-34,-35,-36,-53,-23,-27,-28,-29,-30,-31,-32,-33,-37,-55,-26,-19,-20,-22,-25,135,-21,-24,]),'ESAC':([112,123,130,],[122,-41,-42,]),'ARROW':([131,],[134,]),} +_lr_action_items = {'CLASS':([0,5,],[4,4,]),'$end':([1,2,5,7,],[0,-1,-4,-3,]),'SEMICOLON':([3,11,12,16,24,36,37,38,47,48,49,50,52,75,76,77,78,80,82,90,91,92,93,94,95,96,103,104,107,111,115,125,129,130,132,139,140,141,],[5,17,18,-5,-10,-6,-52,-11,-38,-51,-53,-54,-56,-34,-35,-36,-55,105,-23,-27,-28,-29,-30,-31,-32,-33,-37,-57,-26,-19,126,-20,-22,-12,-25,-21,-24,-45,]),'TYPE':([4,9,19,33,51,55,59,99,127,],[6,15,24,54,78,81,88,113,135,]),'LBRACE':([6,15,32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,81,97,101,102,105,106,108,110,124,128,131,138,],[8,21,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,106,53,53,53,53,53,53,53,53,53,53,53,]),'INHERITS':([6,],[9,]),'ID':([8,17,18,20,21,32,35,39,40,41,42,43,44,45,46,53,57,58,60,61,62,63,64,65,66,67,97,98,100,101,102,105,106,108,109,110,124,126,128,131,138,],[14,14,14,25,14,37,25,70,37,37,37,37,37,37,37,37,37,37,89,37,37,37,37,37,37,37,37,70,116,37,37,37,37,37,122,37,37,116,37,37,37,]),'RBRACE':([8,10,13,17,18,21,22,23,31,37,47,48,49,50,52,75,76,77,78,79,82,90,91,92,93,94,95,96,103,104,105,107,111,119,120,125,129,132,139,140,],[-2,16,-9,-2,-2,-2,-7,-8,36,-52,-38,-51,-53,-54,-56,-34,-35,-36,-55,104,-23,-27,-28,-29,-30,-31,-32,-33,-37,-57,-58,-26,-19,-59,130,-20,-22,-25,-21,-24,]),'COLON':([14,25,34,70,116,],[19,33,55,99,127,]),'LPAREN':([14,32,37,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,89,97,101,102,105,106,108,110,122,124,128,131,138,],[20,43,58,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,110,43,43,43,43,43,43,43,131,43,43,43,43,]),'RPAREN':([20,26,27,28,29,30,37,47,48,49,50,52,54,56,58,74,75,76,77,78,82,83,84,85,86,87,90,91,92,93,94,95,96,103,104,107,110,111,121,123,125,129,131,132,137,139,140,],[-2,34,-13,-14,-15,-17,-52,-38,-51,-53,-54,-56,-18,-16,-2,103,-34,-35,-36,-55,-23,107,-46,-47,-48,-50,-27,-28,-29,-30,-31,-32,-33,-37,-57,-26,-2,-19,-49,132,-20,-22,-2,-25,140,-21,-24,]),'ASSIGN':([24,37,113,],[32,57,124,]),'COMMA':([29,37,47,48,49,50,52,54,69,75,76,77,78,82,86,90,91,92,93,94,95,96,103,104,107,111,113,125,129,132,133,139,140,],[35,-52,-38,-51,-53,-54,-56,-18,98,-34,-35,-36,-55,-23,108,-27,-28,-29,-30,-31,-32,-33,-37,-57,-26,-19,-41,-20,-22,-25,-42,-21,-24,]),'LET':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,101,102,105,106,108,110,124,128,131,138,],[39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,]),'CASE':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,101,102,105,106,108,110,124,128,131,138,],[40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,]),'IF':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,101,102,105,106,108,110,124,128,131,138,],[41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,]),'WHILE':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,101,102,105,106,108,110,124,128,131,138,],[42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,]),'NOT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,101,102,105,106,108,110,124,128,131,138,],[44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,]),'ISVOID':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,101,102,105,106,108,110,124,128,131,138,],[45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,]),'LNOT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,101,102,105,106,108,110,124,128,131,138,],[46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,]),'INT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,101,102,105,106,108,110,124,128,131,138,],[48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,]),'BOOL':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,101,102,105,106,108,110,124,128,131,138,],[49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,]),'STRING':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,101,102,105,106,108,110,124,128,131,138,],[50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,]),'NEW':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,101,102,105,106,108,110,124,128,131,138,],[51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,]),'AT':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,103,104,107,111,117,118,120,125,129,132,133,136,139,140,141,],[-52,59,-38,-51,-53,-54,-56,59,59,59,59,59,59,59,-55,59,59,59,59,59,59,59,59,59,59,-37,-57,-26,59,59,59,59,-20,-22,-25,59,59,-21,-24,59,]),'DOT':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,88,90,91,92,93,94,95,96,103,104,107,111,117,118,120,125,129,132,133,136,139,140,141,],[-52,60,-38,-51,-53,-54,-56,60,60,60,60,60,60,60,-55,60,60,60,109,60,60,60,60,60,60,60,-37,-57,-26,60,60,60,60,-20,-22,-25,60,60,-21,-24,60,]),'PLUS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,103,104,107,111,117,118,120,125,129,132,133,136,139,140,141,],[-52,61,-38,-51,-53,-54,-56,61,61,61,61,61,61,61,-55,61,61,61,61,61,61,61,61,61,61,-37,-57,-26,61,61,61,61,-20,-22,-25,61,61,-21,-24,61,]),'MINUS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,103,104,107,111,117,118,120,125,129,132,133,136,139,140,141,],[-52,62,-38,-51,-53,-54,-56,62,62,62,62,62,62,62,-55,62,62,62,62,62,62,62,62,62,62,-37,-57,-26,62,62,62,62,-20,-22,-25,62,62,-21,-24,62,]),'STAR':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,103,104,107,111,117,118,120,125,129,132,133,136,139,140,141,],[-52,63,-38,-51,-53,-54,-56,63,63,63,63,63,63,63,-55,63,63,63,63,63,63,63,63,63,63,-37,-57,-26,63,63,63,63,-20,-22,-25,63,63,-21,-24,63,]),'DIV':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,103,104,107,111,117,118,120,125,129,132,133,136,139,140,141,],[-52,64,-38,-51,-53,-54,-56,64,64,64,64,64,64,64,-55,64,64,64,64,64,64,64,64,64,64,-37,-57,-26,64,64,64,64,-20,-22,-25,64,64,-21,-24,64,]),'LESS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,103,104,107,111,117,118,120,125,129,132,133,136,139,140,141,],[-52,65,-38,-51,-53,-54,-56,65,65,65,65,65,65,65,-55,65,65,65,65,65,65,65,65,65,65,-37,-57,-26,65,65,65,65,-20,-22,-25,65,65,-21,-24,65,]),'LESSEQ':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,103,104,107,111,117,118,120,125,129,132,133,136,139,140,141,],[-52,66,-38,-51,-53,-54,-56,66,66,66,66,66,66,66,-55,66,66,66,66,66,66,66,66,66,66,-37,-57,-26,66,66,66,66,-20,-22,-25,66,66,-21,-24,66,]),'EQUAL':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,103,104,107,111,117,118,120,125,129,132,133,136,139,140,141,],[-52,67,-38,-51,-53,-54,-56,67,67,67,67,67,67,67,-55,67,67,67,67,67,67,67,67,67,67,-37,-57,-26,67,67,67,67,-20,-22,-25,67,67,-21,-24,67,]),'OF':([37,47,48,49,50,52,71,75,76,77,78,82,90,91,92,93,94,95,96,103,104,107,111,125,129,132,139,140,],[-52,-38,-51,-53,-54,-56,100,-34,-35,-36,-55,-23,-27,-28,-29,-30,-31,-32,-33,-37,-57,-26,-19,-20,-22,-25,-21,-24,]),'THEN':([37,47,48,49,50,52,72,75,76,77,78,82,90,91,92,93,94,95,96,103,104,107,111,125,129,132,139,140,],[-52,-38,-51,-53,-54,-56,101,-34,-35,-36,-55,-23,-27,-28,-29,-30,-31,-32,-33,-37,-57,-26,-19,-20,-22,-25,-21,-24,]),'LOOP':([37,47,48,49,50,52,73,75,76,77,78,82,90,91,92,93,94,95,96,103,104,107,111,125,129,132,139,140,],[-52,-38,-51,-53,-54,-56,102,-34,-35,-36,-55,-23,-27,-28,-29,-30,-31,-32,-33,-37,-57,-26,-19,-20,-22,-25,-21,-24,]),'ELSE':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,103,104,107,111,117,125,129,132,139,140,],[-52,-38,-51,-53,-54,-56,-34,-35,-36,-55,-23,-27,-28,-29,-30,-31,-32,-33,-37,-57,-26,-19,128,-20,-22,-25,-21,-24,]),'POOL':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,103,104,107,111,118,125,129,132,139,140,],[-52,-38,-51,-53,-54,-56,-34,-35,-36,-55,-23,-27,-28,-29,-30,-31,-32,-33,-37,-57,-26,-19,129,-20,-22,-25,-21,-24,]),'IN':([37,47,48,49,50,52,68,69,75,76,77,78,82,90,91,92,93,94,95,96,103,104,107,111,112,113,125,129,132,133,139,140,],[-52,-38,-51,-53,-54,-56,97,-39,-34,-35,-36,-55,-23,-27,-28,-29,-30,-31,-32,-33,-37,-57,-26,-19,-40,-41,-20,-22,-25,-42,-21,-24,]),'FI':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,103,104,107,111,125,129,132,136,139,140,],[-52,-38,-51,-53,-54,-56,-34,-35,-36,-55,-23,-27,-28,-29,-30,-31,-32,-33,-37,-57,-26,-19,-20,-22,-25,139,-21,-24,]),'ESAC':([114,126,134,],[125,-43,-44,]),'ARROW':([135,],[138,]),} _lr_action = {} for _k, _v in _lr_action_items.items(): @@ -17,7 +17,7 @@ _lr_action[_x][_k] = _y del _lr_action_items -_lr_goto_items = {'program':([0,],[1,]),'class_list':([0,5,],[2,7,]),'def_class':([0,5,],[3,3,]),'feature_list':([8,17,18,21,],[10,22,23,31,]),'def_attr':([8,17,18,21,39,98,],[11,11,11,11,69,69,]),'def_func':([8,17,18,21,],[12,12,12,12,]),'epsilon':([8,17,18,20,21,58,109,128,],[13,13,13,30,13,87,87,87,]),'params':([20,],[26,]),'param_list':([20,35,],[27,56,]),'param_list_empty':([20,],[28,]),'param':([20,35,],[29,29,]),'expr':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[38,71,72,73,74,75,76,77,80,82,86,90,91,92,93,94,95,96,110,115,116,80,118,86,86,132,86,137,]),'atom':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,]),'block':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,100,101,104,105,107,109,125,128,134,],[52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,]),'let_attrs':([39,98,],[68,111,]),'block_list':([53,104,],[79,117,]),'args':([58,109,128,],[83,121,133,]),'arg_list':([58,107,109,128,],[84,119,84,84,]),'arg_list_empty':([58,109,128,],[85,85,85,]),'case_list':([99,123,],[112,130,]),'case_option':([99,123,],[113,113,]),} +_lr_goto_items = {'program':([0,],[1,]),'class_list':([0,5,],[2,7,]),'def_class':([0,5,],[3,3,]),'feature_list':([8,17,18,21,],[10,22,23,31,]),'def_attr':([8,17,18,21,],[11,11,11,11,]),'def_func':([8,17,18,21,],[12,12,12,12,]),'epsilon':([8,17,18,20,21,58,110,131,],[13,13,13,30,13,87,87,87,]),'params':([20,],[26,]),'param_list':([20,35,],[27,56,]),'param_list_empty':([20,],[28,]),'param':([20,35,],[29,29,]),'expr':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,101,102,105,106,108,110,124,128,131,138,],[38,71,72,73,74,75,76,77,80,82,86,90,91,92,93,94,95,96,111,117,118,80,120,86,86,133,136,86,141,]),'atom':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,101,102,105,106,108,110,124,128,131,138,],[47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,]),'block':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,101,102,105,106,108,110,124,128,131,138,],[52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,]),'let_attrs':([39,98,],[68,112,]),'def_var':([39,98,],[69,69,]),'block_list':([53,105,],[79,119,]),'args':([58,110,131,],[83,123,137,]),'arg_list':([58,108,110,131,],[84,121,84,84,]),'arg_list_empty':([58,110,131,],[85,85,85,]),'case_list':([100,126,],[114,134,]),'case_option':([100,126,],[115,115,]),} _lr_goto = {} for _k, _v in _lr_goto_items.items(): @@ -29,59 +29,61 @@ ("S' -> program","S'",1,None,None,None), ('program -> class_list','program',1,'p_program','parser.py',28), ('epsilon -> ','epsilon',0,'p_epsilon','parser.py',32), - ('class_list -> def_class SEMICOLON class_list','class_list',3,'p_class_list','parser.py',35), - ('class_list -> def_class SEMICOLON','class_list',2,'p_class_list','parser.py',36), - ('def_class -> CLASS TYPE LBRACE feature_list RBRACE','def_class',5,'p_def_class','parser.py',40), - ('def_class -> CLASS TYPE INHERITS TYPE LBRACE feature_list RBRACE','def_class',7,'p_def_class','parser.py',41), - ('feature_list -> def_attr SEMICOLON feature_list','feature_list',3,'p_feature_list','parser.py',51), - ('feature_list -> def_func SEMICOLON feature_list','feature_list',3,'p_feature_list','parser.py',52), - ('feature_list -> epsilon','feature_list',1,'p_feature_list','parser.py',53), - ('def_attr -> ID COLON TYPE','def_attr',3,'p_def_attr','parser.py',57), - ('def_attr -> ID COLON TYPE ASSIGN expr','def_attr',5,'p_def_attr','parser.py',58), - ('def_func -> ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACE','def_func',9,'p_def_func','parser.py',68), - ('params -> param_list','params',1,'p_params','parser.py',74), - ('params -> param_list_empty','params',1,'p_params','parser.py',75), - ('param_list -> param','param_list',1,'p_param_list','parser.py',79), - ('param_list -> param COMMA param_list','param_list',3,'p_param_list','parser.py',80), - ('param_list_empty -> epsilon','param_list_empty',1,'p_param_list_empty','parser.py',84), - ('param -> ID COLON TYPE','param',3,'p_param','parser.py',88), - ('expr -> LET let_attrs IN expr','expr',4,'p_expr_flow','parser.py',92), - ('expr -> CASE expr OF case_list ESAC','expr',5,'p_expr_flow','parser.py',93), - ('expr -> IF expr THEN expr ELSE expr FI','expr',7,'p_expr_flow','parser.py',94), - ('expr -> WHILE expr LOOP expr POOL','expr',5,'p_expr_flow','parser.py',95), - ('expr -> ID ASSIGN expr','expr',3,'p_expr_assign','parser.py',110), - ('expr -> expr AT TYPE DOT ID LPAREN args RPAREN','expr',8,'p_expr_func_call','parser.py',116), - ('expr -> expr DOT ID LPAREN args RPAREN','expr',6,'p_expr_func_call','parser.py',117), - ('expr -> ID LPAREN args RPAREN','expr',4,'p_expr_func_call','parser.py',118), - ('expr -> expr PLUS expr','expr',3,'p_expr_operators_binary','parser.py',141), - ('expr -> expr MINUS expr','expr',3,'p_expr_operators_binary','parser.py',142), - ('expr -> expr STAR expr','expr',3,'p_expr_operators_binary','parser.py',143), - ('expr -> expr DIV expr','expr',3,'p_expr_operators_binary','parser.py',144), - ('expr -> expr LESS expr','expr',3,'p_expr_operators_binary','parser.py',145), - ('expr -> expr LESSEQ expr','expr',3,'p_expr_operators_binary','parser.py',146), - ('expr -> expr EQUAL expr','expr',3,'p_expr_operators_binary','parser.py',147), - ('expr -> NOT expr','expr',2,'p_expr_operators_unary','parser.py',167), - ('expr -> ISVOID expr','expr',2,'p_expr_operators_unary','parser.py',168), - ('expr -> LNOT expr','expr',2,'p_expr_operators_unary','parser.py',169), - ('expr -> LPAREN expr RPAREN','expr',3,'p_expr_group','parser.py',181), - ('expr -> atom','expr',1,'p_expr_atom','parser.py',185), - ('let_attrs -> def_attr','let_attrs',1,'p_let_attrs','parser.py',189), - ('let_attrs -> def_attr COMMA let_attrs','let_attrs',3,'p_let_attrs','parser.py',190), - ('case_list -> case_option SEMICOLON','case_list',2,'p_case_list','parser.py',194), - ('case_list -> case_option SEMICOLON case_list','case_list',3,'p_case_list','parser.py',195), - ('case_option -> ID COLON TYPE ARROW expr','case_option',5,'p_case_option','parser.py',199), - ('args -> arg_list','args',1,'p_args','parser.py',205), - ('args -> arg_list_empty','args',1,'p_args','parser.py',206), - ('arg_list -> expr','arg_list',1,'p_arg_list','parser.py',210), - ('arg_list -> expr COMMA arg_list','arg_list',3,'p_arg_list','parser.py',211), - ('arg_list_empty -> epsilon','arg_list_empty',1,'p_arg_list_empty','parser.py',215), - ('atom -> INT','atom',1,'p_atom_int','parser.py',219), - ('atom -> ID','atom',1,'p_atom_id','parser.py',225), - ('atom -> BOOL','atom',1,'p_atom_bool','parser.py',231), - ('atom -> STRING','atom',1,'p_atom_string','parser.py',237), - ('atom -> NEW TYPE','atom',2,'p_atom_new','parser.py',243), - ('atom -> block','atom',1,'p_atom_block','parser.py',249), - ('block -> LBRACE block_list RBRACE','block',3,'p_block','parser.py',253), - ('block_list -> expr SEMICOLON','block_list',2,'p_block_list','parser.py',257), - ('block_list -> expr SEMICOLON block_list','block_list',3,'p_block_list','parser.py',258), + ('class_list -> def_class SEMICOLON class_list','class_list',3,'p_class_list','parser.py',36), + ('class_list -> def_class SEMICOLON','class_list',2,'p_class_list','parser.py',37), + ('def_class -> CLASS TYPE LBRACE feature_list RBRACE','def_class',5,'p_def_class','parser.py',41), + ('def_class -> CLASS TYPE INHERITS TYPE LBRACE feature_list RBRACE','def_class',7,'p_def_class','parser.py',42), + ('feature_list -> def_attr SEMICOLON feature_list','feature_list',3,'p_feature_list','parser.py',49), + ('feature_list -> def_func SEMICOLON feature_list','feature_list',3,'p_feature_list','parser.py',50), + ('feature_list -> epsilon','feature_list',1,'p_feature_list','parser.py',51), + ('def_attr -> ID COLON TYPE','def_attr',3,'p_def_attr','parser.py',55), + ('def_attr -> ID COLON TYPE ASSIGN expr','def_attr',5,'p_def_attr','parser.py',56), + ('def_func -> ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACE','def_func',9,'p_def_func','parser.py',63), + ('params -> param_list','params',1,'p_params','parser.py',67), + ('params -> param_list_empty','params',1,'p_params','parser.py',68), + ('param_list -> param','param_list',1,'p_param_list','parser.py',72), + ('param_list -> param COMMA param_list','param_list',3,'p_param_list','parser.py',73), + ('param_list_empty -> epsilon','param_list_empty',1,'p_param_list_empty','parser.py',77), + ('param -> ID COLON TYPE','param',3,'p_param','parser.py',81), + ('expr -> LET let_attrs IN expr','expr',4,'p_expr_flow','parser.py',85), + ('expr -> CASE expr OF case_list ESAC','expr',5,'p_expr_flow','parser.py',86), + ('expr -> IF expr THEN expr ELSE expr FI','expr',7,'p_expr_flow','parser.py',87), + ('expr -> WHILE expr LOOP expr POOL','expr',5,'p_expr_flow','parser.py',88), + ('expr -> ID ASSIGN expr','expr',3,'p_expr_assign','parser.py',100), + ('expr -> expr AT TYPE DOT ID LPAREN args RPAREN','expr',8,'p_expr_func_call','parser.py',104), + ('expr -> expr DOT ID LPAREN args RPAREN','expr',6,'p_expr_func_call','parser.py',105), + ('expr -> ID LPAREN args RPAREN','expr',4,'p_expr_func_call','parser.py',106), + ('expr -> expr PLUS expr','expr',3,'p_expr_operators_binary','parser.py',123), + ('expr -> expr MINUS expr','expr',3,'p_expr_operators_binary','parser.py',124), + ('expr -> expr STAR expr','expr',3,'p_expr_operators_binary','parser.py',125), + ('expr -> expr DIV expr','expr',3,'p_expr_operators_binary','parser.py',126), + ('expr -> expr LESS expr','expr',3,'p_expr_operators_binary','parser.py',127), + ('expr -> expr LESSEQ expr','expr',3,'p_expr_operators_binary','parser.py',128), + ('expr -> expr EQUAL expr','expr',3,'p_expr_operators_binary','parser.py',129), + ('expr -> NOT expr','expr',2,'p_expr_operators_unary','parser.py',146), + ('expr -> ISVOID expr','expr',2,'p_expr_operators_unary','parser.py',147), + ('expr -> LNOT expr','expr',2,'p_expr_operators_unary','parser.py',148), + ('expr -> LPAREN expr RPAREN','expr',3,'p_expr_group','parser.py',157), + ('expr -> atom','expr',1,'p_expr_atom','parser.py',161), + ('let_attrs -> def_var','let_attrs',1,'p_let_attrs','parser.py',165), + ('let_attrs -> def_var COMMA let_attrs','let_attrs',3,'p_let_attrs','parser.py',166), + ('def_var -> ID COLON TYPE','def_var',3,'p_def_var','parser.py',170), + ('def_var -> ID COLON TYPE ASSIGN expr','def_var',5,'p_def_var','parser.py',171), + ('case_list -> case_option SEMICOLON','case_list',2,'p_case_list','parser.py',178), + ('case_list -> case_option SEMICOLON case_list','case_list',3,'p_case_list','parser.py',179), + ('case_option -> ID COLON TYPE ARROW expr','case_option',5,'p_case_option','parser.py',183), + ('args -> arg_list','args',1,'p_args','parser.py',187), + ('args -> arg_list_empty','args',1,'p_args','parser.py',188), + ('arg_list -> expr','arg_list',1,'p_arg_list','parser.py',192), + ('arg_list -> expr COMMA arg_list','arg_list',3,'p_arg_list','parser.py',193), + ('arg_list_empty -> epsilon','arg_list_empty',1,'p_arg_list_empty','parser.py',197), + ('atom -> INT','atom',1,'p_atom_int','parser.py',201), + ('atom -> ID','atom',1,'p_atom_id','parser.py',205), + ('atom -> BOOL','atom',1,'p_atom_bool','parser.py',209), + ('atom -> STRING','atom',1,'p_atom_string','parser.py',213), + ('atom -> NEW TYPE','atom',2,'p_atom_new','parser.py',217), + ('atom -> block','atom',1,'p_atom_block','parser.py',221), + ('block -> LBRACE block_list RBRACE','block',3,'p_block','parser.py',225), + ('block_list -> expr SEMICOLON','block_list',2,'p_block_list','parser.py',229), + ('block_list -> expr SEMICOLON block_list','block_list',3,'p_block_list','parser.py',230), ] diff --git a/src/main.py b/src/main.py index c8038e86d..82e27d79e 100644 --- a/src/main.py +++ b/src/main.py @@ -4,7 +4,7 @@ from lexer import CoolLexer from cparser import CoolParser from semantic.visitors.typeBuilder import TypeBuilder -from semantic.visitors.typeChecker import TypeChecker +# from semantic.visitors.typeChecker import TypeChecker from semantic.visitors.typeCollector import TypeCollector from semantic.visitors.varCollector import VarCollector @@ -34,8 +34,8 @@ def main(_input, _output): typeBuilder.visit(ast) typeInferer = VarCollector(context, semanticErrors) scope = typeInferer.visit(ast) - typeChecker = TypeChecker(context, semanticErrors) - typeChecker.visit(ast, scope) + # typeChecker = TypeChecker(context, semanticErrors) + # typeChecker.visit(ast, scope) if semanticErrors: for error in semanticErrors: print(semanticErrors) diff --git a/src/semantic/visitors/typeBuilder.py b/src/semantic/visitors/typeBuilder.py index a873b94fd..b54941a20 100644 --- a/src/semantic/visitors/typeBuilder.py +++ b/src/semantic/visitors/typeBuilder.py @@ -14,12 +14,12 @@ def __init__(self, context, errors): def visit(self, node): pass - @visit.when(ProgramNode) + @visitor.when(ProgramNode) def visit(self, programNode): for declaration in programNode.declarations: self.visit(declaration) - @visit.when(ClassDeclarationNode) + @visitor.when(ClassDeclarationNode) def visit(self, classDeclarationNode): try: self.currentType = self.context.get_type( @@ -58,7 +58,7 @@ def visit(self, classDeclarationNode): for feature in classDeclarationNode.features: self.visit(feature) - @visit.when(FuncDeclarationNode) + @visitor.when(FuncDeclarationNode) def visit(self, funcDeclarationNode): argsNames = [] argsTypes = [] @@ -94,7 +94,7 @@ def visit(self, funcDeclarationNode): except SemanticError as error: self.errors.append(error) - @visit.when(AttrDeclarationNode) + @visitor.when(AttrDeclarationNode) def visit(self, attrDeclarationNode): try: attrType = self.context.get_type( diff --git a/src/semantic/visitors/typeChecker.py b/src/semantic/visitors/typeChecker.py index 70f7e94c5..46ae10ab9 100644 --- a/src/semantic/visitors/typeChecker.py +++ b/src/semantic/visitors/typeChecker.py @@ -1,377 +1,377 @@ -from utils import visitor -from semantic.semantic import * -from utils.ast import * -from utils.errors import SemanticError, AttributesError, TypesError, NamesError -from utils import get_type, get_common_basetype - - -class TypeChecker: - def __init__(self, context: Context, errors=[]): - self.context: Context = context - self.current_type: Type = None - self.current_method: Method = None - self.errors = errors - self.current_index = None # Lleva el índice del scope en el que se está - - @visitor.on('node') - def visit(self, node, scope): - pass - - @visitor.when(ProgramNode) - def visit(self, node: ProgramNode, scope: Scope): - for declaration, new_scope in zip(node.declarations, scope.children): - self.visit(declaration, new_scope) - - def _get_type(self, ntype: str, pos): - try: - return self.context.get_type(ntype, pos) - except SemanticError as e: - self.errors.append(e) - return ErrorType() - - def _get_method(self, typex: Type, name: str, pos) -> Method: - try: - return typex.get_method(name, pos) - except SemanticError as e: - if type(typex) != ErrorType and type(typex) != AutoType: - error_text = AttributesError.DISPATCH_UNDEFINED % name - self.errors.append(AttributesError(error_text, *pos)) - return MethodError(name, [], [], ErrorType()) - - @visitor.when(ClassDeclarationNode) - def visit(self, node: ClassDeclarationNode, scope: Scope): - self.current_type = self.context.get_type(node.id, node.pos) - - fd = [feat for feat in node.features if isinstance( - feat, FuncDeclarationNode)] - - for feat in node.features: - if isinstance(feat, AttrDeclarationNode): - self.visit(feat, scope) - - for feat, child_scope in zip(fd, scope.functions.values()): - self.visit(feat, child_scope) - - @visitor.when(AttrDeclarationNode) - def visit(self, node: AttrDeclarationNode, scope: Scope): - attr = self.current_type.get_attribute(node.id, node.pos) - vartype = get_type(attr.type, self.current_type) - - self.current_index = attr.index - typex = self.visit(node.expr, scope) - self.current_index = None - - if not typex.conforms_to(vartype): - error_text = TypesError.ATTR_TYPE_ERROR % ( - typex.name, attr.name, vartype.name) - self.errors.append(TypesError(error_text, *node.pos)) - return ErrorType() - return typex - - @visitor.when(FuncDeclarationNode) - def visit(self, node: FuncDeclarationNode, scope: Scope): - parent = self.current_type.parent - - self.current_method = method = self.current_type.get_method( - node.id, node.pos) - if parent is not None: - try: - old_meth = parent.get_method(node.id, node.pos) - if old_meth.return_type.name != method.return_type.name: - error_text = SemanticError.WRONG_SIGNATURE_RETURN % ( - node.id, method.return_type.name, old_meth.return_type.name) - self.errors.append(SemanticError( - error_text, *node.type_pos)) - if len(method.param_names) != len(old_meth.param_names): - error_text = SemanticError.WRONG_NUMBER_PARAM % node.id - self.errors.append(SemanticError(error_text, *node.pos)) - for (name, param), type1, type2 in zip(node.params, method.param_types, old_meth.param_types): - if type1.name != type2.name: - error_text = SemanticError.WRONG_SIGNATURE_PARAMETER % ( - name, type1.name, type2.name) - self.errors.append( - SemanticError(error_text, *param.pos)) - except SemanticError: - pass - - result = self.visit(node.body, scope) - - return_type = get_type(method.return_type, self.current_type) - - if not result.conforms_to(return_type): - error_text = TypesError.RETURN_TYPE_ERROR % ( - result.name, return_type.name) - self.errors.append(TypesError(error_text, *node.type_pos)) - - @visitor.when(VarDeclarationNode) - def visit(self, node: VarDeclarationNode, scope: Scope): - - vtype = self._get_type(node.type, node.type_pos) - vtype = get_type(vtype, self.current_type) - - if node.expr != None: - typex = self.visit(node.expr, scope) - if not typex.conforms_to(vtype): - error_text = TypesError.UNCONFORMS_TYPE % ( - typex.name, node.id, vtype.name) - self.errors.append(TypesError(error_text, *node.type_pos)) - return typex - return vtype - - @visitor.when(AssignNode) - def visit(self, node: AssignNode, scope: Scope): - vinfo = self.find_variable(scope, node.id) - vtype = get_type(vinfo.type, self.current_type) - - typex = self.visit(node.expr, scope) - - if not typex.conforms_to(vtype): - error_text = TypesError.UNCONFORMS_TYPE % ( - typex.name, node.id, vtype.name) - self.errors.append(TypesError(error_text, *node.pos)) - return typex - - def _check_args(self, meth: Method, scope: Scope, args, pos): - arg_types = [self.visit(arg, scope) for arg in args] - - if len(arg_types) > len(meth.param_types): - error_text = SemanticError.ARGUMENT_ERROR % meth.name - self.errors.append(SemanticError(error_text, *pos)) - elif len(arg_types) < len(meth.param_types): - for arg, arg_info in zip(meth.param_names[len(arg_types):], args[len(arg_types):]): - error_text = SemanticError.ARGUMENT_ERROR % (meth.name) - self.errors.append(SemanticError(error_text, *arg_info.pos)) - - for atype, ptype, param_name in zip(arg_types, meth.param_types, meth.param_names): - if not atype.conforms_to(ptype): - error_text = TypesError.INCOSISTENT_ARG_TYPE % ( - meth.name, atype.name, param_name, ptype.name) - self.errors.append(TypesError(error_text, *pos)) - - @visitor.when(CallNode) - def visit(self, node: CallNode, scope: Scope): - stype = self.visit(node.obj, scope) - - meth = self._get_method(stype, node.id, node.pos) - if not isinstance(meth, MethodError): - self._check_args(meth, scope, node.args, node.pos) - - return get_type(meth.return_type, stype) - - @visitor.when(BaseCallNode) - def visit(self, node: BaseCallNode, scope: Scope): - obj = self.visit(node.obj, scope) - typex = self._get_type(node.type, node.type_pos) - - if not obj.conforms_to(typex): - error_text = TypesError.INCOMPATIBLE_TYPES_DISPATCH % ( - typex.name, obj.name) - self.errors.append(TypesError(error_text, *node.type_pos)) - return ErrorType() - - meth = self._get_method(typex, node.id, node.pos) - if not isinstance(meth, MethodError): - self._check_args(meth, scope, node.args, node.pos) - - return get_type(meth.return_type, typex) - - @visitor.when(StaticCallNode) - def visit(self, node: StaticCallNode, scope: Scope): - typex = self.current_type - - meth = self._get_method(typex, node.id, node.pos) - if not isinstance(meth, MethodError): - self._check_args(meth, scope, node.args, node.pos) - - return get_type(meth.return_type, typex) - - @visitor.when(ConstantNumNode) - def visit(self, node: ConstantNumNode, scope: Scope): - return IntType(node.pos) - - @visitor.when(ConstantBoolNode) - def visit(self, node: ConstantBoolNode, scope: Scope): - return BoolType(node.pos) - - @visitor.when(ConstantStrNode) - def visit(self, node: ConstantStrNode, scope: Scope): - return StringType(node.pos) - - @visitor.when(ConstantVoidNode) - def visit(self, node: ConstantVoidNode, scope: Scope): - return VoidType(node.pos) - - def find_variable(self, scope, lex): - var_info = scope.find_local(lex) - if var_info is None: - var_info = scope.find_attribute(lex) - if lex in self.current_type.attributes and var_info is None: - return VariableInfo(lex, VoidType()) - return var_info - - @visitor.when(VariableNode) - def visit(self, node: VariableNode, scope: Scope): - typex = self.find_variable(scope, node.lex).type - return get_type(typex, self.current_type) - - @visitor.when(InstantiateNode) - def visit(self, node: InstantiateNode, scope: Scope): - try: - type_ = self.context.get_type(node.lex, node.pos) - except SemanticError: - type_ = ErrorType() - error_text = TypesError.NEW_UNDEFINED_CLASS % node.lex - self.errors.append(TypesError(error_text, *node.pos)) - - return get_type(type_, self.current_type) - - @visitor.when(WhileNode) - def visit(self, node: WhileNode, scope: Scope): - cond = self.visit(node.cond, scope) - - if cond.name != 'Bool': - self.errors.append(TypesError( - TypesError.LOOP_CONDITION_ERROR, *node.pos)) - - self.visit(node.expr, scope) - return ObjectType() - - @visitor.when(IsVoidNode) - def visit(self, node: IsVoidNode, scope: Scope): - self.visit(node.expr, scope) - return BoolType() - - @visitor.when(ConditionalNode) - def visit(self, node: ConditionalNode, scope: Scope): - cond = self.visit(node.cond, scope) - - if cond.name != 'Bool': - error_text = TypesError.PREDICATE_ERROR % ('if', 'Bool') - self.errors.append(TypesError(error_text, *node.pos)) - - true_type = self.visit(node.stm, scope) - false_type = self.visit(node.else_stm, scope) - - return get_common_basetype([false_type, true_type]) - # if true_type.conforms_to(false_type): - # return false_type - # elif false_type.conforms_to(true_type): - # return true_type - # else: - # error_text = TypesError.INCOMPATIBLE_TYPES % (false_type.name, true_type.name) - # self.errors.append(TypesError(error_text, *node.pos)) - # return ErrorType() - - @visitor.when(BlockNode) - def visit(self, node: BlockNode, scope: Scope): - value = None - for exp in node.expr_list: - value = self.visit(exp, scope) - return value - - @visitor.when(LetNode) - def visit(self, node: LetNode, scope: Scope): - child_scope = scope.expr_dict[node] - for init in node.init_list: - self.visit(init, child_scope) - return self.visit(node.expr, child_scope) - - @visitor.when(CaseNode) - def visit(self, node: CaseNode, scope: Scope): - type_expr = self.visit(node.expr, scope) - - new_scope = scope.expr_dict[node] - types = [] - var_types = [] - for case, c_scope in zip(node.case_list, new_scope.children): - case: OptionNode - t, vt = self.visit(case, c_scope) - types.append(t) - if case.typex in var_types: - error_text = SemanticError.DUPLICATE_CASE_BRANCH % case.typex - self.errors.append(SemanticError(error_text, *case.type_pos)) - var_types.append(case.typex) - - # for t in var_types: - # if not type_expr.conforms_to(t): - # error_text = TypesError.INCOMPATIBLE_TYPES % (t.name, type_expr.name) - # self.errors.append(TypesError(error_text, *node.pos)) - # return ErrorType() - - return get_common_basetype(types) - - @visitor.when(OptionNode) - def visit(self, node: OptionNode, scope: Scope): - var_info = self.find_variable(scope, node.id) - typex = self.visit(node.expr, scope) - return typex, var_info.type - - def binary_operation(self, node, scope, operator): - ltype = self.visit(node.left, scope) - rtype = self.visit(node.right, scope) - int_type = IntType() - if ltype != int_type or rtype != int_type: - error_text = TypesError.BOPERATION_NOT_DEFINED % ( - ltype.name, operator, rtype.name) - self.errors.append(TypesError(error_text, *node.pos)) - return ErrorType() - if operator == '<' or operator == '<=': - return BoolType() - return int_type - - @visitor.when(PlusNode) - def visit(self, node: PlusNode, scope: Scope): - return self.binary_operation(node, scope, '+') - - @visitor.when(MinusNode) - def visit(self, node: MinusNode, scope: Scope): - return self.binary_operation(node, scope, '-') - - @visitor.when(StarNode) - def visit(self, node: StarNode, scope: Scope): - return self.binary_operation(node, scope, '*') - - @visitor.when(DivNode) - def visit(self, node: DivNode, scope: Scope): - return self.binary_operation(node, scope, '/') - - @visitor.when(LessEqNode) - def visit(self, node: DivNode, scope: Scope): - return self.binary_operation(node, scope, '<=') - - @visitor.when(LessNode) - def visit(self, node: DivNode, scope: Scope): - return self.binary_operation(node, scope, '<') - - @visitor.when(EqualNode) - def visit(self, node: EqualNode, scope: Scope): - ltype = self.visit(node.left, scope) - rtype = self.visit(node.right, scope) - if (ltype == IntType() or rtype == IntType() or ltype == StringType() or rtype == StringType() or ltype == BoolType() or rtype == BoolType()) and ltype != rtype: - error_text = TypesError.COMPARISON_ERROR - self.errors.append(TypesError(error_text, *node.pos)) - return ErrorType() - else: - return BoolType() - - @visitor.when(NotNode) - def visit(self, node: NotNode, scope: Scope): - ltype = self.visit(node.expr, scope) - typex = BoolType() - if ltype != typex: - error_text = TypesError.UOPERATION_NOT_DEFINED % ( - 'not', ltype.name, typex.name) - self.errors.append(TypesError(error_text, *node.pos)) - return ErrorType() - return typex - - @visitor.when(BinaryNotNode) - def visit(self, node: BinaryNotNode, scope: Scope): - ltype = self.visit(node.expr, scope) - int_type = IntType() - if ltype != int_type: - error_text = TypesError.UOPERATION_NOT_DEFINED % ( - '~', ltype.name, int_type.name) - self.errors.append(TypesError(error_text, *node.pos)) - return ErrorType() - return int_type +# from utils import visitor +# from semantic.semantic import * +# from utils.ast import * +# from utils.errors import SemanticError, AttributesError, TypesError, NamesError +# from utils import get_type, get_common_basetype + + +# class TypeChecker: +# def __init__(self, context: Context, errors=[]): +# self.context: Context = context +# self.current_type: Type = None +# self.current_method: Method = None +# self.errors = errors +# self.current_index = None # Lleva el índice del scope en el que se está + +# @visitor.on('node') +# def visit(self, node, scope): +# pass + +# @visitor.when(ProgramNode) +# def visit(self, node: ProgramNode, scope: Scope): +# for declaration, new_scope in zip(node.declarations, scope.children): +# self.visit(declaration, new_scope) + +# def _get_type(self, ntype: str, pos): +# try: +# return self.context.get_type(ntype, pos) +# except SemanticError as e: +# self.errors.append(e) +# return ErrorType() + +# def _get_method(self, typex: Type, name: str, pos) -> Method: +# try: +# return typex.get_method(name, pos) +# except SemanticError as e: +# if type(typex) != ErrorType and type(typex) != AutoType: +# error_text = AttributesError.DISPATCH_UNDEFINED % name +# self.errors.append(AttributesError(error_text, *pos)) +# return MethodError(name, [], [], ErrorType()) + +# @visitor.when(ClassDeclarationNode) +# def visit(self, node: ClassDeclarationNode, scope: Scope): +# self.current_type = self.context.get_type(node.id, node.pos) + +# fd = [feat for feat in node.features if isinstance( +# feat, FuncDeclarationNode)] + +# for feat in node.features: +# if isinstance(feat, AttrDeclarationNode): +# self.visit(feat, scope) + +# for feat, child_scope in zip(fd, scope.functions.values()): +# self.visit(feat, child_scope) + +# @visitor.when(AttrDeclarationNode) +# def visit(self, node: AttrDeclarationNode, scope: Scope): +# attr = self.current_type.get_attribute(node.id, node.pos) +# vartype = get_type(attr.type, self.current_type) + +# self.current_index = attr.index +# typex = self.visit(node.expr, scope) +# self.current_index = None + +# if not typex.conforms_to(vartype): +# error_text = TypesError.ATTR_TYPE_ERROR % ( +# typex.name, attr.name, vartype.name) +# self.errors.append(TypesError(error_text, *node.pos)) +# return ErrorType() +# return typex + +# @visitor.when(FuncDeclarationNode) +# def visit(self, node: FuncDeclarationNode, scope: Scope): +# parent = self.current_type.parent + +# self.current_method = method = self.current_type.get_method( +# node.id, node.pos) +# if parent is not None: +# try: +# old_meth = parent.get_method(node.id, node.pos) +# if old_meth.return_type.name != method.return_type.name: +# error_text = SemanticError.WRONG_SIGNATURE_RETURN % ( +# node.id, method.return_type.name, old_meth.return_type.name) +# self.errors.append(SemanticError( +# error_text, *node.type_pos)) +# if len(method.param_names) != len(old_meth.param_names): +# error_text = SemanticError.WRONG_NUMBER_PARAM % node.id +# self.errors.append(SemanticError(error_text, *node.pos)) +# for (name, param), type1, type2 in zip(node.params, method.param_types, old_meth.param_types): +# if type1.name != type2.name: +# error_text = SemanticError.WRONG_SIGNATURE_PARAMETER % ( +# name, type1.name, type2.name) +# self.errors.append( +# SemanticError(error_text, *param.pos)) +# except SemanticError: +# pass + +# result = self.visit(node.body, scope) + +# return_type = get_type(method.return_type, self.current_type) + +# if not result.conforms_to(return_type): +# error_text = TypesError.RETURN_TYPE_ERROR % ( +# result.name, return_type.name) +# self.errors.append(TypesError(error_text, *node.type_pos)) + +# @visitor.when(VarDeclarationNode) +# def visit(self, node: VarDeclarationNode, scope: Scope): + +# vtype = self._get_type(node.type, node.type_pos) +# vtype = get_type(vtype, self.current_type) + +# if node.expr != None: +# typex = self.visit(node.expr, scope) +# if not typex.conforms_to(vtype): +# error_text = TypesError.UNCONFORMS_TYPE % ( +# typex.name, node.id, vtype.name) +# self.errors.append(TypesError(error_text, *node.type_pos)) +# return typex +# return vtype + +# @visitor.when(AssignNode) +# def visit(self, node: AssignNode, scope: Scope): +# vinfo = self.find_variable(scope, node.id) +# vtype = get_type(vinfo.type, self.current_type) + +# typex = self.visit(node.expr, scope) + +# if not typex.conforms_to(vtype): +# error_text = TypesError.UNCONFORMS_TYPE % ( +# typex.name, node.id, vtype.name) +# self.errors.append(TypesError(error_text, *node.pos)) +# return typex + +# def _check_args(self, meth: Method, scope: Scope, args, pos): +# arg_types = [self.visit(arg, scope) for arg in args] + +# if len(arg_types) > len(meth.param_types): +# error_text = SemanticError.ARGUMENT_ERROR % meth.name +# self.errors.append(SemanticError(error_text, *pos)) +# elif len(arg_types) < len(meth.param_types): +# for arg, arg_info in zip(meth.param_names[len(arg_types):], args[len(arg_types):]): +# error_text = SemanticError.ARGUMENT_ERROR % (meth.name) +# self.errors.append(SemanticError(error_text, *arg_info.pos)) + +# for atype, ptype, param_name in zip(arg_types, meth.param_types, meth.param_names): +# if not atype.conforms_to(ptype): +# error_text = TypesError.INCOSISTENT_ARG_TYPE % ( +# meth.name, atype.name, param_name, ptype.name) +# self.errors.append(TypesError(error_text, *pos)) + +# @visitor.when(CallNode) +# def visit(self, node: CallNode, scope: Scope): +# stype = self.visit(node.obj, scope) + +# meth = self._get_method(stype, node.id, node.pos) +# if not isinstance(meth, MethodError): +# self._check_args(meth, scope, node.args, node.pos) + +# return get_type(meth.return_type, stype) + +# @visitor.when(BaseCallNode) +# def visit(self, node: BaseCallNode, scope: Scope): +# obj = self.visit(node.obj, scope) +# typex = self._get_type(node.type, node.type_pos) + +# if not obj.conforms_to(typex): +# error_text = TypesError.INCOMPATIBLE_TYPES_DISPATCH % ( +# typex.name, obj.name) +# self.errors.append(TypesError(error_text, *node.type_pos)) +# return ErrorType() + +# meth = self._get_method(typex, node.id, node.pos) +# if not isinstance(meth, MethodError): +# self._check_args(meth, scope, node.args, node.pos) + +# return get_type(meth.return_type, typex) + +# @visitor.when(StaticCallNode) +# def visit(self, node: StaticCallNode, scope: Scope): +# typex = self.current_type + +# meth = self._get_method(typex, node.id, node.pos) +# if not isinstance(meth, MethodError): +# self._check_args(meth, scope, node.args, node.pos) + +# return get_type(meth.return_type, typex) + +# @visitor.when(ConstantNumNode) +# def visit(self, node: ConstantNumNode, scope: Scope): +# return IntType(node.pos) + +# @visitor.when(ConstantBoolNode) +# def visit(self, node: ConstantBoolNode, scope: Scope): +# return BoolType(node.pos) + +# @visitor.when(ConstantStrNode) +# def visit(self, node: ConstantStrNode, scope: Scope): +# return StringType(node.pos) + +# @visitor.when(ConstantVoidNode) +# def visit(self, node: ConstantVoidNode, scope: Scope): +# return VoidType(node.pos) + +# def find_variable(self, scope, lex): +# var_info = scope.find_local(lex) +# if var_info is None: +# var_info = scope.find_attribute(lex) +# if lex in self.current_type.attributes and var_info is None: +# return VariableInfo(lex, VoidType()) +# return var_info + +# @visitor.when(VariableNode) +# def visit(self, node: VariableNode, scope: Scope): +# typex = self.find_variable(scope, node.lex).type +# return get_type(typex, self.current_type) + +# @visitor.when(InstantiateNode) +# def visit(self, node: InstantiateNode, scope: Scope): +# try: +# type_ = self.context.get_type(node.lex, node.pos) +# except SemanticError: +# type_ = ErrorType() +# error_text = TypesError.NEW_UNDEFINED_CLASS % node.lex +# self.errors.append(TypesError(error_text, *node.pos)) + +# return get_type(type_, self.current_type) + +# @visitor.when(WhileNode) +# def visit(self, node: WhileNode, scope: Scope): +# cond = self.visit(node.cond, scope) + +# if cond.name != 'Bool': +# self.errors.append(TypesError( +# TypesError.LOOP_CONDITION_ERROR, *node.pos)) + +# self.visit(node.expr, scope) +# return ObjectType() + +# @visitor.when(IsVoidNode) +# def visit(self, node: IsVoidNode, scope: Scope): +# self.visit(node.expr, scope) +# return BoolType() + +# @visitor.when(ConditionalNode) +# def visit(self, node: ConditionalNode, scope: Scope): +# cond = self.visit(node.cond, scope) + +# if cond.name != 'Bool': +# error_text = TypesError.PREDICATE_ERROR % ('if', 'Bool') +# self.errors.append(TypesError(error_text, *node.pos)) + +# true_type = self.visit(node.stm, scope) +# false_type = self.visit(node.else_stm, scope) + +# return get_common_basetype([false_type, true_type]) +# # if true_type.conforms_to(false_type): +# # return false_type +# # elif false_type.conforms_to(true_type): +# # return true_type +# # else: +# # error_text = TypesError.INCOMPATIBLE_TYPES % (false_type.name, true_type.name) +# # self.errors.append(TypesError(error_text, *node.pos)) +# # return ErrorType() + +# @visitor.when(BlockNode) +# def visit(self, node: BlockNode, scope: Scope): +# value = None +# for exp in node.expr_list: +# value = self.visit(exp, scope) +# return value + +# @visitor.when(LetNode) +# def visit(self, node: LetNode, scope: Scope): +# child_scope = scope.expr_dict[node] +# for init in node.init_list: +# self.visit(init, child_scope) +# return self.visit(node.expr, child_scope) + +# @visitor.when(CaseNode) +# def visit(self, node: CaseNode, scope: Scope): +# type_expr = self.visit(node.expr, scope) + +# new_scope = scope.expr_dict[node] +# types = [] +# var_types = [] +# for case, c_scope in zip(node.case_list, new_scope.children): +# case: OptionNode +# t, vt = self.visit(case, c_scope) +# types.append(t) +# if case.typex in var_types: +# error_text = SemanticError.DUPLICATE_CASE_BRANCH % case.typex +# self.errors.append(SemanticError(error_text, *case.type_pos)) +# var_types.append(case.typex) + +# # for t in var_types: +# # if not type_expr.conforms_to(t): +# # error_text = TypesError.INCOMPATIBLE_TYPES % (t.name, type_expr.name) +# # self.errors.append(TypesError(error_text, *node.pos)) +# # return ErrorType() + +# return get_common_basetype(types) + +# @visitor.when(OptionNode) +# def visit(self, node: OptionNode, scope: Scope): +# var_info = self.find_variable(scope, node.id) +# typex = self.visit(node.expr, scope) +# return typex, var_info.type + +# def binary_operation(self, node, scope, operator): +# ltype = self.visit(node.left, scope) +# rtype = self.visit(node.right, scope) +# int_type = IntType() +# if ltype != int_type or rtype != int_type: +# error_text = TypesError.BOPERATION_NOT_DEFINED % ( +# ltype.name, operator, rtype.name) +# self.errors.append(TypesError(error_text, *node.pos)) +# return ErrorType() +# if operator == '<' or operator == '<=': +# return BoolType() +# return int_type + +# @visitor.when(PlusNode) +# def visit(self, node: PlusNode, scope: Scope): +# return self.binary_operation(node, scope, '+') + +# @visitor.when(MinusNode) +# def visit(self, node: MinusNode, scope: Scope): +# return self.binary_operation(node, scope, '-') + +# @visitor.when(StarNode) +# def visit(self, node: StarNode, scope: Scope): +# return self.binary_operation(node, scope, '*') + +# @visitor.when(DivNode) +# def visit(self, node: DivNode, scope: Scope): +# return self.binary_operation(node, scope, '/') + +# @visitor.when(LessEqNode) +# def visit(self, node: DivNode, scope: Scope): +# return self.binary_operation(node, scope, '<=') + +# @visitor.when(LessNode) +# def visit(self, node: DivNode, scope: Scope): +# return self.binary_operation(node, scope, '<') + +# @visitor.when(EqualNode) +# def visit(self, node: EqualNode, scope: Scope): +# ltype = self.visit(node.left, scope) +# rtype = self.visit(node.right, scope) +# if (ltype == IntType() or rtype == IntType() or ltype == StringType() or rtype == StringType() or ltype == BoolType() or rtype == BoolType()) and ltype != rtype: +# error_text = TypesError.COMPARISON_ERROR +# self.errors.append(TypesError(error_text, *node.pos)) +# return ErrorType() +# else: +# return BoolType() + +# @visitor.when(NotNode) +# def visit(self, node: NotNode, scope: Scope): +# ltype = self.visit(node.expr, scope) +# typex = BoolType() +# if ltype != typex: +# error_text = TypesError.UOPERATION_NOT_DEFINED % ( +# 'not', ltype.name, typex.name) +# self.errors.append(TypesError(error_text, *node.pos)) +# return ErrorType() +# return typex + +# @visitor.when(BinaryNotNode) +# def visit(self, node: BinaryNotNode, scope: Scope): +# ltype = self.visit(node.expr, scope) +# int_type = IntType() +# if ltype != int_type: +# error_text = TypesError.UOPERATION_NOT_DEFINED % ( +# '~', ltype.name, int_type.name) +# self.errors.append(TypesError(error_text, *node.pos)) +# return ErrorType() +# return int_type From 87979ebcf0a0e8228387f074b141eda06f0167ac Mon Sep 17 00:00:00 2001 From: cwjki Date: Sun, 20 Feb 2022 20:41:08 -0500 Subject: [PATCH 123/194] adding AutoType --- src/semantic/semantic.py | 11 + src/semantic/visitors/typeChecker.py | 412 +++------------------------ 2 files changed, 47 insertions(+), 376 deletions(-) diff --git a/src/semantic/semantic.py b/src/semantic/semantic.py index f57a67c36..ef5ad8d47 100644 --- a/src/semantic/semantic.py +++ b/src/semantic/semantic.py @@ -309,6 +309,17 @@ def __ne__(self, other): return other.name != self.name and not isinstance(other, IOType) +class AutoType(Type): + def __init__(self): + Type.__init__(self, 'AUTO_TYPE') + + def __eq__(self, other): + return other.name == self.name or isinstance(other, AutoType) + + def __ne__(self, other): + return other.name != self.name and not isinstance(other, AutoType) + + class Context: def __init__(self): self.types = {} diff --git a/src/semantic/visitors/typeChecker.py b/src/semantic/visitors/typeChecker.py index 46ae10ab9..2e5501839 100644 --- a/src/semantic/visitors/typeChecker.py +++ b/src/semantic/visitors/typeChecker.py @@ -1,377 +1,37 @@ -# from utils import visitor -# from semantic.semantic import * -# from utils.ast import * -# from utils.errors import SemanticError, AttributesError, TypesError, NamesError -# from utils import get_type, get_common_basetype +from semantic.semantic import ErrorType +from utils.errors import SemanticError +from utils import visitor +from utils.ast import * + + +class TypeChecker: + def __init__(self, context, errors): + self.context = context + self.currentType = None + self.currentMethod = None + self.errors = errors + self.currentIndex = None + + @visitor.on('node') + def visit(self, node, scope): + pass + + @visitor.when(ProgramNode) + def visit(self, programNode, scope): + for i in range(0, len(programNode.declarations)): + self.visit(programNode.declarations[i], scope.children[i]) + + def _get_type(self, ntype, pos): + try: + return self.context.get_type(ntype, pos) + except SemanticError as e: + self.errors.append(e) + return ErrorType() + + def _get_method(self, typex, name, pos): + try: + return typex.get_method(name, pos) + except SemanticError: + if type(typex) != ErrorType and type(typex) != AutoType: + - -# class TypeChecker: -# def __init__(self, context: Context, errors=[]): -# self.context: Context = context -# self.current_type: Type = None -# self.current_method: Method = None -# self.errors = errors -# self.current_index = None # Lleva el índice del scope en el que se está - -# @visitor.on('node') -# def visit(self, node, scope): -# pass - -# @visitor.when(ProgramNode) -# def visit(self, node: ProgramNode, scope: Scope): -# for declaration, new_scope in zip(node.declarations, scope.children): -# self.visit(declaration, new_scope) - -# def _get_type(self, ntype: str, pos): -# try: -# return self.context.get_type(ntype, pos) -# except SemanticError as e: -# self.errors.append(e) -# return ErrorType() - -# def _get_method(self, typex: Type, name: str, pos) -> Method: -# try: -# return typex.get_method(name, pos) -# except SemanticError as e: -# if type(typex) != ErrorType and type(typex) != AutoType: -# error_text = AttributesError.DISPATCH_UNDEFINED % name -# self.errors.append(AttributesError(error_text, *pos)) -# return MethodError(name, [], [], ErrorType()) - -# @visitor.when(ClassDeclarationNode) -# def visit(self, node: ClassDeclarationNode, scope: Scope): -# self.current_type = self.context.get_type(node.id, node.pos) - -# fd = [feat for feat in node.features if isinstance( -# feat, FuncDeclarationNode)] - -# for feat in node.features: -# if isinstance(feat, AttrDeclarationNode): -# self.visit(feat, scope) - -# for feat, child_scope in zip(fd, scope.functions.values()): -# self.visit(feat, child_scope) - -# @visitor.when(AttrDeclarationNode) -# def visit(self, node: AttrDeclarationNode, scope: Scope): -# attr = self.current_type.get_attribute(node.id, node.pos) -# vartype = get_type(attr.type, self.current_type) - -# self.current_index = attr.index -# typex = self.visit(node.expr, scope) -# self.current_index = None - -# if not typex.conforms_to(vartype): -# error_text = TypesError.ATTR_TYPE_ERROR % ( -# typex.name, attr.name, vartype.name) -# self.errors.append(TypesError(error_text, *node.pos)) -# return ErrorType() -# return typex - -# @visitor.when(FuncDeclarationNode) -# def visit(self, node: FuncDeclarationNode, scope: Scope): -# parent = self.current_type.parent - -# self.current_method = method = self.current_type.get_method( -# node.id, node.pos) -# if parent is not None: -# try: -# old_meth = parent.get_method(node.id, node.pos) -# if old_meth.return_type.name != method.return_type.name: -# error_text = SemanticError.WRONG_SIGNATURE_RETURN % ( -# node.id, method.return_type.name, old_meth.return_type.name) -# self.errors.append(SemanticError( -# error_text, *node.type_pos)) -# if len(method.param_names) != len(old_meth.param_names): -# error_text = SemanticError.WRONG_NUMBER_PARAM % node.id -# self.errors.append(SemanticError(error_text, *node.pos)) -# for (name, param), type1, type2 in zip(node.params, method.param_types, old_meth.param_types): -# if type1.name != type2.name: -# error_text = SemanticError.WRONG_SIGNATURE_PARAMETER % ( -# name, type1.name, type2.name) -# self.errors.append( -# SemanticError(error_text, *param.pos)) -# except SemanticError: -# pass - -# result = self.visit(node.body, scope) - -# return_type = get_type(method.return_type, self.current_type) - -# if not result.conforms_to(return_type): -# error_text = TypesError.RETURN_TYPE_ERROR % ( -# result.name, return_type.name) -# self.errors.append(TypesError(error_text, *node.type_pos)) - -# @visitor.when(VarDeclarationNode) -# def visit(self, node: VarDeclarationNode, scope: Scope): - -# vtype = self._get_type(node.type, node.type_pos) -# vtype = get_type(vtype, self.current_type) - -# if node.expr != None: -# typex = self.visit(node.expr, scope) -# if not typex.conforms_to(vtype): -# error_text = TypesError.UNCONFORMS_TYPE % ( -# typex.name, node.id, vtype.name) -# self.errors.append(TypesError(error_text, *node.type_pos)) -# return typex -# return vtype - -# @visitor.when(AssignNode) -# def visit(self, node: AssignNode, scope: Scope): -# vinfo = self.find_variable(scope, node.id) -# vtype = get_type(vinfo.type, self.current_type) - -# typex = self.visit(node.expr, scope) - -# if not typex.conforms_to(vtype): -# error_text = TypesError.UNCONFORMS_TYPE % ( -# typex.name, node.id, vtype.name) -# self.errors.append(TypesError(error_text, *node.pos)) -# return typex - -# def _check_args(self, meth: Method, scope: Scope, args, pos): -# arg_types = [self.visit(arg, scope) for arg in args] - -# if len(arg_types) > len(meth.param_types): -# error_text = SemanticError.ARGUMENT_ERROR % meth.name -# self.errors.append(SemanticError(error_text, *pos)) -# elif len(arg_types) < len(meth.param_types): -# for arg, arg_info in zip(meth.param_names[len(arg_types):], args[len(arg_types):]): -# error_text = SemanticError.ARGUMENT_ERROR % (meth.name) -# self.errors.append(SemanticError(error_text, *arg_info.pos)) - -# for atype, ptype, param_name in zip(arg_types, meth.param_types, meth.param_names): -# if not atype.conforms_to(ptype): -# error_text = TypesError.INCOSISTENT_ARG_TYPE % ( -# meth.name, atype.name, param_name, ptype.name) -# self.errors.append(TypesError(error_text, *pos)) - -# @visitor.when(CallNode) -# def visit(self, node: CallNode, scope: Scope): -# stype = self.visit(node.obj, scope) - -# meth = self._get_method(stype, node.id, node.pos) -# if not isinstance(meth, MethodError): -# self._check_args(meth, scope, node.args, node.pos) - -# return get_type(meth.return_type, stype) - -# @visitor.when(BaseCallNode) -# def visit(self, node: BaseCallNode, scope: Scope): -# obj = self.visit(node.obj, scope) -# typex = self._get_type(node.type, node.type_pos) - -# if not obj.conforms_to(typex): -# error_text = TypesError.INCOMPATIBLE_TYPES_DISPATCH % ( -# typex.name, obj.name) -# self.errors.append(TypesError(error_text, *node.type_pos)) -# return ErrorType() - -# meth = self._get_method(typex, node.id, node.pos) -# if not isinstance(meth, MethodError): -# self._check_args(meth, scope, node.args, node.pos) - -# return get_type(meth.return_type, typex) - -# @visitor.when(StaticCallNode) -# def visit(self, node: StaticCallNode, scope: Scope): -# typex = self.current_type - -# meth = self._get_method(typex, node.id, node.pos) -# if not isinstance(meth, MethodError): -# self._check_args(meth, scope, node.args, node.pos) - -# return get_type(meth.return_type, typex) - -# @visitor.when(ConstantNumNode) -# def visit(self, node: ConstantNumNode, scope: Scope): -# return IntType(node.pos) - -# @visitor.when(ConstantBoolNode) -# def visit(self, node: ConstantBoolNode, scope: Scope): -# return BoolType(node.pos) - -# @visitor.when(ConstantStrNode) -# def visit(self, node: ConstantStrNode, scope: Scope): -# return StringType(node.pos) - -# @visitor.when(ConstantVoidNode) -# def visit(self, node: ConstantVoidNode, scope: Scope): -# return VoidType(node.pos) - -# def find_variable(self, scope, lex): -# var_info = scope.find_local(lex) -# if var_info is None: -# var_info = scope.find_attribute(lex) -# if lex in self.current_type.attributes and var_info is None: -# return VariableInfo(lex, VoidType()) -# return var_info - -# @visitor.when(VariableNode) -# def visit(self, node: VariableNode, scope: Scope): -# typex = self.find_variable(scope, node.lex).type -# return get_type(typex, self.current_type) - -# @visitor.when(InstantiateNode) -# def visit(self, node: InstantiateNode, scope: Scope): -# try: -# type_ = self.context.get_type(node.lex, node.pos) -# except SemanticError: -# type_ = ErrorType() -# error_text = TypesError.NEW_UNDEFINED_CLASS % node.lex -# self.errors.append(TypesError(error_text, *node.pos)) - -# return get_type(type_, self.current_type) - -# @visitor.when(WhileNode) -# def visit(self, node: WhileNode, scope: Scope): -# cond = self.visit(node.cond, scope) - -# if cond.name != 'Bool': -# self.errors.append(TypesError( -# TypesError.LOOP_CONDITION_ERROR, *node.pos)) - -# self.visit(node.expr, scope) -# return ObjectType() - -# @visitor.when(IsVoidNode) -# def visit(self, node: IsVoidNode, scope: Scope): -# self.visit(node.expr, scope) -# return BoolType() - -# @visitor.when(ConditionalNode) -# def visit(self, node: ConditionalNode, scope: Scope): -# cond = self.visit(node.cond, scope) - -# if cond.name != 'Bool': -# error_text = TypesError.PREDICATE_ERROR % ('if', 'Bool') -# self.errors.append(TypesError(error_text, *node.pos)) - -# true_type = self.visit(node.stm, scope) -# false_type = self.visit(node.else_stm, scope) - -# return get_common_basetype([false_type, true_type]) -# # if true_type.conforms_to(false_type): -# # return false_type -# # elif false_type.conforms_to(true_type): -# # return true_type -# # else: -# # error_text = TypesError.INCOMPATIBLE_TYPES % (false_type.name, true_type.name) -# # self.errors.append(TypesError(error_text, *node.pos)) -# # return ErrorType() - -# @visitor.when(BlockNode) -# def visit(self, node: BlockNode, scope: Scope): -# value = None -# for exp in node.expr_list: -# value = self.visit(exp, scope) -# return value - -# @visitor.when(LetNode) -# def visit(self, node: LetNode, scope: Scope): -# child_scope = scope.expr_dict[node] -# for init in node.init_list: -# self.visit(init, child_scope) -# return self.visit(node.expr, child_scope) - -# @visitor.when(CaseNode) -# def visit(self, node: CaseNode, scope: Scope): -# type_expr = self.visit(node.expr, scope) - -# new_scope = scope.expr_dict[node] -# types = [] -# var_types = [] -# for case, c_scope in zip(node.case_list, new_scope.children): -# case: OptionNode -# t, vt = self.visit(case, c_scope) -# types.append(t) -# if case.typex in var_types: -# error_text = SemanticError.DUPLICATE_CASE_BRANCH % case.typex -# self.errors.append(SemanticError(error_text, *case.type_pos)) -# var_types.append(case.typex) - -# # for t in var_types: -# # if not type_expr.conforms_to(t): -# # error_text = TypesError.INCOMPATIBLE_TYPES % (t.name, type_expr.name) -# # self.errors.append(TypesError(error_text, *node.pos)) -# # return ErrorType() - -# return get_common_basetype(types) - -# @visitor.when(OptionNode) -# def visit(self, node: OptionNode, scope: Scope): -# var_info = self.find_variable(scope, node.id) -# typex = self.visit(node.expr, scope) -# return typex, var_info.type - -# def binary_operation(self, node, scope, operator): -# ltype = self.visit(node.left, scope) -# rtype = self.visit(node.right, scope) -# int_type = IntType() -# if ltype != int_type or rtype != int_type: -# error_text = TypesError.BOPERATION_NOT_DEFINED % ( -# ltype.name, operator, rtype.name) -# self.errors.append(TypesError(error_text, *node.pos)) -# return ErrorType() -# if operator == '<' or operator == '<=': -# return BoolType() -# return int_type - -# @visitor.when(PlusNode) -# def visit(self, node: PlusNode, scope: Scope): -# return self.binary_operation(node, scope, '+') - -# @visitor.when(MinusNode) -# def visit(self, node: MinusNode, scope: Scope): -# return self.binary_operation(node, scope, '-') - -# @visitor.when(StarNode) -# def visit(self, node: StarNode, scope: Scope): -# return self.binary_operation(node, scope, '*') - -# @visitor.when(DivNode) -# def visit(self, node: DivNode, scope: Scope): -# return self.binary_operation(node, scope, '/') - -# @visitor.when(LessEqNode) -# def visit(self, node: DivNode, scope: Scope): -# return self.binary_operation(node, scope, '<=') - -# @visitor.when(LessNode) -# def visit(self, node: DivNode, scope: Scope): -# return self.binary_operation(node, scope, '<') - -# @visitor.when(EqualNode) -# def visit(self, node: EqualNode, scope: Scope): -# ltype = self.visit(node.left, scope) -# rtype = self.visit(node.right, scope) -# if (ltype == IntType() or rtype == IntType() or ltype == StringType() or rtype == StringType() or ltype == BoolType() or rtype == BoolType()) and ltype != rtype: -# error_text = TypesError.COMPARISON_ERROR -# self.errors.append(TypesError(error_text, *node.pos)) -# return ErrorType() -# else: -# return BoolType() - -# @visitor.when(NotNode) -# def visit(self, node: NotNode, scope: Scope): -# ltype = self.visit(node.expr, scope) -# typex = BoolType() -# if ltype != typex: -# error_text = TypesError.UOPERATION_NOT_DEFINED % ( -# 'not', ltype.name, typex.name) -# self.errors.append(TypesError(error_text, *node.pos)) -# return ErrorType() -# return typex - -# @visitor.when(BinaryNotNode) -# def visit(self, node: BinaryNotNode, scope: Scope): -# ltype = self.visit(node.expr, scope) -# int_type = IntType() -# if ltype != int_type: -# error_text = TypesError.UOPERATION_NOT_DEFINED % ( -# '~', ltype.name, int_type.name) -# self.errors.append(TypesError(error_text, *node.pos)) -# return ErrorType() -# return int_type From 6a019ddf815a4a1695a255a39517af3324fb6cc8 Mon Sep 17 00:00:00 2001 From: cwjki Date: Sun, 20 Feb 2022 21:58:41 -0500 Subject: [PATCH 124/194] changing almost everything in typeChecker :( --- src/semantic/semantic.py | 8 ++ src/semantic/visitors/typeChecker.py | 120 ++++++++++++++++++++++++++- src/utils/errors.py | 5 ++ src/utils/utils.py | 33 ++++++++ 4 files changed, 163 insertions(+), 3 deletions(-) diff --git a/src/semantic/semantic.py b/src/semantic/semantic.py index ef5ad8d47..11ccc672a 100644 --- a/src/semantic/semantic.py +++ b/src/semantic/semantic.py @@ -36,6 +36,14 @@ def __eq__(self, other): other.param_types == self.param_types +class MethodError(Method): + def __init__(self, name, param_names, param_types, return_types): + super().__init__(name, param_names, param_types, return_types) + + def __str__(self): + return f'[method] {self.name} ERROR' + + class Type: def __init__(self, name: str, pos, parent=True): if name == 'ObjectType': diff --git a/src/semantic/visitors/typeChecker.py b/src/semantic/visitors/typeChecker.py index 2e5501839..6f3a3fdbe 100644 --- a/src/semantic/visitors/typeChecker.py +++ b/src/semantic/visitors/typeChecker.py @@ -1,6 +1,8 @@ -from semantic.semantic import ErrorType -from utils.errors import SemanticError +from distutils.log import error +from semantic.semantic import AutoType, ErrorType, MethodError +from utils.errors import AttributexError, SemanticError, TypexError from utils import visitor +from utils.utils import get_type, get_common_basetype from utils.ast import * @@ -21,6 +23,101 @@ def visit(self, programNode, scope): for i in range(0, len(programNode.declarations)): self.visit(programNode.declarations[i], scope.children[i]) + @visitor.when(ClassDeclarationNode) + def visit(self, classDeclarationNode, scope): + self.currentType = self.context.get_type( + classDeclarationNode.id, (classDeclarationNode.line, classDeclarationNode.col)) + + funcDeclarations = [] + for feature in classDeclarationNode.features: + if isinstance(feature, AttrDeclarationNode): + self.visit(feature, scope) + else: + funcDeclarations.append(feature) + + for funcDeclaration in funcDeclarations: + self.visit(funcDeclaration, scope.functions[funcDeclaration.id]) + + @visitor.when(FuncDeclarationNode) + def visit(self, funcDeclarationNode, scope): + parent = self.currentType.parent + self.currentMethod = self.currentType.get_method( + funcDeclarationNode.id, (funcDeclarationNode.line, funcDeclarationNode.col)) + + method = self.currentMethod + if parent is not None: + try: + oldMethod = parent.get_method( + funcDeclarationNode.id, (funcDeclarationNode.line, funcDeclarationNode.col)) + if oldMethod.return_type.name != method.return_type.name: + errorText = f'In redefined method {funcDeclarationNode.id}, return type {method.return_type.name} is different from original return type {oldMethod.return_type.name}.' + self.errors.append(SemanticError( + errorText, funcDeclarationNode.typeLine, funcDeclarationNode.typeCol)) + if len(method.param_names) != len(oldMethod.param_names): + errorText = f'Incompatible number of formal parameters in redefined method {funcDeclarationNode.id}.' + self.errors.append(SemanticError( + errorText, funcDeclarationNode.line, funcDeclarationNode.col)) + for (name, ptype, pline, pcol), type1, type2 in zip(funcDeclarationNode.params, method.param_types, oldMethod.param_types): + if type1.name != type2.name: + errorText = f'In redefined method {name}, parameter type {type1.name} is different from original type {type2.name}.' + self.errors.append( + SemanticError(errorText, pline, pcol)) + except: + pass + + result = self.visit(funcDeclarationNode.body, scope) + returnType = get_type(method.return_type, self.currentType) + + if not result.conforms_to(returnType): + errorText = f'Inferred return type {result.name} of method test does not conform to declared return type {returnType.name}.' + self.errors.append(TypexError( + errorText, funcDeclarationNode.typeLine, funcDeclarationNode.typeCol)) + + @visitor.when(AttrDeclarationNode) + def visit(self, attrDeclarationNode, scope): + attr = self.currentType.get_attribute( + attrDeclarationNode.id, (attrDeclarationNode.line, attrDeclarationNode.col)) + attrType = get_type(attr.type, self.currentType) + self.currentIndex = attr.index + typex = self.visit(attrDeclarationNode.expr, scope) + self.currentIndex = None + + if not typex.conforms_to(attrType): + errorText = f'Inferred type {typex.name} of initialization of attribute {attr.name} does not conform to declared type {attrType.name}.' + self.errors.append(TypexError( + errorText, attrDeclarationNode.line, attrDeclarationNode.col)) + return ErrorType() + + return typex + + @visitor.when(VarDeclarationNode) + def visit(self, varDeclarationNode, scope): + varType = self._get_type( + varDeclarationNode.type, (varDeclarationNode.line, varDeclarationNode.col)) + varType = get_type(varType, self.currentType) + + if varDeclarationNode.expr == None: + return varType + else: + typex = self.visit(varDeclarationNode.expr, scope) + if not typex.conform_to(varType): + errorText = f'Inferred type {typex.name} of initialization of {varDeclarationNode.id} does not conform to identifier\'s declared type {varType.name}.' + self.errors.append(TypexError( + errorText, varDeclarationNode.typeLine, varDeclarationNode.typeCol)) + return typex + + @visitor.when(AssignNode) + def visit(self, assignNode, scope): + varInfo = self.find_variable(scope, assignNode.id) + varType = get_type(varInfo.type, self.currentType) + typex = self.visit(assignNode.expr, scope) + + if not typex.conforms_to(varType): + errorText = f'Inferred type {typex.name} of initialization of {assignNode.id} does not conform to identifier\'s declared type {varType.name}.' + self.errors.append(TypexError( + errorText, assignNode.line, assignNode.col)) + return typex + def _get_type(self, ntype, pos): try: return self.context.get_type(ntype, pos) @@ -33,5 +130,22 @@ def _get_method(self, typex, name, pos): return typex.get_method(name, pos) except SemanticError: if type(typex) != ErrorType and type(typex) != AutoType: - + errorText = f'Dispatch to undefined method {name}.' + self.errors.append(AttributexError(errorText, *pos)) + return MethodError(name, [], [], ErrorType()) + + def _check_args(self, method, scope, args, pos): + argTypes = [self.visit(arg, scope) for arg in args] + + if len(argTypes) > len(method.param_types): + errorText = f'Method {method.name} called with wrong number of arguments.' + self.errors.append(SemanticError(errorText, *pos)) + elif len(argTypes) < len(method.param_types): + for arg, argInfo in zip(method.param_names[len(argTypes):], args[len(argTypes):]): + errorText = f'Method {method.name} called with wrong number of arguments.' + self.errors.append(SemanticError(errorText, *argInfo.pos)) + for argType, paramType, paramName in zip(argTypes, method.param_types, method.param_names): + if not argType.conforms_to(paramType): + errorText = f'In call of method {method.name}, type {argType.name} of parameter {paramName} does not conform to declared type {paramType.name}.' + self.errors.append(TypexError(errorText, *pos)) diff --git a/src/utils/errors.py b/src/utils/errors.py index 79db36883..a5127b7a9 100644 --- a/src/utils/errors.py +++ b/src/utils/errors.py @@ -35,3 +35,8 @@ def __init__(self, text, line, column): class NamexError(SemanticError): def __init__(self, text, line, column): super().__init__('NameError', text, line, column) + + +class AttributexError(SemanticError): + def __init__(self, text, line, column): + super().__init__('AttributeError', text, line, column) diff --git a/src/utils/utils.py b/src/utils/utils.py index 8d02720b0..f6626b74a 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -1,3 +1,7 @@ +import itertools +from semantic.semantic import SelfType + + def find_column(text, pos): line_start = text.rfind('\n', 0, pos) + 1 return (pos - line_start) + 1 @@ -63,3 +67,32 @@ def __repr__(self): 'NOT', 'BOOL' ] + list(reserved.values()) + + +def path_to_objet(typex): + path = [] + c_type = typex + + while c_type: + path.append(c_type) + + c_type = c_type.parent + + path.reverse() + return path + + +def get_common_basetype(types): + paths = [path_to_objet(typex) for typex in types] + tuples = zip(*paths) + + for i, t in enumerate(tuples): + gr = itertools.groupby(t) + if len(list(gr)) > 1: + return paths[0][i-1] + + return paths[0][-1] + + +def get_type(typex: Type, current_type: Type) -> Type: + return current_type if typex == SelfType() else typex From 48c1e29434240a37787d3983eee2d6ad8849eec9 Mon Sep 17 00:00:00 2001 From: livi98 Date: Mon, 21 Feb 2022 04:01:00 +0100 Subject: [PATCH 125/194] adding arroba and dot callNodes on COOLToCILVisitor --- src/code_generator/COOLToCILVisitor.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index ea5aff94a..f9a6c14f1 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -106,7 +106,24 @@ def visit(self, node, scope): self.register_instruction(cil.AssignNode(local_name, value)) return value, typex - @visitor.when(FuncCallNode) + @visitor.when(ArrobaCallNode) + def visit(self, node, scope): + result_local = self.define_internal_local(scope = scope, name = "result") + expr_value = self.visit(node.instance, scope) + + func_call_args = [] + for arg in node.args: + param_local = self.visit(arg, scope) + func_call_args.append(cil.ArgNode(param_local)) + func_call_args.append(cil.ArgNode(expr_value)) + + static_instance = self.define_internal_local(scope=scope, name='static_instance') + self.register_instruction(cil.AllocateNode(node.static_type,self.context.get_type(node.static_type).tag ,static_instance)) + + self.register_instruction(cil.VCallNode(result_local, node.method, func_call_args, node.static_type, static_instance)) + return result_local + + @visitor.when(DotCallNode) def visit(self, node, scope): result_local = self.define_internal_local(scope = scope, name = "result") expr_value = self.visit(node.instance, scope) From e206a495a2c592b69099d3959eb496687718d9eb Mon Sep 17 00:00:00 2001 From: cwjki Date: Mon, 21 Feb 2022 14:05:05 -0500 Subject: [PATCH 126/194] changing the logic of the functions calls --- src/semantic/visitors/typeChecker.py | 87 ++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/src/semantic/visitors/typeChecker.py b/src/semantic/visitors/typeChecker.py index 6f3a3fdbe..4dac9b094 100644 --- a/src/semantic/visitors/typeChecker.py +++ b/src/semantic/visitors/typeChecker.py @@ -118,6 +118,93 @@ def visit(self, assignNode, scope): errorText, assignNode.line, assignNode.col)) return typex + @visitor.when(ArrobaCallNode) + def visit(self, arrobaCallNode, scope): + objType = self.visit(arrobaCallNode.obj, scope) + typex = self._get_type( + arrobaCallNode.type, (arrobaCallNode.typeLine, arrobaCallNode.typeCol)) + + if not objType.conforms_to(typex): + errorText = f'Expression type {typex.name} does not conform to declared static dispatch type {objType.name}.' + self.errors.append(TypexError( + errorText, arrobaCallNode.typeLine, arrobaCallNode.typeCol)) + return ErrorType() + + method = self._get_method( + typex, arrobaCallNode.id, (arrobaCallNode.line, arrobaCallNode.col)) + if not isinstance(method, MethodError): + # check the args + argTypes = [self.visit(arg, scope) for arg in arrobaCallNode.args] + + if len(argTypes) > len(method.param_types): + errorText = f'Method {method.name} called with wrong number of arguments.' + self.errors.append(SemanticError( + errorText, arrobaCallNode.line, arrobaCallNode.col)) + elif len(argTypes) < len(method.param_types): + for arg, argInfo in zip(method.param_names[len(argTypes):], arrobaCallNode.args[len(argTypes):]): + errorText = f'Method {method.name} called with wrong number of arguments.' + self.errors.append(SemanticError(errorText, *argInfo.pos)) + + for argType, paramType, paramName in zip(argTypes, method.param_types, method.param_names): + if not argType.conforms_to(paramType): + errorText = f'In call of method {method.name}, type {argType.name} of parameter {paramName} does not conform to declared type {paramType.name}.' + self.errors.append(TypexError( + errorText, arrobaCallNode.line, arrobaCallNode.col)) + + return get_type(method.return_type, typex) + + @visitor.when(DotCallNode) + def visit(self, dotCallNode, scope): + objType = self.visit(dotCallNode.obj, scope) + method = self._get_method( + objType, dotCallNode.id, (dotCallNode.line, dotCallNode.col)) + if not isinstance(method, MethodError): + # check the args + argTypes = [self.visit(arg, scope) for arg in dotCallNode.args] + + if len(argTypes) > len(method.param_types): + errorText = f'Method {method.name} called with wrong number of arguments.' + self.errors.append(SemanticError( + errorText, dotCallNode.line, dotCallNode.col)) + elif len(argTypes) < len(method.param_types): + for arg, argInfo in zip(method.param_names[len(argTypes):], dotCallNode.args[len(argTypes):]): + errorText = f'Method {method.name} called with wrong number of arguments.' + self.errors.append(SemanticError(errorText, *argInfo.pos)) + + for argType, paramType, paramName in zip(argTypes, method.param_types, method.param_names): + if not argType.conforms_to(paramType): + errorText = f'In call of method {method.name}, type {argType.name} of parameter {paramName} does not conform to declared type {paramType.name}.' + self.errors.append(TypexError( + errorText, dotCallNode.line, dotCallNode.col)) + + return get_type(method.return_type, objType) + + @visitor.when(MemberCallNode) + def visit(self, memberCallNode, scope): + typex = self.currentType + method = self._get_method( + typex, memberCallNode.id, (memberCallNode.line, memberCallNode.col)) + if not isinstance(method, MethodError): + # check the args + argTypes = [self.visit(arg, scope) for arg in memberCallNode.args] + + if len(argTypes) > len(method.param_types): + errorText = f'Method {method.name} called with wrong number of arguments.' + self.errors.append(SemanticError( + errorText, memberCallNode.line, memberCallNode.col)) + elif len(argTypes) < len(method.param_types): + for arg, argInfo in zip(method.param_names[len(argTypes):], memberCallNode.args[len(argTypes):]): + errorText = f'Method {method.name} called with wrong number of arguments.' + self.errors.append(SemanticError(errorText, *argInfo.pos)) + + for argType, paramType, paramName in zip(argTypes, method.param_types, method.param_names): + if not argType.conforms_to(paramType): + errorText = f'In call of method {method.name}, type {argType.name} of parameter {paramName} does not conform to declared type {paramType.name}.' + self.errors.append(TypexError( + errorText, memberCallNode.line, memberCallNode.col)) + + return get_type(method.return_type, typex) + def _get_type(self, ntype, pos): try: return self.context.get_type(ntype, pos) From 3839191a28cf61baa4b08cb059ce2b027494b6d0 Mon Sep 17 00:00:00 2001 From: cwjki Date: Mon, 21 Feb 2022 14:33:20 -0500 Subject: [PATCH 127/194] testing semantic errors --- src/semantic/visitors/typeChecker.py | 65 +++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/src/semantic/visitors/typeChecker.py b/src/semantic/visitors/typeChecker.py index 4dac9b094..24e26c7bb 100644 --- a/src/semantic/visitors/typeChecker.py +++ b/src/semantic/visitors/typeChecker.py @@ -1,5 +1,7 @@ from distutils.log import error -from semantic.semantic import AutoType, ErrorType, MethodError + +from click import option +from semantic.semantic import AutoType, ErrorType, MethodError, ObjectType from utils.errors import AttributexError, SemanticError, TypexError from utils import visitor from utils.utils import get_type, get_common_basetype @@ -205,6 +207,67 @@ def visit(self, memberCallNode, scope): return get_type(method.return_type, typex) + @visitor.when(IfThenElseNode) + def visit(self, ifThenElseNode, scope): + conditionType = self.visit(ifThenElseNode.condition, scope) + if conditionType.name != 'Bool': + errorText = f'Predicate of \'if\' does not have type Bool.' + self.errors.append(TypexError( + errorText, ifThenElseNode.line, ifThenElseNode.col)) + + ifBodyType = self.visit(ifThenElseNode.idBody, scope) + elseBodyType = self.visit(ifThenElseNode.elseBody, scope) + return get_common_basetype([ifBodyType, elseBodyType]) + + @visitor.when(WhileNode) + def visit(self, whileNode, scope): + conditionType = self.visit(whileNode.condition, scope) + if conditionType.name != 'Bool': + errorText = 'Loop condition does not have type Bool.' + self.errors.append(TypexError( + errorText, whileNode.line, whileNode.col)) + self.visit(whileNode.expr, scope) + return ObjectType() + + + @visitor.when(BlockNode) + def visit(self, blockNode, scope): + typex = None + for expr in blockNode.exprs: + typex = self.visit(expr, scope) + return typex + + @visitor.when(LetInNode) + def visit(self, letInNode, scope): + childScope = scope.expr_dict[letInNode] + for letDeclaration in letInNode.letBody: + self.visit(letDeclaration, childScope) + return self.visit(letInNode.inBody, childScope) + + @visitor.when(CaseNode) + def visit(self, caseNode, scope): + exprType = self.visit(caseNode.expr, scope) + newScope = scope.expr_dict[caseNode] + types = [] + checkDuplicate = [] + for option, optionScope in zip(caseNode.optionList, newScope.children): + optionType = self.visit(option, optionScope) + types.append(optionType) + if option.type in checkDuplicate: + errorText = f'Duplicate branch {option.type} in case statement.' + self.errors.append(SemanticError(errorText, option.typeLine, option.typeCol)) + checkDuplicate.append(option.type) + return get_common_basetype(types) + + @visitor.when(CaseOptionNode) + def visit(self, caseOptionNode, scope): + optionType = self.visit(caseOptionNode.expr, scope) + return optionType + + + + + def _get_type(self, ntype, pos): try: return self.context.get_type(ntype, pos) From 7605ee90f121201d5d74c25e8c3ce61031990f57 Mon Sep 17 00:00:00 2001 From: cwjki Date: Mon, 21 Feb 2022 14:39:18 -0500 Subject: [PATCH 128/194] fixing a typo --- src/utils/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/utils.py b/src/utils/utils.py index f6626b74a..965877820 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -94,5 +94,5 @@ def get_common_basetype(types): return paths[0][-1] -def get_type(typex: Type, current_type: Type) -> Type: +def get_type(typex, current_type): return current_type if typex == SelfType() else typex From 26612bea637cda5b969828fb688c10387534f301 Mon Sep 17 00:00:00 2001 From: cwjki Date: Mon, 21 Feb 2022 16:42:31 -0500 Subject: [PATCH 129/194] testing again semantics --- src/main.py | 6 +- src/semantic/visitors/typeChecker.py | 152 +++++++++++++++++++++++---- 2 files changed, 135 insertions(+), 23 deletions(-) diff --git a/src/main.py b/src/main.py index 82e27d79e..c8038e86d 100644 --- a/src/main.py +++ b/src/main.py @@ -4,7 +4,7 @@ from lexer import CoolLexer from cparser import CoolParser from semantic.visitors.typeBuilder import TypeBuilder -# from semantic.visitors.typeChecker import TypeChecker +from semantic.visitors.typeChecker import TypeChecker from semantic.visitors.typeCollector import TypeCollector from semantic.visitors.varCollector import VarCollector @@ -34,8 +34,8 @@ def main(_input, _output): typeBuilder.visit(ast) typeInferer = VarCollector(context, semanticErrors) scope = typeInferer.visit(ast) - # typeChecker = TypeChecker(context, semanticErrors) - # typeChecker.visit(ast, scope) + typeChecker = TypeChecker(context, semanticErrors) + typeChecker.visit(ast, scope) if semanticErrors: for error in semanticErrors: print(semanticErrors) diff --git a/src/semantic/visitors/typeChecker.py b/src/semantic/visitors/typeChecker.py index 24e26c7bb..083151763 100644 --- a/src/semantic/visitors/typeChecker.py +++ b/src/semantic/visitors/typeChecker.py @@ -1,7 +1,9 @@ +from ast import Div from distutils.log import error +import re from click import option -from semantic.semantic import AutoType, ErrorType, MethodError, ObjectType +from semantic.semantic import AutoType, BoolType, ErrorType, IntType, MethodError, ObjectType, StringType from utils.errors import AttributexError, SemanticError, TypexError from utils import visitor from utils.utils import get_type, get_common_basetype @@ -229,14 +231,13 @@ def visit(self, whileNode, scope): self.visit(whileNode.expr, scope) return ObjectType() - @visitor.when(BlockNode) def visit(self, blockNode, scope): typex = None for expr in blockNode.exprs: typex = self.visit(expr, scope) return typex - + @visitor.when(LetInNode) def visit(self, letInNode, scope): childScope = scope.expr_dict[letInNode] @@ -255,7 +256,8 @@ def visit(self, caseNode, scope): types.append(optionType) if option.type in checkDuplicate: errorText = f'Duplicate branch {option.type} in case statement.' - self.errors.append(SemanticError(errorText, option.typeLine, option.typeCol)) + self.errors.append(SemanticError( + errorText, option.typeLine, option.typeCol)) checkDuplicate.append(option.type) return get_common_basetype(types) @@ -264,9 +266,135 @@ def visit(self, caseOptionNode, scope): optionType = self.visit(caseOptionNode.expr, scope) return optionType + @visitor.when(PlusNode) + def visit(self, plusNode, scope): + leftType = self.visit(plusNode.lvalue, scope) + rightType = self.visit(plusNode.rvalue, scope) + if leftType != IntType() or rightType != IntType(): + errorText = f'non-Int arguments: {leftType.name} + {rightType.name} .' + self.errors.append(TypexError( + errorText, plusNode.line, plusNode.col)) + return ErrorType() + return IntType() + + @visitor.when(MinusNode) + def visit(self, minusNode, scope): + leftType = self.visit(minusNode.lvalue, scope) + rightType = self.visit(minusNode.rvalue, scope) + if leftType != IntType() or rightType != IntType(): + errorText = f'non-Int arguments: {leftType.name} - {rightType.name} .' + self.errors.append(TypexError( + errorText, minusNode.line, minusNode.col)) + return ErrorType() + return IntType() + + @visitor.when(StarNode) + def visit(self, starNode, scope): + leftType = self.visit(starNode.lvalue, scope) + rightType = self.visit(starNode.rvalue, scope) + if leftType != IntType() or rightType != IntType(): + errorText = f'non-Int arguments: {leftType.name} * {rightType.name} .' + self.errors.append(TypexError( + errorText, starNode.line, starNode.col)) + return ErrorType() + return IntType() + + @visitor.when(DivNode) + def visit(self, divNode, scope): + leftType = self.visit(divNode.lvalue, scope) + rightType = self.visit(divNode.rvalue, scope) + if leftType != IntType() or rightType != IntType(): + errorText = f'non-Int arguments: {leftType.name} / {rightType.name} .' + self.errors.append(TypexError( + errorText, divNode.line, divNode.col)) + return ErrorType() + return IntType() + + @visitor.when(LessNode) + def visit(self, lessNode, scope): + leftType = self.visit(lessNode.lvalue, scope) + rightType = self.visit(lessNode.rvalue, scope) + if leftType != IntType() or rightType != IntType(): + errorText = f'non-Int arguments: {leftType.name} < {rightType.name} .' + self.errors.append(TypexError( + errorText, lessNode.line, lessNode.col)) + return ErrorType() + return BoolType() + + @visitor.when(LessEqNode) + def visit(self, lessEq, scope): + leftType = self.visit(lessEq.lvalue, scope) + rightType = self.visit(lessEq.rvalue, scope) + if leftType != IntType() or rightType != IntType(): + errorText = f'non-Int arguments: {leftType.name} <= {rightType.name} .' + self.errors.append(TypexError( + errorText, lessEq.line, lessEq.col)) + return ErrorType() + return BoolType() + + @visitor.when(EqualNode) + def visit(self, lessEq, scope): + leftType = self.visit(lessEq.lvalue, scope) + rightType = self.visit(lessEq.rvalue, scope) + if (leftType != rightType) and (leftType in [IntType(), StringType(), BoolType()] or rightType in [IntType(), StringType(), BoolType()]): + errorText = 'Illegal comparison with a basic type.' + self.errors.append(TypexError(errorText, lessEq.line, lessEq.col)) + return ErrorType() + return BoolType() + @visitor.when(NegationNode) + def visit(self, negationNode, scope): + exprType = self.visit(negationNode.expr, scope) + if exprType != IntType(): + errorText = f'Argument of \'~\' has type {exprType.name} instead of {IntType().name}.' + self.errors.append(TypexError( + errorText, negationNode.line, negationNode.col)) + return ErrorType() + return IntType() + + @visitor.when(LogicNegationNode) + def visit(self, logicNegationNode, scope): + exprType = self.visit(logicNegationNode.expr, scope) + if exprType != BoolType(): + errorText = f'Argument of \'not\' has type {exprType.name} instead of {BoolType().name}.' + self.errors.append(TypexError( + errorText, logicNegationNode.line, logicNegationNode.col)) + return ErrorType() + return BoolType() + + @visitor.when(IsVoidNode) + def visit(self, isVoidNode, scope): + self.visit(isVoidNode.expr, scope) + return BoolType() + @visitor.when(NewNode) + def visit(self, newNode, scope): + try: + typex = self.context.get_type( + newNode.id, (newNode.line, newNode.col)) + except: + typex = ErrorType() + errorText = f'\'new\' used with undefined class {newNode.id}.' + self.errors.append(TypexError( + errorText, newNode.line, newNode.col)) + return get_type(typex, self.currentType) + @visitor.when(IdNode) + def visit(self, idNode, scope): + varType = self.find_variable(scope, idNode.id).type + return get_type(varType, self.currentType) + + @visitor.when(IntNode) + def visit(self, intNode, scope): + return IntType((intNode.line, intNode.col)) + + @visitor.when(BoolNode) + def visit(self, boolNode, scope): + return BoolType((boolNode.line, boolNode.col)) + + @visitor.when(StringNode) + def visit(self, stringNode, scope): + return StringType((stringNode.line, stringNode.col)) def _get_type(self, ntype, pos): try: @@ -283,19 +411,3 @@ def _get_method(self, typex, name, pos): errorText = f'Dispatch to undefined method {name}.' self.errors.append(AttributexError(errorText, *pos)) return MethodError(name, [], [], ErrorType()) - - def _check_args(self, method, scope, args, pos): - argTypes = [self.visit(arg, scope) for arg in args] - - if len(argTypes) > len(method.param_types): - errorText = f'Method {method.name} called with wrong number of arguments.' - self.errors.append(SemanticError(errorText, *pos)) - elif len(argTypes) < len(method.param_types): - for arg, argInfo in zip(method.param_names[len(argTypes):], args[len(argTypes):]): - errorText = f'Method {method.name} called with wrong number of arguments.' - self.errors.append(SemanticError(errorText, *argInfo.pos)) - - for argType, paramType, paramName in zip(argTypes, method.param_types, method.param_names): - if not argType.conforms_to(paramType): - errorText = f'In call of method {method.name}, type {argType.name} of parameter {paramName} does not conform to declared type {paramType.name}.' - self.errors.append(TypexError(errorText, *pos)) From 2c61907429dfc0bc41d69712cfd2416e92bbfa11 Mon Sep 17 00:00:00 2001 From: cwjki Date: Mon, 21 Feb 2022 16:48:55 -0500 Subject: [PATCH 130/194] restesting the semantic --- src/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.py b/src/main.py index c8038e86d..598421383 100644 --- a/src/main.py +++ b/src/main.py @@ -47,7 +47,7 @@ def main(_input, _output): # ast, errors, context, scope = SemanticAn if __name__ == "__main__": - path = '/home/cwjki/Projects/cool-compiler-2021/tests/parser/case2.cl' + path = '/home/cwjki/Projects/cool-compiler-2021/tests/lexer/comment1.cl' _input = sys.argv[1] if len(sys.argv) > 1 else path _output = sys.argv[2] if len(sys.argv) > 2 else None From 27589b51804149efa771c19a4191f60120812eda Mon Sep 17 00:00:00 2001 From: cwjki Date: Mon, 21 Feb 2022 17:47:41 -0500 Subject: [PATCH 131/194] fixing some typos bugs --- src/main.py | 24 ++++++++++++++++++++---- src/semantic/visitors/typeBuilder.py | 4 ++-- src/semantic/visitors/typeChecker.py | 19 +++++++++++-------- src/semantic/visitors/typeCollector.py | 2 +- src/semantic/visitors/varCollector.py | 18 +++++++++++++----- src/utils/errors.py | 6 +++--- 6 files changed, 50 insertions(+), 23 deletions(-) diff --git a/src/main.py b/src/main.py index 598421383..cd499e280 100644 --- a/src/main.py +++ b/src/main.py @@ -7,6 +7,7 @@ from semantic.visitors.typeChecker import TypeChecker from semantic.visitors.typeCollector import TypeCollector from semantic.visitors.varCollector import VarCollector +from utils.errors import SemanticError def main(_input, _output): @@ -29,16 +30,31 @@ def main(_input, _output): semanticErrors = [] typeCollector = TypeCollector(semanticErrors) typeCollector.visit(ast) + print("TYPE COLLECTOR") + if semanticErrors: + for error in semanticErrors: + print(error) + context = typeCollector.context typeBuilder = TypeBuilder(context, semanticErrors) typeBuilder.visit(ast) - typeInferer = VarCollector(context, semanticErrors) - scope = typeInferer.visit(ast) + print("TYPE Builder") + if semanticErrors: + for error in semanticErrors: + print(error) + + varCollector = VarCollector(context, semanticErrors) + scope = varCollector.visit(ast) + print("Var Collector") + if semanticErrors: + for error in semanticErrors: + print(error) + typeChecker = TypeChecker(context, semanticErrors) typeChecker.visit(ast, scope) if semanticErrors: for error in semanticErrors: - print(semanticErrors) + print(error) raise Exception() # Code Generation @@ -47,7 +63,7 @@ def main(_input, _output): # ast, errors, context, scope = SemanticAn if __name__ == "__main__": - path = '/home/cwjki/Projects/cool-compiler-2021/tests/lexer/comment1.cl' + path = '/home/cwjki/Projects/cool-compiler-2021/tests/semantic/arithmetic1.cl' _input = sys.argv[1] if len(sys.argv) > 1 else path _output = sys.argv[2] if len(sys.argv) > 2 else None diff --git a/src/semantic/visitors/typeBuilder.py b/src/semantic/visitors/typeBuilder.py index b54941a20..ab9850192 100644 --- a/src/semantic/visitors/typeBuilder.py +++ b/src/semantic/visitors/typeBuilder.py @@ -43,7 +43,7 @@ def visit(self, classDeclarationNode): parent = None try: current = parent - while current is None: + while current is not None: if current.name == self.currentType.name: errorText = f'Class {self.currentType.name}, or an ancestor of {self.currentType.name}, is involved in an inheritance cycle.' raise SemanticError( @@ -80,7 +80,7 @@ def visit(self, funcDeclarationNode): try: returnType = self.context.get_type( - funcDeclarationNode.type, funcDeclarationNode.typeLine, funcDeclarationNode.typeCol) + funcDeclarationNode.type, (funcDeclarationNode.typeLine, funcDeclarationNode.typeCol)) except SemanticError: errorText = f'Undefined return type {funcDeclarationNode.type} in method {funcDeclarationNode.id}.' self.errors.append(TypexError( diff --git a/src/semantic/visitors/typeChecker.py b/src/semantic/visitors/typeChecker.py index 083151763..5c0a1a248 100644 --- a/src/semantic/visitors/typeChecker.py +++ b/src/semantic/visitors/typeChecker.py @@ -1,9 +1,4 @@ -from ast import Div -from distutils.log import error -import re - -from click import option -from semantic.semantic import AutoType, BoolType, ErrorType, IntType, MethodError, ObjectType, StringType +from semantic.semantic import AutoType, BoolType, ErrorType, IntType, MethodError, ObjectType, StringType, VariableInfo, VoidType from utils.errors import AttributexError, SemanticError, TypexError from utils import visitor from utils.utils import get_type, get_common_basetype @@ -15,8 +10,8 @@ def __init__(self, context, errors): self.context = context self.currentType = None self.currentMethod = None - self.errors = errors self.currentIndex = None + self.errors = errors @visitor.on('node') def visit(self, node, scope): @@ -104,7 +99,7 @@ def visit(self, varDeclarationNode, scope): return varType else: typex = self.visit(varDeclarationNode.expr, scope) - if not typex.conform_to(varType): + if not typex.conforms_to(varType): errorText = f'Inferred type {typex.name} of initialization of {varDeclarationNode.id} does not conform to identifier\'s declared type {varType.name}.' self.errors.append(TypexError( errorText, varDeclarationNode.typeLine, varDeclarationNode.typeCol)) @@ -411,3 +406,11 @@ def _get_method(self, typex, name, pos): errorText = f'Dispatch to undefined method {name}.' self.errors.append(AttributexError(errorText, *pos)) return MethodError(name, [], [], ErrorType()) + + def find_variable(self, scope, lex): + var_info = scope.find_local(lex) + if var_info is None: + var_info = scope.find_attribute(lex) + if lex in self.currentType.attributes and var_info is None: + return VariableInfo(lex, VoidType()) + return var_info diff --git a/src/semantic/visitors/typeCollector.py b/src/semantic/visitors/typeCollector.py index 814159bce..078743e85 100644 --- a/src/semantic/visitors/typeCollector.py +++ b/src/semantic/visitors/typeCollector.py @@ -24,7 +24,7 @@ def visit(self, programNode): self.context.types['IO'] = IOType() for classDeclarationNode in programNode.declarations: - self.visit(self, classDeclarationNode) + self.visit(classDeclarationNode) @visitor.when(ClassDeclarationNode) def visit(self, classDeclarationNode): diff --git a/src/semantic/visitors/varCollector.py b/src/semantic/visitors/varCollector.py index c7a27c7c9..b19ab1381 100644 --- a/src/semantic/visitors/varCollector.py +++ b/src/semantic/visitors/varCollector.py @@ -1,6 +1,6 @@ from utils import visitor -from utils.ast import ArrobaCallNode, AssignNode, AttrDeclarationNode, BlockNode, CaseNode, CaseOptionNode, ClassDeclarationNode, DotCallNode, FuncDeclarationNode, IdNode, IfThenElseNode, IntNode, IsVoidNode, LetInNode, MemberCallNode, ProgramNode, VarDeclarationNode, WhileNode -from semantic.semantic import ErrorType, IntType, Scope, define_default_value +from utils.ast import ArrobaCallNode, AssignNode, AttrDeclarationNode, BlockNode, BoolNode, CaseNode, CaseOptionNode, ClassDeclarationNode, DotCallNode, FuncDeclarationNode, IdNode, IfThenElseNode, IntNode, IsVoidNode, LetInNode, MemberCallNode, ProgramNode, StringNode, VarDeclarationNode, WhileNode +from semantic.semantic import ErrorType, IntType, Scope, StringType from utils.errors import NamexError, SemanticError, TypexError @@ -17,7 +17,7 @@ def visit(self, node, scope): pass @visitor.when(ProgramNode) - def visit(self, programNode, scope): + def visit(self, programNode, scope=None): scope = Scope() for declaration in programNode.declarations: self.visit(declaration, scope.create_child()) @@ -67,7 +67,7 @@ def visit(self, attrDeclarationNode, scope): attr = self.currentType.get_attribute( attrDeclarationNode.id, (attrDeclarationNode.line, attrDeclarationNode.col)) if attrDeclarationNode.expr is None: - define_default_value(attr.type, attrDeclarationNode) + self.define_default_value(attr.type, attrDeclarationNode) else: self.visit(attrDeclarationNode.expr, scope) attr.expr = attrDeclarationNode.expr @@ -104,7 +104,7 @@ def visit(self, varDeclarationNode, scope): if varDeclarationNode.expr is not None: self.visit(varDeclarationNode.expr, scope) else: - define_default_value(vType, varDeclarationNode) + self.define_default_value(vType, varDeclarationNode) @visitor.when(AssignNode) def visit(self, assignNode, scope): @@ -210,3 +210,11 @@ def visit(self, idNode, scope): vInfo = scope.find_variable(idNode.id) return vInfo.type + + def define_default_value(self, typex, node): + if typex == IntType(): + node.expr = IntNode(0) + elif typex == StringType(): + node.expr = StringNode("") + else: + node.expr = BoolNode('false') diff --git a/src/utils/errors.py b/src/utils/errors.py index a5127b7a9..6df03f6fd 100644 --- a/src/utils/errors.py +++ b/src/utils/errors.py @@ -27,16 +27,16 @@ def __init__(self, text, line, column): super().__init__('SemanticError', text, line, column) -class TypexError(SemanticError): +class TypexError(CoolError): def __init__(self, text, line, column): super().__init__('TypeError', text, line, column) -class NamexError(SemanticError): +class NamexError(CoolError): def __init__(self, text, line, column): super().__init__('NameError', text, line, column) -class AttributexError(SemanticError): +class AttributexError(CoolError): def __init__(self, text, line, column): super().__init__('AttributeError', text, line, column) From 801e64ae55176e3e6f401dab8b47a28c2848eb3a Mon Sep 17 00:00:00 2001 From: cwjki Date: Mon, 21 Feb 2022 18:49:45 -0500 Subject: [PATCH 132/194] testign semantics test after fixing some bugs --- src/main.py | 27 +++++++++++++++------------ src/semantic/visitors/varCollector.py | 2 +- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/main.py b/src/main.py index cd499e280..56a3953b0 100644 --- a/src/main.py +++ b/src/main.py @@ -30,25 +30,28 @@ def main(_input, _output): semanticErrors = [] typeCollector = TypeCollector(semanticErrors) typeCollector.visit(ast) - print("TYPE COLLECTOR") - if semanticErrors: - for error in semanticErrors: - print(error) + # print("TYPE COLLECTOR") + # if semanticErrors: + # for error in semanticErrors: + # print(error) context = typeCollector.context typeBuilder = TypeBuilder(context, semanticErrors) typeBuilder.visit(ast) - print("TYPE Builder") - if semanticErrors: - for error in semanticErrors: - print(error) + + # print("CONTEXT") + # print(context) + # print("TYPE Builder") + # if semanticErrors: + # for error in semanticErrors: + # print(error) varCollector = VarCollector(context, semanticErrors) scope = varCollector.visit(ast) - print("Var Collector") - if semanticErrors: - for error in semanticErrors: - print(error) + # print("Var Collector") + # if semanticErrors: + # for error in semanticErrors: + # print(error) typeChecker = TypeChecker(context, semanticErrors) typeChecker.visit(ast, scope) diff --git a/src/semantic/visitors/varCollector.py b/src/semantic/visitors/varCollector.py index b19ab1381..0d36a9ef3 100644 --- a/src/semantic/visitors/varCollector.py +++ b/src/semantic/visitors/varCollector.py @@ -90,7 +90,7 @@ def visit(self, varDeclarationNode, scope): try: vType = self.context.get_type( - varDeclarationNode.type, varDeclarationNode.line, varDeclarationNode.col) + varDeclarationNode.type, (varDeclarationNode.line, varDeclarationNode.col)) except: errorText = f'Class {varDeclarationNode.type} of let-bound identifier {varDeclarationNode.id} is undefined.' self.errors.append(TypexError( From 4016767b67362c8c6f040a83e9dd4f487584cfd2 Mon Sep 17 00:00:00 2001 From: cwjki Date: Mon, 21 Feb 2022 18:56:37 -0500 Subject: [PATCH 133/194] fixign the attribute 4 semantic test --- src/main.py | 2 +- src/semantic/visitors/typeBuilder.py | 2 +- src/semantic/visitors/typeChecker.py | 2 +- src/semantic/visitors/varCollector.py | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main.py b/src/main.py index 56a3953b0..e33e3d8fb 100644 --- a/src/main.py +++ b/src/main.py @@ -66,7 +66,7 @@ def main(_input, _output): # ast, errors, context, scope = SemanticAn if __name__ == "__main__": - path = '/home/cwjki/Projects/cool-compiler-2021/tests/semantic/arithmetic1.cl' + path = '/home/cwjki/Projects/cool-compiler-2021/tests/semantic/attributes4.cl' _input = sys.argv[1] if len(sys.argv) > 1 else path _output = sys.argv[2] if len(sys.argv) > 2 else None diff --git a/src/semantic/visitors/typeBuilder.py b/src/semantic/visitors/typeBuilder.py index ab9850192..dbcd9d3a8 100644 --- a/src/semantic/visitors/typeBuilder.py +++ b/src/semantic/visitors/typeBuilder.py @@ -70,7 +70,7 @@ def visit(self, funcDeclarationNode): argsNames.append(name) try: - argsTypes = self.context.get_type(typex, line, col) + argType = self.context.get_type(typex, (line, col)) except SemanticError: errorText = f'Class {typex} of formal parameter {typex} is undefined.' self.errors.append(TypexError(errorText, line, col)) diff --git a/src/semantic/visitors/typeChecker.py b/src/semantic/visitors/typeChecker.py index 5c0a1a248..c5283d25a 100644 --- a/src/semantic/visitors/typeChecker.py +++ b/src/semantic/visitors/typeChecker.py @@ -212,7 +212,7 @@ def visit(self, ifThenElseNode, scope): self.errors.append(TypexError( errorText, ifThenElseNode.line, ifThenElseNode.col)) - ifBodyType = self.visit(ifThenElseNode.idBody, scope) + ifBodyType = self.visit(ifThenElseNode.ifBody, scope) elseBodyType = self.visit(ifThenElseNode.elseBody, scope) return get_common_basetype([ifBodyType, elseBodyType]) diff --git a/src/semantic/visitors/varCollector.py b/src/semantic/visitors/varCollector.py index 0d36a9ef3..b1e143581 100644 --- a/src/semantic/visitors/varCollector.py +++ b/src/semantic/visitors/varCollector.py @@ -130,18 +130,18 @@ def visit(self, assignNode, scope): def visit(self, arrobaCallNode, scope): self.visit(arrobaCallNode.obj, scope) for arg in arrobaCallNode.args: - self.visit(arg) + self.visit(arg, scope) @visitor.when(DotCallNode) def visit(self, dotCallNode, scope): self.visit(dotCallNode.obj, scope) for arg in dotCallNode.args: - self.visit(arg) + self.visit(arg, scope) @visitor.when(MemberCallNode) def visit(self, memberCallNode, scope): for arg in memberCallNode.args: - self.visit(arg) + self.visit(arg, scope) @visitor.when(IfThenElseNode) def visit(self, ifThenElseNode, scope): From 711e4edf2bd9d49bd81627c2a4735092d18e4520 Mon Sep 17 00:00:00 2001 From: cwjki Date: Mon, 21 Feb 2022 19:11:58 -0500 Subject: [PATCH 134/194] check attibute 4 again --- src/cparser/parser.py | 3 ++- src/cparser/parsetab.py | 21 +++++++++++---------- src/utils/utils.py | 7 ++++--- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/cparser/parser.py b/src/cparser/parser.py index 5573e6710..3fa65b651 100644 --- a/src/cparser/parser.py +++ b/src/cparser/parser.py @@ -206,7 +206,8 @@ def p_atom_id(self, p): p[0] = IdNode(p.slice[1]) def p_atom_bool(self, p): - '''atom : BOOL''' + '''atom : TRUE + | FALSE''' p[0] = BoolNode(p.slice[1]) def p_atom_string(self, p): diff --git a/src/cparser/parsetab.py b/src/cparser/parsetab.py index fc129f583..18a6f9fdb 100644 --- a/src/cparser/parsetab.py +++ b/src/cparser/parsetab.py @@ -6,9 +6,9 @@ _lr_method = 'LALR' -_lr_signature = 'programARROW ASSIGN AT BOOL CASE CLASS COLON COMMA DIV DOT ELSE EQUAL ESAC FI ID IF IN INHERITS INT ISVOID LBRACE LESS LESSEQ LET LNOT LOOP LPAREN MINUS NEW NOT OF PLUS POOL RBRACE RPAREN SEMICOLON STAR STRING THEN TYPE WHILEprogram : class_listepsilon :class_list : def_class SEMICOLON class_list\n | def_class SEMICOLON def_class : CLASS TYPE LBRACE feature_list RBRACE\n | CLASS TYPE INHERITS TYPE LBRACE feature_list RBRACEfeature_list : def_attr SEMICOLON feature_list\n | def_func SEMICOLON feature_list\n | epsilondef_attr : ID COLON TYPE\n | ID COLON TYPE ASSIGN exprdef_func : ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACEparams : param_list\n | param_list_emptyparam_list : param\n | param COMMA param_listparam_list_empty : epsilonparam : ID COLON TYPEexpr : LET let_attrs IN expr\n | CASE expr OF case_list ESAC\n | IF expr THEN expr ELSE expr FI\n | WHILE expr LOOP expr POOLexpr : ID ASSIGN exprexpr : expr AT TYPE DOT ID LPAREN args RPAREN\n | expr DOT ID LPAREN args RPAREN\n | ID LPAREN args RPARENexpr : expr PLUS expr\n | expr MINUS expr\n | expr STAR expr\n | expr DIV expr\n | expr LESS expr\n | expr LESSEQ expr\n | expr EQUAL exprexpr : NOT expr\n | ISVOID expr\n | LNOT exprexpr : LPAREN expr RPARENexpr : atomlet_attrs : def_var\n | def_var COMMA let_attrsdef_var : ID COLON TYPE\n | ID COLON TYPE ASSIGN exprcase_list : case_option SEMICOLON\n | case_option SEMICOLON case_listcase_option : ID COLON TYPE ARROW exprargs : arg_list\n | arg_list_emptyarg_list : expr\n | expr COMMA arg_listarg_list_empty : epsilonatom : INTatom : IDatom : BOOLatom : STRINGatom : NEW TYPEatom : blockblock : LBRACE block_list RBRACE block_list : expr SEMICOLON\n | expr SEMICOLON block_list' +_lr_signature = 'programARROW ASSIGN AT CASE CLASS COLON COMMA DIV DOT ELSE EQUAL ESAC FALSE FI ID IF IN INHERITS INT ISVOID LBRACE LESS LESSEQ LET LNOT LOOP LPAREN MINUS NEW NOT OF PLUS POOL RBRACE RPAREN SEMICOLON STAR STRING THEN TRUE TYPE WHILEprogram : class_listepsilon :class_list : def_class SEMICOLON class_list\n | def_class SEMICOLON def_class : CLASS TYPE LBRACE feature_list RBRACE\n | CLASS TYPE INHERITS TYPE LBRACE feature_list RBRACEfeature_list : def_attr SEMICOLON feature_list\n | def_func SEMICOLON feature_list\n | epsilondef_attr : ID COLON TYPE\n | ID COLON TYPE ASSIGN exprdef_func : ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACEparams : param_list\n | param_list_emptyparam_list : param\n | param COMMA param_listparam_list_empty : epsilonparam : ID COLON TYPEexpr : LET let_attrs IN expr\n | CASE expr OF case_list ESAC\n | IF expr THEN expr ELSE expr FI\n | WHILE expr LOOP expr POOLexpr : ID ASSIGN exprexpr : expr AT TYPE DOT ID LPAREN args RPAREN\n | expr DOT ID LPAREN args RPAREN\n | ID LPAREN args RPARENexpr : expr PLUS expr\n | expr MINUS expr\n | expr STAR expr\n | expr DIV expr\n | expr LESS expr\n | expr LESSEQ expr\n | expr EQUAL exprexpr : NOT expr\n | ISVOID expr\n | LNOT exprexpr : LPAREN expr RPARENexpr : atomlet_attrs : def_var\n | def_var COMMA let_attrsdef_var : ID COLON TYPE\n | ID COLON TYPE ASSIGN exprcase_list : case_option SEMICOLON\n | case_option SEMICOLON case_listcase_option : ID COLON TYPE ARROW exprargs : arg_list\n | arg_list_emptyarg_list : expr\n | expr COMMA arg_listarg_list_empty : epsilonatom : INTatom : IDatom : TRUE\n | FALSEatom : STRINGatom : NEW TYPEatom : blockblock : LBRACE block_list RBRACE block_list : expr SEMICOLON\n | expr SEMICOLON block_list' -_lr_action_items = {'CLASS':([0,5,],[4,4,]),'$end':([1,2,5,7,],[0,-1,-4,-3,]),'SEMICOLON':([3,11,12,16,24,36,37,38,47,48,49,50,52,75,76,77,78,80,82,90,91,92,93,94,95,96,103,104,107,111,115,125,129,130,132,139,140,141,],[5,17,18,-5,-10,-6,-52,-11,-38,-51,-53,-54,-56,-34,-35,-36,-55,105,-23,-27,-28,-29,-30,-31,-32,-33,-37,-57,-26,-19,126,-20,-22,-12,-25,-21,-24,-45,]),'TYPE':([4,9,19,33,51,55,59,99,127,],[6,15,24,54,78,81,88,113,135,]),'LBRACE':([6,15,32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,81,97,101,102,105,106,108,110,124,128,131,138,],[8,21,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,106,53,53,53,53,53,53,53,53,53,53,53,]),'INHERITS':([6,],[9,]),'ID':([8,17,18,20,21,32,35,39,40,41,42,43,44,45,46,53,57,58,60,61,62,63,64,65,66,67,97,98,100,101,102,105,106,108,109,110,124,126,128,131,138,],[14,14,14,25,14,37,25,70,37,37,37,37,37,37,37,37,37,37,89,37,37,37,37,37,37,37,37,70,116,37,37,37,37,37,122,37,37,116,37,37,37,]),'RBRACE':([8,10,13,17,18,21,22,23,31,37,47,48,49,50,52,75,76,77,78,79,82,90,91,92,93,94,95,96,103,104,105,107,111,119,120,125,129,132,139,140,],[-2,16,-9,-2,-2,-2,-7,-8,36,-52,-38,-51,-53,-54,-56,-34,-35,-36,-55,104,-23,-27,-28,-29,-30,-31,-32,-33,-37,-57,-58,-26,-19,-59,130,-20,-22,-25,-21,-24,]),'COLON':([14,25,34,70,116,],[19,33,55,99,127,]),'LPAREN':([14,32,37,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,89,97,101,102,105,106,108,110,122,124,128,131,138,],[20,43,58,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,110,43,43,43,43,43,43,43,131,43,43,43,43,]),'RPAREN':([20,26,27,28,29,30,37,47,48,49,50,52,54,56,58,74,75,76,77,78,82,83,84,85,86,87,90,91,92,93,94,95,96,103,104,107,110,111,121,123,125,129,131,132,137,139,140,],[-2,34,-13,-14,-15,-17,-52,-38,-51,-53,-54,-56,-18,-16,-2,103,-34,-35,-36,-55,-23,107,-46,-47,-48,-50,-27,-28,-29,-30,-31,-32,-33,-37,-57,-26,-2,-19,-49,132,-20,-22,-2,-25,140,-21,-24,]),'ASSIGN':([24,37,113,],[32,57,124,]),'COMMA':([29,37,47,48,49,50,52,54,69,75,76,77,78,82,86,90,91,92,93,94,95,96,103,104,107,111,113,125,129,132,133,139,140,],[35,-52,-38,-51,-53,-54,-56,-18,98,-34,-35,-36,-55,-23,108,-27,-28,-29,-30,-31,-32,-33,-37,-57,-26,-19,-41,-20,-22,-25,-42,-21,-24,]),'LET':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,101,102,105,106,108,110,124,128,131,138,],[39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,]),'CASE':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,101,102,105,106,108,110,124,128,131,138,],[40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,]),'IF':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,101,102,105,106,108,110,124,128,131,138,],[41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,]),'WHILE':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,101,102,105,106,108,110,124,128,131,138,],[42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,]),'NOT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,101,102,105,106,108,110,124,128,131,138,],[44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,]),'ISVOID':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,101,102,105,106,108,110,124,128,131,138,],[45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,]),'LNOT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,101,102,105,106,108,110,124,128,131,138,],[46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,]),'INT':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,101,102,105,106,108,110,124,128,131,138,],[48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,]),'BOOL':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,101,102,105,106,108,110,124,128,131,138,],[49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,]),'STRING':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,101,102,105,106,108,110,124,128,131,138,],[50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,]),'NEW':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,101,102,105,106,108,110,124,128,131,138,],[51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,]),'AT':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,103,104,107,111,117,118,120,125,129,132,133,136,139,140,141,],[-52,59,-38,-51,-53,-54,-56,59,59,59,59,59,59,59,-55,59,59,59,59,59,59,59,59,59,59,-37,-57,-26,59,59,59,59,-20,-22,-25,59,59,-21,-24,59,]),'DOT':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,88,90,91,92,93,94,95,96,103,104,107,111,117,118,120,125,129,132,133,136,139,140,141,],[-52,60,-38,-51,-53,-54,-56,60,60,60,60,60,60,60,-55,60,60,60,109,60,60,60,60,60,60,60,-37,-57,-26,60,60,60,60,-20,-22,-25,60,60,-21,-24,60,]),'PLUS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,103,104,107,111,117,118,120,125,129,132,133,136,139,140,141,],[-52,61,-38,-51,-53,-54,-56,61,61,61,61,61,61,61,-55,61,61,61,61,61,61,61,61,61,61,-37,-57,-26,61,61,61,61,-20,-22,-25,61,61,-21,-24,61,]),'MINUS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,103,104,107,111,117,118,120,125,129,132,133,136,139,140,141,],[-52,62,-38,-51,-53,-54,-56,62,62,62,62,62,62,62,-55,62,62,62,62,62,62,62,62,62,62,-37,-57,-26,62,62,62,62,-20,-22,-25,62,62,-21,-24,62,]),'STAR':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,103,104,107,111,117,118,120,125,129,132,133,136,139,140,141,],[-52,63,-38,-51,-53,-54,-56,63,63,63,63,63,63,63,-55,63,63,63,63,63,63,63,63,63,63,-37,-57,-26,63,63,63,63,-20,-22,-25,63,63,-21,-24,63,]),'DIV':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,103,104,107,111,117,118,120,125,129,132,133,136,139,140,141,],[-52,64,-38,-51,-53,-54,-56,64,64,64,64,64,64,64,-55,64,64,64,64,64,64,64,64,64,64,-37,-57,-26,64,64,64,64,-20,-22,-25,64,64,-21,-24,64,]),'LESS':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,103,104,107,111,117,118,120,125,129,132,133,136,139,140,141,],[-52,65,-38,-51,-53,-54,-56,65,65,65,65,65,65,65,-55,65,65,65,65,65,65,65,65,65,65,-37,-57,-26,65,65,65,65,-20,-22,-25,65,65,-21,-24,65,]),'LESSEQ':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,103,104,107,111,117,118,120,125,129,132,133,136,139,140,141,],[-52,66,-38,-51,-53,-54,-56,66,66,66,66,66,66,66,-55,66,66,66,66,66,66,66,66,66,66,-37,-57,-26,66,66,66,66,-20,-22,-25,66,66,-21,-24,66,]),'EQUAL':([37,38,47,48,49,50,52,71,72,73,74,75,76,77,78,80,82,86,90,91,92,93,94,95,96,103,104,107,111,117,118,120,125,129,132,133,136,139,140,141,],[-52,67,-38,-51,-53,-54,-56,67,67,67,67,67,67,67,-55,67,67,67,67,67,67,67,67,67,67,-37,-57,-26,67,67,67,67,-20,-22,-25,67,67,-21,-24,67,]),'OF':([37,47,48,49,50,52,71,75,76,77,78,82,90,91,92,93,94,95,96,103,104,107,111,125,129,132,139,140,],[-52,-38,-51,-53,-54,-56,100,-34,-35,-36,-55,-23,-27,-28,-29,-30,-31,-32,-33,-37,-57,-26,-19,-20,-22,-25,-21,-24,]),'THEN':([37,47,48,49,50,52,72,75,76,77,78,82,90,91,92,93,94,95,96,103,104,107,111,125,129,132,139,140,],[-52,-38,-51,-53,-54,-56,101,-34,-35,-36,-55,-23,-27,-28,-29,-30,-31,-32,-33,-37,-57,-26,-19,-20,-22,-25,-21,-24,]),'LOOP':([37,47,48,49,50,52,73,75,76,77,78,82,90,91,92,93,94,95,96,103,104,107,111,125,129,132,139,140,],[-52,-38,-51,-53,-54,-56,102,-34,-35,-36,-55,-23,-27,-28,-29,-30,-31,-32,-33,-37,-57,-26,-19,-20,-22,-25,-21,-24,]),'ELSE':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,103,104,107,111,117,125,129,132,139,140,],[-52,-38,-51,-53,-54,-56,-34,-35,-36,-55,-23,-27,-28,-29,-30,-31,-32,-33,-37,-57,-26,-19,128,-20,-22,-25,-21,-24,]),'POOL':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,103,104,107,111,118,125,129,132,139,140,],[-52,-38,-51,-53,-54,-56,-34,-35,-36,-55,-23,-27,-28,-29,-30,-31,-32,-33,-37,-57,-26,-19,129,-20,-22,-25,-21,-24,]),'IN':([37,47,48,49,50,52,68,69,75,76,77,78,82,90,91,92,93,94,95,96,103,104,107,111,112,113,125,129,132,133,139,140,],[-52,-38,-51,-53,-54,-56,97,-39,-34,-35,-36,-55,-23,-27,-28,-29,-30,-31,-32,-33,-37,-57,-26,-19,-40,-41,-20,-22,-25,-42,-21,-24,]),'FI':([37,47,48,49,50,52,75,76,77,78,82,90,91,92,93,94,95,96,103,104,107,111,125,129,132,136,139,140,],[-52,-38,-51,-53,-54,-56,-34,-35,-36,-55,-23,-27,-28,-29,-30,-31,-32,-33,-37,-57,-26,-19,-20,-22,-25,139,-21,-24,]),'ESAC':([114,126,134,],[125,-43,-44,]),'ARROW':([135,],[138,]),} +_lr_action_items = {'CLASS':([0,5,],[4,4,]),'$end':([1,2,5,7,],[0,-1,-4,-3,]),'SEMICOLON':([3,11,12,16,24,36,37,38,47,48,49,50,51,53,76,77,78,79,81,83,91,92,93,94,95,96,97,104,105,108,112,116,126,130,131,133,140,141,142,],[5,17,18,-5,-10,-6,-52,-11,-38,-51,-53,-54,-55,-57,-34,-35,-36,-56,106,-23,-27,-28,-29,-30,-31,-32,-33,-37,-58,-26,-19,127,-20,-22,-12,-25,-21,-24,-45,]),'TYPE':([4,9,19,33,52,56,60,100,128,],[6,15,24,55,79,82,89,114,136,]),'LBRACE':([6,15,32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,82,98,102,103,106,107,109,111,125,129,132,139,],[8,21,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,107,54,54,54,54,54,54,54,54,54,54,54,]),'INHERITS':([6,],[9,]),'ID':([8,17,18,20,21,32,35,39,40,41,42,43,44,45,46,54,58,59,61,62,63,64,65,66,67,68,98,99,101,102,103,106,107,109,110,111,125,127,129,132,139,],[14,14,14,25,14,37,25,71,37,37,37,37,37,37,37,37,37,37,90,37,37,37,37,37,37,37,37,71,117,37,37,37,37,37,123,37,37,117,37,37,37,]),'RBRACE':([8,10,13,17,18,21,22,23,31,37,47,48,49,50,51,53,76,77,78,79,80,83,91,92,93,94,95,96,97,104,105,106,108,112,120,121,126,130,133,140,141,],[-2,16,-9,-2,-2,-2,-7,-8,36,-52,-38,-51,-53,-54,-55,-57,-34,-35,-36,-56,105,-23,-27,-28,-29,-30,-31,-32,-33,-37,-58,-59,-26,-19,-60,131,-20,-22,-25,-21,-24,]),'COLON':([14,25,34,71,117,],[19,33,56,100,128,]),'LPAREN':([14,32,37,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,90,98,102,103,106,107,109,111,123,125,129,132,139,],[20,43,59,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,111,43,43,43,43,43,43,43,132,43,43,43,43,]),'RPAREN':([20,26,27,28,29,30,37,47,48,49,50,51,53,55,57,59,75,76,77,78,79,83,84,85,86,87,88,91,92,93,94,95,96,97,104,105,108,111,112,122,124,126,130,132,133,138,140,141,],[-2,34,-13,-14,-15,-17,-52,-38,-51,-53,-54,-55,-57,-18,-16,-2,104,-34,-35,-36,-56,-23,108,-46,-47,-48,-50,-27,-28,-29,-30,-31,-32,-33,-37,-58,-26,-2,-19,-49,133,-20,-22,-2,-25,141,-21,-24,]),'ASSIGN':([24,37,114,],[32,58,125,]),'COMMA':([29,37,47,48,49,50,51,53,55,70,76,77,78,79,83,87,91,92,93,94,95,96,97,104,105,108,112,114,126,130,133,134,140,141,],[35,-52,-38,-51,-53,-54,-55,-57,-18,99,-34,-35,-36,-56,-23,109,-27,-28,-29,-30,-31,-32,-33,-37,-58,-26,-19,-41,-20,-22,-25,-42,-21,-24,]),'LET':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,]),'CASE':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,]),'IF':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,]),'WHILE':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,]),'NOT':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,]),'ISVOID':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,]),'LNOT':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,]),'INT':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,]),'TRUE':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,]),'FALSE':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,]),'STRING':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,]),'NEW':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,]),'AT':([37,38,47,48,49,50,51,53,72,73,74,75,76,77,78,79,81,83,87,91,92,93,94,95,96,97,104,105,108,112,118,119,121,126,130,133,134,137,140,141,142,],[-52,60,-38,-51,-53,-54,-55,-57,60,60,60,60,60,60,60,-56,60,60,60,60,60,60,60,60,60,60,-37,-58,-26,60,60,60,60,-20,-22,-25,60,60,-21,-24,60,]),'DOT':([37,38,47,48,49,50,51,53,72,73,74,75,76,77,78,79,81,83,87,89,91,92,93,94,95,96,97,104,105,108,112,118,119,121,126,130,133,134,137,140,141,142,],[-52,61,-38,-51,-53,-54,-55,-57,61,61,61,61,61,61,61,-56,61,61,61,110,61,61,61,61,61,61,61,-37,-58,-26,61,61,61,61,-20,-22,-25,61,61,-21,-24,61,]),'PLUS':([37,38,47,48,49,50,51,53,72,73,74,75,76,77,78,79,81,83,87,91,92,93,94,95,96,97,104,105,108,112,118,119,121,126,130,133,134,137,140,141,142,],[-52,62,-38,-51,-53,-54,-55,-57,62,62,62,62,62,62,62,-56,62,62,62,62,62,62,62,62,62,62,-37,-58,-26,62,62,62,62,-20,-22,-25,62,62,-21,-24,62,]),'MINUS':([37,38,47,48,49,50,51,53,72,73,74,75,76,77,78,79,81,83,87,91,92,93,94,95,96,97,104,105,108,112,118,119,121,126,130,133,134,137,140,141,142,],[-52,63,-38,-51,-53,-54,-55,-57,63,63,63,63,63,63,63,-56,63,63,63,63,63,63,63,63,63,63,-37,-58,-26,63,63,63,63,-20,-22,-25,63,63,-21,-24,63,]),'STAR':([37,38,47,48,49,50,51,53,72,73,74,75,76,77,78,79,81,83,87,91,92,93,94,95,96,97,104,105,108,112,118,119,121,126,130,133,134,137,140,141,142,],[-52,64,-38,-51,-53,-54,-55,-57,64,64,64,64,64,64,64,-56,64,64,64,64,64,64,64,64,64,64,-37,-58,-26,64,64,64,64,-20,-22,-25,64,64,-21,-24,64,]),'DIV':([37,38,47,48,49,50,51,53,72,73,74,75,76,77,78,79,81,83,87,91,92,93,94,95,96,97,104,105,108,112,118,119,121,126,130,133,134,137,140,141,142,],[-52,65,-38,-51,-53,-54,-55,-57,65,65,65,65,65,65,65,-56,65,65,65,65,65,65,65,65,65,65,-37,-58,-26,65,65,65,65,-20,-22,-25,65,65,-21,-24,65,]),'LESS':([37,38,47,48,49,50,51,53,72,73,74,75,76,77,78,79,81,83,87,91,92,93,94,95,96,97,104,105,108,112,118,119,121,126,130,133,134,137,140,141,142,],[-52,66,-38,-51,-53,-54,-55,-57,66,66,66,66,66,66,66,-56,66,66,66,66,66,66,66,66,66,66,-37,-58,-26,66,66,66,66,-20,-22,-25,66,66,-21,-24,66,]),'LESSEQ':([37,38,47,48,49,50,51,53,72,73,74,75,76,77,78,79,81,83,87,91,92,93,94,95,96,97,104,105,108,112,118,119,121,126,130,133,134,137,140,141,142,],[-52,67,-38,-51,-53,-54,-55,-57,67,67,67,67,67,67,67,-56,67,67,67,67,67,67,67,67,67,67,-37,-58,-26,67,67,67,67,-20,-22,-25,67,67,-21,-24,67,]),'EQUAL':([37,38,47,48,49,50,51,53,72,73,74,75,76,77,78,79,81,83,87,91,92,93,94,95,96,97,104,105,108,112,118,119,121,126,130,133,134,137,140,141,142,],[-52,68,-38,-51,-53,-54,-55,-57,68,68,68,68,68,68,68,-56,68,68,68,68,68,68,68,68,68,68,-37,-58,-26,68,68,68,68,-20,-22,-25,68,68,-21,-24,68,]),'OF':([37,47,48,49,50,51,53,72,76,77,78,79,83,91,92,93,94,95,96,97,104,105,108,112,126,130,133,140,141,],[-52,-38,-51,-53,-54,-55,-57,101,-34,-35,-36,-56,-23,-27,-28,-29,-30,-31,-32,-33,-37,-58,-26,-19,-20,-22,-25,-21,-24,]),'THEN':([37,47,48,49,50,51,53,73,76,77,78,79,83,91,92,93,94,95,96,97,104,105,108,112,126,130,133,140,141,],[-52,-38,-51,-53,-54,-55,-57,102,-34,-35,-36,-56,-23,-27,-28,-29,-30,-31,-32,-33,-37,-58,-26,-19,-20,-22,-25,-21,-24,]),'LOOP':([37,47,48,49,50,51,53,74,76,77,78,79,83,91,92,93,94,95,96,97,104,105,108,112,126,130,133,140,141,],[-52,-38,-51,-53,-54,-55,-57,103,-34,-35,-36,-56,-23,-27,-28,-29,-30,-31,-32,-33,-37,-58,-26,-19,-20,-22,-25,-21,-24,]),'ELSE':([37,47,48,49,50,51,53,76,77,78,79,83,91,92,93,94,95,96,97,104,105,108,112,118,126,130,133,140,141,],[-52,-38,-51,-53,-54,-55,-57,-34,-35,-36,-56,-23,-27,-28,-29,-30,-31,-32,-33,-37,-58,-26,-19,129,-20,-22,-25,-21,-24,]),'POOL':([37,47,48,49,50,51,53,76,77,78,79,83,91,92,93,94,95,96,97,104,105,108,112,119,126,130,133,140,141,],[-52,-38,-51,-53,-54,-55,-57,-34,-35,-36,-56,-23,-27,-28,-29,-30,-31,-32,-33,-37,-58,-26,-19,130,-20,-22,-25,-21,-24,]),'IN':([37,47,48,49,50,51,53,69,70,76,77,78,79,83,91,92,93,94,95,96,97,104,105,108,112,113,114,126,130,133,134,140,141,],[-52,-38,-51,-53,-54,-55,-57,98,-39,-34,-35,-36,-56,-23,-27,-28,-29,-30,-31,-32,-33,-37,-58,-26,-19,-40,-41,-20,-22,-25,-42,-21,-24,]),'FI':([37,47,48,49,50,51,53,76,77,78,79,83,91,92,93,94,95,96,97,104,105,108,112,126,130,133,137,140,141,],[-52,-38,-51,-53,-54,-55,-57,-34,-35,-36,-56,-23,-27,-28,-29,-30,-31,-32,-33,-37,-58,-26,-19,-20,-22,-25,140,-21,-24,]),'ESAC':([115,127,135,],[126,-43,-44,]),'ARROW':([136,],[139,]),} _lr_action = {} for _k, _v in _lr_action_items.items(): @@ -17,7 +17,7 @@ _lr_action[_x][_k] = _y del _lr_action_items -_lr_goto_items = {'program':([0,],[1,]),'class_list':([0,5,],[2,7,]),'def_class':([0,5,],[3,3,]),'feature_list':([8,17,18,21,],[10,22,23,31,]),'def_attr':([8,17,18,21,],[11,11,11,11,]),'def_func':([8,17,18,21,],[12,12,12,12,]),'epsilon':([8,17,18,20,21,58,110,131,],[13,13,13,30,13,87,87,87,]),'params':([20,],[26,]),'param_list':([20,35,],[27,56,]),'param_list_empty':([20,],[28,]),'param':([20,35,],[29,29,]),'expr':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,101,102,105,106,108,110,124,128,131,138,],[38,71,72,73,74,75,76,77,80,82,86,90,91,92,93,94,95,96,111,117,118,80,120,86,86,133,136,86,141,]),'atom':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,101,102,105,106,108,110,124,128,131,138,],[47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,]),'block':([32,40,41,42,43,44,45,46,53,57,58,61,62,63,64,65,66,67,97,101,102,105,106,108,110,124,128,131,138,],[52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,]),'let_attrs':([39,98,],[68,112,]),'def_var':([39,98,],[69,69,]),'block_list':([53,105,],[79,119,]),'args':([58,110,131,],[83,123,137,]),'arg_list':([58,108,110,131,],[84,121,84,84,]),'arg_list_empty':([58,110,131,],[85,85,85,]),'case_list':([100,126,],[114,134,]),'case_option':([100,126,],[115,115,]),} +_lr_goto_items = {'program':([0,],[1,]),'class_list':([0,5,],[2,7,]),'def_class':([0,5,],[3,3,]),'feature_list':([8,17,18,21,],[10,22,23,31,]),'def_attr':([8,17,18,21,],[11,11,11,11,]),'def_func':([8,17,18,21,],[12,12,12,12,]),'epsilon':([8,17,18,20,21,59,111,132,],[13,13,13,30,13,88,88,88,]),'params':([20,],[26,]),'param_list':([20,35,],[27,57,]),'param_list_empty':([20,],[28,]),'param':([20,35,],[29,29,]),'expr':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[38,72,73,74,75,76,77,78,81,83,87,91,92,93,94,95,96,97,112,118,119,81,121,87,87,134,137,87,142,]),'atom':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,]),'block':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,53,]),'let_attrs':([39,99,],[69,113,]),'def_var':([39,99,],[70,70,]),'block_list':([54,106,],[80,120,]),'args':([59,111,132,],[84,124,138,]),'arg_list':([59,109,111,132,],[85,122,85,85,]),'arg_list_empty':([59,111,132,],[86,86,86,]),'case_list':([101,127,],[115,135,]),'case_option':([101,127,],[116,116,]),} _lr_goto = {} for _k, _v in _lr_goto_items.items(): @@ -79,11 +79,12 @@ ('arg_list_empty -> epsilon','arg_list_empty',1,'p_arg_list_empty','parser.py',197), ('atom -> INT','atom',1,'p_atom_int','parser.py',201), ('atom -> ID','atom',1,'p_atom_id','parser.py',205), - ('atom -> BOOL','atom',1,'p_atom_bool','parser.py',209), - ('atom -> STRING','atom',1,'p_atom_string','parser.py',213), - ('atom -> NEW TYPE','atom',2,'p_atom_new','parser.py',217), - ('atom -> block','atom',1,'p_atom_block','parser.py',221), - ('block -> LBRACE block_list RBRACE','block',3,'p_block','parser.py',225), - ('block_list -> expr SEMICOLON','block_list',2,'p_block_list','parser.py',229), - ('block_list -> expr SEMICOLON block_list','block_list',3,'p_block_list','parser.py',230), + ('atom -> TRUE','atom',1,'p_atom_bool','parser.py',209), + ('atom -> FALSE','atom',1,'p_atom_bool','parser.py',210), + ('atom -> STRING','atom',1,'p_atom_string','parser.py',214), + ('atom -> NEW TYPE','atom',2,'p_atom_new','parser.py',218), + ('atom -> block','atom',1,'p_atom_block','parser.py',222), + ('block -> LBRACE block_list RBRACE','block',3,'p_block','parser.py',226), + ('block_list -> expr SEMICOLON','block_list',2,'p_block_list','parser.py',230), + ('block_list -> expr SEMICOLON block_list','block_list',3,'p_block_list','parser.py',231), ] diff --git a/src/utils/utils.py b/src/utils/utils.py index 965877820..57794461c 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -38,7 +38,9 @@ def __repr__(self): 'esac': 'ESAC', 'new': 'NEW', 'of': 'OF', - 'not': 'LNOT' + 'not': 'LNOT', + 'true': 'TRUE', + 'false': 'FALSE' } tokens = [ @@ -64,8 +66,7 @@ def __repr__(self): 'ARROW', 'INT', 'STRING', - 'NOT', - 'BOOL' + 'NOT' ] + list(reserved.values()) From 160707a70c5852274ff8429e42026cf24c7a873f Mon Sep 17 00:00:00 2001 From: cwjki Date: Mon, 21 Feb 2022 19:16:12 -0500 Subject: [PATCH 135/194] test if loop1 semantic works --- src/main.py | 2 +- src/semantic/visitors/typeChecker.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.py b/src/main.py index e33e3d8fb..260078477 100644 --- a/src/main.py +++ b/src/main.py @@ -66,7 +66,7 @@ def main(_input, _output): # ast, errors, context, scope = SemanticAn if __name__ == "__main__": - path = '/home/cwjki/Projects/cool-compiler-2021/tests/semantic/attributes4.cl' + path = '/home/cwjki/Projects/cool-compiler-2021/tests/semantic/loops1.cl' _input = sys.argv[1] if len(sys.argv) > 1 else path _output = sys.argv[2] if len(sys.argv) > 2 else None diff --git a/src/semantic/visitors/typeChecker.py b/src/semantic/visitors/typeChecker.py index c5283d25a..0fbff00fb 100644 --- a/src/semantic/visitors/typeChecker.py +++ b/src/semantic/visitors/typeChecker.py @@ -223,7 +223,7 @@ def visit(self, whileNode, scope): errorText = 'Loop condition does not have type Bool.' self.errors.append(TypexError( errorText, whileNode.line, whileNode.col)) - self.visit(whileNode.expr, scope) + self.visit(whileNode.body, scope) return ObjectType() @visitor.when(BlockNode) From 6e4293549c0c0498c97443626e0a4080b5f77248 Mon Sep 17 00:00:00 2001 From: cwjki Date: Mon, 21 Feb 2022 19:49:55 -0500 Subject: [PATCH 136/194] modificating precedence --- src/cparser/parser.py | 27 ++++++--- src/cparser/parsetab.py | 124 ++++++++++++++++++++-------------------- src/main.py | 2 +- 3 files changed, 82 insertions(+), 71 deletions(-) diff --git a/src/cparser/parser.py b/src/cparser/parser.py index 3fa65b651..84d85f7ff 100644 --- a/src/cparser/parser.py +++ b/src/cparser/parser.py @@ -11,14 +11,25 @@ def __init__(self, lexer): self.parser = yacc.yacc(start='program', module=self) self.errors = [] - procedence = ( - ('left, AT'), - ('left, NOT'), - ('left, ISVOID'), - ('left, EQUAL, LESS, LESSEQ'), - ('left, PLUS, MINUS'), - ('left, STAR, DIV'), - ('left, DOT') + # precedence = ( + # ('left, AT'), + # ('left, NOT'), + # ('left, ISVOID'), + # ('left, EQUAL, LESS, LESSEQ'), + # ('left, PLUS, MINUS'), + # ('left, STAR, DIV'), + # ('left, DOT') + # ) + + precedence = ( + ('right', 'ASSIGN'), + ('right', 'NOT'), + ('nonassoc', 'LESSEQ', 'LESS', 'EQUAL'), + ('left', 'PLUS', 'MINUS'), + ('left', 'STAR', 'DIV'), + ('right', 'ISVOID'), + ('left', 'AT'), + ('left', 'DOT') ) def parse(self, program): diff --git a/src/cparser/parsetab.py b/src/cparser/parsetab.py index 18a6f9fdb..f3846f64d 100644 --- a/src/cparser/parsetab.py +++ b/src/cparser/parsetab.py @@ -6,9 +6,9 @@ _lr_method = 'LALR' -_lr_signature = 'programARROW ASSIGN AT CASE CLASS COLON COMMA DIV DOT ELSE EQUAL ESAC FALSE FI ID IF IN INHERITS INT ISVOID LBRACE LESS LESSEQ LET LNOT LOOP LPAREN MINUS NEW NOT OF PLUS POOL RBRACE RPAREN SEMICOLON STAR STRING THEN TRUE TYPE WHILEprogram : class_listepsilon :class_list : def_class SEMICOLON class_list\n | def_class SEMICOLON def_class : CLASS TYPE LBRACE feature_list RBRACE\n | CLASS TYPE INHERITS TYPE LBRACE feature_list RBRACEfeature_list : def_attr SEMICOLON feature_list\n | def_func SEMICOLON feature_list\n | epsilondef_attr : ID COLON TYPE\n | ID COLON TYPE ASSIGN exprdef_func : ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACEparams : param_list\n | param_list_emptyparam_list : param\n | param COMMA param_listparam_list_empty : epsilonparam : ID COLON TYPEexpr : LET let_attrs IN expr\n | CASE expr OF case_list ESAC\n | IF expr THEN expr ELSE expr FI\n | WHILE expr LOOP expr POOLexpr : ID ASSIGN exprexpr : expr AT TYPE DOT ID LPAREN args RPAREN\n | expr DOT ID LPAREN args RPAREN\n | ID LPAREN args RPARENexpr : expr PLUS expr\n | expr MINUS expr\n | expr STAR expr\n | expr DIV expr\n | expr LESS expr\n | expr LESSEQ expr\n | expr EQUAL exprexpr : NOT expr\n | ISVOID expr\n | LNOT exprexpr : LPAREN expr RPARENexpr : atomlet_attrs : def_var\n | def_var COMMA let_attrsdef_var : ID COLON TYPE\n | ID COLON TYPE ASSIGN exprcase_list : case_option SEMICOLON\n | case_option SEMICOLON case_listcase_option : ID COLON TYPE ARROW exprargs : arg_list\n | arg_list_emptyarg_list : expr\n | expr COMMA arg_listarg_list_empty : epsilonatom : INTatom : IDatom : TRUE\n | FALSEatom : STRINGatom : NEW TYPEatom : blockblock : LBRACE block_list RBRACE block_list : expr SEMICOLON\n | expr SEMICOLON block_list' +_lr_signature = 'programrightASSIGNrightNOTnonassocLESSEQLESSEQUALleftPLUSMINUSleftSTARDIVrightISVOIDleftATleftDOTARROW ASSIGN AT CASE CLASS COLON COMMA DIV DOT ELSE EQUAL ESAC FALSE FI ID IF IN INHERITS INT ISVOID LBRACE LESS LESSEQ LET LNOT LOOP LPAREN MINUS NEW NOT OF PLUS POOL RBRACE RPAREN SEMICOLON STAR STRING THEN TRUE TYPE WHILEprogram : class_listepsilon :class_list : def_class SEMICOLON class_list\n | def_class SEMICOLON def_class : CLASS TYPE LBRACE feature_list RBRACE\n | CLASS TYPE INHERITS TYPE LBRACE feature_list RBRACEfeature_list : def_attr SEMICOLON feature_list\n | def_func SEMICOLON feature_list\n | epsilondef_attr : ID COLON TYPE\n | ID COLON TYPE ASSIGN exprdef_func : ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACEparams : param_list\n | param_list_emptyparam_list : param\n | param COMMA param_listparam_list_empty : epsilonparam : ID COLON TYPEexpr : LET let_attrs IN expr\n | CASE expr OF case_list ESAC\n | IF expr THEN expr ELSE expr FI\n | WHILE expr LOOP expr POOLexpr : ID ASSIGN exprexpr : expr AT TYPE DOT ID LPAREN args RPAREN\n | expr DOT ID LPAREN args RPAREN\n | ID LPAREN args RPARENexpr : expr PLUS expr\n | expr MINUS expr\n | expr STAR expr\n | expr DIV expr\n | expr LESS expr\n | expr LESSEQ expr\n | expr EQUAL exprexpr : NOT expr\n | ISVOID expr\n | LNOT exprexpr : LPAREN expr RPARENexpr : atomlet_attrs : def_var\n | def_var COMMA let_attrsdef_var : ID COLON TYPE\n | ID COLON TYPE ASSIGN exprcase_list : case_option SEMICOLON\n | case_option SEMICOLON case_listcase_option : ID COLON TYPE ARROW exprargs : arg_list\n | arg_list_emptyarg_list : expr\n | expr COMMA arg_listarg_list_empty : epsilonatom : INTatom : IDatom : TRUE\n | FALSEatom : STRINGatom : NEW TYPEatom : blockblock : LBRACE block_list RBRACE block_list : expr SEMICOLON\n | expr SEMICOLON block_list' -_lr_action_items = {'CLASS':([0,5,],[4,4,]),'$end':([1,2,5,7,],[0,-1,-4,-3,]),'SEMICOLON':([3,11,12,16,24,36,37,38,47,48,49,50,51,53,76,77,78,79,81,83,91,92,93,94,95,96,97,104,105,108,112,116,126,130,131,133,140,141,142,],[5,17,18,-5,-10,-6,-52,-11,-38,-51,-53,-54,-55,-57,-34,-35,-36,-56,106,-23,-27,-28,-29,-30,-31,-32,-33,-37,-58,-26,-19,127,-20,-22,-12,-25,-21,-24,-45,]),'TYPE':([4,9,19,33,52,56,60,100,128,],[6,15,24,55,79,82,89,114,136,]),'LBRACE':([6,15,32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,82,98,102,103,106,107,109,111,125,129,132,139,],[8,21,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,107,54,54,54,54,54,54,54,54,54,54,54,]),'INHERITS':([6,],[9,]),'ID':([8,17,18,20,21,32,35,39,40,41,42,43,44,45,46,54,58,59,61,62,63,64,65,66,67,68,98,99,101,102,103,106,107,109,110,111,125,127,129,132,139,],[14,14,14,25,14,37,25,71,37,37,37,37,37,37,37,37,37,37,90,37,37,37,37,37,37,37,37,71,117,37,37,37,37,37,123,37,37,117,37,37,37,]),'RBRACE':([8,10,13,17,18,21,22,23,31,37,47,48,49,50,51,53,76,77,78,79,80,83,91,92,93,94,95,96,97,104,105,106,108,112,120,121,126,130,133,140,141,],[-2,16,-9,-2,-2,-2,-7,-8,36,-52,-38,-51,-53,-54,-55,-57,-34,-35,-36,-56,105,-23,-27,-28,-29,-30,-31,-32,-33,-37,-58,-59,-26,-19,-60,131,-20,-22,-25,-21,-24,]),'COLON':([14,25,34,71,117,],[19,33,56,100,128,]),'LPAREN':([14,32,37,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,90,98,102,103,106,107,109,111,123,125,129,132,139,],[20,43,59,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,111,43,43,43,43,43,43,43,132,43,43,43,43,]),'RPAREN':([20,26,27,28,29,30,37,47,48,49,50,51,53,55,57,59,75,76,77,78,79,83,84,85,86,87,88,91,92,93,94,95,96,97,104,105,108,111,112,122,124,126,130,132,133,138,140,141,],[-2,34,-13,-14,-15,-17,-52,-38,-51,-53,-54,-55,-57,-18,-16,-2,104,-34,-35,-36,-56,-23,108,-46,-47,-48,-50,-27,-28,-29,-30,-31,-32,-33,-37,-58,-26,-2,-19,-49,133,-20,-22,-2,-25,141,-21,-24,]),'ASSIGN':([24,37,114,],[32,58,125,]),'COMMA':([29,37,47,48,49,50,51,53,55,70,76,77,78,79,83,87,91,92,93,94,95,96,97,104,105,108,112,114,126,130,133,134,140,141,],[35,-52,-38,-51,-53,-54,-55,-57,-18,99,-34,-35,-36,-56,-23,109,-27,-28,-29,-30,-31,-32,-33,-37,-58,-26,-19,-41,-20,-22,-25,-42,-21,-24,]),'LET':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,]),'CASE':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,]),'IF':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,]),'WHILE':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,]),'NOT':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,]),'ISVOID':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,]),'LNOT':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,]),'INT':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,]),'TRUE':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,]),'FALSE':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,]),'STRING':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,]),'NEW':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,]),'AT':([37,38,47,48,49,50,51,53,72,73,74,75,76,77,78,79,81,83,87,91,92,93,94,95,96,97,104,105,108,112,118,119,121,126,130,133,134,137,140,141,142,],[-52,60,-38,-51,-53,-54,-55,-57,60,60,60,60,60,60,60,-56,60,60,60,60,60,60,60,60,60,60,-37,-58,-26,60,60,60,60,-20,-22,-25,60,60,-21,-24,60,]),'DOT':([37,38,47,48,49,50,51,53,72,73,74,75,76,77,78,79,81,83,87,89,91,92,93,94,95,96,97,104,105,108,112,118,119,121,126,130,133,134,137,140,141,142,],[-52,61,-38,-51,-53,-54,-55,-57,61,61,61,61,61,61,61,-56,61,61,61,110,61,61,61,61,61,61,61,-37,-58,-26,61,61,61,61,-20,-22,-25,61,61,-21,-24,61,]),'PLUS':([37,38,47,48,49,50,51,53,72,73,74,75,76,77,78,79,81,83,87,91,92,93,94,95,96,97,104,105,108,112,118,119,121,126,130,133,134,137,140,141,142,],[-52,62,-38,-51,-53,-54,-55,-57,62,62,62,62,62,62,62,-56,62,62,62,62,62,62,62,62,62,62,-37,-58,-26,62,62,62,62,-20,-22,-25,62,62,-21,-24,62,]),'MINUS':([37,38,47,48,49,50,51,53,72,73,74,75,76,77,78,79,81,83,87,91,92,93,94,95,96,97,104,105,108,112,118,119,121,126,130,133,134,137,140,141,142,],[-52,63,-38,-51,-53,-54,-55,-57,63,63,63,63,63,63,63,-56,63,63,63,63,63,63,63,63,63,63,-37,-58,-26,63,63,63,63,-20,-22,-25,63,63,-21,-24,63,]),'STAR':([37,38,47,48,49,50,51,53,72,73,74,75,76,77,78,79,81,83,87,91,92,93,94,95,96,97,104,105,108,112,118,119,121,126,130,133,134,137,140,141,142,],[-52,64,-38,-51,-53,-54,-55,-57,64,64,64,64,64,64,64,-56,64,64,64,64,64,64,64,64,64,64,-37,-58,-26,64,64,64,64,-20,-22,-25,64,64,-21,-24,64,]),'DIV':([37,38,47,48,49,50,51,53,72,73,74,75,76,77,78,79,81,83,87,91,92,93,94,95,96,97,104,105,108,112,118,119,121,126,130,133,134,137,140,141,142,],[-52,65,-38,-51,-53,-54,-55,-57,65,65,65,65,65,65,65,-56,65,65,65,65,65,65,65,65,65,65,-37,-58,-26,65,65,65,65,-20,-22,-25,65,65,-21,-24,65,]),'LESS':([37,38,47,48,49,50,51,53,72,73,74,75,76,77,78,79,81,83,87,91,92,93,94,95,96,97,104,105,108,112,118,119,121,126,130,133,134,137,140,141,142,],[-52,66,-38,-51,-53,-54,-55,-57,66,66,66,66,66,66,66,-56,66,66,66,66,66,66,66,66,66,66,-37,-58,-26,66,66,66,66,-20,-22,-25,66,66,-21,-24,66,]),'LESSEQ':([37,38,47,48,49,50,51,53,72,73,74,75,76,77,78,79,81,83,87,91,92,93,94,95,96,97,104,105,108,112,118,119,121,126,130,133,134,137,140,141,142,],[-52,67,-38,-51,-53,-54,-55,-57,67,67,67,67,67,67,67,-56,67,67,67,67,67,67,67,67,67,67,-37,-58,-26,67,67,67,67,-20,-22,-25,67,67,-21,-24,67,]),'EQUAL':([37,38,47,48,49,50,51,53,72,73,74,75,76,77,78,79,81,83,87,91,92,93,94,95,96,97,104,105,108,112,118,119,121,126,130,133,134,137,140,141,142,],[-52,68,-38,-51,-53,-54,-55,-57,68,68,68,68,68,68,68,-56,68,68,68,68,68,68,68,68,68,68,-37,-58,-26,68,68,68,68,-20,-22,-25,68,68,-21,-24,68,]),'OF':([37,47,48,49,50,51,53,72,76,77,78,79,83,91,92,93,94,95,96,97,104,105,108,112,126,130,133,140,141,],[-52,-38,-51,-53,-54,-55,-57,101,-34,-35,-36,-56,-23,-27,-28,-29,-30,-31,-32,-33,-37,-58,-26,-19,-20,-22,-25,-21,-24,]),'THEN':([37,47,48,49,50,51,53,73,76,77,78,79,83,91,92,93,94,95,96,97,104,105,108,112,126,130,133,140,141,],[-52,-38,-51,-53,-54,-55,-57,102,-34,-35,-36,-56,-23,-27,-28,-29,-30,-31,-32,-33,-37,-58,-26,-19,-20,-22,-25,-21,-24,]),'LOOP':([37,47,48,49,50,51,53,74,76,77,78,79,83,91,92,93,94,95,96,97,104,105,108,112,126,130,133,140,141,],[-52,-38,-51,-53,-54,-55,-57,103,-34,-35,-36,-56,-23,-27,-28,-29,-30,-31,-32,-33,-37,-58,-26,-19,-20,-22,-25,-21,-24,]),'ELSE':([37,47,48,49,50,51,53,76,77,78,79,83,91,92,93,94,95,96,97,104,105,108,112,118,126,130,133,140,141,],[-52,-38,-51,-53,-54,-55,-57,-34,-35,-36,-56,-23,-27,-28,-29,-30,-31,-32,-33,-37,-58,-26,-19,129,-20,-22,-25,-21,-24,]),'POOL':([37,47,48,49,50,51,53,76,77,78,79,83,91,92,93,94,95,96,97,104,105,108,112,119,126,130,133,140,141,],[-52,-38,-51,-53,-54,-55,-57,-34,-35,-36,-56,-23,-27,-28,-29,-30,-31,-32,-33,-37,-58,-26,-19,130,-20,-22,-25,-21,-24,]),'IN':([37,47,48,49,50,51,53,69,70,76,77,78,79,83,91,92,93,94,95,96,97,104,105,108,112,113,114,126,130,133,134,140,141,],[-52,-38,-51,-53,-54,-55,-57,98,-39,-34,-35,-36,-56,-23,-27,-28,-29,-30,-31,-32,-33,-37,-58,-26,-19,-40,-41,-20,-22,-25,-42,-21,-24,]),'FI':([37,47,48,49,50,51,53,76,77,78,79,83,91,92,93,94,95,96,97,104,105,108,112,126,130,133,137,140,141,],[-52,-38,-51,-53,-54,-55,-57,-34,-35,-36,-56,-23,-27,-28,-29,-30,-31,-32,-33,-37,-58,-26,-19,-20,-22,-25,140,-21,-24,]),'ESAC':([115,127,135,],[126,-43,-44,]),'ARROW':([136,],[139,]),} +_lr_action_items = {'CLASS':([0,5,],[4,4,]),'$end':([1,2,5,7,],[0,-1,-4,-3,]),'SEMICOLON':([3,11,12,16,24,36,37,38,47,48,49,50,51,53,76,77,78,79,81,83,91,92,93,94,95,96,97,104,105,108,112,116,126,130,131,133,140,141,142,],[5,17,18,-5,-10,-6,-52,-11,-38,-51,-53,-54,-55,-57,-34,-35,-36,-56,106,-23,-27,-28,-29,-30,-31,-32,-33,-37,-58,-26,-19,127,-20,-22,-12,-25,-21,-24,-45,]),'TYPE':([4,9,19,33,52,56,60,100,128,],[6,15,24,55,79,82,89,114,136,]),'LBRACE':([6,15,32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,82,98,102,103,106,107,109,111,125,129,132,139,],[8,21,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,107,54,54,54,54,54,54,54,54,54,54,54,]),'INHERITS':([6,],[9,]),'ID':([8,17,18,20,21,32,35,39,40,41,42,43,44,45,46,54,58,59,61,62,63,64,65,66,67,68,98,99,101,102,103,106,107,109,110,111,125,127,129,132,139,],[14,14,14,25,14,37,25,71,37,37,37,37,37,37,37,37,37,37,90,37,37,37,37,37,37,37,37,71,117,37,37,37,37,37,123,37,37,117,37,37,37,]),'RBRACE':([8,10,13,17,18,21,22,23,31,37,47,48,49,50,51,53,76,77,78,79,80,83,91,92,93,94,95,96,97,104,105,106,108,112,120,121,126,130,133,140,141,],[-2,16,-9,-2,-2,-2,-7,-8,36,-52,-38,-51,-53,-54,-55,-57,-34,-35,-36,-56,105,-23,-27,-28,-29,-30,-31,-32,-33,-37,-58,-59,-26,-19,-60,131,-20,-22,-25,-21,-24,]),'COLON':([14,25,34,71,117,],[19,33,56,100,128,]),'LPAREN':([14,32,37,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,90,98,102,103,106,107,109,111,123,125,129,132,139,],[20,43,59,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,43,111,43,43,43,43,43,43,43,132,43,43,43,43,]),'RPAREN':([20,26,27,28,29,30,37,47,48,49,50,51,53,55,57,59,75,76,77,78,79,83,84,85,86,87,88,91,92,93,94,95,96,97,104,105,108,111,112,122,124,126,130,132,133,138,140,141,],[-2,34,-13,-14,-15,-17,-52,-38,-51,-53,-54,-55,-57,-18,-16,-2,104,-34,-35,-36,-56,-23,108,-46,-47,-48,-50,-27,-28,-29,-30,-31,-32,-33,-37,-58,-26,-2,-19,-49,133,-20,-22,-2,-25,141,-21,-24,]),'ASSIGN':([24,37,114,],[32,58,125,]),'COMMA':([29,37,47,48,49,50,51,53,55,70,76,77,78,79,83,87,91,92,93,94,95,96,97,104,105,108,112,114,126,130,133,134,140,141,],[35,-52,-38,-51,-53,-54,-55,-57,-18,99,-34,-35,-36,-56,-23,109,-27,-28,-29,-30,-31,-32,-33,-37,-58,-26,-19,-41,-20,-22,-25,-42,-21,-24,]),'LET':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,]),'CASE':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,]),'IF':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,]),'WHILE':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,42,]),'NOT':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,]),'ISVOID':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,]),'LNOT':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,]),'INT':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,48,]),'TRUE':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,]),'FALSE':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,]),'STRING':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,51,]),'NEW':([32,40,41,42,43,44,45,46,54,58,59,62,63,64,65,66,67,68,98,102,103,106,107,109,111,125,129,132,139,],[52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,]),'AT':([37,38,47,48,49,50,51,53,72,73,74,75,76,77,78,79,81,83,87,91,92,93,94,95,96,97,104,105,108,112,118,119,121,126,130,133,134,137,140,141,142,],[-52,60,-38,-51,-53,-54,-55,-57,60,60,60,60,60,60,60,-56,60,60,60,60,60,60,60,60,60,60,-37,-58,-26,60,60,60,60,-20,-22,-25,60,60,-21,-24,60,]),'DOT':([37,38,47,48,49,50,51,53,72,73,74,75,76,77,78,79,81,83,87,89,91,92,93,94,95,96,97,104,105,108,112,118,119,121,126,130,133,134,137,140,141,142,],[-52,61,-38,-51,-53,-54,-55,-57,61,61,61,61,61,61,61,-56,61,61,61,110,61,61,61,61,61,61,61,-37,-58,-26,61,61,61,61,-20,-22,-25,61,61,-21,-24,61,]),'PLUS':([37,38,47,48,49,50,51,53,72,73,74,75,76,77,78,79,81,83,87,91,92,93,94,95,96,97,104,105,108,112,118,119,121,126,130,133,134,137,140,141,142,],[-52,62,-38,-51,-53,-54,-55,-57,62,62,62,62,62,-35,62,-56,62,62,62,-27,-28,-29,-30,62,62,62,-37,-58,-26,62,62,62,62,-20,-22,-25,62,62,-21,-24,62,]),'MINUS':([37,38,47,48,49,50,51,53,72,73,74,75,76,77,78,79,81,83,87,91,92,93,94,95,96,97,104,105,108,112,118,119,121,126,130,133,134,137,140,141,142,],[-52,63,-38,-51,-53,-54,-55,-57,63,63,63,63,63,-35,63,-56,63,63,63,-27,-28,-29,-30,63,63,63,-37,-58,-26,63,63,63,63,-20,-22,-25,63,63,-21,-24,63,]),'STAR':([37,38,47,48,49,50,51,53,72,73,74,75,76,77,78,79,81,83,87,91,92,93,94,95,96,97,104,105,108,112,118,119,121,126,130,133,134,137,140,141,142,],[-52,64,-38,-51,-53,-54,-55,-57,64,64,64,64,64,-35,64,-56,64,64,64,64,64,-29,-30,64,64,64,-37,-58,-26,64,64,64,64,-20,-22,-25,64,64,-21,-24,64,]),'DIV':([37,38,47,48,49,50,51,53,72,73,74,75,76,77,78,79,81,83,87,91,92,93,94,95,96,97,104,105,108,112,118,119,121,126,130,133,134,137,140,141,142,],[-52,65,-38,-51,-53,-54,-55,-57,65,65,65,65,65,-35,65,-56,65,65,65,65,65,-29,-30,65,65,65,-37,-58,-26,65,65,65,65,-20,-22,-25,65,65,-21,-24,65,]),'LESS':([37,38,47,48,49,50,51,53,72,73,74,75,76,77,78,79,81,83,87,91,92,93,94,95,96,97,104,105,108,112,118,119,121,126,130,133,134,137,140,141,142,],[-52,66,-38,-51,-53,-54,-55,-57,66,66,66,66,66,-35,66,-56,66,66,66,-27,-28,-29,-30,None,None,None,-37,-58,-26,66,66,66,66,-20,-22,-25,66,66,-21,-24,66,]),'LESSEQ':([37,38,47,48,49,50,51,53,72,73,74,75,76,77,78,79,81,83,87,91,92,93,94,95,96,97,104,105,108,112,118,119,121,126,130,133,134,137,140,141,142,],[-52,67,-38,-51,-53,-54,-55,-57,67,67,67,67,67,-35,67,-56,67,67,67,-27,-28,-29,-30,None,None,None,-37,-58,-26,67,67,67,67,-20,-22,-25,67,67,-21,-24,67,]),'EQUAL':([37,38,47,48,49,50,51,53,72,73,74,75,76,77,78,79,81,83,87,91,92,93,94,95,96,97,104,105,108,112,118,119,121,126,130,133,134,137,140,141,142,],[-52,68,-38,-51,-53,-54,-55,-57,68,68,68,68,68,-35,68,-56,68,68,68,-27,-28,-29,-30,None,None,None,-37,-58,-26,68,68,68,68,-20,-22,-25,68,68,-21,-24,68,]),'OF':([37,47,48,49,50,51,53,72,76,77,78,79,83,91,92,93,94,95,96,97,104,105,108,112,126,130,133,140,141,],[-52,-38,-51,-53,-54,-55,-57,101,-34,-35,-36,-56,-23,-27,-28,-29,-30,-31,-32,-33,-37,-58,-26,-19,-20,-22,-25,-21,-24,]),'THEN':([37,47,48,49,50,51,53,73,76,77,78,79,83,91,92,93,94,95,96,97,104,105,108,112,126,130,133,140,141,],[-52,-38,-51,-53,-54,-55,-57,102,-34,-35,-36,-56,-23,-27,-28,-29,-30,-31,-32,-33,-37,-58,-26,-19,-20,-22,-25,-21,-24,]),'LOOP':([37,47,48,49,50,51,53,74,76,77,78,79,83,91,92,93,94,95,96,97,104,105,108,112,126,130,133,140,141,],[-52,-38,-51,-53,-54,-55,-57,103,-34,-35,-36,-56,-23,-27,-28,-29,-30,-31,-32,-33,-37,-58,-26,-19,-20,-22,-25,-21,-24,]),'ELSE':([37,47,48,49,50,51,53,76,77,78,79,83,91,92,93,94,95,96,97,104,105,108,112,118,126,130,133,140,141,],[-52,-38,-51,-53,-54,-55,-57,-34,-35,-36,-56,-23,-27,-28,-29,-30,-31,-32,-33,-37,-58,-26,-19,129,-20,-22,-25,-21,-24,]),'POOL':([37,47,48,49,50,51,53,76,77,78,79,83,91,92,93,94,95,96,97,104,105,108,112,119,126,130,133,140,141,],[-52,-38,-51,-53,-54,-55,-57,-34,-35,-36,-56,-23,-27,-28,-29,-30,-31,-32,-33,-37,-58,-26,-19,130,-20,-22,-25,-21,-24,]),'IN':([37,47,48,49,50,51,53,69,70,76,77,78,79,83,91,92,93,94,95,96,97,104,105,108,112,113,114,126,130,133,134,140,141,],[-52,-38,-51,-53,-54,-55,-57,98,-39,-34,-35,-36,-56,-23,-27,-28,-29,-30,-31,-32,-33,-37,-58,-26,-19,-40,-41,-20,-22,-25,-42,-21,-24,]),'FI':([37,47,48,49,50,51,53,76,77,78,79,83,91,92,93,94,95,96,97,104,105,108,112,126,130,133,137,140,141,],[-52,-38,-51,-53,-54,-55,-57,-34,-35,-36,-56,-23,-27,-28,-29,-30,-31,-32,-33,-37,-58,-26,-19,-20,-22,-25,140,-21,-24,]),'ESAC':([115,127,135,],[126,-43,-44,]),'ARROW':([136,],[139,]),} _lr_action = {} for _k, _v in _lr_action_items.items(): @@ -27,64 +27,64 @@ del _lr_goto_items _lr_productions = [ ("S' -> program","S'",1,None,None,None), - ('program -> class_list','program',1,'p_program','parser.py',28), - ('epsilon -> ','epsilon',0,'p_epsilon','parser.py',32), - ('class_list -> def_class SEMICOLON class_list','class_list',3,'p_class_list','parser.py',36), - ('class_list -> def_class SEMICOLON','class_list',2,'p_class_list','parser.py',37), - ('def_class -> CLASS TYPE LBRACE feature_list RBRACE','def_class',5,'p_def_class','parser.py',41), - ('def_class -> CLASS TYPE INHERITS TYPE LBRACE feature_list RBRACE','def_class',7,'p_def_class','parser.py',42), - ('feature_list -> def_attr SEMICOLON feature_list','feature_list',3,'p_feature_list','parser.py',49), - ('feature_list -> def_func SEMICOLON feature_list','feature_list',3,'p_feature_list','parser.py',50), - ('feature_list -> epsilon','feature_list',1,'p_feature_list','parser.py',51), - ('def_attr -> ID COLON TYPE','def_attr',3,'p_def_attr','parser.py',55), - ('def_attr -> ID COLON TYPE ASSIGN expr','def_attr',5,'p_def_attr','parser.py',56), - ('def_func -> ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACE','def_func',9,'p_def_func','parser.py',63), - ('params -> param_list','params',1,'p_params','parser.py',67), - ('params -> param_list_empty','params',1,'p_params','parser.py',68), - ('param_list -> param','param_list',1,'p_param_list','parser.py',72), - ('param_list -> param COMMA param_list','param_list',3,'p_param_list','parser.py',73), - ('param_list_empty -> epsilon','param_list_empty',1,'p_param_list_empty','parser.py',77), - ('param -> ID COLON TYPE','param',3,'p_param','parser.py',81), - ('expr -> LET let_attrs IN expr','expr',4,'p_expr_flow','parser.py',85), - ('expr -> CASE expr OF case_list ESAC','expr',5,'p_expr_flow','parser.py',86), - ('expr -> IF expr THEN expr ELSE expr FI','expr',7,'p_expr_flow','parser.py',87), - ('expr -> WHILE expr LOOP expr POOL','expr',5,'p_expr_flow','parser.py',88), - ('expr -> ID ASSIGN expr','expr',3,'p_expr_assign','parser.py',100), - ('expr -> expr AT TYPE DOT ID LPAREN args RPAREN','expr',8,'p_expr_func_call','parser.py',104), - ('expr -> expr DOT ID LPAREN args RPAREN','expr',6,'p_expr_func_call','parser.py',105), - ('expr -> ID LPAREN args RPAREN','expr',4,'p_expr_func_call','parser.py',106), - ('expr -> expr PLUS expr','expr',3,'p_expr_operators_binary','parser.py',123), - ('expr -> expr MINUS expr','expr',3,'p_expr_operators_binary','parser.py',124), - ('expr -> expr STAR expr','expr',3,'p_expr_operators_binary','parser.py',125), - ('expr -> expr DIV expr','expr',3,'p_expr_operators_binary','parser.py',126), - ('expr -> expr LESS expr','expr',3,'p_expr_operators_binary','parser.py',127), - ('expr -> expr LESSEQ expr','expr',3,'p_expr_operators_binary','parser.py',128), - ('expr -> expr EQUAL expr','expr',3,'p_expr_operators_binary','parser.py',129), - ('expr -> NOT expr','expr',2,'p_expr_operators_unary','parser.py',146), - ('expr -> ISVOID expr','expr',2,'p_expr_operators_unary','parser.py',147), - ('expr -> LNOT expr','expr',2,'p_expr_operators_unary','parser.py',148), - ('expr -> LPAREN expr RPAREN','expr',3,'p_expr_group','parser.py',157), - ('expr -> atom','expr',1,'p_expr_atom','parser.py',161), - ('let_attrs -> def_var','let_attrs',1,'p_let_attrs','parser.py',165), - ('let_attrs -> def_var COMMA let_attrs','let_attrs',3,'p_let_attrs','parser.py',166), - ('def_var -> ID COLON TYPE','def_var',3,'p_def_var','parser.py',170), - ('def_var -> ID COLON TYPE ASSIGN expr','def_var',5,'p_def_var','parser.py',171), - ('case_list -> case_option SEMICOLON','case_list',2,'p_case_list','parser.py',178), - ('case_list -> case_option SEMICOLON case_list','case_list',3,'p_case_list','parser.py',179), - ('case_option -> ID COLON TYPE ARROW expr','case_option',5,'p_case_option','parser.py',183), - ('args -> arg_list','args',1,'p_args','parser.py',187), - ('args -> arg_list_empty','args',1,'p_args','parser.py',188), - ('arg_list -> expr','arg_list',1,'p_arg_list','parser.py',192), - ('arg_list -> expr COMMA arg_list','arg_list',3,'p_arg_list','parser.py',193), - ('arg_list_empty -> epsilon','arg_list_empty',1,'p_arg_list_empty','parser.py',197), - ('atom -> INT','atom',1,'p_atom_int','parser.py',201), - ('atom -> ID','atom',1,'p_atom_id','parser.py',205), - ('atom -> TRUE','atom',1,'p_atom_bool','parser.py',209), - ('atom -> FALSE','atom',1,'p_atom_bool','parser.py',210), - ('atom -> STRING','atom',1,'p_atom_string','parser.py',214), - ('atom -> NEW TYPE','atom',2,'p_atom_new','parser.py',218), - ('atom -> block','atom',1,'p_atom_block','parser.py',222), - ('block -> LBRACE block_list RBRACE','block',3,'p_block','parser.py',226), - ('block_list -> expr SEMICOLON','block_list',2,'p_block_list','parser.py',230), - ('block_list -> expr SEMICOLON block_list','block_list',3,'p_block_list','parser.py',231), + ('program -> class_list','program',1,'p_program','parser.py',39), + ('epsilon -> ','epsilon',0,'p_epsilon','parser.py',43), + ('class_list -> def_class SEMICOLON class_list','class_list',3,'p_class_list','parser.py',47), + ('class_list -> def_class SEMICOLON','class_list',2,'p_class_list','parser.py',48), + ('def_class -> CLASS TYPE LBRACE feature_list RBRACE','def_class',5,'p_def_class','parser.py',52), + ('def_class -> CLASS TYPE INHERITS TYPE LBRACE feature_list RBRACE','def_class',7,'p_def_class','parser.py',53), + ('feature_list -> def_attr SEMICOLON feature_list','feature_list',3,'p_feature_list','parser.py',60), + ('feature_list -> def_func SEMICOLON feature_list','feature_list',3,'p_feature_list','parser.py',61), + ('feature_list -> epsilon','feature_list',1,'p_feature_list','parser.py',62), + ('def_attr -> ID COLON TYPE','def_attr',3,'p_def_attr','parser.py',66), + ('def_attr -> ID COLON TYPE ASSIGN expr','def_attr',5,'p_def_attr','parser.py',67), + ('def_func -> ID LPAREN params RPAREN COLON TYPE LBRACE expr RBRACE','def_func',9,'p_def_func','parser.py',74), + ('params -> param_list','params',1,'p_params','parser.py',78), + ('params -> param_list_empty','params',1,'p_params','parser.py',79), + ('param_list -> param','param_list',1,'p_param_list','parser.py',83), + ('param_list -> param COMMA param_list','param_list',3,'p_param_list','parser.py',84), + ('param_list_empty -> epsilon','param_list_empty',1,'p_param_list_empty','parser.py',88), + ('param -> ID COLON TYPE','param',3,'p_param','parser.py',92), + ('expr -> LET let_attrs IN expr','expr',4,'p_expr_flow','parser.py',96), + ('expr -> CASE expr OF case_list ESAC','expr',5,'p_expr_flow','parser.py',97), + ('expr -> IF expr THEN expr ELSE expr FI','expr',7,'p_expr_flow','parser.py',98), + ('expr -> WHILE expr LOOP expr POOL','expr',5,'p_expr_flow','parser.py',99), + ('expr -> ID ASSIGN expr','expr',3,'p_expr_assign','parser.py',111), + ('expr -> expr AT TYPE DOT ID LPAREN args RPAREN','expr',8,'p_expr_func_call','parser.py',115), + ('expr -> expr DOT ID LPAREN args RPAREN','expr',6,'p_expr_func_call','parser.py',116), + ('expr -> ID LPAREN args RPAREN','expr',4,'p_expr_func_call','parser.py',117), + ('expr -> expr PLUS expr','expr',3,'p_expr_operators_binary','parser.py',134), + ('expr -> expr MINUS expr','expr',3,'p_expr_operators_binary','parser.py',135), + ('expr -> expr STAR expr','expr',3,'p_expr_operators_binary','parser.py',136), + ('expr -> expr DIV expr','expr',3,'p_expr_operators_binary','parser.py',137), + ('expr -> expr LESS expr','expr',3,'p_expr_operators_binary','parser.py',138), + ('expr -> expr LESSEQ expr','expr',3,'p_expr_operators_binary','parser.py',139), + ('expr -> expr EQUAL expr','expr',3,'p_expr_operators_binary','parser.py',140), + ('expr -> NOT expr','expr',2,'p_expr_operators_unary','parser.py',157), + ('expr -> ISVOID expr','expr',2,'p_expr_operators_unary','parser.py',158), + ('expr -> LNOT expr','expr',2,'p_expr_operators_unary','parser.py',159), + ('expr -> LPAREN expr RPAREN','expr',3,'p_expr_group','parser.py',168), + ('expr -> atom','expr',1,'p_expr_atom','parser.py',172), + ('let_attrs -> def_var','let_attrs',1,'p_let_attrs','parser.py',176), + ('let_attrs -> def_var COMMA let_attrs','let_attrs',3,'p_let_attrs','parser.py',177), + ('def_var -> ID COLON TYPE','def_var',3,'p_def_var','parser.py',181), + ('def_var -> ID COLON TYPE ASSIGN expr','def_var',5,'p_def_var','parser.py',182), + ('case_list -> case_option SEMICOLON','case_list',2,'p_case_list','parser.py',189), + ('case_list -> case_option SEMICOLON case_list','case_list',3,'p_case_list','parser.py',190), + ('case_option -> ID COLON TYPE ARROW expr','case_option',5,'p_case_option','parser.py',194), + ('args -> arg_list','args',1,'p_args','parser.py',198), + ('args -> arg_list_empty','args',1,'p_args','parser.py',199), + ('arg_list -> expr','arg_list',1,'p_arg_list','parser.py',203), + ('arg_list -> expr COMMA arg_list','arg_list',3,'p_arg_list','parser.py',204), + ('arg_list_empty -> epsilon','arg_list_empty',1,'p_arg_list_empty','parser.py',208), + ('atom -> INT','atom',1,'p_atom_int','parser.py',212), + ('atom -> ID','atom',1,'p_atom_id','parser.py',216), + ('atom -> TRUE','atom',1,'p_atom_bool','parser.py',220), + ('atom -> FALSE','atom',1,'p_atom_bool','parser.py',221), + ('atom -> STRING','atom',1,'p_atom_string','parser.py',225), + ('atom -> NEW TYPE','atom',2,'p_atom_new','parser.py',229), + ('atom -> block','atom',1,'p_atom_block','parser.py',233), + ('block -> LBRACE block_list RBRACE','block',3,'p_block','parser.py',237), + ('block_list -> expr SEMICOLON','block_list',2,'p_block_list','parser.py',241), + ('block_list -> expr SEMICOLON block_list','block_list',3,'p_block_list','parser.py',242), ] diff --git a/src/main.py b/src/main.py index 260078477..64db80510 100644 --- a/src/main.py +++ b/src/main.py @@ -66,7 +66,7 @@ def main(_input, _output): # ast, errors, context, scope = SemanticAn if __name__ == "__main__": - path = '/home/cwjki/Projects/cool-compiler-2021/tests/semantic/loops1.cl' + path = '/home/cwjki/Projects/cool-compiler-2021/tests/semantic/arithmetic7.cl' _input = sys.argv[1] if len(sys.argv) > 1 else path _output = sys.argv[2] if len(sys.argv) > 2 else None From ed128ad82b60012317c844898d3029e7dc33c4c7 Mon Sep 17 00:00:00 2001 From: cwjki Date: Mon, 21 Feb 2022 22:29:59 -0500 Subject: [PATCH 137/194] handling void types --- src/main.py | 3 +-- src/semantic/visitors/typeChecker.py | 4 ++++ src/semantic/visitors/varCollector.py | 8 +++++--- src/utils/ast.py | 3 +++ 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main.py b/src/main.py index 64db80510..dee261eca 100644 --- a/src/main.py +++ b/src/main.py @@ -1,4 +1,3 @@ -from ast import parse import sys from lexer import CoolLexer @@ -66,7 +65,7 @@ def main(_input, _output): # ast, errors, context, scope = SemanticAn if __name__ == "__main__": - path = '/home/cwjki/Projects/cool-compiler-2021/tests/semantic/arithmetic7.cl' + path = '/home/cwjki/Projects/cool-compiler-2021/tests/semantic/assignment3.cl' _input = sys.argv[1] if len(sys.argv) > 1 else path _output = sys.argv[2] if len(sys.argv) > 2 else None diff --git a/src/semantic/visitors/typeChecker.py b/src/semantic/visitors/typeChecker.py index 0fbff00fb..2a556dc2a 100644 --- a/src/semantic/visitors/typeChecker.py +++ b/src/semantic/visitors/typeChecker.py @@ -391,6 +391,10 @@ def visit(self, boolNode, scope): def visit(self, stringNode, scope): return StringType((stringNode.line, stringNode.col)) + @visitor.when(VoidNode) + def visit(self, voidNode, scope): + return VoidType((voidNode.line, voidNode.col)) + def _get_type(self, ntype, pos): try: return self.context.get_type(ntype, pos) diff --git a/src/semantic/visitors/varCollector.py b/src/semantic/visitors/varCollector.py index b1e143581..3ddbe0bfe 100644 --- a/src/semantic/visitors/varCollector.py +++ b/src/semantic/visitors/varCollector.py @@ -1,6 +1,6 @@ from utils import visitor -from utils.ast import ArrobaCallNode, AssignNode, AttrDeclarationNode, BlockNode, BoolNode, CaseNode, CaseOptionNode, ClassDeclarationNode, DotCallNode, FuncDeclarationNode, IdNode, IfThenElseNode, IntNode, IsVoidNode, LetInNode, MemberCallNode, ProgramNode, StringNode, VarDeclarationNode, WhileNode -from semantic.semantic import ErrorType, IntType, Scope, StringType +from utils.ast import ArrobaCallNode, AssignNode, AttrDeclarationNode, BlockNode, BoolNode, CaseNode, CaseOptionNode, ClassDeclarationNode, DotCallNode, FuncDeclarationNode, IdNode, IfThenElseNode, IntNode, IsVoidNode, LetInNode, MemberCallNode, ProgramNode, StringNode, VarDeclarationNode, VoidNode, WhileNode +from semantic.semantic import BoolType, ErrorType, IntType, Scope, StringType from utils.errors import NamexError, SemanticError, TypexError @@ -216,5 +216,7 @@ def define_default_value(self, typex, node): node.expr = IntNode(0) elif typex == StringType(): node.expr = StringNode("") - else: + elif typex == BoolType(): node.expr = BoolNode('false') + else: + node.expr = VoidNode(node.id) diff --git a/src/utils/ast.py b/src/utils/ast.py index f3f7804c7..044be4c93 100644 --- a/src/utils/ast.py +++ b/src/utils/ast.py @@ -249,3 +249,6 @@ class BoolNode(AtomicNode): class StringNode(AtomicNode): pass + +class VoidNode(AtomicNode): + pass From 880d7f15af125f2a54cdfab0788318c4e50c1a6c Mon Sep 17 00:00:00 2001 From: cwjki Date: Mon, 21 Feb 2022 22:32:27 -0500 Subject: [PATCH 138/194] fixing a aritmethid 9, a f** typo --- src/main.py | 2 +- src/utils/ast.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.py b/src/main.py index dee261eca..ae7deb075 100644 --- a/src/main.py +++ b/src/main.py @@ -65,7 +65,7 @@ def main(_input, _output): # ast, errors, context, scope = SemanticAn if __name__ == "__main__": - path = '/home/cwjki/Projects/cool-compiler-2021/tests/semantic/assignment3.cl' + path = '/home/cwjki/Projects/cool-compiler-2021/tests/semantic/arithmetic9.cl' _input = sys.argv[1] if len(sys.argv) > 1 else path _output = sys.argv[2] if len(sys.argv) > 2 else None diff --git a/src/utils/ast.py b/src/utils/ast.py index 044be4c93..8f76860c3 100644 --- a/src/utils/ast.py +++ b/src/utils/ast.py @@ -202,7 +202,7 @@ class UnaryNode(ExpressionNode): def __init__(self, expr, token): self.expr = expr self.line = token.lineno - self.column = token.column + self.col = token.column class NegationNode(UnaryNode): From 583b649f38416949f587a84b903cc81dbad505c0 Mon Sep 17 00:00:00 2001 From: cwjki Date: Mon, 21 Feb 2022 22:36:53 -0500 Subject: [PATCH 139/194] all the semantic test passed, trying to pass the code generating --- src/semantic/semantic.py | 9 +++++---- src/semantic/visitors/varCollector.py | 10 +--------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/semantic/semantic.py b/src/semantic/semantic.py index 11ccc672a..c3cf78e55 100644 --- a/src/semantic/semantic.py +++ b/src/semantic/semantic.py @@ -1,4 +1,4 @@ -from utils.ast import BoolNode, IntNode, IsVoidNode, StringNode +from utils.ast import BoolNode, IntNode, IsVoidNode, StringNode, VoidNode from utils.errors import SemanticError from collections import OrderedDict import itertools as itt @@ -471,11 +471,12 @@ def is_local(self, vname): def define_attribute(self, attr): self.attributes.append(attr) - -def define_default_value(typex, node): +def define_default_value(self, typex, node): if typex == IntType(): node.expr = IntNode(0) elif typex == StringType(): node.expr = StringNode("") - else: + elif typex == BoolType(): node.expr = BoolNode('false') + else: + node.expr = VoidNode(node.id) diff --git a/src/semantic/visitors/varCollector.py b/src/semantic/visitors/varCollector.py index 3ddbe0bfe..c5c84153a 100644 --- a/src/semantic/visitors/varCollector.py +++ b/src/semantic/visitors/varCollector.py @@ -211,12 +211,4 @@ def visit(self, idNode, scope): return vInfo.type - def define_default_value(self, typex, node): - if typex == IntType(): - node.expr = IntNode(0) - elif typex == StringType(): - node.expr = StringNode("") - elif typex == BoolType(): - node.expr = BoolNode('false') - else: - node.expr = VoidNode(node.id) + From cb8aa1e375ea4293fb0779567bce8a505211c1e3 Mon Sep 17 00:00:00 2001 From: cwjki Date: Mon, 21 Feb 2022 22:40:01 -0500 Subject: [PATCH 140/194] test --- src/semantic/visitors/varCollector.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/semantic/visitors/varCollector.py b/src/semantic/visitors/varCollector.py index c5c84153a..552bdf06b 100644 --- a/src/semantic/visitors/varCollector.py +++ b/src/semantic/visitors/varCollector.py @@ -1,6 +1,6 @@ from utils import visitor from utils.ast import ArrobaCallNode, AssignNode, AttrDeclarationNode, BlockNode, BoolNode, CaseNode, CaseOptionNode, ClassDeclarationNode, DotCallNode, FuncDeclarationNode, IdNode, IfThenElseNode, IntNode, IsVoidNode, LetInNode, MemberCallNode, ProgramNode, StringNode, VarDeclarationNode, VoidNode, WhileNode -from semantic.semantic import BoolType, ErrorType, IntType, Scope, StringType +from semantic.semantic import BoolType, ErrorType, IntType, Scope, StringType, define_default_value from utils.errors import NamexError, SemanticError, TypexError @@ -67,7 +67,7 @@ def visit(self, attrDeclarationNode, scope): attr = self.currentType.get_attribute( attrDeclarationNode.id, (attrDeclarationNode.line, attrDeclarationNode.col)) if attrDeclarationNode.expr is None: - self.define_default_value(attr.type, attrDeclarationNode) + define_default_value(attr.type, attrDeclarationNode) else: self.visit(attrDeclarationNode.expr, scope) attr.expr = attrDeclarationNode.expr @@ -104,7 +104,7 @@ def visit(self, varDeclarationNode, scope): if varDeclarationNode.expr is not None: self.visit(varDeclarationNode.expr, scope) else: - self.define_default_value(vType, varDeclarationNode) + define_default_value(vType, varDeclarationNode) @visitor.when(AssignNode) def visit(self, assignNode, scope): From 5001898fc0dd85c5bd3bcaf382ae3f277fc9b922 Mon Sep 17 00:00:00 2001 From: cwjki Date: Mon, 21 Feb 2022 22:41:57 -0500 Subject: [PATCH 141/194] test 2 --- src/semantic/visitors/varCollector.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/semantic/visitors/varCollector.py b/src/semantic/visitors/varCollector.py index 552bdf06b..3ddbe0bfe 100644 --- a/src/semantic/visitors/varCollector.py +++ b/src/semantic/visitors/varCollector.py @@ -1,6 +1,6 @@ from utils import visitor from utils.ast import ArrobaCallNode, AssignNode, AttrDeclarationNode, BlockNode, BoolNode, CaseNode, CaseOptionNode, ClassDeclarationNode, DotCallNode, FuncDeclarationNode, IdNode, IfThenElseNode, IntNode, IsVoidNode, LetInNode, MemberCallNode, ProgramNode, StringNode, VarDeclarationNode, VoidNode, WhileNode -from semantic.semantic import BoolType, ErrorType, IntType, Scope, StringType, define_default_value +from semantic.semantic import BoolType, ErrorType, IntType, Scope, StringType from utils.errors import NamexError, SemanticError, TypexError @@ -67,7 +67,7 @@ def visit(self, attrDeclarationNode, scope): attr = self.currentType.get_attribute( attrDeclarationNode.id, (attrDeclarationNode.line, attrDeclarationNode.col)) if attrDeclarationNode.expr is None: - define_default_value(attr.type, attrDeclarationNode) + self.define_default_value(attr.type, attrDeclarationNode) else: self.visit(attrDeclarationNode.expr, scope) attr.expr = attrDeclarationNode.expr @@ -104,7 +104,7 @@ def visit(self, varDeclarationNode, scope): if varDeclarationNode.expr is not None: self.visit(varDeclarationNode.expr, scope) else: - define_default_value(vType, varDeclarationNode) + self.define_default_value(vType, varDeclarationNode) @visitor.when(AssignNode) def visit(self, assignNode, scope): @@ -211,4 +211,12 @@ def visit(self, idNode, scope): return vInfo.type - + def define_default_value(self, typex, node): + if typex == IntType(): + node.expr = IntNode(0) + elif typex == StringType(): + node.expr = StringNode("") + elif typex == BoolType(): + node.expr = BoolNode('false') + else: + node.expr = VoidNode(node.id) From 12f742bb176d0bb12037bfcbbb62d1704d0e4b91 Mon Sep 17 00:00:00 2001 From: cwjki Date: Mon, 21 Feb 2022 22:42:57 -0500 Subject: [PATCH 142/194] deleting a duplicate method --- src/semantic/semantic.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/semantic/semantic.py b/src/semantic/semantic.py index c3cf78e55..2d92b78c0 100644 --- a/src/semantic/semantic.py +++ b/src/semantic/semantic.py @@ -470,13 +470,3 @@ def is_local(self, vname): def define_attribute(self, attr): self.attributes.append(attr) - -def define_default_value(self, typex, node): - if typex == IntType(): - node.expr = IntNode(0) - elif typex == StringType(): - node.expr = StringNode("") - elif typex == BoolType(): - node.expr = BoolNode('false') - else: - node.expr = VoidNode(node.id) From c77f51b9a20f3214ad68449ae65a358e4fe51a47 Mon Sep 17 00:00:00 2001 From: cwjki Date: Mon, 21 Feb 2022 22:55:36 -0500 Subject: [PATCH 143/194] deleting unnecessary imports --- src/semantic/semantic.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/semantic/semantic.py b/src/semantic/semantic.py index 2d92b78c0..b20d50ab5 100644 --- a/src/semantic/semantic.py +++ b/src/semantic/semantic.py @@ -1,4 +1,3 @@ -from utils.ast import BoolNode, IntNode, IsVoidNode, StringNode, VoidNode from utils.errors import SemanticError from collections import OrderedDict import itertools as itt @@ -374,7 +373,7 @@ class VariableInfo: def __init__(self, name, vtype, index=None): self.name = name self.type = vtype - self.index = index # saves the index in the scope of the variable + self.index = index def __str__(self): return f'{self.name} : {self.type.name}' From 15ae07065140b52a2edde1e3bc62f7db6945801b Mon Sep 17 00:00:00 2001 From: livi98 Date: Tue, 22 Feb 2022 19:23:04 +0100 Subject: [PATCH 144/194] separating the str int prints and reads --- src/code_generator/cil_ast.py | 108 ++++++++++++++++++++++++++-------- src/main.py | 7 ++- 2 files changed, 89 insertions(+), 26 deletions(-) diff --git a/src/code_generator/cil_ast.py b/src/code_generator/cil_ast.py index 7f5a67d33..30f95dedf 100644 --- a/src/code_generator/cil_ast.py +++ b/src/code_generator/cil_ast.py @@ -1,92 +1,122 @@ class Node: pass + class ProgramNode(Node): def __init__(self, dottypes, dotdata, dotcode): self.dottypes = dottypes self.dotdata = dotdata self.dotcode = dotcode -#.TYPE +# .TYPE + + class TypeNode(Node): def __init__(self, name): self.name = name self.attributes = [] self.methods = [] -#.DATA +# .DATA + + class DataNode(Node): def __init__(self, vname, value): self.name = vname self.value = value - -#.CODE + +# .CODE + + class FunctionNode(Node): - def __init__(self, name, params=[], localvars=[], instructions =[]): + def __init__(self, name, params=[], localvars=[], instructions=[]): self.name = name self.params = params self.localvars = localvars self.instructions = instructions + class InstructionNode(Node): def __init__(self): pass + class ParamNode(InstructionNode): - def __init__(self, type, name): - self.type = type + def __init__(self, name, typex): + self.type = typex self.name = name + class LocalNode(InstructionNode): def __init__(self, name): self.name = name + class AssignNode(InstructionNode): def __init__(self, dest, source): self.dest = dest self.source = source + class ArithExpressionNode(InstructionNode): def __init__(self, dest, left, right): self.dest = dest self.left = left self.right = right -#Arith +# Arith + + class PlusNode(ArithExpressionNode): pass + class MinusNode(ArithExpressionNode): pass + class StarNode(ArithExpressionNode): pass + class DivNode(ArithExpressionNode): pass + class LessNode(ArithExpressionNode): pass + class LessEqualNode(ArithExpressionNode): pass + class EqualNode(ArithExpressionNode): pass + class NotNode(Node): def __init__(self, dest, expr): self.dest = dest self.expr = expr -#Attr + +class LogicNotNode(Node): + def __init__(self, dest, expr): + self.dest = dest + self.expr = expr + +# Attr + + class GetAttrNode(InstructionNode): def __init__(self, dest, instance, attr, static_type): self.local_dest = dest self.instance = instance self.attr = attr self.static_type = static_type - + + class SetAttrNode(InstructionNode): def __init__(self, instance, attr, value, static_type): self.instance = instance @@ -99,38 +129,48 @@ def __init__(self, instance, attr, value, static_type): class GetIndexNode(InstructionNode): pass + class SetIndexNode(InstructionNode): pass -#Memory +# Memory + + class AllocateNode(InstructionNode): - def __init__(self, t, dest): - self.type = t + def __init__(self, typex, dest): + self.type = typex self.local_dest = dest - + + class ArrayNode(InstructionNode): pass + class TypeOfNode(InstructionNode): - def __init__(self, obj, dest): - self.obj = obj + def __init__(self, instance, dest): + self.instance = instance self.local_dest = dest -#Jumps +# Jumps + + class LabelNode(InstructionNode): def __init__(self, label): self.label = label + class GoToNode(InstructionNode): def __init__(self, label): self.label = label + class IfGoToNode(InstructionNode): def __init__(self, condition, label): self.condition = condition self.label = label -#Static Invocation + +# Static Invocation class CallNode(InstructionNode): def __init__(self, dest, func, args, static_type, ret_type): self.local_dest = dest @@ -139,7 +179,8 @@ def __init__(self, dest, func, args, static_type, ret_type): self.static_type = static_type self.ret_type = ret_type -#Dynamic Invocation + +# Dynamic Invocation class VCallNode(InstructionNode): def __init__(self, instance, dest, func, args, dynamic_type, ret_type): self.instance = instance @@ -150,40 +191,45 @@ def __init__(self, instance, dest, func, args, dynamic_type, ret_type): self.ret_type = ret_type -#Args +# Args class ArgNode(InstructionNode): def __init__(self, name): self.name = name -#Return +# Return class ReturnNode(InstructionNode): def __init__(self, value): self.value = value -#IO + +# IO class LoadNode(InstructionNode): def __init__(self, dest, msg): self.local_dest = dest self.msg = msg + class LengthNode(InstructionNode): def __init__(self, dest, arg): self.local_dest = dest self.arg = arg - + + class ConcatNode(InstructionNode): def __init__(self, dest, head, tail): self.local_dest = dest self.head = head self.tail = tail + class PrefixNode(InstructionNode): def __init__(self, dest, string, n): self.local_dest = dest self.string = string self.n = n + class SubstringNode(InstructionNode): def __init__(self, dest, string, begin, final): self.local_dest = dest @@ -191,16 +237,28 @@ def __init__(self, dest, string, begin, final): self.string = string self.final = final + class StrNode(InstructionNode): def __init__(self, dest, value): self.local_dest = dest self.value = value -class ReadNode(InstructionNode): + +class ReadStringNode(InstructionNode): def __init__(self, dest): self.local_dest = dest -class PrintNode(InstructionNode): + +class ReadIntNode(InstructionNode): + def __init__(self, dest): + self.local_dest = dest + + +class PrintStringNode(InstructionNode): def __init__(self, value): self.value = value + +class PrintIntNode(InstructionNode): + def __init__(self, value): + self.value = value diff --git a/src/main.py b/src/main.py index ae7deb075..ade9794df 100644 --- a/src/main.py +++ b/src/main.py @@ -6,6 +6,7 @@ from semantic.visitors.typeChecker import TypeChecker from semantic.visitors.typeCollector import TypeCollector from semantic.visitors.varCollector import VarCollector +from code_generator.COOLToCILVisitor import COOLToCILVisitor from utils.errors import SemanticError @@ -17,6 +18,7 @@ def main(_input, _output): # Lexer lexer = CoolLexer() tokens = lexer.run(text) + # Parser parser = CoolParser(lexer) @@ -61,11 +63,14 @@ def main(_input, _output): # Code Generation + coolToCIL = COOLToCILVisitor(context) + cilAST = coolToCIL.visit(ast, scope) + # ast, errors, context, scope = SemanticAn if __name__ == "__main__": - path = '/home/cwjki/Projects/cool-compiler-2021/tests/semantic/arithmetic9.cl' + path = '/mnt/c/Users/Liviton/Desktop/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/semantic/arithmetic1.cl' _input = sys.argv[1] if len(sys.argv) > 1 else path _output = sys.argv[2] if len(sys.argv) > 2 else None From 27184fa72ad35ebc3769ae2ff8fc9cec24cb7a3a Mon Sep 17 00:00:00 2001 From: livi98 Date: Tue, 22 Feb 2022 20:06:47 +0100 Subject: [PATCH 145/194] adding CopyNode cil ast --- src/code_generator/cil_ast.py | 54 ++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/src/code_generator/cil_ast.py b/src/code_generator/cil_ast.py index 30f95dedf..6c952f66b 100644 --- a/src/code_generator/cil_ast.py +++ b/src/code_generator/cil_ast.py @@ -15,7 +15,7 @@ class TypeNode(Node): def __init__(self, name): self.name = name self.attributes = [] - self.methods = [] + self.methods = {} # .DATA @@ -53,9 +53,9 @@ def __init__(self, name): class AssignNode(InstructionNode): - def __init__(self, dest, source): - self.dest = dest - self.source = source + def __init__(self, local_dest, expr): + self.local_dest = local_dest + self.expr = expr class ArithExpressionNode(InstructionNode): @@ -137,8 +137,9 @@ class SetIndexNode(InstructionNode): class AllocateNode(InstructionNode): - def __init__(self, typex, dest): + def __init__(self, typex, tag, dest): self.type = typex + self.tag = tag self.local_dest = dest @@ -204,23 +205,36 @@ def __init__(self, value): # IO -class LoadNode(InstructionNode): - def __init__(self, dest, msg): +class LoadInt(InstructionNode): + def __init__(self, value, dest): + self.value = value self.local_dest = dest + + +class LoadString(InstructionNode): + def __init__(self, msg, dest): self.msg = msg + self.local_dest = dest -class LengthNode(InstructionNode): - def __init__(self, dest, arg): +class LoadVoid(InstructionNode): + def __init__(self, dest): self.local_dest = dest - self.arg = arg + + +class LengthNode(InstructionNode): + def __init__(self, variable, result): + self.variable = variable + self.result = result class ConcatNode(InstructionNode): - def __init__(self, dest, head, tail): - self.local_dest = dest - self.head = head - self.tail = tail + def __init__(self, str1, len1, str2, len2, result): + self.str1 = str1 + self.len1 = len1 + self.str2 = str2 + self.len2 = len2 + self.result = result class PrefixNode(InstructionNode): @@ -262,3 +276,15 @@ def __init__(self, value): class PrintIntNode(InstructionNode): def __init__(self, value): self.value = value + + +class IsVoidNode(InstructionNode): + def __init__(self, result_local, expr): + self.result_local = result_local + self.expr = expr + + +class CopyNode(InstructionNode): + def __init__(self, typex, local_dest): + self.type = typex + self.local_dest = local_dest From 64bbc5fb639d7df15f52597a0f6bce20b576af64 Mon Sep 17 00:00:00 2001 From: livi98 Date: Tue, 22 Feb 2022 20:38:29 +0100 Subject: [PATCH 146/194] modificating graph in context --- src/code_generator/BaseCoolToCilVisitor.py | 20 +++++++- src/main.py | 6 +-- src/semantic/semantic.py | 53 ++++++++++++++-------- 3 files changed, 56 insertions(+), 23 deletions(-) diff --git a/src/code_generator/BaseCoolToCilVisitor.py b/src/code_generator/BaseCoolToCilVisitor.py index 5547a382e..398d26913 100644 --- a/src/code_generator/BaseCoolToCilVisitor.py +++ b/src/code_generator/BaseCoolToCilVisitor.py @@ -7,10 +7,26 @@ def __init__(self, context): self.current_type = None self.current_method = None self.current_function = None - self.constructors = [] self.context = context - self.inherit_graph = {} + + def set_type_tags(self, node='Object', tag=0): + self.types[node].tag = tag + for i,t in enumerate(self.graph[node]): + self.set_type_tags(t, tag + i + 1) + + def set_type_max_tags(self, node='Object'): + if not self.graph[node]: + self.types[node].max_tag = self.types[node].tag + else: + for t in self.graph[node]: + self.set_type_max_tags(t) + maximum = 0 + for t in self.graph[node]: + maximum = max(maximum, self.types[t].max_tag) + self.types[node].max_tag = maximum + + @property def params(self): return self.current_function.params diff --git a/src/main.py b/src/main.py index ade9794df..179442ad3 100644 --- a/src/main.py +++ b/src/main.py @@ -6,7 +6,7 @@ from semantic.visitors.typeChecker import TypeChecker from semantic.visitors.typeCollector import TypeCollector from semantic.visitors.varCollector import VarCollector -from code_generator.COOLToCILVisitor import COOLToCILVisitor +# from code_generator.COOLToCILVisitor import COOLToCILVisitor from utils.errors import SemanticError @@ -63,8 +63,8 @@ def main(_input, _output): # Code Generation - coolToCIL = COOLToCILVisitor(context) - cilAST = coolToCIL.visit(ast, scope) + # coolToCIL = COOLToCILVisitor(context) + # cilAST = coolToCIL.visit(ast, scope) # ast, errors, context, scope = SemanticAn diff --git a/src/semantic/semantic.py b/src/semantic/semantic.py index b20d50ab5..9084f223c 100644 --- a/src/semantic/semantic.py +++ b/src/semantic/semantic.py @@ -330,38 +330,55 @@ def __ne__(self, other): class Context: def __init__(self): self.types = {} + self.graph = {} + self.create_graph() - def get_depth(self, class_name): - typex = self.types[class_name] - if typex.parent is None: - return 0 - return 1 + self.get_depth(typex.parent.name) - - def build_inheritance_graph(self): - graph = {} - for type_name, typex in self.types.items(): - if typex.parent is not None: - graph[type_name] = typex.parent.name - else: - if type_name == 'SELF_TYPE': - continue - graph[type_name] = None - return graph + def create_graph(self): + self.graph['Object'] = ['IO', 'String', 'Bool', 'Int'] + self.graph['IO'] = [] + self.graph['String'] = [] + self.graph['Int'] = [] + self.graph['Bool'] = [] - def create_type(self, name: str, pos) -> Type: + def create_type(self, name, pos): if name in self.types: error_text = 'Classes may not be redefined.' raise SemanticError(error_text, *pos) typex = self.types[name] = Type(name, pos) + + parentName = self.types[name].parent.name + + if not self.graph.__contains__(name): + self.graph[name] = [] + if self.graph.__contains__(parentName): + self.graph[parentName].append(name) + else: + self.graph[parentName] = [name] return typex - def get_type(self, name: str, pos) -> Type: + def get_type(self, name: str, pos): try: return self.types[name] except KeyError: error_text = f'Type {name} is not defined.' raise SemanticError(error_text, *pos) + def set_type_tags(self, node='Object', tag=0): + self.types[node].tag = tag + for i,t in enumerate(self.graph[node]): + self.set_type_tags(t, tag + i + 1) + + def set_type_max_tags(self, node='Object'): + if not self.graph[node]: + self.types[node].max_tag = self.types[node].tag + else: + for t in self.graph[node]: + self.set_type_max_tags(t) + maximum = 0 + for t in self.graph[node]: + maximum = max(maximum, self.types[t].max_tag) + self.types[node].max_tag = maximum + def __str__(self): return '{\n\t' + '\n\t'.join(y for x in self.types.values() for y in str(x).split('\n')) + '\n}' From 0fb67484f15ca69427a505352eaf96d98b0f1032 Mon Sep 17 00:00:00 2001 From: livi98 Date: Tue, 22 Feb 2022 22:51:53 +0100 Subject: [PATCH 147/194] adding string comparison --- src/code_generator/BaseCoolToCilVisitor.py | 513 +++++++++++---------- src/code_generator/cil_ast.py | 21 +- src/semantic/semantic.py | 49 +- 3 files changed, 332 insertions(+), 251 deletions(-) diff --git a/src/code_generator/BaseCoolToCilVisitor.py b/src/code_generator/BaseCoolToCilVisitor.py index 398d26913..508100f39 100644 --- a/src/code_generator/BaseCoolToCilVisitor.py +++ b/src/code_generator/BaseCoolToCilVisitor.py @@ -1,281 +1,314 @@ import cil_ast as cil +from semantic.semantic import VariableInfo + + class BaseCOOLToCILVisitor: def __init__(self, context): - self.dottypes = [] - self.dotdata = [] + self.dottypes = {} + self.dotdata = {} self.dotcode = [] self.current_type = None self.current_method = None self.current_function = None self.context = context - - - def set_type_tags(self, node='Object', tag=0): - self.types[node].tag = tag - for i,t in enumerate(self.graph[node]): - self.set_type_tags(t, tag + i + 1) - - def set_type_max_tags(self, node='Object'): - if not self.graph[node]: - self.types[node].max_tag = self.types[node].tag - else: - for t in self.graph[node]: - self.set_type_max_tags(t) - maximum = 0 - for t in self.graph[node]: - maximum = max(maximum, self.types[t].max_tag) - self.types[node].max_tag = maximum - + self.context.set_type_tags() + self.context.set_type_max_tags() @property def params(self): return self.current_function.params - + @property def localvars(self): return self.current_function.localvars - + @property def instructions(self): return self.current_function.instructions - - def register_param(self, type, name): - #'param_{self.current_function.name[9:]}_{vinfo.name}_{len(self.params)}' - param_node = cil.ParamNode(type, name) + + def register_param(self, vinfo): + # 'param_{self.current_function.name[9:]}_{vinfo.name}_{len(self.params)}' + param_node = cil.ParamNode(vinfo.name) self.params.append(param_node) - return name - + return vinfo.name + def register_local(self, name): #vinfo.name = f'local_{self.current_function.name[9:]}_{vinfo.name}_{len(self.localvars)}' local_node = cil.LocalNode(name) self.localvars.append(local_node) return name - def define_internal_local(self): - return self.register_local('internal') + def define_internal_local(self, scope, name="internal", cool_var=None, class_type=None): + if class_type != None: + cil_name = f'{class_type}.{name}' + scope.define_cil_local(cool_var, cil_name, None) + self.register_local(cil_name) + else: + cil_name = f'{name}_{len(self.localvars)}' + scope.define_cil_local(cool_var, cil_name, None) + self.register_local(cil_name) + return cil_name def register_instruction(self, instruction): self.instructions.append(instruction) return instruction ############################### - + def to_function_name(self, method_name, type_name): - return f'function_{method_name}_at_{type_name}' - - def to_attribute_name(self, attr_name, type_name): - return f'function_{attr_name}_at_{type_name}' - - def to_variable_name(self, var_name): - return f'function_{var_name}' - - def define_method(self, name, param_names, param_types, return_type, pos): - if name in self.methods: - error_text = SemanticError.METHOD_ALREADY_DEFINED % name - raise SemanticError(error_text, *pos) - - method = self.methods[name] = Method(name, param_names, param_types, return_type) - return method - - def initialize_attr(self, constructor, attr, scope): - if attr.expr: - constructor.body.expr_list.append(AssignNode(attr.name, attr.expr)) - elif attr.type == 'Int': - constructor.body.expr_list.append(AssignNode(attr.name, ConstantNumNode(0))) - elif attr.type == 'Bool': - constructor.body.expr_list.append(AssignNode(attr.name, ConstantBoolNode(False))) - elif attr.type == 'String': - constructor.body.expr_list.append(AssignNode(attr.name, ConstantStrNode(""))) - else: - constructor.body.expr_list.append(AssignNode(attr.name, ConstantVoidNode(atrr.name))) - + return f'{type_name}.{method_name}' + def register_function(self, function_name): function_node = cil.FunctionNode(function_name, [], [], []) self.dotcode.append(function_node) return function_node - + def register_type(self, name): type_node = cil.TypeNode(name) - self.dottypes.append(type_node) + self.dottypes[name] = type_node return type_node def register_data(self, value): vname = f'data_{len(self.dotdata)}' - data_node = cil.DataNode(vname, value) - self.dotdata.append(data_node) - return data_node - - def get_all_attributes(self, clean=True): - plain = OrderedDict() if self.parent is None else self.parent.get_all_attributes(False) - for attr in self.attributes.values(): - plain[attr.name] = (attr, self) - return plain.values() if clean else plain - - def get_all_methods(self, clean=True): - plain = OrderedDict() if self.parent is None else self.parent.get_all_methods(False) - for method in self.methods.values(): - plain[method.name] = (method, self) - return plain.values() if clean else plain - - def define_built_in(self): - #regular function - f1_params = [cil.ParamNode("self", 'Object')] - f1_localVars = [cil.LocalNode("local_abort_Object_self_0")] - f1_intructions = [cil.AssignNode(f1_localVars[0].name,f1_params[0].name), - cil.ExitNode(f1_params[0].name)] - f1 = cil.FunctionNode("function_abort_Object",f1_params,f1_localVars,f1_intructions) - - f2_params = [cil.ParamNode("self", 'Object')] - f2_localVars = [cil.LocalNode("local_type_name_Object_result_0")] - f2_intructions = [cil.TypeOfNode(f2_params[0].name,f2_localVars[0].name), - cil.ReturnNode(f2_localVars[0].name)] - f2 = cil.FunctionNode("function_type_name_Object",f2_params,f2_localVars,f2_intructions) - - f3_params = [cil.ParamNode("self", 'Object')] - f3_localVars = [cil.LocalNode("local_copy_Object_result_0")] - f3_intructions = [cil.CopyNode(f3_localVars[0].name,f3_params[0].name), - cil.ReturnNode(f3_localVars[0].name)] - f3 = cil.FunctionNode("function_copy_Object",f3_params,f3_localVars,f3_intructions) - - #IO out - f4_params = [cil.ParamNode("self", 'IO'), cil.ParamNode("word", 'String')] - f4_localVars = [cil.LocalNode("local_out_string_String_self_0")] - f4_intructions = [cil.AssignNode(f4_localVars[0].name, f4_params[0].name), - cil.OutStringNode(f4_params[1].name), - cil.ReturnNode(f4_localVars[0].name)] - f4 = cil.FunctionNode("function_out_string_IO",f4_params,f4_localVars,f4_intructions) - - f5_params = [cil.ParamNode("self", 'IO'), cil.ParamNode("number", 'Int')] - f5_localVars = [cil.LocalNode("local_out_int_IO_self_0")] - f5_intructions = [cil.AssignNode(f5_localVars[0].name,f5_params[0].name), - cil.OutIntNode(f5_params[1].name), - cil.ReturnNode(f5_localVars[0].name)] - f5 = cil.FunctionNode("function_out_int_IO",f5_params,f5_localVars,f5_intructions) - - #IO in - f6_params = [cil.ParamNode("self", 'IO')] - f6_localVars = [cil.LocalNode("local_in_int_IO_result_0")] - f6_intructions = [cil.ReadIntNode(f6_localVars[0].name), - cil.ReturnNode(f6_localVars[0].name)] - f6 = cil.FunctionNode("function_in_int_IO",f6_params,f6_localVars,f6_intructions) - - f7_params = [cil.ParamNode("self", 'IO')] - f7_localVars = [cil.LocalNode("local_in_string_IO_result_0")] - f7_intructions = [cil.ReadStringNode(f7_localVars[0].name), - cil.ReturnNode(f7_localVars[0].name)] - f7 = cil.FunctionNode("function_in_string_IO",f7_params,f7_localVars,f7_intructions) - - #Functions from String type - f8_params = [cil.ParamNode("self", 'String')] - f8_localVars = [cil.LocalNode("local_length_String_result_0")] - f8_intructions = [cil.LengthNode(f8_localVars[0].name,f8_params[0].name), - cil.ReturnNode(f8_localVars[0].name)] - f8 = cil.FunctionNode("function_length_String",f8_params,f8_localVars,f8_intructions) - - f9_params = [cil.ParamNode("self", 'String'), cil.ParamNode("word", 'String')] - f9_localVars = [cil.LocalNode("local_concat_String_result_0")] - f9_intructions = [cil.ConcatNode(f9_localVars[0].name,f9_params[0].name,f9_params[1].name), - cil.ReturnNode(f9_localVars[0].name)] - f9 = cil.FunctionNode("function_concat_String",f9_params,f9_localVars,f9_intructions) - - f10_params = [cil.ParamNode("self", 'String'), cil.ParamNode("begin", 'Int'), cil.ParamNode("end", 'Int')] - f10_localVars = [cil.LocalNode("local_substr_String_result_0")] - f10_intructions = [cil.SubstringNode(f10_localVars[0].name,f10_params[0].name,f10_params[1].name,f10_params[2].name), - cil.ReturnNode(f10_localVars[0].name)] - f10 = cil.FunctionNode("function_substr_String",f10_params,f10_localVars,f10_intructions) - - f11_params = [cil.ParamNode("self", 'String')] - f11_localVars = [cil.LocalNode("local_type_name_String_result_0")] - f11_intructions = [cil.LoadNode(f11_localVars[0].name, 'type_String'), - cil.ReturnNode(f11_localVars[0].name)] - f11 = cil.FunctionNode("function_type_name_String",f11_params,f11_localVars,f11_intructions) - - f12_params = [cil.ParamNode("self", 'String')] - f12_localVars = [cil.LocalNode("local_copy_String_result_0")] - f12_intructions = [cil.ConcatNode(f12_localVars[0].name, f12_params[0].name, None), - cil.ReturnNode(f12_localVars[0].name)] - f12 = cil.FunctionNode("function_copy_String",f12_params,f12_localVars,f12_intructions) - - #Functions from Int type - f13_params = [cil.ParamNode("self", 'Int')] - f13_localVars = [cil.LocalNode("local_type_name_Int_result_0")] - f13_intructions = [cil.LoadNode(f13_localVars[0].name, 'type_Int'), - cil.ReturnNode(f13_localVars[0].name)] - f13 = cil.FunctionNode("function_type_name_Int",f13_params,f13_localVars,f13_intructions) - - f14_params = [cil.ParamNode("self", 'Int')] - f14_localVars = [cil.LocalNode("local_copy_Int_result_0")] - f14_intructions = [cil.AssignNode(f14_localVars[0].name, f14_params[0].name), - cil.ReturnNode(f14_localVars[0].name)] - f14 = cil.FunctionNode("function_copy_Int",f14_params,f14_localVars,f14_intructions) - - #Functions from Bool type - f15_params = [cil.ParamNode("self", 'Bool')] - f15_localVars = [cil.LocalNode("local_type_name_Bool_result_0")] - f15_intructions = [cil.LoadNode(f15_localVars[0].name, 'type_Bool'), - cil.ReturnNode(f15_localVars[0].name)] - f15 = cil.FunctionNode("function_type_name_Bool",f15_params,f15_localVars,f15_intructions) - - f16_params = [cil.ParamNode("self", 'Bool')] - f16_localVars = [cil.LocalNode("local_copy_result_Bool_0")] - f16_intructions = [cil.AssignNode(f16_localVars[0].name, f16_params[0].name), - cil.ReturnNode(f16_localVars[0].name)] - f16 = cil.FunctionNode("function_copy_Bool",f16_params,f16_localVars,f16_intructions) - - self.dotcode += [f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11, f12, f13, f14, f15, f16] - object_methods = [('abort', f1.name), ('type_name', f2.name), ('copy', f3.name)] - string_methods = [('length', f8.name), ('concat', f9.name), ('substr', f10.name), ('type_name', f11.name), ('copy', f12.name)] - io_methods = [('out_string', f4.name), ('out_int', f5.name), ('in_int', f6.name), ('in_string', f7.name)] - int_methods = [('type_name', f13.name), ('copy', f14.name)] - bool_methods = [('type_name', f15.name), ('copy', f16.name)] - - self.dottypes += [cil.TypeNode("Object", [], object_methods), - cil.TypeNode("IO", [], object_methods + io_methods) , - cil.TypeNode("String", [], string_methods), - cil.TypeNode('Int', [], int_methods), - cil.TypeNode('Bool', [], bool_methods)] - - #este metodo tiene que ver con los types de la semantica REVISAAAARRRR! - def get_type(self, name) -> Type: - try: - return self.types[name] - except KeyError: - error_text = TypesError.TYPE_NOT_DEFINED % name - raise TypesError(error_text) - - def check_void(self, expr): - result = self.define_internal_local() - self.register_instruction(cil.TypeOfNode(expr, result)) - - void_expr = self.define_internal_local() - self.register_instruction(cil.LoadNode(void_expr, self.void_data)) - self.register_instruction(cil.EqualNode(result, result, void_expr)) - return result - - def sort_option_nodes_by_type(self, case_list): - return sorted(case_list, reverse=True, - key=lambda x: self.context.get_depth(x.typex)) - - #esto esta asociado al context que define la semantica igual que el hierarchy_types - def get_depth(self, class_name): - typex = self.types[class_name] - if typex.parent is None: - return 0 - return 1 + self.get_depth(typex.parent.name) - - def _define_unary_node(self, node, scope, cil_node): - result = self.define_internal_local() - expr, typex = self.visit(node.expr, scope) - self.register_instruction(cil_node(result, expr)) - return result, typex - - def load_var_if_occupied(self, var): - if var is not None: - self.code.append(f'# Restore {var}') - self.load_var_code(var) - - def save_reg_if_occupied(self, reg): - var = self.reg_desc.get_content(reg) - if var is not None: - self.code.append(f'# Saving {reg} to memory') - self.save_var_code(var) - return var + self.dotdata[vname] = value + return vname + + def define_built_in(self, scope): + for t in ['Object', 'Int', 'String', 'Bool', 'IO']: + builtin_type = self.context.get_type(t) + cil_type = self.register_type(t) + cil_type.attributes = [ + f'{attr}' for attr in builtin_type.attributes] + cil_type.methods = {f'{m}': f'{c}.{m}' for c, + m in builtin_type.get_all_methods()} + if t in ['Int', 'String', 'Bool']: + cil_type.attributes.append('value') + + # ----------------Object--------------------- + # init + self.current_function = self.register_function('Object_init') + self.register_param(VariableInfo('self', None)) + self.register_instruction(cil.ReturnNode(None)) + + # abort + self.current_function = self.register_function( + self.to_function_name('abort', 'Object')) + self.register_param(VariableInfo('self', None)) + msg = self.define_internal_local(scope=scope, name="msg") + key_msg = '' + for s in self.dotdata.keys(): + if self.dotdata[s] == 'Abort called from class ': + key_msg = s + self.register_instruction(cil.LoadStringNode(key_msg, msg)) + self.register_instruction(cil.PrintStringNode(msg)) + type_name = self.define_internal_local(scope=scope, name="type_name") + self.register_instruction(cil.TypeOfNode('self', type_name)) + self.register_instruction(cil.PrintStringNode(type_name)) + eol_local = self.define_internal_local(scope=scope, name="eol") + for s in self.dotdata.keys(): + if self.dotdata[s] == '\n': + eol = s + self.register_instruction(cil.LoadStringNode(eol, eol_local)) + self.register_instruction(cil.PrintStringNode(eol_local)) + self.register_instruction(cil.HaltNode()) + + # type_name + self.current_function = self.register_function( + self.to_function_name('type_name', 'Object')) + self.register_param(VariableInfo('self', None)) + type_name = self.define_internal_local(scope=scope, name="type_name") + self.register_instruction(cil.TypeOfNode('self', type_name)) + instance = self.define_internal_local(scope=scope, name="instance") + self.register_instruction(cil.AllocateNode( + 'String', self.context.get_type('String').tag, instance)) + result_init = self.define_internal_local( + scope=scope, name="result_init") + self.register_instruction(cil.CallNode(result_init, 'String_init', [ + cil.ArgNode(type_name), cil.ArgNode(instance)], "String")) + self.register_instruction(cil.ReturnNode(instance)) + + # copy + self.current_function = self.register_function( + self.to_function_name('copy', 'Object')) + self.register_param(VariableInfo('self', None)) + copy = self.define_internal_local(scope=scope, name="copy") + self.register_instruction(cil.CopyNode('self', copy)) + self.register_instruction(cil.ReturnNode(copy)) + + # ----------------IO--------------------- + # init + self.current_function = self.register_function('IO_init') + self.register_param(VariableInfo('self', None)) + self.register_instruction(cil.ReturnNode(None)) + + # out_string + self.current_function = self.register_function( + self.to_function_name('out_string', 'IO')) + self.register_param(VariableInfo('self', None)) + self.register_param(VariableInfo('x', None)) + v = self.define_internal_local(scope=scope, name="v") + self.register_instruction(cil.GetAttrNode(v, 'x', 'value', 'String')) + self.register_instruction(cil.PrintStringNode(v)) + self.register_instruction(cil.ReturnNode('self')) + + # out_int + self.current_function = self.register_function( + self.to_function_name('out_int', 'IO')) + self.register_param(VariableInfo('self', None)) + self.register_param(VariableInfo('x', None)) + v = self.define_internal_local(scope=scope, name="v") + self.register_instruction(cil.GetAttrNode(v, 'x', 'value', 'Int')) + self.register_instruction(cil.PrintIntNode(v)) + self.register_instruction(cil.ReturnNode('self')) + + # in_string + self.current_function = self.register_function( + self.to_function_name('in_string', 'IO')) + self.register_param(VariableInfo('self', None)) + msg = self.define_internal_local(scope=scope, name="read_str") + self.register_instruction(cil.ReadStringNode(msg)) + instance = self.define_internal_local(scope=scope, name="instance") + self.register_instruction(cil.AllocateNode( + 'String', self.context.get_type('String').tag, instance)) + result_init = self.define_internal_local( + scope=scope, name="result_init") + self.register_instruction(cil.CallNode(result_init, 'String_init', [ + cil.ArgNode(msg), cil.ArgNode(instance)], "String")) + self.register_instruction(cil.ReturnNode(instance)) + + # in_int + self.current_function = self.register_function( + self.to_function_name('in_int', 'IO')) + self.register_param(VariableInfo('self', None)) + number = self.define_internal_local(scope=scope, name="read_int") + self.register_instruction(cil.ReadIntNode(number)) + instance = self.define_internal_local(scope=scope, name="instance") + self.register_instruction(cil.AllocateNode( + 'Int', self.context.get_type('Int').tag, instance)) + result_init = self.define_internal_local( + scope=scope, name="result_init") + self.register_instruction(cil.CallNode(result_init, 'Int_init', [ + cil.ArgNode(number), cil.ArgNode(instance)], "Int")) + self.register_instruction(cil.ReturnNode(instance)) + + # ----------------String--------------------- + # init + self.current_function = self.register_function('String_init') + self.register_param(VariableInfo('self', None)) + self.register_param(VariableInfo('v', None)) + self.register_instruction( + cil.SetAttrNode('self', 'value', 'v', 'String')) + self.register_instruction(cil.ReturnNode(None)) + + # length + self.current_function = self.register_function( + self.to_function_name('length', 'String')) + self.register_param(VariableInfo('self', None)) + length_result = self.define_internal_local(scope=scope, name="length") + self.register_instruction(cil.LengthNode('self', length_result)) + instance = self.define_internal_local(scope=scope, name="instance") + self.register_instruction(cil.AllocateNode( + 'Int', self.context.get_type('Int').tag, instance)) + result_init = self.define_internal_local( + scope=scope, name="result_init") + self.register_instruction(cil.CallNode(result_init, 'Int_init', [ + cil.ArgNode(length_result), cil.ArgNode(instance)], "Int")) + self.register_instruction(cil.ReturnNode(instance)) + + # concat + self.current_function = self.register_function( + self.to_function_name('concat', 'String')) + self.register_param(VariableInfo('self', None)) + self.register_param(VariableInfo('s', None)) + + str1 = self.define_internal_local(scope=scope, name="str1") + self.register_instruction(cil.GetAttrNode( + str1, 'self', 'value', 'String')) + len1 = self.define_internal_local(scope=scope, name="len1") + self.register_instruction(cil.CallNode( + len1, 'String.length', [cil.ArgNode('self')], 'String')) + + str2 = self.define_internal_local(scope=scope, name="str2") + self.register_instruction( + cil.GetAttrNode(str2, 's', 'value', 'String')) + len2 = self.define_internal_local(scope=scope, name="len2") + self.register_instruction(cil.CallNode( + len2, 'String.length', [cil.ArgNode('s')], 'String')) + + local_len1 = self.define_internal_local(scope=scope, name="local_len1") + self.register_instruction(cil.GetAttrNode( + local_len1, len1, 'value', 'Int')) + local_len2 = self.define_internal_local(scope=scope, name="local_len2") + self.register_instruction(cil.GetAttrNode( + local_len2, len2, 'value', 'Int')) + + concat_result = self.define_internal_local(scope=scope, name="concat") + self.register_instruction(cil.ConcatNode( + str1, local_len1, str2, local_len2, concat_result)) + instance = self.define_internal_local(scope=scope, name="instance") + self.register_instruction(cil.AllocateNode( + 'String', self.context.get_type('String').tag, instance)) + result_init = self.define_internal_local( + scope=scope, name="result_init") + self.register_instruction(cil.CallNode(result_init, 'String_init', [ + cil.ArgNode(concat_result), cil.ArgNode(instance)], "String")) + self.register_instruction(cil.ReturnNode(instance)) + + # substr + self.current_function = self.register_function( + self.to_function_name('substr', 'String')) + self.register_param(VariableInfo('self', None)) + self.register_param(VariableInfo('i', None)) + self.register_param(VariableInfo('l', None)) + i_value = self.define_internal_local(scope=scope, name="i_value") + self.register_instruction( + cil.GetAttrNode(i_value, 'i', 'value', 'Int')) + l_value = self.define_internal_local(scope=scope, name="l_value") + self.register_instruction( + cil.GetAttrNode(l_value, 'l', 'value', 'Int')) + subs_result = self.define_internal_local( + scope=scope, name="subs_result") + self.register_instruction(cil.SubstringNode( + i_value, l_value, 'self', subs_result)) + instance = self.define_internal_local(scope=scope, name="instance") + self.register_instruction(cil.AllocateNode( + 'String', self.context.get_type('String').tag, instance)) + result_init = self.define_internal_local( + scope=scope, name="result_init") + self.register_instruction(cil.CallNode(result_init, 'String_init', [ + cil.ArgNode(subs_result), cil.ArgNode(instance)], "String")) + self.register_instruction(cil.ReturnNode(instance)) + + # ----------------Bool--------------------- + # init + self.current_function = self.register_function('Bool_init') + self.register_param(VariableInfo('self', None)) + self.register_param(VariableInfo('v', None)) + self.register_instruction( + cil.SetAttrNode('self', 'value', 'v', 'Bool')) + self.register_instruction(cil.ReturnNode(None)) + + # ----------------Int--------------------- + # init + self.current_function = self.register_function('Int_init') + self.register_param(VariableInfo('self', None)) + self.register_param(VariableInfo('v', None)) + self.register_instruction(cil.SetAttrNode('self', 'value', 'v', 'Int')) + self.register_instruction(cil.ReturnNode(None)) + + def build_string_equals_function(self, scope): + self.current_function = self.register_function('String_equals') + self.register_param(VariableInfo('str1', None)) + self.register_param(VariableInfo('str2', None)) + + str1 = self.define_internal_local(scope=scope, name="str1") + self.register_instruction(cil.GetAttrNode( + str1, 'str1', 'value', 'String')) + + str2 = self.define_internal_local(scope=scope, name="str2") + self.register_instruction(cil.GetAttrNode( + str2, 'str2', 'value', 'String')) + + result = self.define_internal_local( + scope=scope, name="comparison_result") + self.register_instruction(cil.StringEqualsNode(str1, str2, result)) + self.register_instruction(cil.ReturnNode(result)) diff --git a/src/code_generator/cil_ast.py b/src/code_generator/cil_ast.py index 6c952f66b..c2e87213a 100644 --- a/src/code_generator/cil_ast.py +++ b/src/code_generator/cil_ast.py @@ -42,8 +42,7 @@ def __init__(self): class ParamNode(InstructionNode): - def __init__(self, name, typex): - self.type = typex + def __init__(self, name): self.name = name @@ -205,19 +204,19 @@ def __init__(self, value): # IO -class LoadInt(InstructionNode): +class LoadIntNode(InstructionNode): def __init__(self, value, dest): self.value = value self.local_dest = dest -class LoadString(InstructionNode): +class LoadStringNode(InstructionNode): def __init__(self, msg, dest): self.msg = msg self.local_dest = dest -class LoadVoid(InstructionNode): +class LoadVoidNode(InstructionNode): def __init__(self, dest): self.local_dest = dest @@ -284,7 +283,19 @@ def __init__(self, result_local, expr): self.expr = expr +class HaltNode(InstructionNode): + def __init__(self): + pass + + class CopyNode(InstructionNode): def __init__(self, typex, local_dest): self.type = typex self.local_dest = local_dest + + +class StringEqualsNode(InstructionNode): + def __init__(self, s1, s2, result): + self.s1 = s1 + self.s2 = s2 + self.result = result diff --git a/src/semantic/semantic.py b/src/semantic/semantic.py index 9084f223c..53e47553b 100644 --- a/src/semantic/semantic.py +++ b/src/semantic/semantic.py @@ -129,6 +129,19 @@ def all_methods(self, clean=True): plain[method.name] = (method, self) return plain.values() if clean else plain + # code generator + def get_all_attributes(self): + all_attributes = self.parent and self.parent.get_all_attributes() or [] + all_attributes += [(self.name, attr) + for attr in self.attributes.values()] + return all_attributes + + # code generator + def get_all_methods(self): + all_methods = self.parent and self.parent.get_all_methods() or [] + all_methods += [(self.name, method) for method in self.methods] + return all_methods + def conforms_to(self, other): return other.bypass() or self == other or self.parent is not None and self.parent.conforms_to(other) @@ -365,9 +378,9 @@ def get_type(self, name: str, pos): def set_type_tags(self, node='Object', tag=0): self.types[node].tag = tag - for i,t in enumerate(self.graph[node]): + for i, t in enumerate(self.graph[node]): self.set_type_tags(t, tag + i + 1) - + def set_type_max_tags(self, node='Object'): if not self.graph[node]: self.types[node].max_tag = self.types[node].tag @@ -407,6 +420,7 @@ def __init__(self, parent=None): self.children = [] self.expr_dict = {} self.functions = {} + self.cil_locals = {} self.index = 0 if parent is None else len(parent) def __len__(self): @@ -443,13 +457,13 @@ def create_child(self): self.children.append(child) return child - def define_variable(self, vname, vtype) -> VariableInfo: + def define_variable(self, vname, vtype): info = VariableInfo(vname, vtype) if info not in self.locals: self.locals.append(info) return info - def find_variable(self, vname, index=None) -> VariableInfo: + def find_variable(self, vname, index=None): locals = self.attributes + self.locals locals = locals if index is None else itt.islice(locals, index) try: @@ -457,7 +471,7 @@ def find_variable(self, vname, index=None) -> VariableInfo: except StopIteration: return self.parent.find_variable(vname, index) if self.parent is not None else None - def find_local(self, vname, index=None) -> VariableInfo: + def find_local(self, vname, index=None): locals = self.locals if index is None else itt.islice( self.locals, index) try: @@ -465,6 +479,23 @@ def find_local(self, vname, index=None) -> VariableInfo: except StopIteration: return self.parent.find_local(vname, self.index) if self.parent is not None else None + def define_cil_local(self, vname, cil_name, vtype=None): + self.define_variable(vname, vtype) + self.cil_locals[vname] = cil_name + + def get_cil_local(self, vname): + if self.cil_locals.__contains__(vname): + return self.cil_locals[vname] + return None + + def find_cil_local(self, vname, index=None): + locals = self.cil_locals.items() if index is None else itt.islice( + self.cil_locals.items(), index) + try: + return next(cil_name for name, cil_name in locals if name == vname) + except StopIteration: + return self.parent.find_cil_local(vname, self.index) if (self.parent is not None) else None + def find_attribute(self, vname, index=None): locals = self.attributes if index is None else itt.islice( self.attributes, index) @@ -478,11 +509,17 @@ def get_class_scope(self): return self return self.parent.get_class_scope() - def is_defined(self, vname) -> VariableInfo: + def is_defined(self, vname): return self.find_variable(vname) is not None + def is_defined_cil_local(self, vname): + return self.find_cil_local(vname) is not None + def is_local(self, vname): return any(True for x in self.locals if x.name == vname) + def remove_local(self, vname): + self.locals = [local for local in self.locals if local.name != vname] + def define_attribute(self, attr): self.attributes.append(attr) From 5fcfd5528ab8b972ed0a558e615e683887700cbf Mon Sep 17 00:00:00 2001 From: livi98 Date: Wed, 23 Feb 2022 01:31:04 +0100 Subject: [PATCH 148/194] adding computed_type --- src/code_generator/COOLToCILVisitor.py | 285 +++++++++++++++---------- src/code_generator/cil_ast.py | 24 +-- src/main.py | 3 +- src/semantic/visitors/typeChecker.py | 77 +++++-- 4 files changed, 245 insertions(+), 144 deletions(-) diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index f9a6c14f1..05fc5d602 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -1,31 +1,42 @@ import cil_ast as cil from BaseCoolToCilVisitor import BaseCOOLToCILVisitor +from semantic.semantic import Scope, VariableInfo from utils import visitor from utils.ast import * + class COOLToCILVisitor(BaseCOOLToCILVisitor): @visitor.on('node') - def visit(self, node): + def visit(self, node, scope): pass - + @visitor.when(ProgramNode) - def visit(self, node, scope): - self.current_function = self.register_function('entry') - instance = self.define_internal_local() - result = self.define_internal_local() - self.register_instruction(cil.AllocateNode('Main', instance)) - self.register_instruction(cil.ArgNode(instance)) + def visit(self, node, scope=None): + scope = Scope() + self.current_function = self.register_function('main') + instance = self.define_internal_local(scope=scope, name="instance") + result = self.define_internal_local(scope=scope, name="result") + self.register_instruction(cil.AllocateNode( + 'Main', self.context.get_type('Main').tag, instance)) + self.register_instruction(cil.CallNode( + result, 'Main_init', [cil.ArgNode(instance)], "Main")) + self.register_instruction(cil.CallNode(result, self.to_function_name( + 'main', 'Main'), [cil.ArgNode(instance)], "Main")) + self.register_instruction(cil.ReturnNode(None)) + self.current_function = None - #self.register_instruction(cil.CallNode(self.to_function_name('main', 'Main'), result)) - self.register_instruction(cil.CallNode(result, self.to_function_name('main', 'Main'), [cil.ArgNode(instance)], 'Main')) + self.register_data('Abort called from class ') + self.register_data('\n') + self.dotdata['empty_str'] = '' - self.register_instruction(cil.ReturnNode(0)) - self.current_function = None + # Add built-in types in .TYPES section + self.register_builtin_types(scope) - self.define_built_in() + # Add string equals function + self.build_string_equals_function(scope) - for declaration, child_scope in zip(node.declarations, scope.children): - self.visit(declaration, child_scope) + for declaration in node.declarations: + self.visit(declaration, scope.create_child()) return cil.ProgramNode(self.dottypes, self.dotdata, self.dotcode) @@ -33,116 +44,151 @@ def visit(self, node, scope): def visit(self, node, scope): self.current_type = self.context.get_type(node.id) - cil_type_node = self.register_type(self.current_type) - cil_type_node.attributes = self.current_type.get_all_attributes() - - if len(cil_type_node.attributes) != 0: - constructor = FuncDeclarationNode(node.token, [], node.token, BlockNode([], node.token)) - func_declarations = [constructor] - self.constructors.append(node.id) - self.current_type.define_method(self.current_type.name, [], [], self.current_type, node.pos) - scopes = [scope] + list(scope.functions.values()) - else: - func_declarations = [] - scopes = list(scope.functions.values()) - - for attr, a_type in cil_type_node.attributes: - cil_type_node.attributes.append((attr.name, self.to_attribute_name(attr.name, a_type.name))) - self.initialize_attr(constructor, attr, scope) - if cil_type_node.attributes: - constructor.body.expr_list.append(SelfNode()) - - for method, mtype in self.current_type.get_all_methods(): - cil_type_node.methods.append((method.name, self.to_function_name(method.name, mtype.name))) + # Handle all the .TYPE section + cil_type = self.register_type(self.current_type.name) + cil_type.attributes = [f'{attr.name}' for c, + attr in self.current_type.get_all_attributes()] + cil_type.methods = {f'{m}': f'{c}.{m}' for c, + m in self.current_type.get_all_methods()} + + scope.define_cil_local( + "self", self.current_type.name, self.current_type) + + func_declarations = [ + f for f in node.features if isinstance(f, FuncDeclarationNode)] + attr_declarations = [ + a for a in node.features if isinstance(a, AttrDeclarationNode)] + for attr in attr_declarations: + scope.define_cil_local(attr.id, attr.id, node.id) + + # -------------------------Init--------------------------------- + self.current_function = self.register_function(f'{node.id}_init') + self.register_param(VariableInfo('self', None)) + + # Init parents recursively + result = self.define_internal_local(scope=scope, name="result") + self.register_instruction(cil.CallNode(result, f'{node.parent}_init', [ + cil.ArgNode('self')], node.parent)) + self.register_instruction(cil.ReturnNode(None)) + + for attr in attr_declarations: + self.visit(attr, scope) + # --------------------------------------------------------------- + self.current_function = None - func_declarations += [f for f in node.features if isinstance(f, FuncDeclarationNode)] - for feature, child_scope in zip(func_declarations, scopes): - self.visit(feature, child_scope) + for func in func_declarations: + self.visit(func, scope.create_child()) self.current_type = None -#this get_method is from semantic types @visitor.when(FuncDeclarationNode) - def visit(self, node, scope): + def visit(self, node, scope): self.current_method = self.current_type.get_method(node.id) - cil_name = self.to_function_name(node.id, self.current_type.name) - self.current_function = self.register_function(cil_name) - - self.register_param('self', self.current_type.name) - for param_name, param_type in node.params: - self.register_param(param_name, param_type.value) - - ret_value = self.visit(node.body, scope) - if not isinstance(ret_value, str): - result = self.define_internal_local() - self.register_instruction(cil.AssignNode(result, ret_value)) - self.register_instruction(cil.ReturnNode(result)) - else: - self.register_instruction(cil.ReturnNode(ret_value)) + self.dottypes[self.current_type.name].methods[ + node.id] = f'{self.current_type.name}.{node.id}' + cil_method_name = self.to_function_name( + node.id, self.current_type.name) + self.current_function = self.register_function(cil_method_name) + + self.register_param(VariableInfo('self', self.current_type)) + for pname, ptype, _, _ in node.params: + self.register_param(VariableInfo(pname, ptype)) + value = self.visit(node.body, scope) + + self.register_instruction(cil.ReturnNode(value)) self.current_method = None @visitor.when(AttrDeclarationNode) def visit(self, node, scope): - if node.expr: - self.visit(node.expr, scope) - self.register_instruction(cil.SetAttrNode(self.vself.name, node.id, scope.ret_expr, self.current_type)) - elif node.type in self.value_types: - local_value = self.define_internal_local() - self.register_instruction(cil.AllocateNode(node.type, local_value)) - self.register_instruction(cil.SetAttrNode(self.vself.name, node.id, local_value, self.current_type)) - -#this find_local, find_attribute is from scope + instance = None + + if node.type in ['Int', 'Bool']: + instance = self.define_internal_local(scope=scope, name="instance") + self.register_instruction(cil.AllocateNode( + node.type, self.context.get_type(node.type).tag, instance)) + value = self.define_internal_local(scope=scope, name="value") + self.register_instruction(cil.LoadIntNode(0, value)) + result_init = self.define_internal_local( + scope=scope, name="result_init") + self.register_instruction(cil.CallNode(result_init, f'{node.type}_init', [ + cil.ArgNode(value), cil.ArgNode(instance)], node.type)) + elif node.type == 'String': + instance = self.define_internal_local(scope=scope, name="instance") + self.register_instruction(cil.AllocateNode( + node.type, self.context.get_type(node.type).tag, instance)) + value = self.define_internal_local(scope=scope, name="value") + self.register_instruction(cil.LoadStringNode('empty_str', value)) + result_init = self.define_internal_local( + scope=scope, name="result_init") + self.register_instruction(cil.CallNode(result_init, f'{node.type}_init', [ + cil.ArgNode(value), cil.ArgNode(instance)], node.type)) + + if not node.expr is None: + expr = self.visit(node.expr, scope) + self.register_instruction(cil.SetAttrNode( + 'self', node.id, expr, self.current_type.name)) + else: + self.register_instruction(cil.SetAttrNode( + 'self', node.id, instance, self.current_type.name)) + @visitor.when(AssignNode) def visit(self, node, scope): - var_info = scope.find_local(node.id) - value, typex = self.visit(node.expr, scope) - if var_info is None: - var_info = scope.find_attribute(node.id) - attributes_names = [attr.name for attr, attr_type in self.current_type.get_all_attributes()] - self.register_instruction(cil.SetAttrNode('self', var_info.name, self.current_type.name, value)) + expr_local = self.visit(node.expr, scope) + result_local = self.define_internal_local(scope=scope, name="result") + cil_node_name = scope.find_cil_local(node.id) + + if self.is_defined_param(node.id): + self.register_instruction(cil.AssignNode(node.id, expr_local)) + elif self.current_type.has_attr(node.id): + cil_type_name = 'self' + self.register_instruction(cil.SetAttrNode( + cil_type_name, node.id, expr_local, self.current_type.name)) else: - local_name = self.to_variable_name(var_info.name) - self.register_instruction(cil.AssignNode(local_name, value)) - return value, typex + self.register_instruction( + cil.AssignNode(cil_node_name, expr_local)) + return expr_local @visitor.when(ArrobaCallNode) def visit(self, node, scope): - result_local = self.define_internal_local(scope = scope, name = "result") - expr_value = self.visit(node.instance, scope) + result_local = self.define_internal_local(scope=scope, name="result") + expr_value = self.visit(node.obj, scope) - func_call_args = [] - for arg in node.args: + call_args = [] + for arg in reversed(node.args): param_local = self.visit(arg, scope) - func_call_args.append(cil.ArgNode(param_local)) - func_call_args.append(cil.ArgNode(expr_value)) + call_args.append(cil.ArgNode(param_local)) + call_args.append(cil.ArgNode(expr_value)) + + static_instance = self.define_internal_local( + scope=scope, name='static_instance') + self.register_instruction(cil.AllocateNode( + node.type, self.context.get_type(node.type).tag, static_instance)) - static_instance = self.define_internal_local(scope=scope, name='static_instance') - self.register_instruction(cil.AllocateNode(node.static_type,self.context.get_type(node.static_type).tag ,static_instance)) - - self.register_instruction(cil.VCallNode(result_local, node.method, func_call_args, node.static_type, static_instance)) + self.register_instruction(cil.VCallNode( + result_local, node.id, call_args, node.type, static_instance)) return result_local @visitor.when(DotCallNode) def visit(self, node, scope): - result_local = self.define_internal_local(scope = scope, name = "result") - expr_value = self.visit(node.instance, scope) + result_local = self.define_internal_local(scope=scope, name="result") + expr_value = self.visit(node.obj, scope) - func_call_args = [] - for arg in node.args: + call_args = [] + for arg in reversed(node.args): param_local = self.visit(arg, scope) - func_call_args.append(cil.ArgNode(param_local)) - func_call_args.append(cil.ArgNode(expr_value)) + call_args.append(cil.ArgNode(param_local)) + call_args.append(cil.ArgNode(expr_value)) + + dynamic_type = node.obj.computed_type.name + self.register_instruction(CIL_AST.VCall( + result_local, node.method, call_args, dynamic_type, expr_value)) - static_instance = self.define_internal_local(scope=scope, name='static_instance') - self.register_instruction(cil.AllocateNode(node.static_type,self.context.get_type(node.static_type).tag ,static_instance)) - - self.register_instruction(cil.VCallNode(result_local, node.method, func_call_args, node.static_type, static_instance)) return result_local @visitor.when(MemberCallNode) def visit(self, node, scope): - result_local = self.define_internal_local(scope = scope, name = "result") + result_local = self.define_internal_local(scope=scope, name="result") expr_value = self.visit(node.instance, scope) member_call_args = [] @@ -152,8 +198,9 @@ def visit(self, node, scope): member_call_args.append(cil.ArgNode(expr_value)) dynamic_type = node.instance.computed_type.name - self.register_instruction(cil.VCallNode(result_local, node.method, member_call_args, dynamic_type, expr_value)) - + self.register_instruction(cil.VCallNode( + result_local, node.method, member_call_args, dynamic_type, expr_value)) + return result_local @visitor.when(IfNode) @@ -165,18 +212,20 @@ def visit(self, node, scope): else_label_node = self.register_label('else_label') continue_label_node = self.register_label('continue_label') - #If condition GOTO then_label + # If condition GOTO then_label self.visit(node.condition) - self.register_instruction(cil.GetAttrNode(vcondition, scope.ret_expr, 'value', 'Bool')) - self.register_instruction(cil.IfGoToNode(vcondition, then_label_node.label)) - #GOTO else_label + self.register_instruction(cil.GetAttrNode( + vcondition, scope.ret_expr, 'value', 'Bool')) + self.register_instruction(cil.IfGoToNode( + vcondition, then_label_node.label)) + # GOTO else_label self.register_instruction(cil.GoToNode(else_label_node.label)) - #Label then_label + # Label then_label self.register_instruction(then_label_node) self.visit(node.then_expr, scope) self.register_instruction(cil.AssignNode(vcondition, scope.ret_expr)) self.register_instruction(cil.GoToNode(continue_label_node.label)) - #Label else_label + # Label else_label self.register_instruction(else_label_node) self.visit(node.else_expr, scope) self.register_instruction(cil.AssignNode(vcondition, scope.ret_expr)) @@ -188,7 +237,7 @@ def visit(self, node, scope): def visit(self, node, scope): start_label = cil.LabelNode(f'start__{self.idx}') end_label = cil.LabelNode(f'end__{self.idx}') - + result = self.define_internal_local() self.register_instruction(cil.VoidConstantNode(result)) self.register_instruction(start_label) @@ -201,7 +250,7 @@ def visit(self, node, scope): self.register_instruction(end_label) return result, ObjectType() - + @visitor.when(BlockNode) def visit(self, node, scope): for expr in node.exprs: @@ -211,22 +260,24 @@ def visit(self, node, scope): return result, typex visitor.when(LetNode) + def visit(self, node, scope): child_scope = scope.expr_dict[node] for init in node.let_attrs: self.visit(init, child_scope) - + expr, typex = self.visit(node.expr, child_scope) return expr, typex visitor.when(CaseNode) + def visit(self, node, scope): expr, typex = self.visit(node.expr, scope) - + result = self.define_internal_local() end_label = cil.LabelNode(f'end__{self.idx}') error_label = cil.LabelNode(f'error__{self.idx}') - + isvoid = self.check_void(expr) self.register_instruction(cil.IfGoToNode(isvoid, error_label.label)) try: @@ -236,15 +287,17 @@ def visit(self, node, scope): sorted_case_list = self.sort_option_nodes_by_type(node.case_list) for i, case in enumerate(sorted_case_list): next_label = cil.LabelNode(f'next__{self.idx}_{i}') - expr_i = self.visit(case, new_scope.create_child(), expr, next_label, typex) + expr_i = self.visit( + case, new_scope.create_child(), expr, next_label, typex) self.register_instruction(cil.AssignNode(result, expr_i)) self.register_instruction(cil.GoToNode(end_label.label)) self.register_instruction(next_label) self.register_instruction(end_label) return result, typex -#this find_local, find_attribute is from scope, this get_type is separate, need to do it well +# this find_local, find_attribute is from scope, this get_type is separate, need to do it well visitor.when(VarNode) + def visit(self, node, scope): try: typex = scope.find_local(node.lex).type @@ -253,19 +306,22 @@ def visit(self, node, scope): except: var_info = scope.find_attribute(node.lex) local_var = self.register_local(var_info.name) - self.register_instruction(cil.GetAttrNode('self', var_info.name, self.current_type.name, local_var, var_info.type.name)) + self.register_instruction(cil.GetAttrNode( + 'self', var_info.name, self.current_type.name, local_var, var_info.type.name)) return local_var, get_type(var_info.type, self.current_type) visitor.when(NewNode) + def visit(self, node, scope): instance = self.define_internal_local() typex = self.context.get_type(node.lex) typex = get_type(typex, self.current_type) self.register_instruction(cil.AllocateNode(typex.name, instance)) - + if typex.get_all_attributes(): - self.register_instruction(cil.CallNode(typex.name, typex.name, instance, [cil.ArgNode(instance)], typex.name)) - + self.register_instruction(cil.CallNode(typex.name, typex.name, instance, [ + cil.ArgNode(instance)], typex.name)) + return instance, typex @visitor.when(NegationNode) @@ -297,7 +353,7 @@ def visit(self, node, scope): @visitor.when(LessNode) def visit(self, node, scope): return self._define_binary_node(node, scope, cil.LessNode) - + @visitor.when(LessEqNode) def visit(self, node, scope): return self._define_binary_node(node, scope, cil.LessEqualNode) @@ -305,4 +361,3 @@ def visit(self, node, scope): @visitor.when(EqualNode) def visit(self, node, scope): return self._define_binary_node(node, scope, cil.EqualNode) - diff --git a/src/code_generator/cil_ast.py b/src/code_generator/cil_ast.py index c2e87213a..8840b269b 100644 --- a/src/code_generator/cil_ast.py +++ b/src/code_generator/cil_ast.py @@ -170,25 +170,23 @@ def __init__(self, condition, label): self.label = label -# Static Invocation +# Dynamic Invocation class CallNode(InstructionNode): - def __init__(self, dest, func, args, static_type, ret_type): - self.local_dest = dest - self.function = func - self.args = args + def __init__(self, local_dest, function, params, static_type): + self.function = function + self.params = params self.static_type = static_type - self.ret_type = ret_type + self.local_dest = local_dest -# Dynamic Invocation +# Static Invocation class VCallNode(InstructionNode): - def __init__(self, instance, dest, func, args, dynamic_type, ret_type): - self.instance = instance - self.local_dest = dest - self.function = func - self.args = args + def __init__(self, local_dest, function, params, dynamic_type, instance): + self.function = function + self.params = params self.dynamic_type = dynamic_type - self.ret_type = ret_type + self.local_dest = local_dest + self.instance = instance # Args diff --git a/src/main.py b/src/main.py index 179442ad3..232843695 100644 --- a/src/main.py +++ b/src/main.py @@ -56,6 +56,7 @@ def main(_input, _output): typeChecker = TypeChecker(context, semanticErrors) typeChecker.visit(ast, scope) + if semanticErrors: for error in semanticErrors: print(error) @@ -70,7 +71,7 @@ def main(_input, _output): # ast, errors, context, scope = SemanticAn if __name__ == "__main__": - path = '/mnt/c/Users/Liviton/Desktop/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/semantic/arithmetic1.cl' + path = '/mnt/c/Users/Liviton/Desktop/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/semantic/dispatch2.cl' _input = sys.argv[1] if len(sys.argv) > 1 else path _output = sys.argv[2] if len(sys.argv) > 2 else None diff --git a/src/semantic/visitors/typeChecker.py b/src/semantic/visitors/typeChecker.py index 2a556dc2a..9e5bcf3e1 100644 --- a/src/semantic/visitors/typeChecker.py +++ b/src/semantic/visitors/typeChecker.py @@ -115,6 +115,8 @@ def visit(self, assignNode, scope): errorText = f'Inferred type {typex.name} of initialization of {assignNode.id} does not conform to identifier\'s declared type {varType.name}.' self.errors.append(TypexError( errorText, assignNode.line, assignNode.col)) + + assignNode.computed_type = typex return typex @visitor.when(ArrobaCallNode) @@ -176,7 +178,8 @@ def visit(self, dotCallNode, scope): self.errors.append(TypexError( errorText, dotCallNode.line, dotCallNode.col)) - return get_type(method.return_type, objType) + dotCallNode.computed_type = get_type(method.return_type, objType) + return dotCallNode.computed_type @visitor.when(MemberCallNode) def visit(self, memberCallNode, scope): @@ -202,7 +205,8 @@ def visit(self, memberCallNode, scope): self.errors.append(TypexError( errorText, memberCallNode.line, memberCallNode.col)) - return get_type(method.return_type, typex) + memberCallNode.computed_type = get_type(method.return_type, typex) + return memberCallNode.computed_type @visitor.when(IfThenElseNode) def visit(self, ifThenElseNode, scope): @@ -214,7 +218,10 @@ def visit(self, ifThenElseNode, scope): ifBodyType = self.visit(ifThenElseNode.ifBody, scope) elseBodyType = self.visit(ifThenElseNode.elseBody, scope) - return get_common_basetype([ifBodyType, elseBodyType]) + + ifThenElseNode.computed_type = get_common_basetype( + [ifBodyType, elseBodyType]) + return ifThenElseNode.computed_type @visitor.when(WhileNode) def visit(self, whileNode, scope): @@ -224,6 +231,8 @@ def visit(self, whileNode, scope): self.errors.append(TypexError( errorText, whileNode.line, whileNode.col)) self.visit(whileNode.body, scope) + + whileNode.computed_type = ObjectType() return ObjectType() @visitor.when(BlockNode) @@ -231,6 +240,8 @@ def visit(self, blockNode, scope): typex = None for expr in blockNode.exprs: typex = self.visit(expr, scope) + + blockNode.computed_type = typex return typex @visitor.when(LetInNode) @@ -238,7 +249,10 @@ def visit(self, letInNode, scope): childScope = scope.expr_dict[letInNode] for letDeclaration in letInNode.letBody: self.visit(letDeclaration, childScope) - return self.visit(letInNode.inBody, childScope) + + typex = self.visit(letInNode.inBody, childScope) + letInNode.computed_type = typex + return typex @visitor.when(CaseNode) def visit(self, caseNode, scope): @@ -254,11 +268,14 @@ def visit(self, caseNode, scope): self.errors.append(SemanticError( errorText, option.typeLine, option.typeCol)) checkDuplicate.append(option.type) - return get_common_basetype(types) + + caseNode.computed_type = get_common_basetype(types) + return caseNode.computed_type @visitor.when(CaseOptionNode) def visit(self, caseOptionNode, scope): optionType = self.visit(caseOptionNode.expr, scope) + caseOptionNode.computed_type = optionType return optionType @visitor.when(PlusNode) @@ -270,6 +287,8 @@ def visit(self, plusNode, scope): self.errors.append(TypexError( errorText, plusNode.line, plusNode.col)) return ErrorType() + + plusNode.computed_type = IntType() return IntType() @visitor.when(MinusNode) @@ -281,6 +300,8 @@ def visit(self, minusNode, scope): self.errors.append(TypexError( errorText, minusNode.line, minusNode.col)) return ErrorType() + + minusNode.computed_type = IntType() return IntType() @visitor.when(StarNode) @@ -292,6 +313,8 @@ def visit(self, starNode, scope): self.errors.append(TypexError( errorText, starNode.line, starNode.col)) return ErrorType() + + starNode.computed_type = IntType() return IntType() @visitor.when(DivNode) @@ -303,6 +326,8 @@ def visit(self, divNode, scope): self.errors.append(TypexError( errorText, divNode.line, divNode.col)) return ErrorType() + + divNode.computed_type = IntType() return IntType() @visitor.when(LessNode) @@ -314,6 +339,8 @@ def visit(self, lessNode, scope): self.errors.append(TypexError( errorText, lessNode.line, lessNode.col)) return ErrorType() + + lessNode.computed_type = BoolType() return BoolType() @visitor.when(LessEqNode) @@ -325,16 +352,21 @@ def visit(self, lessEq, scope): self.errors.append(TypexError( errorText, lessEq.line, lessEq.col)) return ErrorType() + + lessEq.computed_type = BoolType() return BoolType() @visitor.when(EqualNode) - def visit(self, lessEq, scope): - leftType = self.visit(lessEq.lvalue, scope) - rightType = self.visit(lessEq.rvalue, scope) + def visit(self, equalNode, scope): + leftType = self.visit(equalNode.lvalue, scope) + rightType = self.visit(equalNode.rvalue, scope) if (leftType != rightType) and (leftType in [IntType(), StringType(), BoolType()] or rightType in [IntType(), StringType(), BoolType()]): errorText = 'Illegal comparison with a basic type.' - self.errors.append(TypexError(errorText, lessEq.line, lessEq.col)) + self.errors.append(TypexError( + errorText, equalNode.line, equalNode.col)) return ErrorType() + + equalNode.computed_type = BoolType() return BoolType() @visitor.when(NegationNode) @@ -345,6 +377,8 @@ def visit(self, negationNode, scope): self.errors.append(TypexError( errorText, negationNode.line, negationNode.col)) return ErrorType() + + negationNode.computed_type = IntType() return IntType() @visitor.when(LogicNegationNode) @@ -355,11 +389,14 @@ def visit(self, logicNegationNode, scope): self.errors.append(TypexError( errorText, logicNegationNode.line, logicNegationNode.col)) return ErrorType() + + logicNegationNode.computed_type = BoolType() return BoolType() @visitor.when(IsVoidNode) def visit(self, isVoidNode, scope): self.visit(isVoidNode.expr, scope) + isVoidNode.computed_type = BoolType() return BoolType() @visitor.when(NewNode) @@ -372,28 +409,38 @@ def visit(self, newNode, scope): errorText = f'\'new\' used with undefined class {newNode.id}.' self.errors.append(TypexError( errorText, newNode.line, newNode.col)) - return get_type(typex, self.currentType) + + typex = get_type(typex, self.currentType) + newNode.computed_type = typex + return typex @visitor.when(IdNode) def visit(self, idNode, scope): varType = self.find_variable(scope, idNode.id).type - return get_type(varType, self.currentType) + typex = get_type(varType, self.currentType) + idNode.computed_type = typex + return typex @visitor.when(IntNode) def visit(self, intNode, scope): - return IntType((intNode.line, intNode.col)) + intNode.computed_type = IntType((intNode.line, intNode.col)) + return intNode.computed_type @visitor.when(BoolNode) def visit(self, boolNode, scope): - return BoolType((boolNode.line, boolNode.col)) + boolNode.computed_type = BoolType((boolNode.line, boolNode.col)) + return boolNode.computed_type @visitor.when(StringNode) def visit(self, stringNode, scope): - return StringType((stringNode.line, stringNode.col)) + stringNode.computed_type = StringType( + (stringNode.line, stringNode.col)) + return stringNode.computed_typestringNode @visitor.when(VoidNode) def visit(self, voidNode, scope): - return VoidType((voidNode.line, voidNode.col)) + voidNode.computed_type = VoidType((voidNode.line, voidNode.col)) + return voidNode.computed_type def _get_type(self, ntype, pos): try: From fa2c1cf5122c301562c90f76368041d1c1491740 Mon Sep 17 00:00:00 2001 From: livi98 Date: Wed, 23 Feb 2022 01:33:01 +0100 Subject: [PATCH 149/194] fixing a typo --- src/semantic/visitors/typeChecker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/semantic/visitors/typeChecker.py b/src/semantic/visitors/typeChecker.py index 9e5bcf3e1..ca6567e53 100644 --- a/src/semantic/visitors/typeChecker.py +++ b/src/semantic/visitors/typeChecker.py @@ -435,7 +435,7 @@ def visit(self, boolNode, scope): def visit(self, stringNode, scope): stringNode.computed_type = StringType( (stringNode.line, stringNode.col)) - return stringNode.computed_typestringNode + return stringNode.computed_type @visitor.when(VoidNode) def visit(self, voidNode, scope): From c221e63f4deb7ad2a86f38b9b53b60838c1baf96 Mon Sep 17 00:00:00 2001 From: livi98 Date: Wed, 23 Feb 2022 01:58:05 +0100 Subject: [PATCH 150/194] fixing while node and ifThenElse condition --- src/code_generator/COOLToCILVisitor.py | 87 ++++++++++++-------------- 1 file changed, 39 insertions(+), 48 deletions(-) diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index 05fc5d602..7e6d01b19 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -181,7 +181,7 @@ def visit(self, node, scope): call_args.append(cil.ArgNode(expr_value)) dynamic_type = node.obj.computed_type.name - self.register_instruction(CIL_AST.VCall( + self.register_instruction(cil.VCallNode( result_local, node.method, call_args, dynamic_type, expr_value)) return result_local @@ -189,67 +189,58 @@ def visit(self, node, scope): @visitor.when(MemberCallNode) def visit(self, node, scope): result_local = self.define_internal_local(scope=scope, name="result") - expr_value = self.visit(node.instance, scope) - member_call_args = [] - for arg in node.args: + call_args = [] + for arg in reversed(node.args): param_local = self.visit(arg, scope) - member_call_args.append(cil.ArgNode(param_local)) - member_call_args.append(cil.ArgNode(expr_value)) + call_args.append(cil.ArgNode(param_local)) - dynamic_type = node.instance.computed_type.name self.register_instruction(cil.VCallNode( - result_local, node.method, member_call_args, dynamic_type, expr_value)) + result_local, node.method, call_args, 'self', 'memberCallGuayaba')) return result_local - @visitor.when(IfNode) + @visitor.when(IfThenElseNode) def visit(self, node, scope): - vcondition = self.define_internal_local() - value = self.visit(node.condition, scope) - - then_label_node = self.register_label('then_label') - else_label_node = self.register_label('else_label') - continue_label_node = self.register_label('continue_label') - - # If condition GOTO then_label - self.visit(node.condition) - self.register_instruction(cil.GetAttrNode( - vcondition, scope.ret_expr, 'value', 'Bool')) - self.register_instruction(cil.IfGoToNode( - vcondition, then_label_node.label)) - # GOTO else_label - self.register_instruction(cil.GoToNode(else_label_node.label)) - # Label then_label - self.register_instruction(then_label_node) - self.visit(node.then_expr, scope) - self.register_instruction(cil.AssignNode(vcondition, scope.ret_expr)) - self.register_instruction(cil.GoToNode(continue_label_node.label)) - # Label else_label - self.register_instruction(else_label_node) - self.visit(node.else_expr, scope) - self.register_instruction(cil.AssignNode(vcondition, scope.ret_expr)) - - self.register_instruction(continue_label_node) - scope.ret_expr = vcondition + result_local = self.define_internal_local(scope=scope, name="result") + + cond_value = self.visit(node.condition, scope) + + if_then_label = self.get_label() + self.register_instruction(cil.IfGoToNode(cond_value, if_then_label)) + + else_value = self.visit(node.elseBody, scope) + self.register_instruction(cil.AssignNode(result_local, else_value)) + + end_if_label = self.get_label() + self.register_instruction(cil.GoToNode(end_if_label)) + + self.register_instruction(cil.LabelNode(if_then_label)) + then_value = self.visit(node.ifBody, scope) + self.register_instruction(cil.AssignNode(result_local, then_value)) + self.register_instruction(cil.LabelNode(end_if_label)) + + return result_local @visitor.when(WhileNode) def visit(self, node, scope): - start_label = cil.LabelNode(f'start__{self.idx}') - end_label = cil.LabelNode(f'end__{self.idx}') + result_local = self.define_internal_local(scope=scope, name="result") - result = self.define_internal_local() - self.register_instruction(cil.VoidConstantNode(result)) - self.register_instruction(start_label) + loop_init_label = self.get_label() + loop_body_label = self.get_label() + loop_end_label = self.get_label() + self.register_instruction(cil.LabelNode(loop_init_label)) + pred_value = self.visit(node.condition, scope) + self.register_instruction(cil.IfGoToNode(pred_value, loop_body_label)) + self.register_instruction(cil.GoToNode(loop_end_label)) - cond, _ = self.visit(node.cond, scope) - self.register_instruction(cil.IfGoToNode(cond, end_label.label)) - expr, typex = self.visit(node.expr, scope) - self.register_instruction(cil.AssignNode(result, expr)) - self.register_instruction(cil.GoToNode(start_label.label)) - self.register_instruction(end_label) + self.register_instruction(cil.LabelNode(loop_body_label)) + body_value = self.visit(node.body, scope) + self.register_instruction(cil.GoToNode(loop_init_label)) + self.register_instruction(cil.LabelNode(loop_end_label)) - return result, ObjectType() + self.register_instruction(cil.LoadVoidNode(result_local)) + return result_local @visitor.when(BlockNode) def visit(self, node, scope): From 269bc2ddc66266dd6f52f09a4764c41237f369b0 Mon Sep 17 00:00:00 2001 From: livi98 Date: Wed, 23 Feb 2022 04:50:58 +0100 Subject: [PATCH 151/194] fixing binary expr nodes --- src/code_generator/COOLToCILVisitor.py | 224 +++++++++++++++++++++++-- src/code_generator/cil_ast.py | 8 + 2 files changed, 216 insertions(+), 16 deletions(-) diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index 7e6d01b19..1ae45cde2 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -245,13 +245,10 @@ def visit(self, node, scope): @visitor.when(BlockNode) def visit(self, node, scope): for expr in node.exprs: - value, typex = self.visit(expr, scope) - result = self.define_internal_local() - self.register_instruction(cil.AssignNode(result, value)) - return result, typex - - visitor.when(LetNode) + result_local = self.visit(expr, scope) + return result_local + @visitor.when(LetNode) def visit(self, node, scope): child_scope = scope.expr_dict[node] for init in node.let_attrs: @@ -321,34 +318,229 @@ def visit(self, node, scope): @visitor.when(IsVoidNode) def visit(self, node, scope): - expr, _ = self.visit(node.expr, scope) - result = self.check_void(expr) - return result, BoolType() + expr_value = self.visit(node.expr, scope) + result_local = self.define_internal_local( + scope=scope, name="isvoid_result") + self.register_instruction(cil.IsVoidNode(result_local, expr_value)) + instance = self.define_internal_local(scope=scope, name="instance") + self.register_instruction(cil.AllocateNode( + 'Bool', self.context.get_type('Bool').tag, instance)) + result_init = self.define_internal_local( + scope=scope, name="result_init") + self.register_instruction(cil.CallNode(result_init, 'Bool_init', [ + cil.ArgNode(result_local), cil.ArgNode(instance)], "Bool")) + return instance @visitor.when(PlusNode) def visit(self, node, scope): - return self._define_binary_node(node, scope, cil.PlusNode) + result_local = self.define_internal_local(scope=scope, name="result") + op_local = self.define_internal_local(scope=scope, name="op") + left_local = self.define_internal_local(scope=scope, name="left") + right_local = self.define_internal_local(scope=scope, name="right") + + left_value = self.visit(node.lvalue, scope) + right_value = self.visit(node.rvalue, scope) + + self.register_instruction(cil.GetAttrNode( + left_local, left_value, "value", node.lvalue.computed_type.name)) + self.register_instruction(cil.GetAttrNode( + right_local, right_value, "value", node.rvalue.computed_type.name)) + + self.register_instruction(cil.BinaryOperationNode( + op_local, left_local, right_local, "+")) + + # Allocate Int result + self.register_instruction(cil.AllocateNode( + 'Int', self.context.get_type('Int').tag, result_local)) + result_init = self.define_internal_local( + scope=scope, name="result_init") + self.register_instruction(cil.CallNode(result_init, 'Int_init', [ + cil.ArgNode(op_local), cil.ArgNode(result_local)], "Int")) + + return result_local @visitor.when(MinusNode) def visit(self, node, scope): - return self._define_binary_node(node, scope, cil.MinusNode) + result_local = self.define_internal_local(scope=scope, name="result") + op_local = self.define_internal_local(scope=scope, name="op") + left_local = self.define_internal_local(scope=scope, name="left") + right_local = self.define_internal_local(scope=scope, name="right") + + left_value = self.visit(node.lvalue, scope) + right_value = self.visit(node.rvalue, scope) + + self.register_instruction(cil.GetAttrNode( + left_local, left_value, "value", node.lvalue.computed_type.name)) + self.register_instruction(cil.GetAttrNode( + right_local, right_value, "value", node.rvalue.computed_type.name)) + + self.register_instruction(cil.BinaryOperator( + op_local, left_local, right_local, "-")) + + # Allocate Int result + self.register_instruction(cil.AllocateNode( + 'Int', self.context.get_type('Int').tag, result_local)) + result_init = self.define_internal_local( + scope=scope, name="result_init") + self.register_instruction(cil.CallNode(result_init, 'Int_init', [ + cil.ArgNode(op_local), cil.ArgNode(result_local)], "Int")) + + return result_local @visitor.when(StarNode) def visit(self, node, scope): - return self._define_binary_node(node, scope, cil.StarNode) + result_local = self.define_internal_local(scope=scope, name="result") + op_local = self.define_internal_local(scope=scope, name="op") + left_local = self.define_internal_local(scope=scope, name="left") + right_local = self.define_internal_local(scope=scope, name="right") + + left_value = self.visit(node.lvalue, scope) + right_value = self.visit(node.rvalue, scope) + + self.register_instruction(cil.GetAttrNode( + left_local, left_value, "value", node.lvalue.computed_type.name)) + self.register_instruction(cil.GetAttrNode( + right_local, right_value, "value", node.rvalue.computed_type.name)) + + self.register_instruction(cil.BinaryOperator( + op_local, left_local, right_local, "*")) + + # Allocate Int result + self.register_instruction(cil.AllocateNode( + 'Int', self.context.get_type('Int').tag, result_local)) + result_init = self.define_internal_local( + scope=scope, name="result_init") + self.register_instruction(cil.CallNode(result_init, 'Int_init', [ + cil.ArgNode(op_local), cil.ArgNode(result_local)], "Int")) + + return result_local @visitor.when(DivNode) def visit(self, node, scope): - return self._define_binary_node(node, scope, cil.DivNode) + result_local = self.define_internal_local(scope=scope, name="result") + op_local = self.define_internal_local(scope=scope, name="op") + left_local = self.define_internal_local(scope=scope, name="left") + right_local = self.define_internal_local(scope=scope, name="right") + + left_value = self.visit(node.lvalue, scope) + right_value = self.visit(node.rvalue, scope) + + self.register_instruction(cil.GetAttrNode( + left_local, left_value, "value", node.lvalue.computed_type.name)) + self.register_instruction(cil.GetAttrNode( + right_local, right_value, "value", node.rvalue.computed_type.name)) + + self.register_instruction(cil.BinaryOperator( + op_local, left_local, right_local, "/")) + + # Allocate Int result + self.register_instruction(cil.AllocateNode( + 'Int', self.context.get_type('Int').tag, result_local)) + result_init = self.define_internal_local( + scope=scope, name="result_init") + self.register_instruction(cil.CallNode(result_init, 'Int_init', [ + cil.ArgNode(op_local), cil.ArgNode(result_local)], "Int")) + + return result_local @visitor.when(LessNode) def visit(self, node, scope): - return self._define_binary_node(node, scope, cil.LessNode) + result_local = self.define_internal_local(scope=scope, name="result") + op_local = self.define_internal_local(scope=scope, name="op") + left_local = self.define_internal_local(scope=scope, name="left") + right_local = self.define_internal_local(scope=scope, name="right") + + left_value = self.visit(node.lvalue, scope) + right_value = self.visit(node.rvalue, scope) + + self.register_instruction(cil.GetAttrNode( + left_local, left_value, "value", node.lvalue.computed_type.name)) + self.register_instruction(cil.GetAttrNode( + right_local, right_value, "value", node.rvalue.computed_type.name)) + + self.register_instruction(cil.BinaryOperationNode( + op_local, left_local, right_local, "<")) + + # Allocate Bool result + self.register_instruction(cil.AllocateNode( + 'Bool', self.context.get_type('Bool').tag, result_local)) + result_init = self.define_internal_local( + scope=scope, name="result_init") + self.register_instruction(cil.CallNode(result_init, 'Bool_init', [ + cil.ArgNode(op_local), cil.ArgNode(result_local)], "Bool")) + + return result_local @visitor.when(LessEqNode) def visit(self, node, scope): - return self._define_binary_node(node, scope, cil.LessEqualNode) + result_local = self.define_internal_local(scope=scope, name="result") + op_local = self.define_internal_local(scope=scope, name="op") + left_local = self.define_internal_local(scope=scope, name="left") + right_local = self.define_internal_local(scope=scope, name="right") + + left_value = self.visit(node.lvalue, scope) + right_value = self.visit(node.rvalue, scope) + + self.register_instruction(cil.GetAttrNode( + left_local, left_value, "value", node.lvalue.computed_type.name)) + self.register_instruction(cil.GetAttrNode( + right_local, right_value, "value", node.rvalue.computed_type.name)) + + self.register_instruction(cil.BinaryOperationNode( + op_local, left_local, right_local, "<=")) + + # Allocate Bool result + self.register_instruction(cil.AllocateNode( + 'Bool', self.context.get_type('Bool').tag, result_local)) + result_init = self.define_internal_local( + scope=scope, name="result_init") + self.register_instruction(cil.CallNode(result_init, 'Bool_init', [ + cil.ArgNode(op_local), cil.ArgNode(result_local)], "Bool")) + + return result_local @visitor.when(EqualNode) def visit(self, node, scope): - return self._define_binary_node(node, scope, cil.EqualNode) + result_local = self.define_internal_local(scope=scope, name="result") + op_local = self.define_internal_local(scope=scope, name="op") + left_local = self.define_internal_local(scope=scope, name="left") + right_local = self.define_internal_local(scope=scope, name="right") + + left_value = self.visit(node.lvalue, scope) + right_value = self.visit(node.rvalue, scope) + + if node.lvalue.computed_type.name == 'String': + self.register_instruction(cil.CallNode(op_local, 'String_equals', [ + cil.ArgNode(right_value), cil.ArgNode(left_value)], 'String')) + + # Allocate Bool result + self.register_instruction(cil.AllocateNode( + 'Bool', self.context.get_type('Bool').tag, result_local)) + result_init = self.define_internal_local( + scope=scope, name="result_init") + self.register_instruction(cil.CallNode(result_init, 'Bool_init', [ + cil.ArgNode(op_local), cil.ArgNode(result_local)], "Bool")) + + return result_local + + elif node.lvalue.computed_type.name in ['Int', 'Bool']: + self.register_instruction(cil.GetAttrNode( + left_local, left_value, "value", node.lvalue.computed_type.name)) + self.register_instruction(cil.GetAttrNode( + right_local, right_value, "value", node.rvalue.computed_type.name)) + else: + self.register_instruction(cil.AssignNode(left_local, left_value)) + self.register_instruction(cil.AssignNode(right_local, right_value)) + + self.register_instruction(cil.BinaryOperationNode( + op_local, left_local, right_local, "=")) + + # Allocate Bool result + self.register_instruction(cil.AllocateNode( + 'Bool', self.context.get_type('Bool').tag, result_local)) + result_init = self.define_internal_local( + scope=scope, name="result_init") + self.register_instruction(cil.CallNode(result_init, 'Bool_init', [ + cil.ArgNode(op_local), cil.ArgNode(result_local)], "Bool")) + + return result_local diff --git a/src/code_generator/cil_ast.py b/src/code_generator/cil_ast.py index 8840b269b..c646542e6 100644 --- a/src/code_generator/cil_ast.py +++ b/src/code_generator/cil_ast.py @@ -57,6 +57,14 @@ def __init__(self, local_dest, expr): self.expr = expr +class BinaryOperationNode(InstructionNode): + def __init__(self, local_dest, lvalue, rvalue, op): + self.local_dest = local_dest + self.lvalue = lvalue + self.rvalue = rvalue + self.operator = op + + class ArithExpressionNode(InstructionNode): def __init__(self, dest, left, right): self.dest = dest From 6bd286417f4e4e3f8874bc219a6df118737ebd66 Mon Sep 17 00:00:00 2001 From: livi98 Date: Wed, 23 Feb 2022 05:53:30 +0100 Subject: [PATCH 152/194] fixing let declaration variables in cil --- src/code_generator/COOLToCILVisitor.py | 251 +++++++++++++++++++------ src/code_generator/cil_ast.py | 49 +---- 2 files changed, 201 insertions(+), 99 deletions(-) diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index 1ae45cde2..e995860f3 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -248,16 +248,50 @@ def visit(self, node, scope): result_local = self.visit(expr, scope) return result_local - @visitor.when(LetNode) + @visitor.when(LetInNode) def visit(self, node, scope): - child_scope = scope.expr_dict[node] - for init in node.let_attrs: - self.visit(init, child_scope) + let_scope = scope.create_child() + for var in node.letBody: + self.visit(var, let_scope) + + body_value = self.visit(node.inBody, let_scope) + result_local = self.define_internal_local(scope = scope, name = "let_result") + self.register_instruction(cil.AssignNode(result_local, body_value)) + return result_local - expr, typex = self.visit(node.expr, child_scope) - return expr, typex + @visitor.when(VarDeclarationNode) + def visit(self, node, scope): + instance = None - visitor.when(CaseNode) + if node.type in ['Int', 'Bool']: + instance = self.define_internal_local(scope=scope, name="instance") + self.register_instruction(cil.AllocateNode(node.type,self.context.get_type(node.type).tag, instance)) + value = self.define_internal_local(scope=scope, name="value") + self.register_instruction(cil.LoadIntNode(0,value)) + result_init = self.define_internal_local(scope=scope, name="result_init") + self.register_instruction(cil.CallNode(result_init, f'{node.type}_init', [ cil.ArgNode(value), cil.ArgNode(instance)], node.type)) + elif node.type == 'String': + instance = self.define_internal_local(scope=scope, name="instance") + self.register_instruction(cil.AllocateNode(node.type,self.context.get_type(node.type).tag ,instance)) + value = self.define_internal_local(scope=scope, name="value") + self.register_instruction(cil.LoadStringNode('empty_str',value)) + result_init = self.define_internal_local(scope=scope, name="result_init") + self.register_instruction(cil.CallNode(result_init, f'{node.type}_init', [cil.ArgNode(value), cil.ArgNode(instance)], node.type)) + + if not node.expr is None: + expr_value = self.visit(node.expr, scope) + let_var = self.define_internal_local(scope = scope, name = node.name, cool_var_name= node.name) + self.register_instruction(cil.AssignNode(let_var, expr_value)) + else: + let_var = self.define_internal_local(scope = scope, name = node.name, cool_var_name=node.name) + self.register_instruction(cil.AssignNode(let_var, instance)) + + return let_var + + + + + @visitor.when(CaseNode) def visit(self, node, scope): expr, typex = self.visit(node.expr, scope) @@ -283,54 +317,6 @@ def visit(self, node, scope): self.register_instruction(end_label) return result, typex -# this find_local, find_attribute is from scope, this get_type is separate, need to do it well - visitor.when(VarNode) - - def visit(self, node, scope): - try: - typex = scope.find_local(node.lex).type - name = self.to_variable_name(node.lex) - return name, get_type(typex, self.current_type) - except: - var_info = scope.find_attribute(node.lex) - local_var = self.register_local(var_info.name) - self.register_instruction(cil.GetAttrNode( - 'self', var_info.name, self.current_type.name, local_var, var_info.type.name)) - return local_var, get_type(var_info.type, self.current_type) - - visitor.when(NewNode) - - def visit(self, node, scope): - instance = self.define_internal_local() - typex = self.context.get_type(node.lex) - typex = get_type(typex, self.current_type) - self.register_instruction(cil.AllocateNode(typex.name, instance)) - - if typex.get_all_attributes(): - self.register_instruction(cil.CallNode(typex.name, typex.name, instance, [ - cil.ArgNode(instance)], typex.name)) - - return instance, typex - - @visitor.when(NegationNode) - def visit(self, node, scope): - return self._define_unary_node(node, scope, cil.NotNode) - - @visitor.when(IsVoidNode) - def visit(self, node, scope): - expr_value = self.visit(node.expr, scope) - result_local = self.define_internal_local( - scope=scope, name="isvoid_result") - self.register_instruction(cil.IsVoidNode(result_local, expr_value)) - instance = self.define_internal_local(scope=scope, name="instance") - self.register_instruction(cil.AllocateNode( - 'Bool', self.context.get_type('Bool').tag, instance)) - result_init = self.define_internal_local( - scope=scope, name="result_init") - self.register_instruction(cil.CallNode(result_init, 'Bool_init', [ - cil.ArgNode(result_local), cil.ArgNode(instance)], "Bool")) - return instance - @visitor.when(PlusNode) def visit(self, node, scope): result_local = self.define_internal_local(scope=scope, name="result") @@ -544,3 +530,158 @@ def visit(self, node, scope): cil.ArgNode(op_local), cil.ArgNode(result_local)], "Bool")) return result_local + + @visitor.when(NegationNode) + def visit(self, node, scope): + result_local = self.define_internal_local(scope=scope, name="result") + op_local = self.define_internal_local(scope=scope, name="op") + expr_local = self.define_internal_local(scope=scope) + + expr_value = self.visit(node.expr, scope) + + self.register_instruction(cil.GetAttrNode( + expr_local, expr_value, "value", node.expr.computed_type.name)) + self.register_instruction( + cil.UnaryOperationNode(op_local, expr_local, "~")) + + # Allocate Bool result + self.register_instruction(cil.AllocateNode( + 'Int', self.context.get_type('Int').tag, result_local)) + result_init = self.define_internal_local( + scope=scope, name="result_init") + self.register_instruction(cil.CallNode(result_init, 'Int_init', [ + cil.ArgNode(op_local), cil.ArgNode(result_local)], "Int")) + + return result_local + + @visitor.when(LogicNegationNode) + def visit(self, node, scope): + result_local = self.define_internal_local(scope=scope, name="result") + op_local = self.define_internal_local(scope=scope, name="op") + expr_local = self.define_internal_local(scope=scope) + + expr_value = self.visit(node.expr, scope) + + self.register_instruction(cil.GetAttrNode( + expr_local, expr_value, "value", node.expr.computed_type.name)) + self.register_instruction( + cil.UnaryOperationNode(op_local, expr_local, "not")) + + # Allocate Bool result + self.register_instruction(cil.AllocateNode( + 'Bool', self.context.get_type('Bool').tag, result_local)) + result_init = self.define_internal_local( + scope=scope, name="result_init") + self.register_instruction(cil.CallNode(result_init, 'Bool_init', [ + cil.ArgNode(op_local), cil.ArgNode(result_local)], "Bool")) + + return result_local + + @visitor.when(IsVoidNode) + def visit(self, node, scope): + expr_value = self.visit(node.expr, scope) + result_local = self.define_internal_local( + scope=scope, name="isvoid_result") + self.register_instruction(cil.IsVoidNode(result_local, expr_value)) + instance = self.define_internal_local(scope=scope, name="instance") + self.register_instruction(cil.AllocateNode( + 'Bool', self.context.get_type('Bool').tag, instance)) + result_init = self.define_internal_local( + scope=scope, name="result_init") + self.register_instruction(cil.CallNode(result_init, 'Bool_init', [ + cil.ArgNode(result_local), cil.ArgNode(instance)], "Bool")) + return instance + + @visitor.when(IdNode) + def visit(self, node, scope): + if self.is_defined_param(node.id): + return node.id + elif self.current_type.has_attr(node.id): + result_local = self.define_internal_local( + scope=scope, name=node.id, class_type=self.current_type.name) + self.register_instruction(cil.GetAttrNode( + result_local, 'self', node.id, self.current_type.name)) + return result_local + else: + return scope.find_cil_local(node.id) + + @visitor.when(NewNode) + def visit(self, node, scope): + result_local = self.define_internal_local(scope=scope, name="result") + result_init = self.define_internal_local(scope=scope, name="init") + + if node.id == "SELF_TYPE": + self.register_instruction(cil.AllocateNode( + self.current_type.name, self.current_type.tag, result_local)) + self.register_instruction(cil.CallNode(result_init, f'{self.current_type.name}_init', [ + result_local], self.current_type.name)) + else: + self.register_instruction(cil.AllocateNode( + node.id, self.context.get_type(node.id).tag, result_local)) + self.register_instruction(cil.CallNode(result_init, f'{node.id}_init', [ + cil.ArgNode(result_local)], self.current_type.name)) + + return result_local + + @visitor.when(IntNode) + def visit(self, node, scope): + instance = self.define_internal_local(scope=scope, name="instance") + self.register_instruction(cil.AllocateNode( + 'Int', self.context.get_type('Int').tag, instance)) + value = self.define_internal_local(scope=scope, name="value") + self.register_instruction(cil.LoadIntNode(node.id, value)) + result_init = self.define_internal_local( + scope=scope, name="result_init") + self.register_instruction(cil.CallNode(result_init, 'Int_init', [ + cil.ArgNode(value), cil.ArgNode(instance)], "Int")) + return instance + + @visitor.when(StringNode) + def visit(self, node, scope): + str_name = "" + for s in self.dotdata.keys(): + if self.dotdata[s] == node.id: + str_name = s + break + if str_name == "": + str_name = self.register_data(node.id) + + result_local = self.define_internal_local(scope=scope) + self.register_instruction(cil.LoadStringNode(str_name, result_local)) + instance = self.define_internal_local(scope=scope, name="instance") + self.register_instruction(cil.AllocateNode( + 'String', self.context.get_type('String').tag, instance)) + result_init = self.define_internal_local( + scope=scope, name="result_init") + self.register_instruction(cil.CallNode(result_init, 'String_init', [ + cil.ArgNode(result_local), cil.ArgNode(instance)], "String")) + return instance + + @visitor.when(BoolNode) + def visit(self, node, scope): + boolean = 0 + if str(node.id) == "true": + boolean = 1 + instance = self.define_internal_local(scope=scope, name="instance") + self.register_instruction(cil.AllocateNode( + 'Bool', self.context.get_type('Bool').tag, instance)) + value = self.define_internal_local(scope=scope, name="value") + self.register_instruction(cil.LoadIntNode(boolean, value)) + result_init = self.define_internal_local( + scope=scope, name="result_init") + self.register_instruction(cil.CallNode(result_init, 'Bool_init', [ + cil.ArgNode(value), cil.ArgNode(instance)], "Bool")) + return instance + + @visitor.when(VoidNode) + def visit(self, node, scope): + result_local = self.define_internal_local(scope=scope) + self.register_instruction(cil.LoadStringNode(node.id, result_local)) + instance = self.define_internal_local(scope=scope, name="instance") + self.register_instruction(cil.AllocateNode( + 'String', self.context.get_type('String').tag, instance)) + result_init = self.define_internal_local( + scope=scope, name="result_init") + self.register_instruction(cil.CallNode(result_init, 'Void_init', [ + cil.ArgNode(result_local), cil.ArgNode(instance)], "String")) + return instance diff --git a/src/code_generator/cil_ast.py b/src/code_generator/cil_ast.py index c646542e6..c412e5d38 100644 --- a/src/code_generator/cil_ast.py +++ b/src/code_generator/cil_ast.py @@ -65,53 +65,14 @@ def __init__(self, local_dest, lvalue, rvalue, op): self.operator = op -class ArithExpressionNode(InstructionNode): - def __init__(self, dest, left, right): - self.dest = dest - self.left = left - self.right = right - -# Arith - - -class PlusNode(ArithExpressionNode): - pass - - -class MinusNode(ArithExpressionNode): - pass - - -class StarNode(ArithExpressionNode): - pass - - -class DivNode(ArithExpressionNode): - pass - - -class LessNode(ArithExpressionNode): - pass - - -class LessEqualNode(ArithExpressionNode): - pass - - -class EqualNode(ArithExpressionNode): - pass - - -class NotNode(Node): - def __init__(self, dest, expr): - self.dest = dest +class UnaryOperationNode(InstructionNode): + def __init__(self, local_dest, expr, op): + self.local_dest = local_dest self.expr = expr + self.op = op + -class LogicNotNode(Node): - def __init__(self, dest, expr): - self.dest = dest - self.expr = expr # Attr From 345a87a3d2a5f7ca9c28c7e89dd6d05588e1abf3 Mon Sep 17 00:00:00 2001 From: livi98 Date: Wed, 23 Feb 2022 06:04:06 +0100 Subject: [PATCH 153/194] still have an error in case nodes --- src/code_generator/COOLToCILVisitor.py | 94 ++++++++++++++++---------- src/code_generator/cil_ast.py | 16 ++++- 2 files changed, 72 insertions(+), 38 deletions(-) diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index e995860f3..de2018474 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -253,9 +253,10 @@ def visit(self, node, scope): let_scope = scope.create_child() for var in node.letBody: self.visit(var, let_scope) - + body_value = self.visit(node.inBody, let_scope) - result_local = self.define_internal_local(scope = scope, name = "let_result") + result_local = self.define_internal_local( + scope=scope, name="let_result") self.register_instruction(cil.AssignNode(result_local, body_value)) return result_local @@ -265,57 +266,78 @@ def visit(self, node, scope): if node.type in ['Int', 'Bool']: instance = self.define_internal_local(scope=scope, name="instance") - self.register_instruction(cil.AllocateNode(node.type,self.context.get_type(node.type).tag, instance)) + self.register_instruction(cil.AllocateNode( + node.type, self.context.get_type(node.type).tag, instance)) value = self.define_internal_local(scope=scope, name="value") - self.register_instruction(cil.LoadIntNode(0,value)) - result_init = self.define_internal_local(scope=scope, name="result_init") - self.register_instruction(cil.CallNode(result_init, f'{node.type}_init', [ cil.ArgNode(value), cil.ArgNode(instance)], node.type)) + self.register_instruction(cil.LoadIntNode(0, value)) + result_init = self.define_internal_local( + scope=scope, name="result_init") + self.register_instruction(cil.CallNode(result_init, f'{node.type}_init', [ + cil.ArgNode(value), cil.ArgNode(instance)], node.type)) elif node.type == 'String': instance = self.define_internal_local(scope=scope, name="instance") - self.register_instruction(cil.AllocateNode(node.type,self.context.get_type(node.type).tag ,instance)) + self.register_instruction(cil.AllocateNode( + node.type, self.context.get_type(node.type).tag, instance)) value = self.define_internal_local(scope=scope, name="value") - self.register_instruction(cil.LoadStringNode('empty_str',value)) - result_init = self.define_internal_local(scope=scope, name="result_init") - self.register_instruction(cil.CallNode(result_init, f'{node.type}_init', [cil.ArgNode(value), cil.ArgNode(instance)], node.type)) + self.register_instruction(cil.LoadStringNode('empty_str', value)) + result_init = self.define_internal_local( + scope=scope, name="result_init") + self.register_instruction(cil.CallNode(result_init, f'{node.type}_init', [ + cil.ArgNode(value), cil.ArgNode(instance)], node.type)) if not node.expr is None: expr_value = self.visit(node.expr, scope) - let_var = self.define_internal_local(scope = scope, name = node.name, cool_var_name= node.name) + let_var = self.define_internal_local( + scope=scope, name=node.name, cool_var_name=node.name) self.register_instruction(cil.AssignNode(let_var, expr_value)) else: - let_var = self.define_internal_local(scope = scope, name = node.name, cool_var_name=node.name) + let_var = self.define_internal_local( + scope=scope, name=node.name, cool_var_name=node.name) self.register_instruction(cil.AssignNode(let_var, instance)) return let_var + @visitor.when(CaseNode) + def visit(self, node, scope): + result_local = self.define_internal_local(scope=scope, name="result") + case_expr = self.visit(node.expr, scope) + exit_label = self.get_label() + label = self.get_label() + self.register_instruction(cil.CaseNode(case_expr, label)) - @visitor.when(CaseNode) + tag_lst = [] + option_dict = {} + for option in node.optionList: + tag = self.context.get_type(option.type).tag + tag_lst.append(tag) + option_dict[tag] = option + tag_lst.sort() - def visit(self, node, scope): - expr, typex = self.visit(node.expr, scope) - - result = self.define_internal_local() - end_label = cil.LabelNode(f'end__{self.idx}') - error_label = cil.LabelNode(f'error__{self.idx}') - - isvoid = self.check_void(expr) - self.register_instruction(cil.IfGoToNode(isvoid, error_label.label)) - try: - new_scope = scope.expr_dict[node] - except: - new_scope = scope - sorted_case_list = self.sort_option_nodes_by_type(node.case_list) - for i, case in enumerate(sorted_case_list): - next_label = cil.LabelNode(f'next__{self.idx}_{i}') - expr_i = self.visit( - case, new_scope.create_child(), expr, next_label, typex) - self.register_instruction(cil.AssignNode(result, expr_i)) - self.register_instruction(cil.GoToNode(end_label.label)) - self.register_instruction(next_label) - self.register_instruction(end_label) - return result, typex + for t in reversed(tag_lst): + option = option_dict[t] + self.register_instruction(cil.LabelNode(label)) + label = self.get_label() + + option_type = self.context.get_type(option.type) + self.register_instruction(cil.CaseOptionNode( + case_expr, option_type.tag, option_type.max_tag, label)) + + option_scope = scope.create_child() + option_id = self.define_internal_local( + scope=option_scope, name=option.id, cool_var=option.id) + self.register_instruction(cil.AssignNode(option_id, case_expr)) + expr_result = self.visit(option.expr, option_scope) + + self.register_instruction( + cil.AssignNode(result_local, expr_result)) + self.register_instruction(cil.GoToNode(exit_label)) + + self.register_instruction(cil.LabelNode(label)) + self.register_instruction(cil.GoToNode('case_no_match_error')) + self.register_instruction(cil.LabelNode(exit_label)) + return result_local @visitor.when(PlusNode) def visit(self, node, scope): diff --git a/src/code_generator/cil_ast.py b/src/code_generator/cil_ast.py index c412e5d38..c82c2a1e1 100644 --- a/src/code_generator/cil_ast.py +++ b/src/code_generator/cil_ast.py @@ -72,8 +72,6 @@ def __init__(self, local_dest, expr, op): self.op = op - - # Attr @@ -266,3 +264,17 @@ def __init__(self, s1, s2, result): self.s1 = s1 self.s2 = s2 self.result = result + + +class CaseNode(InstructionNode): + def __init__(self, expr, first_label): + self.expr = expr + self.first_label = first_label + + +class CaseOptionNode(InstructionNode): + def __init__(self, expr, tag, max_tag, next_label): + self.expr = expr + self.tag = tag + self.max_tag = max_tag + self.next_label = next_label From 2f6b6d09cec7b32af7996b54da12c70937cadb23 Mon Sep 17 00:00:00 2001 From: cwjki Date: Wed, 23 Feb 2022 00:30:49 -0500 Subject: [PATCH 154/194] adding formatter --- src/code_generator/formatter.py | 145 ++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 src/code_generator/formatter.py diff --git a/src/code_generator/formatter.py b/src/code_generator/formatter.py new file mode 100644 index 000000000..9b615139d --- /dev/null +++ b/src/code_generator/formatter.py @@ -0,0 +1,145 @@ +def get_formatter(): + + class PrintVisitor(object): + @visitor.on('node') + def visit(self, node): + pass + + @visitor.when(Program) + def visit(self, node): + dottypes = '\n'.join(self.visit(t) for t in node.dottypes.values()) + dotdata = '\n'.join(f'{t}: {node.dotdata[t]}' for t in node.dotdata.keys()) + dotcode = '\n'.join(self.visit(t) for t in node.dotcode) + + return f'.TYPES\n{dottypes}\n\n.DATA\n{dotdata}\n\n.CODE\n{dotcode}' + + @visitor.when(Type) + def visit(self, node): + attributes = '\n\t'.join(f'attribute {x}' for x in node.attributes) + methods = '\n\t'.join(f'method {x} : {node.methods[x]}' for x in node.methods.keys()) + + return f'type {node.name} {{\n\t{attributes}\n\n\t{methods}\n}}' + + @visitor.when(Function) + def visit(self, node): + params = '\n\t'.join(self.visit(x) for x in node.params) + localvars = '\n\t'.join(self.visit(x) for x in node.localvars) + instructions = '\n\t'.join(self.visit(x) for x in node.instructions) + + return f'function {node.name} {{\n\t{params}\n\n\t{localvars}\n\n\t{instructions}\n}}' + + @visitor.when(ParamDec) + def visit(self, node): + return f'PARAM {node.name}' + + @visitor.when(LocalDec) + def visit(self, node): + return f'LOCAL {node.name}' + + @visitor.when(Assign) + def visit(self, node): + return f'{node.local_dest} = {node.right_expr}' + + @visitor.when(IfGoto) + def visit(self, node): + return f'IF {node.variable} GOTO {node.label}' + + @visitor.when(Label) + def visit(self, node): + return f'LABEL {node.label}' + + @visitor.when(Goto) + def visit(self, node): + return f'GOTO {node.label}' + + @visitor.when(UnaryOperator) + def visit(self, node): + return f'{node.local_dest} = {node.op} {node.expr_value}' + + @visitor.when(BinaryOperator) + def visit(self, node): + return f'{node.local_dest} = {node.left} {node.op} {node.right}' + + @visitor.when(Allocate) + def visit(self, node): + return f'{node.local_dest} = ALLOCATE {node.type}' + + @visitor.when(LoadStr) + def visit(self, node): + return f'{node.local_dest} = LOAD {node.msg}' + + @visitor.when(LoadInt) + def visit(self, node): + return f'{node.local_dest} = LOAD {node.num}' + + @visitor.when(LoadVoid) + def visit(self, node): + return f'{node.local_dest} = LOAD VOID' + + @visitor.when(GetAttr) + def visit(self, node): + return f'{node.local_dest} = GetAttr {node.instance} {node.attr} ' + + @visitor.when(SetAttr) + def visit(self, node): + return f'SetAttr {node.instance} {node.attr} {node.value}' + + + @visitor.when(TypeOf) + def visit(self, node): + return f'{node.local_dest} = TYPEOF {node.variable}' + + @visitor.when(Call) + def visit(self, node): + return f'{node.local_dest} = CALL {node.function}' + + @visitor.when(VCall) + def visit(self, node): + return f'{node.local_dest} = VCALL {node.dynamic_type} {node.function} ' + + @visitor.when(Arg) + def visit(self, node): + return f'ARG {node.arg}' + + @visitor.when(Return) + def visit(self, node): + return f'\n RETURN {node.value if node.value is not None else ""}' + + @visitor.when(IsVoid) + def visit(self, node): + return f'{node.result_local} ISVOID {node.expre_value}' + + @visitor.when(Halt) + def visit(self, node): + return 'HALT' + + @visitor.when(Copy) + def visit(self, node): + return f'{node.local_dest} = COPY {node.type}' + + @visitor.when(Length) + def visit(self, node): + return f'{node.result} = LENGTH {node.variable}' + + @visitor.when(Concat) + def visit(self, node): + return f'{node.result} = CONCAT {node.str1} {node.str2}' + + @visitor.when(SubStr) + def visit(self, node): + return f'{node.result} = SUBSTR {node.i} {node.length} {node.string}' + + @visitor.when(StringEquals) + def visit(self, node): + return f'{node.result} = {node.s1} = {node.s2}' + + @visitor.when(Read) + def visit(self, node): + return f'{node.result} = READ' + + @visitor.when(Print) + def visit(self, node): + return f'PRINT {node.variable}' + + printer = PrintVisitor() + return (lambda ast: printer.visit(ast)) From 7e0d75867d59bffcf6fd939b772f860ef17e1779 Mon Sep 17 00:00:00 2001 From: livi98 Date: Wed, 23 Feb 2022 18:41:00 +0100 Subject: [PATCH 155/194] changing all binary operations nodes to the same one --- src/code_generator/BaseCILToMIPSVisitor.py | 344 +++------------------ src/code_generator/CILToMIPSVisitor.py | 294 ++++++------------ src/code_generator/cil_ast.py | 10 +- src/main.py | 8 +- 4 files changed, 142 insertions(+), 514 deletions(-) diff --git a/src/code_generator/BaseCILToMIPSVisitor.py b/src/code_generator/BaseCILToMIPSVisitor.py index 6ace43580..8962589fb 100644 --- a/src/code_generator/BaseCILToMIPSVisitor.py +++ b/src/code_generator/BaseCILToMIPSVisitor.py @@ -1,305 +1,45 @@ -from cil_ast import * -from typing import List, Dict -from enum import Enum class BaseCILToMIPSVisitor: - def __init__(self, inherit_graph): - self.code: list = ['.text', '.globl main', 'main:'] - self.data_code = ['.data'] - self.symbol_table = SymbolTable() - self.reg_desc = RegisterDescriptor() - self.addr_desc = AddressDescriptor() - - self.obj_table: ObjTable = ObjTable(self.dispatch_table) - self.methods = [] - for entry in self.obj_table: - entry: ObjTabEntry - self.methods.extend(entry.dispatch_table_entry) - self.var_address = {'self': AddrType.REF} - - self.loop_idx = 0 - self.first_defined = {'strcopier': True} - self.inherit_graph = inherit_graph - self.space_idx = 0 - - - def is_variable(self, expr): - return isinstance(expr, str) - - def construct_next_use(self, basic_blocks): - next_use = {} - for basic_block in basic_blocks: - for x in self.symbol_table: - self.symbol_table[x].is_live = False - self.symbol_table[x].next_use = None - - for inst in reversed(basic_block): - in1 = inst.in1 if self.is_variable(inst.in1) else None - in2 = inst.in2 if self.is_variable(inst.in2) else None - out = inst.out if self.is_variable(inst.out) else None - - in1nextuse = None - in2nextuse = None - outnextuse = None - in1islive = False - in2islive = False - outislive = False - - entry_in1 = self.symbol_table.lookup(in1) - entry_in2 = self.symbol_table.lookup(in2) - entry_out = self.symbol_table.lookup(out) - if out is not None: - if entry_out is not None: - outnextuse = entry_out.next_use - outislive = entry_out.is_live - else: - entry_out = SymbolTabEntry(out) - entry_out.next_use = None - entry_out.is_live = False - self.symbol_table.insert(entry_out) - if in1 is not None: - if entry_in1 is not None: - in1nextuse = entry_in1.next_use - in1islive = entry_in1.is_live - else: - entry_in1 = SymbolTabEntry(out) - entry_in1.next_use = inst.index - entry_in1.is_live = True - self.symbol_table.insert(entry_in1) - if in2 is not None: - if entry_in2 is not None: - in2nextuse = entry_in2.next_use - in2islive = entry_in2.is_live - else: - entry_in2 = SymbolTabEntry(in2) - entry_in2.next_use = inst.index - entry_in2.is_live = True - self.symbol_table.insert(entry_in2) - - n_entry = NextUseEntry(in1, in2, out, in1nextuse, in2nextuse, outnextuse, in1islive, in2islive, outislive) - next_use[inst.index] = n_entry - return next_use - - - def get_reg(self, inst): - if self.is_variable(inst.in1): - in1_reg = self.get_reg_var(inst.in1) - if self.is_variable(inst.in2): - in2_reg = self.get_reg_var(inst.in2) - - def used_registers(self): - return [(k, v) for k, v in self.registers.items() if v is not None] - - def save_var_code(self, var): - memory, register, _= self.addr_desc.get_var_storage(var) - self.code.append(f"sw ${register}, -{memory}($fp)") - - def insert_register(self, register, content): - self.registers[register] = content - - def empty_registers(self, save=True): - registers = self.reg_desc.used_registers() - for reg, var in registers: - if save: - self.save_var_code(var) - self.addr_desc.set_var_reg(var, None) - self.reg_desc.insert_register(reg, None) - - def get_type(self, xtype): - if xtype == 'Int': - return AddrType.INT - elif xtype == 'Bool': - return AddrType.BOOL - elif xtype == 'String': - return AddrType.STR - return AddrType.REF - - - def is_int(self, expr): - return isinstance(expr, int) - - def save_to_register(self, expr): - if self.is_int(expr): - self.code.append(f'li $t9, {expr}') - return 't9' - elif self.is_variable(expr): - return self.addr_desc.get_var_reg(expr) - - -class AddrType(Enum): - REF = 1, - STR = 2, - BOOL = 3, - INT = 4, - VOID = 5 - - -class NextUseEntry: - def __init__(self, in1, in2, out, in1nextuse, in2nextuse, outnextuse, in1islive, in2islive, outislive): - self.in1 = in1 - self.in2 = in2 - self.out = out - self.in1nextuse = in1nextuse - self.in2nextuse = in2nextuse - self.outnextuse = outnextuse - self.in1islive = in1islive - self.in2islive = in2islive - self.outislive = outislive - - -class ObjTabEntry: - def __init__(self, name, methods, attrs): - self.class_tag: str = name - self.size: int = 3 + len(attrs) - self.dispatch_table_size = len(methods) - self.dispatch_table_entry = methods - self.attrs = attrs - - @property - def class_tag_offset(self): - return 0 - - @property - def size_offset(self): - return 1 - - @property - def dispatch_ptr_offset(self): - return 2 - - def attr_offset(self, attr): - return self.attrs.index(attr) + 3 - - def method_offset(self, meth): - return self.dispatch_table_entry.index(meth) - - -class ObjTable: - def __init__(self, dispatch_table): - self.objects: Dict[str, ObjTabEntry] = {} - self.dispatch_table = dispatch_table - - def initialize_built_in(self): - object_methods = [ - 'function_abort_Object', - 'function_type_name_Object', - 'function_copy_Object'] - io_methods = [ - 'function_out_string_IO', - 'function_out_int_IO', - 'function_in_string_IO', - 'function_in_int_IO'] - str_methods = [ - 'function_length_String', - 'function_concat_String', - 'function_substr_String' ] - return { - 'Int': ObjTabEntry('Int', [], []), - 'Bool': ObjTabEntry('Bool', [], []), - 'IO': ObjTabEntry('IO', io_methods, []), - 'String': ObjTabEntry('String', str_methods, []), - 'Object': ObjTabEntry('Object', object_methods, []) - } - - def add_entry(self, name, methods, attrs): - methods = [y for x, y in methods] - attrs = [x for x, y in attrs] - self.objects[name] = ObjTabEntry(name, methods, attrs) - self.dispatch_table.add_class(name, methods) - - def size_of_entry(self, name): - return self.objects[name].size - - def __getitem__(self, item) -> ObjTabEntry: - return self.objects[item] - - def __iter__(self): - return iter(self.objects.values()) - - -class RegisterDescriptor: def __init__(self): - registers = ['t0', 't1', 't2', 't3', 't4', 't5', 't6', 't7', 'a1', 'a2', 'a3', \ - 's0', 's1', 's2', 's3', 's4', 's5', 's6', 's7', 'v1'] - self.registers = {reg: None for reg in registers} - - def insert_register(self, register:str, content:str): - self.registers[register] = content - - def get_content(self, register: str): - return self.registers[register] - - def find_empty_reg(self): - for k, v in self.registers.items(): - if v is None: - return k - - def used_registers(self): - return [(k, v) for k, v in self.registers.items() if v is not None] - - def empty_registers(self): - for k in self.registers: - self.registers[k] = None - - -class AddressDescriptor: - def __init__(self): - self.vars = {} - - def insert_var(self, name, address, register=None, stack=None): - if address is not None: - self.vars[name] = [4*address, register, stack] - else: - self.vars[name] = [address, register, stack] - - def get_addr(self, name): - return self.vars[name][0] - - def set_addr(self, name, addr): - self.vars[name][0] = 4*addr - - def get_var_reg(self, var): - return self.vars[var][1] - - def set_var_reg(self, name, reg): - self.vars[name][1] = reg - - def get_var_stack(self, name): - return self.vars[name][2] - - def set_var_stack(self, name, stack_pos): - self.vars[name][1] = stack_pos - - def get_var_storage(self, name): - return self.vars[name] - - - - -class SymbolTabEntry: - def __init__(self, name, is_live=False, next_use=None): - self.name = name - self.is_live = is_live - self.next_use = next_use - -class SymbolTable: - def __init__(self, entries = None): - values = entries if entries is not None else [] - self.entries = {v.name: v for v in values} - - def lookup(self, entry_name: str) -> SymbolTabEntry: - if entry_name != None: - if entry_name in self.entries.keys(): - return self.entries[entry_name] - - def insert(self, entry): - self.entries[entry.name] = entry - - def insert_name(self, name): - self.entries[name] = SymbolTabEntry(name) - - def __getitem__(self, item): - return self.entries[item] - - def __iter__(self): - return iter(self.entries) \ No newline at end of file + self.mips_code = '' + self.text = '' + self.data = '' + self.mips_operators = { + '+': 'add', + '-': 'sub', + '*': 'mul', + '/': 'div', + '<': 'slt', + '<=': 'sle', + '=': 'seq', + } + self.current_function = None + self.types = None + self.attr_offset = {} + self.method_offset = {} + self.var_offset = {} + self.runtime_errors = {} + self.register_runtime_errors() + + def is_param(self, name): + return name in self.current_function.params + + def register_runtime_errors(self): + self.runtime_errors[ + 'dispatch_void'] = 'Runtime Error: A dispatch (static or dynamic) on void' + self.runtime_errors['case_void'] = 'Runtime Error: A case on void' + self.runtime_errors['case_no_match'] = 'Runtime Error: Execution of a case statement without a matching branch' + self.runtime_errors['div_zero'] = 'Runtime Error: Division by zero' + self.runtime_errors['substr'] = 'Runtime Error: Substring out of range' + self.runtime_errors['heap'] = 'Runtime Error: Heap overflow' + for error in self.runtime_errors: + self.data += f'{error}: .asciiz "{self.runtime_errors[error]}"\n' + self.generate_runtime_error(error) + + def generate_runtime_error(self, error): + self.text += f'{error}_error:\n' + self.text += f'la $a0 {error}\n' + self.text += f'li $v0, 4\n' + self.text += 'syscall\n' + self.text += 'li $v0, 10\n' + self.text += 'syscall\n' diff --git a/src/code_generator/CILToMIPSVisitor.py b/src/code_generator/CILToMIPSVisitor.py index e98427fb7..adad649f8 100644 --- a/src/code_generator/CILToMIPSVisitor.py +++ b/src/code_generator/CILToMIPSVisitor.py @@ -2,6 +2,7 @@ from utils import visitor import cil_ast as cil + class CILToMIPSVisitor(BaseCILToMIPSVisitor): @visitor.on('node') def visit(self, node): @@ -9,216 +10,99 @@ def visit(self, node): @visitor.when(cil.ProgramNode) def visit(self, node): - #.TYPE - for type_ in node.dottypes: - self.visit(type_) - self.save_meth_addr(node.dotcode) - self.data_code.append(f"type_Void: .asciiz \"Void\"") - self.save_types_addr(node.dottypes) - #.DATA - for data in node.dotdata: - self.visit(data) - #.CODE - for code in node.dotcode: - self.visit(code) - self.initialize_runtime_errors() - return self.data_code, self.code + self.types = node.dottypes + self.data += 'temp_string: .space 2048\n' + self.data += 'void: .word 0\n' + + for node_type in node.dottypes.values(): + self.visit(node_type) + + for node_data in node.dotdata.keys(): + self.data += f'{node_data}: .asciiz "{node.dotdata[node_data]}"\n' + + for node_function in node.dotcode: + self.visit(node_function) + + self.mips_code = '.data\n' + self.data + '.text\n' + self.text + return self.mips_code.strip() @visitor.when(cil.TypeNode) def visit(self, node): - self.obj_table.add_entry(node.name, node.methods, node.attributes) - self.data_code.append(f"type_{node.name}: .asciiz \"{node.name}\"") + self.data += f'{node.name}_name: .asciiz "{node.name}"\n' + self.data += f'{node.name}_methods:\n' + for method in node.methods.values(): + self.data += f'.word {method}\n' - @visitor.when(cil.DataNode) - def visit(self, node): - self.data_code.append(f"{node.name}: .asciiz \"{node.value}\"") + idx = 0 + self.attr_offset.__setitem__(node.name, {}) + for attr in node.attributes: + self.attr_offset[node.name][attr] = 4*idx + 16 + idx = idx + 1 + + idx = 0 + self.method_offset.__setitem__(node.name, {}) + for met in node.methods: + self.method_offset[node.name][met] = 4*idx + idx = idx + 1 @visitor.when(cil.FunctionNode) def visit(self, node): - self.code.append('') - self.code.append(f'{node.name}:') - self.locals = 0 - self.code.append('# Gets the params from the stack') - self.code.append(f'move $fp, $sp') - n = len(node.params) - for i, param in enumerate(node.params, 1): - self.visit(param, i, n) - self.code.append('# Gets the frame pointer from the stack') - for i, var in enumerate(node.localvars, len(node.params)): - self.visit(var, i) - self.locals = len(node.params) + len(node.localvars) - leaders = self.find_leaders(node.instructions) - blocks = [node.instructions[leaders[i-1]:leaders[i]] for i in range(1, len(leaders))] - self.next_use = self.construct_next_use(blocks) - for block in blocks: - self.block = block - for inst in block: - self.inst = inst - self.get_reg(inst) - self.visit(inst) - inst = block[-1] - if not (isinstance(inst, cil.GoToNode) or isinstance(inst, cil.IfGoToNode) or isinstance(inst, cil.ReturnNode) \ - or isinstance(inst, cil.CallNode) or isinstance(inst, cil.VCallNode)): - self.empty_registers() + self.current_function = node + self.var_offset.__setitem__(self.current_function.name, {}) + + for idx, var in enumerate(self.current_function.localvars + self.current_function.params): + self.var_offset[self.current_function.name][var.name] = (idx + 1)*4 + + self.text += f'{node.name}:\n' + # save space for locals + self.text += f'addi $sp, $sp, {-4 * len(node.localvars)}\n' + self.text += 'addi $sp, $sp, -4\n' # save return address + self.text += 'sw $ra, 0($sp)\n' + + for instruction in node.instructions: + self.visit(instruction) + + self.text += 'lw $ra, 0($sp)\n' # recover return address + total = 4 * len(node.localvars) + 4 * len(node.params) + 4 + # pop locals,parameters,return address from the stack + self.text += f'addi $sp, $sp, {total}\n' + self.text += 'jr $ra\n' @visitor.when(cil.ParamNode) - def visit(self, node, idx, length): - self.symbol_table.insert_name(node.name) - self.var_address[node.name] = self.get_type(node.type) - self.code.append(f'# Pops the register with the param value {node.name}') - self.code.append('addiu $fp, $fp, 4') - self.addr_desc.insert_var(node.name, length-idx) + def visit(self, node): + pass @visitor.when(cil.LocalNode) def visit(self, node, idx): - self.symbol_table.insert_name(node.name) - self.addr_desc.insert_var(node.name, idx) - self.code.append(f'# Updates stack pointer pushing {node.name} to the stack') - self.code.append(f'addiu $sp, $sp, -4') + pass @visitor.when(cil.AssignNode) def visit(self, node): - rdest = self.addr_desc.get_var_reg(node.dest) - self.code.append(f'# Moving {node.source} to {node.dest}') - if self.is_variable(node.source): - rsrc = self.addr_desc.get_var_reg(node.source) - self.code.append(f'move ${rdest}, ${rsrc}') - self.var_address[node.dest] = self.var_address[node.source] - elif self.is_int(node.source): - self.code.append(f'li ${rdest}, {node.source}') - self.var_address[node.dest] = AddrType.INT - self.save_var_code(node.dest) - - @visitor.when(cil.PlusNode) - def visit(self, node): - rdest = self.addr_desc.get_var_reg(node.dest) - self.code.append(f'# {node.dest} <- {node.left} + {node.right}') - if self.is_variable(node.left): - rleft = self.addr_desc.get_var_reg(node.left) - if self.is_variable(node.right): - rright = self.addr_desc.get_var_reg(node.right) - self.code.append(f"add ${rdest}, ${rleft}, ${rright}") - elif self.is_int(node.right): - self.code.append(f"addi ${rdest}, ${rleft}, {node.right}") - elif self.is_int(node.left): - if self.is_int(node.right): - self.code.append(f"li ${rdest}, {node.left + node.right}") - elif self.is_variable(node.right): - rright = self.addr_desc.get_var_reg(node.right) - self.code.append(f"addi ${rdest}, ${rright}, {node.left}") - self.var_address[node.dest] = AddrType.INT - - @visitor.when(cil.MinusNode) - def visit(self, node): - rdest = self.addr_desc.get_var_reg(node.dest) - self.code.append(f'# {node.dest} <- {node.left} - {node.right}') - if self.is_variable(node.left): - rleft = self.addr_desc.get_var_reg(node.left) - if self.is_variable(node.right): - rright = self.addr_desc.get_var_reg(node.right) - self.code.append(f"sub ${rdest}, ${rleft}, ${rright}") - elif self.is_int(node.right): - self.code.append(f"addi ${rdest}, ${rleft}, -{node.right}") - elif self.is_int(node.left): - if self.is_int(node.right): - self.code.append(f"li ${rdest}, {node.left-node.right}") - elif self.is_variable(node.right): - rright = self.addr_desc.get_var_reg(node.right) - self.code.append(f"sub $t9, $zero, {rright}") - self.code.append(f"addi ${rdest}, {node.left}, $t9") - self.var_address[node.dest] = AddrType.INT - - @visitor.when(cil.StarNode) - def visit(self, node): - self.code.append(f'# {node.dest} <- {node.left} * {node.right}') - rdest = self.addr_desc.get_var_reg(node.dest) - if self.is_int(node.left) and self.is_int(node.right): - self.code.append(f"li ${rdest}, {node.left*node.right}") + offset = self.var_offset[self.current_function.name][node.local_dest] + if node.expr: + if isinstance(node.expr, int): + self.text += f'li $t1, {node.expr}\n' + else: + right_offset = self.var_offset[self.current_function.name][node.expr] + self.text += f'lw $t1, {right_offset}($sp)\n' else: - if self.is_variable(node.left): - rleft = self.addr_desc.get_var_reg(node.left) - if self.is_variable(node.right): - rright = self.addr_desc.get_var_reg(node.right) - elif self.is_int(node.right): - self.code.append(f"li $t9, {node.right}") - rright = 't9' - elif self.is_int(node.left): - rright = self.addr_desc.get_var_reg(node.right) - self.code.append(f"li $t9, {node.left}") - rleft = 't9' - self.code.append(f"mult ${rleft}, ${rright}") - self.code.append(f"mflo ${rdest}") - self.var_address[node.dest] = AddrType.INT - - @visitor.when(cil.DivNode) - def visit(self, node): - self.code.append(f'# {node.dest} <- {node.left} / {node.right}') - rdest = self.addr_desc.get_var_reg(node.dest) - if self.is_int(node.left) and self.is_int(node.right): - try: - self.code.append(f"li ${rdest}, {node.left/node.right}") - except ZeroDivisionError: - self.code.append('la $a0, zero_error') - self.code.append('j .raise') - else: - if self.is_variable(node.left): - rleft = self.addr_desc.get_var_reg(node.left) - if self.is_variable(node.right): - rright = self.addr_desc.get_var_reg(node.right) - elif self.is_int(node.right): - self.code.append(f"li $t9, {node.right}") - rright = 't9' - elif self.is_int(node.left): - rright = self.addr_desc.get_var_reg(node.right) - self.code.append(f"li $t9, {node.left}") - rleft = 't9' - self.code.append('la $a0, zero_error') - self.code.append(f'beqz ${rright}, .raise') - self.code.append(f"div ${rleft}, ${rright}") - self.code.append(f"mflo ${rdest}") - self.var_address[node.dest] = AddrType.INT - - @visitor.when(cil.LessNode) - def visit(self, node): - self.code.append(f'# {node.dest} <- {node.left} < {node.right}') - rdest = self.addr_desc.get_var_reg(node.dest) - if self.is_variable(node.left): - rleft = self.addr_desc.get_var_reg(node.left) - if self.is_variable(node.right): - rright = self.addr_desc.get_var_reg(node.right) - self.code.append(f"slt ${rdest}, ${rleft}, ${rright}") - elif self.is_int(node.right): - self.code.append(f"li $t9, {node.right}") - self.code.append(f"slt ${rdest}, ${rleft}, $t9") - elif self.is_int(node.left): - if self.is_int(node.right): - self.code.append(f"li ${rdest}, {int(node.left < node.right)}") - elif self.is_variable(node.right): - rright = self.addr_desc.get_var_reg(node.right) - self.code.append(f"li $t9, {node.left}") - self.code.append(f"slt ${rdest}, $t9, ${rright}") - self.var_address[node.dest] = AddrType.BOOL + self.text += f'la $t1, void\n' - @visitor.when(cil.LessEqualNode) + self.text += f'sw $t1, {offset}($sp)\n' + + @visitor.when(cil.BinaryOperationNode) def visit(self, node): - self.code.append(f'# {node.dest} <- {node.left} <= {node.right}') - rdest = self.addr_desc.get_var_reg(node.dest) - if self.is_variable(node.left): - rleft = self.addr_desc.get_var_reg(node.left) - if self.is_variable(node.right): - rright = self.addr_desc.get_var_reg(node.right) - self.code.append(f"sle ${rdest}, ${rleft}, ${rright}") - elif self.is_int(node.right): - self.code.append(f"li $t9, {node.right}") - self.code.append(f"sle ${rdest}, ${rleft}, $t9") - elif self.is_int(node.left): - if self.is_int(node.right): - self.code.append(f"li ${rdest}, {int(node.left <= node.right)}") - elif self.is_variable(node.right): - rright = self.addr_desc.get_var_reg(node.right) - self.code.append(f"li $t9, {node.left}") - self.code.append(f"sle ${rdest}, $t9, ${rright}") - self.var_address[node.dest] = AddrType.BOOL + mips_comm = self.mips_operators[node.op] + left_offset = self.var_offset[self.current_function.name][node.lvalue] + right_offset = self.var_offset[self.current_function.name][node.rvalue] + self.text += f'lw $a0, {left_offset}($sp)\n' + self.text += f'lw $t1, {right_offset}($sp)\n' + if node.op == '/': + self.text += 'beq $t1, 0, div_zero_error\n' + self.text += f'{mips_comm} $a0, $a0, $t1\n' + result_offset = self.var_offset[self.current_function.name][node.local_dest] + self.text += f'sw $a0, {result_offset}($sp)\n' + @visitor.when(cil.EqualNode) def visit(self, node): @@ -237,7 +121,8 @@ def visit(self, node): self.code.append(f"seq ${rdest}, ${rleft}, $t9") elif self.is_int(node.left): if self.is_int(node.right): - self.code.append(f"li ${rdest}, {int(node.left == node.right)}") + self.code.append( + f"li ${rdest}, {int(node.left == node.right)}") elif self.is_variable(node.right): rright = self.addr_desc.get_var_reg(node.right) self.code.append(f"li $t9, {node.left}") @@ -286,19 +171,21 @@ def visit(self, node): def visit(self, node): rdest = self.addr_desc.get_var_reg(node.dest) self.var_address[node.dest] = AddrType.REF - self.code.append('# Syscall to allocate memory of the object entry in heap') + self.code.append( + '# Syscall to allocate memory of the object entry in heap') self.code.append('li $v0, 9') size = 4*self.obj_table.size_of_entry(node.type) self.code.append(f'li $a0, {size}') self.code.append('syscall') addrs_stack = self.addr_desc.get_addr(node.dest) - self.code.append('# Loads the name of the variable and saves the name like the first field') + self.code.append( + '# Loads the name of the variable and saves the name like the first field') self.code.append(f'la $t9, type_{node.type}') self.code.append(f'sw $t9, 0($v0)') self.code.append(f'# Saves the size of the node') self.code.append(f'li $t9, {size}') self.code.append(f'sw $t9, 4($v0)') - self.code.append(f'move ${rdest}, $v0') + self.code.append(f'move ${rdest}, $v0') idx = self.types.index(node.type) self.code.append('# Adding Type Info addr') self.code.append('la $t8, types') @@ -367,10 +254,11 @@ def visit(self, node): def visit(self, node): self.code.append('# Find the actual name in the dispatch table') reg = self.addr_desc.get_var_reg(node.obj) - self.code.append('# Gets in a0 the actual direction of the dispatch table') + self.code.append( + '# Gets in a0 the actual direction of the dispatch table') self.code.append(f'lw $t9, 8(${reg})') self.code.append('lw $a0, 8($t9)') - function = self.dispatch_table.find_full_name(node.type, node.method) + function = self.dispatch_table.find_full_name(node.type, node.method) index = 4*self.dispatch_table.get_offset(node.type, function) + 4 self.code.append(f'# Saves in t8 the direction of {function}') self.code.append(f'lw $t8, {index}($a0)') @@ -405,10 +293,10 @@ def visit(self, node): self.code.append(f'li $t9, {node.dest}') self.code.append(f'sw $t9, ($sp)') self.code.append('addiu $sp, $sp, -4') - + @visitor.when(cil.ReturnNode) def visit(self, node): - if self.is_variable(node.value): + if self.is_variable(node.value): rdest = self.addr_desc.get_var_reg(node.value) self.code.append(f'move $v0, ${rdest}') elif self.is_int(node.value): @@ -426,7 +314,7 @@ def visit(self, node): self.code.append(f'# Saves in {node.dest} {node.msg}') self.var_address[node.dest] = AddrType.STR self.code.append(f'la ${rdest}, {node.msg}') - + @visitor.when(cil.LengthNode) def visit(self, node): rdest = self.addr_desc.get_var_reg(node.dest) @@ -530,10 +418,10 @@ def visit(self, node): loop = f'loop_{self.loop_idx}' end = f'end_{self.loop_idx}' self.code.append(f'{loop}:') - self.code.append(f'sub $t9, $v0, ${rdest}') + self.code.append(f'sub $t9, $v0, ${rdest}') self.code.append(f'beq $t9, ${rend}, {end}') self.code.append(f'lb $t9, 0($t8)') - self.code.append(f'beqz $t9, {error}') + self.code.append(f'beqz $t9, {error}') self.code.append(f'sb $t9, 0($v0)') self.code.append('addi $t8, $t8, 1') self.code.append(f'addi $v0, $v0, 1') diff --git a/src/code_generator/cil_ast.py b/src/code_generator/cil_ast.py index c82c2a1e1..43ed4cf91 100644 --- a/src/code_generator/cil_ast.py +++ b/src/code_generator/cil_ast.py @@ -20,10 +20,10 @@ def __init__(self, name): # .DATA -class DataNode(Node): - def __init__(self, vname, value): - self.name = vname - self.value = value +# class DataNode(Node): +# def __init__(self, vname, value): +# self.name = vname +# self.value = value # .CODE @@ -62,7 +62,7 @@ def __init__(self, local_dest, lvalue, rvalue, op): self.local_dest = local_dest self.lvalue = lvalue self.rvalue = rvalue - self.operator = op + self.op = op class UnaryOperationNode(InstructionNode): diff --git a/src/main.py b/src/main.py index 232843695..fec071691 100644 --- a/src/main.py +++ b/src/main.py @@ -6,7 +6,7 @@ from semantic.visitors.typeChecker import TypeChecker from semantic.visitors.typeCollector import TypeCollector from semantic.visitors.varCollector import VarCollector -# from code_generator.COOLToCILVisitor import COOLToCILVisitor +from code_generator.COOLToCILVisitor import COOLToCILVisitor from utils.errors import SemanticError @@ -63,10 +63,10 @@ def main(_input, _output): raise Exception() # Code Generation + coolToCIL = COOLToCILVisitor(context) + cilAST = coolToCIL.visit(ast, scope) - # coolToCIL = COOLToCILVisitor(context) - # cilAST = coolToCIL.visit(ast, scope) - + # ast, errors, context, scope = SemanticAn if __name__ == "__main__": From d20da2c9530b315f818d293dfbcd9377baba0a65 Mon Sep 17 00:00:00 2001 From: livi98 Date: Wed, 23 Feb 2022 18:52:52 +0100 Subject: [PATCH 156/194] fixing label and go to --- src/code_generator/CILToMIPSVisitor.py | 157 +++++++++---------------- 1 file changed, 58 insertions(+), 99 deletions(-) diff --git a/src/code_generator/CILToMIPSVisitor.py b/src/code_generator/CILToMIPSVisitor.py index adad649f8..db29e4bad 100644 --- a/src/code_generator/CILToMIPSVisitor.py +++ b/src/code_generator/CILToMIPSVisitor.py @@ -103,128 +103,87 @@ def visit(self, node): result_offset = self.var_offset[self.current_function.name][node.local_dest] self.text += f'sw $a0, {result_offset}($sp)\n' - - @visitor.when(cil.EqualNode) + @visitor.when(cil.UnaryOperationNode) def visit(self, node): - self.code.append(f'# {node.dest} <- {node.left} = {node.right}') - if self.is_variable(node.left) and self.is_variable(node.right) and self.var_address[node.left] == AddrType.STR and self.var_address[node.right] == AddrType.STR: - self.compare_strings(node) + expr_offset = self.var_offset[self.current_function.name][node.expr] + self.text += f'lw $t1, {expr_offset}($sp)\n' + if node.op == '~': + self.text += f'xor $a0, $t1, 1\n' else: - rdest = self.addr_desc.get_var_reg(node.dest) - if self.is_variable(node.left): - rleft = self.addr_desc.get_var_reg(node.left) - if self.is_variable(node.right): - rright = self.addr_desc.get_var_reg(node.right) - self.code.append(f"seq ${rdest}, ${rleft}, ${rright}") - elif self.is_int(node.right): - self.code.append(f"li $t9, {node.right}") - self.code.append(f"seq ${rdest}, ${rleft}, $t9") - elif self.is_int(node.left): - if self.is_int(node.right): - self.code.append( - f"li ${rdest}, {int(node.left == node.right)}") - elif self.is_variable(node.right): - rright = self.addr_desc.get_var_reg(node.right) - self.code.append(f"li $t9, {node.left}") - self.code.append(f"seq ${rdest}, $t9, ${rright}") - self.var_address[node.dest] = AddrType.BOOL - - @visitor.when(cil.NotNode) - def visit(self, node): - rdest = self.addr_desc.get_var_reg(node.dest) - rsrc = self.save_to_register(node.expr) - self.code.append(f'# {node.dest} <- not {node.expr}') - self.code.append(f'beqz ${rsrc}, false_{self.loop_idx}') - self.code.append(f'li ${rdest}, 0') - self.code.append(f'j end_{self.loop_idx}') - self.code.append(f'false_{self.loop_idx}:') - self.code.append(f'li ${rdest}, 1') - self.code.append(f'end_{self.loop_idx}:') - self.loop_idx += 1 - self.var_address[node.dest] = AddrType.BOOL + self.text += f'neg $a0, $t1 \n' + + result_offset = self.var_offset[self.current_function.name][node.local_dest] + self.text += f'sw $a0, {result_offset}($sp)\n' @visitor.when(cil.GetAttrNode) def visit(self, node): - self.code.append(f'# {node.dest} <- GET {node.obj} . {node.attr}') - rdest = self.addr_desc.get_var_reg(node.dest) - self.var_address[node.dest] = self.get_type(node.attr_type) - rsrc = self.addr_desc.get_var_reg(node.obj) - attr_offset = 4*self.get_attr_offset(node.attr, node.type_name) - self.code.append(f'lw ${rdest}, {attr_offset}(${rsrc})') + self_offset = self.var_offset[self.current_function.name][node.instance] + self.text += f'lw $t0, {self_offset}($sp)\n' + + attr_offset = self.attr_offset[node.static_type][node.attr] + self.text += f'lw $t1, {attr_offset}($t0)\n' + + result_offset = self.var_offset[self.current_function.name][node.local_dest] + self.text += f'sw $t1, {result_offset}($sp)\n' @visitor.when(cil.SetAttrNode) def visit(self, node): - self.code.append(f'# {node.obj} . {node.attr} <- SET {node.value}') - rdest = self.addr_desc.get_var_reg(node.obj) - attr_offset = 4*self.get_attr_offset(node.attr, node.type_name) - if self.is_variable(node.value): - rsrc = self.addr_desc.get_var_reg(node.value) - elif self.is_int(node.value): - self.code.append(f'li $t9, {node.value}') - rsrc = 't9' - elif self.is_void(node.value): - self.code.append(f'la $t9, type_{VOID_NAME}') - rsrc = 't9' - self.code.append(f'sw ${rsrc}, {attr_offset}(${rdest})') + self_offset = self.var_offset[self.current_function.name][node.instance] + self.text += f'lw $t0, {self_offset}($sp)\n' + + if node.value: + value_offset = self.var_offset[self.current_function.name][node.value] + self.text += f'lw $t1, {value_offset}($sp)\n' + else: + self.text += f'la $t1, void\n' + + attr_offset = self.attr_offset[node.static_type][node.attr] + self.text += f'sw $t1, {attr_offset}($t0)\n' @visitor.when(cil.AllocateNode) def visit(self, node): - rdest = self.addr_desc.get_var_reg(node.dest) - self.var_address[node.dest] = AddrType.REF - self.code.append( - '# Syscall to allocate memory of the object entry in heap') - self.code.append('li $v0, 9') - size = 4*self.obj_table.size_of_entry(node.type) - self.code.append(f'li $a0, {size}') - self.code.append('syscall') - addrs_stack = self.addr_desc.get_addr(node.dest) - self.code.append( - '# Loads the name of the variable and saves the name like the first field') - self.code.append(f'la $t9, type_{node.type}') - self.code.append(f'sw $t9, 0($v0)') - self.code.append(f'# Saves the size of the node') - self.code.append(f'li $t9, {size}') - self.code.append(f'sw $t9, 4($v0)') - self.code.append(f'move ${rdest}, $v0') - idx = self.types.index(node.type) - self.code.append('# Adding Type Info addr') - self.code.append('la $t8, types') - self.code.append(f'lw $v0, {4*idx}($t8)') - self.code.append(f'sw $v0, 8(${rdest})') + amount = len(self.types[node.type].attributes) + 4 + self.text += f'li $a0, {amount * 4}\n' + self.text += f'li $v0, 9\n' + self.text += f'syscall\n' + self.text += 'bge $v0, $sp heap_error\n' + self.text += f'move $t0, $v0\n' + + # Initialize Object + self.text += f'li $t1, {node.tag}\n' + self.text += f'sw $t1, 0($t0)\n' + self.text += f'la $t1, {node.type}_name\n' + self.text += f'sw $t1, 4($t0)\n' + self.text += f'li $t1, {amount}\n' + self.text += f'sw $t1, 8($t0)\n' + self.text += f'la $t1, {node.type}_methods\n' + self.text += f'sw $t1, 12($t0)\n' + + offset = self.var_offset[self.current_function.name][node.local_dest] + self.text += f'sw $t0, {offset}($sp)\n' @visitor.when(cil.TypeOfNode) def visit(self, node): - rdest = self.addr_desc.get_var_reg(node.dest) - self.code.append(f'# {node.dest} <- Type of {node.obj}') - if self.is_variable(node.obj): - rsrc = self.addr_desc.get_var_reg(node.obj) - if self.var_address[node.obj] == AddrType.REF: - self.code.append(f'lw ${rdest}, 0(${rsrc})') - elif self.var_address[node.obj] == AddrType.STR: - self.code.append(f'la ${rdest}, type_String') - elif self.var_address[node.obj] == AddrType.INT: - self.code.append(f'la ${rdest}, type_Int') - elif self.var_address[node.obj] == AddrType.BOOL: - self.code.append(f'la ${rdest}, type_Bool') - elif self.is_int(node.obj): - self.code.append(f'la ${rdest}, type_Int') - self.var_address[node.dest] = AddrType.STR + obj_offset = self.var_offset[self.current_function.name][node.instance] + self.text += f'lw $t0, {obj_offset}($sp)\n' + self.text += 'lw $t1, 4($t0)\n' + res_offset = self.var_offset[self.current_function.name][node.local_dest] + self.text += f'sw $t1, {res_offset}($sp)\n' @visitor.when(cil.LabelNode) def visit(self, node): - self.code.append(f'{node.label}:') + self.text += f'{node.label}:\n' @visitor.when(cil.GoToNode) def visit(self, node): - self.empty_registers() - self.code.append(f'j {node.label}') + self.text += f'b {node.label}\n' @visitor.when(cil.IfGoToNode) def visit(self, node): - reg = self.save_to_register(node.cond) - self.code.append(f'# If {node.cond} goto {node.label}') - self.empty_registers() - self.code.append(f'bnez ${reg}, {node.label}') + predicate_offset = self.var_offset[self.current_function.name][node.condition] + self.text += f'lw $t0, {predicate_offset}($sp)\n' + self.text += f'lw $a0, 16($t0)\n' + self.text += f'bnez $a0, {node.label}\n' @visitor.when(cil.CallNode) def visit(self, node): From 9a2ce97e73877d14f7b3e82165f309edb38fde76 Mon Sep 17 00:00:00 2001 From: livi98 Date: Wed, 23 Feb 2022 18:54:22 +0100 Subject: [PATCH 157/194] check the test again --- src/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.py b/src/main.py index fec071691..394b5e205 100644 --- a/src/main.py +++ b/src/main.py @@ -63,8 +63,8 @@ def main(_input, _output): raise Exception() # Code Generation - coolToCIL = COOLToCILVisitor(context) - cilAST = coolToCIL.visit(ast, scope) + # coolToCIL = COOLToCILVisitor(context) + # cilAST = coolToCIL.visit(ast, scope) From caef4afcd1c6a8f3e794129c13f4c6b58b2592a6 Mon Sep 17 00:00:00 2001 From: livi98 Date: Wed, 23 Feb 2022 18:55:45 +0100 Subject: [PATCH 158/194] rechecking the test --- src/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.py b/src/main.py index 394b5e205..20c4d646a 100644 --- a/src/main.py +++ b/src/main.py @@ -6,7 +6,7 @@ from semantic.visitors.typeChecker import TypeChecker from semantic.visitors.typeCollector import TypeCollector from semantic.visitors.varCollector import VarCollector -from code_generator.COOLToCILVisitor import COOLToCILVisitor +# from code_generator.COOLToCILVisitor import COOLToCILVisitor from utils.errors import SemanticError From 52a92106ad699a60ddf945cc587fdf3b04a0ccb8 Mon Sep 17 00:00:00 2001 From: livi98 Date: Wed, 23 Feb 2022 19:14:52 +0100 Subject: [PATCH 159/194] fixing string equals --- src/code_generator/CILToMIPSVisitor.py | 360 ++++++++++++------------- src/code_generator/cil_ast.py | 10 +- 2 files changed, 172 insertions(+), 198 deletions(-) diff --git a/src/code_generator/CILToMIPSVisitor.py b/src/code_generator/CILToMIPSVisitor.py index db29e4bad..9f2647705 100644 --- a/src/code_generator/CILToMIPSVisitor.py +++ b/src/code_generator/CILToMIPSVisitor.py @@ -187,217 +187,191 @@ def visit(self, node): @visitor.when(cil.CallNode) def visit(self, node): - function = self.dispatch_table.find_full_name(node.type, node.function) - self.code.append(f'# Static Dispatch of the method {node.function}') - self.push_register('fp') - self.push_register('ra') - self.code.append('# Push the arguments to the stack') - for arg in reversed(node.args): + self.text += 'move $t0, $sp\n' + + for arg in node.params: self.visit(arg) - self.code.append('# Empty all used registers and saves them to memory') - self.empty_registers() - self.code.append('# This function will consume the arguments') - self.code.append(f'jal {function}') - self.code.append('# Pop ra register of return function of the stack') - self.pop_register('ra') - self.code.append('# Pop fp register from the stack') - self.pop_register('fp') - if node.dest is not None: - self.get_reg_var(node.dest) - rdest = self.addr_desc.get_var_reg(node.dest) - self.code.append('# saves the return value') - self.code.append(f'move ${rdest}, $v0') - self.var_address[node.dest] = self.get_type(node.return_type) + + self.text += f'jal {node.function}\n' + result_offset = self.var_offset[self.current_function.name][node.local_dest] + self.text += f'sw $a1, {result_offset}($sp)\n' @visitor.when(cil.VCallNode) def visit(self, node): - self.code.append('# Find the actual name in the dispatch table') - reg = self.addr_desc.get_var_reg(node.obj) - self.code.append( - '# Gets in a0 the actual direction of the dispatch table') - self.code.append(f'lw $t9, 8(${reg})') - self.code.append('lw $a0, 8($t9)') - function = self.dispatch_table.find_full_name(node.type, node.method) - index = 4*self.dispatch_table.get_offset(node.type, function) + 4 - self.code.append(f'# Saves in t8 the direction of {function}') - self.code.append(f'lw $t8, {index}($a0)') - self.push_register('fp') - self.push_register('ra') - self.code.append('# Push the arguments to the stack') - for arg in reversed(node.args): + self.text += 'move $t0, $sp\n' + + for arg in node.params: self.visit(arg) - self.code.append('# Empty all used registers and saves them to memory') - self.empty_registers() - self.code.append('# This function will consume the arguments') - self.code.append(f'jal $t8') - self.code.append('# Pop ra register of return function of the stack') - self.pop_register('ra') - self.code.append('# Pop fp register from the stack') - self.pop_register('fp') - if node.dest is not None: - self.get_reg_var(node.dest) - rdest = self.addr_desc.get_var_reg(node.dest) - self.code.append('# saves the return value') - self.code.append(f'move ${rdest}, $v0') - self.var_address[node.dest] = self.get_type(node.return_type) + + value_offset = self.var_offset[self.current_function.name][node.instance] + self.text += f'lw $t1, {value_offset}($t0)\n' + self.text += 'la $t0, void\n' + self.text += 'beq $t1, $t0, dispatch_void_error\n' + + self.text += f'lw $t2, 12($t1)\n' + + method_offset = self.method_offset[node.dynamic_type][node.function] + self.text += f'lw $t3, {method_offset}($t2)\n' + + self.text += 'jal $t3\n' + + result_offset = self.var_offset[self.current_function.name][node.local_dest] + self.text += f'sw $a1, {result_offset}($sp)\n' @visitor.when(cil.ArgNode) def visit(self, node): - self.code.append('# The rest of the arguments are push into the stack') - if self.is_variable(node.dest): - self.get_reg_var(node.dest) - reg = self.addr_desc.get_var_reg(node.dest) - self.code.append(f'sw ${reg}, ($sp)') - elif self.is_int(node.dest): - self.code.append(f'li $t9, {node.dest}') - self.code.append(f'sw $t9, ($sp)') - self.code.append('addiu $sp, $sp, -4') + value_offset = self.var_offset[self.current_function.name][node.name] + self.text += f'lw $t1, {value_offset}($t0)\n' + self.text += 'addi $sp, $sp, -4\n' + self.text += 'sw $t1, 0($sp)\n' @visitor.when(cil.ReturnNode) def visit(self, node): - if self.is_variable(node.value): - rdest = self.addr_desc.get_var_reg(node.value) - self.code.append(f'move $v0, ${rdest}') - elif self.is_int(node.value): - self.code.append(f'li $v0, {node.value}') - self.code.append('# Empty all used registers and saves them to memory') - self.empty_registers() - self.code.append('# Removing all locals from stack') - self.code.append(f'addiu $sp, $sp, {self.locals*4}') - self.code.append(f'jr $ra') - self.code.append('') - - @visitor.when(cil.LoadNode) + if node.value: + offset = self.var_offset[self.current_function.name][node.value] + self.text += f'lw $a1, {offset}($sp)\n' + else: + self.text += f'move $a1, $zero\n' + + @visitor.when(cil.LoadStringNode) def visit(self, node): - rdest = self.addr_desc.get_var_reg(node.dest) - self.code.append(f'# Saves in {node.dest} {node.msg}') - self.var_address[node.dest] = AddrType.STR - self.code.append(f'la ${rdest}, {node.msg}') + self.text += f'la $t0, {node.msg}\n' + offset = self.var_offset[self.current_function.name][node.local_dest] + self.text += f'sw $t0, {offset}($sp)\n' + + @visitor.when(cil.LoadIntNode) + def visit(self, node): + self.text += f'li $t0, {node.value}\n' + offset = self.var_offset[self.current_function.name][node.local_dest] + self.text += f'sw $t0, {offset}($sp)\n' @visitor.when(cil.LengthNode) def visit(self, node): - rdest = self.addr_desc.get_var_reg(node.dest) - reg = self.addr_desc.get_var_reg(node.arg) - loop = f'loop_{self.loop_idx}' - end = f'end_{self.loop_idx}' - self.code.append(f'move $t8, ${reg}') - self.code.append('# Determining the length of a string') - self.code.append(f'{loop}:') - self.code.append(f'lb $t9, 0($t8)') - self.code.append(f'beq $t9, $zero, {end}') - self.code.append(f'addi $t8, $t8, 1') - self.code.append(f'j {loop}') - self.code.append(f'{end}:') - self.code.append(f'sub ${rdest}, $t8, ${reg}') - self.loop_idx += 1 + offset = self.var_offset[self.current_function.name][node.variable] + self.text += f'lw $t0, {offset}($sp)\n' + self.text += f'lw $t0, 16($t0)\n' + + self.text += 'li $a0, 0\n' + self.text += 'count_char:\n' + self.text += 'lb $t1, 0($t0)\n' + self.text += 'beqz $t1, finish_chars_count\n' + self.text += 'addi $t0, $t0, 1\n' + self.text += 'addi $a0, $a0, 1\n' + self.text += 'j count_char\n' + self.text += 'finish_chars_count:\n' + + offset = self.var_offset[self.current_function.name][node.result] + self.text += f'sw $a0, {offset}($sp)\n' @visitor.when(cil.ConcatNode) def visit(self, node): - rdest = self.addr_desc.get_var_reg(node.dest) - self.code.append('# Allocating memory for buffer') - self.code.append('li $a0, 356') - self.code.append('li $v0, 9') - self.code.append('syscall') - self.code.append(f'move ${rdest}, $v0') - rsrc1 = self.addr_desc.get_var_reg(node.arg1) - if node.arg2 is not None: - rsrc2 = self.addr_desc.get_var_reg(node.arg2) - self.code.append('# Copy the first string to dest') - var = self.save_reg_if_occupied('a1') - self.code.append(f'move $a0, ${rsrc1}') - self.code.append(f'move $a1, ${rdest}') - self.push_register('ra') - self.code.append('jal strcopier') - if node.arg2 is not None: - self.code.append('# Concat second string on buffers result') - self.code.append(f'move $a0, ${rsrc2}') - self.code.append(f'move $a1, $v0') - self.code.append('jal strcopier') - self.code.append('sb $0, 0($v0)') - self.pop_register('ra') - self.code.append(f'j finish_{self.loop_idx}') - if self.first_defined['strcopier']: - self.code.append('# Definition of strcopier') - self.code.append('strcopier:') - self.code.append('# In a0 is source and in a1 is dest') - self.code.append(f'loop_{self.loop_idx}:') - self.code.append('lb $t8, ($a0)') - self.code.append(f'beq $t8, $zero, end_{self.loop_idx}') - self.code.append('addiu $a0, $a0, 1') - self.code.append('sb $t8, ($a1)') - self.code.append('addiu $a1, $a1, 1') - self.code.append(f'b loop_{self.loop_idx}') - self.code.append(f'end_{self.loop_idx}:') - self.code.append('move $v0, $a1') - self.code.append('jr $ra') - self.first_defined['strcopier'] = False - self.code.append(f'finish_{self.loop_idx}:') - self.load_var_if_occupied(var) - self.loop_idx += 1 + offset_str1 = self.var_offset[self.current_function.name][node.str1] + offset_len1 = self.var_offset[self.current_function.name][node.len1] + + offset_str2 = self.var_offset[self.current_function.name][node.str2] + offset_len2 = self.var_offset[self.current_function.name][node.len2] + + self.text += f'lw $a0, {offset_len1}($sp)\n' + self.text += f'lw $t0, {offset_len2}($sp)\n' + + self.text += 'add $a0, $a0, $t0\n' + self.text += 'addi $a0, $a0, 1\n' + self.text += f'li $v0, 9\n' + self.text += f'syscall\n' + self.text += 'bge $v0, $sp heap_error\n' + self.text += 'move $t3, $v0\n' + + self.text += f'lw $t0, {offset_str1}($sp)\n' + self.text += f'lw $t1, {offset_str2}($sp)\n' + + self.text += 'copy_str1_char:\n' + self.text += 'lb $t2, 0($t0)\n' + self.text += 'sb $t2, 0($v0)\n' + self.text += 'beqz $t2, concat_str2_char\n' + self.text += 'addi $t0, $t0, 1\n' + self.text += 'addi $v0, $v0, 1\n' + self.text += 'j copy_str1_char\n' + + self.text += 'concat_str2_char:\n' + self.text += 'lb $t2, 0($t1)\n' + self.text += 'sb $t2, 0($v0)\n' + self.text += 'beqz $t2, finish_str2_concat\n' + self.text += 'addi $t1, $t1, 1\n' + self.text += 'addi $v0, $v0, 1\n' + self.text += 'j concat_str2_char\n' + self.text += 'finish_str2_concat:\n' + self.text += 'sb $0, ($v0)\n' + + offset = self.var_offset[self.current_function.name][node.result] + self.text += f'sw $t3, {offset}($sp)\n' @visitor.when(cil.SubstringNode) def visit(self, node): - rdest = self.addr_desc.get_var_reg(node.dest) - self.code.append('# Allocating memory for buffer') - self.code.append('li $a0, 356') - self.code.append('li $v0, 9') - self.code.append('syscall') - self.code.append(f'move ${rdest}, $v0') - if self.is_variable(node.begin): - rstart = self.addr_desc.get_var_reg(node.begin) - elif self.is_int(node.begin): - rstart = 't8' - self.code.append(f'li $t8, {node.begin}') - if self.is_variable(node.end): - rend = self.addr_desc.get_var_reg(node.end) - var = None - elif self.is_int(node.end): - var = self.save_reg_if_occupied('a3') - rend = 'a3' - self.code.append(f'li $a3, {node.end}') - self.get_reg_var(node.word) - rself = self.addr_desc.get_var_reg(node.word) - self.code.append("# Getting substring") - start = f'start_{self.loop_idx}' - error = f'error_{self.loop_idx}' - end_lp = f'end_len_{self.loop_idx}' - self.code.append('# Move to the begining') - self.code.append('li $v0, 0') - self.code.append(f'move $t8, ${rself}') - self.code.append(f'{start}:') - self.code.append('lb $t9, 0($t8)') - self.code.append(f'beqz $t9, {error}') - self.code.append('addi $v0, 1') - self.code.append(f'bgt $v0, ${rstart}, {end_lp}') - self.code.append(f'addi $t8, 1') - self.code.append(f'j {start}') - self.code.append(f'{end_lp}:') - self.code.append('# Saving dest') - self.code.append(f'move $v0, ${rdest}') - loop = f'loop_{self.loop_idx}' - end = f'end_{self.loop_idx}' - self.code.append(f'{loop}:') - self.code.append(f'sub $t9, $v0, ${rdest}') - self.code.append(f'beq $t9, ${rend}, {end}') - self.code.append(f'lb $t9, 0($t8)') - self.code.append(f'beqz $t9, {error}') - self.code.append(f'sb $t9, 0($v0)') - self.code.append('addi $t8, $t8, 1') - self.code.append(f'addi $v0, $v0, 1') - self.code.append(f'j {loop}') - self.code.append(f'{error}:') - self.code.append('la $a0, index_error') - self.code.append('li $v0, 4') - self.code.append(f'move $a0, ${rself}') - self.code.append('syscall') - self.code.append('li $v0, 1') - self.code.append(f'move $a0, ${rstart}') - self.code.append('syscall') - self.code.append('li $v0, 1') - self.code.append(f'move $a0, ${rend}') - self.code.append('syscall') - self.code.append('j .raise') - self.code.append(f'{end}:') - self.code.append('sb $0, 0($v0)') - self.load_var_if_occupied(var) - self.loop_idx += 1 + offset_idx = self.var_offset[self.current_function.name][node.i] + offset_len = self.var_offset[self.current_function.name][node.length] + offset_str = self.var_offset[self.current_function.name][node.string] + + self.text += f'lw $a0, {offset_len}($sp)\n' + self.text += 'addi $a0, $a0, 1\n' + self.text += f'li $v0, 9\n' + self.text += f'syscall\n' + self.text += 'bge $v0, $sp heap_error\n' + + self.text += f'lw $t0, {offset_idx}($sp)\n' + self.text += f'lw $t1, {offset_len}($sp)\n' + self.text += f'lw $t4, {offset_str}($sp)\n' + self.text += f'lw $t2, 16($t4)\n' + + self.text += 'bltz $t0, substr_error\n' + + self.text += 'li $a0, 0\n' + self.text += 'jump_str_char:\n' + self.text += f'beq $a0, $t0, finish_index_jump\n' + self.text += 'addi $a0, $a0, 1\n' + self.text += 'addi $t2, $t2, 1\n' + self.text += 'beq $t2, $zero, substr_error\n' + self.text += 'j jump_str_char\n' + self.text += 'finish_index_jump:\n' + self.text += 'li $a0, 0\n' + self.text += 'move $t3, $v0\n' + + self.text += 'copy_substr_char:\n' + self.text += 'beq $a0, $t1 finish_substr_copy\n' + self.text += 'li $t0, 0\n' + self.text += 'lb $t0, 0($t2)\n' + self.text += 'sb $t0, 0($v0)\n' + self.text += 'addi $t2, $t2, 1\n' + self.text += 'beq $t2, $zero, substr_error\n' + self.text += 'addi $v0, $v0, 1\n' + self.text += 'addi $a0, $a0, 1\n' + self.text += 'j copy_substr_char\n' + self.text += 'finish_substr_copy:\n' + self.text += 'sb $0, ($v0)\n' + + offset = self.var_offset[self.current_function.name][node.result] + self.text += f'sw $t3, {offset}($sp)\n' + + @visitor.when(cil.StringEqualsNode) + def visit(self, node): + offset_str1 = self.var_offset[self.current_function.name][node.s1] + offset_str2 = self.var_offset[self.current_function.name][node.s2] + + self.text += f'lw $t1, {offset_str1}($sp)\n' + self.text += f'lw $t2, {offset_str2}($sp)\n' + + self.text += 'compare_str_char:\n' + self.text += 'li $t3, 0\n' + self.text += 'lb $t3, 0($t1)\n' + self.text += 'li $t4, 0\n' + self.text += 'lb $t4, 0($t2)\n' + self.text += 'seq $a0, $t3, $t4\n' + self.text += 'beqz $a0, finish_compare_str\n' + self.text += 'beqz $t3, finish_compare_str\n' + self.text += 'beqz $t4, finish_compare_str\n' + self.text += 'addi $t1, $t1, 1\n' + self.text += 'addi $t2, $t2, 1\n' + self.text += 'j compare_str_char\n' + self.text += 'finish_compare_str:\n' + + offset = self.var_offset[self.current_function.name][node.result] + self.text += f'sw $a0, {offset}($sp)\n' diff --git a/src/code_generator/cil_ast.py b/src/code_generator/cil_ast.py index 43ed4cf91..09494238a 100644 --- a/src/code_generator/cil_ast.py +++ b/src/code_generator/cil_ast.py @@ -208,12 +208,12 @@ def __init__(self, dest, string, n): self.n = n -class SubstringNode(InstructionNode): - def __init__(self, dest, string, begin, final): - self.local_dest = dest - self.begin = begin +class SubStringNode(InstructionNode): + def __init__(self, i, length, string, result): + self.i = i + self.length = length self.string = string - self.final = final + self.result = result class StrNode(InstructionNode): From d4bae9d65840527d516c82902724b7857881e7cb Mon Sep 17 00:00:00 2001 From: livi98 Date: Wed, 23 Feb 2022 21:12:23 +0100 Subject: [PATCH 160/194] handling string and int load and read separatly --- src/code_generator/BaseCoolToCilVisitor.py | 2 +- src/code_generator/CILToMIPSVisitor.py | 122 +++++++++++++++++++-- src/code_generator/COOLToCILVisitor.py | 4 +- src/main.py | 10 +- 4 files changed, 125 insertions(+), 13 deletions(-) diff --git a/src/code_generator/BaseCoolToCilVisitor.py b/src/code_generator/BaseCoolToCilVisitor.py index 508100f39..d8d23996e 100644 --- a/src/code_generator/BaseCoolToCilVisitor.py +++ b/src/code_generator/BaseCoolToCilVisitor.py @@ -1,4 +1,4 @@ -import cil_ast as cil +import code_generator.cil_ast as cil from semantic.semantic import VariableInfo diff --git a/src/code_generator/CILToMIPSVisitor.py b/src/code_generator/CILToMIPSVisitor.py index 9f2647705..acf05e12b 100644 --- a/src/code_generator/CILToMIPSVisitor.py +++ b/src/code_generator/CILToMIPSVisitor.py @@ -1,6 +1,6 @@ -from BaseCILToMIPSVisitor import * +from code_generator.BaseCILToMIPSVisitor import BaseCILToMIPSVisitor +import code_generator.cil_ast as cil from utils import visitor -import cil_ast as cil class CILToMIPSVisitor(BaseCILToMIPSVisitor): @@ -54,17 +54,16 @@ def visit(self, node): self.var_offset[self.current_function.name][var.name] = (idx + 1)*4 self.text += f'{node.name}:\n' - # save space for locals + self.text += f'addi $sp, $sp, {-4 * len(node.localvars)}\n' - self.text += 'addi $sp, $sp, -4\n' # save return address + self.text += 'addi $sp, $sp, -4\n' self.text += 'sw $ra, 0($sp)\n' for instruction in node.instructions: self.visit(instruction) - self.text += 'lw $ra, 0($sp)\n' # recover return address + self.text += 'lw $ra, 0($sp)\n' total = 4 * len(node.localvars) + 4 * len(node.params) + 4 - # pop locals,parameters,return address from the stack self.text += f'addi $sp, $sp, {total}\n' self.text += 'jr $ra\n' @@ -225,6 +224,20 @@ def visit(self, node): self.text += 'addi $sp, $sp, -4\n' self.text += 'sw $t1, 0($sp)\n' + @visitor.when(cil.CaseNode) + def visit(self, node): + offset = self.var_offset[self.current_function.name][node.expr] + self.text += f'lw $t0, {offset}($sp)\n' + self.text += f'lw $t1, 0($t0)\n' + self.text += 'la $a0, void\n' + self.text += f'bne $t1 $a0 {node.first_label}\n' + self.text += 'b case_void_error\n' + + @visitor.when(cil.CaseOptionNode) + def visit(self, node): + self.text += f'blt $t1 {node.tag} {node.next_label}\n' + self.text += f'bgt $t1 {node.max_tag} {node.next_label}\n' + @visitor.when(cil.ReturnNode) def visit(self, node): if node.value: @@ -305,7 +318,7 @@ def visit(self, node): offset = self.var_offset[self.current_function.name][node.result] self.text += f'sw $t3, {offset}($sp)\n' - @visitor.when(cil.SubstringNode) + @visitor.when(cil.SubStringNode) def visit(self, node): offset_idx = self.var_offset[self.current_function.name][node.i] offset_len = self.var_offset[self.current_function.name][node.length] @@ -375,3 +388,98 @@ def visit(self, node): offset = self.var_offset[self.current_function.name][node.result] self.text += f'sw $a0, {offset}($sp)\n' + + @visitor.when(cil.CopyNode) + def visit(self, node): + self_offset = self.var_offset[self.current_function.name][node.type] + self.text += f'lw $t0, {self_offset}($sp)\n' + self.text += f'lw $a0, 8($t0)\n' + self.text += f'mul $a0, $a0, 4\n' + self.text += f'li $v0, 9\n' + self.text += f'syscall\n' + self.text += 'bge $v0, $sp heap_error\n' + self.text += f'move $t1, $v0\n' + + self.text += 'li $a0, 0\n' + self.text += 'lw $t3, 8($t0)\n' + self.text += 'copy_object_word:\n' + self.text += 'lw $t2, 0($t0)\n' + self.text += 'sw $t2, 0($t1)\n' + self.text += 'addi $t0, $t0, 4\n' + self.text += 'addi $t1, $t1, 4\n' + self.text += 'addi $a0, $a0, 1\n' + + self.text += 'blt $a0, $t3, copy_object_word\n' + offset = self.var_offset[self.current_function.name][node.local_dest] + self.text += f'sw $v0, {offset}($sp)\n' + + @visitor.when(cil.IsVoidNode) + def visit(self, node): + self.text += 'la $t0, void\n' + offset = self.var_offset[self.current_function.name][node.expr] + self.text += f'lw $t1, {offset}($sp)\n' + self.text += 'seq $a0, $t0, $t1\n' + res_offset = self.var_offset[self.current_function.name][node.result_local] + self.text += f'sw $a0, {res_offset}($sp)\n' + + @visitor.when(cil.HaltNode) + def visit(self, node): + self.text += 'li $v0, 10\n' + self.text += 'syscall\n' + + @visitor.when(cil.PrintIntNode) + def visit(self, node): + if isinstance(node.value, int): + self.text += f'li $v0 , 1\n' + self.text += f'li $a0 , {node.value}\n' + self.text += f'syscall\n' + else: + var_offset = self.var_offset[self.current_function.name][node.value] + self.text += f'li $v0 , 1\n' + self.text += f'lw $a0 , {var_offset}($sp)\n' + self.text += f'syscall\n' + + @visitor.when(cil.PrintStringNode) + def visit(self, node): + var_offset = self.var_offset[self.current_function.name][node.value] + self.text += f'lw $a0, {var_offset}($sp)\n' + self.text += f'li $v0, 4\n' + self.text += f'syscall\n' + + @visitor.when(cil.ReadIntNode) + def visit(self, node): + read_offset = self.var_offset[self.current_function.name][node.local_dest] + self.text += f'li $v0, 5\n' + self.text += f'syscall\n' + self.text += f'sw $v0, {read_offset}($sp)\n' + + @visitor.when(cil.ReadStringNode) + def visit(self, node): + read_offset = self.var_offset[self.current_function.name][node.local_dest] + self.text += f'la $a0, temp_string\n' + self.text += f'li $a1, 2048\n' + self.text += f'li $v0, 8\n' + self.text += f'syscall\n' + + self.text += 'move $t0, $a0\n' + self.text += 'jump_read_str_char:\n' + self.text += 'li $t1, 0\n' + self.text += 'lb $t1, 0($t0)\n' + self.text += 'beqz $t1, analize_str_end\n' + self.text += 'addi $t0, $t0, 1\n' + self.text += 'j jump_read_str_char\n' + + self.text += 'analize_str_end:\n' + self.text += 'addi $t0, $t0, -1\n' + self.text += 'li $t1, 0\n' + self.text += 'lb $t1, 0($t0)\n' + self.text += 'bne $t1, 10, finish_jump_read_str_char\n' + self.text += 'sb $0, 0($t0)\n' + self.text += 'addi $t0, $t0, -1\n' + self.text += 'lb $t1, 0($t0)\n' + self.text += 'bne $t1, 13, finish_jump_read_str_char\n' + self.text += 'sb $0, 0($t0)\n' + self.text += 'j analize_str_end\n' + self.text += 'finish_jump_read_str_char:\n' + + self.text += f'sw $a0, {read_offset}($sp)\n' diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index de2018474..84e98540e 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -1,5 +1,5 @@ -import cil_ast as cil -from BaseCoolToCilVisitor import BaseCOOLToCILVisitor +import code_generator.cil_ast as cil +from code_generator.BaseCoolToCilVisitor import BaseCOOLToCILVisitor from semantic.semantic import Scope, VariableInfo from utils import visitor from utils.ast import * diff --git a/src/main.py b/src/main.py index 20c4d646a..d1f466473 100644 --- a/src/main.py +++ b/src/main.py @@ -6,7 +6,8 @@ from semantic.visitors.typeChecker import TypeChecker from semantic.visitors.typeCollector import TypeCollector from semantic.visitors.varCollector import VarCollector -# from code_generator.COOLToCILVisitor import COOLToCILVisitor +from code_generator.COOLToCILVisitor import COOLToCILVisitor +from code_generator.CILToMIPSVisitor import CILToMIPSVisitor from utils.errors import SemanticError @@ -66,6 +67,11 @@ def main(_input, _output): # coolToCIL = COOLToCILVisitor(context) # cilAST = coolToCIL.visit(ast, scope) + # cilToMIPS = CILToMIPSVisitor() + # mips_code = cilToMIPS(cilAST) + + # with open(f'{sys.argv[1][:-3]}.mips', 'w') as f: + # f.write(mips_code) # ast, errors, context, scope = SemanticAn @@ -77,5 +83,3 @@ def main(_input, _output): main(_input, _output) - # input_ = '/mnt/d/UH/4to Año/EVEA/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/lexer/iis4.cl' - # main(input_) From 2e7dce2a1d52a76afcbf2de7f4efc1a36e8613f8 Mon Sep 17 00:00:00 2001 From: livi98 Date: Wed, 23 Feb 2022 21:13:46 +0100 Subject: [PATCH 161/194] testing code gen --- src/main.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main.py b/src/main.py index d1f466473..6e4318478 100644 --- a/src/main.py +++ b/src/main.py @@ -64,14 +64,14 @@ def main(_input, _output): raise Exception() # Code Generation - # coolToCIL = COOLToCILVisitor(context) - # cilAST = coolToCIL.visit(ast, scope) + coolToCIL = COOLToCILVisitor(context) + cilAST = coolToCIL.visit(ast, scope) - # cilToMIPS = CILToMIPSVisitor() - # mips_code = cilToMIPS(cilAST) + cilToMIPS = CILToMIPSVisitor() + mips_code = cilToMIPS(cilAST) - # with open(f'{sys.argv[1][:-3]}.mips', 'w') as f: - # f.write(mips_code) + with open(f'{sys.argv[1][:-3]}.mips', 'w') as f: + f.write(mips_code) # ast, errors, context, scope = SemanticAn From 6387265c24482ea3941ebfea996bde75327e4afd Mon Sep 17 00:00:00 2001 From: livi98 Date: Wed, 23 Feb 2022 21:19:49 +0100 Subject: [PATCH 162/194] fixing get_type --- src/main.py | 2 +- src/semantic/semantic.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.py b/src/main.py index 6e4318478..38e22af64 100644 --- a/src/main.py +++ b/src/main.py @@ -77,7 +77,7 @@ def main(_input, _output): # ast, errors, context, scope = SemanticAn if __name__ == "__main__": - path = '/mnt/c/Users/Liviton/Desktop/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/semantic/dispatch2.cl' + path = '/mnt/c/Users/Liviton/Desktop/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/codegen/hello_world.cl' _input = sys.argv[1] if len(sys.argv) > 1 else path _output = sys.argv[2] if len(sys.argv) > 2 else None diff --git a/src/semantic/semantic.py b/src/semantic/semantic.py index 53e47553b..c1ddb9fdb 100644 --- a/src/semantic/semantic.py +++ b/src/semantic/semantic.py @@ -369,7 +369,7 @@ def create_type(self, name, pos): self.graph[parentName] = [name] return typex - def get_type(self, name: str, pos): + def get_type(self, name: str, pos = None): try: return self.types[name] except KeyError: From 99614e5e55549ae7a138024cfd1cfff7cc216372 Mon Sep 17 00:00:00 2001 From: livi98 Date: Wed, 23 Feb 2022 21:49:26 +0100 Subject: [PATCH 163/194] testing --- src/code_generator/BaseCoolToCilVisitor.py | 2 +- src/code_generator/CILToMIPSVisitor.py | 2 +- src/code_generator/COOLToCILVisitor.py | 6 +++--- src/main.py | 5 +++-- src/semantic/semantic.py | 4 ++-- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/code_generator/BaseCoolToCilVisitor.py b/src/code_generator/BaseCoolToCilVisitor.py index d8d23996e..36924a640 100644 --- a/src/code_generator/BaseCoolToCilVisitor.py +++ b/src/code_generator/BaseCoolToCilVisitor.py @@ -267,7 +267,7 @@ def define_built_in(self, scope): cil.GetAttrNode(l_value, 'l', 'value', 'Int')) subs_result = self.define_internal_local( scope=scope, name="subs_result") - self.register_instruction(cil.SubstringNode( + self.register_instruction(cil.SubStringNode( i_value, l_value, 'self', subs_result)) instance = self.define_internal_local(scope=scope, name="instance") self.register_instruction(cil.AllocateNode( diff --git a/src/code_generator/CILToMIPSVisitor.py b/src/code_generator/CILToMIPSVisitor.py index acf05e12b..eb90b562f 100644 --- a/src/code_generator/CILToMIPSVisitor.py +++ b/src/code_generator/CILToMIPSVisitor.py @@ -201,7 +201,7 @@ def visit(self, node): for arg in node.params: self.visit(arg) - + value_offset = self.var_offset[self.current_function.name][node.instance] self.text += f'lw $t1, {value_offset}($t0)\n' self.text += 'la $t0, void\n' diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index 84e98540e..ca7181b77 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -30,7 +30,7 @@ def visit(self, node, scope=None): self.dotdata['empty_str'] = '' # Add built-in types in .TYPES section - self.register_builtin_types(scope) + self.define_built_in(scope) # Add string equals function self.build_string_equals_function(scope) @@ -182,7 +182,7 @@ def visit(self, node, scope): dynamic_type = node.obj.computed_type.name self.register_instruction(cil.VCallNode( - result_local, node.method, call_args, dynamic_type, expr_value)) + result_local, node.id, call_args, dynamic_type, expr_value)) return result_local @@ -196,7 +196,7 @@ def visit(self, node, scope): call_args.append(cil.ArgNode(param_local)) self.register_instruction(cil.VCallNode( - result_local, node.method, call_args, 'self', 'memberCallGuayaba')) + result_local, node.id, call_args, 'IO', 'self')) return result_local diff --git a/src/main.py b/src/main.py index 38e22af64..d6ebbbfec 100644 --- a/src/main.py +++ b/src/main.py @@ -68,9 +68,10 @@ def main(_input, _output): cilAST = coolToCIL.visit(ast, scope) cilToMIPS = CILToMIPSVisitor() - mips_code = cilToMIPS(cilAST) + mips_code = cilToMIPS.visit(cilAST) - with open(f'{sys.argv[1][:-3]}.mips', 'w') as f: + # print(mips_code) + with open(_output, 'w+') as f: f.write(mips_code) diff --git a/src/semantic/semantic.py b/src/semantic/semantic.py index c1ddb9fdb..df96fa8be 100644 --- a/src/semantic/semantic.py +++ b/src/semantic/semantic.py @@ -62,7 +62,7 @@ def set_parent(self, parent): raise SemanticError(error_msg, *self.pos) self.parent = parent - def get_attribute(self, name: str, pos) -> Attribute: + def get_attribute(self, name: str, pos): try: return self.attributes[name] except KeyError: @@ -92,7 +92,7 @@ def define_attribute(self, name: str, typex, pos): error_msg = f'Attribute {name} is multiply defined in class.' raise SemanticError(error_msg, *pos) - def get_method(self, name: str, pos) -> Method: + def get_method(self, name: str, pos=None): try: return self.methods[name] except KeyError: From 172c4beb3afc9b2e8354f2e63225bb8f34075b70 Mon Sep 17 00:00:00 2001 From: livi98 Date: Thu, 24 Feb 2022 00:00:07 +0100 Subject: [PATCH 164/194] fixing a bug in memberCall --- src/code_generator/BaseCoolToCilVisitor.py | 6 ++++++ src/code_generator/CILToMIPSVisitor.py | 3 ++- src/code_generator/COOLToCILVisitor.py | 2 +- src/main.py | 2 +- src/semantic/semantic.py | 8 ++++++++ src/semantic/visitors/typeChecker.py | 2 ++ src/utils/ast.py | 12 +++++++++--- 7 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/code_generator/BaseCoolToCilVisitor.py b/src/code_generator/BaseCoolToCilVisitor.py index 36924a640..426b357d3 100644 --- a/src/code_generator/BaseCoolToCilVisitor.py +++ b/src/code_generator/BaseCoolToCilVisitor.py @@ -26,6 +26,12 @@ def localvars(self): def instructions(self): return self.current_function.instructions + def is_defined_param(self, name): + for p in self.params: + if p.name == name: + return True + return False + def register_param(self, vinfo): # 'param_{self.current_function.name[9:]}_{vinfo.name}_{len(self.params)}' param_node = cil.ParamNode(vinfo.name) diff --git a/src/code_generator/CILToMIPSVisitor.py b/src/code_generator/CILToMIPSVisitor.py index eb90b562f..66299b273 100644 --- a/src/code_generator/CILToMIPSVisitor.py +++ b/src/code_generator/CILToMIPSVisitor.py @@ -201,7 +201,8 @@ def visit(self, node): for arg in node.params: self.visit(arg) - + + value_offset = self.var_offset[self.current_function.name][node.instance] self.text += f'lw $t1, {value_offset}($t0)\n' self.text += 'la $t0, void\n' diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index ca7181b77..2897ba965 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -196,7 +196,7 @@ def visit(self, node, scope): call_args.append(cil.ArgNode(param_local)) self.register_instruction(cil.VCallNode( - result_local, node.id, call_args, 'IO', 'self')) + result_local, node.id, call_args, node.static_type.name, "self")) return result_local diff --git a/src/main.py b/src/main.py index d6ebbbfec..d5eb511fa 100644 --- a/src/main.py +++ b/src/main.py @@ -70,7 +70,7 @@ def main(_input, _output): cilToMIPS = CILToMIPSVisitor() mips_code = cilToMIPS.visit(cilAST) - # print(mips_code) + print(mips_code) with open(_output, 'w+') as f: f.write(mips_code) diff --git a/src/semantic/semantic.py b/src/semantic/semantic.py index df96fa8be..c79d172b5 100644 --- a/src/semantic/semantic.py +++ b/src/semantic/semantic.py @@ -113,6 +113,14 @@ def define_method(self, name: str, param_names: list, param_types: list, return_ name, param_names, param_types, return_type) return method + def has_attr(self, name: str): + try: + attr_name = self.get_attribute(name) + except: + return False + else: + return True + def change_type(self, method, nparm, newtype): idx = method.param_names.index(nparm) method.param_types[idx] = newtype diff --git a/src/semantic/visitors/typeChecker.py b/src/semantic/visitors/typeChecker.py index ca6567e53..ba7a05986 100644 --- a/src/semantic/visitors/typeChecker.py +++ b/src/semantic/visitors/typeChecker.py @@ -205,6 +205,8 @@ def visit(self, memberCallNode, scope): self.errors.append(TypexError( errorText, memberCallNode.line, memberCallNode.col)) + + memberCallNode.static_type = typex memberCallNode.computed_type = get_type(method.return_type, typex) return memberCallNode.computed_type diff --git a/src/utils/ast.py b/src/utils/ast.py index 8f76860c3..009e830b8 100644 --- a/src/utils/ast.py +++ b/src/utils/ast.py @@ -1,6 +1,3 @@ -from cmath import exp -from select import select - class Node(): pass @@ -105,6 +102,7 @@ def __init__(self, idx, args): self.line = idx.lineno self.col = idx.column self.args = args + self.instance = SelfNode('self', self.line, self.col) class IfThenElseNode(ExpressionNode): @@ -250,5 +248,13 @@ class BoolNode(AtomicNode): class StringNode(AtomicNode): pass + class VoidNode(AtomicNode): pass + + +class SelfNode(): + def __init__(self, name, line, col): + self.name = name + self.line = line + self.col = col From 6b6d14cc8617a6ae2df14c43f568bf44e8f8ad54 Mon Sep 17 00:00:00 2001 From: livi98 Date: Thu, 24 Feb 2022 00:13:56 +0100 Subject: [PATCH 165/194] hoping hello worrld works --- src/code_generator/COOLToCILVisitor.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index 2897ba965..c3544cae8 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -194,6 +194,7 @@ def visit(self, node, scope): for arg in reversed(node.args): param_local = self.visit(arg, scope) call_args.append(cil.ArgNode(param_local)) + call_args.append(cil.ArgNode("self")) self.register_instruction(cil.VCallNode( result_local, node.id, call_args, node.static_type.name, "self")) From 2287d39528d85c13c09da0b832013327d0fc5a3a Mon Sep 17 00:00:00 2001 From: livi98 Date: Thu, 24 Feb 2022 00:21:25 +0100 Subject: [PATCH 166/194] retesting code gen --- src/codeMips.mips | 663 ++++++++++++++++++++++++++++++++++++++++++++++ src/main.py | 8 +- 2 files changed, 667 insertions(+), 4 deletions(-) create mode 100644 src/codeMips.mips diff --git a/src/codeMips.mips b/src/codeMips.mips new file mode 100644 index 000000000..7bae12caf --- /dev/null +++ b/src/codeMips.mips @@ -0,0 +1,663 @@ +.data +dispatch_void: .asciiz "Runtime Error: A dispatch (static or dynamic) on void" +case_void: .asciiz "Runtime Error: A case on void" +case_no_match: .asciiz "Runtime Error: Execution of a case statement without a matching branch" +div_zero: .asciiz "Runtime Error: Division by zero" +substr: .asciiz "Runtime Error: Substring out of range" +heap: .asciiz "Runtime Error: Heap overflow" +temp_string: .space 2048 +void: .word 0 +Object_name: .asciiz "Object" +Object_methods: +.word Object.abort +.word Object.type_name +.word Object.copy +Int_name: .asciiz "Int" +Int_methods: +.word Int.abort +.word Int.type_name +.word Int.copy +String_name: .asciiz "String" +String_methods: +.word String.abort +.word String.type_name +.word String.copy +.word String.length +.word String.concat +.word String.substr +Bool_name: .asciiz "Bool" +Bool_methods: +.word Bool.abort +.word Bool.type_name +.word Bool.copy +IO_name: .asciiz "IO" +IO_methods: +.word Object.abort +.word Object.type_name +.word Object.copy +.word IO.out_string +.word IO.out_int +.word IO.in_string +.word IO.in_int +Main_name: .asciiz "Main" +Main_methods: +.word Object.abort +.word Object.type_name +.word Object.copy +.word IO.out_string +.word IO.out_int +.word IO.in_string +.word IO.in_int +.word Main.main +data_0: .asciiz "Abort called from class " +data_1: .asciiz " +" +empty_str: .asciiz "" +data_3: .asciiz "Hello, World. +" +.text +dispatch_void_error: +la $a0 dispatch_void +li $v0, 4 +syscall +li $v0, 10 +syscall +case_void_error: +la $a0 case_void +li $v0, 4 +syscall +li $v0, 10 +syscall +case_no_match_error: +la $a0 case_no_match +li $v0, 4 +syscall +li $v0, 10 +syscall +div_zero_error: +la $a0 div_zero +li $v0, 4 +syscall +li $v0, 10 +syscall +substr_error: +la $a0 substr +li $v0, 4 +syscall +li $v0, 10 +syscall +heap_error: +la $a0 heap +li $v0, 4 +syscall +li $v0, 10 +syscall +main: +addi $sp, $sp, -8 +addi $sp, $sp, -4 +sw $ra, 0($sp) +li $a0, 16 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 5 +sw $t1, 0($t0) +la $t1, Main_name +sw $t1, 4($t0) +li $t1, 4 +sw $t1, 8($t0) +la $t1, Main_methods +sw $t1, 12($t0) +sw $t0, 4($sp) +move $t0, $sp +lw $t1, 4($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Main_init +sw $a1, 8($sp) +move $t0, $sp +lw $t1, 4($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Main.main +sw $a1, 8($sp) +move $a1, $zero +lw $ra, 0($sp) +addi $sp, $sp, 12 +jr $ra +Object_init: +addi $sp, $sp, 0 +addi $sp, $sp, -4 +sw $ra, 0($sp) +move $a1, $zero +lw $ra, 0($sp) +addi $sp, $sp, 8 +jr $ra +Object.abort: +addi $sp, $sp, -12 +addi $sp, $sp, -4 +sw $ra, 0($sp) +la $t0, data_0 +sw $t0, 4($sp) +lw $a0, 4($sp) +li $v0, 4 +syscall +lw $t0, 16($sp) +lw $t1, 4($t0) +sw $t1, 8($sp) +lw $a0, 8($sp) +li $v0, 4 +syscall +la $t0, data_1 +sw $t0, 12($sp) +lw $a0, 12($sp) +li $v0, 4 +syscall +li $v0, 10 +syscall +lw $ra, 0($sp) +addi $sp, $sp, 20 +jr $ra +Object.type_name: +addi $sp, $sp, -12 +addi $sp, $sp, -4 +sw $ra, 0($sp) +lw $t0, 16($sp) +lw $t1, 4($t0) +sw $t1, 4($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 8($sp) +move $t0, $sp +lw $t1, 4($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 8($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 12($sp) +lw $a1, 8($sp) +lw $ra, 0($sp) +addi $sp, $sp, 20 +jr $ra +Object.copy: +addi $sp, $sp, -4 +addi $sp, $sp, -4 +sw $ra, 0($sp) +lw $t0, 8($sp) +lw $a0, 8($t0) +mul $a0, $a0, 4 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t1, $v0 +li $a0, 0 +lw $t3, 8($t0) +copy_object_word: +lw $t2, 0($t0) +sw $t2, 0($t1) +addi $t0, $t0, 4 +addi $t1, $t1, 4 +addi $a0, $a0, 1 +blt $a0, $t3, copy_object_word +sw $v0, 4($sp) +lw $a1, 4($sp) +lw $ra, 0($sp) +addi $sp, $sp, 12 +jr $ra +IO_init: +addi $sp, $sp, 0 +addi $sp, $sp, -4 +sw $ra, 0($sp) +move $a1, $zero +lw $ra, 0($sp) +addi $sp, $sp, 8 +jr $ra +IO.out_string: +addi $sp, $sp, -4 +addi $sp, $sp, -4 +sw $ra, 0($sp) +lw $t0, 12($sp) +lw $t1, 16($t0) +sw $t1, 4($sp) +lw $a0, 4($sp) +li $v0, 4 +syscall +lw $a1, 8($sp) +lw $ra, 0($sp) +addi $sp, $sp, 16 +jr $ra +IO.out_int: +addi $sp, $sp, -4 +addi $sp, $sp, -4 +sw $ra, 0($sp) +lw $t0, 12($sp) +lw $t1, 16($t0) +sw $t1, 4($sp) +li $v0 , 1 +lw $a0 , 4($sp) +syscall +lw $a1, 8($sp) +lw $ra, 0($sp) +addi $sp, $sp, 16 +jr $ra +IO.in_string: +addi $sp, $sp, -12 +addi $sp, $sp, -4 +sw $ra, 0($sp) +la $a0, temp_string +li $a1, 2048 +li $v0, 8 +syscall +move $t0, $a0 +jump_read_str_char: +li $t1, 0 +lb $t1, 0($t0) +beqz $t1, analize_str_end +addi $t0, $t0, 1 +j jump_read_str_char +analize_str_end: +addi $t0, $t0, -1 +li $t1, 0 +lb $t1, 0($t0) +bne $t1, 10, finish_jump_read_str_char +sb $0, 0($t0) +addi $t0, $t0, -1 +lb $t1, 0($t0) +bne $t1, 13, finish_jump_read_str_char +sb $0, 0($t0) +j analize_str_end +finish_jump_read_str_char: +sw $a0, 4($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 8($sp) +move $t0, $sp +lw $t1, 4($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 8($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 12($sp) +lw $a1, 8($sp) +lw $ra, 0($sp) +addi $sp, $sp, 20 +jr $ra +IO.in_int: +addi $sp, $sp, -12 +addi $sp, $sp, -4 +sw $ra, 0($sp) +li $v0, 5 +syscall +sw $v0, 4($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 8($sp) +move $t0, $sp +lw $t1, 4($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 8($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 12($sp) +lw $a1, 8($sp) +lw $ra, 0($sp) +addi $sp, $sp, 20 +jr $ra +String_init: +addi $sp, $sp, 0 +addi $sp, $sp, -4 +sw $ra, 0($sp) +lw $t0, 4($sp) +lw $t1, 8($sp) +sw $t1, 16($t0) +move $a1, $zero +lw $ra, 0($sp) +addi $sp, $sp, 12 +jr $ra +String.length: +addi $sp, $sp, -12 +addi $sp, $sp, -4 +sw $ra, 0($sp) +lw $t0, 16($sp) +lw $t0, 16($t0) +li $a0, 0 +count_char: +lb $t1, 0($t0) +beqz $t1, finish_chars_count +addi $t0, $t0, 1 +addi $a0, $a0, 1 +j count_char +finish_chars_count: +sw $a0, 4($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 8($sp) +move $t0, $sp +lw $t1, 4($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 8($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 12($sp) +lw $a1, 8($sp) +lw $ra, 0($sp) +addi $sp, $sp, 20 +jr $ra +String.concat: +addi $sp, $sp, -36 +addi $sp, $sp, -4 +sw $ra, 0($sp) +lw $t0, 40($sp) +lw $t1, 16($t0) +sw $t1, 4($sp) +move $t0, $sp +lw $t1, 40($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String.length +sw $a1, 8($sp) +lw $t0, 44($sp) +lw $t1, 16($t0) +sw $t1, 12($sp) +move $t0, $sp +lw $t1, 44($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String.length +sw $a1, 16($sp) +lw $t0, 8($sp) +lw $t1, 16($t0) +sw $t1, 20($sp) +lw $t0, 16($sp) +lw $t1, 16($t0) +sw $t1, 24($sp) +lw $a0, 20($sp) +lw $t0, 24($sp) +add $a0, $a0, $t0 +addi $a0, $a0, 1 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t3, $v0 +lw $t0, 4($sp) +lw $t1, 12($sp) +copy_str1_char: +lb $t2, 0($t0) +sb $t2, 0($v0) +beqz $t2, concat_str2_char +addi $t0, $t0, 1 +addi $v0, $v0, 1 +j copy_str1_char +concat_str2_char: +lb $t2, 0($t1) +sb $t2, 0($v0) +beqz $t2, finish_str2_concat +addi $t1, $t1, 1 +addi $v0, $v0, 1 +j concat_str2_char +finish_str2_concat: +sb $0, ($v0) +sw $t3, 28($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 32($sp) +move $t0, $sp +lw $t1, 28($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 32($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 36($sp) +lw $a1, 32($sp) +lw $ra, 0($sp) +addi $sp, $sp, 48 +jr $ra +String.substr: +addi $sp, $sp, -20 +addi $sp, $sp, -4 +sw $ra, 0($sp) +lw $t0, 28($sp) +lw $t1, 16($t0) +sw $t1, 4($sp) +lw $t0, 32($sp) +lw $t1, 16($t0) +sw $t1, 8($sp) +lw $a0, 8($sp) +addi $a0, $a0, 1 +li $v0, 9 +syscall +bge $v0, $sp heap_error +lw $t0, 4($sp) +lw $t1, 8($sp) +lw $t4, 24($sp) +lw $t2, 16($t4) +bltz $t0, substr_error +li $a0, 0 +jump_str_char: +beq $a0, $t0, finish_index_jump +addi $a0, $a0, 1 +addi $t2, $t2, 1 +beq $t2, $zero, substr_error +j jump_str_char +finish_index_jump: +li $a0, 0 +move $t3, $v0 +copy_substr_char: +beq $a0, $t1 finish_substr_copy +li $t0, 0 +lb $t0, 0($t2) +sb $t0, 0($v0) +addi $t2, $t2, 1 +beq $t2, $zero, substr_error +addi $v0, $v0, 1 +addi $a0, $a0, 1 +j copy_substr_char +finish_substr_copy: +sb $0, ($v0) +sw $t3, 12($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 16($sp) +move $t0, $sp +lw $t1, 12($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 16($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 20($sp) +lw $a1, 16($sp) +lw $ra, 0($sp) +addi $sp, $sp, 36 +jr $ra +Bool_init: +addi $sp, $sp, 0 +addi $sp, $sp, -4 +sw $ra, 0($sp) +lw $t0, 4($sp) +lw $t1, 8($sp) +sw $t1, 16($t0) +move $a1, $zero +lw $ra, 0($sp) +addi $sp, $sp, 12 +jr $ra +Int_init: +addi $sp, $sp, 0 +addi $sp, $sp, -4 +sw $ra, 0($sp) +lw $t0, 4($sp) +lw $t1, 8($sp) +sw $t1, 16($t0) +move $a1, $zero +lw $ra, 0($sp) +addi $sp, $sp, 12 +jr $ra +String_equals: +addi $sp, $sp, -12 +addi $sp, $sp, -4 +sw $ra, 0($sp) +lw $t0, 16($sp) +lw $t1, 16($t0) +sw $t1, 4($sp) +lw $t0, 20($sp) +lw $t1, 16($t0) +sw $t1, 8($sp) +lw $t1, 4($sp) +lw $t2, 8($sp) +compare_str_char: +li $t3, 0 +lb $t3, 0($t1) +li $t4, 0 +lb $t4, 0($t2) +seq $a0, $t3, $t4 +beqz $a0, finish_compare_str +beqz $t3, finish_compare_str +beqz $t4, finish_compare_str +addi $t1, $t1, 1 +addi $t2, $t2, 1 +j compare_str_char +finish_compare_str: +sw $a0, 12($sp) +lw $a1, 12($sp) +lw $ra, 0($sp) +addi $sp, $sp, 24 +jr $ra +Main_init: +addi $sp, $sp, -4 +addi $sp, $sp, -4 +sw $ra, 0($sp) +move $t0, $sp +lw $t1, 8($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal IO_init +sw $a1, 4($sp) +move $a1, $zero +lw $ra, 0($sp) +addi $sp, $sp, 12 +jr $ra +Main.main: +addi $sp, $sp, -16 +addi $sp, $sp, -4 +sw $ra, 0($sp) +la $t0, data_3 +sw $t0, 8($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 12($sp) +move $t0, $sp +lw $t1, 8($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 12($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 16($sp) +move $t0, $sp +lw $t1, 12($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 20($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 20($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 4($sp) +lw $a1, 4($sp) +lw $ra, 0($sp) +addi $sp, $sp, 24 +jr $ra \ No newline at end of file diff --git a/src/main.py b/src/main.py index d5eb511fa..3da18b065 100644 --- a/src/main.py +++ b/src/main.py @@ -70,7 +70,6 @@ def main(_input, _output): cilToMIPS = CILToMIPSVisitor() mips_code = cilToMIPS.visit(cilAST) - print(mips_code) with open(_output, 'w+') as f: f.write(mips_code) @@ -78,9 +77,10 @@ def main(_input, _output): # ast, errors, context, scope = SemanticAn if __name__ == "__main__": - path = '/mnt/c/Users/Liviton/Desktop/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/codegen/hello_world.cl' - _input = sys.argv[1] if len(sys.argv) > 1 else path - _output = sys.argv[2] if len(sys.argv) > 2 else None + in_path = '/mnt/c/Users/Liviton/Desktop/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/codegen/hello_world.cl' + out_path = '/mnt/c/Users/Liviton/Desktop/Complementos de Compilacion/cool-compiler/cool-compiler-2021/src/codeMips.mips' + _input = sys.argv[1] if len(sys.argv) > 1 else in_path + _output = sys.argv[2] if len(sys.argv) > 2 else out_path main(_input, _output) From 799cf58a9177ad19b30e094ec4de34db6512620a Mon Sep 17 00:00:00 2001 From: livi98 Date: Thu, 24 Feb 2022 00:38:29 +0100 Subject: [PATCH 167/194] retesting --- src/codeMips.mips | 9 --------- src/semantic/semantic.py | 10 +++++----- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/src/codeMips.mips b/src/codeMips.mips index 7bae12caf..ce3d4cd25 100644 --- a/src/codeMips.mips +++ b/src/codeMips.mips @@ -14,22 +14,13 @@ Object_methods: .word Object.copy Int_name: .asciiz "Int" Int_methods: -.word Int.abort -.word Int.type_name -.word Int.copy String_name: .asciiz "String" String_methods: -.word String.abort -.word String.type_name -.word String.copy .word String.length .word String.concat .word String.substr Bool_name: .asciiz "Bool" Bool_methods: -.word Bool.abort -.word Bool.type_name -.word Bool.copy IO_name: .asciiz "IO" IO_methods: .word Object.abort diff --git a/src/semantic/semantic.py b/src/semantic/semantic.py index c79d172b5..27e939a53 100644 --- a/src/semantic/semantic.py +++ b/src/semantic/semantic.py @@ -211,7 +211,7 @@ def __init__(self, pos=(0, 0)): self.methods = {} self.parent = None self.pos = pos - self.init_methods() + # self.init_methods() def init_methods(self): self.define_method('abort', [], [], self) @@ -250,7 +250,7 @@ def __init__(self, pos=(0, 0)): self.methods = {} self.parent = None self.pos = pos - self.init_methods() + # self.init_methods() def init_methods(self): self.define_method('abort', [], [], self) @@ -277,9 +277,9 @@ def __init__(self, pos=(0, 0)): self.init_methods() def init_methods(self): - self.define_method('abort', [], [], self) - self.define_method('type_name', [], [], self) - self.define_method('copy', [], [], SelfType()) + # self.define_method('abort', [], [], self) + # self.define_method('type_name', [], [], self) + # self.define_method('copy', [], [], SelfType()) self.define_method('length', [], [], IntType()) self.define_method('concat', ['s'], [self], self) self.define_method('substr', ['i', 'l'], [IntType(), IntType()], self) From cf42ed7bc4558436a97591c4ed36de91c7826a91 Mon Sep 17 00:00:00 2001 From: livi98 Date: Thu, 24 Feb 2022 00:47:59 +0100 Subject: [PATCH 168/194] hello world test passed, checking print cool --- src/codeMips.mips | 268 +++++++++++++++++++++++-- src/main.py | 2 +- src/semantic/semantic.py | 2 +- src/semantic/visitors/typeCollector.py | 5 + 4 files changed, 260 insertions(+), 17 deletions(-) diff --git a/src/codeMips.mips b/src/codeMips.mips index ce3d4cd25..81c25ce81 100644 --- a/src/codeMips.mips +++ b/src/codeMips.mips @@ -14,13 +14,22 @@ Object_methods: .word Object.copy Int_name: .asciiz "Int" Int_methods: +.word Object.abort +.word Object.type_name +.word Object.copy String_name: .asciiz "String" String_methods: +.word Object.abort +.word Object.type_name +.word Object.copy .word String.length .word String.concat .word String.substr Bool_name: .asciiz "Bool" Bool_methods: +.word Bool.abort +.word Bool.type_name +.word Bool.copy IO_name: .asciiz "IO" IO_methods: .word Object.abort @@ -44,8 +53,6 @@ data_0: .asciiz "Abort called from class " data_1: .asciiz " " empty_str: .asciiz "" -data_3: .asciiz "Hello, World. -" .text dispatch_void_error: la $a0 dispatch_void @@ -606,11 +613,242 @@ lw $ra, 0($sp) addi $sp, $sp, 12 jr $ra Main.main: -addi $sp, $sp, -16 +addi $sp, $sp, -108 addi $sp, $sp, -4 sw $ra, 0($sp) -la $t0, data_3 -sw $t0, 8($sp) +li $a0, 16 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 0 +sw $t1, 0($t0) +la $t1, Object_name +sw $t1, 4($t0) +li $t1, 4 +sw $t1, 8($t0) +la $t1, Object_methods +sw $t1, 12($t0) +sw $t0, 20($sp) +move $t0, $sp +lw $t1, 20($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Object_init +sw $a1, 24($sp) +move $t0, $sp +lw $t1, 20($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 20($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 4($t2) +jal $t3 +sw $a1, 16($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 28($sp) +li $t0, 1 +sw $t0, 32($sp) +move $t0, $sp +lw $t1, 32($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 28($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 36($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 40($sp) +li $t0, 4 +sw $t0, 44($sp) +move $t0, $sp +lw $t1, 44($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 40($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 48($sp) +move $t0, $sp +lw $t1, 28($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 40($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 16($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 16($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 20($t2) +jal $t3 +sw $a1, 12($sp) +move $t0, $sp +lw $t1, 12($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 112($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 112($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 8($sp) +la $t0, void +lw $t1, 112($sp) +seq $a0, $t0, $t1 +sw $a0, 60($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 64($sp) +move $t0, $sp +lw $t1, 60($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 64($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 68($sp) +move $t0, $sp +lw $t1, 64($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 64($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 4($t2) +jal $t3 +sw $a1, 56($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 72($sp) +li $t0, 3 +sw $t0, 76($sp) +move $t0, $sp +lw $t1, 76($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 72($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 80($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 84($sp) +li $t0, 1 +sw $t0, 88($sp) +move $t0, $sp +lw $t1, 88($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 84($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 92($sp) +move $t0, $sp +lw $t1, 72($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 84($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 56($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 56($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 20($t2) +jal $t3 +sw $a1, 52($sp) +move $t0, $sp +lw $t1, 52($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 8($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 8($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 4($sp) +la $t0, data_1 +sw $t0, 100($sp) li $a0, 20 li $v0, 9 syscall @@ -624,31 +862,31 @@ li $t1, 5 sw $t1, 8($t0) la $t1, String_methods sw $t1, 12($t0) -sw $t0, 12($sp) +sw $t0, 104($sp) move $t0, $sp -lw $t1, 8($t0) +lw $t1, 100($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 12($t0) +lw $t1, 104($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal String_init -sw $a1, 16($sp) +sw $a1, 108($sp) move $t0, $sp -lw $t1, 12($t0) +lw $t1, 104($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 20($t0) +lw $t1, 112($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 20($t0) +lw $t1, 112($t0) la $t0, void beq $t1, $t0, dispatch_void_error lw $t2, 12($t1) lw $t3, 12($t2) jal $t3 -sw $a1, 4($sp) -lw $a1, 4($sp) +sw $a1, 96($sp) +lw $a1, 96($sp) lw $ra, 0($sp) -addi $sp, $sp, 24 +addi $sp, $sp, 116 jr $ra \ No newline at end of file diff --git a/src/main.py b/src/main.py index 3da18b065..1f71b7c5c 100644 --- a/src/main.py +++ b/src/main.py @@ -77,7 +77,7 @@ def main(_input, _output): # ast, errors, context, scope = SemanticAn if __name__ == "__main__": - in_path = '/mnt/c/Users/Liviton/Desktop/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/codegen/hello_world.cl' + in_path = '/mnt/c/Users/Liviton/Desktop/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/codegen/print-cool.cl' out_path = '/mnt/c/Users/Liviton/Desktop/Complementos de Compilacion/cool-compiler/cool-compiler-2021/src/codeMips.mips' _input = sys.argv[1] if len(sys.argv) > 1 else in_path _output = sys.argv[2] if len(sys.argv) > 2 else out_path diff --git a/src/semantic/semantic.py b/src/semantic/semantic.py index 27e939a53..ae4ac5648 100644 --- a/src/semantic/semantic.py +++ b/src/semantic/semantic.py @@ -211,7 +211,7 @@ def __init__(self, pos=(0, 0)): self.methods = {} self.parent = None self.pos = pos - # self.init_methods() + self.init_methods() def init_methods(self): self.define_method('abort', [], [], self) diff --git a/src/semantic/visitors/typeCollector.py b/src/semantic/visitors/typeCollector.py index 078743e85..e356ad1df 100644 --- a/src/semantic/visitors/typeCollector.py +++ b/src/semantic/visitors/typeCollector.py @@ -23,6 +23,11 @@ def visit(self, programNode): self.context.types['SELF_TYPE'] = SelfType() self.context.types['IO'] = IOType() + self.context.types['IO'].set_parent(self.context.types['Object']) + self.context.types['String'].set_parent(self.context.types['Object']) + self.context.types['Int'].set_parent(self.context.types['Object']) + self.context.types['Bool'].set_parent(self.context.types['Object']) + for classDeclarationNode in programNode.declarations: self.visit(classDeclarationNode) From 3e93f9474a27aa856ca2387a568908db18d958e5 Mon Sep 17 00:00:00 2001 From: livi98 Date: Thu, 24 Feb 2022 00:51:52 +0100 Subject: [PATCH 169/194] retesting print cool --- src/semantic/semantic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/semantic/semantic.py b/src/semantic/semantic.py index ae4ac5648..27e939a53 100644 --- a/src/semantic/semantic.py +++ b/src/semantic/semantic.py @@ -211,7 +211,7 @@ def __init__(self, pos=(0, 0)): self.methods = {} self.parent = None self.pos = pos - self.init_methods() + # self.init_methods() def init_methods(self): self.define_method('abort', [], [], self) From c2a4abc5fa5a4de705781029c241cebe282b41dc Mon Sep 17 00:00:00 2001 From: livi98 Date: Thu, 24 Feb 2022 01:23:34 +0100 Subject: [PATCH 170/194] testing fib --- src/codeMips.mips | 444 +++++++++++++++------ src/code_generator/BaseCoolToCilVisitor.py | 6 + src/code_generator/CILToMIPSVisitor.py | 2 + src/code_generator/COOLToCILVisitor.py | 10 +- src/main.py | 7 +- 5 files changed, 342 insertions(+), 127 deletions(-) diff --git a/src/codeMips.mips b/src/codeMips.mips index 81c25ce81..8b2b706a4 100644 --- a/src/codeMips.mips +++ b/src/codeMips.mips @@ -27,9 +27,9 @@ String_methods: .word String.substr Bool_name: .asciiz "Bool" Bool_methods: -.word Bool.abort -.word Bool.type_name -.word Bool.copy +.word Object.abort +.word Object.type_name +.word Object.copy IO_name: .asciiz "IO" IO_methods: .word Object.abort @@ -49,10 +49,13 @@ Main_methods: .word IO.in_string .word IO.in_int .word Main.main +.word Main.fib data_0: .asciiz "Abort called from class " data_1: .asciiz " " empty_str: .asciiz "" +data_3: .asciiz "Enter n to find nth fibonacci number! +" .text dispatch_void_error: la $a0 dispatch_void @@ -613,40 +616,134 @@ lw $ra, 0($sp) addi $sp, $sp, 12 jr $ra Main.main: -addi $sp, $sp, -108 +addi $sp, $sp, -44 addi $sp, $sp, -4 sw $ra, 0($sp) -li $a0, 16 +la $t0, data_3 +sw $t0, 8($sp) +li $a0, 20 li $v0, 9 syscall bge $v0, $sp heap_error move $t0, $v0 -li $t1, 0 +li $t1, 2 sw $t1, 0($t0) -la $t1, Object_name +la $t1, String_name sw $t1, 4($t0) -li $t1, 4 +li $t1, 5 sw $t1, 8($t0) -la $t1, Object_methods +la $t1, String_methods sw $t1, 12($t0) -sw $t0, 20($sp) +sw $t0, 12($sp) move $t0, $sp -lw $t1, 20($t0) +lw $t1, 8($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 12($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 16($sp) +move $t0, $sp +lw $t1, 12($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 48($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 48($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 4($sp) +move $t0, $sp +lw $t1, 48($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -jal Object_init +lw $t1, 48($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 24($t2) +jal $t3 +sw $a1, 28($sp) +move $t0, $sp +lw $t1, 28($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 48($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 48($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 32($t2) +jal $t3 sw $a1, 24($sp) move $t0, $sp -lw $t1, 20($t0) +lw $t1, 24($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 20($t0) +lw $t1, 48($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 48($t0) la $t0, void beq $t1, $t0, dispatch_void_error lw $t2, 12($t1) -lw $t3, 4($t2) +lw $t3, 16($t2) jal $t3 -sw $a1, 16($sp) +sw $a1, 20($sp) +la $t0, data_1 +sw $t0, 36($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 40($sp) +move $t0, $sp +lw $t1, 36($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 40($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 44($sp) +move $t0, $sp +lw $t1, 40($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 48($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 48($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 32($sp) +lw $a1, 32($sp) +lw $ra, 0($sp) +addi $sp, $sp, 52 +jr $ra +Main.fib: +addi $sp, $sp, -208 +addi $sp, $sp, -4 +sw $ra, 0($sp) li $a0, 20 li $v0, 9 syscall @@ -660,18 +757,18 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 28($sp) -li $t0, 1 -sw $t0, 32($sp) +sw $t0, 4($sp) +li $t0, 0 +sw $t0, 8($sp) move $t0, $sp -lw $t1, 32($t0) +lw $t1, 8($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 28($t0) +lw $t1, 4($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init -sw $a1, 36($sp) +sw $a1, 12($sp) li $a0, 20 li $v0, 9 syscall @@ -685,87 +782,97 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 40($sp) -li $t0, 4 -sw $t0, 44($sp) +sw $t0, 16($sp) +li $t0, 1 +sw $t0, 20($sp) move $t0, $sp -lw $t1, 44($t0) +lw $t1, 20($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 40($t0) +lw $t1, 16($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init -sw $a1, 48($sp) +sw $a1, 24($sp) +lw $t1, 16($sp) +sw $t1, 28($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 32($sp) +li $t0, 0 +sw $t0, 36($sp) move $t0, $sp -lw $t1, 28($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 40($t0) +lw $t1, 36($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 16($t0) +lw $t1, 32($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 16($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 20($t2) -jal $t3 -sw $a1, 12($sp) +jal Int_init +sw $a1, 40($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 44($sp) +li $t0, 0 +sw $t0, 48($sp) move $t0, $sp -lw $t1, 12($t0) +lw $t1, 48($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 112($t0) +lw $t1, 44($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 112($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 8($sp) -la $t0, void -lw $t1, 112($sp) -seq $a0, $t0, $t1 -sw $a0, 60($sp) +jal Int_init +sw $a1, 52($sp) +lw $t1, 44($sp) +sw $t1, 56($sp) li $a0, 20 li $v0, 9 syscall bge $v0, $sp heap_error move $t0, $v0 -li $t1, 3 +li $t1, 4 sw $t1, 0($t0) -la $t1, Bool_name +la $t1, Int_name sw $t1, 4($t0) li $t1, 5 sw $t1, 8($t0) -la $t1, Bool_methods +la $t1, Int_methods sw $t1, 12($t0) +sw $t0, 60($sp) +li $t0, 0 sw $t0, 64($sp) move $t0, $sp -lw $t1, 60($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) lw $t1, 64($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -jal Bool_init -sw $a1, 68($sp) -move $t0, $sp -lw $t1, 64($t0) +lw $t1, 60($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 64($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 4($t2) -jal $t3 -sw $a1, 56($sp) +jal Int_init +sw $a1, 68($sp) li $a0, 20 li $v0, 9 syscall @@ -780,7 +887,7 @@ sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) sw $t0, 72($sp) -li $t0, 3 +li $t0, 0 sw $t0, 76($sp) move $t0, $sp lw $t1, 76($t0) @@ -791,6 +898,9 @@ addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init sw $a1, 80($sp) +lw $t1, 72($sp) +sw $t1, 84($sp) +label_1: li $a0, 20 li $v0, 9 syscall @@ -804,89 +914,189 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 84($sp) -li $t0, 1 -sw $t0, 88($sp) +sw $t0, 120($sp) +li $t0, 0 +sw $t0, 124($sp) move $t0, $sp -lw $t1, 88($t0) +lw $t1, 124($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 84($t0) +lw $t1, 120($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init -sw $a1, 92($sp) +sw $a1, 128($sp) +lw $t0, 216($sp) +lw $t1, 16($t0) +sw $t1, 112($sp) +lw $t0, 120($sp) +lw $t1, 16($t0) +sw $t1, 116($sp) +lw $a0, 112($sp) +lw $t1, 116($sp) +seq $a0, $a0, $t1 +sw $a0, 108($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 104($sp) move $t0, $sp -lw $t1, 72($t0) +lw $t1, 108($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 104($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 84($t0) +jal Bool_init +sw $a1, 132($sp) +lw $t0, 104($sp) +lw $t1, 16($t0) +sw $t1, 100($sp) +lw $t1, 100($sp) +neg $a0, $t1 +sw $a0, 96($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 92($sp) +move $t0, $sp +lw $t1, 96($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 56($t0) +lw $t1, 92($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 56($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 20($t2) -jal $t3 -sw $a1, 52($sp) +jal Bool_init +sw $a1, 136($sp) +lw $t0, 92($sp) +lw $a0, 16($t0) +bnez $a0, label_2 +b label_3 +label_2: +lw $t0, 28($sp) +lw $t1, 16($t0) +sw $t1, 148($sp) +lw $t0, 56($sp) +lw $t1, 16($t0) +sw $t1, 152($sp) +lw $a0, 148($sp) +lw $t1, 152($sp) +add $a0, $a0, $t1 +sw $a0, 144($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 140($sp) move $t0, $sp -lw $t1, 52($t0) +lw $t1, 144($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 8($t0) +lw $t1, 140($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 8($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 4($sp) -la $t0, data_1 -sw $t0, 100($sp) +jal Int_init +sw $a1, 156($sp) +lw $t1, 140($sp) +sw $t1, 84($sp) li $a0, 20 li $v0, 9 syscall bge $v0, $sp heap_error move $t0, $v0 -li $t1, 2 +li $t1, 4 sw $t1, 0($t0) -la $t1, String_name +la $t1, Int_name sw $t1, 4($t0) li $t1, 5 sw $t1, 8($t0) -la $t1, String_methods +la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 104($sp) +sw $t0, 180($sp) +li $t0, 1 +sw $t0, 184($sp) move $t0, $sp -lw $t1, 100($t0) +lw $t1, 184($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 104($t0) +lw $t1, 180($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -jal String_init -sw $a1, 108($sp) +jal Int_init +sw $a1, 188($sp) +lw $t0, 216($sp) +lw $t1, 16($t0) +sw $t1, 172($sp) +lw $t0, 180($sp) +lw $t1, 16($t0) +sw $t1, 176($sp) +lw $a0, 172($sp) +lw $t1, 176($sp) +sub $a0, $a0, $t1 +sw $a0, 168($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 164($sp) move $t0, $sp -lw $t1, 104($t0) +lw $t1, 168($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 112($t0) +lw $t1, 164($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 112($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 96($sp) -lw $a1, 96($sp) +jal Int_init +sw $a1, 192($sp) +lw $t1, 164($sp) +sw $t1, 216($sp) +lw $t1, 28($sp) +sw $t1, 56($sp) +lw $t1, 84($sp) +sw $t1, 28($sp) +b label_1 +label_3: +lw $t1, 84($sp) +sw $t1, 208($sp) +lw $a1, 208($sp) lw $ra, 0($sp) -addi $sp, $sp, 116 +addi $sp, $sp, 220 jr $ra \ No newline at end of file diff --git a/src/code_generator/BaseCoolToCilVisitor.py b/src/code_generator/BaseCoolToCilVisitor.py index 426b357d3..ff35eec02 100644 --- a/src/code_generator/BaseCoolToCilVisitor.py +++ b/src/code_generator/BaseCoolToCilVisitor.py @@ -13,6 +13,8 @@ def __init__(self, context): self.context = context self.context.set_type_tags() self.context.set_type_max_tags() + self.label_count = 0 + @property def params(self): @@ -32,6 +34,10 @@ def is_defined_param(self, name): return True return False + def get_label(self): + self.label_count += 1 + return f'label_{self.label_count}' + def register_param(self, vinfo): # 'param_{self.current_function.name[9:]}_{vinfo.name}_{len(self.params)}' param_node = cil.ParamNode(vinfo.name) diff --git a/src/code_generator/CILToMIPSVisitor.py b/src/code_generator/CILToMIPSVisitor.py index 66299b273..f8e5a136f 100644 --- a/src/code_generator/CILToMIPSVisitor.py +++ b/src/code_generator/CILToMIPSVisitor.py @@ -77,6 +77,8 @@ def visit(self, node, idx): @visitor.when(cil.AssignNode) def visit(self, node): + # print(self.current_function.name) + # print(node.local_dest) offset = self.var_offset[self.current_function.name][node.local_dest] if node.expr: if isinstance(node.expr, int): diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index c3544cae8..5a81c6cc1 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -289,11 +289,11 @@ def visit(self, node, scope): if not node.expr is None: expr_value = self.visit(node.expr, scope) let_var = self.define_internal_local( - scope=scope, name=node.name, cool_var_name=node.name) + scope=scope, name=node.id, cool_var=node.id) self.register_instruction(cil.AssignNode(let_var, expr_value)) else: let_var = self.define_internal_local( - scope=scope, name=node.name, cool_var_name=node.name) + scope=scope, name=node.id, cool_var=node.id) self.register_instruction(cil.AssignNode(let_var, instance)) return let_var @@ -383,7 +383,7 @@ def visit(self, node, scope): self.register_instruction(cil.GetAttrNode( right_local, right_value, "value", node.rvalue.computed_type.name)) - self.register_instruction(cil.BinaryOperator( + self.register_instruction(cil.BinaryOperationNode( op_local, left_local, right_local, "-")) # Allocate Int result @@ -411,7 +411,7 @@ def visit(self, node, scope): self.register_instruction(cil.GetAttrNode( right_local, right_value, "value", node.rvalue.computed_type.name)) - self.register_instruction(cil.BinaryOperator( + self.register_instruction(cil.BinaryOperationNode( op_local, left_local, right_local, "*")) # Allocate Int result @@ -439,7 +439,7 @@ def visit(self, node, scope): self.register_instruction(cil.GetAttrNode( right_local, right_value, "value", node.rvalue.computed_type.name)) - self.register_instruction(cil.BinaryOperator( + self.register_instruction(cil.BinaryOperationNode( op_local, left_local, right_local, "/")) # Allocate Int result diff --git a/src/main.py b/src/main.py index 1f71b7c5c..c8c97d0c8 100644 --- a/src/main.py +++ b/src/main.py @@ -19,7 +19,6 @@ def main(_input, _output): # Lexer lexer = CoolLexer() tokens = lexer.run(text) - # Parser parser = CoolParser(lexer) @@ -54,7 +53,7 @@ def main(_input, _output): # if semanticErrors: # for error in semanticErrors: # print(error) - + typeChecker = TypeChecker(context, semanticErrors) typeChecker.visit(ast, scope) @@ -72,15 +71,13 @@ def main(_input, _output): with open(_output, 'w+') as f: f.write(mips_code) - # ast, errors, context, scope = SemanticAn if __name__ == "__main__": - in_path = '/mnt/c/Users/Liviton/Desktop/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/codegen/print-cool.cl' + in_path = '/mnt/c/Users/Liviton/Desktop/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/codegen/fib.cl' out_path = '/mnt/c/Users/Liviton/Desktop/Complementos de Compilacion/cool-compiler/cool-compiler-2021/src/codeMips.mips' _input = sys.argv[1] if len(sys.argv) > 1 else in_path _output = sys.argv[2] if len(sys.argv) > 2 else out_path main(_input, _output) - From 6bc3200393ff12b794387bf1de1d9dbf426008d8 Mon Sep 17 00:00:00 2001 From: livi98 Date: Thu, 24 Feb 2022 01:55:29 +0100 Subject: [PATCH 171/194] cahnging not and xor --- src/codeMips.mips | 2 +- src/code_generator/CILToMIPSVisitor.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/codeMips.mips b/src/codeMips.mips index 8b2b706a4..737ba8fff 100644 --- a/src/codeMips.mips +++ b/src/codeMips.mips @@ -963,7 +963,7 @@ lw $t0, 104($sp) lw $t1, 16($t0) sw $t1, 100($sp) lw $t1, 100($sp) -neg $a0, $t1 +xor $a0, $t1 sw $a0, 96($sp) li $a0, 20 li $v0, 9 diff --git a/src/code_generator/CILToMIPSVisitor.py b/src/code_generator/CILToMIPSVisitor.py index f8e5a136f..1a306d661 100644 --- a/src/code_generator/CILToMIPSVisitor.py +++ b/src/code_generator/CILToMIPSVisitor.py @@ -109,9 +109,9 @@ def visit(self, node): expr_offset = self.var_offset[self.current_function.name][node.expr] self.text += f'lw $t1, {expr_offset}($sp)\n' if node.op == '~': - self.text += f'xor $a0, $t1, 1\n' + self.text += f'neg $a0, $t1, 1\n' else: - self.text += f'neg $a0, $t1 \n' + self.text += f'xor $a0, $t1 \n' result_offset = self.var_offset[self.current_function.name][node.local_dest] self.text += f'sw $a0, {result_offset}($sp)\n' From e3293967f6220f287aadee69b4cd00cc67e09321 Mon Sep 17 00:00:00 2001 From: livi98 Date: Thu, 24 Feb 2022 02:05:22 +0100 Subject: [PATCH 172/194] changing again xor and neg --- src/code_generator/CILToMIPSVisitor.py | 4 ++-- src/code_generator/COOLToCILVisitor.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/code_generator/CILToMIPSVisitor.py b/src/code_generator/CILToMIPSVisitor.py index 1a306d661..f8e5a136f 100644 --- a/src/code_generator/CILToMIPSVisitor.py +++ b/src/code_generator/CILToMIPSVisitor.py @@ -109,9 +109,9 @@ def visit(self, node): expr_offset = self.var_offset[self.current_function.name][node.expr] self.text += f'lw $t1, {expr_offset}($sp)\n' if node.op == '~': - self.text += f'neg $a0, $t1, 1\n' + self.text += f'xor $a0, $t1, 1\n' else: - self.text += f'xor $a0, $t1 \n' + self.text += f'neg $a0, $t1 \n' result_offset = self.var_offset[self.current_function.name][node.local_dest] self.text += f'sw $a0, {result_offset}($sp)\n' diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index 5a81c6cc1..0a3680776 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -567,7 +567,7 @@ def visit(self, node, scope): self.register_instruction( cil.UnaryOperationNode(op_local, expr_local, "~")) - # Allocate Bool result + # Allocate Int result self.register_instruction(cil.AllocateNode( 'Int', self.context.get_type('Int').tag, result_local)) result_init = self.define_internal_local( From 425bb5b88a9070b13a3a4b1afb508664af4658dd Mon Sep 17 00:00:00 2001 From: cwjki Date: Wed, 23 Feb 2022 23:13:38 -0500 Subject: [PATCH 173/194] fixing a bug in get_attributte --- src/codeMips.mips | 772 ++++++++++++++++++------- src/code_generator/CILToMIPSVisitor.py | 2 - src/code_generator/COOLToCILVisitor.py | 48 +- src/main.py | 4 +- src/semantic/semantic.py | 2 +- src/semantic/visitors/typeChecker.py | 3 +- 6 files changed, 592 insertions(+), 239 deletions(-) diff --git a/src/codeMips.mips b/src/codeMips.mips index 737ba8fff..0837fb7bc 100644 --- a/src/codeMips.mips +++ b/src/codeMips.mips @@ -48,13 +48,17 @@ Main_methods: .word IO.out_int .word IO.in_string .word IO.in_int +.word Main.pal .word Main.main -.word Main.fib data_0: .asciiz "Abort called from class " data_1: .asciiz " " empty_str: .asciiz "" -data_3: .asciiz "Enter n to find nth fibonacci number! +data_3: .asciiz "enter a string +" +data_4: .asciiz "that was not a palindrome +" +data_5: .asciiz "that was a palindrome " .text dispatch_void_error: @@ -97,7 +101,7 @@ main: addi $sp, $sp, -8 addi $sp, $sp, -4 sw $ra, 0($sp) -li $a0, 16 +li $a0, 20 li $v0, 9 syscall bge $v0, $sp heap_error @@ -106,7 +110,7 @@ li $t1, 5 sw $t1, 0($t0) la $t1, Main_name sw $t1, 4($t0) -li $t1, 4 +li $t1, 5 sw $t1, 8($t0) la $t1, Main_methods sw $t1, 12($t0) @@ -602,148 +606,134 @@ lw $ra, 0($sp) addi $sp, $sp, 24 jr $ra Main_init: -addi $sp, $sp, -4 +addi $sp, $sp, -16 addi $sp, $sp, -4 sw $ra, 0($sp) move $t0, $sp -lw $t1, 8($t0) +lw $t1, 20($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal IO_init sw $a1, 4($sp) move $a1, $zero -lw $ra, 0($sp) -addi $sp, $sp, 12 -jr $ra -Main.main: -addi $sp, $sp, -44 -addi $sp, $sp, -4 -sw $ra, 0($sp) -la $t0, data_3 -sw $t0, 8($sp) li $a0, 20 li $v0, 9 syscall bge $v0, $sp heap_error move $t0, $v0 -li $t1, 2 +li $t1, 4 sw $t1, 0($t0) -la $t1, String_name +la $t1, Int_name sw $t1, 4($t0) li $t1, 5 sw $t1, 8($t0) -la $t1, String_methods +la $t1, Int_methods sw $t1, 12($t0) +sw $t0, 8($sp) +li $t0, 0 sw $t0, 12($sp) move $t0, $sp -lw $t1, 8($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 12($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 16($sp) -move $t0, $sp lw $t1, 12($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 48($t0) +lw $t1, 8($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 48($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 4($sp) -move $t0, $sp -lw $t1, 48($t0) +jal Int_init +sw $a1, 16($sp) +lw $t0, 20($sp) +lw $t1, 8($sp) +sw $t1, 16($t0) +lw $ra, 0($sp) +addi $sp, $sp, 24 +jr $ra +Main.pal: +addi $sp, $sp, -276 addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 48($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 24($t2) -jal $t3 -sw $a1, 28($sp) +sw $ra, 0($sp) move $t0, $sp -lw $t1, 28($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 48($t0) +lw $t1, 284($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 48($t0) +lw $t1, 284($t0) la $t0, void beq $t1, $t0, dispatch_void_error lw $t2, 12($t1) -lw $t3, 32($t2) +lw $t3, 12($t2) jal $t3 sw $a1, 24($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 28($sp) +li $t0, 0 +sw $t0, 32($sp) move $t0, $sp -lw $t1, 24($t0) +lw $t1, 32($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 48($t0) +lw $t1, 28($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 48($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 16($t2) -jal $t3 -sw $a1, 20($sp) -la $t0, data_1 -sw $t0, 36($sp) +jal Int_init +sw $a1, 36($sp) +lw $t0, 24($sp) +lw $t1, 16($t0) +sw $t1, 16($sp) +lw $t0, 28($sp) +lw $t1, 16($t0) +sw $t1, 20($sp) +lw $a0, 16($sp) +lw $t1, 20($sp) +seq $a0, $a0, $t1 +sw $a0, 12($sp) li $a0, 20 li $v0, 9 syscall bge $v0, $sp heap_error move $t0, $v0 -li $t1, 2 +li $t1, 3 sw $t1, 0($t0) -la $t1, String_name +la $t1, Bool_name sw $t1, 4($t0) li $t1, 5 sw $t1, 8($t0) -la $t1, String_methods +la $t1, Bool_methods sw $t1, 12($t0) -sw $t0, 40($sp) +sw $t0, 8($sp) move $t0, $sp -lw $t1, 36($t0) +lw $t1, 12($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 40($t0) +lw $t1, 8($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -jal String_init -sw $a1, 44($sp) +jal Bool_init +sw $a1, 40($sp) +lw $t0, 8($sp) +lw $a0, 16($t0) +bnez $a0, label_1 move $t0, $sp -lw $t1, 40($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 48($t0) +lw $t1, 284($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 48($t0) +lw $t1, 284($t0) la $t0, void beq $t1, $t0, dispatch_void_error lw $t2, 12($t1) lw $t3, 12($t2) jal $t3 -sw $a1, 32($sp) -lw $a1, 32($sp) -lw $ra, 0($sp) -addi $sp, $sp, 52 -jr $ra -Main.fib: -addi $sp, $sp, -208 -addi $sp, $sp, -4 -sw $ra, 0($sp) +sw $a1, 64($sp) li $a0, 20 li $v0, 9 syscall @@ -757,45 +747,54 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 4($sp) -li $t0, 0 -sw $t0, 8($sp) +sw $t0, 68($sp) +li $t0, 1 +sw $t0, 72($sp) move $t0, $sp -lw $t1, 8($t0) +lw $t1, 72($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 4($t0) +lw $t1, 68($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init -sw $a1, 12($sp) +sw $a1, 76($sp) +lw $t0, 64($sp) +lw $t1, 16($t0) +sw $t1, 56($sp) +lw $t0, 68($sp) +lw $t1, 16($t0) +sw $t1, 60($sp) +lw $a0, 56($sp) +lw $t1, 60($sp) +seq $a0, $a0, $t1 +sw $a0, 52($sp) li $a0, 20 li $v0, 9 syscall bge $v0, $sp heap_error move $t0, $v0 -li $t1, 4 +li $t1, 3 sw $t1, 0($t0) -la $t1, Int_name +la $t1, Bool_name sw $t1, 4($t0) li $t1, 5 sw $t1, 8($t0) -la $t1, Int_methods +la $t1, Bool_methods sw $t1, 12($t0) -sw $t0, 16($sp) -li $t0, 1 -sw $t0, 20($sp) +sw $t0, 48($sp) move $t0, $sp -lw $t1, 20($t0) +lw $t1, 52($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 16($t0) +lw $t1, 48($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -jal Int_init -sw $a1, 24($sp) -lw $t1, 16($sp) -sw $t1, 28($sp) +jal Bool_init +sw $a1, 80($sp) +lw $t0, 48($sp) +lw $a0, 16($t0) +bnez $a0, label_2 li $a0, 20 li $v0, 9 syscall @@ -809,18 +808,18 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 32($sp) -li $t0, 0 -sw $t0, 36($sp) +sw $t0, 108($sp) +li $t0, 1 +sw $t0, 112($sp) move $t0, $sp -lw $t1, 36($t0) +lw $t1, 112($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 32($t0) +lw $t1, 108($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init -sw $a1, 40($sp) +sw $a1, 116($sp) li $a0, 20 li $v0, 9 syscall @@ -834,20 +833,35 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 44($sp) +sw $t0, 120($sp) li $t0, 0 -sw $t0, 48($sp) +sw $t0, 124($sp) move $t0, $sp -lw $t1, 48($t0) +lw $t1, 124($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 44($t0) +lw $t1, 120($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init -sw $a1, 52($sp) -lw $t1, 44($sp) -sw $t1, 56($sp) +sw $a1, 128($sp) +move $t0, $sp +lw $t1, 108($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 120($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 284($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 284($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 20($t2) +jal $t3 +sw $a1, 104($sp) li $a0, 20 li $v0, 9 syscall @@ -861,18 +875,29 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 60($sp) -li $t0, 0 -sw $t0, 64($sp) +sw $t0, 136($sp) +li $t0, 1 +sw $t0, 140($sp) move $t0, $sp -lw $t1, 64($t0) +lw $t1, 140($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 60($t0) +lw $t1, 136($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init -sw $a1, 68($sp) +sw $a1, 144($sp) +move $t0, $sp +lw $t1, 284($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 284($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 164($sp) li $a0, 20 li $v0, 9 syscall @@ -886,21 +911,28 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 72($sp) -li $t0, 0 -sw $t0, 76($sp) +sw $t0, 168($sp) +li $t0, 1 +sw $t0, 172($sp) move $t0, $sp -lw $t1, 76($t0) +lw $t1, 172($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 72($t0) +lw $t1, 168($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init -sw $a1, 80($sp) -lw $t1, 72($sp) -sw $t1, 84($sp) -label_1: +sw $a1, 176($sp) +lw $t0, 164($sp) +lw $t1, 16($t0) +sw $t1, 156($sp) +lw $t0, 168($sp) +lw $t1, 16($t0) +sw $t1, 160($sp) +lw $a0, 156($sp) +lw $t1, 160($sp) +sub $a0, $a0, $t1 +sw $a0, 152($sp) li $a0, 20 li $v0, 9 syscall @@ -914,28 +946,42 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 120($sp) -li $t0, 0 -sw $t0, 124($sp) +sw $t0, 148($sp) move $t0, $sp -lw $t1, 124($t0) +lw $t1, 152($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 120($t0) +lw $t1, 148($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init -sw $a1, 128($sp) -lw $t0, 216($sp) -lw $t1, 16($t0) -sw $t1, 112($sp) -lw $t0, 120($sp) -lw $t1, 16($t0) -sw $t1, 116($sp) -lw $a0, 112($sp) -lw $t1, 116($sp) -seq $a0, $a0, $t1 -sw $a0, 108($sp) +sw $a1, 180($sp) +move $t0, $sp +lw $t1, 136($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 148($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 284($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 284($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 20($t2) +jal $t3 +sw $a1, 132($sp) +move $t0, $sp +lw $t1, 132($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 104($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_equals +sw $a1, 92($sp) li $a0, 20 li $v0, 9 syscall @@ -949,22 +995,19 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Bool_methods sw $t1, 12($t0) -sw $t0, 104($sp) +sw $t0, 88($sp) move $t0, $sp -lw $t1, 108($t0) +lw $t1, 92($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 104($t0) +lw $t1, 88($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Bool_init -sw $a1, 132($sp) -lw $t0, 104($sp) -lw $t1, 16($t0) -sw $t1, 100($sp) -lw $t1, 100($sp) -xor $a0, $t1 -sw $a0, 96($sp) +sw $a1, 184($sp) +lw $t0, 88($sp) +lw $a0, 16($t0) +bnez $a0, label_3 li $a0, 20 li $v0, 9 syscall @@ -978,32 +1021,34 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Bool_methods sw $t1, 12($t0) -sw $t0, 92($sp) +sw $t0, 188($sp) +li $t0, 0 +sw $t0, 192($sp) move $t0, $sp -lw $t1, 96($t0) +lw $t1, 192($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 92($t0) +lw $t1, 188($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Bool_init -sw $a1, 136($sp) -lw $t0, 92($sp) -lw $a0, 16($t0) -bnez $a0, label_2 -b label_3 -label_2: -lw $t0, 28($sp) -lw $t1, 16($t0) -sw $t1, 148($sp) -lw $t0, 56($sp) -lw $t1, 16($t0) -sw $t1, 152($sp) -lw $a0, 148($sp) -lw $t1, 152($sp) -add $a0, $a0, $t1 -sw $a0, 144($sp) -li $a0, 20 +sw $a1, 196($sp) +lw $t1, 188($sp) +sw $t1, 84($sp) +b label_4 +label_3: +move $t0, $sp +lw $t1, 284($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 284($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 224($sp) +li $a0, 20 li $v0, 9 syscall bge $v0, $sp heap_error @@ -1016,18 +1061,51 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 140($sp) +sw $t0, 228($sp) +li $t0, 2 +sw $t0, 232($sp) move $t0, $sp -lw $t1, 144($t0) +lw $t1, 232($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 140($t0) +lw $t1, 228($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init -sw $a1, 156($sp) -lw $t1, 140($sp) -sw $t1, 84($sp) +sw $a1, 236($sp) +lw $t0, 224($sp) +lw $t1, 16($t0) +sw $t1, 216($sp) +lw $t0, 228($sp) +lw $t1, 16($t0) +sw $t1, 220($sp) +lw $a0, 216($sp) +lw $t1, 220($sp) +sub $a0, $a0, $t1 +sw $a0, 212($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 208($sp) +move $t0, $sp +lw $t1, 212($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 208($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 240($sp) li $a0, 20 li $v0, 9 syscall @@ -1041,28 +1119,155 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 180($sp) +sw $t0, 244($sp) li $t0, 1 -sw $t0, 184($sp) +sw $t0, 248($sp) move $t0, $sp -lw $t1, 184($t0) +lw $t1, 248($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 180($t0) +lw $t1, 244($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init -sw $a1, 188($sp) -lw $t0, 216($sp) +sw $a1, 252($sp) +move $t0, $sp +lw $t1, 208($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 244($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 284($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 284($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 20($t2) +jal $t3 +sw $a1, 204($sp) +move $t0, $sp +lw $t1, 204($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 280($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 280($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 28($t2) +jal $t3 +sw $a1, 200($sp) +lw $t1, 200($sp) +sw $t1, 84($sp) +label_4: +lw $t1, 84($sp) +sw $t1, 44($sp) +b label_5 +label_2: +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 256($sp) +li $t0, 1 +sw $t0, 260($sp) +move $t0, $sp +lw $t1, 260($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 256($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 264($sp) +lw $t1, 256($sp) +sw $t1, 44($sp) +label_5: +lw $t1, 44($sp) +sw $t1, 4($sp) +b label_6 +label_1: +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 268($sp) +li $t0, 1 +sw $t0, 272($sp) +move $t0, $sp +lw $t1, 272($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 268($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 276($sp) +lw $t1, 268($sp) +sw $t1, 4($sp) +label_6: +lw $a1, 4($sp) +lw $ra, 0($sp) +addi $sp, $sp, 288 +jr $ra +Main.main: +addi $sp, $sp, -92 +addi $sp, $sp, -4 +sw $ra, 0($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 16($sp) +li $t0, 1 +sw $t0, 20($sp) +move $t0, $sp +lw $t1, 20($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) lw $t1, 16($t0) -sw $t1, 172($sp) -lw $t0, 180($sp) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 24($sp) +lw $t0, 16($sp) lw $t1, 16($t0) -sw $t1, 176($sp) -lw $a0, 172($sp) -lw $t1, 176($sp) -sub $a0, $a0, $t1 -sw $a0, 168($sp) +sw $t1, 12($sp) +lw $t1, 12($sp) +xor $a0, $t1, 1 +sw $a0, 8($sp) li $a0, 20 li $v0, 9 syscall @@ -1076,27 +1281,172 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 164($sp) +sw $t0, 4($sp) move $t0, $sp -lw $t1, 168($t0) +lw $t1, 8($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 164($t0) +lw $t1, 4($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init -sw $a1, 192($sp) -lw $t1, 164($sp) -sw $t1, 216($sp) -lw $t1, 28($sp) -sw $t1, 56($sp) -lw $t1, 84($sp) -sw $t1, 28($sp) -b label_1 -label_3: -lw $t1, 84($sp) -sw $t1, 208($sp) -lw $a1, 208($sp) +sw $a1, 28($sp) +lw $t0, 96($sp) +lw $t1, 4($sp) +sw $t1, 16($t0) +la $t0, data_3 +sw $t0, 40($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 44($sp) +move $t0, $sp +lw $t1, 40($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 44($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 48($sp) +move $t0, $sp +lw $t1, 44($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 96($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 96($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 36($sp) +move $t0, $sp +lw $t1, 96($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 96($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 20($t2) +jal $t3 +sw $a1, 60($sp) +move $t0, $sp +lw $t1, 60($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 96($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 96($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 28($t2) +jal $t3 +sw $a1, 56($sp) +lw $t0, 56($sp) +lw $a0, 16($t0) +bnez $a0, label_7 +la $t0, data_4 +sw $t0, 68($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 72($sp) +move $t0, $sp +lw $t1, 68($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 72($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 76($sp) +move $t0, $sp +lw $t1, 72($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 96($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 96($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 64($sp) +lw $t1, 64($sp) +sw $t1, 52($sp) +b label_8 +label_7: +la $t0, data_5 +sw $t0, 84($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 88($sp) +move $t0, $sp +lw $t1, 84($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 88($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 92($sp) +move $t0, $sp +lw $t1, 88($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 96($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 96($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 80($sp) +lw $t1, 80($sp) +sw $t1, 52($sp) +label_8: +lw $a1, 52($sp) lw $ra, 0($sp) -addi $sp, $sp, 220 +addi $sp, $sp, 100 jr $ra \ No newline at end of file diff --git a/src/code_generator/CILToMIPSVisitor.py b/src/code_generator/CILToMIPSVisitor.py index f8e5a136f..66299b273 100644 --- a/src/code_generator/CILToMIPSVisitor.py +++ b/src/code_generator/CILToMIPSVisitor.py @@ -77,8 +77,6 @@ def visit(self, node, idx): @visitor.when(cil.AssignNode) def visit(self, node): - # print(self.current_function.name) - # print(node.local_dest) offset = self.var_offset[self.current_function.name][node.local_dest] if node.expr: if isinstance(node.expr, int): diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index 0a3680776..2e2b21377 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -101,34 +101,38 @@ def visit(self, node, scope): @visitor.when(AttrDeclarationNode) def visit(self, node, scope): - instance = None - - if node.type in ['Int', 'Bool']: - instance = self.define_internal_local(scope=scope, name="instance") - self.register_instruction(cil.AllocateNode( - node.type, self.context.get_type(node.type).tag, instance)) - value = self.define_internal_local(scope=scope, name="value") - self.register_instruction(cil.LoadIntNode(0, value)) - result_init = self.define_internal_local( - scope=scope, name="result_init") - self.register_instruction(cil.CallNode(result_init, f'{node.type}_init', [ - cil.ArgNode(value), cil.ArgNode(instance)], node.type)) - elif node.type == 'String': - instance = self.define_internal_local(scope=scope, name="instance") - self.register_instruction(cil.AllocateNode( - node.type, self.context.get_type(node.type).tag, instance)) - value = self.define_internal_local(scope=scope, name="value") - self.register_instruction(cil.LoadStringNode('empty_str', value)) - result_init = self.define_internal_local( - scope=scope, name="result_init") - self.register_instruction(cil.CallNode(result_init, f'{node.type}_init', [ - cil.ArgNode(value), cil.ArgNode(instance)], node.type)) if not node.expr is None: expr = self.visit(node.expr, scope) self.register_instruction(cil.SetAttrNode( 'self', node.id, expr, self.current_type.name)) else: + instance = None + + if node.type in ['Int', 'Bool']: + instance = self.define_internal_local( + scope=scope, name="instance") + self.register_instruction(cil.AllocateNode( + node.type, self.context.get_type(node.type).tag, instance)) + value = self.define_internal_local(scope=scope, name="value") + self.register_instruction(cil.LoadIntNode(0, value)) + result_init = self.define_internal_local( + scope=scope, name="result_init") + self.register_instruction(cil.CallNode(result_init, f'{node.type}_init', [ + cil.ArgNode(value), cil.ArgNode(instance)], node.type)) + elif node.type == 'String': + instance = self.define_internal_local( + scope=scope, name="instance") + self.register_instruction(cil.AllocateNode( + node.type, self.context.get_type(node.type).tag, instance)) + value = self.define_internal_local(scope=scope, name="value") + self.register_instruction( + cil.LoadStringNode('empty_str', value)) + result_init = self.define_internal_local( + scope=scope, name="result_init") + self.register_instruction(cil.CallNode(result_init, f'{node.type}_init', [ + cil.ArgNode(value), cil.ArgNode(instance)], node.type)) + self.register_instruction(cil.SetAttrNode( 'self', node.id, instance, self.current_type.name)) diff --git a/src/main.py b/src/main.py index c8c97d0c8..660c2f826 100644 --- a/src/main.py +++ b/src/main.py @@ -75,8 +75,8 @@ def main(_input, _output): # ast, errors, context, scope = SemanticAn if __name__ == "__main__": - in_path = '/mnt/c/Users/Liviton/Desktop/Complementos de Compilacion/cool-compiler/cool-compiler-2021/tests/codegen/fib.cl' - out_path = '/mnt/c/Users/Liviton/Desktop/Complementos de Compilacion/cool-compiler/cool-compiler-2021/src/codeMips.mips' + in_path = '/home/cwjki/Projects/cool-compiler-2021/tests/codegen/palindrome.cl' + out_path = '/home/cwjki/Projects/cool-compiler-2021/src/codeMips.mips' _input = sys.argv[1] if len(sys.argv) > 1 else in_path _output = sys.argv[2] if len(sys.argv) > 2 else out_path diff --git a/src/semantic/semantic.py b/src/semantic/semantic.py index 27e939a53..f93c48d9e 100644 --- a/src/semantic/semantic.py +++ b/src/semantic/semantic.py @@ -62,7 +62,7 @@ def set_parent(self, parent): raise SemanticError(error_msg, *self.pos) self.parent = parent - def get_attribute(self, name: str, pos): + def get_attribute(self, name: str, pos=None): try: return self.attributes[name] except KeyError: diff --git a/src/semantic/visitors/typeChecker.py b/src/semantic/visitors/typeChecker.py index ba7a05986..28021822a 100644 --- a/src/semantic/visitors/typeChecker.py +++ b/src/semantic/visitors/typeChecker.py @@ -152,7 +152,8 @@ def visit(self, arrobaCallNode, scope): self.errors.append(TypexError( errorText, arrobaCallNode.line, arrobaCallNode.col)) - return get_type(method.return_type, typex) + arrobaCallNode.computed_type = get_type(method.return_type, TypexError) + return arrobaCallNode.computed_type @visitor.when(DotCallNode) def visit(self, dotCallNode, scope): From c19f83558113059382784f980ef0f65613167737 Mon Sep 17 00:00:00 2001 From: cwjki Date: Wed, 23 Feb 2022 23:18:50 -0500 Subject: [PATCH 174/194] 7/17 codegen pass --- src/code_generator/COOLToCILVisitor.py | 49 ++++++++++++++------------ 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index 2e2b21377..185601ce1 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -267,35 +267,40 @@ def visit(self, node, scope): @visitor.when(VarDeclarationNode) def visit(self, node, scope): - instance = None - - if node.type in ['Int', 'Bool']: - instance = self.define_internal_local(scope=scope, name="instance") - self.register_instruction(cil.AllocateNode( - node.type, self.context.get_type(node.type).tag, instance)) - value = self.define_internal_local(scope=scope, name="value") - self.register_instruction(cil.LoadIntNode(0, value)) - result_init = self.define_internal_local( - scope=scope, name="result_init") - self.register_instruction(cil.CallNode(result_init, f'{node.type}_init', [ - cil.ArgNode(value), cil.ArgNode(instance)], node.type)) - elif node.type == 'String': - instance = self.define_internal_local(scope=scope, name="instance") - self.register_instruction(cil.AllocateNode( - node.type, self.context.get_type(node.type).tag, instance)) - value = self.define_internal_local(scope=scope, name="value") - self.register_instruction(cil.LoadStringNode('empty_str', value)) - result_init = self.define_internal_local( - scope=scope, name="result_init") - self.register_instruction(cil.CallNode(result_init, f'{node.type}_init', [ - cil.ArgNode(value), cil.ArgNode(instance)], node.type)) if not node.expr is None: expr_value = self.visit(node.expr, scope) let_var = self.define_internal_local( scope=scope, name=node.id, cool_var=node.id) self.register_instruction(cil.AssignNode(let_var, expr_value)) + else: + instance = None + + if node.type in ['Int', 'Bool']: + instance = self.define_internal_local( + scope=scope, name="instance") + self.register_instruction(cil.AllocateNode( + node.type, self.context.get_type(node.type).tag, instance)) + value = self.define_internal_local(scope=scope, name="value") + self.register_instruction(cil.LoadIntNode(0, value)) + result_init = self.define_internal_local( + scope=scope, name="result_init") + self.register_instruction(cil.CallNode(result_init, f'{node.type}_init', [ + cil.ArgNode(value), cil.ArgNode(instance)], node.type)) + elif node.type == 'String': + instance = self.define_internal_local( + scope=scope, name="instance") + self.register_instruction(cil.AllocateNode( + node.type, self.context.get_type(node.type).tag, instance)) + value = self.define_internal_local(scope=scope, name="value") + self.register_instruction( + cil.LoadStringNode('empty_str', value)) + result_init = self.define_internal_local( + scope=scope, name="result_init") + self.register_instruction(cil.CallNode(result_init, f'{node.type}_init', [ + cil.ArgNode(value), cil.ArgNode(instance)], node.type)) + let_var = self.define_internal_local( scope=scope, name=node.id, cool_var=node.id) self.register_instruction(cil.AssignNode(let_var, instance)) From 36a2e9efacd7a0029e3c60167458eab4412cdb6f Mon Sep 17 00:00:00 2001 From: cwjki Date: Wed, 23 Feb 2022 23:26:36 -0500 Subject: [PATCH 175/194] trying to fix primes.cl test --- src/codeMips.mips | 932 +++++++++++++++++++++++---------------- src/main.py | 2 +- src/semantic/semantic.py | 6 +- 3 files changed, 546 insertions(+), 394 deletions(-) diff --git a/src/codeMips.mips b/src/codeMips.mips index 0837fb7bc..dd1f301dd 100644 --- a/src/codeMips.mips +++ b/src/codeMips.mips @@ -19,9 +19,9 @@ Int_methods: .word Object.copy String_name: .asciiz "String" String_methods: -.word Object.abort -.word Object.type_name -.word Object.copy +.word String.abort +.word String.type_name +.word String.copy .word String.length .word String.concat .word String.substr @@ -48,18 +48,17 @@ Main_methods: .word IO.out_int .word IO.in_string .word IO.in_int -.word Main.pal .word Main.main data_0: .asciiz "Abort called from class " data_1: .asciiz " " empty_str: .asciiz "" -data_3: .asciiz "enter a string -" -data_4: .asciiz "that was not a palindrome +data_3: .asciiz "2 is trivially prime. " -data_5: .asciiz "that was a palindrome +data_4: .asciiz " is prime. " +data_5: .asciiz "continue" +data_6: .asciiz "halt" .text dispatch_void_error: la $a0 dispatch_void @@ -101,7 +100,7 @@ main: addi $sp, $sp, -8 addi $sp, $sp, -4 sw $ra, 0($sp) -li $a0, 20 +li $a0, 36 li $v0, 9 syscall bge $v0, $sp heap_error @@ -110,7 +109,7 @@ li $t1, 5 sw $t1, 0($t0) la $t1, Main_name sw $t1, 4($t0) -li $t1, 5 +li $t1, 9 sw $t1, 8($t0) la $t1, Main_methods sw $t1, 12($t0) @@ -606,62 +605,55 @@ lw $ra, 0($sp) addi $sp, $sp, 24 jr $ra Main_init: -addi $sp, $sp, -16 +addi $sp, $sp, -540 addi $sp, $sp, -4 sw $ra, 0($sp) move $t0, $sp -lw $t1, 20($t0) +lw $t1, 544($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal IO_init sw $a1, 4($sp) move $a1, $zero +la $t0, data_3 +sw $t0, 12($sp) li $a0, 20 li $v0, 9 syscall bge $v0, $sp heap_error move $t0, $v0 -li $t1, 4 +li $t1, 2 sw $t1, 0($t0) -la $t1, Int_name +la $t1, String_name sw $t1, 4($t0) li $t1, 5 sw $t1, 8($t0) -la $t1, Int_methods +la $t1, String_methods sw $t1, 12($t0) -sw $t0, 8($sp) -li $t0, 0 -sw $t0, 12($sp) +sw $t0, 16($sp) move $t0, $sp lw $t1, 12($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 8($t0) +lw $t1, 16($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -jal Int_init -sw $a1, 16($sp) -lw $t0, 20($sp) -lw $t1, 8($sp) -sw $t1, 16($t0) -lw $ra, 0($sp) -addi $sp, $sp, 24 -jr $ra -Main.pal: -addi $sp, $sp, -276 -addi $sp, $sp, -4 -sw $ra, 0($sp) +jal String_init +sw $a1, 20($sp) move $t0, $sp -lw $t1, 284($t0) +lw $t1, 16($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 544($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 284($t0) +lw $t1, 544($t0) la $t0, void beq $t1, $t0, dispatch_void_error lw $t2, 12($t1) lw $t3, 12($t2) jal $t3 -sw $a1, 24($sp) +sw $a1, 8($sp) li $a0, 20 li $v0, 9 syscall @@ -675,65 +667,55 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) +sw $t0, 24($sp) +li $t0, 2 sw $t0, 28($sp) -li $t0, 0 -sw $t0, 32($sp) move $t0, $sp -lw $t1, 32($t0) +lw $t1, 28($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 28($t0) +lw $t1, 24($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init -sw $a1, 36($sp) -lw $t0, 24($sp) -lw $t1, 16($t0) -sw $t1, 16($sp) -lw $t0, 28($sp) +sw $a1, 32($sp) +lw $t0, 544($sp) +lw $t1, 24($sp) +sw $t1, 16($t0) +lw $t0, 544($sp) lw $t1, 16($t0) -sw $t1, 20($sp) -lw $a0, 16($sp) -lw $t1, 20($sp) -seq $a0, $a0, $t1 -sw $a0, 12($sp) +sw $t1, 464($sp) +lw $t0, 544($sp) +lw $t1, 464($sp) +sw $t1, 20($t0) li $a0, 20 li $v0, 9 syscall bge $v0, $sp heap_error move $t0, $v0 -li $t1, 3 +li $t1, 4 sw $t1, 0($t0) -la $t1, Bool_name +la $t1, Int_name sw $t1, 4($t0) li $t1, 5 sw $t1, 8($t0) -la $t1, Bool_methods +la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 8($sp) +sw $t0, 40($sp) +li $t0, 0 +sw $t0, 44($sp) move $t0, $sp -lw $t1, 12($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 8($t0) +lw $t1, 44($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -jal Bool_init -sw $a1, 40($sp) -lw $t0, 8($sp) -lw $a0, 16($t0) -bnez $a0, label_1 -move $t0, $sp -lw $t1, 284($t0) +lw $t1, 40($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 284($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 64($sp) +jal Int_init +sw $a1, 48($sp) +lw $t0, 544($sp) +lw $t1, 40($sp) +sw $t1, 24($t0) li $a0, 20 li $v0, 9 syscall @@ -747,28 +729,22 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 68($sp) -li $t0, 1 -sw $t0, 72($sp) +sw $t0, 52($sp) +li $t0, 500 +sw $t0, 56($sp) move $t0, $sp -lw $t1, 72($t0) +lw $t1, 56($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 68($t0) +lw $t1, 52($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init -sw $a1, 76($sp) -lw $t0, 64($sp) -lw $t1, 16($t0) -sw $t1, 56($sp) -lw $t0, 68($sp) -lw $t1, 16($t0) -sw $t1, 60($sp) -lw $a0, 56($sp) -lw $t1, 60($sp) -seq $a0, $a0, $t1 -sw $a0, 52($sp) +sw $a1, 60($sp) +lw $t0, 544($sp) +lw $t1, 52($sp) +sw $t1, 28($t0) +label_1: li $a0, 20 li $v0, 9 syscall @@ -782,19 +758,26 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Bool_methods sw $t1, 12($t0) -sw $t0, 48($sp) +sw $t0, 68($sp) +li $t0, 1 +sw $t0, 72($sp) move $t0, $sp -lw $t1, 52($t0) +lw $t1, 72($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 48($t0) +lw $t1, 68($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Bool_init -sw $a1, 80($sp) -lw $t0, 48($sp) +sw $a1, 76($sp) +lw $t0, 68($sp) lw $a0, 16($t0) bnez $a0, label_2 +b label_3 +label_2: +lw $t0, 544($sp) +lw $t1, 20($t0) +sw $t1, 508($sp) li $a0, 20 li $v0, 9 syscall @@ -808,18 +791,28 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 108($sp) +sw $t0, 100($sp) li $t0, 1 -sw $t0, 112($sp) +sw $t0, 104($sp) move $t0, $sp -lw $t1, 112($t0) +lw $t1, 104($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 108($t0) +lw $t1, 100($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init -sw $a1, 116($sp) +sw $a1, 108($sp) +lw $t0, 508($sp) +lw $t1, 16($t0) +sw $t1, 88($sp) +lw $t0, 100($sp) +lw $t1, 16($t0) +sw $t1, 92($sp) +lw $a0, 88($sp) +lw $t1, 92($sp) +add $a0, $a0, $t1 +sw $a0, 84($sp) li $a0, 20 li $v0, 9 syscall @@ -833,35 +826,19 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 120($sp) -li $t0, 0 -sw $t0, 124($sp) +sw $t0, 80($sp) move $t0, $sp -lw $t1, 124($t0) +lw $t1, 84($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 120($t0) +lw $t1, 80($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init -sw $a1, 128($sp) -move $t0, $sp -lw $t1, 108($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 120($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 284($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 284($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 20($t2) -jal $t3 -sw $a1, 104($sp) +sw $a1, 112($sp) +lw $t0, 544($sp) +lw $t1, 80($sp) +sw $t1, 20($t0) li $a0, 20 li $v0, 9 syscall @@ -875,29 +852,41 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 136($sp) -li $t0, 1 -sw $t0, 140($sp) +sw $t0, 120($sp) +li $t0, 2 +sw $t0, 124($sp) move $t0, $sp -lw $t1, 140($t0) +lw $t1, 124($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 136($t0) +lw $t1, 120($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init -sw $a1, 144($sp) -move $t0, $sp -lw $t1, 284($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 284($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 164($sp) +sw $a1, 128($sp) +lw $t0, 544($sp) +lw $t1, 120($sp) +sw $t1, 24($t0) +label_4: +lw $t0, 544($sp) +lw $t1, 20($t0) +sw $t1, 508($sp) +lw $t0, 544($sp) +lw $t1, 24($t0) +sw $t1, 428($sp) +lw $t0, 544($sp) +lw $t1, 24($t0) +sw $t1, 428($sp) +lw $t0, 428($sp) +lw $t1, 16($t0) +sw $t1, 172($sp) +lw $t0, 428($sp) +lw $t1, 16($t0) +sw $t1, 176($sp) +lw $a0, 172($sp) +lw $t1, 176($sp) +mul $a0, $a0, $t1 +sw $a0, 168($sp) li $a0, 20 li $v0, 9 syscall @@ -911,77 +900,26 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 168($sp) -li $t0, 1 -sw $t0, 172($sp) +sw $t0, 164($sp) move $t0, $sp -lw $t1, 172($t0) +lw $t1, 168($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 168($t0) +lw $t1, 164($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init -sw $a1, 176($sp) +sw $a1, 188($sp) +lw $t0, 508($sp) +lw $t1, 16($t0) +sw $t1, 152($sp) lw $t0, 164($sp) lw $t1, 16($t0) sw $t1, 156($sp) -lw $t0, 168($sp) -lw $t1, 16($t0) -sw $t1, 160($sp) -lw $a0, 156($sp) -lw $t1, 160($sp) -sub $a0, $a0, $t1 -sw $a0, 152($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 148($sp) -move $t0, $sp -lw $t1, 152($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 148($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 180($sp) -move $t0, $sp -lw $t1, 136($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 148($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 284($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 284($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 20($t2) -jal $t3 -sw $a1, 132($sp) -move $t0, $sp -lw $t1, 132($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 104($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_equals -sw $a1, 92($sp) +lw $a0, 152($sp) +lw $t1, 156($sp) +slt $a0, $a0, $t1 +sw $a0, 148($sp) li $a0, 20 li $v0, 9 syscall @@ -995,59 +933,75 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Bool_methods sw $t1, 12($t0) -sw $t0, 88($sp) +sw $t0, 144($sp) move $t0, $sp -lw $t1, 92($t0) +lw $t1, 148($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 88($t0) +lw $t1, 144($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Bool_init -sw $a1, 184($sp) -lw $t0, 88($sp) +sw $a1, 192($sp) +lw $t0, 144($sp) lw $a0, 16($t0) -bnez $a0, label_3 +bnez $a0, label_7 +lw $t0, 544($sp) +lw $t1, 20($t0) +sw $t1, 508($sp) +lw $t0, 544($sp) +lw $t1, 24($t0) +sw $t1, 428($sp) +lw $t0, 544($sp) +lw $t1, 20($t0) +sw $t1, 508($sp) +lw $t0, 544($sp) +lw $t1, 24($t0) +sw $t1, 428($sp) +lw $t0, 508($sp) +lw $t1, 16($t0) +sw $t1, 264($sp) +lw $t0, 428($sp) +lw $t1, 16($t0) +sw $t1, 268($sp) +lw $a0, 264($sp) +lw $t1, 268($sp) +beq $t1, 0, div_zero_error +div $a0, $a0, $t1 +sw $a0, 260($sp) li $a0, 20 li $v0, 9 syscall bge $v0, $sp heap_error move $t0, $v0 -li $t1, 3 +li $t1, 4 sw $t1, 0($t0) -la $t1, Bool_name +la $t1, Int_name sw $t1, 4($t0) li $t1, 5 sw $t1, 8($t0) -la $t1, Bool_methods +la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 188($sp) -li $t0, 0 -sw $t0, 192($sp) +sw $t0, 256($sp) move $t0, $sp -lw $t1, 192($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 188($t0) +lw $t1, 260($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -jal Bool_init -sw $a1, 196($sp) -lw $t1, 188($sp) -sw $t1, 84($sp) -b label_4 -label_3: -move $t0, $sp -lw $t1, 284($t0) +lw $t1, 256($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 284($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 224($sp) +jal Int_init +sw $a1, 280($sp) +lw $t0, 428($sp) +lw $t1, 16($t0) +sw $t1, 244($sp) +lw $t0, 256($sp) +lw $t1, 16($t0) +sw $t1, 248($sp) +lw $a0, 244($sp) +lw $t1, 248($sp) +mul $a0, $a0, $t1 +sw $a0, 240($sp) li $a0, 20 li $v0, 9 syscall @@ -1061,28 +1015,26 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 228($sp) -li $t0, 2 -sw $t0, 232($sp) +sw $t0, 236($sp) move $t0, $sp -lw $t1, 232($t0) +lw $t1, 240($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 228($t0) +lw $t1, 236($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init -sw $a1, 236($sp) -lw $t0, 224($sp) +sw $a1, 284($sp) +lw $t0, 508($sp) lw $t1, 16($t0) -sw $t1, 216($sp) -lw $t0, 228($sp) +sw $t1, 224($sp) +lw $t0, 236($sp) lw $t1, 16($t0) -sw $t1, 220($sp) -lw $a0, 216($sp) -lw $t1, 220($sp) +sw $t1, 228($sp) +lw $a0, 224($sp) +lw $t1, 228($sp) sub $a0, $a0, $t1 -sw $a0, 212($sp) +sw $a0, 220($sp) li $a0, 20 li $v0, 9 syscall @@ -1096,16 +1048,16 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 208($sp) +sw $t0, 216($sp) move $t0, $sp -lw $t1, 212($t0) +lw $t1, 220($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 208($t0) +lw $t1, 216($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init -sw $a1, 240($sp) +sw $a1, 288($sp) li $a0, 20 li $v0, 9 syscall @@ -1119,56 +1071,83 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 244($sp) -li $t0, 1 -sw $t0, 248($sp) +sw $t0, 292($sp) +li $t0, 0 +sw $t0, 296($sp) move $t0, $sp -lw $t1, 248($t0) +lw $t1, 296($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 244($t0) +lw $t1, 292($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init -sw $a1, 252($sp) +sw $a1, 300($sp) +lw $t0, 216($sp) +lw $t1, 16($t0) +sw $t1, 208($sp) +lw $t0, 292($sp) +lw $t1, 16($t0) +sw $t1, 212($sp) +lw $a0, 208($sp) +lw $t1, 212($sp) +seq $a0, $a0, $t1 +sw $a0, 204($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 200($sp) move $t0, $sp -lw $t1, 208($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 244($t0) +lw $t1, 204($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 284($t0) +lw $t1, 200($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 284($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 20($t2) -jal $t3 -sw $a1, 204($sp) +jal Bool_init +sw $a1, 304($sp) +lw $t0, 200($sp) +lw $a0, 16($t0) +bnez $a0, label_8 +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 308($sp) +li $t0, 1 +sw $t0, 312($sp) move $t0, $sp -lw $t1, 204($t0) +lw $t1, 312($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 280($t0) +lw $t1, 308($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 280($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 28($t2) -jal $t3 -sw $a1, 200($sp) -lw $t1, 200($sp) -sw $t1, 84($sp) -label_4: -lw $t1, 84($sp) -sw $t1, 44($sp) -b label_5 -label_2: +jal Bool_init +sw $a1, 316($sp) +lw $t1, 308($sp) +sw $t1, 196($sp) +b label_9 +label_8: li $a0, 20 li $v0, 9 syscall @@ -1182,25 +1161,25 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Bool_methods sw $t1, 12($t0) -sw $t0, 256($sp) -li $t0, 1 -sw $t0, 260($sp) +sw $t0, 320($sp) +li $t0, 0 +sw $t0, 324($sp) move $t0, $sp -lw $t1, 260($t0) +lw $t1, 324($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 256($t0) +lw $t1, 320($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Bool_init -sw $a1, 264($sp) -lw $t1, 256($sp) -sw $t1, 44($sp) -label_5: -lw $t1, 44($sp) -sw $t1, 4($sp) -b label_6 -label_1: +sw $a1, 328($sp) +lw $t1, 320($sp) +sw $t1, 196($sp) +label_9: +lw $t1, 196($sp) +sw $t1, 140($sp) +b label_10 +label_7: li $a0, 20 li $v0, 9 syscall @@ -1214,29 +1193,29 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Bool_methods sw $t1, 12($t0) -sw $t0, 268($sp) -li $t0, 1 -sw $t0, 272($sp) +sw $t0, 332($sp) +li $t0, 0 +sw $t0, 336($sp) move $t0, $sp -lw $t1, 272($t0) +lw $t1, 336($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 268($t0) +lw $t1, 332($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Bool_init -sw $a1, 276($sp) -lw $t1, 268($sp) -sw $t1, 4($sp) -label_6: -lw $a1, 4($sp) -lw $ra, 0($sp) -addi $sp, $sp, 288 -jr $ra -Main.main: -addi $sp, $sp, -92 -addi $sp, $sp, -4 -sw $ra, 0($sp) +sw $a1, 340($sp) +lw $t1, 332($sp) +sw $t1, 140($sp) +label_10: +lw $t0, 140($sp) +lw $a0, 16($t0) +bnez $a0, label_5 +b label_6 +label_5: +lw $t0, 544($sp) +lw $t1, 24($t0) +sw $t1, 428($sp) li $a0, 20 li $v0, 9 syscall @@ -1250,24 +1229,28 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 16($sp) +sw $t0, 364($sp) li $t0, 1 -sw $t0, 20($sp) +sw $t0, 368($sp) move $t0, $sp -lw $t1, 20($t0) +lw $t1, 368($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 16($t0) +lw $t1, 364($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init -sw $a1, 24($sp) -lw $t0, 16($sp) +sw $a1, 372($sp) +lw $t0, 428($sp) lw $t1, 16($t0) -sw $t1, 12($sp) -lw $t1, 12($sp) -xor $a0, $t1, 1 -sw $a0, 8($sp) +sw $t1, 352($sp) +lw $t0, 364($sp) +lw $t1, 16($t0) +sw $t1, 356($sp) +lw $a0, 352($sp) +lw $t1, 356($sp) +add $a0, $a0, $t1 +sw $a0, 348($sp) li $a0, 20 li $v0, 9 syscall @@ -1281,88 +1264,153 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 4($sp) +sw $t0, 344($sp) move $t0, $sp -lw $t1, 8($t0) +lw $t1, 348($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 4($t0) +lw $t1, 344($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init -sw $a1, 28($sp) -lw $t0, 96($sp) -lw $t1, 4($sp) -sw $t1, 16($t0) -la $t0, data_3 -sw $t0, 40($sp) +sw $a1, 376($sp) +lw $t0, 544($sp) +lw $t1, 344($sp) +sw $t1, 24($t0) +b label_4 +label_6: +lw $t0, 544($sp) +lw $t1, 20($t0) +sw $t1, 508($sp) +lw $t0, 544($sp) +lw $t1, 24($t0) +sw $t1, 428($sp) +lw $t0, 544($sp) +lw $t1, 24($t0) +sw $t1, 428($sp) +lw $t0, 428($sp) +lw $t1, 16($t0) +sw $t1, 416($sp) +lw $t0, 428($sp) +lw $t1, 16($t0) +sw $t1, 420($sp) +lw $a0, 416($sp) +lw $t1, 420($sp) +mul $a0, $a0, $t1 +sw $a0, 412($sp) li $a0, 20 li $v0, 9 syscall bge $v0, $sp heap_error move $t0, $v0 -li $t1, 2 +li $t1, 4 sw $t1, 0($t0) -la $t1, String_name +la $t1, Int_name sw $t1, 4($t0) li $t1, 5 sw $t1, 8($t0) -la $t1, String_methods +la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 44($sp) +sw $t0, 408($sp) move $t0, $sp -lw $t1, 40($t0) +lw $t1, 412($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 44($t0) +lw $t1, 408($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -jal String_init -sw $a1, 48($sp) +jal Int_init +sw $a1, 432($sp) +lw $t0, 508($sp) +lw $t1, 16($t0) +sw $t1, 396($sp) +lw $t0, 408($sp) +lw $t1, 16($t0) +sw $t1, 400($sp) +lw $a0, 396($sp) +lw $t1, 400($sp) +slt $a0, $a0, $t1 +sw $a0, 392($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 388($sp) move $t0, $sp -lw $t1, 44($t0) +lw $t1, 392($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 96($t0) +lw $t1, 388($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 96($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 36($sp) +jal Bool_init +sw $a1, 436($sp) +lw $t0, 388($sp) +lw $a0, 16($t0) +bnez $a0, label_11 +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 440($sp) +li $t0, 0 +sw $t0, 444($sp) move $t0, $sp -lw $t1, 96($t0) +lw $t1, 444($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 96($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 20($t2) -jal $t3 -sw $a1, 60($sp) +lw $t1, 440($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 448($sp) +lw $t1, 440($sp) +sw $t1, 384($sp) +b label_12 +label_11: +lw $t0, 544($sp) +lw $t1, 20($t0) +sw $t1, 508($sp) +lw $t0, 544($sp) +lw $t1, 508($sp) +sw $t1, 16($t0) +lw $t0, 544($sp) +lw $t1, 16($t0) +sw $t1, 464($sp) move $t0, $sp -lw $t1, 60($t0) +lw $t1, 464($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 96($t0) +lw $t1, 544($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 96($t0) +lw $t1, 544($t0) la $t0, void beq $t1, $t0, dispatch_void_error lw $t2, 12($t1) -lw $t3, 28($t2) +lw $t3, 16($t2) jal $t3 -sw $a1, 56($sp) -lw $t0, 56($sp) -lw $a0, 16($t0) -bnez $a0, label_7 +sw $a1, 460($sp) la $t0, data_4 -sw $t0, 68($sp) +sw $t0, 472($sp) li $a0, 20 li $v0, 9 syscall @@ -1376,36 +1424,77 @@ li $t1, 5 sw $t1, 8($t0) la $t1, String_methods sw $t1, 12($t0) -sw $t0, 72($sp) +sw $t0, 476($sp) move $t0, $sp -lw $t1, 68($t0) +lw $t1, 472($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 72($t0) +lw $t1, 476($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal String_init -sw $a1, 76($sp) +sw $a1, 480($sp) move $t0, $sp -lw $t1, 72($t0) +lw $t1, 476($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 96($t0) +lw $t1, 544($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 96($t0) +lw $t1, 544($t0) la $t0, void beq $t1, $t0, dispatch_void_error lw $t2, 12($t1) lw $t3, 12($t2) jal $t3 -sw $a1, 64($sp) -lw $t1, 64($sp) -sw $t1, 52($sp) -b label_8 -label_7: +sw $a1, 468($sp) +lw $t1, 468($sp) +sw $t1, 384($sp) +label_12: +lw $t0, 544($sp) +lw $t1, 28($t0) +sw $t1, 504($sp) +lw $t0, 544($sp) +lw $t1, 20($t0) +sw $t1, 508($sp) +lw $t0, 504($sp) +lw $t1, 16($t0) +sw $t1, 496($sp) +lw $t0, 508($sp) +lw $t1, 16($t0) +sw $t1, 500($sp) +lw $a0, 496($sp) +lw $t1, 500($sp) +sle $a0, $a0, $t1 +sw $a0, 492($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 488($sp) +move $t0, $sp +lw $t1, 492($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 488($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 512($sp) +lw $t0, 488($sp) +lw $a0, 16($t0) +bnez $a0, label_13 la $t0, data_5 -sw $t0, 84($sp) +sw $t0, 516($sp) li $a0, 20 li $v0, 9 syscall @@ -1419,34 +1508,97 @@ li $t1, 5 sw $t1, 8($t0) la $t1, String_methods sw $t1, 12($t0) -sw $t0, 88($sp) +sw $t0, 520($sp) move $t0, $sp -lw $t1, 84($t0) +lw $t1, 516($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 88($t0) +lw $t1, 520($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal String_init -sw $a1, 92($sp) +sw $a1, 524($sp) +lw $t1, 520($sp) +sw $t1, 484($sp) +b label_14 +label_13: +la $t0, data_6 +sw $t0, 532($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 536($sp) move $t0, $sp -lw $t1, 88($t0) +lw $t1, 532($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 96($t0) +lw $t1, 536($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 96($t0) +jal String_init +sw $a1, 540($sp) +move $t0, $sp +lw $t1, 536($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 536($t0) la $t0, void beq $t1, $t0, dispatch_void_error lw $t2, 12($t1) -lw $t3, 12($t2) +lw $t3, 0($t2) jal $t3 -sw $a1, 80($sp) -lw $t1, 80($sp) -sw $t1, 52($sp) -label_8: -lw $a1, 52($sp) +sw $a1, 528($sp) +lw $t1, 528($sp) +sw $t1, 484($sp) +label_14: +b label_1 +label_3: +lw $t0, 544($sp) +lw $t1, 64($sp) +sw $t1, 32($t0) lw $ra, 0($sp) -addi $sp, $sp, 100 +addi $sp, $sp, 548 +jr $ra +Main.main: +addi $sp, $sp, -12 +addi $sp, $sp, -4 +sw $ra, 0($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 4($sp) +li $t0, 0 +sw $t0, 8($sp) +move $t0, $sp +lw $t1, 8($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 4($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 12($sp) +lw $a1, 4($sp) +lw $ra, 0($sp) +addi $sp, $sp, 20 jr $ra \ No newline at end of file diff --git a/src/main.py b/src/main.py index 660c2f826..58a91195c 100644 --- a/src/main.py +++ b/src/main.py @@ -75,7 +75,7 @@ def main(_input, _output): # ast, errors, context, scope = SemanticAn if __name__ == "__main__": - in_path = '/home/cwjki/Projects/cool-compiler-2021/tests/codegen/palindrome.cl' + in_path = '/home/cwjki/Projects/cool-compiler-2021/tests/codegen/primes.cl' out_path = '/home/cwjki/Projects/cool-compiler-2021/src/codeMips.mips' _input = sys.argv[1] if len(sys.argv) > 1 else in_path _output = sys.argv[2] if len(sys.argv) > 2 else out_path diff --git a/src/semantic/semantic.py b/src/semantic/semantic.py index f93c48d9e..27894c835 100644 --- a/src/semantic/semantic.py +++ b/src/semantic/semantic.py @@ -277,9 +277,9 @@ def __init__(self, pos=(0, 0)): self.init_methods() def init_methods(self): - # self.define_method('abort', [], [], self) - # self.define_method('type_name', [], [], self) - # self.define_method('copy', [], [], SelfType()) + self.define_method('abort', [], [], self) + self.define_method('type_name', [], [], self) + self.define_method('copy', [], [], SelfType()) self.define_method('length', [], [], IntType()) self.define_method('concat', ['s'], [self], self) self.define_method('substr', ['i', 'l'], [IntType(), IntType()], self) From b8036be1f72f0865653a4c548581a1d161f83f59 Mon Sep 17 00:00:00 2001 From: cwjki Date: Thu, 24 Feb 2022 00:04:48 -0500 Subject: [PATCH 176/194] having trouble with the parent of built in --- src/codeMips.mips | 12 ++++++------ src/main.py | 6 +++++- src/semantic/semantic.py | 8 ++++---- src/semantic/visitors/typeChecker.py | 1 + src/semantic/visitors/typeCollector.py | 8 ++++---- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/codeMips.mips b/src/codeMips.mips index dd1f301dd..ec8ef5a6d 100644 --- a/src/codeMips.mips +++ b/src/codeMips.mips @@ -14,9 +14,9 @@ Object_methods: .word Object.copy Int_name: .asciiz "Int" Int_methods: -.word Object.abort -.word Object.type_name -.word Object.copy +.word Int.abort +.word Int.type_name +.word Int.copy String_name: .asciiz "String" String_methods: .word String.abort @@ -27,9 +27,9 @@ String_methods: .word String.substr Bool_name: .asciiz "Bool" Bool_methods: -.word Object.abort -.word Object.type_name -.word Object.copy +.word Bool.abort +.word Bool.type_name +.word Bool.copy IO_name: .asciiz "IO" IO_methods: .word Object.abort diff --git a/src/main.py b/src/main.py index 58a91195c..4c1c52697 100644 --- a/src/main.py +++ b/src/main.py @@ -41,8 +41,8 @@ def main(_input, _output): typeBuilder.visit(ast) # print("CONTEXT") - # print(context) # print("TYPE Builder") + # print(context) # if semanticErrors: # for error in semanticErrors: # print(error) @@ -50,12 +50,15 @@ def main(_input, _output): varCollector = VarCollector(context, semanticErrors) scope = varCollector.visit(ast) # print("Var Collector") + # print(context) # if semanticErrors: # for error in semanticErrors: # print(error) typeChecker = TypeChecker(context, semanticErrors) typeChecker.visit(ast, scope) + # print("Type Checker") + # print(context) if semanticErrors: for error in semanticErrors: @@ -72,6 +75,7 @@ def main(_input, _output): with open(_output, 'w+') as f: f.write(mips_code) + # ast, errors, context, scope = SemanticAn if __name__ == "__main__": diff --git a/src/semantic/semantic.py b/src/semantic/semantic.py index 27894c835..af4117449 100644 --- a/src/semantic/semantic.py +++ b/src/semantic/semantic.py @@ -114,7 +114,7 @@ def define_method(self, name: str, param_names: list, param_types: list, return_ return method def has_attr(self, name: str): - try: + try: attr_name = self.get_attribute(name) except: return False @@ -211,7 +211,7 @@ def __init__(self, pos=(0, 0)): self.methods = {} self.parent = None self.pos = pos - # self.init_methods() + self.init_methods() def init_methods(self): self.define_method('abort', [], [], self) @@ -250,7 +250,7 @@ def __init__(self, pos=(0, 0)): self.methods = {} self.parent = None self.pos = pos - # self.init_methods() + self.init_methods() def init_methods(self): self.define_method('abort', [], [], self) @@ -377,7 +377,7 @@ def create_type(self, name, pos): self.graph[parentName] = [name] return typex - def get_type(self, name: str, pos = None): + def get_type(self, name: str, pos=None): try: return self.types[name] except KeyError: diff --git a/src/semantic/visitors/typeChecker.py b/src/semantic/visitors/typeChecker.py index 28021822a..ec167b323 100644 --- a/src/semantic/visitors/typeChecker.py +++ b/src/semantic/visitors/typeChecker.py @@ -457,6 +457,7 @@ def _get_method(self, typex, name, pos): return typex.get_method(name, pos) except SemanticError: if type(typex) != ErrorType and type(typex) != AutoType: + print(typex.parent) errorText = f'Dispatch to undefined method {name}.' self.errors.append(AttributexError(errorText, *pos)) return MethodError(name, [], [], ErrorType()) diff --git a/src/semantic/visitors/typeCollector.py b/src/semantic/visitors/typeCollector.py index e356ad1df..db3eb3ac2 100644 --- a/src/semantic/visitors/typeCollector.py +++ b/src/semantic/visitors/typeCollector.py @@ -23,10 +23,10 @@ def visit(self, programNode): self.context.types['SELF_TYPE'] = SelfType() self.context.types['IO'] = IOType() - self.context.types['IO'].set_parent(self.context.types['Object']) - self.context.types['String'].set_parent(self.context.types['Object']) - self.context.types['Int'].set_parent(self.context.types['Object']) - self.context.types['Bool'].set_parent(self.context.types['Object']) + # self.context.types['IO'].set_parent(self.context.types['Object']) + # self.context.types['String'].set_parent(self.context.types['Object']) + # self.context.types['Int'].set_parent(self.context.types['Object']) + # self.context.types['Bool'].set_parent(self.context.types['Object']) for classDeclarationNode in programNode.declarations: self.visit(classDeclarationNode) From 44aaacafefe1578f58ee455dcd7d00964ef79a0f Mon Sep 17 00:00:00 2001 From: cwjki Date: Thu, 24 Feb 2022 00:08:11 -0500 Subject: [PATCH 177/194] again --- src/main.py | 2 +- src/semantic/visitors/typeChecker.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main.py b/src/main.py index 4c1c52697..b877e3fe3 100644 --- a/src/main.py +++ b/src/main.py @@ -79,7 +79,7 @@ def main(_input, _output): # ast, errors, context, scope = SemanticAn if __name__ == "__main__": - in_path = '/home/cwjki/Projects/cool-compiler-2021/tests/codegen/primes.cl' + in_path = '/home/cwjki/Projects/cool-compiler-2021/tests/semantic/dispatch1.cl' out_path = '/home/cwjki/Projects/cool-compiler-2021/src/codeMips.mips' _input = sys.argv[1] if len(sys.argv) > 1 else in_path _output = sys.argv[2] if len(sys.argv) > 2 else out_path diff --git a/src/semantic/visitors/typeChecker.py b/src/semantic/visitors/typeChecker.py index ec167b323..28021822a 100644 --- a/src/semantic/visitors/typeChecker.py +++ b/src/semantic/visitors/typeChecker.py @@ -457,7 +457,6 @@ def _get_method(self, typex, name, pos): return typex.get_method(name, pos) except SemanticError: if type(typex) != ErrorType and type(typex) != AutoType: - print(typex.parent) errorText = f'Dispatch to undefined method {name}.' self.errors.append(AttributexError(errorText, *pos)) return MethodError(name, [], [], ErrorType()) From a55433df1e0bd019c344bd77d9635ac15f3c39ff Mon Sep 17 00:00:00 2001 From: cwjki Date: Thu, 24 Feb 2022 00:23:47 -0500 Subject: [PATCH 178/194] checking parent of built in --- src/semantic/visitors/typeChecker.py | 4 +++- src/semantic/visitors/typeCollector.py | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/semantic/visitors/typeChecker.py b/src/semantic/visitors/typeChecker.py index 28021822a..a0559a5a7 100644 --- a/src/semantic/visitors/typeChecker.py +++ b/src/semantic/visitors/typeChecker.py @@ -1,3 +1,4 @@ +from cgi import print_directory from semantic.semantic import AutoType, BoolType, ErrorType, IntType, MethodError, ObjectType, StringType, VariableInfo, VoidType from utils.errors import AttributexError, SemanticError, TypexError from utils import visitor @@ -206,7 +207,6 @@ def visit(self, memberCallNode, scope): self.errors.append(TypexError( errorText, memberCallNode.line, memberCallNode.col)) - memberCallNode.static_type = typex memberCallNode.computed_type = get_type(method.return_type, typex) return memberCallNode.computed_type @@ -456,6 +456,8 @@ def _get_method(self, typex, name, pos): try: return typex.get_method(name, pos) except SemanticError: + print(self.context) + print(typex.parent) if type(typex) != ErrorType and type(typex) != AutoType: errorText = f'Dispatch to undefined method {name}.' self.errors.append(AttributexError(errorText, *pos)) diff --git a/src/semantic/visitors/typeCollector.py b/src/semantic/visitors/typeCollector.py index db3eb3ac2..e356ad1df 100644 --- a/src/semantic/visitors/typeCollector.py +++ b/src/semantic/visitors/typeCollector.py @@ -23,10 +23,10 @@ def visit(self, programNode): self.context.types['SELF_TYPE'] = SelfType() self.context.types['IO'] = IOType() - # self.context.types['IO'].set_parent(self.context.types['Object']) - # self.context.types['String'].set_parent(self.context.types['Object']) - # self.context.types['Int'].set_parent(self.context.types['Object']) - # self.context.types['Bool'].set_parent(self.context.types['Object']) + self.context.types['IO'].set_parent(self.context.types['Object']) + self.context.types['String'].set_parent(self.context.types['Object']) + self.context.types['Int'].set_parent(self.context.types['Object']) + self.context.types['Bool'].set_parent(self.context.types['Object']) for classDeclarationNode in programNode.declarations: self.visit(classDeclarationNode) From a77ffe12e2c630a780ee5d06c6cf9e20962f0975 Mon Sep 17 00:00:00 2001 From: cwjki Date: Thu, 24 Feb 2022 00:25:34 -0500 Subject: [PATCH 179/194] rechecking parent of built in --- src/semantic/semantic.py | 6 +++--- src/semantic/visitors/typeChecker.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/semantic/semantic.py b/src/semantic/semantic.py index af4117449..17212ac15 100644 --- a/src/semantic/semantic.py +++ b/src/semantic/semantic.py @@ -277,9 +277,9 @@ def __init__(self, pos=(0, 0)): self.init_methods() def init_methods(self): - self.define_method('abort', [], [], self) - self.define_method('type_name', [], [], self) - self.define_method('copy', [], [], SelfType()) + # self.define_method('abort', [], [], self) + # self.define_method('type_name', [], [], self) + # self.define_method('copy', [], [], SelfType()) self.define_method('length', [], [], IntType()) self.define_method('concat', ['s'], [self], self) self.define_method('substr', ['i', 'l'], [IntType(), IntType()], self) diff --git a/src/semantic/visitors/typeChecker.py b/src/semantic/visitors/typeChecker.py index a0559a5a7..d60f44f8c 100644 --- a/src/semantic/visitors/typeChecker.py +++ b/src/semantic/visitors/typeChecker.py @@ -456,8 +456,8 @@ def _get_method(self, typex, name, pos): try: return typex.get_method(name, pos) except SemanticError: - print(self.context) - print(typex.parent) + # print(self.context) + # print(typex.parent) if type(typex) != ErrorType and type(typex) != AutoType: errorText = f'Dispatch to undefined method {name}.' self.errors.append(AttributexError(errorText, *pos)) From cecd267b45a99e1dd9e6da69c58832a45f524609 Mon Sep 17 00:00:00 2001 From: cwjki Date: Thu, 24 Feb 2022 00:33:23 -0500 Subject: [PATCH 180/194] problem solve --- src/codeMips.mips | 18 +++++++++--------- src/main.py | 2 +- src/semantic/semantic.py | 4 ++-- src/semantic/visitors/typeChecker.py | 3 +-- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/codeMips.mips b/src/codeMips.mips index ec8ef5a6d..9249085db 100644 --- a/src/codeMips.mips +++ b/src/codeMips.mips @@ -14,22 +14,22 @@ Object_methods: .word Object.copy Int_name: .asciiz "Int" Int_methods: -.word Int.abort -.word Int.type_name -.word Int.copy +.word Object.abort +.word Object.type_name +.word Object.copy String_name: .asciiz "String" String_methods: -.word String.abort -.word String.type_name -.word String.copy +.word Object.abort +.word Object.type_name +.word Object.copy .word String.length .word String.concat .word String.substr Bool_name: .asciiz "Bool" Bool_methods: -.word Bool.abort -.word Bool.type_name -.word Bool.copy +.word Object.abort +.word Object.type_name +.word Object.copy IO_name: .asciiz "IO" IO_methods: .word Object.abort diff --git a/src/main.py b/src/main.py index b877e3fe3..4c1c52697 100644 --- a/src/main.py +++ b/src/main.py @@ -79,7 +79,7 @@ def main(_input, _output): # ast, errors, context, scope = SemanticAn if __name__ == "__main__": - in_path = '/home/cwjki/Projects/cool-compiler-2021/tests/semantic/dispatch1.cl' + in_path = '/home/cwjki/Projects/cool-compiler-2021/tests/codegen/primes.cl' out_path = '/home/cwjki/Projects/cool-compiler-2021/src/codeMips.mips' _input = sys.argv[1] if len(sys.argv) > 1 else in_path _output = sys.argv[2] if len(sys.argv) > 2 else out_path diff --git a/src/semantic/semantic.py b/src/semantic/semantic.py index 17212ac15..47121ea59 100644 --- a/src/semantic/semantic.py +++ b/src/semantic/semantic.py @@ -211,7 +211,7 @@ def __init__(self, pos=(0, 0)): self.methods = {} self.parent = None self.pos = pos - self.init_methods() + # self.init_methods() def init_methods(self): self.define_method('abort', [], [], self) @@ -250,7 +250,7 @@ def __init__(self, pos=(0, 0)): self.methods = {} self.parent = None self.pos = pos - self.init_methods() + # self.init_methods() def init_methods(self): self.define_method('abort', [], [], self) diff --git a/src/semantic/visitors/typeChecker.py b/src/semantic/visitors/typeChecker.py index d60f44f8c..c5da7bd56 100644 --- a/src/semantic/visitors/typeChecker.py +++ b/src/semantic/visitors/typeChecker.py @@ -453,11 +453,10 @@ def _get_type(self, ntype, pos): return ErrorType() def _get_method(self, typex, name, pos): + typex = self.context.get_type(typex.name) try: return typex.get_method(name, pos) except SemanticError: - # print(self.context) - # print(typex.parent) if type(typex) != ErrorType and type(typex) != AutoType: errorText = f'Dispatch to undefined method {name}.' self.errors.append(AttributexError(errorText, *pos)) From b97e66984d0089b0e203c2962013ee2ec68cd3ca Mon Sep 17 00:00:00 2001 From: cwjki Date: Thu, 24 Feb 2022 00:51:34 -0500 Subject: [PATCH 181/194] testing void --- src/code_generator/COOLToCILVisitor.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index 185601ce1..7bb382879 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -705,15 +705,15 @@ def visit(self, node, scope): cil.ArgNode(value), cil.ArgNode(instance)], "Bool")) return instance - @visitor.when(VoidNode) - def visit(self, node, scope): - result_local = self.define_internal_local(scope=scope) - self.register_instruction(cil.LoadStringNode(node.id, result_local)) - instance = self.define_internal_local(scope=scope, name="instance") - self.register_instruction(cil.AllocateNode( - 'String', self.context.get_type('String').tag, instance)) - result_init = self.define_internal_local( - scope=scope, name="result_init") - self.register_instruction(cil.CallNode(result_init, 'Void_init', [ - cil.ArgNode(result_local), cil.ArgNode(instance)], "String")) - return instance + # @visitor.when(VoidNode) + # def visit(self, node, scope): + # result_local = self.define_internal_local(scope=scope) + # self.register_instruction(cil.LoadStringNode(node.id, result_local)) + # instance = self.define_internal_local(scope=scope, name="instance") + # self.register_instruction(cil.AllocateNode( + # 'String', self.context.get_type('String').tag, instance)) + # result_init = self.define_internal_local( + # scope=scope, name="result_init") + # self.register_instruction(cil.CallNode(result_init, 'Void_init', [ + # cil.ArgNode(result_local), cil.ArgNode(instance)], "String")) + # return instance From 035eab3dc5520cef6157af08b5de9f94a12190f0 Mon Sep 17 00:00:00 2001 From: cwjki Date: Thu, 24 Feb 2022 12:01:00 -0500 Subject: [PATCH 182/194] changing neg y xor cil --- src/codeMips.mips | 939 +++++-------------------- src/code_generator/CILToMIPSVisitor.py | 2 +- src/code_generator/COOLToCILVisitor.py | 25 +- src/main.py | 2 +- 4 files changed, 196 insertions(+), 772 deletions(-) diff --git a/src/codeMips.mips b/src/codeMips.mips index 9249085db..7b51e8589 100644 --- a/src/codeMips.mips +++ b/src/codeMips.mips @@ -49,16 +49,13 @@ Main_methods: .word IO.in_string .word IO.in_int .word Main.main +.word Main.fib data_0: .asciiz "Abort called from class " data_1: .asciiz " " empty_str: .asciiz "" -data_3: .asciiz "2 is trivially prime. +data_3: .asciiz "Enter n to find nth fibonacci number! " -data_4: .asciiz " is prime. -" -data_5: .asciiz "continue" -data_6: .asciiz "halt" .text dispatch_void_error: la $a0 dispatch_void @@ -100,7 +97,7 @@ main: addi $sp, $sp, -8 addi $sp, $sp, -4 sw $ra, 0($sp) -li $a0, 36 +li $a0, 16 li $v0, 9 syscall bge $v0, $sp heap_error @@ -109,7 +106,7 @@ li $t1, 5 sw $t1, 0($t0) la $t1, Main_name sw $t1, 4($t0) -li $t1, 9 +li $t1, 4 sw $t1, 8($t0) la $t1, Main_methods sw $t1, 12($t0) @@ -605,18 +602,25 @@ lw $ra, 0($sp) addi $sp, $sp, 24 jr $ra Main_init: -addi $sp, $sp, -540 +addi $sp, $sp, -4 addi $sp, $sp, -4 sw $ra, 0($sp) move $t0, $sp -lw $t1, 544($t0) +lw $t1, 8($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal IO_init sw $a1, 4($sp) move $a1, $zero +lw $ra, 0($sp) +addi $sp, $sp, 12 +jr $ra +Main.main: +addi $sp, $sp, -44 +addi $sp, $sp, -4 +sw $ra, 0($sp) la $t0, data_3 -sw $t0, 12($sp) +sw $t0, 8($sp) li $a0, 20 li $v0, 9 syscall @@ -630,154 +634,116 @@ li $t1, 5 sw $t1, 8($t0) la $t1, String_methods sw $t1, 12($t0) -sw $t0, 16($sp) +sw $t0, 12($sp) move $t0, $sp -lw $t1, 12($t0) +lw $t1, 8($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 16($t0) +lw $t1, 12($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal String_init -sw $a1, 20($sp) +sw $a1, 16($sp) move $t0, $sp -lw $t1, 16($t0) +lw $t1, 12($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 544($t0) +lw $t1, 48($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 544($t0) +lw $t1, 48($t0) la $t0, void beq $t1, $t0, dispatch_void_error lw $t2, 12($t1) lw $t3, 12($t2) jal $t3 -sw $a1, 8($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 24($sp) -li $t0, 2 -sw $t0, 28($sp) +sw $a1, 4($sp) +move $t0, $sp +lw $t1, 48($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 48($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 24($t2) +jal $t3 +sw $a1, 28($sp) move $t0, $sp lw $t1, 28($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 24($t0) +lw $t1, 48($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -jal Int_init -sw $a1, 32($sp) -lw $t0, 544($sp) -lw $t1, 24($sp) -sw $t1, 16($t0) -lw $t0, 544($sp) -lw $t1, 16($t0) -sw $t1, 464($sp) -lw $t0, 544($sp) -lw $t1, 464($sp) -sw $t1, 20($t0) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 40($sp) -li $t0, 0 -sw $t0, 44($sp) +lw $t1, 48($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 32($t2) +jal $t3 +sw $a1, 24($sp) move $t0, $sp -lw $t1, 44($t0) +lw $t1, 24($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 40($t0) +lw $t1, 48($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -jal Int_init -sw $a1, 48($sp) -lw $t0, 544($sp) -lw $t1, 40($sp) -sw $t1, 24($t0) +lw $t1, 48($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 16($t2) +jal $t3 +sw $a1, 20($sp) +la $t0, data_1 +sw $t0, 36($sp) li $a0, 20 li $v0, 9 syscall bge $v0, $sp heap_error move $t0, $v0 -li $t1, 4 +li $t1, 2 sw $t1, 0($t0) -la $t1, Int_name +la $t1, String_name sw $t1, 4($t0) li $t1, 5 sw $t1, 8($t0) -la $t1, Int_methods +la $t1, String_methods sw $t1, 12($t0) -sw $t0, 52($sp) -li $t0, 500 -sw $t0, 56($sp) +sw $t0, 40($sp) move $t0, $sp -lw $t1, 56($t0) +lw $t1, 36($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 52($t0) +lw $t1, 40($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -jal Int_init -sw $a1, 60($sp) -lw $t0, 544($sp) -lw $t1, 52($sp) -sw $t1, 28($t0) -label_1: -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 68($sp) -li $t0, 1 -sw $t0, 72($sp) +jal String_init +sw $a1, 44($sp) move $t0, $sp -lw $t1, 72($t0) +lw $t1, 40($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 68($t0) +lw $t1, 48($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -jal Bool_init -sw $a1, 76($sp) -lw $t0, 68($sp) -lw $a0, 16($t0) -bnez $a0, label_2 -b label_3 -label_2: -lw $t0, 544($sp) -lw $t1, 20($t0) -sw $t1, 508($sp) +lw $t1, 48($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 32($sp) +lw $a1, 32($sp) +lw $ra, 0($sp) +addi $sp, $sp, 52 +jr $ra +Main.fib: +addi $sp, $sp, -172 +addi $sp, $sp, -4 +sw $ra, 0($sp) li $a0, 20 li $v0, 9 syscall @@ -791,28 +757,20 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 100($sp) +sw $t0, 4($sp) li $t0, 1 -sw $t0, 104($sp) +sw $t0, 8($sp) move $t0, $sp -lw $t1, 104($t0) +lw $t1, 8($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 100($t0) +lw $t1, 4($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init -sw $a1, 108($sp) -lw $t0, 508($sp) -lw $t1, 16($t0) -sw $t1, 88($sp) -lw $t0, 100($sp) -lw $t1, 16($t0) -sw $t1, 92($sp) -lw $a0, 88($sp) -lw $t1, 92($sp) -add $a0, $a0, $t1 -sw $a0, 84($sp) +sw $a1, 12($sp) +lw $t1, 4($sp) +sw $t1, 16($sp) li $a0, 20 li $v0, 9 syscall @@ -826,19 +784,20 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 80($sp) +sw $t0, 20($sp) +li $t0, 0 +sw $t0, 24($sp) move $t0, $sp -lw $t1, 84($t0) +lw $t1, 24($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 80($t0) +lw $t1, 20($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init -sw $a1, 112($sp) -lw $t0, 544($sp) -lw $t1, 80($sp) -sw $t1, 20($t0) +sw $a1, 28($sp) +lw $t1, 20($sp) +sw $t1, 32($sp) li $a0, 20 li $v0, 9 syscall @@ -852,41 +811,21 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 120($sp) -li $t0, 2 -sw $t0, 124($sp) +sw $t0, 36($sp) +li $t0, 0 +sw $t0, 40($sp) move $t0, $sp -lw $t1, 124($t0) +lw $t1, 40($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 120($t0) +lw $t1, 36($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init -sw $a1, 128($sp) -lw $t0, 544($sp) -lw $t1, 120($sp) -sw $t1, 24($t0) -label_4: -lw $t0, 544($sp) -lw $t1, 20($t0) -sw $t1, 508($sp) -lw $t0, 544($sp) -lw $t1, 24($t0) -sw $t1, 428($sp) -lw $t0, 544($sp) -lw $t1, 24($t0) -sw $t1, 428($sp) -lw $t0, 428($sp) -lw $t1, 16($t0) -sw $t1, 172($sp) -lw $t0, 428($sp) -lw $t1, 16($t0) -sw $t1, 176($sp) -lw $a0, 172($sp) -lw $t1, 176($sp) -mul $a0, $a0, $t1 -sw $a0, 168($sp) +sw $a1, 44($sp) +lw $t1, 36($sp) +sw $t1, 48($sp) +label_1: li $a0, 20 li $v0, 9 syscall @@ -900,26 +839,28 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 164($sp) +sw $t0, 84($sp) +li $t0, 0 +sw $t0, 88($sp) move $t0, $sp -lw $t1, 168($t0) +lw $t1, 88($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 164($t0) +lw $t1, 84($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init -sw $a1, 188($sp) -lw $t0, 508($sp) +sw $a1, 92($sp) +lw $t0, 180($sp) lw $t1, 16($t0) -sw $t1, 152($sp) -lw $t0, 164($sp) +sw $t1, 76($sp) +lw $t0, 84($sp) lw $t1, 16($t0) -sw $t1, 156($sp) -lw $a0, 152($sp) -lw $t1, 156($sp) -slt $a0, $a0, $t1 -sw $a0, 148($sp) +sw $t1, 80($sp) +lw $a0, 76($sp) +lw $t1, 80($sp) +seq $a0, $a0, $t1 +sw $a0, 72($sp) li $a0, 20 li $v0, 9 syscall @@ -933,75 +874,60 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Bool_methods sw $t1, 12($t0) -sw $t0, 144($sp) +sw $t0, 68($sp) move $t0, $sp -lw $t1, 148($t0) +lw $t1, 72($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 144($t0) +lw $t1, 68($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Bool_init -sw $a1, 192($sp) -lw $t0, 144($sp) -lw $a0, 16($t0) -bnez $a0, label_7 -lw $t0, 544($sp) -lw $t1, 20($t0) -sw $t1, 508($sp) -lw $t0, 544($sp) -lw $t1, 24($t0) -sw $t1, 428($sp) -lw $t0, 544($sp) -lw $t1, 20($t0) -sw $t1, 508($sp) -lw $t0, 544($sp) -lw $t1, 24($t0) -sw $t1, 428($sp) -lw $t0, 508($sp) -lw $t1, 16($t0) -sw $t1, 264($sp) -lw $t0, 428($sp) +sw $a1, 96($sp) +lw $t0, 68($sp) lw $t1, 16($t0) -sw $t1, 268($sp) -lw $a0, 264($sp) -lw $t1, 268($sp) -beq $t1, 0, div_zero_error -div $a0, $a0, $t1 -sw $a0, 260($sp) +sw $t1, 64($sp) +lw $t1, 64($sp) +xor $a0, $t1, 1 +sw $a0, 60($sp) li $a0, 20 li $v0, 9 syscall bge $v0, $sp heap_error move $t0, $v0 -li $t1, 4 +li $t1, 3 sw $t1, 0($t0) -la $t1, Int_name +la $t1, Bool_name sw $t1, 4($t0) li $t1, 5 sw $t1, 8($t0) -la $t1, Int_methods +la $t1, Bool_methods sw $t1, 12($t0) -sw $t0, 256($sp) +sw $t0, 56($sp) move $t0, $sp -lw $t1, 260($t0) +lw $t1, 60($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 256($t0) +lw $t1, 56($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -jal Int_init -sw $a1, 280($sp) -lw $t0, 428($sp) +jal Bool_init +sw $a1, 100($sp) +lw $t0, 56($sp) +lw $a0, 16($t0) +bnez $a0, label_2 +b label_3 +label_2: +lw $t0, 16($sp) lw $t1, 16($t0) -sw $t1, 244($sp) -lw $t0, 256($sp) +sw $t1, 112($sp) +lw $t0, 32($sp) lw $t1, 16($t0) -sw $t1, 248($sp) -lw $a0, 244($sp) -lw $t1, 248($sp) -mul $a0, $a0, $t1 -sw $a0, 240($sp) +sw $t1, 116($sp) +lw $a0, 112($sp) +lw $t1, 116($sp) +add $a0, $a0, $t1 +sw $a0, 108($sp) li $a0, 20 li $v0, 9 syscall @@ -1015,26 +941,18 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 236($sp) +sw $t0, 104($sp) move $t0, $sp -lw $t1, 240($t0) +lw $t1, 108($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 236($t0) +lw $t1, 104($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init -sw $a1, 284($sp) -lw $t0, 508($sp) -lw $t1, 16($t0) -sw $t1, 224($sp) -lw $t0, 236($sp) -lw $t1, 16($t0) -sw $t1, 228($sp) -lw $a0, 224($sp) -lw $t1, 228($sp) -sub $a0, $a0, $t1 -sw $a0, 220($sp) +sw $a1, 120($sp) +lw $t1, 104($sp) +sw $t1, 48($sp) li $a0, 20 li $v0, 9 syscall @@ -1048,16 +966,28 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 216($sp) +sw $t0, 144($sp) +li $t0, 1 +sw $t0, 148($sp) move $t0, $sp -lw $t1, 220($t0) +lw $t1, 148($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 216($t0) +lw $t1, 144($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init -sw $a1, 288($sp) +sw $a1, 152($sp) +lw $t0, 180($sp) +lw $t1, 16($t0) +sw $t1, 136($sp) +lw $t0, 144($sp) +lw $t1, 16($t0) +sw $t1, 140($sp) +lw $a0, 136($sp) +lw $t1, 140($sp) +sub $a0, $a0, $t1 +sw $a0, 132($sp) li $a0, 20 li $v0, 9 syscall @@ -1071,534 +1001,27 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 292($sp) -li $t0, 0 -sw $t0, 296($sp) +sw $t0, 128($sp) move $t0, $sp -lw $t1, 296($t0) +lw $t1, 132($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 292($t0) +lw $t1, 128($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init -sw $a1, 300($sp) -lw $t0, 216($sp) -lw $t1, 16($t0) -sw $t1, 208($sp) -lw $t0, 292($sp) -lw $t1, 16($t0) -sw $t1, 212($sp) -lw $a0, 208($sp) -lw $t1, 212($sp) -seq $a0, $a0, $t1 -sw $a0, 204($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 200($sp) -move $t0, $sp -lw $t1, 204($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 200($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 304($sp) -lw $t0, 200($sp) -lw $a0, 16($t0) -bnez $a0, label_8 -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 308($sp) -li $t0, 1 -sw $t0, 312($sp) -move $t0, $sp -lw $t1, 312($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 308($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 316($sp) -lw $t1, 308($sp) -sw $t1, 196($sp) -b label_9 -label_8: -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 320($sp) -li $t0, 0 -sw $t0, 324($sp) -move $t0, $sp -lw $t1, 324($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 320($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 328($sp) -lw $t1, 320($sp) -sw $t1, 196($sp) -label_9: -lw $t1, 196($sp) -sw $t1, 140($sp) -b label_10 -label_7: -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 332($sp) -li $t0, 0 -sw $t0, 336($sp) -move $t0, $sp -lw $t1, 336($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 332($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 340($sp) -lw $t1, 332($sp) -sw $t1, 140($sp) -label_10: -lw $t0, 140($sp) -lw $a0, 16($t0) -bnez $a0, label_5 -b label_6 -label_5: -lw $t0, 544($sp) -lw $t1, 24($t0) -sw $t1, 428($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 364($sp) -li $t0, 1 -sw $t0, 368($sp) -move $t0, $sp -lw $t1, 368($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 364($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 372($sp) -lw $t0, 428($sp) -lw $t1, 16($t0) -sw $t1, 352($sp) -lw $t0, 364($sp) -lw $t1, 16($t0) -sw $t1, 356($sp) -lw $a0, 352($sp) -lw $t1, 356($sp) -add $a0, $a0, $t1 -sw $a0, 348($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 344($sp) -move $t0, $sp -lw $t1, 348($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 344($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 376($sp) -lw $t0, 544($sp) -lw $t1, 344($sp) -sw $t1, 24($t0) -b label_4 -label_6: -lw $t0, 544($sp) -lw $t1, 20($t0) -sw $t1, 508($sp) -lw $t0, 544($sp) -lw $t1, 24($t0) -sw $t1, 428($sp) -lw $t0, 544($sp) -lw $t1, 24($t0) -sw $t1, 428($sp) -lw $t0, 428($sp) -lw $t1, 16($t0) -sw $t1, 416($sp) -lw $t0, 428($sp) -lw $t1, 16($t0) -sw $t1, 420($sp) -lw $a0, 416($sp) -lw $t1, 420($sp) -mul $a0, $a0, $t1 -sw $a0, 412($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 408($sp) -move $t0, $sp -lw $t1, 412($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 408($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 432($sp) -lw $t0, 508($sp) -lw $t1, 16($t0) -sw $t1, 396($sp) -lw $t0, 408($sp) -lw $t1, 16($t0) -sw $t1, 400($sp) -lw $a0, 396($sp) -lw $t1, 400($sp) -slt $a0, $a0, $t1 -sw $a0, 392($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 388($sp) -move $t0, $sp -lw $t1, 392($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 388($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 436($sp) -lw $t0, 388($sp) -lw $a0, 16($t0) -bnez $a0, label_11 -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 440($sp) -li $t0, 0 -sw $t0, 444($sp) -move $t0, $sp -lw $t1, 444($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 440($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 448($sp) -lw $t1, 440($sp) -sw $t1, 384($sp) -b label_12 -label_11: -lw $t0, 544($sp) -lw $t1, 20($t0) -sw $t1, 508($sp) -lw $t0, 544($sp) -lw $t1, 508($sp) -sw $t1, 16($t0) -lw $t0, 544($sp) -lw $t1, 16($t0) -sw $t1, 464($sp) -move $t0, $sp -lw $t1, 464($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 544($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 544($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 16($t2) -jal $t3 -sw $a1, 460($sp) -la $t0, data_4 -sw $t0, 472($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 476($sp) -move $t0, $sp -lw $t1, 472($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 476($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 480($sp) -move $t0, $sp -lw $t1, 476($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 544($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 544($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 468($sp) -lw $t1, 468($sp) -sw $t1, 384($sp) -label_12: -lw $t0, 544($sp) -lw $t1, 28($t0) -sw $t1, 504($sp) -lw $t0, 544($sp) -lw $t1, 20($t0) -sw $t1, 508($sp) -lw $t0, 504($sp) -lw $t1, 16($t0) -sw $t1, 496($sp) -lw $t0, 508($sp) -lw $t1, 16($t0) -sw $t1, 500($sp) -lw $a0, 496($sp) -lw $t1, 500($sp) -sle $a0, $a0, $t1 -sw $a0, 492($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 488($sp) -move $t0, $sp -lw $t1, 492($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 488($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 512($sp) -lw $t0, 488($sp) -lw $a0, 16($t0) -bnez $a0, label_13 -la $t0, data_5 -sw $t0, 516($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 520($sp) -move $t0, $sp -lw $t1, 516($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 520($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 524($sp) -lw $t1, 520($sp) -sw $t1, 484($sp) -b label_14 -label_13: -la $t0, data_6 -sw $t0, 532($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 536($sp) -move $t0, $sp -lw $t1, 532($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 536($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 540($sp) -move $t0, $sp -lw $t1, 536($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 536($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 0($t2) -jal $t3 -sw $a1, 528($sp) -lw $t1, 528($sp) -sw $t1, 484($sp) -label_14: +sw $a1, 156($sp) +lw $t1, 128($sp) +sw $t1, 180($sp) +lw $t1, 16($sp) +sw $t1, 32($sp) +lw $t1, 48($sp) +sw $t1, 16($sp) b label_1 label_3: -lw $t0, 544($sp) -lw $t1, 64($sp) -sw $t1, 32($t0) -lw $ra, 0($sp) -addi $sp, $sp, 548 -jr $ra -Main.main: -addi $sp, $sp, -12 -addi $sp, $sp, -4 -sw $ra, 0($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 4($sp) -li $t0, 0 -sw $t0, 8($sp) -move $t0, $sp -lw $t1, 8($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 4($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 12($sp) -lw $a1, 4($sp) +lw $t1, 48($sp) +sw $t1, 172($sp) +lw $a1, 172($sp) lw $ra, 0($sp) -addi $sp, $sp, 20 +addi $sp, $sp, 184 jr $ra \ No newline at end of file diff --git a/src/code_generator/CILToMIPSVisitor.py b/src/code_generator/CILToMIPSVisitor.py index 66299b273..1b9a52cac 100644 --- a/src/code_generator/CILToMIPSVisitor.py +++ b/src/code_generator/CILToMIPSVisitor.py @@ -106,7 +106,7 @@ def visit(self, node): def visit(self, node): expr_offset = self.var_offset[self.current_function.name][node.expr] self.text += f'lw $t1, {expr_offset}($sp)\n' - if node.op == '~': + if node.op == 'not': self.text += f'xor $a0, $t1, 1\n' else: self.text += f'neg $a0, $t1 \n' diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index 7bb382879..4af48644d 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -705,15 +705,16 @@ def visit(self, node, scope): cil.ArgNode(value), cil.ArgNode(instance)], "Bool")) return instance - # @visitor.when(VoidNode) - # def visit(self, node, scope): - # result_local = self.define_internal_local(scope=scope) - # self.register_instruction(cil.LoadStringNode(node.id, result_local)) - # instance = self.define_internal_local(scope=scope, name="instance") - # self.register_instruction(cil.AllocateNode( - # 'String', self.context.get_type('String').tag, instance)) - # result_init = self.define_internal_local( - # scope=scope, name="result_init") - # self.register_instruction(cil.CallNode(result_init, 'Void_init', [ - # cil.ArgNode(result_local), cil.ArgNode(instance)], "String")) - # return instance + @visitor.when(VoidNode) + def visit(self, node, scope): + print(node.id) + result_local = self.define_internal_local(scope=scope) + self.register_instruction(cil.LoadStringNode(node.id, result_local)) + instance = self.define_internal_local(scope=scope, name="instance") + self.register_instruction(cil.AllocateNode( + 'String', self.context.get_type('String').tag, instance)) + result_init = self.define_internal_local( + scope=scope, name="result_init") + self.register_instruction(cil.CallNode(result_init, 'Void_init', [ + cil.ArgNode(result_local), cil.ArgNode(instance)], "String")) + return instance diff --git a/src/main.py b/src/main.py index 4c1c52697..2119e068b 100644 --- a/src/main.py +++ b/src/main.py @@ -79,7 +79,7 @@ def main(_input, _output): # ast, errors, context, scope = SemanticAn if __name__ == "__main__": - in_path = '/home/cwjki/Projects/cool-compiler-2021/tests/codegen/primes.cl' + in_path = '/home/cwjki/Projects/cool-compiler-2021/tests/codegen/fib.cl' out_path = '/home/cwjki/Projects/cool-compiler-2021/src/codeMips.mips' _input = sys.argv[1] if len(sys.argv) > 1 else in_path _output = sys.argv[2] if len(sys.argv) > 2 else out_path From 4c2d399b19d2623d35416acfe5d43f3d240e4b5c Mon Sep 17 00:00:00 2001 From: cwjki Date: Thu, 24 Feb 2022 12:04:05 -0500 Subject: [PATCH 183/194] handlign void types --- src/code_generator/COOLToCILVisitor.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index 4af48644d..1152b4500 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -705,16 +705,16 @@ def visit(self, node, scope): cil.ArgNode(value), cil.ArgNode(instance)], "Bool")) return instance - @visitor.when(VoidNode) - def visit(self, node, scope): - print(node.id) - result_local = self.define_internal_local(scope=scope) - self.register_instruction(cil.LoadStringNode(node.id, result_local)) - instance = self.define_internal_local(scope=scope, name="instance") - self.register_instruction(cil.AllocateNode( - 'String', self.context.get_type('String').tag, instance)) - result_init = self.define_internal_local( - scope=scope, name="result_init") - self.register_instruction(cil.CallNode(result_init, 'Void_init', [ - cil.ArgNode(result_local), cil.ArgNode(instance)], "String")) - return instance + # @visitor.when(VoidNode) + # def visit(self, node, scope): + # print(node.id) + # result_local = self.define_internal_local(scope=scope) + # self.register_instruction(cil.LoadStringNode(node.id, result_local)) + # instance = self.define_internal_local(scope=scope, name="instance") + # self.register_instruction(cil.AllocateNode( + # 'String', self.context.get_type('String').tag, instance)) + # result_init = self.define_internal_local( + # scope=scope, name="result_init") + # self.register_instruction(cil.CallNode(result_init, 'Void_init', [ + # cil.ArgNode(result_local), cil.ArgNode(instance)], "String")) + # return instance From bda9e37dbcbae8f3b7f512c14557cab3686df98f Mon Sep 17 00:00:00 2001 From: cwjki Date: Thu, 24 Feb 2022 12:52:23 -0500 Subject: [PATCH 184/194] fixing a bug in parents --- src/codeMips.mips | 9623 +++++++++++++++++++++++++++++++++++++- src/main.py | 2 +- src/semantic/semantic.py | 6 +- 3 files changed, 9447 insertions(+), 184 deletions(-) diff --git a/src/codeMips.mips b/src/codeMips.mips index 7b51e8589..75c3fee8b 100644 --- a/src/codeMips.mips +++ b/src/codeMips.mips @@ -39,6 +39,81 @@ IO_methods: .word IO.out_int .word IO.in_string .word IO.in_int +A_name: .asciiz "A" +A_methods: +.word Object.abort +.word Object.type_name +.word Object.copy +.word A.value +.word A.set_var +.word A.method1 +.word A.method2 +.word A.method3 +.word A.method4 +.word A.method5 +B_name: .asciiz "B" +B_methods: +.word Object.abort +.word Object.type_name +.word Object.copy +.word A.value +.word A.set_var +.word A.method1 +.word A.method2 +.word A.method3 +.word A.method4 +.word B.method5 +C_name: .asciiz "C" +C_methods: +.word Object.abort +.word Object.type_name +.word Object.copy +.word A.value +.word A.set_var +.word A.method1 +.word A.method2 +.word A.method3 +.word A.method4 +.word C.method5 +.word C.method6 +D_name: .asciiz "D" +D_methods: +.word Object.abort +.word Object.type_name +.word Object.copy +.word A.value +.word A.set_var +.word A.method1 +.word A.method2 +.word A.method3 +.word A.method4 +.word B.method5 +.word D.method7 +E_name: .asciiz "E" +E_methods: +.word Object.abort +.word Object.type_name +.word Object.copy +.word A.value +.word A.set_var +.word A.method1 +.word A.method2 +.word A.method3 +.word A.method4 +.word B.method5 +.word D.method7 +.word E.method6 +A2I_name: .asciiz "A2I" +A2I_methods: +.word Object.abort +.word Object.type_name +.word Object.copy +.word A2I.c2i +.word A2I.i2c +.word A2I.a2i +.word A2I.a2i_aux +.word A2I.i2a +.word A2I.i2a_aux Main_name: .asciiz "Main" Main_methods: .word Object.abort @@ -48,13 +123,93 @@ Main_methods: .word IO.out_int .word IO.in_string .word IO.in_int +.word Main.menu +.word Main.prompt +.word Main.get_int +.word Main.is_even +.word Main.class_type +.word Main.print .word Main.main -.word Main.fib data_0: .asciiz "Abort called from class " data_1: .asciiz " " empty_str: .asciiz "" -data_3: .asciiz "Enter n to find nth fibonacci number! +data_3: .asciiz "0" +data_4: .asciiz "1" +data_5: .asciiz "2" +data_6: .asciiz "3" +data_7: .asciiz "4" +data_8: .asciiz "5" +data_9: .asciiz "6" +data_10: .asciiz "7" +data_11: .asciiz "8" +data_12: .asciiz "9" +data_13: .asciiz "-" +data_14: .asciiz "+" +data_15: .asciiz " + tTo add a number to " +data_16: .asciiz "...enter a: +" +data_17: .asciiz " tTo negate " +data_18: .asciiz "...enter b: +" +data_19: .asciiz " tTo find the difference between " +data_20: .asciiz "and another number...enter c: +" +data_21: .asciiz " tTo find the factorial of " +data_22: .asciiz "...enter d: +" +data_23: .asciiz " tTo square " +data_24: .asciiz "...enter e: +" +data_25: .asciiz " tTo cube " +data_26: .asciiz "...enter f: +" +data_27: .asciiz " tTo find out if " +data_28: .asciiz "is a multiple of 3...enter g: +" +data_29: .asciiz " tTo divide " +data_30: .asciiz "by 8...enter h: +" +data_31: .asciiz " tTo get a new number...enter j: +" +data_32: .asciiz " tTo quit...enter q: + +" +data_33: .asciiz "Please enter a number... " +data_34: .asciiz "Class type is now E +" +data_35: .asciiz "Class type is now D +" +data_36: .asciiz "Class type is now C +" +data_37: .asciiz "Class type is now B +" +data_38: .asciiz "Class type is now A +" +data_39: .asciiz "Oooops +" +data_40: .asciiz " " +data_41: .asciiz "number " +data_42: .asciiz "is odd! +" +data_43: .asciiz "is even! +" +data_44: .asciiz "a" +data_45: .asciiz "b" +data_46: .asciiz "c" +data_47: .asciiz "d" +data_48: .asciiz "e" +data_49: .asciiz "f" +data_50: .asciiz "g" +data_51: .asciiz "h" +data_52: .asciiz "j" +data_53: .asciiz "q" +data_54: .asciiz "is equal to " +data_55: .asciiz "times 8 with a remainder of " +data_56: .asciiz "is not divisible by 3. +" +data_57: .asciiz "is divisible by 3. " .text dispatch_void_error: @@ -97,16 +252,16 @@ main: addi $sp, $sp, -8 addi $sp, $sp, -4 sw $ra, 0($sp) -li $a0, 16 +li $a0, 32 li $v0, 9 syscall bge $v0, $sp heap_error move $t0, $v0 -li $t1, 5 +li $t1, 11 sw $t1, 0($t0) la $t1, Main_name sw $t1, 4($t0) -li $t1, 4 +li $t1, 8 sw $t1, 8($t0) la $t1, Main_methods sw $t1, 12($t0) @@ -601,129 +756,166 @@ lw $a1, 12($sp) lw $ra, 0($sp) addi $sp, $sp, 24 jr $ra -Main_init: -addi $sp, $sp, -4 +A_init: +addi $sp, $sp, -16 addi $sp, $sp, -4 sw $ra, 0($sp) move $t0, $sp -lw $t1, 8($t0) +lw $t1, 20($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -jal IO_init +jal Object_init sw $a1, 4($sp) move $a1, $zero -lw $ra, 0($sp) -addi $sp, $sp, 12 -jr $ra -Main.main: -addi $sp, $sp, -44 -addi $sp, $sp, -4 -sw $ra, 0($sp) -la $t0, data_3 -sw $t0, 8($sp) li $a0, 20 li $v0, 9 syscall bge $v0, $sp heap_error move $t0, $v0 -li $t1, 2 +li $t1, 4 sw $t1, 0($t0) -la $t1, String_name +la $t1, Int_name sw $t1, 4($t0) li $t1, 5 sw $t1, 8($t0) -la $t1, String_methods +la $t1, Int_methods sw $t1, 12($t0) +sw $t0, 8($sp) +li $t0, 0 sw $t0, 12($sp) move $t0, $sp -lw $t1, 8($t0) +lw $t1, 12($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 12($t0) +lw $t1, 8($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -jal String_init +jal Int_init sw $a1, 16($sp) -move $t0, $sp -lw $t1, 12($t0) +lw $t0, 20($sp) +lw $t1, 8($sp) +sw $t1, 16($t0) +lw $ra, 0($sp) +addi $sp, $sp, 24 +jr $ra +A.value: addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 48($t0) addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 48($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 4($sp) -move $t0, $sp -lw $t1, 48($t0) +sw $ra, 0($sp) +lw $t0, 8($sp) +lw $t1, 16($t0) +sw $t1, 4($sp) +lw $a1, 4($sp) +lw $ra, 0($sp) +addi $sp, $sp, 12 +jr $ra +A.set_var: addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 48($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 24($t2) -jal $t3 -sw $a1, 28($sp) +addi $sp, $sp, -4 +sw $ra, 0($sp) +lw $t0, 8($sp) +lw $t1, 12($sp) +sw $t1, 16($t0) +lw $a1, 8($sp) +lw $ra, 0($sp) +addi $sp, $sp, 16 +jr $ra +A.method1: +addi $sp, $sp, 0 +addi $sp, $sp, -4 +sw $ra, 0($sp) +lw $a1, 4($sp) +lw $ra, 0($sp) +addi $sp, $sp, 12 +jr $ra +A.method2: +addi $sp, $sp, -56 +addi $sp, $sp, -4 +sw $ra, 0($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 4($sp) +li $t0, 0 +sw $t0, 8($sp) move $t0, $sp -lw $t1, 28($t0) +lw $t1, 8($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 48($t0) +lw $t1, 4($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 48($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 32($t2) -jal $t3 -sw $a1, 24($sp) +jal Int_init +sw $a1, 12($sp) +lw $t1, 4($sp) +sw $t1, 16($sp) +lw $t0, 64($sp) +lw $t1, 16($t0) +sw $t1, 28($sp) +lw $t0, 68($sp) +lw $t1, 16($t0) +sw $t1, 32($sp) +lw $a0, 28($sp) +lw $t1, 32($sp) +add $a0, $a0, $t1 +sw $a0, 24($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 20($sp) move $t0, $sp lw $t1, 24($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 48($t0) +lw $t1, 20($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 48($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 16($t2) -jal $t3 -sw $a1, 20($sp) -la $t0, data_1 -sw $t0, 36($sp) +jal Int_init +sw $a1, 36($sp) +lw $t1, 20($sp) +sw $t1, 16($sp) li $a0, 20 li $v0, 9 syscall bge $v0, $sp heap_error move $t0, $v0 -li $t1, 2 +li $t1, 6 sw $t1, 0($t0) -la $t1, String_name +la $t1, B_name sw $t1, 4($t0) li $t1, 5 sw $t1, 8($t0) -la $t1, String_methods +la $t1, B_methods sw $t1, 12($t0) -sw $t0, 40($sp) +sw $t0, 48($sp) move $t0, $sp -lw $t1, 36($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 40($t0) +lw $t1, 48($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -jal String_init -sw $a1, 44($sp) +jal B_init +sw $a1, 52($sp) move $t0, $sp -lw $t1, 40($t0) +lw $t1, 16($t0) addi $sp, $sp, -4 sw $t1, 0($sp) lw $t1, 48($t0) @@ -733,15 +925,17 @@ lw $t1, 48($t0) la $t0, void beq $t1, $t0, dispatch_void_error lw $t2, 12($t1) -lw $t3, 12($t2) +lw $t3, 16($t2) jal $t3 -sw $a1, 32($sp) -lw $a1, 32($sp) +sw $a1, 44($sp) +lw $t1, 44($sp) +sw $t1, 56($sp) +lw $a1, 56($sp) lw $ra, 0($sp) -addi $sp, $sp, 52 +addi $sp, $sp, 72 jr $ra -Main.fib: -addi $sp, $sp, -172 +A.method3: +addi $sp, $sp, -52 addi $sp, $sp, -4 sw $ra, 0($sp) li $a0, 20 @@ -758,7 +952,7 @@ sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) sw $t0, 4($sp) -li $t0, 1 +li $t0, 0 sw $t0, 8($sp) move $t0, $sp lw $t1, 8($t0) @@ -771,6 +965,12 @@ jal Int_init sw $a1, 12($sp) lw $t1, 4($sp) sw $t1, 16($sp) +lw $t0, 60($sp) +lw $t1, 16($t0) +sw $t1, 28($sp) +lw $t1, 28($sp) +neg $a0, $t1 +sw $a0, 24($sp) li $a0, 20 li $v0, 9 syscall @@ -785,8 +985,6 @@ sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) sw $t0, 20($sp) -li $t0, 0 -sw $t0, 24($sp) move $t0, $sp lw $t1, 24($t0) addi $sp, $sp, -4 @@ -795,49 +993,203 @@ lw $t1, 20($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init -sw $a1, 28($sp) +sw $a1, 32($sp) lw $t1, 20($sp) -sw $t1, 32($sp) +sw $t1, 16($sp) li $a0, 20 li $v0, 9 syscall bge $v0, $sp heap_error move $t0, $v0 -li $t1, 4 +li $t1, 7 sw $t1, 0($t0) -la $t1, Int_name +la $t1, C_name sw $t1, 4($t0) li $t1, 5 sw $t1, 8($t0) -la $t1, Int_methods +la $t1, C_methods sw $t1, 12($t0) -sw $t0, 36($sp) -li $t0, 0 -sw $t0, 40($sp) +sw $t0, 44($sp) move $t0, $sp -lw $t1, 40($t0) +lw $t1, 44($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 36($t0) +jal C_init +sw $a1, 48($sp) +move $t0, $sp +lw $t1, 16($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -jal Int_init -sw $a1, 44($sp) -lw $t1, 36($sp) -sw $t1, 48($sp) -label_1: +lw $t1, 44($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 44($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 16($t2) +jal $t3 +sw $a1, 40($sp) +lw $t1, 40($sp) +sw $t1, 52($sp) +lw $a1, 52($sp) +lw $ra, 0($sp) +addi $sp, $sp, 64 +jr $ra +A.method4: +addi $sp, $sp, -136 +addi $sp, $sp, -4 +sw $ra, 0($sp) +lw $t0, 148($sp) +lw $t1, 16($t0) +sw $t1, 16($sp) +lw $t0, 144($sp) +lw $t1, 16($t0) +sw $t1, 20($sp) +lw $a0, 16($sp) +lw $t1, 20($sp) +slt $a0, $a0, $t1 +sw $a0, 12($sp) li $a0, 20 li $v0, 9 syscall bge $v0, $sp heap_error move $t0, $v0 -li $t1, 4 +li $t1, 3 sw $t1, 0($t0) -la $t1, Int_name +la $t1, Bool_name sw $t1, 4($t0) li $t1, 5 sw $t1, 8($t0) -la $t1, Int_methods +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 8($sp) +move $t0, $sp +lw $t1, 12($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 8($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 24($sp) +lw $t0, 8($sp) +lw $a0, 16($t0) +bnez $a0, label_1 +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 28($sp) +li $t0, 0 +sw $t0, 32($sp) +move $t0, $sp +lw $t1, 32($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 28($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 36($sp) +lw $t1, 28($sp) +sw $t1, 40($sp) +lw $t0, 148($sp) +lw $t1, 16($t0) +sw $t1, 52($sp) +lw $t0, 144($sp) +lw $t1, 16($t0) +sw $t1, 56($sp) +lw $a0, 52($sp) +lw $t1, 56($sp) +sub $a0, $a0, $t1 +sw $a0, 48($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 44($sp) +move $t0, $sp +lw $t1, 48($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 44($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 60($sp) +lw $t1, 44($sp) +sw $t1, 40($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 8 +sw $t1, 0($t0) +la $t1, D_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, D_methods +sw $t1, 12($t0) +sw $t0, 72($sp) +move $t0, $sp +lw $t1, 72($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal D_init +sw $a1, 76($sp) +move $t0, $sp +lw $t1, 40($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 72($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 72($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 16($t2) +jal $t3 +sw $a1, 68($sp) +lw $t1, 68($sp) +sw $t1, 80($sp) +lw $t1, 80($sp) +sw $t1, 4($sp) +b label_2 +label_1: +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods sw $t1, 12($t0) sw $t0, 84($sp) li $t0, 0 @@ -851,83 +1203,90 @@ addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init sw $a1, 92($sp) -lw $t0, 180($sp) +lw $t1, 84($sp) +sw $t1, 96($sp) +lw $t0, 144($sp) lw $t1, 16($t0) -sw $t1, 76($sp) -lw $t0, 84($sp) +sw $t1, 108($sp) +lw $t0, 148($sp) lw $t1, 16($t0) -sw $t1, 80($sp) -lw $a0, 76($sp) -lw $t1, 80($sp) -seq $a0, $a0, $t1 -sw $a0, 72($sp) +sw $t1, 112($sp) +lw $a0, 108($sp) +lw $t1, 112($sp) +sub $a0, $a0, $t1 +sw $a0, 104($sp) li $a0, 20 li $v0, 9 syscall bge $v0, $sp heap_error move $t0, $v0 -li $t1, 3 +li $t1, 4 sw $t1, 0($t0) -la $t1, Bool_name +la $t1, Int_name sw $t1, 4($t0) li $t1, 5 sw $t1, 8($t0) -la $t1, Bool_methods +la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 68($sp) +sw $t0, 100($sp) move $t0, $sp -lw $t1, 72($t0) +lw $t1, 104($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 68($t0) +lw $t1, 100($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -jal Bool_init -sw $a1, 96($sp) -lw $t0, 68($sp) -lw $t1, 16($t0) -sw $t1, 64($sp) -lw $t1, 64($sp) -xor $a0, $t1, 1 -sw $a0, 60($sp) +jal Int_init +sw $a1, 116($sp) +lw $t1, 100($sp) +sw $t1, 96($sp) li $a0, 20 li $v0, 9 syscall bge $v0, $sp heap_error move $t0, $v0 -li $t1, 3 +li $t1, 8 sw $t1, 0($t0) -la $t1, Bool_name +la $t1, D_name sw $t1, 4($t0) li $t1, 5 sw $t1, 8($t0) -la $t1, Bool_methods +la $t1, D_methods sw $t1, 12($t0) -sw $t0, 56($sp) +sw $t0, 128($sp) move $t0, $sp -lw $t1, 60($t0) +lw $t1, 128($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 56($t0) +jal D_init +sw $a1, 132($sp) +move $t0, $sp +lw $t1, 96($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -jal Bool_init -sw $a1, 100($sp) -lw $t0, 56($sp) -lw $a0, 16($t0) -bnez $a0, label_2 -b label_3 +lw $t1, 128($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 128($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 16($t2) +jal $t3 +sw $a1, 124($sp) +lw $t1, 124($sp) +sw $t1, 136($sp) +lw $t1, 136($sp) +sw $t1, 4($sp) label_2: -lw $t0, 16($sp) -lw $t1, 16($t0) -sw $t1, 112($sp) -lw $t0, 32($sp) -lw $t1, 16($t0) -sw $t1, 116($sp) -lw $a0, 112($sp) -lw $t1, 116($sp) -add $a0, $a0, $t1 -sw $a0, 108($sp) +lw $a1, 4($sp) +lw $ra, 0($sp) +addi $sp, $sp, 152 +jr $ra +A.method5: +addi $sp, $sp, -136 +addi $sp, $sp, -4 +sw $ra, 0($sp) li $a0, 20 li $v0, 9 syscall @@ -941,18 +1300,20 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 104($sp) +sw $t0, 4($sp) +li $t0, 1 +sw $t0, 8($sp) move $t0, $sp -lw $t1, 108($t0) +lw $t1, 8($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 104($t0) +lw $t1, 4($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init -sw $a1, 120($sp) -lw $t1, 104($sp) -sw $t1, 48($sp) +sw $a1, 12($sp) +lw $t1, 4($sp) +sw $t1, 16($sp) li $a0, 20 li $v0, 9 syscall @@ -966,28 +1327,69 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 144($sp) +sw $t0, 20($sp) li $t0, 1 -sw $t0, 148($sp) +sw $t0, 24($sp) move $t0, $sp -lw $t1, 148($t0) +lw $t1, 24($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 144($t0) +lw $t1, 20($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init -sw $a1, 152($sp) -lw $t0, 180($sp) +sw $a1, 28($sp) +lw $t1, 20($sp) +sw $t1, 32($sp) +label_3: +lw $t0, 32($sp) lw $t1, 16($t0) -sw $t1, 136($sp) +sw $t1, 48($sp) lw $t0, 144($sp) lw $t1, 16($t0) -sw $t1, 140($sp) -lw $a0, 136($sp) -lw $t1, 140($sp) -sub $a0, $a0, $t1 -sw $a0, 132($sp) +sw $t1, 52($sp) +lw $a0, 48($sp) +lw $t1, 52($sp) +sle $a0, $a0, $t1 +sw $a0, 44($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 40($sp) +move $t0, $sp +lw $t1, 44($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 40($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 56($sp) +lw $t0, 40($sp) +lw $a0, 16($t0) +bnez $a0, label_4 +b label_5 +label_4: +lw $t0, 16($sp) +lw $t1, 16($t0) +sw $t1, 68($sp) +lw $t0, 32($sp) +lw $t1, 16($t0) +sw $t1, 72($sp) +lw $a0, 68($sp) +lw $t1, 72($sp) +mul $a0, $a0, $t1 +sw $a0, 64($sp) li $a0, 20 li $v0, 9 syscall @@ -1001,27 +1403,8888 @@ li $t1, 5 sw $t1, 8($t0) la $t1, Int_methods sw $t1, 12($t0) -sw $t0, 128($sp) +sw $t0, 60($sp) move $t0, $sp -lw $t1, 132($t0) +lw $t1, 64($t0) addi $sp, $sp, -4 sw $t1, 0($sp) -lw $t1, 128($t0) +lw $t1, 60($t0) addi $sp, $sp, -4 sw $t1, 0($sp) jal Int_init -sw $a1, 156($sp) -lw $t1, 128($sp) -sw $t1, 180($sp) -lw $t1, 16($sp) -sw $t1, 32($sp) -lw $t1, 48($sp) +sw $a1, 76($sp) +lw $t1, 60($sp) sw $t1, 16($sp) -b label_1 -label_3: -lw $t1, 48($sp) -sw $t1, 172($sp) -lw $a1, 172($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 100($sp) +li $t0, 1 +sw $t0, 104($sp) +move $t0, $sp +lw $t1, 104($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 100($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 108($sp) +lw $t0, 32($sp) +lw $t1, 16($t0) +sw $t1, 92($sp) +lw $t0, 100($sp) +lw $t1, 16($t0) +sw $t1, 96($sp) +lw $a0, 92($sp) +lw $t1, 96($sp) +add $a0, $a0, $t1 +sw $a0, 88($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 84($sp) +move $t0, $sp +lw $t1, 88($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 84($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 112($sp) +lw $t1, 84($sp) +sw $t1, 32($sp) +b label_3 +label_5: +lw $t1, 36($sp) +sw $t1, 120($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 9 +sw $t1, 0($t0) +la $t1, E_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, E_methods +sw $t1, 12($t0) +sw $t0, 128($sp) +move $t0, $sp +lw $t1, 128($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal E_init +sw $a1, 132($sp) +move $t0, $sp +lw $t1, 16($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 128($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 128($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 16($t2) +jal $t3 +sw $a1, 124($sp) +lw $t1, 124($sp) +sw $t1, 136($sp) +lw $a1, 136($sp) +lw $ra, 0($sp) +addi $sp, $sp, 148 +jr $ra +B_init: +addi $sp, $sp, -4 +addi $sp, $sp, -4 +sw $ra, 0($sp) +move $t0, $sp +lw $t1, 8($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal A_init +sw $a1, 4($sp) +move $a1, $zero +lw $ra, 0($sp) +addi $sp, $sp, 12 +jr $ra +B.method5: +addi $sp, $sp, -56 +addi $sp, $sp, -4 +sw $ra, 0($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 4($sp) +li $t0, 0 +sw $t0, 8($sp) +move $t0, $sp +lw $t1, 8($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 4($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 12($sp) +lw $t1, 4($sp) +sw $t1, 16($sp) +lw $t0, 64($sp) +lw $t1, 16($t0) +sw $t1, 28($sp) +lw $t0, 64($sp) +lw $t1, 16($t0) +sw $t1, 32($sp) +lw $a0, 28($sp) +lw $t1, 32($sp) +mul $a0, $a0, $t1 +sw $a0, 24($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 20($sp) +move $t0, $sp +lw $t1, 24($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 20($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 36($sp) +lw $t1, 20($sp) +sw $t1, 16($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 9 +sw $t1, 0($t0) +la $t1, E_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, E_methods +sw $t1, 12($t0) +sw $t0, 48($sp) +move $t0, $sp +lw $t1, 48($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal E_init +sw $a1, 52($sp) +move $t0, $sp +lw $t1, 16($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 48($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 48($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 16($t2) +jal $t3 +sw $a1, 44($sp) +lw $t1, 44($sp) +sw $t1, 56($sp) +lw $a1, 56($sp) +lw $ra, 0($sp) +addi $sp, $sp, 68 +jr $ra +C_init: +addi $sp, $sp, -4 +addi $sp, $sp, -4 +sw $ra, 0($sp) +move $t0, $sp +lw $t1, 8($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal B_init +sw $a1, 4($sp) +move $a1, $zero +lw $ra, 0($sp) +addi $sp, $sp, 12 +jr $ra +C.method6: +addi $sp, $sp, -52 +addi $sp, $sp, -4 +sw $ra, 0($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 4($sp) +li $t0, 0 +sw $t0, 8($sp) +move $t0, $sp +lw $t1, 8($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 4($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 12($sp) +lw $t1, 4($sp) +sw $t1, 16($sp) +lw $t0, 60($sp) +lw $t1, 16($t0) +sw $t1, 28($sp) +lw $t1, 28($sp) +neg $a0, $t1 +sw $a0, 24($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 20($sp) +move $t0, $sp +lw $t1, 24($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 20($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 32($sp) +lw $t1, 20($sp) +sw $t1, 16($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 5 +sw $t1, 0($t0) +la $t1, A_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, A_methods +sw $t1, 12($t0) +sw $t0, 44($sp) +move $t0, $sp +lw $t1, 44($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal A_init +sw $a1, 48($sp) +move $t0, $sp +lw $t1, 16($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 44($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 44($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 16($t2) +jal $t3 +sw $a1, 40($sp) +lw $t1, 40($sp) +sw $t1, 52($sp) +lw $a1, 52($sp) +lw $ra, 0($sp) +addi $sp, $sp, 64 +jr $ra +C.method5: +addi $sp, $sp, -76 +addi $sp, $sp, -4 +sw $ra, 0($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 4($sp) +li $t0, 0 +sw $t0, 8($sp) +move $t0, $sp +lw $t1, 8($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 4($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 12($sp) +lw $t1, 4($sp) +sw $t1, 16($sp) +lw $t0, 84($sp) +lw $t1, 16($t0) +sw $t1, 44($sp) +lw $t0, 84($sp) +lw $t1, 16($t0) +sw $t1, 48($sp) +lw $a0, 44($sp) +lw $t1, 48($sp) +mul $a0, $a0, $t1 +sw $a0, 40($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 36($sp) +move $t0, $sp +lw $t1, 40($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 36($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 52($sp) +lw $t0, 36($sp) +lw $t1, 16($t0) +sw $t1, 28($sp) +lw $t0, 84($sp) +lw $t1, 16($t0) +sw $t1, 32($sp) +lw $a0, 28($sp) +lw $t1, 32($sp) +mul $a0, $a0, $t1 +sw $a0, 24($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 20($sp) +move $t0, $sp +lw $t1, 24($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 20($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 56($sp) +lw $t1, 20($sp) +sw $t1, 16($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 9 +sw $t1, 0($t0) +la $t1, E_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, E_methods +sw $t1, 12($t0) +sw $t0, 68($sp) +move $t0, $sp +lw $t1, 68($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal E_init +sw $a1, 72($sp) +move $t0, $sp +lw $t1, 16($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 68($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 68($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 16($t2) +jal $t3 +sw $a1, 64($sp) +lw $t1, 64($sp) +sw $t1, 76($sp) +lw $a1, 76($sp) +lw $ra, 0($sp) +addi $sp, $sp, 88 +jr $ra +D_init: +addi $sp, $sp, -4 +addi $sp, $sp, -4 +sw $ra, 0($sp) +move $t0, $sp +lw $t1, 8($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal B_init +sw $a1, 4($sp) +move $a1, $zero +lw $ra, 0($sp) +addi $sp, $sp, 12 +jr $ra +D.method7: +addi $sp, $sp, -244 +addi $sp, $sp, -4 +sw $ra, 0($sp) +lw $t1, 252($sp) +sw $t1, 4($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 28($sp) +li $t0, 0 +sw $t0, 32($sp) +move $t0, $sp +lw $t1, 32($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 28($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 36($sp) +lw $t0, 4($sp) +lw $t1, 16($t0) +sw $t1, 20($sp) +lw $t0, 28($sp) +lw $t1, 16($t0) +sw $t1, 24($sp) +lw $a0, 20($sp) +lw $t1, 24($sp) +slt $a0, $a0, $t1 +sw $a0, 16($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 12($sp) +move $t0, $sp +lw $t1, 16($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 12($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 40($sp) +lw $t0, 12($sp) +lw $a0, 16($t0) +bnez $a0, label_6 +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 64($sp) +li $t0, 0 +sw $t0, 68($sp) +move $t0, $sp +lw $t1, 68($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 64($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 72($sp) +lw $t0, 64($sp) +lw $t1, 16($t0) +sw $t1, 56($sp) +lw $t0, 4($sp) +lw $t1, 16($t0) +sw $t1, 60($sp) +lw $a0, 56($sp) +lw $t1, 60($sp) +seq $a0, $a0, $t1 +sw $a0, 52($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 48($sp) +move $t0, $sp +lw $t1, 52($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 48($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 76($sp) +lw $t0, 48($sp) +lw $a0, 16($t0) +bnez $a0, label_7 +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 100($sp) +li $t0, 1 +sw $t0, 104($sp) +move $t0, $sp +lw $t1, 104($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 100($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 108($sp) +lw $t0, 100($sp) +lw $t1, 16($t0) +sw $t1, 92($sp) +lw $t0, 4($sp) +lw $t1, 16($t0) +sw $t1, 96($sp) +lw $a0, 92($sp) +lw $t1, 96($sp) +seq $a0, $a0, $t1 +sw $a0, 88($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 84($sp) +move $t0, $sp +lw $t1, 88($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 84($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 112($sp) +lw $t0, 84($sp) +lw $a0, 16($t0) +bnez $a0, label_8 +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 136($sp) +li $t0, 2 +sw $t0, 140($sp) +move $t0, $sp +lw $t1, 140($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 136($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 144($sp) +lw $t0, 136($sp) +lw $t1, 16($t0) +sw $t1, 128($sp) +lw $t0, 4($sp) +lw $t1, 16($t0) +sw $t1, 132($sp) +lw $a0, 128($sp) +lw $t1, 132($sp) +seq $a0, $a0, $t1 +sw $a0, 124($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 120($sp) +move $t0, $sp +lw $t1, 124($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 120($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 148($sp) +lw $t0, 120($sp) +lw $a0, 16($t0) +bnez $a0, label_9 +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 172($sp) +li $t0, 3 +sw $t0, 176($sp) +move $t0, $sp +lw $t1, 176($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 172($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 180($sp) +lw $t0, 4($sp) +lw $t1, 16($t0) +sw $t1, 164($sp) +lw $t0, 172($sp) +lw $t1, 16($t0) +sw $t1, 168($sp) +lw $a0, 164($sp) +lw $t1, 168($sp) +sub $a0, $a0, $t1 +sw $a0, 160($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 156($sp) +move $t0, $sp +lw $t1, 160($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 156($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 184($sp) +move $t0, $sp +lw $t1, 156($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 248($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 248($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 40($t2) +jal $t3 +sw $a1, 152($sp) +lw $t1, 152($sp) +sw $t1, 116($sp) +b label_10 +label_9: +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 188($sp) +li $t0, 0 +sw $t0, 192($sp) +move $t0, $sp +lw $t1, 192($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 188($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 196($sp) +lw $t1, 188($sp) +sw $t1, 116($sp) +label_10: +lw $t1, 116($sp) +sw $t1, 80($sp) +b label_11 +label_8: +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 200($sp) +li $t0, 0 +sw $t0, 204($sp) +move $t0, $sp +lw $t1, 204($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 200($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 208($sp) +lw $t1, 200($sp) +sw $t1, 80($sp) +label_11: +lw $t1, 80($sp) +sw $t1, 44($sp) +b label_12 +label_7: +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 212($sp) +li $t0, 1 +sw $t0, 216($sp) +move $t0, $sp +lw $t1, 216($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 212($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 220($sp) +lw $t1, 212($sp) +sw $t1, 44($sp) +label_12: +lw $t1, 44($sp) +sw $t1, 8($sp) +b label_13 +label_6: +lw $t0, 4($sp) +lw $t1, 16($t0) +sw $t1, 236($sp) +lw $t1, 236($sp) +neg $a0, $t1 +sw $a0, 232($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 228($sp) +move $t0, $sp +lw $t1, 232($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 228($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 240($sp) +move $t0, $sp +lw $t1, 228($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 248($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 248($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 40($t2) +jal $t3 +sw $a1, 224($sp) +lw $t1, 224($sp) +sw $t1, 8($sp) +label_13: +lw $t1, 8($sp) +sw $t1, 244($sp) +lw $a1, 244($sp) +lw $ra, 0($sp) +addi $sp, $sp, 256 +jr $ra +E_init: +addi $sp, $sp, -4 +addi $sp, $sp, -4 +sw $ra, 0($sp) +move $t0, $sp +lw $t1, 8($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal D_init +sw $a1, 4($sp) +move $a1, $zero +lw $ra, 0($sp) +addi $sp, $sp, 12 +jr $ra +E.method6: +addi $sp, $sp, -68 +addi $sp, $sp, -4 +sw $ra, 0($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 4($sp) +li $t0, 0 +sw $t0, 8($sp) +move $t0, $sp +lw $t1, 8($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 4($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 12($sp) +lw $t1, 4($sp) +sw $t1, 16($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 36($sp) +li $t0, 8 +sw $t0, 40($sp) +move $t0, $sp +lw $t1, 40($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 36($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 44($sp) +lw $t0, 76($sp) +lw $t1, 16($t0) +sw $t1, 28($sp) +lw $t0, 36($sp) +lw $t1, 16($t0) +sw $t1, 32($sp) +lw $a0, 28($sp) +lw $t1, 32($sp) +beq $t1, 0, div_zero_error +div $a0, $a0, $t1 +sw $a0, 24($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 20($sp) +move $t0, $sp +lw $t1, 24($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 20($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 48($sp) +lw $t1, 20($sp) +sw $t1, 16($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 5 +sw $t1, 0($t0) +la $t1, A_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, A_methods +sw $t1, 12($t0) +sw $t0, 60($sp) +move $t0, $sp +lw $t1, 60($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal A_init +sw $a1, 64($sp) +move $t0, $sp +lw $t1, 16($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 60($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 60($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 16($t2) +jal $t3 +sw $a1, 56($sp) +lw $t1, 56($sp) +sw $t1, 68($sp) +lw $a1, 68($sp) +lw $ra, 0($sp) +addi $sp, $sp, 80 +jr $ra +A2I_init: +addi $sp, $sp, -4 +addi $sp, $sp, -4 +sw $ra, 0($sp) +move $t0, $sp +lw $t1, 8($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Object_init +sw $a1, 4($sp) +move $a1, $zero +lw $ra, 0($sp) +addi $sp, $sp, 12 +jr $ra +A2I.c2i: +addi $sp, $sp, -496 +addi $sp, $sp, -4 +sw $ra, 0($sp) +la $t0, data_3 +sw $t0, 24($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 28($sp) +move $t0, $sp +lw $t1, 24($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 28($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 32($sp) +move $t0, $sp +lw $t1, 28($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 504($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_equals +sw $a1, 12($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 8($sp) +move $t0, $sp +lw $t1, 12($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 8($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 36($sp) +lw $t0, 8($sp) +lw $a0, 16($t0) +bnez $a0, label_14 +la $t0, data_4 +sw $t0, 60($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 64($sp) +move $t0, $sp +lw $t1, 60($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 64($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 68($sp) +move $t0, $sp +lw $t1, 64($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 504($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_equals +sw $a1, 48($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 44($sp) +move $t0, $sp +lw $t1, 48($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 44($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 72($sp) +lw $t0, 44($sp) +lw $a0, 16($t0) +bnez $a0, label_15 +la $t0, data_5 +sw $t0, 96($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 100($sp) +move $t0, $sp +lw $t1, 96($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 100($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 104($sp) +move $t0, $sp +lw $t1, 100($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 504($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_equals +sw $a1, 84($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 80($sp) +move $t0, $sp +lw $t1, 84($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 80($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 108($sp) +lw $t0, 80($sp) +lw $a0, 16($t0) +bnez $a0, label_16 +la $t0, data_6 +sw $t0, 132($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 136($sp) +move $t0, $sp +lw $t1, 132($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 136($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 140($sp) +move $t0, $sp +lw $t1, 136($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 504($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_equals +sw $a1, 120($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 116($sp) +move $t0, $sp +lw $t1, 120($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 116($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 144($sp) +lw $t0, 116($sp) +lw $a0, 16($t0) +bnez $a0, label_17 +la $t0, data_7 +sw $t0, 168($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 172($sp) +move $t0, $sp +lw $t1, 168($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 172($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 176($sp) +move $t0, $sp +lw $t1, 172($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 504($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_equals +sw $a1, 156($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 152($sp) +move $t0, $sp +lw $t1, 156($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 152($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 180($sp) +lw $t0, 152($sp) +lw $a0, 16($t0) +bnez $a0, label_18 +la $t0, data_8 +sw $t0, 204($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 208($sp) +move $t0, $sp +lw $t1, 204($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 208($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 212($sp) +move $t0, $sp +lw $t1, 208($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 504($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_equals +sw $a1, 192($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 188($sp) +move $t0, $sp +lw $t1, 192($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 188($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 216($sp) +lw $t0, 188($sp) +lw $a0, 16($t0) +bnez $a0, label_19 +la $t0, data_9 +sw $t0, 240($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 244($sp) +move $t0, $sp +lw $t1, 240($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 244($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 248($sp) +move $t0, $sp +lw $t1, 244($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 504($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_equals +sw $a1, 228($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 224($sp) +move $t0, $sp +lw $t1, 228($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 224($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 252($sp) +lw $t0, 224($sp) +lw $a0, 16($t0) +bnez $a0, label_20 +la $t0, data_10 +sw $t0, 276($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 280($sp) +move $t0, $sp +lw $t1, 276($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 280($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 284($sp) +move $t0, $sp +lw $t1, 280($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 504($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_equals +sw $a1, 264($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 260($sp) +move $t0, $sp +lw $t1, 264($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 260($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 288($sp) +lw $t0, 260($sp) +lw $a0, 16($t0) +bnez $a0, label_21 +la $t0, data_11 +sw $t0, 312($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 316($sp) +move $t0, $sp +lw $t1, 312($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 316($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 320($sp) +move $t0, $sp +lw $t1, 316($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 504($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_equals +sw $a1, 300($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 296($sp) +move $t0, $sp +lw $t1, 300($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 296($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 324($sp) +lw $t0, 296($sp) +lw $a0, 16($t0) +bnez $a0, label_22 +la $t0, data_12 +sw $t0, 348($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 352($sp) +move $t0, $sp +lw $t1, 348($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 352($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 356($sp) +move $t0, $sp +lw $t1, 352($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 504($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_equals +sw $a1, 336($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 332($sp) +move $t0, $sp +lw $t1, 336($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 332($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 360($sp) +lw $t0, 332($sp) +lw $a0, 16($t0) +bnez $a0, label_23 +move $t0, $sp +lw $t1, 500($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 500($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 0($t2) +jal $t3 +sw $a1, 364($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 368($sp) +li $t0, 0 +sw $t0, 372($sp) +move $t0, $sp +lw $t1, 372($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 368($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 376($sp) +lw $t1, 368($sp) +sw $t1, 328($sp) +b label_24 +label_23: +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 380($sp) +li $t0, 9 +sw $t0, 384($sp) +move $t0, $sp +lw $t1, 384($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 380($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 388($sp) +lw $t1, 380($sp) +sw $t1, 328($sp) +label_24: +lw $t1, 328($sp) +sw $t1, 292($sp) +b label_25 +label_22: +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 392($sp) +li $t0, 8 +sw $t0, 396($sp) +move $t0, $sp +lw $t1, 396($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 392($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 400($sp) +lw $t1, 392($sp) +sw $t1, 292($sp) +label_25: +lw $t1, 292($sp) +sw $t1, 256($sp) +b label_26 +label_21: +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 404($sp) +li $t0, 7 +sw $t0, 408($sp) +move $t0, $sp +lw $t1, 408($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 404($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 412($sp) +lw $t1, 404($sp) +sw $t1, 256($sp) +label_26: +lw $t1, 256($sp) +sw $t1, 220($sp) +b label_27 +label_20: +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 416($sp) +li $t0, 6 +sw $t0, 420($sp) +move $t0, $sp +lw $t1, 420($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 416($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 424($sp) +lw $t1, 416($sp) +sw $t1, 220($sp) +label_27: +lw $t1, 220($sp) +sw $t1, 184($sp) +b label_28 +label_19: +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 428($sp) +li $t0, 5 +sw $t0, 432($sp) +move $t0, $sp +lw $t1, 432($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 428($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 436($sp) +lw $t1, 428($sp) +sw $t1, 184($sp) +label_28: +lw $t1, 184($sp) +sw $t1, 148($sp) +b label_29 +label_18: +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 440($sp) +li $t0, 4 +sw $t0, 444($sp) +move $t0, $sp +lw $t1, 444($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 440($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 448($sp) +lw $t1, 440($sp) +sw $t1, 148($sp) +label_29: +lw $t1, 148($sp) +sw $t1, 112($sp) +b label_30 +label_17: +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 452($sp) +li $t0, 3 +sw $t0, 456($sp) +move $t0, $sp +lw $t1, 456($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 452($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 460($sp) +lw $t1, 452($sp) +sw $t1, 112($sp) +label_30: +lw $t1, 112($sp) +sw $t1, 76($sp) +b label_31 +label_16: +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 464($sp) +li $t0, 2 +sw $t0, 468($sp) +move $t0, $sp +lw $t1, 468($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 464($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 472($sp) +lw $t1, 464($sp) +sw $t1, 76($sp) +label_31: +lw $t1, 76($sp) +sw $t1, 40($sp) +b label_32 +label_15: +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 476($sp) +li $t0, 1 +sw $t0, 480($sp) +move $t0, $sp +lw $t1, 480($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 476($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 484($sp) +lw $t1, 476($sp) +sw $t1, 40($sp) +label_32: +lw $t1, 40($sp) +sw $t1, 4($sp) +b label_33 +label_14: +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 488($sp) +li $t0, 0 +sw $t0, 492($sp) +move $t0, $sp +lw $t1, 492($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 488($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 496($sp) +lw $t1, 488($sp) +sw $t1, 4($sp) +label_33: +lw $a1, 4($sp) +lw $ra, 0($sp) +addi $sp, $sp, 508 +jr $ra +A2I.i2c: +addi $sp, $sp, -496 +addi $sp, $sp, -4 +sw $ra, 0($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 24($sp) +li $t0, 0 +sw $t0, 28($sp) +move $t0, $sp +lw $t1, 28($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 24($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 32($sp) +lw $t0, 504($sp) +lw $t1, 16($t0) +sw $t1, 16($sp) +lw $t0, 24($sp) +lw $t1, 16($t0) +sw $t1, 20($sp) +lw $a0, 16($sp) +lw $t1, 20($sp) +seq $a0, $a0, $t1 +sw $a0, 12($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 8($sp) +move $t0, $sp +lw $t1, 12($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 8($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 36($sp) +lw $t0, 8($sp) +lw $a0, 16($t0) +bnez $a0, label_34 +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 60($sp) +li $t0, 1 +sw $t0, 64($sp) +move $t0, $sp +lw $t1, 64($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 60($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 68($sp) +lw $t0, 504($sp) +lw $t1, 16($t0) +sw $t1, 52($sp) +lw $t0, 60($sp) +lw $t1, 16($t0) +sw $t1, 56($sp) +lw $a0, 52($sp) +lw $t1, 56($sp) +seq $a0, $a0, $t1 +sw $a0, 48($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 44($sp) +move $t0, $sp +lw $t1, 48($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 44($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 72($sp) +lw $t0, 44($sp) +lw $a0, 16($t0) +bnez $a0, label_35 +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 96($sp) +li $t0, 2 +sw $t0, 100($sp) +move $t0, $sp +lw $t1, 100($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 96($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 104($sp) +lw $t0, 504($sp) +lw $t1, 16($t0) +sw $t1, 88($sp) +lw $t0, 96($sp) +lw $t1, 16($t0) +sw $t1, 92($sp) +lw $a0, 88($sp) +lw $t1, 92($sp) +seq $a0, $a0, $t1 +sw $a0, 84($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 80($sp) +move $t0, $sp +lw $t1, 84($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 80($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 108($sp) +lw $t0, 80($sp) +lw $a0, 16($t0) +bnez $a0, label_36 +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 132($sp) +li $t0, 3 +sw $t0, 136($sp) +move $t0, $sp +lw $t1, 136($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 132($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 140($sp) +lw $t0, 504($sp) +lw $t1, 16($t0) +sw $t1, 124($sp) +lw $t0, 132($sp) +lw $t1, 16($t0) +sw $t1, 128($sp) +lw $a0, 124($sp) +lw $t1, 128($sp) +seq $a0, $a0, $t1 +sw $a0, 120($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 116($sp) +move $t0, $sp +lw $t1, 120($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 116($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 144($sp) +lw $t0, 116($sp) +lw $a0, 16($t0) +bnez $a0, label_37 +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 168($sp) +li $t0, 4 +sw $t0, 172($sp) +move $t0, $sp +lw $t1, 172($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 168($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 176($sp) +lw $t0, 504($sp) +lw $t1, 16($t0) +sw $t1, 160($sp) +lw $t0, 168($sp) +lw $t1, 16($t0) +sw $t1, 164($sp) +lw $a0, 160($sp) +lw $t1, 164($sp) +seq $a0, $a0, $t1 +sw $a0, 156($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 152($sp) +move $t0, $sp +lw $t1, 156($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 152($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 180($sp) +lw $t0, 152($sp) +lw $a0, 16($t0) +bnez $a0, label_38 +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 204($sp) +li $t0, 5 +sw $t0, 208($sp) +move $t0, $sp +lw $t1, 208($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 204($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 212($sp) +lw $t0, 504($sp) +lw $t1, 16($t0) +sw $t1, 196($sp) +lw $t0, 204($sp) +lw $t1, 16($t0) +sw $t1, 200($sp) +lw $a0, 196($sp) +lw $t1, 200($sp) +seq $a0, $a0, $t1 +sw $a0, 192($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 188($sp) +move $t0, $sp +lw $t1, 192($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 188($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 216($sp) +lw $t0, 188($sp) +lw $a0, 16($t0) +bnez $a0, label_39 +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 240($sp) +li $t0, 6 +sw $t0, 244($sp) +move $t0, $sp +lw $t1, 244($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 240($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 248($sp) +lw $t0, 504($sp) +lw $t1, 16($t0) +sw $t1, 232($sp) +lw $t0, 240($sp) +lw $t1, 16($t0) +sw $t1, 236($sp) +lw $a0, 232($sp) +lw $t1, 236($sp) +seq $a0, $a0, $t1 +sw $a0, 228($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 224($sp) +move $t0, $sp +lw $t1, 228($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 224($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 252($sp) +lw $t0, 224($sp) +lw $a0, 16($t0) +bnez $a0, label_40 +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 276($sp) +li $t0, 7 +sw $t0, 280($sp) +move $t0, $sp +lw $t1, 280($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 276($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 284($sp) +lw $t0, 504($sp) +lw $t1, 16($t0) +sw $t1, 268($sp) +lw $t0, 276($sp) +lw $t1, 16($t0) +sw $t1, 272($sp) +lw $a0, 268($sp) +lw $t1, 272($sp) +seq $a0, $a0, $t1 +sw $a0, 264($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 260($sp) +move $t0, $sp +lw $t1, 264($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 260($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 288($sp) +lw $t0, 260($sp) +lw $a0, 16($t0) +bnez $a0, label_41 +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 312($sp) +li $t0, 8 +sw $t0, 316($sp) +move $t0, $sp +lw $t1, 316($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 312($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 320($sp) +lw $t0, 504($sp) +lw $t1, 16($t0) +sw $t1, 304($sp) +lw $t0, 312($sp) +lw $t1, 16($t0) +sw $t1, 308($sp) +lw $a0, 304($sp) +lw $t1, 308($sp) +seq $a0, $a0, $t1 +sw $a0, 300($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 296($sp) +move $t0, $sp +lw $t1, 300($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 296($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 324($sp) +lw $t0, 296($sp) +lw $a0, 16($t0) +bnez $a0, label_42 +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 348($sp) +li $t0, 9 +sw $t0, 352($sp) +move $t0, $sp +lw $t1, 352($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 348($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 356($sp) +lw $t0, 504($sp) +lw $t1, 16($t0) +sw $t1, 340($sp) +lw $t0, 348($sp) +lw $t1, 16($t0) +sw $t1, 344($sp) +lw $a0, 340($sp) +lw $t1, 344($sp) +seq $a0, $a0, $t1 +sw $a0, 336($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 332($sp) +move $t0, $sp +lw $t1, 336($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 332($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 360($sp) +lw $t0, 332($sp) +lw $a0, 16($t0) +bnez $a0, label_43 +move $t0, $sp +lw $t1, 500($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 500($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 0($t2) +jal $t3 +sw $a1, 364($sp) +la $t0, empty_str +sw $t0, 368($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 372($sp) +move $t0, $sp +lw $t1, 368($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 372($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 376($sp) +lw $t1, 372($sp) +sw $t1, 328($sp) +b label_44 +label_43: +la $t0, data_12 +sw $t0, 380($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 384($sp) +move $t0, $sp +lw $t1, 380($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 384($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 388($sp) +lw $t1, 384($sp) +sw $t1, 328($sp) +label_44: +lw $t1, 328($sp) +sw $t1, 292($sp) +b label_45 +label_42: +la $t0, data_11 +sw $t0, 392($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 396($sp) +move $t0, $sp +lw $t1, 392($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 396($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 400($sp) +lw $t1, 396($sp) +sw $t1, 292($sp) +label_45: +lw $t1, 292($sp) +sw $t1, 256($sp) +b label_46 +label_41: +la $t0, data_10 +sw $t0, 404($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 408($sp) +move $t0, $sp +lw $t1, 404($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 408($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 412($sp) +lw $t1, 408($sp) +sw $t1, 256($sp) +label_46: +lw $t1, 256($sp) +sw $t1, 220($sp) +b label_47 +label_40: +la $t0, data_9 +sw $t0, 416($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 420($sp) +move $t0, $sp +lw $t1, 416($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 420($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 424($sp) +lw $t1, 420($sp) +sw $t1, 220($sp) +label_47: +lw $t1, 220($sp) +sw $t1, 184($sp) +b label_48 +label_39: +la $t0, data_8 +sw $t0, 428($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 432($sp) +move $t0, $sp +lw $t1, 428($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 432($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 436($sp) +lw $t1, 432($sp) +sw $t1, 184($sp) +label_48: +lw $t1, 184($sp) +sw $t1, 148($sp) +b label_49 +label_38: +la $t0, data_7 +sw $t0, 440($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 444($sp) +move $t0, $sp +lw $t1, 440($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 444($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 448($sp) +lw $t1, 444($sp) +sw $t1, 148($sp) +label_49: +lw $t1, 148($sp) +sw $t1, 112($sp) +b label_50 +label_37: +la $t0, data_6 +sw $t0, 452($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 456($sp) +move $t0, $sp +lw $t1, 452($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 456($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 460($sp) +lw $t1, 456($sp) +sw $t1, 112($sp) +label_50: +lw $t1, 112($sp) +sw $t1, 76($sp) +b label_51 +label_36: +la $t0, data_5 +sw $t0, 464($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 468($sp) +move $t0, $sp +lw $t1, 464($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 468($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 472($sp) +lw $t1, 468($sp) +sw $t1, 76($sp) +label_51: +lw $t1, 76($sp) +sw $t1, 40($sp) +b label_52 +label_35: +la $t0, data_4 +sw $t0, 476($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 480($sp) +move $t0, $sp +lw $t1, 476($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 480($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 484($sp) +lw $t1, 480($sp) +sw $t1, 40($sp) +label_52: +lw $t1, 40($sp) +sw $t1, 4($sp) +b label_53 +label_34: +la $t0, data_3 +sw $t0, 488($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 492($sp) +move $t0, $sp +lw $t1, 488($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 492($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 496($sp) +lw $t1, 492($sp) +sw $t1, 4($sp) +label_53: +lw $a1, 4($sp) +lw $ra, 0($sp) +addi $sp, $sp, 508 +jr $ra +A2I.a2i: +addi $sp, $sp, -312 +addi $sp, $sp, -4 +sw $ra, 0($sp) +move $t0, $sp +lw $t1, 320($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 320($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 24($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 28($sp) +li $t0, 0 +sw $t0, 32($sp) +move $t0, $sp +lw $t1, 32($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 28($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 36($sp) +lw $t0, 24($sp) +lw $t1, 16($t0) +sw $t1, 16($sp) +lw $t0, 28($sp) +lw $t1, 16($t0) +sw $t1, 20($sp) +lw $a0, 16($sp) +lw $t1, 20($sp) +seq $a0, $a0, $t1 +sw $a0, 12($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 8($sp) +move $t0, $sp +lw $t1, 12($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 8($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 40($sp) +lw $t0, 8($sp) +lw $a0, 16($t0) +bnez $a0, label_54 +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 68($sp) +li $t0, 1 +sw $t0, 72($sp) +move $t0, $sp +lw $t1, 72($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 68($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 76($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 80($sp) +li $t0, 0 +sw $t0, 84($sp) +move $t0, $sp +lw $t1, 84($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 80($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 88($sp) +move $t0, $sp +lw $t1, 68($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 80($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 320($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 320($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 20($t2) +jal $t3 +sw $a1, 64($sp) +la $t0, data_13 +sw $t0, 92($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 96($sp) +move $t0, $sp +lw $t1, 92($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 96($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 100($sp) +move $t0, $sp +lw $t1, 96($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 64($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_equals +sw $a1, 52($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 48($sp) +move $t0, $sp +lw $t1, 52($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 48($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 104($sp) +lw $t0, 48($sp) +lw $a0, 16($t0) +bnez $a0, label_55 +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 132($sp) +li $t0, 1 +sw $t0, 136($sp) +move $t0, $sp +lw $t1, 136($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 132($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 140($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 144($sp) +li $t0, 0 +sw $t0, 148($sp) +move $t0, $sp +lw $t1, 148($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 144($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 152($sp) +move $t0, $sp +lw $t1, 132($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 144($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 320($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 320($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 20($t2) +jal $t3 +sw $a1, 128($sp) +la $t0, data_14 +sw $t0, 156($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 160($sp) +move $t0, $sp +lw $t1, 156($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 160($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 164($sp) +move $t0, $sp +lw $t1, 160($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 128($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_equals +sw $a1, 116($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 112($sp) +move $t0, $sp +lw $t1, 116($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 112($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 168($sp) +lw $t0, 112($sp) +lw $a0, 16($t0) +bnez $a0, label_56 +move $t0, $sp +lw $t1, 320($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 316($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 316($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 24($t2) +jal $t3 +sw $a1, 172($sp) +lw $t1, 172($sp) +sw $t1, 108($sp) +b label_57 +label_56: +move $t0, $sp +lw $t1, 320($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 320($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 200($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 204($sp) +li $t0, 1 +sw $t0, 208($sp) +move $t0, $sp +lw $t1, 208($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 204($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 212($sp) +lw $t0, 200($sp) +lw $t1, 16($t0) +sw $t1, 192($sp) +lw $t0, 204($sp) +lw $t1, 16($t0) +sw $t1, 196($sp) +lw $a0, 192($sp) +lw $t1, 196($sp) +sub $a0, $a0, $t1 +sw $a0, 188($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 184($sp) +move $t0, $sp +lw $t1, 188($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 184($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 216($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 220($sp) +li $t0, 1 +sw $t0, 224($sp) +move $t0, $sp +lw $t1, 224($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 220($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 228($sp) +move $t0, $sp +lw $t1, 184($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 220($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 320($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 320($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 20($t2) +jal $t3 +sw $a1, 180($sp) +move $t0, $sp +lw $t1, 180($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 316($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 316($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 24($t2) +jal $t3 +sw $a1, 176($sp) +lw $t1, 176($sp) +sw $t1, 108($sp) +label_57: +lw $t1, 108($sp) +sw $t1, 44($sp) +b label_58 +label_55: +move $t0, $sp +lw $t1, 320($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 320($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 268($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 272($sp) +li $t0, 1 +sw $t0, 276($sp) +move $t0, $sp +lw $t1, 276($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 272($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 280($sp) +lw $t0, 268($sp) +lw $t1, 16($t0) +sw $t1, 260($sp) +lw $t0, 272($sp) +lw $t1, 16($t0) +sw $t1, 264($sp) +lw $a0, 260($sp) +lw $t1, 264($sp) +sub $a0, $a0, $t1 +sw $a0, 256($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 252($sp) +move $t0, $sp +lw $t1, 256($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 252($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 284($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 288($sp) +li $t0, 1 +sw $t0, 292($sp) +move $t0, $sp +lw $t1, 292($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 288($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 296($sp) +move $t0, $sp +lw $t1, 252($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 288($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 320($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 320($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 20($t2) +jal $t3 +sw $a1, 248($sp) +move $t0, $sp +lw $t1, 248($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 316($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 316($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 24($t2) +jal $t3 +sw $a1, 244($sp) +lw $t0, 244($sp) +lw $t1, 16($t0) +sw $t1, 240($sp) +lw $t1, 240($sp) +neg $a0, $t1 +sw $a0, 236($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 232($sp) +move $t0, $sp +lw $t1, 236($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 232($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 300($sp) +lw $t1, 232($sp) +sw $t1, 44($sp) +label_58: +lw $t1, 44($sp) +sw $t1, 4($sp) +b label_59 +label_54: +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 304($sp) +li $t0, 0 +sw $t0, 308($sp) +move $t0, $sp +lw $t1, 308($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 304($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 312($sp) +lw $t1, 304($sp) +sw $t1, 4($sp) +label_59: +lw $a1, 4($sp) +lw $ra, 0($sp) +addi $sp, $sp, 324 +jr $ra +A2I.a2i_aux: +addi $sp, $sp, -188 +addi $sp, $sp, -4 +sw $ra, 0($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 4($sp) +li $t0, 0 +sw $t0, 8($sp) +move $t0, $sp +lw $t1, 8($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 4($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 12($sp) +lw $t1, 4($sp) +sw $t1, 16($sp) +move $t0, $sp +lw $t1, 196($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 196($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 20($sp) +lw $t1, 20($sp) +sw $t1, 24($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 28($sp) +li $t0, 0 +sw $t0, 32($sp) +move $t0, $sp +lw $t1, 32($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 28($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 36($sp) +lw $t1, 28($sp) +sw $t1, 40($sp) +label_60: +lw $t0, 40($sp) +lw $t1, 16($t0) +sw $t1, 56($sp) +lw $t0, 24($sp) +lw $t1, 16($t0) +sw $t1, 60($sp) +lw $a0, 56($sp) +lw $t1, 60($sp) +slt $a0, $a0, $t1 +sw $a0, 52($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 48($sp) +move $t0, $sp +lw $t1, 52($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 48($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 64($sp) +lw $t0, 48($sp) +lw $a0, 16($t0) +bnez $a0, label_61 +b label_62 +label_61: +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 100($sp) +li $t0, 10 +sw $t0, 104($sp) +move $t0, $sp +lw $t1, 104($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 100($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 108($sp) +lw $t0, 16($sp) +lw $t1, 16($t0) +sw $t1, 92($sp) +lw $t0, 100($sp) +lw $t1, 16($t0) +sw $t1, 96($sp) +lw $a0, 92($sp) +lw $t1, 96($sp) +mul $a0, $a0, $t1 +sw $a0, 88($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 84($sp) +move $t0, $sp +lw $t1, 88($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 84($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 112($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 124($sp) +li $t0, 1 +sw $t0, 128($sp) +move $t0, $sp +lw $t1, 128($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 124($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 132($sp) +move $t0, $sp +lw $t1, 124($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 40($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 196($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 196($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 20($t2) +jal $t3 +sw $a1, 120($sp) +move $t0, $sp +lw $t1, 120($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 192($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 192($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 116($sp) +lw $t0, 84($sp) +lw $t1, 16($t0) +sw $t1, 76($sp) +lw $t0, 116($sp) +lw $t1, 16($t0) +sw $t1, 80($sp) +lw $a0, 76($sp) +lw $t1, 80($sp) +add $a0, $a0, $t1 +sw $a0, 72($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 68($sp) +move $t0, $sp +lw $t1, 72($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 68($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 136($sp) +lw $t1, 68($sp) +sw $t1, 16($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 160($sp) +li $t0, 1 +sw $t0, 164($sp) +move $t0, $sp +lw $t1, 164($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 160($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 168($sp) +lw $t0, 40($sp) +lw $t1, 16($t0) +sw $t1, 152($sp) +lw $t0, 160($sp) +lw $t1, 16($t0) +sw $t1, 156($sp) +lw $a0, 152($sp) +lw $t1, 156($sp) +add $a0, $a0, $t1 +sw $a0, 148($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 144($sp) +move $t0, $sp +lw $t1, 148($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 144($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 172($sp) +lw $t1, 144($sp) +sw $t1, 40($sp) +b label_60 +label_62: +lw $t1, 44($sp) +sw $t1, 180($sp) +lw $t1, 180($sp) +sw $t1, 184($sp) +lw $t1, 16($sp) +sw $t1, 188($sp) +lw $a1, 188($sp) +lw $ra, 0($sp) +addi $sp, $sp, 200 +jr $ra +A2I.i2a: +addi $sp, $sp, -156 +addi $sp, $sp, -4 +sw $ra, 0($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 24($sp) +li $t0, 0 +sw $t0, 28($sp) +move $t0, $sp +lw $t1, 28($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 24($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 32($sp) +lw $t0, 164($sp) +lw $t1, 16($t0) +sw $t1, 16($sp) +lw $t0, 24($sp) +lw $t1, 16($t0) +sw $t1, 20($sp) +lw $a0, 16($sp) +lw $t1, 20($sp) +seq $a0, $a0, $t1 +sw $a0, 12($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 8($sp) +move $t0, $sp +lw $t1, 12($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 8($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 36($sp) +lw $t0, 8($sp) +lw $a0, 16($t0) +bnez $a0, label_63 +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 60($sp) +li $t0, 0 +sw $t0, 64($sp) +move $t0, $sp +lw $t1, 64($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 60($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 68($sp) +lw $t0, 60($sp) +lw $t1, 16($t0) +sw $t1, 52($sp) +lw $t0, 164($sp) +lw $t1, 16($t0) +sw $t1, 56($sp) +lw $a0, 52($sp) +lw $t1, 56($sp) +slt $a0, $a0, $t1 +sw $a0, 48($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 44($sp) +move $t0, $sp +lw $t1, 48($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 44($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 72($sp) +lw $t0, 44($sp) +lw $a0, 16($t0) +bnez $a0, label_64 +la $t0, data_13 +sw $t0, 80($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 84($sp) +move $t0, $sp +lw $t1, 80($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 84($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 88($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 124($sp) +li $t0, 1 +sw $t0, 128($sp) +move $t0, $sp +lw $t1, 128($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 124($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 132($sp) +lw $t0, 124($sp) +lw $t1, 16($t0) +sw $t1, 120($sp) +lw $t1, 120($sp) +neg $a0, $t1 +sw $a0, 116($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 112($sp) +move $t0, $sp +lw $t1, 116($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 112($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 136($sp) +lw $t0, 164($sp) +lw $t1, 16($t0) +sw $t1, 104($sp) +lw $t0, 112($sp) +lw $t1, 16($t0) +sw $t1, 108($sp) +lw $a0, 104($sp) +lw $t1, 108($sp) +mul $a0, $a0, $t1 +sw $a0, 100($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 96($sp) +move $t0, $sp +lw $t1, 100($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 96($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 140($sp) +move $t0, $sp +lw $t1, 96($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 160($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 160($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 32($t2) +jal $t3 +sw $a1, 92($sp) +move $t0, $sp +lw $t1, 92($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 84($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 84($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 16($t2) +jal $t3 +sw $a1, 76($sp) +lw $t1, 76($sp) +sw $t1, 40($sp) +b label_65 +label_64: +move $t0, $sp +lw $t1, 164($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 160($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 160($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 32($t2) +jal $t3 +sw $a1, 144($sp) +lw $t1, 144($sp) +sw $t1, 40($sp) +label_65: +lw $t1, 40($sp) +sw $t1, 4($sp) +b label_66 +label_63: +la $t0, data_3 +sw $t0, 148($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 152($sp) +move $t0, $sp +lw $t1, 148($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 152($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 156($sp) +lw $t1, 152($sp) +sw $t1, 4($sp) +label_66: +lw $a1, 4($sp) +lw $ra, 0($sp) +addi $sp, $sp, 168 +jr $ra +A2I.i2a_aux: +addi $sp, $sp, -152 +addi $sp, $sp, -4 +sw $ra, 0($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 24($sp) +li $t0, 0 +sw $t0, 28($sp) +move $t0, $sp +lw $t1, 28($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 24($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 32($sp) +lw $t0, 160($sp) +lw $t1, 16($t0) +sw $t1, 16($sp) +lw $t0, 24($sp) +lw $t1, 16($t0) +sw $t1, 20($sp) +lw $a0, 16($sp) +lw $t1, 20($sp) +seq $a0, $a0, $t1 +sw $a0, 12($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 8($sp) +move $t0, $sp +lw $t1, 12($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 8($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 36($sp) +lw $t0, 8($sp) +lw $a0, 16($t0) +bnez $a0, label_67 +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 56($sp) +li $t0, 10 +sw $t0, 60($sp) +move $t0, $sp +lw $t1, 60($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 56($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 64($sp) +lw $t0, 160($sp) +lw $t1, 16($t0) +sw $t1, 48($sp) +lw $t0, 56($sp) +lw $t1, 16($t0) +sw $t1, 52($sp) +lw $a0, 48($sp) +lw $t1, 52($sp) +beq $t1, 0, div_zero_error +div $a0, $a0, $t1 +sw $a0, 44($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 40($sp) +move $t0, $sp +lw $t1, 44($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 40($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 68($sp) +lw $t1, 40($sp) +sw $t1, 72($sp) +move $t0, $sp +lw $t1, 72($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 156($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 156($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 32($t2) +jal $t3 +sw $a1, 80($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 120($sp) +li $t0, 10 +sw $t0, 124($sp) +move $t0, $sp +lw $t1, 124($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 120($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 128($sp) +lw $t0, 72($sp) +lw $t1, 16($t0) +sw $t1, 112($sp) +lw $t0, 120($sp) +lw $t1, 16($t0) +sw $t1, 116($sp) +lw $a0, 112($sp) +lw $t1, 116($sp) +mul $a0, $a0, $t1 +sw $a0, 108($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 104($sp) +move $t0, $sp +lw $t1, 108($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 104($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 132($sp) +lw $t0, 160($sp) +lw $t1, 16($t0) +sw $t1, 96($sp) +lw $t0, 104($sp) +lw $t1, 16($t0) +sw $t1, 100($sp) +lw $a0, 96($sp) +lw $t1, 100($sp) +sub $a0, $a0, $t1 +sw $a0, 92($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 88($sp) +move $t0, $sp +lw $t1, 92($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 88($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 136($sp) +move $t0, $sp +lw $t1, 88($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 156($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 156($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 16($t2) +jal $t3 +sw $a1, 84($sp) +move $t0, $sp +lw $t1, 84($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 80($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 80($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 16($t2) +jal $t3 +sw $a1, 76($sp) +lw $t1, 76($sp) +sw $t1, 140($sp) +lw $t1, 140($sp) +sw $t1, 4($sp) +b label_68 +label_67: +la $t0, empty_str +sw $t0, 144($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 148($sp) +move $t0, $sp +lw $t1, 144($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 148($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 152($sp) +lw $t1, 148($sp) +sw $t1, 4($sp) +label_68: +lw $a1, 4($sp) +lw $ra, 0($sp) +addi $sp, $sp, 164 +jr $ra +Main_init: +addi $sp, $sp, -28 +addi $sp, $sp, -4 +sw $ra, 0($sp) +move $t0, $sp +lw $t1, 32($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal IO_init +sw $a1, 4($sp) +move $a1, $zero +la $t0, empty_str +sw $t0, 8($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 12($sp) +move $t0, $sp +lw $t1, 8($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 12($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 16($sp) +lw $t0, 32($sp) +lw $t1, 12($sp) +sw $t1, 16($t0) +lw $t0, 32($sp) +la $t1, void +sw $t1, 20($t0) +lw $t0, 32($sp) +la $t1, void +sw $t1, 24($t0) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 20($sp) +li $t0, 1 +sw $t0, 24($sp) +move $t0, $sp +lw $t1, 24($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 20($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 28($sp) +lw $t0, 32($sp) +lw $t1, 20($sp) +sw $t1, 28($t0) +lw $ra, 0($sp) +addi $sp, $sp, 36 +jr $ra +Main.menu: +addi $sp, $sp, -356 +addi $sp, $sp, -4 +sw $ra, 0($sp) +la $t0, data_15 +sw $t0, 8($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 12($sp) +move $t0, $sp +lw $t1, 8($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 12($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 16($sp) +move $t0, $sp +lw $t1, 12($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 4($sp) +lw $t0, 360($sp) +lw $t1, 20($t0) +sw $t1, 304($sp) +move $t0, $sp +lw $t1, 304($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 48($t2) +jal $t3 +sw $a1, 20($sp) +la $t0, data_16 +sw $t0, 32($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 36($sp) +move $t0, $sp +lw $t1, 32($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 36($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 40($sp) +move $t0, $sp +lw $t1, 36($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 28($sp) +la $t0, data_17 +sw $t0, 48($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 52($sp) +move $t0, $sp +lw $t1, 48($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 52($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 56($sp) +move $t0, $sp +lw $t1, 52($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 44($sp) +lw $t0, 360($sp) +lw $t1, 20($t0) +sw $t1, 304($sp) +move $t0, $sp +lw $t1, 304($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 48($t2) +jal $t3 +sw $a1, 60($sp) +la $t0, data_18 +sw $t0, 72($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 76($sp) +move $t0, $sp +lw $t1, 72($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 76($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 80($sp) +move $t0, $sp +lw $t1, 76($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 68($sp) +la $t0, data_19 +sw $t0, 88($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 92($sp) +move $t0, $sp +lw $t1, 88($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 92($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 96($sp) +move $t0, $sp +lw $t1, 92($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 84($sp) +lw $t0, 360($sp) +lw $t1, 20($t0) +sw $t1, 304($sp) +move $t0, $sp +lw $t1, 304($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 48($t2) +jal $t3 +sw $a1, 100($sp) +la $t0, data_20 +sw $t0, 112($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 116($sp) +move $t0, $sp +lw $t1, 112($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 116($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 120($sp) +move $t0, $sp +lw $t1, 116($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 108($sp) +la $t0, data_21 +sw $t0, 128($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 132($sp) +move $t0, $sp +lw $t1, 128($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 132($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 136($sp) +move $t0, $sp +lw $t1, 132($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 124($sp) +lw $t0, 360($sp) +lw $t1, 20($t0) +sw $t1, 304($sp) +move $t0, $sp +lw $t1, 304($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 48($t2) +jal $t3 +sw $a1, 140($sp) +la $t0, data_22 +sw $t0, 152($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 156($sp) +move $t0, $sp +lw $t1, 152($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 156($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 160($sp) +move $t0, $sp +lw $t1, 156($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 148($sp) +la $t0, data_23 +sw $t0, 168($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 172($sp) +move $t0, $sp +lw $t1, 168($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 172($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 176($sp) +move $t0, $sp +lw $t1, 172($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 164($sp) +lw $t0, 360($sp) +lw $t1, 20($t0) +sw $t1, 304($sp) +move $t0, $sp +lw $t1, 304($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 48($t2) +jal $t3 +sw $a1, 180($sp) +la $t0, data_24 +sw $t0, 192($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 196($sp) +move $t0, $sp +lw $t1, 192($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 196($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 200($sp) +move $t0, $sp +lw $t1, 196($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 188($sp) +la $t0, data_25 +sw $t0, 208($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 212($sp) +move $t0, $sp +lw $t1, 208($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 212($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 216($sp) +move $t0, $sp +lw $t1, 212($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 204($sp) +lw $t0, 360($sp) +lw $t1, 20($t0) +sw $t1, 304($sp) +move $t0, $sp +lw $t1, 304($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 48($t2) +jal $t3 +sw $a1, 220($sp) +la $t0, data_26 +sw $t0, 232($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 236($sp) +move $t0, $sp +lw $t1, 232($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 236($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 240($sp) +move $t0, $sp +lw $t1, 236($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 228($sp) +la $t0, data_27 +sw $t0, 248($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 252($sp) +move $t0, $sp +lw $t1, 248($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 252($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 256($sp) +move $t0, $sp +lw $t1, 252($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 244($sp) +lw $t0, 360($sp) +lw $t1, 20($t0) +sw $t1, 304($sp) +move $t0, $sp +lw $t1, 304($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 48($t2) +jal $t3 +sw $a1, 260($sp) +la $t0, data_28 +sw $t0, 272($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 276($sp) +move $t0, $sp +lw $t1, 272($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 276($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 280($sp) +move $t0, $sp +lw $t1, 276($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 268($sp) +la $t0, data_29 +sw $t0, 288($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 292($sp) +move $t0, $sp +lw $t1, 288($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 292($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 296($sp) +move $t0, $sp +lw $t1, 292($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 284($sp) +lw $t0, 360($sp) +lw $t1, 20($t0) +sw $t1, 304($sp) +move $t0, $sp +lw $t1, 304($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 48($t2) +jal $t3 +sw $a1, 300($sp) +la $t0, data_30 +sw $t0, 312($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 316($sp) +move $t0, $sp +lw $t1, 312($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 316($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 320($sp) +move $t0, $sp +lw $t1, 316($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 308($sp) +la $t0, data_31 +sw $t0, 328($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 332($sp) +move $t0, $sp +lw $t1, 328($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 332($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 336($sp) +move $t0, $sp +lw $t1, 332($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 324($sp) +la $t0, data_32 +sw $t0, 344($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 348($sp) +move $t0, $sp +lw $t1, 344($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 348($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 352($sp) +move $t0, $sp +lw $t1, 348($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 340($sp) +move $t0, $sp +lw $t1, 360($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 360($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 20($t2) +jal $t3 +sw $a1, 356($sp) +lw $a1, 356($sp) +lw $ra, 0($sp) +addi $sp, $sp, 364 +jr $ra +Main.prompt: +addi $sp, $sp, -36 +addi $sp, $sp, -4 +sw $ra, 0($sp) +la $t0, data_1 +sw $t0, 8($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 12($sp) +move $t0, $sp +lw $t1, 8($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 12($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 16($sp) +move $t0, $sp +lw $t1, 12($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 40($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 40($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 4($sp) +la $t0, data_33 +sw $t0, 24($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 28($sp) +move $t0, $sp +lw $t1, 24($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 28($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 32($sp) +move $t0, $sp +lw $t1, 28($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 40($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 40($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 20($sp) +move $t0, $sp +lw $t1, 40($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 40($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 20($t2) +jal $t3 +sw $a1, 36($sp) +lw $a1, 36($sp) +lw $ra, 0($sp) +addi $sp, $sp, 44 +jr $ra +Main.get_int: +addi $sp, $sp, -32 +addi $sp, $sp, -4 +sw $ra, 0($sp) +li $a0, 16 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 10 +sw $t1, 0($t0) +la $t1, A2I_name +sw $t1, 4($t0) +li $t1, 4 +sw $t1, 8($t0) +la $t1, A2I_methods +sw $t1, 12($t0) +sw $t0, 4($sp) +move $t0, $sp +lw $t1, 4($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal A2I_init +sw $a1, 8($sp) +lw $t1, 4($sp) +sw $t1, 12($sp) +move $t0, $sp +lw $t1, 36($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 36($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 32($t2) +jal $t3 +sw $a1, 16($sp) +lw $t1, 16($sp) +sw $t1, 20($sp) +move $t0, $sp +lw $t1, 20($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 12($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 12($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 20($t2) +jal $t3 +sw $a1, 24($sp) +lw $t1, 24($sp) +sw $t1, 28($sp) +lw $t1, 28($sp) +sw $t1, 32($sp) +lw $a1, 32($sp) +lw $ra, 0($sp) +addi $sp, $sp, 40 +jr $ra +Main.is_even: +addi $sp, $sp, -196 +addi $sp, $sp, -4 +sw $ra, 0($sp) +lw $t1, 204($sp) +sw $t1, 4($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 28($sp) +li $t0, 0 +sw $t0, 32($sp) +move $t0, $sp +lw $t1, 32($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 28($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 36($sp) +lw $t0, 4($sp) +lw $t1, 16($t0) +sw $t1, 20($sp) +lw $t0, 28($sp) +lw $t1, 16($t0) +sw $t1, 24($sp) +lw $a0, 20($sp) +lw $t1, 24($sp) +slt $a0, $a0, $t1 +sw $a0, 16($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 12($sp) +move $t0, $sp +lw $t1, 16($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 12($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 40($sp) +lw $t0, 12($sp) +lw $a0, 16($t0) +bnez $a0, label_69 +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 64($sp) +li $t0, 0 +sw $t0, 68($sp) +move $t0, $sp +lw $t1, 68($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 64($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 72($sp) +lw $t0, 64($sp) +lw $t1, 16($t0) +sw $t1, 56($sp) +lw $t0, 4($sp) +lw $t1, 16($t0) +sw $t1, 60($sp) +lw $a0, 56($sp) +lw $t1, 60($sp) +seq $a0, $a0, $t1 +sw $a0, 52($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 48($sp) +move $t0, $sp +lw $t1, 52($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 48($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 76($sp) +lw $t0, 48($sp) +lw $a0, 16($t0) +bnez $a0, label_70 +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 100($sp) +li $t0, 1 +sw $t0, 104($sp) +move $t0, $sp +lw $t1, 104($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 100($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 108($sp) +lw $t0, 100($sp) +lw $t1, 16($t0) +sw $t1, 92($sp) +lw $t0, 4($sp) +lw $t1, 16($t0) +sw $t1, 96($sp) +lw $a0, 92($sp) +lw $t1, 96($sp) +seq $a0, $a0, $t1 +sw $a0, 88($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 84($sp) +move $t0, $sp +lw $t1, 88($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 84($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 112($sp) +lw $t0, 84($sp) +lw $a0, 16($t0) +bnez $a0, label_71 +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 136($sp) +li $t0, 2 +sw $t0, 140($sp) +move $t0, $sp +lw $t1, 140($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 136($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 144($sp) +lw $t0, 4($sp) +lw $t1, 16($t0) +sw $t1, 128($sp) +lw $t0, 136($sp) +lw $t1, 16($t0) +sw $t1, 132($sp) +lw $a0, 128($sp) +lw $t1, 132($sp) +sub $a0, $a0, $t1 +sw $a0, 124($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 120($sp) +move $t0, $sp +lw $t1, 124($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 120($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 148($sp) +move $t0, $sp +lw $t1, 120($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 200($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 200($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 40($t2) +jal $t3 +sw $a1, 116($sp) +lw $t1, 116($sp) +sw $t1, 80($sp) +b label_72 +label_71: +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 152($sp) +li $t0, 0 +sw $t0, 156($sp) +move $t0, $sp +lw $t1, 156($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 152($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 160($sp) +lw $t1, 152($sp) +sw $t1, 80($sp) +label_72: +lw $t1, 80($sp) +sw $t1, 44($sp) +b label_73 +label_70: +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 164($sp) +li $t0, 1 +sw $t0, 168($sp) +move $t0, $sp +lw $t1, 168($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 164($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 172($sp) +lw $t1, 164($sp) +sw $t1, 44($sp) +label_73: +lw $t1, 44($sp) +sw $t1, 8($sp) +b label_74 +label_69: +lw $t0, 4($sp) +lw $t1, 16($t0) +sw $t1, 188($sp) +lw $t1, 188($sp) +neg $a0, $t1 +sw $a0, 184($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 180($sp) +move $t0, $sp +lw $t1, 184($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 180($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 192($sp) +move $t0, $sp +lw $t1, 180($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 200($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 200($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 40($t2) +jal $t3 +sw $a1, 176($sp) +lw $t1, 176($sp) +sw $t1, 8($sp) +label_74: +lw $t1, 8($sp) +sw $t1, 196($sp) +lw $a1, 196($sp) +lw $ra, 0($sp) +addi $sp, $sp, 208 +jr $ra +Main.class_type: +addi $sp, $sp, -124 +addi $sp, $sp, -4 +sw $ra, 0($sp) +lw $t0, 132($sp) +lw $t1, 0($t0) +la $a0, void +bne $t1 $a0 label_76 +b case_void_error +label_76: +blt $t1 9 label_77 +bgt $t1 9 label_77 +lw $t1, 132($sp) +sw $t1, 8($sp) +la $t0, data_34 +sw $t0, 16($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 20($sp) +move $t0, $sp +lw $t1, 16($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 20($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 24($sp) +move $t0, $sp +lw $t1, 20($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 128($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 128($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 12($sp) +lw $t1, 12($sp) +sw $t1, 4($sp) +b label_75 +label_77: +blt $t1 8 label_78 +bgt $t1 8 label_78 +lw $t1, 132($sp) +sw $t1, 28($sp) +la $t0, data_35 +sw $t0, 36($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 40($sp) +move $t0, $sp +lw $t1, 36($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 40($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 44($sp) +move $t0, $sp +lw $t1, 40($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 128($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 128($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 32($sp) +lw $t1, 32($sp) +sw $t1, 4($sp) +b label_75 +label_78: +blt $t1 7 label_79 +bgt $t1 7 label_79 +lw $t1, 132($sp) +sw $t1, 48($sp) +la $t0, data_36 +sw $t0, 56($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 60($sp) +move $t0, $sp +lw $t1, 56($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 60($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 64($sp) +move $t0, $sp +lw $t1, 60($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 128($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 128($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 52($sp) +lw $t1, 52($sp) +sw $t1, 4($sp) +b label_75 +label_79: +blt $t1 6 label_80 +bgt $t1 6 label_80 +lw $t1, 132($sp) +sw $t1, 68($sp) +la $t0, data_37 +sw $t0, 76($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 80($sp) +move $t0, $sp +lw $t1, 76($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 80($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 84($sp) +move $t0, $sp +lw $t1, 80($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 128($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 128($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 72($sp) +lw $t1, 72($sp) +sw $t1, 4($sp) +b label_75 +label_80: +blt $t1 5 label_81 +bgt $t1 5 label_81 +lw $t1, 132($sp) +sw $t1, 88($sp) +la $t0, data_38 +sw $t0, 96($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 100($sp) +move $t0, $sp +lw $t1, 96($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 100($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 104($sp) +move $t0, $sp +lw $t1, 100($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 128($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 128($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 92($sp) +lw $t1, 92($sp) +sw $t1, 4($sp) +b label_75 +label_81: +blt $t1 0 label_82 +bgt $t1 11 label_82 +lw $t1, 132($sp) +sw $t1, 108($sp) +la $t0, data_39 +sw $t0, 116($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 120($sp) +move $t0, $sp +lw $t1, 116($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 120($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 124($sp) +move $t0, $sp +lw $t1, 120($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 128($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 128($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 112($sp) +lw $t1, 112($sp) +sw $t1, 4($sp) +b label_75 +label_82: +b case_no_match_error +label_75: +lw $a1, 4($sp) +lw $ra, 0($sp) +addi $sp, $sp, 136 +jr $ra +Main.print: +addi $sp, $sp, -44 +addi $sp, $sp, -4 +sw $ra, 0($sp) +li $a0, 16 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 10 +sw $t1, 0($t0) +la $t1, A2I_name +sw $t1, 4($t0) +li $t1, 4 +sw $t1, 8($t0) +la $t1, A2I_methods +sw $t1, 12($t0) +sw $t0, 4($sp) +move $t0, $sp +lw $t1, 4($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal A2I_init +sw $a1, 8($sp) +lw $t1, 4($sp) +sw $t1, 12($sp) +move $t0, $sp +lw $t1, 52($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 52($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 24($sp) +move $t0, $sp +lw $t1, 24($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 12($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 12($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 28($t2) +jal $t3 +sw $a1, 20($sp) +move $t0, $sp +lw $t1, 20($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 48($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 48($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 16($sp) +la $t0, data_40 +sw $t0, 32($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 36($sp) +move $t0, $sp +lw $t1, 32($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 36($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 40($sp) +move $t0, $sp +lw $t1, 36($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 48($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 48($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 28($sp) +lw $t1, 28($sp) +sw $t1, 44($sp) +lw $a1, 44($sp) +lw $ra, 0($sp) +addi $sp, $sp, 56 +jr $ra +Main.main: +addi $sp, $sp, -1136 +addi $sp, $sp, -4 +sw $ra, 0($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 5 +sw $t1, 0($t0) +la $t1, A_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, A_methods +sw $t1, 12($t0) +sw $t0, 4($sp) +move $t0, $sp +lw $t1, 4($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal A_init +sw $a1, 8($sp) +lw $t0, 1140($sp) +lw $t1, 4($sp) +sw $t1, 20($t0) +label_83: +lw $t0, 1140($sp) +lw $t1, 28($t0) +sw $t1, 20($sp) +lw $t0, 20($sp) +lw $a0, 16($t0) +bnez $a0, label_84 +b label_85 +label_84: +la $t0, data_41 +sw $t0, 28($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 32($sp) +move $t0, $sp +lw $t1, 28($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 32($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 36($sp) +move $t0, $sp +lw $t1, 32($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 24($sp) +lw $t0, 1140($sp) +lw $t1, 20($t0) +sw $t1, 1132($sp) +move $t0, $sp +lw $t1, 1132($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 48($t2) +jal $t3 +sw $a1, 40($sp) +lw $t0, 1140($sp) +lw $t1, 20($t0) +sw $t1, 1132($sp) +move $t0, $sp +lw $t1, 1132($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1132($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 56($sp) +move $t0, $sp +lw $t1, 56($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 40($t2) +jal $t3 +sw $a1, 52($sp) +lw $t0, 52($sp) +lw $a0, 16($t0) +bnez $a0, label_86 +la $t0, data_42 +sw $t0, 68($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 72($sp) +move $t0, $sp +lw $t1, 68($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 72($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 76($sp) +move $t0, $sp +lw $t1, 72($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 64($sp) +lw $t1, 64($sp) +sw $t1, 48($sp) +b label_87 +label_86: +la $t0, data_43 +sw $t0, 84($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 88($sp) +move $t0, $sp +lw $t1, 84($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 88($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 92($sp) +move $t0, $sp +lw $t1, 88($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 80($sp) +lw $t1, 80($sp) +sw $t1, 48($sp) +label_87: +lw $t0, 1140($sp) +lw $t1, 20($t0) +sw $t1, 1132($sp) +move $t0, $sp +lw $t1, 1132($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 44($t2) +jal $t3 +sw $a1, 96($sp) +move $t0, $sp +lw $t1, 1140($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 28($t2) +jal $t3 +sw $a1, 104($sp) +lw $t0, 1140($sp) +lw $t1, 104($sp) +sw $t1, 16($t0) +lw $t0, 1140($sp) +lw $t1, 16($t0) +sw $t1, 492($sp) +la $t0, data_44 +sw $t0, 136($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 140($sp) +move $t0, $sp +lw $t1, 136($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 140($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 144($sp) +move $t0, $sp +lw $t1, 140($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 492($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_equals +sw $a1, 120($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 116($sp) +move $t0, $sp +lw $t1, 120($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 116($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 148($sp) +lw $t0, 116($sp) +lw $a0, 16($t0) +bnez $a0, label_88 +lw $t0, 1140($sp) +lw $t1, 16($t0) +sw $t1, 492($sp) +la $t0, data_45 +sw $t0, 176($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 180($sp) +move $t0, $sp +lw $t1, 176($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 180($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 184($sp) +move $t0, $sp +lw $t1, 180($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 492($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_equals +sw $a1, 160($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 156($sp) +move $t0, $sp +lw $t1, 160($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 156($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 188($sp) +lw $t0, 156($sp) +lw $a0, 16($t0) +bnez $a0, label_89 +lw $t0, 1140($sp) +lw $t1, 16($t0) +sw $t1, 492($sp) +la $t0, data_46 +sw $t0, 216($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 220($sp) +move $t0, $sp +lw $t1, 216($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 220($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 224($sp) +move $t0, $sp +lw $t1, 220($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 492($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_equals +sw $a1, 200($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 196($sp) +move $t0, $sp +lw $t1, 200($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 196($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 228($sp) +lw $t0, 196($sp) +lw $a0, 16($t0) +bnez $a0, label_90 +lw $t0, 1140($sp) +lw $t1, 16($t0) +sw $t1, 492($sp) +la $t0, data_47 +sw $t0, 256($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 260($sp) +move $t0, $sp +lw $t1, 256($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 260($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 264($sp) +move $t0, $sp +lw $t1, 260($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 492($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_equals +sw $a1, 240($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 236($sp) +move $t0, $sp +lw $t1, 240($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 236($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 268($sp) +lw $t0, 236($sp) +lw $a0, 16($t0) +bnez $a0, label_91 +lw $t0, 1140($sp) +lw $t1, 16($t0) +sw $t1, 492($sp) +la $t0, data_48 +sw $t0, 296($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 300($sp) +move $t0, $sp +lw $t1, 296($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 300($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 304($sp) +move $t0, $sp +lw $t1, 300($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 492($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_equals +sw $a1, 280($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 276($sp) +move $t0, $sp +lw $t1, 280($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 276($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 308($sp) +lw $t0, 276($sp) +lw $a0, 16($t0) +bnez $a0, label_92 +lw $t0, 1140($sp) +lw $t1, 16($t0) +sw $t1, 492($sp) +la $t0, data_49 +sw $t0, 336($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 340($sp) +move $t0, $sp +lw $t1, 336($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 340($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 344($sp) +move $t0, $sp +lw $t1, 340($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 492($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_equals +sw $a1, 320($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 316($sp) +move $t0, $sp +lw $t1, 320($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 316($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 348($sp) +lw $t0, 316($sp) +lw $a0, 16($t0) +bnez $a0, label_93 +lw $t0, 1140($sp) +lw $t1, 16($t0) +sw $t1, 492($sp) +la $t0, data_50 +sw $t0, 376($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 380($sp) +move $t0, $sp +lw $t1, 376($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 380($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 384($sp) +move $t0, $sp +lw $t1, 380($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 492($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_equals +sw $a1, 360($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 356($sp) +move $t0, $sp +lw $t1, 360($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 356($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 388($sp) +lw $t0, 356($sp) +lw $a0, 16($t0) +bnez $a0, label_94 +lw $t0, 1140($sp) +lw $t1, 16($t0) +sw $t1, 492($sp) +la $t0, data_51 +sw $t0, 416($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 420($sp) +move $t0, $sp +lw $t1, 416($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 420($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 424($sp) +move $t0, $sp +lw $t1, 420($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 492($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_equals +sw $a1, 400($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 396($sp) +move $t0, $sp +lw $t1, 400($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 396($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 428($sp) +lw $t0, 396($sp) +lw $a0, 16($t0) +bnez $a0, label_95 +lw $t0, 1140($sp) +lw $t1, 16($t0) +sw $t1, 492($sp) +la $t0, data_52 +sw $t0, 456($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 460($sp) +move $t0, $sp +lw $t1, 456($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 460($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 464($sp) +move $t0, $sp +lw $t1, 460($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 492($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_equals +sw $a1, 440($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 436($sp) +move $t0, $sp +lw $t1, 440($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 436($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 468($sp) +lw $t0, 436($sp) +lw $a0, 16($t0) +bnez $a0, label_96 +lw $t0, 1140($sp) +lw $t1, 16($t0) +sw $t1, 492($sp) +la $t0, data_53 +sw $t0, 496($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 500($sp) +move $t0, $sp +lw $t1, 496($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 500($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 504($sp) +move $t0, $sp +lw $t1, 500($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 492($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_equals +sw $a1, 480($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 476($sp) +move $t0, $sp +lw $t1, 480($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 476($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 508($sp) +lw $t0, 476($sp) +lw $a0, 16($t0) +bnez $a0, label_97 +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 5 +sw $t1, 0($t0) +la $t1, A_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, A_methods +sw $t1, 12($t0) +sw $t0, 516($sp) +move $t0, $sp +lw $t1, 516($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal A_init +sw $a1, 520($sp) +lw $t0, 1140($sp) +lw $t1, 20($t0) +sw $t1, 1132($sp) +move $t0, $sp +lw $t1, 1132($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1132($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 524($sp) +move $t0, $sp +lw $t1, 524($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 516($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 516($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 20($t2) +jal $t3 +sw $a1, 512($sp) +lw $t0, 1140($sp) +lw $t1, 512($sp) +sw $t1, 20($t0) +lw $t1, 512($sp) +sw $t1, 472($sp) +b label_98 +label_97: +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 3 +sw $t1, 0($t0) +la $t1, Bool_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Bool_methods +sw $t1, 12($t0) +sw $t0, 536($sp) +li $t0, 0 +sw $t0, 540($sp) +move $t0, $sp +lw $t1, 540($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 536($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Bool_init +sw $a1, 544($sp) +lw $t0, 1140($sp) +lw $t1, 536($sp) +sw $t1, 28($t0) +lw $t1, 536($sp) +sw $t1, 472($sp) +label_98: +lw $t1, 472($sp) +sw $t1, 432($sp) +b label_99 +label_96: +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 5 +sw $t1, 0($t0) +la $t1, A_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, A_methods +sw $t1, 12($t0) +sw $t0, 552($sp) +move $t0, $sp +lw $t1, 552($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal A_init +sw $a1, 556($sp) +lw $t0, 1140($sp) +lw $t1, 552($sp) +sw $t1, 20($t0) +lw $t1, 552($sp) +sw $t1, 432($sp) +label_99: +lw $t1, 432($sp) +sw $t1, 392($sp) +b label_100 +label_95: +la $t1, void +sw $t1, 564($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 9 +sw $t1, 0($t0) +la $t1, E_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, E_methods +sw $t1, 12($t0) +sw $t0, 572($sp) +move $t0, $sp +lw $t1, 572($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal E_init +sw $a1, 576($sp) +lw $t0, 1140($sp) +lw $t1, 20($t0) +sw $t1, 1132($sp) +move $t0, $sp +lw $t1, 1132($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1132($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 580($sp) +move $t0, $sp +lw $t1, 580($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 572($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 572($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 44($t2) +jal $t3 +sw $a1, 568($sp) +lw $t1, 568($sp) +sw $t1, 564($sp) +lw $t0, 1140($sp) +lw $t1, 20($t0) +sw $t1, 1132($sp) +move $t0, $sp +lw $t1, 1132($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1132($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 608($sp) +move $t0, $sp +lw $t1, 564($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 564($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 632($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 636($sp) +li $t0, 8 +sw $t0, 640($sp) +move $t0, $sp +lw $t1, 640($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 636($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 644($sp) +lw $t0, 632($sp) +lw $t1, 16($t0) +sw $t1, 624($sp) +lw $t0, 636($sp) +lw $t1, 16($t0) +sw $t1, 628($sp) +lw $a0, 624($sp) +lw $t1, 628($sp) +mul $a0, $a0, $t1 +sw $a0, 620($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 616($sp) +move $t0, $sp +lw $t1, 620($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 616($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 648($sp) +lw $t0, 608($sp) +lw $t1, 16($t0) +sw $t1, 600($sp) +lw $t0, 616($sp) +lw $t1, 16($t0) +sw $t1, 604($sp) +lw $a0, 600($sp) +lw $t1, 604($sp) +sub $a0, $a0, $t1 +sw $a0, 596($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 592($sp) +move $t0, $sp +lw $t1, 596($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 592($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 652($sp) +lw $t1, 592($sp) +sw $t1, 656($sp) +la $t0, data_41 +sw $t0, 664($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 668($sp) +move $t0, $sp +lw $t1, 664($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 668($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 672($sp) +move $t0, $sp +lw $t1, 668($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 660($sp) +lw $t0, 1140($sp) +lw $t1, 20($t0) +sw $t1, 1132($sp) +move $t0, $sp +lw $t1, 1132($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 48($t2) +jal $t3 +sw $a1, 676($sp) +la $t0, data_54 +sw $t0, 688($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 692($sp) +move $t0, $sp +lw $t1, 688($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 692($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 696($sp) +move $t0, $sp +lw $t1, 692($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 684($sp) +move $t0, $sp +lw $t1, 564($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 48($t2) +jal $t3 +sw $a1, 700($sp) +la $t0, data_55 +sw $t0, 708($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 712($sp) +move $t0, $sp +lw $t1, 708($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 712($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 716($sp) +move $t0, $sp +lw $t1, 712($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 704($sp) +li $a0, 16 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 10 +sw $t1, 0($t0) +la $t1, A2I_name +sw $t1, 4($t0) +li $t1, 4 +sw $t1, 8($t0) +la $t1, A2I_methods +sw $t1, 12($t0) +sw $t0, 720($sp) +move $t0, $sp +lw $t1, 720($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal A2I_init +sw $a1, 724($sp) +lw $t1, 720($sp) +sw $t1, 728($sp) +move $t0, $sp +lw $t1, 656($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 728($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 728($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 28($t2) +jal $t3 +sw $a1, 736($sp) +move $t0, $sp +lw $t1, 736($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 732($sp) +la $t0, data_1 +sw $t0, 744($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 748($sp) +move $t0, $sp +lw $t1, 744($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 748($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 752($sp) +move $t0, $sp +lw $t1, 748($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 740($sp) +lw $t1, 740($sp) +sw $t1, 756($sp) +lw $t1, 756($sp) +sw $t1, 760($sp) +lw $t0, 1140($sp) +lw $t1, 564($sp) +sw $t1, 20($t0) +lw $t1, 564($sp) +sw $t1, 768($sp) +lw $t1, 768($sp) +sw $t1, 392($sp) +label_100: +lw $t1, 392($sp) +sw $t1, 352($sp) +b label_101 +label_94: +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 8 +sw $t1, 0($t0) +la $t1, D_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, D_methods +sw $t1, 12($t0) +sw $t0, 780($sp) +move $t0, $sp +lw $t1, 780($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal D_init +sw $a1, 784($sp) +lw $t0, 1140($sp) +lw $t1, 20($t0) +sw $t1, 1132($sp) +move $t0, $sp +lw $t1, 1132($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1132($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 788($sp) +move $t0, $sp +lw $t1, 788($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 780($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 780($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 40($t2) +jal $t3 +sw $a1, 776($sp) +lw $t0, 776($sp) +lw $a0, 16($t0) +bnez $a0, label_102 +la $t0, data_41 +sw $t0, 800($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 804($sp) +move $t0, $sp +lw $t1, 800($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 804($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 808($sp) +move $t0, $sp +lw $t1, 804($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 796($sp) +lw $t0, 1140($sp) +lw $t1, 20($t0) +sw $t1, 1132($sp) +move $t0, $sp +lw $t1, 1132($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 48($t2) +jal $t3 +sw $a1, 812($sp) +la $t0, data_56 +sw $t0, 824($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 828($sp) +move $t0, $sp +lw $t1, 824($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 828($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 832($sp) +move $t0, $sp +lw $t1, 828($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 820($sp) +lw $t1, 820($sp) +sw $t1, 772($sp) +b label_103 +label_102: +la $t0, data_41 +sw $t0, 840($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 844($sp) +move $t0, $sp +lw $t1, 840($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 844($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 848($sp) +move $t0, $sp +lw $t1, 844($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 836($sp) +lw $t0, 1140($sp) +lw $t1, 20($t0) +sw $t1, 1132($sp) +move $t0, $sp +lw $t1, 1132($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 48($t2) +jal $t3 +sw $a1, 852($sp) +la $t0, data_57 +sw $t0, 864($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 868($sp) +move $t0, $sp +lw $t1, 864($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 868($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 872($sp) +move $t0, $sp +lw $t1, 868($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 860($sp) +lw $t1, 860($sp) +sw $t1, 772($sp) +label_103: +lw $t1, 772($sp) +sw $t1, 352($sp) +label_101: +lw $t1, 352($sp) +sw $t1, 312($sp) +b label_104 +label_93: +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 7 +sw $t1, 0($t0) +la $t1, C_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, C_methods +sw $t1, 12($t0) +sw $t0, 880($sp) +move $t0, $sp +lw $t1, 880($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal C_init +sw $a1, 884($sp) +lw $t0, 1140($sp) +lw $t1, 20($t0) +sw $t1, 1132($sp) +move $t0, $sp +lw $t1, 1132($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1132($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 888($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 7 +sw $t1, 0($t0) +la $t1, C_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, C_methods +sw $t1, 12($t0) +sw $t0, 896($sp) +move $t0, $sp +lw $t1, 888($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 880($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 896($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 36($t2) +jal $t3 +sw $a1, 876($sp) +lw $t0, 1140($sp) +lw $t1, 876($sp) +sw $t1, 20($t0) +lw $t1, 876($sp) +sw $t1, 312($sp) +label_104: +lw $t1, 312($sp) +sw $t1, 272($sp) +b label_105 +label_92: +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 7 +sw $t1, 0($t0) +la $t1, C_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, C_methods +sw $t1, 12($t0) +sw $t0, 908($sp) +move $t0, $sp +lw $t1, 908($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal C_init +sw $a1, 912($sp) +lw $t0, 1140($sp) +lw $t1, 20($t0) +sw $t1, 1132($sp) +move $t0, $sp +lw $t1, 1132($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1132($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 916($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 6 +sw $t1, 0($t0) +la $t1, B_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, B_methods +sw $t1, 12($t0) +sw $t0, 924($sp) +move $t0, $sp +lw $t1, 916($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 908($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 924($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 36($t2) +jal $t3 +sw $a1, 904($sp) +lw $t0, 1140($sp) +lw $t1, 904($sp) +sw $t1, 20($t0) +lw $t1, 904($sp) +sw $t1, 272($sp) +label_105: +lw $t1, 272($sp) +sw $t1, 232($sp) +b label_106 +label_91: +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 7 +sw $t1, 0($t0) +la $t1, C_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, C_methods +sw $t1, 12($t0) +sw $t0, 936($sp) +move $t0, $sp +lw $t1, 936($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal C_init +sw $a1, 940($sp) +lw $t0, 1140($sp) +lw $t1, 20($t0) +sw $t1, 1132($sp) +move $t0, $sp +lw $t1, 1132($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1132($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 944($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 5 +sw $t1, 0($t0) +la $t1, A_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, A_methods +sw $t1, 12($t0) +sw $t0, 952($sp) +move $t0, $sp +lw $t1, 944($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 936($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 952($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 36($t2) +jal $t3 +sw $a1, 932($sp) +lw $t0, 1140($sp) +lw $t1, 932($sp) +sw $t1, 20($t0) +lw $t1, 932($sp) +sw $t1, 232($sp) +label_106: +lw $t1, 232($sp) +sw $t1, 192($sp) +b label_107 +label_90: +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 5 +sw $t1, 0($t0) +la $t1, A_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, A_methods +sw $t1, 12($t0) +sw $t0, 964($sp) +move $t0, $sp +lw $t1, 964($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal A_init +sw $a1, 968($sp) +move $t0, $sp +lw $t1, 1140($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 36($t2) +jal $t3 +sw $a1, 972($sp) +move $t0, $sp +lw $t1, 972($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 964($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 964($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 16($t2) +jal $t3 +sw $a1, 960($sp) +lw $t0, 1140($sp) +lw $t1, 960($sp) +sw $t1, 24($t0) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 8 +sw $t1, 0($t0) +la $t1, D_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, D_methods +sw $t1, 12($t0) +sw $t0, 984($sp) +move $t0, $sp +lw $t1, 984($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal D_init +sw $a1, 988($sp) +lw $t0, 1140($sp) +lw $t1, 24($t0) +sw $t1, 1124($sp) +move $t0, $sp +lw $t1, 1124($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1124($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 992($sp) +lw $t0, 1140($sp) +lw $t1, 20($t0) +sw $t1, 1132($sp) +move $t0, $sp +lw $t1, 1132($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1132($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 1000($sp) +move $t0, $sp +lw $t1, 992($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1000($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 984($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 984($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 32($t2) +jal $t3 +sw $a1, 980($sp) +lw $t0, 1140($sp) +lw $t1, 980($sp) +sw $t1, 20($t0) +lw $t1, 980($sp) +sw $t1, 192($sp) +label_107: +lw $t1, 192($sp) +sw $t1, 152($sp) +b label_108 +label_89: +lw $t0, 1140($sp) +lw $t1, 20($t0) +sw $t1, 1132($sp) +lw $t0, 1132($sp) +lw $t1, 0($t0) +la $a0, void +bne $t1 $a0 label_110 +b case_void_error +label_110: +blt $t1 7 label_111 +bgt $t1 7 label_111 +lw $t1, 1132($sp) +sw $t1, 1020($sp) +move $t0, $sp +lw $t1, 1020($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1020($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 1028($sp) +move $t0, $sp +lw $t1, 1028($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1020($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1020($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 40($t2) +jal $t3 +sw $a1, 1024($sp) +lw $t0, 1140($sp) +lw $t1, 1024($sp) +sw $t1, 20($t0) +lw $t1, 1024($sp) +sw $t1, 1012($sp) +b label_109 +label_111: +blt $t1 5 label_112 +bgt $t1 5 label_112 +lw $t1, 1132($sp) +sw $t1, 1036($sp) +move $t0, $sp +lw $t1, 1036($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1036($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 1044($sp) +move $t0, $sp +lw $t1, 1044($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1036($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1036($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 28($t2) +jal $t3 +sw $a1, 1040($sp) +lw $t0, 1140($sp) +lw $t1, 1040($sp) +sw $t1, 20($t0) +lw $t1, 1040($sp) +sw $t1, 1012($sp) +b label_109 +label_112: +blt $t1 0 label_113 +bgt $t1 11 label_113 +lw $t1, 1132($sp) +sw $t1, 1052($sp) +la $t0, data_39 +sw $t0, 1060($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 2 +sw $t1, 0($t0) +la $t1, String_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, String_methods +sw $t1, 12($t0) +sw $t0, 1064($sp) +move $t0, $sp +lw $t1, 1060($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1064($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal String_init +sw $a1, 1068($sp) +move $t0, $sp +lw $t1, 1064($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 1056($sp) +move $t0, $sp +lw $t1, 1140($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 0($t2) +jal $t3 +sw $a1, 1072($sp) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 4 +sw $t1, 0($t0) +la $t1, Int_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, Int_methods +sw $t1, 12($t0) +sw $t0, 1076($sp) +li $t0, 0 +sw $t0, 1080($sp) +move $t0, $sp +lw $t1, 1080($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1076($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal Int_init +sw $a1, 1084($sp) +lw $t1, 1076($sp) +sw $t1, 1012($sp) +b label_109 +label_113: +b case_no_match_error +label_109: +lw $t1, 1012($sp) +sw $t1, 152($sp) +label_108: +lw $t1, 152($sp) +sw $t1, 112($sp) +b label_114 +label_88: +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 5 +sw $t1, 0($t0) +la $t1, A_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, A_methods +sw $t1, 12($t0) +sw $t0, 1092($sp) +move $t0, $sp +lw $t1, 1092($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal A_init +sw $a1, 1096($sp) +move $t0, $sp +lw $t1, 1140($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1140($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 36($t2) +jal $t3 +sw $a1, 1100($sp) +move $t0, $sp +lw $t1, 1100($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1092($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1092($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 16($t2) +jal $t3 +sw $a1, 1088($sp) +lw $t0, 1140($sp) +lw $t1, 1088($sp) +sw $t1, 24($t0) +li $a0, 20 +li $v0, 9 +syscall +bge $v0, $sp heap_error +move $t0, $v0 +li $t1, 6 +sw $t1, 0($t0) +la $t1, B_name +sw $t1, 4($t0) +li $t1, 5 +sw $t1, 8($t0) +la $t1, B_methods +sw $t1, 12($t0) +sw $t0, 1112($sp) +move $t0, $sp +lw $t1, 1112($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +jal B_init +sw $a1, 1116($sp) +lw $t0, 1140($sp) +lw $t1, 24($t0) +sw $t1, 1124($sp) +move $t0, $sp +lw $t1, 1124($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1124($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 1120($sp) +lw $t0, 1140($sp) +lw $t1, 20($t0) +sw $t1, 1132($sp) +move $t0, $sp +lw $t1, 1132($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1132($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 12($t2) +jal $t3 +sw $a1, 1128($sp) +move $t0, $sp +lw $t1, 1120($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1128($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1112($t0) +addi $sp, $sp, -4 +sw $t1, 0($sp) +lw $t1, 1112($t0) +la $t0, void +beq $t1, $t0, dispatch_void_error +lw $t2, 12($t1) +lw $t3, 24($t2) +jal $t3 +sw $a1, 1108($sp) +lw $t0, 1140($sp) +lw $t1, 1108($sp) +sw $t1, 20($t0) +lw $t1, 1108($sp) +sw $t1, 112($sp) +label_114: +b label_83 +label_85: +lw $a1, 16($sp) lw $ra, 0($sp) -addi $sp, $sp, 184 +addi $sp, $sp, 1144 jr $ra \ No newline at end of file diff --git a/src/main.py b/src/main.py index 2119e068b..6afdcc308 100644 --- a/src/main.py +++ b/src/main.py @@ -79,7 +79,7 @@ def main(_input, _output): # ast, errors, context, scope = SemanticAn if __name__ == "__main__": - in_path = '/home/cwjki/Projects/cool-compiler-2021/tests/codegen/fib.cl' + in_path = '/home/cwjki/Projects/cool-compiler-2021/tests/codegen/arith.cl' out_path = '/home/cwjki/Projects/cool-compiler-2021/src/codeMips.mips' _input = sys.argv[1] if len(sys.argv) > 1 else in_path _output = sys.argv[2] if len(sys.argv) > 2 else out_path diff --git a/src/semantic/semantic.py b/src/semantic/semantic.py index 47121ea59..0c79d518d 100644 --- a/src/semantic/semantic.py +++ b/src/semantic/semantic.py @@ -371,10 +371,10 @@ def create_type(self, name, pos): if not self.graph.__contains__(name): self.graph[name] = [] - if self.graph.__contains__(parentName): - self.graph[parentName].append(name) + if self.graph.__contains__(typex.parent): + self.graph[typex.parent].append(name) else: - self.graph[parentName] = [name] + self.graph[typex.parent] = [name] return typex def get_type(self, name: str, pos=None): From 885ab899a40177b29a090323d0a7dfbc7b6fca36 Mon Sep 17 00:00:00 2001 From: cwjki Date: Thu, 24 Feb 2022 13:04:04 -0500 Subject: [PATCH 185/194] no funciono lo anterior --- src/main.py | 2 +- src/semantic/semantic.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.py b/src/main.py index 6afdcc308..6128f8c2d 100644 --- a/src/main.py +++ b/src/main.py @@ -79,7 +79,7 @@ def main(_input, _output): # ast, errors, context, scope = SemanticAn if __name__ == "__main__": - in_path = '/home/cwjki/Projects/cool-compiler-2021/tests/codegen/arith.cl' + in_path = '/home/cwjki/Projects/cool-compiler-2021/tests/semantic/arithmetic1.cl' out_path = '/home/cwjki/Projects/cool-compiler-2021/src/codeMips.mips' _input = sys.argv[1] if len(sys.argv) > 1 else in_path _output = sys.argv[2] if len(sys.argv) > 2 else out_path diff --git a/src/semantic/semantic.py b/src/semantic/semantic.py index 0c79d518d..47121ea59 100644 --- a/src/semantic/semantic.py +++ b/src/semantic/semantic.py @@ -371,10 +371,10 @@ def create_type(self, name, pos): if not self.graph.__contains__(name): self.graph[name] = [] - if self.graph.__contains__(typex.parent): - self.graph[typex.parent].append(name) + if self.graph.__contains__(parentName): + self.graph[parentName].append(name) else: - self.graph[typex.parent] = [name] + self.graph[parentName] = [name] return typex def get_type(self, name: str, pos=None): From 6f2e89a4d9e7e150c796be75ac0c1349c387a314 Mon Sep 17 00:00:00 2001 From: cwjki Date: Thu, 24 Feb 2022 13:26:10 -0500 Subject: [PATCH 186/194] fixing a typo with self type --- src/code_generator/BaseCoolToCilVisitor.py | 6 ++++++ src/code_generator/COOLToCILVisitor.py | 2 +- src/main.py | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/code_generator/BaseCoolToCilVisitor.py b/src/code_generator/BaseCoolToCilVisitor.py index ff35eec02..05d168978 100644 --- a/src/code_generator/BaseCoolToCilVisitor.py +++ b/src/code_generator/BaseCoolToCilVisitor.py @@ -13,6 +13,12 @@ def __init__(self, context): self.context = context self.context.set_type_tags() self.context.set_type_max_tags() + + # print("Context") + # print(self.context) + # print("GRAPH") + # print(self.context.graph) + self.label_count = 0 diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index 1152b4500..c29ebe369 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -642,7 +642,7 @@ def visit(self, node, scope): result_local = self.define_internal_local(scope=scope, name="result") result_init = self.define_internal_local(scope=scope, name="init") - if node.id == "SELF_TYPE": + if node.id == "Self": self.register_instruction(cil.AllocateNode( self.current_type.name, self.current_type.tag, result_local)) self.register_instruction(cil.CallNode(result_init, f'{self.current_type.name}_init', [ diff --git a/src/main.py b/src/main.py index 6128f8c2d..6afdcc308 100644 --- a/src/main.py +++ b/src/main.py @@ -79,7 +79,7 @@ def main(_input, _output): # ast, errors, context, scope = SemanticAn if __name__ == "__main__": - in_path = '/home/cwjki/Projects/cool-compiler-2021/tests/semantic/arithmetic1.cl' + in_path = '/home/cwjki/Projects/cool-compiler-2021/tests/codegen/arith.cl' out_path = '/home/cwjki/Projects/cool-compiler-2021/src/codeMips.mips' _input = sys.argv[1] if len(sys.argv) > 1 else in_path _output = sys.argv[2] if len(sys.argv) > 2 else out_path From 32bef4f46c932383b8e761b8b14bf648552b6176 Mon Sep 17 00:00:00 2001 From: cwjki Date: Thu, 24 Feb 2022 13:59:25 -0500 Subject: [PATCH 187/194] fixing the case graph --- src/codeMips.mips | 20 ++++++++++---------- src/code_generator/BaseCoolToCilVisitor.py | 1 + src/code_generator/COOLToCILVisitor.py | 2 +- src/semantic/semantic.py | 20 ++++++++++++++------ 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/codeMips.mips b/src/codeMips.mips index 75c3fee8b..d98e21e02 100644 --- a/src/codeMips.mips +++ b/src/codeMips.mips @@ -257,7 +257,7 @@ li $v0, 9 syscall bge $v0, $sp heap_error move $t0, $v0 -li $t1, 11 +li $t1, 2 sw $t1, 0($t0) la $t1, Main_name sw $t1, 4($t0) @@ -7143,7 +7143,7 @@ li $v0, 9 syscall bge $v0, $sp heap_error move $t0, $v0 -li $t1, 10 +li $t1, 6 sw $t1, 0($t0) la $t1, A2I_name sw $t1, 4($t0) @@ -7634,7 +7634,7 @@ sw $t1, 4($sp) b label_75 label_77: blt $t1 8 label_78 -bgt $t1 8 label_78 +bgt $t1 9 label_78 lw $t1, 132($sp) sw $t1, 28($sp) la $t0, data_35 @@ -7728,7 +7728,7 @@ sw $t1, 4($sp) b label_75 label_79: blt $t1 6 label_80 -bgt $t1 6 label_80 +bgt $t1 9 label_80 lw $t1, 132($sp) sw $t1, 68($sp) la $t0, data_37 @@ -7775,7 +7775,7 @@ sw $t1, 4($sp) b label_75 label_80: blt $t1 5 label_81 -bgt $t1 5 label_81 +bgt $t1 9 label_81 lw $t1, 132($sp) sw $t1, 88($sp) la $t0, data_38 @@ -7822,7 +7822,7 @@ sw $t1, 4($sp) b label_75 label_81: blt $t1 0 label_82 -bgt $t1 11 label_82 +bgt $t1 9 label_82 lw $t1, 132($sp) sw $t1, 108($sp) la $t0, data_39 @@ -7883,7 +7883,7 @@ li $v0, 9 syscall bge $v0, $sp heap_error move $t0, $v0 -li $t1, 10 +li $t1, 6 sw $t1, 0($t0) la $t1, A2I_name sw $t1, 4($t0) @@ -9296,7 +9296,7 @@ li $v0, 9 syscall bge $v0, $sp heap_error move $t0, $v0 -li $t1, 10 +li $t1, 6 sw $t1, 0($t0) la $t1, A2I_name sw $t1, 4($t0) @@ -10036,7 +10036,7 @@ sw $t1, 1012($sp) b label_109 label_111: blt $t1 5 label_112 -bgt $t1 5 label_112 +bgt $t1 9 label_112 lw $t1, 1132($sp) sw $t1, 1036($sp) move $t0, $sp @@ -10072,7 +10072,7 @@ sw $t1, 1012($sp) b label_109 label_112: blt $t1 0 label_113 -bgt $t1 11 label_113 +bgt $t1 9 label_113 lw $t1, 1132($sp) sw $t1, 1052($sp) la $t0, data_39 diff --git a/src/code_generator/BaseCoolToCilVisitor.py b/src/code_generator/BaseCoolToCilVisitor.py index 05d168978..9c19f311e 100644 --- a/src/code_generator/BaseCoolToCilVisitor.py +++ b/src/code_generator/BaseCoolToCilVisitor.py @@ -11,6 +11,7 @@ def __init__(self, context): self.current_method = None self.current_function = None self.context = context + self.context.update_graph() self.context.set_type_tags() self.context.set_type_max_tags() diff --git a/src/code_generator/COOLToCILVisitor.py b/src/code_generator/COOLToCILVisitor.py index c29ebe369..1152b4500 100644 --- a/src/code_generator/COOLToCILVisitor.py +++ b/src/code_generator/COOLToCILVisitor.py @@ -642,7 +642,7 @@ def visit(self, node, scope): result_local = self.define_internal_local(scope=scope, name="result") result_init = self.define_internal_local(scope=scope, name="init") - if node.id == "Self": + if node.id == "SELF_TYPE": self.register_instruction(cil.AllocateNode( self.current_type.name, self.current_type.tag, result_local)) self.register_instruction(cil.CallNode(result_init, f'{self.current_type.name}_init', [ diff --git a/src/semantic/semantic.py b/src/semantic/semantic.py index 47121ea59..335f31ec5 100644 --- a/src/semantic/semantic.py +++ b/src/semantic/semantic.py @@ -1,3 +1,4 @@ +from unicodedata import name from utils.errors import SemanticError from collections import OrderedDict import itertools as itt @@ -230,7 +231,7 @@ def __ne__(self, other): class SelfType(Type): def __init__(self, pos=(0, 0)): - self.name = 'Self' + self.name = 'SELF_TYPE' self.attributes = {} self.methods = {} self.parent = None @@ -361,12 +362,12 @@ def create_graph(self): self.graph['Int'] = [] self.graph['Bool'] = [] - def create_type(self, name, pos): - if name in self.types: - error_text = 'Classes may not be redefined.' - raise SemanticError(error_text, *pos) - typex = self.types[name] = Type(name, pos) + def update_graph(self): + for tname, _ in self.types.items(): + if not tname in ['Object', 'IO', 'String', 'Bool', 'Int', 'SELF_TYPE']: + self._update_graph(tname) + def _update_graph(self, name): parentName = self.types[name].parent.name if not self.graph.__contains__(name): @@ -375,6 +376,13 @@ def create_type(self, name, pos): self.graph[parentName].append(name) else: self.graph[parentName] = [name] + + def create_type(self, name, pos): + if name in self.types: + error_text = 'Classes may not be redefined.' + raise SemanticError(error_text, *pos) + typex = self.types[name] = Type(name, pos) + return typex def get_type(self, name: str, pos=None): From 5cc9ff3a384ff26b4fb1ddcbf5c74521b07aab78 Mon Sep 17 00:00:00 2001 From: cwjki Date: Thu, 24 Feb 2022 14:28:52 -0500 Subject: [PATCH 188/194] have a problem printing string --- src/semantic/semantic.py | 44 ++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/semantic/semantic.py b/src/semantic/semantic.py index 335f31ec5..5ad002dc8 100644 --- a/src/semantic/semantic.py +++ b/src/semantic/semantic.py @@ -442,28 +442,28 @@ def __init__(self, parent=None): def __len__(self): return len(self.locals) - def __str__(self): - res = '' - for scope in self.children: - try: - classx = scope.locals[0] - name = classx.type.name - except: - name = '1' - # '\n\t' + ('\n' + '\t').join(str(local) for local in scope.locals) + '\n' - res += name + scope.tab_level(1, '', 1) - return res - - def tab_level(self, tabs, name, num) -> str: - res = ('\t' * tabs) + ('\n' + ('\t' * tabs)).join(str(local) - for local in self.locals) - if self.functions: - children = '\n'.join(v.tab_level( - tabs + 1, '[method] ' + k, num) for k, v in self.functions.items()) - else: - children = '\n'.join(child.tab_level( - tabs + 1, num, num + 1) for child in self.children) - return "\t" * (tabs-1) + f'{name}' + "\t" * tabs + f'\n{res}\n{children}' + # def __str__(self): + # res = '' + # for scope in self.children: + # try: + # classx = scope.locals[0] + # name = classx.type.name + # except: + # name = '1' + # # '\n\t' + ('\n' + '\t').join(str(local) for local in scope.locals) + '\n' + # res += name + scope.tab_level(1, '', 1) + # return res + + # def tab_level(self, tabs, name, num) -> str: + # res = ('\t' * tabs) + ('\n' + ('\t' * tabs)).join(str(local) + # for local in self.locals) + # if self.functions: + # children = '\n'.join(v.tab_level( + # tabs + 1, '[method] ' + k, num) for k, v in self.functions.items()) + # else: + # children = '\n'.join(child.tab_level( + # tabs + 1, num, num + 1) for child in self.children) + # return "\t" * (tabs-1) + f'{name}' + "\t" * tabs + f'\n{res}\n{children}' def __repr__(self): return str(self) From 9667b1c74dd47da1d9a4d3fa3246cca6ff1dc100 Mon Sep 17 00:00:00 2001 From: cwjki Date: Thu, 24 Feb 2022 14:34:05 -0500 Subject: [PATCH 189/194] retest --- src/lexer/lexer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lexer/lexer.py b/src/lexer/lexer.py index b3635f544..68ab32cda 100644 --- a/src/lexer/lexer.py +++ b/src/lexer/lexer.py @@ -131,7 +131,7 @@ def t_strings_eof(self, t): self.errors.append(LexicographicError( 'EOF in string constant', t.lineno, t.column)) - t_ignore = ' \t\f\r\t\v' + t_ignore = ' \t\f\r\v' def compute_column(self, t): t.column = t.lexpos - t.lexer.linestart + 1 From 1782916a50a415a8ded4771e552868f56e40a9a5 Mon Sep 17 00:00:00 2001 From: cwjki Date: Thu, 24 Feb 2022 14:42:00 -0500 Subject: [PATCH 190/194] printing a \t de mas --- src/lexer/lexer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lexer/lexer.py b/src/lexer/lexer.py index 68ab32cda..496f72f64 100644 --- a/src/lexer/lexer.py +++ b/src/lexer/lexer.py @@ -56,7 +56,7 @@ def t_comments_eof(self, t): self.errors.append(LexicographicError( "EOF in comment", t.lineno, t.column)) - t_comments_ignore = ' \t\f\r\v' + t_comments_ignore = ' \t\f\r\t\v' # Strings t_strings_ignore = '' @@ -131,7 +131,7 @@ def t_strings_eof(self, t): self.errors.append(LexicographicError( 'EOF in string constant', t.lineno, t.column)) - t_ignore = ' \t\f\r\v' + t_ignore = ' \t\f\r\t\v' def compute_column(self, t): t.column = t.lexpos - t.lexer.linestart + 1 From 65fd7019793f291ccfed2662b108c27b615c0ce9 Mon Sep 17 00:00:00 2001 From: cwjki Date: Thu, 24 Feb 2022 15:36:47 -0500 Subject: [PATCH 191/194] fix the f /t problem, hope all test pass --- src/codeMips.mips | 20 +-- src/code_generator/formatter.py | 216 ++++++++++++++++---------------- src/lexer/lexer.py | 2 +- 3 files changed, 119 insertions(+), 119 deletions(-) diff --git a/src/codeMips.mips b/src/codeMips.mips index d98e21e02..b9183590d 100644 --- a/src/codeMips.mips +++ b/src/codeMips.mips @@ -147,33 +147,33 @@ data_12: .asciiz "9" data_13: .asciiz "-" data_14: .asciiz "+" data_15: .asciiz " - tTo add a number to " + To add a number to " data_16: .asciiz "...enter a: " -data_17: .asciiz " tTo negate " +data_17: .asciiz " To negate " data_18: .asciiz "...enter b: " -data_19: .asciiz " tTo find the difference between " +data_19: .asciiz " To find the difference between " data_20: .asciiz "and another number...enter c: " -data_21: .asciiz " tTo find the factorial of " +data_21: .asciiz " To find the factorial of " data_22: .asciiz "...enter d: " -data_23: .asciiz " tTo square " +data_23: .asciiz " To square " data_24: .asciiz "...enter e: " -data_25: .asciiz " tTo cube " +data_25: .asciiz " To cube " data_26: .asciiz "...enter f: " -data_27: .asciiz " tTo find out if " +data_27: .asciiz " To find out if " data_28: .asciiz "is a multiple of 3...enter g: " -data_29: .asciiz " tTo divide " +data_29: .asciiz " To divide " data_30: .asciiz "by 8...enter h: " -data_31: .asciiz " tTo get a new number...enter j: +data_31: .asciiz " To get a new number...enter j: " -data_32: .asciiz " tTo quit...enter q: +data_32: .asciiz " To quit...enter q: " data_33: .asciiz "Please enter a number... " diff --git a/src/code_generator/formatter.py b/src/code_generator/formatter.py index 9b615139d..467ee5239 100644 --- a/src/code_generator/formatter.py +++ b/src/code_generator/formatter.py @@ -1,145 +1,145 @@ -def get_formatter(): +# def get_formatter(): - class PrintVisitor(object): - @visitor.on('node') - def visit(self, node): - pass +# class PrintVisitor(object): +# @visitor.on('node') +# def visit(self, node): +# pass - @visitor.when(Program) - def visit(self, node): - dottypes = '\n'.join(self.visit(t) for t in node.dottypes.values()) - dotdata = '\n'.join(f'{t}: {node.dotdata[t]}' for t in node.dotdata.keys()) - dotcode = '\n'.join(self.visit(t) for t in node.dotcode) +# @visitor.when(Program) +# def visit(self, node): +# dottypes = '\n'.join(self.visit(t) for t in node.dottypes.values()) +# dotdata = '\n'.join(f'{t}: {node.dotdata[t]}' for t in node.dotdata.keys()) +# dotcode = '\n'.join(self.visit(t) for t in node.dotcode) - return f'.TYPES\n{dottypes}\n\n.DATA\n{dotdata}\n\n.CODE\n{dotcode}' +# return f'.TYPES\n{dottypes}\n\n.DATA\n{dotdata}\n\n.CODE\n{dotcode}' - @visitor.when(Type) - def visit(self, node): - attributes = '\n\t'.join(f'attribute {x}' for x in node.attributes) - methods = '\n\t'.join(f'method {x} : {node.methods[x]}' for x in node.methods.keys()) +# @visitor.when(Type) +# def visit(self, node): +# attributes = '\n\t'.join(f'attribute {x}' for x in node.attributes) +# methods = '\n\t'.join(f'method {x} : {node.methods[x]}' for x in node.methods.keys()) - return f'type {node.name} {{\n\t{attributes}\n\n\t{methods}\n}}' +# return f'type {node.name} {{\n\t{attributes}\n\n\t{methods}\n}}' - @visitor.when(Function) - def visit(self, node): - params = '\n\t'.join(self.visit(x) for x in node.params) - localvars = '\n\t'.join(self.visit(x) for x in node.localvars) - instructions = '\n\t'.join(self.visit(x) for x in node.instructions) +# @visitor.when(Function) +# def visit(self, node): +# params = '\n\t'.join(self.visit(x) for x in node.params) +# localvars = '\n\t'.join(self.visit(x) for x in node.localvars) +# instructions = '\n\t'.join(self.visit(x) for x in node.instructions) - return f'function {node.name} {{\n\t{params}\n\n\t{localvars}\n\n\t{instructions}\n}}' +# return f'function {node.name} {{\n\t{params}\n\n\t{localvars}\n\n\t{instructions}\n}}' - @visitor.when(ParamDec) - def visit(self, node): - return f'PARAM {node.name}' +# @visitor.when(ParamDec) +# def visit(self, node): +# return f'PARAM {node.name}' - @visitor.when(LocalDec) - def visit(self, node): - return f'LOCAL {node.name}' +# @visitor.when(LocalDec) +# def visit(self, node): +# return f'LOCAL {node.name}' - @visitor.when(Assign) - def visit(self, node): - return f'{node.local_dest} = {node.right_expr}' +# @visitor.when(Assign) +# def visit(self, node): +# return f'{node.local_dest} = {node.right_expr}' - @visitor.when(IfGoto) - def visit(self, node): - return f'IF {node.variable} GOTO {node.label}' +# @visitor.when(IfGoto) +# def visit(self, node): +# return f'IF {node.variable} GOTO {node.label}' - @visitor.when(Label) - def visit(self, node): - return f'LABEL {node.label}' +# @visitor.when(Label) +# def visit(self, node): +# return f'LABEL {node.label}' - @visitor.when(Goto) - def visit(self, node): - return f'GOTO {node.label}' +# @visitor.when(Goto) +# def visit(self, node): +# return f'GOTO {node.label}' - @visitor.when(UnaryOperator) - def visit(self, node): - return f'{node.local_dest} = {node.op} {node.expr_value}' +# @visitor.when(UnaryOperator) +# def visit(self, node): +# return f'{node.local_dest} = {node.op} {node.expr_value}' - @visitor.when(BinaryOperator) - def visit(self, node): - return f'{node.local_dest} = {node.left} {node.op} {node.right}' +# @visitor.when(BinaryOperator) +# def visit(self, node): +# return f'{node.local_dest} = {node.left} {node.op} {node.right}' - @visitor.when(Allocate) - def visit(self, node): - return f'{node.local_dest} = ALLOCATE {node.type}' +# @visitor.when(Allocate) +# def visit(self, node): +# return f'{node.local_dest} = ALLOCATE {node.type}' - @visitor.when(LoadStr) - def visit(self, node): - return f'{node.local_dest} = LOAD {node.msg}' +# @visitor.when(LoadStr) +# def visit(self, node): +# return f'{node.local_dest} = LOAD {node.msg}' - @visitor.when(LoadInt) - def visit(self, node): - return f'{node.local_dest} = LOAD {node.num}' +# @visitor.when(LoadInt) +# def visit(self, node): +# return f'{node.local_dest} = LOAD {node.num}' - @visitor.when(LoadVoid) - def visit(self, node): - return f'{node.local_dest} = LOAD VOID' +# @visitor.when(LoadVoid) +# def visit(self, node): +# return f'{node.local_dest} = LOAD VOID' - @visitor.when(GetAttr) - def visit(self, node): - return f'{node.local_dest} = GetAttr {node.instance} {node.attr} ' +# @visitor.when(GetAttr) +# def visit(self, node): +# return f'{node.local_dest} = GetAttr {node.instance} {node.attr} ' - @visitor.when(SetAttr) - def visit(self, node): - return f'SetAttr {node.instance} {node.attr} {node.value}' +# @visitor.when(SetAttr) +# def visit(self, node): +# return f'SetAttr {node.instance} {node.attr} {node.value}' - @visitor.when(TypeOf) - def visit(self, node): - return f'{node.local_dest} = TYPEOF {node.variable}' +# @visitor.when(TypeOf) +# def visit(self, node): +# return f'{node.local_dest} = TYPEOF {node.variable}' - @visitor.when(Call) - def visit(self, node): - return f'{node.local_dest} = CALL {node.function}' +# @visitor.when(Call) +# def visit(self, node): +# return f'{node.local_dest} = CALL {node.function}' - @visitor.when(VCall) - def visit(self, node): - return f'{node.local_dest} = VCALL {node.dynamic_type} {node.function} ' +# @visitor.when(VCall) +# def visit(self, node): +# return f'{node.local_dest} = VCALL {node.dynamic_type} {node.function} ' - @visitor.when(Arg) - def visit(self, node): - return f'ARG {node.arg}' +# @visitor.when(Arg) +# def visit(self, node): +# return f'ARG {node.arg}' - @visitor.when(Return) - def visit(self, node): - return f'\n RETURN {node.value if node.value is not None else ""}' +# @visitor.when(Return) +# def visit(self, node): +# return f'\n RETURN {node.value if node.value is not None else ""}' - @visitor.when(IsVoid) - def visit(self, node): - return f'{node.result_local} ISVOID {node.expre_value}' +# @visitor.when(IsVoid) +# def visit(self, node): +# return f'{node.result_local} ISVOID {node.expre_value}' - @visitor.when(Halt) - def visit(self, node): - return 'HALT' +# @visitor.when(Halt) +# def visit(self, node): +# return 'HALT' - @visitor.when(Copy) - def visit(self, node): - return f'{node.local_dest} = COPY {node.type}' +# @visitor.when(Copy) +# def visit(self, node): +# return f'{node.local_dest} = COPY {node.type}' - @visitor.when(Length) - def visit(self, node): - return f'{node.result} = LENGTH {node.variable}' +# @visitor.when(Length) +# def visit(self, node): +# return f'{node.result} = LENGTH {node.variable}' - @visitor.when(Concat) - def visit(self, node): - return f'{node.result} = CONCAT {node.str1} {node.str2}' +# @visitor.when(Concat) +# def visit(self, node): +# return f'{node.result} = CONCAT {node.str1} {node.str2}' - @visitor.when(SubStr) - def visit(self, node): - return f'{node.result} = SUBSTR {node.i} {node.length} {node.string}' +# @visitor.when(SubStr) +# def visit(self, node): +# return f'{node.result} = SUBSTR {node.i} {node.length} {node.string}' - @visitor.when(StringEquals) - def visit(self, node): - return f'{node.result} = {node.s1} = {node.s2}' +# @visitor.when(StringEquals) +# def visit(self, node): +# return f'{node.result} = {node.s1} = {node.s2}' - @visitor.when(Read) - def visit(self, node): - return f'{node.result} = READ' +# @visitor.when(Read) +# def visit(self, node): +# return f'{node.result} = READ' - @visitor.when(Print) - def visit(self, node): - return f'PRINT {node.variable}' +# @visitor.when(Print) +# def visit(self, node): +# return f'PRINT {node.variable}' - printer = PrintVisitor() - return (lambda ast: printer.visit(ast)) +# printer = PrintVisitor() +# return (lambda ast: printer.visit(ast)) diff --git a/src/lexer/lexer.py b/src/lexer/lexer.py index 496f72f64..bb626369e 100644 --- a/src/lexer/lexer.py +++ b/src/lexer/lexer.py @@ -107,7 +107,7 @@ def t_strings_consume(self, t): t.lexer.string += '\b' elif t.value == 't': t.lexer.string += '\t' - if t.value == 'f': + elif t.value == 'f': t.lexer.string += '\f' elif t.value == 'n': t.lexer.string += '\n' From 45da2b08b011a427fb00c246af9396a41a37918d Mon Sep 17 00:00:00 2001 From: cwjki Date: Thu, 24 Feb 2022 15:56:03 -0500 Subject: [PATCH 192/194] ALL TEST PASSED, deleting some comments and useless imports --- src/code_generator/BaseCoolToCilVisitor.py | 8 -- src/code_generator/cil_visual_visitor.py | 154 --------------------- src/code_generator/formatter.py | 145 ------------------- src/cparser/parser.py | 17 +-- src/main.py | 21 --- src/semantic/semantic.py | 24 ---- src/semantic/visitors/typeChecker.py | 1 - 7 files changed, 1 insertion(+), 369 deletions(-) delete mode 100644 src/code_generator/cil_visual_visitor.py delete mode 100644 src/code_generator/formatter.py diff --git a/src/code_generator/BaseCoolToCilVisitor.py b/src/code_generator/BaseCoolToCilVisitor.py index 9c19f311e..206b006c5 100644 --- a/src/code_generator/BaseCoolToCilVisitor.py +++ b/src/code_generator/BaseCoolToCilVisitor.py @@ -14,15 +14,8 @@ def __init__(self, context): self.context.update_graph() self.context.set_type_tags() self.context.set_type_max_tags() - - # print("Context") - # print(self.context) - # print("GRAPH") - # print(self.context.graph) - self.label_count = 0 - @property def params(self): return self.current_function.params @@ -71,7 +64,6 @@ def define_internal_local(self, scope, name="internal", cool_var=None, class_typ def register_instruction(self, instruction): self.instructions.append(instruction) return instruction - ############################### def to_function_name(self, method_name, type_name): return f'{type_name}.{method_name}' diff --git a/src/code_generator/cil_visual_visitor.py b/src/code_generator/cil_visual_visitor.py deleted file mode 100644 index aa549564a..000000000 --- a/src/code_generator/cil_visual_visitor.py +++ /dev/null @@ -1,154 +0,0 @@ -from utils import visitor -from cil_ast import * - -def get_formatter(): - class PrintVisitor(object): - @visitor.on('node') - def visit(self, node): - pass - - @visitor.when(ProgramNode) - def visit(self, node): - dottypes = '\n'.join(self.visit(t) for t in node.dottypes) - dotdata = '\n'.join(self.visit(t) for t in node.dotdata) - dotcode = '\n'.join(self.visit(t) for t in node.dotcode) - return f'.TYPES\n{dottypes}\n\n.DATA\n{dotdata}\n\n.CODE\n{dotcode}' - - #.TYPE - @visitor.when(TypeNode) - def visit(self, node): - attributes = '\n\t'.join(f'attribute {x}: {y}' for x, y in node.attributes) - methods = '\n\t'.join(f'method {x}: {y}' for x, y in node.methods) - - return f'type {node.name} {{\n\t{attributes}\n\n\t{methods}\n}}' - - #.DATA - @visitor.when(DataNode) - def visit(self, node): - return f'{node.name} = "{node.value}"' - - #.CODE - @visitor.when(FunctionNode) - def visit(self, node): - params = '\n\t'.join(self.visit(x) for x in node.params) - localvars = '\n\t'.join(self.visit(x) for x in node.localvars) - instructions = '\n\t'.join(self.visit(x) for x in node.instructions) - return f'function {node.name} {{\n\t{params}\n\n\t{localvars}\n\n\t{instructions}\n}}' - #InstructionNode - @visitor.when(ParamNode) - def visit(self, node): - return f'PARAM {node.name}' - - @visitor.when(LocalNode) - def visit(self, node): - return f'LOCAL {node.name}' - - @visitor.when(AssignNode) - def visit(self, node): - return f'{node.dest} = {node.source}' - #ArithNode - @visitor.when(PlusNode) - def visit(self, node): - return f'{node.dest} = {node.left} + {node.right}' - - @visitor.when(MinusNode) - def visit(self, node): - return f'{node.dest} = {node.left} - {node.right}' - - @visitor.when(StarNode) - def visit(self, node): - return f'{node.dest} = {node.left} * {node.right}' - - @visitor.when(DivNode) - def visit(self, node): - return f'{node.dest} = {node.left} / {node.right}' - - @visitor.when(LessNode) - def visit(self, node): - return f'{node.dest} = {node.left} < {node.right}' - - @visitor.when(LessEqualNode) - def visit(self, node): - return f'{node.dest} = {node.left} <= {node.right}' - - @visitor.when(EqualNode) - def visit(self, node): - return f'{node.dest} = {node.left} = {node.right}' - - @visitor.when(NotNode) - def visit(self, node): - return f'{node.dest} = NOT {node.expr}' - #Attr - @visitor.when(GetAttrNode) - def visit(self, node): - return f'{node.dest} = GETATTR {node.obj} {node.attr}' - - @visitor.when(SetAttrNode) - def visit(self, node): - return f'SETATTR {node.obj} {node.attr} = {node.value}' - #Memory - @visitor.when(AllocateNode) - def visit(self, node): - return f'{node.dest} = ALLOCATE {node.type}' - - @visitor.when(TypeOfNode) - def visit(self, node): - return f'{node.dest} = TYPEOF {node.obj}' - #Jumps - @visitor.when(LabelNode) - def visit(self, node): - return f'LABEL {node.label}' - - @visitor.when(GoToNode) - def visit(self, node): - return f'GOTO {node.label}' - - @visitor.when(IfGoToNode) - def visit(self, node): - return f'IF {node.cond} GOTO {node.label}' - #Static Invocation - @visitor.when(CallNode) - def visit(self, node): - args = '\n\t'.join(self.visit(arg) for arg in node.args) - return f'{args}\n' + f'\t{node.dest} = CALL {node.function}' - #Dynamic Invocation - @visitor.when(VCallNode) - def visit(self, node): - args = '\n\t'.join(self.visit(arg) for arg in node.args) - return f'{args}\n' + f'\t{node.dest} = VCALL {node.type} {node.method}' - #Args - @visitor.when(ArgNode) - def visit(self, node): - return f'ARG {node.dest}' - #Return - @visitor.when(ReturnNode) - def visit(self, node): - return f'RETURN {node.value if node.value is not None else ""}' - #IO - @visitor.when(LoadNode) - def visit(self, node): - return f'{node.dest} = LOAD {node.msg}' - - @visitor.when(LengthNode) - def visit(self, node): - return f'{node.dest} = LENGTH {node.arg}' - - @visitor.when(ConcatNode) - def visit(self, node): - return f'{node.dest} = CONCAT {node.arg1} {node.arg2}' - - @visitor.when(SubstringNode) - def visit(self, node): - return f'{node.dest} = SUBSTRING {node.word} {node.begin} {node.end}' - - @visitor.when(StrNode) - def visit(self, node): - return f'{node.dest} = STR {node.ivalue}' - - @visitor.when(ReadNode) - def visit(self, node): - return f'{node.dest} = READ_STR' - - printer = PrintVisitor() - return lambda ast: printer.visit(ast) - \ No newline at end of file diff --git a/src/code_generator/formatter.py b/src/code_generator/formatter.py deleted file mode 100644 index 467ee5239..000000000 --- a/src/code_generator/formatter.py +++ /dev/null @@ -1,145 +0,0 @@ -# def get_formatter(): - -# class PrintVisitor(object): -# @visitor.on('node') -# def visit(self, node): -# pass - -# @visitor.when(Program) -# def visit(self, node): -# dottypes = '\n'.join(self.visit(t) for t in node.dottypes.values()) -# dotdata = '\n'.join(f'{t}: {node.dotdata[t]}' for t in node.dotdata.keys()) -# dotcode = '\n'.join(self.visit(t) for t in node.dotcode) - -# return f'.TYPES\n{dottypes}\n\n.DATA\n{dotdata}\n\n.CODE\n{dotcode}' - -# @visitor.when(Type) -# def visit(self, node): -# attributes = '\n\t'.join(f'attribute {x}' for x in node.attributes) -# methods = '\n\t'.join(f'method {x} : {node.methods[x]}' for x in node.methods.keys()) - -# return f'type {node.name} {{\n\t{attributes}\n\n\t{methods}\n}}' - -# @visitor.when(Function) -# def visit(self, node): -# params = '\n\t'.join(self.visit(x) for x in node.params) -# localvars = '\n\t'.join(self.visit(x) for x in node.localvars) -# instructions = '\n\t'.join(self.visit(x) for x in node.instructions) - -# return f'function {node.name} {{\n\t{params}\n\n\t{localvars}\n\n\t{instructions}\n}}' - -# @visitor.when(ParamDec) -# def visit(self, node): -# return f'PARAM {node.name}' - -# @visitor.when(LocalDec) -# def visit(self, node): -# return f'LOCAL {node.name}' - -# @visitor.when(Assign) -# def visit(self, node): -# return f'{node.local_dest} = {node.right_expr}' - -# @visitor.when(IfGoto) -# def visit(self, node): -# return f'IF {node.variable} GOTO {node.label}' - -# @visitor.when(Label) -# def visit(self, node): -# return f'LABEL {node.label}' - -# @visitor.when(Goto) -# def visit(self, node): -# return f'GOTO {node.label}' - -# @visitor.when(UnaryOperator) -# def visit(self, node): -# return f'{node.local_dest} = {node.op} {node.expr_value}' - -# @visitor.when(BinaryOperator) -# def visit(self, node): -# return f'{node.local_dest} = {node.left} {node.op} {node.right}' - -# @visitor.when(Allocate) -# def visit(self, node): -# return f'{node.local_dest} = ALLOCATE {node.type}' - -# @visitor.when(LoadStr) -# def visit(self, node): -# return f'{node.local_dest} = LOAD {node.msg}' - -# @visitor.when(LoadInt) -# def visit(self, node): -# return f'{node.local_dest} = LOAD {node.num}' - -# @visitor.when(LoadVoid) -# def visit(self, node): -# return f'{node.local_dest} = LOAD VOID' - -# @visitor.when(GetAttr) -# def visit(self, node): -# return f'{node.local_dest} = GetAttr {node.instance} {node.attr} ' - -# @visitor.when(SetAttr) -# def visit(self, node): -# return f'SetAttr {node.instance} {node.attr} {node.value}' - - -# @visitor.when(TypeOf) -# def visit(self, node): -# return f'{node.local_dest} = TYPEOF {node.variable}' - -# @visitor.when(Call) -# def visit(self, node): -# return f'{node.local_dest} = CALL {node.function}' - -# @visitor.when(VCall) -# def visit(self, node): -# return f'{node.local_dest} = VCALL {node.dynamic_type} {node.function} ' - -# @visitor.when(Arg) -# def visit(self, node): -# return f'ARG {node.arg}' - -# @visitor.when(Return) -# def visit(self, node): -# return f'\n RETURN {node.value if node.value is not None else ""}' - -# @visitor.when(IsVoid) -# def visit(self, node): -# return f'{node.result_local} ISVOID {node.expre_value}' - -# @visitor.when(Halt) -# def visit(self, node): -# return 'HALT' - -# @visitor.when(Copy) -# def visit(self, node): -# return f'{node.local_dest} = COPY {node.type}' - -# @visitor.when(Length) -# def visit(self, node): -# return f'{node.result} = LENGTH {node.variable}' - -# @visitor.when(Concat) -# def visit(self, node): -# return f'{node.result} = CONCAT {node.str1} {node.str2}' - -# @visitor.when(SubStr) -# def visit(self, node): -# return f'{node.result} = SUBSTR {node.i} {node.length} {node.string}' - -# @visitor.when(StringEquals) -# def visit(self, node): -# return f'{node.result} = {node.s1} = {node.s2}' - -# @visitor.when(Read) -# def visit(self, node): -# return f'{node.result} = READ' - -# @visitor.when(Print) -# def visit(self, node): -# return f'PRINT {node.variable}' - -# printer = PrintVisitor() -# return (lambda ast: printer.visit(ast)) diff --git a/src/cparser/parser.py b/src/cparser/parser.py index 84d85f7ff..a4facd99d 100644 --- a/src/cparser/parser.py +++ b/src/cparser/parser.py @@ -1,7 +1,7 @@ from ply import yacc from utils.ast import * from utils.errors import SyntacticError -from utils.utils import find_column, tokens +from utils.utils import tokens class CoolParser: @@ -11,16 +11,6 @@ def __init__(self, lexer): self.parser = yacc.yacc(start='program', module=self) self.errors = [] - # precedence = ( - # ('left, AT'), - # ('left, NOT'), - # ('left, ISVOID'), - # ('left, EQUAL, LESS, LESSEQ'), - # ('left, PLUS, MINUS'), - # ('left, STAR, DIV'), - # ('left, DOT') - # ) - precedence = ( ('right', 'ASSIGN'), ('right', 'NOT'), @@ -249,11 +239,6 @@ def p_error(self, p): else: self.errors.append(SyntacticError('ERROR at or near EOF', 0, 0)) - # column = find_column(p.lexer.lexdata, p.lexpos) - # line = self.lexer.lexer.lineno - # self.errors.append(SyntacticError( - # 'ERROR at or near EOF', line, column - 1)) - def add_error(self, p): self.errors.append(SyntacticError( f'ERROR at or near {p.value}', p.lineno, p.column)) diff --git a/src/main.py b/src/main.py index 6afdcc308..8604aba19 100644 --- a/src/main.py +++ b/src/main.py @@ -8,7 +8,6 @@ from semantic.visitors.varCollector import VarCollector from code_generator.COOLToCILVisitor import COOLToCILVisitor from code_generator.CILToMIPSVisitor import CILToMIPSVisitor -from utils.errors import SemanticError def main(_input, _output): @@ -31,34 +30,16 @@ def main(_input, _output): semanticErrors = [] typeCollector = TypeCollector(semanticErrors) typeCollector.visit(ast) - # print("TYPE COLLECTOR") - # if semanticErrors: - # for error in semanticErrors: - # print(error) context = typeCollector.context typeBuilder = TypeBuilder(context, semanticErrors) typeBuilder.visit(ast) - # print("CONTEXT") - # print("TYPE Builder") - # print(context) - # if semanticErrors: - # for error in semanticErrors: - # print(error) - varCollector = VarCollector(context, semanticErrors) scope = varCollector.visit(ast) - # print("Var Collector") - # print(context) - # if semanticErrors: - # for error in semanticErrors: - # print(error) typeChecker = TypeChecker(context, semanticErrors) typeChecker.visit(ast, scope) - # print("Type Checker") - # print(context) if semanticErrors: for error in semanticErrors: @@ -75,8 +56,6 @@ def main(_input, _output): with open(_output, 'w+') as f: f.write(mips_code) - - # ast, errors, context, scope = SemanticAn if __name__ == "__main__": in_path = '/home/cwjki/Projects/cool-compiler-2021/tests/codegen/arith.cl' diff --git a/src/semantic/semantic.py b/src/semantic/semantic.py index 5ad002dc8..c2dcc8d75 100644 --- a/src/semantic/semantic.py +++ b/src/semantic/semantic.py @@ -1,4 +1,3 @@ -from unicodedata import name from utils.errors import SemanticError from collections import OrderedDict import itertools as itt @@ -442,29 +441,6 @@ def __init__(self, parent=None): def __len__(self): return len(self.locals) - # def __str__(self): - # res = '' - # for scope in self.children: - # try: - # classx = scope.locals[0] - # name = classx.type.name - # except: - # name = '1' - # # '\n\t' + ('\n' + '\t').join(str(local) for local in scope.locals) + '\n' - # res += name + scope.tab_level(1, '', 1) - # return res - - # def tab_level(self, tabs, name, num) -> str: - # res = ('\t' * tabs) + ('\n' + ('\t' * tabs)).join(str(local) - # for local in self.locals) - # if self.functions: - # children = '\n'.join(v.tab_level( - # tabs + 1, '[method] ' + k, num) for k, v in self.functions.items()) - # else: - # children = '\n'.join(child.tab_level( - # tabs + 1, num, num + 1) for child in self.children) - # return "\t" * (tabs-1) + f'{name}' + "\t" * tabs + f'\n{res}\n{children}' - def __repr__(self): return str(self) diff --git a/src/semantic/visitors/typeChecker.py b/src/semantic/visitors/typeChecker.py index c5da7bd56..069fc090f 100644 --- a/src/semantic/visitors/typeChecker.py +++ b/src/semantic/visitors/typeChecker.py @@ -1,4 +1,3 @@ -from cgi import print_directory from semantic.semantic import AutoType, BoolType, ErrorType, IntType, MethodError, ObjectType, StringType, VariableInfo, VoidType from utils.errors import AttributexError, SemanticError, TypexError from utils import visitor From 6baf39ed080f7ff9758c11f95558cf48cd0ec9bb Mon Sep 17 00:00:00 2001 From: cwjki Date: Thu, 24 Feb 2022 19:39:59 -0500 Subject: [PATCH 193/194] deleting unneccesary files --- src/codeMips.mips | 10290 -------------------------------------------- src/test.cl | 10 - 2 files changed, 10300 deletions(-) delete mode 100644 src/codeMips.mips delete mode 100644 src/test.cl diff --git a/src/codeMips.mips b/src/codeMips.mips deleted file mode 100644 index b9183590d..000000000 --- a/src/codeMips.mips +++ /dev/null @@ -1,10290 +0,0 @@ -.data -dispatch_void: .asciiz "Runtime Error: A dispatch (static or dynamic) on void" -case_void: .asciiz "Runtime Error: A case on void" -case_no_match: .asciiz "Runtime Error: Execution of a case statement without a matching branch" -div_zero: .asciiz "Runtime Error: Division by zero" -substr: .asciiz "Runtime Error: Substring out of range" -heap: .asciiz "Runtime Error: Heap overflow" -temp_string: .space 2048 -void: .word 0 -Object_name: .asciiz "Object" -Object_methods: -.word Object.abort -.word Object.type_name -.word Object.copy -Int_name: .asciiz "Int" -Int_methods: -.word Object.abort -.word Object.type_name -.word Object.copy -String_name: .asciiz "String" -String_methods: -.word Object.abort -.word Object.type_name -.word Object.copy -.word String.length -.word String.concat -.word String.substr -Bool_name: .asciiz "Bool" -Bool_methods: -.word Object.abort -.word Object.type_name -.word Object.copy -IO_name: .asciiz "IO" -IO_methods: -.word Object.abort -.word Object.type_name -.word Object.copy -.word IO.out_string -.word IO.out_int -.word IO.in_string -.word IO.in_int -A_name: .asciiz "A" -A_methods: -.word Object.abort -.word Object.type_name -.word Object.copy -.word A.value -.word A.set_var -.word A.method1 -.word A.method2 -.word A.method3 -.word A.method4 -.word A.method5 -B_name: .asciiz "B" -B_methods: -.word Object.abort -.word Object.type_name -.word Object.copy -.word A.value -.word A.set_var -.word A.method1 -.word A.method2 -.word A.method3 -.word A.method4 -.word B.method5 -C_name: .asciiz "C" -C_methods: -.word Object.abort -.word Object.type_name -.word Object.copy -.word A.value -.word A.set_var -.word A.method1 -.word A.method2 -.word A.method3 -.word A.method4 -.word C.method5 -.word C.method6 -D_name: .asciiz "D" -D_methods: -.word Object.abort -.word Object.type_name -.word Object.copy -.word A.value -.word A.set_var -.word A.method1 -.word A.method2 -.word A.method3 -.word A.method4 -.word B.method5 -.word D.method7 -E_name: .asciiz "E" -E_methods: -.word Object.abort -.word Object.type_name -.word Object.copy -.word A.value -.word A.set_var -.word A.method1 -.word A.method2 -.word A.method3 -.word A.method4 -.word B.method5 -.word D.method7 -.word E.method6 -A2I_name: .asciiz "A2I" -A2I_methods: -.word Object.abort -.word Object.type_name -.word Object.copy -.word A2I.c2i -.word A2I.i2c -.word A2I.a2i -.word A2I.a2i_aux -.word A2I.i2a -.word A2I.i2a_aux -Main_name: .asciiz "Main" -Main_methods: -.word Object.abort -.word Object.type_name -.word Object.copy -.word IO.out_string -.word IO.out_int -.word IO.in_string -.word IO.in_int -.word Main.menu -.word Main.prompt -.word Main.get_int -.word Main.is_even -.word Main.class_type -.word Main.print -.word Main.main -data_0: .asciiz "Abort called from class " -data_1: .asciiz " -" -empty_str: .asciiz "" -data_3: .asciiz "0" -data_4: .asciiz "1" -data_5: .asciiz "2" -data_6: .asciiz "3" -data_7: .asciiz "4" -data_8: .asciiz "5" -data_9: .asciiz "6" -data_10: .asciiz "7" -data_11: .asciiz "8" -data_12: .asciiz "9" -data_13: .asciiz "-" -data_14: .asciiz "+" -data_15: .asciiz " - To add a number to " -data_16: .asciiz "...enter a: -" -data_17: .asciiz " To negate " -data_18: .asciiz "...enter b: -" -data_19: .asciiz " To find the difference between " -data_20: .asciiz "and another number...enter c: -" -data_21: .asciiz " To find the factorial of " -data_22: .asciiz "...enter d: -" -data_23: .asciiz " To square " -data_24: .asciiz "...enter e: -" -data_25: .asciiz " To cube " -data_26: .asciiz "...enter f: -" -data_27: .asciiz " To find out if " -data_28: .asciiz "is a multiple of 3...enter g: -" -data_29: .asciiz " To divide " -data_30: .asciiz "by 8...enter h: -" -data_31: .asciiz " To get a new number...enter j: -" -data_32: .asciiz " To quit...enter q: - -" -data_33: .asciiz "Please enter a number... " -data_34: .asciiz "Class type is now E -" -data_35: .asciiz "Class type is now D -" -data_36: .asciiz "Class type is now C -" -data_37: .asciiz "Class type is now B -" -data_38: .asciiz "Class type is now A -" -data_39: .asciiz "Oooops -" -data_40: .asciiz " " -data_41: .asciiz "number " -data_42: .asciiz "is odd! -" -data_43: .asciiz "is even! -" -data_44: .asciiz "a" -data_45: .asciiz "b" -data_46: .asciiz "c" -data_47: .asciiz "d" -data_48: .asciiz "e" -data_49: .asciiz "f" -data_50: .asciiz "g" -data_51: .asciiz "h" -data_52: .asciiz "j" -data_53: .asciiz "q" -data_54: .asciiz "is equal to " -data_55: .asciiz "times 8 with a remainder of " -data_56: .asciiz "is not divisible by 3. -" -data_57: .asciiz "is divisible by 3. -" -.text -dispatch_void_error: -la $a0 dispatch_void -li $v0, 4 -syscall -li $v0, 10 -syscall -case_void_error: -la $a0 case_void -li $v0, 4 -syscall -li $v0, 10 -syscall -case_no_match_error: -la $a0 case_no_match -li $v0, 4 -syscall -li $v0, 10 -syscall -div_zero_error: -la $a0 div_zero -li $v0, 4 -syscall -li $v0, 10 -syscall -substr_error: -la $a0 substr -li $v0, 4 -syscall -li $v0, 10 -syscall -heap_error: -la $a0 heap -li $v0, 4 -syscall -li $v0, 10 -syscall -main: -addi $sp, $sp, -8 -addi $sp, $sp, -4 -sw $ra, 0($sp) -li $a0, 32 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, Main_name -sw $t1, 4($t0) -li $t1, 8 -sw $t1, 8($t0) -la $t1, Main_methods -sw $t1, 12($t0) -sw $t0, 4($sp) -move $t0, $sp -lw $t1, 4($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Main_init -sw $a1, 8($sp) -move $t0, $sp -lw $t1, 4($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Main.main -sw $a1, 8($sp) -move $a1, $zero -lw $ra, 0($sp) -addi $sp, $sp, 12 -jr $ra -Object_init: -addi $sp, $sp, 0 -addi $sp, $sp, -4 -sw $ra, 0($sp) -move $a1, $zero -lw $ra, 0($sp) -addi $sp, $sp, 8 -jr $ra -Object.abort: -addi $sp, $sp, -12 -addi $sp, $sp, -4 -sw $ra, 0($sp) -la $t0, data_0 -sw $t0, 4($sp) -lw $a0, 4($sp) -li $v0, 4 -syscall -lw $t0, 16($sp) -lw $t1, 4($t0) -sw $t1, 8($sp) -lw $a0, 8($sp) -li $v0, 4 -syscall -la $t0, data_1 -sw $t0, 12($sp) -lw $a0, 12($sp) -li $v0, 4 -syscall -li $v0, 10 -syscall -lw $ra, 0($sp) -addi $sp, $sp, 20 -jr $ra -Object.type_name: -addi $sp, $sp, -12 -addi $sp, $sp, -4 -sw $ra, 0($sp) -lw $t0, 16($sp) -lw $t1, 4($t0) -sw $t1, 4($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 8($sp) -move $t0, $sp -lw $t1, 4($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 8($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 12($sp) -lw $a1, 8($sp) -lw $ra, 0($sp) -addi $sp, $sp, 20 -jr $ra -Object.copy: -addi $sp, $sp, -4 -addi $sp, $sp, -4 -sw $ra, 0($sp) -lw $t0, 8($sp) -lw $a0, 8($t0) -mul $a0, $a0, 4 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t1, $v0 -li $a0, 0 -lw $t3, 8($t0) -copy_object_word: -lw $t2, 0($t0) -sw $t2, 0($t1) -addi $t0, $t0, 4 -addi $t1, $t1, 4 -addi $a0, $a0, 1 -blt $a0, $t3, copy_object_word -sw $v0, 4($sp) -lw $a1, 4($sp) -lw $ra, 0($sp) -addi $sp, $sp, 12 -jr $ra -IO_init: -addi $sp, $sp, 0 -addi $sp, $sp, -4 -sw $ra, 0($sp) -move $a1, $zero -lw $ra, 0($sp) -addi $sp, $sp, 8 -jr $ra -IO.out_string: -addi $sp, $sp, -4 -addi $sp, $sp, -4 -sw $ra, 0($sp) -lw $t0, 12($sp) -lw $t1, 16($t0) -sw $t1, 4($sp) -lw $a0, 4($sp) -li $v0, 4 -syscall -lw $a1, 8($sp) -lw $ra, 0($sp) -addi $sp, $sp, 16 -jr $ra -IO.out_int: -addi $sp, $sp, -4 -addi $sp, $sp, -4 -sw $ra, 0($sp) -lw $t0, 12($sp) -lw $t1, 16($t0) -sw $t1, 4($sp) -li $v0 , 1 -lw $a0 , 4($sp) -syscall -lw $a1, 8($sp) -lw $ra, 0($sp) -addi $sp, $sp, 16 -jr $ra -IO.in_string: -addi $sp, $sp, -12 -addi $sp, $sp, -4 -sw $ra, 0($sp) -la $a0, temp_string -li $a1, 2048 -li $v0, 8 -syscall -move $t0, $a0 -jump_read_str_char: -li $t1, 0 -lb $t1, 0($t0) -beqz $t1, analize_str_end -addi $t0, $t0, 1 -j jump_read_str_char -analize_str_end: -addi $t0, $t0, -1 -li $t1, 0 -lb $t1, 0($t0) -bne $t1, 10, finish_jump_read_str_char -sb $0, 0($t0) -addi $t0, $t0, -1 -lb $t1, 0($t0) -bne $t1, 13, finish_jump_read_str_char -sb $0, 0($t0) -j analize_str_end -finish_jump_read_str_char: -sw $a0, 4($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 8($sp) -move $t0, $sp -lw $t1, 4($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 8($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 12($sp) -lw $a1, 8($sp) -lw $ra, 0($sp) -addi $sp, $sp, 20 -jr $ra -IO.in_int: -addi $sp, $sp, -12 -addi $sp, $sp, -4 -sw $ra, 0($sp) -li $v0, 5 -syscall -sw $v0, 4($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 8($sp) -move $t0, $sp -lw $t1, 4($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 8($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 12($sp) -lw $a1, 8($sp) -lw $ra, 0($sp) -addi $sp, $sp, 20 -jr $ra -String_init: -addi $sp, $sp, 0 -addi $sp, $sp, -4 -sw $ra, 0($sp) -lw $t0, 4($sp) -lw $t1, 8($sp) -sw $t1, 16($t0) -move $a1, $zero -lw $ra, 0($sp) -addi $sp, $sp, 12 -jr $ra -String.length: -addi $sp, $sp, -12 -addi $sp, $sp, -4 -sw $ra, 0($sp) -lw $t0, 16($sp) -lw $t0, 16($t0) -li $a0, 0 -count_char: -lb $t1, 0($t0) -beqz $t1, finish_chars_count -addi $t0, $t0, 1 -addi $a0, $a0, 1 -j count_char -finish_chars_count: -sw $a0, 4($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 8($sp) -move $t0, $sp -lw $t1, 4($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 8($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 12($sp) -lw $a1, 8($sp) -lw $ra, 0($sp) -addi $sp, $sp, 20 -jr $ra -String.concat: -addi $sp, $sp, -36 -addi $sp, $sp, -4 -sw $ra, 0($sp) -lw $t0, 40($sp) -lw $t1, 16($t0) -sw $t1, 4($sp) -move $t0, $sp -lw $t1, 40($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String.length -sw $a1, 8($sp) -lw $t0, 44($sp) -lw $t1, 16($t0) -sw $t1, 12($sp) -move $t0, $sp -lw $t1, 44($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String.length -sw $a1, 16($sp) -lw $t0, 8($sp) -lw $t1, 16($t0) -sw $t1, 20($sp) -lw $t0, 16($sp) -lw $t1, 16($t0) -sw $t1, 24($sp) -lw $a0, 20($sp) -lw $t0, 24($sp) -add $a0, $a0, $t0 -addi $a0, $a0, 1 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t3, $v0 -lw $t0, 4($sp) -lw $t1, 12($sp) -copy_str1_char: -lb $t2, 0($t0) -sb $t2, 0($v0) -beqz $t2, concat_str2_char -addi $t0, $t0, 1 -addi $v0, $v0, 1 -j copy_str1_char -concat_str2_char: -lb $t2, 0($t1) -sb $t2, 0($v0) -beqz $t2, finish_str2_concat -addi $t1, $t1, 1 -addi $v0, $v0, 1 -j concat_str2_char -finish_str2_concat: -sb $0, ($v0) -sw $t3, 28($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 32($sp) -move $t0, $sp -lw $t1, 28($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 32($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 36($sp) -lw $a1, 32($sp) -lw $ra, 0($sp) -addi $sp, $sp, 48 -jr $ra -String.substr: -addi $sp, $sp, -20 -addi $sp, $sp, -4 -sw $ra, 0($sp) -lw $t0, 28($sp) -lw $t1, 16($t0) -sw $t1, 4($sp) -lw $t0, 32($sp) -lw $t1, 16($t0) -sw $t1, 8($sp) -lw $a0, 8($sp) -addi $a0, $a0, 1 -li $v0, 9 -syscall -bge $v0, $sp heap_error -lw $t0, 4($sp) -lw $t1, 8($sp) -lw $t4, 24($sp) -lw $t2, 16($t4) -bltz $t0, substr_error -li $a0, 0 -jump_str_char: -beq $a0, $t0, finish_index_jump -addi $a0, $a0, 1 -addi $t2, $t2, 1 -beq $t2, $zero, substr_error -j jump_str_char -finish_index_jump: -li $a0, 0 -move $t3, $v0 -copy_substr_char: -beq $a0, $t1 finish_substr_copy -li $t0, 0 -lb $t0, 0($t2) -sb $t0, 0($v0) -addi $t2, $t2, 1 -beq $t2, $zero, substr_error -addi $v0, $v0, 1 -addi $a0, $a0, 1 -j copy_substr_char -finish_substr_copy: -sb $0, ($v0) -sw $t3, 12($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 16($sp) -move $t0, $sp -lw $t1, 12($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 16($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 20($sp) -lw $a1, 16($sp) -lw $ra, 0($sp) -addi $sp, $sp, 36 -jr $ra -Bool_init: -addi $sp, $sp, 0 -addi $sp, $sp, -4 -sw $ra, 0($sp) -lw $t0, 4($sp) -lw $t1, 8($sp) -sw $t1, 16($t0) -move $a1, $zero -lw $ra, 0($sp) -addi $sp, $sp, 12 -jr $ra -Int_init: -addi $sp, $sp, 0 -addi $sp, $sp, -4 -sw $ra, 0($sp) -lw $t0, 4($sp) -lw $t1, 8($sp) -sw $t1, 16($t0) -move $a1, $zero -lw $ra, 0($sp) -addi $sp, $sp, 12 -jr $ra -String_equals: -addi $sp, $sp, -12 -addi $sp, $sp, -4 -sw $ra, 0($sp) -lw $t0, 16($sp) -lw $t1, 16($t0) -sw $t1, 4($sp) -lw $t0, 20($sp) -lw $t1, 16($t0) -sw $t1, 8($sp) -lw $t1, 4($sp) -lw $t2, 8($sp) -compare_str_char: -li $t3, 0 -lb $t3, 0($t1) -li $t4, 0 -lb $t4, 0($t2) -seq $a0, $t3, $t4 -beqz $a0, finish_compare_str -beqz $t3, finish_compare_str -beqz $t4, finish_compare_str -addi $t1, $t1, 1 -addi $t2, $t2, 1 -j compare_str_char -finish_compare_str: -sw $a0, 12($sp) -lw $a1, 12($sp) -lw $ra, 0($sp) -addi $sp, $sp, 24 -jr $ra -A_init: -addi $sp, $sp, -16 -addi $sp, $sp, -4 -sw $ra, 0($sp) -move $t0, $sp -lw $t1, 20($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Object_init -sw $a1, 4($sp) -move $a1, $zero -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 8($sp) -li $t0, 0 -sw $t0, 12($sp) -move $t0, $sp -lw $t1, 12($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 8($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 16($sp) -lw $t0, 20($sp) -lw $t1, 8($sp) -sw $t1, 16($t0) -lw $ra, 0($sp) -addi $sp, $sp, 24 -jr $ra -A.value: -addi $sp, $sp, -4 -addi $sp, $sp, -4 -sw $ra, 0($sp) -lw $t0, 8($sp) -lw $t1, 16($t0) -sw $t1, 4($sp) -lw $a1, 4($sp) -lw $ra, 0($sp) -addi $sp, $sp, 12 -jr $ra -A.set_var: -addi $sp, $sp, -4 -addi $sp, $sp, -4 -sw $ra, 0($sp) -lw $t0, 8($sp) -lw $t1, 12($sp) -sw $t1, 16($t0) -lw $a1, 8($sp) -lw $ra, 0($sp) -addi $sp, $sp, 16 -jr $ra -A.method1: -addi $sp, $sp, 0 -addi $sp, $sp, -4 -sw $ra, 0($sp) -lw $a1, 4($sp) -lw $ra, 0($sp) -addi $sp, $sp, 12 -jr $ra -A.method2: -addi $sp, $sp, -56 -addi $sp, $sp, -4 -sw $ra, 0($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 4($sp) -li $t0, 0 -sw $t0, 8($sp) -move $t0, $sp -lw $t1, 8($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 4($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 12($sp) -lw $t1, 4($sp) -sw $t1, 16($sp) -lw $t0, 64($sp) -lw $t1, 16($t0) -sw $t1, 28($sp) -lw $t0, 68($sp) -lw $t1, 16($t0) -sw $t1, 32($sp) -lw $a0, 28($sp) -lw $t1, 32($sp) -add $a0, $a0, $t1 -sw $a0, 24($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 20($sp) -move $t0, $sp -lw $t1, 24($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 20($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 36($sp) -lw $t1, 20($sp) -sw $t1, 16($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 6 -sw $t1, 0($t0) -la $t1, B_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, B_methods -sw $t1, 12($t0) -sw $t0, 48($sp) -move $t0, $sp -lw $t1, 48($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal B_init -sw $a1, 52($sp) -move $t0, $sp -lw $t1, 16($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 48($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 48($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 16($t2) -jal $t3 -sw $a1, 44($sp) -lw $t1, 44($sp) -sw $t1, 56($sp) -lw $a1, 56($sp) -lw $ra, 0($sp) -addi $sp, $sp, 72 -jr $ra -A.method3: -addi $sp, $sp, -52 -addi $sp, $sp, -4 -sw $ra, 0($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 4($sp) -li $t0, 0 -sw $t0, 8($sp) -move $t0, $sp -lw $t1, 8($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 4($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 12($sp) -lw $t1, 4($sp) -sw $t1, 16($sp) -lw $t0, 60($sp) -lw $t1, 16($t0) -sw $t1, 28($sp) -lw $t1, 28($sp) -neg $a0, $t1 -sw $a0, 24($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 20($sp) -move $t0, $sp -lw $t1, 24($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 20($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 32($sp) -lw $t1, 20($sp) -sw $t1, 16($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 7 -sw $t1, 0($t0) -la $t1, C_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, C_methods -sw $t1, 12($t0) -sw $t0, 44($sp) -move $t0, $sp -lw $t1, 44($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal C_init -sw $a1, 48($sp) -move $t0, $sp -lw $t1, 16($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 44($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 44($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 16($t2) -jal $t3 -sw $a1, 40($sp) -lw $t1, 40($sp) -sw $t1, 52($sp) -lw $a1, 52($sp) -lw $ra, 0($sp) -addi $sp, $sp, 64 -jr $ra -A.method4: -addi $sp, $sp, -136 -addi $sp, $sp, -4 -sw $ra, 0($sp) -lw $t0, 148($sp) -lw $t1, 16($t0) -sw $t1, 16($sp) -lw $t0, 144($sp) -lw $t1, 16($t0) -sw $t1, 20($sp) -lw $a0, 16($sp) -lw $t1, 20($sp) -slt $a0, $a0, $t1 -sw $a0, 12($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 8($sp) -move $t0, $sp -lw $t1, 12($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 8($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 24($sp) -lw $t0, 8($sp) -lw $a0, 16($t0) -bnez $a0, label_1 -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 28($sp) -li $t0, 0 -sw $t0, 32($sp) -move $t0, $sp -lw $t1, 32($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 28($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 36($sp) -lw $t1, 28($sp) -sw $t1, 40($sp) -lw $t0, 148($sp) -lw $t1, 16($t0) -sw $t1, 52($sp) -lw $t0, 144($sp) -lw $t1, 16($t0) -sw $t1, 56($sp) -lw $a0, 52($sp) -lw $t1, 56($sp) -sub $a0, $a0, $t1 -sw $a0, 48($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 44($sp) -move $t0, $sp -lw $t1, 48($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 44($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 60($sp) -lw $t1, 44($sp) -sw $t1, 40($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 8 -sw $t1, 0($t0) -la $t1, D_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, D_methods -sw $t1, 12($t0) -sw $t0, 72($sp) -move $t0, $sp -lw $t1, 72($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal D_init -sw $a1, 76($sp) -move $t0, $sp -lw $t1, 40($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 72($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 72($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 16($t2) -jal $t3 -sw $a1, 68($sp) -lw $t1, 68($sp) -sw $t1, 80($sp) -lw $t1, 80($sp) -sw $t1, 4($sp) -b label_2 -label_1: -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 84($sp) -li $t0, 0 -sw $t0, 88($sp) -move $t0, $sp -lw $t1, 88($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 84($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 92($sp) -lw $t1, 84($sp) -sw $t1, 96($sp) -lw $t0, 144($sp) -lw $t1, 16($t0) -sw $t1, 108($sp) -lw $t0, 148($sp) -lw $t1, 16($t0) -sw $t1, 112($sp) -lw $a0, 108($sp) -lw $t1, 112($sp) -sub $a0, $a0, $t1 -sw $a0, 104($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 100($sp) -move $t0, $sp -lw $t1, 104($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 100($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 116($sp) -lw $t1, 100($sp) -sw $t1, 96($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 8 -sw $t1, 0($t0) -la $t1, D_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, D_methods -sw $t1, 12($t0) -sw $t0, 128($sp) -move $t0, $sp -lw $t1, 128($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal D_init -sw $a1, 132($sp) -move $t0, $sp -lw $t1, 96($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 128($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 128($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 16($t2) -jal $t3 -sw $a1, 124($sp) -lw $t1, 124($sp) -sw $t1, 136($sp) -lw $t1, 136($sp) -sw $t1, 4($sp) -label_2: -lw $a1, 4($sp) -lw $ra, 0($sp) -addi $sp, $sp, 152 -jr $ra -A.method5: -addi $sp, $sp, -136 -addi $sp, $sp, -4 -sw $ra, 0($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 4($sp) -li $t0, 1 -sw $t0, 8($sp) -move $t0, $sp -lw $t1, 8($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 4($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 12($sp) -lw $t1, 4($sp) -sw $t1, 16($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 20($sp) -li $t0, 1 -sw $t0, 24($sp) -move $t0, $sp -lw $t1, 24($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 20($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 28($sp) -lw $t1, 20($sp) -sw $t1, 32($sp) -label_3: -lw $t0, 32($sp) -lw $t1, 16($t0) -sw $t1, 48($sp) -lw $t0, 144($sp) -lw $t1, 16($t0) -sw $t1, 52($sp) -lw $a0, 48($sp) -lw $t1, 52($sp) -sle $a0, $a0, $t1 -sw $a0, 44($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 40($sp) -move $t0, $sp -lw $t1, 44($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 40($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 56($sp) -lw $t0, 40($sp) -lw $a0, 16($t0) -bnez $a0, label_4 -b label_5 -label_4: -lw $t0, 16($sp) -lw $t1, 16($t0) -sw $t1, 68($sp) -lw $t0, 32($sp) -lw $t1, 16($t0) -sw $t1, 72($sp) -lw $a0, 68($sp) -lw $t1, 72($sp) -mul $a0, $a0, $t1 -sw $a0, 64($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 60($sp) -move $t0, $sp -lw $t1, 64($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 60($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 76($sp) -lw $t1, 60($sp) -sw $t1, 16($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 100($sp) -li $t0, 1 -sw $t0, 104($sp) -move $t0, $sp -lw $t1, 104($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 100($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 108($sp) -lw $t0, 32($sp) -lw $t1, 16($t0) -sw $t1, 92($sp) -lw $t0, 100($sp) -lw $t1, 16($t0) -sw $t1, 96($sp) -lw $a0, 92($sp) -lw $t1, 96($sp) -add $a0, $a0, $t1 -sw $a0, 88($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 84($sp) -move $t0, $sp -lw $t1, 88($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 84($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 112($sp) -lw $t1, 84($sp) -sw $t1, 32($sp) -b label_3 -label_5: -lw $t1, 36($sp) -sw $t1, 120($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 9 -sw $t1, 0($t0) -la $t1, E_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, E_methods -sw $t1, 12($t0) -sw $t0, 128($sp) -move $t0, $sp -lw $t1, 128($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal E_init -sw $a1, 132($sp) -move $t0, $sp -lw $t1, 16($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 128($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 128($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 16($t2) -jal $t3 -sw $a1, 124($sp) -lw $t1, 124($sp) -sw $t1, 136($sp) -lw $a1, 136($sp) -lw $ra, 0($sp) -addi $sp, $sp, 148 -jr $ra -B_init: -addi $sp, $sp, -4 -addi $sp, $sp, -4 -sw $ra, 0($sp) -move $t0, $sp -lw $t1, 8($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal A_init -sw $a1, 4($sp) -move $a1, $zero -lw $ra, 0($sp) -addi $sp, $sp, 12 -jr $ra -B.method5: -addi $sp, $sp, -56 -addi $sp, $sp, -4 -sw $ra, 0($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 4($sp) -li $t0, 0 -sw $t0, 8($sp) -move $t0, $sp -lw $t1, 8($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 4($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 12($sp) -lw $t1, 4($sp) -sw $t1, 16($sp) -lw $t0, 64($sp) -lw $t1, 16($t0) -sw $t1, 28($sp) -lw $t0, 64($sp) -lw $t1, 16($t0) -sw $t1, 32($sp) -lw $a0, 28($sp) -lw $t1, 32($sp) -mul $a0, $a0, $t1 -sw $a0, 24($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 20($sp) -move $t0, $sp -lw $t1, 24($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 20($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 36($sp) -lw $t1, 20($sp) -sw $t1, 16($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 9 -sw $t1, 0($t0) -la $t1, E_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, E_methods -sw $t1, 12($t0) -sw $t0, 48($sp) -move $t0, $sp -lw $t1, 48($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal E_init -sw $a1, 52($sp) -move $t0, $sp -lw $t1, 16($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 48($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 48($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 16($t2) -jal $t3 -sw $a1, 44($sp) -lw $t1, 44($sp) -sw $t1, 56($sp) -lw $a1, 56($sp) -lw $ra, 0($sp) -addi $sp, $sp, 68 -jr $ra -C_init: -addi $sp, $sp, -4 -addi $sp, $sp, -4 -sw $ra, 0($sp) -move $t0, $sp -lw $t1, 8($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal B_init -sw $a1, 4($sp) -move $a1, $zero -lw $ra, 0($sp) -addi $sp, $sp, 12 -jr $ra -C.method6: -addi $sp, $sp, -52 -addi $sp, $sp, -4 -sw $ra, 0($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 4($sp) -li $t0, 0 -sw $t0, 8($sp) -move $t0, $sp -lw $t1, 8($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 4($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 12($sp) -lw $t1, 4($sp) -sw $t1, 16($sp) -lw $t0, 60($sp) -lw $t1, 16($t0) -sw $t1, 28($sp) -lw $t1, 28($sp) -neg $a0, $t1 -sw $a0, 24($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 20($sp) -move $t0, $sp -lw $t1, 24($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 20($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 32($sp) -lw $t1, 20($sp) -sw $t1, 16($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 5 -sw $t1, 0($t0) -la $t1, A_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, A_methods -sw $t1, 12($t0) -sw $t0, 44($sp) -move $t0, $sp -lw $t1, 44($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal A_init -sw $a1, 48($sp) -move $t0, $sp -lw $t1, 16($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 44($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 44($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 16($t2) -jal $t3 -sw $a1, 40($sp) -lw $t1, 40($sp) -sw $t1, 52($sp) -lw $a1, 52($sp) -lw $ra, 0($sp) -addi $sp, $sp, 64 -jr $ra -C.method5: -addi $sp, $sp, -76 -addi $sp, $sp, -4 -sw $ra, 0($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 4($sp) -li $t0, 0 -sw $t0, 8($sp) -move $t0, $sp -lw $t1, 8($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 4($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 12($sp) -lw $t1, 4($sp) -sw $t1, 16($sp) -lw $t0, 84($sp) -lw $t1, 16($t0) -sw $t1, 44($sp) -lw $t0, 84($sp) -lw $t1, 16($t0) -sw $t1, 48($sp) -lw $a0, 44($sp) -lw $t1, 48($sp) -mul $a0, $a0, $t1 -sw $a0, 40($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 36($sp) -move $t0, $sp -lw $t1, 40($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 36($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 52($sp) -lw $t0, 36($sp) -lw $t1, 16($t0) -sw $t1, 28($sp) -lw $t0, 84($sp) -lw $t1, 16($t0) -sw $t1, 32($sp) -lw $a0, 28($sp) -lw $t1, 32($sp) -mul $a0, $a0, $t1 -sw $a0, 24($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 20($sp) -move $t0, $sp -lw $t1, 24($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 20($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 56($sp) -lw $t1, 20($sp) -sw $t1, 16($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 9 -sw $t1, 0($t0) -la $t1, E_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, E_methods -sw $t1, 12($t0) -sw $t0, 68($sp) -move $t0, $sp -lw $t1, 68($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal E_init -sw $a1, 72($sp) -move $t0, $sp -lw $t1, 16($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 68($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 68($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 16($t2) -jal $t3 -sw $a1, 64($sp) -lw $t1, 64($sp) -sw $t1, 76($sp) -lw $a1, 76($sp) -lw $ra, 0($sp) -addi $sp, $sp, 88 -jr $ra -D_init: -addi $sp, $sp, -4 -addi $sp, $sp, -4 -sw $ra, 0($sp) -move $t0, $sp -lw $t1, 8($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal B_init -sw $a1, 4($sp) -move $a1, $zero -lw $ra, 0($sp) -addi $sp, $sp, 12 -jr $ra -D.method7: -addi $sp, $sp, -244 -addi $sp, $sp, -4 -sw $ra, 0($sp) -lw $t1, 252($sp) -sw $t1, 4($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 28($sp) -li $t0, 0 -sw $t0, 32($sp) -move $t0, $sp -lw $t1, 32($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 28($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 36($sp) -lw $t0, 4($sp) -lw $t1, 16($t0) -sw $t1, 20($sp) -lw $t0, 28($sp) -lw $t1, 16($t0) -sw $t1, 24($sp) -lw $a0, 20($sp) -lw $t1, 24($sp) -slt $a0, $a0, $t1 -sw $a0, 16($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 12($sp) -move $t0, $sp -lw $t1, 16($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 12($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 40($sp) -lw $t0, 12($sp) -lw $a0, 16($t0) -bnez $a0, label_6 -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 64($sp) -li $t0, 0 -sw $t0, 68($sp) -move $t0, $sp -lw $t1, 68($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 64($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 72($sp) -lw $t0, 64($sp) -lw $t1, 16($t0) -sw $t1, 56($sp) -lw $t0, 4($sp) -lw $t1, 16($t0) -sw $t1, 60($sp) -lw $a0, 56($sp) -lw $t1, 60($sp) -seq $a0, $a0, $t1 -sw $a0, 52($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 48($sp) -move $t0, $sp -lw $t1, 52($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 48($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 76($sp) -lw $t0, 48($sp) -lw $a0, 16($t0) -bnez $a0, label_7 -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 100($sp) -li $t0, 1 -sw $t0, 104($sp) -move $t0, $sp -lw $t1, 104($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 100($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 108($sp) -lw $t0, 100($sp) -lw $t1, 16($t0) -sw $t1, 92($sp) -lw $t0, 4($sp) -lw $t1, 16($t0) -sw $t1, 96($sp) -lw $a0, 92($sp) -lw $t1, 96($sp) -seq $a0, $a0, $t1 -sw $a0, 88($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 84($sp) -move $t0, $sp -lw $t1, 88($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 84($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 112($sp) -lw $t0, 84($sp) -lw $a0, 16($t0) -bnez $a0, label_8 -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 136($sp) -li $t0, 2 -sw $t0, 140($sp) -move $t0, $sp -lw $t1, 140($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 136($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 144($sp) -lw $t0, 136($sp) -lw $t1, 16($t0) -sw $t1, 128($sp) -lw $t0, 4($sp) -lw $t1, 16($t0) -sw $t1, 132($sp) -lw $a0, 128($sp) -lw $t1, 132($sp) -seq $a0, $a0, $t1 -sw $a0, 124($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 120($sp) -move $t0, $sp -lw $t1, 124($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 120($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 148($sp) -lw $t0, 120($sp) -lw $a0, 16($t0) -bnez $a0, label_9 -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 172($sp) -li $t0, 3 -sw $t0, 176($sp) -move $t0, $sp -lw $t1, 176($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 172($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 180($sp) -lw $t0, 4($sp) -lw $t1, 16($t0) -sw $t1, 164($sp) -lw $t0, 172($sp) -lw $t1, 16($t0) -sw $t1, 168($sp) -lw $a0, 164($sp) -lw $t1, 168($sp) -sub $a0, $a0, $t1 -sw $a0, 160($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 156($sp) -move $t0, $sp -lw $t1, 160($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 156($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 184($sp) -move $t0, $sp -lw $t1, 156($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 248($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 248($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 40($t2) -jal $t3 -sw $a1, 152($sp) -lw $t1, 152($sp) -sw $t1, 116($sp) -b label_10 -label_9: -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 188($sp) -li $t0, 0 -sw $t0, 192($sp) -move $t0, $sp -lw $t1, 192($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 188($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 196($sp) -lw $t1, 188($sp) -sw $t1, 116($sp) -label_10: -lw $t1, 116($sp) -sw $t1, 80($sp) -b label_11 -label_8: -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 200($sp) -li $t0, 0 -sw $t0, 204($sp) -move $t0, $sp -lw $t1, 204($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 200($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 208($sp) -lw $t1, 200($sp) -sw $t1, 80($sp) -label_11: -lw $t1, 80($sp) -sw $t1, 44($sp) -b label_12 -label_7: -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 212($sp) -li $t0, 1 -sw $t0, 216($sp) -move $t0, $sp -lw $t1, 216($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 212($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 220($sp) -lw $t1, 212($sp) -sw $t1, 44($sp) -label_12: -lw $t1, 44($sp) -sw $t1, 8($sp) -b label_13 -label_6: -lw $t0, 4($sp) -lw $t1, 16($t0) -sw $t1, 236($sp) -lw $t1, 236($sp) -neg $a0, $t1 -sw $a0, 232($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 228($sp) -move $t0, $sp -lw $t1, 232($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 228($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 240($sp) -move $t0, $sp -lw $t1, 228($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 248($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 248($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 40($t2) -jal $t3 -sw $a1, 224($sp) -lw $t1, 224($sp) -sw $t1, 8($sp) -label_13: -lw $t1, 8($sp) -sw $t1, 244($sp) -lw $a1, 244($sp) -lw $ra, 0($sp) -addi $sp, $sp, 256 -jr $ra -E_init: -addi $sp, $sp, -4 -addi $sp, $sp, -4 -sw $ra, 0($sp) -move $t0, $sp -lw $t1, 8($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal D_init -sw $a1, 4($sp) -move $a1, $zero -lw $ra, 0($sp) -addi $sp, $sp, 12 -jr $ra -E.method6: -addi $sp, $sp, -68 -addi $sp, $sp, -4 -sw $ra, 0($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 4($sp) -li $t0, 0 -sw $t0, 8($sp) -move $t0, $sp -lw $t1, 8($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 4($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 12($sp) -lw $t1, 4($sp) -sw $t1, 16($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 36($sp) -li $t0, 8 -sw $t0, 40($sp) -move $t0, $sp -lw $t1, 40($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 36($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 44($sp) -lw $t0, 76($sp) -lw $t1, 16($t0) -sw $t1, 28($sp) -lw $t0, 36($sp) -lw $t1, 16($t0) -sw $t1, 32($sp) -lw $a0, 28($sp) -lw $t1, 32($sp) -beq $t1, 0, div_zero_error -div $a0, $a0, $t1 -sw $a0, 24($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 20($sp) -move $t0, $sp -lw $t1, 24($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 20($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 48($sp) -lw $t1, 20($sp) -sw $t1, 16($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 5 -sw $t1, 0($t0) -la $t1, A_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, A_methods -sw $t1, 12($t0) -sw $t0, 60($sp) -move $t0, $sp -lw $t1, 60($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal A_init -sw $a1, 64($sp) -move $t0, $sp -lw $t1, 16($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 60($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 60($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 16($t2) -jal $t3 -sw $a1, 56($sp) -lw $t1, 56($sp) -sw $t1, 68($sp) -lw $a1, 68($sp) -lw $ra, 0($sp) -addi $sp, $sp, 80 -jr $ra -A2I_init: -addi $sp, $sp, -4 -addi $sp, $sp, -4 -sw $ra, 0($sp) -move $t0, $sp -lw $t1, 8($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Object_init -sw $a1, 4($sp) -move $a1, $zero -lw $ra, 0($sp) -addi $sp, $sp, 12 -jr $ra -A2I.c2i: -addi $sp, $sp, -496 -addi $sp, $sp, -4 -sw $ra, 0($sp) -la $t0, data_3 -sw $t0, 24($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 28($sp) -move $t0, $sp -lw $t1, 24($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 28($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 32($sp) -move $t0, $sp -lw $t1, 28($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 504($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_equals -sw $a1, 12($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 8($sp) -move $t0, $sp -lw $t1, 12($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 8($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 36($sp) -lw $t0, 8($sp) -lw $a0, 16($t0) -bnez $a0, label_14 -la $t0, data_4 -sw $t0, 60($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 64($sp) -move $t0, $sp -lw $t1, 60($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 64($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 68($sp) -move $t0, $sp -lw $t1, 64($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 504($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_equals -sw $a1, 48($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 44($sp) -move $t0, $sp -lw $t1, 48($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 44($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 72($sp) -lw $t0, 44($sp) -lw $a0, 16($t0) -bnez $a0, label_15 -la $t0, data_5 -sw $t0, 96($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 100($sp) -move $t0, $sp -lw $t1, 96($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 100($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 104($sp) -move $t0, $sp -lw $t1, 100($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 504($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_equals -sw $a1, 84($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 80($sp) -move $t0, $sp -lw $t1, 84($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 80($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 108($sp) -lw $t0, 80($sp) -lw $a0, 16($t0) -bnez $a0, label_16 -la $t0, data_6 -sw $t0, 132($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 136($sp) -move $t0, $sp -lw $t1, 132($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 136($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 140($sp) -move $t0, $sp -lw $t1, 136($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 504($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_equals -sw $a1, 120($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 116($sp) -move $t0, $sp -lw $t1, 120($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 116($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 144($sp) -lw $t0, 116($sp) -lw $a0, 16($t0) -bnez $a0, label_17 -la $t0, data_7 -sw $t0, 168($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 172($sp) -move $t0, $sp -lw $t1, 168($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 172($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 176($sp) -move $t0, $sp -lw $t1, 172($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 504($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_equals -sw $a1, 156($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 152($sp) -move $t0, $sp -lw $t1, 156($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 152($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 180($sp) -lw $t0, 152($sp) -lw $a0, 16($t0) -bnez $a0, label_18 -la $t0, data_8 -sw $t0, 204($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 208($sp) -move $t0, $sp -lw $t1, 204($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 208($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 212($sp) -move $t0, $sp -lw $t1, 208($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 504($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_equals -sw $a1, 192($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 188($sp) -move $t0, $sp -lw $t1, 192($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 188($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 216($sp) -lw $t0, 188($sp) -lw $a0, 16($t0) -bnez $a0, label_19 -la $t0, data_9 -sw $t0, 240($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 244($sp) -move $t0, $sp -lw $t1, 240($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 244($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 248($sp) -move $t0, $sp -lw $t1, 244($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 504($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_equals -sw $a1, 228($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 224($sp) -move $t0, $sp -lw $t1, 228($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 224($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 252($sp) -lw $t0, 224($sp) -lw $a0, 16($t0) -bnez $a0, label_20 -la $t0, data_10 -sw $t0, 276($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 280($sp) -move $t0, $sp -lw $t1, 276($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 280($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 284($sp) -move $t0, $sp -lw $t1, 280($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 504($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_equals -sw $a1, 264($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 260($sp) -move $t0, $sp -lw $t1, 264($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 260($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 288($sp) -lw $t0, 260($sp) -lw $a0, 16($t0) -bnez $a0, label_21 -la $t0, data_11 -sw $t0, 312($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 316($sp) -move $t0, $sp -lw $t1, 312($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 316($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 320($sp) -move $t0, $sp -lw $t1, 316($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 504($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_equals -sw $a1, 300($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 296($sp) -move $t0, $sp -lw $t1, 300($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 296($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 324($sp) -lw $t0, 296($sp) -lw $a0, 16($t0) -bnez $a0, label_22 -la $t0, data_12 -sw $t0, 348($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 352($sp) -move $t0, $sp -lw $t1, 348($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 352($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 356($sp) -move $t0, $sp -lw $t1, 352($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 504($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_equals -sw $a1, 336($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 332($sp) -move $t0, $sp -lw $t1, 336($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 332($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 360($sp) -lw $t0, 332($sp) -lw $a0, 16($t0) -bnez $a0, label_23 -move $t0, $sp -lw $t1, 500($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 500($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 0($t2) -jal $t3 -sw $a1, 364($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 368($sp) -li $t0, 0 -sw $t0, 372($sp) -move $t0, $sp -lw $t1, 372($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 368($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 376($sp) -lw $t1, 368($sp) -sw $t1, 328($sp) -b label_24 -label_23: -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 380($sp) -li $t0, 9 -sw $t0, 384($sp) -move $t0, $sp -lw $t1, 384($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 380($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 388($sp) -lw $t1, 380($sp) -sw $t1, 328($sp) -label_24: -lw $t1, 328($sp) -sw $t1, 292($sp) -b label_25 -label_22: -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 392($sp) -li $t0, 8 -sw $t0, 396($sp) -move $t0, $sp -lw $t1, 396($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 392($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 400($sp) -lw $t1, 392($sp) -sw $t1, 292($sp) -label_25: -lw $t1, 292($sp) -sw $t1, 256($sp) -b label_26 -label_21: -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 404($sp) -li $t0, 7 -sw $t0, 408($sp) -move $t0, $sp -lw $t1, 408($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 404($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 412($sp) -lw $t1, 404($sp) -sw $t1, 256($sp) -label_26: -lw $t1, 256($sp) -sw $t1, 220($sp) -b label_27 -label_20: -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 416($sp) -li $t0, 6 -sw $t0, 420($sp) -move $t0, $sp -lw $t1, 420($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 416($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 424($sp) -lw $t1, 416($sp) -sw $t1, 220($sp) -label_27: -lw $t1, 220($sp) -sw $t1, 184($sp) -b label_28 -label_19: -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 428($sp) -li $t0, 5 -sw $t0, 432($sp) -move $t0, $sp -lw $t1, 432($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 428($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 436($sp) -lw $t1, 428($sp) -sw $t1, 184($sp) -label_28: -lw $t1, 184($sp) -sw $t1, 148($sp) -b label_29 -label_18: -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 440($sp) -li $t0, 4 -sw $t0, 444($sp) -move $t0, $sp -lw $t1, 444($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 440($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 448($sp) -lw $t1, 440($sp) -sw $t1, 148($sp) -label_29: -lw $t1, 148($sp) -sw $t1, 112($sp) -b label_30 -label_17: -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 452($sp) -li $t0, 3 -sw $t0, 456($sp) -move $t0, $sp -lw $t1, 456($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 452($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 460($sp) -lw $t1, 452($sp) -sw $t1, 112($sp) -label_30: -lw $t1, 112($sp) -sw $t1, 76($sp) -b label_31 -label_16: -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 464($sp) -li $t0, 2 -sw $t0, 468($sp) -move $t0, $sp -lw $t1, 468($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 464($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 472($sp) -lw $t1, 464($sp) -sw $t1, 76($sp) -label_31: -lw $t1, 76($sp) -sw $t1, 40($sp) -b label_32 -label_15: -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 476($sp) -li $t0, 1 -sw $t0, 480($sp) -move $t0, $sp -lw $t1, 480($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 476($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 484($sp) -lw $t1, 476($sp) -sw $t1, 40($sp) -label_32: -lw $t1, 40($sp) -sw $t1, 4($sp) -b label_33 -label_14: -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 488($sp) -li $t0, 0 -sw $t0, 492($sp) -move $t0, $sp -lw $t1, 492($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 488($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 496($sp) -lw $t1, 488($sp) -sw $t1, 4($sp) -label_33: -lw $a1, 4($sp) -lw $ra, 0($sp) -addi $sp, $sp, 508 -jr $ra -A2I.i2c: -addi $sp, $sp, -496 -addi $sp, $sp, -4 -sw $ra, 0($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 24($sp) -li $t0, 0 -sw $t0, 28($sp) -move $t0, $sp -lw $t1, 28($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 24($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 32($sp) -lw $t0, 504($sp) -lw $t1, 16($t0) -sw $t1, 16($sp) -lw $t0, 24($sp) -lw $t1, 16($t0) -sw $t1, 20($sp) -lw $a0, 16($sp) -lw $t1, 20($sp) -seq $a0, $a0, $t1 -sw $a0, 12($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 8($sp) -move $t0, $sp -lw $t1, 12($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 8($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 36($sp) -lw $t0, 8($sp) -lw $a0, 16($t0) -bnez $a0, label_34 -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 60($sp) -li $t0, 1 -sw $t0, 64($sp) -move $t0, $sp -lw $t1, 64($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 60($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 68($sp) -lw $t0, 504($sp) -lw $t1, 16($t0) -sw $t1, 52($sp) -lw $t0, 60($sp) -lw $t1, 16($t0) -sw $t1, 56($sp) -lw $a0, 52($sp) -lw $t1, 56($sp) -seq $a0, $a0, $t1 -sw $a0, 48($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 44($sp) -move $t0, $sp -lw $t1, 48($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 44($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 72($sp) -lw $t0, 44($sp) -lw $a0, 16($t0) -bnez $a0, label_35 -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 96($sp) -li $t0, 2 -sw $t0, 100($sp) -move $t0, $sp -lw $t1, 100($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 96($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 104($sp) -lw $t0, 504($sp) -lw $t1, 16($t0) -sw $t1, 88($sp) -lw $t0, 96($sp) -lw $t1, 16($t0) -sw $t1, 92($sp) -lw $a0, 88($sp) -lw $t1, 92($sp) -seq $a0, $a0, $t1 -sw $a0, 84($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 80($sp) -move $t0, $sp -lw $t1, 84($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 80($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 108($sp) -lw $t0, 80($sp) -lw $a0, 16($t0) -bnez $a0, label_36 -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 132($sp) -li $t0, 3 -sw $t0, 136($sp) -move $t0, $sp -lw $t1, 136($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 132($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 140($sp) -lw $t0, 504($sp) -lw $t1, 16($t0) -sw $t1, 124($sp) -lw $t0, 132($sp) -lw $t1, 16($t0) -sw $t1, 128($sp) -lw $a0, 124($sp) -lw $t1, 128($sp) -seq $a0, $a0, $t1 -sw $a0, 120($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 116($sp) -move $t0, $sp -lw $t1, 120($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 116($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 144($sp) -lw $t0, 116($sp) -lw $a0, 16($t0) -bnez $a0, label_37 -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 168($sp) -li $t0, 4 -sw $t0, 172($sp) -move $t0, $sp -lw $t1, 172($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 168($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 176($sp) -lw $t0, 504($sp) -lw $t1, 16($t0) -sw $t1, 160($sp) -lw $t0, 168($sp) -lw $t1, 16($t0) -sw $t1, 164($sp) -lw $a0, 160($sp) -lw $t1, 164($sp) -seq $a0, $a0, $t1 -sw $a0, 156($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 152($sp) -move $t0, $sp -lw $t1, 156($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 152($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 180($sp) -lw $t0, 152($sp) -lw $a0, 16($t0) -bnez $a0, label_38 -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 204($sp) -li $t0, 5 -sw $t0, 208($sp) -move $t0, $sp -lw $t1, 208($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 204($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 212($sp) -lw $t0, 504($sp) -lw $t1, 16($t0) -sw $t1, 196($sp) -lw $t0, 204($sp) -lw $t1, 16($t0) -sw $t1, 200($sp) -lw $a0, 196($sp) -lw $t1, 200($sp) -seq $a0, $a0, $t1 -sw $a0, 192($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 188($sp) -move $t0, $sp -lw $t1, 192($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 188($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 216($sp) -lw $t0, 188($sp) -lw $a0, 16($t0) -bnez $a0, label_39 -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 240($sp) -li $t0, 6 -sw $t0, 244($sp) -move $t0, $sp -lw $t1, 244($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 240($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 248($sp) -lw $t0, 504($sp) -lw $t1, 16($t0) -sw $t1, 232($sp) -lw $t0, 240($sp) -lw $t1, 16($t0) -sw $t1, 236($sp) -lw $a0, 232($sp) -lw $t1, 236($sp) -seq $a0, $a0, $t1 -sw $a0, 228($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 224($sp) -move $t0, $sp -lw $t1, 228($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 224($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 252($sp) -lw $t0, 224($sp) -lw $a0, 16($t0) -bnez $a0, label_40 -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 276($sp) -li $t0, 7 -sw $t0, 280($sp) -move $t0, $sp -lw $t1, 280($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 276($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 284($sp) -lw $t0, 504($sp) -lw $t1, 16($t0) -sw $t1, 268($sp) -lw $t0, 276($sp) -lw $t1, 16($t0) -sw $t1, 272($sp) -lw $a0, 268($sp) -lw $t1, 272($sp) -seq $a0, $a0, $t1 -sw $a0, 264($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 260($sp) -move $t0, $sp -lw $t1, 264($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 260($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 288($sp) -lw $t0, 260($sp) -lw $a0, 16($t0) -bnez $a0, label_41 -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 312($sp) -li $t0, 8 -sw $t0, 316($sp) -move $t0, $sp -lw $t1, 316($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 312($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 320($sp) -lw $t0, 504($sp) -lw $t1, 16($t0) -sw $t1, 304($sp) -lw $t0, 312($sp) -lw $t1, 16($t0) -sw $t1, 308($sp) -lw $a0, 304($sp) -lw $t1, 308($sp) -seq $a0, $a0, $t1 -sw $a0, 300($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 296($sp) -move $t0, $sp -lw $t1, 300($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 296($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 324($sp) -lw $t0, 296($sp) -lw $a0, 16($t0) -bnez $a0, label_42 -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 348($sp) -li $t0, 9 -sw $t0, 352($sp) -move $t0, $sp -lw $t1, 352($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 348($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 356($sp) -lw $t0, 504($sp) -lw $t1, 16($t0) -sw $t1, 340($sp) -lw $t0, 348($sp) -lw $t1, 16($t0) -sw $t1, 344($sp) -lw $a0, 340($sp) -lw $t1, 344($sp) -seq $a0, $a0, $t1 -sw $a0, 336($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 332($sp) -move $t0, $sp -lw $t1, 336($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 332($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 360($sp) -lw $t0, 332($sp) -lw $a0, 16($t0) -bnez $a0, label_43 -move $t0, $sp -lw $t1, 500($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 500($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 0($t2) -jal $t3 -sw $a1, 364($sp) -la $t0, empty_str -sw $t0, 368($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 372($sp) -move $t0, $sp -lw $t1, 368($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 372($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 376($sp) -lw $t1, 372($sp) -sw $t1, 328($sp) -b label_44 -label_43: -la $t0, data_12 -sw $t0, 380($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 384($sp) -move $t0, $sp -lw $t1, 380($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 384($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 388($sp) -lw $t1, 384($sp) -sw $t1, 328($sp) -label_44: -lw $t1, 328($sp) -sw $t1, 292($sp) -b label_45 -label_42: -la $t0, data_11 -sw $t0, 392($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 396($sp) -move $t0, $sp -lw $t1, 392($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 396($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 400($sp) -lw $t1, 396($sp) -sw $t1, 292($sp) -label_45: -lw $t1, 292($sp) -sw $t1, 256($sp) -b label_46 -label_41: -la $t0, data_10 -sw $t0, 404($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 408($sp) -move $t0, $sp -lw $t1, 404($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 408($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 412($sp) -lw $t1, 408($sp) -sw $t1, 256($sp) -label_46: -lw $t1, 256($sp) -sw $t1, 220($sp) -b label_47 -label_40: -la $t0, data_9 -sw $t0, 416($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 420($sp) -move $t0, $sp -lw $t1, 416($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 420($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 424($sp) -lw $t1, 420($sp) -sw $t1, 220($sp) -label_47: -lw $t1, 220($sp) -sw $t1, 184($sp) -b label_48 -label_39: -la $t0, data_8 -sw $t0, 428($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 432($sp) -move $t0, $sp -lw $t1, 428($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 432($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 436($sp) -lw $t1, 432($sp) -sw $t1, 184($sp) -label_48: -lw $t1, 184($sp) -sw $t1, 148($sp) -b label_49 -label_38: -la $t0, data_7 -sw $t0, 440($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 444($sp) -move $t0, $sp -lw $t1, 440($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 444($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 448($sp) -lw $t1, 444($sp) -sw $t1, 148($sp) -label_49: -lw $t1, 148($sp) -sw $t1, 112($sp) -b label_50 -label_37: -la $t0, data_6 -sw $t0, 452($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 456($sp) -move $t0, $sp -lw $t1, 452($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 456($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 460($sp) -lw $t1, 456($sp) -sw $t1, 112($sp) -label_50: -lw $t1, 112($sp) -sw $t1, 76($sp) -b label_51 -label_36: -la $t0, data_5 -sw $t0, 464($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 468($sp) -move $t0, $sp -lw $t1, 464($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 468($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 472($sp) -lw $t1, 468($sp) -sw $t1, 76($sp) -label_51: -lw $t1, 76($sp) -sw $t1, 40($sp) -b label_52 -label_35: -la $t0, data_4 -sw $t0, 476($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 480($sp) -move $t0, $sp -lw $t1, 476($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 480($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 484($sp) -lw $t1, 480($sp) -sw $t1, 40($sp) -label_52: -lw $t1, 40($sp) -sw $t1, 4($sp) -b label_53 -label_34: -la $t0, data_3 -sw $t0, 488($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 492($sp) -move $t0, $sp -lw $t1, 488($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 492($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 496($sp) -lw $t1, 492($sp) -sw $t1, 4($sp) -label_53: -lw $a1, 4($sp) -lw $ra, 0($sp) -addi $sp, $sp, 508 -jr $ra -A2I.a2i: -addi $sp, $sp, -312 -addi $sp, $sp, -4 -sw $ra, 0($sp) -move $t0, $sp -lw $t1, 320($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 320($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 24($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 28($sp) -li $t0, 0 -sw $t0, 32($sp) -move $t0, $sp -lw $t1, 32($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 28($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 36($sp) -lw $t0, 24($sp) -lw $t1, 16($t0) -sw $t1, 16($sp) -lw $t0, 28($sp) -lw $t1, 16($t0) -sw $t1, 20($sp) -lw $a0, 16($sp) -lw $t1, 20($sp) -seq $a0, $a0, $t1 -sw $a0, 12($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 8($sp) -move $t0, $sp -lw $t1, 12($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 8($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 40($sp) -lw $t0, 8($sp) -lw $a0, 16($t0) -bnez $a0, label_54 -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 68($sp) -li $t0, 1 -sw $t0, 72($sp) -move $t0, $sp -lw $t1, 72($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 68($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 76($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 80($sp) -li $t0, 0 -sw $t0, 84($sp) -move $t0, $sp -lw $t1, 84($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 80($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 88($sp) -move $t0, $sp -lw $t1, 68($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 80($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 320($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 320($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 20($t2) -jal $t3 -sw $a1, 64($sp) -la $t0, data_13 -sw $t0, 92($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 96($sp) -move $t0, $sp -lw $t1, 92($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 96($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 100($sp) -move $t0, $sp -lw $t1, 96($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 64($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_equals -sw $a1, 52($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 48($sp) -move $t0, $sp -lw $t1, 52($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 48($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 104($sp) -lw $t0, 48($sp) -lw $a0, 16($t0) -bnez $a0, label_55 -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 132($sp) -li $t0, 1 -sw $t0, 136($sp) -move $t0, $sp -lw $t1, 136($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 132($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 140($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 144($sp) -li $t0, 0 -sw $t0, 148($sp) -move $t0, $sp -lw $t1, 148($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 144($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 152($sp) -move $t0, $sp -lw $t1, 132($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 144($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 320($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 320($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 20($t2) -jal $t3 -sw $a1, 128($sp) -la $t0, data_14 -sw $t0, 156($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 160($sp) -move $t0, $sp -lw $t1, 156($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 160($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 164($sp) -move $t0, $sp -lw $t1, 160($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 128($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_equals -sw $a1, 116($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 112($sp) -move $t0, $sp -lw $t1, 116($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 112($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 168($sp) -lw $t0, 112($sp) -lw $a0, 16($t0) -bnez $a0, label_56 -move $t0, $sp -lw $t1, 320($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 316($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 316($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 24($t2) -jal $t3 -sw $a1, 172($sp) -lw $t1, 172($sp) -sw $t1, 108($sp) -b label_57 -label_56: -move $t0, $sp -lw $t1, 320($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 320($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 200($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 204($sp) -li $t0, 1 -sw $t0, 208($sp) -move $t0, $sp -lw $t1, 208($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 204($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 212($sp) -lw $t0, 200($sp) -lw $t1, 16($t0) -sw $t1, 192($sp) -lw $t0, 204($sp) -lw $t1, 16($t0) -sw $t1, 196($sp) -lw $a0, 192($sp) -lw $t1, 196($sp) -sub $a0, $a0, $t1 -sw $a0, 188($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 184($sp) -move $t0, $sp -lw $t1, 188($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 184($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 216($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 220($sp) -li $t0, 1 -sw $t0, 224($sp) -move $t0, $sp -lw $t1, 224($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 220($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 228($sp) -move $t0, $sp -lw $t1, 184($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 220($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 320($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 320($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 20($t2) -jal $t3 -sw $a1, 180($sp) -move $t0, $sp -lw $t1, 180($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 316($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 316($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 24($t2) -jal $t3 -sw $a1, 176($sp) -lw $t1, 176($sp) -sw $t1, 108($sp) -label_57: -lw $t1, 108($sp) -sw $t1, 44($sp) -b label_58 -label_55: -move $t0, $sp -lw $t1, 320($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 320($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 268($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 272($sp) -li $t0, 1 -sw $t0, 276($sp) -move $t0, $sp -lw $t1, 276($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 272($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 280($sp) -lw $t0, 268($sp) -lw $t1, 16($t0) -sw $t1, 260($sp) -lw $t0, 272($sp) -lw $t1, 16($t0) -sw $t1, 264($sp) -lw $a0, 260($sp) -lw $t1, 264($sp) -sub $a0, $a0, $t1 -sw $a0, 256($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 252($sp) -move $t0, $sp -lw $t1, 256($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 252($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 284($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 288($sp) -li $t0, 1 -sw $t0, 292($sp) -move $t0, $sp -lw $t1, 292($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 288($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 296($sp) -move $t0, $sp -lw $t1, 252($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 288($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 320($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 320($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 20($t2) -jal $t3 -sw $a1, 248($sp) -move $t0, $sp -lw $t1, 248($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 316($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 316($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 24($t2) -jal $t3 -sw $a1, 244($sp) -lw $t0, 244($sp) -lw $t1, 16($t0) -sw $t1, 240($sp) -lw $t1, 240($sp) -neg $a0, $t1 -sw $a0, 236($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 232($sp) -move $t0, $sp -lw $t1, 236($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 232($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 300($sp) -lw $t1, 232($sp) -sw $t1, 44($sp) -label_58: -lw $t1, 44($sp) -sw $t1, 4($sp) -b label_59 -label_54: -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 304($sp) -li $t0, 0 -sw $t0, 308($sp) -move $t0, $sp -lw $t1, 308($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 304($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 312($sp) -lw $t1, 304($sp) -sw $t1, 4($sp) -label_59: -lw $a1, 4($sp) -lw $ra, 0($sp) -addi $sp, $sp, 324 -jr $ra -A2I.a2i_aux: -addi $sp, $sp, -188 -addi $sp, $sp, -4 -sw $ra, 0($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 4($sp) -li $t0, 0 -sw $t0, 8($sp) -move $t0, $sp -lw $t1, 8($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 4($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 12($sp) -lw $t1, 4($sp) -sw $t1, 16($sp) -move $t0, $sp -lw $t1, 196($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 196($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 20($sp) -lw $t1, 20($sp) -sw $t1, 24($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 28($sp) -li $t0, 0 -sw $t0, 32($sp) -move $t0, $sp -lw $t1, 32($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 28($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 36($sp) -lw $t1, 28($sp) -sw $t1, 40($sp) -label_60: -lw $t0, 40($sp) -lw $t1, 16($t0) -sw $t1, 56($sp) -lw $t0, 24($sp) -lw $t1, 16($t0) -sw $t1, 60($sp) -lw $a0, 56($sp) -lw $t1, 60($sp) -slt $a0, $a0, $t1 -sw $a0, 52($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 48($sp) -move $t0, $sp -lw $t1, 52($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 48($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 64($sp) -lw $t0, 48($sp) -lw $a0, 16($t0) -bnez $a0, label_61 -b label_62 -label_61: -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 100($sp) -li $t0, 10 -sw $t0, 104($sp) -move $t0, $sp -lw $t1, 104($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 100($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 108($sp) -lw $t0, 16($sp) -lw $t1, 16($t0) -sw $t1, 92($sp) -lw $t0, 100($sp) -lw $t1, 16($t0) -sw $t1, 96($sp) -lw $a0, 92($sp) -lw $t1, 96($sp) -mul $a0, $a0, $t1 -sw $a0, 88($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 84($sp) -move $t0, $sp -lw $t1, 88($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 84($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 112($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 124($sp) -li $t0, 1 -sw $t0, 128($sp) -move $t0, $sp -lw $t1, 128($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 124($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 132($sp) -move $t0, $sp -lw $t1, 124($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 40($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 196($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 196($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 20($t2) -jal $t3 -sw $a1, 120($sp) -move $t0, $sp -lw $t1, 120($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 192($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 192($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 116($sp) -lw $t0, 84($sp) -lw $t1, 16($t0) -sw $t1, 76($sp) -lw $t0, 116($sp) -lw $t1, 16($t0) -sw $t1, 80($sp) -lw $a0, 76($sp) -lw $t1, 80($sp) -add $a0, $a0, $t1 -sw $a0, 72($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 68($sp) -move $t0, $sp -lw $t1, 72($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 68($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 136($sp) -lw $t1, 68($sp) -sw $t1, 16($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 160($sp) -li $t0, 1 -sw $t0, 164($sp) -move $t0, $sp -lw $t1, 164($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 160($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 168($sp) -lw $t0, 40($sp) -lw $t1, 16($t0) -sw $t1, 152($sp) -lw $t0, 160($sp) -lw $t1, 16($t0) -sw $t1, 156($sp) -lw $a0, 152($sp) -lw $t1, 156($sp) -add $a0, $a0, $t1 -sw $a0, 148($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 144($sp) -move $t0, $sp -lw $t1, 148($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 144($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 172($sp) -lw $t1, 144($sp) -sw $t1, 40($sp) -b label_60 -label_62: -lw $t1, 44($sp) -sw $t1, 180($sp) -lw $t1, 180($sp) -sw $t1, 184($sp) -lw $t1, 16($sp) -sw $t1, 188($sp) -lw $a1, 188($sp) -lw $ra, 0($sp) -addi $sp, $sp, 200 -jr $ra -A2I.i2a: -addi $sp, $sp, -156 -addi $sp, $sp, -4 -sw $ra, 0($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 24($sp) -li $t0, 0 -sw $t0, 28($sp) -move $t0, $sp -lw $t1, 28($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 24($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 32($sp) -lw $t0, 164($sp) -lw $t1, 16($t0) -sw $t1, 16($sp) -lw $t0, 24($sp) -lw $t1, 16($t0) -sw $t1, 20($sp) -lw $a0, 16($sp) -lw $t1, 20($sp) -seq $a0, $a0, $t1 -sw $a0, 12($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 8($sp) -move $t0, $sp -lw $t1, 12($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 8($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 36($sp) -lw $t0, 8($sp) -lw $a0, 16($t0) -bnez $a0, label_63 -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 60($sp) -li $t0, 0 -sw $t0, 64($sp) -move $t0, $sp -lw $t1, 64($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 60($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 68($sp) -lw $t0, 60($sp) -lw $t1, 16($t0) -sw $t1, 52($sp) -lw $t0, 164($sp) -lw $t1, 16($t0) -sw $t1, 56($sp) -lw $a0, 52($sp) -lw $t1, 56($sp) -slt $a0, $a0, $t1 -sw $a0, 48($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 44($sp) -move $t0, $sp -lw $t1, 48($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 44($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 72($sp) -lw $t0, 44($sp) -lw $a0, 16($t0) -bnez $a0, label_64 -la $t0, data_13 -sw $t0, 80($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 84($sp) -move $t0, $sp -lw $t1, 80($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 84($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 88($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 124($sp) -li $t0, 1 -sw $t0, 128($sp) -move $t0, $sp -lw $t1, 128($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 124($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 132($sp) -lw $t0, 124($sp) -lw $t1, 16($t0) -sw $t1, 120($sp) -lw $t1, 120($sp) -neg $a0, $t1 -sw $a0, 116($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 112($sp) -move $t0, $sp -lw $t1, 116($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 112($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 136($sp) -lw $t0, 164($sp) -lw $t1, 16($t0) -sw $t1, 104($sp) -lw $t0, 112($sp) -lw $t1, 16($t0) -sw $t1, 108($sp) -lw $a0, 104($sp) -lw $t1, 108($sp) -mul $a0, $a0, $t1 -sw $a0, 100($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 96($sp) -move $t0, $sp -lw $t1, 100($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 96($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 140($sp) -move $t0, $sp -lw $t1, 96($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 160($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 160($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 32($t2) -jal $t3 -sw $a1, 92($sp) -move $t0, $sp -lw $t1, 92($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 84($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 84($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 16($t2) -jal $t3 -sw $a1, 76($sp) -lw $t1, 76($sp) -sw $t1, 40($sp) -b label_65 -label_64: -move $t0, $sp -lw $t1, 164($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 160($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 160($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 32($t2) -jal $t3 -sw $a1, 144($sp) -lw $t1, 144($sp) -sw $t1, 40($sp) -label_65: -lw $t1, 40($sp) -sw $t1, 4($sp) -b label_66 -label_63: -la $t0, data_3 -sw $t0, 148($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 152($sp) -move $t0, $sp -lw $t1, 148($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 152($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 156($sp) -lw $t1, 152($sp) -sw $t1, 4($sp) -label_66: -lw $a1, 4($sp) -lw $ra, 0($sp) -addi $sp, $sp, 168 -jr $ra -A2I.i2a_aux: -addi $sp, $sp, -152 -addi $sp, $sp, -4 -sw $ra, 0($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 24($sp) -li $t0, 0 -sw $t0, 28($sp) -move $t0, $sp -lw $t1, 28($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 24($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 32($sp) -lw $t0, 160($sp) -lw $t1, 16($t0) -sw $t1, 16($sp) -lw $t0, 24($sp) -lw $t1, 16($t0) -sw $t1, 20($sp) -lw $a0, 16($sp) -lw $t1, 20($sp) -seq $a0, $a0, $t1 -sw $a0, 12($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 8($sp) -move $t0, $sp -lw $t1, 12($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 8($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 36($sp) -lw $t0, 8($sp) -lw $a0, 16($t0) -bnez $a0, label_67 -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 56($sp) -li $t0, 10 -sw $t0, 60($sp) -move $t0, $sp -lw $t1, 60($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 56($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 64($sp) -lw $t0, 160($sp) -lw $t1, 16($t0) -sw $t1, 48($sp) -lw $t0, 56($sp) -lw $t1, 16($t0) -sw $t1, 52($sp) -lw $a0, 48($sp) -lw $t1, 52($sp) -beq $t1, 0, div_zero_error -div $a0, $a0, $t1 -sw $a0, 44($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 40($sp) -move $t0, $sp -lw $t1, 44($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 40($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 68($sp) -lw $t1, 40($sp) -sw $t1, 72($sp) -move $t0, $sp -lw $t1, 72($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 156($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 156($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 32($t2) -jal $t3 -sw $a1, 80($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 120($sp) -li $t0, 10 -sw $t0, 124($sp) -move $t0, $sp -lw $t1, 124($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 120($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 128($sp) -lw $t0, 72($sp) -lw $t1, 16($t0) -sw $t1, 112($sp) -lw $t0, 120($sp) -lw $t1, 16($t0) -sw $t1, 116($sp) -lw $a0, 112($sp) -lw $t1, 116($sp) -mul $a0, $a0, $t1 -sw $a0, 108($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 104($sp) -move $t0, $sp -lw $t1, 108($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 104($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 132($sp) -lw $t0, 160($sp) -lw $t1, 16($t0) -sw $t1, 96($sp) -lw $t0, 104($sp) -lw $t1, 16($t0) -sw $t1, 100($sp) -lw $a0, 96($sp) -lw $t1, 100($sp) -sub $a0, $a0, $t1 -sw $a0, 92($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 88($sp) -move $t0, $sp -lw $t1, 92($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 88($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 136($sp) -move $t0, $sp -lw $t1, 88($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 156($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 156($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 16($t2) -jal $t3 -sw $a1, 84($sp) -move $t0, $sp -lw $t1, 84($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 80($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 80($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 16($t2) -jal $t3 -sw $a1, 76($sp) -lw $t1, 76($sp) -sw $t1, 140($sp) -lw $t1, 140($sp) -sw $t1, 4($sp) -b label_68 -label_67: -la $t0, empty_str -sw $t0, 144($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 148($sp) -move $t0, $sp -lw $t1, 144($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 148($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 152($sp) -lw $t1, 148($sp) -sw $t1, 4($sp) -label_68: -lw $a1, 4($sp) -lw $ra, 0($sp) -addi $sp, $sp, 164 -jr $ra -Main_init: -addi $sp, $sp, -28 -addi $sp, $sp, -4 -sw $ra, 0($sp) -move $t0, $sp -lw $t1, 32($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal IO_init -sw $a1, 4($sp) -move $a1, $zero -la $t0, empty_str -sw $t0, 8($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 12($sp) -move $t0, $sp -lw $t1, 8($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 12($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 16($sp) -lw $t0, 32($sp) -lw $t1, 12($sp) -sw $t1, 16($t0) -lw $t0, 32($sp) -la $t1, void -sw $t1, 20($t0) -lw $t0, 32($sp) -la $t1, void -sw $t1, 24($t0) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 20($sp) -li $t0, 1 -sw $t0, 24($sp) -move $t0, $sp -lw $t1, 24($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 20($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 28($sp) -lw $t0, 32($sp) -lw $t1, 20($sp) -sw $t1, 28($t0) -lw $ra, 0($sp) -addi $sp, $sp, 36 -jr $ra -Main.menu: -addi $sp, $sp, -356 -addi $sp, $sp, -4 -sw $ra, 0($sp) -la $t0, data_15 -sw $t0, 8($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 12($sp) -move $t0, $sp -lw $t1, 8($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 12($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 16($sp) -move $t0, $sp -lw $t1, 12($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 4($sp) -lw $t0, 360($sp) -lw $t1, 20($t0) -sw $t1, 304($sp) -move $t0, $sp -lw $t1, 304($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 48($t2) -jal $t3 -sw $a1, 20($sp) -la $t0, data_16 -sw $t0, 32($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 36($sp) -move $t0, $sp -lw $t1, 32($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 36($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 40($sp) -move $t0, $sp -lw $t1, 36($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 28($sp) -la $t0, data_17 -sw $t0, 48($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 52($sp) -move $t0, $sp -lw $t1, 48($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 52($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 56($sp) -move $t0, $sp -lw $t1, 52($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 44($sp) -lw $t0, 360($sp) -lw $t1, 20($t0) -sw $t1, 304($sp) -move $t0, $sp -lw $t1, 304($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 48($t2) -jal $t3 -sw $a1, 60($sp) -la $t0, data_18 -sw $t0, 72($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 76($sp) -move $t0, $sp -lw $t1, 72($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 76($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 80($sp) -move $t0, $sp -lw $t1, 76($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 68($sp) -la $t0, data_19 -sw $t0, 88($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 92($sp) -move $t0, $sp -lw $t1, 88($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 92($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 96($sp) -move $t0, $sp -lw $t1, 92($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 84($sp) -lw $t0, 360($sp) -lw $t1, 20($t0) -sw $t1, 304($sp) -move $t0, $sp -lw $t1, 304($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 48($t2) -jal $t3 -sw $a1, 100($sp) -la $t0, data_20 -sw $t0, 112($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 116($sp) -move $t0, $sp -lw $t1, 112($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 116($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 120($sp) -move $t0, $sp -lw $t1, 116($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 108($sp) -la $t0, data_21 -sw $t0, 128($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 132($sp) -move $t0, $sp -lw $t1, 128($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 132($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 136($sp) -move $t0, $sp -lw $t1, 132($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 124($sp) -lw $t0, 360($sp) -lw $t1, 20($t0) -sw $t1, 304($sp) -move $t0, $sp -lw $t1, 304($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 48($t2) -jal $t3 -sw $a1, 140($sp) -la $t0, data_22 -sw $t0, 152($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 156($sp) -move $t0, $sp -lw $t1, 152($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 156($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 160($sp) -move $t0, $sp -lw $t1, 156($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 148($sp) -la $t0, data_23 -sw $t0, 168($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 172($sp) -move $t0, $sp -lw $t1, 168($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 172($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 176($sp) -move $t0, $sp -lw $t1, 172($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 164($sp) -lw $t0, 360($sp) -lw $t1, 20($t0) -sw $t1, 304($sp) -move $t0, $sp -lw $t1, 304($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 48($t2) -jal $t3 -sw $a1, 180($sp) -la $t0, data_24 -sw $t0, 192($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 196($sp) -move $t0, $sp -lw $t1, 192($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 196($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 200($sp) -move $t0, $sp -lw $t1, 196($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 188($sp) -la $t0, data_25 -sw $t0, 208($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 212($sp) -move $t0, $sp -lw $t1, 208($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 212($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 216($sp) -move $t0, $sp -lw $t1, 212($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 204($sp) -lw $t0, 360($sp) -lw $t1, 20($t0) -sw $t1, 304($sp) -move $t0, $sp -lw $t1, 304($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 48($t2) -jal $t3 -sw $a1, 220($sp) -la $t0, data_26 -sw $t0, 232($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 236($sp) -move $t0, $sp -lw $t1, 232($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 236($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 240($sp) -move $t0, $sp -lw $t1, 236($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 228($sp) -la $t0, data_27 -sw $t0, 248($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 252($sp) -move $t0, $sp -lw $t1, 248($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 252($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 256($sp) -move $t0, $sp -lw $t1, 252($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 244($sp) -lw $t0, 360($sp) -lw $t1, 20($t0) -sw $t1, 304($sp) -move $t0, $sp -lw $t1, 304($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 48($t2) -jal $t3 -sw $a1, 260($sp) -la $t0, data_28 -sw $t0, 272($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 276($sp) -move $t0, $sp -lw $t1, 272($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 276($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 280($sp) -move $t0, $sp -lw $t1, 276($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 268($sp) -la $t0, data_29 -sw $t0, 288($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 292($sp) -move $t0, $sp -lw $t1, 288($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 292($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 296($sp) -move $t0, $sp -lw $t1, 292($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 284($sp) -lw $t0, 360($sp) -lw $t1, 20($t0) -sw $t1, 304($sp) -move $t0, $sp -lw $t1, 304($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 48($t2) -jal $t3 -sw $a1, 300($sp) -la $t0, data_30 -sw $t0, 312($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 316($sp) -move $t0, $sp -lw $t1, 312($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 316($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 320($sp) -move $t0, $sp -lw $t1, 316($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 308($sp) -la $t0, data_31 -sw $t0, 328($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 332($sp) -move $t0, $sp -lw $t1, 328($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 332($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 336($sp) -move $t0, $sp -lw $t1, 332($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 324($sp) -la $t0, data_32 -sw $t0, 344($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 348($sp) -move $t0, $sp -lw $t1, 344($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 348($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 352($sp) -move $t0, $sp -lw $t1, 348($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 340($sp) -move $t0, $sp -lw $t1, 360($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 360($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 20($t2) -jal $t3 -sw $a1, 356($sp) -lw $a1, 356($sp) -lw $ra, 0($sp) -addi $sp, $sp, 364 -jr $ra -Main.prompt: -addi $sp, $sp, -36 -addi $sp, $sp, -4 -sw $ra, 0($sp) -la $t0, data_1 -sw $t0, 8($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 12($sp) -move $t0, $sp -lw $t1, 8($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 12($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 16($sp) -move $t0, $sp -lw $t1, 12($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 40($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 40($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 4($sp) -la $t0, data_33 -sw $t0, 24($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 28($sp) -move $t0, $sp -lw $t1, 24($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 28($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 32($sp) -move $t0, $sp -lw $t1, 28($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 40($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 40($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 20($sp) -move $t0, $sp -lw $t1, 40($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 40($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 20($t2) -jal $t3 -sw $a1, 36($sp) -lw $a1, 36($sp) -lw $ra, 0($sp) -addi $sp, $sp, 44 -jr $ra -Main.get_int: -addi $sp, $sp, -32 -addi $sp, $sp, -4 -sw $ra, 0($sp) -li $a0, 16 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 6 -sw $t1, 0($t0) -la $t1, A2I_name -sw $t1, 4($t0) -li $t1, 4 -sw $t1, 8($t0) -la $t1, A2I_methods -sw $t1, 12($t0) -sw $t0, 4($sp) -move $t0, $sp -lw $t1, 4($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal A2I_init -sw $a1, 8($sp) -lw $t1, 4($sp) -sw $t1, 12($sp) -move $t0, $sp -lw $t1, 36($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 36($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 32($t2) -jal $t3 -sw $a1, 16($sp) -lw $t1, 16($sp) -sw $t1, 20($sp) -move $t0, $sp -lw $t1, 20($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 12($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 12($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 20($t2) -jal $t3 -sw $a1, 24($sp) -lw $t1, 24($sp) -sw $t1, 28($sp) -lw $t1, 28($sp) -sw $t1, 32($sp) -lw $a1, 32($sp) -lw $ra, 0($sp) -addi $sp, $sp, 40 -jr $ra -Main.is_even: -addi $sp, $sp, -196 -addi $sp, $sp, -4 -sw $ra, 0($sp) -lw $t1, 204($sp) -sw $t1, 4($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 28($sp) -li $t0, 0 -sw $t0, 32($sp) -move $t0, $sp -lw $t1, 32($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 28($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 36($sp) -lw $t0, 4($sp) -lw $t1, 16($t0) -sw $t1, 20($sp) -lw $t0, 28($sp) -lw $t1, 16($t0) -sw $t1, 24($sp) -lw $a0, 20($sp) -lw $t1, 24($sp) -slt $a0, $a0, $t1 -sw $a0, 16($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 12($sp) -move $t0, $sp -lw $t1, 16($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 12($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 40($sp) -lw $t0, 12($sp) -lw $a0, 16($t0) -bnez $a0, label_69 -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 64($sp) -li $t0, 0 -sw $t0, 68($sp) -move $t0, $sp -lw $t1, 68($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 64($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 72($sp) -lw $t0, 64($sp) -lw $t1, 16($t0) -sw $t1, 56($sp) -lw $t0, 4($sp) -lw $t1, 16($t0) -sw $t1, 60($sp) -lw $a0, 56($sp) -lw $t1, 60($sp) -seq $a0, $a0, $t1 -sw $a0, 52($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 48($sp) -move $t0, $sp -lw $t1, 52($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 48($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 76($sp) -lw $t0, 48($sp) -lw $a0, 16($t0) -bnez $a0, label_70 -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 100($sp) -li $t0, 1 -sw $t0, 104($sp) -move $t0, $sp -lw $t1, 104($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 100($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 108($sp) -lw $t0, 100($sp) -lw $t1, 16($t0) -sw $t1, 92($sp) -lw $t0, 4($sp) -lw $t1, 16($t0) -sw $t1, 96($sp) -lw $a0, 92($sp) -lw $t1, 96($sp) -seq $a0, $a0, $t1 -sw $a0, 88($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 84($sp) -move $t0, $sp -lw $t1, 88($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 84($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 112($sp) -lw $t0, 84($sp) -lw $a0, 16($t0) -bnez $a0, label_71 -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 136($sp) -li $t0, 2 -sw $t0, 140($sp) -move $t0, $sp -lw $t1, 140($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 136($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 144($sp) -lw $t0, 4($sp) -lw $t1, 16($t0) -sw $t1, 128($sp) -lw $t0, 136($sp) -lw $t1, 16($t0) -sw $t1, 132($sp) -lw $a0, 128($sp) -lw $t1, 132($sp) -sub $a0, $a0, $t1 -sw $a0, 124($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 120($sp) -move $t0, $sp -lw $t1, 124($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 120($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 148($sp) -move $t0, $sp -lw $t1, 120($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 200($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 200($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 40($t2) -jal $t3 -sw $a1, 116($sp) -lw $t1, 116($sp) -sw $t1, 80($sp) -b label_72 -label_71: -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 152($sp) -li $t0, 0 -sw $t0, 156($sp) -move $t0, $sp -lw $t1, 156($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 152($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 160($sp) -lw $t1, 152($sp) -sw $t1, 80($sp) -label_72: -lw $t1, 80($sp) -sw $t1, 44($sp) -b label_73 -label_70: -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 164($sp) -li $t0, 1 -sw $t0, 168($sp) -move $t0, $sp -lw $t1, 168($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 164($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 172($sp) -lw $t1, 164($sp) -sw $t1, 44($sp) -label_73: -lw $t1, 44($sp) -sw $t1, 8($sp) -b label_74 -label_69: -lw $t0, 4($sp) -lw $t1, 16($t0) -sw $t1, 188($sp) -lw $t1, 188($sp) -neg $a0, $t1 -sw $a0, 184($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 180($sp) -move $t0, $sp -lw $t1, 184($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 180($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 192($sp) -move $t0, $sp -lw $t1, 180($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 200($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 200($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 40($t2) -jal $t3 -sw $a1, 176($sp) -lw $t1, 176($sp) -sw $t1, 8($sp) -label_74: -lw $t1, 8($sp) -sw $t1, 196($sp) -lw $a1, 196($sp) -lw $ra, 0($sp) -addi $sp, $sp, 208 -jr $ra -Main.class_type: -addi $sp, $sp, -124 -addi $sp, $sp, -4 -sw $ra, 0($sp) -lw $t0, 132($sp) -lw $t1, 0($t0) -la $a0, void -bne $t1 $a0 label_76 -b case_void_error -label_76: -blt $t1 9 label_77 -bgt $t1 9 label_77 -lw $t1, 132($sp) -sw $t1, 8($sp) -la $t0, data_34 -sw $t0, 16($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 20($sp) -move $t0, $sp -lw $t1, 16($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 20($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 24($sp) -move $t0, $sp -lw $t1, 20($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 128($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 128($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 12($sp) -lw $t1, 12($sp) -sw $t1, 4($sp) -b label_75 -label_77: -blt $t1 8 label_78 -bgt $t1 9 label_78 -lw $t1, 132($sp) -sw $t1, 28($sp) -la $t0, data_35 -sw $t0, 36($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 40($sp) -move $t0, $sp -lw $t1, 36($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 40($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 44($sp) -move $t0, $sp -lw $t1, 40($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 128($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 128($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 32($sp) -lw $t1, 32($sp) -sw $t1, 4($sp) -b label_75 -label_78: -blt $t1 7 label_79 -bgt $t1 7 label_79 -lw $t1, 132($sp) -sw $t1, 48($sp) -la $t0, data_36 -sw $t0, 56($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 60($sp) -move $t0, $sp -lw $t1, 56($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 60($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 64($sp) -move $t0, $sp -lw $t1, 60($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 128($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 128($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 52($sp) -lw $t1, 52($sp) -sw $t1, 4($sp) -b label_75 -label_79: -blt $t1 6 label_80 -bgt $t1 9 label_80 -lw $t1, 132($sp) -sw $t1, 68($sp) -la $t0, data_37 -sw $t0, 76($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 80($sp) -move $t0, $sp -lw $t1, 76($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 80($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 84($sp) -move $t0, $sp -lw $t1, 80($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 128($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 128($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 72($sp) -lw $t1, 72($sp) -sw $t1, 4($sp) -b label_75 -label_80: -blt $t1 5 label_81 -bgt $t1 9 label_81 -lw $t1, 132($sp) -sw $t1, 88($sp) -la $t0, data_38 -sw $t0, 96($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 100($sp) -move $t0, $sp -lw $t1, 96($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 100($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 104($sp) -move $t0, $sp -lw $t1, 100($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 128($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 128($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 92($sp) -lw $t1, 92($sp) -sw $t1, 4($sp) -b label_75 -label_81: -blt $t1 0 label_82 -bgt $t1 9 label_82 -lw $t1, 132($sp) -sw $t1, 108($sp) -la $t0, data_39 -sw $t0, 116($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 120($sp) -move $t0, $sp -lw $t1, 116($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 120($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 124($sp) -move $t0, $sp -lw $t1, 120($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 128($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 128($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 112($sp) -lw $t1, 112($sp) -sw $t1, 4($sp) -b label_75 -label_82: -b case_no_match_error -label_75: -lw $a1, 4($sp) -lw $ra, 0($sp) -addi $sp, $sp, 136 -jr $ra -Main.print: -addi $sp, $sp, -44 -addi $sp, $sp, -4 -sw $ra, 0($sp) -li $a0, 16 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 6 -sw $t1, 0($t0) -la $t1, A2I_name -sw $t1, 4($t0) -li $t1, 4 -sw $t1, 8($t0) -la $t1, A2I_methods -sw $t1, 12($t0) -sw $t0, 4($sp) -move $t0, $sp -lw $t1, 4($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal A2I_init -sw $a1, 8($sp) -lw $t1, 4($sp) -sw $t1, 12($sp) -move $t0, $sp -lw $t1, 52($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 52($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 24($sp) -move $t0, $sp -lw $t1, 24($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 12($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 12($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 28($t2) -jal $t3 -sw $a1, 20($sp) -move $t0, $sp -lw $t1, 20($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 48($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 48($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 16($sp) -la $t0, data_40 -sw $t0, 32($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 36($sp) -move $t0, $sp -lw $t1, 32($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 36($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 40($sp) -move $t0, $sp -lw $t1, 36($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 48($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 48($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 28($sp) -lw $t1, 28($sp) -sw $t1, 44($sp) -lw $a1, 44($sp) -lw $ra, 0($sp) -addi $sp, $sp, 56 -jr $ra -Main.main: -addi $sp, $sp, -1136 -addi $sp, $sp, -4 -sw $ra, 0($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 5 -sw $t1, 0($t0) -la $t1, A_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, A_methods -sw $t1, 12($t0) -sw $t0, 4($sp) -move $t0, $sp -lw $t1, 4($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal A_init -sw $a1, 8($sp) -lw $t0, 1140($sp) -lw $t1, 4($sp) -sw $t1, 20($t0) -label_83: -lw $t0, 1140($sp) -lw $t1, 28($t0) -sw $t1, 20($sp) -lw $t0, 20($sp) -lw $a0, 16($t0) -bnez $a0, label_84 -b label_85 -label_84: -la $t0, data_41 -sw $t0, 28($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 32($sp) -move $t0, $sp -lw $t1, 28($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 32($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 36($sp) -move $t0, $sp -lw $t1, 32($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 24($sp) -lw $t0, 1140($sp) -lw $t1, 20($t0) -sw $t1, 1132($sp) -move $t0, $sp -lw $t1, 1132($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 48($t2) -jal $t3 -sw $a1, 40($sp) -lw $t0, 1140($sp) -lw $t1, 20($t0) -sw $t1, 1132($sp) -move $t0, $sp -lw $t1, 1132($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1132($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 56($sp) -move $t0, $sp -lw $t1, 56($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 40($t2) -jal $t3 -sw $a1, 52($sp) -lw $t0, 52($sp) -lw $a0, 16($t0) -bnez $a0, label_86 -la $t0, data_42 -sw $t0, 68($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 72($sp) -move $t0, $sp -lw $t1, 68($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 72($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 76($sp) -move $t0, $sp -lw $t1, 72($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 64($sp) -lw $t1, 64($sp) -sw $t1, 48($sp) -b label_87 -label_86: -la $t0, data_43 -sw $t0, 84($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 88($sp) -move $t0, $sp -lw $t1, 84($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 88($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 92($sp) -move $t0, $sp -lw $t1, 88($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 80($sp) -lw $t1, 80($sp) -sw $t1, 48($sp) -label_87: -lw $t0, 1140($sp) -lw $t1, 20($t0) -sw $t1, 1132($sp) -move $t0, $sp -lw $t1, 1132($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 44($t2) -jal $t3 -sw $a1, 96($sp) -move $t0, $sp -lw $t1, 1140($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 28($t2) -jal $t3 -sw $a1, 104($sp) -lw $t0, 1140($sp) -lw $t1, 104($sp) -sw $t1, 16($t0) -lw $t0, 1140($sp) -lw $t1, 16($t0) -sw $t1, 492($sp) -la $t0, data_44 -sw $t0, 136($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 140($sp) -move $t0, $sp -lw $t1, 136($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 140($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 144($sp) -move $t0, $sp -lw $t1, 140($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 492($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_equals -sw $a1, 120($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 116($sp) -move $t0, $sp -lw $t1, 120($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 116($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 148($sp) -lw $t0, 116($sp) -lw $a0, 16($t0) -bnez $a0, label_88 -lw $t0, 1140($sp) -lw $t1, 16($t0) -sw $t1, 492($sp) -la $t0, data_45 -sw $t0, 176($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 180($sp) -move $t0, $sp -lw $t1, 176($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 180($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 184($sp) -move $t0, $sp -lw $t1, 180($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 492($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_equals -sw $a1, 160($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 156($sp) -move $t0, $sp -lw $t1, 160($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 156($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 188($sp) -lw $t0, 156($sp) -lw $a0, 16($t0) -bnez $a0, label_89 -lw $t0, 1140($sp) -lw $t1, 16($t0) -sw $t1, 492($sp) -la $t0, data_46 -sw $t0, 216($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 220($sp) -move $t0, $sp -lw $t1, 216($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 220($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 224($sp) -move $t0, $sp -lw $t1, 220($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 492($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_equals -sw $a1, 200($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 196($sp) -move $t0, $sp -lw $t1, 200($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 196($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 228($sp) -lw $t0, 196($sp) -lw $a0, 16($t0) -bnez $a0, label_90 -lw $t0, 1140($sp) -lw $t1, 16($t0) -sw $t1, 492($sp) -la $t0, data_47 -sw $t0, 256($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 260($sp) -move $t0, $sp -lw $t1, 256($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 260($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 264($sp) -move $t0, $sp -lw $t1, 260($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 492($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_equals -sw $a1, 240($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 236($sp) -move $t0, $sp -lw $t1, 240($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 236($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 268($sp) -lw $t0, 236($sp) -lw $a0, 16($t0) -bnez $a0, label_91 -lw $t0, 1140($sp) -lw $t1, 16($t0) -sw $t1, 492($sp) -la $t0, data_48 -sw $t0, 296($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 300($sp) -move $t0, $sp -lw $t1, 296($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 300($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 304($sp) -move $t0, $sp -lw $t1, 300($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 492($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_equals -sw $a1, 280($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 276($sp) -move $t0, $sp -lw $t1, 280($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 276($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 308($sp) -lw $t0, 276($sp) -lw $a0, 16($t0) -bnez $a0, label_92 -lw $t0, 1140($sp) -lw $t1, 16($t0) -sw $t1, 492($sp) -la $t0, data_49 -sw $t0, 336($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 340($sp) -move $t0, $sp -lw $t1, 336($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 340($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 344($sp) -move $t0, $sp -lw $t1, 340($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 492($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_equals -sw $a1, 320($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 316($sp) -move $t0, $sp -lw $t1, 320($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 316($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 348($sp) -lw $t0, 316($sp) -lw $a0, 16($t0) -bnez $a0, label_93 -lw $t0, 1140($sp) -lw $t1, 16($t0) -sw $t1, 492($sp) -la $t0, data_50 -sw $t0, 376($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 380($sp) -move $t0, $sp -lw $t1, 376($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 380($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 384($sp) -move $t0, $sp -lw $t1, 380($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 492($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_equals -sw $a1, 360($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 356($sp) -move $t0, $sp -lw $t1, 360($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 356($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 388($sp) -lw $t0, 356($sp) -lw $a0, 16($t0) -bnez $a0, label_94 -lw $t0, 1140($sp) -lw $t1, 16($t0) -sw $t1, 492($sp) -la $t0, data_51 -sw $t0, 416($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 420($sp) -move $t0, $sp -lw $t1, 416($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 420($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 424($sp) -move $t0, $sp -lw $t1, 420($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 492($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_equals -sw $a1, 400($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 396($sp) -move $t0, $sp -lw $t1, 400($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 396($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 428($sp) -lw $t0, 396($sp) -lw $a0, 16($t0) -bnez $a0, label_95 -lw $t0, 1140($sp) -lw $t1, 16($t0) -sw $t1, 492($sp) -la $t0, data_52 -sw $t0, 456($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 460($sp) -move $t0, $sp -lw $t1, 456($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 460($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 464($sp) -move $t0, $sp -lw $t1, 460($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 492($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_equals -sw $a1, 440($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 436($sp) -move $t0, $sp -lw $t1, 440($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 436($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 468($sp) -lw $t0, 436($sp) -lw $a0, 16($t0) -bnez $a0, label_96 -lw $t0, 1140($sp) -lw $t1, 16($t0) -sw $t1, 492($sp) -la $t0, data_53 -sw $t0, 496($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 500($sp) -move $t0, $sp -lw $t1, 496($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 500($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 504($sp) -move $t0, $sp -lw $t1, 500($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 492($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_equals -sw $a1, 480($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 476($sp) -move $t0, $sp -lw $t1, 480($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 476($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 508($sp) -lw $t0, 476($sp) -lw $a0, 16($t0) -bnez $a0, label_97 -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 5 -sw $t1, 0($t0) -la $t1, A_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, A_methods -sw $t1, 12($t0) -sw $t0, 516($sp) -move $t0, $sp -lw $t1, 516($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal A_init -sw $a1, 520($sp) -lw $t0, 1140($sp) -lw $t1, 20($t0) -sw $t1, 1132($sp) -move $t0, $sp -lw $t1, 1132($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1132($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 524($sp) -move $t0, $sp -lw $t1, 524($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 516($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 516($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 20($t2) -jal $t3 -sw $a1, 512($sp) -lw $t0, 1140($sp) -lw $t1, 512($sp) -sw $t1, 20($t0) -lw $t1, 512($sp) -sw $t1, 472($sp) -b label_98 -label_97: -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 3 -sw $t1, 0($t0) -la $t1, Bool_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Bool_methods -sw $t1, 12($t0) -sw $t0, 536($sp) -li $t0, 0 -sw $t0, 540($sp) -move $t0, $sp -lw $t1, 540($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 536($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Bool_init -sw $a1, 544($sp) -lw $t0, 1140($sp) -lw $t1, 536($sp) -sw $t1, 28($t0) -lw $t1, 536($sp) -sw $t1, 472($sp) -label_98: -lw $t1, 472($sp) -sw $t1, 432($sp) -b label_99 -label_96: -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 5 -sw $t1, 0($t0) -la $t1, A_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, A_methods -sw $t1, 12($t0) -sw $t0, 552($sp) -move $t0, $sp -lw $t1, 552($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal A_init -sw $a1, 556($sp) -lw $t0, 1140($sp) -lw $t1, 552($sp) -sw $t1, 20($t0) -lw $t1, 552($sp) -sw $t1, 432($sp) -label_99: -lw $t1, 432($sp) -sw $t1, 392($sp) -b label_100 -label_95: -la $t1, void -sw $t1, 564($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 9 -sw $t1, 0($t0) -la $t1, E_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, E_methods -sw $t1, 12($t0) -sw $t0, 572($sp) -move $t0, $sp -lw $t1, 572($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal E_init -sw $a1, 576($sp) -lw $t0, 1140($sp) -lw $t1, 20($t0) -sw $t1, 1132($sp) -move $t0, $sp -lw $t1, 1132($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1132($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 580($sp) -move $t0, $sp -lw $t1, 580($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 572($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 572($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 44($t2) -jal $t3 -sw $a1, 568($sp) -lw $t1, 568($sp) -sw $t1, 564($sp) -lw $t0, 1140($sp) -lw $t1, 20($t0) -sw $t1, 1132($sp) -move $t0, $sp -lw $t1, 1132($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1132($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 608($sp) -move $t0, $sp -lw $t1, 564($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 564($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 632($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 636($sp) -li $t0, 8 -sw $t0, 640($sp) -move $t0, $sp -lw $t1, 640($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 636($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 644($sp) -lw $t0, 632($sp) -lw $t1, 16($t0) -sw $t1, 624($sp) -lw $t0, 636($sp) -lw $t1, 16($t0) -sw $t1, 628($sp) -lw $a0, 624($sp) -lw $t1, 628($sp) -mul $a0, $a0, $t1 -sw $a0, 620($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 616($sp) -move $t0, $sp -lw $t1, 620($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 616($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 648($sp) -lw $t0, 608($sp) -lw $t1, 16($t0) -sw $t1, 600($sp) -lw $t0, 616($sp) -lw $t1, 16($t0) -sw $t1, 604($sp) -lw $a0, 600($sp) -lw $t1, 604($sp) -sub $a0, $a0, $t1 -sw $a0, 596($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 592($sp) -move $t0, $sp -lw $t1, 596($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 592($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 652($sp) -lw $t1, 592($sp) -sw $t1, 656($sp) -la $t0, data_41 -sw $t0, 664($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 668($sp) -move $t0, $sp -lw $t1, 664($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 668($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 672($sp) -move $t0, $sp -lw $t1, 668($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 660($sp) -lw $t0, 1140($sp) -lw $t1, 20($t0) -sw $t1, 1132($sp) -move $t0, $sp -lw $t1, 1132($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 48($t2) -jal $t3 -sw $a1, 676($sp) -la $t0, data_54 -sw $t0, 688($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 692($sp) -move $t0, $sp -lw $t1, 688($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 692($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 696($sp) -move $t0, $sp -lw $t1, 692($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 684($sp) -move $t0, $sp -lw $t1, 564($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 48($t2) -jal $t3 -sw $a1, 700($sp) -la $t0, data_55 -sw $t0, 708($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 712($sp) -move $t0, $sp -lw $t1, 708($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 712($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 716($sp) -move $t0, $sp -lw $t1, 712($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 704($sp) -li $a0, 16 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 6 -sw $t1, 0($t0) -la $t1, A2I_name -sw $t1, 4($t0) -li $t1, 4 -sw $t1, 8($t0) -la $t1, A2I_methods -sw $t1, 12($t0) -sw $t0, 720($sp) -move $t0, $sp -lw $t1, 720($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal A2I_init -sw $a1, 724($sp) -lw $t1, 720($sp) -sw $t1, 728($sp) -move $t0, $sp -lw $t1, 656($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 728($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 728($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 28($t2) -jal $t3 -sw $a1, 736($sp) -move $t0, $sp -lw $t1, 736($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 732($sp) -la $t0, data_1 -sw $t0, 744($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 748($sp) -move $t0, $sp -lw $t1, 744($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 748($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 752($sp) -move $t0, $sp -lw $t1, 748($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 740($sp) -lw $t1, 740($sp) -sw $t1, 756($sp) -lw $t1, 756($sp) -sw $t1, 760($sp) -lw $t0, 1140($sp) -lw $t1, 564($sp) -sw $t1, 20($t0) -lw $t1, 564($sp) -sw $t1, 768($sp) -lw $t1, 768($sp) -sw $t1, 392($sp) -label_100: -lw $t1, 392($sp) -sw $t1, 352($sp) -b label_101 -label_94: -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 8 -sw $t1, 0($t0) -la $t1, D_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, D_methods -sw $t1, 12($t0) -sw $t0, 780($sp) -move $t0, $sp -lw $t1, 780($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal D_init -sw $a1, 784($sp) -lw $t0, 1140($sp) -lw $t1, 20($t0) -sw $t1, 1132($sp) -move $t0, $sp -lw $t1, 1132($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1132($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 788($sp) -move $t0, $sp -lw $t1, 788($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 780($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 780($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 40($t2) -jal $t3 -sw $a1, 776($sp) -lw $t0, 776($sp) -lw $a0, 16($t0) -bnez $a0, label_102 -la $t0, data_41 -sw $t0, 800($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 804($sp) -move $t0, $sp -lw $t1, 800($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 804($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 808($sp) -move $t0, $sp -lw $t1, 804($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 796($sp) -lw $t0, 1140($sp) -lw $t1, 20($t0) -sw $t1, 1132($sp) -move $t0, $sp -lw $t1, 1132($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 48($t2) -jal $t3 -sw $a1, 812($sp) -la $t0, data_56 -sw $t0, 824($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 828($sp) -move $t0, $sp -lw $t1, 824($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 828($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 832($sp) -move $t0, $sp -lw $t1, 828($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 820($sp) -lw $t1, 820($sp) -sw $t1, 772($sp) -b label_103 -label_102: -la $t0, data_41 -sw $t0, 840($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 844($sp) -move $t0, $sp -lw $t1, 840($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 844($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 848($sp) -move $t0, $sp -lw $t1, 844($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 836($sp) -lw $t0, 1140($sp) -lw $t1, 20($t0) -sw $t1, 1132($sp) -move $t0, $sp -lw $t1, 1132($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 48($t2) -jal $t3 -sw $a1, 852($sp) -la $t0, data_57 -sw $t0, 864($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 868($sp) -move $t0, $sp -lw $t1, 864($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 868($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 872($sp) -move $t0, $sp -lw $t1, 868($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 860($sp) -lw $t1, 860($sp) -sw $t1, 772($sp) -label_103: -lw $t1, 772($sp) -sw $t1, 352($sp) -label_101: -lw $t1, 352($sp) -sw $t1, 312($sp) -b label_104 -label_93: -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 7 -sw $t1, 0($t0) -la $t1, C_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, C_methods -sw $t1, 12($t0) -sw $t0, 880($sp) -move $t0, $sp -lw $t1, 880($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal C_init -sw $a1, 884($sp) -lw $t0, 1140($sp) -lw $t1, 20($t0) -sw $t1, 1132($sp) -move $t0, $sp -lw $t1, 1132($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1132($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 888($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 7 -sw $t1, 0($t0) -la $t1, C_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, C_methods -sw $t1, 12($t0) -sw $t0, 896($sp) -move $t0, $sp -lw $t1, 888($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 880($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 896($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 36($t2) -jal $t3 -sw $a1, 876($sp) -lw $t0, 1140($sp) -lw $t1, 876($sp) -sw $t1, 20($t0) -lw $t1, 876($sp) -sw $t1, 312($sp) -label_104: -lw $t1, 312($sp) -sw $t1, 272($sp) -b label_105 -label_92: -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 7 -sw $t1, 0($t0) -la $t1, C_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, C_methods -sw $t1, 12($t0) -sw $t0, 908($sp) -move $t0, $sp -lw $t1, 908($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal C_init -sw $a1, 912($sp) -lw $t0, 1140($sp) -lw $t1, 20($t0) -sw $t1, 1132($sp) -move $t0, $sp -lw $t1, 1132($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1132($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 916($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 6 -sw $t1, 0($t0) -la $t1, B_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, B_methods -sw $t1, 12($t0) -sw $t0, 924($sp) -move $t0, $sp -lw $t1, 916($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 908($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 924($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 36($t2) -jal $t3 -sw $a1, 904($sp) -lw $t0, 1140($sp) -lw $t1, 904($sp) -sw $t1, 20($t0) -lw $t1, 904($sp) -sw $t1, 272($sp) -label_105: -lw $t1, 272($sp) -sw $t1, 232($sp) -b label_106 -label_91: -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 7 -sw $t1, 0($t0) -la $t1, C_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, C_methods -sw $t1, 12($t0) -sw $t0, 936($sp) -move $t0, $sp -lw $t1, 936($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal C_init -sw $a1, 940($sp) -lw $t0, 1140($sp) -lw $t1, 20($t0) -sw $t1, 1132($sp) -move $t0, $sp -lw $t1, 1132($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1132($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 944($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 5 -sw $t1, 0($t0) -la $t1, A_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, A_methods -sw $t1, 12($t0) -sw $t0, 952($sp) -move $t0, $sp -lw $t1, 944($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 936($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 952($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 36($t2) -jal $t3 -sw $a1, 932($sp) -lw $t0, 1140($sp) -lw $t1, 932($sp) -sw $t1, 20($t0) -lw $t1, 932($sp) -sw $t1, 232($sp) -label_106: -lw $t1, 232($sp) -sw $t1, 192($sp) -b label_107 -label_90: -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 5 -sw $t1, 0($t0) -la $t1, A_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, A_methods -sw $t1, 12($t0) -sw $t0, 964($sp) -move $t0, $sp -lw $t1, 964($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal A_init -sw $a1, 968($sp) -move $t0, $sp -lw $t1, 1140($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 36($t2) -jal $t3 -sw $a1, 972($sp) -move $t0, $sp -lw $t1, 972($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 964($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 964($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 16($t2) -jal $t3 -sw $a1, 960($sp) -lw $t0, 1140($sp) -lw $t1, 960($sp) -sw $t1, 24($t0) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 8 -sw $t1, 0($t0) -la $t1, D_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, D_methods -sw $t1, 12($t0) -sw $t0, 984($sp) -move $t0, $sp -lw $t1, 984($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal D_init -sw $a1, 988($sp) -lw $t0, 1140($sp) -lw $t1, 24($t0) -sw $t1, 1124($sp) -move $t0, $sp -lw $t1, 1124($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1124($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 992($sp) -lw $t0, 1140($sp) -lw $t1, 20($t0) -sw $t1, 1132($sp) -move $t0, $sp -lw $t1, 1132($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1132($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 1000($sp) -move $t0, $sp -lw $t1, 992($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1000($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 984($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 984($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 32($t2) -jal $t3 -sw $a1, 980($sp) -lw $t0, 1140($sp) -lw $t1, 980($sp) -sw $t1, 20($t0) -lw $t1, 980($sp) -sw $t1, 192($sp) -label_107: -lw $t1, 192($sp) -sw $t1, 152($sp) -b label_108 -label_89: -lw $t0, 1140($sp) -lw $t1, 20($t0) -sw $t1, 1132($sp) -lw $t0, 1132($sp) -lw $t1, 0($t0) -la $a0, void -bne $t1 $a0 label_110 -b case_void_error -label_110: -blt $t1 7 label_111 -bgt $t1 7 label_111 -lw $t1, 1132($sp) -sw $t1, 1020($sp) -move $t0, $sp -lw $t1, 1020($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1020($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 1028($sp) -move $t0, $sp -lw $t1, 1028($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1020($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1020($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 40($t2) -jal $t3 -sw $a1, 1024($sp) -lw $t0, 1140($sp) -lw $t1, 1024($sp) -sw $t1, 20($t0) -lw $t1, 1024($sp) -sw $t1, 1012($sp) -b label_109 -label_111: -blt $t1 5 label_112 -bgt $t1 9 label_112 -lw $t1, 1132($sp) -sw $t1, 1036($sp) -move $t0, $sp -lw $t1, 1036($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1036($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 1044($sp) -move $t0, $sp -lw $t1, 1044($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1036($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1036($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 28($t2) -jal $t3 -sw $a1, 1040($sp) -lw $t0, 1140($sp) -lw $t1, 1040($sp) -sw $t1, 20($t0) -lw $t1, 1040($sp) -sw $t1, 1012($sp) -b label_109 -label_112: -blt $t1 0 label_113 -bgt $t1 9 label_113 -lw $t1, 1132($sp) -sw $t1, 1052($sp) -la $t0, data_39 -sw $t0, 1060($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 2 -sw $t1, 0($t0) -la $t1, String_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, String_methods -sw $t1, 12($t0) -sw $t0, 1064($sp) -move $t0, $sp -lw $t1, 1060($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1064($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal String_init -sw $a1, 1068($sp) -move $t0, $sp -lw $t1, 1064($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 1056($sp) -move $t0, $sp -lw $t1, 1140($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 0($t2) -jal $t3 -sw $a1, 1072($sp) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 4 -sw $t1, 0($t0) -la $t1, Int_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, Int_methods -sw $t1, 12($t0) -sw $t0, 1076($sp) -li $t0, 0 -sw $t0, 1080($sp) -move $t0, $sp -lw $t1, 1080($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1076($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal Int_init -sw $a1, 1084($sp) -lw $t1, 1076($sp) -sw $t1, 1012($sp) -b label_109 -label_113: -b case_no_match_error -label_109: -lw $t1, 1012($sp) -sw $t1, 152($sp) -label_108: -lw $t1, 152($sp) -sw $t1, 112($sp) -b label_114 -label_88: -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 5 -sw $t1, 0($t0) -la $t1, A_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, A_methods -sw $t1, 12($t0) -sw $t0, 1092($sp) -move $t0, $sp -lw $t1, 1092($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal A_init -sw $a1, 1096($sp) -move $t0, $sp -lw $t1, 1140($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1140($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 36($t2) -jal $t3 -sw $a1, 1100($sp) -move $t0, $sp -lw $t1, 1100($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1092($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1092($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 16($t2) -jal $t3 -sw $a1, 1088($sp) -lw $t0, 1140($sp) -lw $t1, 1088($sp) -sw $t1, 24($t0) -li $a0, 20 -li $v0, 9 -syscall -bge $v0, $sp heap_error -move $t0, $v0 -li $t1, 6 -sw $t1, 0($t0) -la $t1, B_name -sw $t1, 4($t0) -li $t1, 5 -sw $t1, 8($t0) -la $t1, B_methods -sw $t1, 12($t0) -sw $t0, 1112($sp) -move $t0, $sp -lw $t1, 1112($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -jal B_init -sw $a1, 1116($sp) -lw $t0, 1140($sp) -lw $t1, 24($t0) -sw $t1, 1124($sp) -move $t0, $sp -lw $t1, 1124($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1124($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 1120($sp) -lw $t0, 1140($sp) -lw $t1, 20($t0) -sw $t1, 1132($sp) -move $t0, $sp -lw $t1, 1132($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1132($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 12($t2) -jal $t3 -sw $a1, 1128($sp) -move $t0, $sp -lw $t1, 1120($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1128($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1112($t0) -addi $sp, $sp, -4 -sw $t1, 0($sp) -lw $t1, 1112($t0) -la $t0, void -beq $t1, $t0, dispatch_void_error -lw $t2, 12($t1) -lw $t3, 24($t2) -jal $t3 -sw $a1, 1108($sp) -lw $t0, 1140($sp) -lw $t1, 1108($sp) -sw $t1, 20($t0) -lw $t1, 1108($sp) -sw $t1, 112($sp) -label_114: -b label_83 -label_85: -lw $a1, 16($sp) -lw $ra, 0($sp) -addi $sp, $sp, 1144 -jr $ra \ No newline at end of file diff --git a/src/test.cl b/src/test.cl deleted file mode 100644 index 2cbd6819c..000000000 --- a/src/test.cl +++ /dev/null @@ -1,10 +0,0 @@ -class Main inherits IO { - a : String <- case 1 of - n : Main => n.type_name(); - a : Int => a.type_name(); - esac; - - main(): IO { - out_string(a) - }; -}; \ No newline at end of file From 129685f5429570065c1405a40ae5a092783ec2fd Mon Sep 17 00:00:00 2001 From: livi98 Date: Fri, 25 Feb 2022 18:56:22 +0100 Subject: [PATCH 194/194] adding report.pdf --- doc/report.pdf | Bin 0 -> 103854 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 doc/report.pdf diff --git a/doc/report.pdf b/doc/report.pdf new file mode 100644 index 0000000000000000000000000000000000000000..214affc0df1672679a438b7e7b43fddbe4f916a6 GIT binary patch literal 103854 zcmeFZby$^6^8ieDhcp~IlsKG2H-dC`DIL-wAq~p@5W>w1l)EeCL3^ zkMH}u*Y|tgKfmkx8=_jV?CcT^egq&)AT_LxEPi5=tjlukT2CAfUc|wA%ekkLn+9vr zLl=ZcQsd$3_6X_AXpexp&g${%Tps!72E0JjIufj$Gp^zMPbbYXFV@uBj@jFf_nLIs zwN!DG^;rUGK~ijq^eLR=<#Gex=!fGpC7Ut`MU@@X^oR*bvX}dcXCe}~1LZgK7 zg{N~L@z4fJ4;RD%Q@N`<^XG!t%Dtm{Cn>rGQ=iI*%fk~f#NZ8Qq{rwstPptNEuJm% zNsdyS+Bz$K!8Nw3i#gz#GPL43AVLGgsW=tf1k7aljHzDaWKsY@_bsU<9N?#E#vNKqrl=2ZA@gEKS^n{>Q8N_^DvZ_ zFq4bplx{v+-)w2z>e7w-CPDc@8>W%hb8O$(f1X5=`C3JSk5TqHT>+g(W}cJK)giMa zp_f;LYL|1=&1s>v1R=eyG%?SX`C0#-D{_~b7~QZBRu6EH0zWe@Jrh9&7ny*9n(a-k zmc4egJ;WK0;yp%?~VxW6$0!Axs5};C^H>jc@m{p>y6e4O2hAJ zpS?kT#fg~a>-XVX_cGio`Z`3Vw1463Mf#dIv_;XY&v2dAbq z@J79xG%4s|w~9<>5pd@WUXK*gIKJ6*kr&>)3p=i{hP9%K2fv^`$|^wtHt0>A7TSfE z)Ec!jyJknB)1-n>v`fa*RpZfdi?|C7qT(oFoEVNiU7a6?cguGah>=hA11XXjxX zywMc4@4Bb3Xr&3Z{66ZUs4Nthu=aUppCj!7T84>4RpR; zmd?)>zfBAkqy?K$hV3lZY$4Y;^0kN*!hIi+z+yq5+YF;&i&$!0TESZ7oFLh+cyNFx z%Y0M2pEInzsYG#3?=+eIs~P3b4kuY}BZM_(S4C$|KaMI+t)q-C zj+T7ac3CB{K-n)?A}=-JU4HaQtw$;axsGW0b8=-&t=Epxu_3!C-u~OgdY6jOrJ#@J zQtn-HQadsfx8Es(Z6dhcN2_?s1-tPCG=58*5#>?1)nuVaNXc7G~Pae&_ElkM9qE@n2mY5b9C>&FAsnBmPI9 z2j%+hnEtEJ1M&fYckUGG|G)r<554z=oV)~QY07UEHk6J;A`AZ*ux|dfQt3TFmh|~>m|6*5 z$CJE?Ew{Df3^e15V$lLC^#>Zt1d{4AFUI!{d@i}LbhWR6p?P%`0lxS#F_d=qByD2GFmo7sUyq%xU8fr5MC5+*nGj}^)uTj8{;PMnMrznnqYKyj!1t| zmri>cVqSgAL(T)AAKTqRvfQ%_fZj%o23g4$nV?&t?;>fA;!h{R$Njnd%L16E2yfui z*{35@#S$I|<6cU}2r8^_HrVfpxtU*6#$4@(fCb)Aq-PL1xT0$69(|_5Cj{*TB|8Q` zH|*Y4dNY+l!J3`~&yz>r_tvaB#RlZ{{tr*Buoo3rroD_b_!SIdH@(LUga63GK3%SE9tz_Af!{NXmyFB+cuDtNecY&rXHCQ z=`)bfcW#ZW+D9^MZL%8_ike>*WR7Ws+Oi10a0vFkyQol!LhFZ5$EnOCBOD4Fj5z0D~?pCxkrC`0XLOofWzE{XL2J^9*^%uw5&p&IGg(84 z_&C+~v^tpgKntW%IP-UdgpHU@=(#!1t}q2t+b8T8hs$9yE{&xkUtBn@!>&H_mujF~ z+MX~uP&{5sUG9_+b;NmzgPL3P?OD{ZIed?LuhnN&qFmVf{=CE$!oSAcK?D{Yi^f*Lst@XZl&;7{dTG11 zM;Ad(jyDuakV&8`&-_4b;>Ajm12uO#e|LUEh-VpT_YxIiql_k-5uXg2?5Iq9phXP) zV{mc<#YX;x2_}w+`lNl$~Mio%nCaBhr6=v z6A}cv3DVcnPSQ{l_-bm=`REgm+U@I=>;uMftg=A5(nFm# z#&3H+*1l4pc*0B;E1DEsW|Cf7`>NlPvs>?cNr=3gU+0*xUfm1E>L(w8KDTMS_QXpz zIt}8)=%H!+!i`6b`Eu+47?1b*r8T(qwI9aZKkg^$>l{3L>+f~Gt}H`o_8KoFw;Q0IhCD@Au1^mL#|11rZVHE_4tXY zo#%9pfYYZgjR$naYbR)v{f3A_Qn)wxS13`)G)Kcfkc9b37zq+TRszD2cupRmOvqb)AHPO-8WM9kL8iio*1&QR9&?q2SwRb@Ixi#z) zLPEHt4OmHGosy9t1OXxQM?BfoR@ml6HUW=H#9m6qy*dzsb756qLJP4cOrJKpz*w{` zod~v;|GKGhB3+ODkrIdD5U)H=Xw|LCzwBKhTj)Htoi>b<>8rN=(YO9$`FIQK3(F&o zOV4}|G4~d_5MCOt>EUg&*qscl*}lINozWQA#axX1gk~VAVaf`#Q7C25s_%|djmf)- z+Ich?r^TU968xH4#6x~_6s41O<3(&Phw+cE>uHpE27yxT;YQL#NaCDq{D7^C!g*cI zd`6|}N@2-5ndcwWqTcB;_PlQq=eROs?r$k%xwc0`c>Z$v`3F3IA}Uc13)0&Kf6z7% zrH@ub?y>;`Mqjq`)$3F(t#32sPvai!j!)Td{5;dEmN)r01Q5#LvXJq9J~o-m42zOy z|3U46aGfNrugQ|rSi?;V$xEf+{=m!yv+zQqQrzdhjKmAmjlLfVg=uHrs! zSI@aY5Ynkt)LH!TEGgF*WB9t{73)&5P?rnhlK~VdO3E~U_{647?zWZY$HSi1SPCnqq9(N)~UQj27|Ckp7p=`gK z`X3U*f0hjXncn_R2EmYw^6uY1NCtJ}oENz9+IO`^;?xR^P})5b%{+$nKG(kk*S}Ve zhnEoNYz6RbbcdbI*uNj3mP+K&I5L9)lN#n-?ILs7M{9|+s`XYJMu6qr`uj6vokT|C z4N^^gi0NBQ>aTiRoUa}yn=KXB)^As3z06>quc*}+R#TiCv$VJ^^)MtqraU*=5Xy2` zPMM$PQ^T@#!(06o{bc@U7Pd&_G$!)=i1pE<&L0HtsD!V#;2-0@bo(j#FsEe>wXbb^ ztOhJURWV&)wXQG9!6~*GaMoaZR@HBKL!5lr`hgZZnh4pje_~u^4Uj=pHgb;is#5+P zJ&2SeJaEtteIohkpx0+^!^h+J)}c%(IAgx86Aeu10#&Xd`z7{I^!`Cn$K2# zl6@*|q2D(l1noPvzj0Nw4e~1$b@0cY?cN<=XZ5C7A?ja}-ic_vsxccUF3f^CUU>MT zAmy$1ELHr+D;uN$k94~Z@(1cQh#jrp5W;?cF)pMuVSpA-^2!jsm@OflE>gP75zAxVao!WM@e=XN4w;C>0W~j z_6QiCW7=Z?-(?jVs;$1g2^1kdbNH%7Ir|Kr@Xbqf1FUzL#9whrJ4!T}iiB-Y&t`R+ zkK>I@`Y)A)acKY-bqvnu19OjA2ev2KIyO za@og*sxD0VZhhO6nL@cMR!B&fdnWUr8YT&qLi1j5vSU>~V0`~nT+X9Wzx~wA6cj6H zC$~jwck^hg{ii8|vzci{k#gpUzjWY+p=Ld%Kq6j$cekQVS0GhVcGDro(;g#Kb6IPC z21Q2_I4o@6<|J>@r?m^F4=HoVRa`XDuzmXsa)}?);PVVLySDcf~H+#1*E#`g=(7bULErm{VQOo&^N`=p$?6sHAx*n<+X&(@`&I!QUU{ zR_wxLBJ#wO(=5O|41O40XdieC|HbIxDkcJV9i@~}6)|&2*;#i>)$GyWG~tIo=f}8xNbLD<4Og$H6-#7^O?YmQa?CtEm4u$?DyKZ|lYqh)2zmY^3n3 zfab|w+XrK&%U zeT3Rcemj_v30=jDDu46Uglb{S3C?;4ocYvZRY?v?KEp?(*q2WVT{aN5Ezv07SfY!g znxNV4fW9^&<7a&>@GdwrMygn~M8%hFa_FpoTv)`xz$f42A(?W(7t8Q-?E}@pex=#r z1Bz`VGv3v<)!@MooSs)J-zXfPBp(#fe8|+>70>v(r1EvF_lbL#*cadiyyEwNPQtBZQ6%j zW~UW8l^bv2^H0(c4_s(eUuh!)P9(hu$byW?|Cd? z#k3E~>rb-NMjo}vA0M)b<_*#)Q!@w?SUqeh;~*eZjo;i&+rR_%tTlFrhK+$DlZy^x{Lsofg8 z`Z~AzqPa6zbD2`IuHnS$QeQ1CXKnJa8GAr>_(eOSS@{FBZ6d};Z6U9n$B`!)L#KmX zqPC$p+f3Rv3BpJo@U0L)?B6A1@j_Mb&B0+c~HZUzpau@C3ae3l- z4U13_T>x((TlmyDQ9bh_;f=oIk0fzKeYh38^+q|f9QZqHd;VNl; ztx)MiG{@ED7Kes1%RG5eta%n@wNH=WW)y?-~>K zPxYc@aeInI6}S@}TU(4&X0ReHV;J|%OQP-0)f2dYy0H1$3}VZ&zD^}tSAz4lh7+sf zqK)bzGa_?-2zsxwNnLDmz$| zW=Poe?x%f;5izZ_$>DXi|CCepYFx&NhD#i+ElC9C)!zCo{Ng<0B*J)p3Z+W;DJ`it zA)=<$ij-AN;HeK@^~Z_zjazs>3YhHwl9T?qgZSTbQfRjKZ(EhX`!6s5b506n`+H9M z=MLo`A8Y={4NA^GzcT&GNr60|f1ZKVtiC3efPQ1$J*odB6VcY}}X8^>5f z$-*yp0T+L760&J%9tqhF8J(7WeV{$C$g!`pxz{3vd0_85WZIx1`w>xZ!DHe1_rhbf zj^a_@%c{>0ByTJ%&2`h}$B%VgaI92q8Y-$TccVQlJ2!mbYG1tODVIWaU@blr$iyt_ z^bbzqldc~$QucVS;t`lYE1wJpw;AVVGO{{b&IfKy7?OvT=h586Lk@bd>~OfY5Dkv0 zhKt@F_`=%LWc5YHmOCi%a(wEgAhq_Fke?h4lnV_NL(krRiq=%B*QHVPe-ceqL9R2m zA}t)`sO?NMr`O-z>A1+9o$!Mcym$aFLq3TY;}g9dFqNb9F|2=_M`}S!)rB@p@~oTk zt2c3Xafhjzd@_}m8X6xVlhr|tV3e3TA!^8hWaDyazzJ7sAgX?C{~qGkTRXIiZ^*{; z)m4_TRXK>s6x4PxZ+Gz-2i|!LJ`dvJ8nrUR?WQ}(ladkvJ&v52eAq8lGh!XdM9+;y z5p(4_mnR04i5&Gk8*y{nOLN_V_Z_=AD#|vVyD=fYJn3pStx#OI3;ro8u}~kFnmUbT zgtit~D*PaF*n6nC5mg#df+g5N>UFSuPTtW`=%Jidt8rZ?holNPKY&JMSAc?5Nyg_3 zMsX&)!d|e3{mop*iv;U*Y-1`4&cw8kQ^PXH`VCG`3BIJyfgdh9dJ zv|8xOPi_=;)mz?>oAlLchS;A5EL08TlI&WH`-s1dZz7+r1kb(?S435f*;6wA22_c&BX}2LKY)j1fCPzIbG{h9IkHALfKsFUkh=z?iFoZWs4WPmAk2VDq zkz^vzX-?-44TVp5PIOtaS?9GFQoXXeT?r8lSc~N=K#cDOb)bu&TFj5X5 z^pcspxwYJ0ijMq(+rLc}DSkg(*FVkk3j!Fo_-Nek2M#RFL9)jyFXAiM zVWLOggoSnEM>hhu0G_tz^)k}Bu;U^U@83waJGdbRTcnRxl?B*UrxSSYf zkXUMrk&=$y28z2Br#Bs%2!f@mjXQd&($eVNpq67hLmWvO5b)eMC=9jK`uXHL7Z#9P1focg$JG_rLLC|!8Fqrw$29aC8;lkye_2D2|wL{8&0FZ7fWX*`#0YzA8uZ*LqV zO`N5*;?)MGk>nWfcX;Cvu?W&VvQy{;a3#bf4{36e`v7+?x>&x31+v^EV zmOhgc;u-U;=qExnVLgnxg&rqAALkF|i4s*R{xF2ky!3W>M9i%!%df5xl~(5F+8jJJ z8QR^&zfZ(d5#3Qvggg_$42L4rGQxQUb92txC(Dd$T*1t`fB>6ACHc}Zu)|L&Caskq z+6oseSljU+4&lh#eNJ6Be`15Qw^h1yE_UU7Ib#gf33Kkr4942l1UB8fhd)6j)oY_T z0oEHvbk99A`8J=kts_$^RR~PT;7r2j7Dns|vMVyRN54-y!=;{akI)J+Uf*+GGnZ6+ z(-gX`-rf9J7S~cF#+6c86a#)=rJ$y--_9<_O08({;^yZHQilfX}#^j0$E0JU{@CP|j$)9hBgPt(S zoj!t-U&VR%Fk;sOvkr;pz1de~4cTllo$#@<{VSGUtLfuRdJ)$FyL&3+qfTB+;@1dKVHp9!P;i>psn1-rRC(hR6}YUUo7B+? zrPc>0S@0Jb+dP-rl8E&sKl}i0;8P=Au3r(4#0Or!jA*X^n9Ob^!9R_~^R%C?&i^51 zRXp-+af{s1@(&b(9vtzyzRj`&oY1DhXqvd)o(Z`3zQnWNZ3Jxi-EKT~jeMWDX|RS`HSDX z-nAyu@He_bPYId0l`D{ReYrE5XBlZz3Z_GPgS>q&lG!5)`%b2uIWKYTp@29Lbhr zPA#0mGT!R*o^!%YZR$0nrg584&>3#*s|^l5FSu>;XH1loJ=eKmJFu@s=RvJ`$w!OAhc4)X^G}Fwu5j}Ex*v0NO|7)%X3{ETu&B}Ly|yR@ zM_O06uiqjTp6lxUmk{yi*Mk2ZBJK{({rO>n^Vg}p|20JXc~bNL_%QL$BE+8y*xwO? zn-ly`BSg8Doc+RGgxD%VYz>!?O(Y;dj0eNw(S@Shd&)Q)(!I@xSes)HKYJ4FVATh+GC7GQVK2(EIvcEdD$y>B?Xn-SC^C;kbXgzv7 zE zdH@Ykj7%)E1H<4Lvnj5iZouPL;(_sHq3W54EGjCQH9}hGDzE0A*U@7QGH3*Y^hiQZ zX;4RvQ(o;acWD3Mrae9_H97-6_e0M=H*nM(T*i_Aogs-(PFJtf(S_t zc0c^sFojMf#jI@0yc$6PQ_zV0NRu=gsj}E1GqvHeLdNpJ&YX*Hk2qTmFV^Y6qi@UH zWZnX4gBO*qElj3c>$c;Bdc5fuF2ivC=^zijSyF^jSH zB`W>#_b}Sa#@}evs^J(=4+Yes^00bbjkPRtz8FSt1(9-!Xd2BVQ*vcK(hd9IXBBlFwcMQpZxxO^xJ~= zREiI2-nN}_juc|^E4a~PPCpj}FZ@TRT;@-rSs0nkaPrr*;920fkPOmFK3n#8TS=JO ziz_m45DG=wWZ3-(t?m5!-mmvd0eP?KscLy~D!aZ$zYMl?1+KVc0CpxGCL{~)pNYmF-Ej-^{AK|Y*>N&SK52Aki zp|-g5{F-2o(CVnpaYsh{nwS2VQ}!c%fAOOTSz-ax6p0jv<+CGn!1X&s*YFaOmmp!@ z$3LwJ$9^&&!<8{ZR-&>c#C;!YsnPlZrpp!HSw$gBdF!@xbkw7#+hoj-nR32NE zwX(WokT(I(E-P48`Fs%@+@AC8Y}vFd6C^dEm3DOfW*-@3Y%OTEi{;nLJGlWv!m_pe zvL_gp`Z$oNVSY+ZQ89#J;uMUWQG`o~@y)%JjNQO_H*FDjnx}kRcBRu3M>L`AJrT+E z!3#`{-7Dc1WVttU1b&P;c}hV3@AwaEWqGb~2r#TAlx!)g{Jwao!m_3NZh!7ne97a# zA|HtM@>#?q7TFiEWMDQ%K5=ZiUO)WwP?9b`SycGls6vPC3fI#8^9uX4YLXN|%IL<5 z74^Ute!aF3_C(=Ey%!+G(FzTG)R&OYH^&3BqXybcq)2qj(-FI$=+&fkvKzt6>jXm{ z&-RXC!z#(s(^|qRHdkJ7HKr`#YO2Hc*I^@#Cprh4+375x<8go97#2(!M*aa`kBz(v zA3caIwM}Frj^|Up3>KVPhJVHr_zle9+1DvfI(m}p(kUJ;XT0FVE|_uP-{Oj~*`~g? zu@Ap8d%7{@8iTQa{b~OE4R(JdoEk&FKXVW|26;M7LTR|F!zygQTvc>1K{C2l1l%>U z(&YNJK>muvCB~lK2Bih#h57zDhYu;PmQfd%p7w{~TLSvH!NVU#{A~2^Ms`wpJN;u( zs85FI-^Oy0E>1d{zrD^QqI%AhDfAvD8g?hDM!vpaY##^)Kv)|*1B@v(Ru_JUJ zQh2FyN+k~;;w{Co$f};le$P0h!X0tY{x321&)v`e9%FwU0sZS7Jm;_D0RKmfg`8`L z?$AQQsf1cL-KY}deSSSwwvhNB#7W$6@F6j4qQjZI=I{W{B|0f+7{5BEj_kOh= zFNlMU8^Fs8Wa9(yaB)Fk9!?OXM_wapr-wQ~ae`)s54Dil)L=k182OX5jWKPnXiIkw06W=QB$rfBfqk>RYuewJmrn)|4u#7a{i!3NRw z*^e9Pm5c9*Tp5Q^?M($adCcr&WyPWzjiB`K_dbFRz=_VXYKazoZ87kx!V0^S7)P z#j~t$t}>WIdx}EV@1H+mdJ!(^?N@Mgl=po)Yt8~zA03Byw%K4pM^Wnp9{ZW^e>uDa z*|_=Z>&?IN?0>FS5bz_2OO->JLxV$;gIkNEL0uZS&a%$QjSx=4M4aYNAMf0hF4%O^ zO&E#UbRy)JtN$aj9gSYHpjiKhBJ3ENs0vY#Wpl zfpCkc-HOxcI@&rM%!Q;x$lqNy=)Y|~f%)!N7J&czoYTLCj3{mbLNsv>B6wUO&SnCS zhy&(^lcU>o;`4CY4tYpS=CJJvBMBL_H=%5}tXk7a23$HJM$?G_K`tgChH;ai0Rizk z6$i)lZFk4TEfxIL?Jef@?JZU8?d`4qPY58|cmpXR^|!Z>jYv}=4rfvGfDxq6ur=tW zj01LTT1pk7Y%qP!FHHYF$h#W>zxV9!;}SGtps}mHFm}1Stp!Db(AX7?Y#~>-AeRUr z1BVbO7`ZrEL9b@9aR50vppygg^A`-crUj)Ezq`H#xpu`0aU(ncZcfO(sy{AzL2qdN z=j|&QTgdG&ae%>HGix1P}0 zC9KTN%^+9lpjYnnK-}y`5Ve4K*xBstT};i)0bovcBQPf<`uqz6Q9HX4r1a6w`u7#ba+H9VZ0kf_0P#{+%lyNhN(4&YscyhGm$yf2|7_s#qT-827c z_AXR{?#esye@K8_F@<#UFFDZqfAafh`}gpDi(npT*YC@F40LEb9MEw2Ygl)2o|_k% zGH`Q2LpIM{T!+$uxS;`=>yL4ALlQJTAU7oL-^sb_`91G1>Gz4nucYHnZP4~0zd#O1 zM286f^~ik}>;D?)e?osf-&^mOHSPr8!+%)s4tvk>3wzhrJ?57w?q>p2o%hfk1?Vo_ z0o~<6zYOw6?Y)AanFuc=D}|PS%?TjKUzYjTy8(v2)AvpQl8``?j{hvV`Jna%LsA#; zuUc+y9tb55Bu#>dzoX{`L6a0d$a@FT@*SQN%m<;lFYjr1Aa(`*qQ8g#qy%w+?~*5I z`HTJ!IUq>F$Mf0b(l}-eaJngxU@a@nLu4gCz945LfI7a#Ax4frqh{qFw# zfT3dU&G8q+$;Suj$Y1q$9CtV_h)dF&!v zCjuYOU#;G?{nw=W*NTzrZfW=Tk{9B5ATJcu)$u@`2`>=(Qu9JqSogG$7|07j0D)l8 zFFfdu0tALmGA>>qfDhu#epBDWQ0{vw@Lk<~c`xs;I?%tU{@$zq74xf4fAs8b1Rx;9 z)o|UF(C7QH@<8kXnI`w+glGjaeIN_o-%|p*f5UJP!?s}8vs z%K`Cg5Y!z3FC>AupOH}EP?#6Q2dRa|P##|B%;x0=Lj>J73t~zd-;W zClALz{mK$mhp3)DjK>=JY8eYQK%r`Re;>hZ1{R6f#?agWn-VPTw~P?bB3HHCiMr3$ zNz*74@4PQ`zI6L+w~fo%d#dHR)(egEibCIfcuxIhl8F9^ft zW5fn)q^JnP!}xameJD;5hvFw(Pm5*3hZnzuEhlhuT$o!qN z)XI8}44Qt(#CFKzaGj#cZn0d;Zo@EK+4x%r)3d-WSbkT-*=Ja`p_mKsD2T9>n9+t0 zV?lesp3%>w2#A9FSmT=NuthC?>9;hc*OG>a*WSD^Y_1i)Z?6P?xY1M{XBlR{ChQqR z+}cBQZ9ts$qY#66;X&xy$e2zD^-G14w>;&lkfG>1)#f;Ps11NKo^8h6Ce-=qFgd$LnLCz4jIE z$J+W2Tc5qo5B-R%a8({Q@axD8utGOR7ae~402uNer0>U+QU*GU~DDr?=y``oNHq)|}>Mq~R~D zxAV-bm`4Z~RYyngvyGR$u=@JftuX%mL0^0~Ctw0@E7nAe2{UW~FgfpsyanI-zTUfe zheUh}x#rj5yQvx|$U=l*crCTXknWYP8ADZZYteLzdU>mMdGP2~E9cf;^1EGhwC{DK zFYb+qPd5JS#IAi`p3~xTj9NCDM>^u>ZNX094XJ@uXx{1V4}z7Bew|pSh8Nf8zyPD~ zhDx#ZNW^w#=Wq0HYIbiZ!BSNqX?QsJTOVB*8~yb3+cnR0wud48oA75vgCcC>Ylqk8 zNls&$IJ;le`hL21i!u>x1s%B$#)M)occ1b`PXj)Pupl{92|Qkoq4w+FxQ5}zVd^^| z`$`1kFmTQNQw&ZJ2CLT>N5t>(SE`c%^`FS7u)H5{qY(ID$w_as`yb8SKG9!@Ijpt= zjOS@)okZ%Bc?Ti{ht(Yq-bLf zC-bB_Ya8B~I`Z0>>p8!Te@1fLU>eW*glCSf=xF8qsik2v{)H+4S>z%8h*=GGS+Rfh-Loe6|bsMMe?EwV~I1cE9y+%_h!EI zEqOr)Dk5Q`DcLK+IYh2giv-%aCLbr=z^deCFRHbr5dE_lBAc^;vz2zL6-9=JT|&v3 z0d%B!JV~T4Ji{2J+z=^_Tm$<~H6$#0I@jDczKP?etvT#_X7(WYA5fQtFVIc$N)@C8 zz{?hwrcX&Ia-bQ|{d63)whrtjBEWCM<5hD@`6fk=7m?bJ5Yj3IC@<0iCKsyN&ra#X zjr2<~(QyVeAjH(ZqQ2^iYW}eJ-3&h}GGlUt7s>BbO-=w7)XHpm8vWiK8Lu$Qwp&Bu zCrQ!imyjfnBA6f>RPcDS{-biayog8RYj|O9kFl`7xroL)f7tgt zE?Su%@@^0~9Usf7@qKcMBK#z$oS2I0?c+d?VDp&kna7|5fPJ1RU$k^a*MWX}|Ii#~ zsfSH!W!GTNC=pqaXi&AZPgSdM1E-ZCk54kK{@uWr<8iSzPqUp)zfx*z1dZTd7OVzUrtrhK3Ja!=t4ST6%!$UA(xfM9mKTp zGoIs&N%Cbo&?aciu+CaVnp-7(v0XI?vDODM{x!QFsX~nc2nZ9~Lo2mMkw~Ie5OZId!iSXK$9wDBm*Bm>0x}avGo|Rt4 zd(oL~uRKZy7nEpqR&qy9{ZW z85tuLzb2fUjp)&p8}AdCtU9DhQgxlD`POr(pRodZR!&Y;5UXH_SM%K3ZpFdZX0(Ob z#9e1yU(wuH#iWFU5bsfINNx4P!svnY#)uU&!G`Ia>yM06vVL(D|1fHbTW6CbfI$;a zowve7Nz+b97S z@eC1-AXWYR$ul|?Hs2KaNkHeTS>6zJ!8fwxjlE5u+fO!k9VVl;pC@RE-5>|Q+Su%U zhPSgHHerWSz9r!JlO*ivBSWU94_yupKUJ@S^eqHk`)0hjoiDmkSe_W=gg<#7*!EXnfln=;+m9x1h})TTDPcY)s>Rz&Mq zUV?SFxto*fHNL)$5|W#o@6I_>qIib$;k_BQ`J}s(>$BMjnl}~ABywyQ?{VoORnv-al!sb?X#Ln+T1VP{Jc$Z^ocFW)b`(jc}7nWtOW_D`V&@O(x)1!R>66@^m(@7qmETi5>5dmUTHhtiAy^H%EC4JzCe9vyA7>0fP~jBIta>$hul;4Ody?tjmhy zX{<62_w)?RvGN$G%T3B)VqHs!WWf@L_B}T0ddkdIjU(6PbC%(-hQ4*C zy{Gj(oPS41^37c@P%nuo<(663YeU1#P-o^{T4}SxAp~15sPS%_GJC7 zLjE3k33V|hA(OQ`Nq|yO7EOT=AD@xW+=LWKap8sjRGV@r(O}Cdb-deI7c&ac@}mI> z<}{D0=T>tfSwTMlFFA9EEnB>~-RirN?Q_O5@IHCHQEJ|@9SrPh3cLIo8Ko{&IrO$1 z@8{(8CmF9qokmB2&~cS!UlVu%`lRnkJi6aJnG8#h`B!yn8{I>QnOb6{K#u9(e#$9U zhJDI2p4`)(1JQ%MVHoFjoDiD)1{IiKuM;bc!y*|OWFq;`jxEVP>ks3{(=64SdPb3 z2MsBjM~T?*Lw@lCE$@;DHpb+K3ji3C#-56TC&1IkO5xQ`*YA>=eA@f>GNU|WSXl53 zM|G{Zd!JR=CJdHLY;)?ad+M%?7t+ttDBniNl1Gvpfpc?65jb{Hibn_3(?;@QZOUtC zXNT*Gz)4Bi_Rowoa&C9><>Dq9q_i0^(QHf#OLJX=-7Ain;19=|eRn46$u>#cB)|#%AQ^ImE7ot%=?;)Wrm&d|PoBOD3HY!~j8u5!2PekxLqjPTsta*_i%alG` z-F2BPV-3GdYT{{fC}U*d3~fjt?ix#y-NKz=VHK)y{E+Y?r{&DcTu6L?{<-eUdfCR7 zuW*3Xda9!_u9J{m6OC8F-h+1Vhbew;>Jdsb((YHOx!jTlRwpZy3^Yxul5dy_As5oK zl|QA&&BtQBboaPyrx`lsLzz1DW!RYoVzg@gR1Av`4;rTo^~KOjx6Rb+=E}0%Z6e8d z@P;aCN5*3^$UoY?4WmgI#U`A4|t*Gr5X|XQ>P}>HwX-k4xD*bE95gk7Y6> zoB3qRf2Ky#ONgQ4G?4~2_S_7Y>(9E$Q52di$S#nlCRgbmy^Q&3cAhr(;u$}l>r$YE z`5<$04-L`>h}Wq>k+{5u9{`-)*JQpKo(OK>c%ILWJL87wE!i+aQ63?vol^lGQF!FF?Le8 zR~5Ep(9mSdiR=LaT8jhdS#2FL+y>4czu8^tE5`A5wIGk?{HD3`T zBWjgzO``7zWVH{Yxc>4d&xSi35hs`r4z1sI&p>6fb>>CPj5lvb8{{4pX8UT9^=(C7 z6tjp2+Z;N6=>Ca)_GZk}2@64VALae*q^Zc{KeVA-%8BZOC0;}k8R08O9m;=kG=e0e zA548yiFUc9w`w75Ceux6ks7d?w;XRrWl*7o0%t_q;~2kTdg*3FY0ZjJPi+_-sdS!8 z&b0yg@D6MD{~*FB(B^4C=^{e^gW55kibCKA7tOuG@539t!l1C_ zVKb@h7Gyr5nL5$n(o)&$+q;*KwkaEvA;U?pxD6q{*(WB0C>BZPw8q`bMbLi!{P4$1 zK61uyH$aC$746k8VXL0Qc;P!}&ZM%?RQVhJ`QpLDrUrAQMh3x!h1GXxf%!)M%Y?oyUdGA5}3NUrF!yxY}huogt0F`)O!w%^>s>mDL@-@S~9(qlUx6LS7Jj z#XYhCSRvLOV+{q#kve%@;V?Mr_vwYIxN;+bz@Q> z!MR@RR$ZWS*+u$!pV&7!X*u2)#&6HNeLk5 z^mhTjzygFtpw(f|E528^#RdM2TkoY(Ixv{#uaASd)yIc>J$Oo17o@+zy(8d1QbtPP zEqWgTCt%F|6>0@>*B-$*L78Rrn@CGGj7NCmioR&(;y3EkDg}~5tOS;*PG?IB&BASw zEr$wQ_ba!t>O|X4+oOSps4Z z*rJ&HS?AZmRC~uZK^S+Lr>epRO8ag2r|O0%nsaC{5YRLeFK)qdmvOvt3Pze>Dx&#B zW#irw*9jeGSQdk+HQun;LvB$&>&iWuI5U>Bp}n^51F#ly_CaRe-Kv#2es%GU`R|&& z3HT>6S3YATkqoX&LFvLA$$u)-3JdBN^ciL|X3Tv~og})$)a#-|;i8fT*+;)=otK7s zvZw8Q`Nh7kohHkSZzF$pBCkV?`{$B3GuuoB0PzblZ%E1xur-PWk^(i>s9U<<_&2@M zaYdTa$#EGGvmvz<+xjSRsuKO|pAh4{X(3)m{gQ0N{0iL~>>)$F88=m=3z(}q6O}7H zYM$BR=90bdu+N|f2Cpm? zFiA!x)b7HJ%rEh;dp{dOoH0HiicD;Am@eU_v*liT{OWIK&iAkt zwmhY_cGgUz)NDH#K^v9BCPR;~W#hIJndCf1c?KSd1>?kl8cHCFBXnSwD?x7{5JDV6 zcoc45IiTz|Yl=AXx<@7N`|LTG7A?+aczN>+ z3rg7dmm-1M+G5H{&8Tw8r~kVb0@%K!&}2-__!9N! zZ3`}HbOPkqe`#J=7)}dB6$1mIMf8WAv+4KbYYfpS)vX{A>P?lLz*_i>!3re zW^v$qWiS<~(Ai~}alG-IELO@gU2&^ZcQ$mrC705ze)Fz@ePUQ=iv`%TBs<3yZsa@D zx+z#!Q~2nSM&AVgzBBu0II2t!lQNq0rqdE{y%{e>Bnb!K3yZL9wWnd-jGd$}Me&ur zrF_t!_{Zz$q_6L62H(oZ55soeG-N)XxbXmdME#R=2NMT2^M{cu3(QZ3atoQ3AdvWR zH~bSqoO)gkC!GS#CGK}>`vj}Y^F~WG;dC<$lzW+5M4MP^W}KZ&v!V-i1x7q z)2I7p5vZ$N zO1mM(isnqtDs$Z|d;!3ACmcZsf1nP|w9iY`Z#3({1!0AV6xEygr(sMjcVjnb<Hs$ccgC3_9eNrqv+#z|cDImim2Iw$Sx zB?pa417Pi*s?lLWu6=LFg(L1-wkRxWv)Ypd%?yIrLigF?G)>V+dop>fJ7Z7A&6l}kkiV2U=ClYeq#DG(d>eHi$SsUIH7DGe=H~^6 zs5;oQiM1FW_L-Q(kgxM(3#y!npUX&L!NVes;O=ulXCEd{xmtoD`n)W)vRPAHTKr$@ zt1H92u3%FpT8DYc|Mo2F%X{oH;{+O#YRhu{CF&S~Vux#GA{vw|uCHIR&YX}a#jh=X zV6}-F>IA(Bfo8E!OEPxUM#i!K9lu{L4h-0DDmC9sxKpdrrCB^_2Wuh|WG_goI`3%C zP!ASprrTRmR;d3nYR7N4pOL{t|4h4?fTBiF-I9{c_Aw|E40}%wxV^*)F#sJ7vBe`6 zxWs~u;M$WnzVlnv)OEg0uWo9%9T`(2_)X-3mV_vZS4~^VC+icOAi3|PjFRP&Z&I&D zLDVC^n)!B*T#r_)XK$c4P-b#Q{wR;R0C}zmmi#-}Dcf@RW1f%%1t?KH%^g*Tp^N&D zF~N5i4r28O2zB_W&P2R*yMn}=%u-)xOFnYN(s`OJT`~=V|MnevVe6nK@YKEy@-7mIC3qqN*E{+hw457OVa(i$R8!B+4TMcOa0nr4F@y z+^?Xw(0Mt{2-$P(d%_DM@Gf~jrAWIE-2YLzqacpz#``&^?0P6{c6=vHUYcul3Ci`1 zF`2*>Z$b1AqNmzL-2Skq8q4M_B@Ooi4xyzsQMx#z*bBtfC@JRIS&i(UZs|WpdnEzs zlqLYTqHqnk0^J?$q~-IfjSWukbhrw5`O@3Fb=#{>k&30oAGu-9T@!qJfH>A)?(?Vb zQOy-GW?l59nfC0ZPc`KDVU)go^WV1y7ZcmmVK>hDr+~mK%iu3s5uyn0Vi50rUalz* zP0gsdT3Zb#3lOm1SVi{)=wdTBl>UKK8SykeuF$yd*dIV!!aa zsgfPbj`JvN0U;cU^9<5$*KZv*w}bpwPeB73v#nWup_Gf1ERoC0`*rQi3DHB+Tg;q# zeQ`6+Jq!f-%FI-@`!}>bmMe}WzQbF|l*UKrnK~O&-a) zzG%-a<4IBTHNT3!-FngV&sfwyBTDw;B~~gyxb_AhmryUIIZGVvc=r6vzgMzq9$t`B zzUu4~PLsrtv(@*Sx!v?J^)X6OP==R=p{^XN+ebCJ#0NBcB)awcE;h|BYe)$MpQuxF zJ<!y#a^#VODu?@N5 z&FQVJ(W<*E)(=3jRSrK}0gw)NJtL~>W9C(o&`n0R@8`enu%mXaxwJeSrJIO)h%3JI zlIV_--$3WbYM7!Tt#c)SEd<4cR#NRC(yh14>&lHDZub5)kwo&*a&;jdI(X0 zH-uhR7gPO!&RA(e(o10HmCVyAHW`;|TByB)L#ME9MQ$k-GanqTkh@vy)h> zCJj~nw2zNBw&>mQQ#x}1N&G*2JKKW-ZwmAhJ&m@yYe$}(B7@$mde@8U?M z=G{4ES%EuHR3Ncj(g^z)v~$qnZxGXyR* z$74dish)&$MuWL1MPKALyhGGEokcrpOcA?Bf)7XwI)hSa(S>X1F+VggpfMHbpg7hq z>o16@oPticlXinjw9W(#euaFj7sZ?MC(ew8P%udQqejb_dzh}}kLv&?JhH{5C!yI^ z#Xdu|-2!%)a?Zge3w>IsPnR%FksCoow(E!kQePXFk+PqnLUKkG*v&7eNHK}T`5~6m_#0|dgjbvt(j-!_Ulp-&AER*cV-(Qz5 z%+7a9v^2NQa1?=R9QD(#2NH1_9^6<`5~~=5EZD)xxmtENDtjM!m*Vd)IWPcSJbO2> zNx&NAp%&*`6L%)Sy{;BR6Xd%lE$^uMy3i9QJ9Lf$AA6yq8(f>xYeW^RV4KM|L1IeM zyK=AyT)QVbT(N!m!Og^U$&wqF!?T1 ze7-RS(CV>-M{^4Ue+au*R?`}B0(9hWMH~5)qbgo6F>`8p3qFle)C^#AiPN_Ocq_S{$FMMjsk;ZmGv`DFV@KU2KF? z_(gYJ+0b72{-UEg>%1b5|E@ZwE~E0n!t?6?S_8})kJ+lr6kNSk2nEqa*J7+)lja|# zWSGE+BbL{J$YaG$U}eT$zrW(%OHFjv;~bJJd9+x^xrgjxRc9c6`xOX+fr~UI&_nW& zbsK1XbQ!p(C1Gl1h>~r0?rkPiK=tciSQHHp*6(u?u1wI4D?Q3!u`24rpJAAZHVN8U z)r}gEH!d5qlQ0R9XAck)t1fL*%wqvOv*5WRPB3T2!M6v8|4g zt%7kz_lAV*u(4k$hrT7@W9&^#jkhg3ZyO@|jn&^P`azbD9wdU23cE44g=ldXt@)}v%a-26v7EUKtvF^s&fPzRNCBi_Q2&?~DEdu_UB z+kDkAsWzfyjbIlT&j7V^yVH=UxO6j`aT0|>KY+XB)h#1_e`yH*fFnFtxD9W%Z_p3b zik%xo8Qx`#Gfd^5RJu^wgLdF*Vrp) z;dYgP!x4U>Dui^`OwynDAxl)Z8ylOTXA#^Hy)V5z+e_XWh`I@li&J6dGUQ?G+iU6$>WB=sQ)NYQhb*+h-15^v{*K)WYV{v;|{OACU6U#|9 zL+1iL)Y*1Qke?7RsNo?j2wrmmg%Zv@zbI@$Y7)$lb&j!p^z!KI7|d0o#^ejW_yA4$ zEn)t@uEIaQ?teQd|Jzj%F?KMtH?wuLvHx%B;J-};Suu5a`9IXcvO<3u|3ORtqJIDm z1piZB_-`$NmX(cwmgzsVGb7tSW{j2LpPL})VECVG88*&;PYUbXN*J2~O#fYS{PPX| zGtGZ$w2c2LN;>LWni&dO11ydI!$c`L8e6IU2d#sq|NB2*`iCF?`^G;B;Xm0j6!gOM zlJqk4vh?!wf9RFy|CxIF4yN=r^p2GOz36`tMaKWQt^W&=XZe2>lz(^@2LtE-qOh3$ zQEZ(5e2tnXZ_PMSlRyz(E2yS|0e+HAD{IHXC28j0>Y(*;jgWW3***jPg#iH&t%oIOertE)}iN!h8) z?fuUadf)L-tlr6~Dan@;JKtK?(Y{ScQ_xsYt~9^O9U?5?Dj=$6v10=AmmhnG}CMP@}U^trG)kZZT+UI(HgyqF^+^FZ5W(-I#dbdjX5tog&6wB_QRgN!%aB z($#d1HV|9^Uv|HwHpJ24yQ|QKD8^CXe=RL@iAZ7o)Pk;k8q<8F0ORi790UFPhw)?g z@^Z$HleY2chGA-CWMTEI(T=@^5j-_j(+>z5sUB9&TFwzDH|h>QSb$o5qvb&WJ+}>Y z_I7G_X3-A_N}m+ywyMA9!hyw}p~b=8$d;w$y+CZ3f3vemeRKHl;_^C{(ZM0)kGQwN zF+4#*OLqtJw^v&-TXQvA_75Sl1GZrT|2Ttlv!QYWV~Y!fWZ0M01DXF1Ei*VL@M>CW zDhFpPFo6fq=+tQBT?|n9wR0|i(xgx5j`{6#V?z^YYG)GgJsUf4*H^Cx7l^h15cw}a zY|BXx>W}R03p-7^6qH)FiMxT_=7)6o6Ww>3*nQ7=;fIa|%fw{pRlw&OoX#3|%9MSaK z1y81DMrti}6{Ph?>ZMBlM{@1x1~d2FL$DP1=Sq6}*~(rJsC*}&dSGzc=<#{z^M~i! z2k-4CIMi!1Og~$(>QCd`rb7QFoKdCewUN>DO6w=7+K1s><)oEBcysiz4-YMn zy9rtG&s>*PO5D-L!`>@ff={`C&BVhF;gD6NWz^3q6PhzT&}<*@Dg4YMn-tCEC6N4a zixUe(+ZX2$kQfBEW=RXNZ_9osFj+JFtPm>~=sH#y-gGz6yKz`vxEkRNrK5Kn3SE?h~R{`1{@y;I9abJ#N5Q zUD^{iUz*OrJ!i5uj~nk*36aA;{Vkh<{{~0dpCB8%seeOs)pw9hc9jqDLk1wjXDlMM<;K% z58dTPk_+JDZUHCNB}& zz{heSZk?HDo%8SHSlM0Nd6c#1X|2)lHVl{Qu6XMvFVY?{q2uNxXDUvk-`P^drv*#- zj-N093VT>)fSu$H=Nxk1d~Qx#-lW!!OaUOO2T9teIOv5h++^xyQNu8-E$8VkoszNL z#HI(KJUz}_NrgEwAhf#SzCbF;Y7n@q59u3k^kLLHH` zsrd|g#f#vIvj5Hci_lBFxBcY7(esPlhm69qm)jHSJI{OtYw5tO4amvzW)C-(~; zeoCX?SGiZw``KRsCy+?nP*{#hOR@N&kLlglieWt;@b`)$APzyhN0PwEA&IAQ$Ba6<@TmzV5WOUqxn6;eVs*}I(ic0s#;Be!XVZbkl1QVQF4mv6Gfv=^m&hu3*j0J*?gaXj6US_vr>)Maufzg=Pn9U<%yTB~ ztPxIHUwlu82gC9b)41vv#hkCI(4gn9x@!8*;vHD$@9Q-3t?0J~v#lHUUdb4tFZdL+ zGGeHa-dr+>(@xx2s^TzXGq6&yHODS&7I7e#shvh`yk=pvH#k6eM|7J`3P+hdu6Qih zYv*K4#k^H>_~C6x@%(NOW}qD$b+{;ig-ZAPFW(M*6C327KzN;faXzV0OvW zV=`~vS7OGSJxj7-pW0i-?S;#iG$eleSviQqG!8z3CP+2Cm#CQY_+C8f43 zT0XOT9ke_zMPC2R)L#b&T^0R+4;?#S2Oswf=B`dsmSdGqtaEJGaK6ujElyO%#Wy`C zK+5t-?bPeZPg@I*H(HYZMg%zI5F8;Nt5|E3@LB$vsSIAk-C&Y^UIHFP8q;-{dLIM< z$NSH9$-E#Xv^n0uXwbQK>bZmmQ49A#D0vzIsYd%@b(A8+t%JF?D>{H?=xiR(-Phl4 zNxxAkWbbxIePy9#q0-v9x(-z@o}Q#M!fZ~B%t@ti+LUITWNk@}DErXcX7oG9H6jbJ?ckG$g7M;u7$E>^nAvn4x?O8mm9V~hd-U8oZ38531Zh{Z2 zf!OQxz(tkzZ%02{tzAWLSCN5k_F< zrcjTBt+3Z}pnj+Y$wgwOTDBuR z#7*FklseO8sG$!`$zC&UXS8?wZOFFEY9yC#@X(2TQb2@;{;*!Y*>CM~>he?OJs*0y)|&_xK?Fv=N!vyBg&{s1wM<_+NZ+GyTKPYbGI74Qb^ znW(&gHIh?_YEI!wsV=fx64?32-69G5c5EzE-z5HP5hb}o`VNgR)Dy5_*Vd%xn3}3R z3Asq5C{kon!IV~@QoFE-;BXIIOKvtoWfAv~W*kx7THJ`3!(UGcZAj9Zj_LgB-3eet ze}RWCT@f2=;k$2@RUU39CQtYFUqqWRc^HJeZhH7*ve>#KUL0a^M-Or?EqJpyqM0$2 z;wwW(q1p3sWxi3uj@Hj)G#$poiCliPjfC6eMX~lRO3njyA|)?1p(@=SPtUOQNE?(> z2|_|5TmU>rg{N}{R>Uttzm?43t0%#djGpdNW{l&ZYKfMPqK1sQLA^`nqm|iV(1LjZ zsUEvVLV3}W8*4*mo5pH|?ZxVqs+}0N1Jz71x z$iB7|PiBc7 z;o+=(kZo!yW(}aOLPj^pS!*Nj_lKP46^Z1Mb9YRT_~csVI1ArL1UrnXtL8aH?##L@ zo*YX0sAFBLvj|AV#(eSMV+o?p4b;_MuWqO>6G&Qb*A!+YK2*qjuz(znU0F{Isg5$G zbbt`dKkO4-XQ(wt06%?LL)85i5?am-$`Zl67vY)g zZ@jl~_4IC`QViG$RbZ8&oR~Wifc_zOVZ?3YVnMx*c>qYwRW+o+lc~iAxyy51Ugm`v zWx&w=UGK{oz9_A8t}|{{zJG$e@U%=dyw3 z{-NAE=XQlQD2bfwx~*C`SH|(OVTZ(fcmN3d2^a0=8sIRPLK@4kWyj;i=OTD-Lc&y$ z*qYPEnkFHQ+j6tX9zCt1Li!f0@?-_;inXl4?Ho6Mj z*ImD!Afb=8n~#6BuatS&a^up-2g$myhDH&9K~h}P^et{qoR z2X4WL&#fJ$QmhOB@R{8)7-5!|F5ha#6*MKA!J41rGvpC#8yG!}T~r-)`}Vu~ky5FSN(vT{tP zoQx!?|N6eVaH`y_5Iv!jQ9#@0=|dFF1Otn9pS>_hJsi%JHtgjV1Vznm62>!&&9eWI z82CM&bpzqzPWe~)ImWnKzGa;)U<~d^4V3yfV@Pf4g2mN^gP+!~Lj+u-LV{H&??-iM zBCvdi1k{Aw%)-^uN_T1}IY%M6bo@wC5I^-Z zi~=xXW*~*bgs0y);)2_DFb~v7xy@5Xf$&jnoWh-8VOQ7zV>URi8)f3)2N*E7Hf@Hl z^Hz)^i+>Q{(K)Cw>enLJ?L@KIl8S)Jn%*`A6t$d?BBu~UtW772xr0KCpDB~WJ|zjo z6&`_TkC$Ul$Cr;{)=N;$G?4^GO;FME%6J~WAXc_0UFrb`jcTFS_$7p;DA5BId}my- zxgWP3X4>Vc3!<*sS1<(95A1!Ckwv64yO&q8W0h?+wL+{sU!1DO2wu^>xYb=j&SS@v zPml@8)Mky#nMKb7pNN#Ud;!G?818)u7TP-R6T+7+@!M2~H-0*yEf>w9{Ma;El=9jO z3OUpXTVH)7@QVJbm+t3(w+-2bUfiYUDi`-cL!)6@VTvhF5&VQ(>PZXu?<`4FvBPgn zDlQ-x*=5Rdwy@{Hs4h|NuI>UX?p&+T|YkSiEe&HocJGlblG90P@6^syXzl9_Nuoa_XHt|_OXjzt!Xa>> zQY@N?;fMm^`74lJq1jEX7TPfv5AH|=jnAHX{tmlC~Zx6g)jh|z37@QH=-lZ!={St1HQ&!>P37?ix*nKlONCck}t^= zbP+QEegWKdW<}&>0aK?MHX$Ds@&R5t%C3+suwfMY-Nf| zhnf0Dy$Ed3L(z{RDgn?19jpgDNAVNJ*!%>6532{qYdB@vEv|LWwrz51o#BMSNU!m5 z7N;l9bM<9D8;ZBW%_kl^h%g?ccAMokKAXd$U^ug35D%< zdsaKGa)MWi?+&b@Hx&>?441Bw4B`}Q7vsr&wA&%qSnQaCSB?`2{TiLSX=CLCUyhevJE_sEiKwvWaNQ@Q#7YBQ zh-0g6XObzTV zo+rGa+x%D%%K?<=E(96Nbe7$%3n6G)QD@~vu(8HLX6UI9k_U3vZkU6L0dQ2bg@bBd zy#igh&yVjFMm9|c|3+%y@%kRtpg`6n8L*Yg&^ODLgQ!^3#KQ}k?@_H9is^5Q7}Mqr z`-jc6Z^Gw>HwDg#fZg33Sp_9SBS3H#-2Fjh*{X)=Clw9ITzWXRU4Ap zFSumu-l<@!Ggi)2LyS7^QW9TAB4$_fJ^c#sAQt^-9~8d*$cb$d%h{h?xe%;=&1aFynvnEAt~E@Gzi~SKpvBgsT{vt_}lTK zHovqOS{cNI?fAWrnuKsSVw}h$b`9{hJa!Hu6;~w}DbI=YX{|Mr^L^VMBgGjQNEJNP zL*wODP&sVvfE}YKafRGzEaxp+7v19Rvw5RBL^$tFcZ}tYtIpX9l2|8Pi;78wGx?I! zc)aVHiLKUf2p1+21X+pKdHpAcazew!TAK9qpbMjF0-KqA^+viUCZvwA1g;C`&Wx&- zo%*Oouv@3MOrw3};iu7ut8Nm%;hF6%Y756{09_6{5)ZtK45?qUG_0R)e&C~HG#RfR`k5SiM z=<%0LScdui2#?1-DUymNd+I z#+6C=q&{GPjq9k@-lW^121>Ux14hPP7263Kbgi&@R(mu?Nr@X9krfHYWCue#Aih9U zqxDqbUL*Yu#cxwQks`RzdVm|-Yym+^t{6?QRUzVp47;Wa=IjBWX)_rI4ONthnk|t; zarr7H%8ZI}S(hc6QhdVF#PgtGTdlY`w7>mNnNYqPbG48Hjiim=k zSHgoB70#(!MamZ0xOL(}O=4n2ALz=XzCpg&*BJQ~Py| z)NpeUz%7F9#%8620?EYZDb2sB$d&hiJ(%i>Yq1d=5FOZ#S&HT%k-;XsbD%?Hs|w{2iYo%XWR2Ost)damk;N4_})l zw@EO4Od66c0}DBSVoiKgS6w~9QX!KytJHdzBs;aShn34d|2jRx${0)nNP~bTLwtG_ z@m>{w!ls)%s$VllZEa`J*ZAN=wiMiqVf{G!oD3s=N`xED5VPgDc8TV))~61{9u_&K z+zA#px+yBxd$lT2jMD=EU1y1ihdqSf%2ZmzMK^jGD>p^jP~KYzC=XmPvLpEeSWJ-}gw;zZiR;E6n6yykpHA zsCVUZC`Oz+urFqUIoePnZGniIeC0-;+L_Djj{`uK6vTEiNoOmcZGkVkn7W=~# zq7T#;9?kb-W?X=K_EFWQauTXLJ1%ZazxsmJu)&Kra)@o(zRIfErS$QHJ!>Ho)#h<` zOkgpS@=V`~gn+ISjlX2?HcOX)`l1tbx*>Wntq8SOD8iUlSJU#G?LqVI92$~h4SE5H z2ViH#p|SZm!>O+2gxgnNZdTHs%+jtkIjv^R_zajVK3Tw@F3Gv?)8r-TmXpn=0UUhB zDyc4n@r%hLelA5Dlg77uLEYaK*BAUzw0UsN(ILQuHJNfx#$Pm?b-l~rf;sC3qJ~Uj zq7Kw$)apGep^CBnbDcf{<*I2sl3OQU^3|jbG&1+QfwUTb}16{YqW+xM=R{@ z-YZmsJ=ep){zdF2{*_yExtGd<=pnpyoM*31Hh7yhJo*h393M*%$e!@Z8A4MZc zRuHQFbe_SpxZ(b}sbs#=w?(h68mJ~Jw2mZ9NP#X(gdFql&xMo_v&vZvGB8xAwq;{V zwfCdnirMbE)UG>k+;)BO+C&Xe*a02OXo(y5Wvk<{Qq$nO)OY0G5ci?>X6!QZ=2gU2 z@!A^AjP^YoDhY67kF_4-X+k#mzEC)5W_VikHBPBX4K*H=uYu2Q5gGY^9Y>`F3%IXGu}7|G!YIIw)1s$_vA!xe4Q*CIqeb*kDGC)n`QycCf9 zZ7Do^=4Ng>BL6zwt85-dfnQG{Lfdb~mMi}(s7X_aBYMMPtcsU$4ZQMj)^^jOwcI;F z0%Onp+tJYsJ>3+8MRhIf3Gq5^W%y`z#PReJ33mp(hppUb^C+r9j8orPA{o^34dZaE zlOrTO_R03|9qJ#4r5NczP~PFKolz9)QBvVhK`rK1C^@&{%#`2_*;pk!0rJ?^ln;Q? zOkeJCS*}&`LBI_OG=q=N&fl9Dl$sNbYQ*!;2@5y#T9e+IkBP57vj>O&I zUtcb|Kw#OC@&(*n`oeK;9i+VNpB_o;OvFD%;Mai1POzY3=oZ1iwm^CRF zFm9mOyJd*%;;Wbei}J|4FNZP8^Ls;cM=m&wmNy#S>+PMBt_iyy5c0GpcR&&_o`iL( zwOliUiC>O$2DkvU&LuP-+f*c>SUg%ex5t@IBlSW}?SkL0E6}iGI|6_ECbq?DsL)xd zE|NRl*VE9fv}5z4kM2EXR~Wg$|kf?IKei&Y)7en zZm6b9=tFy%J>&*6yR+d8q5&68cg>VS4;nLxM4}TI#B|E!YmRCw2K#;^dl&KC*tkVYC^1@_%orKE?K-nqbPQ!>L91P zSW*DC;w3t+*QSKG-+wK)I>#g;?$sod_aXILV(T6OXmNchB~T_j-7*=D!FJA5x9ueX zYetO!X5!SIV37(7`@3+^#U>w0o938W@OhV-a*93^Ie{$TcIp@om2eng%2OW9Xu1U+MOVn7GsY)maAk#@MHJ^f6q5ae zl1j~h(~-o}m)9k51r~3dR;Svo{P(q2PbUn0Y9JqvB>LN14fEeOkWlxL(nG^4Jb?3T zl6^>iy&79T%r{;Osxi~NP%kcnENgGG68g4>1{^@XJ^K41sN8G3Xhg6#mAY`Gt{YZt zFhm9N3RGL;jRI{n<{eJaUQmLwiW_tk2D=Pv@!n~P2k@~Yh8v0I+1CO)0UG88q5#6M z%VjXhxSG<^ZOkkk$*M{wrxcA4DnI7?kblx}VT?SJqk*52sK>-k$XR>_Oi&_RCs|Eg zBzXKG7iPG(OP+S0xrzbY_zg<5Ta2P=_Rw;5GP@6 zCSa$FY!4PV#)~(b!9Dc{D#AT)tEU=hx}&WDN!vumJ^fCJ$MhIF;Ha@&VxeVbg0$y! zc|s;qe=v)j^M#(Ko*4+^E*Gl~jJyEu>{pOaB0_y_X%k&PG}=PE2H|5rUMN5iSe(%c)fI+6Q>d>4 z>t0%L3`>^UO#va~@jVvOp26A|HHD2(u`O*9g`AiYtZjyTqTdoa`WT_%vGaOV zCj_#E0+S=_b!2D1EJzXl5V0h0A79$XiwS8X%-dXa+^-O@B)M;(m2;U(SxcDX$%XGd_{ChkPPl16@r7_oeUw-OMM zA1!Gm?3^-RB?P{VB|fTydOx$8?3EitBq(tnKe$3jC@JM)4u)<61BwRZDw1OyfW?|s zP3)9ZAXfnfeU;v9`Coo6rwB&@;&4oluf$(^InZE0RZr4V*)C_3y#PTEx7gSj_8+S^ zsnI889;v}DCMgxQYv-KYXG#x-o}uT_@2j$b8DFujzT)P?fOOR_x&Det5qeuXlw}wH zZaE#P^oE^Ev5JhPB)LxTud_kr+@JWrjc5~@W5L10_2CVY^n0Uv-(tV2ijQ4WPnh1D z;Dp;woXE?g>bg&;*FIWD0t=P^Cvb*LjK4|4S_PIXI&uUT>5#Q)AfH@YO;Q7a1;@f} z)SSGE@DbtzHwE4=AGXrdMfI{|kYA((c@Oe~dx#oJZ{dx0xZ^xn<5{zH-55a_cekn! zRj@-x>q=yqq=!_xF|5qKb>CGMEa0vrwJ@J`Qo>V?w0EKgeGw+f!=<+Bz4tOhU9R4U zK=hl}Ak^K!ZIIH%BGKEk)8SDRIb-^muY`4JjT)$M#W>4`%h#)HE+qd9W?ioZacf#F zHF&76s9)W5j1s@JlZEbI&IO>(yA2t?BqRBz=BHY_Mn_6Z*-u>KJp)_>zn| zkuefMFgB2f9qI$!D`1{;Dp1twWy41}bW_N|y^A`9&uxLPszGxWg{Vk#r*saKS+_P8 z%^4^YCsCvFw^S%jU%T$rKSwspaZNy1fi04L4QzPa!&6Cv*3o5`i)PQGcVj=FpfGyR zCGy8OPhHTKC{-;xWT*X5Vb;y3z(e2mwfK(5g-?+ep&8_+2;tq5vZUw+%ldFpZOT4m z$o88rU09DRa`HWR{@#SIH=iCtD# zBva2(?gBtj)0l+ZRmD-g92$mY^*aUZm|YK$4qIf;Y{M?Xo{ zx&d8zNw{~r@YtiZto!3RD)R&8$)fY+yv}3VoPJT*1e3l&)S~r{<ejk=&(U(1+UvRuEL+K zoIT2)v=tX=f0VLZmz8;0(FCxrC7`a=kx{m6XSsy;-p#D(<~vJvJ6n*w?NB(DqEx0Z z{O)tHRNIDPxCpn^-5QNbD=2yNwp6frziR}&@zF-Q6H;`Gb*wDMOn2$7626s#;?tQ` zu_nzzN`!=oYE=N8+erOT_6YU=NFbAysgfqP6PsWYh(nm{`;O-i^b_bJbBSa8MBn=+(a4o#g{ zcytIvCf%$LXk`@M^T^}}7s*D^T$O_e(!JZX`}r#L@guM=qB4O|Tu1{PK9gOXA{WVI zVt`o;y6o@f;NI5ZvF>0x%t;p=n(;$|L=Nb&+i5X^Te|s_E$JfYy>8>0 zS=^h=?4U#$@e~tU;dET<&0V~cW{0uB71Vs9_b`|L!P-3qX%c)t+&iB+qP|Y z*|u%lHo9!vwvDc;)BpMAM0_(bC+1w7%N-e!krx?}YwujYXE`ky-@p?Tb7mP*ch|@@ zccj4GdL(2o^UIrTu**c~s#>2O7<&rRaAqd_GV748I+cq^~MT zT}`d(ss#Dk$32x9s7<$2$bY8vN9|2AfnULGoy4tZmfrBVx*jYpnu-fXLN@WS(VsG6 zGrJ!3;>Jd#-kzRb@0$+wc&4TXN%pH(zfm;Rg#uGxtUxa-(2Bn63qvb(uZoozi;;ba z{uRj2AN*b12?did3$}9^WFBCcD{s2Wp*QnVkNu{49+lOWv7yLq-d`SE(xAGR?$7^S zWL`X!zrM8;go8dvGJ4IWqFUr1_#>0z**3`T)+h=lg;aj<&=-O%(6}rLf@z|6>QdHM_A_m8Fv5$+Bsl<0|w7k59gh zqzZC>DvmcQ7o;C~l^T=mAAi3ZHN#ewi{NW0ibA}zVwkSdU2rTKq))i7{F3{uXCVu` zx2(}QV6+3|=0&QKsRza&dAesarCNF9+OnwU8uJ?C<+`7Xkv%U$?qq|+ft%annOFZO zq!)Jf&XYC)^($XCZegYbE>^?gr-DuVg8+EtC=on{FolIC&x?ze30|)+=#YvMZj|ZXi}G9R z;OAb^_4nk{T`^?uYP&wihNq@d(!~r(+Pu2R7k$q(V{dasCiay+xxf6+N=ys9(Z1o( zAAOa*tbfkvj*^{KBE+7{{i%Eo^v+pXRYiYKZjQ8s6POp_KK>kN7rJh_b3MiYiP|RE#{JqK^H2 z)BOUE?y;{3qO$7Q(<~F&H|(ob(Du|`8|wkk>q9hqc8jVq2y@k(Ex`&i&-Rx5!IFZ= zUOz0!2PmipV!x50jWDU86!rvQ1zvaN-lMrhXPu1rHvbY`T?bn_j@IJcA8VcnRt=k) zEV74+rHKhI(4o!39^p*Sw&i@}l5Rwv7k`(?gg24R0 zAP6k~Aqf9^`kDTdhx~tnApFM${4WTC;6H>Q0uTpC{9hE|KM+9$pb9Vq7#h3$HU$^~ zi~%M9Q-C?Z5?}+c1=#)52@U{9fD^zO@EhO)a0Ph$Kdi$4JI z?HJpp2As`S+@_AMQ{G+6+1DTAEgojE#=P_QYOd7@3Q9$#5={0c4q&OZ&5pVM+bXE0 zXZ%m90CjX^rN+SC?-zwU#^x_KqxRzZ%MUx88#qQ+fSJh{Gd`!g2VY=h8KQp*#^7Yn z@Z`wQ2&A5o$?+$ypa&IEU}|l80*+`FD88W$l$$g@YJ4k}R!j8(Gj;O8%R3spj zHH{3A>uf=ST30gxN+2pO0aY!8{4=2D&ryvVLQwAhz7AkU7RDdSt-c;V$i~Lcw5EoN zik_OFhMcmL9Ps|F2?!{K*hUE^O^}tSo=HZ`BSa0U-@+ z130U@-D|EaZcVOsP8Lq>^}lur_ik87lLxM5g)gnG0z8=J!Mo29nq0uLg3Vsc-_DJM z*H_!u-9PYCHCIzpejJ7;7yadS=Er9+$rzt)&=SFS;%30Vf$LeAm>iv&K>TBY^1~{~ z4{z_RauNFds5AVc1o7WIdDeJ3)dVlxIP=eqoBttsidKe(zG78JnQ(KNT1v zi$5w?FSo$?AFoadpx->HfxH%00YH`f!nLFSoC3_pf1JX_kJCS=aJQ@YZ7=-Y2b<{7 z((s;^d7=OD6SuLpGBNVF3z1*o;sQ+X-_2_Q|1X%fg5oZ(Bn2{4vt#4izNR^f$pSg} zn$G51xG1G5I0bS}W_)6J=^@YZUA*?&Ytp9r%3tbbMy;<79feGSotkT;2rHJs9oSa`I|@qBIVx&!DmDxP{ztH z!F+EVKP0N46+*Cy{I7ratQ>yh563QMVF!;H_9L^&&mNh{=W1~Jej9~Gn>#`T;mY`i zYzX>Y`of;?{4EdFx{IQ{*|*>i;Xi+c2&QUnhUl4+om2DO2;A^lhA>ya^39Uy2PaUH z@e@Gg{Mff=f1GD=Roz#xsekW#d99oC4Fk#C@CF-L+4^@8)WVyN7oRS`)lbvk#BUY0 za_$2FMe=f}k0cT`t&cR6ajoAH^!7&kaI1Iqa|E#-xU<~1l)r)hT`t)BZ!0)G17YzU zhR=TDC!O;h#mcUbfRI1f{1fFfH#u|mh6%>@jY&V1&ye#o2T?hUZDIYqOF8wu332v< z$#s=aG?O3oC6A?Wz;Eh*BQAz1O}VEp+whmYzLDwkGF%|0qkZ!S9aN;^^54T$Z0Z9G zocNKO0GHhTg$?9<{165mTZTP*lE3=tG?&rM5h(8Xdr1zYEA$ie^IQuWKp>zTT;k!S zyn}SP5&sfqW$5kp(c}1y{lGhoX61QHUWTwrX|g7AQ5l^NU&gaPv`?_KjPF>fU0`~k zew&o)xpueWe%xxFhdHQ`QqjX6JSjHEYNZc)6#ZyuH|lYEwGJbREh#Ib-fxJa<; zNg$)ACrfZL*PS#qqD1tLH^zwmZe`u%{e$zgMXh$^U@JsAv?@p#$|H)MTXdh^DV;2+ zXHQqBp1b~Ren4FyJ4Pg}TPkkCVJuP4v;@U+bxHe>y>n^2`;#6SNhpHfzZX|uc_G;F zOr$bgbJ+|l;znuk16jg-&61&U#kXwU)-Fe;eu`K36(U`9q4gKE#m$Rvt(y)m0d{^L zqO_e4mL1Oe`O7jL$`vMAy@Pova@$gjhVH&3rA#P;3wF@i0+^I>{sMg$xl@k-ZrFnd zU>{z35(^eJ0YV5z((QO!+IxFy z^??|+p$gae!FHbWN)dI6hjjpa)1Q*)v@CQDI3x1hAt%Spt0;cRahSDYa<5kmnlRF* zz+W|l9gkQuY&1)oMr)7BlCJWk=c5R?AYmeb!k_K8QwVLh6B8nEjB!_N1OVDC{s=g~ zZKXrF@%OC?l=$uA>U0`vJZMGtK9*Hj`-goQ*`b)BR%#qk<(MB!^XjU*;hb6(t?2AV z1Ib?fmvF$Axul1&Y)_6GKX(YtNv(3+W-iWB7@S zi`)K(X<+8lI`H1e`5aa97~~p)8UT|1l=^U!#Zx+9j zCcSI!5qf^{9TcFy(C^gYUFaiH~_DRK;mabkUgR%EZbPaYHwjE!?iyHDIQ+~YyC#RLzI zC2TEUToPSO`HXzzlrh1BTBQan)0`^Gb29IH9*2lCe~!(iL~7gi-I4QGH#%oa$4yzn*fF#Dc*Ev{!hY43aIa1T% zHEAcnQz!-(;1fBpJ&A0wQM}LLqp>(%37Lg=4Hm2|DA% zH6mhWkKRuzJ2HfEJr$cF&djiQxUt??LqUTn_`3N9#BCCc6%R0dY1qTECC)9cNdWWn z!Fw&Y80jwzzDdEP6*1-TrQIME_UDl=pKf>IdVoAT@MJR1>FCf`>Q0Ght2B6s!T8K- zL~oWk4^|86YwX*XYoomxjA!BW`TOByq}wB^5O^jX!BCh^ESZzpVhYdO3#D(@6i&2$ zsK{H0m0j+PMEXHzi}O_v!T1aTbictPDt6IW_nYT{Pk1hqBRDpMPm$&W7lm z@93>n6h|`B)N`!zVwRNkK3w;>_t7V9JsIryM^XoLT)#wc29_#GoT5LyOEgZe&Pob3 z2Rv|JGuXRRcKADyD)^citOPeD`-c(+L<39wLmWJ+=r%@sZf}$aOE=h-x`P>!zmEZz z#(+4Ba6bN|>UZBmOhFsS#M9cp`?%r)>uoqev0lb$bVi)Sq9;jsBQlH;c|*`K)wv>s zN^UZWN5_~HBZ zRKwJ&9nPH?Kvts|ROae48(_FM$O<8drFoK>u@QKV@=HN}5#+--!nusLu=4ec5_I<} zeyfEPmp-{(V*I^E2IdsPJiW8V2CR+mGJjWa?Vw+p%Zy=?YT?@dYWK>2`0|b}i05L5 zq|IFlO>Edq#;pCoDm8R@!5ZCFGssz(^Jo}AH8CH@6uy0saL13oQU1n$pi9u#NZ zF=M8`cpcwk)U|Iw`+)G^aRPnR*zNG#*V{+uA{0$EMi1|*jC2{DoOX0Xk(Ao>A&Ly> zwg~7mH6PrECSU+1q%T-=7^Z~nb1P&`t$S0|z%n1Ar`z%K*`P=}$ln+AvM~nL5yySnG8dso?_VNe^;uvu$+G+mlqj0-L<`fD6>SertmwJONH_ z8~o&L8MEXwzx(?>875b|t_!ItO6YLu4*d%z3ulCbAH`s^^$JD}lBw^7Gc_CPhlBnU zIQzRIu{XO?E6(3dID5U-dz)_A{2^3yxPt@Ckjro(hn?vfkS6_O-dXcKNAz+4F6%Y2 zH)se~1kcwQ@mWdyjBd!5H+^7&soOzKXR0 zKdjmLW!Y;%072zWtCG-XmWw$7U*I&vv$SI8`vA< zLK9=h2E+r3EITmxYQsV`c_Q@TdgU|D!w&EX@MhKUOG$}=5V}B*@=q|t6aEIXK z4Z2Y^o1x)8x$)8ao?CaZ^XK+N_+x!VxRt^Dxi7j7a}q9w4s5Z)lNN4|b?FPk?5FTx02>eU6?*OrSM{zm+eISD8W&I* zBR4_gG}!z5tMR9vyhNN^xfJ%XKbtkz(`=&lu3z_psDFTZk>bH~dv6NLgJ9l5&_($m zph70>iX>mVW10;EaK5#RHzr&yG*UAgAb5X1zS5MqQ3=d3VEZ=Kc`Db$sZ=X3I^?e) zI<$8386lpt-v)jyldI+WUPx0O^Yw@x9R;QFRA-A$1^@OvJR808UXb-A%|+IGDF%H? zX@r&u1}t3C^*EtLZ^EdAEBbE?EyKb)`t{wnurr+W1{i+`#x>()cA^5jz1+1LsMlUR zH@d#7PB41@`EmSJB1sZ>0sLwM9GtK^9peGc-^O}~LXV>8@JhnGq@F1YX@Tqygcew3tJ* z?wNBo0~Fd;O!kuzhHA+*$(XXy%`+(of^d0bG;w3x)+4hyWC41V>O1fIFW|kMa!&mO{Zwdr|K1+0}Q z3f>L}BdHN#R&?8Opu2cB#Qed zo8A3)F5##IQ>nyLN9Y_h6K3Kc>+eU5q7J~Nn9|31+`u1vrSZh#S9HkalZP4Q`lcbR z%!|5SfE&E*^o9?-B1AZF6YSB7aS)kO4rW56lD)&Av3>+RAug#0;-K|t-CyH2)68wB zcx%vSb$+6F`ah|K)e4bXFc6Jp4u9Cf zu?jaKhG=)y3Gkoxp!)(~qrJl8hy!tnqN&oyC;YImGBksD)`8Pz}vayTb=zBQ~yXCJn?!~peE;OMpH43UYAn2fRP~@!Keq3?` z2GGe}1a>d;(huGnAM2;++31-JB}L){HNGdUYv5wRtmiGp{!Q<~WD`lh1O#onIucR{ z%akrnl2?XpJ%^@%pm8_CUzR}| zDXvc4NDO9dmtf2@&o?XlBtbXmwPF{i9Zmna_@N&;UVcP5n97jHRnKls(80)oN!w%j>M)f!B z!Qy1ShXxM0l*z2B3))?5G+jE16~EIggX-eQ6)`od)7IEKKSboCy|P@-5mnx)nNI#*lns6~0|%KR{B<6oo2@V>J)FdA z9w07;+OE8ZQYkv0QM|A2CUEPvJ5x3$`Rm4|_o=4tG(x;)(Yr#r3^^z?>w)am`}Ivg z^@*7oGgn{n?^oB1zH<7NMSM>}l?|ASRCg^Ys`wlUcqU@|OgR48aVb^kLoPAEBnAvf z?0NWzS4^_w)Ot58M;csv+qW4W>#WDSG-5E@PnBSuMvajPu|(JMRtIsskuoGsi$*ET z{x!3+m9rI#W#3 zvrjXf@3o+aV4!9W39*wQYPp7b=PO(zo)moR*+ z+Us|BGVf8xxc5%l*1RH{?V%?*f_C(>IdsWF|DjZn`evz!a)C5>k0H5g0-%nWilm`* zT5V)k{8u*;KZQKQpb!r~CEgWG@oY4H$?s}!?9HXlzu70DIlYW=Zds|`FE#J_eb)yn zQ>XnMVb}ZZOO%elF6iOrx%+tr2(T?Brsj|r_wqlE)?|36^;`6B=oo6~#k6`u*m{uW zmwG=eLQw2b57&r@n&VmVBGS_Gd@1-_81K)X>5$TdSNBBiGjmdi4n;egmz<8>mO*iYuDs8NrkBz&Af)Oh9;mc(sbgBcOHppq zw6mHS1aqy=Xp;zM(-f;?q+6*FRKP74lAlKn+35J}T_E;dP_)1p%|-+7tLPM85{p&} zfM9ojp4!oEY?Z$xW@YHi{`x5C8MZ@y=ql@9-SdRBr+`XM$UD@ znRf62k_j<6SCN|pt#>lzAn}WI-U|@7y50<5fncwPkCXFrh}PCisNNL68Q^oSYIV#j>M8iT*SD5gomU$LdB}C?y2(a$^o%IjFuiUYe^63 zZgl{^vV}IfqUkAu7t~EHXdKNn$#u@{WO);(3XhfkCL1I5{8ds8D$jNADR6Ex^&tEl<-i*$%XrDKXez&>NN&)tANASL zxumeCAX;hef+Y|z5)nh-?`RqjO^|8TMYG(;b=AaAg*UMZUR5o#*t!yaXU#hUNl@PM z#Y#tbGiDeH5xpdNi=dr;X-Tmr!<5ATqMwglcWJUV`?<4N2eh6+Gi;CzSK74ogfZgO zOLIipR78MU&MsJ6mFO5mney1C;4G* zggBNWe59I>2}ruTT67smE=*SDn@tk=^;U%Pt)%pbvw^xF>!`6O;aGZ3Ynp!}K<#B& z+rA_URVQI=^#dvI)n-*ov--v}Sf!QO1R+~VDh_MPY41>vQ#+I#eqNEKI^xM$U{8uy zEOoDtEAT#n3t3lpPp}v%3{4&JD90j*P~E@XZ@zWnaNEiQcZ;T}qu2V8{Q`DGgNXA@ z-ZuqT>-iiEGwFPP$o6zH0Z)+yEj5wQi>H@?yh0}@TzWUFqh;2@pU!?IW7oNEUeD$! zSL%@*wYyyZ$ZB$gc+wj=Ooz5pc7M=Ml3@E=Z~yxDAyjNL6Ah3(^?l2eJ&%ZkeIo)S ze_Hcr7EMo-!%E)>4cvj@h`0;FtWR+RPDTKkYAbaY;_pHBm!CaMM9x6Q;NWg|do1fv zxt667LGa}O(bEoktD?B!+%wKE+eQ|EhxjaiYjzG385<8$)HsjLMig(RT6Cw2(>W*fUN&PI8t?obU;IsV_wyFr}J@`P_g;=i%ypB_eBY!qVr zOjplasvkm7MgRiC(<(!)<;hT|m1ppnY~`c)z@!mXFzL=jWLxq%v-kNZiHsLRhRd)a zCnNd7O~4h>k$<5Rl=nF=P9f9kNwV$?D+IeeK93l>$`q&kPl&R_B#Un+kKmu`Za#`F zCMp}Zp~2hagb`NaG~)C>7iU)sn|<+cyU#jZ`$o)$wTVT|rF*sV7jn$<&6n{-5SZnG z@)rCA)twPrXCu4V9M~}TLRO?JI3H1`lbYAfMRXj@c#~c@aI@3KmWfd|scyb~)f!M& z!eW2&ZBi)3Gh;nlS_Eh=1C#(^zS-YWwdpbi86%ALooqGfg{=mPw?HG5JfkPyfyQHO zP7FQ;BuQqhgE}bFVn_f?PO=vr#Y#3Sf$@A1)e3$8T=eIj$Il!rcZx0l2G%{Mjo(Z( zfco<&8b#fP2L4OvCjUXH4&r6ZdW<*kR@^I3$TqMEWOb9sQS}=0;)+`DuC0~m&*aU=&^CtHr3 zU$@y6_l0N&BwxPYe{!lj;C*zqg%VOZq#?R2k`Um8Vra&?y4Su0pb zkMtVpy9_C!xL`~kAnaTxiF7hpC?O>hZcJiSttZG*&x3JG;n!EP2YPWpLt*9BpYF=2 zDu$`~9S~G-Cvw0S?QIR5GCljBP+_VNrUL|*ZyLZ1iaxxB19Sex*ihKSnJPA5$MO!g ztc7pfBXvtgjIJ@qk}{<|q3yrE#Ph=FE{nW3pkq;z57lbU{Xye(Gk_ZHzg{WqlkZS# z@c)XyRhxgmUw)HQs{VveP;vIfBb5RFhiL@lhl%)y{f1X^5w+9Mr>)Ptw)QXAb@ zK0d>vG4h&}1wT&A)mmpaUHRgL47|yDk7RHD8X^3s97wima2qb7jIGgwOLMctUU89k zVajDS*7B`9%~9=j<&Ft9PL&l{Dy}@&oZG0EpnVWj%9?7LklPE(4AvslS2P#I|1Ilv zv#j<)ggu{|)h@HvMj(CJ%1Rosxr!ZdERse}EOwYyhB&@_3*Fr|Z{}2jxSwtRmjld%;4Xk=QAwi2G(p^u{%W%NfG- za3Zn8@Ij4ZxRbP|e9(dWTo>yOuZdxzw<+r`U3MoVN>+Os%4$xtm?G?Oz$G1nBo+*`0 z&0xY*coqA&Ei{99@!Fba?DK?)utuN|ZC_^2YL=0WXJn97`;QTHxpJh8V$38dJ=}p3 z%5b!poT(mE{pQ$9{rs25EZ0b9c$mMx;ij%C{D}117fd#KA^O)?caRw8wwXOQF*li{ z*;n!2{F7)|8GfbLcktyOyJ>5ehNsC!yz%T&7V+)_ds?2f!Sbjm_%doysI=*{4u?tjp}P zYfuQz1X^tKxK9@vRe4XC+eDJRs$Lp}B~0lDZ#EwtX>f!emLRxN+yu&F551yi^*U5; zUa~^fkMmJVfYh2 zT)V-lK&$5hW*Fc4`-@salNG1)CY^J*Za8N_D zovy2?B*)+-YU?^NkDvo6>|j7m%Zye{&owre?8MbOg;J_0`5^TJ69R^+6`nb2U4)fD z%Byv+5la^Bi91(fctlSEs$qcA`nId$LXij*k$8jeq)0qzXCuSB(YMX6&5mmgL_Yip zvK)hoS@?BIwI*Lil}-tOyL(4^C%B9Zk>1koIS)UWB(-m> zkU>>xid6V*H!Pv;bJB92z#|vQmkBfdMdfN!&OEINV}kauunGy=L^1F&``&{@-K&e^9Qwvw)dis0(?-8!*?n}1mh z^j2P5P4xqfu!?aqEV>&A>O|Gv;&_FaSY{eoAF@viqWCnjwXHf|lwJQ(Zxl;-dag+8 z+mUh3iz9b%G3m4o9t_hSSGD*^<+G}?CH}KXk4BEh5&W%ppeWfE`jd2yiDs7W$hU>u zKL2FsRQH=92&z&X%W*rK!euy^^pvzGB!6)UFnh8SEc~(Xuignz@YoP(MsQ0+k0@(Z z!N$c&2$-LM8K!rbz%s6xUqLgw6=?}-LUbTwK@MOKB4tAc6ezA2Li0Ssl2Tqkjt%CXZV zU%gKQry$xEB$<3&XDnDTo0><CEth02e!n)wG6k|&? z`1IX9{k?_|%Grup$rF+qM1G4d_{+5qm=rFExrth)6RLo2P5M_e)O}#U@%uLFEDC{i zwy9xu#sKjrbNjl=(xmvuNZ~49&FhhPA%&N15SVRN-$keJL~rHkc}hgA6#PnC+0w!? z1tvFM)4A<)N4Dpu#R^U?M!~PP{a+9=v&2P_0gf9^1ZwXdnqSa=+=Q=lLlY|-#Yybx za82~b?B$<=w4x8aIg~rQ4-UiGsq;z;F$iQkhrEL3bsSuYVSAKpqrZF7H0y$oEwku z4i5pRU(~# z?<}^$kfkDJDd;im6vw*Z_6eX?`=O-C4pT$2gx*XYgK_?O^?)^vVr-v9sa+g!a&BeF zM)6>p#C)}`<0{mb=ti^0ug~Tz;4eaTjyt5f+UwyLw1t?2Qc}O^{VO3`sLiSg7fwO( ze6BGXp*7%*CU^S8&UPZEZq$`NR@pR#JtrL0VhY=lCcD!AlRh{M+#K+(2v|u+(mmrH z&he@Hu&h;u-6ms!m4zeKNrc~cT`YT&PT#&q(02x{CXfE5^@$Xd5Of&D;qmgpD-x6) z6p9?1K`6VC~_(ypXw=_xM7lhyd{gfuC#3B%egFonHg zU%@#rx5HI)7Paz8-JiB z%*;1O@*p%S+tee?&&{7CD2=uPQT2;PLA7L8hd(TDM}=URw90mZySGDF?Q+)27AWj{ zIjl3XOD~Uwrnu%!_pL%I%e(0{nDA)L`T}(QO`)SVQxjdf`?h^AX>>7juo0=J&iVtZ z7kfIAld4Yk?*KqMDgp;eIzv=(rnTxC6Vc;So_OQ2R@LgT)DlNyB>IY-zXh5Ws`l}yG><~u}H4c|QiCu<&l=lG&5Wt ziChKd1ZU{H8WBpvBwj*fV^VabQ~?!b%e$Iq0UAcyU;LVID?XL*;ub!kF(GO1WbFlhGjW=_KoH}j%IwM zyGv3j+_=4!9mehqyl76!83_cMj`#>`;cl&v8^>J!wnF<6&w1((*Lwsvgse!dFUMB@7@RgUlDJ?{nQ)PL zIQ;#AKS}?s0`HLhncyQ@)REKpa1_ZaQ|laIt@_8zTQcW;iI}Fg9f98ugdP~*Ncuw7 zk4c8p^K^_?h>>5G4pIME0rs3q78sRS`O0Fm$`@Nij|DY?Y+n>>kda`*N?{^JGtx+OM4-dm5}n53p0&2PVQ+8K_cv1ya}OYI*2k@R6?(3l<_r@*^b_+ziP z;?PCi!ILEpbd zlk6x^OUsuzcLGAHoj!4I@|T|M zaLC8otdT3Eg7s%fH zp;PWlCYF_==KT~jD08vV+()qDeD~xFaI9`*#PA5gtj>70Dr`@p-OdZpV?jA z`5rzfX?KyD?}tKr*oM_`31xg5Xayn$Ke(Y19%g4{Cjt7I;qapM7i2=&{0Qg)jI+<8 zY2Z9HIXh^x(vsEQ`zbL35$9g@~(Lig%Ny z?)+${MNP#^Ixd=%7Z(3sRrztcB>`PowlLt@52DEe=g0EaMnoGY$gLrhOQ)xiSbkUV znb4n+IqR+*fWsh~AniIC_0qDo2d~1!b9XiVp6xUiv2_Xs! zG^iajAEUaBPWx7*d+lE;@M?-lf#JG0C+|40gB~A@7MTT^Sb}&~wvX%8{UTR(;lb>= z3Wgk`k}oniA5$VnV7kpRBd3YWHy$t&XBfI3IM*A4&QAbq3~#CoQB~}obi31Etc}DOz!x07 z)p3s3gh67Ngu_%AqEcPl;!2sTc(0iNXG{a&Tdgp3< zR>?4;!W$HhDV-?CrZI8nS?0iPoq@|Rf`+?HkzjPbx-iNz6Y^*r=Oq-I7h7WwA6u)R zVqz0c2ET?7hZ-usP35Nra9hzM+-5?H)WT@07!}Ec(=mXk+-4|rfOW~@i)v1mBracj zu)xq!?L;#bs-Vd66S1gulUSF3b*|m83ZY#+$%|rOsxZe*^HUgp>I)=xn zO3H6aE{-dPxw^B{W!kDRu8aH3E~o_Y?10GP!kY6+O5$MkK7vq|a-Q^p9wGv&{-X2l zS1s`R_G`i^nkW8K#l(J~6;=MWR6YyxTKl@NFReJ@jBA|c2dYGbC_owwouk8${|x&6 z%2Y6Qo zR&!}v@KhBsI%!wp-LpCU*HSgBGVsB|PSG1WWsziC!|uJoRj0$45N>jevd3A)vuSnZ?p190k`fp%r3o6IE7+^ian)&9)fNf ztcMoO$d$(Ou2|N{yv;KK)Dg53*5C37o?FbF@xm8J3kTKNFAE&>g}jeWGP#;Vz*3{C zp-FH*3V3?#wbA~99!wCeOY#(`;ama_WZ#J%_L7y)%w}t(6#o%M zy@2CJP;XF*Atg*VwmPrJqYAa~Lv0+ybXS?$lw8+4t4DgmBft97=RbKLsTm;bnQprg zIfUsi2W;a??c+6@MR^>45=uA%n@3HTB;H;FB>G*hE{nzb5`BZ87SnF|;}{_EbqM>1 zjTpae@H`f#xo(OCsNvMg+m>xOhT+E~XTs~0zHo#C(!5hEQ`%2VNa#F;K#ufHt?UF? zGp=KhimTM5p;)$TX9-uh@$M1U7)v>nekd;ej_5q$nP~oNh(Iw8+?YY$(hm@9jB)(HEv9&+Zj$@`{ft$pSK-`}2b1 z^=q8#NR3%6Hkr>MX5EXxm?ljaKGfAtKnb_?c!QyjTSnEsxz9Z2%Fz8DRo|&ldme0B z>F~h6T{w&o#W5jds={y2C%yg!k$BeUQetoKrXe`+b)%hLEr|C&@t;+;Yq2*~3}lDp zDrejVc}%FEVHRI=rrcTtcO!FeB9VjJ&|_l$#g%ZUFL&g=eKcwkiWCb=hQ8v+f`5_t z1R0qh-pS6YE?uqS&uC|mT7U;{>{Q4=R*b292 z6&fyaU1bSJMxj- zeg87YD!Ls{u>&JG#87xiOkk=htt zK1XWN=UUbxhZFGz+u*2#9_&~OSVwT}T%^WD_LvXpz?bKq#9uy0TsdyB3~!Xi*F2e< zcUd3nORn!dtD-ttlwWXlNm>N^9JakZQ`5H5F@0~hnC6w1#*-KY&Mt>@5QTROsejH5$ERsS(~mP(Y2?6*(mwPzj1SYNRV;f zLakj>XO}XfB6%=wZ1tCl_#djZXPLag%tdBanzwj$UR$6Qjr|uyr~06ne>(Mnup&k=+}MM+Eij zuop1c7ozqXie7g%UE(2@QU(oWukkVZ5Rcc~4~AFsZEQR=+mZNYFCiQ@u)>|DjN?oM zEthr@5I+lZqsC9V?PBM6X5?xMncWkCMv<=hD`aA22GJf&QB;V5jQa zgJaPH-(O{tD;BO{_AbGXvs+$-T6f`RTNooU6I`8(o-8m!peN!8A%>$SDpF>m#!^PP zzU+kdhvJ&5aB}HdMhd%{eoQv_=YVm+S!lHa_q#f~+mZICp|aO9ccTwT?6l`BSlT;i zennHhxQTcbrh)iSbos>XhK!|pWYNBai4 zT~oWA90U|F62vs5K|ZkM#PNS95RZR6VCZ1IaimY!leJ%s(Q{%`24bI}X1PuVj?p*r z*33NT#8&n53ijwmMz0)yLcIZd}|8G*r$r^g(Cv)vXti`1Bm53NBr%|s(y zqJ5w#EgiaoEr8>v-w!^1X=R071s58n3dZQ;UF0GhvE|BmP@J~g3#)B&cyog+y9iBd z?p5-8k0KGGON10Q;0Y%2P^t*kDjz}bIEz(OBAeeBt?2xHR)uZGT#l7MVALaH#AjzM zjL*j!Ox|SdVnr$b2U-(yX|L@5OY`Eq+^h@sz4Y)Wf2lJxnBs_g+vZ(gk5sPLbc8p6 z#*mv?6iH47Lzw7#VC;#TCF0~Ix8Q%a-!Jj99%nHbKkSG8+bEB zxoJ2)ol@W>F-ibP6LpLY4!XaE)p77&*=>IreBpr@;F zdMClcPOfo$SjC?>?jE9oeTA8%i9}Uu2oWn16a0+hYR1R{-a=}R#kgr0JDVre(>*Df zlQ7smcJ<@HS0VK4NXDush+^%b#cdYRfLaJq6xYURBp-c~bApzfN;3W3ZRu0-@m8eh zSp4gLfejIaFI1U_bO@T5z-PA$?%&PSNR@AbZZdGG0p#)js;JY21^O{MwODAxbIj~$ z-?fiJSE3R$g7h1PfSFNbp<7AZ9GWElq#gT|c|U?HiEdn)^^6-$*+b09YT?% zJKe3p+%G7I^%w<$k9w+nzf8YR2gT?uIJh#RLM5la1eYUkS%tCWa!Kd;INv1u3R%(+ zhkhi7606InJ2$u-7ZrH^5ywv;lAVt8V5MpIbLpZTTi=%NFR(~%V>F+2hUYm}3(O_S zmu)>+l9#;xV~sibPM9OEG$9JwUdDz*k}3ep>WF&Pzw7}I5ylco`@mNS|UqvbW?_az0o}-W}4#(cZ{mn6U_b9ouu~JXZTXpRzYGgkmDfsd{ zP1nc$8Ef+)I>zfDYP|RjE`L_M9Xy#JrEI?MuN>3yeLTg>NZF;;K8NMmon)?rH*Y8U zv-iY26$ufB`&y)50e0Ky!R1qca`i^ix{%oBGT`CszY%A3x7iDM2T^sN22e<>!ugwx z*by*hH1+abT)oGwk6eQ@Y9~Udsa_F7Y4*p%WM^2U_dWO0{TfV)9ur*4z;UAb@;Bk} zYc-4Me8J@vBD0w>A9Yu&+=@8wF>iOZ7=lW3nZVB{8XTtlUTX9`bL7DqaRGtCT>6ca zS_%Lr$0XUxUS(gXrr_&{oa+PPcRlP(?FLh=Kjv0CtPmu|%m_7Scq)j{C|wGtS7R*a zdK)+5N6~`1k1c?6CPQ1&`DUM6ZJcbet9z-tIvmR1DH#qcpcXE@v6U>7G*d-RZ+F_z z_UTEi)Fc>^1kg5x;yDQYe%Ap|>qTvN-KwTq(~YG8^9#OD9QocM{7o|wiiu9s8gKBz z&0wb9QvjT4TD#^K``yV7d43+-R2=hP?YOCi-|AMC{aEtikNuAW!i6k^s&(GJ;fB?D zC6;035h>=-TaU1bj0f_c0Ew8l z3V@oiBjjHqCFqp4sQco&skgWwLJ03LYjjw3H*N$*!deVH?9ci%tWC2wOr)zE3|=>6 zz^u4!NGvO^JSMse=)8zGU3YsDJ_*LO)i#Is;E48arOm8xBdq+ABBcZ8Cw~}Irtmy2 z{TS53b;MpDWnpOC&hpZKMzPN3DiqjCwKfv~URQa~efVVaAC=`|x(1bJt|Q-a#{m+M zvvAA_578I4 zTHj*~*b%GzJ2y8heMu7UJsxg_VDV#yH|r>&7?sQKQ{D+)nZ1&34J`d;Zm>oad~g zUkY(}?+DV6i}kDf-!sKw(=uF}v_V$*q#NgkGud(s*{8G$YhV-J+zuq2>G3@@Y~ucS z>~%?w^KJp2d5huhQx6caR()MT*FL3Hp^ z+FztS*VI&7!3WI>?wwfmFSoR{Cvp|11*@~Y68n&4TQLwi^+<2ZscH19VsWv@i{=+( zJ12G0$QuC+FOuA;c(`X-wRpe?lBOzw^w~`sH zM(e<8QE}Q!)oOX~EBT;W7m6Kg&Ux3sqihSwR!@BOD^A27pr79(NR83>AZ<$4VC+S+ zQMh_#UUU61BTBlTH6-IkE7rP=yHJ}f_oL=J{GCSpLs8lWDn=UgfT7&ePf;}JzekhC z6su4NaeF?#34f=wt0RuKLe#6yOyM~gH)d})mvn$(w;j!ehIjPy3*=l$iQd@+~wk7O5+ij z%8%IiWfbF<*;Itk_#m7&+BPwe))S&PpuZNz1q1b8jZXGZH`dX;`eQ-&9g$z^;!67o z(*f3ik#yHLy`UFqKSK~^@Mu)516;hY&l`QW$!23xE$fOaa}&&-{(Cro+1@PE3w=in z&fu~Twh_$QY4gZ}8+da6^XIMnNssMtxp1&v7b4>siX{w-3Qiz5o(LcgQ4>D_X!mYk z=~a~XNR9*>Sj6?ZAV^OS%?g31%R$~x3jQrN$olVhYlU}l2@2Bfzy%f%x6ga+5T7H| z`qSGw@#Nui#QYgWZuYY>R}~SP0BW8%P*H{3)q>7)Nh7G4}L%_y7 z+*jxwi%*PO<|CoYv96xrr}TX4*$L27GhQgJ>2uZTwEz~)p8iH#HqE5U$U7ow6O>G! zRg3lr9|2G=y4~?GrlMCCa_ReW2dfk$FR>N(nGN z5`-g9>Sp!QoD-&mF@q+10FzWqvi8apzJ6W4SNg>#&A0x0ZJE1;-2y1CS=rauI5oAx z)+8C;Uph!qjp*PW6yn+!ET%4MQ=rnSwf56bP4rx(XKK>`GylMt}FA z8o2Rigb&@3lmVA8a|DSRp<)&qL!~u2@730oac0v{6Q=DWUzCaaKPLcx+l#wZ-y%^e zK4v!lN(&k30QTWX{ksrE9^Q+fO5FmB8GJtulXk-3S%0A^dg<`%Hqes`Dx{!#_kJf9 z#Xp}r=zRy-C`1;8&F!?BAF^Z@%k<6JZa9jXyG(R!X0Hkr@|+zZF8SiA@_~qw0ejy;$LKuOn6_~_vTv4!Kqen%v6#xjb9V+A8WZS4FUIeWE?@rqH6gQZ6;ts zViRvZeDmrqtMS7)z~tb-l^SRq>xvo@6$l!--y9nKaXLc^_!UwY z_+Fpu_}JbP-O)`f>)2Es+~JT&p#L-&Kq^r+Tm=u#7g({9ArBDFlgV36p(i}GAAFs> zgMY`QJ=)Y*_ZztfyQa*VWCtYPw>k#XshZwvS)nsu>GTMSaY-4BwRF2cBpRO8oX0i< zzqc6FKTTZRN4knKh|4WX5pW4Cb>hjE%`lZCU;aMP|Fcs%yyVQxl4FY`6)N!wrMawj z8O_qGngG^Yhc!*Q11Y@wugcd0D)84wwgp7f3CF@R#ti6X4><~gG%_}jHER@#3D<8Q z8i@9}sy`I2T^Nfg6(ZUl_MQ9q0Xi5&6T_Bph~aAFX9JRTu(>VbJZYS%2yPIp9M+#3 zH|9AE0`zEBOwe=s2}jh2Gbrc#wi*?f*tCW^sjuJ27XS_JU+?%4M%u&=S!2yUvUOlQ zgvxsK3B3ko2-qZhGpKV6iu6aHnMLBz`}y+kvz-l0p=jkCX;-+UB9F8{Rm^9ixA4zi zQmUmKVVcs=`^77_xbFBH92BeVnB5YqCu_q(lb`g6=SlVtaNR$ zosGZt5YuvUm*5%st2=U6Z>bA?6bT|yYYqldvy1(nVU?oIeyG3+6(#fzbyUI5d*%&SJ9;S3~KrCHnuTtl@5-oe4sKnQ>ktN78lfQE)ZT}?6`bhID4 z+vp}nU5T+F1?c%P{>dzemR_-1w04=%(fGwX3G?q{;G=HRaN3x$g-})TSl-MxAZYSb za2kZ`jtWZq27x!w%R;NzOg}hcQUsdk-(GDC^H&A|BK4ZOO%N<^77zI43Fg(_8~f*5 z@SdTe2#N~u+*xsc|0Dz}sNRS|Oa4JlOtp{UN%fHFX42y#wN zk?7-%IU5o>!vab{hPlNjPh`PrN?Vv%*NKz2pEz_apRC;I(y=5-K^`67wQs(rwZ5cY zxq8gfk)SGO8lBex zpF93UKrd!fBA*@&NTrW{kQ1UJOStxqu4O>6BF^~IQfmv<5WyctyP|DpLcfuP85Qm} zmbwo{G(GV8Jm2l@nalTl4>4sJJ14PK{VJr-p!W>SlF~cV=nzo#S=5-}GHVK$TqyelL!CydVvFTp(MHW!eb8mH0aH98 zjTI&tbFOCe?h>bfuqUw8z_vr*M?OPV<;{6*&YJ@6P5yE*_L=Z}6MEJgO>WiUKQ*Uy zJyPV^K?Zc<^2k@_{k4#>5xii*;ER`R^Ae0bL@5pFurx`0F_D^~JEJ@+Ho+ygi3o!V z+NR?vXmEb1eOxhC4>jACsh<~i*PjsXCldW91AT{I9**w8{gpjt`R}}w;hfe!hF1py z@_dxnzSt!DYm`%QeY8hlf&0KO*vAFdV-}!!qQ{VgG9d8OM~#oWKxnuXYusNaon)(R z$9UB`w7%~^nXqJf7$EaB7oOmA-aRn78gOy8>wxQ?!KqYX6%{?%9U-HrRe?lS{0{~v zj)uV0MHvG1&O%K2D=c^N@#T7X0L-tF7oX~ht?GNk&Vz+1AzWP1LBk5~xK1u$V>|2j+P|B-pv|y>Weq=% zQ^Ib&MLt1xU|4T#Zy0R&HK_NMlgZseC3yq8xS*Z8pziNhDwwjZC0(QUpww*R4S$rW zUyd^#ut-rw`R(ms0gt*`+GoYTd!ue-}sV$tIumRm|Mh)%D6M8&qcG!PZI z7u1$PSGJBZ9eZ>nimq3^3)G|8c5?+?5L6z>&Tw%!G!;}nUy;9k3ET-2uswI&K&3qV zmE&kp747ZUBhy2Na@g(A9I)8QriEwV=#&W0r#qyYaXfe(o<`h&P4BQ^(#f zNC;GX-06XUQn<3tB9pQ_;v-M_Kr1w=W9`0g6`F|;OGK7)#j0ib`YP973h(-CS-}fz zw-mu+j5tJd@TM#fWCLk)PF20D9#My9K~Eh0kj5)^GUL!)4fIlRo_iM7mfC=1&?J3K z^Q=Q#?hT~i35cFSzG47J%kGvgs-On29jw!t0KYL;2*hSc_PrD(nR?Up&fWd9-1ei; zm?_@eD+C3HKb^yiotwS5T~O*Ukaa?x3lG;D#SFZN2gQALlmTwZzhXq9&ay^vCZ!(X zzNO6~7}g{|srG$rUkv|XRZ3hfH%WuPW2wR$C>BETbGRNzOvxW%GS+fJO&O?z)^&W| z61psKZvt%Bel<_&>%~_^d!}X59{hADA2gtY!j@hBbc}`PI;1^fEKw@ae~YV#6il_G9 z9H(AJg2QdU!_uk6o+c{&mK!A8EVS5DG40W-_CTIw$yv+x!GII&wtIF8jbVz9$BwED{pWJGtQR z@k(~nd;KS07DMdc?Vnlk@zKhPpys7)AZ7a7q$~H1Oxn6*U?e!_&DT#% z^j25g(d?FCYkY3x%k%v=CJ>_2b0$N3Ac{@0%;^c#F??QTA}>M>sao>9u1MI8x9LTSiG@Udq#|&c&8cH!e zgWaU#nHViG({^n)LV}jqsu^s(;{@miWmX?7N{b=j={xXnGJn7V&8Z->A)&D-(o4YN z6*9C$FkP&$66>@w)7o8Z6n=28QzUSvySpvVXGXE1>3TpXdyY}W#7wxknH)j=pgMl7 zt94q|Hp~xk_^K&yS-(5laJi&EP|X38<@WKOPoYM&=249(UMAEG(hx@0y^=b(c4k}6 zyRtJw`Qz@N)`Ls3=wWkWTgY*(94R-N==m(df@lls}QpOPra7u$BGp+(|1rb zb|Rzz@B;+?)2|fjrQKcmO<%9c=$MU-v&aT?J?!p8r_H|5!0*j{mWA z|I629U}yT7yZ`0u{wTuCKNI+0um986Wng6HVEcdcb)y@=<#5c_>7v?ET_I7McXSHb z2RFIRASth|1}U#(^4L*bOIpxM%<|mqDREt%KY!Yn?@`vMRKmGS>s4rshH{{E-`p%N z$v&jL{=U&MB8V7OnWF|90szMprGrq{_>1MS=uy+b|`~Ic2DnL{9W!5)`2E7ol(&Y+1D)~8lARP1*JAr)w zvU9kzvx9K}?6(EVhmX$sQ`6EzfZvyj;~TNtY3CfyIS8auCj;npO~YTuXQm^2a)S>D zgIqPP=D8c~J9>tl130A#oesz`u8|h(GWP^v5chLtVf-r7gbxH7gK=dK!v6L0@i~1G ztdkOh`0tqa$oC4Pw6fxd*q*#o9riun>T-Sna;vw$2U=-y;{Xl-0Ri&Sf%m)i6_sbH z|CB|;{caf(ti%Nl@I`xPEc&Kgx#WE}{g}3<2mUd3>-J&H`GJOf*=zX=-C18G<8c_9E<&d%<;-3j~SXna4!F8oPN zrZR~7S{vtwZB<9)>NuVlUuCav?9WO5&=ROonZ>z*{ym2JSAylIy^)?Kq}bx@>Qk&L zc+b#i?`^jeAk|p^`_6&AoBmD~?c~tzi>ruvpl|jr7G{6%5HyX0Bi%jUz5_8lG8JQI z^3@?Cg)o+v0~V-G5La7A3kY!e3Q~!iJ@d6fK>z@vxD7o43?KkWd_})-0Q0T-A|e2l z-XQFO0-=5L1AHXD3HgEK4sA(#fPu=t0(J7ue!35*FOdMi$c62|EArsPo-vxQq#HO8 zAB^bDc(A}CLia()&ya@C8cudyWUilqu=9rmBagotz%{?PHpb1gzQJ{= zoZnOXC24bh3buBB1$_&n!Kjj#qz>Or8~W_de(&(=njnsV8u>Rh?3fYZ8mMB-`DhaJ zA5ArJ-I}D>sFFvAPkN4)^*`dnaHN-UQk(UkYW#LDd|o_jV%|@FVO+Gm?oWX@xLG1; zZ2FZenh5rIy2;uwNZHprnlBjs1`Ms_z$$&qox6SQ-2i&ItEtzHdUChb4y{*)zO&i( zJnpf8kW>>DOnXs&seIol=u4BUA2}Pr3QLn+FwQoeLtf19pkKhJKg50ClhfXoGdP*; zRjeSU$A8Zqu}k-~^gV^<$#&iNq@Fn5ni-TLl$!?f1?_5;vGsoG69F>Ic3rmzS5mv+ z-WPK#9U7ap<1JF7ZTzTN5~w@$;FKs3^+VjddA%ac;#4_=!xt@ti~U(Ot$@bCzw3U{ zoXA#JMz+pX?)iA^I6Dbw=YDQ|)OjC?0&{Mg*gazf8+}xYIJ+I_^?g?a(K8sh5)qibu1g}YlY!0+Gq5oPf5-#4? zTi$A^F9Ho`uwv9UG@Qx&%vd_mqI5#9LkN0YMXg>Apfw6BWT;83XS~yB!BL(Km5MrZ zL6}Wvtax6B*qF5;hVZf3Pqj?ul~htaf->4g%^M>c9^7K-4YrMGM;?>0h8C~d53!{Z z8sK3FLDM=>deVt<)ycv}tFsULm#S&mF*qa#;X5!tEg!D>CwnsXkdz7C>ZIQnnaX>4 zEb7GZcOW|I-Nhyblo~t&g>Ib5CgG^N+cvx?$(sJKe%6_NnnDTd&A{JvSGx;eMC?@? z$pD7mQhQ~*`5uRJQUA1oL@D01+FPJM`A4xz^Rz+Fao9+d<~nt3T=Ylv=f5Y{w{-`A z&2z>--Dubjd7=mxGF)d6cqoitP$4eq(z2xFSVzbR*KF@z3}VECGz~K_nHK6QKxFa| zO#H>-@3`+nE9f}uW~`B1A*TKu_rMq$Q#SVjW;tr=R*c_qmZGRaz61>eOuI|X<&2flObqz`+Vano+%>1m=^|W z@Pg(LZXf0U;Z^WY@1YA+Lf>G9OQsXueKm6&!W*9!A7?3O{zdu1lx83pzEotAqboxy zaaJ7dnlUCFzgGMxLNIotJU z9h`OI5w2C772XhG7wDr@*fjlug{l$nZRpi5?oVJy>;(KrLxWoqGqT(nlNkDC{~8CDM6=SZOLvYSB!3mu>U&HS~JTW z4k;>}`nt}yO{{=4SG>(Im?N+la%467RE!k&40;Q0+k`yrGwl`$Smiough2`Ks%aZ= z=9^Z2BbUWCd&u#_>iP;!nVqdKu={Ym;wT*O<=^=2GFL0jZ9kg4#K#snVNRRxef&Au zo2Ccjb;m>*U0>bq$pIQFlX5h%!u*^2b1m;r!sd{(cmLS{Pt@)Ro!!2eJY*3BmT$P_ zMDAp?X|e4tM<^Yqwfn#yo4bG=%KN=2>wip_gVQWhLk6y8B)vmJVuoGgx+_~S5zR8T zemTqXgO=+#5^?t#Uillz`B@1xH{fhaP?)X`LKom`aTURdf6C6r9R{pB zvXkq9#bDYsqQSP+j7PkO(p3Ws1b1$EMAPLj1&C|I0+U(ji(yMosgZ8?MqPiIeR?0+ z;-2gXv2c-HTC&Q+XK4vqJ`5xi%1c+Ha27im6s}l+pr&5cZ7iVz%l2KKqzsBpR_w@& zF4)hZS8rpAYh+@mR&RP~nkT>zoQVB;V6MSj02G9ZU7F}Q;9;;+CXEqwMabII(3^@2 zP{~I3FwEoJ?hw?s*4MU!(Ss5HnXH9FgEmtmvSr|jf}2-4NuOLELHa8}@}lX8I9B0J z(u$~#AtK>zcaOwzB$$(^y@uo(?p}j~PTR(T{41Hfys$#QaG}#l5`T05`Ope62wYW6 zsavxe+OKGjdWc_KoI&EueK5iPyAwUj&b&|5t~XA=fqk&k!eY8I{5H7uEKy#DfR&); z?RO?WLV?p^d=Lmrb3NkkF!lVMV~br(i2N_b*MAL;fp<;~f`NlduN++OW7!lUZngs# zH8k>#)pl>_bxB0A<(vJr=m0Tn6;+|MP9yc`MNhn@qJ!;TuWMqw`1JX|G#ATDE_$DT z$R%(v>RO-}Y>282Qj6|MWjz?voh)4A&!3e_)P`BC880O2)wTw5S%aBK*a@GH!j%nd zKHWUVP-vjb0@oMaK)oK^8${C)ZhxQTwD9T**4mO;?hqCBrn<0PWN?k1(5vnayg#6^ z?}D^Dw(2y3uGYmM1#B8RG7kwQy8@rpMBM!8^L{9c{`HS*vuLtQeQ_!)ig}gukLlpe zO&suKMN)1orr3PV?snCK!?nv!);DJ6jb#B`}G1`FLFn$vi8^s^C}ph=vo zoq0|ba-EWocLui7i@be`)wI+maZN1e!)!vEARgY6VX?1}2=To;zJlIz%#IFzyvU+o z5^2t-0fBiwhxKIV)2p0XYpo=7Yz-WMLSI{kqpwW2TA?dVxdZNuQ>kyem@DSOjjO-@dLJXrtfklmN#oqQxH<(u& zanBBSOi;Q}q-27E)eeijM#4IGsh2IDk_KF%)0;f@gT=N-hek5pY2dG&`orn!B%9a{ zj__^tP*C%Ns>E0DSdSFTD541gj^-GKlwu@saAb++@*|>IeXF?qpqoGoj3A+c<>EnGx$BOnntUh7mA0Wu(mDglV9tQ6u#jQej9C{mU;lPSNzQCU%mYl`=_$4ZM zqgzjc&hCxtR^ei?38u77&OD9@L)qNJTi6wvh+;TFXAS+ZmEoR*X zYnXo0TY9F?kRg|DmFlVZtRo6v)WgG9#q_RX97GJs-%CNvyjcHkJ7T5nktIb7vh5)!KBS4&dhC(iUMO=8^K@+;zP~}p+ufY(0v{~ z#kR{ljITGtczKi-3iNf()LX7r&GjN@5g6UUAjgfXbV#jcRQk;r{7Za%bwq206F7x2 zL|Xnt^Z_nz=iXrv6Ls2(0UTV@%rjzs-{xe$W*2WBjO6m_z|q6pykJyz8R*P

_Qo6}ReH(zws>;qSu1x<_zAjc)Gg#)Ke~@Di-=3!JOaK5w1n$*uQy1=Qa}ts~>J58cS=*)J_;C_QlJ% zrmH3@lUS3zNWSqyLwttlaNsWW@2cMkdQ`R}YhTlCkN`5sw){h>SRE3Tq}Q4kv6#{1 z`;pr4ilJ8&(k$`6yl;07(Y4&VV$)S&zmwz|hpWQ?ugV3pk>P=ck?M#jgL1mF9=AQD z7UuyVY+~IN0ON}`=q8lpT!x!gKm1wK?^4oEnGKU5T)|M#g(MZtaKZO5Yk6$-2Tri9 zH6s{$Wie{9>9j+&?RQBW|FTm~bTj|7_AK$pj@BF~kVhlFs3mZc%caY+x$&a8lrCL= z{?(eaXk#z&GMz~M(uB)F)?fdKxO3i$;y52(SF^n*B!uGaiI?%gv?Ntw#Q; z+HqrgmJy&PM`8#fVb$)`hf<5hW-T)KHQF2w#CE=t@>Ojj%nd-u9YibjZ*oIm3-vn3 zq2Q2!gO`@J2S|kD3%eS>lg~zW>RnY_Ds`*WubqBCeu$NJX&sJj-{9YuUM@`mN1>x9 z_hw6WdWif!Ny2mx!#0fcxEWh$)b(qNNlj_k0?E6Ok)-~VH&$Aib}fQ!$2wk8U?#Ch zLp4UVq&b979BXSt!9qf>d^|Z(`QV~T1uw}FiJm%_=Cw{ohpns-L-7a6ZL>OiH0wW8 zYsu_?li^0%T-4UpwE2YXnmuMKPv|0wtsv8?5OjR%uDQ8ALHM;hgAl~uSog7wj1+mO zXj8z&zEJ7mR|U0PDvzKV;tL1+<8OHjQ+l1{ms7VHMe57a!9T&eB#0+*QU?J%^G zfE+jwI)~;gFMhWKM{2n3SwJs2*jzmsb!FZU`rzlT4sLQW-zpQ02~Y6hEgs81Ty3Cv zc;e@}H@0U!8~S3-rn30SW$D_hbx(os&JRrc#ZRJ2rK1&4Zn395!{Rr84~)wk`d7 zvX%Z*Tt|of{3u-3>MimEg=Xu%f`sJLMoA0=9x$U>8{`;Dt*9^@P>Aw9fUbXlHN*4!q__Ql+uar_x1wy+Iu(= z6LlXb@m-Q1DKXL|b^J(p*m$!L|6x>7PA%NO4qV}_3`dvkOhr>fm&uhSOpw_|U!;;g zp;z*wG+P$!TvWKZ%s0cVblS?A0gO-Fi>i$=67VIF&>Mk1dIoToyth63A@*Lwz?&i> z_ok1TV(4nXD8EGn+T(|_@Qlp_nSkUifz+7@_cW`)I0Ss2Tq(7t6I-TEF*Hm-P{wmgR6m?fXR{Ss? z?k3liq&d>37+ZB%yl1KquSHfUv@ruWF>GWQi7#c(0R#A)trHi8@LW8R)p4{lktybH zF{ekV=+C`S37;uyC7MB66}R<1d*^7!LYNQR)u$;zwz}MSCyJSqh3x0e&v3NVxjDv zw};yTvtZ4_Ake%DH4xuwc{Y)q=5CpIwi0D!B;bhS!(yrbyZ8krBibCoOvv~vc8f*j zk}BT5p&@khz?TV^z(>FVw@{-stkceHQRICe2RJ4>v<;1#;?Mgdhe=+OkRHs9wv#iXKAbAS)=U=1|F#UOUli6 z*n=na_fP1SSmHLZM9YF||mNSUUI1Ts6k2=9*JN9-DV-VSv0>mv2OGSuD`> zg6Wzu_svj_&yk_>o#FGoSqV89hH*9W369UPzvA+flkK%JvlFR>%<098Wy5(R(n_st ztu+?|;i-9w5}Y+(mr+U(#bMHbr)-J-ZFROxC71;vHq4-aW$er^5e>9taA&T*-xYiM zN}?KR37Kd1S!lIIr+3CxPNFAdwkrZYBE6tJ7OjC^Y4C5naiRJ!<_cB!yZ0hylY0>R z+-6|zpL^&bYE=I}oNUR#Wai|4l~}&594%U&l5|wuw-)Jz3?Ygx9M2+C#1@hW?Vo)0 zHeSUBU`rf1RS4xs(Mq$#>bj}VI*_!GI&w2VKlY3YdCo6M)nN#>sE*3!%4>VNhVQiR z8&3-;Cw~(nI?wPBjps=IR&+|u`LohuW1TCsY55k7CUd|KJzv$BJ)nUcDBAL>sVo_P zc4@GmuC}CZana?~{Hh%)>;!%mq+t?YuJKm{Z^I6-fm6i5ud59mh~|7X=?O)LeyBGt zm_f^iiN&LIS|Jpu=yLH9uI_DoNJz;Tak)jH#5w>r8_c8BVtVZpb~ojvcWms{>@G`B zJr;nAKG8RS!~xI|`4^Lh$Mxv)HNY2J-uk(Zc4i9AIxm`aaxfALb-WL?Fj!>8lUu#e zn4I+@M{90>VPHeGQSpJ-?%88GlHCvg)g}SAF|UAG>siwtL0x}0Lz}`K6)LRc@>cJ%s};Lr+Pd`&!lFei zoXEa$435(6<9(ky-9ZCsg0L{cXMjb9TrzwWCP9CZ%X&7&y1Y74LMNvK2%$qtd(5^Y z(HLwD++QNJt~Z-gV8DcvJMb1K&%4infzH}&C2mxOw1sxnLw>q#9;$Q39^HWg@1R7% zC22&@49Z;4${A^@hbzy2U>mcyzkp!E_IlV^bSn*cCJ}~w;7^Ps7mDF(e^$t&<3CgP z0I3hnESi2iTW48At?NBDA{&S&!8N>YmKB?ntPY#m95E>IMI84g93w}X%W!F4gRu)p zUPG4C-|8Pcdr3J#XLZOts^`CM(D#AcJ}5T_w&wg?(*u=MNqbXLXxL=L$=0tQ98R^J zn|Q+u-yh?)e_h_ld~jsjp)E;(;0veF!!TLR9<(7p}ipJHBF-H(h3a z$WL){^4pz-P1J7NC$b`j7WyI?=5Nty+$m&e|6y0;N$y9jTycptXLeK)gT49XAhc-S zf|Y3b{d*~8^xk+^JZ3xz1O{goLN;k{kcCoY7mV+{f5q#$?lgo)yH?VWsi^L{a6_uG z(;Gwp12-P%F09->p2^*{yOZf>f$7sCPaC-J@=1S{V8@v$X?%1Vzh763fZ!ql5%6cQ&86)qLotBukz6z~D zXXRJj2Y}B(5_qJtM~7xizY>bFH=rGc+-GDZKlZWh^_ymd*E62_m6n!J zzCgh{$KNV7owx5WsSz}fhzu6J50tFG{$z38z0>!(h)by5cB%Ih4K?TcWRexw+JHs0 z$O*+aOO2Gtsl=>hHhF*IVeU`s5Hw^B&FEwBbp^aBqP2CLdLSOkPUY;ybSHX1KLfM7|xhez7ch$$R;*t+BG zO_tlWsLopI%R3%;w*P{0Kp-(H#>=(F99*^A7)r3Th?nKMu(9}^=!h&uML(ZJ39uV= zettWdZ_aP@oNs$GpfePTHct*hDv9+9H>SVN*#z6a6-V^_nm}3Qb0#j%O~Hb6mN|RZ zS4{TuELzqJVhD$i((9s3>u^G#Sc+%oe(nX7Vd$=6UDq^M!hiSuD&>VVKfu(+FquKI z(MxY1%}nCN6#v<$_T|csyLjXVLG*b`d&74qvqRp}#%UM+STn zo-~Siof(`04nRL`2`4j}K`fv{F*CPCCz`uK6!RJ*q%=6^>t4B-Mj6>4{(O=1y8l*r z>y*(l4}<2;>K_6W?t}AuDq%1aD)MA>z+OfLW}O>!%tpELpZ|4DZ|foy7J!4ip^d4< zp&R3BFW~$1R4;i@PQci)U&g2+x(E!q~&BhY-3f^&9(4GN*D8D{;_= zE6C5kRe!sHpMQnjZlh3Xo9G;bq&M^R!_SFa5dP4Ko=Sl7Na+2mVf$2-y^UdxAn=K6 z|10hNGrVb!BhhQo*zMjxWp^Nna-Bz+jki_e^VQ}4@0RNC^GN#BG9qUHzkNcU^RJsG zoGJN7TmYtIUl-nyHvSenV$DaNS`|8bY~`oQ&~`Rt?4GFe^l+FSuKu_%(QZ1fl2%t7 z3SpF36-$KtLa>W4o4$l+RrMG#eZnu30p`)rw+i=ZW`~& zXl-fMzfP2^Y!x*CxkfWU?w)InEHd!}E9^R+B&$k7V=$H{izow%Myn0Q z8>=}eeTlZ@8Khu+x|~Vs-0T@C>}i^|t3Z9gtg(q*m#*L28+FbB(g;Bfn-PO-+D`(K zEwg&;pyL&y!M_=TU9}|#mA?o!7~MEddE5fQ_k0|d+F-}W7Tb6*U~kb(=jYgfgIRq? zz~k=}TwhA-@|@t5ta{dN`*Oj#ET&)q0 zEHi9+Eo%^(lr1>{GcVU;@Y@5oOgh_WWyvR8Ht9$q81D4#@ zByWnM3_Rq^th%!xufua_fgsQJo_o9VXwQzq0L4VyEVl*cN$(llFDiQ-W_?lM&aEJa zvQA=GFN?OWDfm}CyeUus&7p_saa4ZOgm#Et6Q!jH<{?+J35(M}|H5x<4DZVPwGmpk zjtqdo@?za#jBmM_Qth%~1Y2KAA1T9g%h>g(P$4rr9K0pSZXGQqRqL1Ab~` zktCq%Y`}UfZNGTukT^+nk!r}ZgW>+?n7+1c-9|HUK)IjCF>BIH*dI^7=UyUVN%1&? z)Xto|Ls+*mLbK=ne(HWd8u`Fiy>76w7cil2L5I)xH=F+#%r4amUsp)5yXy3k)!W;rf>3^E&lJy_DBL+7ixJ zP}IXbZ$?uBH~+6*jq*J3=s)p~=hiVoth9BejwQ+|8bN3Ro4;;H1XNXjZ}f0fWibxQ z&`(jdtT$`wDax!V-a&7BW~&m;(?MWl+kJ~eE?O%hz~WPB`rE>^oR_FY+a?vZW>Rft*tqZbIul*Y@pcr1+^P{4Ma+fZGOIb2S16IH# zna}9~DA|Bs-%23gHAwyoUUa2{YkiWGKAhs+bM!9NOcZtBfUt1k9^Y^ixEVi#c=npY z#wu3UGY~w%(lXTU4#@Qbp)McL?cKr=b9$A*Sai=+(mCA?{FTovGAf!&^w;lxtrXkz zRVujz!NM_qF)FU?<*ujKTwUv$vMe)O=(~Eg@yfQCk9c<36e>uxU+x=fzAW=RVn@HX z;nm|anj4|2hW*%B4FPQ<-2Kl#gaU7^)c{-S$mjhL@ovc4Fvd<8cduYzq+RH#Tg%Rb zDvs`g<{Lc@sX@4z%f<`%8!TG%R;b+(!NO!by2Uykg#1(LryC0^^$Fig)eNp42A1eK z`_cV{wz!@0gOX2n{<4pAs|rZ(S})9q4)0D@2R=WF35I9 z^;HcaH|r4hL@+7;;L&bx&I&0RM8cw6`*mY!dtglR@l6<^`Vfnuia)T+EGxnNPn(6J zV|N?OkJY;KzDDtc5{%{~9U8{$V#=QmR!_KXVUVkUj_3xf3=DJl^ig(<*NIs-v-1@IjOCPxP?=& z&0Isp-{-&IGE*+`*X=xR11n)9aO#3mwYNuiCsVg0s4*@A5sG$>W1hjaNGl$r;&8vB;#SS?;1XO)dYNW2-9h_Upf$DuMkz zeP4dT>tQ2VwrO3N^@PA#Fx4Ivigx5fjt7y~*35?9dG7Z%fNHcfVoB^txQk-Y{{}_7*CS4i@&9-dY<}TZ|ZQHJ0 zwq3hy+qP{RyKLLI^_`yEr)Q>b-2MS?M7|l35s9_dW7|xRhdYh#AWxrNLLPWQPWO>s z2|&~&Pp5m&uY!Tl&^7L49Vj4zio}c8UQs&;3Lr_QVX6PmFOS){EGRis4;8#_6@@Kc?@g{E~T z6kAxMM+CUL9_uT!Gox5CyHEzxUb9$j@fxKa!A;zj?ntr=iQUJ1r;E_?7S3&FLc++f ziPh~(gEr+x7jeW@8|1i=xBpKlJL0tM1bQF+*pjVNpj&7DYLdtj)`jd7&u`^{vTSh+ zks%ndN|o2heh5M`EgmErWh>rWViM_u(Y37`4(jDXztgg+wdV~(JXs;W&$u_8v#ivl zFb8YtP&{xMWe2dc#d_niekBxa`ASsPumJ3N!R(wI z$SXML?7r#e!}eiC!yIOn3TLd)ye*4-g8&2vzyl9Jima*ALaIJ@gt#Zo)d9eU+j$K% zsh0eNJjZn_1M)JSn9i&(%S#f|Z5lxBni@s5W4ndr7S=W>v6XHRn98nijAwVkY!|4R zIV8V8uU=2|7GkxV2x10MrE&OSI>iT$-uGz^)Yx`|m{!niX&u56l>QdP762m?Y3W`6 zH?3O#(7`uLHvMMf&&E~OdIr9nyqP46AkReV;d6fD27Q``m7T#l;}^{%E>8`y^VlRT z4stl?yKrh1#qvXxI@vYXboE0<`iGlk6jXMAN)PtXtNA$b4za>=%jNQP0Tn1uLM6 zzIpiZ$DtUw7&}q{f7!*~^G2KjUXn|4id&ZkZZxf9Q{Dn7#|9tV)MXV%Kzmo@GU5$K zmz!A7j?IAxnb-DbOJKz&xqsFAjC4VJQ;+HjggocDfQ)A(MO?KXPPE5SQ8KO4P13&{ z;G{@8>jjKkTV1+bGtDwt!Y8B)VnZ@?>Fsc=qCJX0;WvGK2Lr8ql)*8xnxBWB%J?I4 zBq{bm3YYRzoq?`Zm{Nvsl{({LqT;Uv3A)COPNBf}gc1TOw+#fZp=m@7%|1Mt!aRuG za{s7b(_tm9iKo>69lqto|Fy2wh`#*P$OSxGI#lkQ9s`x>Oygn5q&a=&k_2N~ox6hv zXXIOnHWWW@)YWF7DwVcPQ;X96wLraDY5`YpbPe!o!hnB$m-LHX+O~dyI0$Lal6BX2 zD3cPT3A>P_mV7fZu8fUb7)DV2qe2`vf zQ5xCtB!hMx0@SsyKxh3~^tP0+fPxv|lGfM(Zl?1(#+Z7i3ZMJxDJLQ(^^ex^;IaVU zFKg7n`2=^Tdt8)lDY6f1LZfAo2{Zb*z!tLTS{j_`M+F8)ZdR)=pqgyXnQUq}D0cq57WzsKd4yEDYB{=O(_u*{f7{U}n%8MVTExnbyepq8+1 zh(>sxr~9LjuzfWsV@|s>0kFP&+xpu&0XM^1qpZioIGs!diuac)g&5bs^cqlBmy~ri z^W(SArMs*SVa4AnAx52A)(9L0!w%HQ%+E+T7&Jrs+9$WSRJ zj8bD+#$&&B=)Sp4J)}-mmToUQzn#uvl|ZMlXotVQs_y< zf0GQyCz-mCbJo5Qj2#;@7@#sc;PPC-xpIbrnk(6ShTHGZOS42Nxf>?xfTLiuQ!+W8 z0|g;l6Ha%_%!xs9{+C?v)tC83EPp;h2?`KzzfD zy$(m5W+acUWd%Map)F@(J|S=KkoZ*du+W3uR3 ze05aAt%>A4m3gkbCav%ZPX@X`>sam5zXt-Fsp!zlQ5y!qOwU>fQf-T9upIVHrdgQ` z+aSc`8-*qL#KEl*r53U>OZGzIEa15+6FlwIAh(W7PVMK@x5P|O%Ker#@F}!y$CNkB zUh!yBKm9@@K+{p9{7I={_sofbRhe7JF?5%!7tZpx?XZ8qZv|*dkAb(mD2wQD5&EyS zikmj#DoZuR{&7L(Y1$t&Gd?B!W{O+TAUTkdlM}tU9e@Pb)9xP+Cs@lFf5t zA$Oz|?Y0+15+%5V8KnPE(~%fChpJK=dA~}K25eS)an5SUKlH@zFN6gjpZ&R-&NvUa z*T}Z)*RZLhVvXzRkmgmqvQ4FCSq*bd7YB!cd&iAVW6f5}{bfJb zo%S)ZPSMMrzQHrsB%AT@?TJfLYM*&FqImW#Syr> zq7Wwd+~oCA43?AF&=g%A#1E{(`=4T2X6o(;?GI9gG}y%5{n91)R-tr~dh=4}pCmXZ z-($-Y_c*lGqCVj`4I|8=~lGt672Kb|BpD9RSRL7EPSi}YB^i5ga)mSUXU1JqayxDWi4;q@W`ejyZ|_iHn3Vqa&oehK z?j!stx?FlSdPkM%@EO|mJDm1?)*)VKp;;7{D(R}i%88d~ ztT6N9fk6;3q=fWB60WW-%)l@(OoQ_CSrN{V;u6F^mIk4CN<^dcXlVB}$1%_G_sUy0 zi`5kOO3eA1=k`kX3jKV!Rh^W2A5Cw)Jw`xQ0x${0AH}(Y17JV?O&kIQbXMX5RuDkY zZ<}G$MNqB|{vG;0Ul4JQz$rv{Rtu*=p-dei>oJX@-%{25OnCzySNUK z9lP{U%8A~}!W}p`eT;t4cUSLu1hd-1fmI%V->ga=m@ByZH*9qwebwcjj9SOvAZNV< zveo*ar#(V=(yQNfYkr6Tx(E=1*cg8HE}-vjp9{C!5E%)``k-~f0Mxy#2pCVktN4@p=RG$AyIext z0HV3zmkvPuJ$&Cjj6Q!-P;tN>KjdC=?m@>TODiPIyIv~xecwq)ckuw|Tx@LtxX|e! z2zm#gclHqhUOw0&+c^%dfAN1ysQ76N00RBkCiF$Vs25MquT0-v*wlXCM~cCGVQ4V= zU$Mh_{%!)v@OqiwGm_s4ci-eU+tlA|(cg9g_0{qx_-yz1-`^uPR{;JVU${598ft@q zUn)EBS^)3c@;oS>U`HUo9bbN30E9dEQFs8sZ$SJ~oG)Mw{8IgIKX~OE zUw&GE*<1V@|FuK>8&ZI<7vOIz=H%+>Y50@@{9E41OTCvF84xf}Kbku9qn%{IJ{Off zniN!|#H))9Bcg?<4G&7{3ti~xs_GRtjBx6lE%0j294Qhw7es2Car&Hay7^7_PxHz? z2&;${^X}VjmguF-P21rwZh>{S>}R3;_7tdd%#P-lnCGm77F$0aNn*ziqJ403H6QLr zoIR;$JdW72tvx#8Jf{sTt{mN8Jl!n0tP(lurDa?e46K1+ddPphbr#w-8 zqKM3QFpkFClqTu7B746o#V4%mFSjpE*oqg!3A?ik5|4>8+aT5{L4OIPB0 zMG~1Vl4h9Q$gG6Wh1l-|fzln7ov@_3){40@MW-C++bG+^!gp#xv68Oujw4f{lh>2& zwQFQ_P4b6OPPjQ#3d{3I#RWX^2C4_83uXyst%peB%%i)Et;2H|`Q|cn$!Nf(+$4#- zGFh^ZXAIGmLY7@A-S=wLPb=jjLre49_%#cNWyEHb#><~0Q$LOnB?F&zaZq2Z-=DNu*{~&?Q^IHip!N&-pVbg2l@}nKAH~FCU2{l3# z@QiUenxESPG#=wdLq%j+E-yz6>#cAtw(@@7{UW?W3v1FedJ3Z%j`r+xs0KFX}bo zZT^vYqf}mqEub!Q0@{E``CnQ@dbeOv6jA}o`wB)wB^3t)c3M`#wQjY1IKD2SI8#a! z`)HX(4sqo!A!#{d>KgbVA|gkvf6OK&YxI$jqZ&Nj(@89u<4CMIxd%#aU46+z$@g1A zh*#fefH&UD^h3wy6PVUkilMIXLwL2`BeyRqU*CTsrBLJ}C*JWkEO08N7<`vSogNbG zm@G$ovRv5&a(XBw4kHZ{TrH{D^49yNnG-u#%Zj7An!84Gd|3W{&Glw!L zX+#f~qQ`Qna)DIimx41{QKiWXN4W#)1HUd6_NOBgKD;1Ox4{yUl&Y?9Oo%v=l_LB6 z1}j|w^4?{$9YtDoNLEutW;UJMxwu$$Ve+JCUCdR(6D`hf*)mV|MiW(brE6Y|*gbsk zGk6On?p>=Tm}HRl_?=e0Gbd2(mowN?Q5B%{0BKt5BEk-GmaNO2XXbUmV9{+yj*U_? zHd2)J#Jg}7_E;)gc{L!K^xre`A!Y>W=b=sBJzh?sV$JgTpjW496mxp0i|8hMG`uc2 z8#K`>2ZuCe{4MU${m-<$qO#r8UfK~HJD2?rQ-(4S;GWH$H&~!Y6resJz736g;{ka? z$Ci9;nDC5E$5Y@G{)B;DVBQ%-Rzcn^_edSB*%+`hy?V|v#<DMW*6(Ls5440?vv^K`ayv$nh2pv7PCU&iI zUPD3g6IdM~g;FtvYu$a`_q&sSPCKa1u%l`ExBkw0k~$`xJ*%#w5tmhE0VR#XR^KAh zu7kBSL$z7?EW!~Et4`?jAF^|k2oIVdn+=&UC=m5HV$U$?U_XusGw<@5O+wLkR~sju z>rU}bu^AD7MRZp;>}ZX48r8p-^ZQSu^#QDf`0lr*ZC+UJt7qcvjvFDaP)(R9E>W(* z7@%N9e6(Sp-vN;j4Jb~I=Vy27Ct48$RT*S0Xo|kMFI{ilZ4tyU|72y^_QyQHO#usu z9RzII7m^gbrecy%?R1;^y^Agqt)El8l`^*Ey0n}KoN(f^RQOnwE#(_+JcT z7xakGui-}2@@HruAXmAn<2M1sN!eHd1?5j4%pGGde9-g%Zy&FV=IgPP;rbtv*iJcxBNdYy6#VM{#QAf=pt|ZR1&;BTbOx!WQ%SL} zNqUB5i6k5u-?y%X9w42WDn+CZ6>VaFaKU{I|x%K`3wO^>7Fm; z$if66rA?$s3+C=d>Ccc3tmw`HZjxwaY`82NhQFA}tzNK~iL(vY+Qq$ZL)mSfXA19G5;(OL#EFt~*p``YLA~BoR8kuAVeZ%u3 z*#W8F_JjpTx)Zxp$z(B+I~^!%t$7j!wq?;y9|xaA89UVq-0D<$>xX`UPD?Nq&7k~# zln_8wN2=AKLz)#Q9QSG+=rPJyP3LC8I5u(^oW0UynV`gaJR)0k=)mo-@uaLS8p2YV zBZZ6!D3%3zyHu*`xDh%B*f8LAkgZo1!`2W7aK0^P%CGYDpF1Uja%`dFG&mC!_J5Z$ z9{X7h@pQCyp-zRPYpz7uO`2zKw5`qjS_m+m zV^}iC4_PXQhFmc>Zh_dA!+4_j%jxvmtYrPGPZ3*2F1Nw8XTk% z>s+K6WY&g`XxHVyhr;~zYKsA9rsHpo@z_}65%37(lq=;Smv`_q>Y-9;g|jHrzxFlM zf183u^){le1D@;tB z&B`gzlUfRUnkLk-4hKnEuv9oJvu1gtLg)^@hlCVU$i+)D(o=pY%gTg~ zOqW*{tw;FEzpXt{J^mIq^M-s5(XaQ=x%0DR)w>%arp<`o+hUyhwIx}qG`~QWp51UV zpkKF^_L}x6rh8NN`z%^7H6U6F&S0jFwDbm?&GkBGbsi_&n`6j#IlgX^cb@SO9OppAXVPwvn8 zp59c>Lr>a}|u`m-Yi$k+%&p2Cl_TDeyOj)-+%%Y-~31Es@UaCo@ zVX(`awEAdgwnY>B+Ncv+N%H_jTt&?WedP&E1pU+_e6?H7W={e$rR}AeobWa)1T`hI zvtVu<7@+JtU|UDL7+N+40hxMib*)$}p$%uA;y=ocjVpjP&L=ioc~pcAm}Xd1vpAQ$ z$KB0MG}i|sSaBG#(y1cQFCjYq(g(x-w49V%Au{xq=l78i{pHN6sNn?rQbz!@L7QyU z_C){UaaCvJ>Jc?^79tkDj1BJk!O-#9KXvS5-2l?u)N~Vsr!ez|Wi%iK5y42ffhC}W z2=`U${U=BgUG?zTPj^uZ*0Uc0hY#@Zpl<^=yhY=2Z{RrMCsE_4bsBR<3AUgSJKUmK znQHcN9&}R;LT>eJuBiJU17OGqXxy8zBGr(Nu}yL7T&a$ ziY>AG^xLL1n;bB(cq(pMB^(pj^c)p{j9rSjS$>p(Yce?>8{u(gt#cA-N}MQv6K9F@ zTVrxUS)9`)5$vQqZ%lkaW?wg;NP0sp3eRXgHEX>s5hrTRR)O(Xg$2QufucDUH?Q0) zP(_u1cXC|I(c2`LPS$afX#kWrZNW9z=kpfDq!`~~%uh0jG_oBwhqX(F>6Gu1-ov^X zDlb_(iYFA`_D%#$!Ac4JX{c(Lo*i~{=RqcKyVj&$9U@JRDNEsxnA&YiUkGl#cz*hs z2KaT4-PODiSEams4$azdzQ$&8^M=*uj`+4mm7g;_ii9OAgR75DidjgCu=n$w(AdPP z854ckK=u-x;zD&$H~LJu2raYKH9gL#X8kfmxzDhJ=yc$OB+YnWv3EU^{#1P)0~D<* zSN?l-Q4)Z$2@3XV?N(+x%4vQ1hNUPT%5FF{rFeA&4zVq~Ob9AWCz0|UB;VNA$Gu4H z$WRG1hReda8gE(#1Ba!k77Ka3kW)jn2el6O?|#EC29)h&&%==qK^2NU=ZIBm4Sua% zx_XbIoClH0Y(?XeS6+?xL=Pey08HG?r$4L}4)gXcw9e9&Ni<*c_A1gdl`o>1kV8MW z`v?5->B|>SsV00aQ*XTdun?{!z=?=uQJO8#`W$2z+AC)JZNM=NSDhUnbkCKBrxzVBlM5vi zM^UTGkrRtDHI;_-E`oX(?IujH^BfORT^7L`i&q=z%rGg;L(i38rQMYWu4L`mO^=Il zV(tKstiy9@^?vC$ERJD6I$Yt)GF$mWr?YtKfm+;xzMx8E{AWmU=%h}~l=-0{03vcMvAirkk@Rg_?88o9Z+z#2B*5B%Sj1~hJB>=dB-8LXTa{S z@Y5bYD~p}ubny4JZT5l{Kr(?_c0&uLP?Mg*Lj}!WpPgVwD(v9{Qng1m3B-E_Q zxUVJ>`w0L`YFav(-8s_VMbked(~GwhC}XMHGEs393Kl?CO5I4b!Wi;H>U`M^2A@yX zm%-eL51&dUp;xGSTR9B86Gx@>b7l7uMKv<(gR+gN-QX9zS}2dZNNoTexh$U$OWm>= z)&lvGnTdnfZ;x#M>rX`!tzLq*qp zozK3-`)kQ*OLie-JmLFiuEXjnX)@|Ot)JxaxNV4>Su(Gu7GCIiWKR+=lr;ek-1Shv z&0$|QNen@+*w3;MnFUN({Mmv_J3E+@J9PrUXTZ5cSGJGOmkQZJfl8bP$fdIP#a(oj zaazyBrtfvzlH|vodtxNbwaQ4hYawG44@kvaCns@> zAq+EVluXWHJ96y-2SnsDCN?k47gpy3S%X-AD59j~`apv1OV*P_BVw9BP`S~Pw5oMp z=M_F@enV~#@|fOlsV`$4pSwa3>y|h_3Nza&iV|`I#>Ko9eJbW65-X~T`T2N6Fo>)Gv0*W97R$YLzN7f z7y?$U$4|;G%)P4;T$)LOM^vYc#mtXJ;&Jd`Po8{cu8+E0P&;yaezWS2Vn_z{QRy5u#5H@H*xS@f zs`d?~!y6mF5gIGTV{)b=)|u0d!NaJ!ruuR0@S4XE{qZKpV`}5gjD~)(7KyljLmh=` zFb;K3T$GOne&1!Fsz+e4NE}E9L5{7x<66my_eqP6TH9)iM|y_gyK6yQ|7X8+CPJ4A zqDJixqS-gFFQ|_0xT16#ZECC89$5Vamt>s{>Vr9%(A_zV^o#men{w>#NL$(nWEa|a zhB?Y*N8E6cxc;iFhGdo`?eqkhmh=-O(AuyU;0_XpJHKL;($dr-9%!wIo90^ZL&7IE z3M(7x_sf7rM5?5Jc?AzT#c{+d=A7fCT0s-U(QfI2x?p!oH=w||;a0K5DyOKaI<6yb zK588)HOMT<{zt|`ew(Xd{`8O>v8o6JCS^VZG=VPL`m;X~R|QgH0n^ty8*M|AlK1e| z)Hbx`cw2d%#LQ5`!Y}t_GIxfSin&y#J8_smOiKv8N(F+Zc0#ynOp#7 zfB=Q_TL#mbS3OM`i?AtVu;`bVfk++9=z>{~t^2JDD2-ZC98qoEbKi{8*v57BeCp%Z zK1&^rm+E8cy&%!g_bX&bFWjs8^2e$cuSzFThJ{yMfAf ziuq!bH>81b@Jl{uubNGZ57t(YsgV-29eOp9j(cKC*HZSgAdxs$298t4t}x|NuOU)F zs){yh%!~@Yz9za-sSydtJmewVC@Pf$k}2@^eH7KE{9a^G4!#mF&J%W+l0iPXu-F5{ z;Nct?cah6toE`rao+I9`*6XK5vQVbkI?c9lI7y9WQd>QE%_*jEHwTjFl4r<3F?e?8 zaV58~hxT^}HbntMMNRVfM>I>`3O2W_ao`3=Zx`MT0smX-^TqO{E`(1yMsyCLwTUl` zip%Jm1MI1eTz%y2>POIqO`E4|3{}??50~oIDV|_n9dmctdKRDsgHZh>Fy9zHl9|CW z&-uiqZv~Uv+)P=fcbw$=B0O3Pd)3rjMj)cedc|Hxt3ipn#+GJXh}hr=r0L-NpW$P@ z)?Lg|QQLEGpJ^QL$=UHm$+|I~cQSaA1hvIPMA0PEW32geIZ0nO>Ea^j6_*9A8$jyDAMM^s(_FWNg zG2BU6bI)YJOgVdJM#Dy4K{!YH#oWc5#7JcCm)1dmz^o^pi-|9tsh=_$IeTkN z{`l;UZksi1^-pYwxinVwtx$%atP^v^IjpT-7*|H;&{qLA>AHW~h{_dr#KeVd{6hQF z!k`-GmBbIJ?)lI^g;<2#1LMC#&lr1GOTi^sfdcCvxZ3GsG?o})z_1`m0@{|HaD~gT zRFe_${IIIJ_`YQK%I4f{s>wQNOJEz|;gKmEi-3HLZznCOl@I>AMzh#Cb=)j%CJ{{T zxF5{69j_?^a49)UbALYOw!bVq;aF*!onyP5Jpa{)MGW|Jwg)2T;)(tbgn3M6Pens~ z*-E#>^0I7re8EMLlkEJd3t-rVl1{zi?74kBn76*^9{8niB2%V|0T=^oMh5d?=jgCi zIuyVOUMC^0GD%5vaXebCi6QJ^Yy0F)aBlilnJW*AailkXUT@N0oz3#5UeQTEmlvW{v%`$4ir53H;WrN&$G_KA;oT%V?wK}WgPY(y$8q!N0L*jc zAa^b9ew%#Ha^D$ZnVY^Vsjw>7t0ra^pD>thvaU9gep(=9dLCxt12Ch($Njl&sfNY$FDx;(cO% z9_xL_E+*zJh3gg8JYdXY;$tKN7f~C|V8QRtTO65z`JP>T#`oN`m~m^=_t59&1Wmcr zQ*o{1fP-Wm&T~9w*E0ku2)ysIU1A!|m&!ZK4fU(Y!<)RtdW)kdhh|aNR)yW1-No~! z$Yc7pnNjj_Ujp6FBwKhopalTL$1H@4-`F{W0%?(~tq+)MPo?Wmnbnoe0)U)?O`z^k z-C(@N!pp}$oZU`6N}e5?eoul?Lu8FSixlct#K)Dm-Q}!6;u(!>Q__r!i{mM?iQ|4V z+5E(9ox+-&J!L2-&4FXhELgA*Xx{;Ir9X>g%XO(2>6X6Sv-k$f{7rf%o z=4uHC!hQ8#<0-8aVolhP^y13RQCVSQ~#Bh`WGJczwuH(!QKB%EB_}i#YX>M`@Hnb z?5zJCFvY;Y!u}t`)c*jO`swrHtfJ9GfChAcT0vZ0UBL+ifR^|VV_9te{Y&a*4-41# zm(UHUF93P-F)po*$?5uAIt~E1+cHC4sc{WaS3{Bq=N` zt118$6*vIF!Db$>BRZ;>9TZA7&T8G{D4Ez&m}eTx6sqkkzffh{gtx?q&BmJph_Y zoB-JP`0)Gqy8sMYxx}N3t8lr-Fm)j7-O9`?&48tWG6MWz@4iL3sEtAV7q1%X+B!OE z(KcDBeKBbL&QSnr2!lwuV9r3C?Eq5%Jz`)K*c(9KSkai_P`L(>j&BQjaIB%NSX@AW zbYR$jC}*cnNe9=aVNM|2%HZTvlt4;XfiJ&EsJUd8Gg zDJj)fb=75YjZOpU!_@- z^1Gb~@|`+1K7*(aWoO{>xAvJCz2lmiV31l%lkl^#@pnNWFWml=2*B|#raQixzFRre z-0;`AKUPTYBrl|1m<7|J|y|x>rDOgRi^|*CIFcW92@{TIJ{p*EcVXlwuW-FfbZ|y8gULTCwjl@8B;yk zQ$E;^k0OBep5;Keo9(v5KDu^LAoK6IS8!EY)rAzg=5MpQZ^XOrlG|;KuNubh?U=$W z8|$x|g)fPh@0VyB0oE&D23_ZK822?m(whmg)lWJV=$GTYUw~8m)6L)KNr4zW7XhhR z!BgAdkdEi7Jej&A zuc6Q{^<3XN3ggo#)=!>et8J}-!!a?#SK^g)l7`27KyLM2)&-cem+*+d>ZzB#e^L;7 zC!DtcoN9^Zuc;1AKx<3CSU>$=+yJPDeTkdV`|1F`LpCn}&?2{MHYV0Sgmyt{)xTgl z+I0VPbRA9<+`{hlB-|HuPF=r#-QEMLTYvl037WpD)u${O0R9AZ8;!r^ zeqW(KwXKG1g$y)wW3FX*P) zKB2ooTE79m&m*L>aB=mv%J`a34!^zvzui#$`Pp(Q=jXXsl?g`AoMuxpuo#HcimM>= zFw1GGm^sO2NJm_bxtN2D+s`WfR7R-k4tDXP4rM6UrRMC6W3$0&9wG9o!mrn_y6|B3 zmx^1~|DcuJfRRDN51zeAAcUte3%7LP;dXAlYYjB>yN)Xzat zTo0JX$Yr-%T`;sb;ZdRfs8>2ci9zikB(*8(MhlDCdmWT_FVNYfA_^6P&})^>lkyct zpT@ccSqD8Yk0^(=HySoLDKEyu6kQu<>K{#>3J49&i_sUSd>i<=Gzj#m9qp162Nlfd zkC@i*!9=>D9E_=yZG%J<9iFx|bbUH!INHB(KHj*?jv4aJy8Xi%{W~^Ex`|#f&UT^; zK;*pYrZx^$%#$=EHO|+pSlrF|_M0z@w|M1ge;-7J1j(mn#>DvRq|S{BvEcY>L{7Z| z)}_}>fk52~v1M)1@3L7;T~ET5Y{+Hy+zmS~xS?M0XzPSyZ`#C@MIN+D*QSqFO7Hug z?y2_X7Kzc5-5sF(aCDT5ciWw)N#C}rq?~`rydik1QQDpU+NdYH+J(F>2khSe^_O3$ zz7YV~th^eLH`+cbR;Jm5IF!nS(4fUlw#x`;&jE*Wg}xVjN6xzqD;(xKjh2-^7M&n` zw!fOz(aRJ443ZNduWf8$wS!Vxu9(d4NA|_Q4YRjLiT*W>t&8{174?9sCcK3yyuUZr|>O)XFF3kf!GXPgscQK2KF+JEejyO7P zvdWb+8FmLulubuyE+W`Ho#a%aZ(bzD&;Oo-dIz3ClSf3c8EjK@504Uex}~7 zHBNO!P-y}*2uw+7C0&95QSx;%Xm&n1cFC~KHp=zH-W4tT+A=Ss09W)gKA+hg+UP{i z-4V|KIz#8R@!nl8=Q1mcXX{TJoHEI$Jwi*XIWM~?G1s*4*LqF_io4-r3%#hq%4d-3 zI>lqnS;sVe^Yw`Q^B#m4v0sc)1R&*MMIonQj-N+zAx3#5f;ROh(~F)^j-gbHO&y|hd~Zz%EUCHc_fCsB0m6Ap_H6Xw4dxLAL!cqLae*70YKz2-7+`@ue%IKIkHoq;IugtCjn90J8^ye!=NjU4- zDmi(3bC*O-5!L75v1BjPT-9w)E$j|Zhf=I_q~lH;d~&u${QfVY*<2OwlA?uv&*&AV zrjU{t(vfv z9#y3Y>Vy{(Kr{KN$I<5}!HX5nz|q_nz{BY~g1_D7{bpZ=nl$M)qO0QF2&GMKagCRQxB7RSa0Sm{MI=q`1m?Cr$LzE1 zO6Og4n~F=l;Gw5;j&PXycLM|?C8;%rhEmO9Jr*5XMOD|@nBsP+|C@O*uI0sYPqI5M zg7ImnY{pl3-wH{&$QZp+qL;oW8Mv*R&YWPTiDvG^y`>ffjxfTsV#IuE9-tdsM2J|m zdQ+Aa$Nav50l&eUdzbpCooxle>d?|>fp6;C(g2iSNzf9%IYN{QM6G&Yx!zj^FS}xm zLr0k>?PMyhP>N;iaCKvTAe3@?`>tXYkGrx9mEzI#*31 z$b!S1jYAKc)i4nBKor2&q0sh9c0kkCxsg>m$$0ar!Q=+5~&!Z#;1Y&R27_8&(?c>E84tI zz%%KrP9cQT_;dHsQgk24z7YiU@H26h+>v5t?aSB`9^%tpSa%TAyXrggSpUwxEg(u$ z&Mlxi>M%s1GY~gl3%=9eDx~Flx!^H#tZgd^c0~-{ORZ}$WR5sEK)6i8Kcl0BKD(4r ziP@;EE4!mLP0KZ!Zsg*auJXurIYxfg6fV)=T{E$Ap!208yQtp%hoexQTZVkKFU~!q zk+tcSNun17Wvkm?q{B|HDRX9-gM>^gBt$jA1j?ANX7I_yl{y;fa603;H>9NxB1PeX zTPOWZsjGlGQFXN#C;ck{+!fhN5l?*do;BMG3I;}1*P5}^P9R{o#a4dM_#_vd9KjjR zIk=&g+#5Kz9W1|dUJJ(^kIYQUm$UXcUb`V{F#REMIfpfXpjNz}W;aL*`E z(S8ZHH_D}Dg%19mG?6aEOVw!txe8q9i_!^u$r(hgszSx$Mtqsn(^BWA7u>jTPg3$F zynC1QD`qy9)}xnlNBw!taOcvd@bX9Oe%5)$wX+2=4=17+5{!JYS_9Mjmv;coFQXFi z^AY}6WWlld`*)MXd1ezcH?ZzwyOT`r)VM3glg0%exr&NX(yvk;9YmBQJYsBf{Up2r zk{T$bzvPDSxBZv=b7VSv4E0Gd8!QU@K)G7uXmR1YB#qE%iKOM z*`hxXeitmxlOl7@QNcsER}%zia(0&w{9TJ0@e^{gLge2zWF1J-62f%)PM-v)a6ES| zK28)N;j@n`eWY9b7YS4%&~n=AyTg^CH+u#zAuNd={2-m`Ur#Q*+*@*i{h90$K(ZiiS#O0p z(pkC7bL1>;ewBLt)h8|Z^Wa0Up^m={B}SxpLMDi8qYUuelH$c5# zlnJ=$3JnRxhJFCri0K`uW-ObpHrhk5~v zq0v+*)s?_4?B8VA4()@x=vs<2cLQ!NUG6E)-gY|kGExPd6#5Z~KEFp0<({K1YCQQ8dq;(IBJ4o$ z5zU;2U4MhsaCZ8GSE@AuF5jhC^e`~Eh*IbD<^os9Y zQwhbC9HQUZ%+>qJP)`ER$ zISkKsI4d{dY5Ucgi9Y`$qSTG$5hvzk6JIehkJCc=8+bO#!4d&JL4+cxN_P3%>u!S? z&o}SNLdQBl+vi^y`lj*t-b9leldp#Z>x?1hQQ1)yLYDc@&=gl*sX0Alqfy~rMqS{Z zN$7dnjyxmN8+bI;-mzEWw4#)~E^X97)S>|0mxwQ$>Cz0caqTww3mA?b zz2<>*gAoeJUXMRM6}uT5R8(6JC&QjOpQCs6k?SF(MyrXpW#T1>_j`)Df4m+3&~|Y< z5Hfm3t1EVZ!Y9qKlUk6TmiEp|a7AA4b4~6uYqh%1cE*<8XW9C=nEt|*f;3J&3NDW- zM7^GVCKn7@?thpc$8cD7nS7A@SpCH&T?|6|g4poPIUcy+B4(Ah?j_MeP(_j&zu{E` zzV)?yhX=?o3k_xXat%w-km!Ddp8A}0))vQgon4No*ufzlp9xaC!=rP@;*e86+cof7z zH=1&AIUc+`6IqlwM0 zYlGZM;uc|?lJHMVY?iylxfM3&L*HfPvE-O13`Xxx(Ee!F3gKv~AVgQ^gOvj<|1lszrsl=q{olOo%~hNGS*7Bi(qT*Q#Y`%oe`xxtzD z0fx=94^xlai(X{aXok*0ifO6*PO`-KF&{NXKVK=v8J9Uv9p`$0FlXfy*y{SCc-uhZiEEm?)hwJg0I?66x1;yffj zg;t3_p3!UAUm|12JVrn37xOq4lXZRN>$;wT=>4EAAl1y~>@#uJmonZjKA&+3&tt~P zU!uQ1lJf&yI!knR%&NU^pnc>aJ&jW*lQ(KNh0ziGX>oQV^~&|WZ|f?g}qa) zena_Kc5gbiv^|ExPWsSHrZ8bcfpg{p=GoR|JDM`S0|fjEyDkD#1y;xdMviJJQ(QU^ zX?gP<2QTrUA;AXTFn>rq((D>`?q@18>qt_~Si8=v*k+J-2c4~e#zzw(k(~AX>xW(S zb2~Q$o&cykCXoSJobC_?m4pP8dXc8CnzEXLwnC|__=2JV7NY&vr*~__T6Ry5Z>bw$3xL9U_XIbQacrVA)YZiD9Q2L~oqLOMF zi`S~jN_a2w8}wa#3`y~b(A!$@ZGkonLtv%?|5Kd|r%#DO+QT+@p&>0XDj_?I!Gn&} z;IoNI{t_z32w5Rjyn5b2Nfx-kkBYQ!^hEc1p}XQEfWp@z@hn)8m@+c-PD+dW=q>gk zFC9Ww&|34yUoZt55=)(zILme*`X%&JBL#A8UUT8b7BM^scVw01iVljwc_<&sBiV?O zU^DG7{GNZ|HTgL7Q50L4&tA1ru~RuZ5*B7pw9Wfkxf64v(^}_}nQzw^ZywH{@*fl8 z2}TaO_~qB2`T4&h`>Kd2EvD`}O2yt)SG4g`N8ur=+&5;~7nl?{{3X3?2JM+&wgcOQ zEu8L0bJ2oC>?>%;%dz1bH_DcmA)dhj~K^^|Y|&DmW(pEc~`JzEFLRi6j$=*WQ(INT7-Cn)?{ zb!l86Oy0DAF`s@;=_!L~fGd{uTv4hrWT4=Ts9mh93#H|w~@#m5xcu%kFxkO~^ z^Mik2K|0a^>z=U$saU$*d?I~fzpKZ?f$^7Q8wo$S7}QHjJ5drtoj1j^RB2NNGK8f+ zGJv=v2-2eJi}&{Zof=gu*EtQJ2G0`$LGz<14Vfeg-5il_y(_)gBnK`I_bdZ*pGA{2 zs7QUJAB#56p%P*wH&?7|*rO4^O-p~tUD#u~!s%eFJd>yo(b7G>e4ePDPaPi>-Zh@u z`NCKo*HuO~trGteubM37KEHAGNHv3Ge0;5b1D>_2?UZIQU#PTOehaa6EU_#}5|F z96Ra|zou94iBP49IB{+c$C(A5y?i81WKn6~Qde;&pZ+4ZJNK7JFKEGbcNr9bDoB4E z=?;%v|3J%lh5l`-f7R8{R;c-FLdKT_&hV0$>NM!0!9-G|ksneh7B&o_GqO(1i=G-Y zLHsrH+dz*n{=6tdmQ)2@59~g6P!In8Nzetg&_UwZv^N)1_I|)q zef^{n0!8%r_Iz`Rg3C+Vz0&cdT5X<;HXUa zf`{|6yDUr1kTaHM6=xtsilHU+^QjuzdsijGszRYHCLeMY%fZbz^h`z5X&vpgDM5tt zK;9{1;ylKX8OGgxQxfL#78P9lsMykErn5B$Qh8+o=W>&^=xCbv+lb5^_TSL~u`M)4Q%gkwIS7*PvJBJ z^tvx6Zp^JF(rY5>W6DfKsz0PO~epLu|Eq#{eU z?(5*+Jc}fk;j(~ET-0b!>3Agb-A-58&-4Q$Ee`37z-oq;_;~vf5gv)_@X!Uiy9T>- z81gqRbcEJ8Xn@u1N?0MX()8}V)!5T}gL*N%T0a(e_TwQATtQMA0`TI3TqvAvL@^E@ zkIp_N<9=5ZKOR#IsDW+VBDgH*Brlwuj?9XRR+J$$mTM0G=J(yAG$gq!F_7V{FP=lYeAKb@^CF5yPmlPwjp)5l6sl9)yb>Kx3i4#Q>0`yB>psA)F7DSA z`T6nOkS}YQ3H#iBY3<~+=&m_WcI1bN@HHA$+1}MA%MkL6lVq#-e zp4cB8R-0ZcOil9RsdIM_?8A+sF}o#Orf`hKXVewP6$#Y>Q&COe|DeFzRISM6Cem_6db!6zKTTY6=$Y&z+?BK+|b6 z255rbE8})#%GC7Ijt?g@Q?SM}1?4SSI~1IoRi`I}e2mw{Y7j_bRsd_>XP$IRQ960e ztG!0x7lN@CJxL-7Ru``Xx1ypIzEa<;bJLPq$7M;nqjr2c6MBuEZt+7%lKeiH?Y-7} z$Cu~$2vSZ2`EkT$oCw^;Ngc++?lQ*nrcBJkFW0DEtiQ}T!qMvvcU-UWy&9UB@f_I1 zSob%kaL*vj&fUI5{X&5ESRgt#Z+@cHe3dZ;$D@BowU~o|^TuQ?V9oP&3so5f-kZ%} zMLnr9L^e_I;wxd2np`5+rk6nuAw%0YoyO)n>^SGp_f^H_a*L;X@87*w=OD6*);aE- zGd>NLQZ*=j)im$Q%7w49(Zv1&z%t zE8$m&t{A|`uhp#%3Xb^rVrjFj0Zmui`inUgf{6~6q+z^?uHixMo0aawUn6_&p=7b1 zk-Dtm%g@c`ycJ1Go>>5IWIh{PKU_V+)x*js*cN(sVyjK_7+`wH;+!r>yz-6>cjr4d z!5C)_g&T56N0<0|RpY=0Wrt*~bo(oHfzrUSK1g1Lo%jvAww31-3j0A&<{g5S!nW zis;gqxgMQn39DQV$#*CC({T*HSGoNr1O5xM)k%s2W*~N7?$VH9H%<6 zBP6(%rVO1%Tl&G?g`ZtLm$d8cX4+MS$*dfFj3|!wUg@liYggHbHSkQvHp#l465FDV z#+DAZ&ywWGI})L~5i51`3rc0v3)pPF=d}Fdn)j*F6S;2x6h%#}w|*Oh2OseuKp&+>g78i@YdRG+ z()`NIipd+Nc$18mL7n_uUq5232$!QhBn{by8$uY8G|kPg#D4#k!>#nG3rpJ!oYcOu z8hUox1hFO92S~4J1D9+wIip6fMBHXq^eFgU-H8uK8QmkaE7PxYXbKF?#DZUOsisf@ z*0Nq|Cuk3THO|eGtCS{zuirl4)$e>?jP?$}Y05*p->ujOBm6UD(rVcyH)BH`6P>z0 z?!&Cr@(Yd(=6R$~?AE@_wcO2pCuK?PMz6WnyHvA$+!>;JNkgAW z)w-}*?F=~ZaLX4Is6P)8>`NA17L1h}Qbl<3ibPpRQ$u7efYfheN;0RxL`G!Kq7w=Y z?D}CF@6vd&{&j$^j;K#8(<7N<~gESY=s_r~k5#7x= zvDA0%?(B*8Xx_$1B7HygJav0*^Rt;odh`Ik&c1u0T%xyifCKQ8I~NK59DFB3?+Uf; z)o8UVvZOjv3A_78bh8eHbhY99cO21fq5~}yUv16>cVa`HkKDV?7IesKInieo{AJRl7b5^RN^7 zSo_6>82N>*lH{wc7%K4zhspjHSw`;0U&YV5~7gIo@?jJi~z>mq(+!IH?LJL#G*Q;e0HBN9)wXTfeW531QdBC%%#CLZ%7uT(8hRYm(oA`y_Pe5RgC z&vt~8uF{Fv6Q^IIc+TrFu6Irv@+X(!++wzEZ-weFpL5gMG4{JKo`+3`QYRf^Ra=L|Ap!a?sfb?{*11{*AjT}|0 zJ&bM&FSsdoDq>q_PHHuJTSOIK0r{Cx@C)yG21!LDN@qy%ed6YtwZQHcdKLR%qhuOI zCOLHJYtGlEoW}mqo^)h)TYFLe&6Lq!eBY+*)Z=z!`=bQqNzn3`c3hJ2wPIeT z&U7fT6mLXqZ#!vsaS^wd1#Q%b^-ZU#!Pb_5pcBL??FVLwBcYlHnqJYX0?u;JI4be3 zs!ZEY@*}lx`>~1((ori(&-ncc4rvQrrWss*JcF=iYo*Pyhkc++)>VOnPN+?meY55*W8heFuIX(vFMHXPn#lv(b4X77h1K5Q*0#K z1C<_659PjV^PZHG_I(4Wln&C<6>qnWBCKxEr;$B7Q;-P?3ZBRzO&^XUW3DODT2!Zu zc}L+ETi3=mD1w|W`2c+@U;(Vx${tExV^?X zb!?Sc0}mBuYIXGT1}0zWlg@NAtRGTG2Uf+8_lf))IBf9LYbUM^j!ui4UT!Z>)*uPG z=QFA5am`n-;E-t{dZ>15Vk)P4xLpVop_MhK%U0p17;qF;1FJtNiFwTp)^M*3o42oK zc@S*A4Wtck99)lhCmws%&0;=nsM7hEEFf}P>n*g?WkOg9p@Ffp^1*hMYP=L5@ocGT z`|OvM@ox<3%&D+#z~|ZgHTDn)7#1d3T6(pR{;DPGr^BwrJd2Rmk;}v(&HNEnMKrH>shzXEZ(SToK`ScF*Kt zeD64^`faD|vEU~^IU#VAk1a;iW1IW0o|*bA=!L3v3dV4&dH7mkc}>Zw&dzkAlw&Y7 zta!uDP!iv@#zfRg^gAotJ5%srV$_hDhEqD|s>0=x7sv+p`9wZ>6K@cOBI{ApIMNU+ z$M?Y$<@Em3X+>?}CgtpqXv2Q|a7);V9m~uk5;$sgCYe>)in+Yr^>yECNP#k7Cg&uQ z7|}NNMS_R%Q%b0kq>_$G6mxZpF+?S}8zZ0OvnSM+zQ0~Dp-C`rY6%jtUWXbJbR)-7 zBscSVVawDnsHN&=kGXoC{N65ica=a@|7W=8fuE_h%XM{xenj)ALvs}ZrIg%Gychd% zy5z28X)dxKyIdudW?sH9?SL2A%J)KII_uG;`J$t-dD%Ca$`|>PSLYl(%`(t-@!r!7 z;BI$mq-AnBr;xS1v2d(p8?DP%WaE3<4}>vxs-$Df-4eGfJ=tc2D#9X%`Z;U48c*6b z-~1S^exF8vB+*XcH1S~^ghC8&#;PEY`Bb*pLn13h^3-7YXo=2ooUF`Ot%|Gq^F=R# zvhq7RoTru)`$av<9~wCb)LZzi6%Wv+-OZlQGp3XVfKOy4Y`(mR<$0vUV?^j&Zy-d> zKJa{7Wz7PcZn;(K(KY6410SzVG;MtjVjJBzn;)k9pX-CN!}eLw%A6UkB;WbBun}QY zEbP7(j$lZj(Q$hL;^oxjVMbjm*D5Ju6F6OeW=Aq?5Ye zZ|1#6-BG@zo=%S{WOovGIdSP#y4WvH|hES;b6ki}xpShIfW;VNUOo0VZ#!(wN=}MPuE)@PeNkS=Q zKfk8eYQ%hu0kaq>Q(ZGnh)6hsKCQ_R5li{N|1w|NbeWjS<7N_nx}QHs0JUCbW;vP~ z%vsD6ORDQJq5^+$aIe=(qe3(Cn!v&IfX8n1bsBH1uFpPhqfqYdH62nM8HbdBSC)a@ zlQz6s+FG12{MoW)4pOfG5m;`{G}?tF!;&xc%?k)nAH>2+6C$ z+|?BnKrqj4SX4_xTL3K1r--G6oq&L)6F`mWHXbM&8-Rn2699&Se{oj_!GdM}5)btD zR>Me-PT!Tv5_;35Zj-uH=LfI|bkB@ZvtMKXJh=u4MfJqDb44$+vH0yYCYH*s8_AeMGrdn z3{jA(ZYZYt`7oC>XJcHNVycB?fht#dCoJ6Zs z0#T-pmyly$y3d2-lGAGcB;QmaqDNGCb>E!RXnpa1H-u2UQ%_sWo_2vu2aTH|310Lw zJW?2PEpJPo1(V%NG7V`~%=QcIq^raG%RS-pA;%sU6xmgUo-|2Fm`jWZ+!N6fZ>g-) zq#+pU{cn?z61c*S0c=LNc4#R6j97UL3(!LQr|Y4HVSAgOirn6D3`%OY!WDOB*>-ZZ)|czdW%Finmp5l!;^UJ~26-y? z(ps>UIM=SoQ>UKL>88?x9qDvAF&!_P(`D3rO&nM}%%6kvAJM$~1 zQcc-Pzt9*T4}MPZdNXlTd&!fFUcV5%TRn*(`D}6F3unum&6mX26>SzKJxrGdSMtN< z(h}S@edcLK+Xc@WTj=67?MgOt%*H?4dtkOyMBqK_+{z+kra0Fi-qF!MygFu&Z^@gr z=YL87A?GkNl4 zms?$%Kva*;8I>^?9g&-|z|+v@(L#X3LL*3Le7&?x?NPGai}7fQuOME0L-)Ey$oVqr z@)GIy4mwNI1>|*pAIKv(j5A7XZ87x?>^}H$Htlu(*I~=t9ZyveHN2b2f_=77oTN;N z+ntxImj{S(4#<-@F`F6yTA9ny**(@MOE0vK7SCe6EQqc$GfaCtv6~Nw<)jg%UhoK7 z32;%M@eESkheQWJFd?%1?rCK7oljiak}d`!Ruqu<$lSwtkvHueb0M2wo#_{C(=+-* zQQlaL^sI{r^K#OkRm%qUhsyDC29AmBOAQ(v>{Y}!vFp@U?cO-qw-{;Ol zzA%!0lfnukY2?&wi7Re{Ur73y%bU|Y+xcmvL7s|Rk{(uFrpP^j~rIf92>~{QfrX zzAfz*+1%X!*enX*{C^M75&sM5{{{4aG4%f}Kr=+-sQwA)UuUZS8J_PP?D0E6|2!h( zza!{>;u$s{zB}gr%NYDZ(6^Aki)VJ=|A3%T{~%}~G04e$aVqH|(=^HR<@Lkk5T5v2 z(&FiaqN)01-|(dR$uyqx%;ZcyM-3~-xboFY{lvq`sjgSUI|pAiuPbJzB4@J`&4x#o zy(ui;A2}86e7#E1-w~aCjCiJVzJGRJz%y+1#H@oIF{iQsboXayY}&yvr7 zFa_M3h8E@1J3q4mJWJJF6a;!~GE9&6BGop?uDz~UFM6gb)8tg5S=L3OF1UW<>{x2{ zJ-LZt^`@*$;_B0LMFX|TwCUK2c@9$W3y4-(2JM)qdESpToT3R*>O32TFFwUGqT7JT zv=&ys`;HU1+N|u#$~6MYkf%CLi-17imY3IFE&Ly~TJKglk0Zx)TN~eBu3K{uZ)F zzV>KNfu=m|uFDDQ3&bl6!cLat_kY}fgPRhbBG=y;NdcFR(NK)zH2p#AWnCL;i2&*s z!JS-BY~B9H5VDj=xLb~fO{8te7lfc!h-k8&Up^T2L}Cys_}MQotQZc6rb&6ky-$~d zNHfuLs>)f|y{I01)D;>=%gL2BVPKcajbt~o)U8L zo`#}ft?VUd0e7|2s4E&2LlZ5RA|c|;3SI5QiOG(UPm$wy zeo3`Tr=h;z^W*4-g?NtINwm0F(|OPJ9B|b>#%Fi%bu_g8OS{H&6a9}vjLVZsxb!&k zi$}G#IktZS`qydde+K9~fh6t#`tM=%KPS<@kGMg<0Q&ZLpx-CacaO#a|9XPZ-wR`4 zPS*b%&A=VJ$GCHXnP(AgV7MsyAbp|;n~4e&*uogLRn3b){^#g7*QX(ZuWPs9 zPVgHNoR?|V_S&~CvbN5&4G$>{Egg(l-WV9Jt$zuIjkqgnk_w4Z3k%J8lF_Ai$}RJg zi6`qP*VM*CFjDI5M>plB15bIxro-DX5wA+F9j{$qCAZ5SOfC*3wYBv^BIXkhSH$L1 z*huxYyiudwC*6%y&%b`9Sf4>cQA#{R)k7WpM(^88W8L01dZUQ(>}}197q2)+oo<>P z?a$8PI&1rNKCc%(s~B|YU9k)et>5B#sq$e>UPXmqWwBX5S0W=#OM7vSq8JoP_Kn zsyf|RvybICB;7doXY@$lwq&4sW@2PCcA%hUG|Du}^R^pn@L~*MV_`W)svH`PSQghk?IA{Y6LYfRfF8n`=A#11Y=Rgh8W5Q1qt_D#LG;qBk|0YxULSCOxWe^_tYvLbYOcVi@TCe-znPLDazC#%G4=J z93Ae$&kH+edW7yWhwVs~rBk$?oU|NvQInRFk=je~Zh5(lP+b~9E{zZ_jVLdTbdOpY zE!-DL{XB5KEtZ5^bf?#x)Xy_ieYVnQ{AiR^zgu3k3wT7T9x(jCuQ-nN>QS+zPy3%> zWc`)E{xdY*T_?W-$3NDz*kRFHei<+Sa{|ov2fzMA->>84U+2GnX(yv&XkZIlDYvwT zt*^nLEu&*&aQoNaWr-W>+XB>nngqa4Yy&_)*U12&pVSRt{h1EH`cq4d+vBSKo@%rG z3jBXj6-@1aUDeMa{;wtdROKIIf`3sGY>DqLEq~?&{H$2+w*qd}|GfY~9XlN}OT$|o zV2}Tgr~Rk);9r*}Wo#_V0JK6}tU%V=ivtAVVCCRo0D@?MKpI#&NlX2Imqfuv$I8k;A9g61 zj+w0iOkV|IWo8k3Gc#Qs3yWKo6pV~*0kG>Y)tLTL4ZzL}VFm(d|Dhq>FE7T)#^5yy z5CCRJ0shwy0L;O`#sPQ@_=k++wlCfO04)AX#?A_B;5#zlZEyHZ2IYhTVeS393<}|Z zvDB|J5D*A~efhZ~13`g*)C=N-!aClsd4WI>?7+CYG9dW2FaDMecFr8<-Mk=n5XYT* zfl%0SL3ecqva><%rUSy7;LdZvbb$i@NXH3;-qi&NhC=?(nVtR5@}MB#U7dkY;2&)Y z+*E&Ez5a;dU+wU?~ zAnsEK$ zg$>H~2j0N2mvr}?gF&zp6z`PB$<78t^Y3+VvU5Q1)(c^SfbX^ogdG-j>rP%M2ZZ%* zc~CH{E8I=T3H;-|K_S3fX8P@Up|Iz@(_dgV0``i3PY091Qr?xZ{!s@A$O>Y=^FD56 z&|m7Xv(Yg&Gq8cJ9RXP6ja>|GZ6b@Dr6r90U@d<;uobg-Z3+0v1-Cas05xu?07RHW zn4h0h7|01_g+f@t>_Si>4yXt#7-mM;IC%m8K8XeZMl`l|IyQDcZ81zOcG#erib_~o H1m*t#EW^tP literal 0 HcmV?d00001