Removed public keyword

This commit is contained in:
Kyler Olsen 2024-02-28 12:53:47 -07:00
parent fb098a9250
commit 1c96178846
3 changed files with 37 additions and 68 deletions

View File

@ -111,9 +111,9 @@ ID_Continue ::= ID_Start | <Any decimal ligature: "0"-"9">
``` ```
struct fn enum static struct fn enum static
if else do while if else do while
for pub let break for break continue let
continue True False None
unsigned int fixed float unsigned int fixed float
True False None
``` ```
#### Literals #### Literals
@ -199,21 +199,21 @@ directive compilation occurs.
#### struct #### struct
A `struct` begins with the `struct` keyword, which may optionally be preceded A `struct` begins with the `struct` keyword. It then has its `identifier`
with the `pub` keyword. It then has its `identifier` followed by a comma (`,`) followed by a comma (`,`) separated list enclosed in curly braces (`{` and `}`)
separated list enclosed in curly braces (`{` and `}`) of *structure members*. of *structure members*.
##### Structure Member ##### Structure Member
A *structure member* begins with its `identifier`, which may optionally be A *structure member* begins with its `identifier`. After a colon (`:`) is its
preceded with the `static` keyword. After a colon (`:`) is its `data type`. It `data type`. It may then optionally be followed by an equal sign (`=`) and a
may then optionally be followed by an equal sign (`=`) and a `literal`. `literal`.
#### enum #### enum
A `enum` begins with the `enum` keyword, which may optionally be preceded with A `enum` begins with the `enum` keyword. It then has its `identifier` followed
the `pub` keyword. It then has its `identifier` followed by a comma (`,`) by a comma (`,`) separated list enclosed in curly braces (`{` and `}`) of
separated list enclosed in curly braces (`{` and `}`) of *enum members*. *enum members*.
##### Enum Member ##### Enum Member
@ -222,12 +222,11 @@ followed by an equal sign (`=`) and a `number literal`.
#### Function #### Function
A `function` begins with the `fn` keyword, which may optionally be preceded A `function` begins with the `fn` keyword. It then has its `identifier` followed
with the `pub` keyword. It then has its `identifier` followed by a comma (`,`) by a comma (`,`) separated list enclosed in parentheses (`(` and `)`) of
separated list enclosed in parentheses (`(` and `)`) of *function parameters*. *function parameters*. After that is an arrow (`->`) followed by a `data type`
After that is an arrow (`->`) followed by a `data type` denoting the function's denoting the function's return type. After that is a list enclosed in curly
return type. After that is a list enclosed in curly braces (`{` and `}`) of braces (`{` and `}`) of `statements`.
`statements`.
##### Function Parameter ##### Function Parameter
@ -456,7 +455,3 @@ that is apart of `pytd12dk`.
| `ytd12nc` (b) | `ytd12nc` (a) | `pytd12dk` | | `ytd12nc` (b) | `ytd12nc` (a) | `pytd12dk` |
| `ytd12nc` (c) | `ytd12nc` (b) | `ytd12nc` (a) | | `ytd12nc` (c) | `ytd12nc` (b) | `ytd12nc` (a) |
| `ytd12nc` (d) | `ytd12nc` (c) | `ytd12nc` (b) | | `ytd12nc` (d) | `ytd12nc` (c) | `ytd12nc` (b) |
# TODO / Ideas
Remove `pub` keyword.

View File

@ -50,11 +50,11 @@ _ID_Start = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "_"
_ID_Continue = _ID_Start + "0123456789" _ID_Continue = _ID_Start + "0123456789"
_Keywords = ( _Keywords = (
'struct', 'fn', 'enum', 'static', 'struct', 'fn', 'enum', 'static',
'if', 'else', 'do', 'while', 'if', 'else', 'do', 'while',
'for', 'pub', 'let', 'break', 'for', 'let', 'break', 'continue',
'continue', 'True', 'False', 'None', 'unsigned', 'int', 'fixed', 'float',
'unsigned', 'int', 'fixed', 'float', 'True', 'False', 'None',
) )
_Num_Start = "0123456789" _Num_Start = "0123456789"

View File

@ -535,7 +535,6 @@ class FunctionParameter:
class FunctionBlock: class FunctionBlock:
_identifier: Identifier _identifier: Identifier
_public: bool
_args: list[FunctionParameter] _args: list[FunctionParameter]
_return_type: DataType _return_type: DataType
_code: list[Statement] _code: list[Statement]
@ -543,13 +542,11 @@ class FunctionBlock:
def __init__( def __init__(
self, self,
identifier: Identifier, identifier: Identifier,
public: bool,
args: list[FunctionParameter], args: list[FunctionParameter],
return_type: DataType, return_type: DataType,
code: list[Statement], code: list[Statement],
): ):
self._identifier = identifier self._identifier = identifier
self._public = public
self._args = args[:] self._args = args[:]
self._return_type = return_type self._return_type = return_type
self._code = code[:] self._code = code[:]
@ -572,17 +569,14 @@ class EnumMember:
class EnumBlock: class EnumBlock:
_identifier: Identifier _identifier: Identifier
_public: bool
_members: list[EnumMember] _members: list[EnumMember]
def __init__( def __init__(
self, self,
identifier: Identifier, identifier: Identifier,
public: bool,
members: list[EnumMember], members: list[EnumMember],
): ):
self._identifier = identifier self._identifier = identifier
self._public = public
self._members = members[:] self._members = members[:]
@ -612,17 +606,14 @@ class StructureMember:
class StructBlock: class StructBlock:
_identifier: Identifier _identifier: Identifier
_public: bool
_members: list[StructureMember] _members: list[StructureMember]
def __init__( def __init__(
self, self,
identifier: Identifier, identifier: Identifier,
public: bool,
members: list[StructureMember], members: list[StructureMember],
): ):
self._identifier = identifier self._identifier = identifier
self._public = public
self._members = members[:] self._members = members[:]
@ -704,10 +695,7 @@ def _literal_map(literal: (
elif isinstance(literal, lexer.StringLiteral): elif isinstance(literal, lexer.StringLiteral):
return StringLiteral(literal.value) return StringLiteral(literal.value)
def struct_syntactical_analyzer( def struct_syntactical_analyzer(tokens: list[lexer.Token]) -> StructBlock:
tokens: list[lexer.Token],
public: bool,
) -> StructBlock:
identifier = tokens.pop(0) identifier = tokens.pop(0)
_assert_token(ExpectedIdentifier, identifier) _assert_token(ExpectedIdentifier, identifier)
temp = tokens.pop(0) temp = tokens.pop(0)
@ -761,18 +749,12 @@ def struct_syntactical_analyzer(
StructureMember(member_id, data_type, pointer, static, literal)) StructureMember(member_id, data_type, pointer, static, literal))
else: else:
raise UnexpectedToken(temp, ["Keyword", "Identifier"]) raise UnexpectedToken(temp, ["Keyword", "Identifier"])
return StructBlock(Identifier(identifier.value), public, members) return StructBlock(Identifier(identifier.value), members)
def enumeration_syntactical_analyzer( def enumeration_syntactical_analyzer(tokens: list[lexer.Token]) -> EnumBlock:
tokens: list[lexer.Token],
public: bool,
) -> EnumBlock:
pass pass
def function_syntactical_analyzer( def function_syntactical_analyzer(tokens: list[lexer.Token]) -> FunctionBlock:
tokens: list[lexer.Token],
public: bool,
) -> FunctionBlock:
pass pass
def file_syntactical_analyzer(tokens: list[lexer.Token]) -> File: 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): if isinstance(token, lexer.Directive):
children.append(Directive(token.value)) children.append(Directive(token.value))
elif isinstance(token, lexer.Keyword): elif isinstance(token, lexer.Keyword):
public = False match token.value:
while True: case 'struct':
match token.value: children.append(
case 'pub': struct_syntactical_analyzer(tokens))
token = tokens.pop(0) case 'enum':
_assert_token(ExpectedKeyword, token) children.append(
public = True enumeration_syntactical_analyzer(tokens))
continue case 'fn':
case 'struct': children.append(
children.append( function_syntactical_analyzer(tokens))
struct_syntactical_analyzer(tokens, public)) case _:
case 'enum': raise ExpectedKeyword(token, "struct', 'enum', or 'fn")
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
return File(children) return File(children)