From 1c961788464ba0303c7b01974ba2bf2abc9ffa48 Mon Sep 17 00:00:00 2001 From: Kyler Olsen Date: Wed, 28 Feb 2024 12:53:47 -0700 Subject: [PATCH] Removed public keyword --- docs/ytd 12-bit computer.md | 37 +++++++-------- pytd12dk/compiler/lexer.py | 10 ++-- pytd12dk/compiler/syntactical_analyzer.py | 58 +++++++---------------- 3 files changed, 37 insertions(+), 68 deletions(-) diff --git a/docs/ytd 12-bit computer.md b/docs/ytd 12-bit computer.md index a3e56ab..f029cf3 100644 --- a/docs/ytd 12-bit computer.md +++ b/docs/ytd 12-bit computer.md @@ -111,9 +111,9 @@ ID_Continue ::= ID_Start | ``` struct fn enum static if else do while -for pub let break -continue True False None +for break continue let unsigned int fixed float +True False None ``` #### Literals @@ -199,21 +199,21 @@ directive compilation occurs. #### struct -A `struct` begins with the `struct` keyword, which may optionally be preceded -with the `pub` keyword. It then has its `identifier` followed by a comma (`,`) -separated list enclosed in curly braces (`{` and `}`) of *structure members*. +A `struct` begins with the `struct` keyword. It then has its `identifier` +followed by a comma (`,`) separated list enclosed in curly braces (`{` and `}`) +of *structure members*. ##### Structure Member -A *structure member* begins with its `identifier`, which may optionally be -preceded with the `static` keyword. After a colon (`:`) is its `data type`. It -may then optionally be followed by an equal sign (`=`) and a `literal`. +A *structure member* begins with its `identifier`. After a colon (`:`) is its +`data type`. It may then optionally be followed by an equal sign (`=`) and a +`literal`. #### enum -A `enum` begins with the `enum` keyword, which may optionally be preceded with -the `pub` keyword. It then has its `identifier` followed by a comma (`,`) -separated list enclosed in curly braces (`{` and `}`) of *enum members*. +A `enum` begins with the `enum` keyword. It then has its `identifier` followed +by a comma (`,`) separated list enclosed in curly braces (`{` and `}`) of +*enum members*. ##### Enum Member @@ -222,12 +222,11 @@ followed by an equal sign (`=`) and a `number literal`. #### Function -A `function` begins with the `fn` keyword, which may optionally be preceded -with the `pub` keyword. It then has its `identifier` followed by a comma (`,`) -separated list enclosed in parentheses (`(` and `)`) of *function parameters*. -After that is an arrow (`->`) followed by a `data type` denoting the function's -return type. After that is a list enclosed in curly braces (`{` and `}`) of -`statements`. +A `function` begins with the `fn` keyword. It then has its `identifier` followed +by a comma (`,`) separated list enclosed in parentheses (`(` and `)`) of +*function parameters*. After that is an arrow (`->`) followed by a `data type` +denoting the function's return type. After that is a list enclosed in curly +braces (`{` and `}`) of `statements`. ##### Function Parameter @@ -456,7 +455,3 @@ that is apart of `pytd12dk`. | `ytd12nc` (b) | `ytd12nc` (a) | `pytd12dk` | | `ytd12nc` (c) | `ytd12nc` (b) | `ytd12nc` (a) | | `ytd12nc` (d) | `ytd12nc` (c) | `ytd12nc` (b) | - -# TODO / Ideas - -Remove `pub` keyword. \ No newline at end of file diff --git a/pytd12dk/compiler/lexer.py b/pytd12dk/compiler/lexer.py index a9ee470..6349d01 100644 --- a/pytd12dk/compiler/lexer.py +++ b/pytd12dk/compiler/lexer.py @@ -50,11 +50,11 @@ _ID_Start = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "_" _ID_Continue = _ID_Start + "0123456789" _Keywords = ( - 'struct', 'fn', 'enum', 'static', - 'if', 'else', 'do', 'while', - 'for', 'pub', 'let', 'break', - 'continue', 'True', 'False', 'None', - 'unsigned', 'int', 'fixed', 'float', + 'struct', 'fn', 'enum', 'static', + 'if', 'else', 'do', 'while', + 'for', 'let', 'break', 'continue', + 'unsigned', 'int', 'fixed', 'float', + 'True', 'False', 'None', ) _Num_Start = "0123456789" diff --git a/pytd12dk/compiler/syntactical_analyzer.py b/pytd12dk/compiler/syntactical_analyzer.py index 3ce53f4..3f0ff11 100644 --- a/pytd12dk/compiler/syntactical_analyzer.py +++ b/pytd12dk/compiler/syntactical_analyzer.py @@ -535,7 +535,6 @@ class FunctionParameter: class FunctionBlock: _identifier: Identifier - _public: bool _args: list[FunctionParameter] _return_type: DataType _code: list[Statement] @@ -543,13 +542,11 @@ class FunctionBlock: def __init__( self, identifier: Identifier, - public: bool, args: list[FunctionParameter], return_type: DataType, code: list[Statement], ): self._identifier = identifier - self._public = public self._args = args[:] self._return_type = return_type self._code = code[:] @@ -572,17 +569,14 @@ class EnumMember: class EnumBlock: _identifier: Identifier - _public: bool _members: list[EnumMember] def __init__( self, identifier: Identifier, - public: bool, members: list[EnumMember], ): self._identifier = identifier - self._public = public self._members = members[:] @@ -612,17 +606,14 @@ class StructureMember: class StructBlock: _identifier: Identifier - _public: bool _members: list[StructureMember] def __init__( self, identifier: Identifier, - public: bool, members: list[StructureMember], ): self._identifier = identifier - self._public = public self._members = members[:] @@ -704,10 +695,7 @@ def _literal_map(literal: ( elif isinstance(literal, lexer.StringLiteral): return StringLiteral(literal.value) -def struct_syntactical_analyzer( - tokens: list[lexer.Token], - public: bool, -) -> StructBlock: +def struct_syntactical_analyzer(tokens: list[lexer.Token]) -> StructBlock: identifier = tokens.pop(0) _assert_token(ExpectedIdentifier, identifier) temp = tokens.pop(0) @@ -761,18 +749,12 @@ def struct_syntactical_analyzer( StructureMember(member_id, data_type, pointer, static, literal)) else: raise UnexpectedToken(temp, ["Keyword", "Identifier"]) - return StructBlock(Identifier(identifier.value), public, members) + return StructBlock(Identifier(identifier.value), members) -def enumeration_syntactical_analyzer( - tokens: list[lexer.Token], - public: bool, -) -> EnumBlock: +def enumeration_syntactical_analyzer(tokens: list[lexer.Token]) -> EnumBlock: pass -def function_syntactical_analyzer( - tokens: list[lexer.Token], - public: bool, -) -> FunctionBlock: +def function_syntactical_analyzer(tokens: list[lexer.Token]) -> FunctionBlock: pass def file_syntactical_analyzer(tokens: list[lexer.Token]) -> File: @@ -784,26 +766,18 @@ def file_syntactical_analyzer(tokens: list[lexer.Token]) -> File: if isinstance(token, lexer.Directive): children.append(Directive(token.value)) elif isinstance(token, lexer.Keyword): - public = False - while True: - match token.value: - case 'pub': - token = tokens.pop(0) - _assert_token(ExpectedKeyword, token) - public = True - continue - case 'struct': - children.append( - struct_syntactical_analyzer(tokens, public)) - case 'enum': - children.append( - enumeration_syntactical_analyzer(tokens, public)) - case 'fn': - children.append( - function_syntactical_analyzer(tokens, public)) - case _: - raise ExpectedKeyword(token, "struct', 'enum', or 'fn") - break + match token.value: + case 'struct': + children.append( + struct_syntactical_analyzer(tokens)) + case 'enum': + children.append( + enumeration_syntactical_analyzer(tokens)) + case 'fn': + children.append( + function_syntactical_analyzer(tokens)) + case _: + raise ExpectedKeyword(token, "struct', 'enum', or 'fn") return File(children)