Skip to content

Commit

Permalink
Merge pull request #239 from Typee-Language/dev
Browse files Browse the repository at this point in the history
#150 - Correct/Modify Parser Code
  • Loading branch information
schmouk committed Aug 25, 2019
2 parents 447b12f + 76eb690 commit 1875c0d
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 94 deletions.
2 changes: 1 addition & 1 deletion Language-specifications/typee_specs_LL1-v10.grm
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ SOFTWARE.
<atom element''> ::= <scalar type> <type casting> ## modified
<atom element'''> ::= ##<dotted name'> <atom element'''> ## suppressed
| <function call> <atom element''''> ## modified
| <subscription or slicing> <atom element''''> ## modified
| <is instance of>
| <subscription or slicing> <atom element''''> ## modified
| EPS
<atom element''''> ::= <dotted name'> <atom element'''> ## new
| <atom element'''> ## new
Expand Down
1 change: 1 addition & 0 deletions src/FrontEnd/Errors/fe_syntax_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ class FESyntaxErrors:
NOT_COND = 'missing or badly formed condition expression after keyword "not"',
NOT_IN = 'missing keyword "in" after keyword "not"',

OP_2QUEST_EXPR = 'mising or badly formed expression after keyword "??"',
OP_IDENT_DECL_DEF = 'missing keyword operator in definition instruction or badly formed identifier in declaration instruction',
OPERATOR_ARGS = 'missing or badly formed arguments specification in operator definition',
OPERATOR_BODY = 'missing instruction or block of instructions in operator definition',
Expand Down
10 changes: 1 addition & 9 deletions src/FrontEnd/IntermediateCode/fe_icode_token_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
"""

#=============================================================================
# no import.
## THIS FILE HAS BEEN AUTOMATICALLY GENERATED BY Typee FRAMEWORK.
## DO NOT MODIFY IT: ANY MODIFICATION WOULD BE LOST ON NEXT SCRIPTED GENERATION.
## Last modification version: 201908-242358-45943U
## Last modification version: 201908-251133-48666P


#=============================================================================
Expand Down Expand Up @@ -361,9 +360,6 @@ def is_NOP(self) -> bool:
def is_NOT(self) -> bool:
return self.tk_ident == FEICodeTokens.TK_NOT
@property
def is_NUMERIC(self) -> bool:
return self.tk_ident == FEICodeTokens.TK_NUMERIC
@property
def is_OPERATOR(self) -> bool:
return self.tk_ident == FEICodeTokens.TK_OPERATOR
@property
Expand Down Expand Up @@ -916,10 +912,6 @@ class ICTokenNode_NOT( FEICodeTokenNode ):
def __init__(self, scanner=None, data='not'):
super().__init__( scanner, FEICodeTokens.TK_NOT, data )

class ICTokenNode_NUMERIC( FEICodeTokenNode ):
def __init__(self, scanner=None, data='None'):
super().__init__( scanner, FEICodeTokens.TK_NUMERIC, data )

class ICTokenNode_OPERATOR( FEICodeTokenNode ):
def __init__(self, scanner=None, data='operator'):
super().__init__( scanner, FEICodeTokens.TK_OPERATOR, data )
Expand Down
2 changes: 0 additions & 2 deletions src/FrontEnd/IntermediateCode/fe_icode_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ class FEICodeTokens:

TK_INTEGER = 0
TK_FLOAT = 0
TK_NUMERIC = 0 ##
TK_STRING = 0
TK_ANY_TYPE = 0
TK_SCALAR_TYPE = 0
Expand Down Expand Up @@ -323,7 +322,6 @@ class FEICodeTokensData:

FEICodeTokens._TOKEN_NAMES[ FEICodeTokens.TK_INTEGER ] : None,
FEICodeTokens._TOKEN_NAMES[ FEICodeTokens.TK_FLOAT ] : None,
FEICodeTokens._TOKEN_NAMES[ FEICodeTokens.TK_NUMERIC ] : None,
FEICodeTokens._TOKEN_NAMES[ FEICodeTokens.TK_STRING ] : None,
FEICodeTokens._TOKEN_NAMES[ FEICodeTokens.TK_ANY_TYPE ] : '?',
FEICodeTokens._TOKEN_NAMES[ FEICodeTokens.TK_SCALAR_TYPE ] : None,
Expand Down
195 changes: 114 additions & 81 deletions src/FrontEnd/Parser/fe_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ def _atom(self) -> bool:
# | <reference>
# | <scalar>
# | <string>
# | <boolean>
#=======================================================================
if self._decr():
if not self._dotted_name():
Expand All @@ -305,27 +306,48 @@ def atom1(self) -> bool:
#=======================================================================
# <atom'> ::= <incr or decr>
# | <for comprehension>
# | '??' <expression> <atom''>
#=======================================================================
return self._for_comprehension() or self._incr_or_decr()
## CAUTION: this order of calls is MANDATORY

if self._current.is_OP_2QUEST():
self._append_syntaxic_node()
self._next_token_node()
if not self._expression():
self._append_error( FESyntaxErrors.OP_2QUEST_EXPR )
return self._atom2()
else:
return self._for_comprehension() or self._incr_or_decr()
## CAUTION: this order of calls is MANDATORY

#-------------------------------------------------------------------------
def atom2(self) -> bool:
#=======================================================================
# <atom''> ::= '??' <expression> <atom''>
# | EPS
#=======================================================================
while self._current.is_OP_2QUEST():
self._append_syntaxic_node()
self._next_token_node()
if not self._expression():
self._append_error( FESyntaxErrors.OP_2QUEST_EXPR )
return True

#-------------------------------------------------------------------------
def _atom_element(self) -> bool:
#===============================================================================
# <atom element> ::= <atom>
# | <dotted name> <atom element'>
# | <const qualifier> <atom element'''>
# | <atom element'''>
# | <const qualifier> <atom element''>
# | <atom element''>
#===============================================================================
if self._atom():
return True
elif self._dotted_name():
return self._atom_element1()
elif self._const_qualifier():
if not self._atom_element3():
if not self._atom_element2():
self._append_error( FESyntaxErrors.SCALAR_TYPE )
return True
elif self._atom_element3():
elif self._atom_element2():
return True
else:
return False
Expand All @@ -334,40 +356,36 @@ def _atom_element(self) -> bool:
def _atom_element1(self) -> bool:
#=======================================================================
# <atom element'> ::= <atom'>
# | <atom element''>
# | <atom element'''>
#=======================================================================
return self._atom1() or self._atom_element2()
return self._atom1() or self._atom_element3()

#-------------------------------------------------------------------------
def _atom_element2(self) -> bool:
#=======================================================================
# <atom element'' > ::= <dotted name'> <atom element''>
# | <function call> <atom element''>
# | <is instance of>
# | <scalar type casting>
# | <subscription or slicing> <atom element''>
# | EPS
# <atom element''> ::= <scalar type> <scalar type casting>
#=======================================================================
while self._dotted_name1() or \
self._function_call() or \
self._subscription_or_slicing():
continue
if self._is_instance_of() or self._scalar_type_casting():
if self._scalar_type():
if not self._type_casting():
self._append_error( FESyntaxErrors.CASTING_PAROP )
return True
else:
return True
return False

#-------------------------------------------------------------------------
def _atom_element3(self) -> bool:
#=======================================================================
# <atom element'''> ::= <scalar type> <scalar type casting>
# <atom element'''> ::= <function call> <atom element''''>
# | <is instance of>
# | <subscription or slicing> <atom element''''>
# | EPS
#=======================================================================
if self._scalar_type():
if not self._scalar_type_casting():
self._append_error( FESyntaxErrors.CASTING_PAROP )
while self._function_call() or self._subscription_or_slicing():
continue
if self._is_instance_of():
return True
else:
return False
return True

#-------------------------------------------------------------------------
def _augmented_assign_op(self) -> bool:
Expand All @@ -387,29 +405,39 @@ def _augmented_assign_op(self) -> bool:
# | '**='
# | '^^='
# | '@='
# | '@@='
# | '><='
# | '<>='
# | '!!='
# | '::='
# | '??='
#===============================================================================
return isinstance( self._current, (ICTokenNode_AUG_2COLN,
ICTokenNode_AUG_2EXCL,
ICTokenNode_AUG_2QUEST,
ICTokenNode_AUG_AROBASE,
ICTokenNode_AUG_BITAND,
ICTokenNode_AUG_BITOR,
ICTokenNode_AUG_BITXOR,
ICTokenNode_AUG_DIV,
ICTokenNode_AUG_GRLE,
ICTokenNode_AUG_MINUS,
ICTokenNode_AUG_MOD,
ICTokenNode_AUG_MUL,
ICTokenNode_AUG_PLUS,
ICTokenNode_AUG_POWER,
ICTokenNode_AUG_SHIFT0L,
ICTokenNode_AUG_SHIFT0R,
ICTokenNode_AUG_SHIFTL,
ICTokenNode_AUG_SHIFTR) )
if isinstance( self._current, (ICTokenNode_AUG_2AROB,
ICTokenNode_AUG_2COLN,
ICTokenNode_AUG_2EXCL,
ICTokenNode_AUG_2QUEST,
ICTokenNode_AUG_AROBASE,
ICTokenNode_AUG_BITAND,
ICTokenNode_AUG_BITOR,
ICTokenNode_AUG_BITXOR,
ICTokenNode_AUG_DIV,
ICTokenNode_AUG_GRLE,
ICTokenNode_AUG_LEGR,
ICTokenNode_AUG_MINUS,
ICTokenNode_AUG_MOD,
ICTokenNode_AUG_MUL,
ICTokenNode_AUG_PLUS,
ICTokenNode_AUG_POWER,
ICTokenNode_AUG_SHIFT0L,
ICTokenNode_AUG_SHIFT0R,
ICTokenNode_AUG_SHIFTL,
ICTokenNode_AUG_SHIFTR) ):
self._append_syntaxic_node()
self._next_token_node()
return True
else:
return False


#-------------------------------------------------------------------------
def _auto_type(self) -> bool:
Expand Down Expand Up @@ -2580,24 +2608,25 @@ def _operator(self) -> bool:
#=======================================================================
# <operator> ::= '<=' | '==' | '!=' | '>='
# | '+' | '-' | '*' | '/' | '%' | '**' | '^^'
# | '&' | '|' | '^'
# | '@' | '><' | '!!' | '::' | '??'
# | '&' | '|' | '^' | '@'
# | '@@' | '><' | '<>' | '::' | '!!'
# | '++' | '--' | '#'
# | 'in'
# | <assign op>
# | <cast op>
#=======================================================================
if self._current.is_LE() or self._current.is_EQ() or \
self._current.is_NE() or self._current.is_GE() or \
self._current.is_PLUS() or self._current.is_MINUS() or \
self._current.is_MUL() or self._current.is_DIV() or \
self._current.is_MOD() or self._current.is_POWER() or \
self._current.is_BITAND() or self._current.is_BITOR() or \
self._current.is_BITXOR() or self._current.is_AROBASE() or \
self._current.is_OP_GRLE() or self._current.is_OP_2EXCL() or \
self._current.is_OP_2COLN() or self._current.is_OP_2QUEST() or \
self._current.is_INCR() or self._current.is_DECR() or \
self._current.is_HASH() or self._current.is_IN():
if isinstance( self._current, (ICTokenNode_LE , ICTokenNode_EQ ,
ICTokenNode_NE , ICTokenNode_GE ,
ICTokenNode_PLUS , ICTokenNode_MINUS ,
ICTokenNode_MUL , ICTokenNode_DIV ,
ICTokenNode_MOD , ICTokenNode_POWER ,
ICTokenNode_BITAND , ICTokenNode_BITOR ,
ICTokenNode_BITXOR , ICTokenNode_AROBASE ,
ICTokenNode_OP_2AROB, ICTokenNode_OP_GRLE ,
ICTokenNode_OP_LEGR , ICTokenNode_OP_2COLN,
ICTokenNode_OP_2EXCL, ICTokenNode_INCR ,
ICTokenNode_DECR , ICTokenNode_HASH ,
ICTokenNode_IN ) ):
self._append_syntaxic_node()
self._next_token_node()
return True
Expand All @@ -2613,10 +2642,10 @@ def _operator1(self) -> bool:
#=======================================================================
# <operator'> ::= '<' | '>' | '<<' | '<<<' | '>>' | '>>>' | '<=>'
#=======================================================================
if self._current.is_LT() or self._current.is_GT() or \
self._current.is_SHIFTL() or self._current.is_SHIFT0L() or \
self._current.is_SHIFTR() or self._current.is_SHIFT0R() or \
self._current.is_LEG():
if isinstance( self._current, (ICTokenNode_LT , ICTokenNode_GT ,
ICTokenNode_SHIFTL, ICTokenNode_SHIFT0L,
ICTokenNode_SHIFTR, ICTokenNode_SHIFT0R,
ICTokenNode_LEG ) ):
self._append_syntaxic_node()
self._next_token_node()
return True
Expand Down Expand Up @@ -2896,33 +2925,18 @@ def _scalar_type(self) -> bool:
# | "uint16"
# | "uint32"
# | "uint64"
# | "_float_"
# | "_int_"
# | "_numeric_"
# | "_uint_"
#=======================================================================
if self._current.is_SCALAR_TYPE(): ## (notice: previously scanned by Scanner)
if self._current.is_SCALAR_TYPE(): ## (notice: previously scanned by Front-End Scanner)
self._append_syntaxic_node()
self._next_token_node()
return True
else:
return False

#-------------------------------------------------------------------------
def _scalar_type_casting(self) -> bool:
#=======================================================================
# <scalar type casting> ::= '(' <expression> ')'
#=======================================================================
if self._current.is_PAROP():
self._append_syntaxic_node()
self._next_token_node()
if not self._expression():
self._append_error( FESyntaxErrors.CASTING_EXPR )
if self._current.is_PARCL():
self._append_syntaxic_node()
self._next_token_node()
else:
self._append_error( FESyntaxErrors.CASTING_PARCL )
return True
else:
return False

#-------------------------------------------------------------------------
def _scalar_type_or_dotted_name(self) -> bool:
#=======================================================================
Expand Down Expand Up @@ -3953,6 +3967,25 @@ def _typed_args_list1(self) -> bool:
self._append_error( FESyntaxErrors.TYPE_LIST_IDENT )
return True

#-------------------------------------------------------------------------
def _type_casting(self) -> bool:
#=======================================================================
# <scalar type casting> ::= '(' <expression> ')'
#=======================================================================
if self._current.is_PAROP():
self._append_syntaxic_node()
self._next_token_node()
if not self._expression():
self._append_error( FESyntaxErrors.CASTING_EXPR )
if self._current.is_PARCL():
self._append_syntaxic_node()
self._next_token_node()
else:
self._append_error( FESyntaxErrors.CASTING_PARCL )
return True
else:
return False

#-------------------------------------------------------------------------
def _types_list(self) -> bool:
#=======================================================================
Expand Down
2 changes: 1 addition & 1 deletion src/local_tools/tool_generate_feicode_token_node_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def milli_sec( micro_sec: int ) -> int:
return (micro_sec + 500) // 1000

#-----------------------------------------------------------------
header_length = 25 # copy only the 25 first lines of template
header_length = 24 # copy only the 25 first lines of template
with open( 'template_class.py', 'r' ) as tfp:
fp.writelines( tfp.readlines()[:header_length] )

Expand Down

0 comments on commit 1875c0d

Please sign in to comment.