1

I am implementing terminal emulator similar to default terminal emulator for OSX: Terminal.app.

I open terminal connection with openpty and then use Flex to parse incoming input: normal text and control sequences and Bison which calls callbacks based on tokens produced by Flex (insert string, cursor forward sequence etc).

  1. Along with normal text tokens I have implemented around 30 escape sequences without any outstanding problems.
  2. I made Flex/Bison re-entrant because I needed multiple terminal windows to work simultaneously
  3. I did some workarounds to make Flex/Bison to read continuous output based on my another question: How to detect partial unfinished token and join its pieces that are obtained from two consequent portions of input?.

So far it looks like Flex/Bison do their job, however I suspect that sooner or later I will encounter something that reveals the fact that Flex/Bison should not be used as a tool to parse terminal input.

The question is: what are the problems that Flex/Bison can cause if they are used instead of hand-written parser for terminal input? Can performance be a concern?

Community
  • 1
  • 1
Stanislav Pankevich
  • 11,044
  • 8
  • 69
  • 129
  • It's overkill. To You don't need a DPDA. You can do it all with an NFA/DFA. The most complex terminal language Inknow is 3270 and it is 'simply ' a large state machine. – user207421 Apr 24 '16 at 21:09
  • @EJP, could you please make your answer more explicit? It maybe overkill but so far it does it job: I can write grammar instead of hand-written parser and it seems to be easier way. Overkill in terms of performance? Also unfortunately I don't know anything about DPDA, NFA/DFA at the moment so that is something you could also expand on. Thanks. – Stanislav Pankevich Apr 25 '16 at 09:57
  • Please imagine that you're talking to a much less experienced audience. – Stanislav Pankevich Apr 25 '16 at 09:59
  • Flex is a DFA. Bison is a DPDA. There is no nested syntax here so n need for a stack so no need for a DPDA, and Bison's look ahead will get in your way. – user207421 May 05 '16 at 22:13

1 Answers1

2

Abbreviations are sometimes helpful:

What @ejp is saying is that bison is not needed in your solution because there is only one way that the tokens from lexical analyzer can be interpreted. The stack which was mentioned is used for saving the state of the machine while looking at the alternative ways that the input can be interpreted.

In considering whether flex (and possibly bison) would be a good approach, I would be more concerned with how you are going to solve the problem of control characters which can be interspersed within control sequences.

Further reading:

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105