3

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 custom universal Nodes, e.g. on each while, for, do nodes I need to add parent node LOOP_STATEMENT. I can't find how to do it? Is it possible?

I read all about SmaCC and Pharo, but can't find example or solution here http://books.pharo.org/booklet-Smacc/html/Chapters/Smacc/SmaccAST.html

I tried for example to add custom CST nodes on sample Calculator code.

This is AST grammar

<whitespace> : \s+;

%left "+" "-";
%left "*" "/";
%right "^";

%annotate_tokens;
%root Expression;
%prefix AST;
%suffix Node;

Expression 
    : Expression 'left' "+" 'operator' Expression 'right' {{Binary}}
    | Expression 'left' "-" 'operator' Expression 'right' {{Binary}}
    | Expression 'left' "*" 'operator' Expression 'right' {{Binary}}
    | Expression 'left' "/" 'operator' Expression 'right' {{Binary}}
    | Expression 'left' "^" 'operator' Expression 'right' {{Binary}}
    | "(" Expression ")" {{}}
    | Number
    ;
Number 
    : <number> {{Number}}
    ;

For example, I need to add node SEPARATOR as a parent of each bracket. By knowing how to do that, that would solve my problem with Java grammar and adding LOOP_STATEMENT as a parent of while node.

gal007
  • 6,911
  • 8
  • 47
  • 70
Lazar Djukic
  • 66
  • 1
  • 5
  • We don't tend to use Stackoverflow, as it is not a usable community for small languages like smalltalk. Too many useful questions get closed. You'll be better off on the mailing list or on the discord server – Stephan Eggermont Sep 17 '19 at 17:20
  • 2
    @StephanEggermont Please note that some of us do use SO and are doing our best to keep all the Smalltalk related tags active and interesting. – Leandro Caniglia Sep 20 '19 at 14:41
  • @LeandroCaniglia Yes, and most of us have more or less given up on that – Stephan Eggermont Sep 23 '19 at 19:56

0 Answers0