Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
minichamo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nathan PERIER
minichamo
Commits
8c54243c
Commit
8c54243c
authored
3 years ago
by
Nathan PERIER
Browse files
Options
Downloads
Patches
Plain Diff
Beginning of the parsing for assignations
parent
fd8a8dd9
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/fr/insarennes/nperier/minichamo/parsing/AssignationParser.java
+83
-0
83 additions, 0 deletions
...sarennes/nperier/minichamo/parsing/AssignationParser.java
with
83 additions
and
0 deletions
src/fr/insarennes/nperier/minichamo/parsing/AssignationParser.java
0 → 100644
+
83
−
0
View file @
8c54243c
package
fr.insarennes.nperier.minichamo.parsing
;
import
fr.insarennes.nperier.minichamo.language.assignement.param.AssignementParam
;
import
fr.insarennes.nperier.minichamo.language.assignement.param.NupleParam
;
import
fr.insarennes.nperier.minichamo.language.assignement.param.VarParam
;
import
fr.insarennes.nperier.minichamo.language.typing.Type
;
import
fr.insarennes.nperier.minichamo.lexing.tokens.NameToken
;
import
fr.insarennes.nperier.minichamo.lexing.tokens.TokenType
;
import
fr.insarennes.nperier.minichamo.utils.ParsingException
;
import
fr.insarennes.nperier.minichamo.utils.TokenPeekIterator
;
public
class
AssignationParser
{
public
void
parse
(
TokenPeekIterator
it
,
Context
ctx
)
{
if
(
it
.
junkIf
(
TokenType
.
REC
))
{
parseRecursiveFunction
(
it
,
ctx
);
return
;
}
if
(
it
.
peekIs
(
TokenType
.
NAME
))
{
String
name
=
((
NameToken
)
it
.
next
()).
getName
();
if
(
it
.
peekIs
(
TokenType
.
NAME
)
||
it
.
peekIs
(
TokenType
.
LPAREN
))
{
parseFunctionDef
(
it
,
ctx
,
name
,
false
);
return
;
}
}
}
public
void
parseRecursiveFunction
(
TokenPeekIterator
it
,
Context
ctx
)
{
if
(!
it
.
peekIs
(
TokenType
.
NAME
))
{
throw
new
ParsingException
(
"Expected identifier"
,
it
.
peek
());
}
String
name
=
((
NameToken
)
it
.
next
()).
getName
();
parseFunctionDef
(
it
,
ctx
,
name
,
true
);
}
public
void
parseFunctionDef
(
TokenPeekIterator
it
,
Context
ctx
,
String
name
,
boolean
recursive
)
{
}
public
AssignementParam
parseInParen
(
TokenPeekIterator
it
,
Context
ctx
)
{
AssignementParam
res
;
if
(
it
.
junkIf
(
TokenType
.
LPAREN
))
{
res
=
parseInParen
(
it
,
ctx
);
}
else
{
if
(!
it
.
peekIs
(
TokenType
.
NAME
))
{
throw
new
ParsingException
(
"Expected identifier"
,
it
.
peek
());
}
String
name
=
((
NameToken
)
it
.
next
()).
getName
();
if
(
it
.
peekIs
(
TokenType
.
COLON
))
{
res
=
parseVariableDef
(
it
,
ctx
,
name
);
if
(!
it
.
junkIf
(
TokenType
.
RPAREN
))
{
throw
new
ParsingException
(
"Expected closing parenthesis"
,
it
.
peek
());
}
return
res
;
}
res
=
null
;
// TODO
}
if
(
it
.
peekIs
(
TokenType
.
COMMA
))
{
res
=
parseNupleDef
(
it
,
ctx
,
res
);
}
if
(!
it
.
junkIf
(
TokenType
.
RPAREN
))
{
throw
new
ParsingException
(
"Expected closing parenthesis"
,
it
.
peek
());
}
return
res
;
}
public
AssignementParam
parseVariableDef
(
TokenPeekIterator
it
,
Context
ctx
,
String
name
)
{
if
(
it
.
junkIf
(
TokenType
.
COLON
))
{
Type
t
=
TypeParser
.
parse
(
it
,
ctx
);
return
new
VarParam
(
name
,
t
);
}
return
null
;
}
public
AssignementParam
parseNupleDef
(
TokenPeekIterator
it
,
Context
ctx
,
AssignementParam
first
)
{
NupleParam
res
=
new
NupleParam
();
res
.
addParam
(
first
);
// TODO do ... while it.peekIs(...)
return
res
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment