private static PParser.ProgramContext Parse(ICompilationJob job, FileInfo inputFile) { string fileText = File.ReadAllText(inputFile.FullName); AntlrInputStream fileStream = new AntlrInputStream(fileText); PLexer lexer = new PLexer(fileStream); CommonTokenStream tokens = new CommonTokenStream(lexer); PParser parser = new PParser(tokens); parser.RemoveErrorListeners(); // As currently implemented, P can be parsed by SLL. However, if extensions to the // language are later added, this will remain robust. There is a performance penalty // when a file doesn't parse (it is parsed twice), but most of the time we expect // programs to compile and for code generation to take about as long as parsing. try { // Stage 1: use fast SLL parsing strategy parser.Interpreter.PredictionMode = PredictionMode.Sll; parser.ErrorHandler = new BailErrorStrategy(); return(parser.program()); } catch (Exception e) when(e is RecognitionException || e is OperationCanceledException) { // Stage 2: use slower LL(*) parsing strategy job.Output.WriteMessage("Reverting to LL(*) parsing strategy.", SeverityKind.Warning); tokens.Reset(); parser.AddErrorListener(new PParserErrorListener(inputFile, job.Handler)); parser.Interpreter.PredictionMode = PredictionMode.Ll; parser.ErrorHandler = new DefaultErrorStrategy(); return(parser.program()); } }
public static void Main(string[] args) { try { // open a simple stream to the input CharBuffer input = new CharBuffer(Console.In); // attach java lexer to the input stream, mainLexer = new PLexer(input); // notify selector about starting lexer; name for convenience selector.addInputStream(mainLexer, "main"); selector.select("main"); // start with main P lexer // Create parser attached to selector parser = new PParser(selector); // Parse the input language: P parser.setFilename("<stdin>"); parser.startRule(); } catch (Exception e) { Console.Error.WriteLine("exception: " + e); Console.Error.WriteLine(e.StackTrace); // so we can get stack trace } }
public override void Init(string pParameters) { this.InitializeParameters(pParameters, "CCI:14;TCCI:6;MINUTES:5;"); CCIPeriods = (int)PParser.GetDouble("CCI", 0); TCCIPeriods = (int)PParser.GetDouble("TCCI", 0); Minutes = (int)PParser.GetDouble("MINUTES", 0); CCI = new iCCI(CCIPeriods); TCCI = new iCCI(TCCIPeriods); CCISlope = new iDerivatives(); CCIH = new CQueue(CCIPeriods * 3); TCCIH = new CQueue(CCIPeriods * 3); // OPTIMIZATION PARAMETER CHECK // if parameters are erroneous (TurboCCI length > CCI) // do not register candle listeners // SystemTester will then not send us any ticks // and go to the next iteration // need 6 cci bars to determine trend if ((TCCIPeriods < CCIPeriods) || (CCIPeriods < 6)) { cbx = new cCandleBuilder(Minutes, 10); Framework.TickServer.RegisterTickListener("cbx", "*", cbx); cbx.RegisterCandleListener("cbx", this); Framework.TickServer.RegisterTickListener("System", "*", this); Framework.WriteGraphLine("InTrade,Margin,C,CCI,CCIDelta,CCISpeed,TCCI,TypeOfTrade,Direction,BelowFifty,ZLR"); } }
private static PParser.ProgramContext Parse(ITranslationErrorHandler handler, FileInfo inputFile) { var fileStream = new AntlrFileStream(inputFile.FullName); var lexer = new PLexer(fileStream); var tokens = new CommonTokenStream(lexer); var parser = new PParser(tokens); parser.RemoveErrorListeners(); try { // Stage 1: use fast SLL parsing strategy parser.Interpreter.PredictionMode = PredictionMode.Sll; parser.ErrorHandler = new BailErrorStrategy(); return(parser.program()); } catch (Exception e) when(e is RecognitionException || e is OperationCanceledException) { // Stage 2: use slower LL(*) parsing strategy tokens.Reset(); parser.AddErrorListener(new PParserErrorListener(inputFile, handler)); parser.Interpreter.PredictionMode = PredictionMode.Ll; parser.ErrorHandler = new DefaultErrorStrategy(); return(parser.program()); } }
public override void Init(string pParameters) { InitializeParameters(pParameters, "SRSI:14;MINUTES:5;"); RSIPeriods = (int)PParser.GetDouble("SRSI", 0); StochRSI = new iStochRSI(RSIPeriods); RSISlope = new iSlope(); Minutes = (int)PParser.GetDouble("MINUTES", 0); cbx = new cCandleBuilder(Minutes, 10); cbx.RegisterCandleListener("cbx", this); Framework.TickServer.RegisterTickListener("cbx", "*", cbx); Framework.TickServer.RegisterTickListener("System", "*", this); Framework.WriteGraphLine("StochRSI,RSISlope,InTrade,Margin"); // this is optional // demonstrates we have complete control over ticks served LoadTicks(); // only if specified by parameters FILE1 and FILE2 SelectTicks(); // this is optional // demonstrates registration of multiple period candles cb10 = new cCandleBuilder(10, 4); cb10.RegisterCandleListener("cb10", this); Framework.TickServer.RegisterTickListener("cb10", "*", cb10); }
public override void Init(string pParameters) { this.InitializeParameters(pParameters, "BB:20;WIDTH:-1;HMA:10;BWT:0.0008;BWRT:0.0002;TS:0.0003;MINUTES:5;"); State = 0; iPeriods = (int)PParser.GetDouble("BB", 0); iWidth = (int)PParser.GetDouble("WIDTH", 0); iHMALen = (int)PParser.GetDouble("HMA", 0); Minutes = (int)PParser.GetDouble("MINUTES", 0); BWThreshold = PParser.GetDouble("BWT", 0); BWReversalThreshold = PParser.GetDouble("BWRT", 0); TrailingStop = PParser.GetDouble("TS", 0); BBands = new iBollingerBands(iPeriods, iWidth); HMA = new iHMA(iHMALen); SMASlope = new iSlope(); cbx = new cCandleBuilder(Minutes, 10); Framework.TickServer.RegisterTickListener("cbx", "*", cbx); cbx.RegisterCandleListener("cbx", this); Framework.TickServer.RegisterTickListener("System", "*", this); Framework.WriteGraphLine("InTrade,Margin,B+,C,HMA,SMA,B-,State,BWidth,MinBWidth,EntryRecommend"); }
/// <summary> /// Parses a P syntax tree to C#. /// </summary> /// <param name="tree">SyntaxTree</param> private void ParsePSyntaxTree(SyntaxTree tree) { var root = (CompilationUnitSyntax)tree.GetRoot(); var tokens = new PLexer().Tokenize(root.ToFullString()); var program = new PParser(this, tree).ParseTokens(tokens); this.PPrograms.Add(program as PProgram); this.ProgramMap.Add(program, tree); }
public static int[,] GetMatrixFromCode(string code) { var graph = new Graph <SStatement>(); var tokens = PLexer.ParseTokens(code); PParser.GetFunctionContents(tokens).First().BuildGraphNodes(graph); RemoveUnvisible(graph); return(graph.GetMatrix()); }
public override void Init(string pParameters) { this.InitializeParameters(pParameters, "PERCENT:0.001;"); iPercentage = PParser.GetDouble("PERCENT", 0); Framework.TickServer.RegisterTickListener("System", "*", this); Framework.WriteGraphLine("InTrade,Margin,Tick,Min,MinTh,Max,MaxTh"); FirstTick = true; }
public override void Init(string pParameters) { this.InitializeParameters(pParameters, "MINUTES:5;"); Minutes = (int)PParser.GetDouble("MINUTES", 0); RNG = new Random(); cbx = new cCandleBuilder(Minutes, 10); Framework.TickServer.RegisterTickListener("cbx", "*", cbx); cbx.RegisterCandleListener("cbx", this); Framework.TickServer.RegisterTickListener("System", "*", this); Framework.WriteGraphLine("InTrade,Margin,C"); }
public override void Init(string pParameters) { this.InitializeParameters(pParameters, "MINUTES:5;CHANNEL:25;TRAILSTOP:0.0010;"); Minutes = (int)PParser.GetDouble("MINUTES", 0); channel = (int)PParser.GetDouble("CHANNEL", 0); trailstop = PParser.GetDouble("TRAILSTOP", 0); minmax = new iMinMax(2 * channel); cbx = new cCandleBuilder(Minutes, 10); Framework.TickServer.RegisterTickListener("cbx", "*", cbx); cbx.RegisterCandleListener("cbx", this); Framework.TickServer.RegisterTickListener("System", "*", this); Framework.WriteGraphLine("InTrade,Margin,C"); }
// initialization routine, called once before ticks are sent // if multiple tick sources are used, will get called several times // during the lifetime of the object, once per tick source change public override void Init(string pParameters) { // initialize all ParameterParsers this.InitializeParameters(pParameters, "PERIODS:14;MINUTES:5;"); // get periods to use for the indicator(s) iPeriods = (int)PParser.GetDouble("PERIODS", 0); // now indicators must be instantiated // your indicator instantiation goes here // end of indicator instantiation // instantiate candlebuilder with desired timeframe Minutes = (int)PParser.GetDouble("MINUTES", 0); cbx = new cCandleBuilder(Minutes, 10); // register candlebuilder as a tick listener, name unimportant Framework.TickServer.RegisterTickListener("cbx", "*", cbx); // register this object as a candle listener // the candle name is important since we might receive // several candles with same period. cbx.RegisterCandleListener("cbx", this); // multiple candlebuilders can be setup by using previous 4 lines. // register this object as a tick listener, name unimportant // this is an optional step to receive ticks in between candles Framework.TickServer.RegisterTickListener("System", "*", this); // start header line of numerical output file Framework.WriteGraphLine("InTrade,Margin"); // this is optional // demonstrates we have complete control over ticks served // this function loads different tick sources // in order to execute the same algorithm with the same parameters // in several different tick sources and compare the results // LoadTick imports ticks from FILE1 and FILE2 if the parameters exist. LoadTicks(); // this function observes how many times the object has been executed // and selects the appropriate tick source for the run. SelectTicks(); }
private void DisplayProgram(string program) { try { var tokens = PLexer.ParseTokens(program); foreach (var matchedFunction in PParser.GetFunctionContents(tokens)) { var graph = new Graph <SStatement>(); matchedFunction.BuildGraphNodes(graph); RemoveUnvisible(graph); var matrix = graph.GetMatrix(); dataGridView1.ColumnCount = matrix.GetLength(0); dataGridView1.RowCount = matrix.GetLength(1); dataGridView1.ColumnHeadersHeight = 4; dataGridView1.RowHeadersWidth = 4; for (var i0 = 0; i0 < matrix.GetLength(0); i0++) { dataGridView1.Columns[i0].HeaderText = (i0 + 1).ToString(); dataGridView1.Columns[i0].Width = 17; for (var i1 = 0; i1 < matrix.GetLength(1); i1++) { dataGridView1[i1, i0].Value = matrix[i0, i1]; } } } } catch (ArgumentException exc) { MessageBox.Show(@"There is an error in source code: " + exc.Message); } catch (InvalidOperationException exc) { MessageBox.Show(@"There is an error in source code: " + exc.Message); } catch { MessageBox.Show(@"An unexpected error occured!"); } }
// initialization routine, called once before ticks are sent // if multiple tick sources are used, will get called several times // during the lifetime of the object, once per tick source change public override void Init(string pParameters) { // initialize all ParameterParsers this.InitializeParameters(pParameters, "PERIODS:14;MINUTES:5;"); // get periods to use for the indicator(s) iPeriods = (int)PParser.GetDouble("PERIODS", 0); // now indicators must be instantiated // your indicator instantiation goes here IndicatorDump = new oIndicatorDump(iPeriods); // end of indicator instantiation // instantiate candlebuilder with desired timeframe Minutes = (int)PParser.GetDouble("MINUTES", 0); cbx = new cCandleBuilder(Minutes, 10); // register candlebuilder as a tick listener, name unimportant Framework.TickServer.RegisterTickListener("cbx", "*", cbx); // register this object as a candle listener // the candle name is important since we might receive // several candles with same period. cbx.RegisterCandleListener("cbx", this); // multiple candlebuilders can be setup by using previous 4 lines. // register this object as a tick listener, name unimportant // this is an optional step to receive ticks in between candles Framework.TickServer.RegisterTickListener("System", "*", this); // start header line of numerical output file string Header = IndicatorDump.GetHeader(); Header = "InTrade,Margin," + Header; Framework.WriteGraphLine(Header); }
public static void Main(string[] args) { try { // open a simple stream to the input CharBuffer input = new CharBuffer(Console.In); // attach java lexer to the input stream, mainLexer = new PLexer(input); // notify selector about starting lexer; name for convenience selector.addInputStream(mainLexer, "main"); selector.select("main"); // start with main P lexer // Create parser attached to selector parser = new PParser(selector); // Parse the input language: P parser.setFilename("<stdin>"); parser.startRule(); } catch(Exception e) { Console.Error.WriteLine("exception: "+e); Console.Error.WriteLine(e.StackTrace); // so we can get stack trace } }
// initialization routine, called once before ticks are sent // if multiple tick sources are used, will get called several times // during the lifetime of the object, once per tick source change public override void Init(string pParameters) { this.InitializeParameters(pParameters, "PERIODS:17;MINUTES:10;"); // get periods to use for the indicator(s) Periods = (int)PParser.GetDouble("PERIODS", 0); Derivatives = new iDerivatives(); HMA = new iHMA(Periods); HMAD1 = new CQueue(Periods); FMA = new iFMA(Periods); Deriv1 = new CQueue(Periods); Deriv2 = new CQueue(Periods); BBands = new iBollingerBands(Periods, -1); StochRSI = new iStochRSI(Periods); CCI = new iCCI(Periods); // instantiate candlebuilder with desired timeframe Minutes = (int)PParser.GetDouble("MINUTES", 0); // cbx = new cCandleBuilder(Minutes,PeriodsLong+PeriodsShort+1); cbx = new cCandleBuilder(Minutes, Periods); // register candlebuilder as a tick listener, name unimportant Framework.TickServer.RegisterTickListener("cbx", "*", cbx); // register this object as a candle listener // the candle name is important since we might receive // several candles with same period. cbx.RegisterCandleListener("cbx", this); // multiple candlebuilders can be setup by using previous 4 lines. // register this object as a tick listener, name unimportant // this is an optional step to receive ticks in between candles Framework.TickServer.RegisterTickListener("System", "*", this); // start header line of numerical output file Framework.WriteGraphLine("InTrade,Margin,C,TP,FMA,HMA,Deriv1,Deriv2,SMA,BBand1,BBand2,%b,Bandwidth,StochRSI,CCI"); }