private static bool Member_Refz() { if (Tokens.GetToken().lexeme == ".") { Tokens.NextToken(); if (Tokens.GetToken().type != Token.Type.Identifier) { SyntaxError(Tokens.GetToken(), "Identifier"); } if (semanticPass) { SemanticActions.iPush(Tokens.GetToken(), scope); } Tokens.NextToken(); Fn_Arr_Member(); if (semanticPass) { SemanticActions.rExist(); } Member_Refz(); return(true); } return(false); }
private static bool Expression() { string lexeme = Tokens.GetToken().lexeme; if (lexeme == "(") { if (semanticPass) { SemanticActions.oPush(Tokens.GetToken()); } Tokens.NextToken(); if (!Expression()) { SyntaxError(Tokens.GetToken(), "expression"); } if (Tokens.GetToken().lexeme != ")") { SyntaxError(Tokens.GetToken(), ")"); } if (semanticPass) { SemanticActions.ShuntYardAll(); } Tokens.NextToken(); Expressionz(); return(true); } else if (lexeme == "+" || lexeme == "-" || lexeme == "true" || lexeme == "false" || lexeme == "null" || lexeme == "this" || Tokens.GetToken().type == Token.Type.Number || Tokens.GetToken().type == Token.Type.Character) { if (Tokens.GetToken().lexeme == "this") { if (semanticPass) { SemanticActions.iPush(Tokens.GetToken(), scope); SemanticActions.iExist(); } Tokens.NextToken(); Member_Refz(); Expressionz(); return(true); } else if (lexeme == "true" || lexeme == "false" || lexeme == "null") { string[] data = new string[2]; data[0] = "returnType:bool"; data[1] = "accessMod:public"; Symbol symbol; if (lexeme == "true") { symbol = new Symbol("g", ("Btrue"), "1", "blit", data); } else if (lexeme == "false") { symbol = new Symbol("g", ("Bfalse"), "0", "blit", data); } else { data[0] = "returnType:null"; symbol = new Symbol("g", "null", "2018", "null", data); } SymbolTable.Add(symbol); if (semanticPass) { SemanticActions.lPush(symbol, Tokens.GetToken(), scope); } Tokens.NextToken(); Expressionz(); return(true); } else if (numeric_literal()) { Tokens.NextToken(); Expressionz(); return(true); } else if (character_literal()) { Tokens.NextToken(); Expressionz(); return(true); } return(false); } else if (Tokens.GetToken().type == Token.Type.Identifier) { currentIdentifier = Tokens.GetToken().lexeme; if (semanticPass) { SemanticActions.iPush(Tokens.GetToken(), scope); } Tokens.NextToken(); Fn_Arr_Member(); if (semanticPass) { SemanticActions.iExist(); } Member_Refz(); Expressionz(); return(true); } return(false); }
private static bool Statement() { if (Tokens.GetToken().lexeme == "{") { Tokens.NextToken(); while (Statement()) { ; } if (Tokens.GetToken().lexeme != "}") { SyntaxError(Tokens.GetToken(), "}"); } Tokens.NextToken(); return(true); } if (Tokens.GetToken().lexeme == "if") { Tokens.NextToken(); if (Tokens.GetToken().lexeme != "(") { SyntaxError(Tokens.GetToken(), "("); } if (semanticPass) { SemanticActions.oPush(Tokens.GetToken()); } Tokens.NextToken(); if (!Expression()) { SyntaxError(Tokens.GetToken(), "an expression"); } if (Tokens.GetToken().lexeme != ")") { SyntaxError(Tokens.GetToken(), ")"); } if (semanticPass) { SemanticActions.ShuntYardAll(); SemanticActions.if_(Tokens.GetToken()); } Tokens.NextToken(); if (!Statement()) { SyntaxError(Tokens.GetToken(), "a statement"); } if (Tokens.GetToken().lexeme == "else") { Tokens.NextToken(); if (semanticPass) { string SKIPELSE = ICode.SKIPELSE + ICode.labelCounter++ + " "; ICode.JMP(SKIPELSE); ICode.StackElse(SKIPELSE); ICode.Print(ICode.StackIf()); } if (!Statement()) { SyntaxError(Tokens.GetToken(), "a statement"); } if (semanticPass) { ICode.Print(ICode.StackElse()); } } else if (semanticPass) { ICode.Print(ICode.StackIf()); } return(true); } if (Tokens.GetToken().lexeme == "while") { if (semanticPass) { string BEGIN = ICode.BEGIN + ICode.labelCounter++ + " "; ICode.Print(BEGIN); ICode.StackWhile(BEGIN); } Tokens.NextToken(); if (Tokens.GetToken().lexeme != "(") { SyntaxError(Tokens.GetToken(), "("); } if (semanticPass) { SemanticActions.oPush(Tokens.GetToken()); } Tokens.NextToken(); if (!Expression()) { SyntaxError(Tokens.GetToken(), "an expression"); } if (Tokens.GetToken().lexeme != ")") { SyntaxError(Tokens.GetToken(), ")"); } if (semanticPass) { SemanticActions.ShuntYardAll(); SemanticActions.while_(Tokens.GetToken()); } Tokens.NextToken(); if (!Statement()) { SyntaxError(Tokens.GetToken(), "a statement"); } if (semanticPass) { string BEGIN = ICode.StackWhile(); ICode.JMP(BEGIN); string ENDWHILE = ICode.StackEndWhile(); ICode.Print(ENDWHILE); } return(true); } if (Tokens.GetToken().lexeme == "return") { Tokens.NextToken(); Expression(); if (Tokens.GetToken().lexeme != ";") { SyntaxError(Tokens.GetToken(), ";"); } if (semanticPass) { SemanticActions.return_(Tokens.GetToken(), scope); } Tokens.NextToken(); return(true); } if (Tokens.GetToken().lexeme == "cout") { Tokens.NextToken(); if (Tokens.GetToken().lexeme != "<<") { SyntaxError(Tokens.GetToken(), "<<"); } Tokens.NextToken(); if (!Expression()) { SyntaxError(Tokens.GetToken(), "an expression"); } if (Tokens.GetToken().lexeme != ";") { SyntaxError(Tokens.GetToken(), ";"); } if (semanticPass) { SemanticActions.cout(); } Tokens.NextToken(); return(true); } if (Tokens.GetToken().lexeme == "cin") { Tokens.NextToken(); if (Tokens.GetToken().lexeme != ">>") { SyntaxError(Tokens.GetToken(), ">>"); } Tokens.NextToken(); if (!Expression()) { SyntaxError(Tokens.GetToken(), "an expression"); } if (Tokens.GetToken().lexeme != ";") { SyntaxError(Tokens.GetToken(), ";"); } if (semanticPass) { SemanticActions.cin(); } Tokens.NextToken(); return(true); } if (Tokens.GetToken().lexeme == "spawn") { Tokens.NextToken(); if (!Expression()) { SyntaxError(Tokens.GetToken(), "an expression"); } if (Tokens.GetToken().lexeme != "set") { SyntaxError(Tokens.GetToken(), "set"); } Tokens.NextToken(); if (Tokens.GetToken().type != Token.Type.Identifier) { SyntaxError(Tokens.GetToken(), "an identifier"); } if (semanticPass) { SemanticActions.iPush(Tokens.GetToken(), scope); } Tokens.NextToken(); if (Tokens.GetToken().lexeme != ";") { SyntaxError(Tokens.GetToken(), ";"); } if (semanticPass) { SemanticActions.spawn(); } Tokens.NextToken(); return(true); } if (Tokens.GetToken().lexeme == "block") { Tokens.NextToken(); if (Tokens.GetToken().lexeme != ";") { SyntaxError(Tokens.GetToken(), ";"); } if (semanticPass) { SemanticActions.block(); } Tokens.NextToken(); return(true); } if (Tokens.GetToken().lexeme == "lock") { Tokens.NextToken(); if (Tokens.GetToken().type != Token.Type.Identifier) { SyntaxError(Tokens.GetToken(), "an identifier"); } if (semanticPass) { SemanticActions.iPush(Tokens.GetToken(), scope); } Tokens.NextToken(); if (Tokens.GetToken().lexeme != ";") { SyntaxError(Tokens.GetToken(), ";"); } if (semanticPass) { SemanticActions.lock_(); } Tokens.NextToken(); return(true); } if (Tokens.GetToken().lexeme == "release") { Tokens.NextToken(); if (Tokens.GetToken().type != Token.Type.Identifier) { SyntaxError(Tokens.GetToken(), "an identifier"); } if (semanticPass) { SemanticActions.iPush(Tokens.GetToken(), scope); } Tokens.NextToken(); if (Tokens.GetToken().lexeme != ";") { SyntaxError(Tokens.GetToken(), ";"); } if (semanticPass) { SemanticActions.release(); } Tokens.NextToken(); return(true); } if (Expression()) { if (Tokens.GetToken().lexeme != ";") { SyntaxError(Tokens.GetToken(), ";"); } if (semanticPass) { SemanticActions.EOE(); } Tokens.NextToken(); return(true); } return(false); }