GLRCommandTree CharacterControllerFunc() { if(Lexems[LexemId].Kind == LexemKind.Step && Ensure(LexemId+1, LexemKind.Semicolon, "Ожидается точка с запятой!")) { var node = new GLRCommandTree(); node.Value = new GameLanguageRuntime.CharacterStepCommand(); LexemId+=2; return node; } if(Lexems[LexemId].Kind == LexemKind.TurnLeft && Ensure(LexemId+1, LexemKind.Semicolon, "Ожидается точка с запятой!")) { var node = new GLRCommandTree(); node.Value = new GameLanguageRuntime.CharacterTurnLeftCommand(); LexemId+=2; return node; } if(Lexems[LexemId].Kind == LexemKind.TurnRight && Ensure(LexemId+1, LexemKind.Semicolon, "Ожидается точка с запятой!")) { var node = new GLRCommandTree(); node.Value = new GameLanguageRuntime.CharacterTurnRightCommand(); LexemId+=2; return node; } return null; }
GLRCommandTree Assign() { if(Check(LexemKind.Identifier, LexemId) && Check(LexemKind.Assign, LexemId+1)) { string expression=""; bool find=false; for(int i= LexemId+2; i<Lexems.Count; i++) { if(Lexems[i].Kind == LexemKind.Semicolon) { find = true; break; } expression += Lexems[i].Value; } if(!find) error("Ожидаетс точка с запятой",LexemId); GameLanguageRuntime.AssignCommand command = new GameLanguageRuntime.AssignCommand(); command.VariableTargetName = Lexems[LexemId].Value; command.Expression = expression; GLRCommandTree tree = new GLRCommandTree(); tree.Value = command; return tree; } return null; }
void BlockBeginOperator() { if(Check(LexemKind.BeginBlock,LexemId)) { GLRCommandTree blockNode = new GLRCommandTree(); InnerBlocks.Push(blockNode); LexemId++; } }
GLRCommandTree CreateVariable(LexemKind LexemType, Type CLRType) { if(Lexems[LexemId].Kind == LexemType && Ensure(LexemId+1, LexemKind.Identifier, "Ожидается имя переменной!") && Ensure(LexemId+2, LexemKind.Semicolon, "Ожидается точка с запятой!") ) { GameLanguageRuntime.CreateVariableCommand command = new GameLanguageRuntime.CreateVariableCommand(); command.VariableType = CLRType; command.VariableName = Lexems[LexemId+1].Value; if(createdVariables.ContainsKey(command.VariableName)) error("Переменная {0} уже объявленна", LexemId+1, Lexems[LexemId+1].Value); else createdVariables.Add(command.VariableName,CLRType); LexemId+=3; GLRCommandTree tree = new GLRCommandTree(); tree.Value = command; return tree; } return null; }