Module: Trxl::HelpFunction0

Defined in:
lib/trxl/trxl_grammar.rb

Instance Method Summary collapse

Instance Method Details

#eval(env = Environment.new) ⇒ Object



4729
4730
4731
# File 'lib/trxl/trxl_grammar.rb', line 4729

def eval(env = Environment.new)
  to_s(env)
end

#to_s(env = Environment.new) ⇒ Object



4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
# File 'lib/trxl/trxl_grammar.rb', line 4733

def to_s(env = Environment.new)
  help =  "-----------------------------------------\n"
  help =  "           TRXL Language HELP            \n"
  help =  "-----------------------------------------\n"
  help << "1)  Built in operators:\n"
  help << "    +,-,*,/,%,==,!=,<=,>=,<,>,;\n"
  help << "-----------------------------------------\n"
  help << "2)  Integers and floats in arithmetics:\n"
  help << "    1 or 2.33333 or 0.34 or .34\n"
  help << "-----------------------------------------\n"
  help << "3)  Arbitrary nesting of parentheses:\n"
  help << "    (1+2*(5+((3+4)*3)-6/2)+7*2)\n"
  help << "    => 61\n"
  help << "-----------------------------------------\n"
  help << "4)  Comments:\n"
  help << "    # A comment until the end of the line\n"
  help << "    /* A longer comment that\n"
  help << "       spans multiple lines\n"
  help << "     */\n"
  help << "-----------------------------------------\n"
  help << "5)  Built in keywords:\n"
  help << "    TRUE,FALSE,NULL,IF,ELSE,END\n"
  help << "-----------------------------------------\n"
  help << "6)  Built in functions:\n"
  help << "    HELP,ENV,SIZE,SPLIT,ROUND,MIN,MAX\n"
  help << "    SUM,MULT,AVG, PRINT, PRINT_LINE\n"
  help << "    TO_INT, TO_FLOAT, TO_ARRAY\n"
  help << "-----------------------------------------\n"
  help << "7)  Standard library functions:\n"
  help << "    Use to iterate over Arrays or Strings\n"
  help << "    FOREACH_IN, INJECT\n"
  help << "-----------------------------------------\n"
  help << "8)  Access the current environment:\n"
  help << "    ENV; (your output may differ)\n"
  help << "    => { :a => 3, :foo => 5 }\n"
  help << "    Given the following environment:\n"
  help << "    { :a => 1, :b => 2, :c => 3 }\n"
  help << "    ENV['a']\n"
  help << "    => 1\n"
  help << "    ENV['a'..'b']\n"
  help << "    => { :a => 1, :b => 2 }\n"
  help << "-----------------------------------------\n"
  help << "9)  Numeric variables and literals\n"
  help << "    3;\n"
  help << "    => 3\n"
  help << "    a = 3;\n"
  help << "    => 3\n"
  help << "    a;\n"
  help << "    => 3\n"
  help << "-----------------------------------------\n"
  help << "10) String variables and literals\n"
  help << "    \"This is a string\";\n"
  help << "    => \"This is a string\";\n"
  help << "    'This is a string';\n"
  help << "    => \"This is a string\";\n"
  help << "    s1 = \"This is a string\"; s1;\n"
  help << "    => \"This is a string\"\n"
  help << "    s2 = 'This is a string'; s2;\n"
  help << "    => \"This is a string\"\n"
  help << "    SIZE(s1);\n"
  help << "    => 16\n"
  help << "    SIZE(\"foo\");\n"
  help << "    => 3\n"
  help << "-----------------------------------------\n"
  help << "11) Variables and closure applications\n"
  help << "    a = 3; foo = 5;\n"
  help << "    calc = fun(x,y) { (x + y) * a + foo };\n"
  help << "    calc(2,2);\n"
  help << "    => 17\n"
  help << "-----------------------------------------\n"
  help << "12) Array variables and literals\n"
  help << "    arr = [1, [fun(){2}()], fun(x){x}(3)]\n"
  help << "    SIZE(arr);\n"
  help << "    => 3\n"
  help << "    SIZE([1,2,3]);\n"
  help << "    => 3\n"
  help << "    [1,2,3] + [4,[5,6]];\n"
  help << "    => [1,2,3,4,[5,6]]\n"
  help << "    [1,2,3] - [[1],2,3];\n"
  help << "    => [1]\n"
  help << "-----------------------------------------\n"
  help << "13) Hash variables and literals\n"
  help << "    h = { 1 => fun(){2}(), 'a' => 'foo' }\n"
  help << "    SIZE(h);\n"
  help << "    => 2\n"
  help << "    h[1];\n"
  help << "    => 'fun(){2}()'\n"
  help << "    h['a'];\n"
  help << "    => 'foo'\n"
  help << "    SIZE({ 1 => 2});\n"
  help << "    => 1\n"
  help << "-----------------------------------------\n"
  help << "14) Range variables and literals\n"
  help << "    range_including_upper = 1..5\n" 
  help << "    => [ 1, 2, 3, 4, 5 ]\n" 
  help << "    SIZE(range_including_upper);\n"
  help << "    => 5\n"
  help << "    range_excluding_upper = 1...5\n"
  help << "    => [ 1, 2, 3, 4 ]\n" 
  help << "    SIZE(range_excluding_upper);\n"
  help << "    => 4\n"
  help << "    SIZE([1..5);\n"
  help << "    => 5\n"
  help << "-----------------------------------------\n"
  help << "15) Conditional branching and recursion:\n"
  help << "    factorial = fun(x) {\n"
  help << "      if(x == 0)\n" 
  help << "        1\n" 
  help << "      else\n"
  help << "        x * factorial(x - 1)\n"
  help << "      end\n"
  help << "    }\n"
  help << "    factorial(5);\n"
  help << "    => 120\n"
  help << "-----------------------------------------\n"
  help << "16) Conditional branching:\n"
  help << "    foo = fun(x) {\n"
  help << "      if(x == 0)\n" 
  help << "        0\n" 
  help << "      elsif(x == 1)\n"
  help << "        1\n"
  help << "      else\n"
  help << "        2\n"
  help << "      end\n"
  help << "    }\n"
  help << "    foo(0);\n"
  help << "    => 0\n"
  help << "    foo(1);\n"
  help << "    => 1\n"
  help << "    foo(2);\n"
  help << "    => 2\n"
  help << "-----------------------------------------\n"
  help << "17) case expressions:\n"
  help << "    foo = fun(x) {\n"
  help << "      case x\n" 
  help << "        when 0 then 0\n" 
  help << "        when 1 then 1\n" 
  help << "        when 2 then 2\n" 
  help << "        else 3\n"
  help << "      end\n"
  help << "    }\n"
  help << "    foo(1);\n"
  help << "    => 1\n"
  help << "    foo(3);\n"
  help << "    => 3\n"
  help << "-----------------------------------------\n"
  help
end