volodya-lombrozo / jsmith

Jsmith, a random generator of Java programs
MIT License
11 stars 1 forks source link

Try Semantic Labels #92

Open volodya-lombrozo opened 5 days ago

volodya-lombrozo commented 5 days ago

As I have already described in the Sematic Labels section, we might try to introduce some labels to ANTLR grammar:

grammar Arithmetic;

prog: stat+ ;

stat: expr NEWLINE
    | ID '=' expr NEWLINE #ID_VariableDeclaration
    | NEWLINE
    ;

expr: expr ('*' | '/' ) expr
    | expr ('+' | '-' ) expr
    | INT
    | ID #ID_VariableUsage
    | '(' expr ')'
    ;

ID  : [a-zA-Z]+ ;
INT : [0-9]+ ;
NEWLINE: '\r'? '\n' ;
WS  : [ \t]+ -> skip ;

Pay attention to the #ID_VariableDeclaration and #ID_VariableUsage labels usage. Both of them are applied to ID lexer rule. We should try if it's possible to guide program generation by using such labels.