Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Dec 16, 2023
1 parent 505ec8e commit 1dcb323
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions docs/parsing-techniques.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# Parsing Techniques
---
title: Parsing Techniques
---

## grammar
# grammar

We are able to use markup to pick up parts,
and ignore other parts during collection.
The named parts will be pick up into the resulting object.

The resulting object is a generic AST,
to be matched to target AST in the host language.

```
exp = {
exp:var -> (name: identifier)
Expand All @@ -14,7 +19,7 @@ exp = {
}
```

## fn
# fn

```
one_or_more(x) = {
Expand All @@ -23,7 +28,11 @@ one_or_more(x) = {
}
```

## ap
`one_or_more` as a grammar function, takes grammar and returns grammar.

Can we do shallow embedding by adding a `Grammar` type to JS?

# ap

A function can only take one argument.
- terminal -- "(" & ")" , does not count as argument.
Expand All @@ -44,7 +53,7 @@ one_or_more("(" x ")")
}
```

## parse tree
# parse tree

A parse tree is a graph that shows how a sentence is derived by some CFG.

Expand Down Expand Up @@ -103,6 +112,14 @@ ADT decorated by terminals and ignored non-terminals.
</one_or_more.more>
```

```
one_or_more.one("f")
one_or_more.more("f",
one_or_more.more("f",
one_or_more.one("f")))
```

```
one_or_more.one(value: "f")
Expand Down

0 comments on commit 1dcb323

Please sign in to comment.