private IExpression ReadArrayAccessExpression(IParseContext context, IExpression array) { context.ReadOrPanic(TokenKind.OpenSquareBracket); var indexExpression = Read(context); context.ReadOrPanic(TokenKind.CloseSquareBracket); return(new ArrayAccessExpression(array, indexExpression)); }
private IExpression ReadParanthesisExpression(IParseContext context) { context.ReadOrPanic(TokenKind.OpenParanthesis); var expression = Read(context); context.ReadOrPanic(TokenKind.CloseParanthesis); return(expression); }
private IExpression ReadTypeCastExpression(IParseContext context) { context.ReadOrPanic(TokenKind.OpenAngularBracket); var type = context.ReadNode <Type>(); context.ReadOrPanic(TokenKind.CloseAngularBracket); return(new TypeCastExpression(type, ReadShortExpression(context))); }
private IExpression ReadArrayAllocationExpression(IParseContext context) { context.ReadOrPanic(TokenKind.New); var allocationType = context.ReadNode <Type>(); context.ReadOrPanic(TokenKind.OpenParanthesis); var count = Read(context); context.ReadOrPanic(TokenKind.CloseParanthesis); return(new ArrayAllocationExpression(allocationType, count)); }
public FunctionImport Read(IParseContext context) { context.ReadOrPanic(TokenKind.Import); context.ReadOrPanic(TokenKind.OpenParanthesis); var libraryName = context.ReadOrPanic(TokenKind.StringLiteral); context.ReadOrPanic(TokenKind.CloseParanthesis); var functionDeclaration = context.ReadNode <FunctionDeclaration>(); return(new FunctionImport(libraryName, functionDeclaration)); }
public Declaration Read(IParseContext context) { var type = context.ReadNode <Type>(); var name = context.ReadOrPanic(TokenKind.Identifier); if (context.NextCodeToken.Kind == TokenKind.Assignment) { context.ReadOrPanic(TokenKind.Assignment); return(new Declaration(type, name, context.ReadNode <IExpression>())); } return(new Declaration(type, name)); }
private FunctionCallExpression ReadFunctionCallExpression(IParseContext context, IExpression called) { context.ReadOrPanic(TokenKind.OpenParanthesis); var parameters = new List <IExpression>(); while (context.NextCodeToken.Kind != TokenKind.CloseParanthesis) { parameters.Add(Read(context)); if (context.NextCodeToken.Kind == TokenKind.Comma) { context.ReadCodeToken(); } } context.ReadOrPanic(TokenKind.CloseParanthesis); return(new FunctionCallExpression(called, parameters.ToArray())); }
public FunctionDeclaration Read(IParseContext context) { var returnType = context.ReadNode <Type>(); var identifier = context.ReadOrPanic(TokenKind.Identifier); context.ReadOrPanic(TokenKind.OpenParanthesis); var parameters = new List <FunctionDeclaration.Parameter>(); while (context.NextCodeToken.Kind != TokenKind.CloseParanthesis) { var parameterType = context.ReadNode <Type>(); var parameterIdentifier = context.ReadOrPanic(TokenKind.Identifier); if (context.NextCodeToken.Kind == TokenKind.Comma) { context.ReadCodeToken(); } parameters.Add(new FunctionDeclaration.Parameter(parameterType, parameterIdentifier)); } context.ReadOrPanic(TokenKind.CloseParanthesis); return(new FunctionDeclaration(returnType, identifier, parameters.ToArray())); }
public Type Read(IParseContext context) { var type = new Type(context.ReadOrPanic(TokenKind.PrimitiveType).RawText); while (true) { switch (context.NextCodeToken.Kind) { case TokenKind.Pointer: context.ReadCodeToken(); type = new Type(type, Type.WrappingType.PointerOf); break; case TokenKind.OpenSquareBracket: context.ReadCodeToken(); context.ReadOrPanic(TokenKind.CloseSquareBracket); type = new Type(type, Type.WrappingType.ArrayOf); break; default: return(type); } } }