Questions tagged [parse-tree]

A parse tree (aka. parsing tree or concrete syntax tree) is an ordered, rooted tree that represents the syntactic structure of a string according to some context-free grammar.

A parse tree (aka. parsing tree or concrete syntax tree) is an ordered, rooted tree that represents the syntactic structure of a string according to some context-free grammar.

Example

From What's the difference between parse tree and AST?

enter image description here

See also:

173 questions
95
votes
5 answers

What's the difference between parse tree and AST?

Are they generated by different phases of a compiling process? Or are they just different names for the same thing?
60
votes
5 answers

What's the difference between parse trees and abstract syntax trees?

I found the two terms in a compiler design book, and I'd like to know what each stands for, and how they are different. I searched on the internet and found that parse trees are also called concrete syntax trees (CSTs).
Shashi Bhushan
  • 1,371
  • 3
  • 15
  • 20
25
votes
3 answers

Getting the line number in the ParserVisitor?

I'm trying to get line numbers for more specific error messages in my ParserVisitor (visits the parse tree generated by antlr). However, all I have in this class is the context ctx, and I can do things like ctx.getText() but not getLine(). Is there…
17
votes
1 answer

What does the tag SBAR mean in Stanford’s parse-tree representation?

When the Online Stanford Parser tool is fed this original sentence: After she ate the cake, Emma visited Tony in his room. It produces the following parse-tree representation as its output: (ROOT (S (SBAR (IN After) (S (NP…
user3054733
  • 173
  • 1
  • 6
13
votes
2 answers

Representing a multiple pass Abstract Syntax Tree (AST) in C++?

I am currently exploring designing a compiler that transforms its AST in multiple stages. The idea is that starting from the parse tree, each pass transforms the tree until the resulting AST is optimised and contains all of the required information…
Dylan
  • 1,542
  • 1
  • 10
  • 21
10
votes
1 answer

Searching inside scala 2.10 ASTs

What's the best way to recursively search for an element in scala 2.10 ASTs? The trees might be a result of power.trees(code) or mirror.mkToolBox().parseExpr(code) Edit. In 2.10.0-RC1 parseExpr has been renamed to parse. The concrete use-case that I…
8
votes
4 answers

Javascript syntax test cases

I'm creating a text editor and I've just finished writing the highlighting algorithms to have each of the syntax appear in a different color, and render in the right position using the proper parse trees. I was wondering if anyone could provide me…
GAgnew
  • 3,325
  • 3
  • 22
  • 28
8
votes
2 answers

Extract tokens from grammar

I have been working through the Advent of Code problems in Perl6 this year and was attempting to use a grammar to parse the Day 3's input. Given input in this form: #1 @ 1,3: 4x4 and this grammar that I created: grammar Claim { token TOP { …
Hunter McMillen
  • 52,839
  • 21
  • 105
  • 154
8
votes
4 answers

Generate syntax tree for simple math operations

I am trying to generate a syntax tree, for a given string with simple math operators (+, -, *, /, and parenthesis). Given the string "1 + 2 * 3": It should return an array like this: ["+", [1, ["*", [2,3] ] ] ] I made a function to…
user216441
8
votes
1 answer

Is it possible to use Recursive Descent Parser to both verify the grammar AND build the parse tree at the same time?

Is it possible to generate a parse tree at the same time as I use recursive descent parser to check if the data matches grammar? If so, what approach would I use to build a tree as I recursively descent? Thanks, Boda Cydo. Note: I am new to parsing.…
bodacydo
  • 63,809
  • 83
  • 206
  • 303
7
votes
2 answers

ANTLR v4, JavaLexer and JavaParser returning null as parse tree

I am using antlr v4 for extracting parse tree of java programs for other purposes. I have started from this sample: ANTLR v4 visitor sample And I have tested the steps on given link to check if it works and everything gone right: java Run a = 1+2 b…
ConductedClever
  • 3,537
  • 1
  • 21
  • 54
6
votes
4 answers

How to turn a token stream into a parse tree

I have a lexer built that streams out tokens from in input but I'm not sure how to build the next step in the process - the parse tree. Does anybody have any good resources or examples on how to accomplish this?
Evan Fosmark
  • 89,147
  • 33
  • 99
  • 116
6
votes
1 answer

NLTK tree data structure, finding a node, it's parent or children

I am using nltk's Tree data structure to work with parsetree strings. from nltk.tree import Tree parsed = Tree('(ROOT (S (NP (PRP It)) (VP (VBZ is) (ADJP (RB so) (JJ nice))) (. .)))') The data structure, however, seems to be limited. Is it possible…
CentAu
  • 8,184
  • 12
  • 47
  • 74
6
votes
2 answers

What does the dependency-parse output of TurboParser mean?

I have been trying to use the dependency parse trees generated by CMU's TurboParser. It works flawlessly. The problem, however, is that there is very little documentation. I need to precisely understand the output of their parser. For example, the…
Chthonic Project
  • 7,687
  • 1
  • 39
  • 85
6
votes
1 answer

Unary And Binary Minus in Parse Tree

I am creating a parse tree that will contain expressions similar to 3 - 4 * 8 or 8 * -5 or -(10 * 1) I need a way to distinguish between the unary and binary minus. The way my grammar is going now the binary minus is reached first, but I am…
1
2 3
11 12