private void FindVariables() { this.variableInfo = new List <PsudoVariableInfo>(); for (int i = 0; i < lineTypes.Length; i++) { switch (lineTypes[i]) { case PsudoLineType.Variable: Match typeMatch = Regex.Match(codeLines[i], @"(string|num)", RegexOptions.IgnoreCase); Match match = Regex.Match(codeLines[i], @"(?<=(string|num))[\s]*[a-zA-Z0-9_-]*", RegexOptions.IgnoreCase); PsudoVariableInfo var = new PsudoVariableInfo( match.Value.Trim().ToLower(), typeMatch.Value.Trim().ToLower(), i); Match value = Regex.Match(codeLines[i], @"(?<=(=[\s]*))[a-zA-Z0-9_-]*[\s]*$", RegexOptions.IgnoreCase); if (value.Success) { var.Default = value.Value; } this.variableInfo.Add(var); break; default: break; } } }
protected object CreateVariable(PsudoVariableInfo vInfo) { switch (vInfo.Type) { case "string": if (vInfo.Default != null) { return(vInfo.Default); } return(""); case "num": if (vInfo.Default != null) { return(Convert.ToDouble(vInfo.Default)); } return(0.0); } return(null); }
protected List <PsudoInstruction> CompileBlock(PsudoMethod method, int startLine, int endLine) { List <PsudoInstruction> list = new List <PsudoInstruction>(); for (int i = startLine; i <= endLine; i++) { try { switch (this.scanner.lineTypes[i]) { case PsudoLineType.Variable: PsudoVariableInfo vInfo = this.scanner.variableInfo.Find( item => item.Line == i); vInfo.Processed = true; list.Add(new CreateLocalVariable(i, method, vInfo.Type, vInfo.Name, vInfo.Default)); break; case PsudoLineType.StartDecision: case PsudoLineType.StartStartDecision: int end; list.Add(CompileDecision(method, i, out end)); i = end; break; case PsudoLineType.StartLoop: int end2; list.Add(CompileLoop(method, i, out end2)); i = end2; break; case PsudoLineType.Instruction: list.Add(InstructionFactory.CompileInstruction( this.codeLines[i], i, method)); break; // Nothing to do for the following case PsudoLineType.StartMain: case PsudoLineType.StartMethod: case PsudoLineType.Whitespace: case PsudoLineType.Comment: case PsudoLineType.EndMethod: break; case PsudoLineType.EndDecision: throw new Exception("Unexpected End Decision"); case PsudoLineType.EndLoop: throw new Exception("Unexpected End Loop"); case PsudoLineType.EndClass: case PsudoLineType.StartClass: throw new Exception("Classes Not Supported Currently"); default: throw new Exception(string.Format( "Error Compiling Method \"{0}\" on Line #{1}", method.Name, i + 1)); } } catch (Exception e) { this.Errors.Add(new CompileError(e.Message, i + 1)); } } return(list); }