// ActionClause ::= Action Article ActionSubjectTerminal private TranslateResult ActionClause(ILexer lexer) { var result = new TranslateResult(); var simpleActionResult = ActionVerbTerminal(lexer); result.Join(simpleActionResult); if (result.IsSuccessful) { var nextToken = lexer.PeekNextToken(); while (nextToken.Type == TokenType.Article) { lexer.ConsumeNextToken(); nextToken = lexer.PeekNextToken(); } var actionSubjectResult = ActionSubjectTerminal(lexer); result.Join(actionSubjectResult); if (result.IsSuccessful) { result.Code = $"{actionSubjectResult.Code}\n\t\t{simpleActionResult.Code}"; } } return(result); }
// IfStatement ::= "If" Condition "Then" ActionClause ElseClause? private TranslateResult IfClause(ILexer lexer) { var result = new TranslateResult(); lexer.ConsumeNextToken(); // Execute ConditionStatement var conditionClauseResult = ConditionClause(lexer); result.Join(conditionClauseResult); // Check for "Then" var token = lexer.PeekNextToken(); if (token.Type != TokenType.Then) { result.ErrorMessage = string.Format(ErrorMessageFormat, "then", token.Text); return(result); } lexer.ConsumeNextToken(); var actionClauseResult = ActionClause(lexer); result.Join(actionClauseResult); if (result.IsSuccessful) { // Execute ElseClause result.Code = $@"if({conditionClauseResult.Code}) {{ {actionClauseResult.Code} }}"; } return(result); }