moving from classical lex/yacc to pegged parser
Using lex/yacc I can do a more or less complex things in .yacc semantic actions, such complex as bytecode compilation or real CPU assembly. Playing with `pegged`, I can't figure out how to move from `ParseTree` to such like semantic actions. I even can't parse numbers from strings in lexer-like rules because it looks like every rule runs on any token parse, or sumething like this. Also, I use attribute object trees resemble attribute grammar both for parsing and internal code representation: ```C++ class Object { string value; // or `int value` and `float value` for numbers map attr; vector nested; } ``` And I also can't figure out how to inherit `ParseTree` with all my script language objects to get AST right from pegged parser. Should I use some superloop with lot of matches to process parsed `pt` tree into something I need myself, to drop all unneeded parsing meta info and get clean semantic AST?
Re: D is nice whats really wrong with gc??
It's called GC phobia, a knee-jerk reaction malady common among C/C++ programmers I'd like to use D in hard realtime apps (gaming can be thought as one of them, but I mostly mean realtime dynamic multimedia and digital signal processing). So, GC in such applications commonly supposed unacceptable. In contrast, I can find some PhD theses speaking about realtime GC, prioritized message passing and maybe RDMA-based clustering. Unfortunately, I have no hope that D lang is popular enough that somebody in the topic can rewrite its runtime and gc to be usable in more or less hard RT apps.
[vibe] what's wrong with linking time of vibe applications?
D lang noted as having a very fast compilation time. Playing with tiny web-interface apps I found that modern versions of dmd & vibe has such a fast compiling but a very long executable linking time. Something like 2-3 seconds of compiling stage (with vibe prebuilt), and 24 seconds of total build time ``` dponyatov@i7:~/wad$ time dub build ``` ``` Pre-gen Running commands for openssl Starting Performing "debug" build using /usr/bin/dmd for x86_64. Up-to-date fswatch 0.6.1: target for configuration [library] is up to date. Up-to-date mir-linux-kernel 1.0.1: target for configuration [library] is up to date. Up-to-date taggedalgebraic 0.11.22: target for configuration [library] is up to date. Up-to-date eventcore 0.9.27: target for configuration [epoll] is up to date. Up-to-date stdx-allocator 2.77.5: target for configuration [library] is up to date. Up-to-date vibe-container 1.0.1: target for configuration [library] is up to date. Up-to-date vibe-core 2.6.0: target for configuration [epoll] is up to date. Up-to-date vibe-d:crypto 0.9.7: target for configuration [library] is up to date. Up-to-date vibe-d:utils 0.9.7: target for configuration [library] is up to date. Up-to-date vibe-d:data 0.9.7: target for configuration [library] is up to date. Up-to-date diet-ng 1.8.1: target for configuration [library] is up to date. Up-to-date vibe-d:stream 0.9.7: target for configuration [library] is up to date. Up-to-date vibe-d:textfilter 0.9.7: target for configuration [library] is up to date. Up-to-date vibe-d:inet 0.9.7: target for configuration [library] is up to date. Up-to-date vibe-d:tls 0.9.7: target for configuration [openssl] is up to date. Up-to-date vibe-d:http 0.9.7: target for configuration [library] is up to date. Up-to-date vibe-d:mail 0.9.7: target for configuration [library] is up to date. Up-to-date vibe-d:mongodb 0.9.7: target for configuration [library] is up to date. Up-to-date vibe-d:redis 0.9.7: target for configuration [library] is up to date. Up-to-date vibe-d:web 0.9.7: target for configuration [library] is up to date. Up-to-date vibe-d 0.9.7: target for configuration [library] is up to date. Building wad ~shadow: building configuration [application] Compiling Diet HTML template index.dt... Compiling Diet HTML template about.dt... Compiling Diet HTML template error.dt... Linking wad Finished To force a rebuild of up-to-date targets, run again with --force ``` ``` real0m24.748s user0m19.133s sys 0m2.565s ```
pegged: non@safe semantic actions
What's wrong with using non@safe actions which creates and modifies some external objects? ```D class Layer { int index; string name; this(int index, string name) { class SignalLayer : Layer { class UserLayer : Layer { class PCB { Layer[] layer; PT _deflayer(PT)(PT p) { auto index = to!int(p.matches[0]); switch (p.matches[2]) { case "signal": pcb.layer ~= new SignalLayer(index, p.matches[1]); break; case "user": pcb.layer ~= new UserLayer(index, p.matches[1]); break; default: break; } return p; } mixin(grammar(` parser: kicad_pcb < :l :'kicad_pcb' verzion host general page layers layers< :l :'layers' (deflayer {_deflayer})+ :r deflayer < :l unum layer ('signal'|'user') :r ``` ``` ../.dub/packages/pegged/0.4.9/pegged/pegged/peg.d(3049,19): Error: `@safe` function `pegged.peg.action!(wrapAround, _deflayer).action` cannot call `@system` function `kicad._deflayer!(ParseTree)._deflayer` src/kicad.d(27,5):which calls `kicad.SignalLayer.this` src/kicad.d(68,4):`kicad._deflayer!(ParseTree)._deflayer` is declared here src/kicad.d-mixin-83(219,289): Error: template instance `pegged.peg.action!(wrapAround, _deflayer)` error instantiating src/kicad.d-mixin-83(932,7):instantiated from here: `Genericparser!(ParseTree)` ../.dub/packages/pegged/0.4.9/pegged/pegged/peg.d(544,20): Error: none of the overloads of `layers` are callable using argument types `(GetName)` src/kicad.d-mixin-83(215,23):Candidates are: `kicad.Genericparser!(ParseTree).Genericparser.parser.layers(ParseTree p)` src/kicad.d-mixin-83(234,23): `kicad.Genericparser!(ParseTree).Genericparser.parser.layers(string s)` ../.dub/packages/pegged/0.4.9/pegged/pegged/peg.d(1598,24): Error: template instance `pegged.peg.getName!(layers)` error instantiating src/kicad.d-mixin-83(183,436):instantiated from here: `wrapAround!(named, layers, named)` src/kicad.d-mixin-83(932,7):instantiated from here: `Genericparser!(ParseTree)` ```
compile-time gremlin/ql across pegged parse trees
Is anybody tried to implement some query-like adds for Dlang for making data selection from some data structures such as object graphs or trees (at least for pegged parsed data) ? I'm writing tiny tool for KiCAD (EDA CAD), and it would be great to have some tool to write easy-readable declarative-like code for data selections/conversions in memory. Or maybe someone can recommend book or tutorial about writing object graph traversals, backtracking and matching in C++ to let me make some elements myself?
Re: Compiling an app to a single binary - possible?
Theoretically possible but not really expected to and generally does not give you much over simply distributing an archive. I'd even discourage it because it makes impossible to delegate handling of static assets to reverse proxy like nginx (which is likely to do better job at it being specialized tool) Is vibe-powered backend app really runs notably slower then `nginx` when serving static files? I looked on D lang in web backend as a great alternative for mainstream servers such as `nginx` etc especially with its ability to serve files the the same rates or even more faster. Not for a large sites but mostly embedded application such as vending machines with local-only web interface, or powerful SOHO routers and home automation controllers. Putting all files into an executable also makes it available directly from RAM without any caching, so `sendfile` syscall can be just run for them with direct data pointer, almost without impacting on the app does anything else.
Re: any chance to get it working on windows xp?
With no testing on XP, you are bound to run into difficulties trying to use the tools there. The problem looks mostly not in WinXP-hosted compiler and tools, but in core and side libraries support such as `druntime`, `phobos`, etc. As a sample, I can use LDC for cross-compiling from Linux for `win32-i486` target, but next I'll be stucked on core libs that block me the same as using cross-D on non-glib Linux systems.
Re: Symbolic computations in D
What are semantic limitations you talking about? lack of pattern matching as example, which can tend to lots of ugly code
Re: What parser generator can let me run arbitrary code in its match rules?
Or maybe someone advice me some set of books deeply targets for learning of binary and symmetric parsing (such as binpac), DCG in C or using generators in D, etc to let me write my own lib. Everething I found (besides the Dragon book) uses black magic with Haskell, Lisp etc.
What parser generator can let me run arbitrary code in its match rules?
- not abandoned years ago - documentation and commented samples presenets - CTFE the best
Symbolic computations in D
Yesterday some student asked me about ability to make some dumb symbolic computation in C++ the same like way as it looks in the MathCAD or Maxima CAS, but run it compiled on a robot platform in realtime. I have no idea about CAS design and internals, or any math at all, but today I found some book: - _Tan Kiat Shi, Willi-Hans Steeb and Yorick Hardy_ **SymbolicC++: An Introduction to Computer Algebra using Object-Oriented Programming and** - **Computer Algebra with SymbolicC++** with the same autors (looka like an alias book from another publisher) Maybe someone played in this topic, and can give some advice: is D language with its OOP without multiple inheritance and maybe other semantic limitations able and good enough to be used with these books mechanics? The theme looks complex off the shelf, and I'm not sure to speak about D to this above student, especially I myself can't help him anyway not knowing the language in deep.
Re: druntime homebrew: setup and compile a single project with its own stdlib
If you have a module source file with the same name you want to replace, the build will prioritize your own version. You mean I can create `project/druntime`, and replace the core D runtime part by part by placing here my own files from druntime source? And compiler will route his internal callbacks etc into my own partial stdlib without any undocumented options or .a/.so prebuilding ?
Re: Search for the dialog library
On Saturday, 14 October 2023 at 23:02:34 UTC, Alexander Zhirov wrote: Colleagues, tell me, please, is there any library on D for drawing dialog boxes? Maybe it's time to port the old warm tubby Turbo Vision into the glorious D lang? https://github.com/magiblot/tvision
use dmd for bare metal i386
Is dmd able to be forced not include some unneeded information into target object files to make bare metal 32-bit code? Need some samples and build scripts to do it. Or maybe move to ldc2 required