How Would I Go About Creating a Parser For a Custom Language?

I saw a post in #resources:community-resources i think. I forgot what it was called but I’m pretty sure it was called “Bad-Lang”.

I kinda wanna create something like that. I already know how I’d go about making a Lexer, but now I need to make a Parser…

I don’t know how I’d even start to create it. I’ve looked at other people’s Parsers to see if I’d get an idea on how to make one; but I haven’t had any success with that.

If you have any useful source, please provide them; thanks :slight_smile:

I might seriously be dumb and maybe I don’t need a parser but ima ask anyways.

2 Likes

If your lang is like most langs, a good next step would be syntax analysis: going through your sequence of lexemes and determining which class of “concrete syntax node” each lexeme represents, and how each syntax node fits in with the others.

Most langs have a concept of variables and variable scope, and most langs use scopes that can be nested inside other scopes which creates a tree-like structure. And if you want a concept of expressions list most langs, expressions themselves usually have tree-like structure. Lang syntax is often specified using something called grammars, which are recursive and thus tree-like. So it’s natural to represent your syntax nodes as nodes in a tree. A tree in this case is a type of graph.

The result of this “next step” is a concrete syntax tree aka parse tree OR an abstract syntax tree. The next-next step is semantic analysis.

https://eli.thegreenplace.net/2009/02/16/abstract-vs-concrete-syntax-trees/

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.