Castle: The best Real-Time/Embedded/HighTech language EVER. Attempt 2
修订版 | cad5904cfb4033e2d7eab3a479aea42e5d4296dd (tree) |
---|---|
时间 | 2022-05-19 19:35:08 |
作者 | Albert Mietus < albert AT mietus DOT nl > |
Commiter | Albert Mietus < albert AT mietus DOT nl > |
Updated Castle-Examples wiht Parsers: grammer is code! Not text. So one can't load a grammer (txt) into a Parser
@@ -1,6 +1,6 @@ | ||
1 | 1 | /* (C) Albert Mietus. Demo and test */ |
2 | 2 | |
3 | -from My_ExpressionParser import Fixed_ExpressionParser, Init_ExpressionParser, Port_ExpressionParser; | |
3 | +from My_ExpressionParser import ExpressionParser; | |
4 | 4 | |
5 | 5 | from std.data.grammars import Grammer, Rule, ID; |
6 | 6 | from std.algorithms.parser import PEG; |
@@ -14,10 +14,10 @@ | ||
14 | 14 | /*****************************************************************************************************/ |
15 | 15 | |
16 | 16 | |
17 | -implement ParserDemo.Fixed_ExpressionParser { | |
17 | +implement ParserDemo.ExpressionParser { | |
18 | 18 | |
19 | 19 | - Grammar: my_expression(){ |
20 | - // ToDo: logic expression: (&&,etc | |
20 | + // ToDo: logic expression, ect | |
21 | 21 | |
22 | 22 | Rule: expr; |
23 | 23 | Rule: atom_value, unary, exponentiation, multy_divide, add_minus; |
@@ -61,21 +61,24 @@ | ||
61 | 61 | self.parser = PEG(g); |
62 | 62 | } |
63 | 63 | |
64 | -} //End Fixed_ExpressionParser | |
64 | +} //End ExpressionParser | |
65 | 65 | /*****************************************************************************************************/ |
66 | 66 | |
67 | 67 | |
68 | -implement ParserDemo.Init_ExpressionParser { | |
69 | -- init(Grammer:g) { | |
70 | - self.parser = PEG(g); | |
71 | -} | |
72 | -} //End Init_ExpressionParser | |
68 | +/*GAM: THIS IS NOT POSSIBLE: Grammar's can not be "loaded" (dynamicly) | |
69 | + Each "rule" is basically a very short version of a function -- and as such static */ | |
70 | +//WRONG implement ParserDemo.Init_ExpressionParser { | |
71 | +//WRONG - init(Grammer:g) { | |
72 | +//WRONG self.parser = PEG(g); | |
73 | +//WRONG } | |
74 | +//WRONG } //End Init_ExpressionParser | |
73 | 75 | /*****************************************************************************************************/ |
74 | 76 | |
75 | - | |
76 | -implement ParserDemo.Port_ExpressionParser { | |
77 | -g on expression | |
78 | -{ | |
79 | - self.parser = PEG(g); | |
80 | -} | |
81 | -} //End Port_ExpressionParser | |
\ No newline at end of file | ||
77 | +/*GAM: THIS IS NOT POSSIBLE: Grammar's can not be "loaded" (dynamicly) | |
78 | + Each "rule" is basically a very short version of a function -- and as such static */ | |
79 | +//WRONG implement ParserDemo.Port_ExpressionParser { | |
80 | +//WRONG g on expression | |
81 | +//WRONG { | |
82 | +//WRONG self.parser = PEG(g); | |
83 | +//WRONG } | |
84 | +//WRONG } //End Port_ExpressionParser | |
\ No newline at end of file |
@@ -3,21 +3,22 @@ | ||
3 | 3 | from ParserDemo import Abstract_Parser, Base_ChunkParser; |
4 | 4 | from std.data.grammars import Grammer |
5 | 5 | |
6 | +/*NOTE: A grammar is always "hardcoded (so "Fixed"-- and as such the Fixed-prefix is useless | |
7 | + Each "rule" is basically a very short version of a function -- and as such static */ | |
8 | +component ExpressionParser : Abstract_Parser, Base_ChunkParser { | |
6 | 9 | |
7 | -component Fixed_ExpressionParser : Abstract_Parser, Base_ChunkParser { | |
8 | - """The Fixed_ExpressionParser has the grammer build-in; unlike the :ref:`Init_ExpressionParser` and :ref:`Port_ExpressionParser`""" | |
9 | 10 | } |
10 | 11 | |
11 | 12 | |
12 | 13 | |
13 | -component Init_ExpressionParser : Base_ExpressionParser { | |
14 | - """The Init_ExpressionParser reads the grammer when it is initialized""" | |
15 | -- init(Grammer:g) | |
16 | -} | |
14 | + | |
15 | +//WRONG component Init_ExpressionParser : Base_ExpressionParser { | |
16 | +//WRONG """The Init_ExpressionParser reads the grammer when it is initialized""" | |
17 | +//WRONG - init(Grammer:g) | |
18 | +//WRONG } | |
17 | 19 | |
18 | 20 | |
19 | - | |
20 | -component Port_ExpressionParser : Base_ExpressionParser { | |
21 | - """The Port_ExpressionParser reads the grammer via a port (unlike the :ref:`Fixed_ExpressionParser`.""" | |
22 | - port Grammar<in> expression; | |
23 | -} | |
21 | +//WRONG component Port_ExpressionParser : Base_ExpressionParser { | |
22 | +//WRONG """The Port_ExpressionParser reads the grammer via a port (unlike the :ref:`Fixed_ExpressionParser`.""" | |
23 | +//WRONG port Grammar<in> expression; | |
24 | +//WRONG } |