Cemo
Cemo

Reputation: 5570

Grammar for parsing numbers

I have a file in which each line represents a concatenated String series as this:

302007030064201410241 
30210704006426141
1021070400642614134

Each line starts with operation code and each operation has a known rules to parse remaining part of the line.

What will be the good strategy to parse these numbers? Any sample for start would be great.

Upvotes: 0

Views: 110

Answers (1)

Seki
Seki

Reputation: 11465

IMO, Antlr wont be much usefull if all different informations to parse look like all token are identical.

Write manually a little state machine.

  • Read a digit in loop until that digit and predecessors result in a know "operation code" (it could be simpler if all codes have the same lenght: you could wrap that in a function)

  • then depending on that code (e.g. in a switch) you can call its specific decoding logic in a dedicated function.

Your resulting parser will look like a recursive descent parser.

Upvotes: 1

Related Questions