Once ago we have created an incremental parser, and now when we have decided to load COBOL sources directly into cobolxom (XML Object Model for a COBOL) the parser did the job perfectly.
The good point about incremental parser is that it easily handles COBOL's grammar.
The whole process looks like this:
This is an example of a COBOL:
IDENTIFICATION DIVISION. PROGRAM-ID. FACTORIAL RECURSIVE. DATA DIVISION. WORKING-STORAGE SECTION. 01 NUMB PIC 9(4) VALUE IS 5. 01 FACT PIC 9(8) VALUE IS 0. LOCAL-STORAGE SECTION. 01 NUM PIC 9(4). PROCEDURE DIVISION. MOVE 'X' TO XXX MOVE NUMB TO NUM IF NUMB = 0 THEN MOVE 1 TO FACT ELSE SUBTRACT 1 FROM NUMB CALL 'FACTORIAL' MULTIPLY NUM BY FACT END-IF DISPLAY NUM '! = ' FACT GOBACK. END PROGRAM FACTORIAL.
And a grammar tree:
<Program> <Name data="FACTORIAL"/> <Recursive/> <DataDivision> <WorkingStorageSection> <Data> <Level data="01"/> <Name data="NUMB"/> <Picture data="9(4)"/> <Value> <Numeric data="5"/> </Value> </Data> <Data> <Level data="01"/> <Name data="FACT"/> <Picture data="9(8)"/> <Value> <Numeric data="0"/> </Value> </Data> </WorkingStorageSection> <LocalStorageSection> <Data> <Level data="01"/> <Name data="NUM"/> <Picture data="9(4)"/> </Data> </LocalStorageSection> </DataDivision> <ProcedureDivision> <Sentence> <MoveStatement> <From> <String data="'X'"/> </From> <To> <Identifier> <DataName data="XXX"/> </Identifier> </To> </MoveStatement> <MoveStatement> <From> <Identifier> <DataName data="NUMB"/> </Identifier> </From> <To> <Identifier> <DataName data="NUM"/> </Identifier> </To> </MoveStatement> <IfStatement> <Condition> <Relation> <Identifier> <DataName data="NUMB"/> </Identifier> <Equal/> <Numeric data="0"/> </Relation> </Condition> <Then> <MoveStatement> <From> <Numeric data="1"/> </From> <To> <Identifier> <DataName data="FACT"/> </Identifier> </To> </MoveStatement> </Then> <Else> <SubtractStatement> <Value> <Numeric data="1"/> </Value> <From> <Identifier> <DataName data="NUMB"/> </Identifier> </From> </SubtractStatement> <CallStatement> <Name> <String data="'FACTORIAL'"/> </Name> </CallStatement> <MultiplyStatement> <Value> <Identifier> <DataName data="NUM"/> </Identifier> </Value> <By> <Identifier> <DataName data="FACT"/> </Identifier> </By> </MultiplyStatement> </Else> </IfStatement> <DisplayStatement> <Values> <Identifier> <DataName data="NUM"/> </Identifier> <String data="'! = '"/> <Identifier> <DataName data="FACT"/> </Identifier> </Values> </DisplayStatement> <GobackStatement/> </Sentence> </ProcedureDivision> <EndName data="FACTORIAL"/> </Program>
The last step is to transform tree into cobolxom is in the TODO list.
We have commited COBOL grammar in the same place at SourceForge as it was with XQuery grammar. Solution is now under the VS 2010.
Remember Me
a@href@title, b, blockquote@cite, em, i, strike, strong, sub, super, u