private AST_variable_declaration Parse_variable_declaration() { IncrementDepth(); AST_variable_declaration variable_declaration; AST_identifier name; AST_type type = null; AST_expression expression = null; Match(var_Keyword); name = Parse_identifier(Colon | Semicolon); if (!Match(Colon)) { Error("':' expected.", lastReadToken); SkipUntilFollow(Semicolon); } else { type = Parse_type(Assignment | Semicolon); switch (LookAheadToken().Kind) { case Assignment: Match(Assignment); expression = Parse_expression(Semicolon); break; case Semicolon: break; default: Error("':=' or ';' expected.", LookAheadToken()); SkipUntilFollow(Semicolon); break; } } variable_declaration = new AST_variable_declaration(name, type, expression); DecrementDepth(); return(variable_declaration); }
private AST_type Parse_type(TokenKind followSet) { IncrementDepth(); AST_type type; Token t = GetNextToken(); switch (t.Kind) { case int_Keyword: DebugPrint("type int"); type = new AST_type(int_type); break; case string_Keyword: DebugPrint("type string"); type = new AST_type(string_type); break; case bool_Keyword: DebugPrint("type bool"); type = new AST_type(bool_type); break; default: Error("Type expected.", t); SkipUntilFollow(followSet); type = new AST_type(bool_type); break; } DecrementDepth(); type.Row = t.Row; type.Column = t.Column; return(type); }
public virtual void Visit(AST_type type) { }
override public void Visit(AST_type type) { base.Visit(type); }