GitHub - Prenglis/SetlCup: A LR-Parser-Generator for the programming language SetlX (original) (raw)

SetlCup

Idea

A LR-Parser-Generator for the programming language SetlX oriented on JavaCup

Requirements

How to call

Setlcup can be called in multiple ways:

Command Line

setlx setlcup.stlx -p <input_file>

Creates the Parser in the file input_file_Grammar.stlx (in the directory of the input-file)

setlx setlcup.stlx -p <input_file> -d

Creates the Parser in the file input_file_Grammar.stlx (in the directory of the input-file) and outputs information about the creation process

Shows information about how to call SetlCup correctly

Testing

This programm test the parsergeneration with the given examples. It should return:

Testing math_expression_grammar..
parser generated succefully for math_expression_grammar_ast.g
grammar: math_expression_grammar_ast.g input: math_expression_input.txt successfull: yes
Testing interpreter_grammar..
parser generated succefully for interpreter_grammar_ast.g
grammar: interpreter_grammar_ast.g input: factorial.sl successfull: yes
grammar: interpreter_grammar_ast.g input: solve.sl successfull: yes
grammar: interpreter_grammar_ast.g input: sum.sl successfull: yes
grammar: interpreter_grammar_ast.g input: sum-for.sl successfull: yes

In Setlx

You need to load the program "setlcup_load.stlx"

load("setlcup_load.stlx");

Afterwards Setlcup can be used via the method call

generate_parser(input_grammar, silent_mode);

e.g.

load("setlcup_load.stlx");
generate_parser('examples\math_expression_grammar_ast.g', true);
load('examples\math_expression_grammar_astGrammar.stlx');
result := test_parser_from_file('examples\math_expression_input.txt', true);

##Tutorial In the Folder Tutorial a tutorial explains the needed structure of files which can be used as input. ##Example To parse a simple arithmetic expression grammar you can call:

setlx setlcup.stlx -p examples/math_simple_expression.g
setlx math_simple_expressionGrammar.stlx -p simple_statement.txt

This will return the output:

It is derivated from the input file: