Skip to content

Commit

Permalink
Merge pull request #156 from Typee-Language/#150-Modify-Correct-Parse…
Browse files Browse the repository at this point in the history
…r-Code

#150-Modify-Correct Parser Code
  • Loading branch information
schmouk committed Feb 4, 2019
2 parents 37a2662 + 63e2293 commit 179a72d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
12 changes: 6 additions & 6 deletions Language-specifications/typee_specs_LL1-v9-1.grm
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,8 @@ SOFTWARE.
<simple statement> ::= <assert statement> <simple statement end>
| <del statement> <simple statement end>
| <ensure statement> <simple statement end>
| <file endianness> ##
| <file flushing> ##
| <file endianness>
| <file flushing>
| <flow statement> <simple statement end>
| <import statement> <simple statement end>
| <nop statement> <simple statement end>
Expand Down Expand Up @@ -541,7 +541,7 @@ SOFTWARE.
| <type alias> <simple statement end>
| <decl or def statement''>
<decl or def statement''> ::= <TYPE'> <decl or def statement'''>
| <enum definition> ##
| <enum definition>
| <identifier> <decl constructor or decl end>
<decl or def statement'''> ::= <identifier> <decl or def statement''''>
| <operator definition>
Expand Down Expand Up @@ -579,10 +579,10 @@ SOFTWARE.
<ensure statement'> ::= ',' <expression>
| EPS

<enum definition> ::= <enum type> <identifier> '{' <enum list> '}' ##
<enum definition> ::= <enum type> <identifier> '{' <enum list> '}'

<enum item> ::= <identifier> <enum item'> ##
<enum item'> ::= '=' <expression> ##
<enum item> ::= <identifier> <enum item'>
<enum item'> ::= '=' <expression>
| EPS

<enum list> ::= <enum item> <enum list'>
Expand Down
22 changes: 12 additions & 10 deletions src/FrontEnd/Parser/fe_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,7 @@ def _decl_or_def_statement1(self) -> bool: ###
def _decl_or_def_statement2(self) -> bool: ###
#=======================================================================
# <decl or def statement''> ::= <TYPE'> <decl or def statement'''>
# | <enum definition>
# | <identifier> <decl constructor or decl end>
#=======================================================================
if self._TYPE1():
Expand All @@ -878,6 +879,8 @@ def _decl_or_def_statement2(self) -> bool: ###
if not self._decl_constructor_or_decl_end():
self._append_error( FESyntaxErrors.DECL_DEF_TYPE )
return True
elif self._enum_definition():
return True
else:
self._append_error( FESyntaxErrors.VAR_TYPE )
return False
Expand Down Expand Up @@ -1206,7 +1209,7 @@ def _enum_definition(self) -> bool:
if self._current.is_ENUM():
self._append_syntaxic_node()
self._next_token_node()
if self._current.is_IDENT:
if self._current.is_IDENT():
self._append_syntaxic_node()
self._next_token_node()
else:
Expand All @@ -1216,12 +1219,9 @@ def _enum_definition(self) -> bool:
self._next_token_node()
else:
self._append_error( FESyntaxErrors.ENUM_BRACKET_OP )
if self._enum_list():
self._append_syntaxic_node()
self._next_token_node()
else:
if not self._enum_list():
self._append_error( FESyntaxErrors.ENUM_LIST )
if self._current.is_BRACKETCL:
if self._current.is_BRACKETCL():
self._append_syntaxic_node()
self._next_token_node()
else:
Expand Down Expand Up @@ -1413,7 +1413,7 @@ def _file_endianness1(self) -> bool:
return True

#-------------------------------------------------------------------------
def file_flushing(self) -> bool:
def _file_flushing(self) -> bool:
#=======================================================================
# <file flushing> ::= '!' <dotted name> <file flushing'>
#=======================================================================
Expand All @@ -1428,7 +1428,7 @@ def file_flushing(self) -> bool:
return False

#-------------------------------------------------------------------------
def file_flushing1(self) -> bool:
def _file_flushing1(self) -> bool:
#=======================================================================
# <file flushing'> ::= '(' <expression> <file flushing''> ')'
# | '[' <expression> ']' '=' <expression>
Expand Down Expand Up @@ -2935,6 +2935,8 @@ def _simple_statement(self) -> bool: ###
# <simple statement> ::= <assert statement> <simple statement end>
# | <del statement> <simple statement end>
# | <ensure statement> <simple statement end>
# | <file endianness>
# | <file flushing>
# | <flow statement> <simple statement end>
# | <import statement> <simple statement end>
# | <nop statement> <simple statement end>
Expand All @@ -2945,6 +2947,8 @@ def _simple_statement(self) -> bool: ###
if self._assert_statement() or \
self._del_statement() or \
self._ensure_statement() or \
self._file_endianness() or \
self._file_flushing() or \
self._flow_statement() or \
self._import_statement() or \
self._nop_statement() or \
Expand Down Expand Up @@ -4139,5 +4143,3 @@ def _next_token_node(self) -> FEICodeTokenNode:
return self._current

#===== end of FrontEnd.Parser.parser =====#


0 comments on commit 179a72d

Please sign in to comment.