rochus-keller / EbnfStudio

EbnfStudio can be used to edit and analyze EBNF grammars.
GNU General Public License v2.0
65 stars 10 forks source link

QT's fonts #6

Closed aanastasiou closed 9 months ago

aanastasiou commented 9 months ago

Hello

Thank you for Ebnfstudio.

The application runs fine but unfortunately it fails to find ~/.fonts. Consequently, no text is rendered. Is there a QT package I could bring in or should I locate them one by one and somehow transfer them to my system?

rochus-keller commented 9 months ago

Welcome. I assume you built it with BUSY and LeanQt? It's probably easiest if you just create a .font directory in your home directory and put a ttf file there (or showing the font with the font viewer and press the "add font" button has the same effect). Or you can build EbnfStudio using regular Qt and the .pro file. Otherwise the font has to be loaded on startup from a file or the resources (.qrc), as done e.g. here: https://github.com/rochus-keller/ActiveOberon/blob/3b3f755e18c630dccb77a27d62aa213d54945dde/AoCodeNavigator.cpp#L864

aanastasiou commented 9 months ago

...you built it with BUSY and LeanQt?

Absolutely. And still hope I don't have to install a 4-6GB installation of qt6 :)

Thank you very much, that suggestion worked.

rochus-keller commented 9 months ago

Welcome. I'm not even sure whether my programs compile with Qt6 (never tried so far, and likely won't).

aanastasiou commented 9 months ago

I am not inclined to try either :D

One more side question: Would it be possible to point me towards the EBNF variant that EbnfStudio uses? I can see that defs are ::= but I was wondering what the complete syntax would be.

rochus-keller commented 9 months ago

Documentation is unfortunately lacking. EbnfStudio is still work in progress, even if I use it regularly.

Here are some snippets from the EbnfParser.cpp file:

// factor ::= keyword | delimiter | nonterm | "[" expression "]" | "{" expression "}" | "(" expression ")"
// expression ::= term { "|" term }
// term ::= [ predicate ] factor { factor }

Predicates so far are \LL:2\ or something constructed from this syntax:

la_expr ::= la_term { '|' la_term }
   la_term ::= la_factor { '&' la_factor }
   la_factor ::= Index ':' factor | '(' la_expr ')'
   expression ::= term { '|' term }
   term ::= factor { '&' factor }
   factor ::= String | Literal | '!' factor | '(' expression ')'

There are a lot of examples around, nearly all of my parsers use an EbnfStudio syntax. E.g.

https://github.com/rochus-keller/FreePascal/blob/master/syntax/FreePascal.ebnf

https://github.com/rochus-keller/ActiveOberon/blob/master/Ao.ebnf

https://github.com/rochus-keller/Simula/blob/master/syntax/Simula67.ebnf

https://github.com/rochus-keller/Oberon/blob/master/syntax/Oberon.ebnf

aanastasiou commented 9 months ago

Alright, so, almost in order of appearance in the FreePascal EBNF:

So far so good I think. But then, there are things like use of / ... / as in \LA: 1:ident & 2:('=' | ':') \. Is that literal to be dropped as is in the underlying target? (e.g. ANTLR).

Have I caught everything, at least at a user level (?)

rochus-keller commented 9 months ago

Looks correct. Note that there is also a .keywords file.

are things like use of / ... / as in \LA: 1:ident & 2:('=' | ':') . Is that literal to be dropped as is in the underlying target? (e.g. ANTLR).

No, the syntax actually generates corresponding prefixes in the parser language. Originally I used Coco/R and you can still generate Coco/R files. But I noticed that Coco/R has some bugs which in some cases lead to wrong parser tables. And I also didn't like the necessity of .frame files. So I implemented my own parser generator and use this one for most of my projects since a year. The LA: example you mentioned then leads to an if or while statement in the parser code, in your example checking that first lookahead is an ident and second lookahead is either an equal or colon symbol.

aanastasiou commented 9 months ago

Great, how about things like

ident ::=
unsigned_real ::=
decimal_int ::= // digit sequence
hex_int ::=  // $ hex digit sequence
octal_int ::= // & octal digit sequence
binary_int ::= // % bin digit sequence

Are these definitions "pulled" from somewhere else?

Are ranges parsed correctly? (e.g. {'a'-'z'})

(EDIT: Sorry, that's a lot of things :( What about lhs* ::= rhs, what does the * denote on the lhs?)

rochus-keller commented 9 months ago

EbnfStudio doesn't generate lexers nor cares about lexer productions.

If you just write something like ident ::= or hex_int ::= it generates corresponding tokens in the token type header, prefixed by Tok_, which you can use in the lexer. Nothing else.

What about lhs ::= rhs, what does the denote on the lhs?

As far as I remember this is to suppress lhs in the generated syntax tree; instead only rhs will be present wherever a syntax tree node of lhs would be.

aanastasiou commented 9 months ago

Great, thank you very much for your help.