Skip to content
Snippets Groups Projects
Commit 8c54243c authored by Nathan PERIER's avatar Nathan PERIER
Browse files

Beginning of the parsing for assignations

parent fd8a8dd9
No related branches found
No related tags found
No related merge requests found
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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment