spirit Grammatik



  • hey,

    schreib grad an einem parser der eine Assembler ähnliche sprache einlesen soll natürlich im umfang stark reduziert. Ich hab auch eine erste version fertig nur muss der code linear nacheinander ablaufen das heißt die Eingabe sieht zurzeit so aus

    DAT.F   #0, #0     ; Pointer to target instruction.
    ADD.AB  #4, $-1    ; Increments pointer by step.
    MOV.AB  #0, @-2    ; Bombs target instruction.
    JMP.A   $-2, #0    ; Loops back two instructions.
    

    Ich will jetzt aber auch mit dem wort ORG("ORiGin") den Startpunkt setzen und mit END das ende außerdem will ich referencen oder aliases benutzen können. Also ich möchte mit EQU("EQUate") ein alias setzten bzw. "Name EQU alias". hier ein Bsp.:

    step    EQU      4
    

    Ich benutze die spirit lib und hier ist meine Grammatik:

    definition( Redcode const &self )
            {
    
    		 assembly_file = 
      	        +line
    				;
    		 line = 
    			 instruction
    				;
             instruction =
                 opcode >> '.' >> modifier >> mode >> number >> ',' >> mode >> number
    				;
             opcode =
    			 boost::spirit::str_p("DAT") | boost::spirit::str_p("MOV") | boost::spirit::str_p("ADD") | 
    			 boost::spirit::str_p("SUB") | boost::spirit::str_p("MUL") | boost::spirit::str_p("DIV") | 
    			 boost::spirit::str_p("MOD") | boost::spirit::str_p("JMP") | boost::spirit::str_p("JMZ") | 
    			 boost::spirit::str_p("JMN") | boost::spirit::str_p("DJN") | boost::spirit::str_p("CMP") | 
    			 boost::spirit::str_p("SLT") | boost::spirit::str_p("SPL") | boost::spirit::str_p("ORG") | 
    			 boost::spirit::str_p("EQU") | boost::spirit::str_p("END") 
    				;
             modifier =
    			 boost::spirit::str_p("BA") | boost::spirit::str_p("AB") | boost::spirit::ch_p('A') | 
                 boost::spirit::ch_p('B')   | boost::spirit::ch_p('F')   | boost::spirit::ch_p('X') | 
    			 boost::spirit::ch_p('I') 
    				 ;
             mode =  
    			 boost::spirit::ch_p('#') | boost::spirit::ch_p('$') | boost::spirit::ch_p('@') | 
                 boost::spirit::ch_p('<') | boost::spirit::ch_p('>')
    				;
             number = 
    			 boost::spirit::int_p
    				;
    		 alphanumeral =
    			 boost::spirit::alnum_p
    				;
    }
    ...
            boost::spirit::rule<ScannerT, boost::spirit::parser_context<>, boost::spirit::parser_tag<assembly_fileID> > const&
    		start() const { return assembly_file; }
    

    hoffe ihr könnt mir weiterhelfen 🙂



  • wo _genau_ liegt dein problem?



  • ich weiß nicht wie ich die Grammatik erweitern soll, damit die funktion implementiert wird.



  • ich weis zwar immernoch nichts über deine gedankengänge und wo es hakt, aber ich mach mal nen schuss ins blaue:

    http://www.boost.org/libs/spirit/doc/symbols.html



  • die antwort kommt einbisschen spät aber besser als nie 😉

    wollt mich nur für die antwort bedanken


Anmelden zum Antworten