moving from classical lex/yacc to pegged parser

Dmitry Ponyatov dponyatov at gmail.com
Thu May 9 08:30:14 UTC 2024


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<string, Object*> attr;
   vector<Object*>      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?


More information about the Digitalmars-d-learn mailing list