Questions tagged [concrete-syntax-tree]

Concrete syntax tree is intended for questions related to syntax analysis necessary for automated source code refactoring or syntax analysis tool development.

A concrete syntax tree is a hierarchical representation of the syntax of a language which is generated by parsing tokens based on a grammar definition.

References

19 questions
123
votes
9 answers

What is the difference between an Abstract Syntax Tree and a Concrete Syntax Tree?

I've been reading a bit about how interpreters/compilers work, and one area where I'm getting confused is the difference between an AST and a CST. My understanding is that the parser makes a CST, hands it to the semantic analyzer which turns it…
6
votes
1 answer

How do I reduce my parse tree into an abstract syntax tree?

What are the general strategies for reducing a parse tree (ie. concrete syntax tree) into an abstract syntax tree? For example, I have the following grammar rule: statement_list : statement | statement_list statement which, if left…
5
votes
1 answer

When to use an abstract or concrete syntax tree?

I've been doing research on compilers. The lexer seems to be very straight forward: Take a "sentence" and break it up into words (or tokens). To ensure correct grammar a parser is needed. The parser generally takes the tokens and builds a tree that…
Luke
  • 13,678
  • 7
  • 45
  • 79
5
votes
5 answers

Parse tree and grammar information

Does anyone know where to find good online resources with examples of how to make grammars and parse trees? Preferably introductory materials. Info that is n00b friendly, haven't found anything good with Google myself. Edit: I'm thinking about…
fuzzylogikk
  • 97
  • 1
  • 6
4
votes
2 answers

Difference between a DOM tree parsing and a syntax tree parsing?

After parsing HTML or XML file, we can get the DOM tree. After parsing C, C++, or JavaScript, we can get the Syntax tree. Note that the syntax tree is constructed based on the context-free grammar which specifies a valid C/C++/JS program. But it…
JackWM
  • 10,085
  • 22
  • 65
  • 92
3
votes
0 answers

How to add custom node to AST in Pharo SmaCC?

I am creating CST with universal custom nodes for Java language in SmaCC with Pharo. I found grammar (parser and scanner) and I tested it with few examples, creating Abstract Syntax Tree works perfect. But, I need to create Concrete Syntax Tree with…
3
votes
1 answer

What do I do with a Concrete Syntax Tree?

I'm using pyPEG to create a parse tree for a simple grammar. The tree is represented using lists and tuples. Here's an example: [('command', [('directives', [('directive', [('name', 'retrieve')]), ('directive', [('name',…
exupero
  • 9,136
  • 8
  • 47
  • 63
2
votes
1 answer

How is a NullLiteral represented in tree form?

According to the ECMAScript specification in section 7.8.1 a NullLiteral is defined as follows: NullLiteral :: null What I am trying to understand is how this is represented in tree form when a NullLiteral is included in the following…
ChaosPandion
  • 77,506
  • 18
  • 119
  • 157
2
votes
1 answer

How do I translate LR(1) Parse into a Abstract syntax tree?

I have coded a table driven LR(1) parser and it is working very well however I am having a bit of a disconnect on the stage of turing a parse into a syntax tree/abstract syntax tree. This is a project that I m very passionate about but I have really…
2
votes
2 answers

How to stop `ast.parse` from converting numerical values into int/floats?

For example:: >>> import ast >>> print(type(ast.parse('1.2', mode='eval').body.n) float How do I let the parser convert a python source file into a syntax tree, while preserving the original values of nodes in str type? Because I need to convert…
1
vote
2 answers

Python comment-preserving parsing using only builtin libraries?

I wrote a library using just ast and inspect libraries to parse and emit [uses astor on Python < 3.9] internal Python constructs. Just realised that I really need to preserve comments afterall. Preferably without resorting to a RedBaron or LibCST;…
1
vote
2 answers

libcst: Inserting new node adds inline code and a semicolon

I am trying to introduce a new node (as a new line of code), exactly before an Assign node. The issue occurs when using FlattenSentinel to introduce the new node as I want the node to be separate, but libcst concatenates them using a semicolon (;),…
user10728141
  • 59
  • 1
  • 8
1
vote
1 answer

How I can convert concrete syntax values to other kinds of values?

Given some concrete syntax value, how I can I map it to a different type of value (in this case an int)? // Syntax start syntax MyTree = \node: "(" MyTree left "," MyTree right ")" | leaf: Leaf leaf ; layout…
Tim
  • 221
  • 3
  • 12
0
votes
0 answers

Creating a parse tree for a SQL statement

Given the following statement and ignoring any grammar concerns, what might be the most 'pure' way to parse the following SQL statement? SELECT a, b AS x FROM tbl AS z My thinking is something along the following: selectStatement …
carl.hiass
  • 1,526
  • 1
  • 6
  • 26
0
votes
1 answer

How to get the abstact syntax tree using the language concrete syntax tree?

How to use the concrete syntax tree to parse a file and generate the abstract syntax tree? I came across with concrete syntax trees on this blog post about ungrammar. But I can't wrap my head around on how to build the parser.
1
2