private void InitializeRuntimeContext() { ObjectCreator objCreator = new ObjectCreator(); VariableDictionaryCreator varDictCreator = new VariableDictionaryCreator(); OperatorDictionary operators = OperatorDictionary.Default; var run = new RuntimeContext(varDictCreator, objCreator, operators); var memory = run.Memory as VariableDictionary; memory.Classes.Add("Object", ObjectClass.Instance); memory.Classes.Add("Array", ArrayClass.Instance); memory.Classes.Add("Boolean", BooleanClass.Instance); memory.Classes.Add("Number", NumberClass.Instance); memory.Classes.Add("String", StringClass.Instance); RuntimeContext = run; }
/// <summary> /// grab a set of operator attributes from the operator dictionary. /// this needs to be done after the object is created as we need to /// know if this node is prefix, infix, or postfix, and the prev and /// next siblings are not set yet in the ctor /// </summary> private void GetAttributes() { if (PreviousSibling != null) { if (NextSibling != null) { form = Form.Infix; } else { form = Form.Postfix; } } else { if (NextSibling != null) { form = Form.Prefix; } else { form = Form.Infix; } } if (FirstChild != null) { MathMLGlyphElement glyph = null; if (FirstChild.NodeType == XmlNodeType.Text) { op = OperatorDictionary.GetValue(FirstChild.Value, form); } else if ((glyph = FirstChild as MathMLGlyphElement) != null) { string s = new string((char)glyph.Index, 1); op = OperatorDictionary.GetValue(s, form); } else { op = Operator.Default(form); } } else { op = Operator.Default(form); } dirty = false; }
// public NodesBuilder (int width, OperatorDictionary operatorDictionary) { this.fonts_ = null; this.mathmlSchema = ""; this.mathmlNamespace = "http://www.w3.org/1998/Math/MathML"; this.painter_ = null; this.currentCaret = 0; this.horizontalRes = 0; this.oX = 0; this.oY = 0; this.hasSelection = false; this.fontSize = 12f; this.operators_ = null; this.schema = null; this.undo = new UndoRedoStack (); this.redo = new UndoRedoStack (); this.stretchyBrackets = true; this.operators_ = operatorDictionary; if (this.operators_ == null) { this.operators_ = new OperatorDictionary (); } this.undo.callback = (EventHandler) Delegate.Combine (this.undo.callback, new EventHandler (this.UndoCallback)); this.redo.callback = (EventHandler) Delegate.Combine (this.redo.callback, new EventHandler (this.RedoCallback)); this.clientRect = new Rectangle (0, 0, 0, 0); this.painter_ = new Painter (); this.painter_.SetFontSize (this.FontSize); if (this.operators_ != null) { this.painter_.SetOperators (this.operators_); } this.Width = width; }
public void SetOperators(OperatorDictionary OperatorDictionary) { this.operators = OperatorDictionary; }
static ScriptLexer() { EofToken = new ScriptToken(null, default(SourcePosition), default(SourcePosition), ScriptTokenType.Eof, null); _operators = new OperatorDictionary <ScriptTokenType> { { ";", ScriptTokenType.Semicolon }, { ",", ScriptTokenType.Comma }, { ".", ScriptTokenType.Dot }, { "=", ScriptTokenType.Assign }, { "?", ScriptTokenType.QuestionMark }, { ":", ScriptTokenType.Colon }, { "(", ScriptTokenType.LeftParen }, { ")", ScriptTokenType.RightParen }, { "{", ScriptTokenType.LeftBrace }, { "}", ScriptTokenType.RightBrace }, { "[", ScriptTokenType.LeftSquare }, { "]", ScriptTokenType.RightSquare }, { "+", ScriptTokenType.Add }, { "+=", ScriptTokenType.AddAssign }, { "-", ScriptTokenType.Subtract }, { "-=", ScriptTokenType.SubtractAssign }, { "*", ScriptTokenType.Multiply }, { "*=", ScriptTokenType.MultiplyAssign }, { "/", ScriptTokenType.Divide }, { "/=", ScriptTokenType.DivideAssign }, { "%", ScriptTokenType.Remainder }, { "%=", ScriptTokenType.RemainderAssign }, { "++", ScriptTokenType.Increment }, { "--", ScriptTokenType.Decrement }, { "==", ScriptTokenType.EqualTo }, { "!=", ScriptTokenType.NotEqualTo }, { ">", ScriptTokenType.GreaterThan }, { ">=", ScriptTokenType.GreaterThanOrEqual }, { "<", ScriptTokenType.LessThan }, { "<=", ScriptTokenType.LessThanOrEqual }, { "&&", ScriptTokenType.LogicalAnd }, { "||", ScriptTokenType.LogicalOr }, { "!", ScriptTokenType.LogicalNot }, { "~", ScriptTokenType.BitwiseNot }, { "&", ScriptTokenType.BitwiseAnd }, { "&=", ScriptTokenType.BitwiseAndAssign }, { "|", ScriptTokenType.BitwiseOr }, { "|=", ScriptTokenType.BitwiseOrAssign }, { "^", ScriptTokenType.BitwiseXor }, { "^=", ScriptTokenType.BitwiseXorAssign }, { "<<", ScriptTokenType.BitwiseShiftLeft }, { "<<=", ScriptTokenType.BitwiseShiftLeftAssign }, { ">>", ScriptTokenType.BitwiseShiftRight }, { ">>=", ScriptTokenType.BitwiseShiftRightAssign }, { "##", ScriptTokenType.Hash }, { "#define", ScriptTokenType.PreprocessDefine }, { "#ifdef", ScriptTokenType.PreprocessIfDef }, { "#endif", ScriptTokenType.PreprocessEndIf }, }; _keywords = new Dictionary <string, ScriptTokenType> { { "null", ScriptTokenType.Null }, { "true", ScriptTokenType.True }, { "false", ScriptTokenType.False }, { "return", ScriptTokenType.Return }, { "if", ScriptTokenType.If }, { "else", ScriptTokenType.Else }, { "for", ScriptTokenType.For }, { "while", ScriptTokenType.While }, { "do", ScriptTokenType.Do }, { "break", ScriptTokenType.Break }, { "continue", ScriptTokenType.Continue }, { "switch", ScriptTokenType.Switch }, { "case", ScriptTokenType.Case }, { "default", ScriptTokenType.Default }, { "inherits", ScriptTokenType.Inherits }, { "include", ScriptTokenType.Include }, { "const", ScriptTokenType.Const }, { "public", ScriptTokenType.Public }, { "new", ScriptTokenType.New }, { "instanceof", ScriptTokenType.InstanceOf }, { "try", ScriptTokenType.Try }, { "catch", ScriptTokenType.Catch }, { "throw", ScriptTokenType.Throw }, }; }
static LoonyLexer() { EofToken = new LoonyToken(null, default(SourcePosition), default(SourcePosition), LoonyTokenType.Eof, null); _operators = new OperatorDictionary <LoonyTokenType> { { ";", LoonyTokenType.Semicolon }, { ",", LoonyTokenType.Comma }, { ".", LoonyTokenType.Dot }, { "=", LoonyTokenType.Assign }, { "?", LoonyTokenType.QuestionMark }, { ":", LoonyTokenType.Colon }, { "->", LoonyTokenType.Pointy }, { "(", LoonyTokenType.LeftParen }, { ")", LoonyTokenType.RightParen }, { "{", LoonyTokenType.LeftBrace }, { "}", LoonyTokenType.RightBrace }, { "[", LoonyTokenType.LeftSquare }, { "]", LoonyTokenType.RightSquare }, { "+", LoonyTokenType.Add }, { "+=", LoonyTokenType.AddAssign }, { "-", LoonyTokenType.Subtract }, { "-=", LoonyTokenType.SubtractAssign }, { "*", LoonyTokenType.Multiply }, { "*=", LoonyTokenType.MultiplyAssign }, { "/", LoonyTokenType.Divide }, { "/=", LoonyTokenType.DivideAssign }, { "%", LoonyTokenType.Remainder }, { "%=", LoonyTokenType.RemainderAssign }, { "++", LoonyTokenType.Increment }, { "--", LoonyTokenType.Decrement }, { "==", LoonyTokenType.EqualTo }, { "!=", LoonyTokenType.NotEqualTo }, { ">", LoonyTokenType.GreaterThan }, { ">=", LoonyTokenType.GreaterThanOrEqual }, { "<", LoonyTokenType.LessThan }, { "<=", LoonyTokenType.LessThanOrEqual }, { "&&", LoonyTokenType.LogicalAnd }, { "||", LoonyTokenType.LogicalOr }, { "!", LoonyTokenType.LogicalNot }, { "~", LoonyTokenType.BitwiseNot }, { "&", LoonyTokenType.BitwiseAnd }, { "&=", LoonyTokenType.BitwiseAndAssign }, { "|", LoonyTokenType.BitwiseOr }, { "|=", LoonyTokenType.BitwiseOrAssign }, { "^", LoonyTokenType.BitwiseXor }, { "^=", LoonyTokenType.BitwiseXorAssign }, { "<<", LoonyTokenType.BitwiseShiftLeft }, { "<<=", LoonyTokenType.BitwiseShiftLeftAssign }, { ">>", LoonyTokenType.BitwiseShiftRight }, { ">>=", LoonyTokenType.BitwiseShiftRightAssign }, }; _keywords = new Dictionary <string, LoonyTokenType> { { "null", LoonyTokenType.Null }, { "true", LoonyTokenType.True }, { "false", LoonyTokenType.False }, { "any", LoonyTokenType.Any }, { "bool", LoonyTokenType.Bool }, { "char", LoonyTokenType.Char }, { "short", LoonyTokenType.Short }, { "int", LoonyTokenType.Int }, { "var", LoonyTokenType.Var }, { "return", LoonyTokenType.Return }, { "if", LoonyTokenType.If }, { "else", LoonyTokenType.Else }, { "for", LoonyTokenType.For }, { "while", LoonyTokenType.While }, { "do", LoonyTokenType.Do }, { "break", LoonyTokenType.Break }, { "continue", LoonyTokenType.Continue }, { "const", LoonyTokenType.Const }, { "static", LoonyTokenType.Static }, { "func", LoonyTokenType.Func }, { "struct", LoonyTokenType.Struct }, { "union", LoonyTokenType.Union }, { "extern", LoonyTokenType.Extern }, }; }
private static void Add(string Rep, System.Type Type) { OperatorDictionary.Add(Rep, Type); RepresentationDictionary.Add(Type, Rep); }
private void Init (EntityManager MathMLEntityManager, FontCollection FontCollection) { try { SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler (UserPrefChanged); } catch { } fonts_ = FontCollection; selectionBrush_ = new SolidBrush (Color.Gray); operators_ = new OperatorDictionary (); builder_ = new NodesBuilder (base.ClientRectangle.Width - 20, operators_); builder_.setFonts (fonts_); builder_.SetOrigin (lMargin - OffsetX, tMargin - OffsetY); if (MathMLEntityManager == null) { entityManager = new EntityManager (fonts_); } else { entityManager = MathMLEntityManager; } builder_.SetEntityManager (entityManager); builder_.UndoRedo += new EventHandler (UndoRedoHandler); builder_.InvalidXML += new InvalidXMLFile (OnInvalidXML); builder_.InsertHappened += new InsertionHappenned (OnInsert); base.SetStyle (ControlStyles.UserPaint, true); base.SetStyle (ControlStyles.AllPaintingInWmPaint, true); base.SetStyle (ControlStyles.DoubleBuffer, true); caretBlackPen = new Pen (Color.Black); caretBluePen = new Pen (Color.Blue); caretThread = new Thread (new ThreadStart (CaretThreadProc)); caretThread.Start (); canvasWidth = 0; canvasHeight = 0; ResizeScrollbars (); horScroller_.Visible = false; vertScroller_.Visible = false; vertScroller_.TabStop = false; horScroller_.TabStop = false; vertScroller_.GotFocus += new EventHandler (VertGotFocusHandler); horScroller_.GotFocus += new EventHandler (HorzGotFocusHandler); builder_.PropogateEntityManager (); types = new Types (); builder_.SetTypes (types); SetAntialias (true); try { UpdateMargins (); } catch { } DoResize (base.ClientRectangle.Width, base.ClientRectangle.Height, true, false); if (base.ClientRectangle.Width > 50) { SetWidth ((base.ClientRectangle.Width - vertScroller_.Width) - 2); } else { SetWidth (50); } }
static LoonyLexer() { EofToken = new LoonyToken(null, default(SourcePosition), default(SourcePosition), LoonyTokenType.Eof, null); _operators = new OperatorDictionary<LoonyTokenType> { { ";", LoonyTokenType.Semicolon }, { ",", LoonyTokenType.Comma }, { ".", LoonyTokenType.Dot }, { "=", LoonyTokenType.Assign }, { "?", LoonyTokenType.QuestionMark }, { ":", LoonyTokenType.Colon }, { "->", LoonyTokenType.Pointy }, { "(", LoonyTokenType.LeftParen }, { ")", LoonyTokenType.RightParen }, { "{", LoonyTokenType.LeftBrace }, { "}", LoonyTokenType.RightBrace }, { "[", LoonyTokenType.LeftSquare }, { "]", LoonyTokenType.RightSquare }, { "+", LoonyTokenType.Add }, { "+=", LoonyTokenType.AddAssign }, { "-", LoonyTokenType.Subtract }, { "-=", LoonyTokenType.SubtractAssign }, { "*", LoonyTokenType.Multiply }, { "*=", LoonyTokenType.MultiplyAssign }, { "/", LoonyTokenType.Divide }, { "/=", LoonyTokenType.DivideAssign }, { "%", LoonyTokenType.Remainder }, { "%=", LoonyTokenType.RemainderAssign }, { "++", LoonyTokenType.Increment }, { "--", LoonyTokenType.Decrement }, { "==", LoonyTokenType.EqualTo }, { "!=", LoonyTokenType.NotEqualTo }, { ">", LoonyTokenType.GreaterThan }, { ">=", LoonyTokenType.GreaterThanOrEqual }, { "<", LoonyTokenType.LessThan }, { "<=", LoonyTokenType.LessThanOrEqual }, { "&&", LoonyTokenType.LogicalAnd }, { "||", LoonyTokenType.LogicalOr }, { "!", LoonyTokenType.LogicalNot }, { "~", LoonyTokenType.BitwiseNot }, { "&", LoonyTokenType.BitwiseAnd }, { "&=", LoonyTokenType.BitwiseAndAssign }, { "|", LoonyTokenType.BitwiseOr }, { "|=", LoonyTokenType.BitwiseOrAssign }, { "^", LoonyTokenType.BitwiseXor }, { "^=", LoonyTokenType.BitwiseXorAssign }, { "<<", LoonyTokenType.BitwiseShiftLeft }, { "<<=", LoonyTokenType.BitwiseShiftLeftAssign }, { ">>", LoonyTokenType.BitwiseShiftRight }, { ">>=", LoonyTokenType.BitwiseShiftRightAssign }, }; _keywords = new Dictionary<string, LoonyTokenType> { { "null", LoonyTokenType.Null }, { "true", LoonyTokenType.True }, { "false", LoonyTokenType.False }, { "any", LoonyTokenType.Any }, { "bool", LoonyTokenType.Bool }, { "char", LoonyTokenType.Char }, { "short", LoonyTokenType.Short }, { "int", LoonyTokenType.Int }, { "var", LoonyTokenType.Var }, { "return", LoonyTokenType.Return }, { "if", LoonyTokenType.If }, { "else", LoonyTokenType.Else }, { "for", LoonyTokenType.For }, { "while", LoonyTokenType.While }, { "do", LoonyTokenType.Do }, { "break", LoonyTokenType.Break }, { "continue", LoonyTokenType.Continue }, { "const", LoonyTokenType.Const }, { "static", LoonyTokenType.Static }, { "func", LoonyTokenType.Func }, { "struct", LoonyTokenType.Struct }, { "union", LoonyTokenType.Union }, { "extern", LoonyTokenType.Extern }, }; }
static Lexer() { _operators = new OperatorDictionary { { ";", TokenType.Semicolon }, { ",", TokenType.Comma }, { ".", TokenType.Dot }, { "=", TokenType.Assign }, { "(", TokenType.LeftParen }, { ")", TokenType.RightParen }, { "{", TokenType.LeftBrace }, { "}", TokenType.RightBrace }, { "[", TokenType.LeftSquare }, { "]", TokenType.RightSquare }, { "+", TokenType.Add }, { "-", TokenType.Subtract }, { "*", TokenType.Multiply }, { "/", TokenType.Divide }, { "%", TokenType.Modulo }, { "**", TokenType.Exponent }, { "&", TokenType.BitAnd }, { "|", TokenType.BitOr }, { "^", TokenType.BitXor }, { "~", TokenType.BitNot }, { "<<", TokenType.BitLeftShift }, { ">>", TokenType.BitRightShift }, { "++", TokenType.Increment }, { "--", TokenType.Decrement }, { "+=", TokenType.AddAssign }, { "-=", TokenType.SubtractAssign }, { "*=", TokenType.MultiplyAssign }, { "/=", TokenType.DivideAssign }, { "%=", TokenType.ModuloAssign }, { "**=", TokenType.ExponentAssign }, { "&=", TokenType.BitAndAssign }, { "|=", TokenType.BitOrAssign }, { "^=", TokenType.BitXorAssign }, { "<<=", TokenType.BitLeftShiftAssign }, { ">>=", TokenType.BitRightShiftAssign }, { "==", TokenType.EqualTo }, { "!=", TokenType.NotEqualTo }, { ">", TokenType.GreaterThan }, { ">=", TokenType.GreaterThanOrEqual }, { "<", TokenType.LessThan }, { "<=", TokenType.LessThanOrEqual }, { "!", TokenType.Not }, { "&&", TokenType.ConditionalAnd }, { "||", TokenType.ConditionalOr }, { "?", TokenType.QuestionMark }, { ":", TokenType.Colon }, { "->", TokenType.Pointy }, { "|>", TokenType.Pipeline }, { "...", TokenType.Ellipsis } }; _keywords = new Dictionary <string, TokenType> { { "global", TokenType.Global }, { "undefined", TokenType.Undefined }, { "null", TokenType.Null }, { "true", TokenType.True }, { "false", TokenType.False }, { "NaN", TokenType.NaN }, { "Infinity", TokenType.Infinity }, { "var", TokenType.Var }, { "const", TokenType.Const }, { "fun", TokenType.Fun }, { "return", TokenType.Return }, { "seq", TokenType.Seq }, { "yield", TokenType.Yield }, { "if", TokenType.If }, { "else", TokenType.Else }, { "for", TokenType.For }, { "foreach", TokenType.Foreach }, { "in", TokenType.In }, { "while", TokenType.While }, { "do", TokenType.Do }, { "break", TokenType.Break }, { "continue", TokenType.Continue }, { "switch", TokenType.Switch }, { "case", TokenType.Case }, { "default", TokenType.Default }, }; _hexChars = new HashSet <char> { 'a', 'b', 'c', 'd', 'e', 'f', 'A', 'B', 'C', 'D', 'E', 'F', }; }
static Lexer() { _punctuation = new OperatorDictionary { { ";", TokenType.Semicolon, TokenSubType.Punctuation }, { ",", TokenType.Comma, TokenSubType.Punctuation }, { "(", TokenType.LeftParen, TokenSubType.Punctuation }, { ")", TokenType.RightParen, TokenSubType.Punctuation }, { "{", TokenType.LeftBrace, TokenSubType.Punctuation }, { "}", TokenType.RightBrace, TokenSubType.Punctuation }, { "[", TokenType.LeftSquare, TokenSubType.Punctuation }, { "]", TokenType.RightSquare, TokenSubType.Punctuation }, { ":", TokenType.Colon, TokenSubType.Punctuation }, // Because of the way UDOs work, and how the lexer handles operators and punctuation // These two will never will never be returned by OperatorDictionary.Lookup() // But they are still lexed properly in Lexer.TryLexOperator(). // They have been left in for clarity. { "->", TokenType.Pointy, TokenSubType.Punctuation }, { "!in", TokenType.NotIn, TokenSubType.Operator } }; _operators = new Dictionary <string, TokenType> { { ".", TokenType.Dot }, { "=", TokenType.Assign }, { "+", TokenType.Add }, { "-", TokenType.Subtract }, { "*", TokenType.Multiply }, { "/", TokenType.Divide }, { "%", TokenType.Modulo }, { "**", TokenType.Exponent }, { "&", TokenType.BitAnd }, { "|", TokenType.BitOr }, { "^", TokenType.BitXor }, { "~", TokenType.BitNot }, { "<<", TokenType.BitLeftShift }, { ">>", TokenType.BitRightShift }, { "++", TokenType.Increment }, { "--", TokenType.Decrement }, { "+=", TokenType.AddAssign }, { "-=", TokenType.SubtractAssign }, { "*=", TokenType.MultiplyAssign }, { "/=", TokenType.DivideAssign }, { "%=", TokenType.ModuloAssign }, { "**=", TokenType.ExponentAssign }, { "&=", TokenType.BitAndAssign }, { "|=", TokenType.BitOrAssign }, { "^=", TokenType.BitXorAssign }, { "<<=", TokenType.BitLeftShiftAssign }, { ">>=", TokenType.BitRightShiftAssign }, { "==", TokenType.EqualTo }, { "!=", TokenType.NotEqualTo }, { ">", TokenType.GreaterThan }, { ">=", TokenType.GreaterThanOrEqual }, { "<", TokenType.LessThan }, { "<=", TokenType.LessThanOrEqual }, { "!", TokenType.Not }, { "&&", TokenType.ConditionalAnd }, { "||", TokenType.ConditionalOr }, { "?", TokenType.QuestionMark }, { "|>", TokenType.Pipeline }, { "...", TokenType.Ellipsis }, { "@", TokenType.Decorator } }; _keywords = new Dictionary <string, TokenType> { { "global", TokenType.Global }, { "undefined", TokenType.Undefined }, { "null", TokenType.Null }, { "true", TokenType.True }, { "false", TokenType.False }, { "NaN", TokenType.NaN }, { "Infinity", TokenType.Infinity }, { "var", TokenType.Var }, { "const", TokenType.Const }, { "fun", TokenType.Fun }, { "return", TokenType.Return }, { "seq", TokenType.Seq }, { "yield", TokenType.Yield }, { "if", TokenType.If }, { "else", TokenType.Else }, { "for", TokenType.For }, { "foreach", TokenType.Foreach }, { "in", TokenType.In }, { "while", TokenType.While }, { "do", TokenType.Do }, { "break", TokenType.Break }, { "continue", TokenType.Continue }, { "switch", TokenType.Switch }, { "case", TokenType.Case }, { "default", TokenType.Default }, { "debugger", TokenType.Debugger }, }; _hexChars = new HashSet <char> { 'a', 'b', 'c', 'd', 'e', 'f', 'A', 'B', 'C', 'D', 'E', 'F', }; _operatorChars = new Dictionary <char, string> { { '.', "Dot" }, { '=', "Equals" }, { '+', "Plus" }, { '-', "Minus" }, { '*', "Asterisk" }, { '/', "Slash" }, { '%', "Percent" }, { '&', "Ampersand" }, { '|', "Pipe" }, { '^', "Caret" }, { '~', "Tilde" }, { '<', "LeftAngle" }, { '>', "RightAngle" }, { '!', "Bang" }, { '?', "Question" }, { '@', "At" }, { '#', "Hash" }, { '$', "Dollar" }, { '\\', "Backslash" }, }; }