I am going to write a text editor in Qt which can provide highlighting/code completion/syntax analyzing for a programming language (toy language, for learning purpose).
At first, I thought of writing handcraft C++, which would be more comfortable for me since I’m more familiar. However, upon searching, I found out that flex/bison can simplify parser creation. Upon trying a few simple example, it seems the working examples accept input from standard input in terminal. So, I just want to know, can flex/bison accept input from the text editor widget in GUI framework (such as Qt, which I’m going to learn at the same time after I finish a few features in the parser engine), then later output the result back to the text editor?
flex reads its input from
yyin. If you point it to something that is notstdin… See here for example.Edit: btw,
yyinis aFILE *. You’re using C++, which means you’d want to pass a stream instead. Please, read flex’s documentation on C++ interfacingEdit2: for the output… you’re the one programming yacc/bison actions for the rules, and also the error handler. In that sense, you’re given quite some freedom on what to do there. For example, you can “emit” highlighted code and also use the error handlers to point errors when analyzing the code. The completion would force you to implement at least part of the semantics (symbol table, etc), but that’s a different story…