index.html 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>CodeMirror: EBNF Mode</title>
  5. <meta charset="utf-8"/>
  6. <link rel=stylesheet href="../../doc/docs.css">
  7. <link rel="stylesheet" href="../../lib/codemirror.css">
  8. <script src="../../lib/codemirror.js"></script>
  9. <script src="../javascript/javascript.js"></script>
  10. <script src="ebnf.js"></script>
  11. <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
  12. </head>
  13. <body>
  14. <div id=nav>
  15. <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
  16. <ul>
  17. <li><a href="../../index.html">Home</a>
  18. <li><a href="../../doc/manual.html">Manual</a>
  19. <li><a href="https://github.com/codemirror/codemirror">Code</a>
  20. </ul>
  21. <ul>
  22. <li><a href="../index.html">Language modes</a>
  23. <li><a class=active href="#">EBNF Mode</a>
  24. </ul>
  25. </div>
  26. <article>
  27. <h2>EBNF Mode (bracesMode setting = "javascript")</h2>
  28. <form><textarea id="code" name="code">
  29. /* description: Parses end executes mathematical expressions. */
  30. /* lexical grammar */
  31. %lex
  32. %%
  33. \s+ /* skip whitespace */
  34. [0-9]+("."[0-9]+)?\b return 'NUMBER';
  35. "*" return '*';
  36. "/" return '/';
  37. "-" return '-';
  38. "+" return '+';
  39. "^" return '^';
  40. "(" return '(';
  41. ")" return ')';
  42. "PI" return 'PI';
  43. "E" return 'E';
  44. &lt;&lt;EOF&gt;&gt; return 'EOF';
  45. /lex
  46. /* operator associations and precedence */
  47. %left '+' '-'
  48. %left '*' '/'
  49. %left '^'
  50. %left UMINUS
  51. %start expressions
  52. %% /* language grammar */
  53. expressions
  54. : e EOF
  55. {print($1); return $1;}
  56. ;
  57. e
  58. : e '+' e
  59. {$$ = $1+$3;}
  60. | e '-' e
  61. {$$ = $1-$3;}
  62. | e '*' e
  63. {$$ = $1*$3;}
  64. | e '/' e
  65. {$$ = $1/$3;}
  66. | e '^' e
  67. {$$ = Math.pow($1, $3);}
  68. | '-' e %prec UMINUS
  69. {$$ = -$2;}
  70. | '(' e ')'
  71. {$$ = $2;}
  72. | NUMBER
  73. {$$ = Number(yytext);}
  74. | E
  75. {$$ = Math.E;}
  76. | PI
  77. {$$ = Math.PI;}
  78. ;</textarea></form>
  79. <script>
  80. var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
  81. mode: {name: "ebnf"},
  82. lineNumbers: true,
  83. bracesMode: 'javascript'
  84. });
  85. </script>
  86. <h3>The EBNF Mode</h3>
  87. <p> Created by <a href="https://github.com/robertleeplummerjr">Robert Plummer</a></p>
  88. </article>
  89. </body>
  90. </html>