Allegro.cc - Online Community

Allegro.cc Forums » Off-Topic Ordeals » C++ parsing libraries for symbolic input.

Credits go to axilmar and Tobias Dammers for helping out!
This thread is locked; no one can reply to it. rss feed Print
 1   2 
C++ parsing libraries for symbolic input.
Tobias Dammers
Member #2,604
August 2002
avatar

Get your quotes right.

Also, I believe your original argument went something like this: If I fail to provide an implementation of Java-style event listeners in Haskell, then it logically follows that Haskell is less suitable for implementing parsers than C++.

Yeah, makes perfect sense.

Oh, and for the record: In your example, the view doesn't really observe the model either. It merely passes a bunch of callbacks into the model, and then the model updates the view. Technically speaking.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

axilmar
Member #1,204
April 2001

First of all, the wikipedia article says:

Quote:

2. the View, which observes the state.

So, my quotes are correct.

Secondly, you are wrong, my request for the MVC pattern in Haskell has nothing to do with parsers. I am really curious on how to do the MVC pattern in Haskell, that's just all there is.

Thirdly, in my example, it is the View class that installs the callbacks in the Model, so, the View really observes the Model.

With all this in mind, can you show me how to do the MVC pattern with observers in Haskell or not?

LennyLen
Member #5,313
December 2004
avatar

axilmar said:

So, my quotes are correct.

No, because you said the view observes the model. The article actually says that the view observes the state of the application, and the model is just a representation of the state, not the state itself.

axilmar
Member #1,204
April 2001

The Wikipedia article says that the Model represents the application's state, and the View observes the application's state. So, Model = State and the View observes the Model, which is actually how MVC is implemented in every language.

Arvidsson
Member #4,603
May 2004
avatar

It seems we're getting down to semantics. Who would've thought? :)

verthex
Member #11,340
September 2009
avatar

I tried downloading Antlr 2.7 and I found the calc example a little confusing. There's a file named calc.g shown below, how do this get compiled with the MAIN.cpp file? I'm using codeblocks btw...

#SelectExpand
1options { 2 language="Cpp"; 3} 4 5class CalcParser extends Parser; 6options { 7 buildAST = true; // uses CommonAST by default 8} 9 10expr 11 : mexpr (PLUS^ mexpr)* SEMI! 12 ; 13 14mexpr 15 : atom (STAR^ atom)* 16 ; 17 18atom: INT 19 ; 20 21class CalcLexer extends Lexer; 22 23WS_ : (' ' 24 | '\t' 25 | '\n' 26 | '\r') 27 { _ttype = ANTLR_USE_NAMESPACE(antlr)Token::SKIP; } 28 ; 29 30LPAREN: '(' 31 ; 32 33RPAREN: ')' 34 ; 35 36STAR: '*' 37 ; 38 39PLUS: '+' 40 ; 41 42SEMI: ';' 43 ; 44 45protected 46DIGIT 47 : '0'..'9' 48 ; 49 50INT : (DIGIT)+ 51 ; 52 53class CalcTreeWalker extends TreeParser; 54 55expr returns [float r] 56{ 57 float a,b; 58 r=0; 59} 60 : #(PLUS a=expr b=expr) {r = a+b;} 61 | #(STAR a=expr b=expr) {r = a*b;} 62 | i:INT {r = atof(i->getText().c_str());} 63 ;

Matthew Leverton
Supreme Loser
January 1999
avatar

axilmar said:

How about this?

g++ 4.6.3 on Ubuntu has problems with the latest source due to not and and. Using the previous commit works.

Also had to change line 98 of the calculator:

diff --git a/examples/calculator/calculator.cpp b/examples/calculator/calculator
index 7c8fa18..ea0e6c6 100644
--- a/examples/calculator/calculator.cpp
+++ b/examples/calculator/calculator.cpp
@@ -95,7 +95,7 @@ class binary_expr_t : public expr_t {
 public:
     ast_ptr<expr_t> left, right;
 
-    virtual void print(int depth, int tab) const = 0 {
+    virtual void print(int depth, int tab) const {
         left->print(depth);
         right->print(depth);

axilmar
Member #1,204
April 2001

Jesus H. Christ, I thought I knew all of c++!!! TIL that the words 'not' and 'and' are reserved keywords, as alternatives to operators!

It's part of the C++03 standard, section 2.5.

I fixed the code, thanks Matthew.

 1   2 


Go to: