Mercurial
comparison .cms/lib/codemirror/mode/ebnf/index.html @ 0:78edf6b517a0 draft
24.10
author | Coffee CMS <info@coffee-cms.ru> |
---|---|
date | Fri, 11 Oct 2024 22:40:23 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:78edf6b517a0 |
---|---|
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 | |
8 <link rel="stylesheet" href="../../lib/codemirror.css"> | |
9 <script src="../../lib/codemirror.js"></script> | |
10 <script src="../javascript/javascript.js"></script> | |
11 <script src="ebnf.js"></script> | |
12 <style>.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> | |
13 </head> | |
14 <body> | |
15 <div id=nav> | |
16 <a href="https://codemirror.net/5"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png" alt=""></a> | |
17 | |
18 <ul> | |
19 <li><a href="../../index.html">Home</a> | |
20 <li><a href="../../doc/manual.html">Manual</a> | |
21 <li><a href="https://github.com/codemirror/codemirror5">Code</a> | |
22 </ul> | |
23 <ul> | |
24 <li><a href="../index.html">Language modes</a> | |
25 <li><a class=active href="#">EBNF Mode</a> | |
26 </ul> | |
27 </div> | |
28 | |
29 <article> | |
30 <h2>EBNF Mode (bracesMode setting = "javascript")</h2> | |
31 <form><textarea id="code" name="code"> | |
32 /* description: Parses end executes mathematical expressions. */ | |
33 | |
34 /* lexical grammar */ | |
35 %lex | |
36 | |
37 %% | |
38 \s+ /* skip whitespace */ | |
39 [0-9]+("."[0-9]+)?\b return 'NUMBER'; | |
40 "*" return '*'; | |
41 "/" return '/'; | |
42 "-" return '-'; | |
43 "+" return '+'; | |
44 "^" return '^'; | |
45 "(" return '('; | |
46 ")" return ')'; | |
47 "PI" return 'PI'; | |
48 "E" return 'E'; | |
49 <<EOF>> return 'EOF'; | |
50 | |
51 /lex | |
52 | |
53 /* operator associations and precedence */ | |
54 | |
55 %left '+' '-' | |
56 %left '*' '/' | |
57 %left '^' | |
58 %left UMINUS | |
59 | |
60 %start expressions | |
61 | |
62 %% /* language grammar */ | |
63 | |
64 expressions | |
65 : e EOF | |
66 {print($1); return $1;} | |
67 ; | |
68 | |
69 e | |
70 : e '+' e | |
71 {$$ = $1+$3;} | |
72 | e '-' e | |
73 {$$ = $1-$3;} | |
74 | e '*' e | |
75 {$$ = $1*$3;} | |
76 | e '/' e | |
77 {$$ = $1/$3;} | |
78 | e '^' e | |
79 {$$ = Math.pow($1, $3);} | |
80 | '-' e %prec UMINUS | |
81 {$$ = -$2;} | |
82 | '(' e ')' | |
83 {$$ = $2;} | |
84 | NUMBER | |
85 {$$ = Number(yytext);} | |
86 | E | |
87 {$$ = Math.E;} | |
88 | PI | |
89 {$$ = Math.PI;} | |
90 ;</textarea></form> | |
91 <script> | |
92 var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | |
93 mode: {name: "ebnf"}, | |
94 lineNumbers: true, | |
95 bracesMode: 'javascript' | |
96 }); | |
97 </script> | |
98 <h3>The EBNF Mode</h3> | |
99 <p> Created by <a href="https://github.com/robertleeplummerjr">Robert Plummer</a></p> | |
100 </article> | |
101 </body> | |
102 </html> |