For some one how has only knowledge on tree data structure Is it evident for him to write an Arithmetic Expressions parser without the help of compilation techniques ?
            Asked
            
        
        
            Active
            
        
            Viewed 1,478 times
        
    10
            
            
        - 
                    Your question may be too broad for Stackoverflow but, before one judges this, would you explain what you mean by "evident"? – thb Apr 27 '12 at 11:25
- 
                    Are you familiar with Expression Trees? – st0le Apr 27 '12 at 11:26
- 
                    1@thb "evident" means simple and eazy to write just using basic programming techniques, without learning advanced compilation conceptes – anouar.bagari Apr 27 '12 at 11:31
- 
                    @st0le i'm familiar with Trees data structure – anouar.bagari Apr 27 '12 at 11:32
- 
                    @anouar204, My 2cents. Learn to build an Expression Tree and then Evaluation will be very easy. Also Use Java Math Expression Parser (Open Source) to look up how it's done. – st0le Apr 27 '12 at 11:36
- 
                    I have heard somthing about grammar and lexical analysis, and need to know if those skilles are necessary to have a correct algorithm and not just plumbing, by plumbing i mean sothing like trying to browse a tree expression without knowledge about recursivity – anouar.bagari Apr 27 '12 at 12:00
- 
                    possible duplicate of [Writing a simple equation parser](http://stackoverflow.com/questions/4582398/writing-a-simple-equation-parser) – Saeed Amiri Apr 27 '12 at 12:54
- 
                    @st0le I have never used Java Math Expression Parser. Can it handle operator associativity and precedence? If not, then does the OP require operator associativity and precedence? – Guy Coder Apr 27 '12 at 13:09
- 
                    1possible duplicate of [Equation (expression) parser with precedence?](http://stackoverflow.com/questions/28256/equation-expression-parser-with-precedence) – Adrian McCarthy Apr 27 '12 at 16:20
2 Answers
2
            Without knowledge of compilation techniques it would be ugly. But there is no need to learn a ton of compilation for an introductory example like this.
Look at something like http://www.codeproject.com/Articles/345888/How-to-write-a-simple-interpreter-in-JavaScript and see if it makes sense to you.
 
    
    
        btilly
        
- 43,296
- 3
- 59
- 88
1
            
            
        See my SO answer on how to write top down recursive descent parsers. This method is very easy for expressions.
 
    
    
        Community
        
- 1
- 1
 
    
    
        Ira Baxter
        
- 93,541
- 22
- 172
- 341
