Skip to content

Commit

Permalink
Merge branch 'master' into #150-Modify-Correct-Parser-Code
Browse files Browse the repository at this point in the history
  • Loading branch information
schmouk committed Feb 4, 2019
2 parents f04ae86 + 37a2662 commit 63e2293
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Language-specifications/typee_specs_LL1-v9-1.grm
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ SOFTWARE.
| '>>>' <expression> <file endianness'>
| EPS

<file flushing> ::= '!' <dotted name> <file flushing'>
<file flushing> ::= '!' <dotted.name> <file flushing'>
<file flushing'> ::= '(' <expression> <file flushing''> ')'
| '[' <expression> ']' '=' <expression>
| '>>' <expression>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,21 +200,26 @@ get when it is starting to parse a new statement.

The root rule of __Typee__ language reads this way:
```
<code file> ::= <statements list> <ENDOFFILE>
<code file> ::= <statements list> <ENDOFFILE>
```
with `<statements list>` specified as:
```
<statements list> ::= <empty statement> <statements list>
| <compound statement> <statements list>
| <simple statement> <statements list>
| <statements block> <statements list>
| EPS
<statements list> ::= <empty statement> <statements list>
| <compound statement> <statements list>
| <simple statement> <statements list>
| <statements block> <statements list>
| EPS
```
and `<statements block>` recursively specified as:
and with `<statements block>` recursively specified as:
```
<statements block> ::= '{' <statements list> '}' | ...
<statements block> ::= '{' <statements list> '}' | ...
```

Each time the __Parser__ starts parsing grammar rule `<statements list>`, it
appends a new ___statement node___to the _syntaxic tree_, (i.e. the tree that
contains the _syntaxic intermediate code_). The structure of a ___statement
node___ is described in next subsection.



#### 2.2.2 Syntaxic Nodes structure
Expand Down
28 changes: 23 additions & 5 deletions src/FrontEnd/Errors/fe_syntax_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class FESyntaxErrors:
CASTING_PARCL = 'missing ) at end of scalar type casting clause, leads to unpaired (',
CASTING_PAROP = 'missing ( in scalar type casting clause',
CLASS_BODY = 'missing class definition after class clause',
CLASS_NAME = 'missing class name after keyword class',
CLASS_NAME = 'missing or badly formed class name after keyword class',
COMP_EXPR = 'missing or badly formed expression after comparison operator',
CONST_TYPE = 'missing or badly formed type identifier after keyword "const"',
CONTAINED_TYPE = 'missing type specification after < in contained type definition',
Expand Down Expand Up @@ -99,8 +99,16 @@ class FESyntaxErrors:
END_OF_FILE = 'missing end-of-file marker by end of code file',
ENSURE_COMMA_EXPR = 'missing or badly formed expression after , in ensure clause',
ENSURE_EXPR = 'missing or badly formed conditional expression after keyword "ensure"',
ENUM_BRACKET_CL = 'missing "}" at end of enumeration definition',
ENUM_BRACKET_OP = 'missing "{" at beginning of enumeration definition',
ENUM_EXPR = 'missing or badly formed expression in enumeration definition',
ENUM_IDENT = 'missing or badly formed identifier after keyword "enum"',
ENUM_LIST = 'missing or badly formed enumeration values list',
ENUM_LIST_ITEM = 'missing or badly formed enumeration item after "," in enumeration definition',
EXCEPT_EXPR_BEGIN = 'missing ( after keyword "except" in try-except instruction',
EXCEPT_EXPR_END = 'missing ) at end of except clause in try-except instruction, leads to unpaired (',
EXCLUDE_EMBED = 'missing embedded code in exclude clause',
EXCLUDE_LANGS = 'missing or badly formed targeted languages list in exclude clause',
EXPR_FOR_COMPREHENSION = 'missing keyword for after expression in comprehension clause',

FILE_ENDIAN_EXPR = 'missing or badly formed expression after file identifier while specifying endianness',
Expand All @@ -119,7 +127,7 @@ class FESyntaxErrors:
FOR_COMPR_CONDITION = 'missing or badly formed condition after keyword "if" in for-comprehension clause',
FOR_COMPR_IN = 'missing keyword "in" after identifier(s) in for-comprehension clause',
FOR_COMPR_TARGETS = 'missing or badly formed identifier after keyword "for" in for-comprehension clause',
FOR_ELSE_BODY = 'missing instruction or block of instructions after keyword "else" in for instruction',
FOR_ELSE_BODY = 'missing instruction or block of instructions after keyword "otherwise" in for instruction',
FOR_EXPR = 'missing expression(s) after keyword "in" in for instruction',
FOR_IN = 'missing keyword "in" after identifier(s) in for instruction',
FOR_PARCL = 'missing ) at end of for clause in for clause, leads to unpaired (',
Expand All @@ -128,6 +136,13 @@ class FESyntaxErrors:
FOREVER_BODY = 'missing instruction or block of instructions after forever clause in forever instruction',
FOREVER_PARCL = 'missing ) at end of forever clause, leads to unpaired (',
FOREVER_PAROP = 'missing ( after keyword "forever"',
FORWARD_DECL = 'missing or badly formed declaration after keyword "forward"',
FORWARD_DECL_CONSTR = 'missing or badly formed constructor declaration after keyword "forward"',
FORWARD_DECL_FUNC_VAR_OP = 'missing or badly formed declaration of function, variable or operator in forward clause',
FORWARD_FUNC_VAR_DECL = 'missing or badly formed function or variable declaration after keyword "forward"',
FORWARD_STATIC_DECL = 'missing or badly formed declaration after keyword "static"',
FORWARD_TYPE_DECL = 'missing or badly formed type declaration after keyword "forward"',
FORWARD_VARS_LIST = 'missing or badly formed identifier in variables list in forward clause',
FROM_IDENT_IMPORT = 'missing or badly formed module identifier after keyword "from" in from-import instruction',
FROM_IMPORT = 'missing keyword "import" after module identifier in from-import instruction',
FROM_IMPORT_IDENT = 'missing expected keyword "all" or expected ( or expected identifier after keyword "import" in from-import instruction',
Expand Down Expand Up @@ -155,6 +170,7 @@ class FESyntaxErrors:
INHERITANCE_CLASS = 'missing or badly formed class name in class inheritance specification',
INSTANCE_OF = 'missing or badly formed class name after operator "->"',

LANGUAGES_LIST = 'badly formed list of embedded languages',
LIST_COMMA_EXPR = 'missing or badly formed expression after , in list of expressions',
LIST_COMMA_IDENT = 'missing or badly formed identifier after , in list of expressions',
LIST_END = 'missing ] at end of list specification, leads to unpaired [',
Expand All @@ -178,6 +194,7 @@ class FESyntaxErrors:

PARENTH_EXPR = 'missing or badly formed expression in parenthesis-form clause',
POWER_EXPR = 'missing or badly formed expression after power operator',
PROTECTION_DECL_DEF = 'missing or badly formed declaration/definition after a protection access qualifier',

RAISE_EXPR = 'missing or badly formed expression after keyword "raise" in raise instruction',
RAISE_FROM_EXPR = 'missing or badly formed expression after keyword "from" in raise instruction',
Expand All @@ -198,7 +215,7 @@ class FESyntaxErrors:
SUBCSR_SLICE_END = 'missing ] at end of subscription or slicing specification, leads to unpaired [',
SWITCH_BODY_BEGIN = 'missing { after switch clause and before block of case clauses in switch instruction',
SWITCH_BODY_END = 'missing } at end of case clauses in switch instruction, leads to unpaired {',
SWITCH_ELSE_BODY = 'missing instruction or instructions block after keyword "else" of switch statement',
SWITCH_ELSE_BODY = 'missing instruction or instructions block after keyword "otherwise" of switch statement',
SWITCH_EXPR = 'missing or badly formed expression after ( in switch instruction',
SWITCH_EXPR_BEGIN = 'missing ( after keyword "switch" in switch instruction',
SWITCH_EXPR_END = 'missing ) at end of switch clause in switch instruction, leads to unpaired (',
Expand All @@ -219,8 +236,9 @@ class FESyntaxErrors:
TEMPLATE_TYPES_LIST = 'missing or badly formed expression or type identifier within types-and-expressions list in template specification',
TRY_AS_IDENT = 'missing or badly formed identifier after keyword "as" in except clause',
TRY_BODY = 'missing instruction or instructions block after keyword "try"',
TRY_ELSE_BODY = 'missing instruction or instructions block after keyword "else" in try-except instruction',
TRY_ELSE_BODY = 'missing instruction or instructions block after keyword "otherwise" in try-except instruction',
TRY_EXCEPT_BODY = 'missing instruction or instructions block after except clause in try-except instruction',
TRY_EXCEPTS = 'missing or badly formed except clauses in try-except instruction',
TRY_FINALLY_BODY = 'missing instruction or instructions block after keyword "finally" in try-except instruction',
TYPE_ALIAS = 'missing or badly formed type identifier after keyword "type" in type alias instruction',
TYPE_AS = 'missing keyword "as" after type identifier in type alias instruction',
Expand Down Expand Up @@ -250,7 +268,7 @@ class FESyntaxErrors:
WHILE_COND = 'missing or badly formed conditional expression after ( in while clause',
WHILE_COND_BEGIN = 'missing ( after keyword "while"',
WHILE_COND_END = 'missing ) at end of conditional expression in while clause, leads to unpaired (',
WHILE_ELSE_BODY = 'missing instruction or instructions block after keyword "else" in while instruction',
WHILE_ELSE_BODY = 'missing instruction or instructions block after keyword "otherwise" in while instruction',
WITH_AS_IDENT = 'missing or badly formed identifier after keyword "as" in with clause',
WITH_BODY = 'missing instruction or instructions block after with clause in with instruction',
WITH_EXPR = 'missing or badly formed expression after keyword "with"',
Expand Down
7 changes: 7 additions & 0 deletions src/FrontEnd/IntermediateCode/fe_icode_token_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ def is_EQ(self) -> bool:
def is_EXCEPT(self) -> bool:
return self.tk_ident == FEICodeTokens.TK_EXCEPT
@property
def is_EXCL(self) -> bool:
return self.tk_ident == FEICodeTokens.TK_EXCL
@property
def is_EXCLUDE(self) -> bool:
return self.tk_ident == FEICodeTokens.TK_EXCLUDE
@property
Expand Down Expand Up @@ -723,6 +726,10 @@ class ICTokenNode_EXCEPT( FEICodeTokenNode ):
def __init__(self, scanner=None, data='except'):
super().__init__( scanner, FEICodeTokens.TK_EXCEPT, data )

class ICTokenNode_EXCL( FEICodeTokenNode ):
def __init__(self, scanner=None, data='!'):
super().__init__( scanner, FEICodeTokens.TK_EXCL, data )

class ICTokenNode_EXCLUDE( FEICodeTokenNode ):
def __init__(self, scanner=None, data='exclude'):
super().__init__( scanner, FEICodeTokens.TK_EXCLUDE, data )
Expand Down
2 changes: 2 additions & 0 deletions src/FrontEnd/IntermediateCode/fe_icode_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class FEICodeTokens:
TK_MOD = 0
TK_POWER = 0
TK_TILD = 0
TK_EXCL = 0

TK_BITAND = 0
TK_BITOR = 0
Expand Down Expand Up @@ -242,6 +243,7 @@ class FEICodeTokensData:
FEICodeTokens._TOKEN_NAMES[ FEICodeTokens.TK_MOD ] : '%',
FEICodeTokens._TOKEN_NAMES[ FEICodeTokens.TK_POWER ] : '^^',
FEICodeTokens._TOKEN_NAMES[ FEICodeTokens.TK_TILD ] : '~',
FEICodeTokens._TOKEN_NAMES[ FEICodeTokens.TK_EXCL ] : '!',

FEICodeTokens._TOKEN_NAMES[ FEICodeTokens.TK_BITAND ] : '&',
FEICodeTokens._TOKEN_NAMES[ FEICodeTokens.TK_BITOR ] : '|',
Expand Down
11 changes: 7 additions & 4 deletions src/FrontEnd/Scanner/fe_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ def _escaped_char(self):
elif self._current == '0':
self._next_char()
if self._current in "xX":
self._check_escaped_char( 4, FEScanner._HEXA_CHARS )
self._check_escaped_char( 2, FEScanner._HEXA_CHARS )
if self._current in FEScanner._HEXA_CHARS:
self._check_escaped_char( 2, FEScanner._HEXA_CHARS )
elif self._current == '0':
self._check_escaped_char( 3, FEScanner._OCTAL_CHARS )
else:
Expand Down Expand Up @@ -448,7 +450,7 @@ def _excl(self):
if self._current == '!':
self._check_augmented_operator( ICTokenNode_OP_2EXCL, ICTokenNode_AUG_2EXCL, '!!' )
else:
self._check_augmented_operator( ICTokenNode_UNEXPECTED, ICTokenNode_NE, '!', False )
self._check_augmented_operator( ICTokenNode_EXCL, ICTokenNode_NE, '!', False )
#-------------------------------------------------------------------------
def _greater(self):
self._next_char()
Expand Down Expand Up @@ -580,8 +582,8 @@ def _eof(self): return self.idx >= self.len_code
_NAME_ALPHA_CHARS = _ALPHA_CHARS + '_'
_NAME_CHARS = _ALPHA_NUM_CHARS + '_'
_DOTTED_NAME_CHARS = _NAME_CHARS + '.'
_BIN_CHARS = _NUM_CHARS[:2] + '_'
_OCTAL_CHARS = _NUM_CHARS[:8] + '_'
_BIN_CHARS = _NUM_CHARS[:2] ## + '_'
_OCTAL_CHARS = _NUM_CHARS[:8] ## + '_'
_HEXA_CHARS = _NUM_CHARS + "ABCDEFabcdef"
_SPACE = " \t"
_STRING_START = "'\""
Expand Down Expand Up @@ -692,6 +694,7 @@ def _eof(self): return self.idx >= self.len_code
'ret': ICTokenNode_RETURN,
'return': ICTokenNode_RETURN,
'set': ICTokenNode_SET,
'slice': ICTokenNode_SCALAR_TYPE,
'static': ICTokenNode_STATIC,
'str': ICTokenNode_SCALAR_TYPE,
'str16': ICTokenNode_SCALAR_TYPE,
Expand Down

0 comments on commit 63e2293

Please sign in to comment.