Skip to content

Commit

Permalink
Реализованы переключатели режимов в парсере Рефала-5λ (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mazdaywik committed Dec 31, 2017
1 parent 9b484ce commit a7200f4
Show file tree
Hide file tree
Showing 8 changed files with 427 additions and 106 deletions.
168 changes: 168 additions & 0 deletions autotests/compatibility/classic-extended.OK.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
*$CLASSIC
*$EXTENDED

$ENTRY
*$CLASSIC;
Go
*$EXTENDED;
{
*$CLASSIC
=
*$EXTENDED
;

*$CLASSIC;
(
*$EXTENDED;
A
*$CLASSIC
(
*$EXTENDED
10
*$CLASSIC;
"BCD"
*$EXTENDED;
'efgh'
*$CLASSIC
)
*$EXTENDED
)
*$CLASSIC;
Q
*$EXTENDED;
=
*$CLASSIC
<Go
*$EXTENDED
(
*$CLASSIC;
P
*$EXTENDED;
Q
*$CLASSIC
<Go
*$EXTENDED
>
*$CLASSIC;
R
*$EXTENDED;
)
*$CLASSIC
's'
*$EXTENDED
't'
*$CLASSIC;
>
*$EXTENDED;
;
*$CLASSIC

Pattern
*$EXTENDED
,
*$CLASSIC;
CondResult1
*$EXTENDED;
:
CondPattern1
*$EXTENDED
,
*$CLASSIC;
CondResult2
*$EXTENDED;
:
*$CLASSIC
CondPattern2
*$EXTENDED
=
*$CLASSIC;
Result
*$EXTENDED;
;

*$CLASSIC
Pattern
*$EXTENDED
,
*$CLASSIC;
CondResult1
*$EXTENDED;
:
*$CLASSIC
CondPattern1
*$EXTENDED
,
*$CLASSIC;
BlockResult2
*$EXTENDED;
:
*$CLASSIC
{
*$EXTENDED
BlockPattern1
*$CLASSIC;
=
*$EXTENDED;
BlockResult1
*$CLASSIC
;
*$EXTENDED
BlockPattern2
*$CLASSIC;
,
*$EXTENDED;
BlockCondResult1
*$CLASSIC
:
*$EXTENDED
BlockCondPattern1
*$CLASSIC;
=
*$EXTENDED;
BlockResult2
*$CLASSIC;
;
*$EXTENDED
}
*$CLASSIC;
;

*$EXTENDED;
Pattern
*$CLASSIC;
,
*$EXTENDED
BlockResult
*$CLASSIC;
:
*$EXTENDED;
{
*$CLASSIC;
BlockPattern
*$EXTENDED
=
*$CLASSIC;
BlockResult
*$EXTENDED;
/*;*/
*$CLASSIC;
}
*$EXTENDED
;
*$CLASSIC;
}
*$EXTENDED

$EXTERN
*$CLASSIC;
Foo
*$EXTENDED;
,
*$CLASSIC
Bar
*$EXTENDED
,
*$CLASSIC;
Baz
*$EXTENDED;
;
42 changes: 37 additions & 5 deletions autotests/compatibility/run.bat
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ goto :EOF

:: Поиск srefc
if exist ..\..\bin\srefc-core.exe (
set REFAL_COMPILERS=srefc %REFAL_COMPILERS%
set REFAL_COMPILERS=srefc_classic srefc_lambda %REFAL_COMPILERS%
set SREFC_EXIST=1
echo ... found srefc
call ..\..\scripts\load-config.bat || exit /b 1
Expand Down Expand Up @@ -231,7 +231,7 @@ setlocal
endlocal
goto :EOF

:COMPILE.srefc
:COMPILE_SREFC_COMMON
setlocal
set SRC=%1
set TARGET=%~n1.exe
Expand All @@ -253,7 +253,14 @@ setlocal
endlocal
goto :EOF

:EXECUTE_OK.srefc
:COMPILE.srefc_classic
setlocal
set COMMON_SRFLAGS=%COMMON_SRFLAGS% --classic
call :COMPILE_SREFC_COMMON "%~1" || exit /b 1
endlocal
goto :EOF

:EXECUTE_OK.srefc_classic
setlocal
set EXE=%~n1.exe
echo Y| %EXE% Hello "Hello, World" "" \ > stdout.txt 2>stderr.txt
Expand All @@ -266,7 +273,7 @@ setlocal
endlocal
goto :EOF

:EXECUTE_FAIL.srefc
:EXECUTE_FAIL.srefc_classic
setlocal
set EXE=%~n1.exe
echo Y| %EXE% > stdout.txt
Expand All @@ -287,7 +294,7 @@ setlocal
endlocal
goto :EOF

:CLEANUP.srefc
:CLEANUP.srefc_classic
setlocal
call :CLEANUP_COMMON
if exist "%~1.rasl" erase "%~1.rasl"
Expand All @@ -297,6 +304,31 @@ setlocal
endlocal
goto :EOF

:COMPILE.srefc_lambda
setlocal
set COMMON_SRFLAGS=%COMMON_SRFLAGS% --extended
call :COMPILE_SREFC_COMMON "%~1" || exit /b 1
endlocal
goto :EOF

:EXECUTE_OK.srefc_lambda
setlocal
call :EXECUTE_OK.srefc_classic "%~1" || exit /b 1
endlocal
goto :EOF

:EXECUTE_FAIL.srefc_lambda
setlocal
call :EXECUTE_FAIL.srefc_lambda "%~1" || exit /b 1
endlocal
exit /b 0

:CLEANUP.srefc_lambda
setlocal
call :CLEANUP.srefc_classic "%~1" || exit /b 1
endlocal
goto :EOF

:COMPILE.crefal
setlocal
set RSL="%~n1"-crefal.rsl
Expand Down
33 changes: 27 additions & 6 deletions autotests/compatibility/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ lookup_compilers() {

# Поиск srefc
if [ -e ../../bin/srefc-core ]; then
REFAL_COMPILERS="srefc $REFAL_COMPILERS"
REFAL_COMPILERS="srefc_classic srefc_lambda $REFAL_COMPILERS"
SREFC_EXIST=1
echo ... found srefc
source ../../scripts/load-config.sh ../.. || return 1
Expand Down Expand Up @@ -215,11 +215,12 @@ run_test_result_SYNTAX-ERROR() {
done
}

compile_srefc() {
compile_srefc_common() {
SRC=$1
TARGET=${SRC%%.ref}$(platform_exe_suffix)
FLAGS_EX=$2

../../bin/srefc-core $SRC -o $TARGET "${COMMON_SRFLAGS[@]}" \
../../bin/srefc-core $SRC -o $TARGET "${COMMON_SRFLAGS[@]}" $FLAGS_EX \
--prefix=_test_prefix external 2>__error.txt
if [ $? -ge 100 ]; then
echo COMPILER FAILS ON $SRC, SEE __error.txt
Expand All @@ -231,7 +232,11 @@ compile_srefc() {
rm __error.txt
}

execute_OK_srefc() {
compile_srefc_classic() {
compile_srefc_common "$1" --classic || return 1
}

execute_OK_srefc_classic() {
SRC=$1
EXE=${SRC%%.ref}$(platform_exe_suffix)
echo Y | ./$EXE Hello "Hello, World" "" $SEP > stdout.txt 2>stderr.txt || {
Expand All @@ -241,7 +246,7 @@ execute_OK_srefc() {
}
}

execute_FAIL_srefc() {
execute_FAIL_srefc_classic() {
SRC=$1
EXE=${SRC%%.ref}$(platform_exe_suffix)
if echo Y | ./$EXE > stdout.txt; then
Expand All @@ -256,7 +261,7 @@ cleanup_common() {
rm -f __dump.txt $OUTPUT_FILES REFAL7.DAT
}

cleanup_srefc() {
cleanup_srefc_classic() {
cleanup_common
SRC=$1
RASL=${SRC%%.ref}.rasl
Expand All @@ -266,6 +271,22 @@ cleanup_srefc() {
rm -f external.rasl
}

compile_srefc_lambda() {
compile_srefc_common "$1" --extended || return 1
}

execute_OK_srefc_lambda() {
execute_OK_srefc_classic "$1" || return 1
}

execute_FAIL_srefc_lambda() {
execute_FAIL_srefc_classic "$1" || return 1
}

cleanup_srefc_lambda() {
cleanup_srefc_classic "$1" || return 1
}

compile_crefal() {
SRC=$1
RSL=${SRC%%.ref}-crefal.rsl
Expand Down
17 changes: 17 additions & 0 deletions src/compiler/Config.sref
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ $ENTRY Config-Create {
(#Incorporateds /* пусто */)
(#ChmodXCommand /* пусто */)
(#Prelude /* пусто */)
(#Refal5Mode #Extended)
];
}

Expand Down Expand Up @@ -543,3 +544,19 @@ $ENTRY Config-SetPrelude {
[Config e.Params-B (#Prelude e.OldPrelude) e.Params-E] e.NewPrelude
= #Success [Config e.Params-B (#Prelude e.NewPrelude) e.Params-E];
}

/**
<Config-GetR5Mode t.Config> == s.Refal5Mode
s.Refal5Mode ::= #Classic | #Extended
*/
$ENTRY Config-GetR5Mode {
[Config e.Params-B (#Refal5Mode s.Mode) e.Params-E] = s.Mode;
}

/**
<Config-SetR5Mode t.Config s.Refal5Mode> == #Success t.Config
*/
$ENTRY Config-SetR5Mode {
[Config e.Params-B (#Refal5Mode s.OldMode) e.Params-E] s.NewMode
= #Success [Config e.Params-B (#Refal5Mode s.NewMode) e.Params-E];
}
8 changes: 5 additions & 3 deletions src/compiler/Driver.sref
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ $EXTERN EL-Destroy, EL-Create, EL-AddErrorAt, EL-Concat;
//FROM Config
$EXTERN
Config-GetPrelude,
Config-GetR5Mode,
Config-GetSearchFolders,
Config-GetDebugMode,
Config-GetOptPattern,
Expand Down Expand Up @@ -98,9 +99,9 @@ FrontEnd {
}

R5-Parse-Wrapped {
(e.SrcName) e.Tokens
s.Mode (e.SrcName) e.Tokens
= <EL-Create e.SrcName> : t.ErrorList
= <R5-Parse e.Tokens> : (e.Errors) e.AST
= <R5-Parse s.Mode e.Tokens> : (e.Errors) e.AST
= <MapReduce
{
t.ErrorList^ ((#RowCol s.Line s.Col) e.Message)
Expand Down Expand Up @@ -128,7 +129,8 @@ PreludeIncludeLine {
LoadAST {
t.Config #R5 e.SrcName
= <R5-Scan e.SrcName> : e.Tokens
= <R5-Parse-Wrapped (e.SrcName) e.Tokens> : t.ErrorList e.AST
= <Config-GetR5Mode t.Config> : s.Mode
= <R5-Parse-Wrapped s.Mode (e.SrcName) e.Tokens> : t.ErrorList e.AST
= t.ErrorList <PreludeIncludeLine t.Config> e.AST;

t.Config #SR e.SrcName
Expand Down
Loading

0 comments on commit a7200f4

Please sign in to comment.